diff options
author | Ted Kremenek <kremenek@apple.com> | 2007-11-28 21:32:21 +0000 |
---|---|---|
committer | Ted Kremenek <kremenek@apple.com> | 2007-11-28 21:32:21 +0000 |
commit | ea75c5599072bda2dc9fc1dec2e680936c84f6f1 (patch) | |
tree | 033956044ea2fd63b3c51b7786cd144848e9422f /Driver/SerializationTest.cpp | |
parent | 251f7325b38d3412ac4681edb9f34408f59d3424 (diff) |
Converted AST Pretty-Printer to use iostreams instead of FILE*. This fixes
a bug where the statement pretty-printer used iostreams but the AST printer
did not. This was an issue when dumping ASTs to something other than stderr.
Updated SerializationTest to use the new iostreams interface for the AST printer.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@44417 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'Driver/SerializationTest.cpp')
-rw-r--r-- | Driver/SerializationTest.cpp | 44 |
1 files changed, 14 insertions, 30 deletions
diff --git a/Driver/SerializationTest.cpp b/Driver/SerializationTest.cpp index c0ebff7801..9f756136bd 100644 --- a/Driver/SerializationTest.cpp +++ b/Driver/SerializationTest.cpp @@ -23,11 +23,11 @@ #include "llvm/Support/MemoryBuffer.h" #include "llvm/Bitcode/Serialize.h" #include "llvm/Bitcode/Deserialize.h" +#include <fstream> #include <stdio.h> #include <list> using namespace clang; -using llvm::sys::TimeValue; //===----------------------------------------------------------------------===// // Utility classes @@ -43,20 +43,6 @@ public: operator T*() const { return Obj; } T* operator->() { return Obj; } }; - -class FileSP { - FILE* f; -public: - FileSP(const llvm::sys::Path& fname, const char* mode = "wb") - : f(fopen(fname.c_str(),mode)) {} - - ~FileSP() { if (f) fclose(f); } - - operator FILE*() const { return f; } -private: - void operator=(const FileSP& RHS) {} - FileSP(const FileSP& RHS) {} -}; //===----------------------------------------------------------------------===// // Driver code. @@ -134,9 +120,9 @@ void SerializationTest::Serialize(llvm::sys::Path& Filename, { // Create a printer to "consume" our deserialized ASTS. Janitor<ASTConsumer> Printer(CreateASTPrinter()); - FileSP DeclFP(FNameDeclPrint,"w"); - assert (DeclFP && "Could not open file for printing out decls."); - Janitor<ASTConsumer> FilePrinter(CreateASTPrinter(DeclFP)); + std::ofstream DeclPP(FNameDeclPrint.c_str()); + assert (DeclPP && "Could not open file for printing out decls."); + Janitor<ASTConsumer> FilePrinter(CreateASTPrinter(&DeclPP)); for (std::list<Decl*>::iterator I=Decls.begin(), E=Decls.end(); I!=E; ++I) { llvm::cerr << "Serializing: Decl.\n"; @@ -183,15 +169,13 @@ void SerializationTest::Serialize(llvm::sys::Path& Filename, // ===---------------------------------------------------===/ // Finalize serialization: write the bits to disk. - { - FileSP fp(Filename); - - if (fp) - fwrite((char*)&Buffer.front(), sizeof(char), Buffer.size(), fp); - else { - llvm::cerr << "Error: Cannot open " << Filename.c_str() << "\n"; - return; - } + if (FILE* fp = fopen(Filename.c_str(),"wb")) { + fwrite((char*)&Buffer.front(), sizeof(char), Buffer.size(), fp); + fclose(fp); + } + else { + llvm::cerr << "Error: Cannot open " << Filename.c_str() << "\n"; + return; } llvm::cerr << "Commited bitstream to disk: " << Filename.c_str() << "\n"; @@ -280,9 +264,9 @@ void SerializationTest::Deserialize(llvm::sys::Path& Filename, // Create a printer to "consume" our deserialized ASTS. ASTConsumer* Printer = CreateASTPrinter(); Janitor<ASTConsumer> PrinterJanitor(Printer); - FileSP DeclFP(FNameDeclPrint,"w"); - assert (DeclFP && "Could not open file for printing out decls."); - Janitor<ASTConsumer> FilePrinter(CreateASTPrinter(DeclFP)); + std::ofstream DeclPP(FNameDeclPrint.c_str()); + assert (DeclPP && "Could not open file for printing out decls."); + Janitor<ASTConsumer> FilePrinter(CreateASTPrinter(&DeclPP)); // The remaining objects in the file are top-level decls. while (!Dezr.FinishedBlock(DeclBlockLoc)) { |