[cfe-commits] r90974 - in /cfe/trunk: include/clang/AST/DeclBase.h lib/AST/DeclPrinter.cpp

Anders Carlsson andersca at mac.com
Wed Dec 9 09:27:46 PST 2009


Author: andersca
Date: Wed Dec  9 11:27:46 2009
New Revision: 90974

URL: http://llvm.org/viewvc/llvm-project?rev=90974&view=rev
Log:
Add DeclContext::dump.

Modified:
    cfe/trunk/include/clang/AST/DeclBase.h
    cfe/trunk/lib/AST/DeclPrinter.cpp

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

==============================================================================
--- cfe/trunk/include/clang/AST/DeclBase.h (original)
+++ cfe/trunk/include/clang/AST/DeclBase.h Wed Dec  9 11:27:46 2009
@@ -1003,6 +1003,8 @@
   static bool classof(const Name##Decl *D) { return true; }
 #include "clang/AST/DeclNodes.def"
 
+  void dump() const;
+
 private:
   void LoadLexicalDeclsFromExternalStorage() const;
   void LoadVisibleDeclsFromExternalStorage() const;

Modified: cfe/trunk/lib/AST/DeclPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclPrinter.cpp?rev=90974&r1=90973&r2=90974&view=diff

==============================================================================
--- cfe/trunk/lib/AST/DeclPrinter.cpp (original)
+++ cfe/trunk/lib/AST/DeclPrinter.cpp Wed Dec  9 11:27:46 2009
@@ -148,6 +148,17 @@
   }
 }
 
+void DeclContext::dump() const {
+  // Get the translation unit
+  const DeclContext *DC = this;
+  while (!DC->isTranslationUnit())
+    DC = DC->getParent();
+  
+  ASTContext &Ctx = cast<TranslationUnitDecl>(DC)->getASTContext();
+  DeclPrinter Printer(llvm::errs(), Ctx, Ctx.PrintingPolicy, 0);
+  Printer.VisitDeclContext(const_cast<DeclContext *>(this), /*Indent=*/false);
+}
+
 void Decl::dump() const {
   print(llvm::errs());
 }





More information about the cfe-commits mailing list