summaryrefslogtreecommitdiffstats
path: root/source
diff options
context:
space:
mode:
authorTim Foley <tfoleyNV@users.noreply.github.com>2017-06-20 14:17:15 -0700
committerGitHub <noreply@github.com>2017-06-20 14:17:15 -0700
commit5170a56727c15da1443e8f9b0f21395861da9b0c (patch)
tree90e3852bd59d99ac875010b371172139ed6cd021 /source
parent338232bff7144c6a0e7964984765f01d9f9eecb7 (diff)
parentd852ad9fedb71f23b3aa70db0c7b43f6d6fd10e2 (diff)
Merge pull request #37 from tfoleyNV/falcor-work
Falcor work
Diffstat (limited to 'source')
-rw-r--r--source/slang/check.cpp30
-rw-r--r--source/slang/emit.cpp26
-rw-r--r--source/slang/parser.cpp4
3 files changed, 40 insertions, 20 deletions
diff --git a/source/slang/check.cpp b/source/slang/check.cpp
index 128afcefe..5a82380d3 100644
--- a/source/slang/check.cpp
+++ b/source/slang/check.cpp
@@ -44,7 +44,7 @@ namespace Slang
class SemanticsVisitor : public SyntaxVisitor
{
- ProgramSyntaxNode * program = nullptr;
+// ProgramSyntaxNode * program = nullptr;
FunctionSyntaxNode * function = nullptr;
CompileRequest* request = nullptr;
@@ -1239,37 +1239,40 @@ namespace Slang
}
}
- //
+ // We need/want to visit any `import` declarations before
+ // anything else, to make sure that scoping works.
+ for(auto& importDecl : programNode->getMembersOfType<ImportDecl>())
+ {
+ EnsureDecl(importDecl);
+ }
- HashSet<String> funcNames;
- this->program = programNode;
- this->function = nullptr;
+ //
- for (auto & s : program->GetTypeDefs())
+ for (auto & s : programNode->GetTypeDefs())
VisitTypeDefDecl(s.Ptr());
- for (auto & s : program->GetStructs())
+ for (auto & s : programNode->GetStructs())
{
VisitStruct(s.Ptr());
}
- for (auto & s : program->GetClasses())
+ for (auto & s : programNode->GetClasses())
{
VisitClass(s.Ptr());
}
// HACK(tfoley): Visiting all generic declarations here,
// because otherwise they won't get visited.
- for (auto & g : program->getMembersOfType<GenericDecl>())
+ for (auto & g : programNode->getMembersOfType<GenericDecl>())
{
VisitGenericDecl(g.Ptr());
}
- for (auto & func : program->GetFunctions())
+ for (auto & func : programNode->GetFunctions())
{
if (!func->IsChecked(DeclCheckState::Checked))
{
VisitFunctionDeclaration(func.Ptr());
}
}
- for (auto & func : program->GetFunctions())
+ for (auto & func : programNode->GetFunctions())
{
EnsureDecl(func);
}
@@ -4935,6 +4938,9 @@ namespace Slang
virtual void visitImportDecl(ImportDecl* decl) override
{
+ if(decl->IsChecked(DeclCheckState::Checked))
+ return;
+
// We need to look for a module with the specified name
// (whether it has already been loaded, or needs to
// be loaded), and then put its declarations into
@@ -4961,6 +4967,8 @@ namespace Slang
subScope->nextSibling = scope->nextSibling;
scope->nextSibling = subScope;
+
+ decl->SetCheckState(DeclCheckState::Checked);
}
};
diff --git a/source/slang/emit.cpp b/source/slang/emit.cpp
index 21704f6ff..c531a0a77 100644
--- a/source/slang/emit.cpp
+++ b/source/slang/emit.cpp
@@ -34,6 +34,8 @@ struct EmitContext
// instead.
Dictionary<String, int> mapGLSLSourcePathToID;
int glslSourceIDCount = 0;
+
+ HashSet<ProgramSyntaxNode*> modulesAlreadyEmitted;
};
//
@@ -2662,16 +2664,24 @@ static void EmitDeclImpl(EmitContext* context, RefPtr<Decl> decl, RefPtr<VarLayo
// When in "rewriter" mode, we need to emit the code of the imported
// module in-place at the `import` site.
- auto moduleDecl = importDecl->importedModuleDecl;
+ auto moduleDecl = importDecl->importedModuleDecl.Ptr();
- // TODO: do we need to modify the code generation environment at
- // all when doing this recursive emit?
- //
- // TODO: what if we import the same module along two different
- // paths? Probably need logic to avoid emitting the same
- // module more than once.
+ // We might import the same module along two different paths,
+ // so we need to be careful to only emit each module once
+ // per output.
+ if(!context->modulesAlreadyEmitted.Contains(moduleDecl))
+ {
+ // Add the module to our set before emitting it, just
+ // in case a circular reference would lead us to
+ // infinite recursion (but that shouldn't be allowed
+ // in the first place).
+ context->modulesAlreadyEmitted.Add(moduleDecl);
- EmitDeclsInContainer(context, moduleDecl);
+ // TODO: do we need to modify the code generation environment at
+ // all when doing this recursive emit?
+
+ EmitDeclsInContainer(context, moduleDecl);
+ }
return;
}
diff --git a/source/slang/parser.cpp b/source/slang/parser.cpp
index 5e06aa877..48954dc04 100644
--- a/source/slang/parser.cpp
+++ b/source/slang/parser.cpp
@@ -488,6 +488,9 @@ namespace Slang
RefPtr<TypeDefDecl> ParseTypeDef(Parser* parser)
{
+ RefPtr<TypeDefDecl> typeDefDecl = new TypeDefDecl();
+ typeDefDecl->Position = parser->tokenReader.PeekLoc();
+
// Consume the `typedef` keyword
parser->ReadToken("typedef");
@@ -496,7 +499,6 @@ namespace Slang
auto nameToken = parser->ReadToken(TokenType::Identifier);
- RefPtr<TypeDefDecl> typeDefDecl = new TypeDefDecl();
typeDefDecl->Name = nameToken;
typeDefDecl->Type = type;