257 return Actions.incrementMSManglingNumber();
306 assert(!isTokenSpecial() &&
307 "Should consume special tokens with Consume*Token");
308 PrevTokLocation = Tok.getLocation();
310 return PrevTokLocation;
316 assert(!isTokenSpecial() &&
317 "Should consume special tokens with Consume*Token");
318 PrevTokLocation = Tok.getLocation();
326 Loc = PrevTokLocation;
335 return ConsumeParen();
336 if (isTokenBracket())
337 return ConsumeBracket();
339 return ConsumeBrace();
340 if (isTokenStringLiteral())
341 return ConsumeStringToken();
342 if (Tok.is(tok::code_completion))
343 return ConsumeCodeCompletionTok ? ConsumeCodeCompletionToken()
344 : handleUnexpectedCodeCompletionToken();
345 if (Tok.isAnnotation())
346 return ConsumeAnnotationToken();
360 if (N == 0 || Tok.is(tok::eof))
362 return PP.LookAhead(N - 1);
371 if (!Tok.getAnnotationValue())
406 bool IsAddressOfOperand =
false);
432 (Tok.is(tok::identifier) || Tok.is(tok::coloncolon) ||
433 (Tok.is(tok::annot_template_id) &&
435 Tok.is(tok::kw_decltype) || Tok.is(tok::kw___super));
452 ParseScope(
const ParseScope &) =
delete;
453 void operator=(
const ParseScope &) =
delete;
460 bool BeforeCompoundStmt =
false)
462 if (EnteredScope && !BeforeCompoundStmt)
463 Self->EnterScope(ScopeFlags);
465 if (BeforeCompoundStmt)
466 Self->incrementMSManglingNumber();
468 this->Self = nullptr;
486 class MultiParseScope {
488 unsigned NumScopes = 0;
490 MultiParseScope(
const MultiParseScope &) =
delete;
495 Self.EnterScope(ScopeFlags);
537 static_cast<unsigned>(R));
592 unsigned short ParenCount = 0, BracketCount = 0,
BraceCount = 0;
593 unsigned short MisplacedModuleBeginCount = 0;
604 static constexpr int ScopeCacheSize = 16;
605 unsigned NumCachedScopes;
606 Scope *ScopeCache[ScopeCacheSize];
612 *Ident_GetExceptionCode;
615 *Ident_GetExceptionInfo;
617 IdentifierInfo *Ident__abnormal_termination, *Ident___abnormal_termination,
618 *Ident_AbnormalTermination;
623 std::unique_ptr<CommentHandler> CommentSemaHandler;
628 bool CalledSignatureHelp =
false;
636 bool SkipFunctionBodies;
643 bool isTokenParen()
const {
return Tok.isOneOf(tok::l_paren, tok::r_paren); }
645 bool isTokenBracket()
const {
646 return Tok.isOneOf(tok::l_square, tok::r_square);
649 bool isTokenBrace()
const {
return Tok.isOneOf(tok::l_brace, tok::r_brace); }
651 bool isTokenStringLiteral()
const {
655 bool isTokenSpecial()
const {
656 return isTokenStringLiteral() || isTokenParen() || isTokenBracket() ||
657 isTokenBrace() || Tok.is(tok::code_completion) || Tok.isAnnotation();
662 bool isTokenEqualOrEqualTypo();
666 void UnconsumeToken(Token &Consumed) {
668 PP.EnterToken(Consumed,
true);
670 PP.EnterToken(
Next,
true);
673 SourceLocation ConsumeAnnotationToken() {
674 assert(Tok.isAnnotation() &&
"wrong consume method");
675 SourceLocation Loc = Tok.getLocation();
676 PrevTokLocation = Tok.getAnnotationEndLoc();
683 SourceLocation ConsumeParen() {
684 assert(isTokenParen() &&
"wrong consume method");
685 if (Tok.getKind() == tok::l_paren)
687 else if (ParenCount) {
688 AngleBrackets.clear(*
this);
691 PrevTokLocation = Tok.getLocation();
693 return PrevTokLocation;
698 SourceLocation ConsumeBracket() {
699 assert(isTokenBracket() &&
"wrong consume method");
700 if (Tok.getKind() == tok::l_square)
702 else if (BracketCount) {
703 AngleBrackets.clear(*
this);
707 PrevTokLocation = Tok.getLocation();
709 return PrevTokLocation;
714 SourceLocation ConsumeBrace() {
715 assert(isTokenBrace() &&
"wrong consume method");
716 if (Tok.getKind() == tok::l_brace)
718 else if (BraceCount) {
719 AngleBrackets.clear(*
this);
723 PrevTokLocation = Tok.getLocation();
725 return PrevTokLocation;
732 SourceLocation ConsumeStringToken() {
733 assert(isTokenStringLiteral() &&
734 "Should only consume string literals with this method");
735 PrevTokLocation = Tok.getLocation();
737 return PrevTokLocation;
745 SourceLocation ConsumeCodeCompletionToken() {
746 assert(Tok.is(tok::code_completion));
747 PrevTokLocation = Tok.getLocation();
749 return PrevTokLocation;
757 SourceLocation handleUnexpectedCodeCompletionToken();
761 void cutOffParsing() {
762 if (PP.isCodeCompletionEnabled())
763 PP.setCodeCompletionReached();
765 Tok.setKind(tok::eof);
772 return Kind == tok::eof ||
Kind == tok::annot_module_begin ||
773 Kind == tok::annot_module_end ||
Kind == tok::annot_module_include ||
774 Kind == tok::annot_repl_input_end;
777 static void setTypeAnnotation(Token &Tok,
TypeResult T) {
778 assert((T.isInvalid() || T.get()) &&
779 "produced a valid-but-null type annotation?");
780 Tok.setAnnotationValue(T.isInvalid() ?
nullptr : T.get().getAsOpaquePtr());
783 static NamedDecl *getNonTypeAnnotation(
const Token &Tok) {
784 return static_cast<NamedDecl *
>(Tok.getAnnotationValue());
787 static void setNonTypeAnnotation(Token &Tok, NamedDecl *ND) {
788 Tok.setAnnotationValue(ND);
791 static IdentifierInfo *getIdentifierAnnotation(
const Token &Tok) {
792 return static_cast<IdentifierInfo *
>(Tok.getAnnotationValue());
795 static void setIdentifierAnnotation(Token &Tok, IdentifierInfo *ND) {
796 Tok.setAnnotationValue(ND);
801 static ExprResult getExprAnnotation(
const Token &Tok) {
802 return ExprResult::getFromOpaquePointer(Tok.getAnnotationValue());
807 static void setExprAnnotation(Token &Tok,
ExprResult ER) {
808 Tok.setAnnotationValue(ER.getAsOpaquePointer());
822 TryAnnotateName(CorrectionCandidateCallback *CCC =
nullptr,
827 void AnnotateScopeToken(CXXScopeSpec &SS,
bool IsNewAnnotation);
834 bool TryKeywordIdentFallback(
bool DisableKeyword);
839 TemplateIdAnnotation *takeTemplateIdAnnotation(
const Token &tok);
850 unsigned Diag = diag::err_expected,
851 StringRef DiagMsg =
"");
858 bool ExpectAndConsumeSemi(
unsigned DiagID, StringRef TokenUsed =
"");
863 bool isLikelyAtStartOfNewDeclaration();
874 bool expectIdentifier();
877 enum class CompoundToken {
892 void checkCompoundToken(SourceLocation FirstTokLoc,
895 void diagnoseUseOfC11Keyword(
const Token &Tok);
898 class ParseScopeFlags {
900 unsigned OldFlags = 0;
901 ParseScopeFlags(
const ParseScopeFlags &) =
delete;
902 void operator=(
const ParseScopeFlags &) =
delete;
907 ParseScopeFlags(
Parser *
Self,
unsigned ScopeFlags,
bool ManageFlags =
true);
921 void SuggestParentheses(SourceLocation Loc,
unsigned DK,
922 SourceRange ParenRange);
958 DeclGroupPtrTy ParseExternalDeclaration(ParsedAttributes &DeclAttrs,
959 ParsedAttributes &DeclSpecAttrs,
960 ParsingDeclSpec *DS =
nullptr);
964 bool isDeclarationAfterDeclarator();
968 bool isStartOfFunctionDefinition(
const ParsingDeclarator &Declarator);
971 ParsedAttributes &DeclAttrs, ParsedAttributes &DeclSpecAttrs,
992 DeclGroupPtrTy ParseDeclOrFunctionDefInternal(ParsedAttributes &Attrs,
993 ParsedAttributes &DeclSpecAttrs,
997 void SkipFunctionBody();
999 struct ParsedTemplateInfo;
1017 Decl *ParseFunctionDefinition(
1018 ParsingDeclarator &D,
1019 const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo(),
1020 LateParsedAttrList *LateParsedAttrs =
nullptr);
1024 void ParseKNRParamDeclarations(Declarator &D);
1034 ExprResult ParseSimpleAsm(
bool ForAsmLabel, SourceLocation *EndLoc);
1047 ExprResult ParseAsmStringLiteral(
bool ForAsmLabel);
1051 struct IfExistsCondition {
1053 SourceLocation KeywordLoc;
1069 bool ParseMicrosoftIfExistsCondition(IfExistsCondition &
Result);
1070 void ParseMicrosoftIfExistsExternalDeclaration();
1109 Decl *ParseModuleImport(SourceLocation AtLoc,
1116 bool parseMisplacedModuleImport();
1118 bool tryParseMisplacedModuleImport() {
1120 if (Kind == tok::annot_module_begin || Kind == tok::annot_module_end ||
1121 Kind == tok::annot_module_include)
1122 return parseMisplacedModuleImport();
1135 bool ParseModuleName(SourceLocation UseLoc,
1136 SmallVectorImpl<IdentifierLoc> &Path,
bool IsImport);
1139 void DiagnoseInvalidCXXModuleImport();
1143 void CodeCompleteDirective(
bool InConditional)
override;
1145 void CodeCompleteMacroName(
bool IsDefinition)
override;
1147 void CodeCompleteMacroArgument(IdentifierInfo *
Macro, MacroInfo *MacroInfo,
1148 unsigned ArgumentIndex)
override;
1149 void CodeCompleteIncludedFile(llvm::StringRef Dir,
bool IsAngled)
override;
1151 void CodeCompleteModuleImport(SourceLocation ImportLoc,
1169 struct ParsingClass;
1175 LateParsedClass(
Parser *P, ParsingClass *
C);
1176 ~LateParsedClass()
override;
1185 LateParsedClass(
const LateParsedClass &) =
delete;
1186 LateParsedClass &operator=(
const LateParsedClass &) =
delete;
1190 ParsingClass *
Class;
1204 :
Self(P), AS(AS) {}
1206 void takeToks(
CachedTokens &Cached) { Toks.swap(Cached); }
1216 struct LexedMethod :
public LateParsedDeclaration {
1221 explicit LexedMethod(
Parser *P, Decl *MD) : Self(P), D(MD) {}
1230 struct LateParsedDefaultArgument {
1231 explicit LateParsedDefaultArgument(
1232 Decl *P, std::unique_ptr<CachedTokens> Toks =
nullptr)
1233 : Param(P), Toks(std::move(Toks)) {}
1242 std::unique_ptr<CachedTokens> Toks;
1249 struct LateParsedMethodDeclaration :
public LateParsedDeclaration {
1250 explicit LateParsedMethodDeclaration(
Parser *P, Decl *M)
1251 : Self(P), Method(M), ExceptionSpecTokens(
nullptr) {}
1265 SmallVector<LateParsedDefaultArgument, 8> DefaultArgs;
1275 struct LateParsedMemberInitializer :
public LateParsedDeclaration {
1276 LateParsedMemberInitializer(
Parser *P, Decl *FD) : Self(P), Field(FD) {}
1296 typedef SmallVector<LateParsedDeclaration *, 2>
1297 LateParsedDeclarationsContainer;
1311 const ParsedAttributesView &AccessAttrs,
1312 ParsingDeclarator &D,
1313 const ParsedTemplateInfo &TemplateInfo,
1314 const VirtSpecifiers &VS,
1315 SourceLocation PureSpecLoc);
1318 StringLiteral *ParseCXXDeletedFunctionMessage();
1323 void SkipDeletedFunctionBody();
1329 void ParseCXXNonStaticMemberInitializer(Decl *VarD);
1333 void ParseLexedAttributes(ParsingClass &
Class);
1336 void ParseLexedAttributeList(LateParsedAttrList &LAs, Decl *D,
1351 void ParseLexedMethodDeclarations(ParsingClass &
Class);
1352 void ParseLexedMethodDeclaration(LateParsedMethodDeclaration &LM);
1357 void ParseLexedMethodDefs(ParsingClass &
Class);
1358 void ParseLexedMethodDef(LexedMethod &LM);
1364 void ParseLexedMemberInitializers(ParsingClass &
Class);
1365 void ParseLexedMemberInitializer(LateParsedMemberInitializer &MI);
1399 ParsedAttributes *Attrs =
nullptr);
1405 IdentifierInfo *Ident_vector;
1406 IdentifierInfo *Ident_bool;
1407 IdentifierInfo *Ident_Bool;
1411 IdentifierInfo *Ident_pixel;
1414 IdentifierInfo *Ident_introduced;
1417 IdentifierInfo *Ident_deprecated;
1420 IdentifierInfo *Ident_obsoleted;
1423 IdentifierInfo *Ident_unavailable;
1426 IdentifierInfo *Ident_message;
1429 IdentifierInfo *Ident_strict;
1432 IdentifierInfo *Ident_replacement;
1435 IdentifierInfo *Ident_environment;
1438 IdentifierInfo *Ident_language, *Ident_defined_in,
1439 *Ident_generated_declaration, *Ident_USR;
1442 AttributeFactory AttrFactory;
1447 bool TryAltiVecToken(DeclSpec &DS, SourceLocation Loc,
const char *&PrevSpec,
1452 if (Tok.getIdentifierInfo() != Ident_vector &&
1453 Tok.getIdentifierInfo() != Ident_bool &&
1454 Tok.getIdentifierInfo() != Ident_Bool &&
1455 (!
getLangOpts().AltiVec || Tok.getIdentifierInfo() != Ident_pixel))
1458 return TryAltiVecTokenOutOfLine(DS, Loc, PrevSpec, DiagID,
isInvalid);
1464 bool TryAltiVecVectorToken() {
1466 Tok.getIdentifierInfo() != Ident_vector)
1468 return TryAltiVecVectorTokenOutOfLine();
1473 bool TryAltiVecVectorTokenOutOfLine();
1474 bool TryAltiVecTokenOutOfLine(DeclSpec &DS, SourceLocation Loc,
1475 const char *&PrevSpec,
unsigned &DiagID,
1478 void ParseLexedCAttributeList(LateParsedAttrList &LA,
bool EnterScope,
1479 ParsedAttributes *OutAttrs =
nullptr);
1487 ParsedAttributes *OutAttrs =
nullptr);
1489 void ParseLexedPragmas(ParsingClass &
Class);
1490 void ParseLexedPragma(LateParsedPragma &LP);
1498 bool ConsumeAndStoreFunctionPrologue(
CachedTokens &Toks);
1514 bool ConsumeFinalToken =
true) {
1515 return ConsumeAndStoreUntil(T1, T1, Toks,
StopAtSemi, ConsumeFinalToken);
1526 bool ConsumeFinalToken =
true);
1534 enum class DeclSpecContext {
1539 DSC_alias_declaration,
1544 DSC_template_type_arg,
1545 DSC_objc_method_result,
1554 static bool isTypeSpecifier(DeclSpecContext DSC) {
1556 case DeclSpecContext::DSC_normal:
1557 case DeclSpecContext::DSC_template_param:
1558 case DeclSpecContext::DSC_template_arg:
1559 case DeclSpecContext::DSC_class:
1560 case DeclSpecContext::DSC_top_level:
1561 case DeclSpecContext::DSC_objc_method_result:
1562 case DeclSpecContext::DSC_condition:
1565 case DeclSpecContext::DSC_template_type_arg:
1566 case DeclSpecContext::DSC_type_specifier:
1567 case DeclSpecContext::DSC_conv_operator:
1568 case DeclSpecContext::DSC_trailing:
1569 case DeclSpecContext::DSC_alias_declaration:
1570 case DeclSpecContext::DSC_association:
1571 case DeclSpecContext::DSC_new:
1574 llvm_unreachable(
"Missing DeclSpecContext case");
1578 enum class AllowDefiningTypeSpec {
1595 static AllowDefiningTypeSpec
1596 isDefiningTypeSpecifierContext(DeclSpecContext DSC,
bool IsCPlusPlus) {
1598 case DeclSpecContext::DSC_normal:
1599 case DeclSpecContext::DSC_class:
1600 case DeclSpecContext::DSC_top_level:
1601 case DeclSpecContext::DSC_alias_declaration:
1602 case DeclSpecContext::DSC_objc_method_result:
1603 return AllowDefiningTypeSpec::Yes;
1605 case DeclSpecContext::DSC_condition:
1606 case DeclSpecContext::DSC_template_param:
1607 return AllowDefiningTypeSpec::YesButInvalid;
1609 case DeclSpecContext::DSC_template_type_arg:
1610 case DeclSpecContext::DSC_type_specifier:
1611 return AllowDefiningTypeSpec::NoButErrorRecovery;
1613 case DeclSpecContext::DSC_association:
1614 return IsCPlusPlus ? AllowDefiningTypeSpec::NoButErrorRecovery
1615 : AllowDefiningTypeSpec::Yes;
1617 case DeclSpecContext::DSC_trailing:
1618 case DeclSpecContext::DSC_conv_operator:
1619 case DeclSpecContext::DSC_template_arg:
1620 case DeclSpecContext::DSC_new:
1621 return AllowDefiningTypeSpec::No;
1623 llvm_unreachable(
"Missing DeclSpecContext case");
1627 static bool isOpaqueEnumDeclarationContext(DeclSpecContext DSC) {
1629 case DeclSpecContext::DSC_normal:
1630 case DeclSpecContext::DSC_class:
1631 case DeclSpecContext::DSC_top_level:
1634 case DeclSpecContext::DSC_alias_declaration:
1635 case DeclSpecContext::DSC_objc_method_result:
1636 case DeclSpecContext::DSC_condition:
1637 case DeclSpecContext::DSC_template_param:
1638 case DeclSpecContext::DSC_template_type_arg:
1639 case DeclSpecContext::DSC_type_specifier:
1640 case DeclSpecContext::DSC_trailing:
1641 case DeclSpecContext::DSC_association:
1642 case DeclSpecContext::DSC_conv_operator:
1643 case DeclSpecContext::DSC_template_arg:
1644 case DeclSpecContext::DSC_new:
1648 llvm_unreachable(
"Missing DeclSpecContext case");
1653 static bool isClassTemplateDeductionContext(DeclSpecContext DSC) {
1655 case DeclSpecContext::DSC_normal:
1656 case DeclSpecContext::DSC_template_param:
1657 case DeclSpecContext::DSC_template_arg:
1658 case DeclSpecContext::DSC_class:
1659 case DeclSpecContext::DSC_top_level:
1660 case DeclSpecContext::DSC_condition:
1661 case DeclSpecContext::DSC_type_specifier:
1662 case DeclSpecContext::DSC_association:
1663 case DeclSpecContext::DSC_conv_operator:
1664 case DeclSpecContext::DSC_new:
1667 case DeclSpecContext::DSC_objc_method_result:
1668 case DeclSpecContext::DSC_template_type_arg:
1669 case DeclSpecContext::DSC_trailing:
1670 case DeclSpecContext::DSC_alias_declaration:
1673 llvm_unreachable(
"Missing DeclSpecContext case");
1678 getImplicitTypenameContext(DeclSpecContext DSC) {
1680 case DeclSpecContext::DSC_class:
1681 case DeclSpecContext::DSC_top_level:
1682 case DeclSpecContext::DSC_type_specifier:
1683 case DeclSpecContext::DSC_template_type_arg:
1684 case DeclSpecContext::DSC_trailing:
1685 case DeclSpecContext::DSC_alias_declaration:
1686 case DeclSpecContext::DSC_template_param:
1687 case DeclSpecContext::DSC_new:
1688 case DeclSpecContext::DSC_conv_operator:
1691 case DeclSpecContext::DSC_normal:
1692 case DeclSpecContext::DSC_objc_method_result:
1693 case DeclSpecContext::DSC_condition:
1694 case DeclSpecContext::DSC_template_arg:
1695 case DeclSpecContext::DSC_association:
1698 llvm_unreachable(
"Missing DeclSpecContext case");
1703 struct ForRangeInit {
1704 SourceLocation ColonLoc;
1706 SmallVector<MaterializeTemporaryExpr *, 8> LifetimeExtendTemps;
1707 bool ParsedForRangeDecl() {
return !ColonLoc.
isInvalid(); }
1709 struct ForRangeInfo : ForRangeInit {
1732 SourceLocation &DeclEnd,
1733 ParsedAttributes &DeclAttrs,
1734 ParsedAttributes &DeclSpecAttrs,
1735 SourceLocation *DeclSpecStart =
nullptr);
1762 ParsedAttributes &DeclAttrs,
1763 ParsedAttributes &DeclSpecAttrs,
bool RequireSemi,
1764 ForRangeInit *FRI =
nullptr,
1765 SourceLocation *DeclSpecStart =
nullptr);
1775 ParsedAttributes &Attrs,
1776 ParsedTemplateInfo &TemplateInfo,
1777 SourceLocation *DeclEnd =
nullptr,
1778 ForRangeInit *FRI =
nullptr);
1804 Decl *ParseDeclarationAfterDeclarator(
1806 const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo());
1810 bool ParseAsmAttributesAfterDeclarator(Declarator &D);
1811 Decl *ParseDeclarationAfterDeclaratorAndAttributes(
1813 const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo(),
1814 ForRangeInit *FRI =
nullptr);
1825 bool ParseImplicitInt(DeclSpec &DS, CXXScopeSpec *SS,
1827 DeclSpecContext DSC, ParsedAttributes &Attrs);
1837 ParseDeclarationSpecifiers(DeclSpec &DS, ParsedTemplateInfo &TemplateInfo,
1839 DeclSpecContext DSC = DeclSpecContext::DSC_normal,
1840 LateParsedAttrList *LateAttrs =
nullptr) {
1841 return ParseDeclarationSpecifiers(DS, TemplateInfo, AS, DSC, LateAttrs,
1842 getImplicitTypenameContext(DSC));
1875 ParseDeclarationSpecifiers(DeclSpec &DS, ParsedTemplateInfo &TemplateInfo,
1877 LateParsedAttrList *LateAttrs,
1887 bool DiagnoseMissingSemiAfterTagDefinition(
1889 LateParsedAttrList *LateAttrs =
nullptr);
1891 void ParseSpecifierQualifierList(
1893 DeclSpecContext DSC = DeclSpecContext::DSC_normal) {
1894 ParseSpecifierQualifierList(DS, getImplicitTypenameContext(DSC), AS, DSC);
1905 void ParseSpecifierQualifierList(
1908 DeclSpecContext DSC = DeclSpecContext::DSC_normal);
1942 void ParseEnumSpecifier(SourceLocation TagLoc, DeclSpec &DS,
1943 const ParsedTemplateInfo &TemplateInfo,
1958 void ParseEnumBody(SourceLocation StartLoc, Decl *TagDecl,
1959 SkipBodyInfo *SkipBody =
nullptr);
1973 void ParseStructUnionBody(SourceLocation StartLoc,
DeclSpec::TST TagType,
1974 RecordDecl *TagDecl);
1999 void ParseStructDeclaration(
2000 ParsingDeclSpec &DS,
2001 llvm::function_ref<Decl *(ParsingFieldDeclarator &)> FieldsCallback,
2002 LateParsedAttrList *LateFieldAttrs =
nullptr);
2014 bool DisambiguatingWithExpression =
false);
2018 bool isTypeSpecifierQualifier(
const Token &Tok);
2023 bool isKnownToBeTypeSpecifier(
const Token &Tok)
const;
2028 bool isConstructorDeclarator(
2031 const ParsedTemplateInfo *TemplateInfo =
nullptr);
2035 void DiagnoseBitIntUse(
const Token &Tok);
2039 bool CheckProhibitedCXX11Attribute() {
2040 assert(Tok.is(tok::l_square));
2043 return DiagnoseProhibitedCXX11Attribute();
2054 bool DiagnoseProhibitedCXX11Attribute();
2056 void CheckMisplacedCXX11Attribute(ParsedAttributes &Attrs,
2057 SourceLocation CorrectLocation) {
2058 if (!Tok.isRegularKeywordAttribute() &&
2059 (Tok.isNot(tok::l_square) ||
NextToken().
isNot(tok::l_square)) &&
2060 Tok.isNot(tok::kw_alignas))
2062 DiagnoseMisplacedCXX11Attribute(Attrs, CorrectLocation);
2069 void DiagnoseMisplacedCXX11Attribute(ParsedAttributes &Attrs,
2070 SourceLocation CorrectLocation);
2080 void stripTypeAttributesOffDeclSpec(ParsedAttributes &Attrs, DeclSpec &DS,
2084 void ProhibitAttributes(ParsedAttributes &Attrs,
2085 SourceLocation FixItLoc = SourceLocation()) {
2086 if (Attrs.Range.isInvalid())
2088 DiagnoseProhibitedAttributes(Attrs, FixItLoc);
2092 void ProhibitAttributes(ParsedAttributesView &Attrs,
2093 SourceLocation FixItLoc = SourceLocation()) {
2094 if (Attrs.Range.isInvalid())
2096 DiagnoseProhibitedAttributes(Attrs, FixItLoc);
2097 Attrs.clearListOnly();
2099 void DiagnoseProhibitedAttributes(
const ParsedAttributesView &Attrs,
2100 SourceLocation FixItLoc);
2108 void ProhibitCXX11Attributes(ParsedAttributes &Attrs,
unsigned AttrDiagID,
2109 unsigned KeywordDiagId,
2110 bool DiagnoseEmptyAttrs =
false,
2111 bool WarnOnUnknownAttrs =
false);
2115 void DiagnoseCXX11AttributeExtension(ParsedAttributes &Attrs);
2117 ExprResult ParseUnevaluatedStringInAttribute(
const IdentifierInfo &AttrName);
2124 bool ParseAttributeArgumentList(
2125 const IdentifierInfo &AttrName, SmallVectorImpl<Expr *> &Exprs,
2126 ParsedAttributeArgumentsProperties ArgsProperties,
unsigned Arg);
2133 ParseAttributeArgsCommon(IdentifierInfo *AttrName, SourceLocation AttrNameLoc,
2134 ParsedAttributes &Attrs, SourceLocation *EndLoc,
2135 IdentifierInfo *ScopeName, SourceLocation ScopeLoc,
2136 ParsedAttr::Form Form);
2138 enum ParseAttrKindMask {
2140 PAKM_Declspec = 1 << 1,
2141 PAKM_CXX11 = 1 << 2,
2160 void ParseAttributes(
unsigned WhichAttrKinds, ParsedAttributes &Attrs,
2161 LateParsedAttrList *LateAttrs =
nullptr);
2164 bool MaybeParseAttributes(
unsigned WhichAttrKinds, ParsedAttributes &Attrs,
2165 LateParsedAttrList *LateAttrs =
nullptr) {
2166 if (Tok.isOneOf(tok::kw___attribute, tok::kw___declspec) ||
2167 isAllowedCXX11AttributeSpecifier()) {
2168 ParseAttributes(WhichAttrKinds, Attrs, LateAttrs);
2174 void MaybeParseGNUAttributes(Declarator &D,
2175 LateParsedAttrList *LateAttrs =
nullptr) {
2176 if (Tok.is(tok::kw___attribute)) {
2177 ParsedAttributes Attrs(AttrFactory);
2178 ParseGNUAttributes(Attrs, LateAttrs, &D);
2179 D.takeAttributesAppending(Attrs);
2183 bool MaybeParseGNUAttributes(ParsedAttributes &Attrs,
2184 LateParsedAttrList *LateAttrs =
nullptr) {
2185 if (Tok.is(tok::kw___attribute)) {
2186 ParseGNUAttributes(Attrs, LateAttrs);
2208 bool ParseSingleGNUAttribute(ParsedAttributes &Attrs, SourceLocation &EndLoc,
2209 LateParsedAttrList *LateAttrs =
nullptr,
2210 Declarator *D =
nullptr);
2255 void ParseGNUAttributes(ParsedAttributes &Attrs,
2256 LateParsedAttrList *LateAttrs =
nullptr,
2257 Declarator *D =
nullptr);
2261 void ParseGNUAttributeArgs(IdentifierInfo *AttrName,
2262 SourceLocation AttrNameLoc,
2263 ParsedAttributes &Attrs, SourceLocation *EndLoc,
2264 IdentifierInfo *ScopeName, SourceLocation ScopeLoc,
2265 ParsedAttr::Form Form, Declarator *D);
2266 IdentifierLoc *ParseIdentifierLoc();
2269 ParseClangAttributeArgs(IdentifierInfo *AttrName, SourceLocation AttrNameLoc,
2270 ParsedAttributes &Attrs, SourceLocation *EndLoc,
2271 IdentifierInfo *ScopeName, SourceLocation ScopeLoc,
2272 ParsedAttr::Form Form);
2274 void MaybeParseCXX11Attributes(Declarator &D) {
2275 if (isAllowedCXX11AttributeSpecifier()) {
2276 ParsedAttributes Attrs(AttrFactory);
2277 ParseCXX11Attributes(Attrs);
2278 D.takeAttributesAppending(Attrs);
2282 bool MaybeParseCXX11Attributes(ParsedAttributes &Attrs,
2283 bool OuterMightBeMessageSend =
false) {
2284 if (isAllowedCXX11AttributeSpecifier(
false, OuterMightBeMessageSend)) {
2285 ParseCXX11Attributes(Attrs);
2291 bool MaybeParseMicrosoftAttributes(ParsedAttributes &Attrs) {
2292 bool AttrsParsed =
false;
2294 Tok.is(tok::l_square)) {
2295 ParsedAttributes AttrsWithRange(AttrFactory);
2296 ParseMicrosoftAttributes(AttrsWithRange);
2297 AttrsParsed = !AttrsWithRange.empty();
2298 Attrs.takeAllAppendingFrom(AttrsWithRange);
2302 bool MaybeParseMicrosoftDeclSpecs(ParsedAttributes &Attrs) {
2303 if (
getLangOpts().DeclSpecKeyword && Tok.is(tok::kw___declspec)) {
2304 ParseMicrosoftDeclSpecs(Attrs);
2318 void ParseMicrosoftDeclSpecs(ParsedAttributes &Attrs);
2319 bool ParseMicrosoftDeclSpecArgs(IdentifierInfo *AttrName,
2320 SourceLocation AttrNameLoc,
2321 ParsedAttributes &Attrs);
2322 void ParseMicrosoftTypeAttributes(ParsedAttributes &attrs);
2323 void ParseWebAssemblyFuncrefTypeAttribute(ParsedAttributes &Attrs);
2324 void DiagnoseAndSkipExtendedMicrosoftTypeAttributes();
2325 SourceLocation SkipExtendedMicrosoftTypeAttributes();
2327 void ParseBorlandTypeAttributes(ParsedAttributes &attrs);
2328 void ParseOpenCLKernelAttributes(ParsedAttributes &attrs);
2329 void ParseOpenCLQualifiers(ParsedAttributes &Attrs);
2330 void ParseNullabilityTypeSpecifiers(ParsedAttributes &attrs);
2331 void ParseCUDAFunctionAttributes(ParsedAttributes &attrs);
2332 bool isHLSLQualifier(
const Token &Tok)
const;
2333 void ParseHLSLQualifiers(ParsedAttributes &Attrs);
2345 VersionTuple ParseVersionTuple(SourceRange &Range);
2374 void ParseAvailabilityAttribute(IdentifierInfo &Availability,
2375 SourceLocation AvailabilityLoc,
2376 ParsedAttributes &attrs,
2377 SourceLocation *endLoc,
2378 IdentifierInfo *ScopeName,
2379 SourceLocation ScopeLoc,
2380 ParsedAttr::Form Form);
2398 void ParseExternalSourceSymbolAttribute(IdentifierInfo &ExternalSourceSymbol,
2400 ParsedAttributes &Attrs,
2401 SourceLocation *EndLoc,
2402 IdentifierInfo *ScopeName,
2403 SourceLocation ScopeLoc,
2404 ParsedAttr::Form Form);
2419 void ParseObjCBridgeRelatedAttribute(IdentifierInfo &ObjCBridgeRelated,
2420 SourceLocation ObjCBridgeRelatedLoc,
2421 ParsedAttributes &Attrs,
2422 SourceLocation *EndLoc,
2423 IdentifierInfo *ScopeName,
2424 SourceLocation ScopeLoc,
2425 ParsedAttr::Form Form);
2427 void ParseSwiftNewTypeAttribute(IdentifierInfo &AttrName,
2428 SourceLocation AttrNameLoc,
2429 ParsedAttributes &Attrs,
2430 SourceLocation *EndLoc,
2431 IdentifierInfo *ScopeName,
2432 SourceLocation ScopeLoc,
2433 ParsedAttr::Form Form);
2435 void ParseTypeTagForDatatypeAttribute(IdentifierInfo &AttrName,
2436 SourceLocation AttrNameLoc,
2437 ParsedAttributes &Attrs,
2438 SourceLocation *EndLoc,
2439 IdentifierInfo *ScopeName,
2440 SourceLocation ScopeLoc,
2441 ParsedAttr::Form Form);
2443 void ParseAttributeWithTypeArg(IdentifierInfo &AttrName,
2444 SourceLocation AttrNameLoc,
2445 ParsedAttributes &Attrs,
2446 IdentifierInfo *ScopeName,
2447 SourceLocation ScopeLoc,
2448 ParsedAttr::Form Form);
2450 void DistributeCLateParsedAttrs(Decl *Dcl, LateParsedAttrList *LateAttrs);
2456 void ParseBoundsAttribute(IdentifierInfo &AttrName,
2457 SourceLocation AttrNameLoc, ParsedAttributes &Attrs,
2458 IdentifierInfo *ScopeName, SourceLocation ScopeLoc,
2459 ParsedAttr::Form Form);
2475 void ParseTypeofSpecifier(DeclSpec &DS);
2482 void ParseAtomicSpecifier(DeclSpec &DS);
2492 ExprResult ParseAlignArgument(StringRef KWName, SourceLocation Start,
2493 SourceLocation &EllipsisLoc,
bool &IsType,
2506 void ParseAlignmentSpecifier(ParsedAttributes &Attrs,
2507 SourceLocation *endLoc =
nullptr);
2516 void ParsePtrauthQualifier(ParsedAttributes &Attrs);
2521 class DeclaratorScopeObj {
2528 DeclaratorScopeObj(
Parser &p, CXXScopeSpec &ss)
2529 : P(p), SS(ss), EnteredScope(
false), CreatedScope(
false) {}
2531 void EnterDeclaratorScope() {
2532 assert(!EnteredScope &&
"Already entered the scope!");
2533 assert(SS.isSet() &&
"C++ scope was not set!");
2535 CreatedScope =
true;
2538 if (!P.Actions.ActOnCXXEnterDeclaratorScope(P.getCurScope(), SS))
2539 EnteredScope =
true;
2542 ~DeclaratorScopeObj() {
2544 assert(SS.isSet() &&
"C++ scope was cleared ?");
2545 P.Actions.ActOnCXXExitDeclaratorScope(P.getCurScope(), SS);
2553 void ParseDeclarator(Declarator &D);
2584 void ParseDeclaratorInternal(Declarator &D,
2585 DirectDeclParseFunction DirectDeclParser);
2587 enum AttrRequirements {
2588 AR_NoAttributesParsed = 0,
2589 AR_GNUAttributesParsedAndRejected = 1 << 0,
2590 AR_GNUAttributesParsed = 1 << 1,
2591 AR_CXX11AttributesParsed = 1 << 2,
2592 AR_DeclspecAttributesParsed = 1 << 3,
2593 AR_AllAttributesParsed = AR_GNUAttributesParsed | AR_CXX11AttributesParsed |
2594 AR_DeclspecAttributesParsed,
2595 AR_VendorAttributesParsed =
2596 AR_GNUAttributesParsed | AR_DeclspecAttributesParsed
2613 void ParseTypeQualifierListOpt(
2614 DeclSpec &DS,
unsigned AttrReqs = AR_AllAttributesParsed,
2615 bool AtomicOrPtrauthAllowed =
true,
bool IdentifierRequired =
false,
2616 llvm::function_ref<
void()> CodeCompletionHandler = {});
2666 void ParseDirectDeclarator(Declarator &D);
2667 void ParseDecompositionDeclarator(Declarator &D);
2685 void ParseParenDeclarator(Declarator &D);
2710 void ParseFunctionDeclarator(Declarator &D, ParsedAttributes &FirstArgAttrs,
2712 bool IsAmbiguous,
bool RequiresArg =
false);
2713 void InitCXXThisScopeForDeclaratorIfRelevant(
2714 const Declarator &D,
const DeclSpec &DS,
2715 std::optional<Sema::CXXThisScopeRAII> &ThisScope);
2719 bool ParseRefQualifier(
bool &RefQualifierIsLValueRef,
2720 SourceLocation &RefQualifierLoc);
2727 bool isFunctionDeclaratorIdentifierList();
2741 void ParseFunctionDeclaratorIdentifierList(
2742 Declarator &D, SmallVectorImpl<DeclaratorChunk::ParamInfo> &ParamInfo);
2743 void ParseParameterDeclarationClause(
2744 Declarator &D, ParsedAttributes &attrs,
2745 SmallVectorImpl<DeclaratorChunk::ParamInfo> &ParamInfo,
2746 SourceLocation &EllipsisLoc) {
2747 return ParseParameterDeclarationClause(
2748 D.getContext(), attrs, ParamInfo, EllipsisLoc,
2749 D.getCXXScopeSpec().isSet() &&
2750 D.isFunctionDeclaratorAFunctionDeclaration());
2788 void ParseParameterDeclarationClause(
2790 SmallVectorImpl<DeclaratorChunk::ParamInfo> &ParamInfo,
2791 SourceLocation &EllipsisLoc,
bool IsACXXFunctionDeclaration =
false);
2802 void ParseBracketDeclarator(Declarator &D);
2805 void ParseMisplacedBracketDeclarator(Declarator &D);
2816 TypeResult ParseTypeFromString(StringRef TypeStr, StringRef Context,
2817 SourceLocation IncludeLoc);
2833 mutable IdentifierInfo *Ident_sealed;
2834 mutable IdentifierInfo *Ident_abstract;
2837 mutable IdentifierInfo *Ident_final;
2838 mutable IdentifierInfo *Ident_GNU_final;
2839 mutable IdentifierInfo *Ident_override;
2844 struct ParsingClass {
2845 ParsingClass(Decl *TagOrTemplate,
bool TopLevelClass,
bool IsInterface)
2846 : TopLevelClass(TopLevelClass), IsInterface(IsInterface),
2847 TagOrTemplate(TagOrTemplate) {}
2851 bool TopLevelClass : 1;
2854 bool IsInterface : 1;
2857 Decl *TagOrTemplate;
2862 LateParsedDeclarationsContainer LateParsedDeclarations;
2868 std::stack<ParsingClass *> ClassStack;
2870 ParsingClass &getCurrentClass() {
2871 assert(!ClassStack.empty() &&
"No lexed method stacks!");
2872 return *ClassStack.top();
2876 class ParsingClassDefinition {
2882 ParsingClassDefinition(
Parser &P, Decl *TagOrTemplate,
bool TopLevelClass,
2884 : P(P), Popped(
false),
2885 State(P.PushParsingClass(TagOrTemplate, TopLevelClass, IsInterface)) {
2890 assert(!Popped &&
"Nested class has already been popped");
2892 P.PopParsingClass(State);
2895 ~ParsingClassDefinition() {
2897 P.PopParsingClass(State);
2913 bool Delayed, SourceRange &SpecificationRange,
2914 SmallVectorImpl<ParsedType> &DynamicExceptions,
2915 SmallVectorImpl<SourceRange> &DynamicExceptionRanges,
2933 ParseDynamicExceptionSpecification(SourceRange &SpecificationRange,
2934 SmallVectorImpl<ParsedType> &Exceptions,
2935 SmallVectorImpl<SourceRange> &Ranges);
2942 TypeResult ParseTrailingReturnType(SourceRange &Range,
2943 bool MayBeFollowedByDirectInit);
2946 void ParseTrailingRequiresClauseWithScope(Declarator &D);
2947 void ParseTrailingRequiresClause(Declarator &D);
2949 void ParseMicrosoftIfExistsClassDeclaration(
DeclSpec::TST TagType,
2950 ParsedAttributes &AccessAttrs,
2953 SourceLocation ParsePackIndexingType(DeclSpec &DS);
2954 void AnnotateExistingIndexedTypeNamePack(
ParsedType T,
2955 SourceLocation StartLoc,
2956 SourceLocation EndLoc);
2963 bool isAllowedCXX11AttributeSpecifier(
bool Disambiguate =
false,
2964 bool OuterMightBeMessageSend =
false) {
2965 return (Tok.isRegularKeywordAttribute() ||
2966 isCXX11AttributeSpecifier(Disambiguate, OuterMightBeMessageSend) !=
2973 SourceLocation SkipCXX11Attributes();
2977 void DiagnoseAndSkipCXX11Attributes();
2979 void ParseOpenMPAttributeArgs(
const IdentifierInfo *AttrName,
3008 void ParseCXX11AttributeSpecifierInternal(ParsedAttributes &Attrs,
3010 SourceLocation *EndLoc =
nullptr);
3011 void ParseCXX11AttributeSpecifier(ParsedAttributes &Attrs,
3012 SourceLocation *EndLoc =
nullptr) {
3014 ParseCXX11AttributeSpecifierInternal(Attrs, OpenMPTokens, EndLoc);
3015 ReplayOpenMPAttributeTokens(OpenMPTokens);
3024 void ParseCXX11Attributes(ParsedAttributes &attrs);
3044 bool ParseCXX11AttributeArgs(IdentifierInfo *AttrName,
3045 SourceLocation AttrNameLoc,
3046 ParsedAttributes &Attrs, SourceLocation *EndLoc,
3047 IdentifierInfo *ScopeName,
3048 SourceLocation ScopeLoc,
3054 ParseCXXAssumeAttributeArg(ParsedAttributes &Attrs, IdentifierInfo *AttrName,
3055 SourceLocation AttrNameLoc,
3056 IdentifierInfo *ScopeName, SourceLocation ScopeLoc,
3057 SourceLocation *EndLoc, ParsedAttr::Form Form);
3068 IdentifierInfo *TryParseCXX11AttributeIdentifier(
3069 SourceLocation &Loc,
3072 const IdentifierInfo *EnclosingScope =
nullptr);
3075 void ParseMicrosoftUuidAttributeArgs(ParsedAttributes &Attrs);
3087 void ParseMicrosoftAttributes(ParsedAttributes &Attrs);
3089 void ParseMicrosoftInheritanceClassAttributes(ParsedAttributes &attrs);
3090 void ParseNullabilityClassAttributes(ParsedAttributes &attrs);
3099 SourceLocation ParseDecltypeSpecifier(DeclSpec &DS);
3100 void AnnotateExistingDecltypeSpecifier(
const DeclSpec &DS,
3101 SourceLocation StartLoc,
3102 SourceLocation EndLoc);
3115 return isCXX11VirtSpecifier(Tok);
3125 void ParseOptionalCXX11VirtSpecifierSeq(VirtSpecifiers &VS,
bool IsInterface,
3126 SourceLocation FriendLoc);
3130 bool isCXX11FinalKeyword()
const;
3136 bool isClassCompatibleKeyword()
const;
3138 bool MaybeParseTypeTransformTypeSpecifier(DeclSpec &DS);
3141 void DiagnoseUnexpectedNamespace(NamedDecl *Context);
3173 SourceLocation &DeclEnd,
3174 SourceLocation InlineLoc = SourceLocation());
3176 struct InnerNamespaceInfo {
3177 SourceLocation NamespaceLoc;
3178 SourceLocation InlineLoc;
3179 SourceLocation IdentLoc;
3180 IdentifierInfo *Ident;
3182 using InnerNamespaceInfoList = llvm::SmallVector<InnerNamespaceInfo, 4>;
3185 void ParseInnerNamespace(
const InnerNamespaceInfoList &InnerNSs,
3186 unsigned int index, SourceLocation &InlineLoc,
3187 ParsedAttributes &attrs,
3219 Decl *ParseExportDeclaration();
3225 SourceLocation &DeclEnd, ParsedAttributes &Attrs);
3240 SourceLocation &DeclEnd, ParsedAttributes &attrs);
3242 struct UsingDeclarator {
3243 SourceLocation TypenameLoc;
3246 SourceLocation EllipsisLoc;
3249 TypenameLoc = EllipsisLoc = SourceLocation();
3290 const ParsedTemplateInfo &TemplateInfo,
3291 SourceLocation UsingLoc,
3292 SourceLocation &DeclEnd,
3293 ParsedAttributes &Attrs,
3295 Decl *ParseAliasDeclarationAfterDeclarator(
3296 const ParsedTemplateInfo &TemplateInfo, SourceLocation UsingLoc,
3298 ParsedAttributes &Attrs, Decl **OwnedType =
nullptr);
3311 Decl *ParseStaticAssertDeclaration(SourceLocation &DeclEnd);
3316 Decl *ParseNamespaceAlias(SourceLocation NamespaceLoc,
3317 SourceLocation AliasLoc, IdentifierInfo *Alias,
3318 SourceLocation &DeclEnd);
3326 bool isValidAfterTypeSpecifier(
bool CouldBeBitfield);
3370 void ParseClassSpecifier(
tok::TokenKind TagTokKind, SourceLocation TagLoc,
3371 DeclSpec &DS, ParsedTemplateInfo &TemplateInfo,
3373 DeclSpecContext DSC, ParsedAttributes &Attributes);
3374 void SkipCXXMemberSpecification(SourceLocation StartLoc,
3375 SourceLocation AttrFixitLoc,
unsigned TagType,
3386 void ParseCXXMemberSpecification(SourceLocation StartLoc,
3387 SourceLocation AttrFixitLoc,
3388 ParsedAttributes &Attrs,
unsigned TagType,
3413 ExprResult ParseCXXMemberInitializer(Decl *D,
bool IsFunction,
3414 SourceLocation &EqualLoc);
3418 bool ParseCXXMemberDeclaratorBeforeInitializer(Declarator &DeclaratorInfo,
3421 LateParsedAttrList &LateAttrs);
3426 MaybeParseAndDiagnoseDeclSpecAfterCXX11VirtSpecifierSeq(Declarator &D,
3427 VirtSpecifiers &VS);
3483 ParsedTemplateInfo &TemplateInfo,
3484 ParsingDeclRAIIObject *DiagsFromTParams =
nullptr);
3487 ParsedAttributes &AccessAttrs,
3513 void ParseConstructorInitializer(Decl *ConstructorDecl);
3535 void HandleMemberFunctionDeclDelays(Declarator &DeclaratorInfo,
3563 TypeResult ParseBaseTypeSpecifier(SourceLocation &BaseLoc,
3564 SourceLocation &EndLocation);
3576 void ParseBaseClause(Decl *ClassDecl);
3591 BaseResult ParseBaseSpecifier(Decl *ClassDecl);
3607 bool isClassCompatibleKeyword(Token Tok)
const;
3609 void ParseHLSLRootSignatureAttributeArgs(ParsedAttributes &Attrs);
3784 bool GreaterThanIsOperator;
3788 llvm::SmallDenseMap<IdentifierInfo *, tok::TokenKind> RevertibleTypeTraits;
3807 PushParsingClass(
Decl *TagOrTemplate,
bool TopLevelClass,
bool IsInterface);
3811 void DeallocateParsedClasses(ParsingClass *
Class);
4032 bool isAddressOfOperand,
bool &NotCastExpr,
4034 bool isVectorLiteral =
false,
4035 bool *NotPrimaryExpression =
nullptr);
4037 bool isAddressOfOperand =
false,
4040 bool isVectorLiteral =
false,
4041 bool *NotPrimaryExpression =
nullptr);
4044 bool isNotExpressionStart();
4048 bool isPostfixExpressionSuffixStart() {
4050 return (K == tok::l_square || K == tok::l_paren || K == tok::period ||
4051 K == tok::arrow || K == tok::plusplus || K == tok::minusminus);
4093 ExprResult ParseUnaryExprOrTypeTraitExpression();
4122 ExprResult ParseSYCLUniqueStableNameExpression();
4184 llvm::function_ref<
void()> ExpressionStarts =
4185 llvm::function_ref<
void()>(),
4186 bool FailImmediatelyOnInvalidExpr =
false);
4231 bool StopIfCastExpr,
4268 ExprResult ParseGenericSelectionExpression();
4287 void injectEmbedTokens();
4313 ExprResult ParseAssignmentExprWithObjCMessageExprStart(
4315 Expr *ReceiverExpr);
4320 bool isKnownToBeDeclarationSpecifier() {
4334 bool isTypeIdForGenericSelection() {
4340 return isTypeSpecifierQualifier(Tok);
4346 bool isTypeIdUnambiguously() {
4351 return isTypeSpecifierQualifier(Tok);
4360 void ParseBlockId(SourceLocation CaretLoc);
4369 std::optional<AvailabilitySpec> ParseAvailabilitySpec();
4370 ExprResult ParseAvailabilityCheckExpr(SourceLocation StartLoc);
4376 bool tryParseOpenMPArrayShapingCastPart();
4378 ExprResult ParseBuiltinPtrauthTypeDiscriminator();
4431 bool ObjectHadErrors,
bool EnteringContext,
4432 bool AllowDestructorName,
bool AllowConstructorName,
4433 bool AllowDeductionGuide,
4434 SourceLocation *TemplateKWLoc, UnqualifiedId &
Result);
4452 ExprResult tryParseCXXIdExpression(CXXScopeSpec &SS,
bool isAddressOfOperand);
4503 ExprResult ParseCXXIdExpression(
bool isAddressOfOperand =
false);
4506 bool areTokensAdjacent(
const Token &A,
const Token &B);
4510 void CheckForTemplateAndDigraph(Token &
Next,
ParsedType ObjectTypePtr,
4511 bool EnteringContext, IdentifierInfo &II,
4574 bool ParseOptionalCXXScopeSpecifier(
4575 CXXScopeSpec &SS,
ParsedType ObjectType,
bool ObjectHasErrors,
4576 bool EnteringContext,
bool *MayBePseudoDestructor =
nullptr,
4577 bool IsTypename =
false,
const IdentifierInfo **LastII =
nullptr,
4578 bool OnlyNamespace =
false,
bool InUsingDeclaration =
false,
4579 bool Disambiguation =
false,
bool IsAddressOfOperand =
false,
4580 bool IsInDeclarationContext =
false);
4582 bool ParseOptionalCXXScopeSpecifier(CXXScopeSpec &SS,
ParsedType ObjectType,
4583 bool ObjectHasErrors,
4584 bool EnteringContext,
4585 bool IsAddressOfOperand) {
4586 return ParseOptionalCXXScopeSpecifier(
4587 SS, ObjectType, ObjectHasErrors, EnteringContext,
4594 IsAddressOfOperand);
4601 enum class LambdaIntroducerTentativeParse {
4679 ParseLambdaIntroducer(LambdaIntroducer &Intro,
4680 LambdaIntroducerTentativeParse *Tentative =
nullptr);
4684 ExprResult ParseLambdaExpressionAfterIntroducer(LambdaIntroducer &Intro);
4768 ExprResult ParseCXXPseudoDestructor(Expr *Base, SourceLocation OpLoc,
4823 ExprResult ParseCXXTypeConstructExpression(
const DeclSpec &DS);
4853 void ParseCXXSimpleTypeSpecifier(DeclSpec &DS);
4868 bool ParseCXXTypeSpecifierSeq(
4886 bool ParseExpressionListOrTypeId(SmallVectorImpl<Expr *> &Exprs,
4898 void ParseDirectNewDeclarator(Declarator &D);
4931 ExprResult ParseCXXNewExpression(
bool UseGlobal, SourceLocation Start);
4946 ExprResult ParseCXXDeleteExpression(
bool UseGlobal, SourceLocation Start);
4985 Sema::ConditionResult ParseCXXCondition(
StmtResult *InitStmt,
4989 ForRangeInfo *FRI =
nullptr,
4990 bool EnterForConditionScope =
false);
4992 ParsedAttributes &Attrs);
5039 bool isTypeIdInParens(
bool &isAmbiguous) {
5042 isAmbiguous =
false;
5043 return isTypeSpecifierQualifier(Tok);
5045 bool isTypeIdInParens() {
5047 return isTypeIdInParens(isAmbiguous);
5085 bool ParseUnqualifiedIdTemplateId(CXXScopeSpec &SS,
ParsedType ObjectType,
5086 bool ObjectHadErrors,
5087 SourceLocation TemplateKWLoc,
5088 IdentifierInfo *Name,
5089 SourceLocation NameLoc,
5090 bool EnteringContext, UnqualifiedId &Id,
5091 bool AssumeTemplateId);
5133 bool ParseUnqualifiedIdOperator(CXXScopeSpec &SS,
bool EnteringContext,
5200 bool MaybeParseHLSLAnnotations(Declarator &D,
5201 SourceLocation *EndLoc =
nullptr,
5202 bool CouldBeBitField =
false) {
5203 assert(
getLangOpts().
HLSL &&
"MaybeParseHLSLAnnotations is for HLSL only");
5204 if (Tok.is(tok::colon)) {
5205 ParsedAttributes Attrs(AttrFactory);
5206 ParseHLSLAnnotations(Attrs, EndLoc, CouldBeBitField);
5207 D.takeAttributesAppending(Attrs);
5213 void MaybeParseHLSLAnnotations(ParsedAttributes &Attrs,
5214 SourceLocation *EndLoc =
nullptr) {
5215 assert(
getLangOpts().
HLSL &&
"MaybeParseHLSLAnnotations is for HLSL only");
5216 if (Tok.is(tok::colon))
5217 ParseHLSLAnnotations(Attrs, EndLoc);
5220 struct ParsedSemantic {
5221 StringRef Name =
"";
5223 bool Explicit =
false;
5226 ParsedSemantic ParseHLSLSemantic();
5228 void ParseHLSLAnnotations(ParsedAttributes &Attrs,
5229 SourceLocation *EndLoc =
nullptr,
5230 bool CouldBeBitField =
false);
5231 Decl *ParseHLSLBuffer(SourceLocation &DeclEnd, ParsedAttributes &Attrs);
5255 ExprResult ParseInitializer(Decl *DeclForInitializer =
nullptr);
5260 bool MayBeDesignationStart();
5278 struct DesignatorCompletionInfo {
5279 SmallVectorImpl<Expr *> &InitExprs;
5280 QualType PreferredBaseType;
5329 ExprResult ParseInitializerWithPotentialDesignator(DesignatorCompletionInfo);
5334 typedef SmallVector<Expr *, 12> ExprVector;
5338 bool ParseMicrosoftIfExistsBraceInitializer(ExprVector &InitExprs,
5355 friend class ObjCDeclContextSwitch;
5358 return Actions.ObjC().getObjCDeclContext();
5364 return Actions.getNullabilityKeyword(nullability);
5380 bool InMessageExpression;
5387 bool ParsingInObjCContainer;
5392 bool isObjCInstancetype() {
5394 if (
Tok.isAnnotation())
5396 if (!Ident_instancetype)
5398 return Tok.getIdentifierInfo() == Ident_instancetype;
5406 ObjCContainerDecl *DC;
5407 SaveAndRestore<bool> WithinObjCContainer;
5412 WithinObjCContainer(P.ParsingInObjCContainer, DC !=
nullptr) {
5414 P.Actions.ObjC().ActOnObjCTemporaryExitContainerContext(DC);
5416 ~ObjCDeclContextSwitch() {
5418 P.Actions.ObjC().ActOnObjCReenterContainerContext(DC);
5422 void CheckNestedObjCContexts(SourceLocation AtLoc);
5424 void ParseLexedObjCMethodDefs(LexedMethod &LM,
bool parseMethod);
5442 DeclGroupPtrTy ParseObjCAtDirectives(ParsedAttributes &DeclAttrs,
5443 ParsedAttributes &DeclSpecAttrs);
5454 DeclGroupPtrTy ParseObjCAtClassDeclaration(SourceLocation atLoc);
5487 Decl *ParseObjCAtInterfaceDeclaration(SourceLocation AtLoc,
5488 ParsedAttributes &prefixAttrs);
5494 ObjCTypeParamList *parseObjCTypeParamList();
5522 ObjCTypeParamList *parseObjCTypeParamListOrProtocolRefs(
5524 SmallVectorImpl<IdentifierLoc> &protocolIdents, SourceLocation &rAngleLoc,
5525 bool mayBeProtocolList =
true);
5527 void HelperActionsForIvarDeclarations(ObjCContainerDecl *interfaceDecl,
5528 SourceLocation atLoc,
5530 SmallVectorImpl<Decl *> &AllIvarDecls,
5531 bool RBraceMissing);
5556 void ParseObjCClassInstanceVariables(ObjCContainerDecl *interfaceDecl,
5558 SourceLocation atLoc);
5565 bool ParseObjCProtocolReferences(
5566 SmallVectorImpl<Decl *> &P, SmallVectorImpl<SourceLocation> &PLocs,
5567 bool WarnOnDeclarations,
bool ForObjCContainer, SourceLocation &LAngleLoc,
5568 SourceLocation &EndProtoLoc,
bool consumeLastToken);
5579 void parseObjCTypeArgsOrProtocolQualifiers(
5580 ParsedType baseType, SourceLocation &typeArgsLAngleLoc,
5581 SmallVectorImpl<ParsedType> &typeArgs, SourceLocation &typeArgsRAngleLoc,
5582 SourceLocation &protocolLAngleLoc, SmallVectorImpl<Decl *> &protocols,
5583 SmallVectorImpl<SourceLocation> &protocolLocs,
5584 SourceLocation &protocolRAngleLoc,
bool consumeLastToken,
5585 bool warnOnIncompleteProtocols);
5589 void parseObjCTypeArgsAndProtocolQualifiers(
5590 ParsedType baseType, SourceLocation &typeArgsLAngleLoc,
5591 SmallVectorImpl<ParsedType> &typeArgs, SourceLocation &typeArgsRAngleLoc,
5592 SourceLocation &protocolLAngleLoc, SmallVectorImpl<Decl *> &protocols,
5593 SmallVectorImpl<SourceLocation> &protocolLocs,
5594 SourceLocation &protocolRAngleLoc,
bool consumeLastToken);
5598 TypeResult parseObjCProtocolQualifierType(SourceLocation &rAngleLoc);
5602 TypeResult parseObjCTypeArgsAndProtocolQualifiers(SourceLocation loc,
5604 bool consumeLastToken,
5605 SourceLocation &endLoc);
5641 DeclGroupPtrTy ParseObjCAtProtocolDeclaration(SourceLocation atLoc,
5642 ParsedAttributes &prefixAttrs);
5644 struct ObjCImplParsingDataRAII {
5648 typedef SmallVector<LexedMethod *, 8> LateParsedObjCMethodContainer;
5649 LateParsedObjCMethodContainer LateParsedObjCMethods;
5651 ObjCImplParsingDataRAII(
Parser &parser, Decl *D)
5652 : P(parser), Dcl(D), HasCFunction(
false) {
5653 P.CurParsedObjCImpl =
this;
5656 ~ObjCImplParsingDataRAII();
5658 void finish(SourceRange AtEnd);
5659 bool isFinished()
const {
return Finished; }
5664 ObjCImplParsingDataRAII *CurParsedObjCImpl;
5668 void StashAwayMethodOrFunctionBodyTokens(Decl *MDecl);
5682 DeclGroupPtrTy ParseObjCAtImplementationDeclaration(SourceLocation AtLoc,
5683 ParsedAttributes &Attrs);
5691 Decl *ParseObjCAtAliasDeclaration(SourceLocation atLoc);
5706 Decl *ParseObjCPropertySynthesize(SourceLocation atLoc);
5717 Decl *ParseObjCPropertyDynamic(SourceLocation atLoc);
5729 IdentifierInfo *ParseObjCSelectorPiece(SourceLocation &MethodLocation);
5737 bool isTokIdentifier_in()
const;
5746 ParsedAttributes *ParamAttrs);
5760 Decl *ParseObjCMethodPrototype(
5762 bool MethodDefinition =
true);
5794 Decl *ParseObjCMethodDecl(
5797 bool MethodDefinition =
true);
5827 void ParseObjCPropertyAttribute(ObjCDeclSpec &DS);
5833 Decl *ParseObjCMethodDefinition();
5837 ExprResult ParseObjCAtExpression(SourceLocation AtLocation);
5838 ExprResult ParseObjCStringLiteral(SourceLocation AtLoc);
5845 ExprResult ParseObjCCharacterLiteral(SourceLocation AtLoc);
5854 ExprResult ParseObjCNumericLiteral(SourceLocation AtLoc);
5863 ExprResult ParseObjCBooleanLiteral(SourceLocation AtLoc,
bool ArgValue);
5865 ExprResult ParseObjCArrayLiteral(SourceLocation AtLoc);
5866 ExprResult ParseObjCDictionaryLiteral(SourceLocation AtLoc);
5873 ExprResult ParseObjCBoxedExpr(SourceLocation AtLoc);
5879 ExprResult ParseObjCEncodeExpression(SourceLocation AtLoc);
5885 ExprResult ParseObjCSelectorExpression(SourceLocation AtLoc);
5891 ExprResult ParseObjCProtocolExpression(SourceLocation AtLoc);
5898 bool isSimpleObjCMessageExpression();
5953 ExprResult ParseObjCMessageExpressionBody(SourceLocation LBracloc,
5954 SourceLocation SuperLoc,
5956 Expr *ReceiverExpr);
5982 bool ParseObjCXXMessageReceiver(
bool &IsExpr,
void *&TypeOrExpr);
5987 enum class ParsedStmtContext;
5989 StmtResult ParseObjCAtStatement(SourceLocation atLoc,
5990 ParsedStmtContext StmtCtx);
6005 StmtResult ParseObjCTryStmt(SourceLocation atLoc);
6012 StmtResult ParseObjCThrowStmt(SourceLocation atLoc);
6019 StmtResult ParseObjCSynchronizedStmt(SourceLocation atLoc);
6026 StmtResult ParseObjCAutoreleasePoolStmt(SourceLocation atLoc);
6053 bool isStartOfObjCClassMessageMissingOpenBracket();
6085 bool OpenACCDirectiveParsing =
false;
6089 bool AllowOpenACCArraySections =
false;
6093 class OpenACCArraySectionRAII {
6097 OpenACCArraySectionRAII(
Parser &P) : P(P) {
6098 assert(!P.AllowOpenACCArraySections);
6099 P.AllowOpenACCArraySections =
true;
6101 ~OpenACCArraySectionRAII() {
6102 assert(P.AllowOpenACCArraySections);
6103 P.AllowOpenACCArraySections =
false;
6110 struct OpenACCDirectiveParseInfo {
6112 SourceLocation StartLoc;
6113 SourceLocation DirLoc;
6114 SourceLocation LParenLoc;
6115 SourceLocation RParenLoc;
6116 SourceLocation EndLoc;
6117 SourceLocation MiscLoc;
6119 SmallVector<Expr *> Exprs;
6120 SmallVector<OpenACCClause *> Clauses;
6125 struct OpenACCWaitParseInfo {
6126 bool Failed =
false;
6127 Expr *DevNumExpr =
nullptr;
6128 SourceLocation QueuesLoc;
6129 SmallVector<Expr *> QueueIdExprs;
6131 SmallVector<Expr *> getAllExprs() {
6132 SmallVector<Expr *>
Out;
6133 Out.push_back(DevNumExpr);
6134 llvm::append_range(Out, QueueIdExprs);
6138 struct OpenACCCacheParseInfo {
6139 bool Failed =
false;
6140 SourceLocation ReadOnlyLoc;
6141 SmallVector<Expr *> Vars;
6146 enum class OpenACCParseCanContinue { Cannot = 0, Can = 1 };
6152 using OpenACCClauseParseResult =
6153 llvm::PointerIntPair<OpenACCClause *, 1, OpenACCParseCanContinue>;
6155 OpenACCClauseParseResult OpenACCCanContinue();
6156 OpenACCClauseParseResult OpenACCCannotContinue();
6157 OpenACCClauseParseResult OpenACCSuccess(OpenACCClause *Clause);
6161 OpenACCDirectiveParseInfo ParseOpenACCDirective();
6171 OpenACCCacheParseInfo ParseOpenACCCacheVarList();
6177 using OpenACCVarParseResult = std::pair<ExprResult, OpenACCParseCanContinue>;
6203 OpenACCClauseParseResult
6204 ParseOpenACCClauseParams(ArrayRef<const OpenACCClause *> ExistingClauses,
6206 SourceLocation ClauseLoc);
6210 OpenACCClauseParseResult
6211 ParseOpenACCClause(ArrayRef<const OpenACCClause *> ExistingClauses,
6221 SmallVector<OpenACCClause *>
6230 OpenACCWaitParseInfo ParseOpenACCWaitArgument(SourceLocation Loc,
6235 std::variant<std::monostate, StringLiteral *, IdentifierInfo *>
6236 ParseOpenACCBindClauseArgument();
6241 using OpenACCIntExprParseResult =
6242 std::pair<ExprResult, OpenACCParseCanContinue>;
6247 SourceLocation Loc);
6252 llvm::SmallVectorImpl<Expr *> &IntExprs);
6265 bool ParseOpenACCDeviceTypeList(llvm::SmallVector<IdentifierLoc> &Archs);
6279 SourceLocation Loc);
6294 llvm::SmallVectorImpl<Expr *> &SizeExprs);
6306 bool ParseOpenACCGangArgList(SourceLocation GangLoc,
6307 llvm::SmallVectorImpl<OpenACCGangKind> &GKs,
6308 llvm::SmallVectorImpl<Expr *> &IntExprs);
6310 using OpenACCGangArgRes = std::pair<OpenACCGangKind, ExprResult>;
6314 OpenACCGangArgRes ParseOpenACCGangArg(SourceLocation GangLoc);
6318 ParseOpenACCAfterRoutineDecl(
AccessSpecifier &AS, ParsedAttributes &Attrs,
6320 OpenACCDirectiveParseInfo &DirInfo);
6321 StmtResult ParseOpenACCAfterRoutineStmt(OpenACCDirectiveParseInfo &DirInfo);
6339 bool OpenMPDirectiveParsing =
false;
6344 void ReplayOpenMPAttributeTokens(
CachedTokens &OpenMPTokens) {
6347 if (!OpenMPTokens.empty()) {
6348 PP.EnterToken(Tok,
true);
6349 PP.EnterTokenStream(OpenMPTokens,
true,
6361 SourceLocation Loc);
6366 llvm::omp::TraitSet
Set,
6367 llvm::omp::TraitSelector Selector,
6368 llvm::StringMap<SourceLocation> &Seen);
6372 llvm::omp::TraitSet
Set,
6373 llvm::StringMap<SourceLocation> &Seen);
6377 llvm::StringMap<SourceLocation> &Seen);
6381 llvm::omp::TraitSet
Set,
6382 llvm::StringMap<SourceLocation> &Seen);
6390 llvm::omp::TraitSet
Set,
6391 llvm::StringMap<SourceLocation> &SeenSelectors);
6398 void parseOMPContextSelectorSet(
OMPTraitSet &TISet,
6399 llvm::StringMap<SourceLocation> &SeenSets);
6406 bool parseOMPContextSelectors(SourceLocation Loc,
OMPTraitInfo &TI);
6409 bool parseOpenMPAppendArgs(SmallVectorImpl<OMPInteropInfo> &InteropInfos);
6413 bool parseOMPDeclareVariantMatchClause(SourceLocation Loc,
OMPTraitInfo &TI,
6419 SourceLocation Loc);
6438 void ParseOpenMPAssumesDirective(OpenMPDirectiveKind DKind,
6439 SourceLocation Loc);
6442 void ParseOpenMPEndAssumesDirective(SourceLocation Loc);
6459 void ParseOpenMPClauses(OpenMPDirectiveKind DKind,
6460 SmallVectorImpl<clang::OMPClause *> &Clauses,
6461 SourceLocation Loc);
6464 void ParseOMPDeclareTargetClauses(SemaOpenMP::DeclareTargetContextInfo &DTCI);
6467 void ParseOMPEndDeclareTargetDirective(OpenMPDirectiveKind BeginDKind,
6468 OpenMPDirectiveKind EndDKind,
6469 SourceLocation Loc);
6473 void skipUntilPragmaOpenMPEnd(OpenMPDirectiveKind DKind);
6479 void parseOMPEndDirective(OpenMPDirectiveKind BeginKind,
6480 OpenMPDirectiveKind ExpectedKind,
6481 OpenMPDirectiveKind FoundKind,
6482 SourceLocation MatchingLoc, SourceLocation FoundLoc,
6483 bool SkipUntilOpenMPEnd);
6524 AccessSpecifier &AS, ParsedAttributes &Attrs,
bool Delayed =
false,
6526 Decl *TagDecl =
nullptr);
6540 DeclGroupPtrTy ParseOpenMPDeclareReductionDirective(AccessSpecifier AS);
6544 void ParseOpenMPReductionInitializerForDecl(VarDecl *OmpPrivParm);
6556 DeclGroupPtrTy ParseOpenMPDeclareMapperDirective(AccessSpecifier AS);
6559 TypeResult parseOpenMPDeclareMapperVarDecl(SourceRange &Range,
6560 DeclarationName &Name,
6561 AccessSpecifier AS =
AS_none);
6575 bool ParseOpenMPSimpleVarList(
6576 OpenMPDirectiveKind Kind,
6577 const llvm::function_ref<
void(CXXScopeSpec &, DeclarationNameInfo)>
6579 bool AllowScopeSpecifier);
6628 StmtResult ParseOpenMPDeclarativeOrExecutableDirective(
6629 ParsedStmtContext StmtCtx,
bool ReadDirectiveWithinMetadirective =
false);
6639 ParseOpenMPExecutableDirective(ParsedStmtContext StmtCtx,
6640 OpenMPDirectiveKind DKind, SourceLocation Loc,
6641 bool ReadDirectiveWithinMetadirective);
6650 StmtResult ParseOpenMPInformationalDirective(
6651 ParsedStmtContext StmtCtx, OpenMPDirectiveKind DKind, SourceLocation Loc,
6652 bool ReadDirectiveWithinMetadirective);
6681 OMPClause *ParseOpenMPClause(OpenMPDirectiveKind DKind,
6766 bool ParseOpenMPIndirectClause(SemaOpenMP::DeclareTargetContextInfo &DTCI,
6791 OMPClause *ParseOpenMPSingleExprWithArgClause(OpenMPDirectiveKind DKind,
6796 OMPClause *ParseOpenMPLoopRangeClause();
6805 OMPClause *ParseOpenMPPermutationClause();
6909 OMPClause *ParseOpenMPVarListClause(OpenMPDirectiveKind DKind,
6923 SourceLocation &ClauseNameLoc,
6924 SourceLocation &OpenLoc,
6925 SourceLocation &CloseLoc,
6926 SmallVectorImpl<Expr *> &Exprs,
6927 bool ReqIntConst =
false);
6942 OMPClause *ParseOpenMPUsesAllocatorClause(OpenMPDirectiveKind DKind);
6945 bool ParseOMPInteropInfo(OMPInteropInfo &InteropInfo,
OpenMPClauseKind Kind);
6983 OMPClause *ParseOpenMPOMPXAttributesClause(
bool ParseOnly);
6990 bool IsAddressOfOperand =
false);
6994 SemaOpenMP::OpenMPVarListDataTy &
Data,
6995 const LangOptions &LangOpts);
6998 SmallVectorImpl<Expr *> &Vars,
6999 SemaOpenMP::OpenMPVarListDataTy &
Data);
7034 std::unique_ptr<PragmaHandler> AlignHandler;
7035 std::unique_ptr<PragmaHandler> GCCVisibilityHandler;
7036 std::unique_ptr<PragmaHandler> OptionsHandler;
7037 std::unique_ptr<PragmaHandler> PackHandler;
7038 std::unique_ptr<PragmaHandler> MSStructHandler;
7039 std::unique_ptr<PragmaHandler> UnusedHandler;
7040 std::unique_ptr<PragmaHandler> WeakHandler;
7041 std::unique_ptr<PragmaHandler> RedefineExtnameHandler;
7042 std::unique_ptr<PragmaHandler> FPContractHandler;
7043 std::unique_ptr<PragmaHandler> OpenCLExtensionHandler;
7044 std::unique_ptr<PragmaHandler> OpenMPHandler;
7045 std::unique_ptr<PragmaHandler> OpenACCHandler;
7046 std::unique_ptr<PragmaHandler> PCSectionHandler;
7047 std::unique_ptr<PragmaHandler> MSCommentHandler;
7048 std::unique_ptr<PragmaHandler> MSDetectMismatchHandler;
7049 std::unique_ptr<PragmaHandler> FPEvalMethodHandler;
7050 std::unique_ptr<PragmaHandler> FloatControlHandler;
7051 std::unique_ptr<PragmaHandler> MSPointersToMembers;
7052 std::unique_ptr<PragmaHandler> MSVtorDisp;
7053 std::unique_ptr<PragmaHandler> MSInitSeg;
7054 std::unique_ptr<PragmaHandler> MSDataSeg;
7055 std::unique_ptr<PragmaHandler> MSBSSSeg;
7056 std::unique_ptr<PragmaHandler> MSConstSeg;
7057 std::unique_ptr<PragmaHandler> MSCodeSeg;
7058 std::unique_ptr<PragmaHandler> MSSection;
7059 std::unique_ptr<PragmaHandler> MSStrictGuardStackCheck;
7060 std::unique_ptr<PragmaHandler> MSRuntimeChecks;
7061 std::unique_ptr<PragmaHandler> MSIntrinsic;
7062 std::unique_ptr<PragmaHandler> MSFunction;
7063 std::unique_ptr<PragmaHandler> MSOptimize;
7064 std::unique_ptr<PragmaHandler> MSFenvAccess;
7065 std::unique_ptr<PragmaHandler> MSAllocText;
7066 std::unique_ptr<PragmaHandler> CUDAForceHostDeviceHandler;
7067 std::unique_ptr<PragmaHandler> OptimizeHandler;
7068 std::unique_ptr<PragmaHandler> LoopHintHandler;
7069 std::unique_ptr<PragmaHandler> UnrollHintHandler;
7070 std::unique_ptr<PragmaHandler> NoUnrollHintHandler;
7071 std::unique_ptr<PragmaHandler> UnrollAndJamHintHandler;
7072 std::unique_ptr<PragmaHandler> NoUnrollAndJamHintHandler;
7073 std::unique_ptr<PragmaHandler> FPHandler;
7074 std::unique_ptr<PragmaHandler> STDCFenvAccessHandler;
7075 std::unique_ptr<PragmaHandler> STDCFenvRoundHandler;
7076 std::unique_ptr<PragmaHandler> STDCCXLIMITHandler;
7077 std::unique_ptr<PragmaHandler> STDCUnknownHandler;
7078 std::unique_ptr<PragmaHandler> AttributePragmaHandler;
7079 std::unique_ptr<PragmaHandler> MaxTokensHerePragmaHandler;
7080 std::unique_ptr<PragmaHandler> MaxTokensTotalPragmaHandler;
7081 std::unique_ptr<PragmaHandler> ExportHandler;
7082 std::unique_ptr<PragmaHandler> RISCVPragmaHandler;
7085 void initializePragmaHandlers();
7088 void resetPragmaHandlers();
7095 void HandlePragmaUnused();
7099 void HandlePragmaVisibility();
7103 void HandlePragmaPack();
7107 void HandlePragmaMSStruct();
7109 void HandlePragmaMSPointersToMembers();
7111 void HandlePragmaMSVtorDisp();
7113 void HandlePragmaMSPragma();
7114 bool HandlePragmaMSSection(StringRef PragmaName,
7115 SourceLocation PragmaLocation);
7116 bool HandlePragmaMSSegment(StringRef PragmaName,
7117 SourceLocation PragmaLocation);
7120 bool HandlePragmaMSInitSeg(StringRef PragmaName,
7121 SourceLocation PragmaLocation);
7126 bool HandlePragmaMSStrictGuardStackCheck(StringRef PragmaName,
7127 SourceLocation PragmaLocation);
7128 bool HandlePragmaMSFunction(StringRef PragmaName,
7129 SourceLocation PragmaLocation);
7130 bool HandlePragmaMSAllocText(StringRef PragmaName,
7131 SourceLocation PragmaLocation);
7134 bool HandlePragmaMSOptimize(StringRef PragmaName,
7135 SourceLocation PragmaLocation);
7138 bool HandlePragmaMSIntrinsic(StringRef PragmaName,
7139 SourceLocation PragmaLocation);
7143 void HandlePragmaAlign();
7147 void HandlePragmaDump();
7151 void HandlePragmaWeak();
7155 void HandlePragmaWeakAlias();
7159 void HandlePragmaRedefineExtname();
7163 void HandlePragmaFPContract();
7167 void HandlePragmaFEnvAccess();
7171 void HandlePragmaFEnvRound();
7175 void HandlePragmaCXLimitedRange();
7179 void HandlePragmaFloatControl();
7183 void HandlePragmaFP();
7187 void HandlePragmaOpenCLExtension();
7191 StmtResult HandlePragmaCaptured();
7195 bool HandlePragmaLoopHint(LoopHint &Hint);
7197 bool ParsePragmaAttributeSubjectMatchRuleSet(
7199 SourceLocation &AnyLoc, SourceLocation &LastMatchRuleEndLoc);
7201 void HandlePragmaAttribute();
7207 void HandlePragmaExport();
7233 enum class ParsedStmtContext {
7236 AllowDeclarationsInC = 0x1,
7238 AllowStandaloneOpenMPDirectives = 0x2,
7245 Compound = AllowDeclarationsInC | AllowStandaloneOpenMPDirectives,
7262 ParsedStmtContext StmtCtx = ParsedStmtContext::SubStmt,
7317 ParseStatementOrDeclaration(
StmtVector &Stmts, ParsedStmtContext StmtCtx,
7321 StmtResult ParseStatementOrDeclarationAfterAttributes(
7322 StmtVector &Stmts, ParsedStmtContext StmtCtx,
7327 StmtResult ParseExprStatement(ParsedStmtContext StmtCtx);
7341 ParsedStmtContext StmtCtx);
7350 StmtResult ParseCaseStatement(ParsedStmtContext StmtCtx,
7351 bool MissingCase =
false,
7361 StmtResult ParseDefaultStatement(ParsedStmtContext StmtCtx);
7363 StmtResult ParseCompoundStatement(
bool isStmtExpr =
false);
7389 StmtResult ParseCompoundStatement(
bool isStmtExpr,
unsigned ScopeFlags);
7394 void ParseCompoundStatementLeadingPragmas();
7396 void DiagnoseLabelAtEndOfCompoundStatement();
7406 StmtResult ParseCompoundStatementBody(
bool isStmtExpr =
false);
7424 bool ParseParenExprOrCondition(
StmtResult *InitStmt,
7540 StmtResult ParseBreakOrContinueStatement(
bool IsContinue);
7557 void ParseMicrosoftIfExistsStatement(
StmtVector &Stmts);
7604 StmtResult ParseCXXCatchBlock(
bool FnCatch =
false);
7642 Decl *ParseFunctionStatementBody(
Decl *
Decl, ParseScope &BodyScope);
7651 Decl *ParseFunctionTryBlock(
Decl *
Decl, ParseScope &BodyScope);
7657 bool trySkippingFunctionBody();
7665 bool isDeclarationStatement(
bool DisambiguatingWithExpression =
false) {
7667 return isCXXDeclarationStatement(DisambiguatingWithExpression);
7675 bool isForInitDeclaration() {
7679 return Tok.is(tok::kw_using) ||
7680 isCXXSimpleDeclaration(
true);
7685 bool isForRangeIdentifier();
7702 unsigned &NumLineToksConsumed,
7703 bool IsUnevaluated);
7746 StmtResult ParseMicrosoftAsmStatement(SourceLocation AsmLoc);
7762 bool ParseAsmOperandsOpt(SmallVectorImpl<IdentifierInfo *> &Names,
7763 SmallVectorImpl<Expr *> &Constraints,
7764 SmallVectorImpl<Expr *> &Exprs);
7766 class GNUAsmQualifiers {
7767 unsigned Qualifiers = AQ_unspecified;
7776 static const char *getQualifierName(AQ Qualifier);
7777 bool setAsmQualifier(AQ Qualifier);
7778 inline bool isVolatile()
const {
return Qualifiers & AQ_volatile; };
7779 inline bool isInline()
const {
return Qualifiers & AQ_inline; };
7780 inline bool isGoto()
const {
return Qualifiers & AQ_goto; }
7784 bool isGCCAsmStatement(
const Token &TokAfterAsm)
const;
7786 bool isGNUAsmQualifier(
const Token &TokAfterAsm)
const;
7787 GNUAsmQualifiers::AQ getGNUAsmQualifier(
const Token &Tok)
const;
7800 bool parseGNUAsmQualifierListOpt(GNUAsmQualifiers &AQ);
7824 unsigned TemplateParameterDepth;
7827 class TemplateParameterDepthRAII {
7829 unsigned AddedLevels;
7832 explicit TemplateParameterDepthRAII(
unsigned &Depth)
7833 : Depth(Depth), AddedLevels(0) {}
7835 ~TemplateParameterDepthRAII() { Depth -= AddedLevels; }
7841 void addDepth(
unsigned D) {
7845 void setAddedDepth(
unsigned D) {
7846 Depth = Depth - AddedLevels + D;
7850 unsigned getDepth()
const {
return Depth; }
7851 unsigned getOriginalDepth()
const {
return Depth - AddedLevels; }
7856 SmallVector<TemplateIdAnnotation *, 16> TemplateIds;
7862 bool DelayTemplateIdDestruction =
false;
7864 void MaybeDestroyTemplateIds() {
7865 if (DelayTemplateIdDestruction)
7867 if (!TemplateIds.empty() &&
7868 (Tok.is(tok::eof) || !PP.mightHavePendingAnnotationTokens()))
7869 DestroyTemplateIds();
7871 void DestroyTemplateIds();
7875 struct DestroyTemplateIdAnnotationsRAIIObj {
7878 DestroyTemplateIdAnnotationsRAIIObj(
Parser &Self) : Self(Self) {}
7879 ~DestroyTemplateIdAnnotationsRAIIObj() { Self.MaybeDestroyTemplateIds(); }
7882 struct DelayTemplateIdDestructionRAII {
7884 bool PrevDelayTemplateIdDestruction;
7886 DelayTemplateIdDestructionRAII(
Parser &Self,
7887 bool DelayTemplateIdDestruction) noexcept
7889 PrevDelayTemplateIdDestruction(Self.DelayTemplateIdDestruction) {
7890 Self.DelayTemplateIdDestruction = DelayTemplateIdDestruction;
7893 ~DelayTemplateIdDestructionRAII() noexcept {
7894 Self.DelayTemplateIdDestruction = PrevDelayTemplateIdDestruction;
7899 SmallVector<const IdentifierInfo *, 8> TentativelyDeclaredIdentifiers;
7911 struct AngleBracketTracker {
7914 enum Priority :
unsigned short {
7916 PotentialTypo = 0x0,
7918 DependentName = 0x2,
7921 SpaceBeforeLess = 0x0,
7923 NoSpaceBeforeLess = 0x1,
7954 if (!Locs.empty() && Locs.back().isActive(P)) {
7955 if (Locs.back().Priority <= Prio) {
7957 Locs.back().LessLoc = LessLoc;
7958 Locs.back().Priority = Prio;
7961 Locs.push_back({
TemplateName, LessLoc, Prio, P.ParenCount,
7962 P.BracketCount, P.BraceCount});
7970 while (!Locs.empty() && Locs.back().isActiveOrNested(P))
7977 if (!Locs.empty() && Locs.back().isActive(P))
7978 return &Locs.back();
7983 AngleBracketTracker AngleBrackets;
7988 struct ParsedTemplateInfo {
7989 ParsedTemplateInfo()
7993 bool isSpecialization,
7994 bool lastParameterListWasEmpty =
false)
7997 TemplateParams(TemplateParams),
7998 LastParameterListWasEmpty(lastParameterListWasEmpty) {}
8000 explicit ParsedTemplateInfo(SourceLocation ExternLoc,
8001 SourceLocation TemplateLoc)
8003 TemplateParams(
nullptr), ExternLoc(ExternLoc),
8004 TemplateLoc(TemplateLoc), LastParameterListWasEmpty(
false) {}
8014 SourceLocation ExternLoc;
8018 SourceLocation TemplateLoc;
8021 bool LastParameterListWasEmpty;
8023 SourceRange getSourceRange() const LLVM_READONLY;
8027 void LexTemplateFunctionForLateParsing(
CachedTokens &Toks);
8030 void ParseLateTemplatedFuncDef(LateParsedTemplate &LPT);
8032 static
void LateTemplateParserCallback(
void *P, LateParsedTemplate &LPT);
8040 void checkPotentialAngleBracket(
ExprResult &PotentialTemplateName);
8041 bool checkPotentialAngleBracketDelimiter(const AngleBracketTracker::Loc &,
8042 const Token &OpToken);
8043 bool checkPotentialAngleBracketDelimiter(const Token &OpToken) {
8044 if (
auto *Info = AngleBrackets.getCurrent(*
this))
8045 return checkPotentialAngleBracketDelimiter(*Info, OpToken);
8056 SourceLocation &DeclEnd,
8057 ParsedAttributes &AccessAttrs);
8104 ParsingDeclRAIIObject &DiagsFromParams, SourceLocation &DeclEnd,
8116 bool ParseTemplateParameters(MultiParseScope &TemplateScopes,
unsigned Depth,
8117 SmallVectorImpl<NamedDecl *> &TemplateParams,
8118 SourceLocation &LAngleLoc,
8119 SourceLocation &RAngleLoc);
8131 bool ParseTemplateParameterList(
unsigned Depth,
8132 SmallVectorImpl<NamedDecl *> &TemplateParams);
8134 enum class TPResult;
8138 TPResult isStartOfTemplateTypeParameter();
8162 NamedDecl *ParseTemplateParameter(
unsigned Depth,
unsigned Position);
8175 NamedDecl *ParseTypeParameter(
unsigned Depth,
unsigned Position);
8191 NamedDecl *ParseTemplateTemplateParameter(
unsigned Depth,
unsigned Position);
8201 NamedDecl *ParseNonTypeTemplateParameter(
unsigned Depth,
unsigned Position);
8205 bool isTypeConstraintAnnotation();
8217 bool TryAnnotateTypeConstraint();
8219 void DiagnoseMisplacedEllipsis(SourceLocation EllipsisLoc,
8220 SourceLocation CorrectLoc,
8221 bool AlreadyHasEllipsis,
8222 bool IdentifierHasName);
8223 void DiagnoseMisplacedEllipsisInDeclarator(SourceLocation EllipsisLoc,
8226 typedef SmallVector<ParsedTemplateArgument, 16> TemplateArgList;
8243 bool ParseGreaterThanInTemplateList(SourceLocation LAngleLoc,
8244 SourceLocation &RAngleLoc,
8245 bool ConsumeLastToken,
8246 bool ObjCGenericList);
8259 bool ParseTemplateIdAfterTemplateName(
bool ConsumeLastToken,
8260 SourceLocation &LAngleLoc,
8261 TemplateArgList &TemplateArgs,
8262 SourceLocation &RAngleLoc,
8307 CXXScopeSpec &SS, SourceLocation TemplateKWLoc,
8309 bool AllowTypeAnnotation =
true,
8310 bool TypeConstraint =
false);
8328 AnnotateTemplateIdTokenAsType(CXXScopeSpec &SS,
8330 bool IsClassName =
false);
8342 bool ParseTemplateArgumentList(TemplateArgList &TemplateArgs,
8346 ParsedTemplateArgument ParseTemplateTemplateArgument();
8358 ParsedTemplateArgument ParseTemplateArgument();
8370 SourceLocation ExternLoc,
8371 SourceLocation TemplateLoc,
8372 SourceLocation &DeclEnd,
8373 ParsedAttributes &AccessAttrs,
8382 Decl *ParseConceptDefinition(
const ParsedTemplateInfo &TemplateInfo,
8383 SourceLocation &DeclEnd);
8411 class TentativeParsingAction {
8413 PreferredTypeBuilder PrevPreferredType;
8415 size_t PrevTentativelyDeclaredIdentifierCount;
8416 unsigned short PrevParenCount, PrevBracketCount, PrevBraceCount;
8420 explicit TentativeParsingAction(Parser &p,
bool Unannotated =
false)
8421 : P(p), PrevPreferredType(P.PreferredType) {
8423 PrevTentativelyDeclaredIdentifierCount =
8424 P.TentativelyDeclaredIdentifiers.size();
8425 PrevParenCount = P.ParenCount;
8426 PrevBracketCount = P.BracketCount;
8427 PrevBraceCount = P.BraceCount;
8428 P.PP.EnableBacktrackAtThisPos(Unannotated);
8432 assert(isActive &&
"Parsing action was finished!");
8433 P.TentativelyDeclaredIdentifiers.resize(
8434 PrevTentativelyDeclaredIdentifierCount);
8435 P.PP.CommitBacktrackedTokens();
8439 assert(isActive &&
"Parsing action was finished!");
8441 P.PreferredType = PrevPreferredType;
8443 P.TentativelyDeclaredIdentifiers.resize(
8444 PrevTentativelyDeclaredIdentifierCount);
8445 P.ParenCount = PrevParenCount;
8446 P.BracketCount = PrevBracketCount;
8447 P.BraceCount = PrevBraceCount;
8450 ~TentativeParsingAction() {
8451 assert(!isActive &&
"Forgot to call Commit or Revert!");
8457 class RevertingTentativeParsingAction
8458 :
private Parser::TentativeParsingAction {
8460 using TentativeParsingAction::TentativeParsingAction;
8462 ~RevertingTentativeParsingAction() { Revert(); }
8497 bool isCXXDeclarationStatement(
bool DisambiguatingWithExpression =
false);
8523 bool isCXXSimpleDeclaration(
bool AllowForRangeDecl);
8536 bool isCXXFunctionDeclarator(
bool *IsAmbiguous =
nullptr,
8540 struct ConditionDeclarationOrInitStatementState;
8541 enum class ConditionOrInitStatement {
8568 ConditionOrInitStatement
8569 isCXXConditionDeclarationOrInitStatement(
bool CanBeInitStmt,
8570 bool CanBeForRangeDecl);
8596 return isCXXTypeId(Context, isAmbiguous);
8610 bool isEnumBase(
bool AllowSemi);
8730 TPResult BracedCastResult = TPResult::False,
8731 bool *InvalidAsDeclSpec =
nullptr);
8736 bool isCXXDeclarationSpecifierAType();
8742 TPResult isTemplateArgumentList(
unsigned TokensToSkip);
8747 TPResult isExplicitBool();
8752 bool isTentativelyDeclared(IdentifierInfo *II);
8771 TPResult TryParseSimpleDeclaration(
bool AllowForRangeDecl);
8779 TPResult TryParseTypeofSpecifier();
8783 TPResult TryParseProtocolQualifiers();
8785 TPResult TryParsePtrOperatorSeq();
8807 TPResult TryParseOperatorId();
8838 TPResult TryParseInitDeclaratorList(
bool MayHaveTrailingReturnType =
false);
8895 TPResult TryParseDeclarator(
bool mayBeAbstract,
bool mayHaveIdentifier =
true,
8896 bool mayHaveDirectInit =
false,
8897 bool mayHaveTrailingReturnType =
false);
8918 TPResult TryParseParameterDeclarationClause(
8919 bool *InvalidAsDeclaration =
nullptr,
bool VersusTemplateArg =
false,
8936 TPResult TryParseFunctionDeclarator(
bool MayHaveTrailingReturnType =
false);
8942 bool NameAfterArrowIsNonType();
8948 TPResult TryParseBracketDeclarator();
8952 TPResult TryConsumeDeclarationSpecifier();
8956 bool TrySkipAttributes();
8998 isCXX11AttributeSpecifier(
bool Disambiguate =
false,
8999 bool OuterMightBeMessageSend =
false);