]> granicus.if.org Git - clang/commitdiff
Added method "HandleTopLevelDeclaration" to ASTConsumer. This will eventually
authorTed Kremenek <kremenek@apple.com>
Thu, 29 Nov 2007 23:05:17 +0000 (23:05 +0000)
committerTed Kremenek <kremenek@apple.com>
Thu, 29 Nov 2007 23:05:17 +0000 (23:05 +0000)
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.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@44444 91177308-0d34-0410-b5e6-96231b3b80d8

AST/ASTConsumer.cpp [new file with mode: 0644]
include/clang/AST/ASTConsumer.h

diff --git a/AST/ASTConsumer.cpp b/AST/ASTConsumer.cpp
new file mode 100644 (file)
index 0000000..0cf6141
--- /dev/null
@@ -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);
+}
index 160260f030bc615ccb7667d6a4c5093fdfd0aa65..7221ab789b33859affa9f65b211f73c756673041 100644 (file)
@@ -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() {