From: Richard Smith Date: Tue, 21 May 2013 05:24:00 +0000 (+0000) Subject: In -ast-dump, only dump comments when dumping the actual Decl to which they X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=0a74a4ccc4ecfe1a2792ab72c83815323d8fc914;p=clang In -ast-dump, only dump comments when dumping the actual Decl to which they attach, rather than merging all comments on the declaration chain. This gives a more faithful dump, and has the side benefit of unbreaking uses of dump() from within AST deserialization (where the redeclaration chain may not be sane). git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@182350 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/AST/ASTContext.h b/include/clang/AST/ASTContext.h index 2d08c49e1d..94dad6bbc3 100644 --- a/include/clang/AST/ASTContext.h +++ b/include/clang/AST/ASTContext.h @@ -580,7 +580,12 @@ public: /// preprocessor is not available. comments::FullComment *getCommentForDecl(const Decl *D, const Preprocessor *PP) const; - + + /// Return parsed documentation comment attached to a given declaration. + /// Returns NULL if no comment is attached. Does not look at any + /// redeclarations of the declaration. + comments::FullComment *getLocalCommentForDeclUncached(const Decl *D) const; + comments::FullComment *cloneFullComment(comments::FullComment *FC, const Decl *D) const; diff --git a/lib/AST/ASTContext.cpp b/lib/AST/ASTContext.cpp index b19150f048..f2dda23b4d 100644 --- a/lib/AST/ASTContext.cpp +++ b/lib/AST/ASTContext.cpp @@ -406,6 +406,11 @@ comments::FullComment *ASTContext::cloneFullComment(comments::FullComment *FC, } +comments::FullComment *ASTContext::getLocalCommentForDeclUncached(const Decl *D) const { + const RawComment *RC = getRawCommentForDeclNoCache(D); + return RC ? RC->parse(*this, 0, D) : 0; +} + comments::FullComment *ASTContext::getCommentForDecl( const Decl *D, const Preprocessor *PP) const { diff --git a/lib/AST/ASTDumper.cpp b/lib/AST/ASTDumper.cpp index 4a0173300d..8cf41f5db6 100644 --- a/lib/AST/ASTDumper.cpp +++ b/lib/AST/ASTDumper.cpp @@ -665,15 +665,16 @@ void ASTDumper::dumpDecl(const Decl *D) { dumpSourceRange(D->getSourceRange()); bool HasAttrs = D->attr_begin() != D->attr_end(); - bool HasComment = D->getASTContext().getCommentForDecl(D, 0); + const FullComment *Comment = + D->getASTContext().getLocalCommentForDeclUncached(D); // Decls within functions are visited by the body bool HasDeclContext = !isa(*D) && !isa(*D) && hasNodes(dyn_cast(D)); - setMoreChildren(HasAttrs || HasComment || HasDeclContext); + setMoreChildren(HasAttrs || Comment || HasDeclContext); ConstDeclVisitor::Visit(D); - setMoreChildren(HasComment || HasDeclContext); + setMoreChildren(Comment || HasDeclContext); for (Decl::attr_iterator I = D->attr_begin(), E = D->attr_end(); I != E; ++I) { if (I + 1 == E) @@ -683,7 +684,7 @@ void ASTDumper::dumpDecl(const Decl *D) { setMoreChildren(HasDeclContext); lastChild(); - dumpFullComment(D->getASTContext().getCommentForDecl(D, 0)); + dumpFullComment(Comment); setMoreChildren(false); if (HasDeclContext) diff --git a/test/Misc/ast-dump-decl.cpp b/test/Misc/ast-dump-decl.cpp index 31715cd15e..d98bdb56d5 100644 --- a/test/Misc/ast-dump-decl.cpp +++ b/test/Misc/ast-dump-decl.cpp @@ -458,3 +458,19 @@ namespace TestFriendDecl2 { // CHECK: |-CXXRecordDecl {{.*}} struct S // CHECK: `-FriendDecl // CHECK: `-FunctionDecl {{.*}} parent [[TestFriendDecl2]] prev [[TestFriendDecl2_f]] <{{.*}}> f 'void (void)' + +namespace Comment { + extern int Test; + /// Something here. + extern int Test; + extern int Test; +} + +// CHECK: VarDecl {{.*}} Test 'int' extern +// CHECK-NOT: FullComment +// CHECK: VarDecl {{.*}} Test 'int' extern +// CHECK: `-FullComment +// CHECK: `-ParagraphComment +// CHECK: `-TextComment +// CHECK: VarDecl {{.*}} Test 'int' extern +// CHECK-NOT: FullComment