diff options
author | Dmitri Gribenko <gribozavr@gmail.com> | 2012-07-11 21:38:39 +0000 |
---|---|---|
committer | Dmitri Gribenko <gribozavr@gmail.com> | 2012-07-11 21:38:39 +0000 |
commit | a5ef44ff5d93a3be6ca67782828157a71894cf0c (patch) | |
tree | f19f1a744483b5cfef3a471957125fa76b7ed36a /lib/AST/ASTContext.cpp | |
parent | ff398965a5abfaf5bc47bc022876f56a28e5b9a7 (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/ASTContext.cpp')
-rw-r--r-- | lib/AST/ASTContext.cpp | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/lib/AST/ASTContext.cpp b/lib/AST/ASTContext.cpp index a5b624fbec..27e4de926d 100644 --- a/lib/AST/ASTContext.cpp +++ b/lib/AST/ASTContext.cpp @@ -56,7 +56,7 @@ enum FloatingRank { HalfRank, FloatRank, DoubleRank, LongDoubleRank }; -const RawComment *ASTContext::getRawCommentForDeclNoCache(const Decl *D) const { +RawComment *ASTContext::getRawCommentForDeclNoCache(const Decl *D) const { if (!CommentsLoaded && ExternalSource) { ExternalSource->ReadComments(); CommentsLoaded = true; @@ -160,11 +160,13 @@ const RawComment *ASTContext::getRawCommentForDecl(const Decl *D) const { return C.first; } - const RawComment *RC = getRawCommentForDeclNoCache(D); + RawComment *RC = getRawCommentForDeclNoCache(D); // If we found a comment, it should be a documentation comment. assert(!RC || RC->isDocumentation()); DeclComments[D] = RawAndParsedComment(RC, static_cast<comments::FullComment *>(NULL)); + if (RC) + RC->setAttached(); return RC; } @@ -187,8 +189,10 @@ comments::FullComment *ASTContext::getCommentForDecl(const Decl *D) const { comments::Lexer L(RC->getSourceRange().getBegin(), comments::CommentOptions(), RawText.begin(), RawText.end()); - comments::Sema S(this->BumpAlloc); - comments::Parser P(L, S, this->BumpAlloc); + comments::Sema S(getAllocator(), getSourceManager(), getDiagnostics()); + S.setDecl(D); + comments::Parser P(L, S, getAllocator(), getSourceManager(), + getDiagnostics()); comments::FullComment *FC = P.parseFullComment(); DeclComments[D].second = FC; |