aboutsummaryrefslogtreecommitdiff
path: root/lib/AST/CommentLexer.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
commita5ef44ff5d93a3be6ca67782828157a71894cf0c (patch)
treef19f1a744483b5cfef3a471957125fa76b7ed36a /lib/AST/CommentLexer.cpp
parentff398965a5abfaf5bc47bc022876f56a28e5b9a7 (diff)
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). git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@160078 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/AST/CommentLexer.cpp')
-rw-r--r--lib/AST/CommentLexer.cpp14
1 files changed, 13 insertions, 1 deletions
diff --git a/lib/AST/CommentLexer.cpp b/lib/AST/CommentLexer.cpp
index 55cd409a9c..1f4955d1cf 100644
--- a/lib/AST/CommentLexer.cpp
+++ b/lib/AST/CommentLexer.cpp
@@ -509,7 +509,7 @@ void Lexer::setupAndLexHTMLOpenTag(Token &T) {
const char C = *BufferPtr;
if (BufferPtr != CommentEnd &&
- (C == '>' || isHTMLIdentifierStartingCharacter(C)))
+ (C == '>' || C == '/' || isHTMLIdentifierStartingCharacter(C)))
State = LS_HTMLOpenTag;
}
@@ -546,6 +546,18 @@ void Lexer::lexHTMLOpenTag(Token &T) {
formTokenWithChars(T, TokenPtr, tok::html_greater);
State = LS_Normal;
return;
+ case '/':
+ TokenPtr++;
+ if (TokenPtr != CommentEnd && *TokenPtr == '>') {
+ TokenPtr++;
+ formTokenWithChars(T, TokenPtr, tok::html_slash_greater);
+ } else {
+ StringRef Text(BufferPtr, TokenPtr - BufferPtr);
+ formTokenWithChars(T, TokenPtr, tok::text);
+ T.setText(Text);
+ }
+ State = LS_Normal;
+ return;
}
}