[cfe-commits] r44444 - in /cfe/trunk: AST/ASTConsumer.cpp include/clang/AST/ASTConsumer.h

Ted Kremenek kremenek at apple.com
Thu Nov 29 15:05:17 PST 2007


Author: kremenek
Date: Thu Nov 29 17:05:17 2007
New Revision: 44444

URL: http://llvm.org/viewvc/llvm-project?rev=44444&view=rev
Log:
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.

Added:
    cfe/trunk/AST/ASTConsumer.cpp
Modified:
    cfe/trunk/include/clang/AST/ASTConsumer.h

Added: cfe/trunk/AST/ASTConsumer.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/AST/ASTConsumer.cpp?rev=44444&view=auto

==============================================================================
--- cfe/trunk/AST/ASTConsumer.cpp (added)
+++ cfe/trunk/AST/ASTConsumer.cpp Thu Nov 29 17:05:17 2007
@@ -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);
+}

Modified: cfe/trunk/include/clang/AST/ASTConsumer.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ASTConsumer.h?rev=44444&r1=44443&r2=44444&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/ASTConsumer.h (original)
+++ cfe/trunk/include/clang/AST/ASTConsumer.h Thu Nov 29 17:05:17 2007
@@ -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 @@
   
   /// 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() {





More information about the cfe-commits mailing list