Coverage Report

Created: 2018-07-19 20:53

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