[cfe-commits] r84208 - in /cfe/trunk: include/clang/Frontend/ASTUnit.h include/clang/Frontend/PCHReader.h lib/Frontend/ASTUnit.cpp tools/CIndex/CIndex.cpp tools/c-index-test/c-index-test.c
Chris Lattner
clattner at apple.com
Thu Oct 15 19:27:26 PDT 2009
On Oct 15, 2009, at 3:23 PM, Steve Naroff wrote:
> Author: snaroff
> Date: Thu Oct 15 17:23:48 2009
> New Revision: 84208
>
> URL: http://llvm.org/viewvc/llvm-project?rev=84208&view=rev
> Log:
> Make sure temporary files get unlinked.
Hi Steve,
Please use sys::Path::eraseFromDisk to increase portability instead of
calling unlink. Thanks!
-Chris
>
> Modified:
> cfe/trunk/include/clang/Frontend/ASTUnit.h
> cfe/trunk/include/clang/Frontend/PCHReader.h
> cfe/trunk/lib/Frontend/ASTUnit.cpp
> cfe/trunk/tools/CIndex/CIndex.cpp
> cfe/trunk/tools/c-index-test/c-index-test.c
>
> Modified: cfe/trunk/include/clang/Frontend/ASTUnit.h
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/ASTUnit.h?rev=84208&r1=84207&r2=84208&view=diff
>
> =
> =
> =
> =
> =
> =
> =
> =
> ======================================================================
> --- cfe/trunk/include/clang/Frontend/ASTUnit.h (original)
> +++ cfe/trunk/include/clang/Frontend/ASTUnit.h Thu Oct 15 17:23:48
> 2009
> @@ -38,7 +38,8 @@
> 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 @@
>
> 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.
>
> Modified: cfe/trunk/include/clang/Frontend/PCHReader.h
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/PCHReader.h?rev=84208&r1=84207&r2=84208&view=diff
>
> =
> =
> =
> =
> =
> =
> =
> =
> ======================================================================
> --- cfe/trunk/include/clang/Frontend/PCHReader.h (original)
> +++ cfe/trunk/include/clang/Frontend/PCHReader.h Thu Oct 15 17:23:48
> 2009
> @@ -513,6 +513,9 @@
> /// \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; }
>
>
> Modified: cfe/trunk/lib/Frontend/ASTUnit.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/ASTUnit.cpp?rev=84208&r1=84207&r2=84208&view=diff
>
> =
> =
> =
> =
> =
> =
> =
> =
> ======================================================================
> --- cfe/trunk/lib/Frontend/ASTUnit.cpp (original)
> +++ cfe/trunk/lib/Frontend/ASTUnit.cpp Thu Oct 15 17:23:48 2009
> @@ -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 @@
> 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();
> }
>
> Modified: cfe/trunk/tools/CIndex/CIndex.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/CIndex/CIndex.cpp?rev=84208&r1=84207&r2=84208&view=diff
>
> =
> =
> =
> =
> =
> =
> =
> =
> ======================================================================
> --- cfe/trunk/tools/CIndex/CIndex.cpp (original)
> +++ cfe/trunk/tools/CIndex/CIndex.cpp Thu Oct 15 17:23:48 2009
> @@ -325,7 +325,10 @@
> } 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(
>
> Modified: cfe/trunk/tools/c-index-test/c-index-test.c
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/c-index-test/c-index-test.c?rev=84208&r1=84207&r2=84208&view=diff
>
> =
> =
> =
> =
> =
> =
> =
> =
> ======================================================================
> --- cfe/trunk/tools/c-index-test/c-index-test.c (original)
> +++ cfe/trunk/tools/c-index-test/c-index-test.c Thu Oct 15 17:23:48
> 2009
> @@ -91,6 +91,7 @@
>
> if (!strcmp(argv[2], "all")) {
> clang_loadTranslationUnit(TU, TranslationUnitVisitor, 0);
> + clang_disposeTranslationUnit(TU);
> return 1;
> }
> /* Perform some simple filtering. */
> @@ -101,6 +102,7 @@
> else if (!strcmp(argv[2], "typedef")) K = CXCursor_TypedefDecl;
>
> clang_loadTranslationUnit(TU, TranslationUnitVisitor, &K);
> + clang_disposeTranslationUnit(TU);
> return 1;
> }
> }
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
More information about the cfe-commits
mailing list