diff options
| author | Tim Foley <tim.foley.is@gmail.com> | 2017-08-14 18:50:46 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-08-14 18:50:46 -0700 |
| commit | aeb247cdf02e4dcfc0bb6839cfd291be5128f8ad (patch) | |
| tree | 7314b26e21ded966b6a4fe2430f0421c0c0970bd /source/slang/slang.cpp | |
| parent | bb66d6eddd649d8861cecefa2d6ccb7a28a827bc (diff) | |
| parent | 9885c972a6bfa6f856e505cdd90d9b71fdbdadaf (diff) | |
Merge pull request #159 from tfoleyNV/name-type
Name type
Diffstat (limited to 'source/slang/slang.cpp')
| -rw-r--r-- | source/slang/slang.cpp | 29 |
1 files changed, 20 insertions, 9 deletions
diff --git a/source/slang/slang.cpp b/source/slang/slang.cpp index 2bacb28ca..f6e9bd70b 100644 --- a/source/slang/slang.cpp +++ b/source/slang/slang.cpp @@ -20,9 +20,13 @@ namespace Slang { Session::Session() { + // Initialize name pool + getNamePool()->setRootNamePool(getRootNamePool()); + // Initialize the lookup table of syntax classes: - #define SYNTAX_CLASS(NAME, BASE) mapNameToSyntaxClass.Add(#NAME, getClass<NAME>()); + #define SYNTAX_CLASS(NAME, BASE) \ + mapNameToSyntaxClass.Add(getNamePool()->getName(#NAME), getClass<NAME>()); #include "object-meta-begin.h" #include "syntax-base-defs.h" @@ -110,6 +114,8 @@ struct IncludeHandlerImpl : IncludeHandler CompileRequest::CompileRequest(Session* session) : mSession(session) { + getNamePool()->setRootNamePool(session->getRootNamePool()); + setSourceManager(&sourceManagerStorage); sourceManager->initialize(session->getBuiltinSourceManager()); @@ -378,7 +384,7 @@ int CompileRequest::addEntryPoint( { RefPtr<EntryPointRequest> entryPoint = new EntryPointRequest(); entryPoint->compileRequest = this; - entryPoint->name = name; + entryPoint->name = getNamePool()->getName(name); entryPoint->profile = entryPointProfile; entryPoint->translationUnitIndex = translationUnitIndex; @@ -391,7 +397,7 @@ int CompileRequest::addEntryPoint( } RefPtr<ModuleDecl> CompileRequest::loadModule( - String const& name, + Name* name, String const& path, String const& source, SourceLoc const&) @@ -462,15 +468,20 @@ void CompileRequest::handlePoundImport( // as the "name" when registering things, but this saves // us the trouble of trying to special-case things when // checking an `import` down the road. - mapNameToLoadedModules.Add(path, moduleDecl); + // + // Ideally we'd construct a suitable name by effectively + // running the name->path logic in reverse (e.g., replacing + // `-` with `_` and `/` with `.`). + Name* name = getNamePool()->getName(path); + mapNameToLoadedModules.Add(name, moduleDecl); mapPathToLoadedModule.Add(path, moduleDecl); loadedModulesList.Add(moduleDecl); } RefPtr<ModuleDecl> CompileRequest::findOrImportModule( - String const& name, - SourceLoc const& loc) + Name* name, + SourceLoc const& loc) { // Have we already loaded a module matching this name? // If so, return it. @@ -485,7 +496,7 @@ RefPtr<ModuleDecl> CompileRequest::findOrImportModule( // For example, `foo_bar` becomes `foo-bar.slang`. StringBuilder sb; - for (auto c : name) + for (auto c : getText(name)) { if (c == '_') c = '-'; @@ -541,8 +552,8 @@ RefPtr<ModuleDecl> CompileRequest::findOrImportModule( RefPtr<ModuleDecl> findOrImportModule( CompileRequest* request, - String const& name, - SourceLoc const& loc) + Name* name, + SourceLoc const& loc) { return request->findOrImportModule(name, loc); } |
