summaryrefslogtreecommitdiffstats
path: root/source/slang/syntax.cpp
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/syntax.cpp
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/syntax.cpp')
-rw-r--r--source/slang/syntax.cpp14
1 files changed, 7 insertions, 7 deletions
diff --git a/source/slang/syntax.cpp b/source/slang/syntax.cpp
index a03783825..be1a429a6 100644
--- a/source/slang/syntax.cpp
+++ b/source/slang/syntax.cpp
@@ -260,7 +260,7 @@ void Type::accept(IValVisitor* visitor, void* extra)
return errorType;
}
- SyntaxClass<RefObject> Session::findSyntaxClass(String const& name)
+ SyntaxClass<RefObject> Session::findSyntaxClass(Name* name)
{
SyntaxClass<RefObject> syntaxClass;
if (mapNameToSyntaxClass.TryGetValue(name, syntaxClass))
@@ -306,7 +306,7 @@ void Type::accept(IValVisitor* visitor, void* extra)
String DeclRefType::ToString()
{
- return declRef.GetName();
+ return getText(declRef.GetName());
}
int DeclRefType::GetHashCode()
@@ -620,7 +620,7 @@ void Type::accept(IValVisitor* visitor, void* extra)
String NamedExpressionType::ToString()
{
- return declRef.GetName();
+ return getText(declRef.GetName());
}
bool NamedExpressionType::EqualsImpl(Type * /*type*/)
@@ -646,7 +646,7 @@ void Type::accept(IValVisitor* visitor, void* extra)
{
// TODO: a better approach than this
if (declRef)
- return declRef.GetName();
+ return getText(declRef.GetName());
else
return "/* unknown FuncType */";
}
@@ -786,7 +786,7 @@ void Type::accept(IValVisitor* visitor, void* extra)
String GenericParamIntVal::ToString()
{
- return declRef.GetName();
+ return getText(declRef.GetName());
}
int GenericParamIntVal::GetHashCode()
@@ -947,9 +947,9 @@ void Type::accept(IValVisitor* visitor, void* extra)
}
// Convenience accessors for common properties of declarations
- String const& DeclRefBase::GetName() const
+ Name* DeclRefBase::GetName() const
{
- return decl->name.Content;
+ return decl->nameAndLoc.name;
}
DeclRefBase DeclRefBase::GetParent() const