315 return Actions.incrementMSManglingNumber();
364 assert(!isTokenSpecial() &&
365 "Should consume special tokens with Consume*Token");
366 PrevTokLocation = Tok.getLocation();
368 return PrevTokLocation;
374 assert(!isTokenSpecial() &&
375 "Should consume special tokens with Consume*Token");
376 PrevTokLocation = Tok.getLocation();
384 Loc = PrevTokLocation;
393 return ConsumeParen();
394 if (isTokenBracket())
395 return ConsumeBracket();
397 return ConsumeBrace();
398 if (isTokenStringLiteral())
399 return ConsumeStringToken();
400 if (Tok.is(tok::code_completion))
401 return ConsumeCodeCompletionTok ? ConsumeCodeCompletionToken()
402 : handleUnexpectedCodeCompletionToken();
403 if (Tok.isAnnotation())
404 return ConsumeAnnotationToken();
418 if (N == 0 || Tok.is(tok::eof))
420 return PP.LookAhead(N - 1);
429 if (!Tok.getAnnotationValue())
464 bool IsAddressOfOperand =
false);
490 (Tok.is(tok::identifier) || Tok.is(tok::coloncolon) ||
491 (Tok.is(tok::annot_template_id) &&
493 Tok.is(tok::kw_decltype) || Tok.is(tok::kw___super));
510 ParseScope(
const ParseScope &) =
delete;
511 void operator=(
const ParseScope &) =
delete;
518 bool BeforeCompoundStmt =
false)
520 if (EnteredScope && !BeforeCompoundStmt)
521 Self->EnterScope(ScopeFlags);
523 if (BeforeCompoundStmt)
524 Self->incrementMSManglingNumber();
526 this->Self = nullptr;
544 class MultiParseScope {
546 unsigned NumScopes = 0;
548 MultiParseScope(
const MultiParseScope &) =
delete;
553 Self.EnterScope(ScopeFlags);
595 static_cast<unsigned>(R));
650 unsigned short ParenCount = 0, BracketCount = 0,
BraceCount = 0;
651 unsigned short MisplacedModuleBeginCount = 0;
662 static constexpr int ScopeCacheSize = 16;
663 unsigned NumCachedScopes;
664 Scope *ScopeCache[ScopeCacheSize];
670 *Ident_GetExceptionCode;
673 *Ident_GetExceptionInfo;
675 IdentifierInfo *Ident__abnormal_termination, *Ident___abnormal_termination,
676 *Ident_AbnormalTermination;
682 std::unique_ptr<CommentHandler> CommentSemaHandler;
687 bool CalledSignatureHelp =
false;
689 bool isTokenSEHExcept();
695 bool SkipFunctionBodies;
702 bool isTokenParen()
const {
return Tok.isOneOf(tok::l_paren, tok::r_paren); }
704 bool isTokenBracket()
const {
705 return Tok.isOneOf(tok::l_square, tok::r_square);
708 bool isTokenBrace()
const {
return Tok.isOneOf(tok::l_brace, tok::r_brace); }
710 bool isTokenStringLiteral()
const {
714 bool isTokenSpecial()
const {
715 return isTokenStringLiteral() || isTokenParen() || isTokenBracket() ||
716 isTokenBrace() || Tok.is(tok::code_completion) || Tok.isAnnotation();
721 bool isTokenEqualOrEqualTypo();
725 void UnconsumeToken(Token &Consumed) {
727 PP.EnterToken(Consumed,
true);
729 PP.EnterToken(
Next,
true);
732 SourceLocation ConsumeAnnotationToken() {
733 assert(Tok.isAnnotation() &&
"wrong consume method");
734 SourceLocation Loc = Tok.getLocation();
735 PrevTokLocation = Tok.getAnnotationEndLoc();
742 SourceLocation ConsumeParen() {
743 assert(isTokenParen() &&
"wrong consume method");
744 if (Tok.getKind() == tok::l_paren)
746 else if (ParenCount) {
747 AngleBrackets.clear(*
this);
750 PrevTokLocation = Tok.getLocation();
752 return PrevTokLocation;
757 SourceLocation ConsumeBracket() {
758 assert(isTokenBracket() &&
"wrong consume method");
759 if (Tok.getKind() == tok::l_square)
761 else if (BracketCount) {
762 AngleBrackets.clear(*
this);
766 PrevTokLocation = Tok.getLocation();
768 return PrevTokLocation;
773 SourceLocation ConsumeBrace() {
774 assert(isTokenBrace() &&
"wrong consume method");
775 if (Tok.getKind() == tok::l_brace)
777 else if (BraceCount) {
778 AngleBrackets.clear(*
this);
782 PrevTokLocation = Tok.getLocation();
784 return PrevTokLocation;
791 SourceLocation ConsumeStringToken() {
792 assert(isTokenStringLiteral() &&
793 "Should only consume string literals with this method");
794 PrevTokLocation = Tok.getLocation();
796 return PrevTokLocation;
804 SourceLocation ConsumeCodeCompletionToken() {
805 assert(Tok.is(tok::code_completion));
806 PrevTokLocation = Tok.getLocation();
808 return PrevTokLocation;
816 SourceLocation handleUnexpectedCodeCompletionToken();
820 void cutOffParsing() {
821 if (PP.isCodeCompletionEnabled())
822 PP.setCodeCompletionReached();
824 Tok.setKind(tok::eof);
831 return Kind == tok::eof ||
Kind == tok::annot_module_begin ||
832 Kind == tok::annot_module_end ||
Kind == tok::annot_module_include ||
833 Kind == tok::annot_repl_input_end;
836 static void setTypeAnnotation(Token &Tok,
TypeResult T) {
837 assert((
T.isInvalid() ||
T.get()) &&
838 "produced a valid-but-null type annotation?");
839 Tok.setAnnotationValue(
T.isInvalid() ?
nullptr :
T.get().getAsOpaquePtr());
842 static NamedDecl *getNonTypeAnnotation(
const Token &Tok) {
843 return static_cast<NamedDecl *
>(Tok.getAnnotationValue());
846 static void setNonTypeAnnotation(Token &Tok, NamedDecl *ND) {
847 Tok.setAnnotationValue(ND);
850 static IdentifierInfo *getIdentifierAnnotation(
const Token &Tok) {
851 return static_cast<IdentifierInfo *
>(Tok.getAnnotationValue());
854 static void setIdentifierAnnotation(Token &Tok, IdentifierInfo *ND) {
855 Tok.setAnnotationValue(ND);
860 static ExprResult getExprAnnotation(
const Token &Tok) {
861 return ExprResult::getFromOpaquePointer(Tok.getAnnotationValue());
866 static void setExprAnnotation(Token &Tok,
ExprResult ER) {
867 Tok.setAnnotationValue(ER.getAsOpaquePointer());
881 TryAnnotateName(CorrectionCandidateCallback *CCC =
nullptr,
886 void AnnotateScopeToken(CXXScopeSpec &SS,
bool IsNewAnnotation);
893 bool TryKeywordIdentFallback(
bool DisableKeyword);
898 TemplateIdAnnotation *takeTemplateIdAnnotation(
const Token &tok);
909 unsigned Diag = diag::err_expected,
910 StringRef DiagMsg =
"");
917 bool ExpectAndConsumeSemi(
unsigned DiagID, StringRef TokenUsed =
"");
922 bool isLikelyAtStartOfNewDeclaration();
933 bool expectIdentifier();
936 enum class CompoundToken {
951 void checkCompoundToken(SourceLocation FirstTokLoc,
954 void diagnoseUseOfC11Keyword(
const Token &Tok);
957 class ParseScopeFlags {
959 unsigned OldFlags = 0;
960 ParseScopeFlags(
const ParseScopeFlags &) =
delete;
961 void operator=(
const ParseScopeFlags &) =
delete;
966 ParseScopeFlags(
Parser *
Self,
unsigned ScopeFlags,
bool ManageFlags =
true);
980 void SuggestParentheses(SourceLocation Loc,
unsigned DK,
981 SourceRange ParenRange);
1017 DeclGroupPtrTy ParseExternalDeclaration(ParsedAttributes &DeclAttrs,
1018 ParsedAttributes &DeclSpecAttrs,
1019 ParsingDeclSpec *DS =
nullptr);
1023 bool isDeclarationAfterDeclarator();
1027 bool isStartOfFunctionDefinition(
const ParsingDeclarator &Declarator);
1030 ParsedAttributes &DeclAttrs, ParsedAttributes &DeclSpecAttrs,
1051 DeclGroupPtrTy ParseDeclOrFunctionDefInternal(ParsedAttributes &Attrs,
1052 ParsedAttributes &DeclSpecAttrs,
1053 ParsingDeclSpec &DS,
1056 void SkipFunctionBody();
1058 struct ParsedTemplateInfo;
1076 Decl *ParseFunctionDefinition(
1077 ParsingDeclarator &D,
1078 const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo(),
1079 LateParsedAttrList *LateParsedAttrs =
nullptr);
1083 void ParseKNRParamDeclarations(Declarator &D);
1093 ExprResult ParseSimpleAsm(
bool ForAsmLabel, SourceLocation *EndLoc);
1106 ExprResult ParseAsmStringLiteral(
bool ForAsmLabel);
1110 struct IfExistsCondition {
1112 SourceLocation KeywordLoc;
1128 bool ParseMicrosoftIfExistsCondition(IfExistsCondition &
Result);
1129 void ParseMicrosoftIfExistsExternalDeclaration();
1168 Decl *ParseModuleImport(SourceLocation AtLoc,
1175 bool parseMisplacedModuleImport();
1177 bool tryParseMisplacedModuleImport() {
1179 if (Kind == tok::annot_module_begin || Kind == tok::annot_module_end ||
1180 Kind == tok::annot_module_include)
1181 return parseMisplacedModuleImport();
1194 bool ParseModuleName(SourceLocation UseLoc,
1195 SmallVectorImpl<IdentifierLoc> &Path,
bool IsImport);
1198 void DiagnoseInvalidCXXModuleImport();
1202 void CodeCompleteDirective(
bool InConditional)
override;
1204 void CodeCompleteMacroName(
bool IsDefinition)
override;
1206 void CodeCompleteMacroArgument(IdentifierInfo *
Macro, MacroInfo *MacroInfo,
1207 unsigned ArgumentIndex)
override;
1208 void CodeCompleteIncludedFile(llvm::StringRef Dir,
bool IsAngled)
override;
1210 void CodeCompleteModuleImport(SourceLocation ImportLoc,
1229 struct ParsingClass;
1235 LateParsedClass(
Parser *P, ParsingClass *
C);
1236 ~LateParsedClass()
override;
1245 LateParsedClass(
const LateParsedClass &) =
delete;
1246 LateParsedClass &operator=(
const LateParsedClass &) =
delete;
1250 ParsingClass *
Class;
1264 :
Self(P), AS(AS) {}
1266 void takeToks(
CachedTokens &Cached) { Toks.swap(Cached); }
1276 struct LexedMethod :
public LateParsedDeclaration {
1281 explicit LexedMethod(
Parser *P, Decl *MD) : Self(P), D(MD) {}
1290 struct LateParsedDefaultArgument {
1291 explicit LateParsedDefaultArgument(
1292 Decl *P, std::unique_ptr<CachedTokens> Toks =
nullptr)
1293 : Param(P), Toks(std::move(Toks)) {}
1302 std::unique_ptr<CachedTokens> Toks;
1309 struct LateParsedMethodDeclaration :
public LateParsedDeclaration {
1310 explicit LateParsedMethodDeclaration(
Parser *P, Decl *M)
1311 : Self(P), Method(M), ExceptionSpecTokens(
nullptr) {}
1325 SmallVector<LateParsedDefaultArgument, 8> DefaultArgs;
1335 struct LateParsedMemberInitializer :
public LateParsedDeclaration {
1336 LateParsedMemberInitializer(
Parser *P, Decl *FD) : Self(P), Field(FD) {}
1356 typedef SmallVector<LateParsedDeclaration *, 2>
1357 LateParsedDeclarationsContainer;
1371 const ParsedAttributesView &AccessAttrs,
1372 ParsingDeclarator &D,
1373 const ParsedTemplateInfo &TemplateInfo,
1374 const VirtSpecifiers &VS,
1375 SourceLocation PureSpecLoc);
1378 StringLiteral *ParseCXXDeletedFunctionMessage();
1383 void SkipDeletedFunctionBody();
1389 void ParseCXXNonStaticMemberInitializer(Decl *VarD);
1393 void ParseLexedAttributes(ParsingClass &
Class);
1396 void ParseLexedAttributeList(LateParsedAttrList &LAs, Decl *D,
1398 ParsedAttributes *OutAttrs =
nullptr);
1407 ParsedAttributes *OutAttrs =
nullptr);
1413 void ParseLexedMethodDeclarations(ParsingClass &
Class);
1414 void ParseLexedMethodDeclaration(LateParsedMethodDeclaration &LM);
1419 void ParseLexedMethodDefs(ParsingClass &
Class);
1420 void ParseLexedMethodDef(LexedMethod &LM);
1426 void ParseLexedMemberInitializers(ParsingClass &
Class);
1427 void ParseLexedMemberInitializer(LateParsedMemberInitializer &MI);
1461 ParsedAttributes *Attrs =
nullptr);
1467 IdentifierInfo *Ident_vector;
1468 IdentifierInfo *Ident_bool;
1469 IdentifierInfo *Ident_Bool;
1473 IdentifierInfo *Ident_pixel;
1476 IdentifierInfo *Ident_introduced;
1479 IdentifierInfo *Ident_deprecated;
1482 IdentifierInfo *Ident_obsoleted;
1485 IdentifierInfo *Ident_unavailable;
1488 IdentifierInfo *Ident_message;
1491 IdentifierInfo *Ident_strict;
1494 IdentifierInfo *Ident_replacement;
1497 IdentifierInfo *Ident_environment;
1500 IdentifierInfo *Ident_language, *Ident_defined_in,
1501 *Ident_generated_declaration, *Ident_USR;
1504 AttributeFactory AttrFactory;
1509 bool TryAltiVecToken(DeclSpec &DS, SourceLocation Loc,
const char *&PrevSpec,
1514 if (Tok.getIdentifierInfo() != Ident_vector &&
1515 Tok.getIdentifierInfo() != Ident_bool &&
1516 Tok.getIdentifierInfo() != Ident_Bool &&
1517 (!
getLangOpts().AltiVec || Tok.getIdentifierInfo() != Ident_pixel))
1520 return TryAltiVecTokenOutOfLine(DS, Loc, PrevSpec, DiagID,
isInvalid);
1526 bool TryAltiVecVectorToken() {
1528 Tok.getIdentifierInfo() != Ident_vector)
1530 return TryAltiVecVectorTokenOutOfLine();
1535 bool TryAltiVecVectorTokenOutOfLine();
1536 bool TryAltiVecTokenOutOfLine(DeclSpec &DS, SourceLocation Loc,
1537 const char *&PrevSpec,
unsigned &DiagID,
1541 ParsedAttributes &OutAttrs);
1545 void CompleteLateParsedTypeAttributes(
1546 SmallVectorImpl<LateParsedTypeAttribute *> &LateTypeAttrs);
1556 ArrayRef<const DeclRefExpr *> ParamRefs,
1557 bool ReenteredProtoParams);
1562 static void TakeTypeAttrsAppendingFrom(LateParsedAttrList &To,
1563 LateParsedAttrList &From);
1565 void ParseLexedPragmas(ParsingClass &
Class);
1566 void ParseLexedPragma(LateParsedPragma &LP);
1574 bool ConsumeAndStoreFunctionPrologue(
CachedTokens &Toks);
1590 bool ConsumeFinalToken =
true) {
1591 return ConsumeAndStoreUntil(T1, T1, Toks,
StopAtSemi, ConsumeFinalToken);
1602 bool ConsumeFinalToken =
true);
1610 enum class DeclSpecContext {
1615 DSC_alias_declaration,
1620 DSC_template_type_arg,
1621 DSC_objc_method_result,
1630 static bool isTypeSpecifier(DeclSpecContext DSC) {
1632 case DeclSpecContext::DSC_normal:
1633 case DeclSpecContext::DSC_template_param:
1634 case DeclSpecContext::DSC_template_arg:
1635 case DeclSpecContext::DSC_class:
1636 case DeclSpecContext::DSC_top_level:
1637 case DeclSpecContext::DSC_objc_method_result:
1638 case DeclSpecContext::DSC_condition:
1641 case DeclSpecContext::DSC_template_type_arg:
1642 case DeclSpecContext::DSC_type_specifier:
1643 case DeclSpecContext::DSC_conv_operator:
1644 case DeclSpecContext::DSC_trailing:
1645 case DeclSpecContext::DSC_alias_declaration:
1646 case DeclSpecContext::DSC_association:
1647 case DeclSpecContext::DSC_new:
1650 llvm_unreachable(
"Missing DeclSpecContext case");
1654 enum class AllowDefiningTypeSpec {
1671 static AllowDefiningTypeSpec
1672 isDefiningTypeSpecifierContext(DeclSpecContext DSC,
bool IsCPlusPlus) {
1674 case DeclSpecContext::DSC_normal:
1675 case DeclSpecContext::DSC_class:
1676 case DeclSpecContext::DSC_top_level:
1677 case DeclSpecContext::DSC_alias_declaration:
1678 case DeclSpecContext::DSC_objc_method_result:
1679 return AllowDefiningTypeSpec::Yes;
1681 case DeclSpecContext::DSC_condition:
1682 case DeclSpecContext::DSC_template_param:
1683 return AllowDefiningTypeSpec::YesButInvalid;
1685 case DeclSpecContext::DSC_template_type_arg:
1686 case DeclSpecContext::DSC_type_specifier:
1687 return AllowDefiningTypeSpec::NoButErrorRecovery;
1689 case DeclSpecContext::DSC_association:
1690 return IsCPlusPlus ? AllowDefiningTypeSpec::NoButErrorRecovery
1691 : AllowDefiningTypeSpec::Yes;
1693 case DeclSpecContext::DSC_trailing:
1694 case DeclSpecContext::DSC_conv_operator:
1695 case DeclSpecContext::DSC_template_arg:
1696 case DeclSpecContext::DSC_new:
1697 return AllowDefiningTypeSpec::No;
1699 llvm_unreachable(
"Missing DeclSpecContext case");
1703 static bool isOpaqueEnumDeclarationContext(DeclSpecContext DSC) {
1705 case DeclSpecContext::DSC_normal:
1706 case DeclSpecContext::DSC_class:
1707 case DeclSpecContext::DSC_top_level:
1710 case DeclSpecContext::DSC_alias_declaration:
1711 case DeclSpecContext::DSC_objc_method_result:
1712 case DeclSpecContext::DSC_condition:
1713 case DeclSpecContext::DSC_template_param:
1714 case DeclSpecContext::DSC_template_type_arg:
1715 case DeclSpecContext::DSC_type_specifier:
1716 case DeclSpecContext::DSC_trailing:
1717 case DeclSpecContext::DSC_association:
1718 case DeclSpecContext::DSC_conv_operator:
1719 case DeclSpecContext::DSC_template_arg:
1720 case DeclSpecContext::DSC_new:
1724 llvm_unreachable(
"Missing DeclSpecContext case");
1729 static bool isClassTemplateDeductionContext(DeclSpecContext DSC) {
1731 case DeclSpecContext::DSC_normal:
1732 case DeclSpecContext::DSC_template_param:
1733 case DeclSpecContext::DSC_template_arg:
1734 case DeclSpecContext::DSC_class:
1735 case DeclSpecContext::DSC_top_level:
1736 case DeclSpecContext::DSC_condition:
1737 case DeclSpecContext::DSC_type_specifier:
1738 case DeclSpecContext::DSC_association:
1739 case DeclSpecContext::DSC_conv_operator:
1740 case DeclSpecContext::DSC_new:
1743 case DeclSpecContext::DSC_objc_method_result:
1744 case DeclSpecContext::DSC_template_type_arg:
1745 case DeclSpecContext::DSC_trailing:
1746 case DeclSpecContext::DSC_alias_declaration:
1749 llvm_unreachable(
"Missing DeclSpecContext case");
1754 getImplicitTypenameContext(DeclSpecContext DSC) {
1756 case DeclSpecContext::DSC_class:
1757 case DeclSpecContext::DSC_top_level:
1758 case DeclSpecContext::DSC_type_specifier:
1759 case DeclSpecContext::DSC_template_type_arg:
1760 case DeclSpecContext::DSC_trailing:
1761 case DeclSpecContext::DSC_alias_declaration:
1762 case DeclSpecContext::DSC_template_param:
1763 case DeclSpecContext::DSC_new:
1764 case DeclSpecContext::DSC_conv_operator:
1767 case DeclSpecContext::DSC_normal:
1768 case DeclSpecContext::DSC_objc_method_result:
1769 case DeclSpecContext::DSC_condition:
1770 case DeclSpecContext::DSC_template_arg:
1771 case DeclSpecContext::DSC_association:
1774 llvm_unreachable(
"Missing DeclSpecContext case");
1779 struct ForRangeInit {
1780 SourceLocation ColonLoc;
1782 SmallVector<MaterializeTemporaryExpr *, 8> LifetimeExtendTemps;
1783 CXXExpansionStmtDecl *ExpansionStmt =
nullptr;
1784 bool ParsedForRangeDecl() {
return !ColonLoc.
isInvalid(); }
1786 struct ForRangeInfo : ForRangeInit {
1809 SourceLocation &DeclEnd,
1810 ParsedAttributes &DeclAttrs,
1811 ParsedAttributes &DeclSpecAttrs,
1812 SourceLocation *DeclSpecStart =
nullptr);
1839 ParsedAttributes &DeclAttrs,
1840 ParsedAttributes &DeclSpecAttrs,
bool RequireSemi,
1841 ForRangeInit *FRI =
nullptr,
1842 SourceLocation *DeclSpecStart =
nullptr);
1852 ParsedAttributes &Attrs,
1853 ParsedTemplateInfo &TemplateInfo,
1854 SourceLocation *DeclEnd =
nullptr,
1855 ForRangeInit *FRI =
nullptr);
1881 Decl *ParseDeclarationAfterDeclarator(
1883 const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo());
1887 bool ParseAsmAttributesAfterDeclarator(Declarator &D);
1888 Decl *ParseDeclarationAfterDeclaratorAndAttributes(
1890 const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo(),
1891 ForRangeInit *FRI =
nullptr);
1902 bool ParseImplicitInt(DeclSpec &DS, CXXScopeSpec *SS,
1904 DeclSpecContext DSC, ParsedAttributes &Attrs);
1914 ParseDeclarationSpecifiers(DeclSpec &DS, ParsedTemplateInfo &TemplateInfo,
1916 DeclSpecContext DSC = DeclSpecContext::DSC_normal,
1917 LateParsedAttrList *LateAttrs =
nullptr) {
1918 return ParseDeclarationSpecifiers(DS, TemplateInfo, AS, DSC, LateAttrs,
1919 getImplicitTypenameContext(DSC));
1952 ParseDeclarationSpecifiers(DeclSpec &DS, ParsedTemplateInfo &TemplateInfo,
1954 LateParsedAttrList *LateAttrs,
1964 bool DiagnoseMissingSemiAfterTagDefinition(
1966 LateParsedAttrList *LateAttrs =
nullptr);
1968 void ParseSpecifierQualifierList(
1970 DeclSpecContext DSC = DeclSpecContext::DSC_normal) {
1971 ParseSpecifierQualifierList(DS, getImplicitTypenameContext(DSC), AS, DSC);
1982 void ParseSpecifierQualifierList(
1985 DeclSpecContext DSC = DeclSpecContext::DSC_normal);
2019 void ParseEnumSpecifier(SourceLocation TagLoc, DeclSpec &DS,
2020 const ParsedTemplateInfo &TemplateInfo,
2035 void ParseEnumBody(SourceLocation StartLoc, Decl *TagDecl,
2036 SkipBodyInfo *SkipBody =
nullptr);
2050 void ParseStructUnionBody(SourceLocation StartLoc,
DeclSpec::TST TagType,
2051 RecordDecl *TagDecl);
2076 void ParseStructDeclaration(
2077 ParsingDeclSpec &DS,
2078 llvm::function_ref<Decl *(ParsingFieldDeclarator &)> FieldsCallback,
2079 LateParsedAttrList *LateFieldAttrs =
nullptr);
2091 bool DisambiguatingWithExpression =
false);
2095 bool isTypeSpecifierQualifier(
const Token &Tok);
2100 bool isKnownToBeTypeSpecifier(
const Token &Tok)
const;
2105 bool isConstructorDeclarator(
2108 const ParsedTemplateInfo *TemplateInfo =
nullptr);
2112 void DiagnoseBitIntUse(
const Token &Tok);
2116 bool CheckProhibitedCXX11Attribute() {
2117 assert(Tok.is(tok::l_square));
2120 return DiagnoseProhibitedCXX11Attribute();
2131 bool DiagnoseProhibitedCXX11Attribute();
2133 void CheckMisplacedCXX11Attribute(ParsedAttributes &Attrs,
2134 SourceLocation CorrectLocation) {
2135 if (!Tok.isRegularKeywordAttribute() &&
2136 (Tok.isNot(tok::l_square) ||
NextToken().
isNot(tok::l_square)) &&
2137 Tok.isNot(tok::kw_alignas))
2139 DiagnoseMisplacedCXX11Attribute(Attrs, CorrectLocation);
2146 void DiagnoseMisplacedCXX11Attribute(ParsedAttributes &Attrs,
2147 SourceLocation CorrectLocation);
2157 void stripTypeAttributesOffDeclSpec(ParsedAttributes &Attrs, DeclSpec &DS,
2161 void ProhibitAttributes(ParsedAttributes &Attrs,
2162 SourceLocation FixItLoc = SourceLocation()) {
2163 if (Attrs.Range.isInvalid())
2165 DiagnoseProhibitedAttributes(Attrs, FixItLoc);
2169 void ProhibitAttributes(ParsedAttributesView &Attrs,
2170 SourceLocation FixItLoc = SourceLocation()) {
2171 if (Attrs.Range.isInvalid())
2173 DiagnoseProhibitedAttributes(Attrs, FixItLoc);
2174 Attrs.clearListOnly();
2176 void DiagnoseProhibitedAttributes(
const ParsedAttributesView &Attrs,
2177 SourceLocation FixItLoc);
2185 void ProhibitCXX11Attributes(ParsedAttributes &Attrs,
unsigned AttrDiagID,
2186 unsigned KeywordDiagId,
2187 bool DiagnoseEmptyAttrs =
false,
2188 bool WarnOnUnknownAttrs =
false);
2192 void DiagnoseCXX11AttributeExtension(ParsedAttributes &Attrs);
2194 ExprResult ParseUnevaluatedStringInAttribute(
const IdentifierInfo &AttrName);
2201 bool ParseAttributeArgumentList(
2202 const IdentifierInfo &AttrName, SmallVectorImpl<Expr *> &Exprs,
2203 ParsedAttributeArgumentsProperties ArgsProperties,
unsigned Arg);
2210 ParseAttributeArgsCommon(IdentifierInfo *AttrName, SourceLocation AttrNameLoc,
2211 ParsedAttributes &Attrs, SourceLocation *EndLoc,
2212 IdentifierInfo *ScopeName, SourceLocation ScopeLoc,
2213 ParsedAttr::Form Form);
2215 enum ParseAttrKindMask {
2217 PAKM_Declspec = 1 << 1,
2218 PAKM_CXX11 = 1 << 2,
2237 void ParseAttributes(
unsigned WhichAttrKinds, ParsedAttributes &Attrs,
2238 LateParsedAttrList *LateAttrs =
nullptr);
2241 bool MaybeParseAttributes(
unsigned WhichAttrKinds, ParsedAttributes &Attrs,
2242 LateParsedAttrList *LateAttrs =
nullptr) {
2243 if (Tok.isOneOf(tok::kw___attribute, tok::kw___declspec) ||
2244 isAllowedCXX11AttributeSpecifier()) {
2245 ParseAttributes(WhichAttrKinds, Attrs, LateAttrs);
2251 void MaybeParseGNUAttributes(Declarator &D,
2252 LateParsedAttrList *LateAttrs =
nullptr) {
2253 if (Tok.is(tok::kw___attribute)) {
2254 ParsedAttributes Attrs(AttrFactory);
2255 ParseGNUAttributes(Attrs, LateAttrs, &D);
2256 D.takeAttributesAppending(Attrs);
2260 bool MaybeParseGNUAttributes(ParsedAttributes &Attrs,
2261 LateParsedAttrList *LateAttrs =
nullptr) {
2262 if (Tok.is(tok::kw___attribute)) {
2263 ParseGNUAttributes(Attrs, LateAttrs);
2285 bool ParseSingleGNUAttribute(ParsedAttributes &Attrs, SourceLocation &EndLoc,
2286 LateParsedAttrList *LateAttrs =
nullptr,
2287 Declarator *D =
nullptr);
2332 void ParseGNUAttributes(ParsedAttributes &Attrs,
2333 LateParsedAttrList *LateAttrs =
nullptr,
2334 Declarator *D =
nullptr);
2338 void ParseGNUAttributeArgs(IdentifierInfo *AttrName,
2339 SourceLocation AttrNameLoc,
2340 ParsedAttributes &Attrs, SourceLocation *EndLoc,
2341 IdentifierInfo *ScopeName, SourceLocation ScopeLoc,
2342 ParsedAttr::Form Form, Declarator *D);
2343 IdentifierLoc *ParseIdentifierLoc();
2346 ParseClangAttributeArgs(IdentifierInfo *AttrName, SourceLocation AttrNameLoc,
2347 ParsedAttributes &Attrs, SourceLocation *EndLoc,
2348 IdentifierInfo *ScopeName, SourceLocation ScopeLoc,
2349 ParsedAttr::Form Form);
2351 void MaybeParseCXX11Attributes(Declarator &D) {
2352 if (isAllowedCXX11AttributeSpecifier()) {
2353 ParsedAttributes Attrs(AttrFactory);
2354 ParseCXX11Attributes(Attrs);
2355 D.takeAttributesAppending(Attrs);
2359 bool MaybeParseCXX11Attributes(ParsedAttributes &Attrs,
2360 bool OuterMightBeMessageSend =
false) {
2361 if (isAllowedCXX11AttributeSpecifier(
false, OuterMightBeMessageSend)) {
2362 ParseCXX11Attributes(Attrs);
2368 bool MaybeParseMicrosoftAttributes(ParsedAttributes &Attrs) {
2369 bool AttrsParsed =
false;
2371 Tok.is(tok::l_square)) {
2372 ParsedAttributes AttrsWithRange(AttrFactory);
2373 ParseMicrosoftAttributes(AttrsWithRange);
2374 AttrsParsed = !AttrsWithRange.empty();
2375 Attrs.takeAllAppendingFrom(AttrsWithRange);
2379 bool MaybeParseMicrosoftDeclSpecs(ParsedAttributes &Attrs) {
2380 if (
getLangOpts().DeclSpecKeyword && Tok.is(tok::kw___declspec)) {
2381 ParseMicrosoftDeclSpecs(Attrs);
2395 void ParseMicrosoftDeclSpecs(ParsedAttributes &Attrs);
2396 bool ParseMicrosoftDeclSpecArgs(IdentifierInfo *AttrName,
2397 SourceLocation AttrNameLoc,
2398 ParsedAttributes &Attrs);
2399 void ParseMicrosoftTypeAttributes(ParsedAttributes &attrs);
2400 void ParseWebAssemblyFuncrefTypeAttribute(ParsedAttributes &Attrs);
2401 void DiagnoseAndSkipExtendedMicrosoftTypeAttributes();
2402 SourceLocation SkipExtendedMicrosoftTypeAttributes();
2404 void ParseBorlandTypeAttributes(ParsedAttributes &attrs);
2405 void ParseOpenCLKernelAttributes(ParsedAttributes &attrs);
2406 void ParseOpenCLQualifiers(ParsedAttributes &Attrs);
2407 void ParseNullabilityTypeSpecifiers(ParsedAttributes &attrs);
2408 void ParseCUDAFunctionAttributes(ParsedAttributes &attrs);
2409 void ParseHLSLQualifiers(ParsedAttributes &Attrs);
2421 VersionTuple ParseVersionTuple(SourceRange &Range);
2450 void ParseAvailabilityAttribute(IdentifierInfo &Availability,
2451 SourceLocation AvailabilityLoc,
2452 ParsedAttributes &attrs,
2453 SourceLocation *endLoc,
2454 IdentifierInfo *ScopeName,
2455 SourceLocation ScopeLoc,
2456 ParsedAttr::Form Form);
2474 void ParseExternalSourceSymbolAttribute(IdentifierInfo &ExternalSourceSymbol,
2476 ParsedAttributes &Attrs,
2477 SourceLocation *EndLoc,
2478 IdentifierInfo *ScopeName,
2479 SourceLocation ScopeLoc,
2480 ParsedAttr::Form Form);
2495 void ParseObjCBridgeRelatedAttribute(IdentifierInfo &ObjCBridgeRelated,
2496 SourceLocation ObjCBridgeRelatedLoc,
2497 ParsedAttributes &Attrs,
2498 SourceLocation *EndLoc,
2499 IdentifierInfo *ScopeName,
2500 SourceLocation ScopeLoc,
2501 ParsedAttr::Form Form);
2503 void ParseSwiftNewTypeAttribute(IdentifierInfo &AttrName,
2504 SourceLocation AttrNameLoc,
2505 ParsedAttributes &Attrs,
2506 SourceLocation *EndLoc,
2507 IdentifierInfo *ScopeName,
2508 SourceLocation ScopeLoc,
2509 ParsedAttr::Form Form);
2511 void ParseTypeTagForDatatypeAttribute(IdentifierInfo &AttrName,
2512 SourceLocation AttrNameLoc,
2513 ParsedAttributes &Attrs,
2514 SourceLocation *EndLoc,
2515 IdentifierInfo *ScopeName,
2516 SourceLocation ScopeLoc,
2517 ParsedAttr::Form Form);
2519 void ParseAttributeWithTypeArg(IdentifierInfo &AttrName,
2520 SourceLocation AttrNameLoc,
2521 ParsedAttributes &Attrs,
2522 IdentifierInfo *ScopeName,
2523 SourceLocation ScopeLoc,
2524 ParsedAttr::Form Form);
2526 void DistributeCLateParsedAttrs(Decl *Dcl, LateParsedAttrList *LateAttrs);
2532 void ParseBoundsAttribute(IdentifierInfo &AttrName,
2533 SourceLocation AttrNameLoc, ParsedAttributes &Attrs,
2534 IdentifierInfo *ScopeName, SourceLocation ScopeLoc,
2535 ParsedAttr::Form Form);
2551 void ParseTypeofSpecifier(DeclSpec &DS);
2558 void ParseAtomicSpecifier(DeclSpec &DS);
2568 ExprResult ParseAlignArgument(StringRef KWName, SourceLocation Start,
2569 SourceLocation &EllipsisLoc,
bool &IsType,
2582 void ParseAlignmentSpecifier(ParsedAttributes &Attrs,
2583 SourceLocation *endLoc =
nullptr);
2592 void ParsePtrauthQualifier(ParsedAttributes &Attrs);
2597 class DeclaratorScopeObj {
2604 DeclaratorScopeObj(
Parser &p, CXXScopeSpec &ss)
2605 : P(p), SS(ss), EnteredScope(
false), CreatedScope(
false) {}
2607 void EnterDeclaratorScope() {
2608 assert(!EnteredScope &&
"Already entered the scope!");
2609 assert(SS.isSet() &&
"C++ scope was not set!");
2611 CreatedScope =
true;
2614 if (!P.Actions.ActOnCXXEnterDeclaratorScope(P.getCurScope(), SS))
2615 EnteredScope =
true;
2618 ~DeclaratorScopeObj() {
2620 assert(SS.isSet() &&
"C++ scope was cleared ?");
2621 P.Actions.ActOnCXXExitDeclaratorScope(P.getCurScope(), SS);
2629 void ParseDeclarator(Declarator &D);
2660 void ParseDeclaratorInternal(Declarator &D,
2661 DirectDeclParseFunction DirectDeclParser);
2663 enum AttrRequirements {
2664 AR_NoAttributesParsed = 0,
2665 AR_GNUAttributesParsedAndRejected = 1 << 0,
2666 AR_GNUAttributesParsed = 1 << 1,
2667 AR_CXX11AttributesParsed = 1 << 2,
2668 AR_DeclspecAttributesParsed = 1 << 3,
2669 AR_AllAttributesParsed = AR_GNUAttributesParsed | AR_CXX11AttributesParsed |
2670 AR_DeclspecAttributesParsed,
2671 AR_VendorAttributesParsed =
2672 AR_GNUAttributesParsed | AR_DeclspecAttributesParsed
2689 void ParseTypeQualifierListOpt(
2690 DeclSpec &DS,
unsigned AttrReqs = AR_AllAttributesParsed,
2691 bool AtomicOrPtrauthAllowed =
true,
bool IdentifierRequired =
false,
2692 llvm::function_ref<
void()> CodeCompletionHandler = {});
2742 void ParseDirectDeclarator(Declarator &D);
2743 void ParseDecompositionDeclarator(Declarator &D);
2761 void ParseParenDeclarator(Declarator &D);
2786 void ParseFunctionDeclarator(Declarator &D, ParsedAttributes &FirstArgAttrs,
2788 bool IsAmbiguous,
bool RequiresArg =
false);
2789 void InitCXXThisScopeForDeclaratorIfRelevant(
2790 const Declarator &D,
const DeclSpec &DS,
2791 std::optional<Sema::CXXThisScopeRAII> &ThisScope);
2795 bool ParseRefQualifier(
bool &RefQualifierIsLValueRef,
2796 SourceLocation &RefQualifierLoc);
2803 bool isFunctionDeclaratorIdentifierList();
2817 void ParseFunctionDeclaratorIdentifierList(
2818 Declarator &D, SmallVectorImpl<DeclaratorChunk::ParamInfo> &ParamInfo);
2819 void ParseParameterDeclarationClause(
2820 Declarator &D, ParsedAttributes &attrs,
2821 SmallVectorImpl<DeclaratorChunk::ParamInfo> &ParamInfo,
2822 SourceLocation &EllipsisLoc) {
2823 return ParseParameterDeclarationClause(
2824 D.getContext(), attrs, ParamInfo, EllipsisLoc,
2825 D.getCXXScopeSpec().isSet() &&
2826 D.isFunctionDeclaratorAFunctionDeclaration());
2864 void ParseParameterDeclarationClause(
2866 SmallVectorImpl<DeclaratorChunk::ParamInfo> &ParamInfo,
2867 SourceLocation &EllipsisLoc,
bool IsACXXFunctionDeclaration =
false);
2878 void ParseBracketDeclarator(Declarator &D);
2881 void ParseMisplacedBracketDeclarator(Declarator &D);
2892 TypeResult ParseTypeFromString(StringRef TypeStr, StringRef Context,
2893 SourceLocation IncludeLoc);
2909 mutable IdentifierInfo *Ident_sealed;
2910 mutable IdentifierInfo *Ident_abstract;
2913 mutable IdentifierInfo *Ident_final;
2914 mutable IdentifierInfo *Ident_GNU_final;
2915 mutable IdentifierInfo *Ident_override;
2920 struct ParsingClass {
2921 ParsingClass(Decl *TagOrTemplate,
bool TopLevelClass,
bool IsInterface)
2922 : TopLevelClass(TopLevelClass), IsInterface(IsInterface),
2923 TagOrTemplate(TagOrTemplate) {}
2927 bool TopLevelClass : 1;
2930 bool IsInterface : 1;
2933 Decl *TagOrTemplate;
2938 LateParsedDeclarationsContainer LateParsedDeclarations;
2944 std::stack<ParsingClass *> ClassStack;
2946 ParsingClass &getCurrentClass() {
2947 assert(!ClassStack.empty() &&
"No lexed method stacks!");
2948 return *ClassStack.top();
2952 class ParsingClassDefinition {
2958 ParsingClassDefinition(
Parser &P, Decl *TagOrTemplate,
bool TopLevelClass,
2960 : P(P), Popped(
false),
2961 State(P.PushParsingClass(TagOrTemplate, TopLevelClass, IsInterface)) {
2966 assert(!Popped &&
"Nested class has already been popped");
2968 P.PopParsingClass(State);
2971 ~ParsingClassDefinition() {
2973 P.PopParsingClass(State);
2989 bool Delayed, SourceRange &SpecificationRange,
2990 SmallVectorImpl<ParsedType> &DynamicExceptions,
2991 SmallVectorImpl<SourceRange> &DynamicExceptionRanges,
3009 ParseDynamicExceptionSpecification(SourceRange &SpecificationRange,
3010 SmallVectorImpl<ParsedType> &Exceptions,
3011 SmallVectorImpl<SourceRange> &Ranges);
3018 TypeResult ParseTrailingReturnType(SourceRange &Range,
3019 bool MayBeFollowedByDirectInit);
3022 void ParseTrailingRequiresClauseWithScope(Declarator &D);
3023 void ParseTrailingRequiresClause(Declarator &D);
3025 void ParseMicrosoftIfExistsClassDeclaration(
DeclSpec::TST TagType,
3026 ParsedAttributes &AccessAttrs,
3029 SourceLocation ParsePackIndexingType(DeclSpec &DS);
3030 void AnnotateExistingIndexedTypeNamePack(
ParsedType T,
3031 SourceLocation StartLoc,
3032 SourceLocation EndLoc);
3037 bool AnnotatePackIndexingTemplateName(CXXScopeSpec &SS, UnqualifiedId &Name,
3046 bool isAllowedCXX11AttributeSpecifier(
bool Disambiguate =
false,
3047 bool OuterMightBeMessageSend =
false) {
3048 return (Tok.isRegularKeywordAttribute() ||
3049 isCXX11AttributeSpecifier(Disambiguate, OuterMightBeMessageSend) !=
3056 SourceLocation SkipCXX11Attributes();
3060 void DiagnoseAndSkipCXX11Attributes();
3062 void ParseOpenMPAttributeArgs(
const IdentifierInfo *AttrName,
3091 void ParseCXX11AttributeSpecifierInternal(ParsedAttributes &Attrs,
3093 SourceLocation *EndLoc =
nullptr);
3094 void ParseCXX11AttributeSpecifier(ParsedAttributes &Attrs,
3095 SourceLocation *EndLoc =
nullptr) {
3097 ParseCXX11AttributeSpecifierInternal(Attrs, OpenMPTokens, EndLoc);
3098 ReplayOpenMPAttributeTokens(OpenMPTokens);
3107 void ParseCXX11Attributes(ParsedAttributes &attrs);
3127 bool ParseCXX11AttributeArgs(IdentifierInfo *AttrName,
3128 SourceLocation AttrNameLoc,
3129 ParsedAttributes &Attrs, SourceLocation *EndLoc,
3130 IdentifierInfo *ScopeName,
3131 SourceLocation ScopeLoc,
3137 ParseCXXAssumeAttributeArg(ParsedAttributes &Attrs, IdentifierInfo *AttrName,
3138 SourceLocation AttrNameLoc,
3139 IdentifierInfo *ScopeName, SourceLocation ScopeLoc,
3140 SourceLocation *EndLoc, ParsedAttr::Form Form);
3151 IdentifierInfo *TryParseCXX11AttributeIdentifier(
3152 SourceLocation &Loc,
3155 const IdentifierInfo *EnclosingScope =
nullptr);
3158 void ParseMicrosoftUuidAttributeArgs(ParsedAttributes &Attrs);
3170 void ParseMicrosoftAttributes(ParsedAttributes &Attrs);
3172 void ParseMicrosoftInheritanceClassAttributes(ParsedAttributes &attrs);
3173 void ParseNullabilityClassAttributes(ParsedAttributes &attrs);
3182 SourceLocation ParseDecltypeSpecifier(DeclSpec &DS);
3183 void AnnotateExistingDecltypeSpecifier(
const DeclSpec &DS,
3184 SourceLocation StartLoc,
3185 SourceLocation EndLoc);
3198 return isCXX11VirtSpecifier(Tok);
3208 void ParseOptionalCXX11VirtSpecifierSeq(VirtSpecifiers &VS,
bool IsInterface,
3209 SourceLocation FriendLoc);
3213 bool isCXX11FinalKeyword()
const;
3219 bool isClassCompatibleKeyword()
const;
3221 bool MaybeParseTypeTransformTypeSpecifier(DeclSpec &DS);
3224 void DiagnoseUnexpectedNamespace(NamedDecl *Context);
3256 SourceLocation &DeclEnd,
3257 SourceLocation InlineLoc = SourceLocation());
3259 struct InnerNamespaceInfo {
3260 SourceLocation NamespaceLoc;
3261 SourceLocation InlineLoc;
3262 SourceLocation IdentLoc;
3263 IdentifierInfo *Ident;
3265 using InnerNamespaceInfoList = llvm::SmallVector<InnerNamespaceInfo, 4>;
3268 void ParseInnerNamespace(
const InnerNamespaceInfoList &InnerNSs,
3269 unsigned int index, SourceLocation &InlineLoc,
3270 ParsedAttributes &attrs,
3302 Decl *ParseExportDeclaration();
3308 SourceLocation &DeclEnd, ParsedAttributes &Attrs);
3323 SourceLocation &DeclEnd, ParsedAttributes &attrs);
3325 struct UsingDeclarator {
3326 SourceLocation TypenameLoc;
3329 SourceLocation EllipsisLoc;
3332 TypenameLoc = EllipsisLoc = SourceLocation();
3373 const ParsedTemplateInfo &TemplateInfo,
3374 SourceLocation UsingLoc,
3375 SourceLocation &DeclEnd,
3376 ParsedAttributes &Attrs,
3378 Decl *ParseAliasDeclarationAfterDeclarator(
3379 const ParsedTemplateInfo &TemplateInfo, SourceLocation UsingLoc,
3381 ParsedAttributes &Attrs, Decl **OwnedType =
nullptr);
3394 Decl *ParseStaticAssertDeclaration(SourceLocation &DeclEnd);
3399 Decl *ParseNamespaceAlias(SourceLocation NamespaceLoc,
3400 SourceLocation AliasLoc, IdentifierInfo *Alias,
3401 SourceLocation &DeclEnd);
3409 bool isValidAfterTypeSpecifier(
bool CouldBeBitfield);
3453 void ParseClassSpecifier(
tok::TokenKind TagTokKind, SourceLocation TagLoc,
3454 DeclSpec &DS, ParsedTemplateInfo &TemplateInfo,
3456 DeclSpecContext DSC, ParsedAttributes &Attributes);
3457 void SkipCXXMemberSpecification(SourceLocation StartLoc,
3458 SourceLocation AttrFixitLoc,
unsigned TagType,
3469 void ParseCXXMemberSpecification(SourceLocation StartLoc,
3470 SourceLocation AttrFixitLoc,
3471 ParsedAttributes &Attrs,
unsigned TagType,
3496 ExprResult ParseCXXMemberInitializer(Decl *D,
bool IsFunction,
3497 SourceLocation &EqualLoc);
3501 bool ParseCXXMemberDeclaratorBeforeInitializer(Declarator &DeclaratorInfo,
3504 LateParsedAttrList &LateAttrs);
3509 MaybeParseAndDiagnoseDeclSpecAfterCXX11VirtSpecifierSeq(Declarator &D,
3510 VirtSpecifiers &VS);
3566 ParsedTemplateInfo &TemplateInfo,
3567 ParsingDeclRAIIObject *DiagsFromTParams =
nullptr);
3570 ParsedAttributes &AccessAttrs,
3596 void ParseConstructorInitializer(Decl *ConstructorDecl);
3618 void HandleMemberFunctionDeclDelays(Declarator &DeclaratorInfo,
3646 TypeResult ParseBaseTypeSpecifier(SourceLocation &BaseLoc,
3647 SourceLocation &EndLocation);
3659 void ParseBaseClause(Decl *ClassDecl);
3674 BaseResult ParseBaseSpecifier(Decl *ClassDecl);
3690 bool isClassCompatibleKeyword(Token Tok)
const;
3692 void ParseHLSLRootSignatureAttributeArgs(ParsedAttributes &Attrs);
3867 bool GreaterThanIsOperator;
3871 llvm::SmallDenseMap<IdentifierInfo *, tok::TokenKind> RevertibleTypeTraits;
3890 PushParsingClass(
Decl *TagOrTemplate,
bool TopLevelClass,
bool IsInterface);
3894 void DeallocateParsedClasses(ParsingClass *
Class);
4115 bool isAddressOfOperand,
bool &NotCastExpr,
4117 bool isVectorLiteral =
false,
4118 bool *NotPrimaryExpression =
nullptr);
4120 bool isAddressOfOperand =
false,
4123 bool isVectorLiteral =
false,
4124 bool *NotPrimaryExpression =
nullptr);
4127 bool isNotExpressionStart();
4131 bool isPostfixExpressionSuffixStart() {
4133 return (K == tok::l_square || K == tok::l_paren || K == tok::period ||
4134 K == tok::arrow || K == tok::plusplus || K == tok::minusminus);
4176 ExprResult ParseUnaryExprOrTypeTraitExpression();
4205 ExprResult ParseSYCLUniqueStableNameExpression();
4267 llvm::function_ref<
void()> ExpressionStarts =
4268 llvm::function_ref<
void()>(),
4269 bool FailImmediatelyOnInvalidExpr =
false,
4270 bool ParsingExpansionStmtInitList =
false);
4315 bool StopIfCastExpr,
4352 ExprResult ParseGenericSelectionExpression();
4371 void injectEmbedTokens();
4397 ExprResult ParseAssignmentExprWithObjCMessageExprStart(
4399 Expr *ReceiverExpr);
4404 bool isKnownToBeDeclarationSpecifier() {
4418 bool isTypeIdForGenericSelection() {
4424 return isTypeSpecifierQualifier(Tok);
4430 bool isTypeIdUnambiguously() {
4435 return isTypeSpecifierQualifier(Tok);
4444 void ParseBlockId(SourceLocation CaretLoc);
4453 std::optional<AvailabilitySpec> ParseAvailabilitySpec();
4454 ExprResult ParseAvailabilityCheckExpr(SourceLocation StartLoc);
4460 bool tryParseOpenMPArrayShapingCastPart();
4462 ExprResult ParseBuiltinPtrauthTypeDiscriminator();
4515 bool ObjectHadErrors,
bool EnteringContext,
4516 bool AllowDestructorName,
bool AllowConstructorName,
4517 bool AllowDeductionGuide,
4518 SourceLocation *TemplateKWLoc, UnqualifiedId &
Result);
4530 bool ParsingGenericAssociationType;
4541 ExprResult tryParseCXXIdExpression(CXXScopeSpec &SS,
bool isAddressOfOperand);
4592 ExprResult ParseCXXIdExpression(
bool isAddressOfOperand =
false);
4595 bool areTokensAdjacent(
const Token &A,
const Token &B);
4599 void CheckForTemplateAndDigraph(Token &
Next,
ParsedType ObjectTypePtr,
4600 bool EnteringContext, IdentifierInfo &II,
4663 bool ParseOptionalCXXScopeSpecifier(
4664 CXXScopeSpec &SS,
ParsedType ObjectType,
bool ObjectHasErrors,
4665 bool EnteringContext,
bool *MayBePseudoDestructor =
nullptr,
4666 bool IsTypename =
false,
const IdentifierInfo **LastII =
nullptr,
4667 bool OnlyNamespace =
false,
bool InUsingDeclaration =
false,
4668 bool Disambiguation =
false,
bool IsAddressOfOperand =
false,
4669 bool IsInDeclarationContext =
false);
4671 bool ParseOptionalCXXScopeSpecifier(CXXScopeSpec &SS,
ParsedType ObjectType,
4672 bool ObjectHasErrors,
4673 bool EnteringContext,
4674 bool IsAddressOfOperand) {
4675 return ParseOptionalCXXScopeSpecifier(
4676 SS, ObjectType, ObjectHasErrors, EnteringContext,
4683 IsAddressOfOperand);
4690 enum class LambdaIntroducerTentativeParse {
4768 ParseLambdaIntroducer(LambdaIntroducer &Intro,
4769 LambdaIntroducerTentativeParse *Tentative =
nullptr);
4773 ExprResult ParseLambdaExpressionAfterIntroducer(LambdaIntroducer &Intro);
4776 bool isLambdaSpecifier();
4860 ExprResult ParseCXXPseudoDestructor(Expr *Base, SourceLocation OpLoc,
4915 ExprResult ParseCXXTypeConstructExpression(
const DeclSpec &DS);
4945 void ParseCXXSimpleTypeSpecifier(DeclSpec &DS);
4960 bool ParseCXXTypeSpecifierSeq(
4978 bool ParseExpressionListOrTypeId(SmallVectorImpl<Expr *> &Exprs,
4990 void ParseDirectNewDeclarator(Declarator &D);
5023 ExprResult ParseCXXNewExpression(
bool UseGlobal, SourceLocation Start);
5038 ExprResult ParseCXXDeleteExpression(
bool UseGlobal, SourceLocation Start);
5074 Sema::ConditionResult ParseCondition(
StmtResult *InitStmt, SourceLocation Loc,
5076 ForRangeInfo *FRI =
nullptr);
5078 ParsedAttributes &Attrs);
5125 bool isTypeIdInParens(
bool &isAmbiguous) {
5128 isAmbiguous =
false;
5129 return isTypeSpecifierQualifier(Tok);
5131 bool isTypeIdInParens() {
5133 return isTypeIdInParens(isAmbiguous);
5171 bool ParseUnqualifiedIdTemplateId(CXXScopeSpec &SS,
ParsedType ObjectType,
5172 bool ObjectHadErrors,
5173 SourceLocation TemplateKWLoc,
5174 IdentifierInfo *Name,
5175 SourceLocation NameLoc,
5176 bool EnteringContext, UnqualifiedId &Id,
5177 bool AssumeTemplateId);
5219 bool ParseUnqualifiedIdOperator(CXXScopeSpec &SS,
bool EnteringContext,
5286 bool MaybeParseHLSLAnnotations(Declarator &D,
5287 SourceLocation *EndLoc =
nullptr,
5288 bool CouldBeBitField =
false) {
5289 assert(
getLangOpts().
HLSL &&
"MaybeParseHLSLAnnotations is for HLSL only");
5290 if (Tok.is(tok::colon)) {
5291 ParsedAttributes Attrs(AttrFactory);
5292 ParseHLSLAnnotations(Attrs, EndLoc, CouldBeBitField);
5293 D.takeAttributesAppending(Attrs);
5299 void MaybeParseHLSLAnnotations(ParsedAttributes &Attrs,
5300 SourceLocation *EndLoc =
nullptr) {
5301 assert(
getLangOpts().
HLSL &&
"MaybeParseHLSLAnnotations is for HLSL only");
5302 if (Tok.is(tok::colon))
5303 ParseHLSLAnnotations(Attrs, EndLoc);
5306 struct ParsedSemantic {
5307 StringRef Name =
"";
5309 bool Explicit =
false;
5312 ParsedSemantic ParseHLSLSemantic();
5314 void ParseHLSLAnnotations(ParsedAttributes &Attrs,
5315 SourceLocation *EndLoc =
nullptr,
5316 bool CouldBeBitField =
false);
5317 Decl *ParseHLSLBuffer(SourceLocation &DeclEnd, ParsedAttributes &Attrs);
5341 ExprResult ParseInitializer(Decl *DeclForInitializer =
nullptr);
5346 bool MayBeDesignationStart();
5374 struct DesignatorCompletionInfo {
5375 SmallVectorImpl<Expr *> &InitExprs;
5376 QualType PreferredBaseType;
5425 ExprResult ParseInitializerWithPotentialDesignator(DesignatorCompletionInfo);
5430 typedef SmallVector<Expr *, 12> ExprVector;
5434 bool ParseMicrosoftIfExistsBraceInitializer(ExprVector &InitExprs,
5451 friend class ObjCDeclContextSwitch;
5454 return Actions.ObjC().getObjCDeclContext();
5460 return Actions.getNullabilityKeyword(nullability);
5476 bool InMessageExpression;
5483 bool ParsingInObjCContainer;
5488 bool isObjCInstancetype() {
5490 if (
Tok.isAnnotation())
5492 if (!Ident_instancetype)
5494 return Tok.getIdentifierInfo() == Ident_instancetype;
5502 ObjCContainerDecl *DC;
5503 SaveAndRestore<bool> WithinObjCContainer;
5508 WithinObjCContainer(P.ParsingInObjCContainer, DC !=
nullptr) {
5510 P.Actions.ObjC().ActOnObjCTemporaryExitContainerContext(DC);
5512 ~ObjCDeclContextSwitch() {
5514 P.Actions.ObjC().ActOnObjCReenterContainerContext(DC);
5518 void CheckNestedObjCContexts(SourceLocation AtLoc);
5520 void ParseLexedObjCMethodDefs(LexedMethod &LM,
bool parseMethod);
5538 DeclGroupPtrTy ParseObjCAtDirectives(ParsedAttributes &DeclAttrs,
5539 ParsedAttributes &DeclSpecAttrs);
5550 DeclGroupPtrTy ParseObjCAtClassDeclaration(SourceLocation atLoc);
5583 Decl *ParseObjCAtInterfaceDeclaration(SourceLocation AtLoc,
5584 ParsedAttributes &prefixAttrs);
5590 ObjCTypeParamList *parseObjCTypeParamList();
5618 ObjCTypeParamList *parseObjCTypeParamListOrProtocolRefs(
5620 SmallVectorImpl<IdentifierLoc> &protocolIdents, SourceLocation &rAngleLoc,
5621 bool mayBeProtocolList =
true);
5623 void HelperActionsForIvarDeclarations(ObjCContainerDecl *interfaceDecl,
5624 SourceLocation atLoc,
5626 SmallVectorImpl<Decl *> &AllIvarDecls,
5627 bool RBraceMissing);
5652 void ParseObjCClassInstanceVariables(ObjCContainerDecl *interfaceDecl,
5654 SourceLocation atLoc);
5661 bool ParseObjCProtocolReferences(
5662 SmallVectorImpl<Decl *> &P, SmallVectorImpl<SourceLocation> &PLocs,
5663 bool WarnOnDeclarations,
bool ForObjCContainer, SourceLocation &LAngleLoc,
5664 SourceLocation &EndProtoLoc,
bool consumeLastToken);
5675 void parseObjCTypeArgsOrProtocolQualifiers(
5676 ParsedType baseType, SourceLocation &typeArgsLAngleLoc,
5677 SmallVectorImpl<ParsedType> &typeArgs, SourceLocation &typeArgsRAngleLoc,
5678 SourceLocation &protocolLAngleLoc, SmallVectorImpl<Decl *> &protocols,
5679 SmallVectorImpl<SourceLocation> &protocolLocs,
5680 SourceLocation &protocolRAngleLoc,
bool consumeLastToken,
5681 bool warnOnIncompleteProtocols);
5685 void parseObjCTypeArgsAndProtocolQualifiers(
5686 ParsedType baseType, SourceLocation &typeArgsLAngleLoc,
5687 SmallVectorImpl<ParsedType> &typeArgs, SourceLocation &typeArgsRAngleLoc,
5688 SourceLocation &protocolLAngleLoc, SmallVectorImpl<Decl *> &protocols,
5689 SmallVectorImpl<SourceLocation> &protocolLocs,
5690 SourceLocation &protocolRAngleLoc,
bool consumeLastToken);
5694 TypeResult parseObjCProtocolQualifierType(SourceLocation &rAngleLoc);
5698 TypeResult parseObjCTypeArgsAndProtocolQualifiers(SourceLocation loc,
5700 bool consumeLastToken,
5701 SourceLocation &endLoc);
5737 DeclGroupPtrTy ParseObjCAtProtocolDeclaration(SourceLocation atLoc,
5738 ParsedAttributes &prefixAttrs);
5740 struct ObjCImplParsingDataRAII {
5744 typedef SmallVector<LexedMethod *, 8> LateParsedObjCMethodContainer;
5745 LateParsedObjCMethodContainer LateParsedObjCMethods;
5747 ObjCImplParsingDataRAII(
Parser &parser, Decl *D)
5748 : P(parser), Dcl(D), HasCFunction(
false),
5749 PrevParsedObjCImpl(parser.CurParsedObjCImpl) {
5750 P.CurParsedObjCImpl =
this;
5753 ~ObjCImplParsingDataRAII();
5755 void finish(SourceRange AtEnd);
5756 bool isFinished()
const {
return Finished; }
5764 ObjCImplParsingDataRAII *PrevParsedObjCImpl;
5767 ObjCImplParsingDataRAII *CurParsedObjCImpl;
5771 void StashAwayMethodOrFunctionBodyTokens(Decl *MDecl);
5785 DeclGroupPtrTy ParseObjCAtImplementationDeclaration(SourceLocation AtLoc,
5786 ParsedAttributes &Attrs);
5794 Decl *ParseObjCAtAliasDeclaration(SourceLocation atLoc);
5809 Decl *ParseObjCPropertySynthesize(SourceLocation atLoc);
5820 Decl *ParseObjCPropertyDynamic(SourceLocation atLoc);
5832 IdentifierInfo *ParseObjCSelectorPiece(SourceLocation &MethodLocation);
5840 bool isTokIdentifier_in()
const;
5849 ParsedAttributes *ParamAttrs);
5863 Decl *ParseObjCMethodPrototype(
5865 bool MethodDefinition =
true);
5897 Decl *ParseObjCMethodDecl(
5900 bool MethodDefinition =
true);
5930 void ParseObjCPropertyAttribute(ObjCDeclSpec &DS);
5936 Decl *ParseObjCMethodDefinition();
5940 ExprResult ParseObjCAtExpression(SourceLocation AtLocation);
5941 ExprResult ParseObjCStringLiteral(SourceLocation AtLoc);
5948 ExprResult ParseObjCCharacterLiteral(SourceLocation AtLoc);
5957 ExprResult ParseObjCNumericLiteral(SourceLocation AtLoc);
5966 ExprResult ParseObjCBooleanLiteral(SourceLocation AtLoc,
bool ArgValue);
5968 ExprResult ParseObjCArrayLiteral(SourceLocation AtLoc);
5969 ExprResult ParseObjCDictionaryLiteral(SourceLocation AtLoc);
5976 ExprResult ParseObjCBoxedExpr(SourceLocation AtLoc);
5982 ExprResult ParseObjCEncodeExpression(SourceLocation AtLoc);
5988 ExprResult ParseObjCSelectorExpression(SourceLocation AtLoc);
5994 ExprResult ParseObjCProtocolExpression(SourceLocation AtLoc);
6001 bool isSimpleObjCMessageExpression();
6056 ExprResult ParseObjCMessageExpressionBody(SourceLocation LBracloc,
6057 SourceLocation SuperLoc,
6059 Expr *ReceiverExpr);
6085 bool ParseObjCXXMessageReceiver(
bool &IsExpr,
void *&TypeOrExpr);
6090 enum class ParsedStmtContext;
6092 StmtResult ParseObjCAtStatement(SourceLocation atLoc,
6093 ParsedStmtContext StmtCtx);
6108 StmtResult ParseObjCTryStmt(SourceLocation atLoc);
6115 StmtResult ParseObjCThrowStmt(SourceLocation atLoc);
6122 StmtResult ParseObjCSynchronizedStmt(SourceLocation atLoc);
6129 StmtResult ParseObjCAutoreleasePoolStmt(SourceLocation atLoc);
6156 bool isStartOfObjCClassMessageMissingOpenBracket();
6188 bool OpenACCDirectiveParsing =
false;
6192 bool AllowOpenACCArraySections =
false;
6196 class OpenACCArraySectionRAII {
6200 OpenACCArraySectionRAII(
Parser &P) : P(P) {
6201 assert(!P.AllowOpenACCArraySections);
6202 P.AllowOpenACCArraySections =
true;
6204 ~OpenACCArraySectionRAII() {
6205 assert(P.AllowOpenACCArraySections);
6206 P.AllowOpenACCArraySections =
false;
6213 struct OpenACCDirectiveParseInfo {
6215 SourceLocation StartLoc;
6216 SourceLocation DirLoc;
6217 SourceLocation LParenLoc;
6218 SourceLocation RParenLoc;
6219 SourceLocation EndLoc;
6220 SourceLocation MiscLoc;
6222 SmallVector<Expr *> Exprs;
6223 SmallVector<OpenACCClause *> Clauses;
6228 struct OpenACCWaitParseInfo {
6229 bool Failed =
false;
6230 Expr *DevNumExpr =
nullptr;
6231 SourceLocation QueuesLoc;
6232 SmallVector<Expr *> QueueIdExprs;
6234 SmallVector<Expr *> getAllExprs() {
6235 SmallVector<Expr *>
Out;
6236 Out.push_back(DevNumExpr);
6237 llvm::append_range(Out, QueueIdExprs);
6241 struct OpenACCCacheParseInfo {
6242 bool Failed =
false;
6243 SourceLocation ReadOnlyLoc;
6244 SmallVector<Expr *> Vars;
6249 enum class OpenACCParseCanContinue { Cannot = 0, Can = 1 };
6255 using OpenACCClauseParseResult =
6256 llvm::PointerIntPair<OpenACCClause *, 1, OpenACCParseCanContinue>;
6258 OpenACCClauseParseResult OpenACCCanContinue();
6259 OpenACCClauseParseResult OpenACCCannotContinue();
6260 OpenACCClauseParseResult OpenACCSuccess(OpenACCClause *Clause);
6264 OpenACCDirectiveParseInfo ParseOpenACCDirective();
6274 OpenACCCacheParseInfo ParseOpenACCCacheVarList();
6280 using OpenACCVarParseResult = std::pair<ExprResult, OpenACCParseCanContinue>;
6306 OpenACCClauseParseResult
6307 ParseOpenACCClauseParams(ArrayRef<const OpenACCClause *> ExistingClauses,
6309 SourceLocation ClauseLoc);
6313 OpenACCClauseParseResult
6314 ParseOpenACCClause(ArrayRef<const OpenACCClause *> ExistingClauses,
6324 SmallVector<OpenACCClause *>
6333 OpenACCWaitParseInfo ParseOpenACCWaitArgument(SourceLocation Loc,
6338 std::variant<std::monostate, StringLiteral *, IdentifierInfo *>
6339 ParseOpenACCBindClauseArgument();
6344 using OpenACCIntExprParseResult =
6345 std::pair<ExprResult, OpenACCParseCanContinue>;
6350 SourceLocation Loc);
6355 llvm::SmallVectorImpl<Expr *> &IntExprs);
6368 bool ParseOpenACCDeviceTypeList(llvm::SmallVector<IdentifierLoc> &Archs);
6382 SourceLocation Loc);
6397 llvm::SmallVectorImpl<Expr *> &SizeExprs);
6409 bool ParseOpenACCGangArgList(SourceLocation GangLoc,
6410 llvm::SmallVectorImpl<OpenACCGangKind> &GKs,
6411 llvm::SmallVectorImpl<Expr *> &IntExprs);
6413 using OpenACCGangArgRes = std::pair<OpenACCGangKind, ExprResult>;
6417 OpenACCGangArgRes ParseOpenACCGangArg(SourceLocation GangLoc);
6421 ParseOpenACCAfterRoutineDecl(
AccessSpecifier &AS, ParsedAttributes &Attrs,
6423 OpenACCDirectiveParseInfo &DirInfo);
6424 StmtResult ParseOpenACCAfterRoutineStmt(OpenACCDirectiveParseInfo &DirInfo);
6442 bool OpenMPDirectiveParsing =
false;
6447 void ReplayOpenMPAttributeTokens(
CachedTokens &OpenMPTokens) {
6450 if (!OpenMPTokens.empty()) {
6451 PP.EnterToken(Tok,
true);
6452 PP.EnterTokenStream(OpenMPTokens,
true,
6464 SourceLocation Loc);
6469 llvm::omp::TraitSet
Set,
6470 llvm::omp::TraitSelector Selector,
6471 llvm::StringMap<SourceLocation> &Seen);
6475 llvm::omp::TraitSet
Set,
6476 llvm::StringMap<SourceLocation> &Seen);
6480 llvm::StringMap<SourceLocation> &Seen);
6484 llvm::omp::TraitSet
Set,
6485 llvm::StringMap<SourceLocation> &Seen);
6493 llvm::omp::TraitSet
Set,
6494 llvm::StringMap<SourceLocation> &SeenSelectors);
6501 void parseOMPContextSelectorSet(
OMPTraitSet &TISet,
6502 llvm::StringMap<SourceLocation> &SeenSets);
6509 bool parseOMPContextSelectors(SourceLocation Loc,
OMPTraitInfo &TI);
6512 bool parseOpenMPAppendArgs(SmallVectorImpl<OMPInteropInfo> &InteropInfos);
6516 bool parseOMPDeclareVariantMatchClause(SourceLocation Loc,
OMPTraitInfo &TI,
6522 SourceLocation Loc);
6541 void ParseOpenMPAssumesDirective(OpenMPDirectiveKind DKind,
6542 SourceLocation Loc);
6545 void ParseOpenMPEndAssumesDirective(SourceLocation Loc);
6562 void ParseOpenMPClauses(OpenMPDirectiveKind DKind,
6563 SmallVectorImpl<clang::OMPClause *> &Clauses,
6564 SourceLocation Loc);
6567 void ParseOMPDeclareTargetClauses(SemaOpenMP::DeclareTargetContextInfo &DTCI);
6570 void ParseOMPEndDeclareTargetDirective(OpenMPDirectiveKind BeginDKind,
6571 OpenMPDirectiveKind EndDKind,
6572 SourceLocation Loc);
6576 void skipUntilPragmaOpenMPEnd(OpenMPDirectiveKind DKind);
6582 void parseOMPEndDirective(OpenMPDirectiveKind BeginKind,
6583 OpenMPDirectiveKind ExpectedKind,
6584 OpenMPDirectiveKind FoundKind,
6585 SourceLocation MatchingLoc, SourceLocation FoundLoc,
6586 bool SkipUntilOpenMPEnd);
6627 AccessSpecifier &AS, ParsedAttributes &Attrs,
bool Delayed =
false,
6629 Decl *TagDecl =
nullptr);
6643 DeclGroupPtrTy ParseOpenMPDeclareReductionDirective(AccessSpecifier AS);
6647 void ParseOpenMPReductionInitializerForDecl(VarDecl *OmpPrivParm);
6659 DeclGroupPtrTy ParseOpenMPDeclareMapperDirective(AccessSpecifier AS);
6662 TypeResult parseOpenMPDeclareMapperVarDecl(SourceRange &Range,
6663 DeclarationName &Name,
6664 AccessSpecifier AS =
AS_none);
6678 bool ParseOpenMPSimpleVarList(
6679 OpenMPDirectiveKind Kind,
6680 const llvm::function_ref<
void(CXXScopeSpec &, DeclarationNameInfo)>
6682 bool AllowScopeSpecifier);
6731 StmtResult ParseOpenMPDeclarativeOrExecutableDirective(
6732 ParsedStmtContext StmtCtx,
bool ReadDirectiveWithinMetadirective =
false);
6742 ParseOpenMPExecutableDirective(ParsedStmtContext StmtCtx,
6743 OpenMPDirectiveKind DKind, SourceLocation Loc,
6744 bool ReadDirectiveWithinMetadirective);
6753 StmtResult ParseOpenMPInformationalDirective(
6754 ParsedStmtContext StmtCtx, OpenMPDirectiveKind DKind, SourceLocation Loc,
6755 bool ReadDirectiveWithinMetadirective);
6784 OMPClause *ParseOpenMPClause(OpenMPDirectiveKind DKind,
6869 bool ParseOpenMPIndirectClause(SemaOpenMP::DeclareTargetContextInfo &DTCI,
6894 OMPClause *ParseOpenMPSingleExprWithArgClause(OpenMPDirectiveKind DKind,
6899 OMPClause *ParseOpenMPLoopRangeClause();
6908 OMPClause *ParseOpenMPPermutationClause();
7012 OMPClause *ParseOpenMPVarListClause(OpenMPDirectiveKind DKind,
7026 SourceLocation &ClauseNameLoc,
7027 SourceLocation &OpenLoc,
7028 SourceLocation &CloseLoc,
7029 SmallVectorImpl<Expr *> &Exprs,
7030 bool ReqIntConst =
false);
7045 OMPClause *ParseOpenMPUsesAllocatorClause(OpenMPDirectiveKind DKind);
7048 bool ParseOMPInteropInfo(OMPInteropInfo &InteropInfo,
OpenMPClauseKind Kind);
7054 bool ParseOMPInteropAttrSelector(SmallVectorImpl<Expr *> &Attrs);
7092 OMPClause *ParseOpenMPOMPXAttributesClause(
bool ParseOnly);
7099 bool IsAddressOfOperand =
false);
7103 SemaOpenMP::OpenMPVarListDataTy &
Data,
7104 const LangOptions &LangOpts);
7107 SmallVectorImpl<Expr *> &Vars,
7108 SemaOpenMP::OpenMPVarListDataTy &
Data);
7143 std::unique_ptr<PragmaHandler> AlignHandler;
7144 std::unique_ptr<PragmaHandler> GCCVisibilityHandler;
7145 std::unique_ptr<PragmaHandler> OptionsHandler;
7146 std::unique_ptr<PragmaHandler> PackHandler;
7147 std::unique_ptr<PragmaHandler> MSStructHandler;
7148 std::unique_ptr<PragmaHandler> UnusedHandler;
7149 std::unique_ptr<PragmaHandler> WeakHandler;
7150 std::unique_ptr<PragmaHandler> RedefineExtnameHandler;
7151 std::unique_ptr<PragmaHandler> FPContractHandler;
7152 std::unique_ptr<PragmaHandler> OpenCLExtensionHandler;
7153 std::unique_ptr<PragmaHandler> OpenMPHandler;
7154 std::unique_ptr<PragmaHandler> OpenACCHandler;
7155 std::unique_ptr<PragmaHandler> PCSectionHandler;
7156 std::unique_ptr<PragmaHandler> MSCommentHandler;
7157 std::unique_ptr<PragmaHandler> MSDetectMismatchHandler;
7158 std::unique_ptr<PragmaHandler> FPEvalMethodHandler;
7159 std::unique_ptr<PragmaHandler> FloatControlHandler;
7160 std::unique_ptr<PragmaHandler> MSPointersToMembers;
7161 std::unique_ptr<PragmaHandler> MSVtorDisp;
7162 std::unique_ptr<PragmaHandler> MSInitSeg;
7163 std::unique_ptr<PragmaHandler> MSDataSeg;
7164 std::unique_ptr<PragmaHandler> MSBSSSeg;
7165 std::unique_ptr<PragmaHandler> MSConstSeg;
7166 std::unique_ptr<PragmaHandler> MSCodeSeg;
7167 std::unique_ptr<PragmaHandler> MSSection;
7168 std::unique_ptr<PragmaHandler> MSStrictGuardStackCheck;
7169 std::unique_ptr<PragmaHandler> MSRuntimeChecks;
7170 std::unique_ptr<PragmaHandler> MSIntrinsic;
7171 std::unique_ptr<PragmaHandler> MSFunction;
7172 std::unique_ptr<PragmaHandler> MSOptimize;
7173 std::unique_ptr<PragmaHandler> MSFenvAccess;
7174 std::unique_ptr<PragmaHandler> MSAllocText;
7175 std::unique_ptr<PragmaHandler> CUDAForceHostDeviceHandler;
7176 std::unique_ptr<PragmaHandler> OptimizeHandler;
7177 std::unique_ptr<PragmaHandler> LoopHintHandler;
7178 std::unique_ptr<PragmaHandler> UnrollHintHandler;
7179 std::unique_ptr<PragmaHandler> NoUnrollHintHandler;
7180 std::unique_ptr<PragmaHandler> UnrollAndJamHintHandler;
7181 std::unique_ptr<PragmaHandler> NoUnrollAndJamHintHandler;
7182 std::unique_ptr<PragmaHandler> FPHandler;
7183 std::unique_ptr<PragmaHandler> STDCFenvAccessHandler;
7184 std::unique_ptr<PragmaHandler> STDCFenvRoundHandler;
7185 std::unique_ptr<PragmaHandler> STDCCXLIMITHandler;
7186 std::unique_ptr<PragmaHandler> STDCUnknownHandler;
7187 std::unique_ptr<PragmaHandler> AttributePragmaHandler;
7188 std::unique_ptr<PragmaHandler> MaxTokensHerePragmaHandler;
7189 std::unique_ptr<PragmaHandler> MaxTokensTotalPragmaHandler;
7190 std::unique_ptr<PragmaHandler> ExportHandler;
7191 std::unique_ptr<PragmaHandler> RISCVPragmaHandler;
7194 void initializePragmaHandlers();
7197 void resetPragmaHandlers();
7204 void HandlePragmaUnused();
7208 void HandlePragmaVisibility();
7212 void HandlePragmaPack();
7216 void HandlePragmaMSStruct();
7218 void HandlePragmaMSPointersToMembers();
7220 void HandlePragmaMSVtorDisp();
7222 void HandlePragmaMSPragma();
7223 bool HandlePragmaMSSection(StringRef PragmaName,
7224 SourceLocation PragmaLocation);
7225 bool HandlePragmaMSSegment(StringRef PragmaName,
7226 SourceLocation PragmaLocation);
7229 bool HandlePragmaMSInitSeg(StringRef PragmaName,
7230 SourceLocation PragmaLocation);
7235 bool HandlePragmaMSStrictGuardStackCheck(StringRef PragmaName,
7236 SourceLocation PragmaLocation);
7237 bool HandlePragmaMSFunction(StringRef PragmaName,
7238 SourceLocation PragmaLocation);
7239 bool HandlePragmaMSAllocText(StringRef PragmaName,
7240 SourceLocation PragmaLocation);
7243 bool HandlePragmaMSOptimize(StringRef PragmaName,
7244 SourceLocation PragmaLocation);
7247 bool HandlePragmaMSIntrinsic(StringRef PragmaName,
7248 SourceLocation PragmaLocation);
7252 void HandlePragmaAlign();
7256 void HandlePragmaDump();
7260 void HandlePragmaWeak();
7264 void HandlePragmaWeakAlias();
7268 void HandlePragmaRedefineExtname();
7272 void HandlePragmaFPContract();
7276 void HandlePragmaFEnvAccess();
7280 void HandlePragmaFEnvRound();
7284 void HandlePragmaCXLimitedRange();
7288 void HandlePragmaFloatControl();
7292 void HandlePragmaFP();
7296 void HandlePragmaOpenCLExtension();
7300 StmtResult HandlePragmaCaptured();
7304 bool HandlePragmaLoopHint(LoopHint &Hint);
7306 bool ParsePragmaAttributeSubjectMatchRuleSet(
7308 SourceLocation &AnyLoc, SourceLocation &LastMatchRuleEndLoc);
7310 void HandlePragmaAttribute();
7316 void HandlePragmaExport();
7342 enum class ParsedStmtContext {
7345 AllowDeclarationsInC = 0x1,
7347 AllowStandaloneOpenMPDirectives = 0x2,
7354 Compound = AllowDeclarationsInC | AllowStandaloneOpenMPDirectives,
7356 LLVM_MARK_AS_BITMASK_ENUM(InStmtExpr)
7371 ParsedStmtContext StmtCtx = ParsedStmtContext::SubStmt,
7426 ParseStatementOrDeclaration(
StmtVector &Stmts, ParsedStmtContext StmtCtx,
7430 StmtResult ParseStatementOrDeclarationAfterAttributes(
7431 StmtVector &Stmts, ParsedStmtContext StmtCtx,
7436 StmtResult ParseExprStatement(ParsedStmtContext StmtCtx);
7450 ParsedStmtContext StmtCtx);
7459 StmtResult ParseCaseStatement(ParsedStmtContext StmtCtx,
7460 bool MissingCase =
false,
7470 StmtResult ParseDefaultStatement(ParsedStmtContext StmtCtx);
7472 StmtResult ParseCompoundStatement(
bool isStmtExpr =
false);
7498 StmtResult ParseCompoundStatement(
bool isStmtExpr,
unsigned ScopeFlags);
7503 void ParseCompoundStatementLeadingPragmas();
7505 void DiagnoseLabelAtEndOfCompoundStatement();
7515 StmtResult ParseCompoundStatementBody(
bool isStmtExpr =
false);
7533 bool ParseParenExprOrCondition(
StmtResult *InitStmt,
7607 void ParseForRangeInitializerAfterColon(ForRangeInit &FRI,
7653 StmtResult ParseBreakOrContinueStatement(
bool IsContinue);
7687 void ParseMicrosoftIfExistsStatement(
StmtVector &Stmts);
7734 StmtResult ParseCXXCatchBlock(
bool FnCatch =
false);
7772 Decl *ParseFunctionStatementBody(
Decl *
Decl, ParseScope &BodyScope);
7781 Decl *ParseFunctionTryBlock(
Decl *
Decl, ParseScope &BodyScope);
7792 Decl *ParseFunctionBody(
Decl *D, ParseScope &BodyScope);
7798 bool trySkippingFunctionBody();
7806 bool isDeclarationStatement(
bool DisambiguatingWithExpression =
false) {
7808 return isCXXDeclarationStatement(DisambiguatingWithExpression);
7816 bool isForInitDeclaration() {
7820 return Tok.is(tok::kw_using) ||
7821 isCXXSimpleDeclaration(
true);
7826 bool isForRangeIdentifier();
7843 unsigned &NumLineToksConsumed,
7844 bool IsUnevaluated);
7887 StmtResult ParseMicrosoftAsmStatement(SourceLocation AsmLoc);
7903 bool ParseAsmOperandsOpt(SmallVectorImpl<IdentifierInfo *> &Names,
7904 SmallVectorImpl<Expr *> &Constraints,
7905 SmallVectorImpl<Expr *> &Exprs);
7907 class GNUAsmQualifiers {
7908 unsigned Qualifiers = AQ_unspecified;
7917 static const char *getQualifierName(AQ Qualifier);
7918 bool setAsmQualifier(AQ Qualifier);
7919 inline bool isVolatile()
const {
return Qualifiers & AQ_volatile; };
7920 inline bool isInline()
const {
return Qualifiers & AQ_inline; };
7921 inline bool isGoto()
const {
return Qualifiers & AQ_goto; }
7925 bool isGCCAsmStatement(
const Token &TokAfterAsm)
const;
7927 bool isGNUAsmQualifier(
const Token &TokAfterAsm)
const;
7928 GNUAsmQualifiers::AQ getGNUAsmQualifier(
const Token &Tok)
const;
7941 bool parseGNUAsmQualifierListOpt(GNUAsmQualifiers &AQ);
7965 unsigned TemplateParameterDepth;
7968 class TemplateParameterDepthRAII {
7970 unsigned AddedLevels;
7973 explicit TemplateParameterDepthRAII(
unsigned &Depth)
7974 : Depth(Depth), AddedLevels(0) {}
7976 ~TemplateParameterDepthRAII() { Depth -= AddedLevels; }
7982 void addDepth(
unsigned D) {
7986 void setAddedDepth(
unsigned D) {
7987 Depth = Depth - AddedLevels + D;
7991 unsigned getDepth()
const {
return Depth; }
7992 unsigned getOriginalDepth()
const {
return Depth - AddedLevels; }
7997 SmallVector<TemplateIdAnnotation *, 16> TemplateIds;
8003 bool DelayTemplateIdDestruction =
false;
8005 void MaybeDestroyTemplateIds() {
8006 if (DelayTemplateIdDestruction)
8008 if (!TemplateIds.empty() &&
8009 (Tok.is(tok::eof) || !PP.mightHavePendingAnnotationTokens()))
8010 DestroyTemplateIds();
8012 void DestroyTemplateIds();
8016 struct DestroyTemplateIdAnnotationsRAIIObj {
8019 DestroyTemplateIdAnnotationsRAIIObj(
Parser &Self) : Self(Self) {}
8020 ~DestroyTemplateIdAnnotationsRAIIObj() { Self.MaybeDestroyTemplateIds(); }
8023 struct DelayTemplateIdDestructionRAII {
8025 bool PrevDelayTemplateIdDestruction;
8027 DelayTemplateIdDestructionRAII(
Parser &Self,
8028 bool DelayTemplateIdDestruction) noexcept
8030 PrevDelayTemplateIdDestruction(Self.DelayTemplateIdDestruction) {
8031 Self.DelayTemplateIdDestruction = DelayTemplateIdDestruction;
8034 ~DelayTemplateIdDestructionRAII() noexcept {
8035 Self.DelayTemplateIdDestruction = PrevDelayTemplateIdDestruction;
8040 SmallVector<const IdentifierInfo *, 8> TentativelyDeclaredIdentifiers;
8052 struct AngleBracketTracker {
8055 enum Priority :
unsigned short {
8057 PotentialTypo = 0x0,
8059 DependentName = 0x2,
8062 SpaceBeforeLess = 0x0,
8064 NoSpaceBeforeLess = 0x1,
8095 if (!Locs.empty() && Locs.back().isActive(P)) {
8096 if (Locs.back().Priority <= Prio) {
8098 Locs.back().LessLoc = LessLoc;
8099 Locs.back().Priority = Prio;
8102 Locs.push_back({
TemplateName, LessLoc, Prio, P.ParenCount,
8103 P.BracketCount, P.BraceCount});
8111 while (!Locs.empty() && Locs.back().isActiveOrNested(P))
8118 if (!Locs.empty() && Locs.back().isActive(P))
8119 return &Locs.back();
8124 AngleBracketTracker AngleBrackets;
8129 struct ParsedTemplateInfo {
8130 ParsedTemplateInfo()
8134 bool isSpecialization,
8135 bool lastParameterListWasEmpty =
false)
8138 TemplateParams(TemplateParams),
8139 LastParameterListWasEmpty(lastParameterListWasEmpty) {}
8141 explicit ParsedTemplateInfo(SourceLocation ExternLoc,
8142 SourceLocation TemplateLoc)
8144 TemplateParams(
nullptr), ExternLoc(ExternLoc),
8145 TemplateLoc(TemplateLoc), LastParameterListWasEmpty(
false) {}
8155 SourceLocation ExternLoc;
8159 SourceLocation TemplateLoc;
8162 bool LastParameterListWasEmpty;
8164 SourceRange getSourceRange() const LLVM_READONLY;
8168 void LexTemplateFunctionForLateParsing(
CachedTokens &Toks);
8171 void ParseLateTemplatedFuncDef(LateParsedTemplate &LPT);
8173 static
void LateTemplateParserCallback(
void *P, LateParsedTemplate &LPT);
8181 void checkPotentialAngleBracket(
ExprResult &PotentialTemplateName);
8182 bool checkPotentialAngleBracketDelimiter(const AngleBracketTracker::Loc &,
8183 const Token &OpToken);
8184 bool checkPotentialAngleBracketDelimiter(const Token &OpToken) {
8185 if (
auto *Info = AngleBrackets.getCurrent(*
this))
8186 return checkPotentialAngleBracketDelimiter(*Info, OpToken);
8197 SourceLocation &DeclEnd,
8198 ParsedAttributes &AccessAttrs);
8245 ParsingDeclRAIIObject &DiagsFromParams, SourceLocation &DeclEnd,
8257 bool ParseTemplateParameters(MultiParseScope &TemplateScopes,
unsigned Depth,
8258 SmallVectorImpl<NamedDecl *> &TemplateParams,
8259 SourceLocation &LAngleLoc,
8260 SourceLocation &RAngleLoc);
8272 bool ParseTemplateParameterList(
unsigned Depth,
8273 SmallVectorImpl<NamedDecl *> &TemplateParams);
8275 enum class TPResult;
8279 TPResult isStartOfTemplateTypeParameter();
8303 NamedDecl *ParseTemplateParameter(
unsigned Depth,
unsigned Position);
8316 NamedDecl *ParseTypeParameter(
unsigned Depth,
unsigned Position);
8332 NamedDecl *ParseTemplateTemplateParameter(
unsigned Depth,
unsigned Position);
8342 NamedDecl *ParseNonTypeTemplateParameter(
unsigned Depth,
unsigned Position);
8346 bool isTypeConstraintAnnotation();
8358 bool TryAnnotateTypeConstraint();
8360 void DiagnoseMisplacedEllipsis(SourceLocation EllipsisLoc,
8361 SourceLocation CorrectLoc,
8362 bool AlreadyHasEllipsis,
8363 bool IdentifierHasName);
8364 void DiagnoseMisplacedEllipsisInDeclarator(SourceLocation EllipsisLoc,
8367 typedef SmallVector<ParsedTemplateArgument, 16> TemplateArgList;
8384 bool ParseGreaterThanInTemplateList(SourceLocation LAngleLoc,
8385 SourceLocation &RAngleLoc,
8386 bool ConsumeLastToken,
8387 bool ObjCGenericList);
8400 bool ParseTemplateIdAfterTemplateName(
bool ConsumeLastToken,
8401 SourceLocation &LAngleLoc,
8402 TemplateArgList &TemplateArgs,
8403 SourceLocation &RAngleLoc,
8448 CXXScopeSpec &SS, SourceLocation TemplateKWLoc,
8450 bool AllowTypeAnnotation =
true,
8451 bool TypeConstraint =
false);
8469 AnnotateTemplateIdTokenAsType(CXXScopeSpec &SS,
8471 bool IsClassName =
false);
8483 bool ParseTemplateArgumentList(TemplateArgList &TemplateArgs,
8487 ParsedTemplateArgument ParseTemplateTemplateArgument();
8499 ParsedTemplateArgument ParseTemplateArgument();
8511 SourceLocation ExternLoc,
8512 SourceLocation TemplateLoc,
8513 SourceLocation &DeclEnd,
8514 ParsedAttributes &AccessAttrs,
8523 Decl *ParseConceptDefinition(
const ParsedTemplateInfo &TemplateInfo,
8524 SourceLocation &DeclEnd);
8552 class TentativeParsingAction {
8554 PreferredTypeBuilder PrevPreferredType;
8556 size_t PrevTentativelyDeclaredIdentifierCount;
8557 unsigned short PrevParenCount, PrevBracketCount, PrevBraceCount;
8561 explicit TentativeParsingAction(Parser &p,
bool Unannotated =
false)
8562 : P(p), PrevPreferredType(P.PreferredType) {
8564 PrevTentativelyDeclaredIdentifierCount =
8565 P.TentativelyDeclaredIdentifiers.size();
8566 PrevParenCount = P.ParenCount;
8567 PrevBracketCount = P.BracketCount;
8568 PrevBraceCount = P.BraceCount;
8569 P.PP.EnableBacktrackAtThisPos(Unannotated);
8573 assert(isActive &&
"Parsing action was finished!");
8574 P.TentativelyDeclaredIdentifiers.resize(
8575 PrevTentativelyDeclaredIdentifierCount);
8576 P.PP.CommitBacktrackedTokens();
8580 assert(isActive &&
"Parsing action was finished!");
8582 P.PreferredType = PrevPreferredType;
8584 P.TentativelyDeclaredIdentifiers.resize(
8585 PrevTentativelyDeclaredIdentifierCount);
8586 P.ParenCount = PrevParenCount;
8587 P.BracketCount = PrevBracketCount;
8588 P.BraceCount = PrevBraceCount;
8591 ~TentativeParsingAction() {
8592 assert(!isActive &&
"Forgot to call Commit or Revert!");
8598 class RevertingTentativeParsingAction
8599 :
private Parser::TentativeParsingAction {
8601 using TentativeParsingAction::TentativeParsingAction;
8603 ~RevertingTentativeParsingAction() { Revert(); }
8638 bool isCXXDeclarationStatement(
bool DisambiguatingWithExpression =
false);
8664 bool isCXXSimpleDeclaration(
bool AllowForRangeDecl);
8677 bool isCXXFunctionDeclarator(
bool *IsAmbiguous =
nullptr,
8681 struct ConditionDeclarationOrInitStatementState;
8682 enum class ConditionOrInitStatement {
8709 ConditionOrInitStatement
8710 isCXXConditionDeclarationOrInitStatement(
bool CanBeInitStmt,
8711 bool CanBeForRangeDecl);
8737 return isCXXTypeId(Context, isAmbiguous);
8751 bool isEnumBase(
bool AllowSemi);
8871 TPResult BracedCastResult = TPResult::False,
8872 bool *InvalidAsDeclSpec =
nullptr);
8877 bool isCXXDeclarationSpecifierAType();
8883 TPResult isTemplateArgumentList(
unsigned TokensToSkip);
8888 TPResult isExplicitBool();
8893 bool isTentativelyDeclared(IdentifierInfo *II);
8912 TPResult TryParseSimpleDeclaration(
bool AllowForRangeDecl);
8920 TPResult TryParseTypeofSpecifier();
8924 TPResult TryParseProtocolQualifiers();
8926 TPResult TryParsePtrOperatorSeq();
8948 TPResult TryParseOperatorId();
8979 TPResult TryParseInitDeclaratorList(
bool MayHaveTrailingReturnType =
false);
9036 TPResult TryParseDeclarator(
bool mayBeAbstract,
bool mayHaveIdentifier =
true,
9037 bool mayHaveDirectInit =
false,
9038 bool mayHaveTrailingReturnType =
false);
9059 TPResult TryParseParameterDeclarationClause(
9060 bool *InvalidAsDeclaration =
nullptr,
bool VersusTemplateArg =
false,
9077 TPResult TryParseFunctionDeclarator(
bool MayHaveTrailingReturnType =
false);
9083 bool NameAfterArrowIsNonType();
9089 TPResult TryParseBracketDeclarator();
9093 TPResult TryConsumeDeclarationSpecifier();
9097 bool TrySkipAttributes();
9101 bool hasLambdaLikeContinuation();
9143 isCXX11AttributeSpecifier(
bool Disambiguate =
false,
9144 bool OuterMightBeMessageSend =
false);