diff options
| author | Tim Foley <tfoley@nvidia.com> | 2017-08-14 14:48:37 -0700 |
|---|---|---|
| committer | Tim Foley <tfoley@nvidia.com> | 2017-08-14 14:48:37 -0700 |
| commit | 9885c972a6bfa6f856e505cdd90d9b71fdbdadaf (patch) | |
| tree | 7314b26e21ded966b6a4fe2430f0421c0c0970bd /source/slang/syntax-base-defs.h | |
| parent | 7f57ea4ad86c2a3eb5a14fef458e711845c1f87e (diff) | |
Add an explicit `Name` type
Fixes #23
Up to this point, the compiler has used the ordinary `String` type to represent declaration names, which means a bunch of lookup structures throughout the compiler were string-to-whatever maps, which can reduce efficiency.
It also means that things like the `Token` type end up carying a `String` by value and paying for things like reference-counting.
This change adds a `Name` type that is used to represent names of variables, types, macros, etc.
Names are cached and unique'd globally for a session, and the string-to-name mapping gets done during lexing.
From that point on, most mapping is from pointers, which should make all the various table lookups faster.
More importantly (possibly), this brings us one step closer to being able to pool-allocate the AST nodes.
Diffstat (limited to 'source/slang/syntax-base-defs.h')
| -rw-r--r-- | source/slang/syntax-base-defs.h | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/source/slang/syntax-base-defs.h b/source/slang/syntax-base-defs.h index d67acbe5c..e6f7cc55e 100644 --- a/source/slang/syntax-base-defs.h +++ b/source/slang/syntax-base-defs.h @@ -9,7 +9,7 @@ ABSTRACT_SYNTAX_CLASS(SyntaxNodeBase, RefObject) // The primary source location associated with this AST node - FIELD(SourceLoc, Position) + FIELD(SourceLoc, loc) RAW( // Allow dynamic casting with a convenient syntax @@ -173,8 +173,13 @@ ABSTRACT_SYNTAX_CLASS(Modifier, SyntaxNodeBase) // Next modifier in linked list of modifiers on same piece of syntax SYNTAX_FIELD(RefPtr<Modifier>, next) - // The token that was used to name this modifier. - FIELD(Token, nameToken) + // The keyword that was used to introduce t that was used to name this modifier. + FIELD(Name*, name) + + RAW( + Name* getName() { return name; } + NameLoc getNameAndLoc() { return NameLoc(name, loc); } + ) END_SYNTAX_CLASS() // A syntax node which can have modifiers appled @@ -211,11 +216,12 @@ END_SYNTAX_CLASS() ABSTRACT_SYNTAX_CLASS(Decl, DeclBase) DECL_FIELD(ContainerDecl*, ParentDecl RAW(=nullptr)) - FIELD(Token, name) + FIELD(NameLoc, nameAndLoc) RAW( - String const& getName() { return name.Content; } - Token const& getNameToken() { return name; } + Name* getName() { return nameAndLoc.name; } + SourceLoc getNameLoc() { return nameAndLoc.loc ; } + NameLoc getNameAndLoc() { return nameAndLoc ; } ) |
