clang  6.0.0svn
ParseTentative.cpp
Go to the documentation of this file.
1 //===--- ParseTentative.cpp - Ambiguity Resolution Parsing ----------------===//
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 // This file implements the tentative parsing portions of the Parser
11 // interfaces, for ambiguity resolution.
12 //
13 //===----------------------------------------------------------------------===//
14 
15 #include "clang/Parse/Parser.h"
18 using namespace clang;
19 
20 /// isCXXDeclarationStatement - C++-specialized function that disambiguates
21 /// between a declaration or an expression statement, when parsing function
22 /// bodies. Returns true for declaration, false for expression.
23 ///
24 /// declaration-statement:
25 /// block-declaration
26 ///
27 /// block-declaration:
28 /// simple-declaration
29 /// asm-definition
30 /// namespace-alias-definition
31 /// using-declaration
32 /// using-directive
33 /// [C++0x] static_assert-declaration
34 ///
35 /// asm-definition:
36 /// 'asm' '(' string-literal ')' ';'
37 ///
38 /// namespace-alias-definition:
39 /// 'namespace' identifier = qualified-namespace-specifier ';'
40 ///
41 /// using-declaration:
42 /// 'using' typename[opt] '::'[opt] nested-name-specifier
43 /// unqualified-id ';'
44 /// 'using' '::' unqualified-id ;
45 ///
46 /// using-directive:
47 /// 'using' 'namespace' '::'[opt] nested-name-specifier[opt]
48 /// namespace-name ';'
49 ///
50 bool Parser::isCXXDeclarationStatement() {
51  switch (Tok.getKind()) {
52  // asm-definition
53  case tok::kw_asm:
54  // namespace-alias-definition
55  case tok::kw_namespace:
56  // using-declaration
57  // using-directive
58  case tok::kw_using:
59  // static_assert-declaration
60  case tok::kw_static_assert:
61  case tok::kw__Static_assert:
62  return true;
63  // simple-declaration
64  default:
65  return isCXXSimpleDeclaration(/*AllowForRangeDecl=*/false);
66  }
67 }
68 
69 /// isCXXSimpleDeclaration - C++-specialized function that disambiguates
70 /// between a simple-declaration or an expression-statement.
71 /// If during the disambiguation process a parsing error is encountered,
72 /// the function returns true to let the declaration parsing code handle it.
73 /// Returns false if the statement is disambiguated as expression.
74 ///
75 /// simple-declaration:
76 /// decl-specifier-seq init-declarator-list[opt] ';'
77 /// decl-specifier-seq ref-qualifier[opt] '[' identifier-list ']'
78 /// brace-or-equal-initializer ';' [C++17]
79 ///
80 /// (if AllowForRangeDecl specified)
81 /// for ( for-range-declaration : for-range-initializer ) statement
82 ///
83 /// for-range-declaration:
84 /// decl-specifier-seq declarator
85 /// decl-specifier-seq ref-qualifier[opt] '[' identifier-list ']'
86 ///
87 /// In any of the above cases there can be a preceding attribute-specifier-seq,
88 /// but the caller is expected to handle that.
89 bool Parser::isCXXSimpleDeclaration(bool AllowForRangeDecl) {
90  // C++ 6.8p1:
91  // There is an ambiguity in the grammar involving expression-statements and
92  // declarations: An expression-statement with a function-style explicit type
93  // conversion (5.2.3) as its leftmost subexpression can be indistinguishable
94  // from a declaration where the first declarator starts with a '('. In those
95  // cases the statement is a declaration. [Note: To disambiguate, the whole
96  // statement might have to be examined to determine if it is an
97  // expression-statement or a declaration].
98 
99  // C++ 6.8p3:
100  // The disambiguation is purely syntactic; that is, the meaning of the names
101  // occurring in such a statement, beyond whether they are type-names or not,
102  // is not generally used in or changed by the disambiguation. Class
103  // templates are instantiated as necessary to determine if a qualified name
104  // is a type-name. Disambiguation precedes parsing, and a statement
105  // disambiguated as a declaration may be an ill-formed declaration.
106 
107  // We don't have to parse all of the decl-specifier-seq part. There's only
108  // an ambiguity if the first decl-specifier is
109  // simple-type-specifier/typename-specifier followed by a '(', which may
110  // indicate a function-style cast expression.
111  // isCXXDeclarationSpecifier will return TPResult::Ambiguous only in such
112  // a case.
113 
114  bool InvalidAsDeclaration = false;
115  TPResult TPR = isCXXDeclarationSpecifier(TPResult::False,
116  &InvalidAsDeclaration);
117  if (TPR != TPResult::Ambiguous)
118  return TPR != TPResult::False; // Returns true for TPResult::True or
119  // TPResult::Error.
120 
121  // FIXME: TryParseSimpleDeclaration doesn't look past the first initializer,
122  // and so gets some cases wrong. We can't carry on if we've already seen
123  // something which makes this statement invalid as a declaration in this case,
124  // since it can cause us to misparse valid code. Revisit this once
125  // TryParseInitDeclaratorList is fixed.
126  if (InvalidAsDeclaration)
127  return false;
128 
129  // FIXME: Add statistics about the number of ambiguous statements encountered
130  // and how they were resolved (number of declarations+number of expressions).
131 
132  // Ok, we have a simple-type-specifier/typename-specifier followed by a '(',
133  // or an identifier which doesn't resolve as anything. We need tentative
134  // parsing...
135 
136  {
137  RevertingTentativeParsingAction PA(*this);
138  TPR = TryParseSimpleDeclaration(AllowForRangeDecl);
139  }
140 
141  // In case of an error, let the declaration parsing code handle it.
142  if (TPR == TPResult::Error)
143  return true;
144 
145  // Declarations take precedence over expressions.
146  if (TPR == TPResult::Ambiguous)
147  TPR = TPResult::True;
148 
149  assert(TPR == TPResult::True || TPR == TPResult::False);
150  return TPR == TPResult::True;
151 }
152 
153 /// Try to consume a token sequence that we've already identified as
154 /// (potentially) starting a decl-specifier.
155 Parser::TPResult Parser::TryConsumeDeclarationSpecifier() {
156  switch (Tok.getKind()) {
157  case tok::kw__Atomic:
158  if (NextToken().isNot(tok::l_paren)) {
159  ConsumeToken();
160  break;
161  }
162  // Fall through.
163  case tok::kw_typeof:
164  case tok::kw___attribute:
165  case tok::kw___underlying_type: {
166  ConsumeToken();
167  if (Tok.isNot(tok::l_paren))
168  return TPResult::Error;
169  ConsumeParen();
170  if (!SkipUntil(tok::r_paren))
171  return TPResult::Error;
172  break;
173  }
174 
175  case tok::kw_class:
176  case tok::kw_struct:
177  case tok::kw_union:
178  case tok::kw___interface:
179  case tok::kw_enum:
180  // elaborated-type-specifier:
181  // class-key attribute-specifier-seq[opt]
182  // nested-name-specifier[opt] identifier
183  // class-key nested-name-specifier[opt] template[opt] simple-template-id
184  // enum nested-name-specifier[opt] identifier
185  //
186  // FIXME: We don't support class-specifiers nor enum-specifiers here.
187  ConsumeToken();
188 
189  // Skip attributes.
190  while (Tok.isOneOf(tok::l_square, tok::kw___attribute, tok::kw___declspec,
191  tok::kw_alignas)) {
192  if (Tok.is(tok::l_square)) {
193  ConsumeBracket();
194  if (!SkipUntil(tok::r_square))
195  return TPResult::Error;
196  } else {
197  ConsumeToken();
198  if (Tok.isNot(tok::l_paren))
199  return TPResult::Error;
200  ConsumeParen();
201  if (!SkipUntil(tok::r_paren))
202  return TPResult::Error;
203  }
204  }
205 
206  if (Tok.isOneOf(tok::identifier, tok::coloncolon, tok::kw_decltype,
207  tok::annot_template_id) &&
209  return TPResult::Error;
210  if (Tok.is(tok::annot_cxxscope))
211  ConsumeAnnotationToken();
212  if (Tok.is(tok::identifier))
213  ConsumeToken();
214  else if (Tok.is(tok::annot_template_id))
215  ConsumeAnnotationToken();
216  else
217  return TPResult::Error;
218  break;
219 
220  case tok::annot_cxxscope:
221  ConsumeAnnotationToken();
222  // Fall through.
223  default:
224  ConsumeAnyToken();
225 
226  if (getLangOpts().ObjC1 && Tok.is(tok::less))
227  return TryParseProtocolQualifiers();
228  break;
229  }
230 
231  return TPResult::Ambiguous;
232 }
233 
234 /// simple-declaration:
235 /// decl-specifier-seq init-declarator-list[opt] ';'
236 ///
237 /// (if AllowForRangeDecl specified)
238 /// for ( for-range-declaration : for-range-initializer ) statement
239 /// for-range-declaration:
240 /// attribute-specifier-seqopt type-specifier-seq declarator
241 ///
242 Parser::TPResult Parser::TryParseSimpleDeclaration(bool AllowForRangeDecl) {
243  if (TryConsumeDeclarationSpecifier() == TPResult::Error)
244  return TPResult::Error;
245 
246  // Two decl-specifiers in a row conclusively disambiguate this as being a
247  // simple-declaration. Don't bother calling isCXXDeclarationSpecifier in the
248  // overwhelmingly common case that the next token is a '('.
249  if (Tok.isNot(tok::l_paren)) {
250  TPResult TPR = isCXXDeclarationSpecifier();
251  if (TPR == TPResult::Ambiguous)
252  return TPResult::True;
253  if (TPR == TPResult::True || TPR == TPResult::Error)
254  return TPR;
255  assert(TPR == TPResult::False);
256  }
257 
258  TPResult TPR = TryParseInitDeclaratorList();
259  if (TPR != TPResult::Ambiguous)
260  return TPR;
261 
262  if (Tok.isNot(tok::semi) && (!AllowForRangeDecl || Tok.isNot(tok::colon)))
263  return TPResult::False;
264 
265  return TPResult::Ambiguous;
266 }
267 
268 /// Tentatively parse an init-declarator-list in order to disambiguate it from
269 /// an expression.
270 ///
271 /// init-declarator-list:
272 /// init-declarator
273 /// init-declarator-list ',' init-declarator
274 ///
275 /// init-declarator:
276 /// declarator initializer[opt]
277 /// [GNU] declarator simple-asm-expr[opt] attributes[opt] initializer[opt]
278 ///
279 /// initializer:
280 /// brace-or-equal-initializer
281 /// '(' expression-list ')'
282 ///
283 /// brace-or-equal-initializer:
284 /// '=' initializer-clause
285 /// [C++11] braced-init-list
286 ///
287 /// initializer-clause:
288 /// assignment-expression
289 /// braced-init-list
290 ///
291 /// braced-init-list:
292 /// '{' initializer-list ','[opt] '}'
293 /// '{' '}'
294 ///
295 Parser::TPResult Parser::TryParseInitDeclaratorList() {
296  while (1) {
297  // declarator
298  TPResult TPR = TryParseDeclarator(false/*mayBeAbstract*/);
299  if (TPR != TPResult::Ambiguous)
300  return TPR;
301 
302  // [GNU] simple-asm-expr[opt] attributes[opt]
303  if (Tok.isOneOf(tok::kw_asm, tok::kw___attribute))
304  return TPResult::True;
305 
306  // initializer[opt]
307  if (Tok.is(tok::l_paren)) {
308  // Parse through the parens.
309  ConsumeParen();
310  if (!SkipUntil(tok::r_paren, StopAtSemi))
311  return TPResult::Error;
312  } else if (Tok.is(tok::l_brace)) {
313  // A left-brace here is sufficient to disambiguate the parse; an
314  // expression can never be followed directly by a braced-init-list.
315  return TPResult::True;
316  } else if (Tok.is(tok::equal) || isTokIdentifier_in()) {
317  // MSVC and g++ won't examine the rest of declarators if '=' is
318  // encountered; they just conclude that we have a declaration.
319  // EDG parses the initializer completely, which is the proper behavior
320  // for this case.
321  //
322  // At present, Clang follows MSVC and g++, since the parser does not have
323  // the ability to parse an expression fully without recording the
324  // results of that parse.
325  // FIXME: Handle this case correctly.
326  //
327  // Also allow 'in' after an Objective-C declaration as in:
328  // for (int (^b)(void) in array). Ideally this should be done in the
329  // context of parsing for-init-statement of a foreach statement only. But,
330  // in any other context 'in' is invalid after a declaration and parser
331  // issues the error regardless of outcome of this decision.
332  // FIXME: Change if above assumption does not hold.
333  return TPResult::True;
334  }
335 
336  if (!TryConsumeToken(tok::comma))
337  break;
338  }
339 
340  return TPResult::Ambiguous;
341 }
342 
345  bool CanBeExpression = true;
346  bool CanBeCondition = true;
348 
350  : P(P), CanBeInitStatement(CanBeInitStatement) {}
351 
353  CanBeExpression = false;
354 
355  if (CanBeCondition && CanBeInitStatement) {
356  // FIXME: Unify the parsing codepaths for condition variables and
357  // simple-declarations so that we don't need to eagerly figure out which
358  // kind we have here. (Just parse init-declarators until we reach a
359  // semicolon or right paren.)
360  RevertingTentativeParsingAction PA(P);
361  P.SkipUntil(tok::r_paren, tok::semi, StopBeforeMatch);
362  if (P.Tok.isNot(tok::r_paren))
363  CanBeCondition = false;
364  if (P.Tok.isNot(tok::semi))
365  CanBeInitStatement = false;
366  }
367  }
368 
370  CanBeCondition = false;
371  return !CanBeInitStatement || !CanBeExpression;
372  }
373 
374  bool update(TPResult IsDecl) {
375  switch (IsDecl) {
376  case TPResult::True:
377  markNotExpression();
378  return true;
379  case TPResult::False:
380  CanBeCondition = CanBeInitStatement = false;
381  return true;
382  case TPResult::Ambiguous:
383  return false;
384  case TPResult::Error:
385  CanBeExpression = CanBeCondition = CanBeInitStatement = false;
386  return true;
387  }
388  llvm_unreachable("unknown tentative parse result");
389  }
390 
391  ConditionOrInitStatement result() const {
392  assert(CanBeExpression + CanBeCondition + CanBeInitStatement < 2 &&
393  "result called but not yet resolved");
394  if (CanBeExpression)
395  return ConditionOrInitStatement::Expression;
396  if (CanBeCondition)
397  return ConditionOrInitStatement::ConditionDecl;
398  if (CanBeInitStatement)
399  return ConditionOrInitStatement::InitStmtDecl;
400  return ConditionOrInitStatement::Error;
401  }
402 };
403 
404 /// \brief Disambiguates between a declaration in a condition, a
405 /// simple-declaration in an init-statement, and an expression for
406 /// a condition of a if/switch statement.
407 ///
408 /// condition:
409 /// expression
410 /// type-specifier-seq declarator '=' assignment-expression
411 /// [C++11] type-specifier-seq declarator '=' initializer-clause
412 /// [C++11] type-specifier-seq declarator braced-init-list
413 /// [GNU] type-specifier-seq declarator simple-asm-expr[opt] attributes[opt]
414 /// '=' assignment-expression
415 /// simple-declaration:
416 /// decl-specifier-seq init-declarator-list[opt] ';'
417 ///
418 /// Note that, unlike isCXXSimpleDeclaration, we must disambiguate all the way
419 /// to the ';' to disambiguate cases like 'int(x))' (an expression) from
420 /// 'int(x);' (a simple-declaration in an init-statement).
421 Parser::ConditionOrInitStatement
422 Parser::isCXXConditionDeclarationOrInitStatement(bool CanBeInitStatement) {
423  ConditionDeclarationOrInitStatementState State(*this, CanBeInitStatement);
424 
425  if (State.update(isCXXDeclarationSpecifier()))
426  return State.result();
427 
428  // It might be a declaration; we need tentative parsing.
429  RevertingTentativeParsingAction PA(*this);
430 
431  // FIXME: A tag definition unambiguously tells us this is an init-statement.
432  if (State.update(TryConsumeDeclarationSpecifier()))
433  return State.result();
434  assert(Tok.is(tok::l_paren) && "Expected '('");
435 
436  while (true) {
437  // Consume a declarator.
438  if (State.update(TryParseDeclarator(false/*mayBeAbstract*/)))
439  return State.result();
440 
441  // Attributes, asm label, or an initializer imply this is not an expression.
442  // FIXME: Disambiguate properly after an = instead of assuming that it's a
443  // valid declaration.
444  if (Tok.isOneOf(tok::equal, tok::kw_asm, tok::kw___attribute) ||
445  (getLangOpts().CPlusPlus11 && Tok.is(tok::l_brace))) {
446  State.markNotExpression();
447  return State.result();
448  }
449 
450  // At this point, it can't be a condition any more, because a condition
451  // must have a brace-or-equal-initializer.
452  if (State.markNotCondition())
453  return State.result();
454 
455  // A parenthesized initializer could be part of an expression or a
456  // simple-declaration.
457  if (Tok.is(tok::l_paren)) {
458  ConsumeParen();
459  SkipUntil(tok::r_paren, StopAtSemi);
460  }
461 
462  if (!TryConsumeToken(tok::comma))
463  break;
464  }
465 
466  // We reached the end. If it can now be some kind of decl, then it is.
467  if (State.CanBeCondition && Tok.is(tok::r_paren))
468  return ConditionOrInitStatement::ConditionDecl;
469  else if (State.CanBeInitStatement && Tok.is(tok::semi))
470  return ConditionOrInitStatement::InitStmtDecl;
471  else
472  return ConditionOrInitStatement::Expression;
473 }
474 
475  /// \brief Determine whether the next set of tokens contains a type-id.
476  ///
477  /// The context parameter states what context we're parsing right
478  /// now, which affects how this routine copes with the token
479  /// following the type-id. If the context is TypeIdInParens, we have
480  /// already parsed the '(' and we will cease lookahead when we hit
481  /// the corresponding ')'. If the context is
482  /// TypeIdAsTemplateArgument, we've already parsed the '<' or ','
483  /// before this template argument, and will cease lookahead when we
484  /// hit a '>', '>>' (in C++0x), or ','; or, in C++0x, an ellipsis immediately
485  /// preceding such. Returns true for a type-id and false for an expression.
486  /// If during the disambiguation process a parsing error is encountered,
487  /// the function returns true to let the declaration parsing code handle it.
488  ///
489  /// type-id:
490  /// type-specifier-seq abstract-declarator[opt]
491  ///
492 bool Parser::isCXXTypeId(TentativeCXXTypeIdContext Context, bool &isAmbiguous) {
493 
494  isAmbiguous = false;
495 
496  // C++ 8.2p2:
497  // The ambiguity arising from the similarity between a function-style cast and
498  // a type-id can occur in different contexts. The ambiguity appears as a
499  // choice between a function-style cast expression and a declaration of a
500  // type. The resolution is that any construct that could possibly be a type-id
501  // in its syntactic context shall be considered a type-id.
502 
503  TPResult TPR = isCXXDeclarationSpecifier();
504  if (TPR != TPResult::Ambiguous)
505  return TPR != TPResult::False; // Returns true for TPResult::True or
506  // TPResult::Error.
507 
508  // FIXME: Add statistics about the number of ambiguous statements encountered
509  // and how they were resolved (number of declarations+number of expressions).
510 
511  // Ok, we have a simple-type-specifier/typename-specifier followed by a '('.
512  // We need tentative parsing...
513 
514  RevertingTentativeParsingAction PA(*this);
515 
516  // type-specifier-seq
517  TryConsumeDeclarationSpecifier();
518  assert(Tok.is(tok::l_paren) && "Expected '('");
519 
520  // declarator
521  TPR = TryParseDeclarator(true/*mayBeAbstract*/, false/*mayHaveIdentifier*/);
522 
523  // In case of an error, let the declaration parsing code handle it.
524  if (TPR == TPResult::Error)
525  TPR = TPResult::True;
526 
527  if (TPR == TPResult::Ambiguous) {
528  // We are supposed to be inside parens, so if after the abstract declarator
529  // we encounter a ')' this is a type-id, otherwise it's an expression.
530  if (Context == TypeIdInParens && Tok.is(tok::r_paren)) {
531  TPR = TPResult::True;
532  isAmbiguous = true;
533 
534  // We are supposed to be inside a template argument, so if after
535  // the abstract declarator we encounter a '>', '>>' (in C++0x), or
536  // ','; or, in C++0x, an ellipsis immediately preceding such, this
537  // is a type-id. Otherwise, it's an expression.
538  } else if (Context == TypeIdAsTemplateArgument &&
539  (Tok.isOneOf(tok::greater, tok::comma) ||
540  (getLangOpts().CPlusPlus11 &&
541  (Tok.is(tok::greatergreater) ||
542  (Tok.is(tok::ellipsis) &&
543  NextToken().isOneOf(tok::greater, tok::greatergreater,
544  tok::comma)))))) {
545  TPR = TPResult::True;
546  isAmbiguous = true;
547 
548  } else
549  TPR = TPResult::False;
550  }
551 
552  assert(TPR == TPResult::True || TPR == TPResult::False);
553  return TPR == TPResult::True;
554 }
555 
556 /// \brief Returns true if this is a C++11 attribute-specifier. Per
557 /// C++11 [dcl.attr.grammar]p6, two consecutive left square bracket tokens
558 /// always introduce an attribute. In Objective-C++11, this rule does not
559 /// apply if either '[' begins a message-send.
560 ///
561 /// If Disambiguate is true, we try harder to determine whether a '[[' starts
562 /// an attribute-specifier, and return CAK_InvalidAttributeSpecifier if not.
563 ///
564 /// If OuterMightBeMessageSend is true, we assume the outer '[' is either an
565 /// Obj-C message send or the start of an attribute. Otherwise, we assume it
566 /// is not an Obj-C message send.
567 ///
568 /// C++11 [dcl.attr.grammar]:
569 ///
570 /// attribute-specifier:
571 /// '[' '[' attribute-list ']' ']'
572 /// alignment-specifier
573 ///
574 /// attribute-list:
575 /// attribute[opt]
576 /// attribute-list ',' attribute[opt]
577 /// attribute '...'
578 /// attribute-list ',' attribute '...'
579 ///
580 /// attribute:
581 /// attribute-token attribute-argument-clause[opt]
582 ///
583 /// attribute-token:
584 /// identifier
585 /// identifier '::' identifier
586 ///
587 /// attribute-argument-clause:
588 /// '(' balanced-token-seq ')'
589 Parser::CXX11AttributeKind
590 Parser::isCXX11AttributeSpecifier(bool Disambiguate,
591  bool OuterMightBeMessageSend) {
592  if (Tok.is(tok::kw_alignas))
593  return CAK_AttributeSpecifier;
594 
595  if (Tok.isNot(tok::l_square) || NextToken().isNot(tok::l_square))
596  return CAK_NotAttributeSpecifier;
597 
598  // No tentative parsing if we don't need to look for ']]' or a lambda.
599  if (!Disambiguate && !getLangOpts().ObjC1)
600  return CAK_AttributeSpecifier;
601 
602  RevertingTentativeParsingAction PA(*this);
603 
604  // Opening brackets were checked for above.
605  ConsumeBracket();
606 
607  // Outside Obj-C++11, treat anything with a matching ']]' as an attribute.
608  if (!getLangOpts().ObjC1) {
609  ConsumeBracket();
610 
611  bool IsAttribute = SkipUntil(tok::r_square);
612  IsAttribute &= Tok.is(tok::r_square);
613 
614  return IsAttribute ? CAK_AttributeSpecifier : CAK_InvalidAttributeSpecifier;
615  }
616 
617  // In Obj-C++11, we need to distinguish four situations:
618  // 1a) int x[[attr]]; C++11 attribute.
619  // 1b) [[attr]]; C++11 statement attribute.
620  // 2) int x[[obj](){ return 1; }()]; Lambda in array size/index.
621  // 3a) int x[[obj get]]; Message send in array size/index.
622  // 3b) [[Class alloc] init]; Message send in message send.
623  // 4) [[obj]{ return self; }() doStuff]; Lambda in message send.
624  // (1) is an attribute, (2) is ill-formed, and (3) and (4) are accepted.
625 
626  // If we have a lambda-introducer, then this is definitely not a message send.
627  // FIXME: If this disambiguation is too slow, fold the tentative lambda parse
628  // into the tentative attribute parse below.
629  LambdaIntroducer Intro;
630  if (!TryParseLambdaIntroducer(Intro)) {
631  // A lambda cannot end with ']]', and an attribute must.
632  bool IsAttribute = Tok.is(tok::r_square);
633 
634  if (IsAttribute)
635  // Case 1: C++11 attribute.
636  return CAK_AttributeSpecifier;
637 
638  if (OuterMightBeMessageSend)
639  // Case 4: Lambda in message send.
640  return CAK_NotAttributeSpecifier;
641 
642  // Case 2: Lambda in array size / index.
643  return CAK_InvalidAttributeSpecifier;
644  }
645 
646  ConsumeBracket();
647 
648  // If we don't have a lambda-introducer, then we have an attribute or a
649  // message-send.
650  bool IsAttribute = true;
651  while (Tok.isNot(tok::r_square)) {
652  if (Tok.is(tok::comma)) {
653  // Case 1: Stray commas can only occur in attributes.
654  return CAK_AttributeSpecifier;
655  }
656 
657  // Parse the attribute-token, if present.
658  // C++11 [dcl.attr.grammar]:
659  // If a keyword or an alternative token that satisfies the syntactic
660  // requirements of an identifier is contained in an attribute-token,
661  // it is considered an identifier.
662  SourceLocation Loc;
663  if (!TryParseCXX11AttributeIdentifier(Loc)) {
664  IsAttribute = false;
665  break;
666  }
667  if (Tok.is(tok::coloncolon)) {
668  ConsumeToken();
669  if (!TryParseCXX11AttributeIdentifier(Loc)) {
670  IsAttribute = false;
671  break;
672  }
673  }
674 
675  // Parse the attribute-argument-clause, if present.
676  if (Tok.is(tok::l_paren)) {
677  ConsumeParen();
678  if (!SkipUntil(tok::r_paren)) {
679  IsAttribute = false;
680  break;
681  }
682  }
683 
684  TryConsumeToken(tok::ellipsis);
685 
686  if (!TryConsumeToken(tok::comma))
687  break;
688  }
689 
690  // An attribute must end ']]'.
691  if (IsAttribute) {
692  if (Tok.is(tok::r_square)) {
693  ConsumeBracket();
694  IsAttribute = Tok.is(tok::r_square);
695  } else {
696  IsAttribute = false;
697  }
698  }
699 
700  if (IsAttribute)
701  // Case 1: C++11 statement attribute.
702  return CAK_AttributeSpecifier;
703 
704  // Case 3: Message send.
705  return CAK_NotAttributeSpecifier;
706 }
707 
708 Parser::TPResult Parser::TryParsePtrOperatorSeq() {
709  while (true) {
710  if (Tok.isOneOf(tok::coloncolon, tok::identifier))
711  if (TryAnnotateCXXScopeToken(true))
712  return TPResult::Error;
713 
714  if (Tok.isOneOf(tok::star, tok::amp, tok::caret, tok::ampamp) ||
715  (Tok.is(tok::annot_cxxscope) && NextToken().is(tok::star))) {
716  // ptr-operator
717  ConsumeAnyToken();
718  while (Tok.isOneOf(tok::kw_const, tok::kw_volatile, tok::kw_restrict,
719  tok::kw__Nonnull, tok::kw__Nullable,
720  tok::kw__Null_unspecified))
721  ConsumeToken();
722  } else {
723  return TPResult::True;
724  }
725  }
726 }
727 
728 /// operator-function-id:
729 /// 'operator' operator
730 ///
731 /// operator: one of
732 /// new delete new[] delete[] + - * / % ^ [...]
733 ///
734 /// conversion-function-id:
735 /// 'operator' conversion-type-id
736 ///
737 /// conversion-type-id:
738 /// type-specifier-seq conversion-declarator[opt]
739 ///
740 /// conversion-declarator:
741 /// ptr-operator conversion-declarator[opt]
742 ///
743 /// literal-operator-id:
744 /// 'operator' string-literal identifier
745 /// 'operator' user-defined-string-literal
746 Parser::TPResult Parser::TryParseOperatorId() {
747  assert(Tok.is(tok::kw_operator));
748  ConsumeToken();
749 
750  // Maybe this is an operator-function-id.
751  switch (Tok.getKind()) {
752  case tok::kw_new: case tok::kw_delete:
753  ConsumeToken();
754  if (Tok.is(tok::l_square) && NextToken().is(tok::r_square)) {
755  ConsumeBracket();
756  ConsumeBracket();
757  }
758  return TPResult::True;
759 
760 #define OVERLOADED_OPERATOR(Name, Spelling, Token, Unary, Binary, MemOnly) \
761  case tok::Token:
762 #define OVERLOADED_OPERATOR_MULTI(Name, Spelling, Unary, Binary, MemOnly)
763 #include "clang/Basic/OperatorKinds.def"
764  ConsumeToken();
765  return TPResult::True;
766 
767  case tok::l_square:
768  if (NextToken().is(tok::r_square)) {
769  ConsumeBracket();
770  ConsumeBracket();
771  return TPResult::True;
772  }
773  break;
774 
775  case tok::l_paren:
776  if (NextToken().is(tok::r_paren)) {
777  ConsumeParen();
778  ConsumeParen();
779  return TPResult::True;
780  }
781  break;
782 
783  default:
784  break;
785  }
786 
787  // Maybe this is a literal-operator-id.
788  if (getLangOpts().CPlusPlus11 && isTokenStringLiteral()) {
789  bool FoundUDSuffix = false;
790  do {
791  FoundUDSuffix |= Tok.hasUDSuffix();
792  ConsumeStringToken();
793  } while (isTokenStringLiteral());
794 
795  if (!FoundUDSuffix) {
796  if (Tok.is(tok::identifier))
797  ConsumeToken();
798  else
799  return TPResult::Error;
800  }
801  return TPResult::True;
802  }
803 
804  // Maybe this is a conversion-function-id.
805  bool AnyDeclSpecifiers = false;
806  while (true) {
807  TPResult TPR = isCXXDeclarationSpecifier();
808  if (TPR == TPResult::Error)
809  return TPR;
810  if (TPR == TPResult::False) {
811  if (!AnyDeclSpecifiers)
812  return TPResult::Error;
813  break;
814  }
815  if (TryConsumeDeclarationSpecifier() == TPResult::Error)
816  return TPResult::Error;
817  AnyDeclSpecifiers = true;
818  }
819  return TryParsePtrOperatorSeq();
820 }
821 
822 /// declarator:
823 /// direct-declarator
824 /// ptr-operator declarator
825 ///
826 /// direct-declarator:
827 /// declarator-id
828 /// direct-declarator '(' parameter-declaration-clause ')'
829 /// cv-qualifier-seq[opt] exception-specification[opt]
830 /// direct-declarator '[' constant-expression[opt] ']'
831 /// '(' declarator ')'
832 /// [GNU] '(' attributes declarator ')'
833 ///
834 /// abstract-declarator:
835 /// ptr-operator abstract-declarator[opt]
836 /// direct-abstract-declarator
837 ///
838 /// direct-abstract-declarator:
839 /// direct-abstract-declarator[opt]
840 /// '(' parameter-declaration-clause ')' cv-qualifier-seq[opt]
841 /// exception-specification[opt]
842 /// direct-abstract-declarator[opt] '[' constant-expression[opt] ']'
843 /// '(' abstract-declarator ')'
844 /// [C++0x] ...
845 ///
846 /// ptr-operator:
847 /// '*' cv-qualifier-seq[opt]
848 /// '&'
849 /// [C++0x] '&&' [TODO]
850 /// '::'[opt] nested-name-specifier '*' cv-qualifier-seq[opt]
851 ///
852 /// cv-qualifier-seq:
853 /// cv-qualifier cv-qualifier-seq[opt]
854 ///
855 /// cv-qualifier:
856 /// 'const'
857 /// 'volatile'
858 ///
859 /// declarator-id:
860 /// '...'[opt] id-expression
861 ///
862 /// id-expression:
863 /// unqualified-id
864 /// qualified-id [TODO]
865 ///
866 /// unqualified-id:
867 /// identifier
868 /// operator-function-id
869 /// conversion-function-id
870 /// literal-operator-id
871 /// '~' class-name [TODO]
872 /// '~' decltype-specifier [TODO]
873 /// template-id [TODO]
874 ///
875 Parser::TPResult Parser::TryParseDeclarator(bool mayBeAbstract,
876  bool mayHaveIdentifier) {
877  // declarator:
878  // direct-declarator
879  // ptr-operator declarator
880  if (TryParsePtrOperatorSeq() == TPResult::Error)
881  return TPResult::Error;
882 
883  // direct-declarator:
884  // direct-abstract-declarator:
885  if (Tok.is(tok::ellipsis))
886  ConsumeToken();
887 
888  if ((Tok.isOneOf(tok::identifier, tok::kw_operator) ||
889  (Tok.is(tok::annot_cxxscope) && (NextToken().is(tok::identifier) ||
890  NextToken().is(tok::kw_operator)))) &&
891  mayHaveIdentifier) {
892  // declarator-id
893  if (Tok.is(tok::annot_cxxscope))
894  ConsumeAnnotationToken();
895  else if (Tok.is(tok::identifier))
896  TentativelyDeclaredIdentifiers.push_back(Tok.getIdentifierInfo());
897  if (Tok.is(tok::kw_operator)) {
898  if (TryParseOperatorId() == TPResult::Error)
899  return TPResult::Error;
900  } else
901  ConsumeToken();
902  } else if (Tok.is(tok::l_paren)) {
903  ConsumeParen();
904  if (mayBeAbstract &&
905  (Tok.is(tok::r_paren) || // 'int()' is a function.
906  // 'int(...)' is a function.
907  (Tok.is(tok::ellipsis) && NextToken().is(tok::r_paren)) ||
908  isDeclarationSpecifier())) { // 'int(int)' is a function.
909  // '(' parameter-declaration-clause ')' cv-qualifier-seq[opt]
910  // exception-specification[opt]
911  TPResult TPR = TryParseFunctionDeclarator();
912  if (TPR != TPResult::Ambiguous)
913  return TPR;
914  } else {
915  // '(' declarator ')'
916  // '(' attributes declarator ')'
917  // '(' abstract-declarator ')'
918  if (Tok.isOneOf(tok::kw___attribute, tok::kw___declspec, tok::kw___cdecl,
919  tok::kw___stdcall, tok::kw___fastcall, tok::kw___thiscall,
920  tok::kw___regcall, tok::kw___vectorcall))
921  return TPResult::True; // attributes indicate declaration
922  TPResult TPR = TryParseDeclarator(mayBeAbstract, mayHaveIdentifier);
923  if (TPR != TPResult::Ambiguous)
924  return TPR;
925  if (Tok.isNot(tok::r_paren))
926  return TPResult::False;
927  ConsumeParen();
928  }
929  } else if (!mayBeAbstract) {
930  return TPResult::False;
931  }
932 
933  while (1) {
934  TPResult TPR(TPResult::Ambiguous);
935 
936  if (Tok.is(tok::l_paren)) {
937  // Check whether we have a function declarator or a possible ctor-style
938  // initializer that follows the declarator. Note that ctor-style
939  // initializers are not possible in contexts where abstract declarators
940  // are allowed.
941  if (!mayBeAbstract && !isCXXFunctionDeclarator())
942  break;
943 
944  // direct-declarator '(' parameter-declaration-clause ')'
945  // cv-qualifier-seq[opt] exception-specification[opt]
946  ConsumeParen();
947  TPR = TryParseFunctionDeclarator();
948  } else if (Tok.is(tok::l_square)) {
949  // direct-declarator '[' constant-expression[opt] ']'
950  // direct-abstract-declarator[opt] '[' constant-expression[opt] ']'
951  TPR = TryParseBracketDeclarator();
952  } else {
953  break;
954  }
955 
956  if (TPR != TPResult::Ambiguous)
957  return TPR;
958  }
959 
960  return TPResult::Ambiguous;
961 }
962 
963 Parser::TPResult
964 Parser::isExpressionOrTypeSpecifierSimple(tok::TokenKind Kind) {
965  switch (Kind) {
966  // Obviously starts an expression.
967  case tok::numeric_constant:
968  case tok::char_constant:
969  case tok::wide_char_constant:
970  case tok::utf8_char_constant:
971  case tok::utf16_char_constant:
972  case tok::utf32_char_constant:
973  case tok::string_literal:
974  case tok::wide_string_literal:
975  case tok::utf8_string_literal:
976  case tok::utf16_string_literal:
977  case tok::utf32_string_literal:
978  case tok::l_square:
979  case tok::l_paren:
980  case tok::amp:
981  case tok::ampamp:
982  case tok::star:
983  case tok::plus:
984  case tok::plusplus:
985  case tok::minus:
986  case tok::minusminus:
987  case tok::tilde:
988  case tok::exclaim:
989  case tok::kw_sizeof:
990  case tok::kw___func__:
991  case tok::kw_const_cast:
992  case tok::kw_delete:
993  case tok::kw_dynamic_cast:
994  case tok::kw_false:
995  case tok::kw_new:
996  case tok::kw_operator:
997  case tok::kw_reinterpret_cast:
998  case tok::kw_static_cast:
999  case tok::kw_this:
1000  case tok::kw_throw:
1001  case tok::kw_true:
1002  case tok::kw_typeid:
1003  case tok::kw_alignof:
1004  case tok::kw_noexcept:
1005  case tok::kw_nullptr:
1006  case tok::kw__Alignof:
1007  case tok::kw___null:
1008  case tok::kw___alignof:
1009  case tok::kw___builtin_choose_expr:
1010  case tok::kw___builtin_offsetof:
1011  case tok::kw___builtin_va_arg:
1012  case tok::kw___imag:
1013  case tok::kw___real:
1014  case tok::kw___FUNCTION__:
1015  case tok::kw___FUNCDNAME__:
1016  case tok::kw___FUNCSIG__:
1017  case tok::kw_L__FUNCTION__:
1018  case tok::kw___PRETTY_FUNCTION__:
1019  case tok::kw___uuidof:
1020 #define TYPE_TRAIT(N,Spelling,K) \
1021  case tok::kw_##Spelling:
1022 #include "clang/Basic/TokenKinds.def"
1023  return TPResult::True;
1024 
1025  // Obviously starts a type-specifier-seq:
1026  case tok::kw_char:
1027  case tok::kw_const:
1028  case tok::kw_double:
1029  case tok::kw__Float16:
1030  case tok::kw___float128:
1031  case tok::kw_enum:
1032  case tok::kw_half:
1033  case tok::kw_float:
1034  case tok::kw_int:
1035  case tok::kw_long:
1036  case tok::kw___int64:
1037  case tok::kw___int128:
1038  case tok::kw_restrict:
1039  case tok::kw_short:
1040  case tok::kw_signed:
1041  case tok::kw_struct:
1042  case tok::kw_union:
1043  case tok::kw_unsigned:
1044  case tok::kw_void:
1045  case tok::kw_volatile:
1046  case tok::kw__Bool:
1047  case tok::kw__Complex:
1048  case tok::kw_class:
1049  case tok::kw_typename:
1050  case tok::kw_wchar_t:
1051  case tok::kw_char16_t:
1052  case tok::kw_char32_t:
1053  case tok::kw__Decimal32:
1054  case tok::kw__Decimal64:
1055  case tok::kw__Decimal128:
1056  case tok::kw___interface:
1057  case tok::kw___thread:
1058  case tok::kw_thread_local:
1059  case tok::kw__Thread_local:
1060  case tok::kw_typeof:
1061  case tok::kw___underlying_type:
1062  case tok::kw___cdecl:
1063  case tok::kw___stdcall:
1064  case tok::kw___fastcall:
1065  case tok::kw___thiscall:
1066  case tok::kw___regcall:
1067  case tok::kw___vectorcall:
1068  case tok::kw___unaligned:
1069  case tok::kw___vector:
1070  case tok::kw___pixel:
1071  case tok::kw___bool:
1072  case tok::kw__Atomic:
1073 #define GENERIC_IMAGE_TYPE(ImgType, Id) case tok::kw_##ImgType##_t:
1074 #include "clang/Basic/OpenCLImageTypes.def"
1075  case tok::kw___unknown_anytype:
1076  return TPResult::False;
1077 
1078  default:
1079  break;
1080  }
1081 
1082  return TPResult::Ambiguous;
1083 }
1084 
1085 bool Parser::isTentativelyDeclared(IdentifierInfo *II) {
1086  return std::find(TentativelyDeclaredIdentifiers.begin(),
1087  TentativelyDeclaredIdentifiers.end(), II)
1088  != TentativelyDeclaredIdentifiers.end();
1089 }
1090 
1091 namespace {
1092 class TentativeParseCCC : public CorrectionCandidateCallback {
1093 public:
1094  TentativeParseCCC(const Token &Next) {
1095  WantRemainingKeywords = false;
1096  WantTypeSpecifiers = Next.isOneOf(tok::l_paren, tok::r_paren, tok::greater,
1097  tok::l_brace, tok::identifier);
1098  }
1099 
1100  bool ValidateCandidate(const TypoCorrection &Candidate) override {
1101  // Reject any candidate that only resolves to instance members since they
1102  // aren't viable as standalone identifiers instead of member references.
1103  if (Candidate.isResolved() && !Candidate.isKeyword() &&
1104  std::all_of(Candidate.begin(), Candidate.end(),
1105  [](NamedDecl *ND) { return ND->isCXXInstanceMember(); }))
1106  return false;
1107 
1109  }
1110 };
1111 }
1112 /// isCXXDeclarationSpecifier - Returns TPResult::True if it is a declaration
1113 /// specifier, TPResult::False if it is not, TPResult::Ambiguous if it could
1114 /// be either a decl-specifier or a function-style cast, and TPResult::Error
1115 /// if a parsing error was found and reported.
1116 ///
1117 /// If HasMissingTypename is provided, a name with a dependent scope specifier
1118 /// will be treated as ambiguous if the 'typename' keyword is missing. If this
1119 /// happens, *HasMissingTypename will be set to 'true'. This will also be used
1120 /// as an indicator that undeclared identifiers (which will trigger a later
1121 /// parse error) should be treated as types. Returns TPResult::Ambiguous in
1122 /// such cases.
1123 ///
1124 /// decl-specifier:
1125 /// storage-class-specifier
1126 /// type-specifier
1127 /// function-specifier
1128 /// 'friend'
1129 /// 'typedef'
1130 /// [C++11] 'constexpr'
1131 /// [GNU] attributes declaration-specifiers[opt]
1132 ///
1133 /// storage-class-specifier:
1134 /// 'register'
1135 /// 'static'
1136 /// 'extern'
1137 /// 'mutable'
1138 /// 'auto'
1139 /// [GNU] '__thread'
1140 /// [C++11] 'thread_local'
1141 /// [C11] '_Thread_local'
1142 ///
1143 /// function-specifier:
1144 /// 'inline'
1145 /// 'virtual'
1146 /// 'explicit'
1147 ///
1148 /// typedef-name:
1149 /// identifier
1150 ///
1151 /// type-specifier:
1152 /// simple-type-specifier
1153 /// class-specifier
1154 /// enum-specifier
1155 /// elaborated-type-specifier
1156 /// typename-specifier
1157 /// cv-qualifier
1158 ///
1159 /// simple-type-specifier:
1160 /// '::'[opt] nested-name-specifier[opt] type-name
1161 /// '::'[opt] nested-name-specifier 'template'
1162 /// simple-template-id [TODO]
1163 /// 'char'
1164 /// 'wchar_t'
1165 /// 'bool'
1166 /// 'short'
1167 /// 'int'
1168 /// 'long'
1169 /// 'signed'
1170 /// 'unsigned'
1171 /// 'float'
1172 /// 'double'
1173 /// 'void'
1174 /// [GNU] typeof-specifier
1175 /// [GNU] '_Complex'
1176 /// [C++11] 'auto'
1177 /// [GNU] '__auto_type'
1178 /// [C++11] 'decltype' ( expression )
1179 /// [C++1y] 'decltype' ( 'auto' )
1180 ///
1181 /// type-name:
1182 /// class-name
1183 /// enum-name
1184 /// typedef-name
1185 ///
1186 /// elaborated-type-specifier:
1187 /// class-key '::'[opt] nested-name-specifier[opt] identifier
1188 /// class-key '::'[opt] nested-name-specifier[opt] 'template'[opt]
1189 /// simple-template-id
1190 /// 'enum' '::'[opt] nested-name-specifier[opt] identifier
1191 ///
1192 /// enum-name:
1193 /// identifier
1194 ///
1195 /// enum-specifier:
1196 /// 'enum' identifier[opt] '{' enumerator-list[opt] '}'
1197 /// 'enum' identifier[opt] '{' enumerator-list ',' '}'
1198 ///
1199 /// class-specifier:
1200 /// class-head '{' member-specification[opt] '}'
1201 ///
1202 /// class-head:
1203 /// class-key identifier[opt] base-clause[opt]
1204 /// class-key nested-name-specifier identifier base-clause[opt]
1205 /// class-key nested-name-specifier[opt] simple-template-id
1206 /// base-clause[opt]
1207 ///
1208 /// class-key:
1209 /// 'class'
1210 /// 'struct'
1211 /// 'union'
1212 ///
1213 /// cv-qualifier:
1214 /// 'const'
1215 /// 'volatile'
1216 /// [GNU] restrict
1217 ///
1218 Parser::TPResult
1219 Parser::isCXXDeclarationSpecifier(Parser::TPResult BracedCastResult,
1220  bool *HasMissingTypename) {
1221  switch (Tok.getKind()) {
1222  case tok::identifier: {
1223  // Check for need to substitute AltiVec __vector keyword
1224  // for "vector" identifier.
1225  if (TryAltiVecVectorToken())
1226  return TPResult::True;
1227 
1228  const Token &Next = NextToken();
1229  // In 'foo bar', 'foo' is always a type name outside of Objective-C.
1230  if (!getLangOpts().ObjC1 && Next.is(tok::identifier))
1231  return TPResult::True;
1232 
1233  if (Next.isNot(tok::coloncolon) && Next.isNot(tok::less)) {
1234  // Determine whether this is a valid expression. If not, we will hit
1235  // a parse error one way or another. In that case, tell the caller that
1236  // this is ambiguous. Typo-correct to type and expression keywords and
1237  // to types and identifiers, in order to try to recover from errors.
1238  switch (TryAnnotateName(false /* no nested name specifier */,
1239  llvm::make_unique<TentativeParseCCC>(Next))) {
1240  case ANK_Error:
1241  return TPResult::Error;
1242  case ANK_TentativeDecl:
1243  return TPResult::False;
1244  case ANK_TemplateName:
1245  // A bare type template-name which can't be a template template
1246  // argument is an error, and was probably intended to be a type.
1247  return GreaterThanIsOperator ? TPResult::True : TPResult::False;
1248  case ANK_Unresolved:
1249  return HasMissingTypename ? TPResult::Ambiguous : TPResult::False;
1250  case ANK_Success:
1251  break;
1252  }
1253  assert(Tok.isNot(tok::identifier) &&
1254  "TryAnnotateName succeeded without producing an annotation");
1255  } else {
1256  // This might possibly be a type with a dependent scope specifier and
1257  // a missing 'typename' keyword. Don't use TryAnnotateName in this case,
1258  // since it will annotate as a primary expression, and we want to use the
1259  // "missing 'typename'" logic.
1261  return TPResult::Error;
1262  // If annotation failed, assume it's a non-type.
1263  // FIXME: If this happens due to an undeclared identifier, treat it as
1264  // ambiguous.
1265  if (Tok.is(tok::identifier))
1266  return TPResult::False;
1267  }
1268 
1269  // We annotated this token as something. Recurse to handle whatever we got.
1270  return isCXXDeclarationSpecifier(BracedCastResult, HasMissingTypename);
1271  }
1272 
1273  case tok::kw_typename: // typename T::type
1274  // Annotate typenames and C++ scope specifiers. If we get one, just
1275  // recurse to handle whatever we get.
1277  return TPResult::Error;
1278  return isCXXDeclarationSpecifier(BracedCastResult, HasMissingTypename);
1279 
1280  case tok::coloncolon: { // ::foo::bar
1281  const Token &Next = NextToken();
1282  if (Next.isOneOf(tok::kw_new, // ::new
1283  tok::kw_delete)) // ::delete
1284  return TPResult::False;
1285  }
1286  // Fall through.
1287  case tok::kw___super:
1288  case tok::kw_decltype:
1289  // Annotate typenames and C++ scope specifiers. If we get one, just
1290  // recurse to handle whatever we get.
1292  return TPResult::Error;
1293  return isCXXDeclarationSpecifier(BracedCastResult, HasMissingTypename);
1294 
1295  // decl-specifier:
1296  // storage-class-specifier
1297  // type-specifier
1298  // function-specifier
1299  // 'friend'
1300  // 'typedef'
1301  // 'constexpr'
1302  // 'concept'
1303  case tok::kw_friend:
1304  case tok::kw_typedef:
1305  case tok::kw_constexpr:
1306  case tok::kw_concept:
1307  // storage-class-specifier
1308  case tok::kw_register:
1309  case tok::kw_static:
1310  case tok::kw_extern:
1311  case tok::kw_mutable:
1312  case tok::kw_auto:
1313  case tok::kw___thread:
1314  case tok::kw_thread_local:
1315  case tok::kw__Thread_local:
1316  // function-specifier
1317  case tok::kw_inline:
1318  case tok::kw_virtual:
1319  case tok::kw_explicit:
1320 
1321  // Modules
1322  case tok::kw___module_private__:
1323 
1324  // Debugger support
1325  case tok::kw___unknown_anytype:
1326 
1327  // type-specifier:
1328  // simple-type-specifier
1329  // class-specifier
1330  // enum-specifier
1331  // elaborated-type-specifier
1332  // typename-specifier
1333  // cv-qualifier
1334 
1335  // class-specifier
1336  // elaborated-type-specifier
1337  case tok::kw_class:
1338  case tok::kw_struct:
1339  case tok::kw_union:
1340  case tok::kw___interface:
1341  // enum-specifier
1342  case tok::kw_enum:
1343  // cv-qualifier
1344  case tok::kw_const:
1345  case tok::kw_volatile:
1346 
1347  // GNU
1348  case tok::kw_restrict:
1349  case tok::kw__Complex:
1350  case tok::kw___attribute:
1351  case tok::kw___auto_type:
1352  return TPResult::True;
1353 
1354  // Microsoft
1355  case tok::kw___declspec:
1356  case tok::kw___cdecl:
1357  case tok::kw___stdcall:
1358  case tok::kw___fastcall:
1359  case tok::kw___thiscall:
1360  case tok::kw___regcall:
1361  case tok::kw___vectorcall:
1362  case tok::kw___w64:
1363  case tok::kw___sptr:
1364  case tok::kw___uptr:
1365  case tok::kw___ptr64:
1366  case tok::kw___ptr32:
1367  case tok::kw___forceinline:
1368  case tok::kw___unaligned:
1369  case tok::kw__Nonnull:
1370  case tok::kw__Nullable:
1371  case tok::kw__Null_unspecified:
1372  case tok::kw___kindof:
1373  return TPResult::True;
1374 
1375  // Borland
1376  case tok::kw___pascal:
1377  return TPResult::True;
1378 
1379  // AltiVec
1380  case tok::kw___vector:
1381  return TPResult::True;
1382 
1383  case tok::annot_template_id: {
1384  TemplateIdAnnotation *TemplateId = takeTemplateIdAnnotation(Tok);
1385  if (TemplateId->Kind != TNK_Type_template)
1386  return TPResult::False;
1387  CXXScopeSpec SS;
1388  AnnotateTemplateIdTokenAsType();
1389  assert(Tok.is(tok::annot_typename));
1390  goto case_typename;
1391  }
1392 
1393  case tok::annot_cxxscope: // foo::bar or ::foo::bar, but already parsed
1394  // We've already annotated a scope; try to annotate a type.
1396  return TPResult::Error;
1397  if (!Tok.is(tok::annot_typename)) {
1398  // If the next token is an identifier or a type qualifier, then this
1399  // can't possibly be a valid expression either.
1400  if (Tok.is(tok::annot_cxxscope) && NextToken().is(tok::identifier)) {
1401  CXXScopeSpec SS;
1402  Actions.RestoreNestedNameSpecifierAnnotation(Tok.getAnnotationValue(),
1403  Tok.getAnnotationRange(),
1404  SS);
1405  if (SS.getScopeRep() && SS.getScopeRep()->isDependent()) {
1406  RevertingTentativeParsingAction PA(*this);
1407  ConsumeAnnotationToken();
1408  ConsumeToken();
1409  bool isIdentifier = Tok.is(tok::identifier);
1410  TPResult TPR = TPResult::False;
1411  if (!isIdentifier)
1412  TPR = isCXXDeclarationSpecifier(BracedCastResult,
1413  HasMissingTypename);
1414 
1415  if (isIdentifier ||
1416  TPR == TPResult::True || TPR == TPResult::Error)
1417  return TPResult::Error;
1418 
1419  if (HasMissingTypename) {
1420  // We can't tell whether this is a missing 'typename' or a valid
1421  // expression.
1422  *HasMissingTypename = true;
1423  return TPResult::Ambiguous;
1424  }
1425 
1426  // FIXME: Fails to either revert or commit the tentative parse!
1427  } else {
1428  // Try to resolve the name. If it doesn't exist, assume it was
1429  // intended to name a type and keep disambiguating.
1430  switch (TryAnnotateName(false /* SS is not dependent */)) {
1431  case ANK_Error:
1432  return TPResult::Error;
1433  case ANK_TentativeDecl:
1434  return TPResult::False;
1435  case ANK_TemplateName:
1436  // A bare type template-name which can't be a template template
1437  // argument is an error, and was probably intended to be a type.
1438  return GreaterThanIsOperator ? TPResult::True : TPResult::False;
1439  case ANK_Unresolved:
1440  return HasMissingTypename ? TPResult::Ambiguous
1441  : TPResult::False;
1442  case ANK_Success:
1443  // Annotated it, check again.
1444  assert(Tok.isNot(tok::annot_cxxscope) ||
1445  NextToken().isNot(tok::identifier));
1446  return isCXXDeclarationSpecifier(BracedCastResult,
1447  HasMissingTypename);
1448  }
1449  }
1450  }
1451  return TPResult::False;
1452  }
1453  // If that succeeded, fallthrough into the generic simple-type-id case.
1454  LLVM_FALLTHROUGH;
1455 
1456  // The ambiguity resides in a simple-type-specifier/typename-specifier
1457  // followed by a '('. The '(' could either be the start of:
1458  //
1459  // direct-declarator:
1460  // '(' declarator ')'
1461  //
1462  // direct-abstract-declarator:
1463  // '(' parameter-declaration-clause ')' cv-qualifier-seq[opt]
1464  // exception-specification[opt]
1465  // '(' abstract-declarator ')'
1466  //
1467  // or part of a function-style cast expression:
1468  //
1469  // simple-type-specifier '(' expression-list[opt] ')'
1470  //
1471 
1472  // simple-type-specifier:
1473 
1474  case tok::annot_typename:
1475  case_typename:
1476  // In Objective-C, we might have a protocol-qualified type.
1477  if (getLangOpts().ObjC1 && NextToken().is(tok::less)) {
1478  // Tentatively parse the protocol qualifiers.
1479  RevertingTentativeParsingAction PA(*this);
1480  ConsumeAnyToken(); // The type token
1481 
1482  TPResult TPR = TryParseProtocolQualifiers();
1483  bool isFollowedByParen = Tok.is(tok::l_paren);
1484  bool isFollowedByBrace = Tok.is(tok::l_brace);
1485 
1486  if (TPR == TPResult::Error)
1487  return TPResult::Error;
1488 
1489  if (isFollowedByParen)
1490  return TPResult::Ambiguous;
1491 
1492  if (getLangOpts().CPlusPlus11 && isFollowedByBrace)
1493  return BracedCastResult;
1494 
1495  return TPResult::True;
1496  }
1497  LLVM_FALLTHROUGH;
1498 
1499  case tok::kw_char:
1500  case tok::kw_wchar_t:
1501  case tok::kw_char16_t:
1502  case tok::kw_char32_t:
1503  case tok::kw_bool:
1504  case tok::kw_short:
1505  case tok::kw_int:
1506  case tok::kw_long:
1507  case tok::kw___int64:
1508  case tok::kw___int128:
1509  case tok::kw_signed:
1510  case tok::kw_unsigned:
1511  case tok::kw_half:
1512  case tok::kw_float:
1513  case tok::kw_double:
1514  case tok::kw__Float16:
1515  case tok::kw___float128:
1516  case tok::kw_void:
1517  case tok::annot_decltype:
1518  if (NextToken().is(tok::l_paren))
1519  return TPResult::Ambiguous;
1520 
1521  // This is a function-style cast in all cases we disambiguate other than
1522  // one:
1523  // struct S {
1524  // enum E : int { a = 4 }; // enum
1525  // enum E : int { 4 }; // bit-field
1526  // };
1527  if (getLangOpts().CPlusPlus11 && NextToken().is(tok::l_brace))
1528  return BracedCastResult;
1529 
1530  if (isStartOfObjCClassMessageMissingOpenBracket())
1531  return TPResult::False;
1532 
1533  return TPResult::True;
1534 
1535  // GNU typeof support.
1536  case tok::kw_typeof: {
1537  if (NextToken().isNot(tok::l_paren))
1538  return TPResult::True;
1539 
1540  RevertingTentativeParsingAction PA(*this);
1541 
1542  TPResult TPR = TryParseTypeofSpecifier();
1543  bool isFollowedByParen = Tok.is(tok::l_paren);
1544  bool isFollowedByBrace = Tok.is(tok::l_brace);
1545 
1546  if (TPR == TPResult::Error)
1547  return TPResult::Error;
1548 
1549  if (isFollowedByParen)
1550  return TPResult::Ambiguous;
1551 
1552  if (getLangOpts().CPlusPlus11 && isFollowedByBrace)
1553  return BracedCastResult;
1554 
1555  return TPResult::True;
1556  }
1557 
1558  // C++0x type traits support
1559  case tok::kw___underlying_type:
1560  return TPResult::True;
1561 
1562  // C11 _Atomic
1563  case tok::kw__Atomic:
1564  return TPResult::True;
1565 
1566  default:
1567  return TPResult::False;
1568  }
1569 }
1570 
1571 bool Parser::isCXXDeclarationSpecifierAType() {
1572  switch (Tok.getKind()) {
1573  // typename-specifier
1574  case tok::annot_decltype:
1575  case tok::annot_template_id:
1576  case tok::annot_typename:
1577  case tok::kw_typeof:
1578  case tok::kw___underlying_type:
1579  return true;
1580 
1581  // elaborated-type-specifier
1582  case tok::kw_class:
1583  case tok::kw_struct:
1584  case tok::kw_union:
1585  case tok::kw___interface:
1586  case tok::kw_enum:
1587  return true;
1588 
1589  // simple-type-specifier
1590  case tok::kw_char:
1591  case tok::kw_wchar_t:
1592  case tok::kw_char16_t:
1593  case tok::kw_char32_t:
1594  case tok::kw_bool:
1595  case tok::kw_short:
1596  case tok::kw_int:
1597  case tok::kw_long:
1598  case tok::kw___int64:
1599  case tok::kw___int128:
1600  case tok::kw_signed:
1601  case tok::kw_unsigned:
1602  case tok::kw_half:
1603  case tok::kw_float:
1604  case tok::kw_double:
1605  case tok::kw__Float16:
1606  case tok::kw___float128:
1607  case tok::kw_void:
1608  case tok::kw___unknown_anytype:
1609  case tok::kw___auto_type:
1610  return true;
1611 
1612  case tok::kw_auto:
1613  return getLangOpts().CPlusPlus11;
1614 
1615  case tok::kw__Atomic:
1616  // "_Atomic foo"
1617  return NextToken().is(tok::l_paren);
1618 
1619  default:
1620  return false;
1621  }
1622 }
1623 
1624 /// [GNU] typeof-specifier:
1625 /// 'typeof' '(' expressions ')'
1626 /// 'typeof' '(' type-name ')'
1627 ///
1628 Parser::TPResult Parser::TryParseTypeofSpecifier() {
1629  assert(Tok.is(tok::kw_typeof) && "Expected 'typeof'!");
1630  ConsumeToken();
1631 
1632  assert(Tok.is(tok::l_paren) && "Expected '('");
1633  // Parse through the parens after 'typeof'.
1634  ConsumeParen();
1635  if (!SkipUntil(tok::r_paren, StopAtSemi))
1636  return TPResult::Error;
1637 
1638  return TPResult::Ambiguous;
1639 }
1640 
1641 /// [ObjC] protocol-qualifiers:
1642 //// '<' identifier-list '>'
1643 Parser::TPResult Parser::TryParseProtocolQualifiers() {
1644  assert(Tok.is(tok::less) && "Expected '<' for qualifier list");
1645  ConsumeToken();
1646  do {
1647  if (Tok.isNot(tok::identifier))
1648  return TPResult::Error;
1649  ConsumeToken();
1650 
1651  if (Tok.is(tok::comma)) {
1652  ConsumeToken();
1653  continue;
1654  }
1655 
1656  if (Tok.is(tok::greater)) {
1657  ConsumeToken();
1658  return TPResult::Ambiguous;
1659  }
1660  } while (false);
1661 
1662  return TPResult::Error;
1663 }
1664 
1665 /// isCXXFunctionDeclarator - Disambiguates between a function declarator or
1666 /// a constructor-style initializer, when parsing declaration statements.
1667 /// Returns true for function declarator and false for constructor-style
1668 /// initializer.
1669 /// If during the disambiguation process a parsing error is encountered,
1670 /// the function returns true to let the declaration parsing code handle it.
1671 ///
1672 /// '(' parameter-declaration-clause ')' cv-qualifier-seq[opt]
1673 /// exception-specification[opt]
1674 ///
1675 bool Parser::isCXXFunctionDeclarator(bool *IsAmbiguous) {
1676 
1677  // C++ 8.2p1:
1678  // The ambiguity arising from the similarity between a function-style cast and
1679  // a declaration mentioned in 6.8 can also occur in the context of a
1680  // declaration. In that context, the choice is between a function declaration
1681  // with a redundant set of parentheses around a parameter name and an object
1682  // declaration with a function-style cast as the initializer. Just as for the
1683  // ambiguities mentioned in 6.8, the resolution is to consider any construct
1684  // that could possibly be a declaration a declaration.
1685 
1686  RevertingTentativeParsingAction PA(*this);
1687 
1688  ConsumeParen();
1689  bool InvalidAsDeclaration = false;
1690  TPResult TPR = TryParseParameterDeclarationClause(&InvalidAsDeclaration);
1691  if (TPR == TPResult::Ambiguous) {
1692  if (Tok.isNot(tok::r_paren))
1693  TPR = TPResult::False;
1694  else {
1695  const Token &Next = NextToken();
1696  if (Next.isOneOf(tok::amp, tok::ampamp, tok::kw_const, tok::kw_volatile,
1697  tok::kw_throw, tok::kw_noexcept, tok::l_square,
1698  tok::l_brace, tok::kw_try, tok::equal, tok::arrow) ||
1699  isCXX11VirtSpecifier(Next))
1700  // The next token cannot appear after a constructor-style initializer,
1701  // and can appear next in a function definition. This must be a function
1702  // declarator.
1703  TPR = TPResult::True;
1704  else if (InvalidAsDeclaration)
1705  // Use the absence of 'typename' as a tie-breaker.
1706  TPR = TPResult::False;
1707  }
1708  }
1709 
1710  if (IsAmbiguous && TPR == TPResult::Ambiguous)
1711  *IsAmbiguous = true;
1712 
1713  // In case of an error, let the declaration parsing code handle it.
1714  return TPR != TPResult::False;
1715 }
1716 
1717 /// parameter-declaration-clause:
1718 /// parameter-declaration-list[opt] '...'[opt]
1719 /// parameter-declaration-list ',' '...'
1720 ///
1721 /// parameter-declaration-list:
1722 /// parameter-declaration
1723 /// parameter-declaration-list ',' parameter-declaration
1724 ///
1725 /// parameter-declaration:
1726 /// attribute-specifier-seq[opt] decl-specifier-seq declarator attributes[opt]
1727 /// attribute-specifier-seq[opt] decl-specifier-seq declarator attributes[opt]
1728 /// '=' assignment-expression
1729 /// attribute-specifier-seq[opt] decl-specifier-seq abstract-declarator[opt]
1730 /// attributes[opt]
1731 /// attribute-specifier-seq[opt] decl-specifier-seq abstract-declarator[opt]
1732 /// attributes[opt] '=' assignment-expression
1733 ///
1734 Parser::TPResult
1735 Parser::TryParseParameterDeclarationClause(bool *InvalidAsDeclaration,
1736  bool VersusTemplateArgument) {
1737 
1738  if (Tok.is(tok::r_paren))
1739  return TPResult::Ambiguous;
1740 
1741  // parameter-declaration-list[opt] '...'[opt]
1742  // parameter-declaration-list ',' '...'
1743  //
1744  // parameter-declaration-list:
1745  // parameter-declaration
1746  // parameter-declaration-list ',' parameter-declaration
1747  //
1748  while (1) {
1749  // '...'[opt]
1750  if (Tok.is(tok::ellipsis)) {
1751  ConsumeToken();
1752  if (Tok.is(tok::r_paren))
1753  return TPResult::True; // '...)' is a sign of a function declarator.
1754  else
1755  return TPResult::False;
1756  }
1757 
1758  // An attribute-specifier-seq here is a sign of a function declarator.
1759  if (isCXX11AttributeSpecifier(/*Disambiguate*/false,
1760  /*OuterMightBeMessageSend*/true))
1761  return TPResult::True;
1762 
1763  ParsedAttributes attrs(AttrFactory);
1764  MaybeParseMicrosoftAttributes(attrs);
1765 
1766  // decl-specifier-seq
1767  // A parameter-declaration's initializer must be preceded by an '=', so
1768  // decl-specifier-seq '{' is not a parameter in C++11.
1769  TPResult TPR = isCXXDeclarationSpecifier(TPResult::False,
1770  InvalidAsDeclaration);
1771 
1772  if (VersusTemplateArgument && TPR == TPResult::True) {
1773  // Consume the decl-specifier-seq. We have to look past it, since a
1774  // type-id might appear here in a template argument.
1775  bool SeenType = false;
1776  do {
1777  SeenType |= isCXXDeclarationSpecifierAType();
1778  if (TryConsumeDeclarationSpecifier() == TPResult::Error)
1779  return TPResult::Error;
1780 
1781  // If we see a parameter name, this can't be a template argument.
1782  if (SeenType && Tok.is(tok::identifier))
1783  return TPResult::True;
1784 
1785  TPR = isCXXDeclarationSpecifier(TPResult::False,
1786  InvalidAsDeclaration);
1787  if (TPR == TPResult::Error)
1788  return TPR;
1789  } while (TPR != TPResult::False);
1790  } else if (TPR == TPResult::Ambiguous) {
1791  // Disambiguate what follows the decl-specifier.
1792  if (TryConsumeDeclarationSpecifier() == TPResult::Error)
1793  return TPResult::Error;
1794  } else
1795  return TPR;
1796 
1797  // declarator
1798  // abstract-declarator[opt]
1799  TPR = TryParseDeclarator(true/*mayBeAbstract*/);
1800  if (TPR != TPResult::Ambiguous)
1801  return TPR;
1802 
1803  // [GNU] attributes[opt]
1804  if (Tok.is(tok::kw___attribute))
1805  return TPResult::True;
1806 
1807  // If we're disambiguating a template argument in a default argument in
1808  // a class definition versus a parameter declaration, an '=' here
1809  // disambiguates the parse one way or the other.
1810  // If this is a parameter, it must have a default argument because
1811  // (a) the previous parameter did, and
1812  // (b) this must be the first declaration of the function, so we can't
1813  // inherit any default arguments from elsewhere.
1814  // If we see an ')', then we've reached the end of a
1815  // parameter-declaration-clause, and the last param is missing its default
1816  // argument.
1817  if (VersusTemplateArgument)
1818  return Tok.isOneOf(tok::equal, tok::r_paren) ? TPResult::True
1819  : TPResult::False;
1820 
1821  if (Tok.is(tok::equal)) {
1822  // '=' assignment-expression
1823  // Parse through assignment-expression.
1824  // FIXME: assignment-expression may contain an unparenthesized comma.
1825  if (!SkipUntil(tok::comma, tok::r_paren, StopAtSemi | StopBeforeMatch))
1826  return TPResult::Error;
1827  }
1828 
1829  if (Tok.is(tok::ellipsis)) {
1830  ConsumeToken();
1831  if (Tok.is(tok::r_paren))
1832  return TPResult::True; // '...)' is a sign of a function declarator.
1833  else
1834  return TPResult::False;
1835  }
1836 
1837  if (!TryConsumeToken(tok::comma))
1838  break;
1839  }
1840 
1841  return TPResult::Ambiguous;
1842 }
1843 
1844 /// TryParseFunctionDeclarator - We parsed a '(' and we want to try to continue
1845 /// parsing as a function declarator.
1846 /// If TryParseFunctionDeclarator fully parsed the function declarator, it will
1847 /// return TPResult::Ambiguous, otherwise it will return either False() or
1848 /// Error().
1849 ///
1850 /// '(' parameter-declaration-clause ')' cv-qualifier-seq[opt]
1851 /// exception-specification[opt]
1852 ///
1853 /// exception-specification:
1854 /// 'throw' '(' type-id-list[opt] ')'
1855 ///
1856 Parser::TPResult Parser::TryParseFunctionDeclarator() {
1857 
1858  // The '(' is already parsed.
1859 
1860  TPResult TPR = TryParseParameterDeclarationClause();
1861  if (TPR == TPResult::Ambiguous && Tok.isNot(tok::r_paren))
1862  TPR = TPResult::False;
1863 
1864  if (TPR == TPResult::False || TPR == TPResult::Error)
1865  return TPR;
1866 
1867  // Parse through the parens.
1868  if (!SkipUntil(tok::r_paren, StopAtSemi))
1869  return TPResult::Error;
1870 
1871  // cv-qualifier-seq
1872  while (Tok.isOneOf(tok::kw_const, tok::kw_volatile, tok::kw_restrict))
1873  ConsumeToken();
1874 
1875  // ref-qualifier[opt]
1876  if (Tok.isOneOf(tok::amp, tok::ampamp))
1877  ConsumeToken();
1878 
1879  // exception-specification
1880  if (Tok.is(tok::kw_throw)) {
1881  ConsumeToken();
1882  if (Tok.isNot(tok::l_paren))
1883  return TPResult::Error;
1884 
1885  // Parse through the parens after 'throw'.
1886  ConsumeParen();
1887  if (!SkipUntil(tok::r_paren, StopAtSemi))
1888  return TPResult::Error;
1889  }
1890  if (Tok.is(tok::kw_noexcept)) {
1891  ConsumeToken();
1892  // Possibly an expression as well.
1893  if (Tok.is(tok::l_paren)) {
1894  // Find the matching rparen.
1895  ConsumeParen();
1896  if (!SkipUntil(tok::r_paren, StopAtSemi))
1897  return TPResult::Error;
1898  }
1899  }
1900 
1901  return TPResult::Ambiguous;
1902 }
1903 
1904 /// '[' constant-expression[opt] ']'
1905 ///
1906 Parser::TPResult Parser::TryParseBracketDeclarator() {
1907  ConsumeBracket();
1908  if (!SkipUntil(tok::r_square, StopAtSemi))
1909  return TPResult::Error;
1910 
1911  return TPResult::Ambiguous;
1912 }
Simple class containing the result of Sema::CorrectTypo.
bool is(tok::TokenKind K) const
is/isNot - Predicates to check if this token is a specific kind, as in "if (Tok.is(tok::l_brace)) {...
Definition: Token.h:95
bool TryAnnotateCXXScopeToken(bool EnteringContext=false)
TryAnnotateScopeToken - Like TryAnnotateTypeOrScopeToken but only annotates C++ scope specifiers and ...
Definition: Parser.cpp:1850
decl_iterator begin()
TemplateNameKind Kind
The kind of template that Template refers to.
Parser - This implements a parser for the C family of languages.
Definition: Parser.h:57
ConditionDeclarationOrInitStatementState(Parser &P, bool CanBeInitStatement)
tok::TokenKind getKind() const
Definition: Token.h:90
bool SkipUntil(tok::TokenKind T, SkipUntilFlags Flags=static_cast< SkipUntilFlags >(0))
SkipUntil - Read tokens until we get to the specified token, then consume it (unless StopBeforeMatch ...
Definition: Parser.h:945
bool CanBeExpression
Information about a template-id annotation token.
const Token & NextToken()
NextToken - This peeks ahead one token and returns it without consuming it.
Definition: Parser.h:613
bool TryConsumeToken(tok::TokenKind Expected)
Definition: Parser.h:324
One of these records is kept for each identifier that is lexed.
LineState State
Base class for callback objects used by Sema::CorrectTypo to check the validity of a potential typo c...
Token - This structure provides full information about a lexed token.
Definition: Token.h:35
bool isNot(T Kind) const
Definition: FormatToken.h:313
Represents a C++ nested-name-specifier or a global scope specifier.
Definition: DeclSpec.h:63
SourceLocation ConsumeAnyToken(bool ConsumeCodeCompletionTok=false)
ConsumeAnyToken - Dispatch to the right Consume* method based on the current token type...
Definition: Parser.h:344
bool isOneOf(A K1, B K2) const
Definition: FormatToken.h:306
virtual bool ValidateCandidate(const TypoCorrection &candidate)
Simple predicate used by the default RankCandidate to determine whether to return an edit distance of...
const LangOptions & getLangOpts() const
Definition: Parser.h:271
NestedNameSpecifier * getScopeRep() const
Retrieve the representation of the nested-name-specifier.
Definition: DeclSpec.h:76
Kind
Stop skipping at semicolon.
Definition: Parser.h:925
Encodes a location in the source.
bool TryAnnotateTypeOrScopeToken()
TryAnnotateTypeOrScopeToken - If the current token position is on a typename (possibly qualified in C...
Definition: Parser.cpp:1629
bool is(tok::TokenKind Kind) const
Definition: FormatToken.h:297
TokenKind
Provides a simple uniform namespace for tokens from all C languages.
Definition: TokenKinds.h:25
bool isNot(tok::TokenKind K) const
Definition: Token.h:96
Dataflow Directional Tag Classes.
bool isDependent() const
Whether this nested name specifier refers to a dependent type or not.
bool isOneOf(tok::TokenKind K1, tok::TokenKind K2) const
Definition: Token.h:97
The name refers to a template whose specialization produces a type.
Definition: TemplateKinds.h:30
SourceLocation ConsumeToken()
ConsumeToken - Consume the current &#39;peek token&#39; and lex the next one.
Definition: Parser.h:316
decl_iterator end()
Represents a complete lambda introducer.
Definition: DeclSpec.h:2522
NamedDecl - This represents a decl with a name.
Definition: Decl.h:245
ParsedAttributes - A collection of parsed attributes.
Stop skipping at specified token, but don&#39;t skip the token itself.
Definition: Parser.h:927