summaryrefslogtreecommitdiffstats
path: root/source
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2018-01-19 18:20:23 -0500
committerYong He <yonghe@outlook.com>2018-01-19 22:21:29 -0500
commit9d515dd257498cba9144dd31f2f3219e997e03d0 (patch)
tree131571608747f80354236ba62ca946c7fc703db7 /source
parent2079b941bc5849b6ab33774fb90cefe9c2d624cb (diff)
Allow arbitrary type string as type argument in spAddEntryPointEx.
Diffstat (limited to 'source')
-rw-r--r--source/slang/check.cpp35
-rw-r--r--source/slang/compiler.h4
-rw-r--r--source/slang/decl-defs.h4
-rw-r--r--source/slang/parser.cpp13
-rw-r--r--source/slang/parser.h5
-rw-r--r--source/slang/slang.cpp17
6 files changed, 58 insertions, 20 deletions
diff --git a/source/slang/check.cpp b/source/slang/check.cpp
index dfc09c485..7cfb317fb 100644
--- a/source/slang/check.cpp
+++ b/source/slang/check.cpp
@@ -6945,25 +6945,26 @@ namespace Slang
// Lookup generic parameter types in global scope
for (auto name : entryPoint->genericParameterTypeNames)
- {
- firstDeclWithName = entryPoint->compileRequest->lookupGlobalDecl(name);
- if (!firstDeclWithName)
- {
- // If there doesn't appear to be any such declaration, then
- // we need to diagnose it as an error, and then bail out.
- sink->diagnose(translationUnitSyntax, Diagnostics::entryPointTypeParameterNotFound, name);
- return;
- }
+ {
+ // parse type name
RefPtr<Type> type;
- if (auto aggType = firstDeclWithName->As<AggTypeDecl>())
- {
- type = DeclRefType::Create(entryPoint->compileRequest->mSession, DeclRef<Decl>(aggType, nullptr));
- }
- else if (auto typeDefDecl = firstDeclWithName->As<TypeDefDecl>())
- {
- type = GetType(DeclRef<TypeDefDecl>(typeDefDecl, nullptr));
+ for (auto & module : entryPoint->compileRequest->loadedModulesList)
+ {
+ RefPtr<Expr> typeExpr = entryPoint->compileRequest->parseTypeString(entryPoint->getTranslationUnit(),
+ name, module->moduleDecl->scope);
+ DiagnosticSink nSink;
+ SemanticsVisitor visitor(
+ &nSink,
+ translationUnit->compileRequest,
+ translationUnit);
+ auto typeOut = visitor.CheckProperType(TypeExp(typeExpr));
+ if (!nSink.errorCount)
+ {
+ type = typeOut.type;
+ break;
+ }
}
- else
+ if (!type)
{
sink->diagnose(firstDeclWithName, Diagnostics::entryPointTypeSymbolNotAType, name);
return;
diff --git a/source/slang/compiler.h b/source/slang/compiler.h
index 1fca4751c..4854f4060 100644
--- a/source/slang/compiler.h
+++ b/source/slang/compiler.h
@@ -104,7 +104,7 @@ namespace Slang
// The type names we want to substitute into the
// global generic type parameters
- List<Name*> genericParameterTypeNames;
+ List<String> genericParameterTypeNames;
// The profile that the entry point will be compiled for
// (this is a combination of the target state, and also
@@ -318,6 +318,8 @@ namespace Slang
~CompileRequest();
+ RefPtr<Expr> parseTypeString(TranslationUnitRequest * translationUnit, String typeStr, RefPtr<Scope> scope);
+
void parseTranslationUnit(
TranslationUnitRequest* translationUnit);
diff --git a/source/slang/decl-defs.h b/source/slang/decl-defs.h
index fb35e327a..8e1985e3f 100644
--- a/source/slang/decl-defs.h
+++ b/source/slang/decl-defs.h
@@ -196,7 +196,9 @@ SIMPLE_SYNTAX_CLASS(Variable, VarDeclBase);
// A "module" of code (essentiately, a single translation unit)
// that provides a scope for some number of declarations.
-SIMPLE_SYNTAX_CLASS(ModuleDecl, ContainerDecl)
+SYNTAX_CLASS(ModuleDecl, ContainerDecl)
+ FIELD(RefPtr<Scope>, scope)
+END_SYNTAX_CLASS()
SYNTAX_CLASS(ImportDecl, Decl)
// The name of the module we are trying to import
diff --git a/source/slang/parser.cpp b/source/slang/parser.cpp
index 7e36b0e71..531606f8d 100644
--- a/source/slang/parser.cpp
+++ b/source/slang/parser.cpp
@@ -2704,6 +2704,7 @@ namespace Slang
PushScope(program);
program->loc = tokenReader.PeekLoc();
+ program->scope = currentScope;
ParseDeclBody(this, program, TokenType::EndOfFile);
PopScope();
@@ -3960,6 +3961,17 @@ namespace Slang
return parsePrefixExpr(this);
}
+ RefPtr<Expr> parseTypeFromSourceFile(TranslationUnitRequest* translationUnit,
+ TokenSpan const& tokens,
+ DiagnosticSink* sink,
+ RefPtr<Scope> const& outerScope)
+ {
+ Parser parser(tokens, sink, outerScope);
+ parser.translationUnit = translationUnit;
+ parser.currentScope = outerScope;
+ return parser.ParseType();
+ }
+
// Parse a source file into an existing translation unit
void parseSourceFile(
TranslationUnitRequest* translationUnit,
@@ -3971,6 +3983,7 @@ namespace Slang
parser.translationUnit = translationUnit;
+
return parser.parseSourceFile(translationUnit->SyntaxNode.Ptr());
}
diff --git a/source/slang/parser.h b/source/slang/parser.h
index 60fe4b3ae..785b6e345 100644
--- a/source/slang/parser.h
+++ b/source/slang/parser.h
@@ -14,6 +14,11 @@ namespace Slang
DiagnosticSink* sink,
RefPtr<Scope> const& outerScope);
+ RefPtr<Expr> parseTypeFromSourceFile(TranslationUnitRequest* translationUnit,
+ TokenSpan const& tokens,
+ DiagnosticSink* sink,
+ RefPtr<Scope> const& outerScope);
+
RefPtr<ModuleDecl> populateBaseLanguageModule(
Session* session,
RefPtr<Scope> scope);
diff --git a/source/slang/slang.cpp b/source/slang/slang.cpp
index 2ebf024e3..d907e7614 100644
--- a/source/slang/slang.cpp
+++ b/source/slang/slang.cpp
@@ -125,6 +125,21 @@ CompileRequest::CompileRequest(Session* session)
CompileRequest::~CompileRequest()
{}
+
+RefPtr<Expr> CompileRequest::parseTypeString(TranslationUnitRequest * translationUnit, String typeStr, RefPtr<Scope> scope)
+{
+ Slang::SourceFile srcFile;
+ srcFile.content = typeStr;
+ DiagnosticSink sink;
+ auto tokens = preprocessSource(
+ &srcFile,
+ &sink,
+ nullptr,
+ Dictionary<String,String>(),
+ translationUnit);
+ return parseTypeFromSourceFile(translationUnit, tokens, &sink, scope);
+}
+
void CompileRequest::parseTranslationUnit(
TranslationUnitRequest* translationUnit)
{
@@ -429,7 +444,7 @@ int CompileRequest::addEntryPoint(
entryPoint->profile = entryPointProfile;
entryPoint->translationUnitIndex = translationUnitIndex;
for (auto typeName : genericTypeNames)
- entryPoint->genericParameterTypeNames.Add(getNamePool()->getName(typeName));
+ entryPoint->genericParameterTypeNames.Add(typeName);
auto translationUnit = translationUnits[translationUnitIndex].Ptr();
translationUnit->entryPoints.Add(entryPoint);