From ce879112cb16e3def1b8673104e7123b8b17ee2a Mon Sep 17 00:00:00 2001 From: Yong He Date: Sun, 21 Jan 2018 07:09:55 -0500 Subject: Improvements and bug fixes for global type parameters 1. allow spReflection_FindTypeByName to accept arbitrary type expression string 2. allow const int generic value to be used as expression value, and as array size 3. various bug fixes in witness table specialization / function cloning during specializeIRForEntryPoint to avoid creating duplicate global values, not copying the right definition of a function from the other module, not cloning witness tables that are required by specializeGenerics etc. --- source/slang/slang.cpp | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'source/slang/slang.cpp') diff --git a/source/slang/slang.cpp b/source/slang/slang.cpp index d907e7614..4c9ecf8a8 100644 --- a/source/slang/slang.cpp +++ b/source/slang/slang.cpp @@ -131,6 +131,7 @@ RefPtr CompileRequest::parseTypeString(TranslationUnitRequest * translatio Slang::SourceFile srcFile; srcFile.content = typeStr; DiagnosticSink sink; + sink.sourceManager = sourceManager; auto tokens = preprocessSource( &srcFile, &sink, @@ -140,6 +141,34 @@ RefPtr CompileRequest::parseTypeString(TranslationUnitRequest * translatio return parseTypeFromSourceFile(translationUnit, tokens, &sink, scope); } +RefPtr checkProperType(TranslationUnitRequest * tu, TypeExp typeExp); +Type* CompileRequest::getTypeFromString(String typeStr) +{ + RefPtr type; + if (types.TryGetValue(typeStr, type)) + return type; + auto translationUnit = translationUnits.First(); + List> 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 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) { -- cgit v1.2.3