From d2fa67570b363843215f62395b795c1f70e6b85f Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Sat, 28 Mar 2009 03:56:54 +0000 Subject: [PATCH] hoist TranslationUnit some more. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@67905 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/AST/TranslationUnit.h | 2 +- lib/AST/TranslationUnit.cpp | 4 ++-- tools/clang-cc/ASTConsumers.cpp | 4 ++-- tools/clang-cc/SerializationTest.cpp | 12 +++++++----- 4 files changed, 12 insertions(+), 10 deletions(-) diff --git a/include/clang/AST/TranslationUnit.h b/include/clang/AST/TranslationUnit.h index 40513e2019..2b22cf98e4 100644 --- a/include/clang/AST/TranslationUnit.h +++ b/include/clang/AST/TranslationUnit.h @@ -62,7 +62,7 @@ public: }; /// EmitASTBitcodeBuffer - Emit a translation unit to a buffer. -bool EmitASTBitcodeBuffer(const TranslationUnit& TU, +bool EmitASTBitcodeBuffer(const ASTContext &Ctx, std::vector& Buffer); /// ReadASTBitcodeBuffer - Reconsitute a translation unit from a buffer. diff --git a/lib/AST/TranslationUnit.cpp b/lib/AST/TranslationUnit.cpp index 55ab1a7360..df135edf63 100644 --- a/lib/AST/TranslationUnit.cpp +++ b/lib/AST/TranslationUnit.cpp @@ -39,7 +39,7 @@ TranslationUnit::~TranslationUnit() { } } -bool clang::EmitASTBitcodeBuffer(const TranslationUnit& TU, +bool clang::EmitASTBitcodeBuffer(const ASTContext &Ctx, std::vector& Buffer) { // Create bitstream. llvm::BitstreamWriter Stream(Buffer); @@ -58,7 +58,7 @@ bool clang::EmitASTBitcodeBuffer(const TranslationUnit& TU, llvm::Serializer Sezr(Stream); // Emit the translation unit. - TU.getContext().EmitAll(Sezr); + Ctx.EmitAll(Sezr); } return true; diff --git a/tools/clang-cc/ASTConsumers.cpp b/tools/clang-cc/ASTConsumers.cpp index c040a54b44..288225d1e5 100644 --- a/tools/clang-cc/ASTConsumers.cpp +++ b/tools/clang-cc/ASTConsumers.cpp @@ -982,7 +982,7 @@ public: std::vector Buffer; Buffer.reserve(256*1024); - EmitASTBitcodeBuffer(TU,Buffer); + EmitASTBitcodeBuffer(TU.getContext(), Buffer); // Write the bits to disk. if (FILE* fp = fopen(FName.c_str(),"wb")) { @@ -1033,7 +1033,7 @@ public: std::vector Buffer; Buffer.reserve(256*1024); - EmitASTBitcodeBuffer(TU,Buffer); + EmitASTBitcodeBuffer(TU.getContext(), Buffer); // Write the bits to disk. if (FILE* fp = fopen(FName.c_str(),"wb")) { diff --git a/tools/clang-cc/SerializationTest.cpp b/tools/clang-cc/SerializationTest.cpp index aa3163f556..770f9b3b87 100644 --- a/tools/clang-cc/SerializationTest.cpp +++ b/tools/clang-cc/SerializationTest.cpp @@ -46,7 +46,7 @@ public: private: bool Serialize(llvm::sys::Path& Filename, llvm::sys::Path& FNameDeclPrint, - TranslationUnit& TU); + ASTContext &Ctx); bool Deserialize(llvm::sys::Path& Filename, llvm::sys::Path& FNameDeclPrint); }; @@ -61,7 +61,7 @@ clang::CreateSerializationTest(Diagnostic &Diags, FileManager& FMgr) { bool SerializationTest::Serialize(llvm::sys::Path& Filename, llvm::sys::Path& FNameDeclPrint, - TranslationUnit& TU) { + ASTContext &Ctx) { { // Pretty-print the decls to a temp file. std::string Err; @@ -69,7 +69,9 @@ bool SerializationTest::Serialize(llvm::sys::Path& Filename, assert (Err.empty() && "Could not open file for printing out decls."); llvm::OwningPtr FilePrinter(CreateASTPrinter(&DeclPP)); - for (TranslationUnit::iterator I=TU.begin(), E=TU.end(); I!=E; ++I) + TranslationUnitDecl *TUD = Ctx.getTranslationUnitDecl(); + for (DeclContext::decl_iterator I = TUD->decls_begin(), E =TUD->decls_end(); + I != E; ++I) FilePrinter->HandleTopLevelDecl(*I); } @@ -79,7 +81,7 @@ bool SerializationTest::Serialize(llvm::sys::Path& Filename, std::vector Buffer; Buffer.reserve(256*1024); - EmitASTBitcodeBuffer(TU,Buffer); + EmitASTBitcodeBuffer(Ctx, Buffer); // Write the bits to disk. if (FILE* fp = fopen(Filename.c_str(),"wb")) { @@ -177,7 +179,7 @@ void SerializationTest::HandleTranslationUnit(TranslationUnit& TU) { } // Serialize and then deserialize the ASTs. - bool status = Serialize(ASTFilename, FNameDeclBefore, TU); + bool status = Serialize(ASTFilename, FNameDeclBefore, TU.getContext()); assert (status && "Serialization failed."); status = Deserialize(ASTFilename, FNameDeclAfter); assert (status && "Deserialization failed."); -- 2.40.0