[cfe-commits] r165771 - in /cfe/trunk: include/clang/AST/ASTContext.h include/clang/AST/Comment.h lib/AST/ASTContext.cpp lib/AST/Comment.cpp lib/AST/CommentSema.cpp test/Index/overriding-method-comments.mm tools/libclang/CXComment.cpp
Fariborz Jahanian
fjahanian at apple.com
Thu Oct 11 16:52:51 PDT 2012
Author: fjahanian
Date: Thu Oct 11 18:52:50 2012
New Revision: 165771
URL: http://llvm.org/viewvc/llvm-project?rev=165771&view=rev
Log:
search for overridden methods with comment when overriding method
has none of its own. Factor in Doug's comments.
// rdar://12378793
Modified:
cfe/trunk/include/clang/AST/ASTContext.h
cfe/trunk/include/clang/AST/Comment.h
cfe/trunk/lib/AST/ASTContext.cpp
cfe/trunk/lib/AST/Comment.cpp
cfe/trunk/lib/AST/CommentSema.cpp
cfe/trunk/test/Index/overriding-method-comments.mm
cfe/trunk/tools/libclang/CXComment.cpp
Modified: cfe/trunk/include/clang/AST/ASTContext.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ASTContext.h?rev=165771&r1=165770&r2=165771&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/ASTContext.h (original)
+++ cfe/trunk/include/clang/AST/ASTContext.h Thu Oct 11 18:52:50 2012
@@ -537,6 +537,9 @@
/// preprocessor is not available.
comments::FullComment *getCommentForDecl(const Decl *D,
const Preprocessor *PP) const;
+
+ comments::FullComment *cloneFullComment(comments::FullComment *FC,
+ const Decl *D) const;
private:
mutable comments::CommandTraits CommentCommandTraits;
Modified: cfe/trunk/include/clang/AST/Comment.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Comment.h?rev=165771&r1=165770&r2=165771&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Comment.h (original)
+++ cfe/trunk/include/clang/AST/Comment.h Thu Oct 11 18:52:50 2012
@@ -27,7 +27,7 @@
class TemplateParameterList;
namespace comments {
-
+class FullComment;
/// Any part of the comment.
/// Abstract class.
class Comment {
@@ -706,19 +706,7 @@
return getNumArgs() > 0;
}
- StringRef getParamName(const Decl *OverridingDecl) const {
- if (OverridingDecl && isParamIndexValid()) {
- if (const ObjCMethodDecl *OMD = dyn_cast<ObjCMethodDecl>(OverridingDecl)) {
- const ParmVarDecl *ParamDecl = OMD->param_begin()[getParamIndex()];
- return ParamDecl->getName();
- }
- else if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(OverridingDecl)) {
- const ParmVarDecl *ParamDecl = FD->param_begin()[getParamIndex()];
- return ParamDecl->getName();
- }
- }
- return Args[0].Text;
- }
+ StringRef getParamName(comments::FullComment *FC) const;
SourceRange getParamNameRange() const {
return Args[0].Range;
@@ -1017,18 +1005,12 @@
/// A full comment attached to a declaration, contains block content.
class FullComment : public Comment {
llvm::ArrayRef<BlockContentComment *> Blocks;
-
DeclInfo *ThisDeclInfo;
- /// Declaration that a comment is being looked for. This declaration and
- /// CommentDecl in ThisDeclInfo are generally the same. But they could be
- /// different when ThisDecl does not have comment and uses CommentDecl's comment.
- const Decl *ThisDecl;
public:
- FullComment(llvm::ArrayRef<BlockContentComment *> Blocks, DeclInfo *D,
- Decl *TD) :
+ FullComment(llvm::ArrayRef<BlockContentComment *> Blocks, DeclInfo *D) :
Comment(FullCommentKind, SourceLocation(), SourceLocation()),
- Blocks(Blocks), ThisDeclInfo(D), ThisDecl(TD) {
+ Blocks(Blocks), ThisDeclInfo(D) {
if (Blocks.empty())
return;
@@ -1046,16 +1028,12 @@
}
child_iterator child_end() const {
- return reinterpret_cast<child_iterator>(Blocks.end());
+ return reinterpret_cast<child_iterator>(Blocks.end());
}
const Decl *getDecl() const LLVM_READONLY {
return ThisDeclInfo->CommentDecl;
}
-
- const Decl *getDeclForCommentLookup() const LLVM_READONLY {
- return ThisDecl;
- }
const DeclInfo *getDeclInfo() const LLVM_READONLY {
if (!ThisDeclInfo->IsFilled)
@@ -1070,7 +1048,6 @@
llvm::ArrayRef<BlockContentComment *> getBlocks() const { return Blocks; }
};
-
} // end namespace comments
} // end namespace clang
Modified: cfe/trunk/lib/AST/ASTContext.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTContext.cpp?rev=165771&r1=165770&r2=165771&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ASTContext.cpp (original)
+++ cfe/trunk/lib/AST/ASTContext.cpp Thu Oct 11 18:52:50 2012
@@ -374,6 +374,20 @@
}
}
+comments::FullComment *ASTContext::cloneFullComment(comments::FullComment *FC,
+ const Decl *D) const {
+ comments::DeclInfo *ThisDeclInfo = new (*this) comments::DeclInfo;
+ ThisDeclInfo->CommentDecl = D;
+ ThisDeclInfo->IsFilled = false;
+ ThisDeclInfo->fill();
+ ThisDeclInfo->CommentDecl = FC->getDecl();
+ comments::FullComment *CFC =
+ new (*this) comments::FullComment(FC->getBlocks(),
+ ThisDeclInfo);
+ return CFC;
+
+}
+
comments::FullComment *ASTContext::getCommentForDecl(
const Decl *D,
const Preprocessor *PP) const {
@@ -384,16 +398,9 @@
ParsedComments.find(Canonical);
if (Pos != ParsedComments.end()) {
- if (Canonical != D &&
- (isa<ObjCMethodDecl>(D) || isa<FunctionDecl>(D))) {
- // case of method being redeclaration of the canonical, not
- // overriding it; i.e. method in implementation, canonical in
- // interface. Or, out-of-line cxx-method definition.
+ if (Canonical != D) {
comments::FullComment *FC = Pos->second;
- comments::FullComment *CFC =
- new (*this) comments::FullComment(FC->getBlocks(),
- FC->getThisDeclInfo(),
- const_cast<Decl *>(D));
+ comments::FullComment *CFC = cloneFullComment(FC, D);
return CFC;
}
return Pos->second;
@@ -411,10 +418,7 @@
overridden);
for (unsigned i = 0, e = overridden.size(); i < e; i++) {
if (comments::FullComment *FC = getCommentForDecl(overridden[i], PP)) {
- comments::FullComment *CFC =
- new (*this) comments::FullComment(FC->getBlocks(),
- FC->getThisDeclInfo(),
- const_cast<Decl *>(D));
+ comments::FullComment *CFC = cloneFullComment(FC, D);
return CFC;
}
}
Modified: cfe/trunk/lib/AST/Comment.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Comment.cpp?rev=165771&r1=165770&r2=165771&view=diff
==============================================================================
--- cfe/trunk/lib/AST/Comment.cpp (original)
+++ cfe/trunk/lib/AST/Comment.cpp Thu Oct 11 18:52:50 2012
@@ -304,6 +304,12 @@
IsFilled = true;
}
+StringRef ParamCommandComment::getParamName(comments::FullComment *FC) const {
+ if (FC && isParamIndexValid())
+ return FC->getThisDeclInfo()->ParamVars[getParamIndex()]->getName();
+ return Args[0].Text;
+}
+
} // end namespace comments
} // end namespace clang
Modified: cfe/trunk/lib/AST/CommentSema.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/CommentSema.cpp?rev=165771&r1=165770&r2=165771&view=diff
==============================================================================
--- cfe/trunk/lib/AST/CommentSema.cpp (original)
+++ cfe/trunk/lib/AST/CommentSema.cpp Thu Oct 11 18:52:50 2012
@@ -413,7 +413,7 @@
FullComment *Sema::actOnFullComment(
ArrayRef<BlockContentComment *> Blocks) {
- FullComment *FC = new (Allocator) FullComment(Blocks, ThisDeclInfo, 0);
+ FullComment *FC = new (Allocator) FullComment(Blocks, ThisDeclInfo);
resolveParamCommandIndexes(FC);
return FC;
}
Modified: cfe/trunk/test/Index/overriding-method-comments.mm
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/overriding-method-comments.mm?rev=165771&r1=165770&r2=165771&view=diff
==============================================================================
--- cfe/trunk/test/Index/overriding-method-comments.mm (original)
+++ cfe/trunk/test/Index/overriding-method-comments.mm Thu Oct 11 18:52:50 2012
@@ -2,7 +2,7 @@
// RUN: mkdir %t
// RUN: c-index-test -test-load-source all -comments-xml-schema=%S/../../bindings/xml/comment-xml-schema.rng %s > %t/out
// RUN: FileCheck %s < %t/out
-// rdar://12378793
+// Test to search overridden methods for documentation when overriding method has none. rdar://12378793
// Ensure that XML we generate is not invalid.
// RUN: FileCheck %s -check-prefix=WRONG < %t/out
Modified: cfe/trunk/tools/libclang/CXComment.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CXComment.cpp?rev=165771&r1=165770&r2=165771&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/CXComment.cpp (original)
+++ cfe/trunk/tools/libclang/CXComment.cpp Thu Oct 11 18:52:50 2012
@@ -671,7 +671,7 @@
} else
Result << "<dt class=\"param-name-index-invalid\">";
- appendToResultWithHTMLEscaping(C->getParamName(FC->getDeclForCommentLookup()));
+ appendToResultWithHTMLEscaping(C->getParamName(FC));
Result << "</dt>";
if (C->isParamIndexValid()) {
@@ -960,7 +960,7 @@
void CommentASTToXMLConverter::visitParamCommandComment(const ParamCommandComment *C) {
Result << "<Parameter><Name>";
- appendToResultWithXMLEscaping(C->getParamName(FC->getDeclForCommentLookup()));
+ appendToResultWithXMLEscaping(C->getParamName(FC));
Result << "</Name>";
if (C->isParamIndexValid())
More information about the cfe-commits
mailing list