Revert r366449: [CrossTU] Add a function to retrieve original source location.
Reason: the commit breaks layering by adding a dependency on ASTUnit (which is inside clangFrontend) from the ASTImporter (which is inside clangAST). llvm-svn: 366453
This commit is contained in:
parent
6acdf83cfa
commit
abc744d263
|
@ -34,7 +34,6 @@ namespace clang {
|
||||||
|
|
||||||
class ASTContext;
|
class ASTContext;
|
||||||
class ASTImporterSharedState;
|
class ASTImporterSharedState;
|
||||||
class ASTUnit;
|
|
||||||
class Attr;
|
class Attr;
|
||||||
class CXXBaseSpecifier;
|
class CXXBaseSpecifier;
|
||||||
class CXXCtorInitializer;
|
class CXXCtorInitializer;
|
||||||
|
@ -230,11 +229,6 @@ class TypeSourceInfo;
|
||||||
/// The file managers we're importing to and from.
|
/// The file managers we're importing to and from.
|
||||||
FileManager &ToFileManager, &FromFileManager;
|
FileManager &ToFileManager, &FromFileManager;
|
||||||
|
|
||||||
/// The ASTUnit for the From context, if any.
|
|
||||||
/// This is used to create a mapping of imported ('To') FileID's to the
|
|
||||||
/// original ('From') FileID and ASTUnit.
|
|
||||||
ASTUnit *FromUnit;
|
|
||||||
|
|
||||||
/// Whether to perform a minimal import.
|
/// Whether to perform a minimal import.
|
||||||
bool Minimal;
|
bool Minimal;
|
||||||
|
|
||||||
|
@ -283,11 +277,6 @@ class TypeSourceInfo;
|
||||||
|
|
||||||
void AddToLookupTable(Decl *ToD);
|
void AddToLookupTable(Decl *ToD);
|
||||||
|
|
||||||
ASTImporter(ASTContext &ToContext, FileManager &ToFileManager,
|
|
||||||
ASTContext &FromContext, FileManager &FromFileManager,
|
|
||||||
ASTUnit *FromUnit, bool MinimalImport,
|
|
||||||
std::shared_ptr<ASTImporterSharedState> SharedState);
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
/// Can be overwritten by subclasses to implement their own import logic.
|
/// Can be overwritten by subclasses to implement their own import logic.
|
||||||
/// The overwritten method should call this method if it didn't import the
|
/// The overwritten method should call this method if it didn't import the
|
||||||
|
@ -298,6 +287,7 @@ class TypeSourceInfo;
|
||||||
virtual bool returnWithErrorInTest() { return false; };
|
virtual bool returnWithErrorInTest() { return false; };
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
/// \param ToContext The context we'll be importing into.
|
/// \param ToContext The context we'll be importing into.
|
||||||
///
|
///
|
||||||
/// \param ToFileManager The file manager we'll be importing into.
|
/// \param ToFileManager The file manager we'll be importing into.
|
||||||
|
@ -317,23 +307,6 @@ class TypeSourceInfo;
|
||||||
ASTContext &FromContext, FileManager &FromFileManager,
|
ASTContext &FromContext, FileManager &FromFileManager,
|
||||||
bool MinimalImport,
|
bool MinimalImport,
|
||||||
std::shared_ptr<ASTImporterSharedState> SharedState = nullptr);
|
std::shared_ptr<ASTImporterSharedState> SharedState = nullptr);
|
||||||
/// \param ToContext The context we'll be importing into.
|
|
||||||
///
|
|
||||||
/// \param ToFileManager The file manager we'll be importing into.
|
|
||||||
///
|
|
||||||
/// \param FromUnit Pointer to an ASTUnit that contains the context and
|
|
||||||
/// file manager to import from.
|
|
||||||
///
|
|
||||||
/// \param MinimalImport If true, the importer will attempt to import
|
|
||||||
/// as little as it can, e.g., by importing declarations as forward
|
|
||||||
/// declarations that can be completed at a later point.
|
|
||||||
///
|
|
||||||
/// \param SharedState The importer specific lookup table which may be
|
|
||||||
/// shared amongst several ASTImporter objects.
|
|
||||||
/// If not set then the original C/C++ lookup is used.
|
|
||||||
ASTImporter(ASTContext &ToContext, FileManager &ToFileManager,
|
|
||||||
ASTUnit &FromUnit, bool MinimalImport,
|
|
||||||
std::shared_ptr<ASTImporterSharedState> SharedState = nullptr);
|
|
||||||
|
|
||||||
virtual ~ASTImporter();
|
virtual ~ASTImporter();
|
||||||
|
|
||||||
|
|
|
@ -17,24 +17,18 @@
|
||||||
|
|
||||||
#include "clang/AST/ASTImporterLookupTable.h"
|
#include "clang/AST/ASTImporterLookupTable.h"
|
||||||
#include "clang/AST/Decl.h"
|
#include "clang/AST/Decl.h"
|
||||||
#include "clang/Basic/SourceLocation.h"
|
|
||||||
#include "llvm/ADT/DenseMap.h"
|
#include "llvm/ADT/DenseMap.h"
|
||||||
// FIXME We need this because of ImportError.
|
// FIXME We need this because of ImportError.
|
||||||
#include "clang/AST/ASTImporter.h"
|
#include "clang/AST/ASTImporter.h"
|
||||||
|
|
||||||
namespace clang {
|
namespace clang {
|
||||||
|
|
||||||
class ASTUnit;
|
|
||||||
class TranslationUnitDecl;
|
class TranslationUnitDecl;
|
||||||
|
|
||||||
/// Importer specific state, which may be shared amongst several ASTImporter
|
/// Importer specific state, which may be shared amongst several ASTImporter
|
||||||
/// objects.
|
/// objects.
|
||||||
class ASTImporterSharedState {
|
class ASTImporterSharedState {
|
||||||
public:
|
|
||||||
using ImportedFileIDMap =
|
|
||||||
llvm::DenseMap<FileID, std::pair<FileID, ASTUnit *>>;
|
|
||||||
|
|
||||||
private:
|
|
||||||
/// Pointer to the import specific lookup table.
|
/// Pointer to the import specific lookup table.
|
||||||
std::unique_ptr<ASTImporterLookupTable> LookupTable;
|
std::unique_ptr<ASTImporterLookupTable> LookupTable;
|
||||||
|
|
||||||
|
@ -49,16 +43,6 @@ private:
|
||||||
// FIXME put ImportedFromDecls here!
|
// FIXME put ImportedFromDecls here!
|
||||||
// And from that point we can better encapsulate the lookup table.
|
// And from that point we can better encapsulate the lookup table.
|
||||||
|
|
||||||
/// Map of imported FileID's (in "To" context) to FileID in "From" context
|
|
||||||
/// and the ASTUnit that contains the preprocessor and source manager for the
|
|
||||||
/// "From" FileID. This map is used to lookup a FileID and its SourceManager
|
|
||||||
/// when knowing only the FileID in the 'To' context. The FileID could be
|
|
||||||
/// imported by any of multiple ASTImporter objects. The map is used because
|
|
||||||
/// we do not want to loop over all ASTImporter's to find the one that
|
|
||||||
/// imported the FileID. (The ASTUnit is usable to get the SourceManager and
|
|
||||||
/// additional data.)
|
|
||||||
ImportedFileIDMap ImportedFileIDs;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ASTImporterSharedState() = default;
|
ASTImporterSharedState() = default;
|
||||||
|
|
||||||
|
@ -91,12 +75,6 @@ public:
|
||||||
void setImportDeclError(Decl *To, ImportError Error) {
|
void setImportDeclError(Decl *To, ImportError Error) {
|
||||||
ImportErrors[To] = Error;
|
ImportErrors[To] = Error;
|
||||||
}
|
}
|
||||||
|
|
||||||
ImportedFileIDMap &getImportedFileIDs() { return ImportedFileIDs; }
|
|
||||||
|
|
||||||
const ImportedFileIDMap &getImportedFileIDs() const {
|
|
||||||
return ImportedFileIDs;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace clang
|
} // namespace clang
|
||||||
|
|
|
@ -153,10 +153,8 @@ public:
|
||||||
/// was passed to the constructor.
|
/// was passed to the constructor.
|
||||||
///
|
///
|
||||||
/// \return Returns the resulting definition or an error.
|
/// \return Returns the resulting definition or an error.
|
||||||
llvm::Expected<const FunctionDecl *> importDefinition(const FunctionDecl *FD,
|
llvm::Expected<const FunctionDecl *> importDefinition(const FunctionDecl *FD);
|
||||||
ASTUnit *Unit);
|
llvm::Expected<const VarDecl *> importDefinition(const VarDecl *VD);
|
||||||
llvm::Expected<const VarDecl *> importDefinition(const VarDecl *VD,
|
|
||||||
ASTUnit *Unit);
|
|
||||||
|
|
||||||
/// Get a name to identify a named decl.
|
/// Get a name to identify a named decl.
|
||||||
static std::string getLookupName(const NamedDecl *ND);
|
static std::string getLookupName(const NamedDecl *ND);
|
||||||
|
@ -164,19 +162,9 @@ public:
|
||||||
/// Emit diagnostics for the user for potential configuration errors.
|
/// Emit diagnostics for the user for potential configuration errors.
|
||||||
void emitCrossTUDiagnostics(const IndexError &IE);
|
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:
|
private:
|
||||||
void lazyInitImporterSharedSt(TranslationUnitDecl *ToTU);
|
void lazyInitImporterSharedSt(TranslationUnitDecl *ToTU);
|
||||||
ASTImporter &getOrCreateASTImporter(ASTUnit *Unit);
|
ASTImporter &getOrCreateASTImporter(ASTContext &From);
|
||||||
template <typename T>
|
template <typename T>
|
||||||
llvm::Expected<const T *> getCrossTUDefinitionImpl(const T *D,
|
llvm::Expected<const T *> getCrossTUDefinitionImpl(const T *D,
|
||||||
StringRef CrossTUDir,
|
StringRef CrossTUDir,
|
||||||
|
@ -186,7 +174,7 @@ private:
|
||||||
const T *findDefInDeclContext(const DeclContext *DC,
|
const T *findDefInDeclContext(const DeclContext *DC,
|
||||||
StringRef LookupName);
|
StringRef LookupName);
|
||||||
template <typename T>
|
template <typename T>
|
||||||
llvm::Expected<const T *> importDefinitionImpl(const T *D, ASTUnit *Unit);
|
llvm::Expected<const T *> importDefinitionImpl(const T *D);
|
||||||
|
|
||||||
llvm::StringMap<std::unique_ptr<clang::ASTUnit>> FileASTUnitMap;
|
llvm::StringMap<std::unique_ptr<clang::ASTUnit>> FileASTUnitMap;
|
||||||
llvm::StringMap<clang::ASTUnit *> NameASTUnitMap;
|
llvm::StringMap<clang::ASTUnit *> NameASTUnitMap;
|
||||||
|
|
|
@ -12,9 +12,9 @@
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
#include "clang/AST/ASTImporter.h"
|
#include "clang/AST/ASTImporter.h"
|
||||||
|
#include "clang/AST/ASTImporterSharedState.h"
|
||||||
#include "clang/AST/ASTContext.h"
|
#include "clang/AST/ASTContext.h"
|
||||||
#include "clang/AST/ASTDiagnostic.h"
|
#include "clang/AST/ASTDiagnostic.h"
|
||||||
#include "clang/AST/ASTImporterSharedState.h"
|
|
||||||
#include "clang/AST/ASTStructuralEquivalence.h"
|
#include "clang/AST/ASTStructuralEquivalence.h"
|
||||||
#include "clang/AST/Attr.h"
|
#include "clang/AST/Attr.h"
|
||||||
#include "clang/AST/Decl.h"
|
#include "clang/AST/Decl.h"
|
||||||
|
@ -52,14 +52,13 @@
|
||||||
#include "clang/Basic/SourceLocation.h"
|
#include "clang/Basic/SourceLocation.h"
|
||||||
#include "clang/Basic/SourceManager.h"
|
#include "clang/Basic/SourceManager.h"
|
||||||
#include "clang/Basic/Specifiers.h"
|
#include "clang/Basic/Specifiers.h"
|
||||||
#include "clang/Frontend/ASTUnit.h"
|
|
||||||
#include "llvm/ADT/APSInt.h"
|
#include "llvm/ADT/APSInt.h"
|
||||||
#include "llvm/ADT/ArrayRef.h"
|
#include "llvm/ADT/ArrayRef.h"
|
||||||
#include "llvm/ADT/DenseMap.h"
|
#include "llvm/ADT/DenseMap.h"
|
||||||
#include "llvm/ADT/None.h"
|
#include "llvm/ADT/None.h"
|
||||||
#include "llvm/ADT/Optional.h"
|
#include "llvm/ADT/Optional.h"
|
||||||
#include "llvm/ADT/STLExtras.h"
|
|
||||||
#include "llvm/ADT/ScopeExit.h"
|
#include "llvm/ADT/ScopeExit.h"
|
||||||
|
#include "llvm/ADT/STLExtras.h"
|
||||||
#include "llvm/ADT/SmallVector.h"
|
#include "llvm/ADT/SmallVector.h"
|
||||||
#include "llvm/Support/Casting.h"
|
#include "llvm/Support/Casting.h"
|
||||||
#include "llvm/Support/ErrorHandling.h"
|
#include "llvm/Support/ErrorHandling.h"
|
||||||
|
@ -7717,22 +7716,9 @@ ASTImporter::ASTImporter(ASTContext &ToContext, FileManager &ToFileManager,
|
||||||
ASTContext &FromContext, FileManager &FromFileManager,
|
ASTContext &FromContext, FileManager &FromFileManager,
|
||||||
bool MinimalImport,
|
bool MinimalImport,
|
||||||
std::shared_ptr<ASTImporterSharedState> SharedState)
|
std::shared_ptr<ASTImporterSharedState> SharedState)
|
||||||
: ASTImporter(ToContext, ToFileManager, FromContext, FromFileManager,
|
|
||||||
nullptr, MinimalImport, SharedState){}
|
|
||||||
ASTImporter::ASTImporter(ASTContext &ToContext, FileManager &ToFileManager,
|
|
||||||
ASTUnit &FromUnit, bool MinimalImport,
|
|
||||||
std::shared_ptr<ASTImporterSharedState> SharedState)
|
|
||||||
: ASTImporter(ToContext, ToFileManager, FromUnit.getASTContext(),
|
|
||||||
FromUnit.getFileManager(), &FromUnit, MinimalImport,
|
|
||||||
SharedState){}
|
|
||||||
|
|
||||||
ASTImporter::ASTImporter(ASTContext &ToContext, FileManager &ToFileManager,
|
|
||||||
ASTContext &FromContext, FileManager &FromFileManager,
|
|
||||||
ASTUnit *FromUnit, bool MinimalImport,
|
|
||||||
std::shared_ptr<ASTImporterSharedState> SharedState)
|
|
||||||
: SharedState(SharedState), ToContext(ToContext), FromContext(FromContext),
|
: SharedState(SharedState), ToContext(ToContext), FromContext(FromContext),
|
||||||
ToFileManager(ToFileManager), FromFileManager(FromFileManager),
|
ToFileManager(ToFileManager), FromFileManager(FromFileManager),
|
||||||
FromUnit(FromUnit), Minimal(MinimalImport) {
|
Minimal(MinimalImport) {
|
||||||
|
|
||||||
// Create a default state without the lookup table: LLDB case.
|
// Create a default state without the lookup table: LLDB case.
|
||||||
if (!SharedState) {
|
if (!SharedState) {
|
||||||
|
@ -8435,13 +8421,6 @@ Expected<FileID> ASTImporter::Import(FileID FromID, bool IsBuiltin) {
|
||||||
assert(ToID.isValid() && "Unexpected invalid fileID was created.");
|
assert(ToID.isValid() && "Unexpected invalid fileID was created.");
|
||||||
|
|
||||||
ImportedFileIDs[FromID] = ToID;
|
ImportedFileIDs[FromID] = ToID;
|
||||||
if (FromUnit) {
|
|
||||||
assert(SharedState->getImportedFileIDs().find(ToID) ==
|
|
||||||
SharedState->getImportedFileIDs().end() &&
|
|
||||||
"FileID already imported!");
|
|
||||||
SharedState->getImportedFileIDs()[ToID] = std::make_pair(FromID, FromUnit);
|
|
||||||
}
|
|
||||||
|
|
||||||
return ToID;
|
return ToID;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -295,7 +295,7 @@ llvm::Expected<const T *> CrossTranslationUnitContext::getCrossTUDefinitionImpl(
|
||||||
|
|
||||||
TranslationUnitDecl *TU = Unit->getASTContext().getTranslationUnitDecl();
|
TranslationUnitDecl *TU = Unit->getASTContext().getTranslationUnitDecl();
|
||||||
if (const T *ResultDecl = findDefInDeclContext<T>(TU, LookupName))
|
if (const T *ResultDecl = findDefInDeclContext<T>(TU, LookupName))
|
||||||
return importDefinition(ResultDecl, Unit);
|
return importDefinition(ResultDecl);
|
||||||
return llvm::make_error<IndexError>(index_error_code::failed_import);
|
return llvm::make_error<IndexError>(index_error_code::failed_import);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -411,13 +411,10 @@ llvm::Expected<ASTUnit *> CrossTranslationUnitContext::loadExternalAST(
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
llvm::Expected<const T *>
|
llvm::Expected<const T *>
|
||||||
CrossTranslationUnitContext::importDefinitionImpl(const T *D, ASTUnit *Unit) {
|
CrossTranslationUnitContext::importDefinitionImpl(const T *D) {
|
||||||
assert(hasBodyOrInit(D) && "Decls to be imported should have body or init.");
|
assert(hasBodyOrInit(D) && "Decls to be imported should have body or init.");
|
||||||
|
|
||||||
assert(&D->getASTContext() == &Unit->getASTContext() &&
|
ASTImporter &Importer = getOrCreateASTImporter(D->getASTContext());
|
||||||
"ASTContext of Decl and the unit should match.");
|
|
||||||
ASTImporter &Importer = getOrCreateASTImporter(Unit);
|
|
||||||
|
|
||||||
auto ToDeclOrError = Importer.Import(D);
|
auto ToDeclOrError = Importer.Import(D);
|
||||||
if (!ToDeclOrError) {
|
if (!ToDeclOrError) {
|
||||||
handleAllErrors(ToDeclOrError.takeError(),
|
handleAllErrors(ToDeclOrError.takeError(),
|
||||||
|
@ -444,15 +441,13 @@ CrossTranslationUnitContext::importDefinitionImpl(const T *D, ASTUnit *Unit) {
|
||||||
}
|
}
|
||||||
|
|
||||||
llvm::Expected<const FunctionDecl *>
|
llvm::Expected<const FunctionDecl *>
|
||||||
CrossTranslationUnitContext::importDefinition(const FunctionDecl *FD,
|
CrossTranslationUnitContext::importDefinition(const FunctionDecl *FD) {
|
||||||
ASTUnit *Unit) {
|
return importDefinitionImpl(FD);
|
||||||
return importDefinitionImpl(FD, Unit);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
llvm::Expected<const VarDecl *>
|
llvm::Expected<const VarDecl *>
|
||||||
CrossTranslationUnitContext::importDefinition(const VarDecl *VD,
|
CrossTranslationUnitContext::importDefinition(const VarDecl *VD) {
|
||||||
ASTUnit *Unit) {
|
return importDefinitionImpl(VD);
|
||||||
return importDefinitionImpl(VD, Unit);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CrossTranslationUnitContext::lazyInitImporterSharedSt(
|
void CrossTranslationUnitContext::lazyInitImporterSharedSt(
|
||||||
|
@ -462,40 +457,17 @@ void CrossTranslationUnitContext::lazyInitImporterSharedSt(
|
||||||
}
|
}
|
||||||
|
|
||||||
ASTImporter &
|
ASTImporter &
|
||||||
CrossTranslationUnitContext::getOrCreateASTImporter(ASTUnit *Unit) {
|
CrossTranslationUnitContext::getOrCreateASTImporter(ASTContext &From) {
|
||||||
ASTContext &From = Unit->getASTContext();
|
|
||||||
|
|
||||||
auto I = ASTUnitImporterMap.find(From.getTranslationUnitDecl());
|
auto I = ASTUnitImporterMap.find(From.getTranslationUnitDecl());
|
||||||
if (I != ASTUnitImporterMap.end())
|
if (I != ASTUnitImporterMap.end())
|
||||||
return *I->second;
|
return *I->second;
|
||||||
lazyInitImporterSharedSt(Context.getTranslationUnitDecl());
|
lazyInitImporterSharedSt(Context.getTranslationUnitDecl());
|
||||||
ASTImporter *NewImporter =
|
ASTImporter *NewImporter = new ASTImporter(
|
||||||
new ASTImporter(Context, Context.getSourceManager().getFileManager(),
|
Context, Context.getSourceManager().getFileManager(), From,
|
||||||
*Unit, false, ImporterSharedSt);
|
From.getSourceManager().getFileManager(), false, ImporterSharedSt);
|
||||||
ASTUnitImporterMap[From.getTranslationUnitDecl()].reset(NewImporter);
|
ASTUnitImporterMap[From.getTranslationUnitDecl()].reset(NewImporter);
|
||||||
return *NewImporter;
|
return *NewImporter;
|
||||||
}
|
}
|
||||||
|
|
||||||
llvm::Optional<std::pair<SourceLocation, ASTUnit *>>
|
|
||||||
CrossTranslationUnitContext::getImportedFromSourceLocation(
|
|
||||||
const clang::SourceLocation &ToLoc) const {
|
|
||||||
if (!ImporterSharedSt)
|
|
||||||
return {};
|
|
||||||
|
|
||||||
const SourceManager &SM = Context.getSourceManager();
|
|
||||||
auto DecToLoc = SM.getDecomposedLoc(ToLoc);
|
|
||||||
|
|
||||||
auto I = ImporterSharedSt->getImportedFileIDs().find(DecToLoc.first);
|
|
||||||
if (I == ImporterSharedSt->getImportedFileIDs().end())
|
|
||||||
return {};
|
|
||||||
|
|
||||||
FileID FromID = I->second.first;
|
|
||||||
clang::ASTUnit *Unit = I->second.second;
|
|
||||||
SourceLocation FromLoc =
|
|
||||||
Unit->getSourceManager().getComposedLoc(FromID, DecToLoc.second);
|
|
||||||
|
|
||||||
return std::make_pair(FromLoc, Unit);
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace cross_tu
|
} // namespace cross_tu
|
||||||
} // namespace clang
|
} // namespace clang
|
||||||
|
|
|
@ -28,18 +28,13 @@ public:
|
||||||
: CTU(CI), Success(Success) {}
|
: CTU(CI), Success(Success) {}
|
||||||
|
|
||||||
void HandleTranslationUnit(ASTContext &Ctx) {
|
void HandleTranslationUnit(ASTContext &Ctx) {
|
||||||
auto FindFInTU = [](const TranslationUnitDecl *TU) {
|
|
||||||
const FunctionDecl *FD = nullptr;
|
|
||||||
for (const Decl *D : TU->decls()) {
|
|
||||||
FD = dyn_cast<FunctionDecl>(D);
|
|
||||||
if (FD && FD->getName() == "f")
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
return FD;
|
|
||||||
};
|
|
||||||
|
|
||||||
const TranslationUnitDecl *TU = Ctx.getTranslationUnitDecl();
|
const TranslationUnitDecl *TU = Ctx.getTranslationUnitDecl();
|
||||||
const FunctionDecl *FD = FindFInTU(TU);
|
const FunctionDecl *FD = nullptr;
|
||||||
|
for (const Decl *D : TU->decls()) {
|
||||||
|
FD = dyn_cast<FunctionDecl>(D);
|
||||||
|
if (FD && FD->getName() == "f")
|
||||||
|
break;
|
||||||
|
}
|
||||||
assert(FD && FD->getName() == "f");
|
assert(FD && FD->getName() == "f");
|
||||||
bool OrigFDHasBody = FD->hasBody();
|
bool OrigFDHasBody = FD->hasBody();
|
||||||
|
|
||||||
|
@ -83,28 +78,6 @@ public:
|
||||||
if (NewFDorError) {
|
if (NewFDorError) {
|
||||||
const FunctionDecl *NewFD = *NewFDorError;
|
const FunctionDecl *NewFD = *NewFDorError;
|
||||||
*Success = NewFD && NewFD->hasBody() && !OrigFDHasBody;
|
*Success = NewFD && NewFD->hasBody() && !OrigFDHasBody;
|
||||||
|
|
||||||
if (NewFD) {
|
|
||||||
// Check GetImportedFromSourceLocation.
|
|
||||||
llvm::Optional<std::pair<SourceLocation, ASTUnit *>> SLocResult =
|
|
||||||
CTU.getImportedFromSourceLocation(NewFD->getLocation());
|
|
||||||
EXPECT_TRUE(SLocResult);
|
|
||||||
if (SLocResult) {
|
|
||||||
SourceLocation OrigSLoc = (*SLocResult).first;
|
|
||||||
ASTUnit *OrigUnit = (*SLocResult).second;
|
|
||||||
// OrigUnit is created internally by CTU (is not the
|
|
||||||
// ASTWithDefinition).
|
|
||||||
TranslationUnitDecl *OrigTU =
|
|
||||||
OrigUnit->getASTContext().getTranslationUnitDecl();
|
|
||||||
const FunctionDecl *FDWithDefinition = FindFInTU(OrigTU);
|
|
||||||
EXPECT_TRUE(FDWithDefinition);
|
|
||||||
if (FDWithDefinition) {
|
|
||||||
EXPECT_EQ(FDWithDefinition->getName(), "f");
|
|
||||||
EXPECT_TRUE(FDWithDefinition->isThisDeclarationADefinition());
|
|
||||||
EXPECT_EQ(OrigSLoc, FDWithDefinition->getLocation());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue