[cfe-commits] r160696 - in /cfe/trunk: include/clang/AST/CommentSema.h include/clang/Basic/DiagnosticCommentKinds.td lib/AST/CommentSema.cpp test/Sema/warn-documentation.cpp
Dmitri Gribenko
gribozavr at gmail.com
Tue Jul 24 14:44:16 PDT 2012
Author: gribozavr
Date: Tue Jul 24 16:44:16 2012
New Revision: 160696
URL: http://llvm.org/viewvc/llvm-project?rev=160696&view=rev
Log:
Comment diagnostics: add warning for multiple \param commands with duplicate
parameter names.
Modified:
cfe/trunk/include/clang/AST/CommentSema.h
cfe/trunk/include/clang/Basic/DiagnosticCommentKinds.td
cfe/trunk/lib/AST/CommentSema.cpp
cfe/trunk/test/Sema/warn-documentation.cpp
Modified: cfe/trunk/include/clang/AST/CommentSema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/CommentSema.h?rev=160696&r1=160695&r2=160696&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/CommentSema.h (original)
+++ cfe/trunk/include/clang/AST/CommentSema.h Tue Jul 24 16:44:16 2012
@@ -46,6 +46,13 @@
/// Contains a valid value if \c IsThisDeclInspected is true.
ArrayRef<const ParmVarDecl *> ParamVars;
+ /// Comment AST nodes that correspond to \c ParamVars for which we have
+ /// found a \\param command or NULL if no documentation was found so far.
+ ///
+ /// Has correct size and contains valid values if \c IsThisDeclInspected is
+ /// true.
+ llvm::SmallVector<ParamCommandComment *, 8> ParamVarDocs;
+
/// True if we extracted all important information from \c ThisDecl into
/// \c Sema members.
unsigned IsThisDeclInspected : 1;
Modified: cfe/trunk/include/clang/Basic/DiagnosticCommentKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticCommentKinds.td?rev=160696&r1=160695&r2=160696&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticCommentKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticCommentKinds.td Tue Jul 24 16:44:16 2012
@@ -63,6 +63,13 @@
"a function declaration">,
InGroup<Documentation>, DefaultIgnore;
+def warn_doc_param_duplicate : Warning<
+ "parameter '%0' is already documented">,
+ InGroup<Documentation>, DefaultIgnore;
+
+def note_doc_param_previous : Note<
+ "previous documentation">;
+
def warn_doc_param_not_found : Warning<
"parameter '%0' not found in the function declaration">,
InGroup<Documentation>, DefaultIgnore;
Modified: cfe/trunk/lib/AST/CommentSema.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/CommentSema.cpp?rev=160696&r1=160695&r2=160696&view=diff
==============================================================================
--- cfe/trunk/lib/AST/CommentSema.cpp (original)
+++ cfe/trunk/lib/AST/CommentSema.cpp Tue Jul 24 16:44:16 2012
@@ -153,6 +153,15 @@
const unsigned ResolvedParamIndex = resolveParmVarReference(Arg, ParamVars);
if (ResolvedParamIndex != ParamCommandComment::InvalidParamIndex) {
Command->setParamIndex(ResolvedParamIndex);
+ if (ParamVarDocs[ResolvedParamIndex]) {
+ SourceRange ArgRange(ArgLocBegin, ArgLocEnd);
+ Diag(ArgLocBegin, diag::warn_doc_param_duplicate)
+ << Arg << ArgRange;
+ ParamCommandComment *PrevCommand = ParamVarDocs[ResolvedParamIndex];
+ Diag(PrevCommand->getLocation(), diag::note_doc_param_previous)
+ << PrevCommand->getParamNameRange();
+ }
+ ParamVarDocs[ResolvedParamIndex] = Command;
return Command;
}
@@ -351,7 +360,6 @@
FullComment *Sema::actOnFullComment(
ArrayRef<BlockContentComment *> Blocks) {
- SmallVector<ParamCommandComment *, 8> Params;
return new (Allocator) FullComment(Blocks);
}
@@ -382,6 +390,7 @@
}
void Sema::inspectThisDecl() {
+ assert(!IsThisDeclInspected);
if (!ThisDecl) {
IsFunctionDecl = false;
ParamVars = ArrayRef<const ParmVarDecl *>();
@@ -397,6 +406,7 @@
IsFunctionDecl = false;
ParamVars = ArrayRef<const ParmVarDecl *>();
}
+ ParamVarDocs.resize(ParamVars.size(), NULL);
IsThisDeclInspected = true;
}
Modified: cfe/trunk/test/Sema/warn-documentation.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/warn-documentation.cpp?rev=160696&r1=160695&r2=160696&view=diff
==============================================================================
--- cfe/trunk/test/Sema/warn-documentation.cpp (original)
+++ cfe/trunk/test/Sema/warn-documentation.cpp Tue Jul 24 16:44:16 2012
@@ -166,6 +166,18 @@
int test_param14(int bbb, int ccc);
};
+// expected-warning at +3 {{parameter 'a' is already documented}}
+// expected-note at +1 {{previous documentation}}
+/// \param a Aaa.
+/// \param a Aaa.
+int test_param15(int a);
+
+// expected-warning at +4 {{parameter 'x2' is already documented}}
+// expected-note at +2 {{previous documentation}}
+/// \param x1 Aaa.
+/// \param x2 Bbb.
+/// \param x2 Ccc.
+int test_param16(int x1, int x2, int x3);
// expected-warning at +1 {{empty paragraph passed to '\brief' command}}
int test1; ///< \brief\brief Aaa
More information about the cfe-commits
mailing list