forked from OSchip/llvm-project
parent
fb8e47323f
commit
44cd60eebe
|
@ -38,7 +38,8 @@ class ASTUnit {
|
|||
llvm::OwningPtr<TargetInfo> Target;
|
||||
llvm::OwningPtr<Preprocessor> PP;
|
||||
llvm::OwningPtr<ASTContext> Ctx;
|
||||
|
||||
bool tempFile;
|
||||
|
||||
ASTUnit(const ASTUnit&); // DO NOT IMPLEMENT
|
||||
ASTUnit &operator=(const ASTUnit &); // DO NOT IMPLEMENT
|
||||
ASTUnit(Diagnostic &_Diag);
|
||||
|
@ -60,7 +61,10 @@ public:
|
|||
|
||||
FileManager &getFileManager();
|
||||
const std::string &getOriginalSourceFileName();
|
||||
const std::string &getPCHFileName();
|
||||
|
||||
void unlinkTemporaryFile() { tempFile = true; }
|
||||
|
||||
/// \brief Create a ASTUnit from a PCH file.
|
||||
///
|
||||
/// \param Filename - The PCH file to load.
|
||||
|
|
|
@ -513,6 +513,9 @@ public:
|
|||
/// \brief Sets and initializes the given Context.
|
||||
void InitializeContext(ASTContext &Context);
|
||||
|
||||
/// \brief Retrieve the name of the PCH file
|
||||
const std::string &getFileName() { return FileName; }
|
||||
|
||||
/// \brief Retrieve the name of the original source file name
|
||||
const std::string &getOriginalSourceFile() { return OriginalFileName; }
|
||||
|
||||
|
|
|
@ -24,8 +24,11 @@
|
|||
|
||||
using namespace clang;
|
||||
|
||||
ASTUnit::ASTUnit(Diagnostic &_Diags) : Diags(_Diags) { }
|
||||
ASTUnit::~ASTUnit() { }
|
||||
ASTUnit::ASTUnit(Diagnostic &_Diags) : Diags(_Diags), tempFile(false) { }
|
||||
ASTUnit::~ASTUnit() {
|
||||
if (tempFile)
|
||||
unlink(getPCHFileName().c_str());
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
|
@ -80,6 +83,10 @@ const std::string &ASTUnit::getOriginalSourceFileName() {
|
|||
return dyn_cast<PCHReader>(Ctx->getExternalSource())->getOriginalSourceFile();
|
||||
}
|
||||
|
||||
const std::string &ASTUnit::getPCHFileName() {
|
||||
return dyn_cast<PCHReader>(Ctx->getExternalSource())->getFileName();
|
||||
}
|
||||
|
||||
FileManager &ASTUnit::getFileManager() {
|
||||
return HeaderInfo->getFileMgr();
|
||||
}
|
||||
|
|
|
@ -325,7 +325,10 @@ CXTranslationUnit clang_createTranslationUnitFromSourceFile(
|
|||
} while (tpid != child_pid);
|
||||
|
||||
// Finally, we create the translation unit from the ast file.
|
||||
return clang_createTranslationUnit(CIdx, astTmpFile);
|
||||
ASTUnit *ATU = static_cast<ASTUnit *>(
|
||||
clang_createTranslationUnit(CIdx, astTmpFile));
|
||||
ATU->unlinkTemporaryFile();
|
||||
return ATU;
|
||||
}
|
||||
|
||||
void clang_disposeTranslationUnit(
|
||||
|
|
|
@ -91,6 +91,7 @@ int main(int argc, char **argv) {
|
|||
|
||||
if (!strcmp(argv[2], "all")) {
|
||||
clang_loadTranslationUnit(TU, TranslationUnitVisitor, 0);
|
||||
clang_disposeTranslationUnit(TU);
|
||||
return 1;
|
||||
}
|
||||
/* Perform some simple filtering. */
|
||||
|
@ -101,6 +102,7 @@ int main(int argc, char **argv) {
|
|||
else if (!strcmp(argv[2], "typedef")) K = CXCursor_TypedefDecl;
|
||||
|
||||
clang_loadTranslationUnit(TU, TranslationUnitVisitor, &K);
|
||||
clang_disposeTranslationUnit(TU);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue