diff options
| author | Yong He <yonghe@outlook.com> | 2018-01-21 10:48:31 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-01-21 10:48:31 -0800 |
| commit | 4044a1d3a0605198465a7eb6e0e3c1f8b1a3c298 (patch) | |
| tree | 62927d4d2722b36c8e7eb4060e741b9032686835 /source/slang/check.cpp | |
| parent | 2079b941bc5849b6ab33774fb90cefe9c2d624cb (diff) | |
| parent | f681a1505c98995683a7fbae7ce208dc5e444b9b (diff) | |
Merge pull request #372 from csyonghe/master
Allow type expression as type argument, fix global param enum order
Diffstat (limited to 'source/slang/check.cpp')
| -rw-r--r-- | source/slang/check.cpp | 48 |
1 files changed, 32 insertions, 16 deletions
diff --git a/source/slang/check.cpp b/source/slang/check.cpp index dfc09c485..52558ee15 100644 --- a/source/slang/check.cpp +++ b/source/slang/check.cpp @@ -6849,6 +6849,23 @@ namespace Slang return (!decl->primaryDecl) || (decl == decl->primaryDecl); } + RefPtr<Type> checkProperType(TranslationUnitRequest * tu, TypeExp typeExp) + { + RefPtr<Type> type; + DiagnosticSink nSink; + nSink.sourceManager = tu->compileRequest->sourceManager; + SemanticsVisitor visitor( + &nSink, + tu->compileRequest, + tu); + auto typeOut = visitor.CheckProperType(typeExp); + if (!nSink.errorCount) + { + type = typeOut.type; + } + return type; + } + void validateEntryPoint( EntryPointRequest* entryPoint) { @@ -6944,26 +6961,25 @@ namespace Slang entryPoint->decl = entryPointFuncDecl; // Lookup generic parameter types in global scope + List<RefPtr<Scope>> scopesToTry; + scopesToTry.Add(entryPoint->getTranslationUnit()->SyntaxNode->scope); + for (auto & module : entryPoint->compileRequest->loadedModulesList) + scopesToTry.Add(module->moduleDecl->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>()) + for (auto & s : scopesToTry) { - type = GetType(DeclRef<TypeDefDecl>(typeDefDecl, nullptr)); + RefPtr<Expr> typeExpr = entryPoint->compileRequest->parseTypeString(entryPoint->getTranslationUnit(), + name, s); + type = checkProperType(translationUnit, TypeExp(typeExpr)); + if (type) + { + break; + } } - else + if (!type) { sink->diagnose(firstDeclWithName, Diagnostics::entryPointTypeSymbolNotAType, name); return; |
