Rework translation unit actions to actually take an entire translation unit

as imput.

llvm-svn: 96182
This commit is contained in:
Ted Kremenek 2010-02-14 19:08:51 +00:00
parent c968e5e9b9
commit 39df94b00d
1 changed files with 51 additions and 44 deletions

View File

@ -65,13 +65,17 @@ namespace {
class AnalysisConsumer : public ASTConsumer {
public:
typedef void (*CodeAction)(AnalysisConsumer &C, AnalysisManager &M, Decl *D);
typedef void (*TUAction)(AnalysisConsumer &C, AnalysisManager &M,
TranslationUnitDecl &TU);
private:
typedef std::vector<CodeAction> Actions;
typedef std::vector<TUAction> TUActions;
Actions FunctionActions;
Actions ObjCMethodActions;
Actions ObjCImplementationActions;
Actions TranslationUnitActions;
TUActions TranslationUnitActions;
public:
ASTContext* Ctx;
@ -163,7 +167,7 @@ public:
ObjCImplementationActions.push_back(action);
}
void addTranslationUnitAction(CodeAction action) {
void addTranslationUnitAction(TUAction action) {
TranslationUnitActions.push_back(action);
}
@ -241,27 +245,9 @@ void AnalysisConsumer::HandleTranslationUnit(ASTContext &C) {
TranslationUnitDecl *TU = C.getTranslationUnitDecl();
if (!TranslationUnitActions.empty()) {
// Find the entry function definition (if any).
FunctionDecl *FD = 0;
// Must specify an entry function.
if (!Opts.AnalyzeSpecificFunction.empty()) {
for (DeclContext::decl_iterator I=TU->decls_begin(), E=TU->decls_end();
I != E; ++I) {
if (FunctionDecl *fd = dyn_cast<FunctionDecl>(*I))
if (fd->isThisDeclarationADefinition() &&
fd->getNameAsString() == Opts.AnalyzeSpecificFunction) {
FD = fd;
break;
}
}
}
if (FD) {
for (Actions::iterator I = TranslationUnitActions.begin(),
E = TranslationUnitActions.end(); I != E; ++I)
(*I)(*this, *Mgr, FD);
}
for (TUActions::iterator I = TranslationUnitActions.begin(),
E = TranslationUnitActions.end(); I != E; ++I) {
(*I)(*this, *Mgr, *TU);
}
if (!ObjCImplementationActions.empty()) {
@ -486,7 +472,28 @@ static void ActionWarnSizeofPointer(AnalysisConsumer &C, AnalysisManager &mgr,
}
static void ActionInlineCall(AnalysisConsumer &C, AnalysisManager &mgr,
Decl *D) {
TranslationUnitDecl &TU) {
// Find the entry function definition (if any).
FunctionDecl *D = 0;
// Must specify an entry function.
if (!C.Opts.AnalyzeSpecificFunction.empty()) {
for (DeclContext::decl_iterator I=TU.decls_begin(), E=TU.decls_end();
I != E; ++I) {
if (FunctionDecl *fd = dyn_cast<FunctionDecl>(*I))
if (fd->isThisDeclarationADefinition() &&
fd->getNameAsString() == C.Opts.AnalyzeSpecificFunction) {
D = fd;
break;
}
}
}
if (!D)
return;
// FIXME: This is largely copy of ActionGRExprEngine. Needs cleanup.
// Display progress.
C.DisplayFunction(D);