diff options
| author | Yong He <yonghe@outlook.com> | 2024-02-06 01:03:42 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-02-06 01:03:42 -0800 |
| commit | b301c93753eaddb4571999f209cb8c1faa2fe205 (patch) | |
| tree | 72fef2e499abecad0dda5ba2347e5890346ac173 /source/slang/slang.cpp | |
| parent | 23c65b873f8002b74d60f61cacb3614da60e078d (diff) | |
Unify GLSL and HLSL buffer block parsing. (#3552)
* Unify GLSL and HLSL buffer block parsing.
Automatic GLSL module recognition.
* Fix.
Diffstat (limited to 'source/slang/slang.cpp')
| -rw-r--r-- | source/slang/slang.cpp | 48 |
1 files changed, 33 insertions, 15 deletions
diff --git a/source/slang/slang.cpp b/source/slang/slang.cpp index e99f94484..267d91173 100644 --- a/source/slang/slang.cpp +++ b/source/slang/slang.cpp @@ -1984,17 +1984,23 @@ Expr* Linkage::parseTermString(String typeStr, Scope* scope) // We need to temporarily replace the SourceManager for this CompileRequest ScopeReplaceSourceManager scopeReplaceSourceManager(this, &localSourceManager); + + SourceLanguage sourceLanguage; auto tokens = preprocessSource( srcFile, &sink, nullptr, Dictionary<String,String>(), - this); + this, + sourceLanguage); + + if (sourceLanguage == SourceLanguage::Unknown) + sourceLanguage = SourceLanguage::Slang; return parseTermFromSourceFile( getASTBuilder(), - tokens, &sink, scope, getNamePool(), SourceLanguage::Slang); + tokens, &sink, scope, getNamePool(), sourceLanguage); } Type* checkProperType( @@ -2349,19 +2355,6 @@ void FrontEndCompileRequest::parseTranslationUnit( // would be checked too (after those on the FrontEndCompileRequest). IncludeSystem includeSystem(&linkage->searchDirectories, linkage->getFileSystemExt(), linkage->getSourceManager()); - Scope* languageScope = nullptr; - switch (translationUnit->sourceLanguage) - { - case SourceLanguage::HLSL: - languageScope = getSession()->hlslLanguageScope; - break; - - case SourceLanguage::Slang: - default: - languageScope = getSession()->slangLanguageScope; - break; - } - auto combinedPreprocessorDefinitions = translationUnit->getCombinedPreprocessorDefinitions(); auto module = translationUnit->getModule(); @@ -2406,14 +2399,32 @@ void FrontEndCompileRequest::parseTranslationUnit( for (auto sourceFile : translationUnit->getSourceFiles()) { + SourceLanguage sourceLanguage = SourceLanguage::Unknown; auto tokens = preprocessSource( sourceFile, getSink(), &includeSystem, combinedPreprocessorDefinitions, getLinkage(), + sourceLanguage, &preprocessorHandler); + if (sourceLanguage == SourceLanguage::Unknown) + sourceLanguage = translationUnit->sourceLanguage; + + Scope* languageScope = nullptr; + switch (sourceLanguage) + { + case SourceLanguage::HLSL: + languageScope = getSession()->hlslLanguageScope; + break; + + case SourceLanguage::Slang: + default: + languageScope = getSession()->slangLanguageScope; + break; + } + if (outputIncludes) { _outputIncludes(translationUnit->getSourceFiles(), getSink()->getSourceManager(), getSink()); @@ -2432,6 +2443,7 @@ void FrontEndCompileRequest::parseTranslationUnit( parseSourceFile( astBuilder, translationUnit, + sourceLanguage, tokens, getSink(), languageScope, @@ -3420,18 +3432,24 @@ Linkage::IncludeResult Linkage::findAndIncludeFile(Module* module, TranslationUn FrontEndPreprocessorHandler preprocessorHandler(module, module->getASTBuilder(), sink); auto combinedPreprocessorDefinitions = translationUnit->getCombinedPreprocessorDefinitions(); + SourceLanguage sourceLanguage = SourceLanguage::Unknown; auto tokens = preprocessSource( sourceFile, sink, &includeSystem, combinedPreprocessorDefinitions, this, + sourceLanguage, &preprocessorHandler); + + if (sourceLanguage == SourceLanguage::Unknown) + sourceLanguage = translationUnit->sourceLanguage; auto outerScope = module->getModuleDecl()->ownedScope; parseSourceFile( module->getASTBuilder(), translationUnit, + sourceLanguage, tokens, sink, outerScope, |
