change HandleTranslationUnit to take an ASTContext instead of TranslationUnit

llvm-svn: 67910
This commit is contained in:
Chris Lattner 2009-03-28 04:11:33 +00:00
parent cd58cced81
commit cf16983179
8 changed files with 24 additions and 27 deletions

View File

@ -16,7 +16,6 @@
namespace clang { namespace clang {
class ASTContext; class ASTContext;
class TranslationUnit;
class Decl; class Decl;
class TagDecl; class TagDecl;
class HandleTagDeclDefinition; class HandleTagDeclDefinition;
@ -40,7 +39,7 @@ public:
/// HandleTranslationUnit - This method is called when the ASTs for entire /// HandleTranslationUnit - This method is called when the ASTs for entire
/// translation unit have been parsed. /// translation unit have been parsed.
virtual void HandleTranslationUnit(TranslationUnit& TU) {} virtual void HandleTranslationUnit(ASTContext &Ctx) {}
/// HandleTagDeclDefinition - This callback is invoked each time a TagDecl /// HandleTagDeclDefinition - This callback is invoked each time a TagDecl
/// (e.g. struct, union, enum, class) is completed. This allows the client to /// (e.g. struct, union, enum, class) is completed. This allows the client to

View File

@ -74,7 +74,7 @@ namespace {
Builder->UpdateCompletedType(D); Builder->UpdateCompletedType(D);
} }
virtual void HandleTranslationUnit(TranslationUnit& TU) { virtual void HandleTranslationUnit(ASTContext &Ctx) {
if (Diags.hasErrorOccurred()) { if (Diags.hasErrorOccurred()) {
M.reset(); M.reset();
return; return;

View File

@ -56,7 +56,7 @@ void clang::ParseAST(Preprocessor &PP, ASTConsumer *Consumer,
} }
}; };
Consumer->HandleTranslationUnit(TU); Consumer->HandleTranslationUnit(TU.getContext());
if (PrintStats) { if (PrintStats) {
fprintf(stderr, "\nSTATISTICS:\n"); fprintf(stderr, "\nSTATISTICS:\n");

View File

@ -658,8 +658,8 @@ class DeclContextPrinter : public ASTConsumer {
public: public:
DeclContextPrinter() : Out(llvm::errs()) {} DeclContextPrinter() : Out(llvm::errs()) {}
void HandleTranslationUnit(TranslationUnit& TU) { void HandleTranslationUnit(ASTContext &C) {
PrintDeclContext(TU.getContext().getTranslationUnitDecl(), 4); PrintDeclContext(C.getTranslationUnitDecl(), 4);
} }
void PrintDeclContext(const DeclContext* DC, unsigned Indentation); void PrintDeclContext(const DeclContext* DC, unsigned Indentation);
@ -935,8 +935,7 @@ class InheritanceViewer : public ASTConsumer {
public: public:
InheritanceViewer(const std::string& cname) : clsname(cname) {} InheritanceViewer(const std::string& cname) : clsname(cname) {}
void HandleTranslationUnit(TranslationUnit& TU) { void HandleTranslationUnit(ASTContext &C) {
ASTContext& C = TU.getContext();
for (ASTContext::type_iterator I=C.types_begin(),E=C.types_end(); I!=E; ++I) for (ASTContext::type_iterator I=C.types_begin(),E=C.types_end(); I!=E; ++I)
if (RecordType *T = dyn_cast<RecordType>(*I)) { if (RecordType *T = dyn_cast<RecordType>(*I)) {
if (CXXRecordDecl *D = dyn_cast<CXXRecordDecl>(T->getDecl())) { if (CXXRecordDecl *D = dyn_cast<CXXRecordDecl>(T->getDecl())) {
@ -974,7 +973,7 @@ public:
SingleFileSerializer(const llvm::sys::Path& F, Diagnostic& diags) SingleFileSerializer(const llvm::sys::Path& F, Diagnostic& diags)
: ASTSerializer(diags), FName(F) {} : ASTSerializer(diags), FName(F) {}
virtual void HandleTranslationUnit(TranslationUnit& TU) { virtual void HandleTranslationUnit(ASTContext &Ctx) {
if (Diags.hasErrorOccurred()) if (Diags.hasErrorOccurred())
return; return;
@ -982,7 +981,7 @@ public:
std::vector<unsigned char> Buffer; std::vector<unsigned char> Buffer;
Buffer.reserve(256*1024); Buffer.reserve(256*1024);
EmitASTBitcodeBuffer(TU.getContext(), Buffer); EmitASTBitcodeBuffer(Ctx, Buffer);
// Write the bits to disk. // Write the bits to disk.
if (FILE* fp = fopen(FName.c_str(),"wb")) { if (FILE* fp = fopen(FName.c_str(),"wb")) {
@ -998,11 +997,11 @@ public:
BuildSerializer(const llvm::sys::Path& dir, Diagnostic& diags) BuildSerializer(const llvm::sys::Path& dir, Diagnostic& diags)
: ASTSerializer(diags), EmitDir(dir) {} : ASTSerializer(diags), EmitDir(dir) {}
virtual void HandleTranslationUnit(TranslationUnit& TU) { virtual void HandleTranslationUnit(ASTContext &Ctx) {
if (Diags.hasErrorOccurred()) if (Diags.hasErrorOccurred())
return; return;
SourceManager& SourceMgr = TU.getContext().getSourceManager(); SourceManager& SourceMgr = Ctx.getSourceManager();
FileID ID = SourceMgr.getMainFileID(); FileID ID = SourceMgr.getMainFileID();
assert(!ID.isInvalid() && "MainFileID not set!"); assert(!ID.isInvalid() && "MainFileID not set!");
const FileEntry* FE = SourceMgr.getFileEntryForID(ID); const FileEntry* FE = SourceMgr.getFileEntryForID(ID);
@ -1033,7 +1032,7 @@ public:
std::vector<unsigned char> Buffer; std::vector<unsigned char> Buffer;
Buffer.reserve(256*1024); Buffer.reserve(256*1024);
EmitASTBitcodeBuffer(TU.getContext(), Buffer); EmitASTBitcodeBuffer(Ctx, Buffer);
// Write the bits to disk. // Write the bits to disk.
if (FILE* fp = fopen(FName.c_str(),"wb")) { if (FILE* fp = fopen(FName.c_str(),"wb")) {

View File

@ -223,7 +223,7 @@ namespace {
} }
virtual void HandleTopLevelDecl(Decl *D); virtual void HandleTopLevelDecl(Decl *D);
virtual void HandleTranslationUnit(TranslationUnit &TU); virtual void HandleTranslationUnit(ASTContext &C);
void HandleCode(Decl* D, Stmt* Body, Actions& actions); void HandleCode(Decl* D, Stmt* Body, Actions& actions);
}; };
@ -444,7 +444,7 @@ void AnalysisConsumer::HandleTopLevelDecl(Decl *D) {
} }
} }
void AnalysisConsumer::HandleTranslationUnit(TranslationUnit& TU) { void AnalysisConsumer::HandleTranslationUnit(ASTContext &C) {
if(!TranslationUnitActions.empty()) { if(!TranslationUnitActions.empty()) {
AnalysisManager mgr(*this, AnalyzerDisplayProgress); AnalysisManager mgr(*this, AnalyzerDisplayProgress);
@ -454,7 +454,7 @@ void AnalysisConsumer::HandleTranslationUnit(TranslationUnit& TU) {
} }
if (!ObjCImplementationActions.empty()) { if (!ObjCImplementationActions.empty()) {
TranslationUnitDecl *TUD = TU.getContext().getTranslationUnitDecl(); TranslationUnitDecl *TUD = C.getTranslationUnitDecl();
for (DeclContext::decl_iterator I = TUD->decls_begin(),E = TUD->decls_end(); for (DeclContext::decl_iterator I = TUD->decls_begin(),E = TUD->decls_end();
I != E; ++I) I != E; ++I)

View File

@ -131,13 +131,13 @@ namespace {
LLVMIRGeneration.stopTimer(); LLVMIRGeneration.stopTimer();
} }
virtual void HandleTranslationUnit(TranslationUnit& TU) { virtual void HandleTranslationUnit(ASTContext &C) {
{ {
PrettyStackTraceString CrashInfo("Per-file LLVM IR generation"); PrettyStackTraceString CrashInfo("Per-file LLVM IR generation");
if (CompileOpts.TimePasses) if (CompileOpts.TimePasses)
LLVMIRGeneration.startTimer(); LLVMIRGeneration.startTimer();
Gen->HandleTranslationUnit(TU); Gen->HandleTranslationUnit(C);
if (CompileOpts.TimePasses) if (CompileOpts.TimePasses)
LLVMIRGeneration.stopTimer(); LLVMIRGeneration.stopTimer();

View File

@ -15,7 +15,6 @@
#include "clang/Rewrite/Rewriter.h" #include "clang/Rewrite/Rewriter.h"
#include "clang/AST/AST.h" #include "clang/AST/AST.h"
#include "clang/AST/ASTConsumer.h" #include "clang/AST/ASTConsumer.h"
#include "clang/AST/TranslationUnit.h"
#include "clang/AST/ParentMap.h" #include "clang/AST/ParentMap.h"
#include "clang/Basic/SourceManager.h" #include "clang/Basic/SourceManager.h"
#include "clang/Basic/IdentifierTable.h" #include "clang/Basic/IdentifierTable.h"
@ -134,7 +133,7 @@ namespace {
~RewriteObjC() {} ~RewriteObjC() {}
virtual void HandleTranslationUnit(TranslationUnit& TU); virtual void HandleTranslationUnit(ASTContext &C);
void ReplaceStmt(Stmt *Old, Stmt *New) { void ReplaceStmt(Stmt *Old, Stmt *New) {
Stmt *ReplacingStmt = ReplacedNodes[Old]; Stmt *ReplacingStmt = ReplacedNodes[Old];
@ -4516,7 +4515,7 @@ void RewriteObjC::HandleDeclInMainFile(Decl *D) {
// Nothing yet. // Nothing yet.
} }
void RewriteObjC::HandleTranslationUnit(TranslationUnit& TU) { void RewriteObjC::HandleTranslationUnit(ASTContext &C) {
// Get the top-level buffer that this corresponds to. // Get the top-level buffer that this corresponds to.
// Rewrite tabs if we care. // Rewrite tabs if we care.

View File

@ -42,7 +42,7 @@ public:
~SerializationTest() {} ~SerializationTest() {}
virtual void HandleTranslationUnit(TranslationUnit& TU); virtual void HandleTranslationUnit(ASTContext &C);
private: private:
bool Serialize(llvm::sys::Path& Filename, llvm::sys::Path& FNameDeclPrint, bool Serialize(llvm::sys::Path& Filename, llvm::sys::Path& FNameDeclPrint,
@ -142,7 +142,7 @@ namespace {
}; };
} }
void SerializationTest::HandleTranslationUnit(TranslationUnit& TU) { void SerializationTest::HandleTranslationUnit(ASTContext &Ctx) {
std::string ErrMsg; std::string ErrMsg;
llvm::sys::Path Dir = llvm::sys::Path::GetTemporaryDirectory(&ErrMsg); llvm::sys::Path Dir = llvm::sys::Path::GetTemporaryDirectory(&ErrMsg);
@ -157,7 +157,7 @@ void SerializationTest::HandleTranslationUnit(TranslationUnit& TU) {
llvm::sys::Path FNameDeclBefore = Dir; llvm::sys::Path FNameDeclBefore = Dir;
FNameDeclBefore.appendComponent("test.decl_before.txt"); FNameDeclBefore.appendComponent("test.decl_before.txt");
if (FNameDeclBefore.makeUnique(true,&ErrMsg)) { if (FNameDeclBefore.makeUnique(true, &ErrMsg)) {
llvm::cerr << "Error: " << ErrMsg << "\n"; llvm::cerr << "Error: " << ErrMsg << "\n";
return; return;
} }
@ -165,7 +165,7 @@ void SerializationTest::HandleTranslationUnit(TranslationUnit& TU) {
llvm::sys::Path FNameDeclAfter = Dir; llvm::sys::Path FNameDeclAfter = Dir;
FNameDeclAfter.appendComponent("test.decl_after.txt"); FNameDeclAfter.appendComponent("test.decl_after.txt");
if (FNameDeclAfter.makeUnique(true,&ErrMsg)) { if (FNameDeclAfter.makeUnique(true, &ErrMsg)) {
llvm::cerr << "Error: " << ErrMsg << "\n"; llvm::cerr << "Error: " << ErrMsg << "\n";
return; return;
} }
@ -173,13 +173,13 @@ void SerializationTest::HandleTranslationUnit(TranslationUnit& TU) {
llvm::sys::Path ASTFilename = Dir; llvm::sys::Path ASTFilename = Dir;
ASTFilename.appendComponent("test.ast"); ASTFilename.appendComponent("test.ast");
if (ASTFilename.makeUnique(true,&ErrMsg)) { if (ASTFilename.makeUnique(true, &ErrMsg)) {
llvm::cerr << "Error: " << ErrMsg << "\n"; llvm::cerr << "Error: " << ErrMsg << "\n";
return; return;
} }
// Serialize and then deserialize the ASTs. // Serialize and then deserialize the ASTs.
bool status = Serialize(ASTFilename, FNameDeclBefore, TU.getContext()); bool status = Serialize(ASTFilename, FNameDeclBefore, Ctx);
assert (status && "Serialization failed."); assert (status && "Serialization failed.");
status = Deserialize(ASTFilename, FNameDeclAfter); status = Deserialize(ASTFilename, FNameDeclAfter);
assert (status && "Deserialization failed."); assert (status && "Deserialization failed.");