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