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