aboutsummaryrefslogtreecommitdiff
path: root/lib/AST/CommentSema.cpp
diff options
context:
space:
mode:
authorDmitri Gribenko <gribozavr@gmail.com>2012-08-03 21:15:32 +0000
committerDmitri Gribenko <gribozavr@gmail.com>2012-08-03 21:15:32 +0000
commit89ab7d0012ffe02a335b765eeb9b48977a5ecd79 (patch)
treeefa56afcd5f2be0fbdec3449517e994710df9811 /lib/AST/CommentSema.cpp
parent5295b97d6a0117414a24d319d9a018191ec1d8e3 (diff)
Comment diagnostics: warn if \returns is used in a non-function comment or if
the function returns void. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@161261 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/AST/CommentSema.cpp')
-rw-r--r--lib/AST/CommentSema.cpp45
1 files changed, 40 insertions, 5 deletions
diff --git a/lib/AST/CommentSema.cpp b/lib/AST/CommentSema.cpp
index cbfbc4eb24..c8422508d3 100644
--- a/lib/AST/CommentSema.cpp
+++ b/lib/AST/CommentSema.cpp
@@ -55,6 +55,7 @@ BlockCommandComment *Sema::actOnBlockCommandFinish(
ParagraphComment *Paragraph) {
Command->setParagraph(Paragraph);
checkBlockCommandEmptyParagraph(Command);
+ checkReturnsCommand(Command);
return Command;
}
@@ -472,6 +473,37 @@ void Sema::checkBlockCommandEmptyParagraph(BlockCommandComment *Command) {
}
}
+void Sema::checkReturnsCommand(const BlockCommandComment *Command) {
+ if (!isReturnsCommand(Command->getCommandName()))
+ return;
+ if (isFunctionDecl()) {
+ if (ThisDeclInfo->ResultType->isVoidType()) {
+ unsigned DiagKind;
+ switch (ThisDeclInfo->ThisDecl->getKind()) {
+ default:
+ DiagKind = 0;
+ break;
+ case Decl::CXXConstructor:
+ DiagKind = 1;
+ break;
+ case Decl::CXXDestructor:
+ DiagKind = 2;
+ break;
+ }
+ Diag(Command->getLocation(),
+ diag::warn_doc_returns_attached_to_a_void_function)
+ << Command->getCommandName()
+ << DiagKind
+ << Command->getSourceRange();
+ }
+ return;
+ }
+ Diag(Command->getLocation(),
+ diag::warn_doc_returns_not_attached_to_a_function_decl)
+ << Command->getCommandName()
+ << Command->getSourceRange();
+}
+
bool Sema::isFunctionDecl() {
if (!ThisDeclInfo)
return false;
@@ -643,16 +675,15 @@ StringRef Sema::correctTypoInTParamReference(
// TODO: tablegen
bool Sema::isBlockCommand(StringRef Name) {
- return llvm::StringSwitch<bool>(Name)
+ return isReturnsCommand(Name) ||
+ isParamCommand(Name) || isTParamCommand(Name) ||
+ llvm::StringSwitch<bool>(Name)
.Cases("brief", "short", true)
- .Case("result", true)
- .Case("return", true)
- .Case("returns", true)
.Case("author", true)
.Case("authors", true)
.Case("pre", true)
.Case("post", true)
- .Default(false) || isParamCommand(Name) || isTParamCommand(Name);
+ .Default(false);
}
bool Sema::isParamCommand(StringRef Name) {
@@ -666,6 +697,10 @@ bool Sema::isTParamCommand(StringRef Name) {
return Name == "tparam";
}
+bool Sema::isReturnsCommand(StringRef Name) {
+ return Name == "returns" || Name == "return" || Name == "result";
+}
+
unsigned Sema::getBlockCommandNumArgs(StringRef Name) {
return llvm::StringSwitch<unsigned>(Name)
.Cases("brief", "short", 0)