diff options
Diffstat (limited to 'clang/include')
-rw-r--r-- | clang/include/clang/AST/ASTImporter.h | 12 | ||||
-rw-r--r-- | clang/include/clang/CrossTU/CrossTranslationUnit.h | 33 |
2 files changed, 41 insertions, 4 deletions
diff --git a/clang/include/clang/AST/ASTImporter.h b/clang/include/clang/AST/ASTImporter.h index 4a55c120a45..12bd5623ec0 100644 --- a/clang/include/clang/AST/ASTImporter.h +++ b/clang/include/clang/AST/ASTImporter.h @@ -87,6 +87,8 @@ class TypeSourceInfo; using NonEquivalentDeclSet = llvm::DenseSet<std::pair<Decl *, Decl *>>; using ImportedCXXBaseSpecifierMap = llvm::DenseMap<const CXXBaseSpecifier *, CXXBaseSpecifier *>; + using FileIDImportHandlerType = + std::function<void(FileID /*ToID*/, FileID /*FromID*/)>; // An ImportPath is the list of the AST nodes which we visit during an // Import call. @@ -210,6 +212,8 @@ class TypeSourceInfo; }; private: + FileIDImportHandlerType FileIDImportHandler; + std::shared_ptr<ASTImporterSharedState> SharedState = nullptr; /// The path which we go through during the import of a given AST node. @@ -310,6 +314,14 @@ class TypeSourceInfo; virtual ~ASTImporter(); + /// Set a callback function for FileID import handling. + /// The function is invoked when a FileID is imported from the From context. + /// The imported FileID in the To context and the original FileID in the + /// From context is passed to it. + void setFileIDImportHandler(FileIDImportHandlerType H) { + FileIDImportHandler = H; + } + /// Whether the importer will perform a minimal import, creating /// to-be-completed forward declarations when possible. bool isMinimalImport() const { return Minimal; } diff --git a/clang/include/clang/CrossTU/CrossTranslationUnit.h b/clang/include/clang/CrossTU/CrossTranslationUnit.h index d64329cdff3..3e3d2ba70b3 100644 --- a/clang/include/clang/CrossTU/CrossTranslationUnit.h +++ b/clang/include/clang/CrossTU/CrossTranslationUnit.h @@ -153,8 +153,10 @@ public: /// was passed to the constructor. /// /// \return Returns the resulting definition or an error. - llvm::Expected<const FunctionDecl *> importDefinition(const FunctionDecl *FD); - llvm::Expected<const VarDecl *> importDefinition(const VarDecl *VD); + llvm::Expected<const FunctionDecl *> importDefinition(const FunctionDecl *FD, + ASTUnit *Unit); + llvm::Expected<const VarDecl *> importDefinition(const VarDecl *VD, + ASTUnit *Unit); /// Get a name to identify a named decl. static std::string getLookupName(const NamedDecl *ND); @@ -162,9 +164,23 @@ public: /// Emit diagnostics for the user for potential configuration errors. void emitCrossTUDiagnostics(const IndexError &IE); + /// Determine the original source location in the original TU for an + /// imported source location. + /// \p ToLoc Source location in the imported-to AST. + /// \return Source location in the imported-from AST and the corresponding + /// ASTUnit object (the AST was loaded from a file using an internal ASTUnit + /// object that is returned here). + /// If any error happens (ToLoc is a non-imported source location) empty is + /// returned. + llvm::Optional<std::pair<SourceLocation /*FromLoc*/, ASTUnit *>> + getImportedFromSourceLocation(const clang::SourceLocation &ToLoc) const; + private: + using ImportedFileIDMap = + llvm::DenseMap<FileID, std::pair<FileID, ASTUnit *>>; + void lazyInitImporterSharedSt(TranslationUnitDecl *ToTU); - ASTImporter &getOrCreateASTImporter(ASTContext &From); + ASTImporter &getOrCreateASTImporter(ASTUnit *Unit); template <typename T> llvm::Expected<const T *> getCrossTUDefinitionImpl(const T *D, StringRef CrossTUDir, @@ -174,7 +190,7 @@ private: const T *findDefInDeclContext(const DeclContext *DC, StringRef LookupName); template <typename T> - llvm::Expected<const T *> importDefinitionImpl(const T *D); + llvm::Expected<const T *> importDefinitionImpl(const T *D, ASTUnit *Unit); llvm::StringMap<std::unique_ptr<clang::ASTUnit>> FileASTUnitMap; llvm::StringMap<clang::ASTUnit *> NameASTUnitMap; @@ -184,6 +200,15 @@ private: CompilerInstance &CI; ASTContext &Context; std::shared_ptr<ASTImporterSharedState> ImporterSharedSt; + /// Map of imported FileID's (in "To" context) to FileID in "From" context + /// and the ASTUnit for the From context. + /// This map is used by getImportedFromSourceLocation to lookup a FileID and + /// its Preprocessor when knowing only the FileID in the 'To' context. The + /// FileID could be imported by any of multiple 'From' ASTImporter objects. + /// we do not want to loop over all ASTImporter's to find the one that + /// imported the FileID. + ImportedFileIDMap ImportedFileIDs; + /// \p CTULoadTreshold should serve as an upper limit to the number of TUs /// imported in order to reduce the memory footprint of CTU analysis. const unsigned CTULoadThreshold; |