diff options
| -rw-r--r-- | source/compiler-core/slang-source-loc.h | 9 | ||||
| -rw-r--r-- | source/slang/slang-compiler.h | 6 | ||||
| -rw-r--r-- | source/slang/slang.cpp | 35 |
3 files changed, 45 insertions, 5 deletions
diff --git a/source/compiler-core/slang-source-loc.h b/source/compiler-core/slang-source-loc.h index 674ed2076..b52f2e50d 100644 --- a/source/compiler-core/slang-source-loc.h +++ b/source/compiler-core/slang-source-loc.h @@ -331,6 +331,12 @@ public: m_sourceMapKind = sourceMapKind; } + /// Set the source file as an included file + void setIncludedFile() { m_included = true; } + + /// Check if the source file is an included file + bool isIncludedFile() { return m_included; } + /// Ctor SourceFile(SourceManager* sourceManager, const PathInfo& pathInfo, size_t contentSize); /// Dtor @@ -360,6 +366,9 @@ protected: ComPtr<IBoxValue<SourceMap>> m_sourceMap; // What kind of source map it is (if there is one) SourceMapKind m_sourceMapKind = SourceMapKind::Normal; + + // Indicate if the source file is an included file + bool m_included = false; }; enum class SourceLocType diff --git a/source/slang/slang-compiler.h b/source/slang/slang-compiler.h index 8f7f7d49a..861719aac 100644 --- a/source/slang/slang-compiler.h +++ b/source/slang/slang-compiler.h @@ -1880,6 +1880,7 @@ public: { m_sourceArtifacts.clear(); m_sourceFiles.clear(); + m_includedFileSet.clear(); } /// Add a source artifact @@ -1888,6 +1889,8 @@ public: /// Add both the artifact and the sourceFile. void addSource(IArtifact* sourceArtifact, SourceFile* sourceFile); + void addIncludedSourceFileIfNotExist(SourceFile* sourceFile); + // The entry points associated with this translation unit List<RefPtr<EntryPoint>> const& getEntryPoints() { return module->getEntryPoints(); } @@ -1936,6 +1939,9 @@ protected: // NOTE! This member is generated lazily from m_sourceArtifacts // it is *necessary* to call requireSourceFiles to ensure it's in sync. List<SourceFile*> m_sourceFiles; + + // Track all the included source files added in m_sourceFiles + HashSet<SourceFile*> m_includedFileSet; }; enum class FloatingPointMode : SlangFloatingPointModeIntegral 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; |
