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