diff options
-rw-r--r-- | AST/ASTConsumer.cpp | 27 | ||||
-rw-r--r-- | include/clang/AST/ASTConsumer.h | 19 |
2 files changed, 40 insertions, 6 deletions
diff --git a/AST/ASTConsumer.cpp b/AST/ASTConsumer.cpp new file mode 100644 index 0000000000..0cf614102d --- /dev/null +++ b/AST/ASTConsumer.cpp @@ -0,0 +1,27 @@ +//===--- ASTConsumer.cpp - Abstract interface for reading ASTs --*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file was developed by Ted Kremenek and is distributed under +// the University of Illinois Open Source License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file defines the ASTConsumer class. +// +//===----------------------------------------------------------------------===// + +#include "clang/AST/ASTConsumer.h" +#include "clang/AST/Decl.h" + +using namespace clang; + +void ASTConsumer::HandleTopLevelDeclaration(Decl* d) { + if (ScopedDecl* sd = dyn_cast<ScopedDecl>(d)) + while (sd) { + HandleTopLevelDecl(sd); + sd = sd->getNextDeclarator(); + } + else + HandleTopLevelDecl(d); +} diff --git a/include/clang/AST/ASTConsumer.h b/include/clang/AST/ASTConsumer.h index 160260f030..7221ab789b 100644 --- a/include/clang/AST/ASTConsumer.h +++ b/include/clang/AST/ASTConsumer.h @@ -16,6 +16,7 @@ namespace clang { class ASTContext; + class Decl; /// ASTConsumer - This is an abstract interface that should be implemented by /// clients that read ASTs. This abstraction layer allows the client to be @@ -26,13 +27,19 @@ public: /// Initialize - This is called to initialize the consumer, providing the /// ASTContext and the file ID of the primary file. - virtual void Initialize(ASTContext &Context, unsigned MainFileID) { - } + virtual void Initialize(ASTContext &Context, unsigned MainFileID) {} - /// HandleTopLevelDecl - Handle the specified top-level declaration. - /// - virtual void HandleTopLevelDecl(Decl *D) { - } + /// HandleTopLevelDecl - Handle the specified top-level declaration. This is + /// called by HandleTopLevelDeclaration to process every top-level Decl*. + virtual void HandleTopLevelDecl(Decl *D) {}; + + + /// HandleTopLevelDeclaration - Handle the specified top-level declaration. + /// This is called only for Decl* that are the head of a chain of + /// Decl's (in the case that the Decl* is a ScopedDecl*). Subclasses + /// can override its behavior; by default it calls HandleTopLevelDecl + /// for every Decl* in a decl chain. + virtual void HandleTopLevelDeclaration(Decl *D); /// PrintStats - If desired, print any statistics. virtual void PrintStats() { |