summaryrefslogtreecommitdiffstats
path: root/source/slang/diagnostics.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/diagnostics.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/diagnostics.cpp')
-rw-r--r--source/slang/diagnostics.cpp19
1 files changed, 13 insertions, 6 deletions
diff --git a/source/slang/diagnostics.cpp b/source/slang/diagnostics.cpp
index 6f971ae76..45adf0ad8 100644
--- a/source/slang/diagnostics.cpp
+++ b/source/slang/diagnostics.cpp
@@ -2,6 +2,7 @@
#include "diagnostics.h"
#include "compiler.h"
+#include "name.h"
#include "syntax.h"
#include <assert.h>
@@ -38,9 +39,15 @@ void printDiagnosticArg(StringBuilder& sb, Slang::String const& str)
sb << str;
}
+void printDiagnosticArg(StringBuilder& sb, Name* name)
+{
+ sb << getText(name);
+}
+
+
void printDiagnosticArg(StringBuilder& sb, Decl* decl)
{
- sb << decl->name.Content;
+ sb << getText(decl->getName());
}
void printDiagnosticArg(StringBuilder& sb, Type* type)
@@ -70,17 +77,17 @@ void printDiagnosticArg(StringBuilder& sb, Token const& token)
SourceLoc const& getDiagnosticPos(SyntaxNode const* syntax)
{
- return syntax->Position;
+ return syntax->loc;
}
SourceLoc const& getDiagnosticPos(Token const& token)
{
- return token.Position;
+ return token.loc;
}
SourceLoc const& getDiagnosticPos(TypeExp const& typeExp)
{
- return typeExp.exp->Position;
+ return typeExp.exp->loc;
}
// Take the format string for a diagnostic message, along with its arguments, and turn it into a
@@ -147,7 +154,7 @@ static void formatDiagnostic(
{
auto sourceManager = sink->sourceManager;
- auto expandedLoc = sourceManager->expandSourceLoc(diagnostic.Position);
+ auto expandedLoc = sourceManager->expandSourceLoc(diagnostic.loc);
auto humaneLoc = sourceManager->getHumaneLoc(expandedLoc);
sb << humaneLoc.getPath();
@@ -170,7 +177,7 @@ void DiagnosticSink::diagnoseImpl(SourceLoc const& pos, DiagnosticInfo const& in
Diagnostic diagnostic;
diagnostic.ErrorID = info.id;
diagnostic.Message = sb.ProduceString();
- diagnostic.Position = pos;
+ diagnostic.loc = pos;
diagnostic.severity = info.severity;
if (diagnostic.severity >= Severity::Error)