diff options
Diffstat (limited to 'source/slang/slang.cpp')
| -rw-r--r-- | source/slang/slang.cpp | 35 |
1 files changed, 30 insertions, 5 deletions
diff --git a/source/slang/slang.cpp b/source/slang/slang.cpp index 065b9de93..912cd2e10 100644 --- a/source/slang/slang.cpp +++ b/source/slang/slang.cpp @@ -2540,6 +2540,16 @@ void TranslationUnitRequest::addSource(IArtifact* sourceArtifact, SourceFile* so _addSourceFile(sourceFile); } +void TranslationUnitRequest::addIncludedSourceFileIfNotExist(SourceFile* sourceFile) +{ + if (m_includedFileSet.contains(sourceFile)) + return; + + sourceFile->setIncludedFile(); + m_sourceFiles.add(sourceFile); + m_includedFileSet.add(sourceFile); +} + PathInfo TranslationUnitRequest::_findSourcePathInfo(IArtifact* artifact) { auto pathRep = findRepresentation<IPathArtifactRepresentation>(artifact); @@ -2652,7 +2662,6 @@ void TranslationUnitRequest::_addSourceFile(SourceFile* sourceFile) List<SourceFile*> const& TranslationUnitRequest::getSourceFiles() { - SLANG_ASSERT(m_sourceArtifacts.getCount() == m_sourceFiles.getCount()); return m_sourceFiles; } @@ -3072,8 +3081,15 @@ FrontEndCompileRequest::FrontEndCompileRequest( struct FrontEndPreprocessorHandler : PreprocessorHandler { public: - FrontEndPreprocessorHandler(Module* module, ASTBuilder* astBuilder, DiagnosticSink* sink) - : m_module(module), m_astBuilder(astBuilder), m_sink(sink) + FrontEndPreprocessorHandler( + Module* module, + ASTBuilder* astBuilder, + DiagnosticSink* sink, + TranslationUnitRequest* translationUnit) + : m_module(module) + , m_astBuilder(astBuilder) + , m_sink(sink) + , m_translationUnit(translationUnit) { } @@ -3081,6 +3097,7 @@ protected: Module* m_module; ASTBuilder* m_astBuilder; DiagnosticSink* m_sink; + TranslationUnitRequest* m_translationUnit = nullptr; // The first task that this handler tries to deal with is // capturing all the files on which a module is dependent. @@ -3092,6 +3109,7 @@ protected: void handleFileDependency(SourceFile* sourceFile) SLANG_OVERRIDE { m_module->addFileDependency(sourceFile); + m_translationUnit->addIncludedSourceFileIfNotExist(sourceFile); } // The second task that this handler deals with is detecting @@ -3358,6 +3376,9 @@ static void _outputIncludes( // For all the source files for (SourceFile* sourceFile : sourceFiles) { + if (sourceFile->isIncludedFile()) + continue; + // Find an initial view (this is the view of this file, that doesn't have an initiating loc) SourceView* sourceView = _findInitialSourceView(sourceFile); if (!sourceView) @@ -3429,7 +3450,7 @@ void FrontEndCompileRequest::parseTranslationUnit(TranslationUnitRequest* transl // preprocessoing can be communicated to later phases of // compilation. // - FrontEndPreprocessorHandler preprocessorHandler(module, astBuilder, getSink()); + FrontEndPreprocessorHandler preprocessorHandler(module, astBuilder, getSink(), translationUnit); for (auto sourceFile : translationUnit->getSourceFiles()) { @@ -4950,7 +4971,11 @@ Linkage::IncludeResult Linkage::findAndIncludeFile( fileDecl->parentDecl = module->getModuleDecl(); module->getIncludedSourceFileMap().add(sourceFile, fileDecl); - FrontEndPreprocessorHandler preprocessorHandler(module, module->getASTBuilder(), sink); + FrontEndPreprocessorHandler preprocessorHandler( + module, + module->getASTBuilder(), + sink, + translationUnit); auto combinedPreprocessorDefinitions = translationUnit->getCombinedPreprocessorDefinitions(); SourceLanguage sourceLanguage = translationUnit->sourceLanguage; SlangLanguageVersion slangLanguageVersion = module->getModuleDecl()->languageVersion; |
