From 3f38bf2d441fac379c427f86153fbb0cb41256c6 Mon Sep 17 00:00:00 2001 From: Dmitri Gribenko Date: Fri, 13 Jul 2012 00:44:24 +0000 Subject: [PATCH] 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 --- include/clang/AST/Comment.h | 38 ++-- include/clang/AST/CommentLexer.h | 32 +-- include/clang/AST/CommentParser.h | 4 +- include/clang/AST/CommentSema.h | 22 +- include/clang/Basic/CommentNodes.td | 4 +- include/clang/Basic/DiagnosticCommentKinds.td | 22 +- lib/AST/CommentDumper.cpp | 10 +- lib/AST/CommentLexer.cpp | 34 ++-- lib/AST/CommentParser.cpp | 100 ++++----- lib/AST/CommentSema.cpp | 74 ++++--- test/Sema/warn-documentation.cpp | 28 +-- unittests/AST/CommentLexer.cpp | 192 +++++++++--------- 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 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, // html_slash_greater, // /> - html_tag_close // '. - 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 HTMLOpenTags; + SmallVector 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 Attrs, + HTMLStartTagComment *actOnHTMLStartTagFinish( + HTMLStartTagComment *Tag, + ArrayRef Attrs, SourceLocation GreaterLoc, bool IsSelfClosing); - HTMLCloseTagComment *actOnHTMLCloseTag(SourceLocation LocBegin, - SourceLocation LocEnd, - StringRef TagName); + HTMLEndTagComment *actOnHTMLEndTag(SourceLocation LocBegin, + SourceLocation LocEnd, + StringRef TagName); FullComment *actOnFullComment(ArrayRef 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; def InlineCommandComment : DComment; def HTMLTagComment : DComment; - def HTMLOpenTagComment : DComment; - def HTMLCloseTagComment : DComment; + def HTMLStartTagComment : DComment; + def HTMLEndTagComment : DComment; def BlockContentComment : Comment<1>; def ParagraphComment : DComment; 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, 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, 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, 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, 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, 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 Attrs; + SmallVector 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 Attrs, +HTMLStartTagComment *Sema::actOnHTMLStartTagFinish( + HTMLStartTagComment *Tag, + ArrayRef 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::const_reverse_iterator + for (SmallVectorImpl::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(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(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 '>'}} /// '}} +// expected-warning@+1 {{HTML start tag prematurely ended, expected attribute name or '>'}} /// 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 '>'}} /// 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 '>'}} /// 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 '>'}} /// 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 '>'}} /// '}} 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'}} +// expected-warning@+1 {{HTML start tag prematurely ended, expected attribute name or '>'}} /** Aaa bbb
int test_html11(int); @@ -63,17 +63,17 @@ int test_html_nesting3(int); /// Bbb

