diff options
author | dim <dim@FreeBSD.org> | 2013-04-08 18:45:10 +0000 |
---|---|---|
committer | dim <dim@FreeBSD.org> | 2013-04-08 18:45:10 +0000 |
commit | c72c57c9e9b69944e3e009cd5e209634839581d3 (patch) | |
tree | 4fc2f184c499d106f29a386c452b49e5197bf63d /lib/AST/CommentParser.cpp | |
parent | 5b20025c30d23d521e12c1f33ec8fa6b821952cd (diff) | |
download | FreeBSD-src-c72c57c9e9b69944e3e009cd5e209634839581d3.zip FreeBSD-src-c72c57c9e9b69944e3e009cd5e209634839581d3.tar.gz |
Vendor import of clang trunk r178860:
http://llvm.org/svn/llvm-project/cfe/trunk@178860
Diffstat (limited to 'lib/AST/CommentParser.cpp')
-rw-r--r-- | lib/AST/CommentParser.cpp | 66 |
1 files changed, 43 insertions, 23 deletions
diff --git a/lib/AST/CommentParser.cpp b/lib/AST/CommentParser.cpp index d0a8474..09912c6 100644 --- a/lib/AST/CommentParser.cpp +++ b/lib/AST/CommentParser.cpp @@ -8,9 +8,10 @@ //===----------------------------------------------------------------------===// #include "clang/AST/CommentParser.h" -#include "clang/AST/CommentSema.h" -#include "clang/AST/CommentDiagnostic.h" #include "clang/AST/CommentCommandTraits.h" +#include "clang/AST/CommentDiagnostic.h" +#include "clang/AST/CommentSema.h" +#include "clang/Basic/CharInfo.h" #include "clang/Basic/SourceManager.h" #include "llvm/Support/ErrorHandling.h" @@ -109,11 +110,6 @@ class TextTokenRetokenizer { return true; } - static bool isWhitespace(char C) { - return C == ' ' || C == '\n' || C == '\r' || - C == '\t' || C == '\f' || C == '\v'; - } - void consumeWhitespace() { while (!isEnd()) { if (isWhitespace(peek())) @@ -175,8 +171,7 @@ public: memcpy(TextPtr, WordText.c_str(), Length + 1); StringRef Text = StringRef(TextPtr, Length); - formTokenWithChars(Tok, Loc, WordBegin, - Pos.BufferPtr - WordBegin, Text); + formTokenWithChars(Tok, Loc, WordBegin, Length, Text); return true; } @@ -305,7 +300,7 @@ void Parser::parseBlockCommandArgs(BlockCommandComment *BC, } BlockCommandComment *Parser::parseBlockCommand() { - assert(Tok.is(tok::command)); + assert(Tok.is(tok::backslash_command) || Tok.is(tok::at_command)); ParamCommandComment *PC; TParamCommandComment *TPC; @@ -313,25 +308,29 @@ BlockCommandComment *Parser::parseBlockCommand() { bool IsParam = false; bool IsTParam = false; const CommandInfo *Info = Traits.getCommandInfo(Tok.getCommandID()); + CommandMarkerKind CommandMarker = + Tok.is(tok::backslash_command) ? CMK_Backslash : CMK_At; if (Info->IsParamCommand) { IsParam = true; PC = S.actOnParamCommandStart(Tok.getLocation(), Tok.getEndLocation(), - Tok.getCommandID()); - } if (Info->IsTParamCommand) { + Tok.getCommandID(), + CommandMarker); + } else if (Info->IsTParamCommand) { IsTParam = true; TPC = S.actOnTParamCommandStart(Tok.getLocation(), Tok.getEndLocation(), - Tok.getCommandID()); + Tok.getCommandID(), + CommandMarker); } else { BC = S.actOnBlockCommandStart(Tok.getLocation(), Tok.getEndLocation(), - Tok.getCommandID()); + Tok.getCommandID(), + CommandMarker); } consumeToken(); - if (Tok.is(tok::command) && - Traits.getCommandInfo(Tok.getCommandID())->IsBlockCommand) { + if (isTokBlockCommand()) { // Block command ahead. We can't nest block commands, so pretend that this // command has an empty argument. ParagraphComment *Paragraph = S.actOnParagraphComment( @@ -363,10 +362,28 @@ BlockCommandComment *Parser::parseBlockCommand() { Retokenizer.putBackLeftoverTokens(); } - BlockContentComment *Block = parseParagraphOrBlockCommand(); - // Since we have checked for a block command, we should have parsed a - // paragraph. - ParagraphComment *Paragraph = cast<ParagraphComment>(Block); + // If there's a block command ahead, we will attach an empty paragraph to + // this command. + bool EmptyParagraph = false; + if (isTokBlockCommand()) + EmptyParagraph = true; + else if (Tok.is(tok::newline)) { + Token PrevTok = Tok; + consumeToken(); + EmptyParagraph = isTokBlockCommand(); + putBack(PrevTok); + } + + ParagraphComment *Paragraph; + if (EmptyParagraph) + Paragraph = S.actOnParagraphComment(ArrayRef<InlineContentComment *>()); + else { + BlockContentComment *Block = parseParagraphOrBlockCommand(); + // Since we have checked for a block command, we should have parsed a + // paragraph. + Paragraph = cast<ParagraphComment>(Block); + } + if (IsParam) { S.actOnParamCommandFinish(PC, Paragraph); return PC; @@ -380,7 +397,7 @@ BlockCommandComment *Parser::parseBlockCommand() { } InlineCommandComment *Parser::parseInlineCommand() { - assert(Tok.is(tok::command)); + assert(Tok.is(tok::backslash_command) || Tok.is(tok::at_command)); const Token CommandTok = Tok; consumeToken(); @@ -547,7 +564,8 @@ BlockContentComment *Parser::parseParagraphOrBlockCommand() { consumeToken(); continue; - case tok::command: { + case tok::backslash_command: + case tok::at_command: { const CommandInfo *Info = Traits.getCommandInfo(Tok.getCommandID()); if (Info->IsBlockCommand) { if (Content.size() == 0) @@ -557,6 +575,7 @@ BlockContentComment *Parser::parseParagraphOrBlockCommand() { if (Info->IsVerbatimBlockEndCommand) { Diag(Tok.getLocation(), diag::warn_verbatim_block_end_without_start) + << Tok.is(tok::at_command) << Info->Name << SourceRange(Tok.getLocation(), Tok.getEndLocation()); consumeToken(); @@ -694,7 +713,8 @@ BlockContentComment *Parser::parseBlockContent() { switch (Tok.getKind()) { case tok::text: case tok::unknown_command: - case tok::command: + case tok::backslash_command: + case tok::at_command: case tok::html_start_tag: case tok::html_end_tag: return parseParagraphOrBlockCommand(); |