308 return Actions.incrementMSManglingNumber();
357 assert(!isTokenSpecial() &&
358 "Should consume special tokens with Consume*Token");
359 PrevTokLocation = Tok.getLocation();
361 return PrevTokLocation;
367 assert(!isTokenSpecial() &&
368 "Should consume special tokens with Consume*Token");
369 PrevTokLocation = Tok.getLocation();
377 Loc = PrevTokLocation;
386 return ConsumeParen();
387 if (isTokenBracket())
388 return ConsumeBracket();
390 return ConsumeBrace();
391 if (isTokenStringLiteral())
392 return ConsumeStringToken();
393 if (Tok.is(tok::code_completion))
394 return ConsumeCodeCompletionTok ? ConsumeCodeCompletionToken()
395 : handleUnexpectedCodeCompletionToken();
396 if (Tok.isAnnotation())
397 return ConsumeAnnotationToken();
411 if (N == 0 || Tok.is(tok::eof))
413 return PP.LookAhead(N - 1);
422 if (!Tok.getAnnotationValue())
457 bool IsAddressOfOperand =
false);
483 (Tok.is(tok::identifier) || Tok.is(tok::coloncolon) ||
484 (Tok.is(tok::annot_template_id) &&
486 Tok.is(tok::kw_decltype) || Tok.is(tok::kw___super));
503 ParseScope(
const ParseScope &) =
delete;
504 void operator=(
const ParseScope &) =
delete;
511 bool BeforeCompoundStmt =
false)
513 if (EnteredScope && !BeforeCompoundStmt)
514 Self->EnterScope(ScopeFlags);
516 if (BeforeCompoundStmt)
517 Self->incrementMSManglingNumber();
519 this->Self = nullptr;
537 class MultiParseScope {
539 unsigned NumScopes = 0;
541 MultiParseScope(
const MultiParseScope &) =
delete;
546 Self.EnterScope(ScopeFlags);
588 static_cast<unsigned>(R));
643 unsigned short ParenCount = 0, BracketCount = 0,
BraceCount = 0;
644 unsigned short MisplacedModuleBeginCount = 0;
655 static constexpr int ScopeCacheSize = 16;
656 unsigned NumCachedScopes;
657 Scope *ScopeCache[ScopeCacheSize];
663 *Ident_GetExceptionCode;
666 *Ident_GetExceptionInfo;
668 IdentifierInfo *Ident__abnormal_termination, *Ident___abnormal_termination,
669 *Ident_AbnormalTermination;
675 std::unique_ptr<CommentHandler> CommentSemaHandler;
680 bool CalledSignatureHelp =
false;
682 bool isTokenSEHExcept();
688 bool SkipFunctionBodies;
695 bool isTokenParen()
const {
return Tok.isOneOf(tok::l_paren, tok::r_paren); }
697 bool isTokenBracket()
const {
698 return Tok.isOneOf(tok::l_square, tok::r_square);
701 bool isTokenBrace()
const {
return Tok.isOneOf(tok::l_brace, tok::r_brace); }
703 bool isTokenStringLiteral()
const {
707 bool isTokenSpecial()
const {
708 return isTokenStringLiteral() || isTokenParen() || isTokenBracket() ||
709 isTokenBrace() || Tok.is(tok::code_completion) || Tok.isAnnotation();
714 bool isTokenEqualOrEqualTypo();
718 void UnconsumeToken(Token &Consumed) {
720 PP.EnterToken(Consumed,
true);
722 PP.EnterToken(
Next,
true);
725 SourceLocation ConsumeAnnotationToken() {
726 assert(Tok.isAnnotation() &&
"wrong consume method");
727 SourceLocation Loc = Tok.getLocation();
728 PrevTokLocation = Tok.getAnnotationEndLoc();
735 SourceLocation ConsumeParen() {
736 assert(isTokenParen() &&
"wrong consume method");
737 if (Tok.getKind() == tok::l_paren)
739 else if (ParenCount) {
740 AngleBrackets.clear(*
this);
743 PrevTokLocation = Tok.getLocation();
745 return PrevTokLocation;
750 SourceLocation ConsumeBracket() {
751 assert(isTokenBracket() &&
"wrong consume method");
752 if (Tok.getKind() == tok::l_square)
754 else if (BracketCount) {
755 AngleBrackets.clear(*
this);
759 PrevTokLocation = Tok.getLocation();
761 return PrevTokLocation;
766 SourceLocation ConsumeBrace() {
767 assert(isTokenBrace() &&
"wrong consume method");
768 if (Tok.getKind() == tok::l_brace)
770 else if (BraceCount) {
771 AngleBrackets.clear(*
this);
775 PrevTokLocation = Tok.getLocation();
777 return PrevTokLocation;
784 SourceLocation ConsumeStringToken() {
785 assert(isTokenStringLiteral() &&
786 "Should only consume string literals with this method");
787 PrevTokLocation = Tok.getLocation();
789 return PrevTokLocation;
797 SourceLocation ConsumeCodeCompletionToken() {
798 assert(Tok.is(tok::code_completion));
799 PrevTokLocation = Tok.getLocation();
801 return PrevTokLocation;
809 SourceLocation handleUnexpectedCodeCompletionToken();
813 void cutOffParsing() {
814 if (PP.isCodeCompletionEnabled())
815 PP.setCodeCompletionReached();
817 Tok.setKind(tok::eof);
824 return Kind == tok::eof ||
Kind == tok::annot_module_begin ||
825 Kind == tok::annot_module_end ||
Kind == tok::annot_module_include;
828 static void setTypeAnnotation(Token &Tok,
TypeResult T) {
829 assert((
T.isInvalid() ||
T.get()) &&
830 "produced a valid-but-null type annotation?");
831 Tok.setAnnotationValue(
T.isInvalid() ?
nullptr :
T.get().getAsOpaquePtr());
834 static NamedDecl *getNonTypeAnnotation(
const Token &Tok) {
835 return static_cast<NamedDecl *
>(Tok.getAnnotationValue());
838 static void setNonTypeAnnotation(Token &Tok, NamedDecl *ND) {
839 Tok.setAnnotationValue(ND);
842 static IdentifierInfo *getIdentifierAnnotation(
const Token &Tok) {
843 return static_cast<IdentifierInfo *
>(Tok.getAnnotationValue());
846 static void setIdentifierAnnotation(Token &Tok, IdentifierInfo *ND) {
847 Tok.setAnnotationValue(ND);
852 static ExprResult getExprAnnotation(
const Token &Tok) {
853 return ExprResult::getFromOpaquePointer(Tok.getAnnotationValue());
858 static void setExprAnnotation(Token &Tok,
ExprResult ER) {
859 Tok.setAnnotationValue(ER.getAsOpaquePointer());
873 TryAnnotateName(CorrectionCandidateCallback *CCC =
nullptr,
878 void AnnotateScopeToken(CXXScopeSpec &SS,
bool IsNewAnnotation);
885 bool TryKeywordIdentFallback(
bool DisableKeyword);
890 TemplateIdAnnotation *takeTemplateIdAnnotation(
const Token &tok);
901 unsigned Diag = diag::err_expected,
902 StringRef DiagMsg =
"");
909 bool ExpectAndConsumeSemi(
unsigned DiagID, StringRef TokenUsed =
"");
914 bool isLikelyAtStartOfNewDeclaration();
925 bool expectIdentifier();
928 enum class CompoundToken {
943 void checkCompoundToken(SourceLocation FirstTokLoc,
946 void diagnoseUseOfC11Keyword(
const Token &Tok);
949 class ParseScopeFlags {
951 unsigned OldFlags = 0;
952 ParseScopeFlags(
const ParseScopeFlags &) =
delete;
953 void operator=(
const ParseScopeFlags &) =
delete;
958 ParseScopeFlags(
Parser *
Self,
unsigned ScopeFlags,
bool ManageFlags =
true);
972 void SuggestParentheses(SourceLocation Loc,
unsigned DK,
973 SourceRange ParenRange);
1009 DeclGroupPtrTy ParseExternalDeclaration(ParsedAttributes &DeclAttrs,
1010 ParsedAttributes &DeclSpecAttrs,
1011 ParsingDeclSpec *DS =
nullptr);
1015 bool isDeclarationAfterDeclarator();
1019 bool isStartOfFunctionDefinition(
const ParsingDeclarator &Declarator);
1022 ParsedAttributes &DeclAttrs, ParsedAttributes &DeclSpecAttrs,
1043 DeclGroupPtrTy ParseDeclOrFunctionDefInternal(ParsedAttributes &Attrs,
1044 ParsedAttributes &DeclSpecAttrs,
1045 ParsingDeclSpec &DS,
1048 void SkipFunctionBody();
1050 struct ParsedTemplateInfo;
1068 Decl *ParseFunctionDefinition(
1069 ParsingDeclarator &D,
1070 const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo(),
1071 LateParsedAttrList *LateParsedAttrs =
nullptr);
1075 void ParseKNRParamDeclarations(Declarator &D);
1085 ExprResult ParseSimpleAsm(
bool ForAsmLabel, SourceLocation *EndLoc);
1098 ExprResult ParseAsmStringLiteral(
bool ForAsmLabel);
1102 struct IfExistsCondition {
1104 SourceLocation KeywordLoc;
1120 bool ParseMicrosoftIfExistsCondition(IfExistsCondition &
Result);
1121 void ParseMicrosoftIfExistsExternalDeclaration();
1160 Decl *ParseModuleImport(SourceLocation AtLoc,
1167 bool parseMisplacedModuleImport();
1169 bool tryParseMisplacedModuleImport() {
1171 if (Kind == tok::annot_module_begin || Kind == tok::annot_module_end ||
1172 Kind == tok::annot_module_include)
1173 return parseMisplacedModuleImport();
1186 bool ParseModuleName(SourceLocation UseLoc,
1187 SmallVectorImpl<IdentifierLoc> &Path,
bool IsImport);
1191 void CodeCompleteDirective(
bool InConditional)
override;
1193 void CodeCompleteMacroName(
bool IsDefinition)
override;
1195 void CodeCompleteMacroArgument(IdentifierInfo *
Macro, MacroInfo *MacroInfo,
1196 unsigned ArgumentIndex)
override;
1197 void CodeCompleteIncludedFile(llvm::StringRef Dir,
bool IsAngled)
override;
1199 void CodeCompleteModuleImport(SourceLocation ImportLoc,
1218 struct ParsingClass;
1224 LateParsedClass(
Parser *P, ParsingClass *
C);
1225 ~LateParsedClass()
override;
1234 LateParsedClass(
const LateParsedClass &) =
delete;
1235 LateParsedClass &operator=(
const LateParsedClass &) =
delete;
1239 ParsingClass *
Class;
1253 :
Self(P), AS(AS) {}
1255 void takeToks(
CachedTokens &Cached) { Toks.swap(Cached); }
1265 struct LexedMethod :
public LateParsedDeclaration {
1270 explicit LexedMethod(
Parser *P, Decl *MD) : Self(P), D(MD) {}
1279 struct LateParsedDefaultArgument {
1280 explicit LateParsedDefaultArgument(
1281 Decl *P, std::unique_ptr<CachedTokens> Toks =
nullptr)
1282 : Param(P), Toks(std::move(Toks)) {}
1291 std::unique_ptr<CachedTokens> Toks;
1298 struct LateParsedMethodDeclaration :
public LateParsedDeclaration {
1299 explicit LateParsedMethodDeclaration(
Parser *P, Decl *M)
1300 : Self(P), Method(M), ExceptionSpecTokens(
nullptr) {}
1314 SmallVector<LateParsedDefaultArgument, 8> DefaultArgs;
1324 struct LateParsedMemberInitializer :
public LateParsedDeclaration {
1325 LateParsedMemberInitializer(
Parser *P, Decl *FD) : Self(P), Field(FD) {}
1345 typedef SmallVector<LateParsedDeclaration *, 2>
1346 LateParsedDeclarationsContainer;
1360 const ParsedAttributesView &AccessAttrs,
1361 ParsingDeclarator &D,
1362 const ParsedTemplateInfo &TemplateInfo,
1363 const VirtSpecifiers &VS,
1364 SourceLocation PureSpecLoc);
1367 StringLiteral *ParseCXXDeletedFunctionMessage();
1372 void SkipDeletedFunctionBody();
1378 void ParseCXXNonStaticMemberInitializer(Decl *VarD);
1382 void ParseLexedAttributes(ParsingClass &
Class);
1385 void ParseLexedAttributeList(LateParsedAttrList &LAs, Decl *D,
1387 ParsedAttributes *OutAttrs =
nullptr);
1396 ParsedAttributes *OutAttrs =
nullptr);
1402 void ParseLexedMethodDeclarations(ParsingClass &
Class);
1403 void ParseLexedMethodDeclaration(LateParsedMethodDeclaration &LM);
1408 void ParseLexedMethodDefs(ParsingClass &
Class);
1409 void ParseLexedMethodDef(LexedMethod &LM);
1415 void ParseLexedMemberInitializers(ParsingClass &
Class);
1416 void ParseLexedMemberInitializer(LateParsedMemberInitializer &MI);
1450 ParsedAttributes *Attrs =
nullptr);
1456 IdentifierInfo *Ident_vector;
1457 IdentifierInfo *Ident_bool;
1458 IdentifierInfo *Ident_Bool;
1462 IdentifierInfo *Ident_pixel;
1465 IdentifierInfo *Ident_introduced;
1468 IdentifierInfo *Ident_deprecated;
1471 IdentifierInfo *Ident_obsoleted;
1474 IdentifierInfo *Ident_unavailable;
1477 IdentifierInfo *Ident_message;
1480 IdentifierInfo *Ident_strict;
1483 IdentifierInfo *Ident_replacement;
1486 IdentifierInfo *Ident_environment;
1489 IdentifierInfo *Ident_language, *Ident_defined_in,
1490 *Ident_generated_declaration, *Ident_USR;
1493 AttributeFactory AttrFactory;
1498 bool TryAltiVecToken(DeclSpec &DS, SourceLocation Loc,
const char *&PrevSpec,
1503 if (Tok.getIdentifierInfo() != Ident_vector &&
1504 Tok.getIdentifierInfo() != Ident_bool &&
1505 Tok.getIdentifierInfo() != Ident_Bool &&
1506 (!
getLangOpts().AltiVec || Tok.getIdentifierInfo() != Ident_pixel))
1509 return TryAltiVecTokenOutOfLine(DS, Loc, PrevSpec, DiagID,
isInvalid);
1515 bool TryAltiVecVectorToken() {
1517 Tok.getIdentifierInfo() != Ident_vector)
1519 return TryAltiVecVectorTokenOutOfLine();
1524 bool TryAltiVecVectorTokenOutOfLine();
1525 bool TryAltiVecTokenOutOfLine(DeclSpec &DS, SourceLocation Loc,
1526 const char *&PrevSpec,
unsigned &DiagID,
1530 ParsedAttributes &OutAttrs);
1534 void CompleteLateParsedTypeAttributes(
1535 SmallVectorImpl<LateParsedTypeAttribute *> &LateTypeAttrs);
1544 ArrayRef<const DeclRefExpr *> ParamRefs,
1545 bool ReenteredProtoParams);
1552 LateParsedAttrList &From);
1554 void ParseLexedPragmas(ParsingClass &
Class);
1555 void ParseLexedPragma(LateParsedPragma &LP);
1563 bool ConsumeAndStoreFunctionPrologue(
CachedTokens &Toks);
1579 bool ConsumeFinalToken =
true) {
1580 return ConsumeAndStoreUntil(T1, T1, Toks,
StopAtSemi, ConsumeFinalToken);
1591 bool ConsumeFinalToken =
true);
1599 enum class DeclSpecContext {
1604 DSC_alias_declaration,
1609 DSC_template_type_arg,
1610 DSC_objc_method_result,
1619 static bool isTypeSpecifier(DeclSpecContext DSC) {
1621 case DeclSpecContext::DSC_normal:
1622 case DeclSpecContext::DSC_template_param:
1623 case DeclSpecContext::DSC_template_arg:
1624 case DeclSpecContext::DSC_class:
1625 case DeclSpecContext::DSC_top_level:
1626 case DeclSpecContext::DSC_objc_method_result:
1627 case DeclSpecContext::DSC_condition:
1630 case DeclSpecContext::DSC_template_type_arg:
1631 case DeclSpecContext::DSC_type_specifier:
1632 case DeclSpecContext::DSC_conv_operator:
1633 case DeclSpecContext::DSC_trailing:
1634 case DeclSpecContext::DSC_alias_declaration:
1635 case DeclSpecContext::DSC_association:
1636 case DeclSpecContext::DSC_new:
1639 llvm_unreachable(
"Missing DeclSpecContext case");
1643 enum class AllowDefiningTypeSpec {
1660 static AllowDefiningTypeSpec
1661 isDefiningTypeSpecifierContext(DeclSpecContext DSC,
bool IsCPlusPlus) {
1663 case DeclSpecContext::DSC_normal:
1664 case DeclSpecContext::DSC_class:
1665 case DeclSpecContext::DSC_top_level:
1666 case DeclSpecContext::DSC_alias_declaration:
1667 case DeclSpecContext::DSC_objc_method_result:
1668 return AllowDefiningTypeSpec::Yes;
1670 case DeclSpecContext::DSC_condition:
1671 case DeclSpecContext::DSC_template_param:
1672 return AllowDefiningTypeSpec::YesButInvalid;
1674 case DeclSpecContext::DSC_template_type_arg:
1675 case DeclSpecContext::DSC_type_specifier:
1676 return AllowDefiningTypeSpec::NoButErrorRecovery;
1678 case DeclSpecContext::DSC_association:
1679 return IsCPlusPlus ? AllowDefiningTypeSpec::NoButErrorRecovery
1680 : AllowDefiningTypeSpec::Yes;
1682 case DeclSpecContext::DSC_trailing:
1683 case DeclSpecContext::DSC_conv_operator:
1684 case DeclSpecContext::DSC_template_arg:
1685 case DeclSpecContext::DSC_new:
1686 return AllowDefiningTypeSpec::No;
1688 llvm_unreachable(
"Missing DeclSpecContext case");
1692 static bool isOpaqueEnumDeclarationContext(DeclSpecContext DSC) {
1694 case DeclSpecContext::DSC_normal:
1695 case DeclSpecContext::DSC_class:
1696 case DeclSpecContext::DSC_top_level:
1699 case DeclSpecContext::DSC_alias_declaration:
1700 case DeclSpecContext::DSC_objc_method_result:
1701 case DeclSpecContext::DSC_condition:
1702 case DeclSpecContext::DSC_template_param:
1703 case DeclSpecContext::DSC_template_type_arg:
1704 case DeclSpecContext::DSC_type_specifier:
1705 case DeclSpecContext::DSC_trailing:
1706 case DeclSpecContext::DSC_association:
1707 case DeclSpecContext::DSC_conv_operator:
1708 case DeclSpecContext::DSC_template_arg:
1709 case DeclSpecContext::DSC_new:
1713 llvm_unreachable(
"Missing DeclSpecContext case");
1718 static bool isClassTemplateDeductionContext(DeclSpecContext DSC) {
1720 case DeclSpecContext::DSC_normal:
1721 case DeclSpecContext::DSC_template_param:
1722 case DeclSpecContext::DSC_template_arg:
1723 case DeclSpecContext::DSC_class:
1724 case DeclSpecContext::DSC_top_level:
1725 case DeclSpecContext::DSC_condition:
1726 case DeclSpecContext::DSC_type_specifier:
1727 case DeclSpecContext::DSC_association:
1728 case DeclSpecContext::DSC_conv_operator:
1729 case DeclSpecContext::DSC_new:
1732 case DeclSpecContext::DSC_objc_method_result:
1733 case DeclSpecContext::DSC_template_type_arg:
1734 case DeclSpecContext::DSC_trailing:
1735 case DeclSpecContext::DSC_alias_declaration:
1738 llvm_unreachable(
"Missing DeclSpecContext case");
1743 getImplicitTypenameContext(DeclSpecContext DSC) {
1745 case DeclSpecContext::DSC_class:
1746 case DeclSpecContext::DSC_top_level:
1747 case DeclSpecContext::DSC_type_specifier:
1748 case DeclSpecContext::DSC_template_type_arg:
1749 case DeclSpecContext::DSC_trailing:
1750 case DeclSpecContext::DSC_alias_declaration:
1751 case DeclSpecContext::DSC_template_param:
1752 case DeclSpecContext::DSC_new:
1753 case DeclSpecContext::DSC_conv_operator:
1756 case DeclSpecContext::DSC_normal:
1757 case DeclSpecContext::DSC_objc_method_result:
1758 case DeclSpecContext::DSC_condition:
1759 case DeclSpecContext::DSC_template_arg:
1760 case DeclSpecContext::DSC_association:
1763 llvm_unreachable(
"Missing DeclSpecContext case");
1768 struct ForRangeInit {
1769 SourceLocation ColonLoc;
1771 SmallVector<MaterializeTemporaryExpr *, 8> LifetimeExtendTemps;
1772 CXXExpansionStmtDecl *ExpansionStmt =
nullptr;
1773 bool ParsedForRangeDecl() {
return !ColonLoc.
isInvalid(); }
1775 struct ForRangeInfo : ForRangeInit {
1798 SourceLocation &DeclEnd,
1799 ParsedAttributes &DeclAttrs,
1800 ParsedAttributes &DeclSpecAttrs,
1801 SourceLocation *DeclSpecStart =
nullptr);
1828 ParsedAttributes &DeclAttrs,
1829 ParsedAttributes &DeclSpecAttrs,
bool RequireSemi,
1830 ForRangeInit *FRI =
nullptr,
1831 SourceLocation *DeclSpecStart =
nullptr);
1841 ParsedAttributes &Attrs,
1842 ParsedTemplateInfo &TemplateInfo,
1843 SourceLocation *DeclEnd =
nullptr,
1844 ForRangeInit *FRI =
nullptr);
1870 Decl *ParseDeclarationAfterDeclarator(
1872 const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo());
1876 bool ParseAsmAttributesAfterDeclarator(Declarator &D);
1877 Decl *ParseDeclarationAfterDeclaratorAndAttributes(
1879 const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo(),
1880 ForRangeInit *FRI =
nullptr);
1891 bool ParseImplicitInt(DeclSpec &DS, CXXScopeSpec *SS,
1893 DeclSpecContext DSC, ParsedAttributes &Attrs);
1903 ParseDeclarationSpecifiers(DeclSpec &DS, ParsedTemplateInfo &TemplateInfo,
1905 DeclSpecContext DSC = DeclSpecContext::DSC_normal,
1906 LateParsedAttrList *LateAttrs =
nullptr) {
1907 return ParseDeclarationSpecifiers(DS, TemplateInfo, AS, DSC, LateAttrs,
1908 getImplicitTypenameContext(DSC));
1941 ParseDeclarationSpecifiers(DeclSpec &DS, ParsedTemplateInfo &TemplateInfo,
1943 LateParsedAttrList *LateAttrs,
1953 bool DiagnoseMissingSemiAfterTagDefinition(
1955 LateParsedAttrList *LateAttrs =
nullptr);
1959 DeclSpecContext DSC = DeclSpecContext::DSC_normal,
1960 LateParsedAttrList *LateAttrs =
nullptr) {
1961 ParseSpecifierQualifierList(DS, getImplicitTypenameContext(DSC), AS, DSC,
1974 ParseSpecifierQualifierList(DeclSpec &DS,
1977 DeclSpecContext DSC = DeclSpecContext::DSC_normal,
1978 LateParsedAttrList *LateAttrs =
nullptr);
2012 void ParseEnumSpecifier(SourceLocation TagLoc, DeclSpec &DS,
2013 const ParsedTemplateInfo &TemplateInfo,
2028 void ParseEnumBody(SourceLocation StartLoc, Decl *TagDecl,
2029 SkipBodyInfo *SkipBody =
nullptr);
2043 void ParseStructUnionBody(SourceLocation StartLoc,
DeclSpec::TST TagType,
2044 RecordDecl *TagDecl);
2069 void ParseStructDeclaration(
2070 ParsingDeclSpec &DS,
2071 llvm::function_ref<Decl *(ParsingFieldDeclarator &)> FieldsCallback,
2072 LateParsedAttrList *LateFieldAttrs =
nullptr);
2084 bool DisambiguatingWithExpression =
false);
2088 bool isTypeSpecifierQualifier(
const Token &Tok);
2093 bool isKnownToBeTypeSpecifier(
const Token &Tok)
const;
2098 bool isConstructorDeclarator(
2101 const ParsedTemplateInfo *TemplateInfo =
nullptr);
2105 void DiagnoseBitIntUse(
const Token &Tok);
2109 bool CheckProhibitedCXX11Attribute() {
2110 assert(Tok.is(tok::l_square));
2113 return DiagnoseProhibitedCXX11Attribute();
2124 bool DiagnoseProhibitedCXX11Attribute();
2126 void CheckMisplacedCXX11Attribute(ParsedAttributes &Attrs,
2127 SourceLocation CorrectLocation) {
2128 if (!Tok.isRegularKeywordAttribute() &&
2129 (Tok.isNot(tok::l_square) ||
NextToken().
isNot(tok::l_square)) &&
2130 Tok.isNot(tok::kw_alignas))
2132 DiagnoseMisplacedCXX11Attribute(Attrs, CorrectLocation);
2139 void DiagnoseMisplacedCXX11Attribute(ParsedAttributes &Attrs,
2140 SourceLocation CorrectLocation);
2150 void stripTypeAttributesOffDeclSpec(ParsedAttributes &Attrs, DeclSpec &DS,
2154 void ProhibitAttributes(ParsedAttributes &Attrs,
2155 SourceLocation FixItLoc = SourceLocation()) {
2156 if (Attrs.Range.isInvalid())
2158 DiagnoseProhibitedAttributes(Attrs, FixItLoc);
2162 void ProhibitAttributes(ParsedAttributesView &Attrs,
2163 SourceLocation FixItLoc = SourceLocation()) {
2164 if (Attrs.Range.isInvalid())
2166 DiagnoseProhibitedAttributes(Attrs, FixItLoc);
2167 Attrs.clearListOnly();
2169 void DiagnoseProhibitedAttributes(
const ParsedAttributesView &Attrs,
2170 SourceLocation FixItLoc);
2178 void ProhibitCXX11Attributes(ParsedAttributes &Attrs,
unsigned AttrDiagID,
2179 unsigned KeywordDiagId,
2180 bool DiagnoseEmptyAttrs =
false,
2181 bool WarnOnUnknownAttrs =
false);
2185 void DiagnoseCXX11AttributeExtension(ParsedAttributes &Attrs);
2187 ExprResult ParseUnevaluatedStringInAttribute(
const IdentifierInfo &AttrName);
2194 bool ParseAttributeArgumentList(
2195 const IdentifierInfo &AttrName, SmallVectorImpl<Expr *> &Exprs,
2196 ParsedAttributeArgumentsProperties ArgsProperties,
unsigned Arg);
2203 ParseAttributeArgsCommon(IdentifierInfo *AttrName, SourceLocation AttrNameLoc,
2204 ParsedAttributes &Attrs, SourceLocation *EndLoc,
2205 IdentifierInfo *ScopeName, SourceLocation ScopeLoc,
2206 ParsedAttr::Form Form);
2208 enum ParseAttrKindMask {
2210 PAKM_Declspec = 1 << 1,
2211 PAKM_CXX11 = 1 << 2,
2230 void ParseAttributes(
unsigned WhichAttrKinds, ParsedAttributes &Attrs,
2231 LateParsedAttrList *LateAttrs =
nullptr);
2234 bool MaybeParseAttributes(
unsigned WhichAttrKinds, ParsedAttributes &Attrs,
2235 LateParsedAttrList *LateAttrs =
nullptr) {
2236 if (Tok.isOneOf(tok::kw___attribute, tok::kw___declspec) ||
2237 isAllowedCXX11AttributeSpecifier()) {
2238 ParseAttributes(WhichAttrKinds, Attrs, LateAttrs);
2244 void MaybeParseGNUAttributes(Declarator &D,
2245 LateParsedAttrList *LateAttrs =
nullptr) {
2246 if (Tok.is(tok::kw___attribute)) {
2247 ParsedAttributes Attrs(AttrFactory);
2248 ParseGNUAttributes(Attrs, LateAttrs, &D);
2249 D.takeAttributesAppending(Attrs);
2253 bool MaybeParseGNUAttributes(ParsedAttributes &Attrs,
2254 LateParsedAttrList *LateAttrs =
nullptr) {
2255 if (Tok.is(tok::kw___attribute)) {
2256 ParseGNUAttributes(Attrs, LateAttrs);
2278 bool ParseSingleGNUAttribute(ParsedAttributes &Attrs, SourceLocation &EndLoc,
2279 LateParsedAttrList *LateAttrs =
nullptr,
2280 Declarator *D =
nullptr);
2325 void ParseGNUAttributes(ParsedAttributes &Attrs,
2326 LateParsedAttrList *LateAttrs =
nullptr,
2327 Declarator *D =
nullptr);
2331 void ParseGNUAttributeArgs(IdentifierInfo *AttrName,
2332 SourceLocation AttrNameLoc,
2333 ParsedAttributes &Attrs, SourceLocation *EndLoc,
2334 IdentifierInfo *ScopeName, SourceLocation ScopeLoc,
2335 ParsedAttr::Form Form, Declarator *D);
2336 IdentifierLoc *ParseIdentifierLoc();
2339 ParseClangAttributeArgs(IdentifierInfo *AttrName, SourceLocation AttrNameLoc,
2340 ParsedAttributes &Attrs, SourceLocation *EndLoc,
2341 IdentifierInfo *ScopeName, SourceLocation ScopeLoc,
2342 ParsedAttr::Form Form);
2344 void MaybeParseCXX11Attributes(Declarator &D) {
2345 if (isAllowedCXX11AttributeSpecifier()) {
2346 ParsedAttributes Attrs(AttrFactory);
2347 ParseCXX11Attributes(Attrs);
2348 D.takeAttributesAppending(Attrs);
2352 bool MaybeParseCXX11Attributes(ParsedAttributes &Attrs,
2353 bool OuterMightBeMessageSend =
false) {
2354 if (isAllowedCXX11AttributeSpecifier(
false, OuterMightBeMessageSend)) {
2355 ParseCXX11Attributes(Attrs);
2361 bool MaybeParseMicrosoftAttributes(ParsedAttributes &Attrs) {
2362 bool AttrsParsed =
false;
2364 Tok.is(tok::l_square)) {
2365 ParsedAttributes AttrsWithRange(AttrFactory);
2366 ParseMicrosoftAttributes(AttrsWithRange);
2367 AttrsParsed = !AttrsWithRange.empty();
2368 Attrs.takeAllAppendingFrom(AttrsWithRange);
2372 bool MaybeParseMicrosoftDeclSpecs(ParsedAttributes &Attrs) {
2373 if (
getLangOpts().DeclSpecKeyword && Tok.is(tok::kw___declspec)) {
2374 ParseMicrosoftDeclSpecs(Attrs);
2388 void ParseMicrosoftDeclSpecs(ParsedAttributes &Attrs);
2389 bool ParseMicrosoftDeclSpecArgs(IdentifierInfo *AttrName,
2390 SourceLocation AttrNameLoc,
2391 ParsedAttributes &Attrs);
2392 void ParseMicrosoftTypeAttributes(ParsedAttributes &attrs);
2393 void ParseWebAssemblyFuncrefTypeAttribute(ParsedAttributes &Attrs);
2394 void DiagnoseAndSkipExtendedMicrosoftTypeAttributes();
2395 SourceLocation SkipExtendedMicrosoftTypeAttributes();
2397 void ParseBorlandTypeAttributes(ParsedAttributes &attrs);
2398 void ParseOpenCLKernelAttributes(ParsedAttributes &attrs);
2399 void ParseOpenCLQualifiers(ParsedAttributes &Attrs);
2400 void ParseNullabilityTypeSpecifiers(ParsedAttributes &attrs);
2401 void ParseCUDAFunctionAttributes(ParsedAttributes &attrs);
2402 void ParseHLSLQualifiers(ParsedAttributes &Attrs);
2414 VersionTuple ParseVersionTuple(SourceRange &Range);
2443 void ParseAvailabilityAttribute(IdentifierInfo &Availability,
2444 SourceLocation AvailabilityLoc,
2445 ParsedAttributes &attrs,
2446 SourceLocation *endLoc,
2447 IdentifierInfo *ScopeName,
2448 SourceLocation ScopeLoc,
2449 ParsedAttr::Form Form);
2467 void ParseExternalSourceSymbolAttribute(IdentifierInfo &ExternalSourceSymbol,
2469 ParsedAttributes &Attrs,
2470 SourceLocation *EndLoc,
2471 IdentifierInfo *ScopeName,
2472 SourceLocation ScopeLoc,
2473 ParsedAttr::Form Form);
2488 void ParseObjCBridgeRelatedAttribute(IdentifierInfo &ObjCBridgeRelated,
2489 SourceLocation ObjCBridgeRelatedLoc,
2490 ParsedAttributes &Attrs,
2491 SourceLocation *EndLoc,
2492 IdentifierInfo *ScopeName,
2493 SourceLocation ScopeLoc,
2494 ParsedAttr::Form Form);
2496 void ParseSwiftNewTypeAttribute(IdentifierInfo &AttrName,
2497 SourceLocation AttrNameLoc,
2498 ParsedAttributes &Attrs,
2499 SourceLocation *EndLoc,
2500 IdentifierInfo *ScopeName,
2501 SourceLocation ScopeLoc,
2502 ParsedAttr::Form Form);
2504 void ParseTypeTagForDatatypeAttribute(IdentifierInfo &AttrName,
2505 SourceLocation AttrNameLoc,
2506 ParsedAttributes &Attrs,
2507 SourceLocation *EndLoc,
2508 IdentifierInfo *ScopeName,
2509 SourceLocation ScopeLoc,
2510 ParsedAttr::Form Form);
2512 void ParseAttributeWithTypeArg(IdentifierInfo &AttrName,
2513 SourceLocation AttrNameLoc,
2514 ParsedAttributes &Attrs,
2515 IdentifierInfo *ScopeName,
2516 SourceLocation ScopeLoc,
2517 ParsedAttr::Form Form);
2519 void DistributeCLateParsedAttrs(Decl *Dcl, LateParsedAttrList *LateAttrs);
2525 void ParseBoundsAttribute(IdentifierInfo &AttrName,
2526 SourceLocation AttrNameLoc, ParsedAttributes &Attrs,
2527 IdentifierInfo *ScopeName, SourceLocation ScopeLoc,
2528 ParsedAttr::Form Form);
2544 void ParseTypeofSpecifier(DeclSpec &DS);
2551 void ParseAtomicSpecifier(DeclSpec &DS);
2561 ExprResult ParseAlignArgument(StringRef KWName, SourceLocation Start,
2562 SourceLocation &EllipsisLoc,
bool &IsType,
2575 void ParseAlignmentSpecifier(ParsedAttributes &Attrs,
2576 SourceLocation *endLoc =
nullptr);
2585 void ParsePtrauthQualifier(ParsedAttributes &Attrs);
2590 class DeclaratorScopeObj {
2597 DeclaratorScopeObj(
Parser &p, CXXScopeSpec &ss)
2598 : P(p), SS(ss), EnteredScope(
false), CreatedScope(
false) {}
2600 void EnterDeclaratorScope() {
2601 assert(!EnteredScope &&
"Already entered the scope!");
2602 assert(SS.isSet() &&
"C++ scope was not set!");
2604 CreatedScope =
true;
2607 if (!P.Actions.ActOnCXXEnterDeclaratorScope(P.getCurScope(), SS))
2608 EnteredScope =
true;
2611 ~DeclaratorScopeObj() {
2613 assert(SS.isSet() &&
"C++ scope was cleared ?");
2614 P.Actions.ActOnCXXExitDeclaratorScope(P.getCurScope(), SS);
2622 void ParseDeclarator(Declarator &D);
2653 void ParseDeclaratorInternal(Declarator &D,
2654 DirectDeclParseFunction DirectDeclParser);
2656 enum AttrRequirements {
2657 AR_NoAttributesParsed = 0,
2658 AR_GNUAttributesParsedAndRejected = 1 << 0,
2659 AR_GNUAttributesParsed = 1 << 1,
2660 AR_CXX11AttributesParsed = 1 << 2,
2661 AR_DeclspecAttributesParsed = 1 << 3,
2662 AR_AllAttributesParsed = AR_GNUAttributesParsed | AR_CXX11AttributesParsed |
2663 AR_DeclspecAttributesParsed,
2664 AR_VendorAttributesParsed =
2665 AR_GNUAttributesParsed | AR_DeclspecAttributesParsed
2682 void ParseTypeQualifierListOpt(
2683 DeclSpec &DS,
unsigned AttrReqs = AR_AllAttributesParsed,
2684 bool AtomicOrPtrauthAllowed =
true,
bool IdentifierRequired =
false,
2685 llvm::function_ref<
void()> CodeCompletionHandler = {},
2686 LateParsedAttrList *LateAttrs =
nullptr);
2736 void ParseDirectDeclarator(Declarator &D);
2737 void ParseDecompositionDeclarator(Declarator &D);
2755 void ParseParenDeclarator(Declarator &D);
2780 void ParseFunctionDeclarator(Declarator &D, ParsedAttributes &FirstArgAttrs,
2782 bool IsAmbiguous,
bool RequiresArg =
false);
2783 void InitCXXThisScopeForDeclaratorIfRelevant(
2784 const Declarator &D,
const DeclSpec &DS,
2785 std::optional<Sema::CXXThisScopeRAII> &ThisScope);
2789 bool ParseRefQualifier(
bool &RefQualifierIsLValueRef,
2790 SourceLocation &RefQualifierLoc);
2797 bool isFunctionDeclaratorIdentifierList();
2811 void ParseFunctionDeclaratorIdentifierList(
2812 Declarator &D, SmallVectorImpl<DeclaratorChunk::ParamInfo> &ParamInfo);
2813 void ParseParameterDeclarationClause(
2814 Declarator &D, ParsedAttributes &attrs,
2815 SmallVectorImpl<DeclaratorChunk::ParamInfo> &ParamInfo,
2816 SourceLocation &EllipsisLoc,
2817 LateParsedAttrList *LateParamAttrs =
nullptr) {
2818 return ParseParameterDeclarationClause(
2819 D.getContext(), attrs, ParamInfo, EllipsisLoc,
2820 D.getCXXScopeSpec().isSet() &&
2821 D.isFunctionDeclaratorAFunctionDeclaration(),
2860 void ParseParameterDeclarationClause(
2862 SmallVectorImpl<DeclaratorChunk::ParamInfo> &ParamInfo,
2863 SourceLocation &EllipsisLoc,
bool IsACXXFunctionDeclaration =
false,
2864 LateParsedAttrList *LateParamAttrs =
nullptr);
2875 void ParseBracketDeclarator(Declarator &D);
2878 void ParseMisplacedBracketDeclarator(Declarator &D);
2889 TypeResult ParseTypeFromString(StringRef TypeStr, StringRef Context,
2890 SourceLocation IncludeLoc);
2906 mutable IdentifierInfo *Ident_sealed;
2907 mutable IdentifierInfo *Ident_abstract;
2910 mutable IdentifierInfo *Ident_final;
2911 mutable IdentifierInfo *Ident_GNU_final;
2912 mutable IdentifierInfo *Ident_override;
2917 struct ParsingClass {
2918 ParsingClass(Decl *TagOrTemplate,
bool TopLevelClass,
bool IsInterface)
2919 : TopLevelClass(TopLevelClass), IsInterface(IsInterface),
2920 TagOrTemplate(TagOrTemplate) {}
2924 bool TopLevelClass : 1;
2927 bool IsInterface : 1;
2930 Decl *TagOrTemplate;
2935 LateParsedDeclarationsContainer LateParsedDeclarations;
2941 std::stack<ParsingClass *> ClassStack;
2943 ParsingClass &getCurrentClass() {
2944 assert(!ClassStack.empty() &&
"No lexed method stacks!");
2945 return *ClassStack.top();
2949 class ParsingClassDefinition {
2955 ParsingClassDefinition(
Parser &P, Decl *TagOrTemplate,
bool TopLevelClass,
2957 : P(P), Popped(
false),
2958 State(P.PushParsingClass(TagOrTemplate, TopLevelClass, IsInterface)) {
2963 assert(!Popped &&
"Nested class has already been popped");
2965 P.PopParsingClass(State);
2968 ~ParsingClassDefinition() {
2970 P.PopParsingClass(State);
2986 bool Delayed, SourceRange &SpecificationRange,
2987 SmallVectorImpl<ParsedType> &DynamicExceptions,
2988 SmallVectorImpl<SourceRange> &DynamicExceptionRanges,
3006 ParseDynamicExceptionSpecification(SourceRange &SpecificationRange,
3007 SmallVectorImpl<ParsedType> &Exceptions,
3008 SmallVectorImpl<SourceRange> &Ranges);
3015 TypeResult ParseTrailingReturnType(SourceRange &Range,
3016 bool MayBeFollowedByDirectInit);
3019 void ParseTrailingRequiresClauseWithScope(Declarator &D);
3020 void ParseTrailingRequiresClause(Declarator &D);
3022 void ParseMicrosoftIfExistsClassDeclaration(
DeclSpec::TST TagType,
3023 ParsedAttributes &AccessAttrs,
3026 SourceLocation ParsePackIndexingType(DeclSpec &DS);
3027 void AnnotateExistingIndexedTypeNamePack(
ParsedType T,
3028 SourceLocation StartLoc,
3029 SourceLocation EndLoc);
3034 bool AnnotatePackIndexingTemplateName(CXXScopeSpec &SS, UnqualifiedId &Name,
3043 bool isAllowedCXX11AttributeSpecifier(
bool Disambiguate =
false,
3044 bool OuterMightBeMessageSend =
false) {
3045 return (Tok.isRegularKeywordAttribute() ||
3046 isCXX11AttributeSpecifier(Disambiguate, OuterMightBeMessageSend) !=
3053 SourceLocation SkipCXX11Attributes();
3057 void DiagnoseAndSkipCXX11Attributes();
3059 void ParseOpenMPAttributeArgs(
const IdentifierInfo *AttrName,
3088 void ParseCXX11AttributeSpecifierInternal(ParsedAttributes &Attrs,
3090 SourceLocation *EndLoc =
nullptr);
3091 void ParseCXX11AttributeSpecifier(ParsedAttributes &Attrs,
3092 SourceLocation *EndLoc =
nullptr) {
3094 ParseCXX11AttributeSpecifierInternal(Attrs, OpenMPTokens, EndLoc);
3095 ReplayOpenMPAttributeTokens(OpenMPTokens);
3104 void ParseCXX11Attributes(ParsedAttributes &attrs);
3124 bool ParseCXX11AttributeArgs(IdentifierInfo *AttrName,
3125 SourceLocation AttrNameLoc,
3126 ParsedAttributes &Attrs, SourceLocation *EndLoc,
3127 IdentifierInfo *ScopeName,
3128 SourceLocation ScopeLoc,
3134 ParseCXXAssumeAttributeArg(ParsedAttributes &Attrs, IdentifierInfo *AttrName,
3135 SourceLocation AttrNameLoc,
3136 IdentifierInfo *ScopeName, SourceLocation ScopeLoc,
3137 SourceLocation *EndLoc, ParsedAttr::Form Form);
3148 IdentifierInfo *TryParseCXX11AttributeIdentifier(
3149 SourceLocation &Loc,
3152 const IdentifierInfo *EnclosingScope =
nullptr);
3155 void ParseMicrosoftUuidAttributeArgs(ParsedAttributes &Attrs);
3167 void ParseMicrosoftAttributes(ParsedAttributes &Attrs);
3169 void ParseMicrosoftInheritanceClassAttributes(ParsedAttributes &attrs);
3170 void ParseNullabilityClassAttributes(ParsedAttributes &attrs);
3179 SourceLocation ParseDecltypeSpecifier(DeclSpec &DS);
3180 void AnnotateExistingDecltypeSpecifier(
const DeclSpec &DS,
3181 SourceLocation StartLoc,
3182 SourceLocation EndLoc);
3195 return isCXX11VirtSpecifier(Tok);
3205 void ParseOptionalCXX11VirtSpecifierSeq(VirtSpecifiers &VS,
bool IsInterface,
3206 SourceLocation FriendLoc);
3210 bool isCXX11FinalKeyword()
const;
3216 bool isClassCompatibleKeyword()
const;
3218 bool MaybeParseTypeTransformTypeSpecifier(DeclSpec &DS);
3221 void DiagnoseUnexpectedNamespace(NamedDecl *Context);
3253 SourceLocation &DeclEnd,
3254 SourceLocation InlineLoc = SourceLocation());
3256 struct InnerNamespaceInfo {
3257 SourceLocation NamespaceLoc;
3258 SourceLocation InlineLoc;
3259 SourceLocation IdentLoc;
3260 IdentifierInfo *Ident;
3262 using InnerNamespaceInfoList = llvm::SmallVector<InnerNamespaceInfo, 4>;
3265 void ParseInnerNamespace(
const InnerNamespaceInfoList &InnerNSs,
3266 unsigned int index, SourceLocation &InlineLoc,
3267 ParsedAttributes &attrs,
3299 Decl *ParseExportDeclaration();
3305 SourceLocation &DeclEnd, ParsedAttributes &Attrs);
3320 SourceLocation &DeclEnd, ParsedAttributes &attrs);
3322 struct UsingDeclarator {
3323 SourceLocation TypenameLoc;
3326 SourceLocation EllipsisLoc;
3329 TypenameLoc = EllipsisLoc = SourceLocation();
3370 const ParsedTemplateInfo &TemplateInfo,
3371 SourceLocation UsingLoc,
3372 SourceLocation &DeclEnd,
3373 ParsedAttributes &Attrs,
3375 Decl *ParseAliasDeclarationAfterDeclarator(
3376 const ParsedTemplateInfo &TemplateInfo, SourceLocation UsingLoc,
3378 ParsedAttributes &Attrs, Decl **OwnedType =
nullptr);
3391 Decl *ParseStaticAssertDeclaration(SourceLocation &DeclEnd);
3396 Decl *ParseNamespaceAlias(SourceLocation NamespaceLoc,
3397 SourceLocation AliasLoc, IdentifierInfo *Alias,
3398 SourceLocation &DeclEnd);
3406 bool isValidAfterTypeSpecifier(
bool CouldBeBitfield);
3450 void ParseClassSpecifier(
tok::TokenKind TagTokKind, SourceLocation TagLoc,
3451 DeclSpec &DS, ParsedTemplateInfo &TemplateInfo,
3453 DeclSpecContext DSC, ParsedAttributes &Attributes);
3454 void SkipCXXMemberSpecification(SourceLocation StartLoc,
3455 SourceLocation AttrFixitLoc,
unsigned TagType,
3466 void ParseCXXMemberSpecification(SourceLocation StartLoc,
3467 SourceLocation AttrFixitLoc,
3468 ParsedAttributes &Attrs,
unsigned TagType,
3493 ExprResult ParseCXXMemberInitializer(Decl *D,
bool IsFunction,
3494 SourceLocation &EqualLoc);
3498 bool ParseCXXMemberDeclaratorBeforeInitializer(Declarator &DeclaratorInfo,
3501 LateParsedAttrList &LateAttrs);
3506 MaybeParseAndDiagnoseDeclSpecAfterCXX11VirtSpecifierSeq(Declarator &D,
3507 VirtSpecifiers &VS);
3563 ParsedTemplateInfo &TemplateInfo,
3564 ParsingDeclRAIIObject *DiagsFromTParams =
nullptr);
3567 ParsedAttributes &AccessAttrs,
3593 void ParseConstructorInitializer(Decl *ConstructorDecl);
3615 void HandleMemberFunctionDeclDelays(Declarator &DeclaratorInfo,
3643 TypeResult ParseBaseTypeSpecifier(SourceLocation &BaseLoc,
3644 SourceLocation &EndLocation);
3656 void ParseBaseClause(Decl *ClassDecl);
3671 BaseResult ParseBaseSpecifier(Decl *ClassDecl);
3687 bool isClassCompatibleKeyword(Token Tok)
const;
3689 void ParseHLSLRootSignatureAttributeArgs(ParsedAttributes &Attrs);
3864 bool GreaterThanIsOperator;
3868 llvm::SmallDenseMap<IdentifierInfo *, tok::TokenKind> RevertibleTypeTraits;
3887 PushParsingClass(
Decl *TagOrTemplate,
bool TopLevelClass,
bool IsInterface);
3891 void DeallocateParsedClasses(ParsingClass *
Class);
4113 bool isAddressOfOperand,
bool &NotCastExpr,
4115 bool isVectorLiteral =
false,
4116 bool *NotPrimaryExpression =
nullptr);
4118 bool isAddressOfOperand =
false,
4121 bool isVectorLiteral =
false,
4122 bool *NotPrimaryExpression =
nullptr);
4125 bool isNotExpressionStart();
4129 bool isPostfixExpressionSuffixStart() {
4131 return (K == tok::l_square || K == tok::l_paren || K == tok::lesslessless ||
4132 K == tok::period || K == tok::arrow || K == tok::plusplus ||
4133 K == tok::minusminus);
4175 ExprResult ParseUnaryExprOrTypeTraitExpression();
4204 ExprResult ParseSYCLUniqueStableNameExpression();
4266 llvm::function_ref<
void()> ExpressionStarts =
4267 llvm::function_ref<
void()>(),
4268 bool FailImmediatelyOnInvalidExpr =
false,
4269 bool ParsingExpansionStmtInitList =
false);
4314 bool StopIfCastExpr,
4351 ExprResult ParseGenericSelectionExpression();
4370 void injectEmbedTokens();
4396 ExprResult ParseAssignmentExprWithObjCMessageExprStart(
4398 Expr *ReceiverExpr);
4403 bool isKnownToBeDeclarationSpecifier() {
4417 bool isTypeIdForGenericSelection() {
4423 return isTypeSpecifierQualifier(Tok);
4429 bool isTypeIdUnambiguously() {
4434 return isTypeSpecifierQualifier(Tok);
4443 void ParseBlockId(SourceLocation CaretLoc);
4452 std::optional<AvailabilitySpec> ParseAvailabilitySpec();
4453 ExprResult ParseAvailabilityCheckExpr(SourceLocation StartLoc);
4459 bool tryParseOpenMPArrayShapingCastPart();
4461 ExprResult ParseBuiltinPtrauthTypeDiscriminator();
4514 bool ObjectHadErrors,
bool EnteringContext,
4515 bool AllowDestructorName,
bool AllowConstructorName,
4516 bool AllowDeductionGuide,
4517 SourceLocation *TemplateKWLoc, UnqualifiedId &
Result);
4529 bool ParsingGenericAssociationType;
4540 ExprResult tryParseCXXIdExpression(CXXScopeSpec &SS,
bool isAddressOfOperand);
4591 ExprResult ParseCXXIdExpression(
bool isAddressOfOperand =
false);
4594 bool areTokensAdjacent(
const Token &A,
const Token &B);
4598 void CheckForTemplateAndDigraph(Token &
Next,
ParsedType ObjectTypePtr,
4599 bool EnteringContext, IdentifierInfo &II,
4662 bool ParseOptionalCXXScopeSpecifier(
4663 CXXScopeSpec &SS,
ParsedType ObjectType,
bool ObjectHasErrors,
4664 bool EnteringContext,
bool *MayBePseudoDestructor =
nullptr,
4665 bool IsTypename =
false,
const IdentifierInfo **LastII =
nullptr,
4666 bool OnlyNamespace =
false,
bool InUsingDeclaration =
false,
4667 bool Disambiguation =
false,
bool IsAddressOfOperand =
false,
4668 bool IsInDeclarationContext =
false);
4670 bool ParseOptionalCXXScopeSpecifier(CXXScopeSpec &SS,
ParsedType ObjectType,
4671 bool ObjectHasErrors,
4672 bool EnteringContext,
4673 bool IsAddressOfOperand) {
4674 return ParseOptionalCXXScopeSpecifier(
4675 SS, ObjectType, ObjectHasErrors, EnteringContext,
4682 IsAddressOfOperand);
4689 enum class LambdaIntroducerTentativeParse {
4767 ParseLambdaIntroducer(LambdaIntroducer &Intro,
4768 LambdaIntroducerTentativeParse *Tentative =
nullptr);
4772 ExprResult ParseLambdaExpressionAfterIntroducer(LambdaIntroducer &Intro);
4775 bool isLambdaSpecifier();
4859 ExprResult ParseCXXPseudoDestructor(Expr *Base, SourceLocation OpLoc,
4914 ExprResult ParseCXXTypeConstructExpression(
const DeclSpec &DS);
4944 void ParseCXXSimpleTypeSpecifier(DeclSpec &DS);
4959 bool ParseCXXTypeSpecifierSeq(
4977 bool ParseExpressionListOrTypeId(SmallVectorImpl<Expr *> &Exprs,
4989 void ParseDirectNewDeclarator(Declarator &D);
5022 ExprResult ParseCXXNewExpression(
bool UseGlobal, SourceLocation Start);
5037 ExprResult ParseCXXDeleteExpression(
bool UseGlobal, SourceLocation Start);
5077 Sema::ConditionResult ParseCondition(
StmtResult *InitStmt, SourceLocation Loc,
5079 ForRangeInfo *FRI =
nullptr,
5080 bool AfterInitStmt =
false);
5082 ParsedAttributes &Attrs);
5129 bool isTypeIdInParens(
bool &isAmbiguous) {
5132 isAmbiguous =
false;
5133 return isTypeSpecifierQualifier(Tok);
5135 bool isTypeIdInParens() {
5137 return isTypeIdInParens(isAmbiguous);
5175 bool ParseUnqualifiedIdTemplateId(CXXScopeSpec &SS,
ParsedType ObjectType,
5176 bool ObjectHadErrors,
5177 SourceLocation TemplateKWLoc,
5178 IdentifierInfo *Name,
5179 SourceLocation NameLoc,
5180 bool EnteringContext, UnqualifiedId &Id,
5181 bool AssumeTemplateId);
5223 bool ParseUnqualifiedIdOperator(CXXScopeSpec &SS,
bool EnteringContext,
5290 bool MaybeParseHLSLAnnotations(Declarator &D,
5291 SourceLocation *EndLoc =
nullptr,
5292 bool CouldBeBitField =
false) {
5293 assert(
getLangOpts().
HLSL &&
"MaybeParseHLSLAnnotations is for HLSL only");
5294 if (Tok.is(tok::colon)) {
5295 ParsedAttributes Attrs(AttrFactory);
5296 ParseHLSLAnnotations(Attrs, EndLoc, CouldBeBitField);
5297 D.takeAttributesAppending(Attrs);
5303 void MaybeParseHLSLAnnotations(ParsedAttributes &Attrs,
5304 SourceLocation *EndLoc =
nullptr) {
5305 assert(
getLangOpts().
HLSL &&
"MaybeParseHLSLAnnotations is for HLSL only");
5306 if (Tok.is(tok::colon))
5307 ParseHLSLAnnotations(Attrs, EndLoc);
5310 struct ParsedSemantic {
5311 StringRef Name =
"";
5313 bool Explicit =
false;
5316 ParsedSemantic ParseHLSLSemantic();
5318 void ParseHLSLAnnotations(ParsedAttributes &Attrs,
5319 SourceLocation *EndLoc =
nullptr,
5320 bool CouldBeBitField =
false);
5321 Decl *ParseHLSLBuffer(SourceLocation &DeclEnd, ParsedAttributes &Attrs);
5345 ExprResult ParseInitializer(Decl *DeclForInitializer =
nullptr);
5350 bool MayBeDesignationStart();
5378 struct DesignatorCompletionInfo {
5379 SmallVectorImpl<Expr *> &InitExprs;
5380 QualType PreferredBaseType;
5429 ExprResult ParseInitializerWithPotentialDesignator(DesignatorCompletionInfo);
5434 typedef SmallVector<Expr *, 12> ExprVector;
5438 bool ParseMicrosoftIfExistsBraceInitializer(ExprVector &InitExprs,
5455 friend class ObjCDeclContextSwitch;
5458 return Actions.ObjC().getObjCDeclContext();
5464 return Actions.getNullabilityKeyword(nullability);
5480 bool InMessageExpression;
5487 bool ParsingInObjCContainer;
5492 bool isObjCInstancetype() {
5494 if (
Tok.isAnnotation())
5496 if (!Ident_instancetype)
5498 return Tok.getIdentifierInfo() == Ident_instancetype;
5506 ObjCContainerDecl *DC;
5507 SaveAndRestore<bool> WithinObjCContainer;
5512 WithinObjCContainer(P.ParsingInObjCContainer, DC !=
nullptr) {
5514 P.Actions.ObjC().ActOnObjCTemporaryExitContainerContext(DC);
5516 ~ObjCDeclContextSwitch() {
5518 P.Actions.ObjC().ActOnObjCReenterContainerContext(DC);
5522 void CheckNestedObjCContexts(SourceLocation AtLoc);
5524 void ParseLexedObjCMethodDefs(LexedMethod &LM,
bool parseMethod);
5542 DeclGroupPtrTy ParseObjCAtDirectives(ParsedAttributes &DeclAttrs,
5543 ParsedAttributes &DeclSpecAttrs);
5554 DeclGroupPtrTy ParseObjCAtClassDeclaration(SourceLocation atLoc);
5587 Decl *ParseObjCAtInterfaceDeclaration(SourceLocation AtLoc,
5588 ParsedAttributes &prefixAttrs);
5594 ObjCTypeParamList *parseObjCTypeParamList();
5622 ObjCTypeParamList *parseObjCTypeParamListOrProtocolRefs(
5624 SmallVectorImpl<IdentifierLoc> &protocolIdents, SourceLocation &rAngleLoc,
5625 bool mayBeProtocolList =
true);
5627 void HelperActionsForIvarDeclarations(ObjCContainerDecl *interfaceDecl,
5628 SourceLocation atLoc,
5630 SmallVectorImpl<Decl *> &AllIvarDecls,
5631 bool RBraceMissing);
5656 void ParseObjCClassInstanceVariables(ObjCContainerDecl *interfaceDecl,
5658 SourceLocation atLoc);
5665 bool ParseObjCProtocolReferences(
5666 SmallVectorImpl<Decl *> &P, SmallVectorImpl<SourceLocation> &PLocs,
5667 bool WarnOnDeclarations,
bool ForObjCContainer, SourceLocation &LAngleLoc,
5668 SourceLocation &EndProtoLoc,
bool consumeLastToken);
5679 void parseObjCTypeArgsOrProtocolQualifiers(
5680 ParsedType baseType, SourceLocation &typeArgsLAngleLoc,
5681 SmallVectorImpl<ParsedType> &typeArgs, SourceLocation &typeArgsRAngleLoc,
5682 SourceLocation &protocolLAngleLoc, SmallVectorImpl<Decl *> &protocols,
5683 SmallVectorImpl<SourceLocation> &protocolLocs,
5684 SourceLocation &protocolRAngleLoc,
bool consumeLastToken,
5685 bool warnOnIncompleteProtocols);
5689 void parseObjCTypeArgsAndProtocolQualifiers(
5690 ParsedType baseType, SourceLocation &typeArgsLAngleLoc,
5691 SmallVectorImpl<ParsedType> &typeArgs, SourceLocation &typeArgsRAngleLoc,
5692 SourceLocation &protocolLAngleLoc, SmallVectorImpl<Decl *> &protocols,
5693 SmallVectorImpl<SourceLocation> &protocolLocs,
5694 SourceLocation &protocolRAngleLoc,
bool consumeLastToken);
5698 TypeResult parseObjCProtocolQualifierType(SourceLocation &rAngleLoc);
5702 TypeResult parseObjCTypeArgsAndProtocolQualifiers(SourceLocation loc,
5704 bool consumeLastToken,
5705 SourceLocation &endLoc);
5741 DeclGroupPtrTy ParseObjCAtProtocolDeclaration(SourceLocation atLoc,
5742 ParsedAttributes &prefixAttrs);
5744 struct ObjCImplParsingDataRAII {
5748 typedef SmallVector<LexedMethod *, 8> LateParsedObjCMethodContainer;
5749 LateParsedObjCMethodContainer LateParsedObjCMethods;
5751 ObjCImplParsingDataRAII(
Parser &parser, Decl *D)
5752 : P(parser), Dcl(D), HasCFunction(
false),
5753 PrevParsedObjCImpl(parser.CurParsedObjCImpl) {
5754 P.CurParsedObjCImpl =
this;
5757 ~ObjCImplParsingDataRAII();
5759 void finish(SourceRange AtEnd);
5760 bool isFinished()
const {
return Finished; }
5768 ObjCImplParsingDataRAII *PrevParsedObjCImpl;
5771 ObjCImplParsingDataRAII *CurParsedObjCImpl;
5775 void StashAwayMethodOrFunctionBodyTokens(Decl *MDecl);
5789 DeclGroupPtrTy ParseObjCAtImplementationDeclaration(SourceLocation AtLoc,
5790 ParsedAttributes &Attrs);
5798 Decl *ParseObjCAtAliasDeclaration(SourceLocation atLoc);
5813 Decl *ParseObjCPropertySynthesize(SourceLocation atLoc);
5824 Decl *ParseObjCPropertyDynamic(SourceLocation atLoc);
5836 IdentifierInfo *ParseObjCSelectorPiece(SourceLocation &MethodLocation);
5844 bool isTokIdentifier_in()
const;
5853 ParsedAttributes *ParamAttrs);
5867 Decl *ParseObjCMethodPrototype(
5869 bool MethodDefinition =
true);
5901 Decl *ParseObjCMethodDecl(
5904 bool MethodDefinition =
true);
5934 void ParseObjCPropertyAttribute(ObjCDeclSpec &DS);
5940 Decl *ParseObjCMethodDefinition();
5944 ExprResult ParseObjCAtExpression(SourceLocation AtLocation);
5945 ExprResult ParseObjCStringLiteral(SourceLocation AtLoc);
5952 ExprResult ParseObjCCharacterLiteral(SourceLocation AtLoc);
5961 ExprResult ParseObjCNumericLiteral(SourceLocation AtLoc);
5970 ExprResult ParseObjCBooleanLiteral(SourceLocation AtLoc,
bool ArgValue);
5972 ExprResult ParseObjCArrayLiteral(SourceLocation AtLoc);
5973 ExprResult ParseObjCDictionaryLiteral(SourceLocation AtLoc);
5980 ExprResult ParseObjCBoxedExpr(SourceLocation AtLoc);
5986 ExprResult ParseObjCEncodeExpression(SourceLocation AtLoc);
5992 ExprResult ParseObjCSelectorExpression(SourceLocation AtLoc);
5998 ExprResult ParseObjCProtocolExpression(SourceLocation AtLoc);
6005 bool isSimpleObjCMessageExpression();
6060 ExprResult ParseObjCMessageExpressionBody(SourceLocation LBracloc,
6061 SourceLocation SuperLoc,
6063 Expr *ReceiverExpr);
6089 bool ParseObjCXXMessageReceiver(
bool &IsExpr,
void *&TypeOrExpr);
6094 enum class ParsedStmtContext;
6096 StmtResult ParseObjCAtStatement(SourceLocation atLoc,
6097 ParsedStmtContext StmtCtx);
6112 StmtResult ParseObjCTryStmt(SourceLocation atLoc);
6119 StmtResult ParseObjCThrowStmt(SourceLocation atLoc);
6126 StmtResult ParseObjCSynchronizedStmt(SourceLocation atLoc);
6133 StmtResult ParseObjCAutoreleasePoolStmt(SourceLocation atLoc);
6160 bool isStartOfObjCClassMessageMissingOpenBracket();
6192 bool OpenACCDirectiveParsing =
false;
6196 bool AllowOpenACCArraySections =
false;
6200 class OpenACCArraySectionRAII {
6204 OpenACCArraySectionRAII(
Parser &P) : P(P) {
6205 assert(!P.AllowOpenACCArraySections);
6206 P.AllowOpenACCArraySections =
true;
6208 ~OpenACCArraySectionRAII() {
6209 assert(P.AllowOpenACCArraySections);
6210 P.AllowOpenACCArraySections =
false;
6217 struct OpenACCDirectiveParseInfo {
6219 SourceLocation StartLoc;
6220 SourceLocation DirLoc;
6221 SourceLocation LParenLoc;
6222 SourceLocation RParenLoc;
6223 SourceLocation EndLoc;
6224 SourceLocation MiscLoc;
6226 SmallVector<Expr *> Exprs;
6227 SmallVector<OpenACCClause *> Clauses;
6232 struct OpenACCWaitParseInfo {
6233 bool Failed =
false;
6234 Expr *DevNumExpr =
nullptr;
6235 SourceLocation QueuesLoc;
6236 SmallVector<Expr *> QueueIdExprs;
6238 SmallVector<Expr *> getAllExprs() {
6239 SmallVector<Expr *>
Out;
6240 Out.push_back(DevNumExpr);
6241 llvm::append_range(Out, QueueIdExprs);
6245 struct OpenACCCacheParseInfo {
6246 bool Failed =
false;
6247 SourceLocation ReadOnlyLoc;
6248 SmallVector<Expr *> Vars;
6253 enum class OpenACCParseCanContinue { Cannot = 0, Can = 1 };
6259 using OpenACCClauseParseResult =
6260 llvm::PointerIntPair<OpenACCClause *, 1, OpenACCParseCanContinue>;
6262 OpenACCClauseParseResult OpenACCCanContinue();
6263 OpenACCClauseParseResult OpenACCCannotContinue();
6264 OpenACCClauseParseResult OpenACCSuccess(OpenACCClause *Clause);
6268 OpenACCDirectiveParseInfo ParseOpenACCDirective();
6278 OpenACCCacheParseInfo ParseOpenACCCacheVarList();
6284 using OpenACCVarParseResult = std::pair<ExprResult, OpenACCParseCanContinue>;
6310 OpenACCClauseParseResult
6311 ParseOpenACCClauseParams(ArrayRef<const OpenACCClause *> ExistingClauses,
6313 SourceLocation ClauseLoc);
6317 OpenACCClauseParseResult
6318 ParseOpenACCClause(ArrayRef<const OpenACCClause *> ExistingClauses,
6328 SmallVector<OpenACCClause *>
6337 OpenACCWaitParseInfo ParseOpenACCWaitArgument(SourceLocation Loc,
6342 std::variant<std::monostate, StringLiteral *, IdentifierInfo *>
6343 ParseOpenACCBindClauseArgument();
6348 using OpenACCIntExprParseResult =
6349 std::pair<ExprResult, OpenACCParseCanContinue>;
6354 SourceLocation Loc);
6359 llvm::SmallVectorImpl<Expr *> &IntExprs);
6372 bool ParseOpenACCDeviceTypeList(llvm::SmallVector<IdentifierLoc> &Archs);
6386 SourceLocation Loc);
6401 llvm::SmallVectorImpl<Expr *> &SizeExprs);
6413 bool ParseOpenACCGangArgList(SourceLocation GangLoc,
6414 llvm::SmallVectorImpl<OpenACCGangKind> &GKs,
6415 llvm::SmallVectorImpl<Expr *> &IntExprs);
6417 using OpenACCGangArgRes = std::pair<OpenACCGangKind, ExprResult>;
6421 OpenACCGangArgRes ParseOpenACCGangArg(SourceLocation GangLoc);
6425 ParseOpenACCAfterRoutineDecl(
AccessSpecifier &AS, ParsedAttributes &Attrs,
6427 OpenACCDirectiveParseInfo &DirInfo);
6428 StmtResult ParseOpenACCAfterRoutineStmt(OpenACCDirectiveParseInfo &DirInfo);
6446 bool OpenMPDirectiveParsing =
false;
6451 void ReplayOpenMPAttributeTokens(
CachedTokens &OpenMPTokens) {
6454 if (!OpenMPTokens.empty()) {
6455 PP.EnterToken(Tok,
true);
6456 PP.EnterTokenStream(OpenMPTokens,
true,
6468 SourceLocation Loc);
6473 llvm::omp::TraitSet
Set,
6474 llvm::omp::TraitSelector Selector,
6475 llvm::StringMap<SourceLocation> &Seen);
6479 llvm::omp::TraitSet
Set,
6480 llvm::StringMap<SourceLocation> &Seen);
6484 llvm::StringMap<SourceLocation> &Seen);
6488 llvm::omp::TraitSet
Set,
6489 llvm::StringMap<SourceLocation> &Seen);
6497 llvm::omp::TraitSet
Set,
6498 llvm::StringMap<SourceLocation> &SeenSelectors);
6505 void parseOMPContextSelectorSet(
OMPTraitSet &TISet,
6506 llvm::StringMap<SourceLocation> &SeenSets);
6513 bool parseOMPContextSelectors(SourceLocation Loc,
OMPTraitInfo &TI);
6516 bool parseOpenMPAppendArgs(SmallVectorImpl<OMPInteropInfo> &InteropInfos);
6520 bool parseOMPDeclareVariantMatchClause(SourceLocation Loc,
OMPTraitInfo &TI,
6526 SourceLocation Loc);
6545 void ParseOpenMPAssumesDirective(OpenMPDirectiveKind DKind,
6546 SourceLocation Loc);
6549 void ParseOpenMPEndAssumesDirective(SourceLocation Loc);
6566 void ParseOpenMPClauses(OpenMPDirectiveKind DKind,
6567 SmallVectorImpl<clang::OMPClause *> &Clauses,
6568 SourceLocation Loc);
6571 void ParseOMPDeclareTargetClauses(SemaOpenMP::DeclareTargetContextInfo &DTCI);
6574 void ParseOMPEndDeclareTargetDirective(OpenMPDirectiveKind BeginDKind,
6575 OpenMPDirectiveKind EndDKind,
6576 SourceLocation Loc);
6580 void skipUntilPragmaOpenMPEnd(OpenMPDirectiveKind DKind);
6586 void parseOMPEndDirective(OpenMPDirectiveKind BeginKind,
6587 OpenMPDirectiveKind ExpectedKind,
6588 OpenMPDirectiveKind FoundKind,
6589 SourceLocation MatchingLoc, SourceLocation FoundLoc,
6590 bool SkipUntilOpenMPEnd);
6631 AccessSpecifier &AS, ParsedAttributes &Attrs,
bool Delayed =
false,
6633 Decl *TagDecl =
nullptr);
6647 DeclGroupPtrTy ParseOpenMPDeclareReductionDirective(AccessSpecifier AS);
6651 void ParseOpenMPReductionInitializerForDecl(VarDecl *OmpPrivParm);
6663 DeclGroupPtrTy ParseOpenMPDeclareMapperDirective(AccessSpecifier AS);
6666 TypeResult parseOpenMPDeclareMapperVarDecl(SourceRange &Range,
6667 DeclarationName &Name,
6668 AccessSpecifier AS =
AS_none);
6682 bool ParseOpenMPSimpleVarList(
6683 OpenMPDirectiveKind Kind,
6684 const llvm::function_ref<
void(CXXScopeSpec &, DeclarationNameInfo)>
6686 bool AllowScopeSpecifier);
6735 StmtResult ParseOpenMPDeclarativeOrExecutableDirective(
6736 ParsedStmtContext StmtCtx,
bool ReadDirectiveWithinMetadirective =
false);
6746 ParseOpenMPExecutableDirective(ParsedStmtContext StmtCtx,
6747 OpenMPDirectiveKind DKind, SourceLocation Loc,
6748 bool ReadDirectiveWithinMetadirective);
6757 StmtResult ParseOpenMPInformationalDirective(
6758 ParsedStmtContext StmtCtx, OpenMPDirectiveKind DKind, SourceLocation Loc,
6759 bool ReadDirectiveWithinMetadirective);
6788 OMPClause *ParseOpenMPClause(OpenMPDirectiveKind DKind,
6873 bool ParseOpenMPIndirectClause(SemaOpenMP::DeclareTargetContextInfo &DTCI,
6898 OMPClause *ParseOpenMPSingleExprWithArgClause(OpenMPDirectiveKind DKind,
6903 OMPClause *ParseOpenMPLoopRangeClause();
6912 OMPClause *ParseOpenMPPermutationClause();
7016 OMPClause *ParseOpenMPVarListClause(OpenMPDirectiveKind DKind,
7030 SourceLocation &ClauseNameLoc,
7031 SourceLocation &OpenLoc,
7032 SourceLocation &CloseLoc,
7033 SmallVectorImpl<Expr *> &Exprs,
7034 bool ReqIntConst =
false);
7049 OMPClause *ParseOpenMPUsesAllocatorClause(OpenMPDirectiveKind DKind);
7052 bool ParseOMPInteropInfo(OMPInteropInfo &InteropInfo,
OpenMPClauseKind Kind);
7058 bool ParseOMPInteropAttrSelector(SmallVectorImpl<Expr *> &Attrs);
7096 OMPClause *ParseOpenMPOMPXAttributesClause(
bool ParseOnly);
7103 bool IsAddressOfOperand =
false);
7107 SemaOpenMP::OpenMPVarListDataTy &
Data,
7108 const LangOptions &LangOpts);
7122 SmallVectorImpl<Expr *> &Vars,
7123 SemaOpenMP::OpenMPVarListDataTy &
Data,
7124 SmallVectorImpl<OMPAdjustArgsItem> &AdjustArgsItems);
7159 std::unique_ptr<PragmaHandler> AlignHandler;
7160 std::unique_ptr<PragmaHandler> GCCVisibilityHandler;
7161 std::unique_ptr<PragmaHandler> OptionsHandler;
7162 std::unique_ptr<PragmaHandler> PackHandler;
7163 std::unique_ptr<PragmaHandler> MSStructHandler;
7164 std::unique_ptr<PragmaHandler> UnusedHandler;
7165 std::unique_ptr<PragmaHandler> WeakHandler;
7166 std::unique_ptr<PragmaHandler> RedefineExtnameHandler;
7167 std::unique_ptr<PragmaHandler> FPContractHandler;
7168 std::unique_ptr<PragmaHandler> OpenCLExtensionHandler;
7169 std::unique_ptr<PragmaHandler> OpenMPHandler;
7170 std::unique_ptr<PragmaHandler> OpenACCHandler;
7171 std::unique_ptr<PragmaHandler> PCSectionHandler;
7172 std::unique_ptr<PragmaHandler> MSCommentHandler;
7173 std::unique_ptr<PragmaHandler> MSDetectMismatchHandler;
7174 std::unique_ptr<PragmaHandler> FPEvalMethodHandler;
7175 std::unique_ptr<PragmaHandler> FloatControlHandler;
7176 std::unique_ptr<PragmaHandler> MSPointersToMembers;
7177 std::unique_ptr<PragmaHandler> MSVtorDisp;
7178 std::unique_ptr<PragmaHandler> MSInitSeg;
7179 std::unique_ptr<PragmaHandler> MSDataSeg;
7180 std::unique_ptr<PragmaHandler> MSBSSSeg;
7181 std::unique_ptr<PragmaHandler> MSConstSeg;
7182 std::unique_ptr<PragmaHandler> MSCodeSeg;
7183 std::unique_ptr<PragmaHandler> MSSection;
7184 std::unique_ptr<PragmaHandler> MSStrictGuardStackCheck;
7185 std::unique_ptr<PragmaHandler> MSRuntimeChecks;
7186 std::unique_ptr<PragmaHandler> MSIntrinsic;
7187 std::unique_ptr<PragmaHandler> MSFunction;
7188 std::unique_ptr<PragmaHandler> MSOptimize;
7189 std::unique_ptr<PragmaHandler> MSFenvAccess;
7190 std::unique_ptr<PragmaHandler> MSAllocText;
7191 std::unique_ptr<PragmaHandler> CUDAForceHostDeviceHandler;
7192 std::unique_ptr<PragmaHandler> OptimizeHandler;
7193 std::unique_ptr<PragmaHandler> LoopHintHandler;
7194 std::unique_ptr<PragmaHandler> UnrollHintHandler;
7195 std::unique_ptr<PragmaHandler> NoUnrollHintHandler;
7196 std::unique_ptr<PragmaHandler> UnrollAndJamHintHandler;
7197 std::unique_ptr<PragmaHandler> NoUnrollAndJamHintHandler;
7198 std::unique_ptr<PragmaHandler> FPHandler;
7199 std::unique_ptr<PragmaHandler> STDCFenvAccessHandler;
7200 std::unique_ptr<PragmaHandler> STDCFenvRoundHandler;
7201 std::unique_ptr<PragmaHandler> STDCCXLIMITHandler;
7202 std::unique_ptr<PragmaHandler> STDCUnknownHandler;
7203 std::unique_ptr<PragmaHandler> AttributePragmaHandler;
7204 std::unique_ptr<PragmaHandler> MaxTokensHerePragmaHandler;
7205 std::unique_ptr<PragmaHandler> MaxTokensTotalPragmaHandler;
7206 std::unique_ptr<PragmaHandler> ExportHandler;
7207 std::unique_ptr<PragmaHandler> RISCVPragmaHandler;
7210 void initializePragmaHandlers();
7213 void resetPragmaHandlers();
7220 void HandlePragmaUnused();
7224 void HandlePragmaVisibility();
7228 void HandlePragmaPack();
7232 void HandlePragmaMSStruct();
7234 void HandlePragmaMSPointersToMembers();
7236 void HandlePragmaMSVtorDisp();
7238 void HandlePragmaMSPragma();
7239 bool HandlePragmaMSSection(StringRef PragmaName,
7240 SourceLocation PragmaLocation);
7241 bool HandlePragmaMSSegment(StringRef PragmaName,
7242 SourceLocation PragmaLocation);
7245 bool HandlePragmaMSInitSeg(StringRef PragmaName,
7246 SourceLocation PragmaLocation);
7251 bool HandlePragmaMSStrictGuardStackCheck(StringRef PragmaName,
7252 SourceLocation PragmaLocation);
7253 bool HandlePragmaMSFunction(StringRef PragmaName,
7254 SourceLocation PragmaLocation);
7255 bool HandlePragmaMSAllocText(StringRef PragmaName,
7256 SourceLocation PragmaLocation);
7259 bool HandlePragmaMSOptimize(StringRef PragmaName,
7260 SourceLocation PragmaLocation);
7263 bool HandlePragmaMSIntrinsic(StringRef PragmaName,
7264 SourceLocation PragmaLocation);
7268 void HandlePragmaAlign();
7272 void HandlePragmaDump();
7276 void HandlePragmaWeak();
7280 void HandlePragmaWeakAlias();
7284 void HandlePragmaRedefineExtname();
7288 void HandlePragmaFPContract();
7292 void HandlePragmaFEnvAccess();
7296 void HandlePragmaFEnvRound();
7300 void HandlePragmaCXLimitedRange();
7304 void HandlePragmaFloatControl();
7308 void HandlePragmaFP();
7312 void HandlePragmaOpenCLExtension();
7316 StmtResult HandlePragmaCaptured();
7320 bool HandlePragmaLoopHint(LoopHint &Hint);
7322 bool ParsePragmaAttributeSubjectMatchRuleSet(
7324 SourceLocation &AnyLoc, SourceLocation &LastMatchRuleEndLoc);
7326 void HandlePragmaAttribute();
7332 void HandlePragmaExport();
7358 enum class ParsedStmtContext {
7361 AllowDeclarationsInC = 0x1,
7363 AllowStandaloneOpenMPDirectives = 0x2,
7370 Compound = AllowDeclarationsInC | AllowStandaloneOpenMPDirectives,
7372 LLVM_MARK_AS_BITMASK_ENUM(InStmtExpr)
7387 ParsedStmtContext StmtCtx = ParsedStmtContext::SubStmt,
7442 ParseStatementOrDeclaration(
StmtVector &Stmts, ParsedStmtContext StmtCtx,
7446 StmtResult ParseStatementOrDeclarationAfterAttributes(
7447 StmtVector &Stmts, ParsedStmtContext StmtCtx,
7452 StmtResult ParseExprStatement(ParsedStmtContext StmtCtx);
7466 ParsedStmtContext StmtCtx);
7475 StmtResult ParseCaseStatement(ParsedStmtContext StmtCtx,
7476 bool MissingCase =
false,
7486 StmtResult ParseDefaultStatement(ParsedStmtContext StmtCtx);
7488 StmtResult ParseCompoundStatement(
bool isStmtExpr =
false);
7514 StmtResult ParseCompoundStatement(
bool isStmtExpr,
unsigned ScopeFlags);
7519 void ParseCompoundStatementLeadingPragmas();
7521 void DiagnoseLabelAtEndOfCompoundStatement();
7531 StmtResult ParseCompoundStatementBody(
bool isStmtExpr =
false);
7549 bool ParseParenExprOrCondition(
StmtResult *InitStmt,
7623 void ParseForRangeInitializerAfterColon(ForRangeInit &FRI,
7669 StmtResult ParseBreakOrContinueStatement(
bool IsContinue);
7703 void ParseMicrosoftIfExistsStatement(
StmtVector &Stmts);
7750 StmtResult ParseCXXCatchBlock(
bool FnCatch =
false);
7788 Decl *ParseFunctionStatementBody(
Decl *
Decl, ParseScope &BodyScope);
7797 Decl *ParseFunctionTryBlock(
Decl *
Decl, ParseScope &BodyScope);
7808 Decl *ParseFunctionBody(
Decl *D, ParseScope &BodyScope);
7814 bool trySkippingFunctionBody();
7822 bool isDeclarationStatement(
bool DisambiguatingWithExpression =
false) {
7824 return isCXXDeclarationStatement(DisambiguatingWithExpression);
7832 bool isForInitDeclaration() {
7836 return Tok.is(tok::kw_using) ||
7837 isCXXSimpleDeclaration(
true);
7842 bool isForRangeIdentifier();
7859 unsigned &NumLineToksConsumed,
7860 bool IsUnevaluated);
7903 StmtResult ParseMicrosoftAsmStatement(SourceLocation AsmLoc);
7919 bool ParseAsmOperandsOpt(SmallVectorImpl<IdentifierInfo *> &Names,
7920 SmallVectorImpl<Expr *> &Constraints,
7921 SmallVectorImpl<Expr *> &Exprs);
7923 class GNUAsmQualifiers {
7924 unsigned Qualifiers = AQ_unspecified;
7933 static const char *getQualifierName(AQ Qualifier);
7934 bool setAsmQualifier(AQ Qualifier);
7935 inline bool isVolatile()
const {
return Qualifiers & AQ_volatile; };
7936 inline bool isInline()
const {
return Qualifiers & AQ_inline; };
7937 inline bool isGoto()
const {
return Qualifiers & AQ_goto; }
7941 bool isGCCAsmStatement(
const Token &TokAfterAsm)
const;
7943 bool isGNUAsmQualifier(
const Token &TokAfterAsm)
const;
7944 GNUAsmQualifiers::AQ getGNUAsmQualifier(
const Token &Tok)
const;
7957 bool parseGNUAsmQualifierListOpt(GNUAsmQualifiers &AQ);
7981 unsigned TemplateParameterDepth;
7984 class TemplateParameterDepthRAII {
7986 unsigned AddedLevels;
7989 explicit TemplateParameterDepthRAII(
unsigned &Depth)
7990 : Depth(Depth), AddedLevels(0) {}
7992 ~TemplateParameterDepthRAII() { Depth -= AddedLevels; }
7998 void addDepth(
unsigned D) {
8002 void setAddedDepth(
unsigned D) {
8003 Depth = Depth - AddedLevels + D;
8007 unsigned getDepth()
const {
return Depth; }
8008 unsigned getOriginalDepth()
const {
return Depth - AddedLevels; }
8013 SmallVector<TemplateIdAnnotation *, 16> TemplateIds;
8019 bool DelayTemplateIdDestruction =
false;
8021 void MaybeDestroyTemplateIds() {
8022 if (DelayTemplateIdDestruction)
8024 if (!TemplateIds.empty() &&
8025 (Tok.is(tok::eof) || !PP.mightHavePendingAnnotationTokens()))
8026 DestroyTemplateIds();
8028 void DestroyTemplateIds();
8032 struct DestroyTemplateIdAnnotationsRAIIObj {
8035 DestroyTemplateIdAnnotationsRAIIObj(
Parser &Self) : Self(Self) {}
8036 ~DestroyTemplateIdAnnotationsRAIIObj() { Self.MaybeDestroyTemplateIds(); }
8039 struct DelayTemplateIdDestructionRAII {
8041 bool PrevDelayTemplateIdDestruction;
8043 DelayTemplateIdDestructionRAII(
Parser &Self,
8044 bool DelayTemplateIdDestruction) noexcept
8046 PrevDelayTemplateIdDestruction(Self.DelayTemplateIdDestruction) {
8047 Self.DelayTemplateIdDestruction = DelayTemplateIdDestruction;
8050 ~DelayTemplateIdDestructionRAII() noexcept {
8051 Self.DelayTemplateIdDestruction = PrevDelayTemplateIdDestruction;
8056 SmallVector<const IdentifierInfo *, 8> TentativelyDeclaredIdentifiers;
8068 struct AngleBracketTracker {
8071 enum Priority :
unsigned short {
8073 PotentialTypo = 0x0,
8075 DependentName = 0x2,
8078 SpaceBeforeLess = 0x0,
8080 NoSpaceBeforeLess = 0x1,
8111 if (!Locs.empty() && Locs.back().isActive(P)) {
8112 if (Locs.back().Priority <= Prio) {
8114 Locs.back().LessLoc = LessLoc;
8115 Locs.back().Priority = Prio;
8118 Locs.push_back({
TemplateName, LessLoc, Prio, P.ParenCount,
8119 P.BracketCount, P.BraceCount});
8127 while (!Locs.empty() && Locs.back().isActiveOrNested(P))
8134 if (!Locs.empty() && Locs.back().isActive(P))
8135 return &Locs.back();
8140 AngleBracketTracker AngleBrackets;
8145 struct ParsedTemplateInfo {
8146 ParsedTemplateInfo()
8150 bool isSpecialization,
8151 bool lastParameterListWasEmpty =
false)
8154 TemplateParams(TemplateParams),
8155 LastParameterListWasEmpty(lastParameterListWasEmpty) {}
8157 explicit ParsedTemplateInfo(SourceLocation ExternLoc,
8158 SourceLocation TemplateLoc)
8160 TemplateParams(
nullptr), ExternLoc(ExternLoc),
8161 TemplateLoc(TemplateLoc), LastParameterListWasEmpty(
false) {}
8171 SourceLocation ExternLoc;
8175 SourceLocation TemplateLoc;
8178 bool LastParameterListWasEmpty;
8180 SourceRange getSourceRange() const LLVM_READONLY;
8184 void LexTemplateFunctionForLateParsing(
CachedTokens &Toks);
8187 void ParseLateTemplatedFuncDef(LateParsedTemplate &LPT);
8189 static
void LateTemplateParserCallback(
void *P, LateParsedTemplate &LPT);
8197 void checkPotentialAngleBracket(
ExprResult &PotentialTemplateName);
8198 bool checkPotentialAngleBracketDelimiter(const AngleBracketTracker::Loc &,
8199 const Token &OpToken);
8200 bool checkPotentialAngleBracketDelimiter(const Token &OpToken) {
8201 if (
auto *Info = AngleBrackets.getCurrent(*
this))
8202 return checkPotentialAngleBracketDelimiter(*Info, OpToken);
8213 SourceLocation &DeclEnd,
8214 ParsedAttributes &AccessAttrs);
8261 ParsingDeclRAIIObject &DiagsFromParams, SourceLocation &DeclEnd,
8273 bool ParseTemplateParameters(MultiParseScope &TemplateScopes,
unsigned Depth,
8274 SmallVectorImpl<NamedDecl *> &TemplateParams,
8275 SourceLocation &LAngleLoc,
8276 SourceLocation &RAngleLoc);
8288 bool ParseTemplateParameterList(
unsigned Depth,
8289 SmallVectorImpl<NamedDecl *> &TemplateParams);
8291 enum class TPResult;
8295 TPResult isStartOfTemplateTypeParameter();
8319 NamedDecl *ParseTemplateParameter(
unsigned Depth,
unsigned Position);
8332 NamedDecl *ParseTypeParameter(
unsigned Depth,
unsigned Position);
8348 NamedDecl *ParseTemplateTemplateParameter(
unsigned Depth,
unsigned Position);
8358 NamedDecl *ParseNonTypeTemplateParameter(
unsigned Depth,
unsigned Position);
8362 bool isTypeConstraintAnnotation();
8374 bool TryAnnotateTypeConstraint();
8376 void DiagnoseMisplacedEllipsis(SourceLocation EllipsisLoc,
8377 SourceLocation CorrectLoc,
8378 bool AlreadyHasEllipsis,
8379 bool IdentifierHasName);
8380 void DiagnoseMisplacedEllipsisInDeclarator(SourceLocation EllipsisLoc,
8383 typedef SmallVector<ParsedTemplateArgument, 16> TemplateArgList;
8400 bool ParseGreaterThanInTemplateList(SourceLocation LAngleLoc,
8401 SourceLocation &RAngleLoc,
8402 bool ConsumeLastToken,
8403 bool ObjCGenericList);
8416 bool ParseTemplateIdAfterTemplateName(
bool ConsumeLastToken,
8417 SourceLocation &LAngleLoc,
8418 TemplateArgList &TemplateArgs,
8419 SourceLocation &RAngleLoc,
8464 CXXScopeSpec &SS, SourceLocation TemplateKWLoc,
8466 bool AllowTypeAnnotation =
true,
8467 bool TypeConstraint =
false);
8485 AnnotateTemplateIdTokenAsType(CXXScopeSpec &SS,
8487 bool IsClassName =
false);
8499 bool ParseTemplateArgumentList(TemplateArgList &TemplateArgs,
8503 ParsedTemplateArgument ParseTemplateTemplateArgument();
8515 ParsedTemplateArgument ParseTemplateArgument();
8527 SourceLocation ExternLoc,
8528 SourceLocation TemplateLoc,
8529 SourceLocation &DeclEnd,
8530 ParsedAttributes &AccessAttrs,
8539 Decl *ParseConceptDefinition(
const ParsedTemplateInfo &TemplateInfo,
8540 SourceLocation &DeclEnd);
8568 class TentativeParsingAction {
8570 PreferredTypeBuilder PrevPreferredType;
8572 size_t PrevTentativelyDeclaredIdentifierCount;
8573 unsigned short PrevParenCount, PrevBracketCount, PrevBraceCount;
8577 explicit TentativeParsingAction(Parser &p,
bool Unannotated =
false)
8578 : P(p), PrevPreferredType(P.PreferredType) {
8580 PrevTentativelyDeclaredIdentifierCount =
8581 P.TentativelyDeclaredIdentifiers.size();
8582 PrevParenCount = P.ParenCount;
8583 PrevBracketCount = P.BracketCount;
8584 PrevBraceCount = P.BraceCount;
8585 P.PP.EnableBacktrackAtThisPos(Unannotated);
8589 assert(isActive &&
"Parsing action was finished!");
8590 P.TentativelyDeclaredIdentifiers.resize(
8591 PrevTentativelyDeclaredIdentifierCount);
8592 P.PP.CommitBacktrackedTokens();
8596 assert(isActive &&
"Parsing action was finished!");
8598 P.PreferredType = PrevPreferredType;
8600 P.TentativelyDeclaredIdentifiers.resize(
8601 PrevTentativelyDeclaredIdentifierCount);
8602 P.ParenCount = PrevParenCount;
8603 P.BracketCount = PrevBracketCount;
8604 P.BraceCount = PrevBraceCount;
8607 ~TentativeParsingAction() {
8608 assert(!isActive &&
"Forgot to call Commit or Revert!");
8614 class RevertingTentativeParsingAction
8615 :
private Parser::TentativeParsingAction {
8617 using TentativeParsingAction::TentativeParsingAction;
8619 ~RevertingTentativeParsingAction() { Revert(); }
8654 bool isCXXDeclarationStatement(
bool DisambiguatingWithExpression =
false);
8680 bool isCXXSimpleDeclaration(
bool AllowForRangeDecl);
8693 bool isCXXFunctionDeclarator(
bool *IsAmbiguous =
nullptr,
8697 struct ConditionDeclarationOrInitStatementState;
8698 enum class ConditionOrInitStatement {
8725 ConditionOrInitStatement
8726 isCXXConditionDeclarationOrInitStatement(
bool CanBeInitStmt,
8727 bool CanBeForRangeDecl);
8753 return isCXXTypeId(Context, isAmbiguous);
8767 bool isEnumBase(
bool AllowSemi);
8887 TPResult BracedCastResult = TPResult::False,
8888 bool *InvalidAsDeclSpec =
nullptr);
8893 bool isCXXDeclarationSpecifierAType();
8899 TPResult isTemplateArgumentList(
unsigned TokensToSkip);
8904 TPResult isExplicitBool();
8909 bool isTentativelyDeclared(IdentifierInfo *II);
8928 TPResult TryParseSimpleDeclaration(
bool AllowForRangeDecl);
8936 TPResult TryParseTypeofSpecifier();
8940 TPResult TryParseProtocolQualifiers();
8942 TPResult TryParsePtrOperatorSeq();
8964 TPResult TryParseOperatorId();
8995 TPResult TryParseInitDeclaratorList(
bool MayHaveTrailingReturnType =
false);
9052 TPResult TryParseDeclarator(
bool mayBeAbstract,
bool mayHaveIdentifier =
true,
9053 bool mayHaveDirectInit =
false,
9054 bool mayHaveTrailingReturnType =
false);
9075 TPResult TryParseParameterDeclarationClause(
9076 bool *InvalidAsDeclaration =
nullptr,
bool VersusTemplateArg =
false,
9093 TPResult TryParseFunctionDeclarator(
bool MayHaveTrailingReturnType =
false);
9099 bool NameAfterArrowIsNonType();
9105 TPResult TryParseBracketDeclarator();
9109 TPResult TryConsumeDeclarationSpecifier();
9113 bool TrySkipAttributes();
9117 bool hasLambdaLikeContinuation();
9159 isCXX11AttributeSpecifier(
bool Disambiguate =
false,
9160 bool OuterMightBeMessageSend =
false);