clang  8.0.0svn
Parser.h
Go to the documentation of this file.
1 //===--- Parser.h - C Language Parser ---------------------------*- C++ -*-===//
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 defines the Parser interface.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_CLANG_PARSE_PARSER_H
15 #define LLVM_CLANG_PARSE_PARSER_H
16 
17 #include "clang/AST/Availability.h"
21 #include "clang/Basic/Specifiers.h"
23 #include "clang/Lex/Preprocessor.h"
24 #include "clang/Sema/DeclSpec.h"
25 #include "clang/Sema/LoopHint.h"
26 #include "clang/Sema/Sema.h"
27 #include "llvm/ADT/SmallVector.h"
28 #include "llvm/Support/Compiler.h"
29 #include "llvm/Support/PrettyStackTrace.h"
30 #include "llvm/Support/SaveAndRestore.h"
31 #include <memory>
32 #include <stack>
33 
34 namespace clang {
35  class PragmaHandler;
36  class Scope;
37  class BalancedDelimiterTracker;
38  class CorrectionCandidateCallback;
39  class DeclGroupRef;
40  class DiagnosticBuilder;
41  class Parser;
42  class ParsingDeclRAIIObject;
43  class ParsingDeclSpec;
44  class ParsingDeclarator;
45  class ParsingFieldDeclarator;
46  class ColonProtectionRAIIObject;
47  class InMessageExpressionRAIIObject;
48  class PoisonSEHIdentifiersRAIIObject;
49  class OMPClause;
50  class ObjCTypeParamList;
51  class ObjCTypeParameter;
52 
53 /// Parser - This implements a parser for the C family of languages. After
54 /// parsing units of the grammar, productions are invoked to handle whatever has
55 /// been read.
56 ///
57 class Parser : public CodeCompletionHandler {
61  friend class ObjCDeclContextSwitch;
64 
65  Preprocessor &PP;
66 
67  /// Tok - The current token we are peeking ahead. All parsing methods assume
68  /// that this is valid.
69  Token Tok;
70 
71  // PrevTokLocation - The location of the token we previously
72  // consumed. This token is used for diagnostics where we expected to
73  // see a token following another token (e.g., the ';' at the end of
74  // a statement).
75  SourceLocation PrevTokLocation;
76 
77  unsigned short ParenCount = 0, BracketCount = 0, BraceCount = 0;
78  unsigned short MisplacedModuleBeginCount = 0;
79 
80  /// Actions - These are the callbacks we invoke as we parse various constructs
81  /// in the file.
82  Sema &Actions;
83 
84  DiagnosticsEngine &Diags;
85 
86  /// ScopeCache - Cache scopes to reduce malloc traffic.
87  enum { ScopeCacheSize = 16 };
88  unsigned NumCachedScopes;
89  Scope *ScopeCache[ScopeCacheSize];
90 
91  /// Identifiers used for SEH handling in Borland. These are only
92  /// allowed in particular circumstances
93  // __except block
94  IdentifierInfo *Ident__exception_code,
95  *Ident___exception_code,
96  *Ident_GetExceptionCode;
97  // __except filter expression
98  IdentifierInfo *Ident__exception_info,
99  *Ident___exception_info,
100  *Ident_GetExceptionInfo;
101  // __finally
102  IdentifierInfo *Ident__abnormal_termination,
103  *Ident___abnormal_termination,
104  *Ident_AbnormalTermination;
105 
106  /// Contextual keywords for Microsoft extensions.
107  IdentifierInfo *Ident__except;
108  mutable IdentifierInfo *Ident_sealed;
109 
110  /// Ident_super - IdentifierInfo for "super", to support fast
111  /// comparison.
112  IdentifierInfo *Ident_super;
113  /// Ident_vector, Ident_bool - cached IdentifierInfos for "vector" and
114  /// "bool" fast comparison. Only present if AltiVec or ZVector are enabled.
115  IdentifierInfo *Ident_vector;
116  IdentifierInfo *Ident_bool;
117  /// Ident_pixel - cached IdentifierInfos for "pixel" fast comparison.
118  /// Only present if AltiVec enabled.
119  IdentifierInfo *Ident_pixel;
120 
121  /// Objective-C contextual keywords.
122  mutable IdentifierInfo *Ident_instancetype;
123 
124  /// Identifier for "introduced".
125  IdentifierInfo *Ident_introduced;
126 
127  /// Identifier for "deprecated".
128  IdentifierInfo *Ident_deprecated;
129 
130  /// Identifier for "obsoleted".
131  IdentifierInfo *Ident_obsoleted;
132 
133  /// Identifier for "unavailable".
134  IdentifierInfo *Ident_unavailable;
135 
136  /// Identifier for "message".
137  IdentifierInfo *Ident_message;
138 
139  /// Identifier for "strict".
140  IdentifierInfo *Ident_strict;
141 
142  /// Identifier for "replacement".
143  IdentifierInfo *Ident_replacement;
144 
145  /// Identifiers used by the 'external_source_symbol' attribute.
146  IdentifierInfo *Ident_language, *Ident_defined_in,
147  *Ident_generated_declaration;
148 
149  /// C++0x contextual keywords.
150  mutable IdentifierInfo *Ident_final;
151  mutable IdentifierInfo *Ident_GNU_final;
152  mutable IdentifierInfo *Ident_override;
153 
154  // C++ type trait keywords that can be reverted to identifiers and still be
155  // used as type traits.
156  llvm::SmallDenseMap<IdentifierInfo *, tok::TokenKind> RevertibleTypeTraits;
157 
158  std::unique_ptr<PragmaHandler> AlignHandler;
159  std::unique_ptr<PragmaHandler> GCCVisibilityHandler;
160  std::unique_ptr<PragmaHandler> OptionsHandler;
161  std::unique_ptr<PragmaHandler> PackHandler;
162  std::unique_ptr<PragmaHandler> MSStructHandler;
163  std::unique_ptr<PragmaHandler> UnusedHandler;
164  std::unique_ptr<PragmaHandler> WeakHandler;
165  std::unique_ptr<PragmaHandler> RedefineExtnameHandler;
166  std::unique_ptr<PragmaHandler> FPContractHandler;
167  std::unique_ptr<PragmaHandler> OpenCLExtensionHandler;
168  std::unique_ptr<PragmaHandler> OpenMPHandler;
169  std::unique_ptr<PragmaHandler> PCSectionHandler;
170  std::unique_ptr<PragmaHandler> MSCommentHandler;
171  std::unique_ptr<PragmaHandler> MSDetectMismatchHandler;
172  std::unique_ptr<PragmaHandler> MSPointersToMembers;
173  std::unique_ptr<PragmaHandler> MSVtorDisp;
174  std::unique_ptr<PragmaHandler> MSInitSeg;
175  std::unique_ptr<PragmaHandler> MSDataSeg;
176  std::unique_ptr<PragmaHandler> MSBSSSeg;
177  std::unique_ptr<PragmaHandler> MSConstSeg;
178  std::unique_ptr<PragmaHandler> MSCodeSeg;
179  std::unique_ptr<PragmaHandler> MSSection;
180  std::unique_ptr<PragmaHandler> MSRuntimeChecks;
181  std::unique_ptr<PragmaHandler> MSIntrinsic;
182  std::unique_ptr<PragmaHandler> MSOptimize;
183  std::unique_ptr<PragmaHandler> CUDAForceHostDeviceHandler;
184  std::unique_ptr<PragmaHandler> OptimizeHandler;
185  std::unique_ptr<PragmaHandler> LoopHintHandler;
186  std::unique_ptr<PragmaHandler> UnrollHintHandler;
187  std::unique_ptr<PragmaHandler> NoUnrollHintHandler;
188  std::unique_ptr<PragmaHandler> UnrollAndJamHintHandler;
189  std::unique_ptr<PragmaHandler> NoUnrollAndJamHintHandler;
190  std::unique_ptr<PragmaHandler> FPHandler;
191  std::unique_ptr<PragmaHandler> STDCFENVHandler;
192  std::unique_ptr<PragmaHandler> STDCCXLIMITHandler;
193  std::unique_ptr<PragmaHandler> STDCUnknownHandler;
194  std::unique_ptr<PragmaHandler> AttributePragmaHandler;
195 
196  std::unique_ptr<CommentHandler> CommentSemaHandler;
197 
198  /// Whether the '>' token acts as an operator or not. This will be
199  /// true except when we are parsing an expression within a C++
200  /// template argument list, where the '>' closes the template
201  /// argument list.
202  bool GreaterThanIsOperator;
203 
204  /// ColonIsSacred - When this is false, we aggressively try to recover from
205  /// code like "foo : bar" as if it were a typo for "foo :: bar". This is not
206  /// safe in case statements and a few other things. This is managed by the
207  /// ColonProtectionRAIIObject RAII object.
208  bool ColonIsSacred;
209 
210  /// When true, we are directly inside an Objective-C message
211  /// send expression.
212  ///
213  /// This is managed by the \c InMessageExpressionRAIIObject class, and
214  /// should not be set directly.
215  bool InMessageExpression;
216 
217  /// The "depth" of the template parameters currently being parsed.
218  unsigned TemplateParameterDepth;
219 
220  /// RAII class that manages the template parameter depth.
221  class TemplateParameterDepthRAII {
222  unsigned &Depth;
223  unsigned AddedLevels;
224  public:
225  explicit TemplateParameterDepthRAII(unsigned &Depth)
226  : Depth(Depth), AddedLevels(0) {}
227 
228  ~TemplateParameterDepthRAII() {
229  Depth -= AddedLevels;
230  }
231 
232  void operator++() {
233  ++Depth;
234  ++AddedLevels;
235  }
236  void addDepth(unsigned D) {
237  Depth += D;
238  AddedLevels += D;
239  }
240  unsigned getDepth() const { return Depth; }
241  };
242 
243  /// Factory object for creating ParsedAttr objects.
244  AttributeFactory AttrFactory;
245 
246  /// Gathers and cleans up TemplateIdAnnotations when parsing of a
247  /// top-level declaration is finished.
249 
250  /// Identifiers which have been declared within a tentative parse.
251  SmallVector<IdentifierInfo *, 8> TentativelyDeclaredIdentifiers;
252 
253  /// Tracker for '<' tokens that might have been intended to be treated as an
254  /// angle bracket instead of a less-than comparison.
255  ///
256  /// This happens when the user intends to form a template-id, but typoes the
257  /// template-name or forgets a 'template' keyword for a dependent template
258  /// name.
259  ///
260  /// We track these locations from the point where we see a '<' with a
261  /// name-like expression on its left until we see a '>' or '>>' that might
262  /// match it.
263  struct AngleBracketTracker {
264  /// Flags used to rank candidate template names when there is more than one
265  /// '<' in a scope.
266  enum Priority : unsigned short {
267  /// A non-dependent name that is a potential typo for a template name.
268  PotentialTypo = 0x0,
269  /// A dependent name that might instantiate to a template-name.
270  DependentName = 0x2,
271 
272  /// A space appears before the '<' token.
273  SpaceBeforeLess = 0x0,
274  /// No space before the '<' token
275  NoSpaceBeforeLess = 0x1,
276 
277  LLVM_MARK_AS_BITMASK_ENUM(/*LargestValue*/ DependentName)
278  };
279 
280  struct Loc {
283  AngleBracketTracker::Priority Priority;
284  unsigned short ParenCount, BracketCount, BraceCount;
285 
286  bool isActive(Parser &P) const {
287  return P.ParenCount == ParenCount && P.BracketCount == BracketCount &&
288  P.BraceCount == BraceCount;
289  }
290 
291  bool isActiveOrNested(Parser &P) const {
292  return isActive(P) || P.ParenCount > ParenCount ||
293  P.BracketCount > BracketCount || P.BraceCount > BraceCount;
294  }
295  };
296 
297  SmallVector<Loc, 8> Locs;
298 
299  /// Add an expression that might have been intended to be a template name.
300  /// In the case of ambiguity, we arbitrarily select the innermost such
301  /// expression, for example in 'foo < bar < baz', 'bar' is the current
302  /// candidate. No attempt is made to track that 'foo' is also a candidate
303  /// for the case where we see a second suspicious '>' token.
304  void add(Parser &P, Expr *TemplateName, SourceLocation LessLoc,
305  Priority Prio) {
306  if (!Locs.empty() && Locs.back().isActive(P)) {
307  if (Locs.back().Priority <= Prio) {
308  Locs.back().TemplateName = TemplateName;
309  Locs.back().LessLoc = LessLoc;
310  Locs.back().Priority = Prio;
311  }
312  } else {
313  Locs.push_back({TemplateName, LessLoc, Prio,
314  P.ParenCount, P.BracketCount, P.BraceCount});
315  }
316  }
317 
318  /// Mark the current potential missing template location as having been
319  /// handled (this happens if we pass a "corresponding" '>' or '>>' token
320  /// or leave a bracket scope).
321  void clear(Parser &P) {
322  while (!Locs.empty() && Locs.back().isActiveOrNested(P))
323  Locs.pop_back();
324  }
325 
326  /// Get the current enclosing expression that might hve been intended to be
327  /// a template name.
328  Loc *getCurrent(Parser &P) {
329  if (!Locs.empty() && Locs.back().isActive(P))
330  return &Locs.back();
331  return nullptr;
332  }
333  };
334 
335  AngleBracketTracker AngleBrackets;
336 
337  IdentifierInfo *getSEHExceptKeyword();
338 
339  /// True if we are within an Objective-C container while parsing C-like decls.
340  ///
341  /// This is necessary because Sema thinks we have left the container
342  /// to parse the C-like decls, meaning Actions.getObjCDeclContext() will
343  /// be NULL.
344  bool ParsingInObjCContainer;
345 
346  /// Whether to skip parsing of function bodies.
347  ///
348  /// This option can be used, for example, to speed up searches for
349  /// declarations/definitions when indexing.
350  bool SkipFunctionBodies;
351 
352  /// The location of the expression statement that is being parsed right now.
353  /// Used to determine if an expression that is being parsed is a statement or
354  /// just a regular sub-expression.
355  SourceLocation ExprStatementTokLoc;
356 
357 public:
358  Parser(Preprocessor &PP, Sema &Actions, bool SkipFunctionBodies);
359  ~Parser() override;
360 
361  const LangOptions &getLangOpts() const { return PP.getLangOpts(); }
362  const TargetInfo &getTargetInfo() const { return PP.getTargetInfo(); }
363  Preprocessor &getPreprocessor() const { return PP; }
364  Sema &getActions() const { return Actions; }
365  AttributeFactory &getAttrFactory() { return AttrFactory; }
366 
367  const Token &getCurToken() const { return Tok; }
368  Scope *getCurScope() const { return Actions.getCurScope(); }
370  return Actions.incrementMSManglingNumber();
371  }
372 
373  Decl *getObjCDeclContext() const { return Actions.getObjCDeclContext(); }
374 
375  // Type forwarding. All of these are statically 'void*', but they may all be
376  // different actual classes based on the actions in place.
379 
381 
383 
384  // Parsing methods.
385 
386  /// Initialize - Warm up the parser.
387  ///
388  void Initialize();
389 
390  /// Parse the first top-level declaration in a translation unit.
391  bool ParseFirstTopLevelDecl(DeclGroupPtrTy &Result);
392 
393  /// ParseTopLevelDecl - Parse one top-level declaration. Returns true if
394  /// the EOF was encountered.
395  bool ParseTopLevelDecl(DeclGroupPtrTy &Result);
397  DeclGroupPtrTy Result;
398  return ParseTopLevelDecl(Result);
399  }
400 
401  /// ConsumeToken - Consume the current 'peek token' and lex the next one.
402  /// This does not work with special tokens: string literals, code completion,
403  /// annotation tokens and balanced tokens must be handled using the specific
404  /// consume methods.
405  /// Returns the location of the consumed token.
407  assert(!isTokenSpecial() &&
408  "Should consume special tokens with Consume*Token");
409  PrevTokLocation = Tok.getLocation();
410  PP.Lex(Tok);
411  return PrevTokLocation;
412  }
413 
415  if (Tok.isNot(Expected))
416  return false;
417  assert(!isTokenSpecial() &&
418  "Should consume special tokens with Consume*Token");
419  PrevTokLocation = Tok.getLocation();
420  PP.Lex(Tok);
421  return true;
422  }
423 
425  if (!TryConsumeToken(Expected))
426  return false;
427  Loc = PrevTokLocation;
428  return true;
429  }
430 
431  /// ConsumeAnyToken - Dispatch to the right Consume* method based on the
432  /// current token type. This should only be used in cases where the type of
433  /// the token really isn't known, e.g. in error recovery.
434  SourceLocation ConsumeAnyToken(bool ConsumeCodeCompletionTok = false) {
435  if (isTokenParen())
436  return ConsumeParen();
437  if (isTokenBracket())
438  return ConsumeBracket();
439  if (isTokenBrace())
440  return ConsumeBrace();
441  if (isTokenStringLiteral())
442  return ConsumeStringToken();
443  if (Tok.is(tok::code_completion))
444  return ConsumeCodeCompletionTok ? ConsumeCodeCompletionToken()
445  : handleUnexpectedCodeCompletionToken();
446  if (Tok.isAnnotation())
447  return ConsumeAnnotationToken();
448  return ConsumeToken();
449  }
450 
451 
453  return PP.getLocForEndOfToken(PrevTokLocation);
454  }
455 
456  /// Retrieve the underscored keyword (_Nonnull, _Nullable) that corresponds
457  /// to the given nullability kind.
459  return Actions.getNullabilityKeyword(nullability);
460  }
461 
462 private:
463  //===--------------------------------------------------------------------===//
464  // Low-Level token peeking and consumption methods.
465  //
466 
467  /// isTokenParen - Return true if the cur token is '(' or ')'.
468  bool isTokenParen() const {
469  return Tok.isOneOf(tok::l_paren, tok::r_paren);
470  }
471  /// isTokenBracket - Return true if the cur token is '[' or ']'.
472  bool isTokenBracket() const {
473  return Tok.isOneOf(tok::l_square, tok::r_square);
474  }
475  /// isTokenBrace - Return true if the cur token is '{' or '}'.
476  bool isTokenBrace() const {
477  return Tok.isOneOf(tok::l_brace, tok::r_brace);
478  }
479  /// isTokenStringLiteral - True if this token is a string-literal.
480  bool isTokenStringLiteral() const {
481  return tok::isStringLiteral(Tok.getKind());
482  }
483  /// isTokenSpecial - True if this token requires special consumption methods.
484  bool isTokenSpecial() const {
485  return isTokenStringLiteral() || isTokenParen() || isTokenBracket() ||
486  isTokenBrace() || Tok.is(tok::code_completion) || Tok.isAnnotation();
487  }
488 
489  /// Returns true if the current token is '=' or is a type of '='.
490  /// For typos, give a fixit to '='
491  bool isTokenEqualOrEqualTypo();
492 
493  /// Return the current token to the token stream and make the given
494  /// token the current token.
495  void UnconsumeToken(Token &Consumed) {
496  Token Next = Tok;
497  PP.EnterToken(Consumed);
498  PP.Lex(Tok);
499  PP.EnterToken(Next);
500  }
501 
502  SourceLocation ConsumeAnnotationToken() {
503  assert(Tok.isAnnotation() && "wrong consume method");
504  SourceLocation Loc = Tok.getLocation();
505  PrevTokLocation = Tok.getAnnotationEndLoc();
506  PP.Lex(Tok);
507  return Loc;
508  }
509 
510  /// ConsumeParen - This consume method keeps the paren count up-to-date.
511  ///
512  SourceLocation ConsumeParen() {
513  assert(isTokenParen() && "wrong consume method");
514  if (Tok.getKind() == tok::l_paren)
515  ++ParenCount;
516  else if (ParenCount) {
517  AngleBrackets.clear(*this);
518  --ParenCount; // Don't let unbalanced )'s drive the count negative.
519  }
520  PrevTokLocation = Tok.getLocation();
521  PP.Lex(Tok);
522  return PrevTokLocation;
523  }
524 
525  /// ConsumeBracket - This consume method keeps the bracket count up-to-date.
526  ///
527  SourceLocation ConsumeBracket() {
528  assert(isTokenBracket() && "wrong consume method");
529  if (Tok.getKind() == tok::l_square)
530  ++BracketCount;
531  else if (BracketCount) {
532  AngleBrackets.clear(*this);
533  --BracketCount; // Don't let unbalanced ]'s drive the count negative.
534  }
535 
536  PrevTokLocation = Tok.getLocation();
537  PP.Lex(Tok);
538  return PrevTokLocation;
539  }
540 
541  /// ConsumeBrace - This consume method keeps the brace count up-to-date.
542  ///
543  SourceLocation ConsumeBrace() {
544  assert(isTokenBrace() && "wrong consume method");
545  if (Tok.getKind() == tok::l_brace)
546  ++BraceCount;
547  else if (BraceCount) {
548  AngleBrackets.clear(*this);
549  --BraceCount; // Don't let unbalanced }'s drive the count negative.
550  }
551 
552  PrevTokLocation = Tok.getLocation();
553  PP.Lex(Tok);
554  return PrevTokLocation;
555  }
556 
557  /// ConsumeStringToken - Consume the current 'peek token', lexing a new one
558  /// and returning the token kind. This method is specific to strings, as it
559  /// handles string literal concatenation, as per C99 5.1.1.2, translation
560  /// phase #6.
561  SourceLocation ConsumeStringToken() {
562  assert(isTokenStringLiteral() &&
563  "Should only consume string literals with this method");
564  PrevTokLocation = Tok.getLocation();
565  PP.Lex(Tok);
566  return PrevTokLocation;
567  }
568 
569  /// Consume the current code-completion token.
570  ///
571  /// This routine can be called to consume the code-completion token and
572  /// continue processing in special cases where \c cutOffParsing() isn't
573  /// desired, such as token caching or completion with lookahead.
574  SourceLocation ConsumeCodeCompletionToken() {
575  assert(Tok.is(tok::code_completion));
576  PrevTokLocation = Tok.getLocation();
577  PP.Lex(Tok);
578  return PrevTokLocation;
579  }
580 
581  ///\ brief When we are consuming a code-completion token without having
582  /// matched specific position in the grammar, provide code-completion results
583  /// based on context.
584  ///
585  /// \returns the source location of the code-completion token.
586  SourceLocation handleUnexpectedCodeCompletionToken();
587 
588  /// Abruptly cut off parsing; mainly used when we have reached the
589  /// code-completion point.
590  void cutOffParsing() {
591  if (PP.isCodeCompletionEnabled())
593  // Cut off parsing by acting as if we reached the end-of-file.
594  Tok.setKind(tok::eof);
595  }
596 
597  /// Determine if we're at the end of the file or at a transition
598  /// between modules.
599  bool isEofOrEom() {
600  tok::TokenKind Kind = Tok.getKind();
601  return Kind == tok::eof || Kind == tok::annot_module_begin ||
602  Kind == tok::annot_module_end || Kind == tok::annot_module_include;
603  }
604 
605  /// Checks if the \p Level is valid for use in a fold expression.
606  bool isFoldOperator(prec::Level Level) const;
607 
608  /// Checks if the \p Kind is a valid operator for fold expressions.
609  bool isFoldOperator(tok::TokenKind Kind) const;
610 
611  /// Initialize all pragma handlers.
612  void initializePragmaHandlers();
613 
614  /// Destroy and reset all pragma handlers.
615  void resetPragmaHandlers();
616 
617  /// Handle the annotation token produced for #pragma unused(...)
618  void HandlePragmaUnused();
619 
620  /// Handle the annotation token produced for
621  /// #pragma GCC visibility...
622  void HandlePragmaVisibility();
623 
624  /// Handle the annotation token produced for
625  /// #pragma pack...
626  void HandlePragmaPack();
627 
628  /// Handle the annotation token produced for
629  /// #pragma ms_struct...
630  void HandlePragmaMSStruct();
631 
632  /// Handle the annotation token produced for
633  /// #pragma comment...
634  void HandlePragmaMSComment();
635 
636  void HandlePragmaMSPointersToMembers();
637 
638  void HandlePragmaMSVtorDisp();
639 
640  void HandlePragmaMSPragma();
641  bool HandlePragmaMSSection(StringRef PragmaName,
642  SourceLocation PragmaLocation);
643  bool HandlePragmaMSSegment(StringRef PragmaName,
644  SourceLocation PragmaLocation);
645  bool HandlePragmaMSInitSeg(StringRef PragmaName,
646  SourceLocation PragmaLocation);
647 
648  /// Handle the annotation token produced for
649  /// #pragma align...
650  void HandlePragmaAlign();
651 
652  /// Handle the annotation token produced for
653  /// #pragma clang __debug dump...
654  void HandlePragmaDump();
655 
656  /// Handle the annotation token produced for
657  /// #pragma weak id...
658  void HandlePragmaWeak();
659 
660  /// Handle the annotation token produced for
661  /// #pragma weak id = id...
662  void HandlePragmaWeakAlias();
663 
664  /// Handle the annotation token produced for
665  /// #pragma redefine_extname...
666  void HandlePragmaRedefineExtname();
667 
668  /// Handle the annotation token produced for
669  /// #pragma STDC FP_CONTRACT...
670  void HandlePragmaFPContract();
671 
672  /// Handle the annotation token produced for
673  /// #pragma clang fp ...
674  void HandlePragmaFP();
675 
676  /// Handle the annotation token produced for
677  /// #pragma OPENCL EXTENSION...
678  void HandlePragmaOpenCLExtension();
679 
680  /// Handle the annotation token produced for
681  /// #pragma clang __debug captured
682  StmtResult HandlePragmaCaptured();
683 
684  /// Handle the annotation token produced for
685  /// #pragma clang loop and #pragma unroll.
686  bool HandlePragmaLoopHint(LoopHint &Hint);
687 
688  bool ParsePragmaAttributeSubjectMatchRuleSet(
689  attr::ParsedSubjectMatchRuleSet &SubjectMatchRules,
690  SourceLocation &AnyLoc, SourceLocation &LastMatchRuleEndLoc);
691 
692  void HandlePragmaAttribute();
693 
694  /// GetLookAheadToken - This peeks ahead N tokens and returns that token
695  /// without consuming any tokens. LookAhead(0) returns 'Tok', LookAhead(1)
696  /// returns the token after Tok, etc.
697  ///
698  /// Note that this differs from the Preprocessor's LookAhead method, because
699  /// the Parser always has one token lexed that the preprocessor doesn't.
700  ///
701  const Token &GetLookAheadToken(unsigned N) {
702  if (N == 0 || Tok.is(tok::eof)) return Tok;
703  return PP.LookAhead(N-1);
704  }
705 
706 public:
707  /// NextToken - This peeks ahead one token and returns it without
708  /// consuming it.
709  const Token &NextToken() {
710  return PP.LookAhead(0);
711  }
712 
713  /// getTypeAnnotation - Read a parsed type out of an annotation token.
714  static ParsedType getTypeAnnotation(const Token &Tok) {
716  }
717 
718 private:
719  static void setTypeAnnotation(Token &Tok, ParsedType T) {
721  }
722 
723  /// Read an already-translated primary expression out of an annotation
724  /// token.
725  static ExprResult getExprAnnotation(const Token &Tok) {
726  return ExprResult::getFromOpaquePointer(Tok.getAnnotationValue());
727  }
728 
729  /// Set the primary expression corresponding to the given annotation
730  /// token.
731  static void setExprAnnotation(Token &Tok, ExprResult ER) {
732  Tok.setAnnotationValue(ER.getAsOpaquePointer());
733  }
734 
735 public:
736  // If NeedType is true, then TryAnnotateTypeOrScopeToken will try harder to
737  // find a type name by attempting typo correction.
740  bool IsNewScope);
741  bool TryAnnotateCXXScopeToken(bool EnteringContext = false);
742 
743 private:
744  enum AnnotatedNameKind {
745  /// Annotation has failed and emitted an error.
746  ANK_Error,
747  /// The identifier is a tentatively-declared name.
748  ANK_TentativeDecl,
749  /// The identifier is a template name. FIXME: Add an annotation for that.
750  ANK_TemplateName,
751  /// The identifier can't be resolved.
752  ANK_Unresolved,
753  /// Annotation was successful.
754  ANK_Success
755  };
756  AnnotatedNameKind
757  TryAnnotateName(bool IsAddressOfOperand,
758  std::unique_ptr<CorrectionCandidateCallback> CCC = nullptr);
759 
760  /// Push a tok::annot_cxxscope token onto the token stream.
761  void AnnotateScopeToken(CXXScopeSpec &SS, bool IsNewAnnotation);
762 
763  /// TryAltiVecToken - Check for context-sensitive AltiVec identifier tokens,
764  /// replacing them with the non-context-sensitive keywords. This returns
765  /// true if the token was replaced.
766  bool TryAltiVecToken(DeclSpec &DS, SourceLocation Loc,
767  const char *&PrevSpec, unsigned &DiagID,
768  bool &isInvalid) {
769  if (!getLangOpts().AltiVec && !getLangOpts().ZVector)
770  return false;
771 
772  if (Tok.getIdentifierInfo() != Ident_vector &&
773  Tok.getIdentifierInfo() != Ident_bool &&
774  (!getLangOpts().AltiVec || Tok.getIdentifierInfo() != Ident_pixel))
775  return false;
776 
777  return TryAltiVecTokenOutOfLine(DS, Loc, PrevSpec, DiagID, isInvalid);
778  }
779 
780  /// TryAltiVecVectorToken - Check for context-sensitive AltiVec vector
781  /// identifier token, replacing it with the non-context-sensitive __vector.
782  /// This returns true if the token was replaced.
783  bool TryAltiVecVectorToken() {
784  if ((!getLangOpts().AltiVec && !getLangOpts().ZVector) ||
785  Tok.getIdentifierInfo() != Ident_vector) return false;
786  return TryAltiVecVectorTokenOutOfLine();
787  }
788 
789  bool TryAltiVecVectorTokenOutOfLine();
790  bool TryAltiVecTokenOutOfLine(DeclSpec &DS, SourceLocation Loc,
791  const char *&PrevSpec, unsigned &DiagID,
792  bool &isInvalid);
793 
794  /// Returns true if the current token is the identifier 'instancetype'.
795  ///
796  /// Should only be used in Objective-C language modes.
797  bool isObjCInstancetype() {
798  assert(getLangOpts().ObjC1);
799  if (Tok.isAnnotation())
800  return false;
801  if (!Ident_instancetype)
802  Ident_instancetype = PP.getIdentifierInfo("instancetype");
803  return Tok.getIdentifierInfo() == Ident_instancetype;
804  }
805 
806  /// TryKeywordIdentFallback - For compatibility with system headers using
807  /// keywords as identifiers, attempt to convert the current token to an
808  /// identifier and optionally disable the keyword for the remainder of the
809  /// translation unit. This returns false if the token was not replaced,
810  /// otherwise emits a diagnostic and returns true.
811  bool TryKeywordIdentFallback(bool DisableKeyword);
812 
813  /// Get the TemplateIdAnnotation from the token.
814  TemplateIdAnnotation *takeTemplateIdAnnotation(const Token &tok);
815 
816  /// TentativeParsingAction - An object that is used as a kind of "tentative
817  /// parsing transaction". It gets instantiated to mark the token position and
818  /// after the token consumption is done, Commit() or Revert() is called to
819  /// either "commit the consumed tokens" or revert to the previously marked
820  /// token position. Example:
821  ///
822  /// TentativeParsingAction TPA(*this);
823  /// ConsumeToken();
824  /// ....
825  /// TPA.Revert();
826  ///
827  class TentativeParsingAction {
828  Parser &P;
829  Token PrevTok;
830  size_t PrevTentativelyDeclaredIdentifierCount;
831  unsigned short PrevParenCount, PrevBracketCount, PrevBraceCount;
832  bool isActive;
833 
834  public:
835  explicit TentativeParsingAction(Parser& p) : P(p) {
836  PrevTok = P.Tok;
837  PrevTentativelyDeclaredIdentifierCount =
838  P.TentativelyDeclaredIdentifiers.size();
839  PrevParenCount = P.ParenCount;
840  PrevBracketCount = P.BracketCount;
841  PrevBraceCount = P.BraceCount;
843  isActive = true;
844  }
845  void Commit() {
846  assert(isActive && "Parsing action was finished!");
847  P.TentativelyDeclaredIdentifiers.resize(
848  PrevTentativelyDeclaredIdentifierCount);
850  isActive = false;
851  }
852  void Revert() {
853  assert(isActive && "Parsing action was finished!");
854  P.PP.Backtrack();
855  P.Tok = PrevTok;
856  P.TentativelyDeclaredIdentifiers.resize(
857  PrevTentativelyDeclaredIdentifierCount);
858  P.ParenCount = PrevParenCount;
859  P.BracketCount = PrevBracketCount;
860  P.BraceCount = PrevBraceCount;
861  isActive = false;
862  }
863  ~TentativeParsingAction() {
864  assert(!isActive && "Forgot to call Commit or Revert!");
865  }
866  };
867  /// A TentativeParsingAction that automatically reverts in its destructor.
868  /// Useful for disambiguation parses that will always be reverted.
869  class RevertingTentativeParsingAction
870  : private Parser::TentativeParsingAction {
871  public:
872  RevertingTentativeParsingAction(Parser &P)
873  : Parser::TentativeParsingAction(P) {}
874  ~RevertingTentativeParsingAction() { Revert(); }
875  };
876 
878 
879  /// ObjCDeclContextSwitch - An object used to switch context from
880  /// an objective-c decl context to its enclosing decl context and
881  /// back.
882  class ObjCDeclContextSwitch {
883  Parser &P;
884  Decl *DC;
885  SaveAndRestore<bool> WithinObjCContainer;
886  public:
887  explicit ObjCDeclContextSwitch(Parser &p)
888  : P(p), DC(p.getObjCDeclContext()),
889  WithinObjCContainer(P.ParsingInObjCContainer, DC != nullptr) {
890  if (DC)
891  P.Actions.ActOnObjCTemporaryExitContainerContext(cast<DeclContext>(DC));
892  }
894  if (DC)
895  P.Actions.ActOnObjCReenterContainerContext(cast<DeclContext>(DC));
896  }
897  };
898 
899  /// ExpectAndConsume - The parser expects that 'ExpectedTok' is next in the
900  /// input. If so, it is consumed and false is returned.
901  ///
902  /// If a trivial punctuator misspelling is encountered, a FixIt error
903  /// diagnostic is issued and false is returned after recovery.
904  ///
905  /// If the input is malformed, this emits the specified diagnostic and true is
906  /// returned.
907  bool ExpectAndConsume(tok::TokenKind ExpectedTok,
908  unsigned Diag = diag::err_expected,
909  StringRef DiagMsg = "");
910 
911  /// The parser expects a semicolon and, if present, will consume it.
912  ///
913  /// If the next token is not a semicolon, this emits the specified diagnostic,
914  /// or, if there's just some closing-delimiter noise (e.g., ')' or ']') prior
915  /// to the semicolon, consumes that extra token.
916  bool ExpectAndConsumeSemi(unsigned DiagID);
917 
918  /// The kind of extra semi diagnostic to emit.
919  enum ExtraSemiKind {
920  OutsideFunction = 0,
921  InsideStruct = 1,
922  InstanceVariableList = 2,
923  AfterMemberFunctionDefinition = 3
924  };
925 
926  /// Consume any extra semi-colons until the end of the line.
927  void ConsumeExtraSemi(ExtraSemiKind Kind, unsigned TST = TST_unspecified);
928 
929  /// Return false if the next token is an identifier. An 'expected identifier'
930  /// error is emitted otherwise.
931  ///
932  /// The parser tries to recover from the error by checking if the next token
933  /// is a C++ keyword when parsing Objective-C++. Return false if the recovery
934  /// was successful.
935  bool expectIdentifier();
936 
937 public:
938  //===--------------------------------------------------------------------===//
939  // Scope manipulation
940 
941  /// ParseScope - Introduces a new scope for parsing. The kind of
942  /// scope is determined by ScopeFlags. Objects of this type should
943  /// be created on the stack to coincide with the position where the
944  /// parser enters the new scope, and this object's constructor will
945  /// create that new scope. Similarly, once the object is destroyed
946  /// the parser will exit the scope.
947  class ParseScope {
948  Parser *Self;
949  ParseScope(const ParseScope &) = delete;
950  void operator=(const ParseScope &) = delete;
951 
952  public:
953  // ParseScope - Construct a new object to manage a scope in the
954  // parser Self where the new Scope is created with the flags
955  // ScopeFlags, but only when we aren't about to enter a compound statement.
956  ParseScope(Parser *Self, unsigned ScopeFlags, bool EnteredScope = true,
957  bool BeforeCompoundStmt = false)
958  : Self(Self) {
959  if (EnteredScope && !BeforeCompoundStmt)
960  Self->EnterScope(ScopeFlags);
961  else {
962  if (BeforeCompoundStmt)
964 
965  this->Self = nullptr;
966  }
967  }
968 
969  // Exit - Exit the scope associated with this object now, rather
970  // than waiting until the object is destroyed.
971  void Exit() {
972  if (Self) {
973  Self->ExitScope();
974  Self = nullptr;
975  }
976  }
977 
979  Exit();
980  }
981  };
982 
983  /// EnterScope - Start a new scope.
984  void EnterScope(unsigned ScopeFlags);
985 
986  /// ExitScope - Pop a scope off the scope stack.
987  void ExitScope();
988 
989 private:
990  /// RAII object used to modify the scope flags for the current scope.
991  class ParseScopeFlags {
992  Scope *CurScope;
993  unsigned OldFlags;
994  ParseScopeFlags(const ParseScopeFlags &) = delete;
995  void operator=(const ParseScopeFlags &) = delete;
996 
997  public:
998  ParseScopeFlags(Parser *Self, unsigned ScopeFlags, bool ManageFlags = true);
999  ~ParseScopeFlags();
1000  };
1001 
1002  //===--------------------------------------------------------------------===//
1003  // Diagnostic Emission and Error recovery.
1004 
1005 public:
1006  DiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID);
1007  DiagnosticBuilder Diag(const Token &Tok, unsigned DiagID);
1008  DiagnosticBuilder Diag(unsigned DiagID) {
1009  return Diag(Tok, DiagID);
1010  }
1011 
1012 private:
1013  void SuggestParentheses(SourceLocation Loc, unsigned DK,
1014  SourceRange ParenRange);
1015  void CheckNestedObjCContexts(SourceLocation AtLoc);
1016 
1017 public:
1018 
1019  /// Control flags for SkipUntil functions.
1021  StopAtSemi = 1 << 0, ///< Stop skipping at semicolon
1022  /// Stop skipping at specified token, but don't skip the token itself
1024  StopAtCodeCompletion = 1 << 2 ///< Stop at code completion
1025  };
1026 
1028  SkipUntilFlags R) {
1029  return static_cast<SkipUntilFlags>(static_cast<unsigned>(L) |
1030  static_cast<unsigned>(R));
1031  }
1032 
1033  /// SkipUntil - Read tokens until we get to the specified token, then consume
1034  /// it (unless StopBeforeMatch is specified). Because we cannot guarantee
1035  /// that the token will ever occur, this skips to the next token, or to some
1036  /// likely good stopping point. If Flags has StopAtSemi flag, skipping will
1037  /// stop at a ';' character.
1038  ///
1039  /// If SkipUntil finds the specified token, it returns true, otherwise it
1040  /// returns false.
1042  SkipUntilFlags Flags = static_cast<SkipUntilFlags>(0)) {
1043  return SkipUntil(llvm::makeArrayRef(T), Flags);
1044  }
1046  SkipUntilFlags Flags = static_cast<SkipUntilFlags>(0)) {
1047  tok::TokenKind TokArray[] = {T1, T2};
1048  return SkipUntil(TokArray, Flags);
1049  }
1051  SkipUntilFlags Flags = static_cast<SkipUntilFlags>(0)) {
1052  tok::TokenKind TokArray[] = {T1, T2, T3};
1053  return SkipUntil(TokArray, Flags);
1054  }
1056  SkipUntilFlags Flags = static_cast<SkipUntilFlags>(0));
1057 
1058  /// SkipMalformedDecl - Read tokens until we get to some likely good stopping
1059  /// point for skipping past a simple-declaration.
1060  void SkipMalformedDecl();
1061 
1062 private:
1063  //===--------------------------------------------------------------------===//
1064  // Lexing and parsing of C++ inline methods.
1065 
1066  struct ParsingClass;
1067 
1068  /// [class.mem]p1: "... the class is regarded as complete within
1069  /// - function bodies
1070  /// - default arguments
1071  /// - exception-specifications (TODO: C++0x)
1072  /// - and brace-or-equal-initializers for non-static data members
1073  /// (including such things in nested classes)."
1074  /// LateParsedDeclarations build the tree of those elements so they can
1075  /// be parsed after parsing the top-level class.
1076  class LateParsedDeclaration {
1077  public:
1078  virtual ~LateParsedDeclaration();
1079 
1080  virtual void ParseLexedMethodDeclarations();
1081  virtual void ParseLexedMemberInitializers();
1082  virtual void ParseLexedMethodDefs();
1083  virtual void ParseLexedAttributes();
1084  };
1085 
1086  /// Inner node of the LateParsedDeclaration tree that parses
1087  /// all its members recursively.
1088  class LateParsedClass : public LateParsedDeclaration {
1089  public:
1090  LateParsedClass(Parser *P, ParsingClass *C);
1091  ~LateParsedClass() override;
1092 
1093  void ParseLexedMethodDeclarations() override;
1094  void ParseLexedMemberInitializers() override;
1095  void ParseLexedMethodDefs() override;
1096  void ParseLexedAttributes() override;
1097 
1098  private:
1099  Parser *Self;
1100  ParsingClass *Class;
1101  };
1102 
1103  /// Contains the lexed tokens of an attribute with arguments that
1104  /// may reference member variables and so need to be parsed at the
1105  /// end of the class declaration after parsing all other member
1106  /// member declarations.
1107  /// FIXME: Perhaps we should change the name of LateParsedDeclaration to
1108  /// LateParsedTokens.
1109  struct LateParsedAttribute : public LateParsedDeclaration {
1110  Parser *Self;
1111  CachedTokens Toks;
1112  IdentifierInfo &AttrName;
1113  SourceLocation AttrNameLoc;
1114  SmallVector<Decl*, 2> Decls;
1115 
1116  explicit LateParsedAttribute(Parser *P, IdentifierInfo &Name,
1117  SourceLocation Loc)
1118  : Self(P), AttrName(Name), AttrNameLoc(Loc) {}
1119 
1120  void ParseLexedAttributes() override;
1121 
1122  void addDecl(Decl *D) { Decls.push_back(D); }
1123  };
1124 
1125  // A list of late-parsed attributes. Used by ParseGNUAttributes.
1126  class LateParsedAttrList: public SmallVector<LateParsedAttribute *, 2> {
1127  public:
1128  LateParsedAttrList(bool PSoon = false) : ParseSoon(PSoon) { }
1129 
1130  bool parseSoon() { return ParseSoon; }
1131 
1132  private:
1133  bool ParseSoon; // Are we planning to parse these shortly after creation?
1134  };
1135 
1136  /// Contains the lexed tokens of a member function definition
1137  /// which needs to be parsed at the end of the class declaration
1138  /// after parsing all other member declarations.
1139  struct LexedMethod : public LateParsedDeclaration {
1140  Parser *Self;
1141  Decl *D;
1142  CachedTokens Toks;
1143 
1144  /// Whether this member function had an associated template
1145  /// scope. When true, D is a template declaration.
1146  /// otherwise, it is a member function declaration.
1147  bool TemplateScope;
1148 
1149  explicit LexedMethod(Parser* P, Decl *MD)
1150  : Self(P), D(MD), TemplateScope(false) {}
1151 
1152  void ParseLexedMethodDefs() override;
1153  };
1154 
1155  /// LateParsedDefaultArgument - Keeps track of a parameter that may
1156  /// have a default argument that cannot be parsed yet because it
1157  /// occurs within a member function declaration inside the class
1158  /// (C++ [class.mem]p2).
1159  struct LateParsedDefaultArgument {
1160  explicit LateParsedDefaultArgument(Decl *P,
1161  std::unique_ptr<CachedTokens> Toks = nullptr)
1162  : Param(P), Toks(std::move(Toks)) { }
1163 
1164  /// Param - The parameter declaration for this parameter.
1165  Decl *Param;
1166 
1167  /// Toks - The sequence of tokens that comprises the default
1168  /// argument expression, not including the '=' or the terminating
1169  /// ')' or ','. This will be NULL for parameters that have no
1170  /// default argument.
1171  std::unique_ptr<CachedTokens> Toks;
1172  };
1173 
1174  /// LateParsedMethodDeclaration - A method declaration inside a class that
1175  /// contains at least one entity whose parsing needs to be delayed
1176  /// until the class itself is completely-defined, such as a default
1177  /// argument (C++ [class.mem]p2).
1178  struct LateParsedMethodDeclaration : public LateParsedDeclaration {
1179  explicit LateParsedMethodDeclaration(Parser *P, Decl *M)
1180  : Self(P), Method(M), TemplateScope(false),
1181  ExceptionSpecTokens(nullptr) {}
1182 
1183  void ParseLexedMethodDeclarations() override;
1184 
1185  Parser* Self;
1186 
1187  /// Method - The method declaration.
1188  Decl *Method;
1189 
1190  /// Whether this member function had an associated template
1191  /// scope. When true, D is a template declaration.
1192  /// otherwise, it is a member function declaration.
1193  bool TemplateScope;
1194 
1195  /// DefaultArgs - Contains the parameters of the function and
1196  /// their default arguments. At least one of the parameters will
1197  /// have a default argument, but all of the parameters of the
1198  /// method will be stored so that they can be reintroduced into
1199  /// scope at the appropriate times.
1201 
1202  /// The set of tokens that make up an exception-specification that
1203  /// has not yet been parsed.
1204  CachedTokens *ExceptionSpecTokens;
1205  };
1206 
1207  /// LateParsedMemberInitializer - An initializer for a non-static class data
1208  /// member whose parsing must to be delayed until the class is completely
1209  /// defined (C++11 [class.mem]p2).
1210  struct LateParsedMemberInitializer : public LateParsedDeclaration {
1211  LateParsedMemberInitializer(Parser *P, Decl *FD)
1212  : Self(P), Field(FD) { }
1213 
1214  void ParseLexedMemberInitializers() override;
1215 
1216  Parser *Self;
1217 
1218  /// Field - The field declaration.
1219  Decl *Field;
1220 
1221  /// CachedTokens - The sequence of tokens that comprises the initializer,
1222  /// including any leading '='.
1223  CachedTokens Toks;
1224  };
1225 
1226  /// LateParsedDeclarationsContainer - During parsing of a top (non-nested)
1227  /// C++ class, its method declarations that contain parts that won't be
1228  /// parsed until after the definition is completed (C++ [class.mem]p2),
1229  /// the method declarations and possibly attached inline definitions
1230  /// will be stored here with the tokens that will be parsed to create those
1231  /// entities.
1233 
1234  /// Representation of a class that has been parsed, including
1235  /// any member function declarations or definitions that need to be
1236  /// parsed after the corresponding top-level class is complete.
1237  struct ParsingClass {
1238  ParsingClass(Decl *TagOrTemplate, bool TopLevelClass, bool IsInterface)
1239  : TopLevelClass(TopLevelClass), TemplateScope(false),
1240  IsInterface(IsInterface), TagOrTemplate(TagOrTemplate) { }
1241 
1242  /// Whether this is a "top-level" class, meaning that it is
1243  /// not nested within another class.
1244  bool TopLevelClass : 1;
1245 
1246  /// Whether this class had an associated template
1247  /// scope. When true, TagOrTemplate is a template declaration;
1248  /// otherwise, it is a tag declaration.
1249  bool TemplateScope : 1;
1250 
1251  /// Whether this class is an __interface.
1252  bool IsInterface : 1;
1253 
1254  /// The class or class template whose definition we are parsing.
1255  Decl *TagOrTemplate;
1256 
1257  /// LateParsedDeclarations - Method declarations, inline definitions and
1258  /// nested classes that contain pieces whose parsing will be delayed until
1259  /// the top-level class is fully defined.
1260  LateParsedDeclarationsContainer LateParsedDeclarations;
1261  };
1262 
1263  /// The stack of classes that is currently being
1264  /// parsed. Nested and local classes will be pushed onto this stack
1265  /// when they are parsed, and removed afterward.
1266  std::stack<ParsingClass *> ClassStack;
1267 
1268  ParsingClass &getCurrentClass() {
1269  assert(!ClassStack.empty() && "No lexed method stacks!");
1270  return *ClassStack.top();
1271  }
1272 
1273  /// RAII object used to manage the parsing of a class definition.
1274  class ParsingClassDefinition {
1275  Parser &P;
1276  bool Popped;
1278 
1279  public:
1280  ParsingClassDefinition(Parser &P, Decl *TagOrTemplate, bool TopLevelClass,
1281  bool IsInterface)
1282  : P(P), Popped(false),
1283  State(P.PushParsingClass(TagOrTemplate, TopLevelClass, IsInterface)) {
1284  }
1285 
1286  /// Pop this class of the stack.
1287  void Pop() {
1288  assert(!Popped && "Nested class has already been popped");
1289  Popped = true;
1290  P.PopParsingClass(State);
1291  }
1292 
1293  ~ParsingClassDefinition() {
1294  if (!Popped)
1295  P.PopParsingClass(State);
1296  }
1297  };
1298 
1299  /// Contains information about any template-specific
1300  /// information that has been parsed prior to parsing declaration
1301  /// specifiers.
1302  struct ParsedTemplateInfo {
1303  ParsedTemplateInfo()
1304  : Kind(NonTemplate), TemplateParams(nullptr), TemplateLoc() { }
1305 
1306  ParsedTemplateInfo(TemplateParameterLists *TemplateParams,
1307  bool isSpecialization,
1308  bool lastParameterListWasEmpty = false)
1309  : Kind(isSpecialization? ExplicitSpecialization : Template),
1310  TemplateParams(TemplateParams),
1311  LastParameterListWasEmpty(lastParameterListWasEmpty) { }
1312 
1313  explicit ParsedTemplateInfo(SourceLocation ExternLoc,
1314  SourceLocation TemplateLoc)
1315  : Kind(ExplicitInstantiation), TemplateParams(nullptr),
1316  ExternLoc(ExternLoc), TemplateLoc(TemplateLoc),
1317  LastParameterListWasEmpty(false){ }
1318 
1319  /// The kind of template we are parsing.
1320  enum {
1321  /// We are not parsing a template at all.
1322  NonTemplate = 0,
1323  /// We are parsing a template declaration.
1324  Template,
1325  /// We are parsing an explicit specialization.
1326  ExplicitSpecialization,
1327  /// We are parsing an explicit instantiation.
1328  ExplicitInstantiation
1329  } Kind;
1330 
1331  /// The template parameter lists, for template declarations
1332  /// and explicit specializations.
1333  TemplateParameterLists *TemplateParams;
1334 
1335  /// The location of the 'extern' keyword, if any, for an explicit
1336  /// instantiation
1337  SourceLocation ExternLoc;
1338 
1339  /// The location of the 'template' keyword, for an explicit
1340  /// instantiation.
1341  SourceLocation TemplateLoc;
1342 
1343  /// Whether the last template parameter list was empty.
1344  bool LastParameterListWasEmpty;
1345 
1346  SourceRange getSourceRange() const LLVM_READONLY;
1347  };
1348 
1349  void LexTemplateFunctionForLateParsing(CachedTokens &Toks);
1350  void ParseLateTemplatedFuncDef(LateParsedTemplate &LPT);
1351 
1352  static void LateTemplateParserCallback(void *P, LateParsedTemplate &LPT);
1353  static void LateTemplateParserCleanupCallback(void *P);
1354 
1356  PushParsingClass(Decl *TagOrTemplate, bool TopLevelClass, bool IsInterface);
1357  void DeallocateParsedClasses(ParsingClass *Class);
1358  void PopParsingClass(Sema::ParsingClassState);
1359 
1360  enum CachedInitKind {
1361  CIK_DefaultArgument,
1362  CIK_DefaultInitializer
1363  };
1364 
1365  NamedDecl *ParseCXXInlineMethodDef(AccessSpecifier AS,
1366  ParsedAttributes &AccessAttrs,
1367  ParsingDeclarator &D,
1368  const ParsedTemplateInfo &TemplateInfo,
1369  const VirtSpecifiers &VS,
1370  SourceLocation PureSpecLoc);
1371  void ParseCXXNonStaticMemberInitializer(Decl *VarD);
1372  void ParseLexedAttributes(ParsingClass &Class);
1373  void ParseLexedAttributeList(LateParsedAttrList &LAs, Decl *D,
1374  bool EnterScope, bool OnDefinition);
1375  void ParseLexedAttribute(LateParsedAttribute &LA,
1376  bool EnterScope, bool OnDefinition);
1377  void ParseLexedMethodDeclarations(ParsingClass &Class);
1378  void ParseLexedMethodDeclaration(LateParsedMethodDeclaration &LM);
1379  void ParseLexedMethodDefs(ParsingClass &Class);
1380  void ParseLexedMethodDef(LexedMethod &LM);
1381  void ParseLexedMemberInitializers(ParsingClass &Class);
1382  void ParseLexedMemberInitializer(LateParsedMemberInitializer &MI);
1383  void ParseLexedObjCMethodDefs(LexedMethod &LM, bool parseMethod);
1384  bool ConsumeAndStoreFunctionPrologue(CachedTokens &Toks);
1385  bool ConsumeAndStoreInitializer(CachedTokens &Toks, CachedInitKind CIK);
1386  bool ConsumeAndStoreConditional(CachedTokens &Toks);
1387  bool ConsumeAndStoreUntil(tok::TokenKind T1,
1388  CachedTokens &Toks,
1389  bool StopAtSemi = true,
1390  bool ConsumeFinalToken = true) {
1391  return ConsumeAndStoreUntil(T1, T1, Toks, StopAtSemi, ConsumeFinalToken);
1392  }
1393  bool ConsumeAndStoreUntil(tok::TokenKind T1, tok::TokenKind T2,
1394  CachedTokens &Toks,
1395  bool StopAtSemi = true,
1396  bool ConsumeFinalToken = true);
1397 
1398  //===--------------------------------------------------------------------===//
1399  // C99 6.9: External Definitions.
1400  struct ParsedAttributesWithRange : ParsedAttributes {
1401  ParsedAttributesWithRange(AttributeFactory &factory)
1402  : ParsedAttributes(factory) {}
1403 
1404  void clear() {
1406  Range = SourceRange();
1407  }
1408 
1409  SourceRange Range;
1410  };
1411  struct ParsedAttributesViewWithRange : ParsedAttributesView {
1412  ParsedAttributesViewWithRange() : ParsedAttributesView() {}
1413  void clearListOnly() {
1415  Range = SourceRange();
1416  }
1417 
1418  SourceRange Range;
1419  };
1420 
1421  DeclGroupPtrTy ParseExternalDeclaration(ParsedAttributesWithRange &attrs,
1422  ParsingDeclSpec *DS = nullptr);
1423  bool isDeclarationAfterDeclarator();
1424  bool isStartOfFunctionDefinition(const ParsingDeclarator &Declarator);
1425  DeclGroupPtrTy ParseDeclarationOrFunctionDefinition(
1426  ParsedAttributesWithRange &attrs,
1427  ParsingDeclSpec *DS = nullptr,
1428  AccessSpecifier AS = AS_none);
1429  DeclGroupPtrTy ParseDeclOrFunctionDefInternal(ParsedAttributesWithRange &attrs,
1430  ParsingDeclSpec &DS,
1431  AccessSpecifier AS);
1432 
1433  void SkipFunctionBody();
1434  Decl *ParseFunctionDefinition(ParsingDeclarator &D,
1435  const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo(),
1436  LateParsedAttrList *LateParsedAttrs = nullptr);
1437  void ParseKNRParamDeclarations(Declarator &D);
1438  // EndLoc, if non-NULL, is filled with the location of the last token of
1439  // the simple-asm.
1440  ExprResult ParseSimpleAsm(SourceLocation *EndLoc = nullptr);
1441  ExprResult ParseAsmStringLiteral();
1442 
1443  // Objective-C External Declarations
1444  void MaybeSkipAttributes(tok::ObjCKeywordKind Kind);
1445  DeclGroupPtrTy ParseObjCAtDirectives(ParsedAttributesWithRange &Attrs);
1446  DeclGroupPtrTy ParseObjCAtClassDeclaration(SourceLocation atLoc);
1447  Decl *ParseObjCAtInterfaceDeclaration(SourceLocation AtLoc,
1448  ParsedAttributes &prefixAttrs);
1449  class ObjCTypeParamListScope;
1450  ObjCTypeParamList *parseObjCTypeParamList();
1451  ObjCTypeParamList *parseObjCTypeParamListOrProtocolRefs(
1453  SmallVectorImpl<IdentifierLocPair> &protocolIdents,
1454  SourceLocation &rAngleLoc, bool mayBeProtocolList = true);
1455 
1456  void HelperActionsForIvarDeclarations(Decl *interfaceDecl, SourceLocation atLoc,
1458  SmallVectorImpl<Decl *> &AllIvarDecls,
1459  bool RBraceMissing);
1460  void ParseObjCClassInstanceVariables(Decl *interfaceDecl,
1461  tok::ObjCKeywordKind visibility,
1462  SourceLocation atLoc);
1463  bool ParseObjCProtocolReferences(SmallVectorImpl<Decl *> &P,
1465  bool WarnOnDeclarations,
1466  bool ForObjCContainer,
1467  SourceLocation &LAngleLoc,
1468  SourceLocation &EndProtoLoc,
1469  bool consumeLastToken);
1470 
1471  /// Parse the first angle-bracket-delimited clause for an
1472  /// Objective-C object or object pointer type, which may be either
1473  /// type arguments or protocol qualifiers.
1474  void parseObjCTypeArgsOrProtocolQualifiers(
1475  ParsedType baseType,
1476  SourceLocation &typeArgsLAngleLoc,
1477  SmallVectorImpl<ParsedType> &typeArgs,
1478  SourceLocation &typeArgsRAngleLoc,
1479  SourceLocation &protocolLAngleLoc,
1480  SmallVectorImpl<Decl *> &protocols,
1481  SmallVectorImpl<SourceLocation> &protocolLocs,
1482  SourceLocation &protocolRAngleLoc,
1483  bool consumeLastToken,
1484  bool warnOnIncompleteProtocols);
1485 
1486  /// Parse either Objective-C type arguments or protocol qualifiers; if the
1487  /// former, also parse protocol qualifiers afterward.
1488  void parseObjCTypeArgsAndProtocolQualifiers(
1489  ParsedType baseType,
1490  SourceLocation &typeArgsLAngleLoc,
1491  SmallVectorImpl<ParsedType> &typeArgs,
1492  SourceLocation &typeArgsRAngleLoc,
1493  SourceLocation &protocolLAngleLoc,
1494  SmallVectorImpl<Decl *> &protocols,
1495  SmallVectorImpl<SourceLocation> &protocolLocs,
1496  SourceLocation &protocolRAngleLoc,
1497  bool consumeLastToken);
1498 
1499  /// Parse a protocol qualifier type such as '<NSCopying>', which is
1500  /// an anachronistic way of writing 'id<NSCopying>'.
1501  TypeResult parseObjCProtocolQualifierType(SourceLocation &rAngleLoc);
1502 
1503  /// Parse Objective-C type arguments and protocol qualifiers, extending the
1504  /// current type with the parsed result.
1505  TypeResult parseObjCTypeArgsAndProtocolQualifiers(SourceLocation loc,
1506  ParsedType type,
1507  bool consumeLastToken,
1508  SourceLocation &endLoc);
1509 
1510  void ParseObjCInterfaceDeclList(tok::ObjCKeywordKind contextKey,
1511  Decl *CDecl);
1512  DeclGroupPtrTy ParseObjCAtProtocolDeclaration(SourceLocation atLoc,
1513  ParsedAttributes &prefixAttrs);
1514 
1515  struct ObjCImplParsingDataRAII {
1516  Parser &P;
1517  Decl *Dcl;
1518  bool HasCFunction;
1519  typedef SmallVector<LexedMethod*, 8> LateParsedObjCMethodContainer;
1520  LateParsedObjCMethodContainer LateParsedObjCMethods;
1521 
1522  ObjCImplParsingDataRAII(Parser &parser, Decl *D)
1523  : P(parser), Dcl(D), HasCFunction(false) {
1524  P.CurParsedObjCImpl = this;
1525  Finished = false;
1526  }
1527  ~ObjCImplParsingDataRAII();
1528 
1529  void finish(SourceRange AtEnd);
1530  bool isFinished() const { return Finished; }
1531 
1532  private:
1533  bool Finished;
1534  };
1535  ObjCImplParsingDataRAII *CurParsedObjCImpl;
1536  void StashAwayMethodOrFunctionBodyTokens(Decl *MDecl);
1537 
1538  DeclGroupPtrTy ParseObjCAtImplementationDeclaration(SourceLocation AtLoc);
1539  DeclGroupPtrTy ParseObjCAtEndDeclaration(SourceRange atEnd);
1540  Decl *ParseObjCAtAliasDeclaration(SourceLocation atLoc);
1541  Decl *ParseObjCPropertySynthesize(SourceLocation atLoc);
1542  Decl *ParseObjCPropertyDynamic(SourceLocation atLoc);
1543 
1544  IdentifierInfo *ParseObjCSelectorPiece(SourceLocation &MethodLocation);
1545  // Definitions for Objective-c context sensitive keywords recognition.
1546  enum ObjCTypeQual {
1547  objc_in=0, objc_out, objc_inout, objc_oneway, objc_bycopy, objc_byref,
1548  objc_nonnull, objc_nullable, objc_null_unspecified,
1549  objc_NumQuals
1550  };
1551  IdentifierInfo *ObjCTypeQuals[objc_NumQuals];
1552 
1553  bool isTokIdentifier_in() const;
1554 
1555  ParsedType ParseObjCTypeName(ObjCDeclSpec &DS, DeclaratorContext Ctx,
1556  ParsedAttributes *ParamAttrs);
1557  void ParseObjCMethodRequirement();
1558  Decl *ParseObjCMethodPrototype(
1559  tok::ObjCKeywordKind MethodImplKind = tok::objc_not_keyword,
1560  bool MethodDefinition = true);
1561  Decl *ParseObjCMethodDecl(SourceLocation mLoc, tok::TokenKind mType,
1562  tok::ObjCKeywordKind MethodImplKind = tok::objc_not_keyword,
1563  bool MethodDefinition=true);
1564  void ParseObjCPropertyAttribute(ObjCDeclSpec &DS);
1565 
1566  Decl *ParseObjCMethodDefinition();
1567 
1568 public:
1569  //===--------------------------------------------------------------------===//
1570  // C99 6.5: Expressions.
1571 
1572  /// TypeCastState - State whether an expression is or may be a type cast.
1577  };
1578 
1581  TypeCastState isTypeCast = NotTypeCast);
1585  // Expr that doesn't include commas.
1587 
1589  unsigned &NumLineToksConsumed,
1590  bool IsUnevaluated);
1591 
1592 private:
1593  ExprResult ParseExpressionWithLeadingAt(SourceLocation AtLoc);
1594 
1595  ExprResult ParseExpressionWithLeadingExtension(SourceLocation ExtLoc);
1596 
1597  ExprResult ParseRHSOfBinaryExpression(ExprResult LHS,
1598  prec::Level MinPrec);
1599  ExprResult ParseCastExpression(bool isUnaryExpression,
1600  bool isAddressOfOperand,
1601  bool &NotCastExpr,
1602  TypeCastState isTypeCast,
1603  bool isVectorLiteral = false);
1604  ExprResult ParseCastExpression(bool isUnaryExpression,
1605  bool isAddressOfOperand = false,
1606  TypeCastState isTypeCast = NotTypeCast,
1607  bool isVectorLiteral = false);
1608 
1609  /// Returns true if the next token cannot start an expression.
1610  bool isNotExpressionStart();
1611 
1612  /// Returns true if the next token would start a postfix-expression
1613  /// suffix.
1614  bool isPostfixExpressionSuffixStart() {
1615  tok::TokenKind K = Tok.getKind();
1616  return (K == tok::l_square || K == tok::l_paren ||
1617  K == tok::period || K == tok::arrow ||
1618  K == tok::plusplus || K == tok::minusminus);
1619  }
1620 
1621  bool diagnoseUnknownTemplateId(ExprResult TemplateName, SourceLocation Less);
1622  void checkPotentialAngleBracket(ExprResult &PotentialTemplateName);
1623  bool checkPotentialAngleBracketDelimiter(const AngleBracketTracker::Loc &,
1624  const Token &OpToken);
1625  bool checkPotentialAngleBracketDelimiter(const Token &OpToken) {
1626  if (auto *Info = AngleBrackets.getCurrent(*this))
1627  return checkPotentialAngleBracketDelimiter(*Info, OpToken);
1628  return false;
1629  }
1630 
1631  ExprResult ParsePostfixExpressionSuffix(ExprResult LHS);
1632  ExprResult ParseUnaryExprOrTypeTraitExpression();
1633  ExprResult ParseBuiltinPrimaryExpression();
1634 
1635  ExprResult ParseExprAfterUnaryExprOrTypeTrait(const Token &OpTok,
1636  bool &isCastExpr,
1637  ParsedType &CastTy,
1638  SourceRange &CastRange);
1639 
1642 
1643  /// ParseExpressionList - Used for C/C++ (argument-)expression-list.
1644  bool ParseExpressionList(
1645  SmallVectorImpl<Expr *> &Exprs,
1647  llvm::function_ref<void()> Completer = llvm::function_ref<void()>());
1648 
1649  /// ParseSimpleExpressionList - A simple comma-separated list of expressions,
1650  /// used for misc language extensions.
1651  bool ParseSimpleExpressionList(SmallVectorImpl<Expr*> &Exprs,
1652  SmallVectorImpl<SourceLocation> &CommaLocs);
1653 
1654 
1655  /// ParenParseOption - Control what ParseParenExpression will parse.
1656  enum ParenParseOption {
1657  SimpleExpr, // Only parse '(' expression ')'
1658  FoldExpr, // Also allow fold-expression <anything>
1659  CompoundStmt, // Also allow '(' compound-statement ')'
1660  CompoundLiteral, // Also allow '(' type-name ')' '{' ... '}'
1661  CastExpr // Also allow '(' type-name ')' <anything>
1662  };
1663  ExprResult ParseParenExpression(ParenParseOption &ExprType,
1664  bool stopIfCastExpr,
1665  bool isTypeCast,
1666  ParsedType &CastTy,
1667  SourceLocation &RParenLoc);
1668 
1669  ExprResult ParseCXXAmbiguousParenExpression(
1670  ParenParseOption &ExprType, ParsedType &CastTy,
1672  ExprResult ParseCompoundLiteralExpression(ParsedType Ty,
1673  SourceLocation LParenLoc,
1674  SourceLocation RParenLoc);
1675 
1676  ExprResult ParseStringLiteralExpression(bool AllowUserDefinedLiteral = false);
1677 
1678  ExprResult ParseGenericSelectionExpression();
1679 
1680  ExprResult ParseObjCBoolLiteral();
1681 
1682  ExprResult ParseFoldExpression(ExprResult LHS, BalancedDelimiterTracker &T);
1683 
1684  //===--------------------------------------------------------------------===//
1685  // C++ Expressions
1686  ExprResult tryParseCXXIdExpression(CXXScopeSpec &SS, bool isAddressOfOperand,
1687  Token &Replacement);
1688  ExprResult ParseCXXIdExpression(bool isAddressOfOperand = false);
1689 
1690  bool areTokensAdjacent(const Token &A, const Token &B);
1691 
1692  void CheckForTemplateAndDigraph(Token &Next, ParsedType ObjectTypePtr,
1693  bool EnteringContext, IdentifierInfo &II,
1694  CXXScopeSpec &SS);
1695 
1696  bool ParseOptionalCXXScopeSpecifier(CXXScopeSpec &SS,
1697  ParsedType ObjectType,
1698  bool EnteringContext,
1699  bool *MayBePseudoDestructor = nullptr,
1700  bool IsTypename = false,
1701  IdentifierInfo **LastII = nullptr,
1702  bool OnlyNamespace = false);
1703 
1704  //===--------------------------------------------------------------------===//
1705  // C++0x 5.1.2: Lambda expressions
1706 
1707  // [...] () -> type {...}
1708  ExprResult ParseLambdaExpression();
1709  ExprResult TryParseLambdaExpression();
1710  Optional<unsigned> ParseLambdaIntroducer(LambdaIntroducer &Intro,
1711  bool *SkippedInits = nullptr);
1712  bool TryParseLambdaIntroducer(LambdaIntroducer &Intro);
1713  ExprResult ParseLambdaExpressionAfterIntroducer(
1714  LambdaIntroducer &Intro);
1715 
1716  //===--------------------------------------------------------------------===//
1717  // C++ 5.2p1: C++ Casts
1718  ExprResult ParseCXXCasts();
1719 
1720  //===--------------------------------------------------------------------===//
1721  // C++ 5.2p1: C++ Type Identification
1722  ExprResult ParseCXXTypeid();
1723 
1724  //===--------------------------------------------------------------------===//
1725  // C++ : Microsoft __uuidof Expression
1726  ExprResult ParseCXXUuidof();
1727 
1728  //===--------------------------------------------------------------------===//
1729  // C++ 5.2.4: C++ Pseudo-Destructor Expressions
1730  ExprResult ParseCXXPseudoDestructor(Expr *Base, SourceLocation OpLoc,
1731  tok::TokenKind OpKind,
1732  CXXScopeSpec &SS,
1733  ParsedType ObjectType);
1734 
1735  //===--------------------------------------------------------------------===//
1736  // C++ 9.3.2: C++ 'this' pointer
1737  ExprResult ParseCXXThis();
1738 
1739  //===--------------------------------------------------------------------===//
1740  // C++ 15: C++ Throw Expression
1741  ExprResult ParseThrowExpression();
1742 
1743  ExceptionSpecificationType tryParseExceptionSpecification(
1744  bool Delayed,
1745  SourceRange &SpecificationRange,
1746  SmallVectorImpl<ParsedType> &DynamicExceptions,
1747  SmallVectorImpl<SourceRange> &DynamicExceptionRanges,
1748  ExprResult &NoexceptExpr,
1749  CachedTokens *&ExceptionSpecTokens);
1750 
1751  // EndLoc is filled with the location of the last token of the specification.
1752  ExceptionSpecificationType ParseDynamicExceptionSpecification(
1753  SourceRange &SpecificationRange,
1754  SmallVectorImpl<ParsedType> &Exceptions,
1756 
1757  //===--------------------------------------------------------------------===//
1758  // C++0x 8: Function declaration trailing-return-type
1759  TypeResult ParseTrailingReturnType(SourceRange &Range,
1760  bool MayBeFollowedByDirectInit);
1761 
1762  //===--------------------------------------------------------------------===//
1763  // C++ 2.13.5: C++ Boolean Literals
1764  ExprResult ParseCXXBoolLiteral();
1765 
1766  //===--------------------------------------------------------------------===//
1767  // C++ 5.2.3: Explicit type conversion (functional notation)
1768  ExprResult ParseCXXTypeConstructExpression(const DeclSpec &DS);
1769 
1770  /// ParseCXXSimpleTypeSpecifier - [C++ 7.1.5.2] Simple type specifiers.
1771  /// This should only be called when the current token is known to be part of
1772  /// simple-type-specifier.
1773  void ParseCXXSimpleTypeSpecifier(DeclSpec &DS);
1774 
1775  bool ParseCXXTypeSpecifierSeq(DeclSpec &DS);
1776 
1777  //===--------------------------------------------------------------------===//
1778  // C++ 5.3.4 and 5.3.5: C++ new and delete
1779  bool ParseExpressionListOrTypeId(SmallVectorImpl<Expr*> &Exprs,
1780  Declarator &D);
1781  void ParseDirectNewDeclarator(Declarator &D);
1782  ExprResult ParseCXXNewExpression(bool UseGlobal, SourceLocation Start);
1783  ExprResult ParseCXXDeleteExpression(bool UseGlobal,
1784  SourceLocation Start);
1785 
1786  //===--------------------------------------------------------------------===//
1787  // C++ if/switch/while condition expression.
1788  Sema::ConditionResult ParseCXXCondition(StmtResult *InitStmt,
1789  SourceLocation Loc,
1790  Sema::ConditionKind CK);
1791 
1792  //===--------------------------------------------------------------------===//
1793  // C++ Coroutines
1794 
1795  ExprResult ParseCoyieldExpression();
1796 
1797  //===--------------------------------------------------------------------===//
1798  // C99 6.7.8: Initialization.
1799 
1800  /// ParseInitializer
1801  /// initializer: [C99 6.7.8]
1802  /// assignment-expression
1803  /// '{' ...
1804  ExprResult ParseInitializer() {
1805  if (Tok.isNot(tok::l_brace))
1806  return ParseAssignmentExpression();
1807  return ParseBraceInitializer();
1808  }
1809  bool MayBeDesignationStart();
1810  ExprResult ParseBraceInitializer();
1811  ExprResult ParseInitializerWithPotentialDesignator();
1812 
1813  //===--------------------------------------------------------------------===//
1814  // clang Expressions
1815 
1816  ExprResult ParseBlockLiteralExpression(); // ^{...}
1817 
1818  //===--------------------------------------------------------------------===//
1819  // Objective-C Expressions
1820  ExprResult ParseObjCAtExpression(SourceLocation AtLocation);
1821  ExprResult ParseObjCStringLiteral(SourceLocation AtLoc);
1822  ExprResult ParseObjCCharacterLiteral(SourceLocation AtLoc);
1823  ExprResult ParseObjCNumericLiteral(SourceLocation AtLoc);
1824  ExprResult ParseObjCBooleanLiteral(SourceLocation AtLoc, bool ArgValue);
1825  ExprResult ParseObjCArrayLiteral(SourceLocation AtLoc);
1826  ExprResult ParseObjCDictionaryLiteral(SourceLocation AtLoc);
1827  ExprResult ParseObjCBoxedExpr(SourceLocation AtLoc);
1828  ExprResult ParseObjCEncodeExpression(SourceLocation AtLoc);
1829  ExprResult ParseObjCSelectorExpression(SourceLocation AtLoc);
1830  ExprResult ParseObjCProtocolExpression(SourceLocation AtLoc);
1831  bool isSimpleObjCMessageExpression();
1832  ExprResult ParseObjCMessageExpression();
1833  ExprResult ParseObjCMessageExpressionBody(SourceLocation LBracloc,
1834  SourceLocation SuperLoc,
1835  ParsedType ReceiverType,
1836  Expr *ReceiverExpr);
1837  ExprResult ParseAssignmentExprWithObjCMessageExprStart(
1838  SourceLocation LBracloc, SourceLocation SuperLoc,
1839  ParsedType ReceiverType, Expr *ReceiverExpr);
1840  bool ParseObjCXXMessageReceiver(bool &IsExpr, void *&TypeOrExpr);
1841 
1842  //===--------------------------------------------------------------------===//
1843  // C99 6.8: Statements and Blocks.
1844 
1845  /// A SmallVector of statements, with stack size 32 (as that is the only one
1846  /// used.)
1848  /// A SmallVector of expressions, with stack size 12 (the maximum used.)
1850  /// A SmallVector of types.
1852 
1853  StmtResult ParseStatement(SourceLocation *TrailingElseLoc = nullptr,
1854  bool AllowOpenMPStandalone = false);
1855  enum AllowedConstructsKind {
1856  /// Allow any declarations, statements, OpenMP directives.
1857  ACK_Any,
1858  /// Allow only statements and non-standalone OpenMP directives.
1859  ACK_StatementsOpenMPNonStandalone,
1860  /// Allow statements and all executable OpenMP directives
1861  ACK_StatementsOpenMPAnyExecutable
1862  };
1863  StmtResult
1864  ParseStatementOrDeclaration(StmtVector &Stmts, AllowedConstructsKind Allowed,
1865  SourceLocation *TrailingElseLoc = nullptr);
1866  StmtResult ParseStatementOrDeclarationAfterAttributes(
1867  StmtVector &Stmts,
1868  AllowedConstructsKind Allowed,
1869  SourceLocation *TrailingElseLoc,
1870  ParsedAttributesWithRange &Attrs);
1871  StmtResult ParseExprStatement();
1872  StmtResult ParseLabeledStatement(ParsedAttributesWithRange &attrs);
1873  StmtResult ParseCaseStatement(bool MissingCase = false,
1874  ExprResult Expr = ExprResult());
1875  StmtResult ParseDefaultStatement();
1876  StmtResult ParseCompoundStatement(bool isStmtExpr = false);
1877  StmtResult ParseCompoundStatement(bool isStmtExpr,
1878  unsigned ScopeFlags);
1879  void ParseCompoundStatementLeadingPragmas();
1880  StmtResult ParseCompoundStatementBody(bool isStmtExpr = false);
1881  bool ParseParenExprOrCondition(StmtResult *InitStmt,
1882  Sema::ConditionResult &CondResult,
1883  SourceLocation Loc,
1884  Sema::ConditionKind CK);
1885  StmtResult ParseIfStatement(SourceLocation *TrailingElseLoc);
1886  StmtResult ParseSwitchStatement(SourceLocation *TrailingElseLoc);
1887  StmtResult ParseWhileStatement(SourceLocation *TrailingElseLoc);
1888  StmtResult ParseDoStatement();
1889  StmtResult ParseForStatement(SourceLocation *TrailingElseLoc);
1890  StmtResult ParseGotoStatement();
1891  StmtResult ParseContinueStatement();
1892  StmtResult ParseBreakStatement();
1893  StmtResult ParseReturnStatement();
1894  StmtResult ParseAsmStatement(bool &msAsm);
1895  StmtResult ParseMicrosoftAsmStatement(SourceLocation AsmLoc);
1896  StmtResult ParsePragmaLoopHint(StmtVector &Stmts,
1897  AllowedConstructsKind Allowed,
1898  SourceLocation *TrailingElseLoc,
1899  ParsedAttributesWithRange &Attrs);
1900 
1901  /// Describes the behavior that should be taken for an __if_exists
1902  /// block.
1903  enum IfExistsBehavior {
1904  /// Parse the block; this code is always used.
1905  IEB_Parse,
1906  /// Skip the block entirely; this code is never used.
1907  IEB_Skip,
1908  /// Parse the block as a dependent block, which may be used in
1909  /// some template instantiations but not others.
1910  IEB_Dependent
1911  };
1912 
1913  /// Describes the condition of a Microsoft __if_exists or
1914  /// __if_not_exists block.
1915  struct IfExistsCondition {
1916  /// The location of the initial keyword.
1917  SourceLocation KeywordLoc;
1918  /// Whether this is an __if_exists block (rather than an
1919  /// __if_not_exists block).
1920  bool IsIfExists;
1921 
1922  /// Nested-name-specifier preceding the name.
1923  CXXScopeSpec SS;
1924 
1925  /// The name we're looking for.
1926  UnqualifiedId Name;
1927 
1928  /// The behavior of this __if_exists or __if_not_exists block
1929  /// should.
1930  IfExistsBehavior Behavior;
1931  };
1932 
1933  bool ParseMicrosoftIfExistsCondition(IfExistsCondition& Result);
1934  void ParseMicrosoftIfExistsStatement(StmtVector &Stmts);
1935  void ParseMicrosoftIfExistsExternalDeclaration();
1936  void ParseMicrosoftIfExistsClassDeclaration(DeclSpec::TST TagType,
1937  ParsedAttributes &AccessAttrs,
1938  AccessSpecifier &CurAS);
1939  bool ParseMicrosoftIfExistsBraceInitializer(ExprVector &InitExprs,
1940  bool &InitExprsOk);
1941  bool ParseAsmOperandsOpt(SmallVectorImpl<IdentifierInfo *> &Names,
1942  SmallVectorImpl<Expr *> &Constraints,
1943  SmallVectorImpl<Expr *> &Exprs);
1944 
1945  //===--------------------------------------------------------------------===//
1946  // C++ 6: Statements and Blocks
1947 
1948  StmtResult ParseCXXTryBlock();
1949  StmtResult ParseCXXTryBlockCommon(SourceLocation TryLoc, bool FnTry = false);
1950  StmtResult ParseCXXCatchBlock(bool FnCatch = false);
1951 
1952  //===--------------------------------------------------------------------===//
1953  // MS: SEH Statements and Blocks
1954 
1955  StmtResult ParseSEHTryBlock();
1956  StmtResult ParseSEHExceptBlock(SourceLocation Loc);
1957  StmtResult ParseSEHFinallyBlock(SourceLocation Loc);
1958  StmtResult ParseSEHLeaveStatement();
1959 
1960  //===--------------------------------------------------------------------===//
1961  // Objective-C Statements
1962 
1963  StmtResult ParseObjCAtStatement(SourceLocation atLoc);
1964  StmtResult ParseObjCTryStmt(SourceLocation atLoc);
1965  StmtResult ParseObjCThrowStmt(SourceLocation atLoc);
1966  StmtResult ParseObjCSynchronizedStmt(SourceLocation atLoc);
1967  StmtResult ParseObjCAutoreleasePoolStmt(SourceLocation atLoc);
1968 
1969 
1970  //===--------------------------------------------------------------------===//
1971  // C99 6.7: Declarations.
1972 
1973  /// A context for parsing declaration specifiers. TODO: flesh this
1974  /// out, there are other significant restrictions on specifiers than
1975  /// would be best implemented in the parser.
1976  enum class DeclSpecContext {
1977  DSC_normal, // normal context
1978  DSC_class, // class context, enables 'friend'
1979  DSC_type_specifier, // C++ type-specifier-seq or C specifier-qualifier-list
1980  DSC_trailing, // C++11 trailing-type-specifier in a trailing return type
1981  DSC_alias_declaration, // C++11 type-specifier-seq in an alias-declaration
1982  DSC_top_level, // top-level/namespace declaration context
1983  DSC_template_param, // template parameter context
1984  DSC_template_type_arg, // template type argument context
1985  DSC_objc_method_result, // ObjC method result context, enables 'instancetype'
1986  DSC_condition // condition declaration context
1987  };
1988 
1989  /// Is this a context in which we are parsing just a type-specifier (or
1990  /// trailing-type-specifier)?
1991  static bool isTypeSpecifier(DeclSpecContext DSC) {
1992  switch (DSC) {
1993  case DeclSpecContext::DSC_normal:
1994  case DeclSpecContext::DSC_template_param:
1995  case DeclSpecContext::DSC_class:
1996  case DeclSpecContext::DSC_top_level:
1997  case DeclSpecContext::DSC_objc_method_result:
1998  case DeclSpecContext::DSC_condition:
1999  return false;
2000 
2001  case DeclSpecContext::DSC_template_type_arg:
2002  case DeclSpecContext::DSC_type_specifier:
2003  case DeclSpecContext::DSC_trailing:
2004  case DeclSpecContext::DSC_alias_declaration:
2005  return true;
2006  }
2007  llvm_unreachable("Missing DeclSpecContext case");
2008  }
2009 
2010  /// Is this a context in which we can perform class template argument
2011  /// deduction?
2012  static bool isClassTemplateDeductionContext(DeclSpecContext DSC) {
2013  switch (DSC) {
2014  case DeclSpecContext::DSC_normal:
2015  case DeclSpecContext::DSC_template_param:
2016  case DeclSpecContext::DSC_class:
2017  case DeclSpecContext::DSC_top_level:
2018  case DeclSpecContext::DSC_condition:
2019  case DeclSpecContext::DSC_type_specifier:
2020  return true;
2021 
2022  case DeclSpecContext::DSC_objc_method_result:
2023  case DeclSpecContext::DSC_template_type_arg:
2024  case DeclSpecContext::DSC_trailing:
2025  case DeclSpecContext::DSC_alias_declaration:
2026  return false;
2027  }
2028  llvm_unreachable("Missing DeclSpecContext case");
2029  }
2030 
2031  /// Information on a C++0x for-range-initializer found while parsing a
2032  /// declaration which turns out to be a for-range-declaration.
2033  struct ForRangeInit {
2035  ExprResult RangeExpr;
2036 
2037  bool ParsedForRangeDecl() { return !ColonLoc.isInvalid(); }
2038  };
2039 
2040  DeclGroupPtrTy ParseDeclaration(DeclaratorContext Context,
2041  SourceLocation &DeclEnd,
2042  ParsedAttributesWithRange &attrs);
2043  DeclGroupPtrTy ParseSimpleDeclaration(DeclaratorContext Context,
2044  SourceLocation &DeclEnd,
2045  ParsedAttributesWithRange &attrs,
2046  bool RequireSemi,
2047  ForRangeInit *FRI = nullptr);
2048  bool MightBeDeclarator(DeclaratorContext Context);
2049  DeclGroupPtrTy ParseDeclGroup(ParsingDeclSpec &DS, DeclaratorContext Context,
2050  SourceLocation *DeclEnd = nullptr,
2051  ForRangeInit *FRI = nullptr);
2052  Decl *ParseDeclarationAfterDeclarator(Declarator &D,
2053  const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo());
2054  bool ParseAsmAttributesAfterDeclarator(Declarator &D);
2055  Decl *ParseDeclarationAfterDeclaratorAndAttributes(
2056  Declarator &D,
2057  const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo(),
2058  ForRangeInit *FRI = nullptr);
2059  Decl *ParseFunctionStatementBody(Decl *Decl, ParseScope &BodyScope);
2060  Decl *ParseFunctionTryBlock(Decl *Decl, ParseScope &BodyScope);
2061 
2062  /// When in code-completion, skip parsing of the function/method body
2063  /// unless the body contains the code-completion point.
2064  ///
2065  /// \returns true if the function body was skipped.
2066  bool trySkippingFunctionBody();
2067 
2068  bool ParseImplicitInt(DeclSpec &DS, CXXScopeSpec *SS,
2069  const ParsedTemplateInfo &TemplateInfo,
2070  AccessSpecifier AS, DeclSpecContext DSC,
2071  ParsedAttributesWithRange &Attrs);
2072  DeclSpecContext
2073  getDeclSpecContextFromDeclaratorContext(DeclaratorContext Context);
2074  void ParseDeclarationSpecifiers(
2075  DeclSpec &DS,
2076  const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo(),
2077  AccessSpecifier AS = AS_none,
2078  DeclSpecContext DSC = DeclSpecContext::DSC_normal,
2079  LateParsedAttrList *LateAttrs = nullptr);
2080  bool DiagnoseMissingSemiAfterTagDefinition(
2081  DeclSpec &DS, AccessSpecifier AS, DeclSpecContext DSContext,
2082  LateParsedAttrList *LateAttrs = nullptr);
2083 
2084  void ParseSpecifierQualifierList(
2085  DeclSpec &DS, AccessSpecifier AS = AS_none,
2086  DeclSpecContext DSC = DeclSpecContext::DSC_normal);
2087 
2088  void ParseObjCTypeQualifierList(ObjCDeclSpec &DS,
2089  DeclaratorContext Context);
2090 
2091  void ParseEnumSpecifier(SourceLocation TagLoc, DeclSpec &DS,
2092  const ParsedTemplateInfo &TemplateInfo,
2093  AccessSpecifier AS, DeclSpecContext DSC);
2094  void ParseEnumBody(SourceLocation StartLoc, Decl *TagDecl);
2095  void ParseStructUnionBody(SourceLocation StartLoc, unsigned TagType,
2096  Decl *TagDecl);
2097 
2098  void ParseStructDeclaration(
2099  ParsingDeclSpec &DS,
2100  llvm::function_ref<void(ParsingFieldDeclarator &)> FieldsCallback);
2101 
2102  bool isDeclarationSpecifier(bool DisambiguatingWithExpression = false);
2103  bool isTypeSpecifierQualifier();
2104 
2105  /// isKnownToBeTypeSpecifier - Return true if we know that the specified token
2106  /// is definitely a type-specifier. Return false if it isn't part of a type
2107  /// specifier or if we're not sure.
2108  bool isKnownToBeTypeSpecifier(const Token &Tok) const;
2109 
2110  /// Return true if we know that we are definitely looking at a
2111  /// decl-specifier, and isn't part of an expression such as a function-style
2112  /// cast. Return false if it's no a decl-specifier, or we're not sure.
2113  bool isKnownToBeDeclarationSpecifier() {
2114  if (getLangOpts().CPlusPlus)
2115  return isCXXDeclarationSpecifier() == TPResult::True;
2116  return isDeclarationSpecifier(true);
2117  }
2118 
2119  /// isDeclarationStatement - Disambiguates between a declaration or an
2120  /// expression statement, when parsing function bodies.
2121  /// Returns true for declaration, false for expression.
2122  bool isDeclarationStatement() {
2123  if (getLangOpts().CPlusPlus)
2124  return isCXXDeclarationStatement();
2125  return isDeclarationSpecifier(true);
2126  }
2127 
2128  /// isForInitDeclaration - Disambiguates between a declaration or an
2129  /// expression in the context of the C 'clause-1' or the C++
2130  // 'for-init-statement' part of a 'for' statement.
2131  /// Returns true for declaration, false for expression.
2132  bool isForInitDeclaration() {
2133  if (getLangOpts().CPlusPlus)
2134  return isCXXSimpleDeclaration(/*AllowForRangeDecl=*/true);
2135  return isDeclarationSpecifier(true);
2136  }
2137 
2138  /// Determine whether this is a C++1z for-range-identifier.
2139  bool isForRangeIdentifier();
2140 
2141  /// Determine whether we are currently at the start of an Objective-C
2142  /// class message that appears to be missing the open bracket '['.
2143  bool isStartOfObjCClassMessageMissingOpenBracket();
2144 
2145  /// Starting with a scope specifier, identifier, or
2146  /// template-id that refers to the current class, determine whether
2147  /// this is a constructor declarator.
2148  bool isConstructorDeclarator(bool Unqualified, bool DeductionGuide = false);
2149 
2150  /// Specifies the context in which type-id/expression
2151  /// disambiguation will occur.
2152  enum TentativeCXXTypeIdContext {
2153  TypeIdInParens,
2154  TypeIdUnambiguous,
2155  TypeIdAsTemplateArgument
2156  };
2157 
2158 
2159  /// isTypeIdInParens - Assumes that a '(' was parsed and now we want to know
2160  /// whether the parens contain an expression or a type-id.
2161  /// Returns true for a type-id and false for an expression.
2162  bool isTypeIdInParens(bool &isAmbiguous) {
2163  if (getLangOpts().CPlusPlus)
2164  return isCXXTypeId(TypeIdInParens, isAmbiguous);
2165  isAmbiguous = false;
2166  return isTypeSpecifierQualifier();
2167  }
2168  bool isTypeIdInParens() {
2169  bool isAmbiguous;
2170  return isTypeIdInParens(isAmbiguous);
2171  }
2172 
2173  /// Checks if the current tokens form type-id or expression.
2174  /// It is similar to isTypeIdInParens but does not suppose that type-id
2175  /// is in parenthesis.
2176  bool isTypeIdUnambiguously() {
2177  bool IsAmbiguous;
2178  if (getLangOpts().CPlusPlus)
2179  return isCXXTypeId(TypeIdUnambiguous, IsAmbiguous);
2180  return isTypeSpecifierQualifier();
2181  }
2182 
2183  /// isCXXDeclarationStatement - C++-specialized function that disambiguates
2184  /// between a declaration or an expression statement, when parsing function
2185  /// bodies. Returns true for declaration, false for expression.
2186  bool isCXXDeclarationStatement();
2187 
2188  /// isCXXSimpleDeclaration - C++-specialized function that disambiguates
2189  /// between a simple-declaration or an expression-statement.
2190  /// If during the disambiguation process a parsing error is encountered,
2191  /// the function returns true to let the declaration parsing code handle it.
2192  /// Returns false if the statement is disambiguated as expression.
2193  bool isCXXSimpleDeclaration(bool AllowForRangeDecl);
2194 
2195  /// isCXXFunctionDeclarator - Disambiguates between a function declarator or
2196  /// a constructor-style initializer, when parsing declaration statements.
2197  /// Returns true for function declarator and false for constructor-style
2198  /// initializer. Sets 'IsAmbiguous' to true to indicate that this declaration
2199  /// might be a constructor-style initializer.
2200  /// If during the disambiguation process a parsing error is encountered,
2201  /// the function returns true to let the declaration parsing code handle it.
2202  bool isCXXFunctionDeclarator(bool *IsAmbiguous = nullptr);
2203 
2205  enum class ConditionOrInitStatement {
2206  Expression, ///< Disambiguated as an expression (either kind).
2207  ConditionDecl, ///< Disambiguated as the declaration form of condition.
2208  InitStmtDecl, ///< Disambiguated as a simple-declaration init-statement.
2209  Error ///< Can't be any of the above!
2210  };
2211  /// Disambiguates between the different kinds of things that can happen
2212  /// after 'if (' or 'switch ('. This could be one of two different kinds of
2213  /// declaration (depending on whether there is a ';' later) or an expression.
2214  ConditionOrInitStatement
2215  isCXXConditionDeclarationOrInitStatement(bool CanBeInitStmt);
2216 
2217  bool isCXXTypeId(TentativeCXXTypeIdContext Context, bool &isAmbiguous);
2218  bool isCXXTypeId(TentativeCXXTypeIdContext Context) {
2219  bool isAmbiguous;
2220  return isCXXTypeId(Context, isAmbiguous);
2221  }
2222 
2223  /// TPResult - Used as the result value for functions whose purpose is to
2224  /// disambiguate C++ constructs by "tentatively parsing" them.
2225  enum class TPResult {
2226  True, False, Ambiguous, Error
2227  };
2228 
2229  /// Based only on the given token kind, determine whether we know that
2230  /// we're at the start of an expression or a type-specifier-seq (which may
2231  /// be an expression, in C++).
2232  ///
2233  /// This routine does not attempt to resolve any of the trick cases, e.g.,
2234  /// those involving lookup of identifiers.
2235  ///
2236  /// \returns \c TPR_true if this token starts an expression, \c TPR_false if
2237  /// this token starts a type-specifier-seq, or \c TPR_ambiguous if it cannot
2238  /// tell.
2239  TPResult isExpressionOrTypeSpecifierSimple(tok::TokenKind Kind);
2240 
2241  /// isCXXDeclarationSpecifier - Returns TPResult::True if it is a
2242  /// declaration specifier, TPResult::False if it is not,
2243  /// TPResult::Ambiguous if it could be either a decl-specifier or a
2244  /// function-style cast, and TPResult::Error if a parsing error was
2245  /// encountered. If it could be a braced C++11 function-style cast, returns
2246  /// BracedCastResult.
2247  /// Doesn't consume tokens.
2248  TPResult
2249  isCXXDeclarationSpecifier(TPResult BracedCastResult = TPResult::False,
2250  bool *HasMissingTypename = nullptr);
2251 
2252  /// Given that isCXXDeclarationSpecifier returns \c TPResult::True or
2253  /// \c TPResult::Ambiguous, determine whether the decl-specifier would be
2254  /// a type-specifier other than a cv-qualifier.
2255  bool isCXXDeclarationSpecifierAType();
2256 
2257  /// Determine whether an identifier has been tentatively declared as a
2258  /// non-type. Such tentative declarations should not be found to name a type
2259  /// during a tentative parse, but also should not be annotated as a non-type.
2260  bool isTentativelyDeclared(IdentifierInfo *II);
2261 
2262  // "Tentative parsing" functions, used for disambiguation. If a parsing error
2263  // is encountered they will return TPResult::Error.
2264  // Returning TPResult::True/False indicates that the ambiguity was
2265  // resolved and tentative parsing may stop. TPResult::Ambiguous indicates
2266  // that more tentative parsing is necessary for disambiguation.
2267  // They all consume tokens, so backtracking should be used after calling them.
2268 
2269  TPResult TryParseSimpleDeclaration(bool AllowForRangeDecl);
2270  TPResult TryParseTypeofSpecifier();
2271  TPResult TryParseProtocolQualifiers();
2272  TPResult TryParsePtrOperatorSeq();
2273  TPResult TryParseOperatorId();
2274  TPResult TryParseInitDeclaratorList();
2275  TPResult TryParseDeclarator(bool mayBeAbstract, bool mayHaveIdentifier = true,
2276  bool mayHaveDirectInit = false);
2277  TPResult
2278  TryParseParameterDeclarationClause(bool *InvalidAsDeclaration = nullptr,
2279  bool VersusTemplateArg = false);
2280  TPResult TryParseFunctionDeclarator();
2281  TPResult TryParseBracketDeclarator();
2282  TPResult TryConsumeDeclarationSpecifier();
2283 
2284 public:
2285  TypeResult ParseTypeName(SourceRange *Range = nullptr,
2286  DeclaratorContext Context
2288  AccessSpecifier AS = AS_none,
2289  Decl **OwnedType = nullptr,
2290  ParsedAttributes *Attrs = nullptr);
2291 
2292 private:
2293  void ParseBlockId(SourceLocation CaretLoc);
2294 
2295  /// Are [[]] attributes enabled?
2296  bool standardAttributesAllowed() const {
2297  const LangOptions &LO = getLangOpts();
2298  return LO.DoubleSquareBracketAttributes;
2299  }
2300 
2301  // Check for the start of an attribute-specifier-seq in a context where an
2302  // attribute is not allowed.
2303  bool CheckProhibitedCXX11Attribute() {
2304  assert(Tok.is(tok::l_square));
2305  if (!standardAttributesAllowed() || NextToken().isNot(tok::l_square))
2306  return false;
2307  return DiagnoseProhibitedCXX11Attribute();
2308  }
2309 
2310  bool DiagnoseProhibitedCXX11Attribute();
2311  void CheckMisplacedCXX11Attribute(ParsedAttributesWithRange &Attrs,
2312  SourceLocation CorrectLocation) {
2313  if (!standardAttributesAllowed())
2314  return;
2315  if ((Tok.isNot(tok::l_square) || NextToken().isNot(tok::l_square)) &&
2316  Tok.isNot(tok::kw_alignas))
2317  return;
2318  DiagnoseMisplacedCXX11Attribute(Attrs, CorrectLocation);
2319  }
2320  void DiagnoseMisplacedCXX11Attribute(ParsedAttributesWithRange &Attrs,
2321  SourceLocation CorrectLocation);
2322 
2323  void stripTypeAttributesOffDeclSpec(ParsedAttributesWithRange &Attrs,
2324  DeclSpec &DS, Sema::TagUseKind TUK);
2325 
2326  // FixItLoc = possible correct location for the attributes
2327  void ProhibitAttributes(ParsedAttributesWithRange &Attrs,
2328  SourceLocation FixItLoc = SourceLocation()) {
2329  if (Attrs.Range.isInvalid())
2330  return;
2331  DiagnoseProhibitedAttributes(Attrs.Range, FixItLoc);
2332  Attrs.clear();
2333  }
2334 
2335  void ProhibitAttributes(ParsedAttributesViewWithRange &Attrs,
2336  SourceLocation FixItLoc = SourceLocation()) {
2337  if (Attrs.Range.isInvalid())
2338  return;
2339  DiagnoseProhibitedAttributes(Attrs.Range, FixItLoc);
2340  Attrs.clearListOnly();
2341  }
2342  void DiagnoseProhibitedAttributes(const SourceRange &Range,
2343  SourceLocation FixItLoc);
2344 
2345  // Forbid C++11 and C2x attributes that appear on certain syntactic locations
2346  // which standard permits but we don't supported yet, for example, attributes
2347  // appertain to decl specifiers.
2348  void ProhibitCXX11Attributes(ParsedAttributesWithRange &Attrs,
2349  unsigned DiagID);
2350 
2351  /// Skip C++11 and C2x attributes and return the end location of the
2352  /// last one.
2353  /// \returns SourceLocation() if there are no attributes.
2354  SourceLocation SkipCXX11Attributes();
2355 
2356  /// Diagnose and skip C++11 and C2x attributes that appear in syntactic
2357  /// locations where attributes are not allowed.
2358  void DiagnoseAndSkipCXX11Attributes();
2359 
2360  /// Parses syntax-generic attribute arguments for attributes which are
2361  /// known to the implementation, and adds them to the given ParsedAttributes
2362  /// list with the given attribute syntax. Returns the number of arguments
2363  /// parsed for the attribute.
2364  unsigned
2365  ParseAttributeArgsCommon(IdentifierInfo *AttrName, SourceLocation AttrNameLoc,
2366  ParsedAttributes &Attrs, SourceLocation *EndLoc,
2367  IdentifierInfo *ScopeName, SourceLocation ScopeLoc,
2368  ParsedAttr::Syntax Syntax);
2369 
2370  void MaybeParseGNUAttributes(Declarator &D,
2371  LateParsedAttrList *LateAttrs = nullptr) {
2372  if (Tok.is(tok::kw___attribute)) {
2373  ParsedAttributes attrs(AttrFactory);
2374  SourceLocation endLoc;
2375  ParseGNUAttributes(attrs, &endLoc, LateAttrs, &D);
2376  D.takeAttributes(attrs, endLoc);
2377  }
2378  }
2379  void MaybeParseGNUAttributes(ParsedAttributes &attrs,
2380  SourceLocation *endLoc = nullptr,
2381  LateParsedAttrList *LateAttrs = nullptr) {
2382  if (Tok.is(tok::kw___attribute))
2383  ParseGNUAttributes(attrs, endLoc, LateAttrs);
2384  }
2385  void ParseGNUAttributes(ParsedAttributes &attrs,
2386  SourceLocation *endLoc = nullptr,
2387  LateParsedAttrList *LateAttrs = nullptr,
2388  Declarator *D = nullptr);
2389  void ParseGNUAttributeArgs(IdentifierInfo *AttrName,
2390  SourceLocation AttrNameLoc,
2391  ParsedAttributes &Attrs, SourceLocation *EndLoc,
2392  IdentifierInfo *ScopeName, SourceLocation ScopeLoc,
2393  ParsedAttr::Syntax Syntax, Declarator *D);
2394  IdentifierLoc *ParseIdentifierLoc();
2395 
2396  unsigned
2397  ParseClangAttributeArgs(IdentifierInfo *AttrName, SourceLocation AttrNameLoc,
2398  ParsedAttributes &Attrs, SourceLocation *EndLoc,
2399  IdentifierInfo *ScopeName, SourceLocation ScopeLoc,
2400  ParsedAttr::Syntax Syntax);
2401 
2402  void MaybeParseCXX11Attributes(Declarator &D) {
2403  if (standardAttributesAllowed() && isCXX11AttributeSpecifier()) {
2404  ParsedAttributesWithRange attrs(AttrFactory);
2405  SourceLocation endLoc;
2406  ParseCXX11Attributes(attrs, &endLoc);
2407  D.takeAttributes(attrs, endLoc);
2408  }
2409  }
2410  void MaybeParseCXX11Attributes(ParsedAttributes &attrs,
2411  SourceLocation *endLoc = nullptr) {
2412  if (standardAttributesAllowed() && isCXX11AttributeSpecifier()) {
2413  ParsedAttributesWithRange attrsWithRange(AttrFactory);
2414  ParseCXX11Attributes(attrsWithRange, endLoc);
2415  attrs.takeAllFrom(attrsWithRange);
2416  }
2417  }
2418  void MaybeParseCXX11Attributes(ParsedAttributesWithRange &attrs,
2419  SourceLocation *endLoc = nullptr,
2420  bool OuterMightBeMessageSend = false) {
2421  if (standardAttributesAllowed() &&
2422  isCXX11AttributeSpecifier(false, OuterMightBeMessageSend))
2423  ParseCXX11Attributes(attrs, endLoc);
2424  }
2425 
2426  void ParseCXX11AttributeSpecifier(ParsedAttributes &attrs,
2427  SourceLocation *EndLoc = nullptr);
2428  void ParseCXX11Attributes(ParsedAttributesWithRange &attrs,
2429  SourceLocation *EndLoc = nullptr);
2430  /// Parses a C++11 (or C2x)-style attribute argument list. Returns true
2431  /// if this results in adding an attribute to the ParsedAttributes list.
2432  bool ParseCXX11AttributeArgs(IdentifierInfo *AttrName,
2433  SourceLocation AttrNameLoc,
2434  ParsedAttributes &Attrs, SourceLocation *EndLoc,
2435  IdentifierInfo *ScopeName,
2436  SourceLocation ScopeLoc);
2437 
2438  IdentifierInfo *TryParseCXX11AttributeIdentifier(SourceLocation &Loc);
2439 
2440  void MaybeParseMicrosoftAttributes(ParsedAttributes &attrs,
2441  SourceLocation *endLoc = nullptr) {
2442  if (getLangOpts().MicrosoftExt && Tok.is(tok::l_square))
2443  ParseMicrosoftAttributes(attrs, endLoc);
2444  }
2445  void ParseMicrosoftUuidAttributeArgs(ParsedAttributes &Attrs);
2446  void ParseMicrosoftAttributes(ParsedAttributes &attrs,
2447  SourceLocation *endLoc = nullptr);
2448  void MaybeParseMicrosoftDeclSpecs(ParsedAttributes &Attrs,
2449  SourceLocation *End = nullptr) {
2450  const auto &LO = getLangOpts();
2451  if (LO.DeclSpecKeyword && Tok.is(tok::kw___declspec))
2452  ParseMicrosoftDeclSpecs(Attrs, End);
2453  }
2454  void ParseMicrosoftDeclSpecs(ParsedAttributes &Attrs,
2455  SourceLocation *End = nullptr);
2456  bool ParseMicrosoftDeclSpecArgs(IdentifierInfo *AttrName,
2457  SourceLocation AttrNameLoc,
2458  ParsedAttributes &Attrs);
2459  void ParseMicrosoftTypeAttributes(ParsedAttributes &attrs);
2460  void DiagnoseAndSkipExtendedMicrosoftTypeAttributes();
2461  SourceLocation SkipExtendedMicrosoftTypeAttributes();
2462  void ParseMicrosoftInheritanceClassAttributes(ParsedAttributes &attrs);
2463  void ParseBorlandTypeAttributes(ParsedAttributes &attrs);
2464  void ParseOpenCLKernelAttributes(ParsedAttributes &attrs);
2465  void ParseOpenCLQualifiers(ParsedAttributes &Attrs);
2466  /// Parses opencl_unroll_hint attribute if language is OpenCL v2.0
2467  /// or higher.
2468  /// \return false if error happens.
2469  bool MaybeParseOpenCLUnrollHintAttribute(ParsedAttributes &Attrs) {
2470  if (getLangOpts().OpenCL)
2471  return ParseOpenCLUnrollHintAttribute(Attrs);
2472  return true;
2473  }
2474  /// Parses opencl_unroll_hint attribute.
2475  /// \return false if error happens.
2476  bool ParseOpenCLUnrollHintAttribute(ParsedAttributes &Attrs);
2477  void ParseNullabilityTypeSpecifiers(ParsedAttributes &attrs);
2478 
2479  VersionTuple ParseVersionTuple(SourceRange &Range);
2480  void ParseAvailabilityAttribute(IdentifierInfo &Availability,
2481  SourceLocation AvailabilityLoc,
2482  ParsedAttributes &attrs,
2483  SourceLocation *endLoc,
2484  IdentifierInfo *ScopeName,
2485  SourceLocation ScopeLoc,
2486  ParsedAttr::Syntax Syntax);
2487 
2488  Optional<AvailabilitySpec> ParseAvailabilitySpec();
2489  ExprResult ParseAvailabilityCheckExpr(SourceLocation StartLoc);
2490 
2491  void ParseExternalSourceSymbolAttribute(IdentifierInfo &ExternalSourceSymbol,
2492  SourceLocation Loc,
2493  ParsedAttributes &Attrs,
2494  SourceLocation *EndLoc,
2495  IdentifierInfo *ScopeName,
2496  SourceLocation ScopeLoc,
2497  ParsedAttr::Syntax Syntax);
2498 
2499  void ParseObjCBridgeRelatedAttribute(IdentifierInfo &ObjCBridgeRelated,
2500  SourceLocation ObjCBridgeRelatedLoc,
2501  ParsedAttributes &attrs,
2502  SourceLocation *endLoc,
2503  IdentifierInfo *ScopeName,
2504  SourceLocation ScopeLoc,
2505  ParsedAttr::Syntax Syntax);
2506 
2507  void ParseTypeTagForDatatypeAttribute(IdentifierInfo &AttrName,
2508  SourceLocation AttrNameLoc,
2509  ParsedAttributes &Attrs,
2510  SourceLocation *EndLoc,
2511  IdentifierInfo *ScopeName,
2512  SourceLocation ScopeLoc,
2513  ParsedAttr::Syntax Syntax);
2514 
2515  void
2516  ParseAttributeWithTypeArg(IdentifierInfo &AttrName,
2517  SourceLocation AttrNameLoc, ParsedAttributes &Attrs,
2518  SourceLocation *EndLoc, IdentifierInfo *ScopeName,
2519  SourceLocation ScopeLoc, ParsedAttr::Syntax Syntax);
2520 
2521  void ParseTypeofSpecifier(DeclSpec &DS);
2522  SourceLocation ParseDecltypeSpecifier(DeclSpec &DS);
2523  void AnnotateExistingDecltypeSpecifier(const DeclSpec &DS,
2524  SourceLocation StartLoc,
2525  SourceLocation EndLoc);
2526  void ParseUnderlyingTypeSpecifier(DeclSpec &DS);
2527  void ParseAtomicSpecifier(DeclSpec &DS);
2528 
2529  ExprResult ParseAlignArgument(SourceLocation Start,
2530  SourceLocation &EllipsisLoc);
2531  void ParseAlignmentSpecifier(ParsedAttributes &Attrs,
2532  SourceLocation *endLoc = nullptr);
2533 
2534  VirtSpecifiers::Specifier isCXX11VirtSpecifier(const Token &Tok) const;
2535  VirtSpecifiers::Specifier isCXX11VirtSpecifier() const {
2536  return isCXX11VirtSpecifier(Tok);
2537  }
2538  void ParseOptionalCXX11VirtSpecifierSeq(VirtSpecifiers &VS, bool IsInterface,
2539  SourceLocation FriendLoc);
2540 
2541  bool isCXX11FinalKeyword() const;
2542 
2543  /// DeclaratorScopeObj - RAII object used in Parser::ParseDirectDeclarator to
2544  /// enter a new C++ declarator scope and exit it when the function is
2545  /// finished.
2546  class DeclaratorScopeObj {
2547  Parser &P;
2548  CXXScopeSpec &SS;
2549  bool EnteredScope;
2550  bool CreatedScope;
2551  public:
2552  DeclaratorScopeObj(Parser &p, CXXScopeSpec &ss)
2553  : P(p), SS(ss), EnteredScope(false), CreatedScope(false) {}
2554 
2555  void EnterDeclaratorScope() {
2556  assert(!EnteredScope && "Already entered the scope!");
2557  assert(SS.isSet() && "C++ scope was not set!");
2558 
2559  CreatedScope = true;
2560  P.EnterScope(0); // Not a decl scope.
2561 
2562  if (!P.Actions.ActOnCXXEnterDeclaratorScope(P.getCurScope(), SS))
2563  EnteredScope = true;
2564  }
2565 
2566  ~DeclaratorScopeObj() {
2567  if (EnteredScope) {
2568  assert(SS.isSet() && "C++ scope was cleared ?");
2569  P.Actions.ActOnCXXExitDeclaratorScope(P.getCurScope(), SS);
2570  }
2571  if (CreatedScope)
2572  P.ExitScope();
2573  }
2574  };
2575 
2576  /// ParseDeclarator - Parse and verify a newly-initialized declarator.
2577  void ParseDeclarator(Declarator &D);
2578  /// A function that parses a variant of direct-declarator.
2579  typedef void (Parser::*DirectDeclParseFunction)(Declarator&);
2580  void ParseDeclaratorInternal(Declarator &D,
2581  DirectDeclParseFunction DirectDeclParser);
2582 
2583  enum AttrRequirements {
2584  AR_NoAttributesParsed = 0, ///< No attributes are diagnosed.
2585  AR_GNUAttributesParsedAndRejected = 1 << 0, ///< Diagnose GNU attributes.
2586  AR_GNUAttributesParsed = 1 << 1,
2587  AR_CXX11AttributesParsed = 1 << 2,
2588  AR_DeclspecAttributesParsed = 1 << 3,
2589  AR_AllAttributesParsed = AR_GNUAttributesParsed |
2590  AR_CXX11AttributesParsed |
2591  AR_DeclspecAttributesParsed,
2592  AR_VendorAttributesParsed = AR_GNUAttributesParsed |
2593  AR_DeclspecAttributesParsed
2594  };
2595 
2596  void ParseTypeQualifierListOpt(
2597  DeclSpec &DS, unsigned AttrReqs = AR_AllAttributesParsed,
2598  bool AtomicAllowed = true, bool IdentifierRequired = false,
2599  Optional<llvm::function_ref<void()>> CodeCompletionHandler = None);
2600  void ParseDirectDeclarator(Declarator &D);
2601  void ParseDecompositionDeclarator(Declarator &D);
2602  void ParseParenDeclarator(Declarator &D);
2603  void ParseFunctionDeclarator(Declarator &D,
2604  ParsedAttributes &attrs,
2605  BalancedDelimiterTracker &Tracker,
2606  bool IsAmbiguous,
2607  bool RequiresArg = false);
2608  bool ParseRefQualifier(bool &RefQualifierIsLValueRef,
2609  SourceLocation &RefQualifierLoc);
2610  bool isFunctionDeclaratorIdentifierList();
2611  void ParseFunctionDeclaratorIdentifierList(
2612  Declarator &D,
2614  void ParseParameterDeclarationClause(
2615  Declarator &D,
2616  ParsedAttributes &attrs,
2618  SourceLocation &EllipsisLoc);
2619  void ParseBracketDeclarator(Declarator &D);
2620  void ParseMisplacedBracketDeclarator(Declarator &D);
2621 
2622  //===--------------------------------------------------------------------===//
2623  // C++ 7: Declarations [dcl.dcl]
2624 
2625  /// The kind of attribute specifier we have found.
2626  enum CXX11AttributeKind {
2627  /// This is not an attribute specifier.
2628  CAK_NotAttributeSpecifier,
2629  /// This should be treated as an attribute-specifier.
2630  CAK_AttributeSpecifier,
2631  /// The next tokens are '[[', but this is not an attribute-specifier. This
2632  /// is ill-formed by C++11 [dcl.attr.grammar]p6.
2633  CAK_InvalidAttributeSpecifier
2634  };
2635  CXX11AttributeKind
2636  isCXX11AttributeSpecifier(bool Disambiguate = false,
2637  bool OuterMightBeMessageSend = false);
2638 
2639  void DiagnoseUnexpectedNamespace(NamedDecl *Context);
2640 
2641  DeclGroupPtrTy ParseNamespace(DeclaratorContext Context,
2642  SourceLocation &DeclEnd,
2643  SourceLocation InlineLoc = SourceLocation());
2644  void ParseInnerNamespace(std::vector<SourceLocation> &IdentLoc,
2645  std::vector<IdentifierInfo *> &Ident,
2646  std::vector<SourceLocation> &NamespaceLoc,
2647  unsigned int index, SourceLocation &InlineLoc,
2648  ParsedAttributes &attrs,
2649  BalancedDelimiterTracker &Tracker);
2650  Decl *ParseLinkage(ParsingDeclSpec &DS, DeclaratorContext Context);
2651  Decl *ParseExportDeclaration();
2652  DeclGroupPtrTy ParseUsingDirectiveOrDeclaration(
2653  DeclaratorContext Context, const ParsedTemplateInfo &TemplateInfo,
2654  SourceLocation &DeclEnd, ParsedAttributesWithRange &attrs);
2655  Decl *ParseUsingDirective(DeclaratorContext Context,
2656  SourceLocation UsingLoc,
2657  SourceLocation &DeclEnd,
2658  ParsedAttributes &attrs);
2659 
2660  struct UsingDeclarator {
2661  SourceLocation TypenameLoc;
2662  CXXScopeSpec SS;
2663  UnqualifiedId Name;
2664  SourceLocation EllipsisLoc;
2665 
2666  void clear() {
2667  TypenameLoc = EllipsisLoc = SourceLocation();
2668  SS.clear();
2669  Name.clear();
2670  }
2671  };
2672 
2673  bool ParseUsingDeclarator(DeclaratorContext Context, UsingDeclarator &D);
2674  DeclGroupPtrTy ParseUsingDeclaration(DeclaratorContext Context,
2675  const ParsedTemplateInfo &TemplateInfo,
2676  SourceLocation UsingLoc,
2677  SourceLocation &DeclEnd,
2678  AccessSpecifier AS = AS_none);
2679  Decl *ParseAliasDeclarationAfterDeclarator(
2680  const ParsedTemplateInfo &TemplateInfo, SourceLocation UsingLoc,
2681  UsingDeclarator &D, SourceLocation &DeclEnd, AccessSpecifier AS,
2682  ParsedAttributes &Attrs, Decl **OwnedType = nullptr);
2683 
2684  Decl *ParseStaticAssertDeclaration(SourceLocation &DeclEnd);
2685  Decl *ParseNamespaceAlias(SourceLocation NamespaceLoc,
2686  SourceLocation AliasLoc, IdentifierInfo *Alias,
2687  SourceLocation &DeclEnd);
2688 
2689  //===--------------------------------------------------------------------===//
2690  // C++ 9: classes [class] and C structs/unions.
2691  bool isValidAfterTypeSpecifier(bool CouldBeBitfield);
2692  void ParseClassSpecifier(tok::TokenKind TagTokKind, SourceLocation TagLoc,
2693  DeclSpec &DS, const ParsedTemplateInfo &TemplateInfo,
2694  AccessSpecifier AS, bool EnteringContext,
2695  DeclSpecContext DSC,
2696  ParsedAttributesWithRange &Attributes);
2697  void SkipCXXMemberSpecification(SourceLocation StartLoc,
2698  SourceLocation AttrFixitLoc,
2699  unsigned TagType,
2700  Decl *TagDecl);
2701  void ParseCXXMemberSpecification(SourceLocation StartLoc,
2702  SourceLocation AttrFixitLoc,
2703  ParsedAttributesWithRange &Attrs,
2704  unsigned TagType,
2705  Decl *TagDecl);
2706  ExprResult ParseCXXMemberInitializer(Decl *D, bool IsFunction,
2707  SourceLocation &EqualLoc);
2708  bool ParseCXXMemberDeclaratorBeforeInitializer(Declarator &DeclaratorInfo,
2709  VirtSpecifiers &VS,
2710  ExprResult &BitfieldSize,
2711  LateParsedAttrList &LateAttrs);
2712  void MaybeParseAndDiagnoseDeclSpecAfterCXX11VirtSpecifierSeq(Declarator &D,
2713  VirtSpecifiers &VS);
2714  DeclGroupPtrTy ParseCXXClassMemberDeclaration(
2716  const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo(),
2717  ParsingDeclRAIIObject *DiagsFromTParams = nullptr);
2718  DeclGroupPtrTy ParseCXXClassMemberDeclarationWithPragmas(
2719  AccessSpecifier &AS, ParsedAttributesWithRange &AccessAttrs,
2720  DeclSpec::TST TagType, Decl *Tag);
2721  void ParseConstructorInitializer(Decl *ConstructorDecl);
2722  MemInitResult ParseMemInitializer(Decl *ConstructorDecl);
2723  void HandleMemberFunctionDeclDelays(Declarator& DeclaratorInfo,
2724  Decl *ThisDecl);
2725 
2726  //===--------------------------------------------------------------------===//
2727  // C++ 10: Derived classes [class.derived]
2728  TypeResult ParseBaseTypeSpecifier(SourceLocation &BaseLoc,
2729  SourceLocation &EndLocation);
2730  void ParseBaseClause(Decl *ClassDecl);
2731  BaseResult ParseBaseSpecifier(Decl *ClassDecl);
2732  AccessSpecifier getAccessSpecifierIfPresent() const;
2733 
2734  bool ParseUnqualifiedIdTemplateId(CXXScopeSpec &SS,
2735  SourceLocation TemplateKWLoc,
2736  IdentifierInfo *Name,
2737  SourceLocation NameLoc,
2738  bool EnteringContext,
2739  ParsedType ObjectType,
2740  UnqualifiedId &Id,
2741  bool AssumeTemplateId);
2742  bool ParseUnqualifiedIdOperator(CXXScopeSpec &SS, bool EnteringContext,
2743  ParsedType ObjectType,
2745 
2746  //===--------------------------------------------------------------------===//
2747  // OpenMP: Directives and clauses.
2748  /// Parse clauses for '#pragma omp declare simd'.
2749  DeclGroupPtrTy ParseOMPDeclareSimdClauses(DeclGroupPtrTy Ptr,
2750  CachedTokens &Toks,
2751  SourceLocation Loc);
2752  /// Parses declarative OpenMP directives.
2753  DeclGroupPtrTy ParseOpenMPDeclarativeDirectiveWithExtDecl(
2754  AccessSpecifier &AS, ParsedAttributesWithRange &Attrs,
2756  Decl *TagDecl = nullptr);
2757  /// Parse 'omp declare reduction' construct.
2758  DeclGroupPtrTy ParseOpenMPDeclareReductionDirective(AccessSpecifier AS);
2759  /// Parses initializer for provided omp_priv declaration inside the reduction
2760  /// initializer.
2761  void ParseOpenMPReductionInitializerForDecl(VarDecl *OmpPrivParm);
2762 
2763  /// Parses simple list of variables.
2764  ///
2765  /// \param Kind Kind of the directive.
2766  /// \param Callback Callback function to be called for the list elements.
2767  /// \param AllowScopeSpecifier true, if the variables can have fully
2768  /// qualified names.
2769  ///
2770  bool ParseOpenMPSimpleVarList(
2771  OpenMPDirectiveKind Kind,
2772  const llvm::function_ref<void(CXXScopeSpec &, DeclarationNameInfo)> &
2773  Callback,
2774  bool AllowScopeSpecifier);
2775  /// Parses declarative or executable directive.
2776  ///
2777  /// \param Allowed ACK_Any, if any directives are allowed,
2778  /// ACK_StatementsOpenMPAnyExecutable - if any executable directives are
2779  /// allowed, ACK_StatementsOpenMPNonStandalone - if only non-standalone
2780  /// executable directives are allowed.
2781  ///
2782  StmtResult
2783  ParseOpenMPDeclarativeOrExecutableDirective(AllowedConstructsKind Allowed);
2784  /// Parses clause of kind \a CKind for directive of a kind \a Kind.
2785  ///
2786  /// \param DKind Kind of current directive.
2787  /// \param CKind Kind of current clause.
2788  /// \param FirstClause true, if this is the first clause of a kind \a CKind
2789  /// in current directive.
2790  ///
2791  OMPClause *ParseOpenMPClause(OpenMPDirectiveKind DKind,
2792  OpenMPClauseKind CKind, bool FirstClause);
2793  /// Parses clause with a single expression of a kind \a Kind.
2794  ///
2795  /// \param Kind Kind of current clause.
2796  /// \param ParseOnly true to skip the clause's semantic actions and return
2797  /// nullptr.
2798  ///
2799  OMPClause *ParseOpenMPSingleExprClause(OpenMPClauseKind Kind,
2800  bool ParseOnly);
2801  /// Parses simple clause of a kind \a Kind.
2802  ///
2803  /// \param Kind Kind of current clause.
2804  /// \param ParseOnly true to skip the clause's semantic actions and return
2805  /// nullptr.
2806  ///
2807  OMPClause *ParseOpenMPSimpleClause(OpenMPClauseKind Kind, bool ParseOnly);
2808  /// Parses clause with a single expression and an additional argument
2809  /// of a kind \a Kind.
2810  ///
2811  /// \param Kind Kind of current clause.
2812  /// \param ParseOnly true to skip the clause's semantic actions and return
2813  /// nullptr.
2814  ///
2815  OMPClause *ParseOpenMPSingleExprWithArgClause(OpenMPClauseKind Kind,
2816  bool ParseOnly);
2817  /// Parses clause without any additional arguments.
2818  ///
2819  /// \param Kind Kind of current clause.
2820  /// \param ParseOnly true to skip the clause's semantic actions and return
2821  /// nullptr.
2822  ///
2823  OMPClause *ParseOpenMPClause(OpenMPClauseKind Kind, bool ParseOnly = false);
2824  /// Parses clause with the list of variables of a kind \a Kind.
2825  ///
2826  /// \param Kind Kind of current clause.
2827  /// \param ParseOnly true to skip the clause's semantic actions and return
2828  /// nullptr.
2829  ///
2830  OMPClause *ParseOpenMPVarListClause(OpenMPDirectiveKind DKind,
2831  OpenMPClauseKind Kind, bool ParseOnly);
2832 
2833 public:
2834  /// Parses simple expression in parens for single-expression clauses of OpenMP
2835  /// constructs.
2836  /// \param RLoc Returned location of right paren.
2837  ExprResult ParseOpenMPParensExpr(StringRef ClauseName, SourceLocation &RLoc);
2838 
2839  /// Data used for parsing list of variables in OpenMP clauses.
2841  Expr *TailExpr = nullptr;
2847  OpenMPLinearClauseKind LinKind = OMPC_LINEAR_val;
2850  bool IsMapTypeImplicit = false;
2852  };
2853 
2854  /// Parses clauses with list.
2857  OpenMPVarListDataTy &Data);
2858  bool ParseUnqualifiedId(CXXScopeSpec &SS, bool EnteringContext,
2859  bool AllowDestructorName,
2860  bool AllowConstructorName,
2861  bool AllowDeductionGuide,
2862  ParsedType ObjectType,
2863  SourceLocation *TemplateKWLoc,
2865 
2866 private:
2867  //===--------------------------------------------------------------------===//
2868  // C++ 14: Templates [temp]
2869 
2870  // C++ 14.1: Template Parameters [temp.param]
2871  Decl *ParseDeclarationStartingWithTemplate(DeclaratorContext Context,
2872  SourceLocation &DeclEnd,
2873  ParsedAttributes &AccessAttrs,
2874  AccessSpecifier AS = AS_none);
2875  Decl *ParseTemplateDeclarationOrSpecialization(DeclaratorContext Context,
2876  SourceLocation &DeclEnd,
2877  ParsedAttributes &AccessAttrs,
2878  AccessSpecifier AS);
2879  Decl *ParseSingleDeclarationAfterTemplate(
2880  DeclaratorContext Context, const ParsedTemplateInfo &TemplateInfo,
2881  ParsingDeclRAIIObject &DiagsFromParams, SourceLocation &DeclEnd,
2882  ParsedAttributes &AccessAttrs, AccessSpecifier AS = AS_none);
2883  bool ParseTemplateParameters(unsigned Depth,
2884  SmallVectorImpl<NamedDecl *> &TemplateParams,
2885  SourceLocation &LAngleLoc,
2886  SourceLocation &RAngleLoc);
2887  bool ParseTemplateParameterList(unsigned Depth,
2888  SmallVectorImpl<NamedDecl*> &TemplateParams);
2889  bool isStartOfTemplateTypeParameter();
2890  NamedDecl *ParseTemplateParameter(unsigned Depth, unsigned Position);
2891  NamedDecl *ParseTypeParameter(unsigned Depth, unsigned Position);
2892  NamedDecl *ParseTemplateTemplateParameter(unsigned Depth, unsigned Position);
2893  NamedDecl *ParseNonTypeTemplateParameter(unsigned Depth, unsigned Position);
2894  void DiagnoseMisplacedEllipsis(SourceLocation EllipsisLoc,
2895  SourceLocation CorrectLoc,
2896  bool AlreadyHasEllipsis,
2897  bool IdentifierHasName);
2898  void DiagnoseMisplacedEllipsisInDeclarator(SourceLocation EllipsisLoc,
2899  Declarator &D);
2900  // C++ 14.3: Template arguments [temp.arg]
2902 
2903  bool ParseGreaterThanInTemplateList(SourceLocation &RAngleLoc,
2904  bool ConsumeLastToken,
2905  bool ObjCGenericList);
2906  bool ParseTemplateIdAfterTemplateName(bool ConsumeLastToken,
2907  SourceLocation &LAngleLoc,
2908  TemplateArgList &TemplateArgs,
2909  SourceLocation &RAngleLoc);
2910 
2911  bool AnnotateTemplateIdToken(TemplateTy Template, TemplateNameKind TNK,
2912  CXXScopeSpec &SS,
2913  SourceLocation TemplateKWLoc,
2915  bool AllowTypeAnnotation = true);
2916  void AnnotateTemplateIdTokenAsType(bool IsClassName = false);
2917  bool IsTemplateArgumentList(unsigned Skip = 0);
2918  bool ParseTemplateArgumentList(TemplateArgList &TemplateArgs);
2919  ParsedTemplateArgument ParseTemplateTemplateArgument();
2920  ParsedTemplateArgument ParseTemplateArgument();
2921  Decl *ParseExplicitInstantiation(DeclaratorContext Context,
2922  SourceLocation ExternLoc,
2923  SourceLocation TemplateLoc,
2924  SourceLocation &DeclEnd,
2925  ParsedAttributes &AccessAttrs,
2926  AccessSpecifier AS = AS_none);
2927 
2928  //===--------------------------------------------------------------------===//
2929  // Modules
2930  DeclGroupPtrTy ParseModuleDecl();
2931  Decl *ParseModuleImport(SourceLocation AtLoc);
2932  bool parseMisplacedModuleImport();
2933  bool tryParseMisplacedModuleImport() {
2934  tok::TokenKind Kind = Tok.getKind();
2935  if (Kind == tok::annot_module_begin || Kind == tok::annot_module_end ||
2936  Kind == tok::annot_module_include)
2937  return parseMisplacedModuleImport();
2938  return false;
2939  }
2940 
2941  bool ParseModuleName(
2942  SourceLocation UseLoc,
2943  SmallVectorImpl<std::pair<IdentifierInfo *, SourceLocation>> &Path,
2944  bool IsImport);
2945 
2946  //===--------------------------------------------------------------------===//
2947  // C++11/G++: Type Traits [Type-Traits.html in the GCC manual]
2948  ExprResult ParseTypeTrait();
2949 
2950  //===--------------------------------------------------------------------===//
2951  // Embarcadero: Arary and Expression Traits
2952  ExprResult ParseArrayTypeTrait();
2953  ExprResult ParseExpressionTrait();
2954 
2955  //===--------------------------------------------------------------------===//
2956  // Preprocessor code-completion pass-through
2957  void CodeCompleteDirective(bool InConditional) override;
2958  void CodeCompleteInConditionalExclusion() override;
2959  void CodeCompleteMacroName(bool IsDefinition) override;
2960  void CodeCompletePreprocessorExpression() override;
2961  void CodeCompleteMacroArgument(IdentifierInfo *Macro, MacroInfo *MacroInfo,
2962  unsigned ArgumentIndex) override;
2963  void CodeCompleteNaturalLanguage() override;
2964 };
2965 
2966 } // end namespace clang
2967 
2968 #endif
Sema::FullExprArg FullExprArg
Definition: Parser.h:382
IdentifierInfo * getNullabilityKeyword(NullabilityKind nullability)
Retrieve the underscored keyword (_Nonnull, _Nullable) that corresponds to the given nullability kind...
Definition: Parser.h:458
ExprResult ParseExpression(TypeCastState isTypeCast=NotTypeCast)
Simple precedence-based parser for binary/ternary operators.
Definition: ParseExpr.cpp:123
ParseScope - Introduces a new scope for parsing.
Definition: Parser.h:947
DeclarationNameInfo ReductionId
Definition: Parser.h:2845
SourceLocation getEndOfPreviousToken()
Definition: Parser.h:452
void Initialize()
Initialize - Warm up the parser.
Definition: Parser.cpp:438
IdentifierInfo * getIdentifierInfo(StringRef Name) const
Return information about the specified preprocessor identifier token.
Class to handle popping type parameters when leaving the scope.
Definition: ParseObjc.cpp:98
const Token & LookAhead(unsigned N)
Peeks ahead N tokens and returns that token without consuming any tokens.
NullabilityKind
Describes the nullability of a particular type.
Definition: Specifiers.h:285
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
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:86
RAII object used to inform the actions that we&#39;re currently parsing a declaration.
Captures information about "declaration specifiers" specific to Objective-C.
Definition: DeclSpec.h:783
StringRef P
bool TryAnnotateCXXScopeToken(bool EnteringContext=false)
TryAnnotateScopeToken - Like TryAnnotateTypeOrScopeToken but only annotates C++ scope specifiers and ...
Definition: Parser.cpp:1872
virtual void clear()
AccessSpecifier
A C++ access specifier (public, private, protected), plus the special value "none" which means differ...
Definition: Specifiers.h:98
Wrapper for void* pointer.
Definition: Ownership.h:51
Parser - This implements a parser for the C family of languages.
Definition: Parser.h:57
TypeCastState
TypeCastState - State whether an expression is or may be a type cast.
Definition: Parser.h:1573
void setCodeCompletionReached()
Note that we hit the code-completion point.
void ActOnObjCReenterContainerContext(DeclContext *DC)
Definition: SemaDecl.cpp:14896
void EnterToken(const Token &Tok)
Enters a token in the token stream to be lexed next.
Represents a variable declaration or definition.
Definition: Decl.h:820
Information about one declarator, including the parsed type information and the identifier.
Definition: DeclSpec.h:1764
bool isStringLiteral(TokenKind K)
Return true if this is a C or C++ string-literal (or C++11 user-defined-string-literal) token...
Definition: TokenKinds.h:79
TypeSpecifierType
Specifies the kind of type.
Definition: Specifiers.h:45
void ActOnObjCTemporaryExitContainerContext(DeclContext *DC)
Invoked when we must temporarily exit the objective-c container scope for parsing/looking-up C constr...
Definition: SemaDecl.cpp:14890
void ActOnCXXExitDeclaratorScope(Scope *S, const CXXScopeSpec &SS)
ActOnCXXExitDeclaratorScope - Called when a declarator that previously invoked ActOnCXXEnterDeclarato...
RAII object that makes sure paren/bracket/brace count is correct after declaration/statement parsing...
bool isAnnotation() const
Return true if this is any of tok::annot_* kind tokens.
Definition: Token.h:118
friend class ObjCDeclContextSwitch
Definition: Parser.h:61
ColonProtectionRAIIObject - This sets the Parser::ColonIsSacred bool and restores it when destroyed...
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:1041
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:709
SourceLocation getLocForEndOfToken(SourceLocation Loc, unsigned Offset=0)
Computes the source location just past the end of the token at this source location.
bool TryConsumeToken(tok::TokenKind Expected)
Definition: Parser.h:414
One of these records is kept for each identifier that is lexed.
SourceLocation getAnnotationEndLoc() const
Definition: Token.h:138
LineState State
OpenMPLinearClauseKind
OpenMP attributes for &#39;linear&#39; clause.
Definition: OpenMPKinds.h:84
const TargetInfo & getTargetInfo() const
Definition: Preprocessor.h:825
Token - This structure provides full information about a lexed token.
Definition: Token.h:35
void setKind(tok::TokenKind K)
Definition: Token.h:91
RAII class that helps handle the parsing of an open/close delimiter pair, such as braces { ...
Defines some OpenMP-specific enums and functions.
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Definition: LangOptions.h:50
const LangOptions & getLangOpts() const
Definition: Preprocessor.h:824
void * getAsOpaquePtr() const
Definition: Ownership.h:91
Represents a C++ unqualified-id that has been parsed.
Definition: DeclSpec.h:928
friend constexpr SkipUntilFlags operator|(SkipUntilFlags L, SkipUntilFlags R)
Definition: Parser.h:1027
static ParsedType getTypeAnnotation(const Token &Tok)
getTypeAnnotation - Read a parsed type out of an annotation token.
Definition: Parser.h:714
const FormatToken & Tok
bool TryConsumeToken(tok::TokenKind Expected, SourceLocation &Loc)
Definition: Parser.h:424
Decl * getObjCDeclContext() const
Definition: SemaDecl.cpp:17163
Concrete class used by the front-end to report problems and issues.
Definition: Diagnostic.h:149
void incrementMSManglingNumber() const
Definition: Sema.h:10621
void takeAllFrom(ParsedAttributes &attrs)
Definition: ParsedAttr.h:857
bool SkipUntil(tok::TokenKind T1, tok::TokenKind T2, SkipUntilFlags Flags=static_cast< SkipUntilFlags >(0))
Definition: Parser.h:1045
void CommitBacktrackedTokens()
Disable the last EnableBacktrackAtThisPos call.
Definition: PPCaching.cpp:32
Scope - A scope is a transient data structure that is used while parsing the program.
Definition: Scope.h:40
Represents a C++ nested-name-specifier or a global scope specifier.
Definition: DeclSpec.h:63
CastExpr - Base class for type casts, including both implicit casts (ImplicitCastExpr) and explicit c...
Definition: Expr.h:2935
SourceLocation ConsumeAnyToken(bool ConsumeCodeCompletionTok=false)
ConsumeAnyToken - Dispatch to the right Consume* method based on the current token type...
Definition: Parser.h:434
AttributeFactory & getAttrFactory()
Definition: Parser.h:365
bool isActiveOrNested(Parser &P) const
Definition: Parser.h:291
void incrementMSManglingNumber() const
Definition: Parser.h:369
Sema - This implements semantic analysis and AST building for C.
Definition: Sema.h:277
A little helper class used to produce diagnostics.
Definition: Diagnostic.h:1042
CompoundStmt - This represents a group of statements like { stmt stmt }.
Definition: Stmt.h:637
A class for parsing a declarator.
Stop at code completion.
Definition: Parser.h:1024
void Backtrack()
Make Preprocessor re-lex the tokens that were lexed since EnableBacktrackAtThisPos() was previously c...
Definition: PPCaching.cpp:63
Scope * getCurScope() const
Retrieve the parser&#39;s current scope.
Definition: Sema.h:10619
Exposes information about the current target.
Definition: TargetInfo.h:54
void setAnnotationValue(void *val)
Definition: Token.h:228
bool isCodeCompletionEnabled() const
Determine if we are performing code completion.
Expr - This represents one expression.
Definition: Expr.h:106
SourceLocation End
int Id
Definition: ASTDiff.cpp:191
void EnableBacktrackAtThisPos()
From the point that this method is called, and until CommitBacktrackedTokens() or Backtrack() is call...
Definition: PPCaching.cpp:26
This file defines the classes used to store parsed information about declaration-specifiers and decla...
Sema & getActions() const
Definition: Parser.h:364
void SkipMalformedDecl()
SkipMalformedDecl - Read tokens until we get to some likely good stopping point for skipping past a s...
Definition: ParseDecl.cpp:1825
bool ParseUnqualifiedId(CXXScopeSpec &SS, bool EnteringContext, bool AllowDestructorName, bool AllowConstructorName, bool AllowDeductionGuide, ParsedType ObjectType, SourceLocation *TemplateKWLoc, UnqualifiedId &Result)
Parse a C++ unqualified-id (or a C identifier), which describes the name of an entity.
const Token & getCurToken() const
Definition: Parser.h:367
OpaquePtr< TemplateName > TemplateTy
Definition: Parser.h:378
void clear()
Clear out this unqualified-id, setting it to default (invalid) state.
Definition: DeclSpec.h:996
SourceLocation getLocation() const
Return a source location identifier for the specified offset in the current file. ...
Definition: Token.h:124
Defines the clang::Preprocessor interface.
OpenMPClauseKind
OpenMP clauses.
Definition: OpenMPKinds.h:33
Represents a C++ template name within the type system.
Definition: TemplateName.h:178
int Depth
Definition: ASTDiff.cpp:191
A class for parsing a field declarator.
TemplateNameKind
Specifies the kind of template name that an identifier refers to.
Definition: TemplateKinds.h:21
Provides LLVM&#39;s BitmaskEnum facility to enumeration types declared in namespace clang.
Preprocessor & getPreprocessor() const
Definition: Parser.h:363
DeclaratorContext
Definition: DeclSpec.h:1722
Defines and computes precedence levels for binary/ternary operators.
ConditionKind
Definition: Sema.h:9825
Wraps an identifier and optional source location for the identifier.
Definition: ParsedAttr.h:95
The result type of a method or function.
ObjCKeywordKind
Provides a namespace for Objective-C keywords which start with an &#39;@&#39;.
Definition: TokenKinds.h:41
OpaquePtr< DeclGroupRef > DeclGroupPtrTy
Definition: Parser.h:377
const LangOptions & getLangOpts() const
Definition: Parser.h:361
A class for parsing a DeclSpec.
#define false
Definition: stdbool.h:33
Kind
Stop skipping at semicolon.
Definition: Parser.h:1021
ActionResult - This structure is used while parsing/acting on expressions, stmts, etc...
Definition: Ownership.h:157
Represents the parsed form of a C++ template argument.
bool ParseTopLevelDecl()
Definition: Parser.h:396
Encodes a location in the source.
OpenMPDependClauseKind
OpenMP attributes for &#39;depend&#39; clause.
Definition: OpenMPKinds.h:76
bool TryAnnotateTypeOrScopeToken()
TryAnnotateTypeOrScopeToken - If the current token position is on a typename (possibly qualified in C...
Definition: Parser.cpp:1651
DiagnosticBuilder Diag(unsigned DiagID)
Definition: Parser.h:1008
bool ParseOpenMPVarList(OpenMPDirectiveKind DKind, OpenMPClauseKind Kind, SmallVectorImpl< Expr *> &Vars, OpenMPVarListDataTy &Data)
Parses clauses with list.
Syntax
The style used to specify an attribute.
Definition: ParsedAttr.h:140
Represents the declaration of a struct/union/class/enum.
Definition: Decl.h:3043
void ExitScope()
ExitScope - Pop a scope off the scope stack.
Definition: Parser.cpp:370
IdentifierInfo * getIdentifierInfo() const
Definition: Token.h:177
Parser(Preprocessor &PP, Sema &Actions, bool SkipFunctionBodies)
Definition: Parser.cpp:51
OpenMPDirectiveKind
OpenMP directives.
Definition: OpenMPKinds.h:23
ExprResult ParseMSAsmIdentifier(llvm::SmallVectorImpl< Token > &LineToks, unsigned &NumLineToksConsumed, bool IsUnevaluated)
Parse an identifier in an MS-style inline assembly block.
A tentative parsing action that can also revert token annotations.
void Lex(Token &Result)
Lex the next token for this preprocessor.
void EnterScope(unsigned ScopeFlags)
EnterScope - Start a new scope.
Definition: Parser.cpp:359
This is a basic class for representing single OpenMP clause.
Definition: OpenMPClause.h:51
TokenKind
Provides a simple uniform namespace for tokens from all C languages.
Definition: TokenKinds.h:25
Represents a C++11 virt-specifier-seq.
Definition: DeclSpec.h:2506
Scope * getCurScope() const
Definition: Parser.h:368
ExprResult ParseOpenMPParensExpr(StringRef ClauseName, SourceLocation &RLoc)
Parses simple expression in parens for single-expression clauses of OpenMP constructs.
ExprResult ParseConstantExpressionInExprEvalContext(TypeCastState isTypeCast=NotTypeCast)
Definition: ParseExpr.cpp:200
Defines various enumerations that describe declaration and type specifiers.
void takeAttributes(ParsedAttributes &attrs, SourceLocation lastLoc)
takeAttributes - Takes attributes from the given parsed-attributes set and add them to this declarato...
Definition: DeclSpec.h:2409
bool isNot(tok::TokenKind K) const
Definition: Token.h:96
ParseScope(Parser *Self, unsigned ScopeFlags, bool EnteredScope=true, bool BeforeCompoundStmt=false)
Definition: Parser.h:956
bool isActive(Parser &P) const
Definition: Parser.h:286
static bool isInvalid(LocType Loc, bool *Invalid)
Dataflow Directional Tag Classes.
SourceRange getSourceRange(const SourceRange &Range)
Returns the SourceRange of a SourceRange.
Definition: FixIt.h:34
ExprResult ParseCaseExpression(SourceLocation CaseLoc)
Definition: ParseExpr.cpp:220
ExprResult ParseConstraintExpression()
Parse a constraint-expression.
Definition: ParseExpr.cpp:234
bool isOneOf(tok::TokenKind K1, tok::TokenKind K2) const
Definition: Token.h:97
SkipUntilFlags
Control flags for SkipUntil functions.
Definition: Parser.h:1020
Data used for parsing list of variables in OpenMP clauses.
Definition: Parser.h:2840
DeclarationNameInfo - A collector data type for bundling together a DeclarationName and the correspnd...
static const TST TST_unspecified
Definition: DeclSpec.h:272
Encapsulates the data about a macro definition (e.g.
Definition: MacroInfo.h:40
const TargetInfo & getTargetInfo() const
Definition: Parser.h:362
~Parser() override
Definition: Parser.cpp:409
DiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID)
Definition: Parser.cpp:73
ExprResult ParseAssignmentExpression(TypeCastState isTypeCast=NotTypeCast)
Parse an expr that doesn&#39;t include (top-level) commas.
Definition: ParseExpr.cpp:160
ExceptionSpecificationType
The various types of exception specifications that exist in C++11.
SmallVector< TemplateParameterList *, 4 > TemplateParameterLists
Definition: Parser.h:380
bool ActOnCXXEnterDeclaratorScope(Scope *S, CXXScopeSpec &SS)
ActOnCXXEnterDeclaratorScope - Called when a C++ scope specifier (global scope or nested-name-specifi...
bool isSet() const
Deprecated.
Definition: DeclSpec.h:209
ExprResult ParseConstantExpression(TypeCastState isTypeCast=NotTypeCast)
Definition: ParseExpr.cpp:210
Captures information about "declaration specifiers".
Definition: DeclSpec.h:228
ActionResult< Expr * > ExprResult
Definition: Ownership.h:267
SourceLocation ConsumeToken()
ConsumeToken - Consume the current &#39;peek token&#39; and lex the next one.
Definition: Parser.h:406
A factory, from which one makes pools, from which one creates individual attributes which are dealloc...
Definition: ParsedAttr.h:574
OpenMPMapClauseKind
OpenMP mapping kind for &#39;map&#39; clause.
Definition: OpenMPKinds.h:92
llvm::DenseMap< int, SourceRange > ParsedSubjectMatchRuleSet
Stores a list of Objective-C type parameters for a parameterized class or a category/extension thereo...
Definition: DeclObjC.h:634
Decl * getObjCDeclContext() const
Definition: Parser.h:373
IdentifierInfo * getNullabilityKeyword(NullabilityKind nullability)
Retrieve the keyword associated.
Definition: SemaType.cpp:3406
Represents a complete lambda introducer.
Definition: DeclSpec.h:2556
bool TryAnnotateTypeOrScopeTokenAfterScopeSpec(CXXScopeSpec &SS, bool IsNewScope)
Try to annotate a type or scope token, having already parsed an optional scope specifier.
Definition: Parser.cpp:1765
bool SkipUntil(tok::TokenKind T1, tok::TokenKind T2, tok::TokenKind T3, SkipUntilFlags Flags=static_cast< SkipUntilFlags >(0))
Definition: Parser.h:1050
Contains a late templated function.
Definition: Sema.h:10789
Loop optimization hint for loop and unroll pragmas.
Definition: LoopHint.h:21
AngleBracketTracker::Priority Priority
Definition: Parser.h:283
A trivial tuple used to represent a source range.
This represents a decl that may have a name.
Definition: Decl.h:248
Callback handler that receives notifications when performing code completion within the preprocessor...
void * getAnnotationValue() const
Definition: Token.h:224
static OpaquePtr getFromOpaquePtr(void *P)
Definition: Ownership.h:92
ParsedAttributes - A collection of parsed attributes.
Definition: ParsedAttr.h:850
SourceLocation ColonLoc
Location of &#39;:&#39;.
Definition: OpenMPClause.h:102
TypeResult ParseTypeName(SourceRange *Range=nullptr, DeclaratorContext Context=DeclaratorContext::TypeNameContext, AccessSpecifier AS=AS_none, Decl **OwnedType=nullptr, ParsedAttributes *Attrs=nullptr)
ParseTypeName type-name: [C99 6.7.6] specifier-qualifier-list abstract-declarator[opt].
Definition: ParseDecl.cpp:44
Attr - This represents one attribute.
Definition: Attr.h:43
bool ParseFirstTopLevelDecl(DeclGroupPtrTy &Result)
Parse the first top-level declaration in a translation unit.
Definition: Parser.cpp:529
Engages in a tight little dance with the lexer to efficiently preprocess tokens.
Definition: Preprocessor.h:127
Stop skipping at specified token, but don&#39;t skip the token itself.
Definition: Parser.h:1023