forked from OSchip/llvm-project
Unbreak SerializationTest and the Rewriter by doing the work in HandleTranslationUnit instead of the destructor.
llvm-svn: 54513
This commit is contained in:
parent
6067b44985
commit
6231e7e4ec
clang/Driver
|
@ -108,7 +108,10 @@ namespace {
|
|||
void HandleDeclInMainFile(Decl *D);
|
||||
RewriteObjC(std::string inFile, std::string outFile,
|
||||
Diagnostic &D, const LangOptions &LOpts);
|
||||
~RewriteObjC();
|
||||
|
||||
~RewriteObjC() {}
|
||||
|
||||
virtual void HandleTranslationUnit(TranslationUnit& TU);
|
||||
|
||||
void ReplaceStmt(Stmt *Old, Stmt *New) {
|
||||
// If replacement succeeded or warning disabled return with no warning.
|
||||
|
@ -439,7 +442,7 @@ void RewriteObjC::HandleDeclInMainFile(Decl *D) {
|
|||
// Nothing yet.
|
||||
}
|
||||
|
||||
RewriteObjC::~RewriteObjC() {
|
||||
void RewriteObjC::HandleTranslationUnit(TranslationUnit& TU) {
|
||||
// Get the top-level buffer that this corresponds to.
|
||||
|
||||
// Rewrite tabs if we care.
|
||||
|
|
|
@ -33,19 +33,20 @@ using namespace clang;
|
|||
namespace {
|
||||
|
||||
class SerializationTest : public ASTConsumer {
|
||||
TranslationUnit* TU;
|
||||
Diagnostic &Diags;
|
||||
FileManager &FMgr;
|
||||
public:
|
||||
SerializationTest(Diagnostic &d, FileManager& fmgr)
|
||||
: TU(0), Diags(d), FMgr(fmgr) {}
|
||||
: Diags(d), FMgr(fmgr) {}
|
||||
|
||||
~SerializationTest();
|
||||
|
||||
virtual void InitializeTU(TranslationUnit& tu) { TU = &tu; }
|
||||
~SerializationTest() {}
|
||||
|
||||
virtual void HandleTranslationUnit(TranslationUnit& TU);
|
||||
|
||||
private:
|
||||
bool Serialize(llvm::sys::Path& Filename, llvm::sys::Path& FNameDeclPrint);
|
||||
bool Serialize(llvm::sys::Path& Filename, llvm::sys::Path& FNameDeclPrint,
|
||||
TranslationUnit& TU);
|
||||
|
||||
bool Deserialize(llvm::sys::Path& Filename, llvm::sys::Path& FNameDeclPrint);
|
||||
};
|
||||
|
||||
|
@ -58,19 +59,20 @@ clang::CreateSerializationTest(Diagnostic &Diags, FileManager& FMgr) {
|
|||
|
||||
|
||||
bool SerializationTest::Serialize(llvm::sys::Path& Filename,
|
||||
llvm::sys::Path& FNameDeclPrint) {
|
||||
llvm::sys::Path& FNameDeclPrint,
|
||||
TranslationUnit& TU) {
|
||||
{
|
||||
// Pretty-print the decls to a temp file.
|
||||
std::ofstream DeclPP(FNameDeclPrint.c_str());
|
||||
assert (DeclPP && "Could not open file for printing out decls.");
|
||||
llvm::OwningPtr<ASTConsumer> FilePrinter(CreateASTPrinter(&DeclPP));
|
||||
|
||||
for (TranslationUnit::iterator I=TU->begin(), E=TU->end(); I!=E; ++I)
|
||||
for (TranslationUnit::iterator I=TU.begin(), E=TU.end(); I!=E; ++I)
|
||||
FilePrinter->HandleTopLevelDecl(*I);
|
||||
}
|
||||
|
||||
// Serialize the translation unit.
|
||||
return EmitASTBitcodeFile(*TU,Filename);
|
||||
return EmitASTBitcodeFile(TU,Filename);
|
||||
}
|
||||
|
||||
bool SerializationTest::Deserialize(llvm::sys::Path& Filename,
|
||||
|
@ -82,7 +84,7 @@ bool SerializationTest::Deserialize(llvm::sys::Path& Filename,
|
|||
if (!NewTU)
|
||||
return false;
|
||||
|
||||
{
|
||||
{
|
||||
// Pretty-print the deserialized decls to a temp file.
|
||||
std::ofstream DeclPP(FNameDeclPrint.c_str());
|
||||
assert (DeclPP && "Could not open file for printing out decls.");
|
||||
|
@ -110,7 +112,7 @@ namespace {
|
|||
};
|
||||
}
|
||||
|
||||
SerializationTest::~SerializationTest() {
|
||||
void SerializationTest::HandleTranslationUnit(TranslationUnit& TU) {
|
||||
|
||||
std::string ErrMsg;
|
||||
llvm::sys::Path Dir = llvm::sys::Path::GetTemporaryDirectory(&ErrMsg);
|
||||
|
@ -147,7 +149,7 @@ SerializationTest::~SerializationTest() {
|
|||
}
|
||||
|
||||
// Serialize and then deserialize the ASTs.
|
||||
bool status = Serialize(ASTFilename, FNameDeclBefore);
|
||||
bool status = Serialize(ASTFilename, FNameDeclBefore, TU);
|
||||
assert (status && "Serialization failed.");
|
||||
status = Deserialize(ASTFilename, FNameDeclAfter);
|
||||
assert (status && "Deserialization failed.");
|
||||
|
|
Loading…
Reference in New Issue