int test_html_nesting4(int); -// expected-warning@+1 {{HTML closing tag does not match any opening tag}} +// expected-warning@+1 {{HTML end tag does not match any start tag}} /// Meow
int test_html_nesting5(int); -// expected-warning@+2 {{HTML opening tag 'i' closed by 'b'}} -// expected-warning@+1 {{HTML closing tag does not match any opening tag}} +// expected-warning@+2 {{HTML start tag 'i' closed by 'b'}} +// expected-warning@+1 {{HTML end tag does not match any start tag}} /// Meow int test_html_nesting6(int); -// expected-warning@+2 {{HTML opening tag 'i' closed by 'b'}} -// expected-warning@+1 {{HTML closing tag does not match any opening tag}} +// expected-warning@+2 {{HTML start tag 'i' closed by 'b'}} +// expected-warning@+1 {{HTML end tag does not match any start tag}} /// Meow int test_html_nesting7(int); diff --git a/unittests/AST/CommentLexer.cpp b/unittests/AST/CommentLexer.cpp index 471863924a..6be5909f8a 100644 --- a/unittests/AST/CommentLexer.cpp +++ b/unittests/AST/CommentLexer.cpp @@ -858,13 +858,13 @@ TEST_F(CommentLexerTest, HTML4) { ASSERT_EQ(3U, Toks.size()); - ASSERT_EQ(tok::text, Toks[0].getKind()); - ASSERT_EQ(StringRef(" "), Toks[0].getText()); + ASSERT_EQ(tok::text, Toks[0].getKind()); + ASSERT_EQ(StringRef(" "), Toks[0].getText()); - ASSERT_EQ(tok::html_tag_open, Toks[1].getKind()); - ASSERT_EQ(StringRef("tag"), Toks[1].getHTMLTagOpenName()); + ASSERT_EQ(tok::html_start_tag, Toks[1].getKind()); + ASSERT_EQ(StringRef("tag"), Toks[1].getHTMLTagStartName()); - ASSERT_EQ(tok::newline, Toks[2].getKind()); + ASSERT_EQ(tok::newline, Toks[2].getKind()); } } @@ -878,16 +878,16 @@ TEST_F(CommentLexerTest, HTML5) { ASSERT_EQ(4U, Toks.size()); - ASSERT_EQ(tok::text, Toks[0].getKind()); - ASSERT_EQ(StringRef(" "), Toks[0].getText()); + ASSERT_EQ(tok::text, Toks[0].getKind()); + ASSERT_EQ(StringRef(" "), Toks[0].getText()); - ASSERT_EQ(tok::html_tag_open, Toks[1].getKind()); - ASSERT_EQ(StringRef("tag"), Toks[1].getHTMLTagOpenName()); + ASSERT_EQ(tok::html_start_tag, Toks[1].getKind()); + ASSERT_EQ(StringRef("tag"), Toks[1].getHTMLTagStartName()); - ASSERT_EQ(tok::text, Toks[2].getKind()); - ASSERT_EQ(StringRef("42"), Toks[2].getText()); + ASSERT_EQ(tok::text, Toks[2].getKind()); + ASSERT_EQ(StringRef("42"), Toks[2].getText()); - ASSERT_EQ(tok::newline, Toks[3].getKind()); + ASSERT_EQ(tok::newline, Toks[3].getKind()); } TEST_F(CommentLexerTest, HTML6) { @@ -899,18 +899,18 @@ TEST_F(CommentLexerTest, HTML6) { ASSERT_EQ(5U, Toks.size()); - ASSERT_EQ(tok::text, Toks[0].getKind()); - ASSERT_EQ(StringRef(" "), Toks[0].getText()); + ASSERT_EQ(tok::text, Toks[0].getKind()); + ASSERT_EQ(StringRef(" "), Toks[0].getText()); - ASSERT_EQ(tok::html_tag_open, Toks[1].getKind()); - ASSERT_EQ(StringRef("tag"), Toks[1].getHTMLTagOpenName()); + ASSERT_EQ(tok::html_start_tag, Toks[1].getKind()); + ASSERT_EQ(StringRef("tag"), Toks[1].getHTMLTagStartName()); - ASSERT_EQ(tok::html_greater, Toks[2].getKind()); + ASSERT_EQ(tok::html_greater, Toks[2].getKind()); - ASSERT_EQ(tok::text, Toks[3].getKind()); - ASSERT_EQ(StringRef(" Meow"), Toks[3].getText()); + ASSERT_EQ(tok::text, Toks[3].getKind()); + ASSERT_EQ(StringRef(" Meow"), Toks[3].getText()); - ASSERT_EQ(tok::newline, Toks[4].getKind()); + ASSERT_EQ(tok::newline, Toks[4].getKind()); } TEST_F(CommentLexerTest, HTML7) { @@ -922,16 +922,16 @@ TEST_F(CommentLexerTest, HTML7) { ASSERT_EQ(4U, Toks.size()); - ASSERT_EQ(tok::text, Toks[0].getKind()); - ASSERT_EQ(StringRef(" "), Toks[0].getText()); + ASSERT_EQ(tok::text, Toks[0].getKind()); + ASSERT_EQ(StringRef(" "), Toks[0].getText()); - ASSERT_EQ(tok::html_tag_open, Toks[1].getKind()); - ASSERT_EQ(StringRef("tag"), Toks[1].getHTMLTagOpenName()); + ASSERT_EQ(tok::html_start_tag, Toks[1].getKind()); + ASSERT_EQ(StringRef("tag"), Toks[1].getHTMLTagStartName()); - ASSERT_EQ(tok::text, Toks[2].getKind()); - ASSERT_EQ(StringRef("="), Toks[2].getText()); + ASSERT_EQ(tok::text, Toks[2].getKind()); + ASSERT_EQ(StringRef("="), Toks[2].getText()); - ASSERT_EQ(tok::newline, Toks[3].getKind()); + ASSERT_EQ(tok::newline, Toks[3].getKind()); } TEST_F(CommentLexerTest, HTML8) { @@ -943,23 +943,23 @@ TEST_F(CommentLexerTest, HTML8) { ASSERT_EQ(7U, Toks.size()); - ASSERT_EQ(tok::text, Toks[0].getKind()); - ASSERT_EQ(StringRef(" "), Toks[0].getText()); + ASSERT_EQ(tok::text, Toks[0].getKind()); + ASSERT_EQ(StringRef(" "), Toks[0].getText()); - ASSERT_EQ(tok::html_tag_open, Toks[1].getKind()); - ASSERT_EQ(StringRef("tag"), Toks[1].getHTMLTagOpenName()); + ASSERT_EQ(tok::html_start_tag, Toks[1].getKind()); + ASSERT_EQ(StringRef("tag"), Toks[1].getHTMLTagStartName()); - ASSERT_EQ(tok::html_ident, Toks[2].getKind()); - ASSERT_EQ(StringRef("attr"), Toks[2].getHTMLIdent()); + ASSERT_EQ(tok::html_ident, Toks[2].getKind()); + ASSERT_EQ(StringRef("attr"), Toks[2].getHTMLIdent()); - ASSERT_EQ(tok::html_equals, Toks[3].getKind()); + ASSERT_EQ(tok::html_equals, Toks[3].getKind()); - ASSERT_EQ(tok::html_greater, Toks[4].getKind()); + ASSERT_EQ(tok::html_greater, Toks[4].getKind()); - ASSERT_EQ(tok::text, Toks[5].getKind()); - ASSERT_EQ(StringRef(" Meow"), Toks[5].getText()); + ASSERT_EQ(tok::text, Toks[5].getKind()); + ASSERT_EQ(StringRef(" Meow"), Toks[5].getText()); - ASSERT_EQ(tok::newline, Toks[6].getKind()); + ASSERT_EQ(tok::newline, Toks[6].getKind()); } TEST_F(CommentLexerTest, HTML9) { @@ -975,16 +975,16 @@ TEST_F(CommentLexerTest, HTML9) { ASSERT_EQ(4U, Toks.size()); - ASSERT_EQ(tok::text, Toks[0].getKind()); - ASSERT_EQ(StringRef(" "), Toks[0].getText()); + ASSERT_EQ(tok::text, Toks[0].getKind()); + ASSERT_EQ(StringRef(" "), Toks[0].getText()); - ASSERT_EQ(tok::html_tag_open, Toks[1].getKind()); - ASSERT_EQ(StringRef("tag"), Toks[1].getHTMLTagOpenName()); + ASSERT_EQ(tok::html_start_tag, Toks[1].getKind()); + ASSERT_EQ(StringRef("tag"), Toks[1].getHTMLTagStartName()); - ASSERT_EQ(tok::html_ident, Toks[2].getKind()); - ASSERT_EQ(StringRef("attr"), Toks[2].getHTMLIdent()); + ASSERT_EQ(tok::html_ident, Toks[2].getKind()); + ASSERT_EQ(StringRef("attr"), Toks[2].getHTMLIdent()); - ASSERT_EQ(tok::newline, Toks[3].getKind()); + ASSERT_EQ(tok::newline, Toks[3].getKind()); } } @@ -1001,18 +1001,18 @@ TEST_F(CommentLexerTest, HTML10) { ASSERT_EQ(5U, Toks.size()); - ASSERT_EQ(tok::text, Toks[0].getKind()); - ASSERT_EQ(StringRef(" "), Toks[0].getText()); + ASSERT_EQ(tok::text, Toks[0].getKind()); + ASSERT_EQ(StringRef(" "), Toks[0].getText()); - ASSERT_EQ(tok::html_tag_open, Toks[1].getKind()); - ASSERT_EQ(StringRef("tag"), Toks[1].getHTMLTagOpenName()); + ASSERT_EQ(tok::html_start_tag, Toks[1].getKind()); + ASSERT_EQ(StringRef("tag"), Toks[1].getHTMLTagStartName()); - ASSERT_EQ(tok::html_ident, Toks[2].getKind()); - ASSERT_EQ(StringRef("attr"), Toks[2].getHTMLIdent()); + ASSERT_EQ(tok::html_ident, Toks[2].getKind()); + ASSERT_EQ(StringRef("attr"), Toks[2].getHTMLIdent()); - ASSERT_EQ(tok::html_equals, Toks[3].getKind()); + ASSERT_EQ(tok::html_equals, Toks[3].getKind()); - ASSERT_EQ(tok::newline, Toks[4].getKind()); + ASSERT_EQ(tok::newline, Toks[4].getKind()); } } @@ -1034,8 +1034,8 @@ TEST_F(CommentLexerTest, HTML11) { ASSERT_EQ(tok::text, Toks[0].getKind()); ASSERT_EQ(StringRef(" "), Toks[0].getText()); - ASSERT_EQ(tok::html_tag_open, Toks[1].getKind()); - ASSERT_EQ(StringRef("tag"), Toks[1].getHTMLTagOpenName()); + ASSERT_EQ(tok::html_start_tag, Toks[1].getKind()); + ASSERT_EQ(StringRef("tag"), Toks[1].getHTMLTagStartName()); ASSERT_EQ(tok::html_ident, Toks[2].getKind()); ASSERT_EQ(StringRef("attr"), Toks[2].getHTMLIdent()); @@ -1058,21 +1058,21 @@ TEST_F(CommentLexerTest, HTML12) { ASSERT_EQ(6U, Toks.size()); - ASSERT_EQ(tok::text, Toks[0].getKind()); - ASSERT_EQ(StringRef(" "), Toks[0].getText()); + ASSERT_EQ(tok::text, Toks[0].getKind()); + ASSERT_EQ(StringRef(" "), Toks[0].getText()); - ASSERT_EQ(tok::html_tag_open, Toks[1].getKind()); - ASSERT_EQ(StringRef("tag"), Toks[1].getHTMLTagOpenName()); + ASSERT_EQ(tok::html_start_tag, Toks[1].getKind()); + ASSERT_EQ(StringRef("tag"), Toks[1].getHTMLTagStartName()); - ASSERT_EQ(tok::html_ident, Toks[2].getKind()); - ASSERT_EQ(StringRef("attr"), Toks[2].getHTMLIdent()); + ASSERT_EQ(tok::html_ident, Toks[2].getKind()); + ASSERT_EQ(StringRef("attr"), Toks[2].getHTMLIdent()); - ASSERT_EQ(tok::html_equals, Toks[3].getKind()); + ASSERT_EQ(tok::html_equals, Toks[3].getKind()); - ASSERT_EQ(tok::text, Toks[4].getKind()); - ASSERT_EQ(StringRef("@"), Toks[4].getText()); + ASSERT_EQ(tok::text, Toks[4].getKind()); + ASSERT_EQ(StringRef("@"), Toks[4].getText()); - ASSERT_EQ(tok::newline, Toks[5].getKind()); + ASSERT_EQ(tok::newline, Toks[5].getKind()); } TEST_F(CommentLexerTest, HTML13) { @@ -1093,8 +1093,8 @@ TEST_F(CommentLexerTest, HTML13) { ASSERT_EQ(tok::text, Toks[0].getKind()); ASSERT_EQ(StringRef(" "), Toks[0].getText()); - ASSERT_EQ(tok::html_tag_open, Toks[1].getKind()); - ASSERT_EQ(StringRef("tag"), Toks[1].getHTMLTagOpenName()); + ASSERT_EQ(tok::html_start_tag, Toks[1].getKind()); + ASSERT_EQ(StringRef("tag"), Toks[1].getHTMLTagStartName()); ASSERT_EQ(tok::html_ident, Toks[2].getKind()); ASSERT_EQ(StringRef("attr"), Toks[2].getHTMLIdent()); @@ -1124,8 +1124,8 @@ TEST_F(CommentLexerTest, HTML14) { ASSERT_EQ(tok::text, Toks[0].getKind()); ASSERT_EQ(StringRef(" "), Toks[0].getText()); - ASSERT_EQ(tok::html_tag_open, Toks[1].getKind()); - ASSERT_EQ(StringRef("tag"), Toks[1].getHTMLTagOpenName()); + ASSERT_EQ(tok::html_start_tag, Toks[1].getKind()); + ASSERT_EQ(StringRef("tag"), Toks[1].getHTMLTagStartName()); ASSERT_EQ(tok::html_ident, Toks[2].getKind()); ASSERT_EQ(StringRef("attr"), Toks[2].getHTMLIdent()); @@ -1157,8 +1157,8 @@ TEST_F(CommentLexerTest, HTML15) { ASSERT_EQ(tok::text, Toks[0].getKind()); ASSERT_EQ(StringRef(" "), Toks[0].getText()); - ASSERT_EQ(tok::html_tag_open, Toks[1].getKind()); - ASSERT_EQ(StringRef("tag"), Toks[1].getHTMLTagOpenName()); + ASSERT_EQ(tok::html_start_tag, Toks[1].getKind()); + ASSERT_EQ(StringRef("tag"), Toks[1].getHTMLTagStartName()); ASSERT_EQ(tok::html_slash_greater, Toks[2].getKind()); @@ -1182,8 +1182,8 @@ TEST_F(CommentLexerTest, HTML16) { ASSERT_EQ(tok::text, Toks[0].getKind()); ASSERT_EQ(StringRef(" "), Toks[0].getText()); - ASSERT_EQ(tok::html_tag_open, Toks[1].getKind()); - ASSERT_EQ(StringRef("tag"), Toks[1].getHTMLTagOpenName()); + ASSERT_EQ(tok::html_start_tag, Toks[1].getKind()); + ASSERT_EQ(StringRef("tag"), Toks[1].getHTMLTagStartName()); ASSERT_EQ(tok::text, Toks[2].getKind()); ASSERT_EQ(StringRef("/"), Toks[2].getText()); @@ -1204,13 +1204,13 @@ TEST_F(CommentLexerTest, HTML17) { ASSERT_EQ(3U, Toks.size()); - ASSERT_EQ(tok::text, Toks[0].getKind()); - ASSERT_EQ(StringRef(" "), Toks[0].getText()); + ASSERT_EQ(tok::text, Toks[0].getKind()); + ASSERT_EQ(StringRef(" "), Toks[0].getText()); - ASSERT_EQ(tok::html_tag_close, Toks[1].getKind()); - ASSERT_EQ(StringRef(""), Toks[1].getHTMLTagCloseName()); + ASSERT_EQ(tok::html_end_tag, Toks[1].getKind()); + ASSERT_EQ(StringRef(""), Toks[1].getHTMLTagEndName()); - ASSERT_EQ(tok::newline, Toks[2].getKind()); + ASSERT_EQ(tok::newline, Toks[2].getKind()); } TEST_F(CommentLexerTest, HTML18) { @@ -1222,16 +1222,16 @@ TEST_F(CommentLexerTest, HTML18) { ASSERT_EQ(4U, Toks.size()); - ASSERT_EQ(tok::text, Toks[0].getKind()); - ASSERT_EQ(StringRef(" "), Toks[0].getText()); + ASSERT_EQ(tok::text, Toks[0].getKind()); + ASSERT_EQ(StringRef(" "), Toks[0].getText()); - ASSERT_EQ(tok::html_tag_close, Toks[1].getKind()); - ASSERT_EQ(StringRef(""), Toks[1].getHTMLTagCloseName()); + ASSERT_EQ(tok::html_end_tag, Toks[1].getKind()); + ASSERT_EQ(StringRef(""), Toks[1].getHTMLTagEndName()); - ASSERT_EQ(tok::text, Toks[2].getKind()); - ASSERT_EQ(StringRef("@"), Toks[2].getText()); + ASSERT_EQ(tok::text, Toks[2].getKind()); + ASSERT_EQ(StringRef("@"), Toks[2].getText()); - ASSERT_EQ(tok::newline, Toks[3].getKind()); + ASSERT_EQ(tok::newline, Toks[3].getKind()); } TEST_F(CommentLexerTest, HTML19) { @@ -1243,13 +1243,13 @@ TEST_F(CommentLexerTest, HTML19) { ASSERT_EQ(3U, Toks.size()); - ASSERT_EQ(tok::text, Toks[0].getKind()); - ASSERT_EQ(StringRef(" "), Toks[0].getText()); + ASSERT_EQ(tok::text, Toks[0].getKind()); + ASSERT_EQ(StringRef(" "), Toks[0].getText()); - ASSERT_EQ(tok::html_tag_close, Toks[1].getKind()); - ASSERT_EQ(StringRef("tag"), Toks[1].getHTMLTagCloseName()); + ASSERT_EQ(tok::html_end_tag, Toks[1].getKind()); + ASSERT_EQ(StringRef("tag"), Toks[1].getHTMLTagEndName()); - ASSERT_EQ(tok::newline, Toks[2].getKind()); + ASSERT_EQ(tok::newline, Toks[2].getKind()); } TEST_F(CommentLexerTest, HTML20) { @@ -1266,15 +1266,15 @@ TEST_F(CommentLexerTest, HTML20) { ASSERT_EQ(4U, Toks.size()); - ASSERT_EQ(tok::text, Toks[0].getKind()); - ASSERT_EQ(StringRef(" "), Toks[0].getText()); + ASSERT_EQ(tok::text, Toks[0].getKind()); + ASSERT_EQ(StringRef(" "), Toks[0].getText()); - ASSERT_EQ(tok::html_tag_close, Toks[1].getKind()); - ASSERT_EQ(StringRef("tag"), Toks[1].getHTMLTagCloseName()); + ASSERT_EQ(tok::html_end_tag, Toks[1].getKind()); + ASSERT_EQ(StringRef("tag"), Toks[1].getHTMLTagEndName()); - ASSERT_EQ(tok::html_greater, Toks[2].getKind()); + ASSERT_EQ(tok::html_greater, Toks[2].getKind()); - ASSERT_EQ(tok::newline, Toks[3].getKind()); + ASSERT_EQ(tok::newline, Toks[3].getKind()); } } diff --git a/unittests/AST/CommentParser.cpp b/unittests/AST/CommentParser.cpp index c779a881d4..d2f87488de 100644 --- a/unittests/AST/CommentParser.cpp +++ b/unittests/AST/CommentParser.cpp @@ -275,18 +275,18 @@ struct NoArgs {}; return ::testing::AssertionSuccess(); } -::testing::AssertionResult HasHTMLOpenTagAt(const Comment *C, - size_t Idx, - HTMLOpenTagComment *&HOT, - StringRef TagName) { - ::testing::AssertionResult AR = GetChildAt(C, Idx, HOT); +::testing::AssertionResult HasHTMLStartTagAt(const Comment *C, + size_t Idx, + HTMLStartTagComment *&HST, + StringRef TagName) { + ::testing::AssertionResult AR = GetChildAt(C, Idx, HST); if (!AR) return AR; - StringRef ActualTagName = HOT->getTagName(); + StringRef ActualTagName = HST->getTagName(); if (ActualTagName != TagName) return ::testing::AssertionFailure() - << "HTMLOpenTagComment has name \"" << ActualTagName.str() << "\", " + << "HTMLStartTagComment has name \"" << ActualTagName.str() << "\", " "expected \"" << TagName.str() << "\""; return ::testing::AssertionSuccess(); @@ -294,18 +294,18 @@ struct NoArgs {}; struct SelfClosing {}; -::testing::AssertionResult HasHTMLOpenTagAt(const Comment *C, - size_t Idx, - HTMLOpenTagComment *&HOT, - StringRef TagName, - SelfClosing) { - ::testing::AssertionResult AR = HasHTMLOpenTagAt(C, Idx, HOT, TagName); +::testing::AssertionResult HasHTMLStartTagAt(const Comment *C, + size_t Idx, + HTMLStartTagComment *&HST, + StringRef TagName, + SelfClosing) { + ::testing::AssertionResult AR = HasHTMLStartTagAt(C, Idx, HST, TagName); if (!AR) return AR; - if (!HOT->isSelfClosing()) + if (!HST->isSelfClosing()) return ::testing::AssertionFailure() - << "HTMLOpenTagComment is not self-closing"; + << "HTMLStartTagComment is not self-closing"; return ::testing::AssertionSuccess(); } @@ -313,73 +313,73 @@ struct SelfClosing {}; struct NoAttrs {}; -::testing::AssertionResult HasHTMLOpenTagAt(const Comment *C, - size_t Idx, - HTMLOpenTagComment *&HOT, - StringRef TagName, - NoAttrs) { - ::testing::AssertionResult AR = HasHTMLOpenTagAt(C, Idx, HOT, TagName); +::testing::AssertionResult HasHTMLStartTagAt(const Comment *C, + size_t Idx, + HTMLStartTagComment *&HST, + StringRef TagName, + NoAttrs) { + ::testing::AssertionResult AR = HasHTMLStartTagAt(C, Idx, HST, TagName); if (!AR) return AR; - if (HOT->isSelfClosing()) + if (HST->isSelfClosing()) return ::testing::AssertionFailure() - << "HTMLOpenTagComment is self-closing"; + << "HTMLStartTagComment is self-closing"; - if (HOT->getAttrCount() != 0) + if (HST->getAttrCount() != 0) return ::testing::AssertionFailure() - << "HTMLOpenTagComment has " << HOT->getAttrCount() << " attr(s), " + << "HTMLStartTagComment has " << HST->getAttrCount() << " attr(s), " "expected 0"; return ::testing::AssertionSuccess(); } -::testing::AssertionResult HasHTMLOpenTagAt(const Comment *C, - size_t Idx, - HTMLOpenTagComment *&HOT, - StringRef TagName, - StringRef AttrName, - StringRef AttrValue) { - ::testing::AssertionResult AR = HasHTMLOpenTagAt(C, Idx, HOT, TagName); +::testing::AssertionResult HasHTMLStartTagAt(const Comment *C, + size_t Idx, + HTMLStartTagComment *&HST, + StringRef TagName, + StringRef AttrName, + StringRef AttrValue) { + ::testing::AssertionResult AR = HasHTMLStartTagAt(C, Idx, HST, TagName); if (!AR) return AR; - if (HOT->isSelfClosing()) + if (HST->isSelfClosing()) return ::testing::AssertionFailure() - << "HTMLOpenTagComment is self-closing"; + << "HTMLStartTagComment is self-closing"; - if (HOT->getAttrCount() != 1) + if (HST->getAttrCount() != 1) return ::testing::AssertionFailure() - << "HTMLOpenTagComment has " << HOT->getAttrCount() << " attr(s), " + << "HTMLStartTagComment has " << HST->getAttrCount() << " attr(s), " "expected 1"; - StringRef ActualName = HOT->getAttr(0).Name; + StringRef ActualName = HST->getAttr(0).Name; if (ActualName != AttrName) return ::testing::AssertionFailure() - << "HTMLOpenTagComment has attr \"" << ActualName.str() << "\", " + << "HTMLStartTagComment has attr \"" << ActualName.str() << "\", " "expected \"" << AttrName.str() << "\""; - StringRef ActualValue = HOT->getAttr(0).Value; + StringRef ActualValue = HST->getAttr(0).Value; if (ActualValue != AttrValue) return ::testing::AssertionFailure() - << "HTMLOpenTagComment has attr value \"" << ActualValue.str() << "\", " + << "HTMLStartTagComment has attr value \"" << ActualValue.str() << "\", " "expected \"" << AttrValue.str() << "\""; return ::testing::AssertionSuccess(); } -::testing::AssertionResult HasHTMLCloseTagAt(const Comment *C, - size_t Idx, - HTMLCloseTagComment *&HCT, - StringRef TagName) { - ::testing::AssertionResult AR = GetChildAt(C, Idx, HCT); +::testing::AssertionResult HasHTMLEndTagAt(const Comment *C, + size_t Idx, + HTMLEndTagComment *&HET, + StringRef TagName) { + ::testing::AssertionResult AR = GetChildAt(C, Idx, HET); if (!AR) return AR; - StringRef ActualTagName = HCT->getTagName(); + StringRef ActualTagName = HET->getTagName(); if (ActualTagName != TagName) return ::testing::AssertionFailure() - << "HTMLCloseTagComment has name \"" << ActualTagName.str() << "\", " + << "HTMLEndTagComment has name \"" << ActualTagName.str() << "\", " "expected \"" << TagName.str() << "\""; return ::testing::AssertionSuccess(); @@ -852,12 +852,12 @@ TEST_F(CommentParserTest, HTML1) { { ParagraphComment *PC; - HTMLOpenTagComment *HOT; + HTMLStartTagComment *HST; ASSERT_TRUE(GetChildAt(FC, 0, PC)); ASSERT_TRUE(HasChildCount(PC, 2)); ASSERT_TRUE(HasTextAt(PC, 0, " ")); - ASSERT_TRUE(HasHTMLOpenTagAt(PC, 1, HOT, "a", NoAttrs())); + ASSERT_TRUE(HasHTMLStartTagAt(PC, 1, HST, "a", NoAttrs())); } } } @@ -874,12 +874,12 @@ TEST_F(CommentParserTest, HTML2) { { ParagraphComment *PC; - HTMLOpenTagComment *HOT; + HTMLStartTagComment *HST; ASSERT_TRUE(GetChildAt(FC, 0, PC)); ASSERT_TRUE(HasChildCount(PC, 2)); ASSERT_TRUE(HasTextAt(PC, 0, " ")); - ASSERT_TRUE(HasHTMLOpenTagAt(PC, 1, HOT, "br", SelfClosing())); + ASSERT_TRUE(HasHTMLStartTagAt(PC, 1, HST, "br", SelfClosing())); } } } @@ -898,12 +898,12 @@ TEST_F(CommentParserTest, HTML3) { { ParagraphComment *PC; - HTMLOpenTagComment *HOT; + HTMLStartTagComment *HST; ASSERT_TRUE(GetChildAt(FC, 0, PC)); ASSERT_TRUE(HasChildCount(PC, 2)); ASSERT_TRUE(HasTextAt(PC, 0, " ")); - ASSERT_TRUE(HasHTMLOpenTagAt(PC, 1, HOT, "a", "href", "")); + ASSERT_TRUE(HasHTMLStartTagAt(PC, 1, HST, "a", "href", "")); } } } @@ -920,12 +920,12 @@ TEST_F(CommentParserTest, HTML4) { { ParagraphComment *PC; - HTMLOpenTagComment *HOT; + HTMLStartTagComment *HST; ASSERT_TRUE(GetChildAt(FC, 0, PC)); ASSERT_TRUE(HasChildCount(PC, 2)); ASSERT_TRUE(HasTextAt(PC, 0, " ")); - ASSERT_TRUE(HasHTMLOpenTagAt(PC, 1, HOT, "a", "href", "bbb")); + ASSERT_TRUE(HasHTMLStartTagAt(PC, 1, HST, "a", "href", "bbb")); } } } @@ -943,12 +943,12 @@ TEST_F(CommentParserTest, HTML5) { { ParagraphComment *PC; - HTMLCloseTagComment *HCT; + HTMLEndTagComment *HET; ASSERT_TRUE(GetChildAt(FC, 0, PC)); ASSERT_TRUE(HasChildCount(PC, 2)); ASSERT_TRUE(HasTextAt(PC, 0, " ")); - ASSERT_TRUE(HasHTMLCloseTagAt(PC, 1, HCT, "a")); + ASSERT_TRUE(HasHTMLEndTagAt(PC, 1, HET, "a")); } } } @@ -965,17 +965,17 @@ TEST_F(CommentParserTest, HTML6) { { ParagraphComment *PC; - HTMLOpenTagComment *HOT; - HTMLCloseTagComment *HCT; + HTMLStartTagComment *HST; + HTMLEndTagComment *HET; ASSERT_TRUE(GetChildAt(FC, 0, PC)); ASSERT_TRUE(HasChildCount(PC, 6)); ASSERT_TRUE(HasTextAt(PC, 0, " ")); - ASSERT_TRUE(HasHTMLOpenTagAt(PC, 1, HOT, "pre", NoAttrs())); + ASSERT_TRUE(HasHTMLStartTagAt(PC, 1, HST, "pre", NoAttrs())); ASSERT_TRUE(HasTextWithNewlineAt(PC, 2, " Aaa")); ASSERT_TRUE(HasTextWithNewlineAt(PC, 3, " Bbb")); ASSERT_TRUE(HasTextAt(PC, 4, " ")); - ASSERT_TRUE(HasHTMLCloseTagAt(PC, 5, HCT, "pre")); + ASSERT_TRUE(HasHTMLEndTagAt(PC, 5, HET, "pre")); } } -- 2.40.0