diff options
author | Dmitri Gribenko <gribozavr@gmail.com> | 2012-07-13 00:44:24 +0000 |
---|---|---|
committer | Dmitri Gribenko <gribozavr@gmail.com> | 2012-07-13 00:44:24 +0000 |
commit | 3f38bf2d441fac379c427f86153fbb0cb41256c6 (patch) | |
tree | 85044422828656cba608b746c8e3e6937697aeb9 | |
parent | 3d986980bd02594b1a5aa7b9f9f68d201621ced7 (diff) |
Comment parsing: repaint the bikesched: rename 'HTML open tags' to 'HTML start tags' and 'HTML close tags' to 'HTML end tags' according to HTML spec.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@160153 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | include/clang/AST/Comment.h | 38 | ||||
-rw-r--r-- | include/clang/AST/CommentLexer.h | 32 | ||||
-rw-r--r-- | include/clang/AST/CommentParser.h | 4 | ||||
-rw-r--r-- | include/clang/AST/CommentSema.h | 22 | ||||
-rw-r--r-- | include/clang/Basic/CommentNodes.td | 4 | ||||
-rw-r--r-- | include/clang/Basic/DiagnosticCommentKinds.td | 22 | ||||
-rw-r--r-- | lib/AST/CommentDumper.cpp | 10 | ||||
-rw-r--r-- | lib/AST/CommentLexer.cpp | 34 | ||||
-rw-r--r-- | lib/AST/CommentParser.cpp | 100 | ||||
-rw-r--r-- | lib/AST/CommentSema.cpp | 74 | ||||
-rw-r--r-- | test/Sema/warn-documentation.cpp | 28 | ||||
-rw-r--r-- | unittests/AST/CommentLexer.cpp | 192 | ||||
-rw-r--r-- | unittests/AST/CommentParser.cpp | 122 |
13 files changed, 340 insertions, 342 deletions
diff --git a/include/clang/AST/Comment.h b/include/clang/AST/Comment.h index 16719dfd23..8710f45bf0 100644 --- a/include/clang/AST/Comment.h +++ b/include/clang/AST/Comment.h @@ -50,8 +50,8 @@ protected: }; enum { NumInlineContentCommentBitfields = 9 }; - class HTMLOpenTagCommentBitfields { - friend class HTMLOpenTagComment; + class HTMLStartTagCommentBitfields { + friend class HTMLStartTagComment; unsigned : NumInlineContentCommentBitfields; @@ -76,7 +76,7 @@ protected: union { CommentBitfields CommentBits; InlineContentCommentBitfields InlineContentCommentBits; - HTMLOpenTagCommentBitfields HTMLOpenTagCommentBits; + HTMLStartTagCommentBitfields HTMLStartTagCommentBits; ParamCommandCommentBitfields ParamCommandCommentBits; }; @@ -293,7 +293,7 @@ public: }; /// An opening HTML tag with attributes. -class HTMLOpenTagComment : public HTMLTagComment { +class HTMLStartTagComment : public HTMLTagComment { public: class Attribute { public: @@ -334,21 +334,21 @@ private: ArrayRef<Attribute> Attributes; public: - HTMLOpenTagComment(SourceLocation LocBegin, - StringRef TagName) : - HTMLTagComment(HTMLOpenTagCommentKind, + HTMLStartTagComment(SourceLocation LocBegin, + StringRef TagName) : + HTMLTagComment(HTMLStartTagCommentKind, LocBegin, LocBegin.getLocWithOffset(1 + TagName.size()), TagName, LocBegin.getLocWithOffset(1), LocBegin.getLocWithOffset(1 + TagName.size())) { - HTMLOpenTagCommentBits.IsSelfClosing = false; + HTMLStartTagCommentBits.IsSelfClosing = false; } static bool classof(const Comment *C) { - return C->getCommentKind() == HTMLOpenTagCommentKind; + return C->getCommentKind() == HTMLStartTagCommentKind; } - static bool classof(const HTMLOpenTagComment *) { return true; } + static bool classof(const HTMLStartTagComment *) { return true; } child_iterator child_begin() const { return NULL; } @@ -380,21 +380,21 @@ public: } bool isSelfClosing() const { - return HTMLOpenTagCommentBits.IsSelfClosing; + return HTMLStartTagCommentBits.IsSelfClosing; } void setSelfClosing() { - HTMLOpenTagCommentBits.IsSelfClosing = true; + HTMLStartTagCommentBits.IsSelfClosing = true; } }; /// A closing HTML tag. -class HTMLCloseTagComment : public HTMLTagComment { +class HTMLEndTagComment : public HTMLTagComment { public: - HTMLCloseTagComment(SourceLocation LocBegin, - SourceLocation LocEnd, - StringRef TagName) : - HTMLTagComment(HTMLCloseTagCommentKind, + HTMLEndTagComment(SourceLocation LocBegin, + SourceLocation LocEnd, + StringRef TagName) : + HTMLTagComment(HTMLEndTagCommentKind, LocBegin, LocEnd, TagName, LocBegin.getLocWithOffset(2), @@ -402,10 +402,10 @@ public: { } static bool classof(const Comment *C) { - return C->getCommentKind() == HTMLCloseTagCommentKind; + return C->getCommentKind() == HTMLEndTagCommentKind; } - static bool classof(const HTMLCloseTagComment *) { return true; } + static bool classof(const HTMLEndTagComment *) { return true; } child_iterator child_begin() const { return NULL; } diff --git a/include/clang/AST/CommentLexer.h b/include/clang/AST/CommentLexer.h index f167934b8a..41e84db839 100644 --- a/include/clang/AST/CommentLexer.h +++ b/include/clang/AST/CommentLexer.h @@ -38,13 +38,13 @@ enum TokenKind { verbatim_block_end, verbatim_line_name, verbatim_line_text, - html_tag_open, // <tag + html_start_tag, // <tag html_ident, // attr html_equals, // = html_quoted_string, // "blah\"blah" or 'blah\'blah' html_greater, // > html_slash_greater, // /> - html_tag_close // </tag + html_end_tag // </tag }; } // end namespace tok @@ -158,13 +158,13 @@ public: TextLen1 = Text.size(); } - StringRef getHTMLTagOpenName() const LLVM_READONLY { - assert(is(tok::html_tag_open)); + StringRef getHTMLTagStartName() const LLVM_READONLY { + assert(is(tok::html_start_tag)); return StringRef(TextPtr1, TextLen1); } - void setHTMLTagOpenName(StringRef Name) { - assert(is(tok::html_tag_open)); + void setHTMLTagStartName(StringRef Name) { + assert(is(tok::html_start_tag)); TextPtr1 = Name.data(); TextLen1 = Name.size(); } @@ -191,13 +191,13 @@ public: TextLen1 = Str.size(); } - StringRef getHTMLTagCloseName() const LLVM_READONLY { - assert(is(tok::html_tag_close)); + StringRef getHTMLTagEndName() const LLVM_READONLY { + assert(is(tok::html_end_tag)); return StringRef(TextPtr1, TextLen1); } - void setHTMLTagCloseName(StringRef Name) { - assert(is(tok::html_tag_close)); + void setHTMLTagEndName(StringRef Name) { + assert(is(tok::html_end_tag)); TextPtr1 = Name.data(); TextLen1 = Name.size(); } @@ -249,10 +249,10 @@ private: LS_VerbatimLineText, /// Finished lexing \verbatim <TAG \endverbatim part, lexing tag attributes. - LS_HTMLOpenTag, + LS_HTMLStartTag, /// Finished lexing \verbatim </TAG \endverbatim part, lexing '>'. - LS_HTMLCloseTag + LS_HTMLEndTag }; /// Current lexing mode. @@ -328,13 +328,13 @@ private: void lexVerbatimLineText(Token &T); - void setupAndLexHTMLOpenTag(Token &T); + void setupAndLexHTMLStartTag(Token &T); - void lexHTMLOpenTag(Token &T); + void lexHTMLStartTag(Token &T); - void setupAndLexHTMLCloseTag(Token &T); + void setupAndLexHTMLEndTag(Token &T); - void lexHTMLCloseTag(Token &T); + void lexHTMLEndTag(Token &T); public: Lexer(SourceLocation FileLoc, const CommentOptions &CommOpts, diff --git a/include/clang/AST/CommentParser.h b/include/clang/AST/CommentParser.h index d78705a808..47cab25f25 100644 --- a/include/clang/AST/CommentParser.h +++ b/include/clang/AST/CommentParser.h @@ -108,8 +108,8 @@ public: BlockCommandComment *parseBlockCommand(); InlineCommandComment *parseInlineCommand(); - HTMLOpenTagComment *parseHTMLOpenTag(); - HTMLCloseTagComment *parseHTMLCloseTag(); + HTMLStartTagComment *parseHTMLStartTag(); + HTMLEndTagComment *parseHTMLEndTag(); BlockContentComment *parseParagraphOrBlockCommand(); diff --git a/include/clang/AST/CommentSema.h b/include/clang/AST/CommentSema.h index aae8e5cddb..14be08a895 100644 --- a/include/clang/AST/CommentSema.h +++ b/include/clang/AST/CommentSema.h @@ -46,7 +46,7 @@ class Sema { /// A stack of HTML tags that are currently open (not matched with closing /// tags). - SmallVector<HTMLOpenTagComment *, 8> HTMLOpenTags; + SmallVector<HTMLStartTagComment *, 8> HTMLOpenTags; public: Sema(llvm::BumpPtrAllocator &Allocator, const SourceManager &SourceMgr, @@ -123,18 +123,18 @@ public: SourceLocation TextBegin, StringRef Text); - HTMLOpenTagComment *actOnHTMLOpenTagStart(SourceLocation LocBegin, - StringRef TagName); + HTMLStartTagComment *actOnHTMLStartTagStart(SourceLocation LocBegin, + StringRef TagName); - HTMLOpenTagComment *actOnHTMLOpenTagFinish( - HTMLOpenTagComment *Tag, - ArrayRef<HTMLOpenTagComment::Attribute> Attrs, + HTMLStartTagComment *actOnHTMLStartTagFinish( + HTMLStartTagComment *Tag, + ArrayRef<HTMLStartTagComment::Attribute> Attrs, SourceLocation GreaterLoc, bool IsSelfClosing); - HTMLCloseTagComment *actOnHTMLCloseTag(SourceLocation LocBegin, - SourceLocation LocEnd, - StringRef TagName); + HTMLEndTagComment *actOnHTMLEndTag(SourceLocation LocBegin, + SourceLocation LocEnd, + StringRef TagName); FullComment *actOnFullComment(ArrayRef<BlockContentComment *> Blocks); @@ -157,8 +157,8 @@ public: bool isInlineCommand(StringRef Name); - bool isHTMLCloseTagOptional(StringRef Name); - bool isHTMLCloseTagForbidden(StringRef Name); + bool isHTMLEndTagOptional(StringRef Name); + bool isHTMLEndTagForbidden(StringRef Name); }; } // end namespace comments diff --git a/include/clang/Basic/CommentNodes.td b/include/clang/Basic/CommentNodes.td index bcadbace56..0e3f284521 100644 --- a/include/clang/Basic/CommentNodes.td +++ b/include/clang/Basic/CommentNodes.td @@ -10,8 +10,8 @@ def InlineContentComment : Comment<1>; def TextComment : DComment<InlineContentComment>; def InlineCommandComment : DComment<InlineContentComment>; def HTMLTagComment : DComment<InlineContentComment, 1>; - def HTMLOpenTagComment : DComment<HTMLTagComment>; - def HTMLCloseTagComment : DComment<HTMLTagComment>; + def HTMLStartTagComment : DComment<HTMLTagComment>; + def HTMLEndTagComment : DComment<HTMLTagComment>; def BlockContentComment : Comment<1>; def ParagraphComment : DComment<BlockContentComment>; diff --git a/include/clang/Basic/DiagnosticCommentKinds.td b/include/clang/Basic/DiagnosticCommentKinds.td index a4b974ae82..890606a85a 100644 --- a/include/clang/Basic/DiagnosticCommentKinds.td +++ b/include/clang/Basic/DiagnosticCommentKinds.td @@ -13,12 +13,12 @@ let CategoryName = "Documentation Issue" in { // HTML parsing errors. These are under -Wdocumentation to make sure the user // knows that we didn't parse something as he might expect. -def warn_doc_html_open_tag_expected_quoted_string : Warning< +def warn_doc_html_start_tag_expected_quoted_string : Warning< "expected quoted string after equals sign">, InGroup<Documentation>, DefaultIgnore; -def warn_doc_html_open_tag_expected_ident_or_greater : Warning< - "HTML opening tag prematurely ended, expected attribute name or '>'">, +def warn_doc_html_start_tag_expected_ident_or_greater : Warning< + "HTML start tag prematurely ended, expected attribute name or '>'">, InGroup<Documentation>, DefaultIgnore; def note_doc_html_tag_started_here : Note< @@ -26,20 +26,20 @@ def note_doc_html_tag_started_here : Note< // HTML semantic errors -def warn_doc_html_close_forbidden : Warning< - "HTML closing tag '%0' is forbidden">, +def warn_doc_html_end_forbidden : Warning< + "HTML end tag '%0' is forbidden">, InGroup<DocumentationHTML>, DefaultIgnore; -def warn_doc_html_close_unbalanced : Warning< - "HTML closing tag does not match any opening tag">, +def warn_doc_html_end_unbalanced : Warning< + "HTML end tag does not match any start tag">, InGroup<DocumentationHTML>, DefaultIgnore; -def warn_doc_html_open_close_mismatch : Warning< - "HTML opening tag '%0' closed by '%1'">, +def warn_doc_html_start_end_mismatch : Warning< + "HTML start tag '%0' closed by '%1'">, InGroup<DocumentationHTML>, DefaultIgnore; -def note_doc_html_closing_tag : Note< - "closing tag">; +def note_doc_html_end_tag : Note< + "end tag">; // Commands diff --git a/lib/AST/CommentDumper.cpp b/lib/AST/CommentDumper.cpp index 267657b76b..7ff61e0a27 100644 --- a/lib/AST/CommentDumper.cpp +++ b/lib/AST/CommentDumper.cpp @@ -43,8 +43,8 @@ public: // Inline content. void visitTextComment(const TextComment *C); void visitInlineCommandComment(const InlineCommandComment *C); - void visitHTMLOpenTagComment(const HTMLOpenTagComment *C); - void visitHTMLCloseTagComment(const HTMLCloseTagComment *C); + void visitHTMLStartTagComment(const HTMLStartTagComment *C); + void visitHTMLEndTagComment(const HTMLEndTagComment *C); // Block content. void visitParagraphComment(const ParagraphComment *C); @@ -110,14 +110,14 @@ void CommentDumper::visitInlineCommandComment(const InlineCommandComment *C) { OS << " Arg[" << i << "]=\"" << C->getArgText(i) << "\""; } -void CommentDumper::visitHTMLOpenTagComment(const HTMLOpenTagComment *C) { +void CommentDumper::visitHTMLStartTagComment(const HTMLStartTagComment *C) { dumpComment(C); OS << " Name=\"" << C->getTagName() << "\""; if (C->getAttrCount() != 0) { OS << " Attrs: "; for (unsigned i = 0, e = C->getAttrCount(); i != e; ++i) { - const HTMLOpenTagComment::Attribute &Attr = C->getAttr(i); + const HTMLStartTagComment::Attribute &Attr = C->getAttr(i); OS << " \"" << Attr.Name << "=\"" << Attr.Value << "\""; } } @@ -125,7 +125,7 @@ void CommentDumper::visitHTMLOpenTagComment(const HTMLOpenTagComment *C) { OS << " SelfClosing"; } -void CommentDumper::visitHTMLCloseTagComment(const HTMLCloseTagComment *C) { +void CommentDumper::visitHTMLEndTagComment(const HTMLEndTagComment *C) { dumpComment(C); OS << " Name=\"" << C->getTagName() << "\""; diff --git a/lib/AST/CommentLexer.cpp b/lib/AST/CommentLexer.cpp index 1f4955d1cf..5b411ca9cc 100644 --- a/lib/AST/CommentLexer.cpp +++ b/lib/AST/CommentLexer.cpp @@ -273,11 +273,11 @@ void Lexer::lexCommentText(Token &T) { case LS_VerbatimLineText: lexVerbatimLineText(T); return; - case LS_HTMLOpenTag: - lexHTMLOpenTag(T); + case LS_HTMLStartTag: + lexHTMLStartTag(T); return; - case LS_HTMLCloseTag: - lexHTMLCloseTag(T); + case LS_HTMLEndTag: + lexHTMLEndTag(T); return; } @@ -363,9 +363,9 @@ void Lexer::lexCommentText(Token &T) { } const char C = *TokenPtr; if (isHTMLIdentifierStartingCharacter(C)) - setupAndLexHTMLOpenTag(T); + setupAndLexHTMLStartTag(T); else if (C == '/') - setupAndLexHTMLCloseTag(T); + setupAndLexHTMLEndTag(T); else { StringRef Text(BufferPtr, TokenPtr - BufferPtr); formTokenWithChars(T, TokenPtr, tok::text); @@ -496,25 +496,25 @@ void Lexer::lexVerbatimLineText(Token &T) { State = LS_Normal; } -void Lexer::setupAndLexHTMLOpenTag(Token &T) { +void Lexer::setupAndLexHTMLStartTag(Token &T) { assert(BufferPtr[0] == '<' && isHTMLIdentifierStartingCharacter(BufferPtr[1])); const char *TagNameEnd = skipHTMLIdentifier(BufferPtr + 2, CommentEnd); StringRef Name(BufferPtr + 1, TagNameEnd - (BufferPtr + 1)); - formTokenWithChars(T, TagNameEnd, tok::html_tag_open); - T.setHTMLTagOpenName(Name); + formTokenWithChars(T, TagNameEnd, tok::html_start_tag); + T.setHTMLTagStartName(Name); BufferPtr = skipWhitespace(BufferPtr, CommentEnd); const char C = *BufferPtr; if (BufferPtr != CommentEnd && (C == '>' || C == '/' || isHTMLIdentifierStartingCharacter(C))) - State = LS_HTMLOpenTag; + State = LS_HTMLStartTag; } -void Lexer::lexHTMLOpenTag(Token &T) { - assert(State == LS_HTMLOpenTag); +void Lexer::lexHTMLStartTag(Token &T) { + assert(State == LS_HTMLStartTag); const char *TokenPtr = BufferPtr; char C = *TokenPtr; @@ -577,7 +577,7 @@ void Lexer::lexHTMLOpenTag(Token &T) { } } -void Lexer::setupAndLexHTMLCloseTag(Token &T) { +void Lexer::setupAndLexHTMLEndTag(Token &T) { assert(BufferPtr[0] == '<' && BufferPtr[1] == '/'); const char *TagNameBegin = skipWhitespace(BufferPtr + 2, CommentEnd); @@ -585,14 +585,14 @@ void Lexer::setupAndLexHTMLCloseTag(Token &T) { const char *End = skipWhitespace(TagNameEnd, CommentEnd); - formTokenWithChars(T, End, tok::html_tag_close); - T.setHTMLTagCloseName(StringRef(TagNameBegin, TagNameEnd - TagNameBegin)); + formTokenWithChars(T, End, tok::html_end_tag); + T.setHTMLTagEndName(StringRef(TagNameBegin, TagNameEnd - TagNameBegin)); if (BufferPtr != CommentEnd && *BufferPtr == '>') - State = LS_HTMLCloseTag; + State = LS_HTMLEndTag; } -void Lexer::lexHTMLCloseTag(Token &T) { +void Lexer::lexHTMLEndTag(Token &T) { assert(BufferPtr != CommentEnd && *BufferPtr == '>'); formTokenWithChars(T, BufferPtr + 1, tok::html_greater); diff --git a/lib/AST/CommentParser.cpp b/lib/AST/CommentParser.cpp index eabe61c979..ddcfef023f 100644 --- a/lib/AST/CommentParser.cpp +++ b/lib/AST/CommentParser.cpp @@ -155,38 +155,38 @@ InlineCommandComment *Parser::parseInlineCommand() { return IC; } -HTMLOpenTagComment *Parser::parseHTMLOpenTag() { - assert(Tok.is(tok::html_tag_open)); - HTMLOpenTagComment *HOT = - S.actOnHTMLOpenTagStart(Tok.getLocation(), - Tok.getHTMLTagOpenName()); +HTMLStartTagComment *Parser::parseHTMLStartTag() { + assert(Tok.is(tok::html_start_tag)); + HTMLStartTagComment *HST = + S.actOnHTMLStartTagStart(Tok.getLocation(), + Tok.getHTMLTagStartName()); consumeToken(); - SmallVector<HTMLOpenTagComment::Attribute, 2> Attrs; + SmallVector<HTMLStartTagComment::Attribute, 2> Attrs; while (true) { switch (Tok.getKind()) { case tok::html_ident: { Token Ident = Tok; consumeToken(); if (Tok.isNot(tok::html_equals)) { - Attrs.push_back(HTMLOpenTagComment::Attribute(Ident.getLocation(), - Ident.getHTMLIdent())); + Attrs.push_back(HTMLStartTagComment::Attribute(Ident.getLocation(), + Ident.getHTMLIdent())); continue; } Token Equals = Tok; consumeToken(); if (Tok.isNot(tok::html_quoted_string)) { Diag(Tok.getLocation(), - diag::warn_doc_html_open_tag_expected_quoted_string) + diag::warn_doc_html_start_tag_expected_quoted_string) << SourceRange(Equals.getLocation()); - Attrs.push_back(HTMLOpenTagComment::Attribute(Ident.getLocation(), - Ident.getHTMLIdent())); + Attrs.push_back(HTMLStartTagComment::Attribute(Ident.getLocation(), + Ident.getHTMLIdent())); while (Tok.is(tok::html_equals) || Tok.is(tok::html_quoted_string)) consumeToken(); continue; } - Attrs.push_back(HTMLOpenTagComment::Attribute( + Attrs.push_back(HTMLStartTagComment::Attribute( Ident.getLocation(), Ident.getHTMLIdent(), Equals.getLocation(), @@ -198,25 +198,25 @@ HTMLOpenTagComment *Parser::parseHTMLOpenTag() { } case tok::html_greater: - HOT = S.actOnHTMLOpenTagFinish(HOT, - copyArray(llvm::makeArrayRef(Attrs)), - Tok.getLocation(), - /* IsSelfClosing = */ false); + HST = S.actOnHTMLStartTagFinish(HST, + copyArray(llvm::makeArrayRef(Attrs)), + Tok.getLocation(), + /* IsSelfClosing = */ false); consumeToken(); - return HOT; + return HST; case tok::html_slash_greater: - HOT = S.actOnHTMLOpenTagFinish(HOT, - copyArray(llvm::makeArrayRef(Attrs)), - Tok.getLocation(), - /* IsSelfClosing = */ true); + HST = S.actOnHTMLStartTagFinish(HST, + copyArray(llvm::makeArrayRef(Attrs)), + Tok.getLocation(), + /* IsSelfClosing = */ true); consumeToken(); - return HOT; + return HST; case tok::html_equals: case tok::html_quoted_string: Diag(Tok.getLocation(), - diag::warn_doc_html_open_tag_expected_ident_or_greater); + diag::warn_doc_html_start_tag_expected_ident_or_greater); while (Tok.is(tok::html_equals) || Tok.is(tok::html_quoted_string)) consumeToken(); @@ -225,20 +225,20 @@ HTMLOpenTagComment *Parser::parseHTMLOpenTag() { Tok.is(tok::html_slash_greater)) continue; - return S.actOnHTMLOpenTagFinish(HOT, + return S.actOnHTMLStartTagFinish(HST, + copyArray(llvm::makeArrayRef(Attrs)), + SourceLocation(), + /* IsSelfClosing = */ false); + + default: + // Not a token from an HTML start tag. Thus HTML tag prematurely ended. + HST = S.actOnHTMLStartTagFinish(HST, copyArray(llvm::makeArrayRef(Attrs)), SourceLocation(), /* IsSelfClosing = */ false); - - default: - // Not a token from an HTML open tag. Thus HTML tag prematurely ended. - HOT = S.actOnHTMLOpenTagFinish(HOT, - copyArray(llvm::makeArrayRef(Attrs)), - SourceLocation(), - /* IsSelfClosing = */ false); bool StartLineInvalid; const unsigned StartLine = SourceMgr.getPresumedLineNumber( - HOT->getLocation(), + HST->getLocation(), &StartLineInvalid); bool EndLineInvalid; const unsigned EndLine = SourceMgr.getPresumedLineNumber( @@ -246,22 +246,22 @@ HTMLOpenTagComment *Parser::parseHTMLOpenTag() { &EndLineInvalid); if (StartLineInvalid || EndLineInvalid || StartLine == EndLine) Diag(Tok.getLocation(), - diag::warn_doc_html_open_tag_expected_ident_or_greater) - << HOT->getSourceRange(); + diag::warn_doc_html_start_tag_expected_ident_or_greater) + << HST->getSourceRange(); else { Diag(Tok.getLocation(), - diag::warn_doc_html_open_tag_expected_ident_or_greater); - Diag(HOT->getLocation(), diag::note_doc_html_tag_started_here) - << HOT->getSourceRange(); + diag::warn_doc_html_start_tag_expected_ident_or_greater); + Diag(HST->getLocation(), diag::note_doc_html_tag_started_here) + << HST->getSourceRange(); } - return HOT; + return HST; } } } -HTMLCloseTagComment *Parser::parseHTMLCloseTag() { - assert(Tok.is(tok::html_tag_close)); - Token TokTagOpen = Tok; +HTMLEndTagComment *Parser::parseHTMLEndTag() { + assert(Tok.is(tok::html_end_tag)); + Token TokEndTag = Tok; consumeToken(); SourceLocation Loc; if (Tok.is(tok::html_greater)) { @@ -269,9 +269,9 @@ HTMLCloseTagComment *Parser::parseHTMLCloseTag() { consumeToken(); } - return S.actOnHTMLCloseTag(TokTagOpen.getLocation(), - Loc, - TokTagOpen.getHTMLTagCloseName()); + return S.actOnHTMLEndTag(TokEndTag.getLocation(), + Loc, + TokEndTag.getHTMLTagEndName()); } BlockContentComment *Parser::parseParagraphOrBlockCommand() { @@ -315,12 +315,12 @@ BlockContentComment *Parser::parseParagraphOrBlockCommand() { } // Don't deal with HTML tag soup now. - case tok::html_tag_open: - Content.push_back(parseHTMLOpenTag()); + case tok::html_start_tag: + Content.push_back(parseHTMLStartTag()); continue; - case tok::html_tag_close: - Content.push_back(parseHTMLCloseTag()); + case tok::html_end_tag: + Content.push_back(parseHTMLEndTag()); continue; case tok::text: @@ -418,8 +418,8 @@ BlockContentComment *Parser::parseBlockContent() { switch (Tok.getKind()) { case tok::text: case tok::command: - case tok::html_tag_open: - case tok::html_tag_close: + case tok::html_start_tag: + case tok::html_end_tag: return parseParagraphOrBlockCommand(); case tok::verbatim_block_begin: diff --git a/lib/AST/CommentSema.cpp b/lib/AST/CommentSema.cpp index 69cc01683c..955629c658 100644 --- a/lib/AST/CommentSema.cpp +++ b/lib/AST/CommentSema.cpp @@ -273,40 +273,38 @@ VerbatimLineComment *Sema::actOnVerbatimLine(SourceLocation LocBegin, Text); } -HTMLOpenTagComment *Sema::actOnHTMLOpenTagStart(SourceLocation LocBegin, - StringRef TagName) { - HTMLOpenTagComment *HOT = - new (Allocator) HTMLOpenTagComment(LocBegin, TagName); - return HOT; +HTMLStartTagComment *Sema::actOnHTMLStartTagStart(SourceLocation LocBegin, + StringRef TagName) { + return new (Allocator) HTMLStartTagComment(LocBegin, TagName); } -HTMLOpenTagComment *Sema::actOnHTMLOpenTagFinish( - HTMLOpenTagComment *Tag, - ArrayRef<HTMLOpenTagComment::Attribute> Attrs, +HTMLStartTagComment *Sema::actOnHTMLStartTagFinish( + HTMLStartTagComment *Tag, + ArrayRef<HTMLStartTagComment::Attribute> Attrs, SourceLocation GreaterLoc, bool IsSelfClosing) { Tag->setAttrs(Attrs); Tag->setGreaterLoc(GreaterLoc); if (IsSelfClosing) Tag->setSelfClosing(); - else if (!isHTMLCloseTagForbidden(Tag->getTagName())) + else if (!isHTMLEndTagForbidden(Tag->getTagName())) HTMLOpenTags.push_back(Tag); return Tag; } -HTMLCloseTagComment *Sema::actOnHTMLCloseTag(SourceLocation LocBegin, - SourceLocation LocEnd, - StringRef TagName) { - HTMLCloseTagComment *HCT = - new (Allocator) HTMLCloseTagComment(LocBegin, LocEnd, TagName); - if (isHTMLCloseTagForbidden(TagName)) { - Diag(HCT->getLocation(), diag::warn_doc_html_close_forbidden) - << TagName << HCT->getSourceRange(); - return HCT; +HTMLEndTagComment *Sema::actOnHTMLEndTag(SourceLocation LocBegin, + SourceLocation LocEnd, + StringRef TagName) { + HTMLEndTagComment *HET = + new (Allocator) HTMLEndTagComment(LocBegin, LocEnd, TagName); + if (isHTMLEndTagForbidden(TagName)) { + Diag(HET->getLocation(), diag::warn_doc_html_end_forbidden) + << TagName << HET->getSourceRange(); + return HET; } bool FoundOpen = false; - for (SmallVectorImpl<HTMLOpenTagComment *>::const_reverse_iterator + for (SmallVectorImpl<HTMLStartTagComment *>::const_reverse_iterator I = HTMLOpenTags.rbegin(), E = HTMLOpenTags.rend(); I != E; ++I) { if ((*I)->getTagName() == TagName) { @@ -315,44 +313,44 @@ HTMLCloseTagComment *Sema::actOnHTMLCloseTag(SourceLocation LocBegin, } } if (!FoundOpen) { - Diag(HCT->getLocation(), diag::warn_doc_html_close_unbalanced) - << HCT->getSourceRange(); - return HCT; + Diag(HET->getLocation(), diag::warn_doc_html_end_unbalanced) + << HET->getSourceRange(); + return HET; } while (!HTMLOpenTags.empty()) { - const HTMLOpenTagComment *HOT = HTMLOpenTags.back(); + const HTMLStartTagComment *HST = HTMLOpenTags.back(); HTMLOpenTags.pop_back(); - StringRef LastNotClosedTagName = HOT->getTagName(); + StringRef LastNotClosedTagName = HST->getTagName(); if (LastNotClosedTagName == TagName) break; - if (isHTMLCloseTagOptional(LastNotClosedTagName)) + if (isHTMLEndTagOptional(LastNotClosedTagName)) continue; bool OpenLineInvalid; const unsigned OpenLine = SourceMgr.getPresumedLineNumber( - HOT->getLocation(), + HST->getLocation(), &OpenLineInvalid); bool CloseLineInvalid; const unsigned CloseLine = SourceMgr.getPresumedLineNumber( - HCT->getLocation(), + HET->getLocation(), &CloseLineInvalid); if (OpenLineInvalid || CloseLineInvalid || OpenLine == CloseLine) - Diag(HOT->getLocation(), diag::warn_doc_html_open_close_mismatch) - << HOT->getTagName() << HCT->getTagName() - << HOT->getSourceRange() << HCT->getSourceRange(); + Diag(HST->getLocation(), diag::warn_doc_html_start_end_mismatch) + << HST->getTagName() << HET->getTagName() + << HST->getSourceRange() << HET->getSourceRange(); else { - Diag(HOT->getLocation(), diag::warn_doc_html_open_close_mismatch) - << HOT->getTagName() << HCT->getTagName() - << HOT->getSourceRange(); - Diag(HCT->getLocation(), diag::note_doc_html_closing_tag) - << HCT->getSourceRange(); + Diag(HST->getLocation(), diag::warn_doc_html_start_end_mismatch) + << HST->getTagName() << HET->getTagName() + << HST->getSourceRange(); + Diag(HET->getLocation(), diag::note_doc_html_end_tag) + << HET->getSourceRange(); } } - return HCT; + return HET; } FullComment *Sema::actOnFullComment( @@ -454,7 +452,7 @@ bool Sema::isInlineCommand(StringRef Name) { .Default(false); } -bool Sema::isHTMLCloseTagOptional(StringRef Name) { +bool Sema::isHTMLEndTagOptional(StringRef Name) { return llvm::StringSwitch<bool>(Name) .Case("p", true) .Case("li", true) @@ -470,7 +468,7 @@ bool Sema::isHTMLCloseTagOptional(StringRef Name) { .Default(false); } -bool Sema::isHTMLCloseTagForbidden(StringRef Name) { +bool Sema::isHTMLEndTagForbidden(StringRef Name) { return llvm::StringSwitch<bool>(Name) .Case("br", true) .Case("hr", true) diff --git a/test/Sema/warn-documentation.cpp b/test/Sema/warn-documentation.cpp index b1c871a5fd..f12871856b 100644 --- a/test/Sema/warn-documentation.cpp +++ b/test/Sema/warn-documentation.cpp @@ -9,43 +9,43 @@ int test_html1(int); int test_html2(int); // expected-warning@+2 {{expected quoted string after equals sign}} -// expected-warning@+1 {{HTML opening tag prematurely ended, expected attribute name or '>'}} +// expected-warning@+1 {{HTML start tag prematurely ended, expected attribute name or '>'}} /// <a href= blah int test_html3(int); -// expected-warning@+1 {{HTML opening tag prematurely ended, expected attribute name or '>'}} +// expected-warning@+1 {{HTML start tag prematurely ended, expected attribute name or '>'}} /// <a => int test_html4(int); -// expected-warning@+1 {{HTML opening tag prematurely ended, expected attribute name or '>'}} +// expected-warning@+1 {{HTML start tag prematurely ended, expected attribute name or '>'}} /// <a "aaa"> int test_html5(int); -// expected-warning@+1 {{HTML opening tag prematurely ended, expected attribute name or '>'}} +// expected-warning@+1 {{HTML start tag prematurely ended, expected attribute name or '>'}} /// <a a="b" => int test_html6(int); -// expected-warning@+1 {{HTML opening tag prematurely ended, expected attribute name or '>'}} +// expected-warning@+1 {{HTML start tag prematurely ended, expected attribute name or '>'}} /// <a a="b" "aaa"> int test_html7(int); -// expected-warning@+1 {{HTML opening tag prematurely ended, expected attribute name or '>'}} +// expected-warning@+1 {{HTML start tag prematurely ended, expected attribute name or '>'}} /// <a a="b" = int test_html8(int); -// expected-warning@+2 {{HTML opening tag prematurely ended, expected attribute name or '>'}} expected-note@+1 {{HTML tag started here}} +// expected-warning@+2 {{HTML start tag prematurely ended, expected attribute name or '>'}} expected-note@+1 {{HTML tag started here}} /** Aaa bbb<ccc ddd eee * fff ggg. */ int test_html9(int); -// expected-warni |