summaryrefslogtreecommitdiffstats
path: root/clang/lib/AST/Comment.cpp
diff options
context:
space:
mode:
authorDmitri Gribenko <gribozavr@gmail.com>2012-07-11 21:38:39 +0000
committerDmitri Gribenko <gribozavr@gmail.com>2012-07-11 21:38:39 +0000
commitf26054f0fb53f65dbfbfc01954dc3b2028582cde (patch)
tree51e846b631a7c929833c43b321a0532d3b64bf45 /clang/lib/AST/Comment.cpp
parenta46ec4534d458f9cdb76f213ca3a42690296f21b (diff)
downloadbcm5719-llvm-f26054f0fb53f65dbfbfc01954dc3b2028582cde.tar.gz
bcm5719-llvm-f26054f0fb53f65dbfbfc01954dc3b2028582cde.zip
Enable comment parsing and semantic analysis to emit diagnostics. A few
diagnostics implemented -- see testcases. I created a new TableGen file for comment diagnostics, DiagnosticCommentKinds.td, because comment diagnostics don't logically fit into AST diagnostics file. But I don't feel strongly about it. This also implements support for self-closing HTML tags in comment lexer and parser (for example, <br />). In order to issue precise diagnostics CommentSema needs to know the declaration the comment is attached to. There is no easy way to find a decl by comment, so we match comments and decls in lockstep: after parsing one declgroup we check if we have any new, not yet attached comments. If we do -- then we do the usual comment-finding process. It is interesting that this automatically handles trailing comments. We pick up not only comments that precede the declaration, but also comments that *follow* the declaration -- thanks to the lookahead in the lexer: after parsing the declgroup we've consumed the semicolon and looked ahead through comments. Added -Wdocumentation-html flag for semantic HTML errors to allow the user to disable only HTML warnings (but not HTML parse errors, which we emit as warnings in -Wdocumentation). llvm-svn: 160078
Diffstat (limited to 'clang/lib/AST/Comment.cpp')
-rw-r--r--clang/lib/AST/Comment.cpp32
1 files changed, 32 insertions, 0 deletions
diff --git a/clang/lib/AST/Comment.cpp b/clang/lib/AST/Comment.cpp
index 4681d5a143d..1520d134172 100644
--- a/clang/lib/AST/Comment.cpp
+++ b/clang/lib/AST/Comment.cpp
@@ -86,6 +86,38 @@ Comment::child_iterator Comment::child_end() const {
llvm_unreachable("Unknown comment kind!");
}
+bool TextComment::isWhitespace() const {
+ for (StringRef::const_iterator I = Text.begin(), E = Text.end();
+ I != E; ++I) {
+ const char C = *I;
+ if (C != ' ' && C != '\n' && C != '\r' &&
+ C != '\t' && C != '\f' && C != '\v')
+ return false;
+ }
+ return true;
+}
+
+bool ParagraphComment::isWhitespace() const {
+ for (child_iterator I = child_begin(), E = child_end(); I != E; ++I) {
+ if (const TextComment *TC = dyn_cast<TextComment>(*I)) {
+ if (!TC->isWhitespace())
+ return false;
+ }
+ }
+ return true;
+}
+
+const char *ParamCommandComment::getDirectionAsString(PassDirection D) {
+ switch (D) {
+ case ParamCommandComment::In:
+ return "[in]";
+ case ParamCommandComment::Out:
+ return "[out]";
+ case ParamCommandComment::InOut:
+ return "[in,out]";
+ }
+ llvm_unreachable("unknown PassDirection");
+}
} // end namespace comments
} // end namespace clang
OpenPOWER on IntegriCloud