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);
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.
/// \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; }
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 {
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();
}
} 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(
if (!strcmp(argv[2], "all")) {
clang_loadTranslationUnit(TU, TranslationUnitVisitor, 0);
+ clang_disposeTranslationUnit(TU);
return 1;
}
/* Perform some simple filtering. */
else if (!strcmp(argv[2], "typedef")) K = CXCursor_TypedefDecl;
clang_loadTranslationUnit(TU, TranslationUnitVisitor, &K);
+ clang_disposeTranslationUnit(TU);
return 1;
}
}