diff options
| author | Richard Smith <richard-llvm@metafoo.co.uk> | 2013-05-21 05:24:00 +0000 |
|---|---|---|
| committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2013-05-21 05:24:00 +0000 |
| commit | b39b9d57350edbb7116715042fe7543dacba5fb4 (patch) | |
| tree | 12657bb188a94d132ea38728e24c2a2816d9a831 | |
| parent | db142d4e1e64de6288803741683f97660c4a8981 (diff) | |
| download | bcm5719-llvm-b39b9d57350edbb7116715042fe7543dacba5fb4.tar.gz bcm5719-llvm-b39b9d57350edbb7116715042fe7543dacba5fb4.zip | |
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).
llvm-svn: 182350
| -rw-r--r-- | clang/include/clang/AST/ASTContext.h | 7 | ||||
| -rw-r--r-- | clang/lib/AST/ASTContext.cpp | 5 | ||||
| -rw-r--r-- | clang/lib/AST/ASTDumper.cpp | 9 | ||||
| -rw-r--r-- | clang/test/Misc/ast-dump-decl.cpp | 16 |
4 files changed, 32 insertions, 5 deletions
diff --git a/clang/include/clang/AST/ASTContext.h b/clang/include/clang/AST/ASTContext.h index 2d08c49e1d0..94dad6bbc3a 100644 --- a/clang/include/clang/AST/ASTContext.h +++ b/clang/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/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp index b19150f0485..f2dda23b4d5 100644 --- a/clang/lib/AST/ASTContext.cpp +++ b/clang/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/clang/lib/AST/ASTDumper.cpp b/clang/lib/AST/ASTDumper.cpp index 4a0173300d8..8cf41f5db66 100644 --- a/clang/lib/AST/ASTDumper.cpp +++ b/clang/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<FunctionDecl>(*D) && !isa<ObjCMethodDecl>(*D) && hasNodes(dyn_cast<DeclContext>(D)); - setMoreChildren(HasAttrs || HasComment || HasDeclContext); + setMoreChildren(HasAttrs || Comment || HasDeclContext); ConstDeclVisitor<ASTDumper>::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/clang/test/Misc/ast-dump-decl.cpp b/clang/test/Misc/ast-dump-decl.cpp index 31715cd15e4..d98bdb56d5b 100644 --- a/clang/test/Misc/ast-dump-decl.cpp +++ b/clang/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 |

