File indexing completed on 2026-05-10 08:36:58
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013 #ifndef LLVM_CLANG_PARSE_PARSER_H
0014 #define LLVM_CLANG_PARSE_PARSER_H
0015
0016 #include "clang/Basic/OpenACCKinds.h"
0017 #include "clang/Basic/OperatorPrecedence.h"
0018 #include "clang/Lex/CodeCompletionHandler.h"
0019 #include "clang/Lex/Preprocessor.h"
0020 #include "clang/Sema/Sema.h"
0021 #include "clang/Sema/SemaCodeCompletion.h"
0022 #include "clang/Sema/SemaObjC.h"
0023 #include "clang/Sema/SemaOpenMP.h"
0024 #include "llvm/ADT/SmallVector.h"
0025 #include "llvm/Frontend/OpenMP/OMPContext.h"
0026 #include "llvm/Support/SaveAndRestore.h"
0027 #include <optional>
0028 #include <stack>
0029
0030 namespace clang {
0031 class PragmaHandler;
0032 class Scope;
0033 class BalancedDelimiterTracker;
0034 class CorrectionCandidateCallback;
0035 class DeclGroupRef;
0036 class DiagnosticBuilder;
0037 struct LoopHint;
0038 class Parser;
0039 class ParsingDeclRAIIObject;
0040 class ParsingDeclSpec;
0041 class ParsingDeclarator;
0042 class ParsingFieldDeclarator;
0043 class ColonProtectionRAIIObject;
0044 class InMessageExpressionRAIIObject;
0045 class PoisonSEHIdentifiersRAIIObject;
0046 class OMPClause;
0047 class OpenACCClause;
0048 class ObjCTypeParamList;
0049 struct OMPTraitProperty;
0050 struct OMPTraitSelector;
0051 struct OMPTraitSet;
0052 class OMPTraitInfo;
0053
0054
0055
0056
0057
0058 class Parser : public CodeCompletionHandler {
0059 friend class ColonProtectionRAIIObject;
0060 friend class ParsingOpenMPDirectiveRAII;
0061 friend class ParsingOpenACCDirectiveRAII;
0062 friend class InMessageExpressionRAIIObject;
0063 friend class OffsetOfStateRAIIObject;
0064 friend class PoisonSEHIdentifiersRAIIObject;
0065 friend class ObjCDeclContextSwitch;
0066 friend class ParenBraceBracketBalancer;
0067 friend class BalancedDelimiterTracker;
0068
0069 Preprocessor &PP;
0070
0071
0072
0073 Token Tok;
0074
0075
0076
0077
0078
0079 SourceLocation PrevTokLocation;
0080
0081
0082
0083 PreferredTypeBuilder PreferredType;
0084
0085 unsigned short ParenCount = 0, BracketCount = 0, BraceCount = 0;
0086 unsigned short MisplacedModuleBeginCount = 0;
0087
0088
0089
0090 Sema &Actions;
0091
0092 DiagnosticsEngine &Diags;
0093
0094
0095 enum { ScopeCacheSize = 16 };
0096 unsigned NumCachedScopes;
0097 Scope *ScopeCache[ScopeCacheSize];
0098
0099
0100
0101
0102 IdentifierInfo *Ident__exception_code,
0103 *Ident___exception_code,
0104 *Ident_GetExceptionCode;
0105
0106 IdentifierInfo *Ident__exception_info,
0107 *Ident___exception_info,
0108 *Ident_GetExceptionInfo;
0109
0110 IdentifierInfo *Ident__abnormal_termination,
0111 *Ident___abnormal_termination,
0112 *Ident_AbnormalTermination;
0113
0114
0115 IdentifierInfo *Ident__except;
0116 mutable IdentifierInfo *Ident_sealed;
0117 mutable IdentifierInfo *Ident_abstract;
0118
0119
0120
0121 IdentifierInfo *Ident_super;
0122
0123
0124
0125 IdentifierInfo *Ident_vector;
0126 IdentifierInfo *Ident_bool;
0127 IdentifierInfo *Ident_Bool;
0128
0129
0130 IdentifierInfo *Ident_pixel;
0131
0132
0133 IdentifierInfo *Ident_instancetype;
0134
0135
0136 IdentifierInfo *Ident_introduced;
0137
0138
0139 IdentifierInfo *Ident_deprecated;
0140
0141
0142 IdentifierInfo *Ident_obsoleted;
0143
0144
0145 IdentifierInfo *Ident_unavailable;
0146
0147
0148 IdentifierInfo *Ident_message;
0149
0150
0151 IdentifierInfo *Ident_strict;
0152
0153
0154 IdentifierInfo *Ident_replacement;
0155
0156
0157 IdentifierInfo *Ident_environment;
0158
0159
0160 IdentifierInfo *Ident_language, *Ident_defined_in,
0161 *Ident_generated_declaration, *Ident_USR;
0162
0163
0164 mutable IdentifierInfo *Ident_final;
0165 mutable IdentifierInfo *Ident_GNU_final;
0166 mutable IdentifierInfo *Ident_override;
0167
0168
0169 mutable IdentifierInfo *Ident_import;
0170 mutable IdentifierInfo *Ident_module;
0171
0172
0173
0174 llvm::SmallDenseMap<IdentifierInfo *, tok::TokenKind> RevertibleTypeTraits;
0175
0176 std::unique_ptr<PragmaHandler> AlignHandler;
0177 std::unique_ptr<PragmaHandler> GCCVisibilityHandler;
0178 std::unique_ptr<PragmaHandler> OptionsHandler;
0179 std::unique_ptr<PragmaHandler> PackHandler;
0180 std::unique_ptr<PragmaHandler> MSStructHandler;
0181 std::unique_ptr<PragmaHandler> UnusedHandler;
0182 std::unique_ptr<PragmaHandler> WeakHandler;
0183 std::unique_ptr<PragmaHandler> RedefineExtnameHandler;
0184 std::unique_ptr<PragmaHandler> FPContractHandler;
0185 std::unique_ptr<PragmaHandler> OpenCLExtensionHandler;
0186 std::unique_ptr<PragmaHandler> OpenMPHandler;
0187 std::unique_ptr<PragmaHandler> OpenACCHandler;
0188 std::unique_ptr<PragmaHandler> PCSectionHandler;
0189 std::unique_ptr<PragmaHandler> MSCommentHandler;
0190 std::unique_ptr<PragmaHandler> MSDetectMismatchHandler;
0191 std::unique_ptr<PragmaHandler> FPEvalMethodHandler;
0192 std::unique_ptr<PragmaHandler> FloatControlHandler;
0193 std::unique_ptr<PragmaHandler> MSPointersToMembers;
0194 std::unique_ptr<PragmaHandler> MSVtorDisp;
0195 std::unique_ptr<PragmaHandler> MSInitSeg;
0196 std::unique_ptr<PragmaHandler> MSDataSeg;
0197 std::unique_ptr<PragmaHandler> MSBSSSeg;
0198 std::unique_ptr<PragmaHandler> MSConstSeg;
0199 std::unique_ptr<PragmaHandler> MSCodeSeg;
0200 std::unique_ptr<PragmaHandler> MSSection;
0201 std::unique_ptr<PragmaHandler> MSStrictGuardStackCheck;
0202 std::unique_ptr<PragmaHandler> MSRuntimeChecks;
0203 std::unique_ptr<PragmaHandler> MSIntrinsic;
0204 std::unique_ptr<PragmaHandler> MSFunction;
0205 std::unique_ptr<PragmaHandler> MSOptimize;
0206 std::unique_ptr<PragmaHandler> MSFenvAccess;
0207 std::unique_ptr<PragmaHandler> MSAllocText;
0208 std::unique_ptr<PragmaHandler> CUDAForceHostDeviceHandler;
0209 std::unique_ptr<PragmaHandler> OptimizeHandler;
0210 std::unique_ptr<PragmaHandler> LoopHintHandler;
0211 std::unique_ptr<PragmaHandler> UnrollHintHandler;
0212 std::unique_ptr<PragmaHandler> NoUnrollHintHandler;
0213 std::unique_ptr<PragmaHandler> UnrollAndJamHintHandler;
0214 std::unique_ptr<PragmaHandler> NoUnrollAndJamHintHandler;
0215 std::unique_ptr<PragmaHandler> FPHandler;
0216 std::unique_ptr<PragmaHandler> STDCFenvAccessHandler;
0217 std::unique_ptr<PragmaHandler> STDCFenvRoundHandler;
0218 std::unique_ptr<PragmaHandler> STDCCXLIMITHandler;
0219 std::unique_ptr<PragmaHandler> STDCUnknownHandler;
0220 std::unique_ptr<PragmaHandler> AttributePragmaHandler;
0221 std::unique_ptr<PragmaHandler> MaxTokensHerePragmaHandler;
0222 std::unique_ptr<PragmaHandler> MaxTokensTotalPragmaHandler;
0223 std::unique_ptr<PragmaHandler> RISCVPragmaHandler;
0224
0225 std::unique_ptr<CommentHandler> CommentSemaHandler;
0226
0227
0228
0229
0230
0231 bool GreaterThanIsOperator;
0232
0233
0234
0235
0236
0237 bool ColonIsSacred;
0238
0239
0240 bool OpenMPDirectiveParsing = false;
0241
0242
0243 bool OpenACCDirectiveParsing = false;
0244
0245
0246
0247 bool AllowOpenACCArraySections = false;
0248
0249
0250
0251 class OpenACCArraySectionRAII {
0252 Parser &P;
0253
0254 public:
0255 OpenACCArraySectionRAII(Parser &P) : P(P) {
0256 assert(!P.AllowOpenACCArraySections);
0257 P.AllowOpenACCArraySections = true;
0258 }
0259 ~OpenACCArraySectionRAII() {
0260 assert(P.AllowOpenACCArraySections);
0261 P.AllowOpenACCArraySections = false;
0262 }
0263 };
0264
0265
0266
0267
0268
0269
0270 bool InMessageExpression;
0271
0272
0273
0274
0275 bool CalledSignatureHelp = false;
0276
0277 Sema::OffsetOfKind OffsetOfState = Sema::OffsetOfKind::OOK_Outside;
0278
0279
0280 unsigned TemplateParameterDepth;
0281
0282
0283 OpenMPClauseKind OMPClauseKind = llvm::omp::OMPC_unknown;
0284
0285
0286 class TemplateParameterDepthRAII {
0287 unsigned &Depth;
0288 unsigned AddedLevels;
0289 public:
0290 explicit TemplateParameterDepthRAII(unsigned &Depth)
0291 : Depth(Depth), AddedLevels(0) {}
0292
0293 ~TemplateParameterDepthRAII() {
0294 Depth -= AddedLevels;
0295 }
0296
0297 void operator++() {
0298 ++Depth;
0299 ++AddedLevels;
0300 }
0301 void addDepth(unsigned D) {
0302 Depth += D;
0303 AddedLevels += D;
0304 }
0305 void setAddedDepth(unsigned D) {
0306 Depth = Depth - AddedLevels + D;
0307 AddedLevels = D;
0308 }
0309
0310 unsigned getDepth() const { return Depth; }
0311 unsigned getOriginalDepth() const { return Depth - AddedLevels; }
0312 };
0313
0314
0315 AttributeFactory AttrFactory;
0316
0317
0318
0319 SmallVector<TemplateIdAnnotation *, 16> TemplateIds;
0320
0321
0322
0323
0324
0325 bool DelayTemplateIdDestruction = false;
0326
0327 void MaybeDestroyTemplateIds() {
0328 if (DelayTemplateIdDestruction)
0329 return;
0330 if (!TemplateIds.empty() &&
0331 (Tok.is(tok::eof) || !PP.mightHavePendingAnnotationTokens()))
0332 DestroyTemplateIds();
0333 }
0334 void DestroyTemplateIds();
0335
0336
0337
0338 struct DestroyTemplateIdAnnotationsRAIIObj {
0339 Parser &Self;
0340
0341 DestroyTemplateIdAnnotationsRAIIObj(Parser &Self) : Self(Self) {}
0342 ~DestroyTemplateIdAnnotationsRAIIObj() { Self.MaybeDestroyTemplateIds(); }
0343 };
0344
0345 struct DelayTemplateIdDestructionRAII {
0346 Parser &Self;
0347 bool PrevDelayTemplateIdDestruction;
0348
0349 DelayTemplateIdDestructionRAII(Parser &Self,
0350 bool DelayTemplateIdDestruction) noexcept
0351 : Self(Self),
0352 PrevDelayTemplateIdDestruction(Self.DelayTemplateIdDestruction) {
0353 Self.DelayTemplateIdDestruction = DelayTemplateIdDestruction;
0354 }
0355
0356 ~DelayTemplateIdDestructionRAII() noexcept {
0357 Self.DelayTemplateIdDestruction = PrevDelayTemplateIdDestruction;
0358 }
0359 };
0360
0361
0362 SmallVector<const IdentifierInfo *, 8> TentativelyDeclaredIdentifiers;
0363
0364
0365
0366
0367
0368
0369
0370
0371
0372
0373
0374 struct AngleBracketTracker {
0375
0376
0377 enum Priority : unsigned short {
0378
0379 PotentialTypo = 0x0,
0380
0381 DependentName = 0x2,
0382
0383
0384 SpaceBeforeLess = 0x0,
0385
0386 NoSpaceBeforeLess = 0x1,
0387
0388 LLVM_MARK_AS_BITMASK_ENUM( DependentName)
0389 };
0390
0391 struct Loc {
0392 Expr *TemplateName;
0393 SourceLocation LessLoc;
0394 AngleBracketTracker::Priority Priority;
0395 unsigned short ParenCount, BracketCount, BraceCount;
0396
0397 bool isActive(Parser &P) const {
0398 return P.ParenCount == ParenCount && P.BracketCount == BracketCount &&
0399 P.BraceCount == BraceCount;
0400 }
0401
0402 bool isActiveOrNested(Parser &P) const {
0403 return isActive(P) || P.ParenCount > ParenCount ||
0404 P.BracketCount > BracketCount || P.BraceCount > BraceCount;
0405 }
0406 };
0407
0408 SmallVector<Loc, 8> Locs;
0409
0410
0411
0412
0413
0414
0415 void add(Parser &P, Expr *TemplateName, SourceLocation LessLoc,
0416 Priority Prio) {
0417 if (!Locs.empty() && Locs.back().isActive(P)) {
0418 if (Locs.back().Priority <= Prio) {
0419 Locs.back().TemplateName = TemplateName;
0420 Locs.back().LessLoc = LessLoc;
0421 Locs.back().Priority = Prio;
0422 }
0423 } else {
0424 Locs.push_back({TemplateName, LessLoc, Prio,
0425 P.ParenCount, P.BracketCount, P.BraceCount});
0426 }
0427 }
0428
0429
0430
0431
0432 void clear(Parser &P) {
0433 while (!Locs.empty() && Locs.back().isActiveOrNested(P))
0434 Locs.pop_back();
0435 }
0436
0437
0438
0439 Loc *getCurrent(Parser &P) {
0440 if (!Locs.empty() && Locs.back().isActive(P))
0441 return &Locs.back();
0442 return nullptr;
0443 }
0444 };
0445
0446 AngleBracketTracker AngleBrackets;
0447
0448 IdentifierInfo *getSEHExceptKeyword();
0449
0450
0451
0452
0453
0454
0455 bool ParsingInObjCContainer;
0456
0457
0458
0459
0460
0461 bool SkipFunctionBodies;
0462
0463
0464
0465
0466 SourceLocation ExprStatementTokLoc;
0467
0468
0469 enum class ParsedStmtContext {
0470
0471
0472 AllowDeclarationsInC = 0x1,
0473
0474 AllowStandaloneOpenMPDirectives = 0x2,
0475
0476 InStmtExpr = 0x4,
0477
0478
0479 SubStmt = 0,
0480
0481 Compound = AllowDeclarationsInC | AllowStandaloneOpenMPDirectives,
0482
0483 LLVM_MARK_AS_BITMASK_ENUM(InStmtExpr)
0484 };
0485
0486
0487
0488
0489 StmtResult handleExprStmt(ExprResult E, ParsedStmtContext StmtCtx);
0490
0491 public:
0492 Parser(Preprocessor &PP, Sema &Actions, bool SkipFunctionBodies);
0493 ~Parser() override;
0494
0495 const LangOptions &getLangOpts() const { return PP.getLangOpts(); }
0496 const TargetInfo &getTargetInfo() const { return PP.getTargetInfo(); }
0497 Preprocessor &getPreprocessor() const { return PP; }
0498 Sema &getActions() const { return Actions; }
0499 AttributeFactory &getAttrFactory() { return AttrFactory; }
0500
0501 const Token &getCurToken() const { return Tok; }
0502 Scope *getCurScope() const { return Actions.getCurScope(); }
0503 void incrementMSManglingNumber() const {
0504 return Actions.incrementMSManglingNumber();
0505 }
0506
0507 ObjCContainerDecl *getObjCDeclContext() const {
0508 return Actions.ObjC().getObjCDeclContext();
0509 }
0510
0511
0512
0513 typedef OpaquePtr<DeclGroupRef> DeclGroupPtrTy;
0514 typedef OpaquePtr<TemplateName> TemplateTy;
0515
0516 typedef SmallVector<TemplateParameterList *, 4> TemplateParameterLists;
0517
0518 typedef Sema::FullExprArg FullExprArg;
0519
0520
0521 typedef SmallVector<Stmt *, 32> StmtVector;
0522
0523
0524
0525
0526
0527 void Initialize();
0528
0529
0530 bool ParseFirstTopLevelDecl(DeclGroupPtrTy &Result,
0531 Sema::ModuleImportState &ImportState);
0532
0533
0534
0535 bool ParseTopLevelDecl(DeclGroupPtrTy &Result,
0536 Sema::ModuleImportState &ImportState);
0537 bool ParseTopLevelDecl() {
0538 DeclGroupPtrTy Result;
0539 Sema::ModuleImportState IS = Sema::ModuleImportState::NotACXX20Module;
0540 return ParseTopLevelDecl(Result, IS);
0541 }
0542
0543
0544
0545
0546
0547
0548 SourceLocation ConsumeToken() {
0549 assert(!isTokenSpecial() &&
0550 "Should consume special tokens with Consume*Token");
0551 PrevTokLocation = Tok.getLocation();
0552 PP.Lex(Tok);
0553 return PrevTokLocation;
0554 }
0555
0556 bool TryConsumeToken(tok::TokenKind Expected) {
0557 if (Tok.isNot(Expected))
0558 return false;
0559 assert(!isTokenSpecial() &&
0560 "Should consume special tokens with Consume*Token");
0561 PrevTokLocation = Tok.getLocation();
0562 PP.Lex(Tok);
0563 return true;
0564 }
0565
0566 bool TryConsumeToken(tok::TokenKind Expected, SourceLocation &Loc) {
0567 if (!TryConsumeToken(Expected))
0568 return false;
0569 Loc = PrevTokLocation;
0570 return true;
0571 }
0572
0573
0574
0575
0576 SourceLocation ConsumeAnyToken(bool ConsumeCodeCompletionTok = false) {
0577 if (isTokenParen())
0578 return ConsumeParen();
0579 if (isTokenBracket())
0580 return ConsumeBracket();
0581 if (isTokenBrace())
0582 return ConsumeBrace();
0583 if (isTokenStringLiteral())
0584 return ConsumeStringToken();
0585 if (Tok.is(tok::code_completion))
0586 return ConsumeCodeCompletionTok ? ConsumeCodeCompletionToken()
0587 : handleUnexpectedCodeCompletionToken();
0588 if (Tok.isAnnotation())
0589 return ConsumeAnnotationToken();
0590 return ConsumeToken();
0591 }
0592
0593
0594 SourceLocation getEndOfPreviousToken() {
0595 return PP.getLocForEndOfToken(PrevTokLocation);
0596 }
0597
0598
0599
0600 IdentifierInfo *getNullabilityKeyword(NullabilityKind nullability) {
0601 return Actions.getNullabilityKeyword(nullability);
0602 }
0603
0604 private:
0605
0606
0607
0608
0609
0610 bool isTokenParen() const {
0611 return Tok.isOneOf(tok::l_paren, tok::r_paren);
0612 }
0613
0614 bool isTokenBracket() const {
0615 return Tok.isOneOf(tok::l_square, tok::r_square);
0616 }
0617
0618 bool isTokenBrace() const {
0619 return Tok.isOneOf(tok::l_brace, tok::r_brace);
0620 }
0621
0622 bool isTokenStringLiteral() const {
0623 return tok::isStringLiteral(Tok.getKind());
0624 }
0625
0626 bool isTokenSpecial() const {
0627 return isTokenStringLiteral() || isTokenParen() || isTokenBracket() ||
0628 isTokenBrace() || Tok.is(tok::code_completion) || Tok.isAnnotation();
0629 }
0630
0631
0632
0633 bool isTokenEqualOrEqualTypo();
0634
0635
0636
0637 void UnconsumeToken(Token &Consumed) {
0638 Token Next = Tok;
0639 PP.EnterToken(Consumed, true);
0640 PP.Lex(Tok);
0641 PP.EnterToken(Next, true);
0642 }
0643
0644 SourceLocation ConsumeAnnotationToken() {
0645 assert(Tok.isAnnotation() && "wrong consume method");
0646 SourceLocation Loc = Tok.getLocation();
0647 PrevTokLocation = Tok.getAnnotationEndLoc();
0648 PP.Lex(Tok);
0649 return Loc;
0650 }
0651
0652
0653
0654 SourceLocation ConsumeParen() {
0655 assert(isTokenParen() && "wrong consume method");
0656 if (Tok.getKind() == tok::l_paren)
0657 ++ParenCount;
0658 else if (ParenCount) {
0659 AngleBrackets.clear(*this);
0660 --ParenCount;
0661 }
0662 PrevTokLocation = Tok.getLocation();
0663 PP.Lex(Tok);
0664 return PrevTokLocation;
0665 }
0666
0667
0668
0669 SourceLocation ConsumeBracket() {
0670 assert(isTokenBracket() && "wrong consume method");
0671 if (Tok.getKind() == tok::l_square)
0672 ++BracketCount;
0673 else if (BracketCount) {
0674 AngleBrackets.clear(*this);
0675 --BracketCount;
0676 }
0677
0678 PrevTokLocation = Tok.getLocation();
0679 PP.Lex(Tok);
0680 return PrevTokLocation;
0681 }
0682
0683
0684
0685 SourceLocation ConsumeBrace() {
0686 assert(isTokenBrace() && "wrong consume method");
0687 if (Tok.getKind() == tok::l_brace)
0688 ++BraceCount;
0689 else if (BraceCount) {
0690 AngleBrackets.clear(*this);
0691 --BraceCount;
0692 }
0693
0694 PrevTokLocation = Tok.getLocation();
0695 PP.Lex(Tok);
0696 return PrevTokLocation;
0697 }
0698
0699
0700
0701
0702
0703 SourceLocation ConsumeStringToken() {
0704 assert(isTokenStringLiteral() &&
0705 "Should only consume string literals with this method");
0706 PrevTokLocation = Tok.getLocation();
0707 PP.Lex(Tok);
0708 return PrevTokLocation;
0709 }
0710
0711
0712
0713
0714
0715
0716 SourceLocation ConsumeCodeCompletionToken() {
0717 assert(Tok.is(tok::code_completion));
0718 PrevTokLocation = Tok.getLocation();
0719 PP.Lex(Tok);
0720 return PrevTokLocation;
0721 }
0722
0723
0724
0725
0726
0727
0728 SourceLocation handleUnexpectedCodeCompletionToken();
0729
0730
0731
0732 void cutOffParsing() {
0733 if (PP.isCodeCompletionEnabled())
0734 PP.setCodeCompletionReached();
0735
0736 Tok.setKind(tok::eof);
0737 }
0738
0739
0740
0741 bool isEofOrEom() {
0742 tok::TokenKind Kind = Tok.getKind();
0743 return Kind == tok::eof || Kind == tok::annot_module_begin ||
0744 Kind == tok::annot_module_end || Kind == tok::annot_module_include ||
0745 Kind == tok::annot_repl_input_end;
0746 }
0747
0748
0749 bool isFoldOperator(prec::Level Level) const;
0750
0751
0752 bool isFoldOperator(tok::TokenKind Kind) const;
0753
0754
0755 void initializePragmaHandlers();
0756
0757
0758 void resetPragmaHandlers();
0759
0760
0761 void HandlePragmaUnused();
0762
0763
0764
0765 void HandlePragmaVisibility();
0766
0767
0768
0769 void HandlePragmaPack();
0770
0771
0772
0773 void HandlePragmaMSStruct();
0774
0775 void HandlePragmaMSPointersToMembers();
0776
0777 void HandlePragmaMSVtorDisp();
0778
0779 void HandlePragmaMSPragma();
0780 bool HandlePragmaMSSection(StringRef PragmaName,
0781 SourceLocation PragmaLocation);
0782 bool HandlePragmaMSSegment(StringRef PragmaName,
0783 SourceLocation PragmaLocation);
0784 bool HandlePragmaMSInitSeg(StringRef PragmaName,
0785 SourceLocation PragmaLocation);
0786 bool HandlePragmaMSStrictGuardStackCheck(StringRef PragmaName,
0787 SourceLocation PragmaLocation);
0788 bool HandlePragmaMSFunction(StringRef PragmaName,
0789 SourceLocation PragmaLocation);
0790 bool HandlePragmaMSAllocText(StringRef PragmaName,
0791 SourceLocation PragmaLocation);
0792 bool HandlePragmaMSOptimize(StringRef PragmaName,
0793 SourceLocation PragmaLocation);
0794
0795
0796
0797 void HandlePragmaAlign();
0798
0799
0800
0801 void HandlePragmaDump();
0802
0803
0804
0805 void HandlePragmaWeak();
0806
0807
0808
0809 void HandlePragmaWeakAlias();
0810
0811
0812
0813 void HandlePragmaRedefineExtname();
0814
0815
0816
0817 void HandlePragmaFPContract();
0818
0819
0820
0821 void HandlePragmaFEnvAccess();
0822
0823
0824
0825 void HandlePragmaFEnvRound();
0826
0827
0828
0829 void HandlePragmaCXLimitedRange();
0830
0831
0832
0833 void HandlePragmaFloatControl();
0834
0835
0836
0837 void HandlePragmaFP();
0838
0839
0840
0841 void HandlePragmaOpenCLExtension();
0842
0843
0844
0845 StmtResult HandlePragmaCaptured();
0846
0847
0848
0849 bool HandlePragmaLoopHint(LoopHint &Hint);
0850
0851 bool ParsePragmaAttributeSubjectMatchRuleSet(
0852 attr::ParsedSubjectMatchRuleSet &SubjectMatchRules,
0853 SourceLocation &AnyLoc, SourceLocation &LastMatchRuleEndLoc);
0854
0855 void HandlePragmaAttribute();
0856
0857
0858
0859
0860
0861
0862
0863
0864 const Token &GetLookAheadToken(unsigned N) {
0865 if (N == 0 || Tok.is(tok::eof)) return Tok;
0866 return PP.LookAhead(N-1);
0867 }
0868
0869 public:
0870
0871
0872 const Token &NextToken() {
0873 return PP.LookAhead(0);
0874 }
0875
0876
0877 static TypeResult getTypeAnnotation(const Token &Tok) {
0878 if (!Tok.getAnnotationValue())
0879 return TypeError();
0880 return ParsedType::getFromOpaquePtr(Tok.getAnnotationValue());
0881 }
0882
0883 private:
0884 static void setTypeAnnotation(Token &Tok, TypeResult T) {
0885 assert((T.isInvalid() || T.get()) &&
0886 "produced a valid-but-null type annotation?");
0887 Tok.setAnnotationValue(T.isInvalid() ? nullptr : T.get().getAsOpaquePtr());
0888 }
0889
0890 static NamedDecl *getNonTypeAnnotation(const Token &Tok) {
0891 return static_cast<NamedDecl*>(Tok.getAnnotationValue());
0892 }
0893
0894 static void setNonTypeAnnotation(Token &Tok, NamedDecl *ND) {
0895 Tok.setAnnotationValue(ND);
0896 }
0897
0898 static IdentifierInfo *getIdentifierAnnotation(const Token &Tok) {
0899 return static_cast<IdentifierInfo*>(Tok.getAnnotationValue());
0900 }
0901
0902 static void setIdentifierAnnotation(Token &Tok, IdentifierInfo *ND) {
0903 Tok.setAnnotationValue(ND);
0904 }
0905
0906
0907
0908 static ExprResult getExprAnnotation(const Token &Tok) {
0909 return ExprResult::getFromOpaquePointer(Tok.getAnnotationValue());
0910 }
0911
0912
0913
0914 static void setExprAnnotation(Token &Tok, ExprResult ER) {
0915 Tok.setAnnotationValue(ER.getAsOpaquePointer());
0916 }
0917
0918 public:
0919
0920
0921 bool
0922 TryAnnotateTypeOrScopeToken(ImplicitTypenameContext AllowImplicitTypename =
0923 ImplicitTypenameContext::No);
0924 bool TryAnnotateTypeOrScopeTokenAfterScopeSpec(
0925 CXXScopeSpec &SS, bool IsNewScope,
0926 ImplicitTypenameContext AllowImplicitTypename);
0927 bool TryAnnotateCXXScopeToken(bool EnteringContext = false);
0928
0929 bool MightBeCXXScopeToken() {
0930 return getLangOpts().CPlusPlus &&
0931 (Tok.is(tok::identifier) || Tok.is(tok::coloncolon) ||
0932 (Tok.is(tok::annot_template_id) &&
0933 NextToken().is(tok::coloncolon)) ||
0934 Tok.is(tok::kw_decltype) || Tok.is(tok::kw___super));
0935 }
0936 bool TryAnnotateOptionalCXXScopeToken(bool EnteringContext = false) {
0937 return MightBeCXXScopeToken() && TryAnnotateCXXScopeToken(EnteringContext);
0938 }
0939
0940 private:
0941 enum AnnotatedNameKind {
0942
0943 ANK_Error,
0944
0945 ANK_TentativeDecl,
0946
0947 ANK_TemplateName,
0948
0949 ANK_Unresolved,
0950
0951 ANK_Success
0952 };
0953
0954 AnnotatedNameKind
0955 TryAnnotateName(CorrectionCandidateCallback *CCC = nullptr,
0956 ImplicitTypenameContext AllowImplicitTypename =
0957 ImplicitTypenameContext::No);
0958
0959
0960 void AnnotateScopeToken(CXXScopeSpec &SS, bool IsNewAnnotation);
0961
0962
0963
0964
0965 bool TryAltiVecToken(DeclSpec &DS, SourceLocation Loc,
0966 const char *&PrevSpec, unsigned &DiagID,
0967 bool &isInvalid) {
0968 if (!getLangOpts().AltiVec && !getLangOpts().ZVector)
0969 return false;
0970
0971 if (Tok.getIdentifierInfo() != Ident_vector &&
0972 Tok.getIdentifierInfo() != Ident_bool &&
0973 Tok.getIdentifierInfo() != Ident_Bool &&
0974 (!getLangOpts().AltiVec || Tok.getIdentifierInfo() != Ident_pixel))
0975 return false;
0976
0977 return TryAltiVecTokenOutOfLine(DS, Loc, PrevSpec, DiagID, isInvalid);
0978 }
0979
0980
0981
0982
0983 bool TryAltiVecVectorToken() {
0984 if ((!getLangOpts().AltiVec && !getLangOpts().ZVector) ||
0985 Tok.getIdentifierInfo() != Ident_vector) return false;
0986 return TryAltiVecVectorTokenOutOfLine();
0987 }
0988
0989 bool TryAltiVecVectorTokenOutOfLine();
0990 bool TryAltiVecTokenOutOfLine(DeclSpec &DS, SourceLocation Loc,
0991 const char *&PrevSpec, unsigned &DiagID,
0992 bool &isInvalid);
0993
0994
0995
0996
0997 bool isObjCInstancetype() {
0998 assert(getLangOpts().ObjC);
0999 if (Tok.isAnnotation())
1000 return false;
1001 if (!Ident_instancetype)
1002 Ident_instancetype = PP.getIdentifierInfo("instancetype");
1003 return Tok.getIdentifierInfo() == Ident_instancetype;
1004 }
1005
1006
1007
1008
1009
1010
1011 bool TryKeywordIdentFallback(bool DisableKeyword);
1012
1013
1014 TemplateIdAnnotation *takeTemplateIdAnnotation(const Token &tok);
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029 class TentativeParsingAction {
1030 Parser &P;
1031 PreferredTypeBuilder PrevPreferredType;
1032 Token PrevTok;
1033 size_t PrevTentativelyDeclaredIdentifierCount;
1034 unsigned short PrevParenCount, PrevBracketCount, PrevBraceCount;
1035 bool isActive;
1036
1037 public:
1038 explicit TentativeParsingAction(Parser &p, bool Unannotated = false)
1039 : P(p), PrevPreferredType(P.PreferredType) {
1040 PrevTok = P.Tok;
1041 PrevTentativelyDeclaredIdentifierCount =
1042 P.TentativelyDeclaredIdentifiers.size();
1043 PrevParenCount = P.ParenCount;
1044 PrevBracketCount = P.BracketCount;
1045 PrevBraceCount = P.BraceCount;
1046 P.PP.EnableBacktrackAtThisPos(Unannotated);
1047 isActive = true;
1048 }
1049 void Commit() {
1050 assert(isActive && "Parsing action was finished!");
1051 P.TentativelyDeclaredIdentifiers.resize(
1052 PrevTentativelyDeclaredIdentifierCount);
1053 P.PP.CommitBacktrackedTokens();
1054 isActive = false;
1055 }
1056 void Revert() {
1057 assert(isActive && "Parsing action was finished!");
1058 P.PP.Backtrack();
1059 P.PreferredType = PrevPreferredType;
1060 P.Tok = PrevTok;
1061 P.TentativelyDeclaredIdentifiers.resize(
1062 PrevTentativelyDeclaredIdentifierCount);
1063 P.ParenCount = PrevParenCount;
1064 P.BracketCount = PrevBracketCount;
1065 P.BraceCount = PrevBraceCount;
1066 isActive = false;
1067 }
1068 ~TentativeParsingAction() {
1069 assert(!isActive && "Forgot to call Commit or Revert!");
1070 }
1071 };
1072
1073
1074 class RevertingTentativeParsingAction
1075 : private Parser::TentativeParsingAction {
1076 public:
1077 using TentativeParsingAction::TentativeParsingAction;
1078
1079 ~RevertingTentativeParsingAction() { Revert(); }
1080 };
1081
1082
1083
1084
1085 class ObjCDeclContextSwitch {
1086 Parser &P;
1087 ObjCContainerDecl *DC;
1088 SaveAndRestore<bool> WithinObjCContainer;
1089 public:
1090 explicit ObjCDeclContextSwitch(Parser &p)
1091 : P(p), DC(p.getObjCDeclContext()),
1092 WithinObjCContainer(P.ParsingInObjCContainer, DC != nullptr) {
1093 if (DC)
1094 P.Actions.ObjC().ActOnObjCTemporaryExitContainerContext(DC);
1095 }
1096 ~ObjCDeclContextSwitch() {
1097 if (DC)
1098 P.Actions.ObjC().ActOnObjCReenterContainerContext(DC);
1099 }
1100 };
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110 bool ExpectAndConsume(tok::TokenKind ExpectedTok,
1111 unsigned Diag = diag::err_expected,
1112 StringRef DiagMsg = "");
1113
1114
1115
1116
1117
1118
1119 bool ExpectAndConsumeSemi(unsigned DiagID , StringRef TokenUsed = "");
1120
1121
1122 enum ExtraSemiKind {
1123 OutsideFunction = 0,
1124 InsideStruct = 1,
1125 InstanceVariableList = 2,
1126 AfterMemberFunctionDefinition = 3
1127 };
1128
1129
1130 void ConsumeExtraSemi(ExtraSemiKind Kind, DeclSpec::TST T = TST_unspecified);
1131
1132
1133
1134
1135
1136
1137
1138 bool expectIdentifier();
1139
1140
1141 enum class CompoundToken {
1142
1143 StmtExprBegin,
1144
1145 StmtExprEnd,
1146
1147 AttrBegin,
1148
1149 AttrEnd,
1150
1151 MemberPtr,
1152 };
1153
1154
1155
1156 void checkCompoundToken(SourceLocation FirstTokLoc,
1157 tok::TokenKind FirstTokKind, CompoundToken Op);
1158
1159 void diagnoseUseOfC11Keyword(const Token &Tok);
1160
1161 public:
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171 class ParseScope {
1172 Parser *Self;
1173 ParseScope(const ParseScope &) = delete;
1174 void operator=(const ParseScope &) = delete;
1175
1176 public:
1177
1178
1179
1180 ParseScope(Parser *Self, unsigned ScopeFlags, bool EnteredScope = true,
1181 bool BeforeCompoundStmt = false)
1182 : Self(Self) {
1183 if (EnteredScope && !BeforeCompoundStmt)
1184 Self->EnterScope(ScopeFlags);
1185 else {
1186 if (BeforeCompoundStmt)
1187 Self->incrementMSManglingNumber();
1188
1189 this->Self = nullptr;
1190 }
1191 }
1192
1193
1194
1195 void Exit() {
1196 if (Self) {
1197 Self->ExitScope();
1198 Self = nullptr;
1199 }
1200 }
1201
1202 ~ParseScope() {
1203 Exit();
1204 }
1205 };
1206
1207
1208
1209 class MultiParseScope {
1210 Parser &Self;
1211 unsigned NumScopes = 0;
1212
1213 MultiParseScope(const MultiParseScope&) = delete;
1214
1215 public:
1216 MultiParseScope(Parser &Self) : Self(Self) {}
1217 void Enter(unsigned ScopeFlags) {
1218 Self.EnterScope(ScopeFlags);
1219 ++NumScopes;
1220 }
1221 void Exit() {
1222 while (NumScopes) {
1223 Self.ExitScope();
1224 --NumScopes;
1225 }
1226 }
1227 ~MultiParseScope() {
1228 Exit();
1229 }
1230 };
1231
1232
1233 void EnterScope(unsigned ScopeFlags);
1234
1235
1236 void ExitScope();
1237
1238
1239 unsigned ReenterTemplateScopes(MultiParseScope &S, Decl *D);
1240
1241 private:
1242
1243 class ParseScopeFlags {
1244 Scope *CurScope;
1245 unsigned OldFlags = 0;
1246 ParseScopeFlags(const ParseScopeFlags &) = delete;
1247 void operator=(const ParseScopeFlags &) = delete;
1248
1249 public:
1250 ParseScopeFlags(Parser *Self, unsigned ScopeFlags, bool ManageFlags = true);
1251 ~ParseScopeFlags();
1252 };
1253
1254
1255
1256
1257 public:
1258 DiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID);
1259 DiagnosticBuilder Diag(const Token &Tok, unsigned DiagID);
1260 DiagnosticBuilder Diag(unsigned DiagID) {
1261 return Diag(Tok, DiagID);
1262 }
1263
1264 private:
1265 void SuggestParentheses(SourceLocation Loc, unsigned DK,
1266 SourceRange ParenRange);
1267 void CheckNestedObjCContexts(SourceLocation AtLoc);
1268
1269 public:
1270
1271
1272 enum SkipUntilFlags {
1273 StopAtSemi = 1 << 0,
1274
1275 StopBeforeMatch = 1 << 1,
1276 StopAtCodeCompletion = 1 << 2
1277 };
1278
1279 friend constexpr SkipUntilFlags operator|(SkipUntilFlags L,
1280 SkipUntilFlags R) {
1281 return static_cast<SkipUntilFlags>(static_cast<unsigned>(L) |
1282 static_cast<unsigned>(R));
1283 }
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294 bool SkipUntil(tok::TokenKind T,
1295 SkipUntilFlags Flags = static_cast<SkipUntilFlags>(0)) {
1296 return SkipUntil(llvm::ArrayRef(T), Flags);
1297 }
1298 bool SkipUntil(tok::TokenKind T1, tok::TokenKind T2,
1299 SkipUntilFlags Flags = static_cast<SkipUntilFlags>(0)) {
1300 tok::TokenKind TokArray[] = {T1, T2};
1301 return SkipUntil(TokArray, Flags);
1302 }
1303 bool SkipUntil(tok::TokenKind T1, tok::TokenKind T2, tok::TokenKind T3,
1304 SkipUntilFlags Flags = static_cast<SkipUntilFlags>(0)) {
1305 tok::TokenKind TokArray[] = {T1, T2, T3};
1306 return SkipUntil(TokArray, Flags);
1307 }
1308 bool SkipUntil(ArrayRef<tok::TokenKind> Toks,
1309 SkipUntilFlags Flags = static_cast<SkipUntilFlags>(0));
1310
1311
1312
1313 void SkipMalformedDecl();
1314
1315
1316
1317
1318 SourceLocation MisleadingIndentationElseLoc;
1319
1320 private:
1321
1322
1323
1324 struct ParsingClass;
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334 class LateParsedDeclaration {
1335 public:
1336 virtual ~LateParsedDeclaration();
1337
1338 virtual void ParseLexedMethodDeclarations();
1339 virtual void ParseLexedMemberInitializers();
1340 virtual void ParseLexedMethodDefs();
1341 virtual void ParseLexedAttributes();
1342 virtual void ParseLexedPragmas();
1343 };
1344
1345
1346
1347 class LateParsedClass : public LateParsedDeclaration {
1348 public:
1349 LateParsedClass(Parser *P, ParsingClass *C);
1350 ~LateParsedClass() override;
1351
1352 void ParseLexedMethodDeclarations() override;
1353 void ParseLexedMemberInitializers() override;
1354 void ParseLexedMethodDefs() override;
1355 void ParseLexedAttributes() override;
1356 void ParseLexedPragmas() override;
1357
1358
1359 LateParsedClass(const LateParsedClass &) = delete;
1360 LateParsedClass &operator=(const LateParsedClass &) = delete;
1361
1362 private:
1363 Parser *Self;
1364 ParsingClass *Class;
1365 };
1366
1367
1368
1369
1370
1371
1372
1373 struct LateParsedAttribute : public LateParsedDeclaration {
1374 Parser *Self;
1375 CachedTokens Toks;
1376 IdentifierInfo &AttrName;
1377 IdentifierInfo *MacroII = nullptr;
1378 SourceLocation AttrNameLoc;
1379 SmallVector<Decl*, 2> Decls;
1380
1381 explicit LateParsedAttribute(Parser *P, IdentifierInfo &Name,
1382 SourceLocation Loc)
1383 : Self(P), AttrName(Name), AttrNameLoc(Loc) {}
1384
1385 void ParseLexedAttributes() override;
1386
1387 void addDecl(Decl *D) { Decls.push_back(D); }
1388 };
1389
1390
1391
1392
1393
1394 class LateParsedPragma : public LateParsedDeclaration {
1395 Parser *Self = nullptr;
1396 AccessSpecifier AS = AS_none;
1397 CachedTokens Toks;
1398
1399 public:
1400 explicit LateParsedPragma(Parser *P, AccessSpecifier AS)
1401 : Self(P), AS(AS) {}
1402
1403 void takeToks(CachedTokens &Cached) { Toks.swap(Cached); }
1404 const CachedTokens &toks() const { return Toks; }
1405 AccessSpecifier getAccessSpecifier() const { return AS; }
1406
1407 void ParseLexedPragmas() override;
1408 };
1409
1410
1411 class LateParsedAttrList: public SmallVector<LateParsedAttribute *, 2> {
1412 public:
1413 LateParsedAttrList(bool PSoon = false,
1414 bool LateAttrParseExperimentalExtOnly = false)
1415 : ParseSoon(PSoon),
1416 LateAttrParseExperimentalExtOnly(LateAttrParseExperimentalExtOnly) {}
1417
1418 bool parseSoon() { return ParseSoon; }
1419
1420
1421 bool lateAttrParseExperimentalExtOnly() {
1422 return LateAttrParseExperimentalExtOnly;
1423 }
1424
1425 private:
1426 bool ParseSoon;
1427 bool LateAttrParseExperimentalExtOnly;
1428 };
1429
1430
1431
1432
1433 struct LexedMethod : public LateParsedDeclaration {
1434 Parser *Self;
1435 Decl *D;
1436 CachedTokens Toks;
1437
1438 explicit LexedMethod(Parser *P, Decl *MD) : Self(P), D(MD) {}
1439
1440 void ParseLexedMethodDefs() override;
1441 };
1442
1443
1444
1445
1446
1447 struct LateParsedDefaultArgument {
1448 explicit LateParsedDefaultArgument(Decl *P,
1449 std::unique_ptr<CachedTokens> Toks = nullptr)
1450 : Param(P), Toks(std::move(Toks)) { }
1451
1452
1453 Decl *Param;
1454
1455
1456
1457
1458
1459 std::unique_ptr<CachedTokens> Toks;
1460 };
1461
1462
1463
1464
1465
1466 struct LateParsedMethodDeclaration : public LateParsedDeclaration {
1467 explicit LateParsedMethodDeclaration(Parser *P, Decl *M)
1468 : Self(P), Method(M), ExceptionSpecTokens(nullptr) {}
1469
1470 void ParseLexedMethodDeclarations() override;
1471
1472 Parser *Self;
1473
1474
1475 Decl *Method;
1476
1477
1478
1479
1480
1481
1482 SmallVector<LateParsedDefaultArgument, 8> DefaultArgs;
1483
1484
1485
1486 CachedTokens *ExceptionSpecTokens;
1487 };
1488
1489
1490
1491
1492 struct LateParsedMemberInitializer : public LateParsedDeclaration {
1493 LateParsedMemberInitializer(Parser *P, Decl *FD)
1494 : Self(P), Field(FD) { }
1495
1496 void ParseLexedMemberInitializers() override;
1497
1498 Parser *Self;
1499
1500
1501 Decl *Field;
1502
1503
1504
1505 CachedTokens Toks;
1506 };
1507
1508
1509
1510
1511
1512
1513
1514 typedef SmallVector<LateParsedDeclaration*,2> LateParsedDeclarationsContainer;
1515
1516
1517
1518
1519 struct ParsingClass {
1520 ParsingClass(Decl *TagOrTemplate, bool TopLevelClass, bool IsInterface)
1521 : TopLevelClass(TopLevelClass), IsInterface(IsInterface),
1522 TagOrTemplate(TagOrTemplate) {}
1523
1524
1525
1526 bool TopLevelClass : 1;
1527
1528
1529 bool IsInterface : 1;
1530
1531
1532 Decl *TagOrTemplate;
1533
1534
1535
1536
1537 LateParsedDeclarationsContainer LateParsedDeclarations;
1538 };
1539
1540
1541
1542
1543 std::stack<ParsingClass *> ClassStack;
1544
1545 ParsingClass &getCurrentClass() {
1546 assert(!ClassStack.empty() && "No lexed method stacks!");
1547 return *ClassStack.top();
1548 }
1549
1550
1551 class ParsingClassDefinition {
1552 Parser &P;
1553 bool Popped;
1554 Sema::ParsingClassState State;
1555
1556 public:
1557 ParsingClassDefinition(Parser &P, Decl *TagOrTemplate, bool TopLevelClass,
1558 bool IsInterface)
1559 : P(P), Popped(false),
1560 State(P.PushParsingClass(TagOrTemplate, TopLevelClass, IsInterface)) {
1561 }
1562
1563
1564 void Pop() {
1565 assert(!Popped && "Nested class has already been popped");
1566 Popped = true;
1567 P.PopParsingClass(State);
1568 }
1569
1570 ~ParsingClassDefinition() {
1571 if (!Popped)
1572 P.PopParsingClass(State);
1573 }
1574 };
1575
1576
1577
1578
1579 struct ParsedTemplateInfo {
1580 ParsedTemplateInfo() : Kind(NonTemplate), TemplateParams(nullptr) {}
1581
1582 ParsedTemplateInfo(TemplateParameterLists *TemplateParams,
1583 bool isSpecialization,
1584 bool lastParameterListWasEmpty = false)
1585 : Kind(isSpecialization? ExplicitSpecialization : Template),
1586 TemplateParams(TemplateParams),
1587 LastParameterListWasEmpty(lastParameterListWasEmpty) { }
1588
1589 explicit ParsedTemplateInfo(SourceLocation ExternLoc,
1590 SourceLocation TemplateLoc)
1591 : Kind(ExplicitInstantiation), TemplateParams(nullptr),
1592 ExternLoc(ExternLoc), TemplateLoc(TemplateLoc),
1593 LastParameterListWasEmpty(false){ }
1594
1595
1596 enum {
1597
1598 NonTemplate = 0,
1599
1600 Template,
1601
1602 ExplicitSpecialization,
1603
1604 ExplicitInstantiation
1605 } Kind;
1606
1607
1608
1609 TemplateParameterLists *TemplateParams;
1610
1611
1612
1613 SourceLocation ExternLoc;
1614
1615
1616
1617 SourceLocation TemplateLoc;
1618
1619
1620 bool LastParameterListWasEmpty;
1621
1622 SourceRange getSourceRange() const LLVM_READONLY;
1623 };
1624
1625
1626 struct ReenterTemplateScopeRAII;
1627 struct ReenterClassScopeRAII;
1628
1629 void LexTemplateFunctionForLateParsing(CachedTokens &Toks);
1630 void ParseLateTemplatedFuncDef(LateParsedTemplate &LPT);
1631
1632 static void LateTemplateParserCallback(void *P, LateParsedTemplate &LPT);
1633
1634 Sema::ParsingClassState
1635 PushParsingClass(Decl *TagOrTemplate, bool TopLevelClass, bool IsInterface);
1636 void DeallocateParsedClasses(ParsingClass *Class);
1637 void PopParsingClass(Sema::ParsingClassState);
1638
1639 enum CachedInitKind {
1640 CIK_DefaultArgument,
1641 CIK_DefaultInitializer
1642 };
1643
1644 NamedDecl *ParseCXXInlineMethodDef(AccessSpecifier AS,
1645 const ParsedAttributesView &AccessAttrs,
1646 ParsingDeclarator &D,
1647 const ParsedTemplateInfo &TemplateInfo,
1648 const VirtSpecifiers &VS,
1649 SourceLocation PureSpecLoc);
1650 StringLiteral *ParseCXXDeletedFunctionMessage();
1651 void SkipDeletedFunctionBody();
1652 void ParseCXXNonStaticMemberInitializer(Decl *VarD);
1653 void ParseLexedAttributes(ParsingClass &Class);
1654 void ParseLexedAttributeList(LateParsedAttrList &LAs, Decl *D,
1655 bool EnterScope, bool OnDefinition);
1656 void ParseLexedCAttributeList(LateParsedAttrList &LA, bool EnterScope,
1657 ParsedAttributes *OutAttrs = nullptr);
1658 void ParseLexedAttribute(LateParsedAttribute &LA,
1659 bool EnterScope, bool OnDefinition);
1660 void ParseLexedCAttribute(LateParsedAttribute &LA, bool EnterScope,
1661 ParsedAttributes *OutAttrs = nullptr);
1662 void ParseLexedMethodDeclarations(ParsingClass &Class);
1663 void ParseLexedMethodDeclaration(LateParsedMethodDeclaration &LM);
1664 void ParseLexedMethodDefs(ParsingClass &Class);
1665 void ParseLexedMethodDef(LexedMethod &LM);
1666 void ParseLexedMemberInitializers(ParsingClass &Class);
1667 void ParseLexedMemberInitializer(LateParsedMemberInitializer &MI);
1668 void ParseLexedObjCMethodDefs(LexedMethod &LM, bool parseMethod);
1669 void ParseLexedPragmas(ParsingClass &Class);
1670 void ParseLexedPragma(LateParsedPragma &LP);
1671 bool ConsumeAndStoreFunctionPrologue(CachedTokens &Toks);
1672 bool ConsumeAndStoreInitializer(CachedTokens &Toks, CachedInitKind CIK);
1673 bool ConsumeAndStoreConditional(CachedTokens &Toks);
1674 bool ConsumeAndStoreUntil(tok::TokenKind T1,
1675 CachedTokens &Toks,
1676 bool StopAtSemi = true,
1677 bool ConsumeFinalToken = true) {
1678 return ConsumeAndStoreUntil(T1, T1, Toks, StopAtSemi, ConsumeFinalToken);
1679 }
1680 bool ConsumeAndStoreUntil(tok::TokenKind T1, tok::TokenKind T2,
1681 CachedTokens &Toks,
1682 bool StopAtSemi = true,
1683 bool ConsumeFinalToken = true);
1684
1685
1686
1687 DeclGroupPtrTy ParseExternalDeclaration(ParsedAttributes &DeclAttrs,
1688 ParsedAttributes &DeclSpecAttrs,
1689 ParsingDeclSpec *DS = nullptr);
1690 bool isDeclarationAfterDeclarator();
1691 bool isStartOfFunctionDefinition(const ParsingDeclarator &Declarator);
1692 DeclGroupPtrTy ParseDeclarationOrFunctionDefinition(
1693 ParsedAttributes &DeclAttrs, ParsedAttributes &DeclSpecAttrs,
1694 ParsingDeclSpec *DS = nullptr, AccessSpecifier AS = AS_none);
1695 DeclGroupPtrTy ParseDeclOrFunctionDefInternal(ParsedAttributes &Attrs,
1696 ParsedAttributes &DeclSpecAttrs,
1697 ParsingDeclSpec &DS,
1698 AccessSpecifier AS);
1699
1700 void SkipFunctionBody();
1701 Decl *ParseFunctionDefinition(ParsingDeclarator &D,
1702 const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo(),
1703 LateParsedAttrList *LateParsedAttrs = nullptr);
1704 void ParseKNRParamDeclarations(Declarator &D);
1705
1706 ExprResult ParseSimpleAsm(bool ForAsmLabel, SourceLocation *EndLoc);
1707 ExprResult ParseAsmStringLiteral(bool ForAsmLabel);
1708
1709
1710 void MaybeSkipAttributes(tok::ObjCKeywordKind Kind);
1711 DeclGroupPtrTy ParseObjCAtDirectives(ParsedAttributes &DeclAttrs,
1712 ParsedAttributes &DeclSpecAttrs);
1713 DeclGroupPtrTy ParseObjCAtClassDeclaration(SourceLocation atLoc);
1714 Decl *ParseObjCAtInterfaceDeclaration(SourceLocation AtLoc,
1715 ParsedAttributes &prefixAttrs);
1716 class ObjCTypeParamListScope;
1717 ObjCTypeParamList *parseObjCTypeParamList();
1718 ObjCTypeParamList *parseObjCTypeParamListOrProtocolRefs(
1719 ObjCTypeParamListScope &Scope, SourceLocation &lAngleLoc,
1720 SmallVectorImpl<IdentifierLocPair> &protocolIdents,
1721 SourceLocation &rAngleLoc, bool mayBeProtocolList = true);
1722
1723 void HelperActionsForIvarDeclarations(ObjCContainerDecl *interfaceDecl,
1724 SourceLocation atLoc,
1725 BalancedDelimiterTracker &T,
1726 SmallVectorImpl<Decl *> &AllIvarDecls,
1727 bool RBraceMissing);
1728 void ParseObjCClassInstanceVariables(ObjCContainerDecl *interfaceDecl,
1729 tok::ObjCKeywordKind visibility,
1730 SourceLocation atLoc);
1731 bool ParseObjCProtocolReferences(SmallVectorImpl<Decl *> &P,
1732 SmallVectorImpl<SourceLocation> &PLocs,
1733 bool WarnOnDeclarations,
1734 bool ForObjCContainer,
1735 SourceLocation &LAngleLoc,
1736 SourceLocation &EndProtoLoc,
1737 bool consumeLastToken);
1738
1739
1740
1741
1742 void parseObjCTypeArgsOrProtocolQualifiers(
1743 ParsedType baseType,
1744 SourceLocation &typeArgsLAngleLoc,
1745 SmallVectorImpl<ParsedType> &typeArgs,
1746 SourceLocation &typeArgsRAngleLoc,
1747 SourceLocation &protocolLAngleLoc,
1748 SmallVectorImpl<Decl *> &protocols,
1749 SmallVectorImpl<SourceLocation> &protocolLocs,
1750 SourceLocation &protocolRAngleLoc,
1751 bool consumeLastToken,
1752 bool warnOnIncompleteProtocols);
1753
1754
1755
1756 void parseObjCTypeArgsAndProtocolQualifiers(
1757 ParsedType baseType,
1758 SourceLocation &typeArgsLAngleLoc,
1759 SmallVectorImpl<ParsedType> &typeArgs,
1760 SourceLocation &typeArgsRAngleLoc,
1761 SourceLocation &protocolLAngleLoc,
1762 SmallVectorImpl<Decl *> &protocols,
1763 SmallVectorImpl<SourceLocation> &protocolLocs,
1764 SourceLocation &protocolRAngleLoc,
1765 bool consumeLastToken);
1766
1767
1768
1769 TypeResult parseObjCProtocolQualifierType(SourceLocation &rAngleLoc);
1770
1771
1772
1773 TypeResult parseObjCTypeArgsAndProtocolQualifiers(SourceLocation loc,
1774 ParsedType type,
1775 bool consumeLastToken,
1776 SourceLocation &endLoc);
1777
1778 void ParseObjCInterfaceDeclList(tok::ObjCKeywordKind contextKey,
1779 Decl *CDecl);
1780 DeclGroupPtrTy ParseObjCAtProtocolDeclaration(SourceLocation atLoc,
1781 ParsedAttributes &prefixAttrs);
1782
1783 struct ObjCImplParsingDataRAII {
1784 Parser &P;
1785 Decl *Dcl;
1786 bool HasCFunction;
1787 typedef SmallVector<LexedMethod*, 8> LateParsedObjCMethodContainer;
1788 LateParsedObjCMethodContainer LateParsedObjCMethods;
1789
1790 ObjCImplParsingDataRAII(Parser &parser, Decl *D)
1791 : P(parser), Dcl(D), HasCFunction(false) {
1792 P.CurParsedObjCImpl = this;
1793 Finished = false;
1794 }
1795 ~ObjCImplParsingDataRAII();
1796
1797 void finish(SourceRange AtEnd);
1798 bool isFinished() const { return Finished; }
1799
1800 private:
1801 bool Finished;
1802 };
1803 ObjCImplParsingDataRAII *CurParsedObjCImpl;
1804 void StashAwayMethodOrFunctionBodyTokens(Decl *MDecl);
1805
1806 DeclGroupPtrTy ParseObjCAtImplementationDeclaration(SourceLocation AtLoc,
1807 ParsedAttributes &Attrs);
1808 DeclGroupPtrTy ParseObjCAtEndDeclaration(SourceRange atEnd);
1809 Decl *ParseObjCAtAliasDeclaration(SourceLocation atLoc);
1810 Decl *ParseObjCPropertySynthesize(SourceLocation atLoc);
1811 Decl *ParseObjCPropertyDynamic(SourceLocation atLoc);
1812
1813 IdentifierInfo *ParseObjCSelectorPiece(SourceLocation &MethodLocation);
1814
1815 enum ObjCTypeQual {
1816 objc_in=0, objc_out, objc_inout, objc_oneway, objc_bycopy, objc_byref,
1817 objc_nonnull, objc_nullable, objc_null_unspecified,
1818 objc_NumQuals
1819 };
1820 IdentifierInfo *ObjCTypeQuals[objc_NumQuals];
1821
1822 bool isTokIdentifier_in() const;
1823
1824 ParsedType ParseObjCTypeName(ObjCDeclSpec &DS, DeclaratorContext Ctx,
1825 ParsedAttributes *ParamAttrs);
1826 Decl *ParseObjCMethodPrototype(
1827 tok::ObjCKeywordKind MethodImplKind = tok::objc_not_keyword,
1828 bool MethodDefinition = true);
1829 Decl *ParseObjCMethodDecl(SourceLocation mLoc, tok::TokenKind mType,
1830 tok::ObjCKeywordKind MethodImplKind = tok::objc_not_keyword,
1831 bool MethodDefinition=true);
1832 void ParseObjCPropertyAttribute(ObjCDeclSpec &DS);
1833
1834 Decl *ParseObjCMethodDefinition();
1835
1836 public:
1837
1838
1839
1840
1841 enum TypeCastState {
1842 NotTypeCast = 0,
1843 MaybeTypeCast,
1844 IsTypeCast
1845 };
1846
1847 ExprResult ParseExpression(TypeCastState isTypeCast = NotTypeCast);
1848 ExprResult ParseConstantExpressionInExprEvalContext(
1849 TypeCastState isTypeCast = NotTypeCast);
1850 ExprResult ParseConstantExpression();
1851 ExprResult ParseArrayBoundExpression();
1852 ExprResult ParseCaseExpression(SourceLocation CaseLoc);
1853 ExprResult ParseConstraintExpression();
1854 ExprResult
1855 ParseConstraintLogicalAndExpression(bool IsTrailingRequiresClause);
1856 ExprResult ParseConstraintLogicalOrExpression(bool IsTrailingRequiresClause);
1857
1858 ExprResult ParseAssignmentExpression(TypeCastState isTypeCast = NotTypeCast);
1859 ExprResult ParseConditionalExpression();
1860
1861 ExprResult ParseMSAsmIdentifier(llvm::SmallVectorImpl<Token> &LineToks,
1862 unsigned &NumLineToksConsumed,
1863 bool IsUnevaluated);
1864
1865 ExprResult ParseStringLiteralExpression(bool AllowUserDefinedLiteral = false);
1866 ExprResult ParseUnevaluatedStringLiteralExpression();
1867
1868 private:
1869 ExprResult ParseStringLiteralExpression(bool AllowUserDefinedLiteral,
1870 bool Unevaluated);
1871
1872 ExprResult ParseExpressionWithLeadingAt(SourceLocation AtLoc);
1873
1874 ExprResult ParseExpressionWithLeadingExtension(SourceLocation ExtLoc);
1875
1876 ExprResult ParseRHSOfBinaryExpression(ExprResult LHS,
1877 prec::Level MinPrec);
1878
1879 enum CastParseKind {
1880 AnyCastExpr = 0,
1881 UnaryExprOnly,
1882 PrimaryExprOnly
1883 };
1884
1885 bool isRevertibleTypeTrait(const IdentifierInfo *Id,
1886 clang::tok::TokenKind *Kind = nullptr);
1887
1888 ExprResult ParseCastExpression(CastParseKind ParseKind,
1889 bool isAddressOfOperand,
1890 bool &NotCastExpr,
1891 TypeCastState isTypeCast,
1892 bool isVectorLiteral = false,
1893 bool *NotPrimaryExpression = nullptr);
1894 ExprResult ParseCastExpression(CastParseKind ParseKind,
1895 bool isAddressOfOperand = false,
1896 TypeCastState isTypeCast = NotTypeCast,
1897 bool isVectorLiteral = false,
1898 bool *NotPrimaryExpression = nullptr);
1899
1900
1901 bool isNotExpressionStart();
1902
1903
1904
1905 bool isPostfixExpressionSuffixStart() {
1906 tok::TokenKind K = Tok.getKind();
1907 return (K == tok::l_square || K == tok::l_paren ||
1908 K == tok::period || K == tok::arrow ||
1909 K == tok::plusplus || K == tok::minusminus);
1910 }
1911
1912 bool diagnoseUnknownTemplateId(ExprResult TemplateName, SourceLocation Less);
1913 void checkPotentialAngleBracket(ExprResult &PotentialTemplateName);
1914 bool checkPotentialAngleBracketDelimiter(const AngleBracketTracker::Loc &,
1915 const Token &OpToken);
1916 bool checkPotentialAngleBracketDelimiter(const Token &OpToken) {
1917 if (auto *Info = AngleBrackets.getCurrent(*this))
1918 return checkPotentialAngleBracketDelimiter(*Info, OpToken);
1919 return false;
1920 }
1921
1922 ExprResult ParsePostfixExpressionSuffix(ExprResult LHS);
1923 ExprResult ParseUnaryExprOrTypeTraitExpression();
1924 ExprResult ParseBuiltinPrimaryExpression();
1925 ExprResult ParseSYCLUniqueStableNameExpression();
1926
1927 ExprResult ParseExprAfterUnaryExprOrTypeTrait(const Token &OpTok,
1928 bool &isCastExpr,
1929 ParsedType &CastTy,
1930 SourceRange &CastRange);
1931
1932
1933 bool ParseExpressionList(SmallVectorImpl<Expr *> &Exprs,
1934 llvm::function_ref<void()> ExpressionStarts =
1935 llvm::function_ref<void()>(),
1936 bool FailImmediatelyOnInvalidExpr = false,
1937 bool EarlyTypoCorrection = false,
1938 bool *HasTrailingComma = nullptr);
1939
1940
1941
1942 bool ParseSimpleExpressionList(SmallVectorImpl<Expr *> &Exprs);
1943
1944
1945 enum ParenParseOption {
1946 SimpleExpr,
1947 FoldExpr,
1948 CompoundStmt,
1949 CompoundLiteral,
1950 CastExpr
1951 };
1952 ExprResult ParseParenExpression(ParenParseOption &ExprType,
1953 bool stopIfCastExpr,
1954 bool isTypeCast,
1955 ParsedType &CastTy,
1956 SourceLocation &RParenLoc);
1957
1958 ExprResult ParseCXXAmbiguousParenExpression(
1959 ParenParseOption &ExprType, ParsedType &CastTy,
1960 BalancedDelimiterTracker &Tracker, ColonProtectionRAIIObject &ColonProt);
1961 ExprResult ParseCompoundLiteralExpression(ParsedType Ty,
1962 SourceLocation LParenLoc,
1963 SourceLocation RParenLoc);
1964
1965 ExprResult ParseGenericSelectionExpression();
1966
1967 ExprResult ParseObjCBoolLiteral();
1968
1969 ExprResult ParseFoldExpression(ExprResult LHS, BalancedDelimiterTracker &T);
1970
1971
1972
1973 ExprResult tryParseCXXIdExpression(CXXScopeSpec &SS, bool isAddressOfOperand,
1974 Token &Replacement);
1975
1976 ExprResult tryParseCXXPackIndexingExpression(ExprResult PackIdExpression);
1977 ExprResult ParseCXXPackIndexingExpression(ExprResult PackIdExpression);
1978
1979 ExprResult ParseCXXIdExpression(bool isAddressOfOperand = false);
1980
1981 bool areTokensAdjacent(const Token &A, const Token &B);
1982
1983 void CheckForTemplateAndDigraph(Token &Next, ParsedType ObjectTypePtr,
1984 bool EnteringContext, IdentifierInfo &II,
1985 CXXScopeSpec &SS);
1986
1987 bool ParseOptionalCXXScopeSpecifier(
1988 CXXScopeSpec &SS, ParsedType ObjectType, bool ObjectHasErrors,
1989 bool EnteringContext, bool *MayBePseudoDestructor = nullptr,
1990 bool IsTypename = false, const IdentifierInfo **LastII = nullptr,
1991 bool OnlyNamespace = false, bool InUsingDeclaration = false,
1992 bool Disambiguation = false);
1993
1994
1995
1996
1997
1998 enum class LambdaIntroducerTentativeParse {
1999
2000 Success,
2001
2002
2003 Incomplete,
2004
2005
2006 MessageSend,
2007
2008 Invalid,
2009 };
2010
2011
2012 ExprResult ParseLambdaExpression();
2013 ExprResult TryParseLambdaExpression();
2014 bool
2015 ParseLambdaIntroducer(LambdaIntroducer &Intro,
2016 LambdaIntroducerTentativeParse *Tentative = nullptr);
2017 ExprResult ParseLambdaExpressionAfterIntroducer(LambdaIntroducer &Intro);
2018
2019
2020
2021 ExprResult ParseCXXCasts();
2022
2023
2024 ExprResult ParseBuiltinBitCast();
2025
2026
2027
2028 ExprResult ParseCXXTypeid();
2029
2030
2031
2032 ExprResult ParseCXXUuidof();
2033
2034
2035
2036 ExprResult ParseCXXPseudoDestructor(Expr *Base, SourceLocation OpLoc,
2037 tok::TokenKind OpKind,
2038 CXXScopeSpec &SS,
2039 ParsedType ObjectType);
2040
2041
2042
2043 ExprResult ParseCXXThis();
2044
2045
2046
2047 ExprResult ParseThrowExpression();
2048
2049 ExceptionSpecificationType tryParseExceptionSpecification(
2050 bool Delayed,
2051 SourceRange &SpecificationRange,
2052 SmallVectorImpl<ParsedType> &DynamicExceptions,
2053 SmallVectorImpl<SourceRange> &DynamicExceptionRanges,
2054 ExprResult &NoexceptExpr,
2055 CachedTokens *&ExceptionSpecTokens);
2056
2057
2058 ExceptionSpecificationType ParseDynamicExceptionSpecification(
2059 SourceRange &SpecificationRange,
2060 SmallVectorImpl<ParsedType> &Exceptions,
2061 SmallVectorImpl<SourceRange> &Ranges);
2062
2063
2064
2065 TypeResult ParseTrailingReturnType(SourceRange &Range,
2066 bool MayBeFollowedByDirectInit);
2067
2068
2069
2070 ExprResult ParseCXXBoolLiteral();
2071
2072
2073
2074 ExprResult ParseCXXTypeConstructExpression(const DeclSpec &DS);
2075
2076
2077
2078
2079 void ParseCXXSimpleTypeSpecifier(DeclSpec &DS);
2080
2081 bool ParseCXXTypeSpecifierSeq(
2082 DeclSpec &DS, DeclaratorContext Context = DeclaratorContext::TypeName);
2083
2084
2085
2086 bool ParseExpressionListOrTypeId(SmallVectorImpl<Expr*> &Exprs,
2087 Declarator &D);
2088 void ParseDirectNewDeclarator(Declarator &D);
2089 ExprResult ParseCXXNewExpression(bool UseGlobal, SourceLocation Start);
2090 ExprResult ParseCXXDeleteExpression(bool UseGlobal,
2091 SourceLocation Start);
2092
2093
2094
2095 struct ForRangeInfo;
2096 Sema::ConditionResult ParseCXXCondition(StmtResult *InitStmt,
2097 SourceLocation Loc,
2098 Sema::ConditionKind CK,
2099 bool MissingOK,
2100 ForRangeInfo *FRI = nullptr,
2101 bool EnterForConditionScope = false);
2102 DeclGroupPtrTy ParseAliasDeclarationInInitStatement(DeclaratorContext Context,
2103 ParsedAttributes &Attrs);
2104
2105
2106
2107
2108 ExprResult ParseCoyieldExpression();
2109
2110
2111
2112
2113 ExprResult ParseRequiresExpression();
2114 void ParseTrailingRequiresClause(Declarator &D);
2115
2116
2117
2118
2119
2120
2121
2122
2123 ExprResult ParseInitializer() {
2124 if (Tok.isNot(tok::l_brace))
2125 return ParseAssignmentExpression();
2126 return ParseBraceInitializer();
2127 }
2128 bool MayBeDesignationStart();
2129 ExprResult ParseBraceInitializer();
2130 struct DesignatorCompletionInfo {
2131 SmallVectorImpl<Expr *> &InitExprs;
2132 QualType PreferredBaseType;
2133 };
2134 ExprResult ParseInitializerWithPotentialDesignator(DesignatorCompletionInfo);
2135 ExprResult createEmbedExpr();
2136 void injectEmbedTokens();
2137
2138
2139
2140
2141 ExprResult ParseBlockLiteralExpression();
2142
2143
2144
2145 ExprResult ParseObjCAtExpression(SourceLocation AtLocation);
2146 ExprResult ParseObjCStringLiteral(SourceLocation AtLoc);
2147 ExprResult ParseObjCCharacterLiteral(SourceLocation AtLoc);
2148 ExprResult ParseObjCNumericLiteral(SourceLocation AtLoc);
2149 ExprResult ParseObjCBooleanLiteral(SourceLocation AtLoc, bool ArgValue);
2150 ExprResult ParseObjCArrayLiteral(SourceLocation AtLoc);
2151 ExprResult ParseObjCDictionaryLiteral(SourceLocation AtLoc);
2152 ExprResult ParseObjCBoxedExpr(SourceLocation AtLoc);
2153 ExprResult ParseObjCEncodeExpression(SourceLocation AtLoc);
2154 ExprResult ParseObjCSelectorExpression(SourceLocation AtLoc);
2155 ExprResult ParseObjCProtocolExpression(SourceLocation AtLoc);
2156 bool isSimpleObjCMessageExpression();
2157 ExprResult ParseObjCMessageExpression();
2158 ExprResult ParseObjCMessageExpressionBody(SourceLocation LBracloc,
2159 SourceLocation SuperLoc,
2160 ParsedType ReceiverType,
2161 Expr *ReceiverExpr);
2162 ExprResult ParseAssignmentExprWithObjCMessageExprStart(
2163 SourceLocation LBracloc, SourceLocation SuperLoc,
2164 ParsedType ReceiverType, Expr *ReceiverExpr);
2165 bool ParseObjCXXMessageReceiver(bool &IsExpr, void *&TypeOrExpr);
2166
2167
2168
2169
2170
2171 typedef SmallVector<Expr*, 12> ExprVector;
2172
2173 StmtResult
2174 ParseStatement(SourceLocation *TrailingElseLoc = nullptr,
2175 ParsedStmtContext StmtCtx = ParsedStmtContext::SubStmt);
2176 StmtResult ParseStatementOrDeclaration(
2177 StmtVector &Stmts, ParsedStmtContext StmtCtx,
2178 SourceLocation *TrailingElseLoc = nullptr);
2179 StmtResult ParseStatementOrDeclarationAfterAttributes(
2180 StmtVector &Stmts, ParsedStmtContext StmtCtx,
2181 SourceLocation *TrailingElseLoc, ParsedAttributes &DeclAttrs,
2182 ParsedAttributes &DeclSpecAttrs);
2183 StmtResult ParseExprStatement(ParsedStmtContext StmtCtx);
2184 StmtResult ParseLabeledStatement(ParsedAttributes &Attrs,
2185 ParsedStmtContext StmtCtx);
2186 StmtResult ParseCaseStatement(ParsedStmtContext StmtCtx,
2187 bool MissingCase = false,
2188 ExprResult Expr = ExprResult());
2189 StmtResult ParseDefaultStatement(ParsedStmtContext StmtCtx);
2190 StmtResult ParseCompoundStatement(bool isStmtExpr = false);
2191 StmtResult ParseCompoundStatement(bool isStmtExpr,
2192 unsigned ScopeFlags);
2193 void ParseCompoundStatementLeadingPragmas();
2194 void DiagnoseLabelAtEndOfCompoundStatement();
2195 bool ConsumeNullStmt(StmtVector &Stmts);
2196 StmtResult ParseCompoundStatementBody(bool isStmtExpr = false);
2197 bool ParseParenExprOrCondition(StmtResult *InitStmt,
2198 Sema::ConditionResult &CondResult,
2199 SourceLocation Loc, Sema::ConditionKind CK,
2200 SourceLocation &LParenLoc,
2201 SourceLocation &RParenLoc);
2202 StmtResult ParseIfStatement(SourceLocation *TrailingElseLoc);
2203 StmtResult ParseSwitchStatement(SourceLocation *TrailingElseLoc);
2204 StmtResult ParseWhileStatement(SourceLocation *TrailingElseLoc);
2205 StmtResult ParseDoStatement();
2206 StmtResult ParseForStatement(SourceLocation *TrailingElseLoc);
2207 StmtResult ParseGotoStatement();
2208 StmtResult ParseContinueStatement();
2209 StmtResult ParseBreakStatement();
2210 StmtResult ParseReturnStatement();
2211 StmtResult ParseAsmStatement(bool &msAsm);
2212 StmtResult ParseMicrosoftAsmStatement(SourceLocation AsmLoc);
2213 StmtResult ParsePragmaLoopHint(StmtVector &Stmts, ParsedStmtContext StmtCtx,
2214 SourceLocation *TrailingElseLoc,
2215 ParsedAttributes &Attrs);
2216
2217
2218
2219 enum IfExistsBehavior {
2220
2221 IEB_Parse,
2222
2223 IEB_Skip,
2224
2225
2226 IEB_Dependent
2227 };
2228
2229
2230
2231 struct IfExistsCondition {
2232
2233 SourceLocation KeywordLoc;
2234
2235
2236 bool IsIfExists;
2237
2238
2239 CXXScopeSpec SS;
2240
2241
2242 UnqualifiedId Name;
2243
2244
2245
2246 IfExistsBehavior Behavior;
2247 };
2248
2249 bool ParseMicrosoftIfExistsCondition(IfExistsCondition& Result);
2250 void ParseMicrosoftIfExistsStatement(StmtVector &Stmts);
2251 void ParseMicrosoftIfExistsExternalDeclaration();
2252 void ParseMicrosoftIfExistsClassDeclaration(DeclSpec::TST TagType,
2253 ParsedAttributes &AccessAttrs,
2254 AccessSpecifier &CurAS);
2255 bool ParseMicrosoftIfExistsBraceInitializer(ExprVector &InitExprs,
2256 bool &InitExprsOk);
2257 bool ParseAsmOperandsOpt(SmallVectorImpl<IdentifierInfo *> &Names,
2258 SmallVectorImpl<Expr *> &Constraints,
2259 SmallVectorImpl<Expr *> &Exprs);
2260
2261
2262
2263
2264 StmtResult ParseCXXTryBlock();
2265 StmtResult ParseCXXTryBlockCommon(SourceLocation TryLoc, bool FnTry = false);
2266 StmtResult ParseCXXCatchBlock(bool FnCatch = false);
2267
2268
2269
2270
2271 StmtResult ParseSEHTryBlock();
2272 StmtResult ParseSEHExceptBlock(SourceLocation Loc);
2273 StmtResult ParseSEHFinallyBlock(SourceLocation Loc);
2274 StmtResult ParseSEHLeaveStatement();
2275
2276
2277
2278
2279 StmtResult ParseObjCAtStatement(SourceLocation atLoc,
2280 ParsedStmtContext StmtCtx);
2281 StmtResult ParseObjCTryStmt(SourceLocation atLoc);
2282 StmtResult ParseObjCThrowStmt(SourceLocation atLoc);
2283 StmtResult ParseObjCSynchronizedStmt(SourceLocation atLoc);
2284 StmtResult ParseObjCAutoreleasePoolStmt(SourceLocation atLoc);
2285
2286
2287
2288
2289
2290
2291
2292
2293 enum class DeclSpecContext {
2294 DSC_normal,
2295 DSC_class,
2296 DSC_type_specifier,
2297 DSC_trailing,
2298 DSC_alias_declaration,
2299 DSC_conv_operator,
2300 DSC_top_level,
2301 DSC_template_param,
2302 DSC_template_arg,
2303 DSC_template_type_arg,
2304 DSC_objc_method_result,
2305
2306 DSC_condition,
2307 DSC_association,
2308 DSC_new,
2309 };
2310
2311
2312
2313 static bool isTypeSpecifier(DeclSpecContext DSC) {
2314 switch (DSC) {
2315 case DeclSpecContext::DSC_normal:
2316 case DeclSpecContext::DSC_template_param:
2317 case DeclSpecContext::DSC_template_arg:
2318 case DeclSpecContext::DSC_class:
2319 case DeclSpecContext::DSC_top_level:
2320 case DeclSpecContext::DSC_objc_method_result:
2321 case DeclSpecContext::DSC_condition:
2322 return false;
2323
2324 case DeclSpecContext::DSC_template_type_arg:
2325 case DeclSpecContext::DSC_type_specifier:
2326 case DeclSpecContext::DSC_conv_operator:
2327 case DeclSpecContext::DSC_trailing:
2328 case DeclSpecContext::DSC_alias_declaration:
2329 case DeclSpecContext::DSC_association:
2330 case DeclSpecContext::DSC_new:
2331 return true;
2332 }
2333 llvm_unreachable("Missing DeclSpecContext case");
2334 }
2335
2336
2337 enum class AllowDefiningTypeSpec {
2338
2339
2340 No,
2341
2342
2343 NoButErrorRecovery,
2344
2345
2346 YesButInvalid,
2347
2348 Yes
2349 };
2350
2351
2352
2353
2354 static AllowDefiningTypeSpec
2355 isDefiningTypeSpecifierContext(DeclSpecContext DSC, bool IsCPlusPlus) {
2356 switch (DSC) {
2357 case DeclSpecContext::DSC_normal:
2358 case DeclSpecContext::DSC_class:
2359 case DeclSpecContext::DSC_top_level:
2360 case DeclSpecContext::DSC_alias_declaration:
2361 case DeclSpecContext::DSC_objc_method_result:
2362 return AllowDefiningTypeSpec::Yes;
2363
2364 case DeclSpecContext::DSC_condition:
2365 case DeclSpecContext::DSC_template_param:
2366 return AllowDefiningTypeSpec::YesButInvalid;
2367
2368 case DeclSpecContext::DSC_template_type_arg:
2369 case DeclSpecContext::DSC_type_specifier:
2370 return AllowDefiningTypeSpec::NoButErrorRecovery;
2371
2372 case DeclSpecContext::DSC_association:
2373 return IsCPlusPlus ? AllowDefiningTypeSpec::NoButErrorRecovery
2374 : AllowDefiningTypeSpec::Yes;
2375
2376 case DeclSpecContext::DSC_trailing:
2377 case DeclSpecContext::DSC_conv_operator:
2378 case DeclSpecContext::DSC_template_arg:
2379 case DeclSpecContext::DSC_new:
2380 return AllowDefiningTypeSpec::No;
2381 }
2382 llvm_unreachable("Missing DeclSpecContext case");
2383 }
2384
2385
2386 static bool isOpaqueEnumDeclarationContext(DeclSpecContext DSC) {
2387 switch (DSC) {
2388 case DeclSpecContext::DSC_normal:
2389 case DeclSpecContext::DSC_class:
2390 case DeclSpecContext::DSC_top_level:
2391 return true;
2392
2393 case DeclSpecContext::DSC_alias_declaration:
2394 case DeclSpecContext::DSC_objc_method_result:
2395 case DeclSpecContext::DSC_condition:
2396 case DeclSpecContext::DSC_template_param:
2397 case DeclSpecContext::DSC_template_type_arg:
2398 case DeclSpecContext::DSC_type_specifier:
2399 case DeclSpecContext::DSC_trailing:
2400 case DeclSpecContext::DSC_association:
2401 case DeclSpecContext::DSC_conv_operator:
2402 case DeclSpecContext::DSC_template_arg:
2403 case DeclSpecContext::DSC_new:
2404
2405 return false;
2406 }
2407 llvm_unreachable("Missing DeclSpecContext case");
2408 }
2409
2410
2411
2412 static bool isClassTemplateDeductionContext(DeclSpecContext DSC) {
2413 switch (DSC) {
2414 case DeclSpecContext::DSC_normal:
2415 case DeclSpecContext::DSC_template_param:
2416 case DeclSpecContext::DSC_template_arg:
2417 case DeclSpecContext::DSC_class:
2418 case DeclSpecContext::DSC_top_level:
2419 case DeclSpecContext::DSC_condition:
2420 case DeclSpecContext::DSC_type_specifier:
2421 case DeclSpecContext::DSC_association:
2422 case DeclSpecContext::DSC_conv_operator:
2423 case DeclSpecContext::DSC_new:
2424 return true;
2425
2426 case DeclSpecContext::DSC_objc_method_result:
2427 case DeclSpecContext::DSC_template_type_arg:
2428 case DeclSpecContext::DSC_trailing:
2429 case DeclSpecContext::DSC_alias_declaration:
2430 return false;
2431 }
2432 llvm_unreachable("Missing DeclSpecContext case");
2433 }
2434
2435
2436 static ImplicitTypenameContext
2437 getImplicitTypenameContext(DeclSpecContext DSC) {
2438 switch (DSC) {
2439 case DeclSpecContext::DSC_class:
2440 case DeclSpecContext::DSC_top_level:
2441 case DeclSpecContext::DSC_type_specifier:
2442 case DeclSpecContext::DSC_template_type_arg:
2443 case DeclSpecContext::DSC_trailing:
2444 case DeclSpecContext::DSC_alias_declaration:
2445 case DeclSpecContext::DSC_template_param:
2446 case DeclSpecContext::DSC_new:
2447 return ImplicitTypenameContext::Yes;
2448
2449 case DeclSpecContext::DSC_normal:
2450 case DeclSpecContext::DSC_objc_method_result:
2451 case DeclSpecContext::DSC_condition:
2452 case DeclSpecContext::DSC_template_arg:
2453 case DeclSpecContext::DSC_conv_operator:
2454 case DeclSpecContext::DSC_association:
2455 return ImplicitTypenameContext::No;
2456 }
2457 llvm_unreachable("Missing DeclSpecContext case");
2458 }
2459
2460
2461
2462 struct ForRangeInit {
2463 SourceLocation ColonLoc;
2464 ExprResult RangeExpr;
2465 SmallVector<MaterializeTemporaryExpr *, 8> LifetimeExtendTemps;
2466 bool ParsedForRangeDecl() { return !ColonLoc.isInvalid(); }
2467 };
2468 struct ForRangeInfo : ForRangeInit {
2469 StmtResult LoopVar;
2470 };
2471
2472 DeclGroupPtrTy ParseDeclaration(DeclaratorContext Context,
2473 SourceLocation &DeclEnd,
2474 ParsedAttributes &DeclAttrs,
2475 ParsedAttributes &DeclSpecAttrs,
2476 SourceLocation *DeclSpecStart = nullptr);
2477 DeclGroupPtrTy
2478 ParseSimpleDeclaration(DeclaratorContext Context, SourceLocation &DeclEnd,
2479 ParsedAttributes &DeclAttrs,
2480 ParsedAttributes &DeclSpecAttrs, bool RequireSemi,
2481 ForRangeInit *FRI = nullptr,
2482 SourceLocation *DeclSpecStart = nullptr);
2483 bool MightBeDeclarator(DeclaratorContext Context);
2484 DeclGroupPtrTy ParseDeclGroup(ParsingDeclSpec &DS, DeclaratorContext Context,
2485 ParsedAttributes &Attrs,
2486 ParsedTemplateInfo &TemplateInfo,
2487 SourceLocation *DeclEnd = nullptr,
2488 ForRangeInit *FRI = nullptr);
2489 Decl *ParseDeclarationAfterDeclarator(Declarator &D,
2490 const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo());
2491 bool ParseAsmAttributesAfterDeclarator(Declarator &D);
2492 Decl *ParseDeclarationAfterDeclaratorAndAttributes(
2493 Declarator &D,
2494 const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo(),
2495 ForRangeInit *FRI = nullptr);
2496 Decl *ParseFunctionStatementBody(Decl *Decl, ParseScope &BodyScope);
2497 Decl *ParseFunctionTryBlock(Decl *Decl, ParseScope &BodyScope);
2498
2499
2500
2501
2502
2503 bool trySkippingFunctionBody();
2504
2505 bool ParseImplicitInt(DeclSpec &DS, CXXScopeSpec *SS,
2506 ParsedTemplateInfo &TemplateInfo, AccessSpecifier AS,
2507 DeclSpecContext DSC, ParsedAttributes &Attrs);
2508 DeclSpecContext
2509 getDeclSpecContextFromDeclaratorContext(DeclaratorContext Context);
2510 void
2511 ParseDeclarationSpecifiers(DeclSpec &DS, ParsedTemplateInfo &TemplateInfo,
2512 AccessSpecifier AS = AS_none,
2513 DeclSpecContext DSC = DeclSpecContext::DSC_normal,
2514 LateParsedAttrList *LateAttrs = nullptr) {
2515 return ParseDeclarationSpecifiers(DS, TemplateInfo, AS, DSC, LateAttrs,
2516 getImplicitTypenameContext(DSC));
2517 }
2518 void
2519 ParseDeclarationSpecifiers(DeclSpec &DS, ParsedTemplateInfo &TemplateInfo,
2520 AccessSpecifier AS, DeclSpecContext DSC,
2521 LateParsedAttrList *LateAttrs,
2522 ImplicitTypenameContext AllowImplicitTypename);
2523
2524 SourceLocation ParsePackIndexingType(DeclSpec &DS);
2525 void AnnotateExistingIndexedTypeNamePack(ParsedType T,
2526 SourceLocation StartLoc,
2527 SourceLocation EndLoc);
2528
2529 bool DiagnoseMissingSemiAfterTagDefinition(
2530 DeclSpec &DS, AccessSpecifier AS, DeclSpecContext DSContext,
2531 LateParsedAttrList *LateAttrs = nullptr);
2532
2533 void ParseSpecifierQualifierList(
2534 DeclSpec &DS, AccessSpecifier AS = AS_none,
2535 DeclSpecContext DSC = DeclSpecContext::DSC_normal) {
2536 ParseSpecifierQualifierList(DS, getImplicitTypenameContext(DSC), AS, DSC);
2537 }
2538
2539 void ParseSpecifierQualifierList(
2540 DeclSpec &DS, ImplicitTypenameContext AllowImplicitTypename,
2541 AccessSpecifier AS = AS_none,
2542 DeclSpecContext DSC = DeclSpecContext::DSC_normal);
2543
2544 void ParseObjCTypeQualifierList(ObjCDeclSpec &DS,
2545 DeclaratorContext Context);
2546
2547 void ParseEnumSpecifier(SourceLocation TagLoc, DeclSpec &DS,
2548 const ParsedTemplateInfo &TemplateInfo,
2549 AccessSpecifier AS, DeclSpecContext DSC);
2550 void ParseEnumBody(SourceLocation StartLoc, Decl *TagDecl);
2551 void ParseStructUnionBody(SourceLocation StartLoc, DeclSpec::TST TagType,
2552 RecordDecl *TagDecl);
2553
2554 void ParseStructDeclaration(
2555 ParsingDeclSpec &DS,
2556 llvm::function_ref<Decl *(ParsingFieldDeclarator &)> FieldsCallback,
2557 LateParsedAttrList *LateFieldAttrs = nullptr);
2558
2559 DeclGroupPtrTy ParseTopLevelStmtDecl();
2560
2561 bool isDeclarationSpecifier(ImplicitTypenameContext AllowImplicitTypename,
2562 bool DisambiguatingWithExpression = false);
2563 bool isTypeSpecifierQualifier();
2564
2565
2566
2567
2568 bool isKnownToBeTypeSpecifier(const Token &Tok) const;
2569
2570
2571
2572
2573 bool isKnownToBeDeclarationSpecifier() {
2574 if (getLangOpts().CPlusPlus)
2575 return isCXXDeclarationSpecifier(ImplicitTypenameContext::No) ==
2576 TPResult::True;
2577 return isDeclarationSpecifier(ImplicitTypenameContext::No, true);
2578 }
2579
2580
2581
2582
2583
2584
2585
2586 bool isDeclarationStatement(bool DisambiguatingWithExpression = false) {
2587 if (getLangOpts().CPlusPlus)
2588 return isCXXDeclarationStatement(DisambiguatingWithExpression);
2589 return isDeclarationSpecifier(ImplicitTypenameContext::No, true);
2590 }
2591
2592
2593
2594
2595
2596 bool isForInitDeclaration() {
2597 if (getLangOpts().OpenMP)
2598 Actions.OpenMP().startOpenMPLoop();
2599 if (getLangOpts().CPlusPlus)
2600 return Tok.is(tok::kw_using) ||
2601 isCXXSimpleDeclaration(true);
2602 return isDeclarationSpecifier(ImplicitTypenameContext::No, true);
2603 }
2604
2605
2606 bool isForRangeIdentifier();
2607
2608
2609
2610 bool isStartOfObjCClassMessageMissingOpenBracket();
2611
2612
2613
2614
2615 bool isConstructorDeclarator(
2616 bool Unqualified, bool DeductionGuide = false,
2617 DeclSpec::FriendSpecified IsFriend = DeclSpec::FriendSpecified::No,
2618 const ParsedTemplateInfo *TemplateInfo = nullptr);
2619
2620
2621
2622 enum TentativeCXXTypeIdContext {
2623 TypeIdInParens,
2624 TypeIdUnambiguous,
2625 TypeIdAsTemplateArgument,
2626 TypeIdInTrailingReturnType,
2627 TypeIdAsGenericSelectionArgument,
2628 };
2629
2630
2631
2632
2633 bool isTypeIdInParens(bool &isAmbiguous) {
2634 if (getLangOpts().CPlusPlus)
2635 return isCXXTypeId(TypeIdInParens, isAmbiguous);
2636 isAmbiguous = false;
2637 return isTypeSpecifierQualifier();
2638 }
2639 bool isTypeIdInParens() {
2640 bool isAmbiguous;
2641 return isTypeIdInParens(isAmbiguous);
2642 }
2643
2644
2645
2646
2647
2648
2649
2650
2651 bool isTypeIdForGenericSelection() {
2652 if (getLangOpts().CPlusPlus) {
2653 bool isAmbiguous;
2654 return isCXXTypeId(TypeIdAsGenericSelectionArgument, isAmbiguous);
2655 }
2656 return isTypeSpecifierQualifier();
2657 }
2658
2659
2660
2661
2662 bool isTypeIdUnambiguously() {
2663 if (getLangOpts().CPlusPlus) {
2664 bool isAmbiguous;
2665 return isCXXTypeId(TypeIdUnambiguous, isAmbiguous);
2666 }
2667 return isTypeSpecifierQualifier();
2668 }
2669
2670
2671
2672
2673 bool isCXXDeclarationStatement(bool DisambiguatingWithExpression = false);
2674
2675
2676
2677
2678
2679
2680 bool isCXXSimpleDeclaration(bool AllowForRangeDecl);
2681
2682
2683
2684
2685
2686
2687
2688
2689 bool isCXXFunctionDeclarator(bool *IsAmbiguous = nullptr,
2690 ImplicitTypenameContext AllowImplicitTypename =
2691 ImplicitTypenameContext::No);
2692
2693 struct ConditionDeclarationOrInitStatementState;
2694 enum class ConditionOrInitStatement {
2695 Expression,
2696 ConditionDecl,
2697 InitStmtDecl,
2698 ForRangeDecl,
2699 Error
2700 };
2701
2702
2703
2704 ConditionOrInitStatement
2705 isCXXConditionDeclarationOrInitStatement(bool CanBeInitStmt,
2706 bool CanBeForRangeDecl);
2707
2708 bool isCXXTypeId(TentativeCXXTypeIdContext Context, bool &isAmbiguous);
2709 bool isCXXTypeId(TentativeCXXTypeIdContext Context) {
2710 bool isAmbiguous;
2711 return isCXXTypeId(Context, isAmbiguous);
2712 }
2713
2714
2715
2716 enum class TPResult {
2717 True, False, Ambiguous, Error
2718 };
2719
2720
2721
2722
2723
2724
2725
2726
2727 bool isEnumBase(bool AllowSemi);
2728
2729
2730
2731
2732
2733
2734
2735
2736 TPResult
2737 isCXXDeclarationSpecifier(ImplicitTypenameContext AllowImplicitTypename,
2738 TPResult BracedCastResult = TPResult::False,
2739 bool *InvalidAsDeclSpec = nullptr);
2740
2741
2742
2743
2744 bool isCXXDeclarationSpecifierAType();
2745
2746
2747
2748
2749 TPResult isTemplateArgumentList(unsigned TokensToSkip);
2750
2751
2752
2753
2754 TPResult isExplicitBool();
2755
2756
2757
2758
2759 bool isTentativelyDeclared(IdentifierInfo *II);
2760
2761
2762
2763
2764
2765
2766
2767
2768 TPResult TryParseSimpleDeclaration(bool AllowForRangeDecl);
2769 TPResult TryParseTypeofSpecifier();
2770 TPResult TryParseProtocolQualifiers();
2771 TPResult TryParsePtrOperatorSeq();
2772 TPResult TryParseOperatorId();
2773 TPResult TryParseInitDeclaratorList(bool MayHaveTrailingReturnType = false);
2774 TPResult TryParseDeclarator(bool mayBeAbstract, bool mayHaveIdentifier = true,
2775 bool mayHaveDirectInit = false,
2776 bool mayHaveTrailingReturnType = false);
2777 TPResult TryParseParameterDeclarationClause(
2778 bool *InvalidAsDeclaration = nullptr, bool VersusTemplateArg = false,
2779 ImplicitTypenameContext AllowImplicitTypename =
2780 ImplicitTypenameContext::No);
2781 TPResult TryParseFunctionDeclarator(bool MayHaveTrailingReturnType = false);
2782 bool NameAfterArrowIsNonType();
2783 TPResult TryParseBracketDeclarator();
2784 TPResult TryConsumeDeclarationSpecifier();
2785
2786
2787
2788 bool TrySkipAttributes();
2789
2790
2791
2792 void DiagnoseBitIntUse(const Token &Tok);
2793
2794 public:
2795 TypeResult
2796 ParseTypeName(SourceRange *Range = nullptr,
2797 DeclaratorContext Context = DeclaratorContext::TypeName,
2798 AccessSpecifier AS = AS_none, Decl **OwnedType = nullptr,
2799 ParsedAttributes *Attrs = nullptr);
2800
2801 private:
2802 void ParseBlockId(SourceLocation CaretLoc);
2803
2804
2805
2806
2807
2808
2809 bool isAllowedCXX11AttributeSpecifier(bool Disambiguate = false,
2810 bool OuterMightBeMessageSend = false) {
2811 return (Tok.isRegularKeywordAttribute() ||
2812 isCXX11AttributeSpecifier(Disambiguate, OuterMightBeMessageSend));
2813 }
2814
2815
2816
2817 bool CheckProhibitedCXX11Attribute() {
2818 assert(Tok.is(tok::l_square));
2819 if (NextToken().isNot(tok::l_square))
2820 return false;
2821 return DiagnoseProhibitedCXX11Attribute();
2822 }
2823
2824 bool DiagnoseProhibitedCXX11Attribute();
2825 void CheckMisplacedCXX11Attribute(ParsedAttributes &Attrs,
2826 SourceLocation CorrectLocation) {
2827 if (!Tok.isRegularKeywordAttribute() &&
2828 (Tok.isNot(tok::l_square) || NextToken().isNot(tok::l_square)) &&
2829 Tok.isNot(tok::kw_alignas))
2830 return;
2831 DiagnoseMisplacedCXX11Attribute(Attrs, CorrectLocation);
2832 }
2833 void DiagnoseMisplacedCXX11Attribute(ParsedAttributes &Attrs,
2834 SourceLocation CorrectLocation);
2835
2836 void stripTypeAttributesOffDeclSpec(ParsedAttributes &Attrs, DeclSpec &DS,
2837 TagUseKind TUK);
2838
2839
2840 void ProhibitAttributes(ParsedAttributes &Attrs,
2841 SourceLocation FixItLoc = SourceLocation()) {
2842 if (Attrs.Range.isInvalid())
2843 return;
2844 DiagnoseProhibitedAttributes(Attrs, FixItLoc);
2845 Attrs.clear();
2846 }
2847
2848 void ProhibitAttributes(ParsedAttributesView &Attrs,
2849 SourceLocation FixItLoc = SourceLocation()) {
2850 if (Attrs.Range.isInvalid())
2851 return;
2852 DiagnoseProhibitedAttributes(Attrs, FixItLoc);
2853 Attrs.clearListOnly();
2854 }
2855 void DiagnoseProhibitedAttributes(const ParsedAttributesView &Attrs,
2856 SourceLocation FixItLoc);
2857
2858
2859
2860
2861
2862
2863
2864 void ProhibitCXX11Attributes(ParsedAttributes &Attrs, unsigned AttrDiagID,
2865 unsigned KeywordDiagId,
2866 bool DiagnoseEmptyAttrs = false,
2867 bool WarnOnUnknownAttrs = false);
2868
2869
2870
2871
2872 SourceLocation SkipCXX11Attributes();
2873
2874
2875
2876 void DiagnoseAndSkipCXX11Attributes();
2877
2878
2879
2880 void DiagnoseCXX11AttributeExtension(ParsedAttributes &Attrs);
2881
2882 ExprResult ParseUnevaluatedStringInAttribute(const IdentifierInfo &AttrName);
2883
2884 bool
2885 ParseAttributeArgumentList(const clang::IdentifierInfo &AttrName,
2886 SmallVectorImpl<Expr *> &Exprs,
2887 ParsedAttributeArgumentsProperties ArgsProperties);
2888
2889
2890
2891
2892
2893 unsigned
2894 ParseAttributeArgsCommon(IdentifierInfo *AttrName, SourceLocation AttrNameLoc,
2895 ParsedAttributes &Attrs, SourceLocation *EndLoc,
2896 IdentifierInfo *ScopeName, SourceLocation ScopeLoc,
2897 ParsedAttr::Form Form);
2898
2899 enum ParseAttrKindMask {
2900 PAKM_GNU = 1 << 0,
2901 PAKM_Declspec = 1 << 1,
2902 PAKM_CXX11 = 1 << 2,
2903 };
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919 void ParseAttributes(unsigned WhichAttrKinds, ParsedAttributes &Attrs,
2920 LateParsedAttrList *LateAttrs = nullptr);
2921
2922
2923 bool MaybeParseAttributes(unsigned WhichAttrKinds, ParsedAttributes &Attrs,
2924 LateParsedAttrList *LateAttrs = nullptr) {
2925 if (Tok.isOneOf(tok::kw___attribute, tok::kw___declspec) ||
2926 isAllowedCXX11AttributeSpecifier()) {
2927 ParseAttributes(WhichAttrKinds, Attrs, LateAttrs);
2928 return true;
2929 }
2930 return false;
2931 }
2932
2933 void MaybeParseGNUAttributes(Declarator &D,
2934 LateParsedAttrList *LateAttrs = nullptr) {
2935 if (Tok.is(tok::kw___attribute)) {
2936 ParsedAttributes Attrs(AttrFactory);
2937 ParseGNUAttributes(Attrs, LateAttrs, &D);
2938 D.takeAttributes(Attrs);
2939 }
2940 }
2941
2942 bool MaybeParseGNUAttributes(ParsedAttributes &Attrs,
2943 LateParsedAttrList *LateAttrs = nullptr) {
2944 if (Tok.is(tok::kw___attribute)) {
2945 ParseGNUAttributes(Attrs, LateAttrs);
2946 return true;
2947 }
2948 return false;
2949 }
2950
2951 bool ParseSingleGNUAttribute(ParsedAttributes &Attrs, SourceLocation &EndLoc,
2952 LateParsedAttrList *LateAttrs = nullptr,
2953 Declarator *D = nullptr);
2954 void ParseGNUAttributes(ParsedAttributes &Attrs,
2955 LateParsedAttrList *LateAttrs = nullptr,
2956 Declarator *D = nullptr);
2957 void ParseGNUAttributeArgs(IdentifierInfo *AttrName,
2958 SourceLocation AttrNameLoc,
2959 ParsedAttributes &Attrs, SourceLocation *EndLoc,
2960 IdentifierInfo *ScopeName, SourceLocation ScopeLoc,
2961 ParsedAttr::Form Form, Declarator *D);
2962 IdentifierLoc *ParseIdentifierLoc();
2963
2964 unsigned
2965 ParseClangAttributeArgs(IdentifierInfo *AttrName, SourceLocation AttrNameLoc,
2966 ParsedAttributes &Attrs, SourceLocation *EndLoc,
2967 IdentifierInfo *ScopeName, SourceLocation ScopeLoc,
2968 ParsedAttr::Form Form);
2969
2970 void ReplayOpenMPAttributeTokens(CachedTokens &OpenMPTokens) {
2971
2972
2973 if (!OpenMPTokens.empty()) {
2974 PP.EnterToken(Tok, true);
2975 PP.EnterTokenStream(OpenMPTokens, true,
2976 true);
2977 ConsumeAnyToken( true);
2978 }
2979 }
2980 void MaybeParseCXX11Attributes(Declarator &D) {
2981 if (isAllowedCXX11AttributeSpecifier()) {
2982 ParsedAttributes Attrs(AttrFactory);
2983 ParseCXX11Attributes(Attrs);
2984 D.takeAttributes(Attrs);
2985 }
2986 }
2987
2988 bool MaybeParseCXX11Attributes(ParsedAttributes &Attrs,
2989 bool OuterMightBeMessageSend = false) {
2990 if (isAllowedCXX11AttributeSpecifier(false, OuterMightBeMessageSend)) {
2991 ParseCXX11Attributes(Attrs);
2992 return true;
2993 }
2994 return false;
2995 }
2996
2997 void ParseOpenMPAttributeArgs(const IdentifierInfo *AttrName,
2998 CachedTokens &OpenMPTokens);
2999
3000 void ParseCXX11AttributeSpecifierInternal(ParsedAttributes &Attrs,
3001 CachedTokens &OpenMPTokens,
3002 SourceLocation *EndLoc = nullptr);
3003 void ParseCXX11AttributeSpecifier(ParsedAttributes &Attrs,
3004 SourceLocation *EndLoc = nullptr) {
3005 CachedTokens OpenMPTokens;
3006 ParseCXX11AttributeSpecifierInternal(Attrs, OpenMPTokens, EndLoc);
3007 ReplayOpenMPAttributeTokens(OpenMPTokens);
3008 }
3009 void ParseCXX11Attributes(ParsedAttributes &attrs);
3010
3011
3012 bool ParseCXX11AttributeArgs(IdentifierInfo *AttrName,
3013 SourceLocation AttrNameLoc,
3014 ParsedAttributes &Attrs, SourceLocation *EndLoc,
3015 IdentifierInfo *ScopeName,
3016 SourceLocation ScopeLoc,
3017 CachedTokens &OpenMPTokens);
3018
3019
3020 bool ParseCXXAssumeAttributeArg(ParsedAttributes &Attrs,
3021 IdentifierInfo *AttrName,
3022 SourceLocation AttrNameLoc,
3023 SourceLocation *EndLoc,
3024 ParsedAttr::Form Form);
3025
3026 IdentifierInfo *TryParseCXX11AttributeIdentifier(
3027 SourceLocation &Loc,
3028 SemaCodeCompletion::AttributeCompletion Completion =
3029 SemaCodeCompletion::AttributeCompletion::None,
3030 const IdentifierInfo *EnclosingScope = nullptr);
3031
3032 bool MaybeParseHLSLAnnotations(Declarator &D,
3033 SourceLocation *EndLoc = nullptr,
3034 bool CouldBeBitField = false) {
3035 assert(getLangOpts().HLSL && "MaybeParseHLSLAnnotations is for HLSL only");
3036 if (Tok.is(tok::colon)) {
3037 ParsedAttributes Attrs(AttrFactory);
3038 ParseHLSLAnnotations(Attrs, EndLoc, CouldBeBitField);
3039 D.takeAttributes(Attrs);
3040 return true;
3041 }
3042 return false;
3043 }
3044
3045 void MaybeParseHLSLAnnotations(ParsedAttributes &Attrs,
3046 SourceLocation *EndLoc = nullptr) {
3047 assert(getLangOpts().HLSL && "MaybeParseHLSLAnnotations is for HLSL only");
3048 if (Tok.is(tok::colon))
3049 ParseHLSLAnnotations(Attrs, EndLoc);
3050 }
3051
3052 void ParseHLSLAnnotations(ParsedAttributes &Attrs,
3053 SourceLocation *EndLoc = nullptr,
3054 bool CouldBeBitField = false);
3055 Decl *ParseHLSLBuffer(SourceLocation &DeclEnd);
3056
3057 void MaybeParseMicrosoftAttributes(ParsedAttributes &Attrs) {
3058 if ((getLangOpts().MicrosoftExt || getLangOpts().HLSL) &&
3059 Tok.is(tok::l_square)) {
3060 ParsedAttributes AttrsWithRange(AttrFactory);
3061 ParseMicrosoftAttributes(AttrsWithRange);
3062 Attrs.takeAllFrom(AttrsWithRange);
3063 }
3064 }
3065 void ParseMicrosoftUuidAttributeArgs(ParsedAttributes &Attrs);
3066 void ParseMicrosoftAttributes(ParsedAttributes &Attrs);
3067 bool MaybeParseMicrosoftDeclSpecs(ParsedAttributes &Attrs) {
3068 if (getLangOpts().DeclSpecKeyword && Tok.is(tok::kw___declspec)) {
3069 ParseMicrosoftDeclSpecs(Attrs);
3070 return true;
3071 }
3072 return false;
3073 }
3074 void ParseMicrosoftDeclSpecs(ParsedAttributes &Attrs);
3075 bool ParseMicrosoftDeclSpecArgs(IdentifierInfo *AttrName,
3076 SourceLocation AttrNameLoc,
3077 ParsedAttributes &Attrs);
3078 void ParseMicrosoftTypeAttributes(ParsedAttributes &attrs);
3079 void ParseWebAssemblyFuncrefTypeAttribute(ParsedAttributes &Attrs);
3080 void DiagnoseAndSkipExtendedMicrosoftTypeAttributes();
3081 SourceLocation SkipExtendedMicrosoftTypeAttributes();
3082 void ParseMicrosoftInheritanceClassAttributes(ParsedAttributes &attrs);
3083 void ParseNullabilityClassAttributes(ParsedAttributes &attrs);
3084 void ParseBorlandTypeAttributes(ParsedAttributes &attrs);
3085 void ParseOpenCLKernelAttributes(ParsedAttributes &attrs);
3086 void ParseOpenCLQualifiers(ParsedAttributes &Attrs);
3087 void ParseNullabilityTypeSpecifiers(ParsedAttributes &attrs);
3088 void ParseCUDAFunctionAttributes(ParsedAttributes &attrs);
3089 bool isHLSLQualifier(const Token &Tok) const;
3090 void ParseHLSLQualifiers(ParsedAttributes &Attrs);
3091
3092 VersionTuple ParseVersionTuple(SourceRange &Range);
3093 void ParseAvailabilityAttribute(IdentifierInfo &Availability,
3094 SourceLocation AvailabilityLoc,
3095 ParsedAttributes &attrs,
3096 SourceLocation *endLoc,
3097 IdentifierInfo *ScopeName,
3098 SourceLocation ScopeLoc,
3099 ParsedAttr::Form Form);
3100
3101 std::optional<AvailabilitySpec> ParseAvailabilitySpec();
3102 ExprResult ParseAvailabilityCheckExpr(SourceLocation StartLoc);
3103
3104 void ParseExternalSourceSymbolAttribute(IdentifierInfo &ExternalSourceSymbol,
3105 SourceLocation Loc,
3106 ParsedAttributes &Attrs,
3107 SourceLocation *EndLoc,
3108 IdentifierInfo *ScopeName,
3109 SourceLocation ScopeLoc,
3110 ParsedAttr::Form Form);
3111
3112 void ParseObjCBridgeRelatedAttribute(IdentifierInfo &ObjCBridgeRelated,
3113 SourceLocation ObjCBridgeRelatedLoc,
3114 ParsedAttributes &Attrs,
3115 SourceLocation *EndLoc,
3116 IdentifierInfo *ScopeName,
3117 SourceLocation ScopeLoc,
3118 ParsedAttr::Form Form);
3119
3120 void ParseSwiftNewTypeAttribute(IdentifierInfo &AttrName,
3121 SourceLocation AttrNameLoc,
3122 ParsedAttributes &Attrs,
3123 SourceLocation *EndLoc,
3124 IdentifierInfo *ScopeName,
3125 SourceLocation ScopeLoc,
3126 ParsedAttr::Form Form);
3127
3128 void ParseTypeTagForDatatypeAttribute(IdentifierInfo &AttrName,
3129 SourceLocation AttrNameLoc,
3130 ParsedAttributes &Attrs,
3131 SourceLocation *EndLoc,
3132 IdentifierInfo *ScopeName,
3133 SourceLocation ScopeLoc,
3134 ParsedAttr::Form Form);
3135
3136 void ParseAttributeWithTypeArg(IdentifierInfo &AttrName,
3137 SourceLocation AttrNameLoc,
3138 ParsedAttributes &Attrs,
3139 IdentifierInfo *ScopeName,
3140 SourceLocation ScopeLoc,
3141 ParsedAttr::Form Form);
3142
3143 void DistributeCLateParsedAttrs(Decl *Dcl, LateParsedAttrList *LateAttrs);
3144
3145 void ParseBoundsAttribute(IdentifierInfo &AttrName,
3146 SourceLocation AttrNameLoc, ParsedAttributes &Attrs,
3147 IdentifierInfo *ScopeName, SourceLocation ScopeLoc,
3148 ParsedAttr::Form Form);
3149
3150 void ParseTypeofSpecifier(DeclSpec &DS);
3151 SourceLocation ParseDecltypeSpecifier(DeclSpec &DS);
3152 void AnnotateExistingDecltypeSpecifier(const DeclSpec &DS,
3153 SourceLocation StartLoc,
3154 SourceLocation EndLoc);
3155 void ParseAtomicSpecifier(DeclSpec &DS);
3156
3157 ExprResult ParseAlignArgument(StringRef KWName, SourceLocation Start,
3158 SourceLocation &EllipsisLoc, bool &IsType,
3159 ParsedType &Ty);
3160 void ParseAlignmentSpecifier(ParsedAttributes &Attrs,
3161 SourceLocation *endLoc = nullptr);
3162 ExprResult ParseExtIntegerArgument();
3163
3164 VirtSpecifiers::Specifier isCXX11VirtSpecifier(const Token &Tok) const;
3165 VirtSpecifiers::Specifier isCXX11VirtSpecifier() const {
3166 return isCXX11VirtSpecifier(Tok);
3167 }
3168 void ParseOptionalCXX11VirtSpecifierSeq(VirtSpecifiers &VS, bool IsInterface,
3169 SourceLocation FriendLoc);
3170
3171 bool isCXX11FinalKeyword() const;
3172 bool isClassCompatibleKeyword() const;
3173
3174
3175
3176
3177 class DeclaratorScopeObj {
3178 Parser &P;
3179 CXXScopeSpec &SS;
3180 bool EnteredScope;
3181 bool CreatedScope;
3182 public:
3183 DeclaratorScopeObj(Parser &p, CXXScopeSpec &ss)
3184 : P(p), SS(ss), EnteredScope(false), CreatedScope(false) {}
3185
3186 void EnterDeclaratorScope() {
3187 assert(!EnteredScope && "Already entered the scope!");
3188 assert(SS.isSet() && "C++ scope was not set!");
3189
3190 CreatedScope = true;
3191 P.EnterScope(0);
3192
3193 if (!P.Actions.ActOnCXXEnterDeclaratorScope(P.getCurScope(), SS))
3194 EnteredScope = true;
3195 }
3196
3197 ~DeclaratorScopeObj() {
3198 if (EnteredScope) {
3199 assert(SS.isSet() && "C++ scope was cleared ?");
3200 P.Actions.ActOnCXXExitDeclaratorScope(P.getCurScope(), SS);
3201 }
3202 if (CreatedScope)
3203 P.ExitScope();
3204 }
3205 };
3206
3207
3208 void ParseDeclarator(Declarator &D);
3209
3210 typedef void (Parser::*DirectDeclParseFunction)(Declarator&);
3211 void ParseDeclaratorInternal(Declarator &D,
3212 DirectDeclParseFunction DirectDeclParser);
3213
3214 enum AttrRequirements {
3215 AR_NoAttributesParsed = 0,
3216 AR_GNUAttributesParsedAndRejected = 1 << 0,
3217 AR_GNUAttributesParsed = 1 << 1,
3218 AR_CXX11AttributesParsed = 1 << 2,
3219 AR_DeclspecAttributesParsed = 1 << 3,
3220 AR_AllAttributesParsed = AR_GNUAttributesParsed |
3221 AR_CXX11AttributesParsed |
3222 AR_DeclspecAttributesParsed,
3223 AR_VendorAttributesParsed = AR_GNUAttributesParsed |
3224 AR_DeclspecAttributesParsed
3225 };
3226
3227 void ParseTypeQualifierListOpt(
3228 DeclSpec &DS, unsigned AttrReqs = AR_AllAttributesParsed,
3229 bool AtomicAllowed = true, bool IdentifierRequired = false,
3230 std::optional<llvm::function_ref<void()>> CodeCompletionHandler =
3231 std::nullopt);
3232 void ParseDirectDeclarator(Declarator &D);
3233 void ParseDecompositionDeclarator(Declarator &D);
3234 void ParseParenDeclarator(Declarator &D);
3235 void ParseFunctionDeclarator(Declarator &D, ParsedAttributes &FirstArgAttrs,
3236 BalancedDelimiterTracker &Tracker,
3237 bool IsAmbiguous, bool RequiresArg = false);
3238 void InitCXXThisScopeForDeclaratorIfRelevant(
3239 const Declarator &D, const DeclSpec &DS,
3240 std::optional<Sema::CXXThisScopeRAII> &ThisScope);
3241 bool ParseRefQualifier(bool &RefQualifierIsLValueRef,
3242 SourceLocation &RefQualifierLoc);
3243 bool isFunctionDeclaratorIdentifierList();
3244 void ParseFunctionDeclaratorIdentifierList(
3245 Declarator &D,
3246 SmallVectorImpl<DeclaratorChunk::ParamInfo> &ParamInfo);
3247 void ParseParameterDeclarationClause(
3248 Declarator &D, ParsedAttributes &attrs,
3249 SmallVectorImpl<DeclaratorChunk::ParamInfo> &ParamInfo,
3250 SourceLocation &EllipsisLoc) {
3251 return ParseParameterDeclarationClause(
3252 D.getContext(), attrs, ParamInfo, EllipsisLoc,
3253 D.getCXXScopeSpec().isSet() &&
3254 D.isFunctionDeclaratorAFunctionDeclaration());
3255 }
3256 void ParseParameterDeclarationClause(
3257 DeclaratorContext DeclaratorContext, ParsedAttributes &attrs,
3258 SmallVectorImpl<DeclaratorChunk::ParamInfo> &ParamInfo,
3259 SourceLocation &EllipsisLoc, bool IsACXXFunctionDeclaration = false);
3260
3261 void ParseBracketDeclarator(Declarator &D);
3262 void ParseMisplacedBracketDeclarator(Declarator &D);
3263 bool MaybeParseTypeTransformTypeSpecifier(DeclSpec &DS);
3264 DeclSpec::TST TypeTransformTokToDeclSpec();
3265
3266
3267
3268
3269
3270 enum CXX11AttributeKind {
3271
3272 CAK_NotAttributeSpecifier,
3273
3274 CAK_AttributeSpecifier,
3275
3276
3277 CAK_InvalidAttributeSpecifier
3278 };
3279 CXX11AttributeKind
3280 isCXX11AttributeSpecifier(bool Disambiguate = false,
3281 bool OuterMightBeMessageSend = false);
3282
3283 void DiagnoseUnexpectedNamespace(NamedDecl *Context);
3284
3285 DeclGroupPtrTy ParseNamespace(DeclaratorContext Context,
3286 SourceLocation &DeclEnd,
3287 SourceLocation InlineLoc = SourceLocation());
3288
3289 struct InnerNamespaceInfo {
3290 SourceLocation NamespaceLoc;
3291 SourceLocation InlineLoc;
3292 SourceLocation IdentLoc;
3293 IdentifierInfo *Ident;
3294 };
3295 using InnerNamespaceInfoList = llvm::SmallVector<InnerNamespaceInfo, 4>;
3296
3297 void ParseInnerNamespace(const InnerNamespaceInfoList &InnerNSs,
3298 unsigned int index, SourceLocation &InlineLoc,
3299 ParsedAttributes &attrs,
3300 BalancedDelimiterTracker &Tracker);
3301 Decl *ParseLinkage(ParsingDeclSpec &DS, DeclaratorContext Context);
3302 Decl *ParseExportDeclaration();
3303 DeclGroupPtrTy ParseUsingDirectiveOrDeclaration(
3304 DeclaratorContext Context, const ParsedTemplateInfo &TemplateInfo,
3305 SourceLocation &DeclEnd, ParsedAttributes &Attrs);
3306 Decl *ParseUsingDirective(DeclaratorContext Context,
3307 SourceLocation UsingLoc,
3308 SourceLocation &DeclEnd,
3309 ParsedAttributes &attrs);
3310
3311 struct UsingDeclarator {
3312 SourceLocation TypenameLoc;
3313 CXXScopeSpec SS;
3314 UnqualifiedId Name;
3315 SourceLocation EllipsisLoc;
3316
3317 void clear() {
3318 TypenameLoc = EllipsisLoc = SourceLocation();
3319 SS.clear();
3320 Name.clear();
3321 }
3322 };
3323
3324 bool ParseUsingDeclarator(DeclaratorContext Context, UsingDeclarator &D);
3325 DeclGroupPtrTy ParseUsingDeclaration(DeclaratorContext Context,
3326 const ParsedTemplateInfo &TemplateInfo,
3327 SourceLocation UsingLoc,
3328 SourceLocation &DeclEnd,
3329 ParsedAttributes &Attrs,
3330 AccessSpecifier AS = AS_none);
3331 Decl *ParseAliasDeclarationAfterDeclarator(
3332 const ParsedTemplateInfo &TemplateInfo, SourceLocation UsingLoc,
3333 UsingDeclarator &D, SourceLocation &DeclEnd, AccessSpecifier AS,
3334 ParsedAttributes &Attrs, Decl **OwnedType = nullptr);
3335
3336 Decl *ParseStaticAssertDeclaration(SourceLocation &DeclEnd);
3337 Decl *ParseNamespaceAlias(SourceLocation NamespaceLoc,
3338 SourceLocation AliasLoc, IdentifierInfo *Alias,
3339 SourceLocation &DeclEnd);
3340
3341
3342
3343 bool isValidAfterTypeSpecifier(bool CouldBeBitfield);
3344 void ParseClassSpecifier(tok::TokenKind TagTokKind, SourceLocation TagLoc,
3345 DeclSpec &DS, ParsedTemplateInfo &TemplateInfo,
3346 AccessSpecifier AS, bool EnteringContext,
3347 DeclSpecContext DSC, ParsedAttributes &Attributes);
3348 void SkipCXXMemberSpecification(SourceLocation StartLoc,
3349 SourceLocation AttrFixitLoc,
3350 unsigned TagType,
3351 Decl *TagDecl);
3352 void ParseCXXMemberSpecification(SourceLocation StartLoc,
3353 SourceLocation AttrFixitLoc,
3354 ParsedAttributes &Attrs, unsigned TagType,
3355 Decl *TagDecl);
3356 ExprResult ParseCXXMemberInitializer(Decl *D, bool IsFunction,
3357 SourceLocation &EqualLoc);
3358 bool
3359 ParseCXXMemberDeclaratorBeforeInitializer(Declarator &DeclaratorInfo,
3360 VirtSpecifiers &VS,
3361 ExprResult &BitfieldSize,
3362 LateParsedAttrList &LateAttrs);
3363 void MaybeParseAndDiagnoseDeclSpecAfterCXX11VirtSpecifierSeq(Declarator &D,
3364 VirtSpecifiers &VS);
3365 DeclGroupPtrTy ParseCXXClassMemberDeclaration(
3366 AccessSpecifier AS, ParsedAttributes &Attr,
3367 ParsedTemplateInfo &TemplateInfo,
3368 ParsingDeclRAIIObject *DiagsFromTParams = nullptr);
3369 DeclGroupPtrTy
3370 ParseCXXClassMemberDeclarationWithPragmas(AccessSpecifier &AS,
3371 ParsedAttributes &AccessAttrs,
3372 DeclSpec::TST TagType, Decl *Tag);
3373 void ParseConstructorInitializer(Decl *ConstructorDecl);
3374 MemInitResult ParseMemInitializer(Decl *ConstructorDecl);
3375 void HandleMemberFunctionDeclDelays(Declarator& DeclaratorInfo,
3376 Decl *ThisDecl);
3377
3378
3379
3380 TypeResult ParseBaseTypeSpecifier(SourceLocation &BaseLoc,
3381 SourceLocation &EndLocation);
3382 void ParseBaseClause(Decl *ClassDecl);
3383 BaseResult ParseBaseSpecifier(Decl *ClassDecl);
3384 AccessSpecifier getAccessSpecifierIfPresent() const;
3385
3386 bool ParseUnqualifiedIdTemplateId(CXXScopeSpec &SS,
3387 ParsedType ObjectType,
3388 bool ObjectHadErrors,
3389 SourceLocation TemplateKWLoc,
3390 IdentifierInfo *Name,
3391 SourceLocation NameLoc,
3392 bool EnteringContext,
3393 UnqualifiedId &Id,
3394 bool AssumeTemplateId);
3395 bool ParseUnqualifiedIdOperator(CXXScopeSpec &SS, bool EnteringContext,
3396 ParsedType ObjectType,
3397 UnqualifiedId &Result);
3398
3399
3400
3401
3402 DeclGroupPtrTy ParseOMPDeclareSimdClauses(DeclGroupPtrTy Ptr,
3403 CachedTokens &Toks,
3404 SourceLocation Loc);
3405
3406
3407
3408 void parseOMPTraitPropertyKind(OMPTraitProperty &TIProperty,
3409 llvm::omp::TraitSet Set,
3410 llvm::omp::TraitSelector Selector,
3411 llvm::StringMap<SourceLocation> &Seen);
3412
3413
3414 void parseOMPTraitSelectorKind(OMPTraitSelector &TISelector,
3415 llvm::omp::TraitSet Set,
3416 llvm::StringMap<SourceLocation> &Seen);
3417
3418
3419 void parseOMPTraitSetKind(OMPTraitSet &TISet,
3420 llvm::StringMap<SourceLocation> &Seen);
3421
3422
3423 void parseOMPContextProperty(OMPTraitSelector &TISelector,
3424 llvm::omp::TraitSet Set,
3425 llvm::StringMap<SourceLocation> &Seen);
3426
3427
3428 void parseOMPContextSelector(OMPTraitSelector &TISelector,
3429 llvm::omp::TraitSet Set,
3430 llvm::StringMap<SourceLocation> &SeenSelectors);
3431
3432
3433 void parseOMPContextSelectorSet(OMPTraitSet &TISet,
3434 llvm::StringMap<SourceLocation> &SeenSets);
3435
3436
3437 bool parseOMPContextSelectors(SourceLocation Loc, OMPTraitInfo &TI);
3438
3439
3440 bool parseOpenMPAppendArgs(SmallVectorImpl<OMPInteropInfo> &InteropInfos);
3441
3442
3443
3444 bool parseOMPDeclareVariantMatchClause(SourceLocation Loc, OMPTraitInfo &TI,
3445 OMPTraitInfo *ParentTI);
3446
3447
3448 void ParseOMPDeclareVariantClauses(DeclGroupPtrTy Ptr, CachedTokens &Toks,
3449 SourceLocation Loc);
3450
3451
3452 void ParseOpenMPAssumesDirective(OpenMPDirectiveKind DKind,
3453 SourceLocation Loc);
3454
3455
3456 void ParseOpenMPEndAssumesDirective(SourceLocation Loc);
3457
3458
3459
3460
3461
3462
3463 void ParseOpenMPClauses(OpenMPDirectiveKind DKind,
3464 SmallVectorImpl<clang::OMPClause *> &Clauses,
3465 SourceLocation Loc);
3466
3467
3468 void ParseOMPDeclareTargetClauses(SemaOpenMP::DeclareTargetContextInfo &DTCI);
3469
3470
3471 void ParseOMPEndDeclareTargetDirective(OpenMPDirectiveKind BeginDKind,
3472 OpenMPDirectiveKind EndDKind,
3473 SourceLocation Loc);
3474
3475
3476
3477 void skipUntilPragmaOpenMPEnd(OpenMPDirectiveKind DKind);
3478
3479
3480
3481
3482
3483 void parseOMPEndDirective(OpenMPDirectiveKind BeginKind,
3484 OpenMPDirectiveKind ExpectedKind,
3485 OpenMPDirectiveKind FoundKind,
3486 SourceLocation MatchingLoc,
3487 SourceLocation FoundLoc,
3488 bool SkipUntilOpenMPEnd);
3489
3490
3491 DeclGroupPtrTy ParseOpenMPDeclarativeDirectiveWithExtDecl(
3492 AccessSpecifier &AS, ParsedAttributes &Attrs, bool Delayed = false,
3493 DeclSpec::TST TagType = DeclSpec::TST_unspecified,
3494 Decl *TagDecl = nullptr);
3495
3496 DeclGroupPtrTy ParseOpenMPDeclareReductionDirective(AccessSpecifier AS);
3497
3498
3499 void ParseOpenMPReductionInitializerForDecl(VarDecl *OmpPrivParm);
3500
3501
3502 DeclGroupPtrTy ParseOpenMPDeclareMapperDirective(AccessSpecifier AS);
3503
3504 TypeResult parseOpenMPDeclareMapperVarDecl(SourceRange &Range,
3505 DeclarationName &Name,
3506 AccessSpecifier AS = AS_none);
3507
3508
3509
3510 bool tryParseOpenMPArrayShapingCastPart();
3511
3512
3513
3514
3515
3516
3517
3518
3519 bool ParseOpenMPSimpleVarList(
3520 OpenMPDirectiveKind Kind,
3521 const llvm::function_ref<void(CXXScopeSpec &, DeclarationNameInfo)> &
3522 Callback,
3523 bool AllowScopeSpecifier);
3524
3525
3526
3527
3528
3529 StmtResult ParseOpenMPDeclarativeOrExecutableDirective(
3530 ParsedStmtContext StmtCtx, bool ReadDirectiveWithinMetadirective = false);
3531
3532
3533
3534
3535
3536
3537
3538
3539 StmtResult
3540 ParseOpenMPExecutableDirective(ParsedStmtContext StmtCtx,
3541 OpenMPDirectiveKind DKind, SourceLocation Loc,
3542 bool ReadDirectiveWithinMetadirective);
3543
3544
3545
3546
3547
3548
3549
3550
3551 StmtResult ParseOpenMPInformationalDirective(
3552 ParsedStmtContext StmtCtx, OpenMPDirectiveKind DKind, SourceLocation Loc,
3553 bool ReadDirectiveWithinMetadirective);
3554
3555
3556
3557
3558
3559
3560
3561
3562 OMPClause *ParseOpenMPClause(OpenMPDirectiveKind DKind,
3563 OpenMPClauseKind CKind, bool FirstClause);
3564
3565
3566
3567
3568
3569
3570 OMPClause *ParseOpenMPSingleExprClause(OpenMPClauseKind Kind,
3571 bool ParseOnly);
3572
3573
3574
3575
3576
3577
3578 OMPClause *ParseOpenMPSimpleClause(OpenMPClauseKind Kind, bool ParseOnly);
3579
3580
3581
3582 bool ParseOpenMPIndirectClause(SemaOpenMP::DeclareTargetContextInfo &DTCI,
3583 bool ParseOnly);
3584
3585
3586
3587
3588
3589
3590
3591
3592 OMPClause *ParseOpenMPSingleExprWithArgClause(OpenMPDirectiveKind DKind,
3593 OpenMPClauseKind Kind,
3594 bool ParseOnly);
3595
3596
3597 OMPClause *ParseOpenMPSizesClause();
3598
3599
3600 OMPClause *ParseOpenMPPermutationClause();
3601
3602
3603
3604
3605
3606
3607
3608 OMPClause *ParseOpenMPClause(OpenMPClauseKind Kind, bool ParseOnly = false);
3609
3610
3611
3612
3613
3614
3615 OMPClause *ParseOpenMPVarListClause(OpenMPDirectiveKind DKind,
3616 OpenMPClauseKind Kind, bool ParseOnly);
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628 bool ParseOpenMPExprListClause(OpenMPClauseKind Kind,
3629 SourceLocation &ClauseNameLoc,
3630 SourceLocation &OpenLoc,
3631 SourceLocation &CloseLoc,
3632 SmallVectorImpl<Expr *> &Exprs,
3633 bool ReqIntConst = false);
3634
3635
3636
3637
3638 ExprResult ParseOpenMPIteratorsExpr();
3639
3640
3641
3642
3643 OMPClause *ParseOpenMPUsesAllocatorClause(OpenMPDirectiveKind DKind);
3644
3645
3646 bool ParseOMPInteropInfo(OMPInteropInfo &InteropInfo, OpenMPClauseKind Kind);
3647
3648
3649
3650
3651
3652
3653
3654 OMPClause *ParseOpenMPInteropClause(OpenMPClauseKind Kind, bool ParseOnly);
3655
3656
3657
3658
3659
3660
3661 OMPClause *ParseOpenMPOMPXAttributesClause(bool ParseOnly);
3662
3663 public:
3664
3665
3666
3667 ExprResult ParseOpenMPParensExpr(StringRef ClauseName, SourceLocation &RLoc,
3668 bool IsAddressOfOperand = false);
3669
3670
3671 bool ParseOpenMPReservedLocator(OpenMPClauseKind Kind,
3672 SemaOpenMP::OpenMPVarListDataTy &Data,
3673 const LangOptions &LangOpts);
3674
3675 bool ParseOpenMPVarList(OpenMPDirectiveKind DKind, OpenMPClauseKind Kind,
3676 SmallVectorImpl<Expr *> &Vars,
3677 SemaOpenMP::OpenMPVarListDataTy &Data);
3678 bool ParseUnqualifiedId(CXXScopeSpec &SS, ParsedType ObjectType,
3679 bool ObjectHadErrors, bool EnteringContext,
3680 bool AllowDestructorName, bool AllowConstructorName,
3681 bool AllowDeductionGuide,
3682 SourceLocation *TemplateKWLoc, UnqualifiedId &Result);
3683
3684
3685 bool parseMapperModifier(SemaOpenMP::OpenMPVarListDataTy &Data);
3686
3687
3688
3689 bool parseMapTypeModifiers(SemaOpenMP::OpenMPVarListDataTy &Data);
3690
3691
3692
3693
3694
3695
3696
3697 public:
3698 DeclGroupPtrTy ParseOpenACCDirectiveDecl();
3699 StmtResult ParseOpenACCDirectiveStmt();
3700
3701 private:
3702
3703
3704
3705 struct OpenACCDirectiveParseInfo {
3706 OpenACCDirectiveKind DirKind;
3707 SourceLocation StartLoc;
3708 SourceLocation DirLoc;
3709 SourceLocation LParenLoc;
3710 SourceLocation RParenLoc;
3711 SourceLocation EndLoc;
3712 SourceLocation MiscLoc;
3713 SmallVector<Expr *> Exprs;
3714 SmallVector<OpenACCClause *> Clauses;
3715
3716
3717 };
3718
3719 struct OpenACCWaitParseInfo {
3720 bool Failed = false;
3721 Expr *DevNumExpr = nullptr;
3722 SourceLocation QueuesLoc;
3723 SmallVector<Expr *> QueueIdExprs;
3724
3725 SmallVector<Expr *> getAllExprs() {
3726 SmallVector<Expr *> Out;
3727 Out.push_back(DevNumExpr);
3728 Out.insert(Out.end(), QueueIdExprs.begin(), QueueIdExprs.end());
3729 return Out;
3730 }
3731 };
3732
3733
3734
3735 enum class OpenACCParseCanContinue { Cannot = 0, Can = 1 };
3736
3737
3738
3739
3740
3741 using OpenACCClauseParseResult =
3742 llvm::PointerIntPair<OpenACCClause *, 1, OpenACCParseCanContinue>;
3743
3744 OpenACCClauseParseResult OpenACCCanContinue();
3745 OpenACCClauseParseResult OpenACCCannotContinue();
3746 OpenACCClauseParseResult OpenACCSuccess(OpenACCClause *Clause);
3747
3748
3749
3750 OpenACCDirectiveParseInfo ParseOpenACCDirective();
3751
3752 ExprResult ParseOpenACCIDExpression();
3753
3754 void ParseOpenACCCacheVarList();
3755
3756 using OpenACCVarParseResult = std::pair<ExprResult, OpenACCParseCanContinue>;
3757
3758 OpenACCVarParseResult ParseOpenACCVar(OpenACCClauseKind CK);
3759
3760 llvm::SmallVector<Expr *> ParseOpenACCVarList(OpenACCClauseKind CK);
3761
3762
3763 OpenACCClauseParseResult
3764 ParseOpenACCClauseParams(ArrayRef<const OpenACCClause *> ExistingClauses,
3765 OpenACCDirectiveKind DirKind, OpenACCClauseKind Kind,
3766 SourceLocation ClauseLoc);
3767
3768
3769 OpenACCClauseParseResult
3770 ParseOpenACCClause(ArrayRef<const OpenACCClause *> ExistingClauses,
3771 OpenACCDirectiveKind DirKind);
3772
3773 SmallVector<OpenACCClause *>
3774 ParseOpenACCClauseList(OpenACCDirectiveKind DirKind);
3775 OpenACCWaitParseInfo ParseOpenACCWaitArgument(SourceLocation Loc,
3776 bool IsDirective);
3777
3778
3779 ExprResult ParseOpenACCBindClauseArgument();
3780
3781
3782
3783
3784 using OpenACCIntExprParseResult =
3785 std::pair<ExprResult, OpenACCParseCanContinue>;
3786
3787
3788 OpenACCIntExprParseResult ParseOpenACCIntExpr(OpenACCDirectiveKind DK,
3789 OpenACCClauseKind CK,
3790 SourceLocation Loc);
3791
3792
3793 bool ParseOpenACCIntExprList(OpenACCDirectiveKind DK, OpenACCClauseKind CK,
3794 SourceLocation Loc,
3795 llvm::SmallVectorImpl<Expr *> &IntExprs);
3796
3797 bool ParseOpenACCDeviceTypeList(
3798 llvm::SmallVector<std::pair<IdentifierInfo *, SourceLocation>> &Archs);
3799
3800
3801 OpenACCIntExprParseResult ParseOpenACCAsyncArgument(OpenACCDirectiveKind DK,
3802 OpenACCClauseKind CK,
3803 SourceLocation Loc);
3804
3805
3806
3807 ExprResult ParseOpenACCSizeExpr(OpenACCClauseKind CK);
3808
3809 bool ParseOpenACCSizeExprList(OpenACCClauseKind CK,
3810 llvm::SmallVectorImpl<Expr *> &SizeExprs);
3811
3812 bool ParseOpenACCGangArgList(SourceLocation GangLoc,
3813 llvm::SmallVectorImpl<OpenACCGangKind> &GKs,
3814 llvm::SmallVectorImpl<Expr *> &IntExprs);
3815
3816 using OpenACCGangArgRes = std::pair<OpenACCGangKind, ExprResult>;
3817
3818
3819
3820 OpenACCGangArgRes ParseOpenACCGangArg(SourceLocation GangLoc);
3821
3822 ExprResult ParseOpenACCConditionExpr();
3823
3824 private:
3825
3826
3827
3828
3829 DeclGroupPtrTy
3830 ParseDeclarationStartingWithTemplate(DeclaratorContext Context,
3831 SourceLocation &DeclEnd,
3832 ParsedAttributes &AccessAttrs);
3833 DeclGroupPtrTy ParseTemplateDeclarationOrSpecialization(
3834 DeclaratorContext Context, SourceLocation &DeclEnd,
3835 ParsedAttributes &AccessAttrs, AccessSpecifier AS);
3836 DeclGroupPtrTy ParseDeclarationAfterTemplate(
3837 DeclaratorContext Context, ParsedTemplateInfo &TemplateInfo,
3838 ParsingDeclRAIIObject &DiagsFromParams, SourceLocation &DeclEnd,
3839 ParsedAttributes &AccessAttrs, AccessSpecifier AS = AS_none);
3840 bool ParseTemplateParameters(MultiParseScope &TemplateScopes, unsigned Depth,
3841 SmallVectorImpl<NamedDecl *> &TemplateParams,
3842 SourceLocation &LAngleLoc,
3843 SourceLocation &RAngleLoc);
3844 bool ParseTemplateParameterList(unsigned Depth,
3845 SmallVectorImpl<NamedDecl*> &TemplateParams);
3846 TPResult isStartOfTemplateTypeParameter();
3847 NamedDecl *ParseTemplateParameter(unsigned Depth, unsigned Position);
3848 NamedDecl *ParseTypeParameter(unsigned Depth, unsigned Position);
3849 NamedDecl *ParseTemplateTemplateParameter(unsigned Depth, unsigned Position);
3850 NamedDecl *ParseNonTypeTemplateParameter(unsigned Depth, unsigned Position);
3851 bool isTypeConstraintAnnotation();
3852 bool TryAnnotateTypeConstraint();
3853 void DiagnoseMisplacedEllipsis(SourceLocation EllipsisLoc,
3854 SourceLocation CorrectLoc,
3855 bool AlreadyHasEllipsis,
3856 bool IdentifierHasName);
3857 void DiagnoseMisplacedEllipsisInDeclarator(SourceLocation EllipsisLoc,
3858 Declarator &D);
3859
3860 typedef SmallVector<ParsedTemplateArgument, 16> TemplateArgList;
3861
3862 bool ParseGreaterThanInTemplateList(SourceLocation LAngleLoc,
3863 SourceLocation &RAngleLoc,
3864 bool ConsumeLastToken,
3865 bool ObjCGenericList);
3866 bool ParseTemplateIdAfterTemplateName(bool ConsumeLastToken,
3867 SourceLocation &LAngleLoc,
3868 TemplateArgList &TemplateArgs,
3869 SourceLocation &RAngleLoc,
3870 TemplateTy NameHint = nullptr);
3871
3872 bool AnnotateTemplateIdToken(TemplateTy Template, TemplateNameKind TNK,
3873 CXXScopeSpec &SS,
3874 SourceLocation TemplateKWLoc,
3875 UnqualifiedId &TemplateName,
3876 bool AllowTypeAnnotation = true,
3877 bool TypeConstraint = false);
3878 void
3879 AnnotateTemplateIdTokenAsType(CXXScopeSpec &SS,
3880 ImplicitTypenameContext AllowImplicitTypename,
3881 bool IsClassName = false);
3882 bool ParseTemplateArgumentList(TemplateArgList &TemplateArgs,
3883 TemplateTy Template, SourceLocation OpenLoc);
3884 ParsedTemplateArgument ParseTemplateTemplateArgument();
3885 ParsedTemplateArgument ParseTemplateArgument();
3886 DeclGroupPtrTy ParseExplicitInstantiation(DeclaratorContext Context,
3887 SourceLocation ExternLoc,
3888 SourceLocation TemplateLoc,
3889 SourceLocation &DeclEnd,
3890 ParsedAttributes &AccessAttrs,
3891 AccessSpecifier AS = AS_none);
3892
3893 Decl *
3894 ParseConceptDefinition(const ParsedTemplateInfo &TemplateInfo,
3895 SourceLocation &DeclEnd);
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906 TypeResult ParseTypeFromString(StringRef TypeStr, StringRef Context,
3907 SourceLocation IncludeLoc);
3908
3909
3910
3911 DeclGroupPtrTy ParseModuleDecl(Sema::ModuleImportState &ImportState);
3912 Decl *ParseModuleImport(SourceLocation AtLoc,
3913 Sema::ModuleImportState &ImportState);
3914 bool parseMisplacedModuleImport();
3915 bool tryParseMisplacedModuleImport() {
3916 tok::TokenKind Kind = Tok.getKind();
3917 if (Kind == tok::annot_module_begin || Kind == tok::annot_module_end ||
3918 Kind == tok::annot_module_include)
3919 return parseMisplacedModuleImport();
3920 return false;
3921 }
3922
3923 bool ParseModuleName(
3924 SourceLocation UseLoc,
3925 SmallVectorImpl<std::pair<IdentifierInfo *, SourceLocation>> &Path,
3926 bool IsImport);
3927
3928
3929
3930 ExprResult ParseTypeTrait();
3931
3932
3933
3934 ExprResult ParseArrayTypeTrait();
3935 ExprResult ParseExpressionTrait();
3936
3937 ExprResult ParseBuiltinPtrauthTypeDiscriminator();
3938
3939
3940
3941 void CodeCompleteDirective(bool InConditional) override;
3942 void CodeCompleteInConditionalExclusion() override;
3943 void CodeCompleteMacroName(bool IsDefinition) override;
3944 void CodeCompletePreprocessorExpression() override;
3945 void CodeCompleteMacroArgument(IdentifierInfo *Macro, MacroInfo *MacroInfo,
3946 unsigned ArgumentIndex) override;
3947 void CodeCompleteIncludedFile(llvm::StringRef Dir, bool IsAngled) override;
3948 void CodeCompleteNaturalLanguage() override;
3949
3950 class GNUAsmQualifiers {
3951 unsigned Qualifiers = AQ_unspecified;
3952
3953 public:
3954 enum AQ {
3955 AQ_unspecified = 0,
3956 AQ_volatile = 1,
3957 AQ_inline = 2,
3958 AQ_goto = 4,
3959 };
3960 static const char *getQualifierName(AQ Qualifier);
3961 bool setAsmQualifier(AQ Qualifier);
3962 inline bool isVolatile() const { return Qualifiers & AQ_volatile; };
3963 inline bool isInline() const { return Qualifiers & AQ_inline; };
3964 inline bool isGoto() const { return Qualifiers & AQ_goto; }
3965 };
3966 bool isGCCAsmStatement(const Token &TokAfterAsm) const;
3967 bool isGNUAsmQualifier(const Token &TokAfterAsm) const;
3968 GNUAsmQualifiers::AQ getGNUAsmQualifier(const Token &Tok) const;
3969 bool parseGNUAsmQualifierListOpt(GNUAsmQualifiers &AQ);
3970 };
3971
3972 }
3973
3974 #endif