16 #include "llvm/Support/ErrorHandling.h" 21 for (StringRef::const_iterator I = S.begin(), E = S.end(); I != E; ++I) {
32 llvm::BumpPtrAllocator &Allocator;
36 bool NoMoreInterestingTokens;
43 const char *BufferStart;
44 const char *BufferEnd;
45 const char *BufferPtr;
54 return Pos.CurToken >= Toks.size();
60 const Token &
Tok = Toks[Pos.CurToken];
62 Pos.BufferStart = Tok.
getText().begin();
63 Pos.BufferEnd = Tok.
getText().end();
64 Pos.BufferPtr = Pos.BufferStart;
69 const unsigned CharNo = Pos.BufferPtr - Pos.BufferStart;
70 return Pos.BufferStartLoc.getLocWithOffset(CharNo);
75 assert(Pos.BufferPtr != Pos.BufferEnd);
76 return *Pos.BufferPtr;
81 assert(Pos.BufferPtr != Pos.BufferEnd);
83 if (Pos.BufferPtr == Pos.BufferEnd) {
85 if (isEnd() && !addToken())
97 if (NoMoreInterestingTokens)
102 Token Newline = P.Tok;
106 NoMoreInterestingTokens =
true;
111 NoMoreInterestingTokens =
true;
115 Toks.push_back(P.Tok);
117 if (Toks.size() == 1)
122 void consumeWhitespace() {
131 void formTokenWithChars(
Token &Result,
133 const char *TokBegin,
140 Result.TextPtr =
"<UNSET>";
148 Allocator(Allocator), P(P), NoMoreInterestingTokens(
false) {
158 Position SavedPos = Pos;
162 const char *WordBegin = Pos.BufferPtr;
165 const char C = peek();
167 WordText.push_back(C);
172 const unsigned Length = WordText.size();
178 char *TextPtr = Allocator.Allocate<
char>(Length + 1);
180 memcpy(TextPtr, WordText.c_str(), Length + 1);
181 StringRef Text = StringRef(TextPtr, Length);
183 formTokenWithChars(Tok, Loc, WordBegin, Length, Text);
191 Position SavedPos = Pos;
195 const char *WordBegin = Pos.BufferPtr;
199 const char C = peek();
200 if (C == OpenDelim) {
201 WordText.push_back(C);
207 while (!Error && !isEnd()) {
209 WordText.push_back(C);
214 if (!Error && C != CloseDelim)
222 const unsigned Length = WordText.size();
223 char *TextPtr = Allocator.Allocate<
char>(Length + 1);
225 memcpy(TextPtr, WordText.c_str(), Length + 1);
226 StringRef Text = StringRef(TextPtr, Length);
228 formTokenWithChars(Tok, Loc, WordBegin,
229 Pos.BufferPtr - WordBegin, Text);
238 bool HavePartialTok =
false;
240 if (Pos.BufferPtr != Pos.BufferStart) {
241 formTokenWithChars(PartialTok, getSourceLocation(),
242 Pos.BufferPtr, Pos.BufferEnd - Pos.BufferPtr,
243 StringRef(Pos.BufferPtr,
244 Pos.BufferEnd - Pos.BufferPtr));
245 HavePartialTok =
true;
249 P.putBack(llvm::makeArrayRef(Toks.begin() + Pos.CurToken, Toks.end()));
250 Pos.CurToken = Toks.size();
253 P.putBack(PartialTok);
257 Parser::Parser(
Lexer &L,
Sema &S, llvm::BumpPtrAllocator &Allocator,
260 L(L), S(S), Allocator(Allocator), SourceMgr(SourceMgr), Diags(Diags),
298 new (Allocator.Allocate<Argument>(NumArgs)) Argument[NumArgs];
299 unsigned ParsedArgs = 0;
301 while (ParsedArgs < NumArgs && Retokenizer.
lexWord(Arg)) {
338 if (isTokBlockCommand()) {
354 if (PC || TPC || Info->
NumArgs > 0) {
371 bool EmptyParagraph =
false;
372 if (isTokBlockCommand())
373 EmptyParagraph =
true;
377 EmptyParagraph = isTokBlockCommand();
388 Paragraph = cast<ParagraphComment>(Block);
406 const Token CommandTok = Tok;
412 bool ArgTokValid = Retokenizer.
lexWord(ArgTok);
417 CommandTok.getEndLocation(),
418 CommandTok.getCommandID(),
424 CommandTok.getEndLocation(),
425 CommandTok.getCommandID());
455 diag::warn_doc_html_start_tag_expected_quoted_string)
494 diag::warn_doc_html_start_tag_expected_ident_or_greater);
515 bool StartLineInvalid;
523 if (StartLineInvalid || EndLineInvalid || StartLine == EndLine)
525 diag::warn_doc_html_start_tag_expected_ident_or_greater)
526 << HST->getSourceRange();
529 diag::warn_doc_html_start_tag_expected_ident_or_greater);
530 Diag(HST->getLocation(), diag::note_doc_html_tag_started_here)
531 << HST->getSourceRange();
540 Token TokEndTag = Tok;
550 TokEndTag.getHTMLTagEndName());
561 assert(Content.size() != 0);
575 if (Content.size() == 0)
581 diag::warn_verbatim_block_end_without_start)
609 Token WhitespaceTok = Tok;
616 putBack(WhitespaceTok);
618 if (Content.size() > 0)
619 Content.back()->addTrailingNewline();
647 llvm_unreachable(
"should not see this token");
684 Lines.push_back(Line);
716 TextBegin = NameTok.getEndLocation();
721 NameTok.getVerbatimLineID(),
754 llvm_unreachable(
"should not see this token");
756 llvm_unreachable(
"bogus token kind");
Defines the SourceManager interface.
LLVM_READONLY bool isWhitespace(unsigned char c)
Return true if this character is horizontal or vertical ASCII whitespace: ' ', '\t', '\f', '\v', '\n', '\r'.
Concrete class used by the front-end to report problems and issues.
const AnnotatedLine * Line
unsigned getPresumedLineNumber(SourceLocation Loc, bool *Invalid=nullptr) const
Encodes a location in the source.
Dataflow Directional Tag Classes.
A trivial tuple used to represent a source range.
This class handles loading and caching of source files into memory.