summaryrefslogtreecommitdiffstats
path: root/clang
diff options
context:
space:
mode:
authorDmitri Gribenko <gribozavr@gmail.com>2012-07-24 21:44:16 +0000
committerDmitri Gribenko <gribozavr@gmail.com>2012-07-24 21:44:16 +0000
commit8f0f1b0c41cd7667aa92a7f1307d9f00047394ba (patch)
tree11de1b8f5de6603cee8a70b44e41bb85efee881b /clang
parenta44e193a11a5e8aa6fcbe6b4b65638ff2d0b0e26 (diff)
downloadbcm5719-llvm-8f0f1b0c41cd7667aa92a7f1307d9f00047394ba.tar.gz
bcm5719-llvm-8f0f1b0c41cd7667aa92a7f1307d9f00047394ba.zip
Comment diagnostics: add warning for multiple \param commands with duplicate
parameter names. llvm-svn: 160696
Diffstat (limited to 'clang')
-rw-r--r--clang/include/clang/AST/CommentSema.h7
-rw-r--r--clang/include/clang/Basic/DiagnosticCommentKinds.td7
-rw-r--r--clang/lib/AST/CommentSema.cpp12
-rw-r--r--clang/test/Sema/warn-documentation.cpp12
4 files changed, 37 insertions, 1 deletions
diff --git a/clang/include/clang/AST/CommentSema.h b/clang/include/clang/AST/CommentSema.h
index f8b35d0c6f3..56d61f1693c 100644
--- a/clang/include/clang/AST/CommentSema.h
+++ b/clang/include/clang/AST/CommentSema.h
@@ -46,6 +46,13 @@ class Sema {
/// 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;
diff --git a/clang/include/clang/Basic/DiagnosticCommentKinds.td b/clang/include/clang/Basic/DiagnosticCommentKinds.td
index 890606a85a4..91aa5f19e65 100644
--- a/clang/include/clang/Basic/DiagnosticCommentKinds.td
+++ b/clang/include/clang/Basic/DiagnosticCommentKinds.td
@@ -63,6 +63,13 @@ def warn_doc_param_not_attached_to_a_function_decl : Warning<
"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;
diff --git a/clang/lib/AST/CommentSema.cpp b/clang/lib/AST/CommentSema.cpp
index 8fa8ab7d06f..5301bfebe96 100644
--- a/clang/lib/AST/CommentSema.cpp
+++ b/clang/lib/AST/CommentSema.cpp
@@ -153,6 +153,15 @@ ParamCommandComment *Sema::actOnParamCommandParamNameArg(
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 @@ HTMLEndTagComment *Sema::actOnHTMLEndTag(SourceLocation LocBegin,
FullComment *Sema::actOnFullComment(
ArrayRef<BlockContentComment *> Blocks) {
- SmallVector<ParamCommandComment *, 8> Params;
return new (Allocator) FullComment(Blocks);
}
@@ -382,6 +390,7 @@ ArrayRef<const ParmVarDecl *> Sema::getParamVars() {
}
void Sema::inspectThisDecl() {
+ assert(!IsThisDeclInspected);
if (!ThisDecl) {
IsFunctionDecl = false;
ParamVars = ArrayRef<const ParmVarDecl *>();
@@ -397,6 +406,7 @@ void Sema::inspectThisDecl() {
IsFunctionDecl = false;
ParamVars = ArrayRef<const ParmVarDecl *>();
}
+ ParamVarDocs.resize(ParamVars.size(), NULL);
IsThisDeclInspected = true;
}
diff --git a/clang/test/Sema/warn-documentation.cpp b/clang/test/Sema/warn-documentation.cpp
index 69e12b5097e..b59c6e4c5bc 100644
--- a/clang/test/Sema/warn-documentation.cpp
+++ b/clang/test/Sema/warn-documentation.cpp
@@ -166,6 +166,18 @@ class C {
int test_param14(int bbb, int ccc);
};
+// expected-warning@+3 {{parameter 'a' is already documented}}
+// expected-note@+1 {{previous documentation}}
+/// \param a Aaa.
+/// \param a Aaa.
+int test_param15(int a);
+
+// expected-warning@+4 {{parameter 'x2' is already documented}}
+// expected-note@+2 {{previous documentation}}
+/// \param x1 Aaa.
+/// \param x2 Bbb.
+/// \param x2 Ccc.
+int test_param16(int x1, int x2, int x3);
// expected-warning@+1 {{empty paragraph passed to '\brief' command}}
int test1; ///< \brief\brief Aaa
OpenPOWER on IntegriCloud