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