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/slang.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/slang.cpp')
| -rw-r--r-- | source/slang/slang.cpp | 46 |
1 files changed, 45 insertions, 1 deletions
diff --git a/source/slang/slang.cpp b/source/slang/slang.cpp index 2ebf024e3..4c9ecf8a8 100644 --- a/source/slang/slang.cpp +++ b/source/slang/slang.cpp @@ -125,6 +125,50 @@ 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; + sink.sourceManager = sourceManager; + auto tokens = preprocessSource( + &srcFile, + &sink, + nullptr, + Dictionary<String,String>(), + translationUnit); + return parseTypeFromSourceFile(translationUnit, tokens, &sink, scope); +} + +RefPtr<Type> checkProperType(TranslationUnitRequest * tu, TypeExp typeExp); +Type* CompileRequest::getTypeFromString(String typeStr) +{ + RefPtr<Type> type; + if (types.TryGetValue(typeStr, type)) + return type; + auto translationUnit = translationUnits.First(); + List<RefPtr<Scope>> scopesToTry; + for (auto tu : translationUnits) + scopesToTry.Add(tu->SyntaxNode->scope); + for (auto & module : loadedModulesList) + scopesToTry.Add(module->moduleDecl->scope); + // parse type name + for (auto & s : scopesToTry) + { + RefPtr<Expr> typeExpr = parseTypeString(translationUnit, + typeStr, s); + type = checkProperType(translationUnit, TypeExp(typeExpr)); + if (type) + break; + } + if (type) + { + types[typeStr] = type; + } + return type.Ptr(); +} + void CompileRequest::parseTranslationUnit( TranslationUnitRequest* translationUnit) { @@ -429,7 +473,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); |
