From: Fariborz Jahanian Date: Thu, 18 Oct 2012 21:42:42 +0000 (+0000) Subject: [doc parsing] use getParamName to access parameter X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=262e60c1ccb5197e8e2ea49ada1196ed65183734;p=clang [doc parsing] use getParamName to access parameter for current(rewritten) comment and getParamNameAsWritten to access param name coming with \param marker. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@166231 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/AST/Comment.h b/include/clang/AST/Comment.h index 600046b899..33a24df43d 100644 --- a/include/clang/AST/Comment.h +++ b/include/clang/AST/Comment.h @@ -707,6 +707,10 @@ public: } StringRef getParamName(comments::FullComment *FC) const; + + StringRef getParamNameAsWritten() const { + return Args[0].Text; + } SourceRange getParamNameRange() const { return Args[0].Range; @@ -760,6 +764,10 @@ public: } StringRef getParamName(comments::FullComment *FC) const; + + StringRef getParamNameAsWritten() const { + return Args[0].Text; + } SourceRange getParamNameRange() const { return Args[0].Range; diff --git a/lib/AST/Comment.cpp b/lib/AST/Comment.cpp index 03b58a7aa3..edb0f60fdf 100644 --- a/lib/AST/Comment.cpp +++ b/lib/AST/Comment.cpp @@ -306,24 +306,22 @@ void DeclInfo::fill() { } StringRef ParamCommandComment::getParamName(comments::FullComment *FC) const { - if (FC && isParamIndexValid()) - return FC->getThisDeclInfo()->ParamVars[getParamIndex()]->getName(); - return Args[0].Text; + assert(isParamIndexValid()); + return FC->getThisDeclInfo()->ParamVars[getParamIndex()]->getName(); } StringRef TParamCommandComment::getParamName(comments::FullComment *FC) const { - if (FC && isPositionValid()) { - const TemplateParameterList *TPL = FC->getThisDeclInfo()->TemplateParameters; - for (unsigned i = 0, e = getDepth(); i != e; ++i) { - if (i == e-1) - return TPL->getParam(getIndex(i))->getName(); - const NamedDecl *Param = TPL->getParam(getIndex(i)); - if (const TemplateTemplateParmDecl *TTP = + assert(isPositionValid()); + const TemplateParameterList *TPL = FC->getThisDeclInfo()->TemplateParameters; + for (unsigned i = 0, e = getDepth(); i != e; ++i) { + if (i == e-1) + return TPL->getParam(getIndex(i))->getName(); + const NamedDecl *Param = TPL->getParam(getIndex(i)); + if (const TemplateTemplateParmDecl *TTP = dyn_cast(Param)) - TPL = TTP->getTemplateParameters(); - } + TPL = TTP->getTemplateParameters(); } - return Args[0].Text; + return ""; } } // end namespace comments diff --git a/lib/AST/CommentDumper.cpp b/lib/AST/CommentDumper.cpp index 4f51cd5622..18ba47ff6c 100644 --- a/lib/AST/CommentDumper.cpp +++ b/lib/AST/CommentDumper.cpp @@ -186,8 +186,12 @@ void CommentDumper::visitParamCommandComment(const ParamCommandComment *C) { else OS << " implicitly"; - if (C->hasParamName()) - OS << " Param=\"" << C->getParamName(const_cast(FC)) << "\""; + if (C->hasParamName()) { + if (C->isParamIndexValid()) + OS << " Param=\"" << C->getParamName(const_cast(FC)) << "\""; + else + OS << " Param=\"" << C->getParamNameAsWritten() << "\""; + } if (C->isParamIndexValid()) OS << " ParamIndex=" << C->getParamIndex(); @@ -197,7 +201,10 @@ void CommentDumper::visitTParamCommandComment(const TParamCommandComment *C) { dumpComment(C); if (C->hasParamName()) { - OS << " Param=\"" << C->getParamName(const_cast(FC)) << "\""; + if (C->isPositionValid()) + OS << " Param=\"" << C->getParamName(const_cast(FC)) << "\""; + else + OS << " Param=\"" << C->getParamNameAsWritten() << "\""; } if (C->isPositionValid()) { diff --git a/lib/AST/CommentSema.cpp b/lib/AST/CommentSema.cpp index d664bdb632..08ecb3a994 100644 --- a/lib/AST/CommentSema.cpp +++ b/lib/AST/CommentSema.cpp @@ -574,7 +574,7 @@ void Sema::resolveParamCommandIndexes(const FullComment *FC) { ParamCommandComment *PCC = dyn_cast(*I); if (!PCC || !PCC->hasParamName()) continue; - StringRef ParamName = PCC->getParamName(0); + StringRef ParamName = PCC->getParamNameAsWritten(); // Check that referenced parameter name is in the function decl. const unsigned ResolvedParamIndex = resolveParmVarReference(ParamName, @@ -609,7 +609,7 @@ void Sema::resolveParamCommandIndexes(const FullComment *FC) { const ParamCommandComment *PCC = UnresolvedParamCommands[i]; SourceRange ArgRange = PCC->getParamNameRange(); - StringRef ParamName = PCC->getParamName(0); + StringRef ParamName = PCC->getParamNameAsWritten(); Diag(ArgRange.getBegin(), diag::warn_doc_param_not_found) << ParamName << ArgRange; diff --git a/tools/libclang/CXComment.cpp b/tools/libclang/CXComment.cpp index 90a67ca69c..6f3f382444 100644 --- a/tools/libclang/CXComment.cpp +++ b/tools/libclang/CXComment.cpp @@ -255,7 +255,7 @@ CXString clang_ParamCommandComment_getParamName(CXComment CXC) { if (!PCC || !PCC->hasParamName()) return createCXString((const char *) 0); - return createCXString(PCC->getParamName(0), /*DupString=*/ false); + return createCXString(PCC->getParamNameAsWritten(), /*DupString=*/ false); } unsigned clang_ParamCommandComment_isParamIndexValid(CXComment CXC) { @@ -306,7 +306,7 @@ CXString clang_TParamCommandComment_getParamName(CXComment CXC) { if (!TPCC || !TPCC->hasParamName()) return createCXString((const char *) 0); - return createCXString(TPCC->getParamName(0), /*DupString=*/ false); + return createCXString(TPCC->getParamNameAsWritten(), /*DupString=*/ false); } unsigned clang_TParamCommandComment_isParamPositionValid(CXComment CXC) { @@ -669,10 +669,11 @@ void CommentASTToHTMLConverter::visitParamCommandComment( Result << "
getParamIndex() << "\">"; - } else + appendToResultWithHTMLEscaping(C->getParamName(FC)); + } else { Result << "
"; - - appendToResultWithHTMLEscaping(C->getParamName(FC)); + appendToResultWithHTMLEscaping(C->getParamNameAsWritten()); + } Result << "
"; if (C->isParamIndexValid()) { @@ -695,10 +696,12 @@ void CommentASTToHTMLConverter::visitTParamCommandComment( << "\">"; else Result << "
"; - } else + appendToResultWithHTMLEscaping(C->getParamName(FC)); + } else { Result << "
"; - - appendToResultWithHTMLEscaping(C->getParamName(FC)); + appendToResultWithHTMLEscaping(C->getParamNameAsWritten()); + } + Result << "
"; if (C->isPositionValid()) { @@ -961,7 +964,8 @@ void CommentASTToXMLConverter::visitBlockCommandComment(const BlockCommandCommen void CommentASTToXMLConverter::visitParamCommandComment(const ParamCommandComment *C) { Result << ""; - appendToResultWithXMLEscaping(C->getParamName(FC)); + appendToResultWithXMLEscaping(C->isParamIndexValid() ? C->getParamName(FC) + : C->getParamNameAsWritten()); Result << ""; if (C->isParamIndexValid()) @@ -987,7 +991,8 @@ void CommentASTToXMLConverter::visitParamCommandComment(const ParamCommandCommen void CommentASTToXMLConverter::visitTParamCommandComment( const TParamCommandComment *C) { Result << ""; - appendToResultWithXMLEscaping(C->getParamName(FC)); + appendToResultWithXMLEscaping(C->isPositionValid() ? C->getParamName(FC) + : C->getParamNameAsWritten()); Result << ""; if (C->isPositionValid() && C->getDepth() == 1) { diff --git a/unittests/AST/CommentParser.cpp b/unittests/AST/CommentParser.cpp index 01ece2e41f..e4226e7d3d 100644 --- a/unittests/AST/CommentParser.cpp +++ b/unittests/AST/CommentParser.cpp @@ -213,7 +213,7 @@ template return ::testing::AssertionFailure() << "ParamCommandComment has no parameter name"; - StringRef ActualParamName = PCC->hasParamName() ? PCC->getParamName(0) : ""; + StringRef ActualParamName = PCC->hasParamName() ? PCC->getParamNameAsWritten() : ""; if (ActualParamName != ParamName) return ::testing::AssertionFailure() << "ParamCommandComment has parameter name \"" << ActualParamName.str() @@ -247,7 +247,7 @@ template return ::testing::AssertionFailure() << "TParamCommandComment has no parameter name"; - StringRef ActualParamName = TPCC->hasParamName() ? TPCC->getParamName(0) : ""; + StringRef ActualParamName = TPCC->hasParamName() ? TPCC->getParamNameAsWritten() : ""; if (ActualParamName != ParamName) return ::testing::AssertionFailure() << "TParamCommandComment has parameter name \"" << ActualParamName.str()