]> granicus.if.org Git - clang/commitdiff
Add DeclContext::dump.
authorAnders Carlsson <andersca@mac.com>
Wed, 9 Dec 2009 17:27:46 +0000 (17:27 +0000)
committerAnders Carlsson <andersca@mac.com>
Wed, 9 Dec 2009 17:27:46 +0000 (17:27 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@90974 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/AST/DeclBase.h
lib/AST/DeclPrinter.cpp

index e1f948fdd550c2e61c6bc8f6ac2a7636eab8783c..ab54ddfe04616abc00a32ccf8ba1199f6aaf597e 100644 (file)
@@ -1003,6 +1003,8 @@ public:
   static bool classof(const Name##Decl *D) { return true; }
 #include "clang/AST/DeclNodes.def"
 
+  void dump() const;
+
 private:
   void LoadLexicalDeclsFromExternalStorage() const;
   void LoadVisibleDeclsFromExternalStorage() const;
index adf7ed3b0e2d479c5f93b20e5ceb0e24b20827aa..ed16b33116d64a5533e2bc5fad40555ff03e5b28 100644 (file)
@@ -148,6 +148,17 @@ void Decl::printGroup(Decl** Begin, unsigned NumDecls,
   }
 }
 
+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());
 }