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);
1550 static void TakeTypeAttrsAppendingFrom(LateParsedAttrList &To,
1551 LateParsedAttrList &From);
1553 void ParseLexedPragmas(ParsingClass &
Class);
1554 void ParseLexedPragma(LateParsedPragma &LP);
1562 bool ConsumeAndStoreFunctionPrologue(
CachedTokens &Toks);
1578 bool ConsumeFinalToken =
true) {
1579 return ConsumeAndStoreUntil(T1, T1, Toks,
StopAtSemi, ConsumeFinalToken);
1590 bool ConsumeFinalToken =
true);
1598 enum class DeclSpecContext {
1603 DSC_alias_declaration,
1608 DSC_template_type_arg,
1609 DSC_objc_method_result,
1618 static bool isTypeSpecifier(DeclSpecContext DSC) {
1620 case DeclSpecContext::DSC_normal:
1621 case DeclSpecContext::DSC_template_param:
1622 case DeclSpecContext::DSC_template_arg:
1623 case DeclSpecContext::DSC_class:
1624 case DeclSpecContext::DSC_top_level:
1625 case DeclSpecContext::DSC_objc_method_result:
1626 case DeclSpecContext::DSC_condition:
1629 case DeclSpecContext::DSC_template_type_arg:
1630 case DeclSpecContext::DSC_type_specifier:
1631 case DeclSpecContext::DSC_conv_operator:
1632 case DeclSpecContext::DSC_trailing:
1633 case DeclSpecContext::DSC_alias_declaration:
1634 case DeclSpecContext::DSC_association:
1635 case DeclSpecContext::DSC_new:
1638 llvm_unreachable(
"Missing DeclSpecContext case");
1642 enum class AllowDefiningTypeSpec {
1659 static AllowDefiningTypeSpec
1660 isDefiningTypeSpecifierContext(DeclSpecContext DSC,
bool IsCPlusPlus) {
1662 case DeclSpecContext::DSC_normal:
1663 case DeclSpecContext::DSC_class:
1664 case DeclSpecContext::DSC_top_level:
1665 case DeclSpecContext::DSC_alias_declaration:
1666 case DeclSpecContext::DSC_objc_method_result:
1667 return AllowDefiningTypeSpec::Yes;
1669 case DeclSpecContext::DSC_condition:
1670 case DeclSpecContext::DSC_template_param:
1671 return AllowDefiningTypeSpec::YesButInvalid;
1673 case DeclSpecContext::DSC_template_type_arg:
1674 case DeclSpecContext::DSC_type_specifier:
1675 return AllowDefiningTypeSpec::NoButErrorRecovery;
1677 case DeclSpecContext::DSC_association:
1678 return IsCPlusPlus ? AllowDefiningTypeSpec::NoButErrorRecovery
1679 : AllowDefiningTypeSpec::Yes;
1681 case DeclSpecContext::DSC_trailing:
1682 case DeclSpecContext::DSC_conv_operator:
1683 case DeclSpecContext::DSC_template_arg:
1684 case DeclSpecContext::DSC_new:
1685 return AllowDefiningTypeSpec::No;
1687 llvm_unreachable(
"Missing DeclSpecContext case");
1691 static bool isOpaqueEnumDeclarationContext(DeclSpecContext DSC) {
1693 case DeclSpecContext::DSC_normal:
1694 case DeclSpecContext::DSC_class:
1695 case DeclSpecContext::DSC_top_level:
1698 case DeclSpecContext::DSC_alias_declaration:
1699 case DeclSpecContext::DSC_objc_method_result:
1700 case DeclSpecContext::DSC_condition:
1701 case DeclSpecContext::DSC_template_param:
1702 case DeclSpecContext::DSC_template_type_arg:
1703 case DeclSpecContext::DSC_type_specifier:
1704 case DeclSpecContext::DSC_trailing:
1705 case DeclSpecContext::DSC_association:
1706 case DeclSpecContext::DSC_conv_operator:
1707 case DeclSpecContext::DSC_template_arg:
1708 case DeclSpecContext::DSC_new:
1712 llvm_unreachable(
"Missing DeclSpecContext case");
1717 static bool isClassTemplateDeductionContext(DeclSpecContext DSC) {
1719 case DeclSpecContext::DSC_normal:
1720 case DeclSpecContext::DSC_template_param:
1721 case DeclSpecContext::DSC_template_arg:
1722 case DeclSpecContext::DSC_class:
1723 case DeclSpecContext::DSC_top_level:
1724 case DeclSpecContext::DSC_condition:
1725 case DeclSpecContext::DSC_type_specifier:
1726 case DeclSpecContext::DSC_association:
1727 case DeclSpecContext::DSC_conv_operator:
1728 case DeclSpecContext::DSC_new:
1731 case DeclSpecContext::DSC_objc_method_result:
1732 case DeclSpecContext::DSC_template_type_arg:
1733 case DeclSpecContext::DSC_trailing:
1734 case DeclSpecContext::DSC_alias_declaration:
1737 llvm_unreachable(
"Missing DeclSpecContext case");
1742 getImplicitTypenameContext(DeclSpecContext DSC) {
1744 case DeclSpecContext::DSC_class:
1745 case DeclSpecContext::DSC_top_level:
1746 case DeclSpecContext::DSC_type_specifier:
1747 case DeclSpecContext::DSC_template_type_arg:
1748 case DeclSpecContext::DSC_trailing:
1749 case DeclSpecContext::DSC_alias_declaration:
1750 case DeclSpecContext::DSC_template_param:
1751 case DeclSpecContext::DSC_new:
1752 case DeclSpecContext::DSC_conv_operator:
1755 case DeclSpecContext::DSC_normal:
1756 case DeclSpecContext::DSC_objc_method_result:
1757 case DeclSpecContext::DSC_condition:
1758 case DeclSpecContext::DSC_template_arg:
1759 case DeclSpecContext::DSC_association:
1762 llvm_unreachable(
"Missing DeclSpecContext case");
1767 struct ForRangeInit {
1768 SourceLocation ColonLoc;
1770 SmallVector<MaterializeTemporaryExpr *, 8> LifetimeExtendTemps;
1771 CXXExpansionStmtDecl *ExpansionStmt =
nullptr;
1772 bool ParsedForRangeDecl() {
return !ColonLoc.
isInvalid(); }
1774 struct ForRangeInfo : ForRangeInit {
1797 SourceLocation &DeclEnd,
1798 ParsedAttributes &DeclAttrs,
1799 ParsedAttributes &DeclSpecAttrs,
1800 SourceLocation *DeclSpecStart =
nullptr);
1827 ParsedAttributes &DeclAttrs,
1828 ParsedAttributes &DeclSpecAttrs,
bool RequireSemi,
1829 ForRangeInit *FRI =
nullptr,
1830 SourceLocation *DeclSpecStart =
nullptr);
1840 ParsedAttributes &Attrs,
1841 ParsedTemplateInfo &TemplateInfo,
1842 SourceLocation *DeclEnd =
nullptr,
1843 ForRangeInit *FRI =
nullptr);
1869 Decl *ParseDeclarationAfterDeclarator(
1871 const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo());
1875 bool ParseAsmAttributesAfterDeclarator(Declarator &D);
1876 Decl *ParseDeclarationAfterDeclaratorAndAttributes(
1878 const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo(),
1879 ForRangeInit *FRI =
nullptr);
1890 bool ParseImplicitInt(DeclSpec &DS, CXXScopeSpec *SS,
1892 DeclSpecContext DSC, ParsedAttributes &Attrs);
1902 ParseDeclarationSpecifiers(DeclSpec &DS, ParsedTemplateInfo &TemplateInfo,
1904 DeclSpecContext DSC = DeclSpecContext::DSC_normal,
1905 LateParsedAttrList *LateAttrs =
nullptr) {
1906 return ParseDeclarationSpecifiers(DS, TemplateInfo, AS, DSC, LateAttrs,
1907 getImplicitTypenameContext(DSC));
1940 ParseDeclarationSpecifiers(DeclSpec &DS, ParsedTemplateInfo &TemplateInfo,
1942 LateParsedAttrList *LateAttrs,
1952 bool DiagnoseMissingSemiAfterTagDefinition(
1954 LateParsedAttrList *LateAttrs =
nullptr);
1958 DeclSpecContext DSC = DeclSpecContext::DSC_normal,
1959 LateParsedAttrList *LateAttrs =
nullptr) {
1960 ParseSpecifierQualifierList(DS, getImplicitTypenameContext(DSC), AS, DSC,
1973 ParseSpecifierQualifierList(DeclSpec &DS,
1976 DeclSpecContext DSC = DeclSpecContext::DSC_normal,
1977 LateParsedAttrList *LateAttrs =
nullptr);
2011 void ParseEnumSpecifier(SourceLocation TagLoc, DeclSpec &DS,
2012 const ParsedTemplateInfo &TemplateInfo,
2027 void ParseEnumBody(SourceLocation StartLoc, Decl *TagDecl,
2028 SkipBodyInfo *SkipBody =
nullptr);
2042 void ParseStructUnionBody(SourceLocation StartLoc,
DeclSpec::TST TagType,
2043 RecordDecl *TagDecl);
2068 void ParseStructDeclaration(
2069 ParsingDeclSpec &DS,
2070 llvm::function_ref<Decl *(ParsingFieldDeclarator &)> FieldsCallback,
2071 LateParsedAttrList *LateFieldAttrs =
nullptr);
2083 bool DisambiguatingWithExpression =
false);
2087 bool isTypeSpecifierQualifier(
const Token &Tok);
2092 bool isKnownToBeTypeSpecifier(
const Token &Tok)
const;
2097 bool isConstructorDeclarator(
2100 const ParsedTemplateInfo *TemplateInfo =
nullptr);
2104 void DiagnoseBitIntUse(
const Token &Tok);
2108 bool CheckProhibitedCXX11Attribute() {
2109 assert(Tok.is(tok::l_square));
2112 return DiagnoseProhibitedCXX11Attribute();
2123 bool DiagnoseProhibitedCXX11Attribute();
2125 void CheckMisplacedCXX11Attribute(ParsedAttributes &Attrs,
2126 SourceLocation CorrectLocation) {
2127 if (!Tok.isRegularKeywordAttribute() &&
2128 (Tok.isNot(tok::l_square) ||
NextToken().
isNot(tok::l_square)) &&
2129 Tok.isNot(tok::kw_alignas))
2131 DiagnoseMisplacedCXX11Attribute(Attrs, CorrectLocation);
2138 void DiagnoseMisplacedCXX11Attribute(ParsedAttributes &Attrs,
2139 SourceLocation CorrectLocation);
2149 void stripTypeAttributesOffDeclSpec(ParsedAttributes &Attrs, DeclSpec &DS,
2153 void ProhibitAttributes(ParsedAttributes &Attrs,
2154 SourceLocation FixItLoc = SourceLocation()) {
2155 if (Attrs.Range.isInvalid())
2157 DiagnoseProhibitedAttributes(Attrs, FixItLoc);
2161 void ProhibitAttributes(ParsedAttributesView &Attrs,
2162 SourceLocation FixItLoc = SourceLocation()) {
2163 if (Attrs.Range.isInvalid())
2165 DiagnoseProhibitedAttributes(Attrs, FixItLoc);
2166 Attrs.clearListOnly();
2168 void DiagnoseProhibitedAttributes(
const ParsedAttributesView &Attrs,
2169 SourceLocation FixItLoc);
2177 void ProhibitCXX11Attributes(ParsedAttributes &Attrs,
unsigned AttrDiagID,
2178 unsigned KeywordDiagId,
2179 bool DiagnoseEmptyAttrs =
false,
2180 bool WarnOnUnknownAttrs =
false);
2184 void DiagnoseCXX11AttributeExtension(ParsedAttributes &Attrs);
2186 ExprResult ParseUnevaluatedStringInAttribute(
const IdentifierInfo &AttrName);
2193 bool ParseAttributeArgumentList(
2194 const IdentifierInfo &AttrName, SmallVectorImpl<Expr *> &Exprs,
2195 ParsedAttributeArgumentsProperties ArgsProperties,
unsigned Arg);
2202 ParseAttributeArgsCommon(IdentifierInfo *AttrName, SourceLocation AttrNameLoc,
2203 ParsedAttributes &Attrs, SourceLocation *EndLoc,
2204 IdentifierInfo *ScopeName, SourceLocation ScopeLoc,
2205 ParsedAttr::Form Form);
2207 enum ParseAttrKindMask {
2209 PAKM_Declspec = 1 << 1,
2210 PAKM_CXX11 = 1 << 2,
2229 void ParseAttributes(
unsigned WhichAttrKinds, ParsedAttributes &Attrs,
2230 LateParsedAttrList *LateAttrs =
nullptr);
2233 bool MaybeParseAttributes(
unsigned WhichAttrKinds, ParsedAttributes &Attrs,
2234 LateParsedAttrList *LateAttrs =
nullptr) {
2235 if (Tok.isOneOf(tok::kw___attribute, tok::kw___declspec) ||
2236 isAllowedCXX11AttributeSpecifier()) {
2237 ParseAttributes(WhichAttrKinds, Attrs, LateAttrs);
2243 void MaybeParseGNUAttributes(Declarator &D,
2244 LateParsedAttrList *LateAttrs =
nullptr) {
2245 if (Tok.is(tok::kw___attribute)) {
2246 ParsedAttributes Attrs(AttrFactory);
2247 ParseGNUAttributes(Attrs, LateAttrs, &D);
2248 D.takeAttributesAppending(Attrs);
2252 bool MaybeParseGNUAttributes(ParsedAttributes &Attrs,
2253 LateParsedAttrList *LateAttrs =
nullptr) {
2254 if (Tok.is(tok::kw___attribute)) {
2255 ParseGNUAttributes(Attrs, LateAttrs);
2277 bool ParseSingleGNUAttribute(ParsedAttributes &Attrs, SourceLocation &EndLoc,
2278 LateParsedAttrList *LateAttrs =
nullptr,
2279 Declarator *D =
nullptr);
2324 void ParseGNUAttributes(ParsedAttributes &Attrs,
2325 LateParsedAttrList *LateAttrs =
nullptr,
2326 Declarator *D =
nullptr);
2330 void ParseGNUAttributeArgs(IdentifierInfo *AttrName,
2331 SourceLocation AttrNameLoc,
2332 ParsedAttributes &Attrs, SourceLocation *EndLoc,
2333 IdentifierInfo *ScopeName, SourceLocation ScopeLoc,
2334 ParsedAttr::Form Form, Declarator *D);
2335 IdentifierLoc *ParseIdentifierLoc();
2338 ParseClangAttributeArgs(IdentifierInfo *AttrName, SourceLocation AttrNameLoc,
2339 ParsedAttributes &Attrs, SourceLocation *EndLoc,
2340 IdentifierInfo *ScopeName, SourceLocation ScopeLoc,
2341 ParsedAttr::Form Form);
2343 void MaybeParseCXX11Attributes(Declarator &D) {
2344 if (isAllowedCXX11AttributeSpecifier()) {
2345 ParsedAttributes Attrs(AttrFactory);
2346 ParseCXX11Attributes(Attrs);
2347 D.takeAttributesAppending(Attrs);
2351 bool MaybeParseCXX11Attributes(ParsedAttributes &Attrs,
2352 bool OuterMightBeMessageSend =
false) {
2353 if (isAllowedCXX11AttributeSpecifier(
false, OuterMightBeMessageSend)) {
2354 ParseCXX11Attributes(Attrs);
2360 bool MaybeParseMicrosoftAttributes(ParsedAttributes &Attrs) {
2361 bool AttrsParsed =
false;
2363 Tok.is(tok::l_square)) {
2364 ParsedAttributes AttrsWithRange(AttrFactory);
2365 ParseMicrosoftAttributes(AttrsWithRange);
2366 AttrsParsed = !AttrsWithRange.empty();
2367 Attrs.takeAllAppendingFrom(AttrsWithRange);
2371 bool MaybeParseMicrosoftDeclSpecs(ParsedAttributes &Attrs) {
2372 if (
getLangOpts().DeclSpecKeyword && Tok.is(tok::kw___declspec)) {
2373 ParseMicrosoftDeclSpecs(Attrs);
2387 void ParseMicrosoftDeclSpecs(ParsedAttributes &Attrs);
2388 bool ParseMicrosoftDeclSpecArgs(IdentifierInfo *AttrName,
2389 SourceLocation AttrNameLoc,
2390 ParsedAttributes &Attrs);
2391 void ParseMicrosoftTypeAttributes(ParsedAttributes &attrs);
2392 void ParseWebAssemblyFuncrefTypeAttribute(ParsedAttributes &Attrs);
2393 void DiagnoseAndSkipExtendedMicrosoftTypeAttributes();
2394 SourceLocation SkipExtendedMicrosoftTypeAttributes();
2396 void ParseBorlandTypeAttributes(ParsedAttributes &attrs);
2397 void ParseOpenCLKernelAttributes(ParsedAttributes &attrs);
2398 void ParseOpenCLQualifiers(ParsedAttributes &Attrs);
2399 void ParseNullabilityTypeSpecifiers(ParsedAttributes &attrs);
2400 void ParseCUDAFunctionAttributes(ParsedAttributes &attrs);
2401 void ParseHLSLQualifiers(ParsedAttributes &Attrs);
2413 VersionTuple ParseVersionTuple(SourceRange &Range);
2442 void ParseAvailabilityAttribute(IdentifierInfo &Availability,
2443 SourceLocation AvailabilityLoc,
2444 ParsedAttributes &attrs,
2445 SourceLocation *endLoc,
2446 IdentifierInfo *ScopeName,
2447 SourceLocation ScopeLoc,
2448 ParsedAttr::Form Form);
2466 void ParseExternalSourceSymbolAttribute(IdentifierInfo &ExternalSourceSymbol,
2468 ParsedAttributes &Attrs,
2469 SourceLocation *EndLoc,
2470 IdentifierInfo *ScopeName,
2471 SourceLocation ScopeLoc,
2472 ParsedAttr::Form Form);
2487 void ParseObjCBridgeRelatedAttribute(IdentifierInfo &ObjCBridgeRelated,
2488 SourceLocation ObjCBridgeRelatedLoc,
2489 ParsedAttributes &Attrs,
2490 SourceLocation *EndLoc,
2491 IdentifierInfo *ScopeName,
2492 SourceLocation ScopeLoc,
2493 ParsedAttr::Form Form);
2495 void ParseSwiftNewTypeAttribute(IdentifierInfo &AttrName,
2496 SourceLocation AttrNameLoc,
2497 ParsedAttributes &Attrs,
2498 SourceLocation *EndLoc,
2499 IdentifierInfo *ScopeName,
2500 SourceLocation ScopeLoc,
2501 ParsedAttr::Form Form);
2503 void ParseTypeTagForDatatypeAttribute(IdentifierInfo &AttrName,
2504 SourceLocation AttrNameLoc,
2505 ParsedAttributes &Attrs,
2506 SourceLocation *EndLoc,
2507 IdentifierInfo *ScopeName,
2508 SourceLocation ScopeLoc,
2509 ParsedAttr::Form Form);
2511 void ParseAttributeWithTypeArg(IdentifierInfo &AttrName,
2512 SourceLocation AttrNameLoc,
2513 ParsedAttributes &Attrs,
2514 IdentifierInfo *ScopeName,
2515 SourceLocation ScopeLoc,
2516 ParsedAttr::Form Form);
2518 void DistributeCLateParsedAttrs(Decl *Dcl, LateParsedAttrList *LateAttrs);
2524 void ParseBoundsAttribute(IdentifierInfo &AttrName,
2525 SourceLocation AttrNameLoc, ParsedAttributes &Attrs,
2526 IdentifierInfo *ScopeName, SourceLocation ScopeLoc,
2527 ParsedAttr::Form Form);
2543 void ParseTypeofSpecifier(DeclSpec &DS);
2550 void ParseAtomicSpecifier(DeclSpec &DS);
2560 ExprResult ParseAlignArgument(StringRef KWName, SourceLocation Start,
2561 SourceLocation &EllipsisLoc,
bool &IsType,
2574 void ParseAlignmentSpecifier(ParsedAttributes &Attrs,
2575 SourceLocation *endLoc =
nullptr);
2584 void ParsePtrauthQualifier(ParsedAttributes &Attrs);
2589 class DeclaratorScopeObj {
2596 DeclaratorScopeObj(
Parser &p, CXXScopeSpec &ss)
2597 : P(p), SS(ss), EnteredScope(
false), CreatedScope(
false) {}
2599 void EnterDeclaratorScope() {
2600 assert(!EnteredScope &&
"Already entered the scope!");
2601 assert(SS.isSet() &&
"C++ scope was not set!");
2603 CreatedScope =
true;
2606 if (!P.Actions.ActOnCXXEnterDeclaratorScope(P.getCurScope(), SS))
2607 EnteredScope =
true;
2610 ~DeclaratorScopeObj() {
2612 assert(SS.isSet() &&
"C++ scope was cleared ?");
2613 P.Actions.ActOnCXXExitDeclaratorScope(P.getCurScope(), SS);
2621 void ParseDeclarator(Declarator &D);
2652 void ParseDeclaratorInternal(Declarator &D,
2653 DirectDeclParseFunction DirectDeclParser);
2655 enum AttrRequirements {
2656 AR_NoAttributesParsed = 0,
2657 AR_GNUAttributesParsedAndRejected = 1 << 0,
2658 AR_GNUAttributesParsed = 1 << 1,
2659 AR_CXX11AttributesParsed = 1 << 2,
2660 AR_DeclspecAttributesParsed = 1 << 3,
2661 AR_AllAttributesParsed = AR_GNUAttributesParsed | AR_CXX11AttributesParsed |
2662 AR_DeclspecAttributesParsed,
2663 AR_VendorAttributesParsed =
2664 AR_GNUAttributesParsed | AR_DeclspecAttributesParsed
2681 void ParseTypeQualifierListOpt(
2682 DeclSpec &DS,
unsigned AttrReqs = AR_AllAttributesParsed,
2683 bool AtomicOrPtrauthAllowed =
true,
bool IdentifierRequired =
false,
2684 llvm::function_ref<
void()> CodeCompletionHandler = {},
2685 LateParsedAttrList *LateAttrs =
nullptr);
2735 void ParseDirectDeclarator(Declarator &D);
2736 void ParseDecompositionDeclarator(Declarator &D);
2754 void ParseParenDeclarator(Declarator &D);
2779 void ParseFunctionDeclarator(Declarator &D, ParsedAttributes &FirstArgAttrs,
2781 bool IsAmbiguous,
bool RequiresArg =
false);
2782 void InitCXXThisScopeForDeclaratorIfRelevant(
2783 const Declarator &D,
const DeclSpec &DS,
2784 std::optional<Sema::CXXThisScopeRAII> &ThisScope);
2788 bool ParseRefQualifier(
bool &RefQualifierIsLValueRef,
2789 SourceLocation &RefQualifierLoc);
2796 bool isFunctionDeclaratorIdentifierList();
2810 void ParseFunctionDeclaratorIdentifierList(
2811 Declarator &D, SmallVectorImpl<DeclaratorChunk::ParamInfo> &ParamInfo);
2812 void ParseParameterDeclarationClause(
2813 Declarator &D, ParsedAttributes &attrs,
2814 SmallVectorImpl<DeclaratorChunk::ParamInfo> &ParamInfo,
2815 SourceLocation &EllipsisLoc) {
2816 return ParseParameterDeclarationClause(
2817 D.getContext(), attrs, ParamInfo, EllipsisLoc,
2818 D.getCXXScopeSpec().isSet() &&
2819 D.isFunctionDeclaratorAFunctionDeclaration());
2857 void ParseParameterDeclarationClause(
2859 SmallVectorImpl<DeclaratorChunk::ParamInfo> &ParamInfo,
2860 SourceLocation &EllipsisLoc,
bool IsACXXFunctionDeclaration =
false);
2871 void ParseBracketDeclarator(Declarator &D);
2874 void ParseMisplacedBracketDeclarator(Declarator &D);
2885 TypeResult ParseTypeFromString(StringRef TypeStr, StringRef Context,
2886 SourceLocation IncludeLoc);
2902 mutable IdentifierInfo *Ident_sealed;
2903 mutable IdentifierInfo *Ident_abstract;
2906 mutable IdentifierInfo *Ident_final;
2907 mutable IdentifierInfo *Ident_GNU_final;
2908 mutable IdentifierInfo *Ident_override;
2913 struct ParsingClass {
2914 ParsingClass(Decl *TagOrTemplate,
bool TopLevelClass,
bool IsInterface)
2915 : TopLevelClass(TopLevelClass), IsInterface(IsInterface),
2916 TagOrTemplate(TagOrTemplate) {}
2920 bool TopLevelClass : 1;
2923 bool IsInterface : 1;
2926 Decl *TagOrTemplate;
2931 LateParsedDeclarationsContainer LateParsedDeclarations;
2937 std::stack<ParsingClass *> ClassStack;
2939 ParsingClass &getCurrentClass() {
2940 assert(!ClassStack.empty() &&
"No lexed method stacks!");
2941 return *ClassStack.top();
2945 class ParsingClassDefinition {
2951 ParsingClassDefinition(
Parser &P, Decl *TagOrTemplate,
bool TopLevelClass,
2953 : P(P), Popped(
false),
2954 State(P.PushParsingClass(TagOrTemplate, TopLevelClass, IsInterface)) {
2959 assert(!Popped &&
"Nested class has already been popped");
2961 P.PopParsingClass(State);
2964 ~ParsingClassDefinition() {
2966 P.PopParsingClass(State);
2982 bool Delayed, SourceRange &SpecificationRange,
2983 SmallVectorImpl<ParsedType> &DynamicExceptions,
2984 SmallVectorImpl<SourceRange> &DynamicExceptionRanges,
3002 ParseDynamicExceptionSpecification(SourceRange &SpecificationRange,
3003 SmallVectorImpl<ParsedType> &Exceptions,
3004 SmallVectorImpl<SourceRange> &Ranges);
3011 TypeResult ParseTrailingReturnType(SourceRange &Range,
3012 bool MayBeFollowedByDirectInit);
3015 void ParseTrailingRequiresClauseWithScope(Declarator &D);
3016 void ParseTrailingRequiresClause(Declarator &D);
3018 void ParseMicrosoftIfExistsClassDeclaration(
DeclSpec::TST TagType,
3019 ParsedAttributes &AccessAttrs,
3022 SourceLocation ParsePackIndexingType(DeclSpec &DS);
3023 void AnnotateExistingIndexedTypeNamePack(
ParsedType T,
3024 SourceLocation StartLoc,
3025 SourceLocation EndLoc);
3030 bool AnnotatePackIndexingTemplateName(CXXScopeSpec &SS, UnqualifiedId &Name,
3039 bool isAllowedCXX11AttributeSpecifier(
bool Disambiguate =
false,
3040 bool OuterMightBeMessageSend =
false) {
3041 return (Tok.isRegularKeywordAttribute() ||
3042 isCXX11AttributeSpecifier(Disambiguate, OuterMightBeMessageSend) !=
3049 SourceLocation SkipCXX11Attributes();
3053 void DiagnoseAndSkipCXX11Attributes();
3055 void ParseOpenMPAttributeArgs(
const IdentifierInfo *AttrName,
3084 void ParseCXX11AttributeSpecifierInternal(ParsedAttributes &Attrs,
3086 SourceLocation *EndLoc =
nullptr);
3087 void ParseCXX11AttributeSpecifier(ParsedAttributes &Attrs,
3088 SourceLocation *EndLoc =
nullptr) {
3090 ParseCXX11AttributeSpecifierInternal(Attrs, OpenMPTokens, EndLoc);
3091 ReplayOpenMPAttributeTokens(OpenMPTokens);
3100 void ParseCXX11Attributes(ParsedAttributes &attrs);
3120 bool ParseCXX11AttributeArgs(IdentifierInfo *AttrName,
3121 SourceLocation AttrNameLoc,
3122 ParsedAttributes &Attrs, SourceLocation *EndLoc,
3123 IdentifierInfo *ScopeName,
3124 SourceLocation ScopeLoc,
3130 ParseCXXAssumeAttributeArg(ParsedAttributes &Attrs, IdentifierInfo *AttrName,
3131 SourceLocation AttrNameLoc,
3132 IdentifierInfo *ScopeName, SourceLocation ScopeLoc,
3133 SourceLocation *EndLoc, ParsedAttr::Form Form);
3144 IdentifierInfo *TryParseCXX11AttributeIdentifier(
3145 SourceLocation &Loc,
3148 const IdentifierInfo *EnclosingScope =
nullptr);
3151 void ParseMicrosoftUuidAttributeArgs(ParsedAttributes &Attrs);
3163 void ParseMicrosoftAttributes(ParsedAttributes &Attrs);
3165 void ParseMicrosoftInheritanceClassAttributes(ParsedAttributes &attrs);
3166 void ParseNullabilityClassAttributes(ParsedAttributes &attrs);
3175 SourceLocation ParseDecltypeSpecifier(DeclSpec &DS);
3176 void AnnotateExistingDecltypeSpecifier(
const DeclSpec &DS,
3177 SourceLocation StartLoc,
3178 SourceLocation EndLoc);
3191 return isCXX11VirtSpecifier(Tok);
3201 void ParseOptionalCXX11VirtSpecifierSeq(VirtSpecifiers &VS,
bool IsInterface,
3202 SourceLocation FriendLoc);
3206 bool isCXX11FinalKeyword()
const;
3212 bool isClassCompatibleKeyword()
const;
3214 bool MaybeParseTypeTransformTypeSpecifier(DeclSpec &DS);
3217 void DiagnoseUnexpectedNamespace(NamedDecl *Context);
3249 SourceLocation &DeclEnd,
3250 SourceLocation InlineLoc = SourceLocation());
3252 struct InnerNamespaceInfo {
3253 SourceLocation NamespaceLoc;
3254 SourceLocation InlineLoc;
3255 SourceLocation IdentLoc;
3256 IdentifierInfo *Ident;
3258 using InnerNamespaceInfoList = llvm::SmallVector<InnerNamespaceInfo, 4>;
3261 void ParseInnerNamespace(
const InnerNamespaceInfoList &InnerNSs,
3262 unsigned int index, SourceLocation &InlineLoc,
3263 ParsedAttributes &attrs,
3295 Decl *ParseExportDeclaration();
3301 SourceLocation &DeclEnd, ParsedAttributes &Attrs);
3316 SourceLocation &DeclEnd, ParsedAttributes &attrs);
3318 struct UsingDeclarator {
3319 SourceLocation TypenameLoc;
3322 SourceLocation EllipsisLoc;
3325 TypenameLoc = EllipsisLoc = SourceLocation();
3366 const ParsedTemplateInfo &TemplateInfo,
3367 SourceLocation UsingLoc,
3368 SourceLocation &DeclEnd,
3369 ParsedAttributes &Attrs,
3371 Decl *ParseAliasDeclarationAfterDeclarator(
3372 const ParsedTemplateInfo &TemplateInfo, SourceLocation UsingLoc,
3374 ParsedAttributes &Attrs, Decl **OwnedType =
nullptr);
3387 Decl *ParseStaticAssertDeclaration(SourceLocation &DeclEnd);
3392 Decl *ParseNamespaceAlias(SourceLocation NamespaceLoc,
3393 SourceLocation AliasLoc, IdentifierInfo *Alias,
3394 SourceLocation &DeclEnd);
3402 bool isValidAfterTypeSpecifier(
bool CouldBeBitfield);
3446 void ParseClassSpecifier(
tok::TokenKind TagTokKind, SourceLocation TagLoc,
3447 DeclSpec &DS, ParsedTemplateInfo &TemplateInfo,
3449 DeclSpecContext DSC, ParsedAttributes &Attributes);
3450 void SkipCXXMemberSpecification(SourceLocation StartLoc,
3451 SourceLocation AttrFixitLoc,
unsigned TagType,
3462 void ParseCXXMemberSpecification(SourceLocation StartLoc,
3463 SourceLocation AttrFixitLoc,
3464 ParsedAttributes &Attrs,
unsigned TagType,
3489 ExprResult ParseCXXMemberInitializer(Decl *D,
bool IsFunction,
3490 SourceLocation &EqualLoc);
3494 bool ParseCXXMemberDeclaratorBeforeInitializer(Declarator &DeclaratorInfo,
3497 LateParsedAttrList &LateAttrs);
3502 MaybeParseAndDiagnoseDeclSpecAfterCXX11VirtSpecifierSeq(Declarator &D,
3503 VirtSpecifiers &VS);
3559 ParsedTemplateInfo &TemplateInfo,
3560 ParsingDeclRAIIObject *DiagsFromTParams =
nullptr);
3563 ParsedAttributes &AccessAttrs,
3589 void ParseConstructorInitializer(Decl *ConstructorDecl);
3611 void HandleMemberFunctionDeclDelays(Declarator &DeclaratorInfo,
3639 TypeResult ParseBaseTypeSpecifier(SourceLocation &BaseLoc,
3640 SourceLocation &EndLocation);
3652 void ParseBaseClause(Decl *ClassDecl);
3667 BaseResult ParseBaseSpecifier(Decl *ClassDecl);
3683 bool isClassCompatibleKeyword(Token Tok)
const;
3685 void ParseHLSLRootSignatureAttributeArgs(ParsedAttributes &Attrs);
3860 bool GreaterThanIsOperator;
3864 llvm::SmallDenseMap<IdentifierInfo *, tok::TokenKind> RevertibleTypeTraits;
3883 PushParsingClass(
Decl *TagOrTemplate,
bool TopLevelClass,
bool IsInterface);
3887 void DeallocateParsedClasses(ParsingClass *
Class);
4108 bool isAddressOfOperand,
bool &NotCastExpr,
4110 bool isVectorLiteral =
false,
4111 bool *NotPrimaryExpression =
nullptr);
4113 bool isAddressOfOperand =
false,
4116 bool isVectorLiteral =
false,
4117 bool *NotPrimaryExpression =
nullptr);
4120 bool isNotExpressionStart();
4124 bool isPostfixExpressionSuffixStart() {
4126 return (K == tok::l_square || K == tok::l_paren || K == tok::period ||
4127 K == tok::arrow || K == tok::plusplus || K == tok::minusminus);
4169 ExprResult ParseUnaryExprOrTypeTraitExpression();
4198 ExprResult ParseSYCLUniqueStableNameExpression();
4260 llvm::function_ref<
void()> ExpressionStarts =
4261 llvm::function_ref<
void()>(),
4262 bool FailImmediatelyOnInvalidExpr =
false,
4263 bool ParsingExpansionStmtInitList =
false);
4308 bool StopIfCastExpr,
4345 ExprResult ParseGenericSelectionExpression();
4364 void injectEmbedTokens();
4390 ExprResult ParseAssignmentExprWithObjCMessageExprStart(
4392 Expr *ReceiverExpr);
4397 bool isKnownToBeDeclarationSpecifier() {
4411 bool isTypeIdForGenericSelection() {
4417 return isTypeSpecifierQualifier(Tok);
4423 bool isTypeIdUnambiguously() {
4428 return isTypeSpecifierQualifier(Tok);
4437 void ParseBlockId(SourceLocation CaretLoc);
4446 std::optional<AvailabilitySpec> ParseAvailabilitySpec();
4447 ExprResult ParseAvailabilityCheckExpr(SourceLocation StartLoc);
4453 bool tryParseOpenMPArrayShapingCastPart();
4455 ExprResult ParseBuiltinPtrauthTypeDiscriminator();
4508 bool ObjectHadErrors,
bool EnteringContext,
4509 bool AllowDestructorName,
bool AllowConstructorName,
4510 bool AllowDeductionGuide,
4511 SourceLocation *TemplateKWLoc, UnqualifiedId &
Result);
4523 bool ParsingGenericAssociationType;
4534 ExprResult tryParseCXXIdExpression(CXXScopeSpec &SS,
bool isAddressOfOperand);
4585 ExprResult ParseCXXIdExpression(
bool isAddressOfOperand =
false);
4588 bool areTokensAdjacent(
const Token &A,
const Token &B);
4592 void CheckForTemplateAndDigraph(Token &
Next,
ParsedType ObjectTypePtr,
4593 bool EnteringContext, IdentifierInfo &II,
4656 bool ParseOptionalCXXScopeSpecifier(
4657 CXXScopeSpec &SS,
ParsedType ObjectType,
bool ObjectHasErrors,
4658 bool EnteringContext,
bool *MayBePseudoDestructor =
nullptr,
4659 bool IsTypename =
false,
const IdentifierInfo **LastII =
nullptr,
4660 bool OnlyNamespace =
false,
bool InUsingDeclaration =
false,
4661 bool Disambiguation =
false,
bool IsAddressOfOperand =
false,
4662 bool IsInDeclarationContext =
false);
4664 bool ParseOptionalCXXScopeSpecifier(CXXScopeSpec &SS,
ParsedType ObjectType,
4665 bool ObjectHasErrors,
4666 bool EnteringContext,
4667 bool IsAddressOfOperand) {
4668 return ParseOptionalCXXScopeSpecifier(
4669 SS, ObjectType, ObjectHasErrors, EnteringContext,
4676 IsAddressOfOperand);
4683 enum class LambdaIntroducerTentativeParse {
4761 ParseLambdaIntroducer(LambdaIntroducer &Intro,
4762 LambdaIntroducerTentativeParse *Tentative =
nullptr);
4766 ExprResult ParseLambdaExpressionAfterIntroducer(LambdaIntroducer &Intro);
4769 bool isLambdaSpecifier();
4853 ExprResult ParseCXXPseudoDestructor(Expr *Base, SourceLocation OpLoc,
4908 ExprResult ParseCXXTypeConstructExpression(
const DeclSpec &DS);
4938 void ParseCXXSimpleTypeSpecifier(DeclSpec &DS);
4953 bool ParseCXXTypeSpecifierSeq(
4971 bool ParseExpressionListOrTypeId(SmallVectorImpl<Expr *> &Exprs,
4983 void ParseDirectNewDeclarator(Declarator &D);
5016 ExprResult ParseCXXNewExpression(
bool UseGlobal, SourceLocation Start);
5031 ExprResult ParseCXXDeleteExpression(
bool UseGlobal, SourceLocation Start);
5071 Sema::ConditionResult ParseCondition(
StmtResult *InitStmt, SourceLocation Loc,
5073 ForRangeInfo *FRI =
nullptr,
5074 bool AfterInitStmt =
false);
5076 ParsedAttributes &Attrs);
5123 bool isTypeIdInParens(
bool &isAmbiguous) {
5126 isAmbiguous =
false;
5127 return isTypeSpecifierQualifier(Tok);
5129 bool isTypeIdInParens() {
5131 return isTypeIdInParens(isAmbiguous);
5169 bool ParseUnqualifiedIdTemplateId(CXXScopeSpec &SS,
ParsedType ObjectType,
5170 bool ObjectHadErrors,
5171 SourceLocation TemplateKWLoc,
5172 IdentifierInfo *Name,
5173 SourceLocation NameLoc,
5174 bool EnteringContext, UnqualifiedId &Id,
5175 bool AssumeTemplateId);
5217 bool ParseUnqualifiedIdOperator(CXXScopeSpec &SS,
bool EnteringContext,
5284 bool MaybeParseHLSLAnnotations(Declarator &D,
5285 SourceLocation *EndLoc =
nullptr,
5286 bool CouldBeBitField =
false) {
5287 assert(
getLangOpts().
HLSL &&
"MaybeParseHLSLAnnotations is for HLSL only");
5288 if (Tok.is(tok::colon)) {
5289 ParsedAttributes Attrs(AttrFactory);
5290 ParseHLSLAnnotations(Attrs, EndLoc, CouldBeBitField);
5291 D.takeAttributesAppending(Attrs);
5297 void MaybeParseHLSLAnnotations(ParsedAttributes &Attrs,
5298 SourceLocation *EndLoc =
nullptr) {
5299 assert(
getLangOpts().
HLSL &&
"MaybeParseHLSLAnnotations is for HLSL only");
5300 if (Tok.is(tok::colon))
5301 ParseHLSLAnnotations(Attrs, EndLoc);
5304 struct ParsedSemantic {
5305 StringRef Name =
"";
5307 bool Explicit =
false;
5310 ParsedSemantic ParseHLSLSemantic();
5312 void ParseHLSLAnnotations(ParsedAttributes &Attrs,
5313 SourceLocation *EndLoc =
nullptr,
5314 bool CouldBeBitField =
false);
5315 Decl *ParseHLSLBuffer(SourceLocation &DeclEnd, ParsedAttributes &Attrs);
5339 ExprResult ParseInitializer(Decl *DeclForInitializer =
nullptr);
5344 bool MayBeDesignationStart();
5372 struct DesignatorCompletionInfo {
5373 SmallVectorImpl<Expr *> &InitExprs;
5374 QualType PreferredBaseType;
5423 ExprResult ParseInitializerWithPotentialDesignator(DesignatorCompletionInfo);
5428 typedef SmallVector<Expr *, 12> ExprVector;
5432 bool ParseMicrosoftIfExistsBraceInitializer(ExprVector &InitExprs,
5449 friend class ObjCDeclContextSwitch;
5452 return Actions.ObjC().getObjCDeclContext();
5458 return Actions.getNullabilityKeyword(nullability);
5474 bool InMessageExpression;
5481 bool ParsingInObjCContainer;
5486 bool isObjCInstancetype() {
5488 if (
Tok.isAnnotation())
5490 if (!Ident_instancetype)
5492 return Tok.getIdentifierInfo() == Ident_instancetype;
5500 ObjCContainerDecl *DC;
5501 SaveAndRestore<bool> WithinObjCContainer;
5506 WithinObjCContainer(P.ParsingInObjCContainer, DC !=
nullptr) {
5508 P.Actions.ObjC().ActOnObjCTemporaryExitContainerContext(DC);
5510 ~ObjCDeclContextSwitch() {
5512 P.Actions.ObjC().ActOnObjCReenterContainerContext(DC);
5516 void CheckNestedObjCContexts(SourceLocation AtLoc);
5518 void ParseLexedObjCMethodDefs(LexedMethod &LM,
bool parseMethod);
5536 DeclGroupPtrTy ParseObjCAtDirectives(ParsedAttributes &DeclAttrs,
5537 ParsedAttributes &DeclSpecAttrs);
5548 DeclGroupPtrTy ParseObjCAtClassDeclaration(SourceLocation atLoc);
5581 Decl *ParseObjCAtInterfaceDeclaration(SourceLocation AtLoc,
5582 ParsedAttributes &prefixAttrs);
5588 ObjCTypeParamList *parseObjCTypeParamList();
5616 ObjCTypeParamList *parseObjCTypeParamListOrProtocolRefs(
5618 SmallVectorImpl<IdentifierLoc> &protocolIdents, SourceLocation &rAngleLoc,
5619 bool mayBeProtocolList =
true);
5621 void HelperActionsForIvarDeclarations(ObjCContainerDecl *interfaceDecl,
5622 SourceLocation atLoc,
5624 SmallVectorImpl<Decl *> &AllIvarDecls,
5625 bool RBraceMissing);
5650 void ParseObjCClassInstanceVariables(ObjCContainerDecl *interfaceDecl,
5652 SourceLocation atLoc);
5659 bool ParseObjCProtocolReferences(
5660 SmallVectorImpl<Decl *> &P, SmallVectorImpl<SourceLocation> &PLocs,
5661 bool WarnOnDeclarations,
bool ForObjCContainer, SourceLocation &LAngleLoc,
5662 SourceLocation &EndProtoLoc,
bool consumeLastToken);
5673 void parseObjCTypeArgsOrProtocolQualifiers(
5674 ParsedType baseType, SourceLocation &typeArgsLAngleLoc,
5675 SmallVectorImpl<ParsedType> &typeArgs, SourceLocation &typeArgsRAngleLoc,
5676 SourceLocation &protocolLAngleLoc, SmallVectorImpl<Decl *> &protocols,
5677 SmallVectorImpl<SourceLocation> &protocolLocs,
5678 SourceLocation &protocolRAngleLoc,
bool consumeLastToken,
5679 bool warnOnIncompleteProtocols);
5683 void parseObjCTypeArgsAndProtocolQualifiers(
5684 ParsedType baseType, SourceLocation &typeArgsLAngleLoc,
5685 SmallVectorImpl<ParsedType> &typeArgs, SourceLocation &typeArgsRAngleLoc,
5686 SourceLocation &protocolLAngleLoc, SmallVectorImpl<Decl *> &protocols,
5687 SmallVectorImpl<SourceLocation> &protocolLocs,
5688 SourceLocation &protocolRAngleLoc,
bool consumeLastToken);
5692 TypeResult parseObjCProtocolQualifierType(SourceLocation &rAngleLoc);
5696 TypeResult parseObjCTypeArgsAndProtocolQualifiers(SourceLocation loc,
5698 bool consumeLastToken,
5699 SourceLocation &endLoc);
5735 DeclGroupPtrTy ParseObjCAtProtocolDeclaration(SourceLocation atLoc,
5736 ParsedAttributes &prefixAttrs);
5738 struct ObjCImplParsingDataRAII {
5742 typedef SmallVector<LexedMethod *, 8> LateParsedObjCMethodContainer;
5743 LateParsedObjCMethodContainer LateParsedObjCMethods;
5745 ObjCImplParsingDataRAII(
Parser &parser, Decl *D)
5746 : P(parser), Dcl(D), HasCFunction(
false),
5747 PrevParsedObjCImpl(parser.CurParsedObjCImpl) {
5748 P.CurParsedObjCImpl =
this;
5751 ~ObjCImplParsingDataRAII();
5753 void finish(SourceRange AtEnd);
5754 bool isFinished()
const {
return Finished; }
5762 ObjCImplParsingDataRAII *PrevParsedObjCImpl;
5765 ObjCImplParsingDataRAII *CurParsedObjCImpl;
5769 void StashAwayMethodOrFunctionBodyTokens(Decl *MDecl);
5783 DeclGroupPtrTy ParseObjCAtImplementationDeclaration(SourceLocation AtLoc,
5784 ParsedAttributes &Attrs);
5792 Decl *ParseObjCAtAliasDeclaration(SourceLocation atLoc);
5807 Decl *ParseObjCPropertySynthesize(SourceLocation atLoc);
5818 Decl *ParseObjCPropertyDynamic(SourceLocation atLoc);
5830 IdentifierInfo *ParseObjCSelectorPiece(SourceLocation &MethodLocation);
5838 bool isTokIdentifier_in()
const;
5847 ParsedAttributes *ParamAttrs);
5861 Decl *ParseObjCMethodPrototype(
5863 bool MethodDefinition =
true);
5895 Decl *ParseObjCMethodDecl(
5898 bool MethodDefinition =
true);
5928 void ParseObjCPropertyAttribute(ObjCDeclSpec &DS);
5934 Decl *ParseObjCMethodDefinition();
5938 ExprResult ParseObjCAtExpression(SourceLocation AtLocation);
5939 ExprResult ParseObjCStringLiteral(SourceLocation AtLoc);
5946 ExprResult ParseObjCCharacterLiteral(SourceLocation AtLoc);
5955 ExprResult ParseObjCNumericLiteral(SourceLocation AtLoc);
5964 ExprResult ParseObjCBooleanLiteral(SourceLocation AtLoc,
bool ArgValue);
5966 ExprResult ParseObjCArrayLiteral(SourceLocation AtLoc);
5967 ExprResult ParseObjCDictionaryLiteral(SourceLocation AtLoc);
5974 ExprResult ParseObjCBoxedExpr(SourceLocation AtLoc);
5980 ExprResult ParseObjCEncodeExpression(SourceLocation AtLoc);
5986 ExprResult ParseObjCSelectorExpression(SourceLocation AtLoc);
5992 ExprResult ParseObjCProtocolExpression(SourceLocation AtLoc);
5999 bool isSimpleObjCMessageExpression();
6054 ExprResult ParseObjCMessageExpressionBody(SourceLocation LBracloc,
6055 SourceLocation SuperLoc,
6057 Expr *ReceiverExpr);
6083 bool ParseObjCXXMessageReceiver(
bool &IsExpr,
void *&TypeOrExpr);
6088 enum class ParsedStmtContext;
6090 StmtResult ParseObjCAtStatement(SourceLocation atLoc,
6091 ParsedStmtContext StmtCtx);
6106 StmtResult ParseObjCTryStmt(SourceLocation atLoc);
6113 StmtResult ParseObjCThrowStmt(SourceLocation atLoc);
6120 StmtResult ParseObjCSynchronizedStmt(SourceLocation atLoc);
6127 StmtResult ParseObjCAutoreleasePoolStmt(SourceLocation atLoc);
6154 bool isStartOfObjCClassMessageMissingOpenBracket();
6186 bool OpenACCDirectiveParsing =
false;
6190 bool AllowOpenACCArraySections =
false;
6194 class OpenACCArraySectionRAII {
6198 OpenACCArraySectionRAII(
Parser &P) : P(P) {
6199 assert(!P.AllowOpenACCArraySections);
6200 P.AllowOpenACCArraySections =
true;
6202 ~OpenACCArraySectionRAII() {
6203 assert(P.AllowOpenACCArraySections);
6204 P.AllowOpenACCArraySections =
false;
6211 struct OpenACCDirectiveParseInfo {
6213 SourceLocation StartLoc;
6214 SourceLocation DirLoc;
6215 SourceLocation LParenLoc;
6216 SourceLocation RParenLoc;
6217 SourceLocation EndLoc;
6218 SourceLocation MiscLoc;
6220 SmallVector<Expr *> Exprs;
6221 SmallVector<OpenACCClause *> Clauses;
6226 struct OpenACCWaitParseInfo {
6227 bool Failed =
false;
6228 Expr *DevNumExpr =
nullptr;
6229 SourceLocation QueuesLoc;
6230 SmallVector<Expr *> QueueIdExprs;
6232 SmallVector<Expr *> getAllExprs() {
6233 SmallVector<Expr *>
Out;
6234 Out.push_back(DevNumExpr);
6235 llvm::append_range(Out, QueueIdExprs);
6239 struct OpenACCCacheParseInfo {
6240 bool Failed =
false;
6241 SourceLocation ReadOnlyLoc;
6242 SmallVector<Expr *> Vars;
6247 enum class OpenACCParseCanContinue { Cannot = 0, Can = 1 };
6253 using OpenACCClauseParseResult =
6254 llvm::PointerIntPair<OpenACCClause *, 1, OpenACCParseCanContinue>;
6256 OpenACCClauseParseResult OpenACCCanContinue();
6257 OpenACCClauseParseResult OpenACCCannotContinue();
6258 OpenACCClauseParseResult OpenACCSuccess(OpenACCClause *Clause);
6262 OpenACCDirectiveParseInfo ParseOpenACCDirective();
6272 OpenACCCacheParseInfo ParseOpenACCCacheVarList();
6278 using OpenACCVarParseResult = std::pair<ExprResult, OpenACCParseCanContinue>;
6304 OpenACCClauseParseResult
6305 ParseOpenACCClauseParams(ArrayRef<const OpenACCClause *> ExistingClauses,
6307 SourceLocation ClauseLoc);
6311 OpenACCClauseParseResult
6312 ParseOpenACCClause(ArrayRef<const OpenACCClause *> ExistingClauses,
6322 SmallVector<OpenACCClause *>
6331 OpenACCWaitParseInfo ParseOpenACCWaitArgument(SourceLocation Loc,
6336 std::variant<std::monostate, StringLiteral *, IdentifierInfo *>
6337 ParseOpenACCBindClauseArgument();
6342 using OpenACCIntExprParseResult =
6343 std::pair<ExprResult, OpenACCParseCanContinue>;
6348 SourceLocation Loc);
6353 llvm::SmallVectorImpl<Expr *> &IntExprs);
6366 bool ParseOpenACCDeviceTypeList(llvm::SmallVector<IdentifierLoc> &Archs);
6380 SourceLocation Loc);
6395 llvm::SmallVectorImpl<Expr *> &SizeExprs);
6407 bool ParseOpenACCGangArgList(SourceLocation GangLoc,
6408 llvm::SmallVectorImpl<OpenACCGangKind> &GKs,
6409 llvm::SmallVectorImpl<Expr *> &IntExprs);
6411 using OpenACCGangArgRes = std::pair<OpenACCGangKind, ExprResult>;
6415 OpenACCGangArgRes ParseOpenACCGangArg(SourceLocation GangLoc);
6419 ParseOpenACCAfterRoutineDecl(
AccessSpecifier &AS, ParsedAttributes &Attrs,
6421 OpenACCDirectiveParseInfo &DirInfo);
6422 StmtResult ParseOpenACCAfterRoutineStmt(OpenACCDirectiveParseInfo &DirInfo);
6440 bool OpenMPDirectiveParsing =
false;
6445 void ReplayOpenMPAttributeTokens(
CachedTokens &OpenMPTokens) {
6448 if (!OpenMPTokens.empty()) {
6449 PP.EnterToken(Tok,
true);
6450 PP.EnterTokenStream(OpenMPTokens,
true,
6462 SourceLocation Loc);
6467 llvm::omp::TraitSet
Set,
6468 llvm::omp::TraitSelector Selector,
6469 llvm::StringMap<SourceLocation> &Seen);
6473 llvm::omp::TraitSet
Set,
6474 llvm::StringMap<SourceLocation> &Seen);
6478 llvm::StringMap<SourceLocation> &Seen);
6482 llvm::omp::TraitSet
Set,
6483 llvm::StringMap<SourceLocation> &Seen);
6491 llvm::omp::TraitSet
Set,
6492 llvm::StringMap<SourceLocation> &SeenSelectors);
6499 void parseOMPContextSelectorSet(
OMPTraitSet &TISet,
6500 llvm::StringMap<SourceLocation> &SeenSets);
6507 bool parseOMPContextSelectors(SourceLocation Loc,
OMPTraitInfo &TI);
6510 bool parseOpenMPAppendArgs(SmallVectorImpl<OMPInteropInfo> &InteropInfos);
6514 bool parseOMPDeclareVariantMatchClause(SourceLocation Loc,
OMPTraitInfo &TI,
6520 SourceLocation Loc);
6539 void ParseOpenMPAssumesDirective(OpenMPDirectiveKind DKind,
6540 SourceLocation Loc);
6543 void ParseOpenMPEndAssumesDirective(SourceLocation Loc);
6560 void ParseOpenMPClauses(OpenMPDirectiveKind DKind,
6561 SmallVectorImpl<clang::OMPClause *> &Clauses,
6562 SourceLocation Loc);
6565 void ParseOMPDeclareTargetClauses(SemaOpenMP::DeclareTargetContextInfo &DTCI);
6568 void ParseOMPEndDeclareTargetDirective(OpenMPDirectiveKind BeginDKind,
6569 OpenMPDirectiveKind EndDKind,
6570 SourceLocation Loc);
6574 void skipUntilPragmaOpenMPEnd(OpenMPDirectiveKind DKind);
6580 void parseOMPEndDirective(OpenMPDirectiveKind BeginKind,
6581 OpenMPDirectiveKind ExpectedKind,
6582 OpenMPDirectiveKind FoundKind,
6583 SourceLocation MatchingLoc, SourceLocation FoundLoc,
6584 bool SkipUntilOpenMPEnd);
6625 AccessSpecifier &AS, ParsedAttributes &Attrs,
bool Delayed =
false,
6627 Decl *TagDecl =
nullptr);
6641 DeclGroupPtrTy ParseOpenMPDeclareReductionDirective(AccessSpecifier AS);
6645 void ParseOpenMPReductionInitializerForDecl(VarDecl *OmpPrivParm);
6657 DeclGroupPtrTy ParseOpenMPDeclareMapperDirective(AccessSpecifier AS);
6660 TypeResult parseOpenMPDeclareMapperVarDecl(SourceRange &Range,
6661 DeclarationName &Name,
6662 AccessSpecifier AS =
AS_none);
6676 bool ParseOpenMPSimpleVarList(
6677 OpenMPDirectiveKind Kind,
6678 const llvm::function_ref<
void(CXXScopeSpec &, DeclarationNameInfo)>
6680 bool AllowScopeSpecifier);
6729 StmtResult ParseOpenMPDeclarativeOrExecutableDirective(
6730 ParsedStmtContext StmtCtx,
bool ReadDirectiveWithinMetadirective =
false);
6740 ParseOpenMPExecutableDirective(ParsedStmtContext StmtCtx,
6741 OpenMPDirectiveKind DKind, SourceLocation Loc,
6742 bool ReadDirectiveWithinMetadirective);
6751 StmtResult ParseOpenMPInformationalDirective(
6752 ParsedStmtContext StmtCtx, OpenMPDirectiveKind DKind, SourceLocation Loc,
6753 bool ReadDirectiveWithinMetadirective);
6782 OMPClause *ParseOpenMPClause(OpenMPDirectiveKind DKind,
6867 bool ParseOpenMPIndirectClause(SemaOpenMP::DeclareTargetContextInfo &DTCI,
6892 OMPClause *ParseOpenMPSingleExprWithArgClause(OpenMPDirectiveKind DKind,
6897 OMPClause *ParseOpenMPLoopRangeClause();
6906 OMPClause *ParseOpenMPPermutationClause();
7010 OMPClause *ParseOpenMPVarListClause(OpenMPDirectiveKind DKind,
7024 SourceLocation &ClauseNameLoc,
7025 SourceLocation &OpenLoc,
7026 SourceLocation &CloseLoc,
7027 SmallVectorImpl<Expr *> &Exprs,
7028 bool ReqIntConst =
false);
7043 OMPClause *ParseOpenMPUsesAllocatorClause(OpenMPDirectiveKind DKind);
7046 bool ParseOMPInteropInfo(OMPInteropInfo &InteropInfo,
OpenMPClauseKind Kind);
7052 bool ParseOMPInteropAttrSelector(SmallVectorImpl<Expr *> &Attrs);
7090 OMPClause *ParseOpenMPOMPXAttributesClause(
bool ParseOnly);
7097 bool IsAddressOfOperand =
false);
7101 SemaOpenMP::OpenMPVarListDataTy &
Data,
7102 const LangOptions &LangOpts);
7116 SmallVectorImpl<Expr *> &Vars,
7117 SemaOpenMP::OpenMPVarListDataTy &
Data,
7118 SmallVectorImpl<OMPAdjustArgsItem> &AdjustArgsItems);
7153 std::unique_ptr<PragmaHandler> AlignHandler;
7154 std::unique_ptr<PragmaHandler> GCCVisibilityHandler;
7155 std::unique_ptr<PragmaHandler> OptionsHandler;
7156 std::unique_ptr<PragmaHandler> PackHandler;
7157 std::unique_ptr<PragmaHandler> MSStructHandler;
7158 std::unique_ptr<PragmaHandler> UnusedHandler;
7159 std::unique_ptr<PragmaHandler> WeakHandler;
7160 std::unique_ptr<PragmaHandler> RedefineExtnameHandler;
7161 std::unique_ptr<PragmaHandler> FPContractHandler;
7162 std::unique_ptr<PragmaHandler> OpenCLExtensionHandler;
7163 std::unique_ptr<PragmaHandler> OpenMPHandler;
7164 std::unique_ptr<PragmaHandler> OpenACCHandler;
7165 std::unique_ptr<PragmaHandler> PCSectionHandler;
7166 std::unique_ptr<PragmaHandler> MSCommentHandler;
7167 std::unique_ptr<PragmaHandler> MSDetectMismatchHandler;
7168 std::unique_ptr<PragmaHandler> FPEvalMethodHandler;
7169 std::unique_ptr<PragmaHandler> FloatControlHandler;
7170 std::unique_ptr<PragmaHandler> MSPointersToMembers;
7171 std::unique_ptr<PragmaHandler> MSVtorDisp;
7172 std::unique_ptr<PragmaHandler> MSInitSeg;
7173 std::unique_ptr<PragmaHandler> MSDataSeg;
7174 std::unique_ptr<PragmaHandler> MSBSSSeg;
7175 std::unique_ptr<PragmaHandler> MSConstSeg;
7176 std::unique_ptr<PragmaHandler> MSCodeSeg;
7177 std::unique_ptr<PragmaHandler> MSSection;
7178 std::unique_ptr<PragmaHandler> MSStrictGuardStackCheck;
7179 std::unique_ptr<PragmaHandler> MSRuntimeChecks;
7180 std::unique_ptr<PragmaHandler> MSIntrinsic;
7181 std::unique_ptr<PragmaHandler> MSFunction;
7182 std::unique_ptr<PragmaHandler> MSOptimize;
7183 std::unique_ptr<PragmaHandler> MSFenvAccess;
7184 std::unique_ptr<PragmaHandler> MSAllocText;
7185 std::unique_ptr<PragmaHandler> CUDAForceHostDeviceHandler;
7186 std::unique_ptr<PragmaHandler> OptimizeHandler;
7187 std::unique_ptr<PragmaHandler> LoopHintHandler;
7188 std::unique_ptr<PragmaHandler> UnrollHintHandler;
7189 std::unique_ptr<PragmaHandler> NoUnrollHintHandler;
7190 std::unique_ptr<PragmaHandler> UnrollAndJamHintHandler;
7191 std::unique_ptr<PragmaHandler> NoUnrollAndJamHintHandler;
7192 std::unique_ptr<PragmaHandler> FPHandler;
7193 std::unique_ptr<PragmaHandler> STDCFenvAccessHandler;
7194 std::unique_ptr<PragmaHandler> STDCFenvRoundHandler;
7195 std::unique_ptr<PragmaHandler> STDCCXLIMITHandler;
7196 std::unique_ptr<PragmaHandler> STDCUnknownHandler;
7197 std::unique_ptr<PragmaHandler> AttributePragmaHandler;
7198 std::unique_ptr<PragmaHandler> MaxTokensHerePragmaHandler;
7199 std::unique_ptr<PragmaHandler> MaxTokensTotalPragmaHandler;
7200 std::unique_ptr<PragmaHandler> ExportHandler;
7201 std::unique_ptr<PragmaHandler> RISCVPragmaHandler;
7204 void initializePragmaHandlers();
7207 void resetPragmaHandlers();
7214 void HandlePragmaUnused();
7218 void HandlePragmaVisibility();
7222 void HandlePragmaPack();
7226 void HandlePragmaMSStruct();
7228 void HandlePragmaMSPointersToMembers();
7230 void HandlePragmaMSVtorDisp();
7232 void HandlePragmaMSPragma();
7233 bool HandlePragmaMSSection(StringRef PragmaName,
7234 SourceLocation PragmaLocation);
7235 bool HandlePragmaMSSegment(StringRef PragmaName,
7236 SourceLocation PragmaLocation);
7239 bool HandlePragmaMSInitSeg(StringRef PragmaName,
7240 SourceLocation PragmaLocation);
7245 bool HandlePragmaMSStrictGuardStackCheck(StringRef PragmaName,
7246 SourceLocation PragmaLocation);
7247 bool HandlePragmaMSFunction(StringRef PragmaName,
7248 SourceLocation PragmaLocation);
7249 bool HandlePragmaMSAllocText(StringRef PragmaName,
7250 SourceLocation PragmaLocation);
7253 bool HandlePragmaMSOptimize(StringRef PragmaName,
7254 SourceLocation PragmaLocation);
7257 bool HandlePragmaMSIntrinsic(StringRef PragmaName,
7258 SourceLocation PragmaLocation);
7262 void HandlePragmaAlign();
7266 void HandlePragmaDump();
7270 void HandlePragmaWeak();
7274 void HandlePragmaWeakAlias();
7278 void HandlePragmaRedefineExtname();
7282 void HandlePragmaFPContract();
7286 void HandlePragmaFEnvAccess();
7290 void HandlePragmaFEnvRound();
7294 void HandlePragmaCXLimitedRange();
7298 void HandlePragmaFloatControl();
7302 void HandlePragmaFP();
7306 void HandlePragmaOpenCLExtension();
7310 StmtResult HandlePragmaCaptured();
7314 bool HandlePragmaLoopHint(LoopHint &Hint);
7316 bool ParsePragmaAttributeSubjectMatchRuleSet(
7318 SourceLocation &AnyLoc, SourceLocation &LastMatchRuleEndLoc);
7320 void HandlePragmaAttribute();
7326 void HandlePragmaExport();
7352 enum class ParsedStmtContext {
7355 AllowDeclarationsInC = 0x1,
7357 AllowStandaloneOpenMPDirectives = 0x2,
7364 Compound = AllowDeclarationsInC | AllowStandaloneOpenMPDirectives,
7366 LLVM_MARK_AS_BITMASK_ENUM(InStmtExpr)
7381 ParsedStmtContext StmtCtx = ParsedStmtContext::SubStmt,
7436 ParseStatementOrDeclaration(
StmtVector &Stmts, ParsedStmtContext StmtCtx,
7440 StmtResult ParseStatementOrDeclarationAfterAttributes(
7441 StmtVector &Stmts, ParsedStmtContext StmtCtx,
7446 StmtResult ParseExprStatement(ParsedStmtContext StmtCtx);
7460 ParsedStmtContext StmtCtx);
7469 StmtResult ParseCaseStatement(ParsedStmtContext StmtCtx,
7470 bool MissingCase =
false,
7480 StmtResult ParseDefaultStatement(ParsedStmtContext StmtCtx);
7482 StmtResult ParseCompoundStatement(
bool isStmtExpr =
false);
7508 StmtResult ParseCompoundStatement(
bool isStmtExpr,
unsigned ScopeFlags);
7513 void ParseCompoundStatementLeadingPragmas();
7515 void DiagnoseLabelAtEndOfCompoundStatement();
7525 StmtResult ParseCompoundStatementBody(
bool isStmtExpr =
false);
7543 bool ParseParenExprOrCondition(
StmtResult *InitStmt,
7617 void ParseForRangeInitializerAfterColon(ForRangeInit &FRI,
7663 StmtResult ParseBreakOrContinueStatement(
bool IsContinue);
7697 void ParseMicrosoftIfExistsStatement(
StmtVector &Stmts);
7744 StmtResult ParseCXXCatchBlock(
bool FnCatch =
false);
7782 Decl *ParseFunctionStatementBody(
Decl *
Decl, ParseScope &BodyScope);
7791 Decl *ParseFunctionTryBlock(
Decl *
Decl, ParseScope &BodyScope);
7802 Decl *ParseFunctionBody(
Decl *D, ParseScope &BodyScope);
7808 bool trySkippingFunctionBody();
7816 bool isDeclarationStatement(
bool DisambiguatingWithExpression =
false) {
7818 return isCXXDeclarationStatement(DisambiguatingWithExpression);
7826 bool isForInitDeclaration() {
7830 return Tok.is(tok::kw_using) ||
7831 isCXXSimpleDeclaration(
true);
7836 bool isForRangeIdentifier();
7853 unsigned &NumLineToksConsumed,
7854 bool IsUnevaluated);
7897 StmtResult ParseMicrosoftAsmStatement(SourceLocation AsmLoc);
7913 bool ParseAsmOperandsOpt(SmallVectorImpl<IdentifierInfo *> &Names,
7914 SmallVectorImpl<Expr *> &Constraints,
7915 SmallVectorImpl<Expr *> &Exprs);
7917 class GNUAsmQualifiers {
7918 unsigned Qualifiers = AQ_unspecified;
7927 static const char *getQualifierName(AQ Qualifier);
7928 bool setAsmQualifier(AQ Qualifier);
7929 inline bool isVolatile()
const {
return Qualifiers & AQ_volatile; };
7930 inline bool isInline()
const {
return Qualifiers & AQ_inline; };
7931 inline bool isGoto()
const {
return Qualifiers & AQ_goto; }
7935 bool isGCCAsmStatement(
const Token &TokAfterAsm)
const;
7937 bool isGNUAsmQualifier(
const Token &TokAfterAsm)
const;
7938 GNUAsmQualifiers::AQ getGNUAsmQualifier(
const Token &Tok)
const;
7951 bool parseGNUAsmQualifierListOpt(GNUAsmQualifiers &AQ);
7975 unsigned TemplateParameterDepth;
7978 class TemplateParameterDepthRAII {
7980 unsigned AddedLevels;
7983 explicit TemplateParameterDepthRAII(
unsigned &Depth)
7984 : Depth(Depth), AddedLevels(0) {}
7986 ~TemplateParameterDepthRAII() { Depth -= AddedLevels; }
7992 void addDepth(
unsigned D) {
7996 void setAddedDepth(
unsigned D) {
7997 Depth = Depth - AddedLevels + D;
8001 unsigned getDepth()
const {
return Depth; }
8002 unsigned getOriginalDepth()
const {
return Depth - AddedLevels; }
8007 SmallVector<TemplateIdAnnotation *, 16> TemplateIds;
8013 bool DelayTemplateIdDestruction =
false;
8015 void MaybeDestroyTemplateIds() {
8016 if (DelayTemplateIdDestruction)
8018 if (!TemplateIds.empty() &&
8019 (Tok.is(tok::eof) || !PP.mightHavePendingAnnotationTokens()))
8020 DestroyTemplateIds();
8022 void DestroyTemplateIds();
8026 struct DestroyTemplateIdAnnotationsRAIIObj {
8029 DestroyTemplateIdAnnotationsRAIIObj(
Parser &Self) : Self(Self) {}
8030 ~DestroyTemplateIdAnnotationsRAIIObj() { Self.MaybeDestroyTemplateIds(); }
8033 struct DelayTemplateIdDestructionRAII {
8035 bool PrevDelayTemplateIdDestruction;
8037 DelayTemplateIdDestructionRAII(
Parser &Self,
8038 bool DelayTemplateIdDestruction) noexcept
8040 PrevDelayTemplateIdDestruction(Self.DelayTemplateIdDestruction) {
8041 Self.DelayTemplateIdDestruction = DelayTemplateIdDestruction;
8044 ~DelayTemplateIdDestructionRAII() noexcept {
8045 Self.DelayTemplateIdDestruction = PrevDelayTemplateIdDestruction;
8050 SmallVector<const IdentifierInfo *, 8> TentativelyDeclaredIdentifiers;
8062 struct AngleBracketTracker {
8065 enum Priority :
unsigned short {
8067 PotentialTypo = 0x0,
8069 DependentName = 0x2,
8072 SpaceBeforeLess = 0x0,
8074 NoSpaceBeforeLess = 0x1,
8105 if (!Locs.empty() && Locs.back().isActive(P)) {
8106 if (Locs.back().Priority <= Prio) {
8108 Locs.back().LessLoc = LessLoc;
8109 Locs.back().Priority = Prio;
8112 Locs.push_back({
TemplateName, LessLoc, Prio, P.ParenCount,
8113 P.BracketCount, P.BraceCount});
8121 while (!Locs.empty() && Locs.back().isActiveOrNested(P))
8128 if (!Locs.empty() && Locs.back().isActive(P))
8129 return &Locs.back();
8134 AngleBracketTracker AngleBrackets;
8139 struct ParsedTemplateInfo {
8140 ParsedTemplateInfo()
8144 bool isSpecialization,
8145 bool lastParameterListWasEmpty =
false)
8148 TemplateParams(TemplateParams),
8149 LastParameterListWasEmpty(lastParameterListWasEmpty) {}
8151 explicit ParsedTemplateInfo(SourceLocation ExternLoc,
8152 SourceLocation TemplateLoc)
8154 TemplateParams(
nullptr), ExternLoc(ExternLoc),
8155 TemplateLoc(TemplateLoc), LastParameterListWasEmpty(
false) {}
8165 SourceLocation ExternLoc;
8169 SourceLocation TemplateLoc;
8172 bool LastParameterListWasEmpty;
8174 SourceRange getSourceRange() const LLVM_READONLY;
8178 void LexTemplateFunctionForLateParsing(
CachedTokens &Toks);
8181 void ParseLateTemplatedFuncDef(LateParsedTemplate &LPT);
8183 static
void LateTemplateParserCallback(
void *P, LateParsedTemplate &LPT);
8191 void checkPotentialAngleBracket(
ExprResult &PotentialTemplateName);
8192 bool checkPotentialAngleBracketDelimiter(const AngleBracketTracker::Loc &,
8193 const Token &OpToken);
8194 bool checkPotentialAngleBracketDelimiter(const Token &OpToken) {
8195 if (
auto *Info = AngleBrackets.getCurrent(*
this))
8196 return checkPotentialAngleBracketDelimiter(*Info, OpToken);
8207 SourceLocation &DeclEnd,
8208 ParsedAttributes &AccessAttrs);
8255 ParsingDeclRAIIObject &DiagsFromParams, SourceLocation &DeclEnd,
8267 bool ParseTemplateParameters(MultiParseScope &TemplateScopes,
unsigned Depth,
8268 SmallVectorImpl<NamedDecl *> &TemplateParams,
8269 SourceLocation &LAngleLoc,
8270 SourceLocation &RAngleLoc);
8282 bool ParseTemplateParameterList(
unsigned Depth,
8283 SmallVectorImpl<NamedDecl *> &TemplateParams);
8285 enum class TPResult;
8289 TPResult isStartOfTemplateTypeParameter();
8313 NamedDecl *ParseTemplateParameter(
unsigned Depth,
unsigned Position);
8326 NamedDecl *ParseTypeParameter(
unsigned Depth,
unsigned Position);
8342 NamedDecl *ParseTemplateTemplateParameter(
unsigned Depth,
unsigned Position);
8352 NamedDecl *ParseNonTypeTemplateParameter(
unsigned Depth,
unsigned Position);
8356 bool isTypeConstraintAnnotation();
8368 bool TryAnnotateTypeConstraint();
8370 void DiagnoseMisplacedEllipsis(SourceLocation EllipsisLoc,
8371 SourceLocation CorrectLoc,
8372 bool AlreadyHasEllipsis,
8373 bool IdentifierHasName);
8374 void DiagnoseMisplacedEllipsisInDeclarator(SourceLocation EllipsisLoc,
8377 typedef SmallVector<ParsedTemplateArgument, 16> TemplateArgList;
8394 bool ParseGreaterThanInTemplateList(SourceLocation LAngleLoc,
8395 SourceLocation &RAngleLoc,
8396 bool ConsumeLastToken,
8397 bool ObjCGenericList);
8410 bool ParseTemplateIdAfterTemplateName(
bool ConsumeLastToken,
8411 SourceLocation &LAngleLoc,
8412 TemplateArgList &TemplateArgs,
8413 SourceLocation &RAngleLoc,
8458 CXXScopeSpec &SS, SourceLocation TemplateKWLoc,
8460 bool AllowTypeAnnotation =
true,
8461 bool TypeConstraint =
false);
8479 AnnotateTemplateIdTokenAsType(CXXScopeSpec &SS,
8481 bool IsClassName =
false);
8493 bool ParseTemplateArgumentList(TemplateArgList &TemplateArgs,
8497 ParsedTemplateArgument ParseTemplateTemplateArgument();
8509 ParsedTemplateArgument ParseTemplateArgument();
8521 SourceLocation ExternLoc,
8522 SourceLocation TemplateLoc,
8523 SourceLocation &DeclEnd,
8524 ParsedAttributes &AccessAttrs,
8533 Decl *ParseConceptDefinition(
const ParsedTemplateInfo &TemplateInfo,
8534 SourceLocation &DeclEnd);
8562 class TentativeParsingAction {
8564 PreferredTypeBuilder PrevPreferredType;
8566 size_t PrevTentativelyDeclaredIdentifierCount;
8567 unsigned short PrevParenCount, PrevBracketCount, PrevBraceCount;
8571 explicit TentativeParsingAction(Parser &p,
bool Unannotated =
false)
8572 : P(p), PrevPreferredType(P.PreferredType) {
8574 PrevTentativelyDeclaredIdentifierCount =
8575 P.TentativelyDeclaredIdentifiers.size();
8576 PrevParenCount = P.ParenCount;
8577 PrevBracketCount = P.BracketCount;
8578 PrevBraceCount = P.BraceCount;
8579 P.PP.EnableBacktrackAtThisPos(Unannotated);
8583 assert(isActive &&
"Parsing action was finished!");
8584 P.TentativelyDeclaredIdentifiers.resize(
8585 PrevTentativelyDeclaredIdentifierCount);
8586 P.PP.CommitBacktrackedTokens();
8590 assert(isActive &&
"Parsing action was finished!");
8592 P.PreferredType = PrevPreferredType;
8594 P.TentativelyDeclaredIdentifiers.resize(
8595 PrevTentativelyDeclaredIdentifierCount);
8596 P.ParenCount = PrevParenCount;
8597 P.BracketCount = PrevBracketCount;
8598 P.BraceCount = PrevBraceCount;
8601 ~TentativeParsingAction() {
8602 assert(!isActive &&
"Forgot to call Commit or Revert!");
8608 class RevertingTentativeParsingAction
8609 :
private Parser::TentativeParsingAction {
8611 using TentativeParsingAction::TentativeParsingAction;
8613 ~RevertingTentativeParsingAction() { Revert(); }
8648 bool isCXXDeclarationStatement(
bool DisambiguatingWithExpression =
false);
8674 bool isCXXSimpleDeclaration(
bool AllowForRangeDecl);
8687 bool isCXXFunctionDeclarator(
bool *IsAmbiguous =
nullptr,
8691 struct ConditionDeclarationOrInitStatementState;
8692 enum class ConditionOrInitStatement {
8719 ConditionOrInitStatement
8720 isCXXConditionDeclarationOrInitStatement(
bool CanBeInitStmt,
8721 bool CanBeForRangeDecl);
8747 return isCXXTypeId(Context, isAmbiguous);
8761 bool isEnumBase(
bool AllowSemi);
8881 TPResult BracedCastResult = TPResult::False,
8882 bool *InvalidAsDeclSpec =
nullptr);
8887 bool isCXXDeclarationSpecifierAType();
8893 TPResult isTemplateArgumentList(
unsigned TokensToSkip);
8898 TPResult isExplicitBool();
8903 bool isTentativelyDeclared(IdentifierInfo *II);
8922 TPResult TryParseSimpleDeclaration(
bool AllowForRangeDecl);
8930 TPResult TryParseTypeofSpecifier();
8934 TPResult TryParseProtocolQualifiers();
8936 TPResult TryParsePtrOperatorSeq();
8958 TPResult TryParseOperatorId();
8989 TPResult TryParseInitDeclaratorList(
bool MayHaveTrailingReturnType =
false);
9046 TPResult TryParseDeclarator(
bool mayBeAbstract,
bool mayHaveIdentifier =
true,
9047 bool mayHaveDirectInit =
false,
9048 bool mayHaveTrailingReturnType =
false);
9069 TPResult TryParseParameterDeclarationClause(
9070 bool *InvalidAsDeclaration =
nullptr,
bool VersusTemplateArg =
false,
9087 TPResult TryParseFunctionDeclarator(
bool MayHaveTrailingReturnType =
false);
9093 bool NameAfterArrowIsNonType();
9099 TPResult TryParseBracketDeclarator();
9103 TPResult TryConsumeDeclarationSpecifier();
9107 bool TrySkipAttributes();
9111 bool hasLambdaLikeContinuation();
9153 isCXX11AttributeSpecifier(
bool Disambiguate =
false,
9154 bool OuterMightBeMessageSend =
false);