Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 1 | //===--- CommentParser.cpp - Doxygen comment parser -----------------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #include "clang/AST/CommentParser.h" |
Dmitri Gribenko | aa58081 | 2012-08-09 00:03:17 +0000 | [diff] [blame] | 11 | #include "clang/AST/CommentCommandTraits.h" |
Chandler Carruth | 55fc873 | 2012-12-04 09:13:33 +0000 | [diff] [blame^] | 12 | #include "clang/AST/CommentDiagnostic.h" |
| 13 | #include "clang/AST/CommentSema.h" |
Dmitri Gribenko | a5ef44f | 2012-07-11 21:38:39 +0000 | [diff] [blame] | 14 | #include "clang/Basic/SourceManager.h" |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 15 | #include "llvm/Support/ErrorHandling.h" |
| 16 | |
| 17 | namespace clang { |
| 18 | namespace comments { |
| 19 | |
Dmitri Gribenko | c4b0f9b | 2012-07-24 17:43:18 +0000 | [diff] [blame] | 20 | /// Re-lexes a sequence of tok::text tokens. |
| 21 | class TextTokenRetokenizer { |
| 22 | llvm::BumpPtrAllocator &Allocator; |
Dmitri Gribenko | db13f04 | 2012-07-24 17:52:18 +0000 | [diff] [blame] | 23 | Parser &P; |
Dmitri Gribenko | 0c43a92 | 2012-07-24 18:23:31 +0000 | [diff] [blame] | 24 | |
| 25 | /// This flag is set when there are no more tokens we can fetch from lexer. |
| 26 | bool NoMoreInterestingTokens; |
| 27 | |
| 28 | /// Token buffer: tokens we have processed and lookahead. |
Dmitri Gribenko | db13f04 | 2012-07-24 17:52:18 +0000 | [diff] [blame] | 29 | SmallVector<Token, 16> Toks; |
Dmitri Gribenko | c4b0f9b | 2012-07-24 17:43:18 +0000 | [diff] [blame] | 30 | |
Dmitri Gribenko | 0c43a92 | 2012-07-24 18:23:31 +0000 | [diff] [blame] | 31 | /// A position in \c Toks. |
Dmitri Gribenko | c4b0f9b | 2012-07-24 17:43:18 +0000 | [diff] [blame] | 32 | struct Position { |
| 33 | unsigned CurToken; |
| 34 | const char *BufferStart; |
| 35 | const char *BufferEnd; |
| 36 | const char *BufferPtr; |
| 37 | SourceLocation BufferStartLoc; |
| 38 | }; |
| 39 | |
| 40 | /// Current position in Toks. |
| 41 | Position Pos; |
| 42 | |
| 43 | bool isEnd() const { |
| 44 | return Pos.CurToken >= Toks.size(); |
| 45 | } |
| 46 | |
| 47 | /// Sets up the buffer pointers to point to current token. |
| 48 | void setupBuffer() { |
Dmitri Gribenko | db13f04 | 2012-07-24 17:52:18 +0000 | [diff] [blame] | 49 | assert(!isEnd()); |
Dmitri Gribenko | c4b0f9b | 2012-07-24 17:43:18 +0000 | [diff] [blame] | 50 | const Token &Tok = Toks[Pos.CurToken]; |
| 51 | |
| 52 | Pos.BufferStart = Tok.getText().begin(); |
| 53 | Pos.BufferEnd = Tok.getText().end(); |
| 54 | Pos.BufferPtr = Pos.BufferStart; |
| 55 | Pos.BufferStartLoc = Tok.getLocation(); |
| 56 | } |
| 57 | |
| 58 | SourceLocation getSourceLocation() const { |
| 59 | const unsigned CharNo = Pos.BufferPtr - Pos.BufferStart; |
| 60 | return Pos.BufferStartLoc.getLocWithOffset(CharNo); |
| 61 | } |
| 62 | |
| 63 | char peek() const { |
| 64 | assert(!isEnd()); |
| 65 | assert(Pos.BufferPtr != Pos.BufferEnd); |
| 66 | return *Pos.BufferPtr; |
| 67 | } |
| 68 | |
| 69 | void consumeChar() { |
| 70 | assert(!isEnd()); |
| 71 | assert(Pos.BufferPtr != Pos.BufferEnd); |
| 72 | Pos.BufferPtr++; |
| 73 | if (Pos.BufferPtr == Pos.BufferEnd) { |
| 74 | Pos.CurToken++; |
Dmitri Gribenko | 0c43a92 | 2012-07-24 18:23:31 +0000 | [diff] [blame] | 75 | if (isEnd() && !addToken()) |
| 76 | return; |
| 77 | |
| 78 | assert(!isEnd()); |
| 79 | setupBuffer(); |
Dmitri Gribenko | c4b0f9b | 2012-07-24 17:43:18 +0000 | [diff] [blame] | 80 | } |
| 81 | } |
| 82 | |
Dmitri Gribenko | db13f04 | 2012-07-24 17:52:18 +0000 | [diff] [blame] | 83 | /// Add a token. |
| 84 | /// Returns true on success, false if there are no interesting tokens to |
| 85 | /// fetch from lexer. |
| 86 | bool addToken() { |
Dmitri Gribenko | 0c43a92 | 2012-07-24 18:23:31 +0000 | [diff] [blame] | 87 | if (NoMoreInterestingTokens) |
Dmitri Gribenko | db13f04 | 2012-07-24 17:52:18 +0000 | [diff] [blame] | 88 | return false; |
| 89 | |
Dmitri Gribenko | 0c43a92 | 2012-07-24 18:23:31 +0000 | [diff] [blame] | 90 | if (P.Tok.is(tok::newline)) { |
| 91 | // If we see a single newline token between text tokens, skip it. |
| 92 | Token Newline = P.Tok; |
| 93 | P.consumeToken(); |
| 94 | if (P.Tok.isNot(tok::text)) { |
| 95 | P.putBack(Newline); |
| 96 | NoMoreInterestingTokens = true; |
| 97 | return false; |
| 98 | } |
| 99 | } |
| 100 | if (P.Tok.isNot(tok::text)) { |
| 101 | NoMoreInterestingTokens = true; |
| 102 | return false; |
| 103 | } |
| 104 | |
Dmitri Gribenko | db13f04 | 2012-07-24 17:52:18 +0000 | [diff] [blame] | 105 | Toks.push_back(P.Tok); |
| 106 | P.consumeToken(); |
| 107 | if (Toks.size() == 1) |
| 108 | setupBuffer(); |
| 109 | return true; |
| 110 | } |
| 111 | |
Dmitri Gribenko | c4b0f9b | 2012-07-24 17:43:18 +0000 | [diff] [blame] | 112 | static bool isWhitespace(char C) { |
| 113 | return C == ' ' || C == '\n' || C == '\r' || |
| 114 | C == '\t' || C == '\f' || C == '\v'; |
| 115 | } |
| 116 | |
| 117 | void consumeWhitespace() { |
| 118 | while (!isEnd()) { |
| 119 | if (isWhitespace(peek())) |
| 120 | consumeChar(); |
| 121 | else |
| 122 | break; |
| 123 | } |
| 124 | } |
| 125 | |
| 126 | void formTokenWithChars(Token &Result, |
| 127 | SourceLocation Loc, |
| 128 | const char *TokBegin, |
| 129 | unsigned TokLength, |
| 130 | StringRef Text) { |
| 131 | Result.setLocation(Loc); |
| 132 | Result.setKind(tok::text); |
| 133 | Result.setLength(TokLength); |
| 134 | #ifndef NDEBUG |
Dmitri Gribenko | e4330a3 | 2012-09-10 20:32:42 +0000 | [diff] [blame] | 135 | Result.TextPtr = "<UNSET>"; |
| 136 | Result.IntVal = 7; |
Dmitri Gribenko | c4b0f9b | 2012-07-24 17:43:18 +0000 | [diff] [blame] | 137 | #endif |
| 138 | Result.setText(Text); |
| 139 | } |
| 140 | |
| 141 | public: |
Dmitri Gribenko | db13f04 | 2012-07-24 17:52:18 +0000 | [diff] [blame] | 142 | TextTokenRetokenizer(llvm::BumpPtrAllocator &Allocator, Parser &P): |
Dmitri Gribenko | 0c43a92 | 2012-07-24 18:23:31 +0000 | [diff] [blame] | 143 | Allocator(Allocator), P(P), NoMoreInterestingTokens(false) { |
Dmitri Gribenko | c4b0f9b | 2012-07-24 17:43:18 +0000 | [diff] [blame] | 144 | Pos.CurToken = 0; |
Dmitri Gribenko | db13f04 | 2012-07-24 17:52:18 +0000 | [diff] [blame] | 145 | addToken(); |
Dmitri Gribenko | c4b0f9b | 2012-07-24 17:43:18 +0000 | [diff] [blame] | 146 | } |
| 147 | |
| 148 | /// Extract a word -- sequence of non-whitespace characters. |
| 149 | bool lexWord(Token &Tok) { |
| 150 | if (isEnd()) |
| 151 | return false; |
| 152 | |
| 153 | Position SavedPos = Pos; |
| 154 | |
| 155 | consumeWhitespace(); |
| 156 | SmallString<32> WordText; |
| 157 | const char *WordBegin = Pos.BufferPtr; |
| 158 | SourceLocation Loc = getSourceLocation(); |
| 159 | while (!isEnd()) { |
| 160 | const char C = peek(); |
| 161 | if (!isWhitespace(C)) { |
| 162 | WordText.push_back(C); |
| 163 | consumeChar(); |
| 164 | } else |
| 165 | break; |
| 166 | } |
| 167 | const unsigned Length = WordText.size(); |
| 168 | if (Length == 0) { |
| 169 | Pos = SavedPos; |
| 170 | return false; |
| 171 | } |
| 172 | |
| 173 | char *TextPtr = Allocator.Allocate<char>(Length + 1); |
| 174 | |
| 175 | memcpy(TextPtr, WordText.c_str(), Length + 1); |
| 176 | StringRef Text = StringRef(TextPtr, Length); |
| 177 | |
| 178 | formTokenWithChars(Tok, Loc, WordBegin, |
| 179 | Pos.BufferPtr - WordBegin, Text); |
| 180 | return true; |
| 181 | } |
| 182 | |
| 183 | bool lexDelimitedSeq(Token &Tok, char OpenDelim, char CloseDelim) { |
| 184 | if (isEnd()) |
| 185 | return false; |
| 186 | |
| 187 | Position SavedPos = Pos; |
| 188 | |
| 189 | consumeWhitespace(); |
| 190 | SmallString<32> WordText; |
| 191 | const char *WordBegin = Pos.BufferPtr; |
| 192 | SourceLocation Loc = getSourceLocation(); |
| 193 | bool Error = false; |
| 194 | if (!isEnd()) { |
| 195 | const char C = peek(); |
| 196 | if (C == OpenDelim) { |
| 197 | WordText.push_back(C); |
| 198 | consumeChar(); |
| 199 | } else |
| 200 | Error = true; |
| 201 | } |
| 202 | char C = '\0'; |
| 203 | while (!Error && !isEnd()) { |
| 204 | C = peek(); |
| 205 | WordText.push_back(C); |
| 206 | consumeChar(); |
| 207 | if (C == CloseDelim) |
| 208 | break; |
| 209 | } |
| 210 | if (!Error && C != CloseDelim) |
| 211 | Error = true; |
| 212 | |
| 213 | if (Error) { |
| 214 | Pos = SavedPos; |
| 215 | return false; |
| 216 | } |
| 217 | |
| 218 | const unsigned Length = WordText.size(); |
| 219 | char *TextPtr = Allocator.Allocate<char>(Length + 1); |
| 220 | |
| 221 | memcpy(TextPtr, WordText.c_str(), Length + 1); |
| 222 | StringRef Text = StringRef(TextPtr, Length); |
| 223 | |
| 224 | formTokenWithChars(Tok, Loc, WordBegin, |
| 225 | Pos.BufferPtr - WordBegin, Text); |
| 226 | return true; |
| 227 | } |
| 228 | |
Dmitri Gribenko | db13f04 | 2012-07-24 17:52:18 +0000 | [diff] [blame] | 229 | /// Put back tokens that we didn't consume. |
| 230 | void putBackLeftoverTokens() { |
Dmitri Gribenko | c4b0f9b | 2012-07-24 17:43:18 +0000 | [diff] [blame] | 231 | if (isEnd()) |
Dmitri Gribenko | db13f04 | 2012-07-24 17:52:18 +0000 | [diff] [blame] | 232 | return; |
Dmitri Gribenko | c4b0f9b | 2012-07-24 17:43:18 +0000 | [diff] [blame] | 233 | |
Dmitri Gribenko | db13f04 | 2012-07-24 17:52:18 +0000 | [diff] [blame] | 234 | bool HavePartialTok = false; |
| 235 | Token PartialTok; |
| 236 | if (Pos.BufferPtr != Pos.BufferStart) { |
| 237 | formTokenWithChars(PartialTok, getSourceLocation(), |
Dmitri Gribenko | c4b0f9b | 2012-07-24 17:43:18 +0000 | [diff] [blame] | 238 | Pos.BufferPtr, Pos.BufferEnd - Pos.BufferPtr, |
| 239 | StringRef(Pos.BufferPtr, |
| 240 | Pos.BufferEnd - Pos.BufferPtr)); |
Dmitri Gribenko | db13f04 | 2012-07-24 17:52:18 +0000 | [diff] [blame] | 241 | HavePartialTok = true; |
| 242 | Pos.CurToken++; |
| 243 | } |
Dmitri Gribenko | c4b0f9b | 2012-07-24 17:43:18 +0000 | [diff] [blame] | 244 | |
Dmitri Gribenko | db13f04 | 2012-07-24 17:52:18 +0000 | [diff] [blame] | 245 | P.putBack(llvm::makeArrayRef(Toks.begin() + Pos.CurToken, Toks.end())); |
| 246 | Pos.CurToken = Toks.size(); |
| 247 | |
| 248 | if (HavePartialTok) |
| 249 | P.putBack(PartialTok); |
Dmitri Gribenko | c4b0f9b | 2012-07-24 17:43:18 +0000 | [diff] [blame] | 250 | } |
| 251 | }; |
| 252 | |
Dmitri Gribenko | a5ef44f | 2012-07-11 21:38:39 +0000 | [diff] [blame] | 253 | Parser::Parser(Lexer &L, Sema &S, llvm::BumpPtrAllocator &Allocator, |
Dmitri Gribenko | aa58081 | 2012-08-09 00:03:17 +0000 | [diff] [blame] | 254 | const SourceManager &SourceMgr, DiagnosticsEngine &Diags, |
| 255 | const CommandTraits &Traits): |
| 256 | L(L), S(S), Allocator(Allocator), SourceMgr(SourceMgr), Diags(Diags), |
| 257 | Traits(Traits) { |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 258 | consumeToken(); |
| 259 | } |
| 260 | |
Dmitri Gribenko | 7d9b511 | 2012-08-06 19:03:12 +0000 | [diff] [blame] | 261 | void Parser::parseParamCommandArgs(ParamCommandComment *PC, |
| 262 | TextTokenRetokenizer &Retokenizer) { |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 263 | Token Arg; |
| 264 | // Check if argument looks like direction specification: [dir] |
| 265 | // e.g., [in], [out], [in,out] |
| 266 | if (Retokenizer.lexDelimitedSeq(Arg, '[', ']')) |
Dmitri Gribenko | 7d9b511 | 2012-08-06 19:03:12 +0000 | [diff] [blame] | 267 | S.actOnParamCommandDirectionArg(PC, |
| 268 | Arg.getLocation(), |
| 269 | Arg.getEndLocation(), |
| 270 | Arg.getText()); |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 271 | |
| 272 | if (Retokenizer.lexWord(Arg)) |
Dmitri Gribenko | 7d9b511 | 2012-08-06 19:03:12 +0000 | [diff] [blame] | 273 | S.actOnParamCommandParamNameArg(PC, |
| 274 | Arg.getLocation(), |
| 275 | Arg.getEndLocation(), |
| 276 | Arg.getText()); |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 277 | } |
| 278 | |
Dmitri Gribenko | 7d9b511 | 2012-08-06 19:03:12 +0000 | [diff] [blame] | 279 | void Parser::parseTParamCommandArgs(TParamCommandComment *TPC, |
| 280 | TextTokenRetokenizer &Retokenizer) { |
Dmitri Gribenko | 96b0986 | 2012-07-31 22:37:06 +0000 | [diff] [blame] | 281 | Token Arg; |
| 282 | if (Retokenizer.lexWord(Arg)) |
Dmitri Gribenko | 7d9b511 | 2012-08-06 19:03:12 +0000 | [diff] [blame] | 283 | S.actOnTParamCommandParamNameArg(TPC, |
| 284 | Arg.getLocation(), |
| 285 | Arg.getEndLocation(), |
| 286 | Arg.getText()); |
Dmitri Gribenko | 96b0986 | 2012-07-31 22:37:06 +0000 | [diff] [blame] | 287 | } |
| 288 | |
Dmitri Gribenko | 7d9b511 | 2012-08-06 19:03:12 +0000 | [diff] [blame] | 289 | void Parser::parseBlockCommandArgs(BlockCommandComment *BC, |
| 290 | TextTokenRetokenizer &Retokenizer, |
| 291 | unsigned NumArgs) { |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 292 | typedef BlockCommandComment::Argument Argument; |
Dmitri Gribenko | 814e219 | 2012-07-06 16:41:59 +0000 | [diff] [blame] | 293 | Argument *Args = |
| 294 | new (Allocator.Allocate<Argument>(NumArgs)) Argument[NumArgs]; |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 295 | unsigned ParsedArgs = 0; |
| 296 | Token Arg; |
| 297 | while (ParsedArgs < NumArgs && Retokenizer.lexWord(Arg)) { |
| 298 | Args[ParsedArgs] = Argument(SourceRange(Arg.getLocation(), |
| 299 | Arg.getEndLocation()), |
| 300 | Arg.getText()); |
| 301 | ParsedArgs++; |
| 302 | } |
| 303 | |
Dmitri Gribenko | 7d9b511 | 2012-08-06 19:03:12 +0000 | [diff] [blame] | 304 | S.actOnBlockCommandArgs(BC, llvm::makeArrayRef(Args, ParsedArgs)); |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 305 | } |
| 306 | |
| 307 | BlockCommandComment *Parser::parseBlockCommand() { |
| 308 | assert(Tok.is(tok::command)); |
| 309 | |
| 310 | ParamCommandComment *PC; |
Dmitri Gribenko | 96b0986 | 2012-07-31 22:37:06 +0000 | [diff] [blame] | 311 | TParamCommandComment *TPC; |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 312 | BlockCommandComment *BC; |
| 313 | bool IsParam = false; |
Dmitri Gribenko | 96b0986 | 2012-07-31 22:37:06 +0000 | [diff] [blame] | 314 | bool IsTParam = false; |
Dmitri Gribenko | e4330a3 | 2012-09-10 20:32:42 +0000 | [diff] [blame] | 315 | const CommandInfo *Info = Traits.getCommandInfo(Tok.getCommandID()); |
| 316 | if (Info->IsParamCommand) { |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 317 | IsParam = true; |
| 318 | PC = S.actOnParamCommandStart(Tok.getLocation(), |
| 319 | Tok.getEndLocation(), |
Dmitri Gribenko | e4330a3 | 2012-09-10 20:32:42 +0000 | [diff] [blame] | 320 | Tok.getCommandID()); |
| 321 | } if (Info->IsTParamCommand) { |
Dmitri Gribenko | 96b0986 | 2012-07-31 22:37:06 +0000 | [diff] [blame] | 322 | IsTParam = true; |
| 323 | TPC = S.actOnTParamCommandStart(Tok.getLocation(), |
| 324 | Tok.getEndLocation(), |
Dmitri Gribenko | e4330a3 | 2012-09-10 20:32:42 +0000 | [diff] [blame] | 325 | Tok.getCommandID()); |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 326 | } else { |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 327 | BC = S.actOnBlockCommandStart(Tok.getLocation(), |
| 328 | Tok.getEndLocation(), |
Dmitri Gribenko | e4330a3 | 2012-09-10 20:32:42 +0000 | [diff] [blame] | 329 | Tok.getCommandID()); |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 330 | } |
| 331 | consumeToken(); |
| 332 | |
Dmitri Gribenko | e4330a3 | 2012-09-10 20:32:42 +0000 | [diff] [blame] | 333 | if (Tok.is(tok::command) && |
| 334 | Traits.getCommandInfo(Tok.getCommandID())->IsBlockCommand) { |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 335 | // Block command ahead. We can't nest block commands, so pretend that this |
| 336 | // command has an empty argument. |
Dmitri Gribenko | e5deb79 | 2012-07-30 18:05:28 +0000 | [diff] [blame] | 337 | ParagraphComment *Paragraph = S.actOnParagraphComment( |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 338 | ArrayRef<InlineContentComment *>()); |
Dmitri Gribenko | 7d9b511 | 2012-08-06 19:03:12 +0000 | [diff] [blame] | 339 | if (IsParam) { |
Dmitri Gribenko | 8a90393 | 2012-08-06 23:48:44 +0000 | [diff] [blame] | 340 | S.actOnParamCommandFinish(PC, Paragraph); |
Dmitri Gribenko | 7d9b511 | 2012-08-06 19:03:12 +0000 | [diff] [blame] | 341 | return PC; |
Dmitri Gribenko | 8a90393 | 2012-08-06 23:48:44 +0000 | [diff] [blame] | 342 | } else if (IsTParam) { |
| 343 | S.actOnTParamCommandFinish(TPC, Paragraph); |
| 344 | return TPC; |
Dmitri Gribenko | 7d9b511 | 2012-08-06 19:03:12 +0000 | [diff] [blame] | 345 | } else { |
| 346 | S.actOnBlockCommandFinish(BC, Paragraph); |
| 347 | return BC; |
| 348 | } |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 349 | } |
| 350 | |
Dmitri Gribenko | e4330a3 | 2012-09-10 20:32:42 +0000 | [diff] [blame] | 351 | if (IsParam || IsTParam || Info->NumArgs > 0) { |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 352 | // In order to parse command arguments we need to retokenize a few |
| 353 | // following text tokens. |
Dmitri Gribenko | db13f04 | 2012-07-24 17:52:18 +0000 | [diff] [blame] | 354 | TextTokenRetokenizer Retokenizer(Allocator, *this); |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 355 | |
| 356 | if (IsParam) |
Dmitri Gribenko | 7d9b511 | 2012-08-06 19:03:12 +0000 | [diff] [blame] | 357 | parseParamCommandArgs(PC, Retokenizer); |
Dmitri Gribenko | 96b0986 | 2012-07-31 22:37:06 +0000 | [diff] [blame] | 358 | else if (IsTParam) |
Dmitri Gribenko | 7d9b511 | 2012-08-06 19:03:12 +0000 | [diff] [blame] | 359 | parseTParamCommandArgs(TPC, Retokenizer); |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 360 | else |
Dmitri Gribenko | e4330a3 | 2012-09-10 20:32:42 +0000 | [diff] [blame] | 361 | parseBlockCommandArgs(BC, Retokenizer, Info->NumArgs); |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 362 | |
Dmitri Gribenko | db13f04 | 2012-07-24 17:52:18 +0000 | [diff] [blame] | 363 | Retokenizer.putBackLeftoverTokens(); |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 364 | } |
| 365 | |
| 366 | BlockContentComment *Block = parseParagraphOrBlockCommand(); |
| 367 | // Since we have checked for a block command, we should have parsed a |
| 368 | // paragraph. |
Dmitri Gribenko | 7d9b511 | 2012-08-06 19:03:12 +0000 | [diff] [blame] | 369 | ParagraphComment *Paragraph = cast<ParagraphComment>(Block); |
| 370 | if (IsParam) { |
| 371 | S.actOnParamCommandFinish(PC, Paragraph); |
| 372 | return PC; |
| 373 | } else if (IsTParam) { |
| 374 | S.actOnTParamCommandFinish(TPC, Paragraph); |
| 375 | return TPC; |
| 376 | } else { |
| 377 | S.actOnBlockCommandFinish(BC, Paragraph); |
| 378 | return BC; |
| 379 | } |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 380 | } |
| 381 | |
| 382 | InlineCommandComment *Parser::parseInlineCommand() { |
| 383 | assert(Tok.is(tok::command)); |
| 384 | |
| 385 | const Token CommandTok = Tok; |
| 386 | consumeToken(); |
| 387 | |
Dmitri Gribenko | db13f04 | 2012-07-24 17:52:18 +0000 | [diff] [blame] | 388 | TextTokenRetokenizer Retokenizer(Allocator, *this); |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 389 | |
| 390 | Token ArgTok; |
| 391 | bool ArgTokValid = Retokenizer.lexWord(ArgTok); |
| 392 | |
| 393 | InlineCommandComment *IC; |
| 394 | if (ArgTokValid) { |
| 395 | IC = S.actOnInlineCommand(CommandTok.getLocation(), |
| 396 | CommandTok.getEndLocation(), |
Dmitri Gribenko | e4330a3 | 2012-09-10 20:32:42 +0000 | [diff] [blame] | 397 | CommandTok.getCommandID(), |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 398 | ArgTok.getLocation(), |
| 399 | ArgTok.getEndLocation(), |
| 400 | ArgTok.getText()); |
| 401 | } else { |
| 402 | IC = S.actOnInlineCommand(CommandTok.getLocation(), |
| 403 | CommandTok.getEndLocation(), |
Dmitri Gribenko | e4330a3 | 2012-09-10 20:32:42 +0000 | [diff] [blame] | 404 | CommandTok.getCommandID()); |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 405 | } |
| 406 | |
Dmitri Gribenko | db13f04 | 2012-07-24 17:52:18 +0000 | [diff] [blame] | 407 | Retokenizer.putBackLeftoverTokens(); |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 408 | |
| 409 | return IC; |
| 410 | } |
| 411 | |
Dmitri Gribenko | 3f38bf2 | 2012-07-13 00:44:24 +0000 | [diff] [blame] | 412 | HTMLStartTagComment *Parser::parseHTMLStartTag() { |
| 413 | assert(Tok.is(tok::html_start_tag)); |
| 414 | HTMLStartTagComment *HST = |
| 415 | S.actOnHTMLStartTagStart(Tok.getLocation(), |
| 416 | Tok.getHTMLTagStartName()); |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 417 | consumeToken(); |
| 418 | |
Dmitri Gribenko | 3f38bf2 | 2012-07-13 00:44:24 +0000 | [diff] [blame] | 419 | SmallVector<HTMLStartTagComment::Attribute, 2> Attrs; |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 420 | while (true) { |
Dmitri Gribenko | a5ef44f | 2012-07-11 21:38:39 +0000 | [diff] [blame] | 421 | switch (Tok.getKind()) { |
| 422 | case tok::html_ident: { |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 423 | Token Ident = Tok; |
| 424 | consumeToken(); |
| 425 | if (Tok.isNot(tok::html_equals)) { |
Dmitri Gribenko | 3f38bf2 | 2012-07-13 00:44:24 +0000 | [diff] [blame] | 426 | Attrs.push_back(HTMLStartTagComment::Attribute(Ident.getLocation(), |
| 427 | Ident.getHTMLIdent())); |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 428 | continue; |
| 429 | } |
| 430 | Token Equals = Tok; |
| 431 | consumeToken(); |
| 432 | if (Tok.isNot(tok::html_quoted_string)) { |
Dmitri Gribenko | a5ef44f | 2012-07-11 21:38:39 +0000 | [diff] [blame] | 433 | Diag(Tok.getLocation(), |
Dmitri Gribenko | 3f38bf2 | 2012-07-13 00:44:24 +0000 | [diff] [blame] | 434 | diag::warn_doc_html_start_tag_expected_quoted_string) |
Dmitri Gribenko | a5ef44f | 2012-07-11 21:38:39 +0000 | [diff] [blame] | 435 | << SourceRange(Equals.getLocation()); |
Dmitri Gribenko | 3f38bf2 | 2012-07-13 00:44:24 +0000 | [diff] [blame] | 436 | Attrs.push_back(HTMLStartTagComment::Attribute(Ident.getLocation(), |
| 437 | Ident.getHTMLIdent())); |
Dmitri Gribenko | a5ef44f | 2012-07-11 21:38:39 +0000 | [diff] [blame] | 438 | while (Tok.is(tok::html_equals) || |
| 439 | Tok.is(tok::html_quoted_string)) |
| 440 | consumeToken(); |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 441 | continue; |
| 442 | } |
Dmitri Gribenko | 3f38bf2 | 2012-07-13 00:44:24 +0000 | [diff] [blame] | 443 | Attrs.push_back(HTMLStartTagComment::Attribute( |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 444 | Ident.getLocation(), |
| 445 | Ident.getHTMLIdent(), |
| 446 | Equals.getLocation(), |
| 447 | SourceRange(Tok.getLocation(), |
| 448 | Tok.getEndLocation()), |
| 449 | Tok.getHTMLQuotedString())); |
| 450 | consumeToken(); |
| 451 | continue; |
Dmitri Gribenko | a5ef44f | 2012-07-11 21:38:39 +0000 | [diff] [blame] | 452 | } |
| 453 | |
| 454 | case tok::html_greater: |
Dmitri Gribenko | 7d9b511 | 2012-08-06 19:03:12 +0000 | [diff] [blame] | 455 | S.actOnHTMLStartTagFinish(HST, |
| 456 | S.copyArray(llvm::makeArrayRef(Attrs)), |
| 457 | Tok.getLocation(), |
| 458 | /* IsSelfClosing = */ false); |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 459 | consumeToken(); |
Dmitri Gribenko | 3f38bf2 | 2012-07-13 00:44:24 +0000 | [diff] [blame] | 460 | return HST; |
Dmitri Gribenko | a5ef44f | 2012-07-11 21:38:39 +0000 | [diff] [blame] | 461 | |
| 462 | case tok::html_slash_greater: |
Dmitri Gribenko | 7d9b511 | 2012-08-06 19:03:12 +0000 | [diff] [blame] | 463 | S.actOnHTMLStartTagFinish(HST, |
| 464 | S.copyArray(llvm::makeArrayRef(Attrs)), |
| 465 | Tok.getLocation(), |
| 466 | /* IsSelfClosing = */ true); |
Dmitri Gribenko | a5ef44f | 2012-07-11 21:38:39 +0000 | [diff] [blame] | 467 | consumeToken(); |
Dmitri Gribenko | 3f38bf2 | 2012-07-13 00:44:24 +0000 | [diff] [blame] | 468 | return HST; |
Dmitri Gribenko | a5ef44f | 2012-07-11 21:38:39 +0000 | [diff] [blame] | 469 | |
| 470 | case tok::html_equals: |
| 471 | case tok::html_quoted_string: |
| 472 | Diag(Tok.getLocation(), |
Dmitri Gribenko | 3f38bf2 | 2012-07-13 00:44:24 +0000 | [diff] [blame] | 473 | diag::warn_doc_html_start_tag_expected_ident_or_greater); |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 474 | while (Tok.is(tok::html_equals) || |
| 475 | Tok.is(tok::html_quoted_string)) |
| 476 | consumeToken(); |
Dmitri Gribenko | a5ef44f | 2012-07-11 21:38:39 +0000 | [diff] [blame] | 477 | if (Tok.is(tok::html_ident) || |
| 478 | Tok.is(tok::html_greater) || |
| 479 | Tok.is(tok::html_slash_greater)) |
| 480 | continue; |
| 481 | |
Dmitri Gribenko | 7d9b511 | 2012-08-06 19:03:12 +0000 | [diff] [blame] | 482 | S.actOnHTMLStartTagFinish(HST, |
| 483 | S.copyArray(llvm::makeArrayRef(Attrs)), |
| 484 | SourceLocation(), |
| 485 | /* IsSelfClosing = */ false); |
| 486 | return HST; |
Dmitri Gribenko | 3f38bf2 | 2012-07-13 00:44:24 +0000 | [diff] [blame] | 487 | |
| 488 | default: |
| 489 | // Not a token from an HTML start tag. Thus HTML tag prematurely ended. |
Dmitri Gribenko | 7d9b511 | 2012-08-06 19:03:12 +0000 | [diff] [blame] | 490 | S.actOnHTMLStartTagFinish(HST, |
| 491 | S.copyArray(llvm::makeArrayRef(Attrs)), |
| 492 | SourceLocation(), |
| 493 | /* IsSelfClosing = */ false); |
Dmitri Gribenko | a5ef44f | 2012-07-11 21:38:39 +0000 | [diff] [blame] | 494 | bool StartLineInvalid; |
| 495 | const unsigned StartLine = SourceMgr.getPresumedLineNumber( |
Dmitri Gribenko | 3f38bf2 | 2012-07-13 00:44:24 +0000 | [diff] [blame] | 496 | HST->getLocation(), |
Dmitri Gribenko | a5ef44f | 2012-07-11 21:38:39 +0000 | [diff] [blame] | 497 | &StartLineInvalid); |
| 498 | bool EndLineInvalid; |
| 499 | const unsigned EndLine = SourceMgr.getPresumedLineNumber( |
| 500 | Tok.getLocation(), |
| 501 | &EndLineInvalid); |
| 502 | if (StartLineInvalid || EndLineInvalid || StartLine == EndLine) |
| 503 | Diag(Tok.getLocation(), |
Dmitri Gribenko | 3f38bf2 | 2012-07-13 00:44:24 +0000 | [diff] [blame] | 504 | diag::warn_doc_html_start_tag_expected_ident_or_greater) |
| 505 | << HST->getSourceRange(); |
Dmitri Gribenko | a5ef44f | 2012-07-11 21:38:39 +0000 | [diff] [blame] | 506 | else { |
| 507 | Diag(Tok.getLocation(), |
Dmitri Gribenko | 3f38bf2 | 2012-07-13 00:44:24 +0000 | [diff] [blame] | 508 | diag::warn_doc_html_start_tag_expected_ident_or_greater); |
| 509 | Diag(HST->getLocation(), diag::note_doc_html_tag_started_here) |
| 510 | << HST->getSourceRange(); |
Dmitri Gribenko | a5ef44f | 2012-07-11 21:38:39 +0000 | [diff] [blame] | 511 | } |
Dmitri Gribenko | 3f38bf2 | 2012-07-13 00:44:24 +0000 | [diff] [blame] | 512 | return HST; |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 513 | } |
| 514 | } |
| 515 | } |
| 516 | |
Dmitri Gribenko | 3f38bf2 | 2012-07-13 00:44:24 +0000 | [diff] [blame] | 517 | HTMLEndTagComment *Parser::parseHTMLEndTag() { |
| 518 | assert(Tok.is(tok::html_end_tag)); |
| 519 | Token TokEndTag = Tok; |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 520 | consumeToken(); |
| 521 | SourceLocation Loc; |
| 522 | if (Tok.is(tok::html_greater)) { |
| 523 | Loc = Tok.getLocation(); |
| 524 | consumeToken(); |
| 525 | } |
| 526 | |
Dmitri Gribenko | 3f38bf2 | 2012-07-13 00:44:24 +0000 | [diff] [blame] | 527 | return S.actOnHTMLEndTag(TokEndTag.getLocation(), |
| 528 | Loc, |
| 529 | TokEndTag.getHTMLTagEndName()); |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 530 | } |
| 531 | |
| 532 | BlockContentComment *Parser::parseParagraphOrBlockCommand() { |
| 533 | SmallVector<InlineContentComment *, 8> Content; |
| 534 | |
| 535 | while (true) { |
| 536 | switch (Tok.getKind()) { |
| 537 | case tok::verbatim_block_begin: |
| 538 | case tok::verbatim_line_name: |
| 539 | case tok::eof: |
| 540 | assert(Content.size() != 0); |
| 541 | break; // Block content or EOF ahead, finish this parapgaph. |
| 542 | |
Dmitri Gribenko | e4330a3 | 2012-09-10 20:32:42 +0000 | [diff] [blame] | 543 | case tok::unknown_command: |
| 544 | Content.push_back(S.actOnUnknownCommand(Tok.getLocation(), |
| 545 | Tok.getEndLocation(), |
| 546 | Tok.getUnknownCommandName())); |
| 547 | consumeToken(); |
| 548 | continue; |
| 549 | |
| 550 | case tok::command: { |
| 551 | const CommandInfo *Info = Traits.getCommandInfo(Tok.getCommandID()); |
| 552 | if (Info->IsBlockCommand) { |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 553 | if (Content.size() == 0) |
| 554 | return parseBlockCommand(); |
| 555 | break; // Block command ahead, finish this parapgaph. |
| 556 | } |
Dmitri Gribenko | 36cbbe9 | 2012-11-18 00:30:31 +0000 | [diff] [blame] | 557 | if (Info->IsVerbatimBlockEndCommand) { |
| 558 | Diag(Tok.getLocation(), |
| 559 | diag::warn_verbatim_block_end_without_start) |
| 560 | << Info->Name |
| 561 | << SourceRange(Tok.getLocation(), Tok.getEndLocation()); |
| 562 | consumeToken(); |
| 563 | continue; |
| 564 | } |
Dmitri Gribenko | b0b8a96 | 2012-09-11 19:22:03 +0000 | [diff] [blame] | 565 | if (Info->IsUnknownCommand) { |
| 566 | Content.push_back(S.actOnUnknownCommand(Tok.getLocation(), |
| 567 | Tok.getEndLocation(), |
| 568 | Info->getID())); |
| 569 | consumeToken(); |
| 570 | continue; |
| 571 | } |
Dmitri Gribenko | e4330a3 | 2012-09-10 20:32:42 +0000 | [diff] [blame] | 572 | assert(Info->IsInlineCommand); |
| 573 | Content.push_back(parseInlineCommand()); |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 574 | continue; |
Dmitri Gribenko | e4330a3 | 2012-09-10 20:32:42 +0000 | [diff] [blame] | 575 | } |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 576 | |
| 577 | case tok::newline: { |
| 578 | consumeToken(); |
| 579 | if (Tok.is(tok::newline) || Tok.is(tok::eof)) { |
| 580 | consumeToken(); |
| 581 | break; // Two newlines -- end of paragraph. |
| 582 | } |
| 583 | if (Content.size() > 0) |
| 584 | Content.back()->addTrailingNewline(); |
| 585 | continue; |
| 586 | } |
| 587 | |
| 588 | // Don't deal with HTML tag soup now. |
Dmitri Gribenko | 3f38bf2 | 2012-07-13 00:44:24 +0000 | [diff] [blame] | 589 | case tok::html_start_tag: |
| 590 | Content.push_back(parseHTMLStartTag()); |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 591 | continue; |
| 592 | |
Dmitri Gribenko | 3f38bf2 | 2012-07-13 00:44:24 +0000 | [diff] [blame] | 593 | case tok::html_end_tag: |
| 594 | Content.push_back(parseHTMLEndTag()); |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 595 | continue; |
| 596 | |
| 597 | case tok::text: |
| 598 | Content.push_back(S.actOnText(Tok.getLocation(), |
| 599 | Tok.getEndLocation(), |
| 600 | Tok.getText())); |
| 601 | consumeToken(); |
| 602 | continue; |
| 603 | |
| 604 | case tok::verbatim_block_line: |
| 605 | case tok::verbatim_block_end: |
| 606 | case tok::verbatim_line_text: |
| 607 | case tok::html_ident: |
| 608 | case tok::html_equals: |
| 609 | case tok::html_quoted_string: |
| 610 | case tok::html_greater: |
Dmitri Gribenko | a5ef44f | 2012-07-11 21:38:39 +0000 | [diff] [blame] | 611 | case tok::html_slash_greater: |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 612 | llvm_unreachable("should not see this token"); |
| 613 | } |
| 614 | break; |
| 615 | } |
| 616 | |
Dmitri Gribenko | 96b0986 | 2012-07-31 22:37:06 +0000 | [diff] [blame] | 617 | return S.actOnParagraphComment(S.copyArray(llvm::makeArrayRef(Content))); |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 618 | } |
| 619 | |
| 620 | VerbatimBlockComment *Parser::parseVerbatimBlock() { |
| 621 | assert(Tok.is(tok::verbatim_block_begin)); |
| 622 | |
| 623 | VerbatimBlockComment *VB = |
| 624 | S.actOnVerbatimBlockStart(Tok.getLocation(), |
Dmitri Gribenko | e4330a3 | 2012-09-10 20:32:42 +0000 | [diff] [blame] | 625 | Tok.getVerbatimBlockID()); |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 626 | consumeToken(); |
| 627 | |
| 628 | // Don't create an empty line if verbatim opening command is followed |
| 629 | // by a newline. |
| 630 | if (Tok.is(tok::newline)) |
| 631 | consumeToken(); |
| 632 | |
| 633 | SmallVector<VerbatimBlockLineComment *, 8> Lines; |
| 634 | while (Tok.is(tok::verbatim_block_line) || |
| 635 | Tok.is(tok::newline)) { |
| 636 | VerbatimBlockLineComment *Line; |
| 637 | if (Tok.is(tok::verbatim_block_line)) { |
| 638 | Line = S.actOnVerbatimBlockLine(Tok.getLocation(), |
| 639 | Tok.getVerbatimBlockText()); |
| 640 | consumeToken(); |
| 641 | if (Tok.is(tok::newline)) { |
| 642 | consumeToken(); |
| 643 | } |
| 644 | } else { |
| 645 | // Empty line, just a tok::newline. |
Dmitri Gribenko | 94572c3 | 2012-07-18 21:27:38 +0000 | [diff] [blame] | 646 | Line = S.actOnVerbatimBlockLine(Tok.getLocation(), ""); |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 647 | consumeToken(); |
| 648 | } |
| 649 | Lines.push_back(Line); |
| 650 | } |
| 651 | |
Dmitri Gribenko | 9f08f49 | 2012-07-20 20:18:53 +0000 | [diff] [blame] | 652 | if (Tok.is(tok::verbatim_block_end)) { |
Dmitri Gribenko | e4330a3 | 2012-09-10 20:32:42 +0000 | [diff] [blame] | 653 | const CommandInfo *Info = Traits.getCommandInfo(Tok.getVerbatimBlockID()); |
Dmitri Gribenko | 7d9b511 | 2012-08-06 19:03:12 +0000 | [diff] [blame] | 654 | S.actOnVerbatimBlockFinish(VB, Tok.getLocation(), |
Dmitri Gribenko | e4330a3 | 2012-09-10 20:32:42 +0000 | [diff] [blame] | 655 | Info->Name, |
Dmitri Gribenko | 7d9b511 | 2012-08-06 19:03:12 +0000 | [diff] [blame] | 656 | S.copyArray(llvm::makeArrayRef(Lines))); |
Dmitri Gribenko | 9f08f49 | 2012-07-20 20:18:53 +0000 | [diff] [blame] | 657 | consumeToken(); |
| 658 | } else { |
| 659 | // Unterminated \\verbatim block |
Dmitri Gribenko | 7d9b511 | 2012-08-06 19:03:12 +0000 | [diff] [blame] | 660 | S.actOnVerbatimBlockFinish(VB, SourceLocation(), "", |
| 661 | S.copyArray(llvm::makeArrayRef(Lines))); |
Dmitri Gribenko | 9f08f49 | 2012-07-20 20:18:53 +0000 | [diff] [blame] | 662 | } |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 663 | |
| 664 | return VB; |
| 665 | } |
| 666 | |
| 667 | VerbatimLineComment *Parser::parseVerbatimLine() { |
| 668 | assert(Tok.is(tok::verbatim_line_name)); |
| 669 | |
| 670 | Token NameTok = Tok; |
| 671 | consumeToken(); |
| 672 | |
| 673 | SourceLocation TextBegin; |
| 674 | StringRef Text; |
| 675 | // Next token might not be a tok::verbatim_line_text if verbatim line |
| 676 | // starting command comes just before a newline or comment end. |
| 677 | if (Tok.is(tok::verbatim_line_text)) { |
| 678 | TextBegin = Tok.getLocation(); |
| 679 | Text = Tok.getVerbatimLineText(); |
| 680 | } else { |
| 681 | TextBegin = NameTok.getEndLocation(); |
| 682 | Text = ""; |
| 683 | } |
| 684 | |
| 685 | VerbatimLineComment *VL = S.actOnVerbatimLine(NameTok.getLocation(), |
Dmitri Gribenko | e4330a3 | 2012-09-10 20:32:42 +0000 | [diff] [blame] | 686 | NameTok.getVerbatimLineID(), |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 687 | TextBegin, |
| 688 | Text); |
| 689 | consumeToken(); |
| 690 | return VL; |
| 691 | } |
| 692 | |
| 693 | BlockContentComment *Parser::parseBlockContent() { |
| 694 | switch (Tok.getKind()) { |
| 695 | case tok::text: |
Dmitri Gribenko | e4330a3 | 2012-09-10 20:32:42 +0000 | [diff] [blame] | 696 | case tok::unknown_command: |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 697 | case tok::command: |
Dmitri Gribenko | 3f38bf2 | 2012-07-13 00:44:24 +0000 | [diff] [blame] | 698 | case tok::html_start_tag: |
| 699 | case tok::html_end_tag: |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 700 | return parseParagraphOrBlockCommand(); |
| 701 | |
| 702 | case tok::verbatim_block_begin: |
| 703 | return parseVerbatimBlock(); |
| 704 | |
| 705 | case tok::verbatim_line_name: |
| 706 | return parseVerbatimLine(); |
| 707 | |
| 708 | case tok::eof: |
| 709 | case tok::newline: |
| 710 | case tok::verbatim_block_line: |
| 711 | case tok::verbatim_block_end: |
| 712 | case tok::verbatim_line_text: |
| 713 | case tok::html_ident: |
| 714 | case tok::html_equals: |
| 715 | case tok::html_quoted_string: |
| 716 | case tok::html_greater: |
Dmitri Gribenko | a5ef44f | 2012-07-11 21:38:39 +0000 | [diff] [blame] | 717 | case tok::html_slash_greater: |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 718 | llvm_unreachable("should not see this token"); |
| 719 | } |
Matt Beaumont-Gay | 4d48b5c | 2012-07-06 21:13:09 +0000 | [diff] [blame] | 720 | llvm_unreachable("bogus token kind"); |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 721 | } |
| 722 | |
| 723 | FullComment *Parser::parseFullComment() { |
| 724 | // Skip newlines at the beginning of the comment. |
| 725 | while (Tok.is(tok::newline)) |
| 726 | consumeToken(); |
| 727 | |
| 728 | SmallVector<BlockContentComment *, 8> Blocks; |
| 729 | while (Tok.isNot(tok::eof)) { |
| 730 | Blocks.push_back(parseBlockContent()); |
| 731 | |
| 732 | // Skip extra newlines after paragraph end. |
| 733 | while (Tok.is(tok::newline)) |
| 734 | consumeToken(); |
| 735 | } |
Dmitri Gribenko | 96b0986 | 2012-07-31 22:37:06 +0000 | [diff] [blame] | 736 | return S.actOnFullComment(S.copyArray(llvm::makeArrayRef(Blocks))); |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 737 | } |
| 738 | |
| 739 | } // end namespace comments |
| 740 | } // end namespace clang |