summaryrefslogtreecommitdiff
path: root/include/clang/CrossTU
diff options
context:
space:
mode:
authorBalazs Keri <1.int32@gmail.com>2019-07-18 15:23:10 +0000
committerBalazs Keri <1.int32@gmail.com>2019-07-18 15:23:10 +0000
commit449753109dfd0a96900ef409618fee4333dd81c1 (patch)
treefa64b616f64224064315d713716b84ec53928b9d /include/clang/CrossTU
parent217af05bd106347304676e169f97d8b6a1ebc3ca (diff)
downloadclang-449753109dfd0a96900ef409618fee4333dd81c1.tar.gz
[CrossTU] Add a function to retrieve original source location.
Summary: A new function will be added to get the original SourceLocation for a SourceLocation that was imported as result of getCrossTUDefinition. The returned SourceLocation is in the context of the (original) SourceManager for the original source file. Additionally the ASTUnit object for that source file is returned. This is needed to get a SourceManager to operate on with the returned source location. The new function works if multiple different source files are loaded with the same CrossTU context. This patch can be treated as part of a bigger change that is needed to improve macro expansion handliong at plist generation. Reviewers: martong, shafik, a_sidorin, xazax.hun Reviewed By: martong Subscribers: rnkovacs, dkrupp, Szelethus, gamesh411, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D64554 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@366449 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/clang/CrossTU')
-rw-r--r--include/clang/CrossTU/CrossTranslationUnit.h20
1 files changed, 16 insertions, 4 deletions
diff --git a/include/clang/CrossTU/CrossTranslationUnit.h b/include/clang/CrossTU/CrossTranslationUnit.h
index d64329cdff..7b689bdf33 100644
--- a/include/clang/CrossTU/CrossTranslationUnit.h
+++ b/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,19 @@ 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.
+ /// 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:
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 +186,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;