summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTed Kremenek <kremenek@apple.com>2007-11-29 23:05:17 +0000
committerTed Kremenek <kremenek@apple.com>2007-11-29 23:05:17 +0000
commitbfcf8cdbd72f368f3662002ab73fd3d9e39e94eb (patch)
treeabf49685a8630f93970479a150b475ba09174960
parentd35b5acae4dc424fa49e13e080bcf65e9e0f4992 (diff)
downloadbcm5719-llvm-bfcf8cdbd72f368f3662002ab73fd3d9e39e94eb.tar.gz
bcm5719-llvm-bfcf8cdbd72f368f3662002ab73fd3d9e39e94eb.zip
Added method "HandleTopLevelDeclaration" to ASTConsumer. This will eventually
be the new hook that ASTStreamer calls to feed top-level Decls to ASTConsumers. The difference between "HandleTopLevelDeclaration" and "HandleTopLevelDecl" is that "HandleTopLevelDecl" is currently called by ASTStreamer for every top-level declaration, including those that appear within a Decl chain. Using the new interface, ASTStreamer would only call HandleTopLevelDeclaration for Decls that appear that the beginning of a Decl chain (i.e., a group of related decls). To preserve the behavior that all subclasses of ASTConsumer currently expect, the default implementation of HandleTopLevelDeclaration simply calls HandleTopLevelDecl, and for decl chains it calls HandleTopLevelDecl for each Decl* in a chain of Decls. The advantage of this interface is that some subclasses of ASTConsumer only really want the Decl chain, and not each individual Decl passed to them. This extra level of indirection allows subclasses to override the default behavior if they so desire. llvm-svn: 44444
-rw-r--r--clang/AST/ASTConsumer.cpp27
-rw-r--r--clang/include/clang/AST/ASTConsumer.h19
2 files changed, 40 insertions, 6 deletions
diff --git a/clang/AST/ASTConsumer.cpp b/clang/AST/ASTConsumer.cpp
new file mode 100644
index 00000000000..0cf614102d0
--- /dev/null
+++ b/clang/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/clang/include/clang/AST/ASTConsumer.h b/clang/include/clang/AST/ASTConsumer.h
index 160260f030b..7221ab789b3 100644
--- a/clang/include/clang/AST/ASTConsumer.h
+++ b/clang/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() {
OpenPOWER on IntegriCloud