summaryrefslogtreecommitdiff
path: root/source/slang/decl-defs.h
diff options
context:
space:
mode:
authorTim Foley <tfoley@nvidia.com>2017-08-14 14:48:37 -0700
committerTim Foley <tfoley@nvidia.com>2017-08-14 14:48:37 -0700
commit9885c972a6bfa6f856e505cdd90d9b71fdbdadaf (patch)
tree7314b26e21ded966b6a4fe2430f0421c0c0970bd /source/slang/decl-defs.h
parent7f57ea4ad86c2a3eb5a14fef458e711845c1f87e (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/decl-defs.h')
-rw-r--r--source/slang/decl-defs.h24
1 files changed, 2 insertions, 22 deletions
diff --git a/source/slang/decl-defs.h b/source/slang/decl-defs.h
index a63df243b..f27ab9ba6 100644
--- a/source/slang/decl-defs.h
+++ b/source/slang/decl-defs.h
@@ -21,7 +21,7 @@ ABSTRACT_SYNTAX_CLASS(ContainerDecl, Decl)
// Dictionary for looking up members by name.
// This is built on demand before performing lookup.
- Dictionary<String, Decl*> memberDictionary;
+ Dictionary<Name*, Decl*> memberDictionary;
// Whether the `memberDictionary` is valid.
// Should be set to `false` if any members get added/remoed.
@@ -80,26 +80,6 @@ RAW(
{
return getMembersOfType<StructField>();
}
- StructField* FindField(String name)
- {
- for (auto field : GetFields())
- {
- if (field->name.Content == name)
- return field.Ptr();
- }
- return nullptr;
- }
- int FindFieldIndex(String name)
- {
- int index = 0;
- for (auto field : GetFields())
- {
- if (field->name.Content == name)
- return index;
- index++;
- }
- return -1;
- }
)
END_SYNTAX_CLASS()
@@ -176,7 +156,7 @@ SIMPLE_SYNTAX_CLASS(ModuleDecl, ContainerDecl)
SYNTAX_CLASS(ImportDecl, Decl)
// The name of the module we are trying to import
- FIELD(Token, nameToken)
+ FIELD(NameLoc, moduleNameAndLoc)
// The scope that we want to import into
FIELD(RefPtr<Scope>, scope)