From: Richard Smith Date: Thu, 7 Feb 2013 01:35:44 +0000 (+0000) Subject: AST dumping: indicate the previous declaration for a redeclaration, and X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=f5f43546b3d63380bbb5fda4e4b012a0cf9c0a34;p=platform%2Fupstream%2Fllvm.git AST dumping: indicate the previous declaration for a redeclaration, and indicate the semantic DC if it's not the lexical DC. In passing, correct the ascii-art child marker for a child of a FriendDecl. llvm-svn: 174570 --- diff --git a/clang/lib/AST/ASTDumper.cpp b/clang/lib/AST/ASTDumper.cpp index 646cb16..3f221a7 100644 --- a/clang/lib/AST/ASTDumper.cpp +++ b/clang/lib/AST/ASTDumper.cpp @@ -511,6 +511,27 @@ void ASTDumper::dumpAttr(const Attr *A) { #include "clang/AST/AttrDump.inc" } +static Decl *getPreviousDeclImpl(...) { + return 0; +} + +template +static const Decl *getPreviousDeclImpl(const Redeclarable *D) { + return D->getPreviousDecl(); +} + +/// Get the previous declaration in the redeclaration chain for a declaration. +static const Decl *getPreviousDecl(const Decl *D) { + switch (D->getKind()) { +#define DECL(DERIVED, BASE) \ + case Decl::DERIVED: \ + return getPreviousDeclImpl(cast(D)); +#define ABSTRACT_DECL(DECL) +#include "clang/AST/DeclNodes.inc" + } + llvm_unreachable("Decl that isn't part of DeclNodes.inc!"); +} + //===----------------------------------------------------------------------===// // C++ Utilities //===----------------------------------------------------------------------===// @@ -639,6 +660,10 @@ void ASTDumper::dumpDecl(const Decl *D) { OS << D->getDeclKindName() << "Decl"; } dumpPointer(D); + if (D->getLexicalDeclContext() != D->getDeclContext()) + OS << " parent " << cast(D->getDeclContext()); + if (const Decl *Prev = getPreviousDecl(D)) + OS << " prev " << Prev; dumpSourceRange(D->getSourceRange()); bool HasAttrs = D->attr_begin() != D->attr_end(); @@ -664,7 +689,7 @@ void ASTDumper::dumpDecl(const Decl *D) { setMoreChildren(false); if (HasDeclContext) - dumpDeclContext(dyn_cast(D)); + dumpDeclContext(cast(D)); } void ASTDumper::VisitLabelDecl(const LabelDecl *D) { @@ -1049,6 +1074,7 @@ void ASTDumper::VisitAccessSpecDecl(const AccessSpecDecl *D) { } void ASTDumper::VisitFriendDecl(const FriendDecl *D) { + lastChild(); if (TypeSourceInfo *T = D->getFriendType()) dumpType(T->getType()); else diff --git a/clang/test/Misc/ast-dump-decl.cpp b/clang/test/Misc/ast-dump-decl.cpp index ab847ca..d8072b7 100644 --- a/clang/test/Misc/ast-dump-decl.cpp +++ b/clang/test/Misc/ast-dump-decl.cpp @@ -403,3 +403,16 @@ namespace TestFileScopeAsmDecl { // CHECK: NamespaceDecl{{.*}} TestFileScopeAsmDecl{{$}} // CHECK: FileScopeAsmDecl{{.*>$}} // CHECK-NEXT: StringLiteral + +namespace TestFriendDecl2 { + void f(); + struct S { + friend void f(); + }; +} +// CHECK: NamespaceDecl [[TestFriendDecl2:0x.*]] <{{.*}}> TestFriendDecl2 +// CHECK: |-FunctionDecl [[TestFriendDecl2_f:0x.*]] <{{.*}}> f 'void (void)' +// CHECK: `-CXXRecordDecl {{.*}} struct S +// CHECK: |-CXXRecordDecl {{.*}} struct S +// CHECK: `-FriendDecl +// CHECK: `-FunctionDecl {{.*}} parent [[TestFriendDecl2]] prev [[TestFriendDecl2_f]] <{{.*}}> f 'void (void)'