299 return Actions.incrementMSManglingNumber();
348 assert(!isTokenSpecial() &&
349 "Should consume special tokens with Consume*Token");
350 PrevTokLocation = Tok.getLocation();
352 return PrevTokLocation;
358 assert(!isTokenSpecial() &&
359 "Should consume special tokens with Consume*Token");
360 PrevTokLocation = Tok.getLocation();
368 Loc = PrevTokLocation;
377 return ConsumeParen();
378 if (isTokenBracket())
379 return ConsumeBracket();
381 return ConsumeBrace();
382 if (isTokenStringLiteral())
383 return ConsumeStringToken();
384 if (Tok.is(tok::code_completion))
385 return ConsumeCodeCompletionTok ? ConsumeCodeCompletionToken()
386 : handleUnexpectedCodeCompletionToken();
387 if (Tok.isAnnotation())
388 return ConsumeAnnotationToken();
402 if (N == 0 || Tok.is(tok::eof))
404 return PP.LookAhead(N - 1);
413 if (!Tok.getAnnotationValue())
448 bool IsAddressOfOperand =
false);
474 (Tok.is(tok::identifier) || Tok.is(tok::coloncolon) ||
475 (Tok.is(tok::annot_template_id) &&
477 Tok.is(tok::kw_decltype) || Tok.is(tok::kw___super));
494 ParseScope(
const ParseScope &) =
delete;
495 void operator=(
const ParseScope &) =
delete;
502 bool BeforeCompoundStmt =
false)
504 if (EnteredScope && !BeforeCompoundStmt)
505 Self->EnterScope(ScopeFlags);
507 if (BeforeCompoundStmt)
508 Self->incrementMSManglingNumber();
510 this->Self = nullptr;
528 class MultiParseScope {
530 unsigned NumScopes = 0;
532 MultiParseScope(
const MultiParseScope &) =
delete;
537 Self.EnterScope(ScopeFlags);
579 static_cast<unsigned>(R));
634 unsigned short ParenCount = 0, BracketCount = 0,
BraceCount = 0;
635 unsigned short MisplacedModuleBeginCount = 0;
646 static constexpr int ScopeCacheSize = 16;
647 unsigned NumCachedScopes;
648 Scope *ScopeCache[ScopeCacheSize];
654 *Ident_GetExceptionCode;
657 *Ident_GetExceptionInfo;
659 IdentifierInfo *Ident__abnormal_termination, *Ident___abnormal_termination,
660 *Ident_AbnormalTermination;
665 std::unique_ptr<CommentHandler> CommentSemaHandler;
670 bool CalledSignatureHelp =
false;
678 bool SkipFunctionBodies;
685 bool isTokenParen()
const {
return Tok.isOneOf(tok::l_paren, tok::r_paren); }
687 bool isTokenBracket()
const {
688 return Tok.isOneOf(tok::l_square, tok::r_square);
691 bool isTokenBrace()
const {
return Tok.isOneOf(tok::l_brace, tok::r_brace); }
693 bool isTokenStringLiteral()
const {
697 bool isTokenSpecial()
const {
698 return isTokenStringLiteral() || isTokenParen() || isTokenBracket() ||
699 isTokenBrace() || Tok.is(tok::code_completion) || Tok.isAnnotation();
704 bool isTokenEqualOrEqualTypo();
708 void UnconsumeToken(Token &Consumed) {
710 PP.EnterToken(Consumed,
true);
712 PP.EnterToken(
Next,
true);
715 SourceLocation ConsumeAnnotationToken() {
716 assert(Tok.isAnnotation() &&
"wrong consume method");
717 SourceLocation Loc = Tok.getLocation();
718 PrevTokLocation = Tok.getAnnotationEndLoc();
725 SourceLocation ConsumeParen() {
726 assert(isTokenParen() &&
"wrong consume method");
727 if (Tok.getKind() == tok::l_paren)
729 else if (ParenCount) {
730 AngleBrackets.clear(*
this);
733 PrevTokLocation = Tok.getLocation();
735 return PrevTokLocation;
740 SourceLocation ConsumeBracket() {
741 assert(isTokenBracket() &&
"wrong consume method");
742 if (Tok.getKind() == tok::l_square)
744 else if (BracketCount) {
745 AngleBrackets.clear(*
this);
749 PrevTokLocation = Tok.getLocation();
751 return PrevTokLocation;
756 SourceLocation ConsumeBrace() {
757 assert(isTokenBrace() &&
"wrong consume method");
758 if (Tok.getKind() == tok::l_brace)
760 else if (BraceCount) {
761 AngleBrackets.clear(*
this);
765 PrevTokLocation = Tok.getLocation();
767 return PrevTokLocation;
774 SourceLocation ConsumeStringToken() {
775 assert(isTokenStringLiteral() &&
776 "Should only consume string literals with this method");
777 PrevTokLocation = Tok.getLocation();
779 return PrevTokLocation;
787 SourceLocation ConsumeCodeCompletionToken() {
788 assert(Tok.is(tok::code_completion));
789 PrevTokLocation = Tok.getLocation();
791 return PrevTokLocation;
799 SourceLocation handleUnexpectedCodeCompletionToken();
803 void cutOffParsing() {
804 if (PP.isCodeCompletionEnabled())
805 PP.setCodeCompletionReached();
807 Tok.setKind(tok::eof);
814 return Kind == tok::eof ||
Kind == tok::annot_module_begin ||
815 Kind == tok::annot_module_end ||
Kind == tok::annot_module_include ||
816 Kind == tok::annot_repl_input_end;
819 static void setTypeAnnotation(Token &Tok,
TypeResult T) {
820 assert((T.isInvalid() || T.get()) &&
821 "produced a valid-but-null type annotation?");
822 Tok.setAnnotationValue(T.isInvalid() ?
nullptr : T.get().getAsOpaquePtr());
825 static NamedDecl *getNonTypeAnnotation(
const Token &Tok) {
826 return static_cast<NamedDecl *
>(Tok.getAnnotationValue());
829 static void setNonTypeAnnotation(Token &Tok, NamedDecl *ND) {
830 Tok.setAnnotationValue(ND);
833 static IdentifierInfo *getIdentifierAnnotation(
const Token &Tok) {
834 return static_cast<IdentifierInfo *
>(Tok.getAnnotationValue());
837 static void setIdentifierAnnotation(Token &Tok, IdentifierInfo *ND) {
838 Tok.setAnnotationValue(ND);
843 static ExprResult getExprAnnotation(
const Token &Tok) {
844 return ExprResult::getFromOpaquePointer(Tok.getAnnotationValue());
849 static void setExprAnnotation(Token &Tok,
ExprResult ER) {
850 Tok.setAnnotationValue(ER.getAsOpaquePointer());
864 TryAnnotateName(CorrectionCandidateCallback *CCC =
nullptr,
869 void AnnotateScopeToken(CXXScopeSpec &SS,
bool IsNewAnnotation);
876 bool TryKeywordIdentFallback(
bool DisableKeyword);
881 TemplateIdAnnotation *takeTemplateIdAnnotation(
const Token &tok);
892 unsigned Diag = diag::err_expected,
893 StringRef DiagMsg =
"");
900 bool ExpectAndConsumeSemi(
unsigned DiagID, StringRef TokenUsed =
"");
905 bool isLikelyAtStartOfNewDeclaration();
916 bool expectIdentifier();
919 enum class CompoundToken {
934 void checkCompoundToken(SourceLocation FirstTokLoc,
937 void diagnoseUseOfC11Keyword(
const Token &Tok);
940 class ParseScopeFlags {
942 unsigned OldFlags = 0;
943 ParseScopeFlags(
const ParseScopeFlags &) =
delete;
944 void operator=(
const ParseScopeFlags &) =
delete;
949 ParseScopeFlags(
Parser *
Self,
unsigned ScopeFlags,
bool ManageFlags =
true);
963 void SuggestParentheses(SourceLocation Loc,
unsigned DK,
964 SourceRange ParenRange);
1000 DeclGroupPtrTy ParseExternalDeclaration(ParsedAttributes &DeclAttrs,
1001 ParsedAttributes &DeclSpecAttrs,
1002 ParsingDeclSpec *DS =
nullptr);
1006 bool isDeclarationAfterDeclarator();
1010 bool isStartOfFunctionDefinition(
const ParsingDeclarator &Declarator);
1013 ParsedAttributes &DeclAttrs, ParsedAttributes &DeclSpecAttrs,
1034 DeclGroupPtrTy ParseDeclOrFunctionDefInternal(ParsedAttributes &Attrs,
1035 ParsedAttributes &DeclSpecAttrs,
1036 ParsingDeclSpec &DS,
1039 void SkipFunctionBody();
1041 struct ParsedTemplateInfo;
1059 Decl *ParseFunctionDefinition(
1060 ParsingDeclarator &D,
1061 const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo(),
1062 LateParsedAttrList *LateParsedAttrs =
nullptr);
1066 void ParseKNRParamDeclarations(Declarator &D);
1076 ExprResult ParseSimpleAsm(
bool ForAsmLabel, SourceLocation *EndLoc);
1089 ExprResult ParseAsmStringLiteral(
bool ForAsmLabel);
1093 struct IfExistsCondition {
1095 SourceLocation KeywordLoc;
1111 bool ParseMicrosoftIfExistsCondition(IfExistsCondition &
Result);
1112 void ParseMicrosoftIfExistsExternalDeclaration();
1151 Decl *ParseModuleImport(SourceLocation AtLoc,
1158 bool parseMisplacedModuleImport();
1160 bool tryParseMisplacedModuleImport() {
1162 if (Kind == tok::annot_module_begin || Kind == tok::annot_module_end ||
1163 Kind == tok::annot_module_include)
1164 return parseMisplacedModuleImport();
1177 bool ParseModuleName(SourceLocation UseLoc,
1178 SmallVectorImpl<IdentifierLoc> &Path,
bool IsImport);
1181 void DiagnoseInvalidCXXModuleImport();
1185 void CodeCompleteDirective(
bool InConditional)
override;
1187 void CodeCompleteMacroName(
bool IsDefinition)
override;
1189 void CodeCompleteMacroArgument(IdentifierInfo *
Macro, MacroInfo *MacroInfo,
1190 unsigned ArgumentIndex)
override;
1191 void CodeCompleteIncludedFile(llvm::StringRef Dir,
bool IsAngled)
override;
1193 void CodeCompleteModuleImport(SourceLocation ImportLoc,
1212 struct ParsingClass;
1218 LateParsedClass(
Parser *P, ParsingClass *
C);
1219 ~LateParsedClass()
override;
1228 LateParsedClass(
const LateParsedClass &) =
delete;
1229 LateParsedClass &operator=(
const LateParsedClass &) =
delete;
1233 ParsingClass *
Class;
1247 :
Self(P), AS(AS) {}
1249 void takeToks(
CachedTokens &Cached) { Toks.swap(Cached); }
1259 struct LexedMethod :
public LateParsedDeclaration {
1264 explicit LexedMethod(
Parser *P, Decl *MD) : Self(P), D(MD) {}
1273 struct LateParsedDefaultArgument {
1274 explicit LateParsedDefaultArgument(
1275 Decl *P, std::unique_ptr<CachedTokens> Toks =
nullptr)
1276 : Param(P), Toks(std::move(Toks)) {}
1285 std::unique_ptr<CachedTokens> Toks;
1292 struct LateParsedMethodDeclaration :
public LateParsedDeclaration {
1293 explicit LateParsedMethodDeclaration(
Parser *P, Decl *M)
1294 : Self(P), Method(M), ExceptionSpecTokens(
nullptr) {}
1308 SmallVector<LateParsedDefaultArgument, 8> DefaultArgs;
1318 struct LateParsedMemberInitializer :
public LateParsedDeclaration {
1319 LateParsedMemberInitializer(
Parser *P, Decl *FD) : Self(P), Field(FD) {}
1339 typedef SmallVector<LateParsedDeclaration *, 2>
1340 LateParsedDeclarationsContainer;
1354 const ParsedAttributesView &AccessAttrs,
1355 ParsingDeclarator &D,
1356 const ParsedTemplateInfo &TemplateInfo,
1357 const VirtSpecifiers &VS,
1358 SourceLocation PureSpecLoc);
1361 StringLiteral *ParseCXXDeletedFunctionMessage();
1366 void SkipDeletedFunctionBody();
1372 void ParseCXXNonStaticMemberInitializer(Decl *VarD);
1376 void ParseLexedAttributes(ParsingClass &
Class);
1379 void ParseLexedAttributeList(LateParsedAttrList &LAs, Decl *D,
1394 void ParseLexedMethodDeclarations(ParsingClass &
Class);
1395 void ParseLexedMethodDeclaration(LateParsedMethodDeclaration &LM);
1400 void ParseLexedMethodDefs(ParsingClass &
Class);
1401 void ParseLexedMethodDef(LexedMethod &LM);
1407 void ParseLexedMemberInitializers(ParsingClass &
Class);
1408 void ParseLexedMemberInitializer(LateParsedMemberInitializer &MI);
1442 ParsedAttributes *Attrs =
nullptr);
1448 IdentifierInfo *Ident_vector;
1449 IdentifierInfo *Ident_bool;
1450 IdentifierInfo *Ident_Bool;
1454 IdentifierInfo *Ident_pixel;
1457 IdentifierInfo *Ident_introduced;
1460 IdentifierInfo *Ident_deprecated;
1463 IdentifierInfo *Ident_obsoleted;
1466 IdentifierInfo *Ident_unavailable;
1469 IdentifierInfo *Ident_message;
1472 IdentifierInfo *Ident_strict;
1475 IdentifierInfo *Ident_replacement;
1478 IdentifierInfo *Ident_environment;
1481 IdentifierInfo *Ident_language, *Ident_defined_in,
1482 *Ident_generated_declaration, *Ident_USR;
1485 AttributeFactory AttrFactory;
1490 bool TryAltiVecToken(DeclSpec &DS, SourceLocation Loc,
const char *&PrevSpec,
1495 if (Tok.getIdentifierInfo() != Ident_vector &&
1496 Tok.getIdentifierInfo() != Ident_bool &&
1497 Tok.getIdentifierInfo() != Ident_Bool &&
1498 (!
getLangOpts().AltiVec || Tok.getIdentifierInfo() != Ident_pixel))
1501 return TryAltiVecTokenOutOfLine(DS, Loc, PrevSpec, DiagID,
isInvalid);
1507 bool TryAltiVecVectorToken() {
1509 Tok.getIdentifierInfo() != Ident_vector)
1511 return TryAltiVecVectorTokenOutOfLine();
1516 bool TryAltiVecVectorTokenOutOfLine();
1517 bool TryAltiVecTokenOutOfLine(DeclSpec &DS, SourceLocation Loc,
1518 const char *&PrevSpec,
unsigned &DiagID,
1521 void ParseLexedCAttributeList(LateParsedAttrList &LA,
1522 ParsedAttributes *OutAttrs =
nullptr);
1530 ParsedAttributes *OutAttrs =
nullptr);
1533 ParsedAttributes &OutAttrs);
1543 static void TakeTypeAttrsAppendingFrom(LateParsedAttrList &To,
1544 LateParsedAttrList &From);
1546 void ParseLexedPragmas(ParsingClass &
Class);
1547 void ParseLexedPragma(LateParsedPragma &LP);
1555 bool ConsumeAndStoreFunctionPrologue(
CachedTokens &Toks);
1571 bool ConsumeFinalToken =
true) {
1572 return ConsumeAndStoreUntil(T1, T1, Toks,
StopAtSemi, ConsumeFinalToken);
1583 bool ConsumeFinalToken =
true);
1591 enum class DeclSpecContext {
1596 DSC_alias_declaration,
1601 DSC_template_type_arg,
1602 DSC_objc_method_result,
1611 static bool isTypeSpecifier(DeclSpecContext DSC) {
1613 case DeclSpecContext::DSC_normal:
1614 case DeclSpecContext::DSC_template_param:
1615 case DeclSpecContext::DSC_template_arg:
1616 case DeclSpecContext::DSC_class:
1617 case DeclSpecContext::DSC_top_level:
1618 case DeclSpecContext::DSC_objc_method_result:
1619 case DeclSpecContext::DSC_condition:
1622 case DeclSpecContext::DSC_template_type_arg:
1623 case DeclSpecContext::DSC_type_specifier:
1624 case DeclSpecContext::DSC_conv_operator:
1625 case DeclSpecContext::DSC_trailing:
1626 case DeclSpecContext::DSC_alias_declaration:
1627 case DeclSpecContext::DSC_association:
1628 case DeclSpecContext::DSC_new:
1631 llvm_unreachable(
"Missing DeclSpecContext case");
1635 enum class AllowDefiningTypeSpec {
1652 static AllowDefiningTypeSpec
1653 isDefiningTypeSpecifierContext(DeclSpecContext DSC,
bool IsCPlusPlus) {
1655 case DeclSpecContext::DSC_normal:
1656 case DeclSpecContext::DSC_class:
1657 case DeclSpecContext::DSC_top_level:
1658 case DeclSpecContext::DSC_alias_declaration:
1659 case DeclSpecContext::DSC_objc_method_result:
1660 return AllowDefiningTypeSpec::Yes;
1662 case DeclSpecContext::DSC_condition:
1663 case DeclSpecContext::DSC_template_param:
1664 return AllowDefiningTypeSpec::YesButInvalid;
1666 case DeclSpecContext::DSC_template_type_arg:
1667 case DeclSpecContext::DSC_type_specifier:
1668 return AllowDefiningTypeSpec::NoButErrorRecovery;
1670 case DeclSpecContext::DSC_association:
1671 return IsCPlusPlus ? AllowDefiningTypeSpec::NoButErrorRecovery
1672 : AllowDefiningTypeSpec::Yes;
1674 case DeclSpecContext::DSC_trailing:
1675 case DeclSpecContext::DSC_conv_operator:
1676 case DeclSpecContext::DSC_template_arg:
1677 case DeclSpecContext::DSC_new:
1678 return AllowDefiningTypeSpec::No;
1680 llvm_unreachable(
"Missing DeclSpecContext case");
1684 static bool isOpaqueEnumDeclarationContext(DeclSpecContext DSC) {
1686 case DeclSpecContext::DSC_normal:
1687 case DeclSpecContext::DSC_class:
1688 case DeclSpecContext::DSC_top_level:
1691 case DeclSpecContext::DSC_alias_declaration:
1692 case DeclSpecContext::DSC_objc_method_result:
1693 case DeclSpecContext::DSC_condition:
1694 case DeclSpecContext::DSC_template_param:
1695 case DeclSpecContext::DSC_template_type_arg:
1696 case DeclSpecContext::DSC_type_specifier:
1697 case DeclSpecContext::DSC_trailing:
1698 case DeclSpecContext::DSC_association:
1699 case DeclSpecContext::DSC_conv_operator:
1700 case DeclSpecContext::DSC_template_arg:
1701 case DeclSpecContext::DSC_new:
1705 llvm_unreachable(
"Missing DeclSpecContext case");
1710 static bool isClassTemplateDeductionContext(DeclSpecContext DSC) {
1712 case DeclSpecContext::DSC_normal:
1713 case DeclSpecContext::DSC_template_param:
1714 case DeclSpecContext::DSC_template_arg:
1715 case DeclSpecContext::DSC_class:
1716 case DeclSpecContext::DSC_top_level:
1717 case DeclSpecContext::DSC_condition:
1718 case DeclSpecContext::DSC_type_specifier:
1719 case DeclSpecContext::DSC_association:
1720 case DeclSpecContext::DSC_conv_operator:
1721 case DeclSpecContext::DSC_new:
1724 case DeclSpecContext::DSC_objc_method_result:
1725 case DeclSpecContext::DSC_template_type_arg:
1726 case DeclSpecContext::DSC_trailing:
1727 case DeclSpecContext::DSC_alias_declaration:
1730 llvm_unreachable(
"Missing DeclSpecContext case");
1735 getImplicitTypenameContext(DeclSpecContext DSC) {
1737 case DeclSpecContext::DSC_class:
1738 case DeclSpecContext::DSC_top_level:
1739 case DeclSpecContext::DSC_type_specifier:
1740 case DeclSpecContext::DSC_template_type_arg:
1741 case DeclSpecContext::DSC_trailing:
1742 case DeclSpecContext::DSC_alias_declaration:
1743 case DeclSpecContext::DSC_template_param:
1744 case DeclSpecContext::DSC_new:
1745 case DeclSpecContext::DSC_conv_operator:
1748 case DeclSpecContext::DSC_normal:
1749 case DeclSpecContext::DSC_objc_method_result:
1750 case DeclSpecContext::DSC_condition:
1751 case DeclSpecContext::DSC_template_arg:
1752 case DeclSpecContext::DSC_association:
1755 llvm_unreachable(
"Missing DeclSpecContext case");
1760 struct ForRangeInit {
1761 SourceLocation ColonLoc;
1763 SmallVector<MaterializeTemporaryExpr *, 8> LifetimeExtendTemps;
1764 bool ParsedForRangeDecl() {
return !ColonLoc.
isInvalid(); }
1766 struct ForRangeInfo : ForRangeInit {
1789 SourceLocation &DeclEnd,
1790 ParsedAttributes &DeclAttrs,
1791 ParsedAttributes &DeclSpecAttrs,
1792 SourceLocation *DeclSpecStart =
nullptr);
1819 ParsedAttributes &DeclAttrs,
1820 ParsedAttributes &DeclSpecAttrs,
bool RequireSemi,
1821 ForRangeInit *FRI =
nullptr,
1822 SourceLocation *DeclSpecStart =
nullptr);
1832 ParsedAttributes &Attrs,
1833 ParsedTemplateInfo &TemplateInfo,
1834 SourceLocation *DeclEnd =
nullptr,
1835 ForRangeInit *FRI =
nullptr);
1861 Decl *ParseDeclarationAfterDeclarator(
1863 const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo());
1867 bool ParseAsmAttributesAfterDeclarator(Declarator &D);
1868 Decl *ParseDeclarationAfterDeclaratorAndAttributes(
1870 const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo(),
1871 ForRangeInit *FRI =
nullptr);
1882 bool ParseImplicitInt(DeclSpec &DS, CXXScopeSpec *SS,
1884 DeclSpecContext DSC, ParsedAttributes &Attrs);
1894 ParseDeclarationSpecifiers(DeclSpec &DS, ParsedTemplateInfo &TemplateInfo,
1896 DeclSpecContext DSC = DeclSpecContext::DSC_normal,
1897 LateParsedAttrList *LateAttrs =
nullptr) {
1898 return ParseDeclarationSpecifiers(DS, TemplateInfo, AS, DSC, LateAttrs,
1899 getImplicitTypenameContext(DSC));
1932 ParseDeclarationSpecifiers(DeclSpec &DS, ParsedTemplateInfo &TemplateInfo,
1934 LateParsedAttrList *LateAttrs,
1944 bool DiagnoseMissingSemiAfterTagDefinition(
1946 LateParsedAttrList *LateAttrs =
nullptr);
1948 void ParseSpecifierQualifierList(
1950 DeclSpecContext DSC = DeclSpecContext::DSC_normal) {
1951 ParseSpecifierQualifierList(DS, getImplicitTypenameContext(DSC), AS, DSC);
1962 void ParseSpecifierQualifierList(
1965 DeclSpecContext DSC = DeclSpecContext::DSC_normal);
1999 void ParseEnumSpecifier(SourceLocation TagLoc, DeclSpec &DS,
2000 const ParsedTemplateInfo &TemplateInfo,
2015 void ParseEnumBody(SourceLocation StartLoc, Decl *TagDecl,
2016 SkipBodyInfo *SkipBody =
nullptr);
2030 void ParseStructUnionBody(SourceLocation StartLoc,
DeclSpec::TST TagType,
2031 RecordDecl *TagDecl);
2056 void ParseStructDeclaration(
2057 ParsingDeclSpec &DS,
2058 llvm::function_ref<Decl *(ParsingFieldDeclarator &)> FieldsCallback,
2059 LateParsedAttrList *LateFieldAttrs =
nullptr);
2071 bool DisambiguatingWithExpression =
false);
2075 bool isTypeSpecifierQualifier(
const Token &Tok);
2080 bool isKnownToBeTypeSpecifier(
const Token &Tok)
const;
2085 bool isConstructorDeclarator(
2088 const ParsedTemplateInfo *TemplateInfo =
nullptr);
2092 void DiagnoseBitIntUse(
const Token &Tok);
2096 bool CheckProhibitedCXX11Attribute() {
2097 assert(Tok.is(tok::l_square));
2100 return DiagnoseProhibitedCXX11Attribute();
2111 bool DiagnoseProhibitedCXX11Attribute();
2113 void CheckMisplacedCXX11Attribute(ParsedAttributes &Attrs,
2114 SourceLocation CorrectLocation) {
2115 if (!Tok.isRegularKeywordAttribute() &&
2116 (Tok.isNot(tok::l_square) ||
NextToken().
isNot(tok::l_square)) &&
2117 Tok.isNot(tok::kw_alignas))
2119 DiagnoseMisplacedCXX11Attribute(Attrs, CorrectLocation);
2126 void DiagnoseMisplacedCXX11Attribute(ParsedAttributes &Attrs,
2127 SourceLocation CorrectLocation);
2137 void stripTypeAttributesOffDeclSpec(ParsedAttributes &Attrs, DeclSpec &DS,
2141 void ProhibitAttributes(ParsedAttributes &Attrs,
2142 SourceLocation FixItLoc = SourceLocation()) {
2143 if (Attrs.Range.isInvalid())
2145 DiagnoseProhibitedAttributes(Attrs, FixItLoc);
2149 void ProhibitAttributes(ParsedAttributesView &Attrs,
2150 SourceLocation FixItLoc = SourceLocation()) {
2151 if (Attrs.Range.isInvalid())
2153 DiagnoseProhibitedAttributes(Attrs, FixItLoc);
2154 Attrs.clearListOnly();
2156 void DiagnoseProhibitedAttributes(
const ParsedAttributesView &Attrs,
2157 SourceLocation FixItLoc);
2165 void ProhibitCXX11Attributes(ParsedAttributes &Attrs,
unsigned AttrDiagID,
2166 unsigned KeywordDiagId,
2167 bool DiagnoseEmptyAttrs =
false,
2168 bool WarnOnUnknownAttrs =
false);
2172 void DiagnoseCXX11AttributeExtension(ParsedAttributes &Attrs);
2174 ExprResult ParseUnevaluatedStringInAttribute(
const IdentifierInfo &AttrName);
2181 bool ParseAttributeArgumentList(
2182 const IdentifierInfo &AttrName, SmallVectorImpl<Expr *> &Exprs,
2183 ParsedAttributeArgumentsProperties ArgsProperties,
unsigned Arg);
2190 ParseAttributeArgsCommon(IdentifierInfo *AttrName, SourceLocation AttrNameLoc,
2191 ParsedAttributes &Attrs, SourceLocation *EndLoc,
2192 IdentifierInfo *ScopeName, SourceLocation ScopeLoc,
2193 ParsedAttr::Form Form);
2195 enum ParseAttrKindMask {
2197 PAKM_Declspec = 1 << 1,
2198 PAKM_CXX11 = 1 << 2,
2217 void ParseAttributes(
unsigned WhichAttrKinds, ParsedAttributes &Attrs,
2218 LateParsedAttrList *LateAttrs =
nullptr);
2221 bool MaybeParseAttributes(
unsigned WhichAttrKinds, ParsedAttributes &Attrs,
2222 LateParsedAttrList *LateAttrs =
nullptr) {
2223 if (Tok.isOneOf(tok::kw___attribute, tok::kw___declspec) ||
2224 isAllowedCXX11AttributeSpecifier()) {
2225 ParseAttributes(WhichAttrKinds, Attrs, LateAttrs);
2231 void MaybeParseGNUAttributes(Declarator &D,
2232 LateParsedAttrList *LateAttrs =
nullptr) {
2233 if (Tok.is(tok::kw___attribute)) {
2234 ParsedAttributes Attrs(AttrFactory);
2235 ParseGNUAttributes(Attrs, LateAttrs, &D);
2236 D.takeAttributesAppending(Attrs);
2240 bool MaybeParseGNUAttributes(ParsedAttributes &Attrs,
2241 LateParsedAttrList *LateAttrs =
nullptr) {
2242 if (Tok.is(tok::kw___attribute)) {
2243 ParseGNUAttributes(Attrs, LateAttrs);
2265 bool ParseSingleGNUAttribute(ParsedAttributes &Attrs, SourceLocation &EndLoc,
2266 LateParsedAttrList *LateAttrs =
nullptr,
2267 Declarator *D =
nullptr);
2312 void ParseGNUAttributes(ParsedAttributes &Attrs,
2313 LateParsedAttrList *LateAttrs =
nullptr,
2314 Declarator *D =
nullptr);
2318 void ParseGNUAttributeArgs(IdentifierInfo *AttrName,
2319 SourceLocation AttrNameLoc,
2320 ParsedAttributes &Attrs, SourceLocation *EndLoc,
2321 IdentifierInfo *ScopeName, SourceLocation ScopeLoc,
2322 ParsedAttr::Form Form, Declarator *D);
2323 IdentifierLoc *ParseIdentifierLoc();
2326 ParseClangAttributeArgs(IdentifierInfo *AttrName, SourceLocation AttrNameLoc,
2327 ParsedAttributes &Attrs, SourceLocation *EndLoc,
2328 IdentifierInfo *ScopeName, SourceLocation ScopeLoc,
2329 ParsedAttr::Form Form);
2331 void MaybeParseCXX11Attributes(Declarator &D) {
2332 if (isAllowedCXX11AttributeSpecifier()) {
2333 ParsedAttributes Attrs(AttrFactory);
2334 ParseCXX11Attributes(Attrs);
2335 D.takeAttributesAppending(Attrs);
2339 bool MaybeParseCXX11Attributes(ParsedAttributes &Attrs,
2340 bool OuterMightBeMessageSend =
false) {
2341 if (isAllowedCXX11AttributeSpecifier(
false, OuterMightBeMessageSend)) {
2342 ParseCXX11Attributes(Attrs);
2348 bool MaybeParseMicrosoftAttributes(ParsedAttributes &Attrs) {
2349 bool AttrsParsed =
false;
2351 Tok.is(tok::l_square)) {
2352 ParsedAttributes AttrsWithRange(AttrFactory);
2353 ParseMicrosoftAttributes(AttrsWithRange);
2354 AttrsParsed = !AttrsWithRange.empty();
2355 Attrs.takeAllAppendingFrom(AttrsWithRange);
2359 bool MaybeParseMicrosoftDeclSpecs(ParsedAttributes &Attrs) {
2360 if (
getLangOpts().DeclSpecKeyword && Tok.is(tok::kw___declspec)) {
2361 ParseMicrosoftDeclSpecs(Attrs);
2375 void ParseMicrosoftDeclSpecs(ParsedAttributes &Attrs);
2376 bool ParseMicrosoftDeclSpecArgs(IdentifierInfo *AttrName,
2377 SourceLocation AttrNameLoc,
2378 ParsedAttributes &Attrs);
2379 void ParseMicrosoftTypeAttributes(ParsedAttributes &attrs);
2380 void ParseWebAssemblyFuncrefTypeAttribute(ParsedAttributes &Attrs);
2381 void DiagnoseAndSkipExtendedMicrosoftTypeAttributes();
2382 SourceLocation SkipExtendedMicrosoftTypeAttributes();
2384 void ParseBorlandTypeAttributes(ParsedAttributes &attrs);
2385 void ParseOpenCLKernelAttributes(ParsedAttributes &attrs);
2386 void ParseOpenCLQualifiers(ParsedAttributes &Attrs);
2387 void ParseNullabilityTypeSpecifiers(ParsedAttributes &attrs);
2388 void ParseCUDAFunctionAttributes(ParsedAttributes &attrs);
2389 bool isHLSLQualifier(
const Token &Tok)
const;
2390 void ParseHLSLQualifiers(ParsedAttributes &Attrs);
2402 VersionTuple ParseVersionTuple(SourceRange &Range);
2431 void ParseAvailabilityAttribute(IdentifierInfo &Availability,
2432 SourceLocation AvailabilityLoc,
2433 ParsedAttributes &attrs,
2434 SourceLocation *endLoc,
2435 IdentifierInfo *ScopeName,
2436 SourceLocation ScopeLoc,
2437 ParsedAttr::Form Form);
2455 void ParseExternalSourceSymbolAttribute(IdentifierInfo &ExternalSourceSymbol,
2457 ParsedAttributes &Attrs,
2458 SourceLocation *EndLoc,
2459 IdentifierInfo *ScopeName,
2460 SourceLocation ScopeLoc,
2461 ParsedAttr::Form Form);
2476 void ParseObjCBridgeRelatedAttribute(IdentifierInfo &ObjCBridgeRelated,
2477 SourceLocation ObjCBridgeRelatedLoc,
2478 ParsedAttributes &Attrs,
2479 SourceLocation *EndLoc,
2480 IdentifierInfo *ScopeName,
2481 SourceLocation ScopeLoc,
2482 ParsedAttr::Form Form);
2484 void ParseSwiftNewTypeAttribute(IdentifierInfo &AttrName,
2485 SourceLocation AttrNameLoc,
2486 ParsedAttributes &Attrs,
2487 SourceLocation *EndLoc,
2488 IdentifierInfo *ScopeName,
2489 SourceLocation ScopeLoc,
2490 ParsedAttr::Form Form);
2492 void ParseTypeTagForDatatypeAttribute(IdentifierInfo &AttrName,
2493 SourceLocation AttrNameLoc,
2494 ParsedAttributes &Attrs,
2495 SourceLocation *EndLoc,
2496 IdentifierInfo *ScopeName,
2497 SourceLocation ScopeLoc,
2498 ParsedAttr::Form Form);
2500 void ParseAttributeWithTypeArg(IdentifierInfo &AttrName,
2501 SourceLocation AttrNameLoc,
2502 ParsedAttributes &Attrs,
2503 IdentifierInfo *ScopeName,
2504 SourceLocation ScopeLoc,
2505 ParsedAttr::Form Form);
2507 void DistributeCLateParsedAttrs(Decl *Dcl, LateParsedAttrList *LateAttrs);
2513 void ParseBoundsAttribute(IdentifierInfo &AttrName,
2514 SourceLocation AttrNameLoc, ParsedAttributes &Attrs,
2515 IdentifierInfo *ScopeName, SourceLocation ScopeLoc,
2516 ParsedAttr::Form Form);
2532 void ParseTypeofSpecifier(DeclSpec &DS);
2539 void ParseAtomicSpecifier(DeclSpec &DS);
2549 ExprResult ParseAlignArgument(StringRef KWName, SourceLocation Start,
2550 SourceLocation &EllipsisLoc,
bool &IsType,
2563 void ParseAlignmentSpecifier(ParsedAttributes &Attrs,
2564 SourceLocation *endLoc =
nullptr);
2573 void ParsePtrauthQualifier(ParsedAttributes &Attrs);
2578 class DeclaratorScopeObj {
2585 DeclaratorScopeObj(
Parser &p, CXXScopeSpec &ss)
2586 : P(p), SS(ss), EnteredScope(
false), CreatedScope(
false) {}
2588 void EnterDeclaratorScope() {
2589 assert(!EnteredScope &&
"Already entered the scope!");
2590 assert(SS.isSet() &&
"C++ scope was not set!");
2592 CreatedScope =
true;
2595 if (!P.Actions.ActOnCXXEnterDeclaratorScope(P.getCurScope(), SS))
2596 EnteredScope =
true;
2599 ~DeclaratorScopeObj() {
2601 assert(SS.isSet() &&
"C++ scope was cleared ?");
2602 P.Actions.ActOnCXXExitDeclaratorScope(P.getCurScope(), SS);
2610 void ParseDeclarator(Declarator &D);
2641 void ParseDeclaratorInternal(Declarator &D,
2642 DirectDeclParseFunction DirectDeclParser);
2644 enum AttrRequirements {
2645 AR_NoAttributesParsed = 0,
2646 AR_GNUAttributesParsedAndRejected = 1 << 0,
2647 AR_GNUAttributesParsed = 1 << 1,
2648 AR_CXX11AttributesParsed = 1 << 2,
2649 AR_DeclspecAttributesParsed = 1 << 3,
2650 AR_AllAttributesParsed = AR_GNUAttributesParsed | AR_CXX11AttributesParsed |
2651 AR_DeclspecAttributesParsed,
2652 AR_VendorAttributesParsed =
2653 AR_GNUAttributesParsed | AR_DeclspecAttributesParsed
2670 void ParseTypeQualifierListOpt(
2671 DeclSpec &DS,
unsigned AttrReqs = AR_AllAttributesParsed,
2672 bool AtomicOrPtrauthAllowed =
true,
bool IdentifierRequired =
false,
2673 llvm::function_ref<
void()> CodeCompletionHandler = {});
2723 void ParseDirectDeclarator(Declarator &D);
2724 void ParseDecompositionDeclarator(Declarator &D);
2742 void ParseParenDeclarator(Declarator &D);
2767 void ParseFunctionDeclarator(Declarator &D, ParsedAttributes &FirstArgAttrs,
2769 bool IsAmbiguous,
bool RequiresArg =
false);
2770 void InitCXXThisScopeForDeclaratorIfRelevant(
2771 const Declarator &D,
const DeclSpec &DS,
2772 std::optional<Sema::CXXThisScopeRAII> &ThisScope);
2776 bool ParseRefQualifier(
bool &RefQualifierIsLValueRef,
2777 SourceLocation &RefQualifierLoc);
2784 bool isFunctionDeclaratorIdentifierList();
2798 void ParseFunctionDeclaratorIdentifierList(
2799 Declarator &D, SmallVectorImpl<DeclaratorChunk::ParamInfo> &ParamInfo);
2800 void ParseParameterDeclarationClause(
2801 Declarator &D, ParsedAttributes &attrs,
2802 SmallVectorImpl<DeclaratorChunk::ParamInfo> &ParamInfo,
2803 SourceLocation &EllipsisLoc) {
2804 return ParseParameterDeclarationClause(
2805 D.getContext(), attrs, ParamInfo, EllipsisLoc,
2806 D.getCXXScopeSpec().isSet() &&
2807 D.isFunctionDeclaratorAFunctionDeclaration());
2845 void ParseParameterDeclarationClause(
2847 SmallVectorImpl<DeclaratorChunk::ParamInfo> &ParamInfo,
2848 SourceLocation &EllipsisLoc,
bool IsACXXFunctionDeclaration =
false);
2859 void ParseBracketDeclarator(Declarator &D);
2862 void ParseMisplacedBracketDeclarator(Declarator &D);
2873 TypeResult ParseTypeFromString(StringRef TypeStr, StringRef Context,
2874 SourceLocation IncludeLoc);
2890 mutable IdentifierInfo *Ident_sealed;
2891 mutable IdentifierInfo *Ident_abstract;
2894 mutable IdentifierInfo *Ident_final;
2895 mutable IdentifierInfo *Ident_GNU_final;
2896 mutable IdentifierInfo *Ident_override;
2901 struct ParsingClass {
2902 ParsingClass(Decl *TagOrTemplate,
bool TopLevelClass,
bool IsInterface)
2903 : TopLevelClass(TopLevelClass), IsInterface(IsInterface),
2904 TagOrTemplate(TagOrTemplate) {}
2908 bool TopLevelClass : 1;
2911 bool IsInterface : 1;
2914 Decl *TagOrTemplate;
2919 LateParsedDeclarationsContainer LateParsedDeclarations;
2925 std::stack<ParsingClass *> ClassStack;
2927 ParsingClass &getCurrentClass() {
2928 assert(!ClassStack.empty() &&
"No lexed method stacks!");
2929 return *ClassStack.top();
2933 class ParsingClassDefinition {
2939 ParsingClassDefinition(
Parser &P, Decl *TagOrTemplate,
bool TopLevelClass,
2941 : P(P), Popped(
false),
2942 State(P.PushParsingClass(TagOrTemplate, TopLevelClass, IsInterface)) {
2947 assert(!Popped &&
"Nested class has already been popped");
2949 P.PopParsingClass(State);
2952 ~ParsingClassDefinition() {
2954 P.PopParsingClass(State);
2970 bool Delayed, SourceRange &SpecificationRange,
2971 SmallVectorImpl<ParsedType> &DynamicExceptions,
2972 SmallVectorImpl<SourceRange> &DynamicExceptionRanges,
2990 ParseDynamicExceptionSpecification(SourceRange &SpecificationRange,
2991 SmallVectorImpl<ParsedType> &Exceptions,
2992 SmallVectorImpl<SourceRange> &Ranges);
2999 TypeResult ParseTrailingReturnType(SourceRange &Range,
3000 bool MayBeFollowedByDirectInit);
3003 void ParseTrailingRequiresClauseWithScope(Declarator &D);
3004 void ParseTrailingRequiresClause(Declarator &D);
3006 void ParseMicrosoftIfExistsClassDeclaration(
DeclSpec::TST TagType,
3007 ParsedAttributes &AccessAttrs,
3010 SourceLocation ParsePackIndexingType(DeclSpec &DS);
3011 void AnnotateExistingIndexedTypeNamePack(
ParsedType T,
3012 SourceLocation StartLoc,
3013 SourceLocation EndLoc);
3020 bool isAllowedCXX11AttributeSpecifier(
bool Disambiguate =
false,
3021 bool OuterMightBeMessageSend =
false) {
3022 return (Tok.isRegularKeywordAttribute() ||
3023 isCXX11AttributeSpecifier(Disambiguate, OuterMightBeMessageSend) !=
3030 SourceLocation SkipCXX11Attributes();
3034 void DiagnoseAndSkipCXX11Attributes();
3036 void ParseOpenMPAttributeArgs(
const IdentifierInfo *AttrName,
3065 void ParseCXX11AttributeSpecifierInternal(ParsedAttributes &Attrs,
3067 SourceLocation *EndLoc =
nullptr);
3068 void ParseCXX11AttributeSpecifier(ParsedAttributes &Attrs,
3069 SourceLocation *EndLoc =
nullptr) {
3071 ParseCXX11AttributeSpecifierInternal(Attrs, OpenMPTokens, EndLoc);
3072 ReplayOpenMPAttributeTokens(OpenMPTokens);
3081 void ParseCXX11Attributes(ParsedAttributes &attrs);
3101 bool ParseCXX11AttributeArgs(IdentifierInfo *AttrName,
3102 SourceLocation AttrNameLoc,
3103 ParsedAttributes &Attrs, SourceLocation *EndLoc,
3104 IdentifierInfo *ScopeName,
3105 SourceLocation ScopeLoc,
3111 ParseCXXAssumeAttributeArg(ParsedAttributes &Attrs, IdentifierInfo *AttrName,
3112 SourceLocation AttrNameLoc,
3113 IdentifierInfo *ScopeName, SourceLocation ScopeLoc,
3114 SourceLocation *EndLoc, ParsedAttr::Form Form);
3125 IdentifierInfo *TryParseCXX11AttributeIdentifier(
3126 SourceLocation &Loc,
3129 const IdentifierInfo *EnclosingScope =
nullptr);
3132 void ParseMicrosoftUuidAttributeArgs(ParsedAttributes &Attrs);
3144 void ParseMicrosoftAttributes(ParsedAttributes &Attrs);
3146 void ParseMicrosoftInheritanceClassAttributes(ParsedAttributes &attrs);
3147 void ParseNullabilityClassAttributes(ParsedAttributes &attrs);
3156 SourceLocation ParseDecltypeSpecifier(DeclSpec &DS);
3157 void AnnotateExistingDecltypeSpecifier(
const DeclSpec &DS,
3158 SourceLocation StartLoc,
3159 SourceLocation EndLoc);
3172 return isCXX11VirtSpecifier(Tok);
3182 void ParseOptionalCXX11VirtSpecifierSeq(VirtSpecifiers &VS,
bool IsInterface,
3183 SourceLocation FriendLoc);
3187 bool isCXX11FinalKeyword()
const;
3193 bool isClassCompatibleKeyword()
const;
3195 bool MaybeParseTypeTransformTypeSpecifier(DeclSpec &DS);
3198 void DiagnoseUnexpectedNamespace(NamedDecl *Context);
3230 SourceLocation &DeclEnd,
3231 SourceLocation InlineLoc = SourceLocation());
3233 struct InnerNamespaceInfo {
3234 SourceLocation NamespaceLoc;
3235 SourceLocation InlineLoc;
3236 SourceLocation IdentLoc;
3237 IdentifierInfo *Ident;
3239 using InnerNamespaceInfoList = llvm::SmallVector<InnerNamespaceInfo, 4>;
3242 void ParseInnerNamespace(
const InnerNamespaceInfoList &InnerNSs,
3243 unsigned int index, SourceLocation &InlineLoc,
3244 ParsedAttributes &attrs,
3276 Decl *ParseExportDeclaration();
3282 SourceLocation &DeclEnd, ParsedAttributes &Attrs);
3297 SourceLocation &DeclEnd, ParsedAttributes &attrs);
3299 struct UsingDeclarator {
3300 SourceLocation TypenameLoc;
3303 SourceLocation EllipsisLoc;
3306 TypenameLoc = EllipsisLoc = SourceLocation();
3347 const ParsedTemplateInfo &TemplateInfo,
3348 SourceLocation UsingLoc,
3349 SourceLocation &DeclEnd,
3350 ParsedAttributes &Attrs,
3352 Decl *ParseAliasDeclarationAfterDeclarator(
3353 const ParsedTemplateInfo &TemplateInfo, SourceLocation UsingLoc,
3355 ParsedAttributes &Attrs, Decl **OwnedType =
nullptr);
3368 Decl *ParseStaticAssertDeclaration(SourceLocation &DeclEnd);
3373 Decl *ParseNamespaceAlias(SourceLocation NamespaceLoc,
3374 SourceLocation AliasLoc, IdentifierInfo *Alias,
3375 SourceLocation &DeclEnd);
3383 bool isValidAfterTypeSpecifier(
bool CouldBeBitfield);
3427 void ParseClassSpecifier(
tok::TokenKind TagTokKind, SourceLocation TagLoc,
3428 DeclSpec &DS, ParsedTemplateInfo &TemplateInfo,
3430 DeclSpecContext DSC, ParsedAttributes &Attributes);
3431 void SkipCXXMemberSpecification(SourceLocation StartLoc,
3432 SourceLocation AttrFixitLoc,
unsigned TagType,
3443 void ParseCXXMemberSpecification(SourceLocation StartLoc,
3444 SourceLocation AttrFixitLoc,
3445 ParsedAttributes &Attrs,
unsigned TagType,
3470 ExprResult ParseCXXMemberInitializer(Decl *D,
bool IsFunction,
3471 SourceLocation &EqualLoc);
3475 bool ParseCXXMemberDeclaratorBeforeInitializer(Declarator &DeclaratorInfo,
3478 LateParsedAttrList &LateAttrs);
3483 MaybeParseAndDiagnoseDeclSpecAfterCXX11VirtSpecifierSeq(Declarator &D,
3484 VirtSpecifiers &VS);
3540 ParsedTemplateInfo &TemplateInfo,
3541 ParsingDeclRAIIObject *DiagsFromTParams =
nullptr);
3544 ParsedAttributes &AccessAttrs,
3570 void ParseConstructorInitializer(Decl *ConstructorDecl);
3592 void HandleMemberFunctionDeclDelays(Declarator &DeclaratorInfo,
3620 TypeResult ParseBaseTypeSpecifier(SourceLocation &BaseLoc,
3621 SourceLocation &EndLocation);
3633 void ParseBaseClause(Decl *ClassDecl);
3648 BaseResult ParseBaseSpecifier(Decl *ClassDecl);
3664 bool isClassCompatibleKeyword(Token Tok)
const;
3666 void ParseHLSLRootSignatureAttributeArgs(ParsedAttributes &Attrs);
3841 bool GreaterThanIsOperator;
3845 llvm::SmallDenseMap<IdentifierInfo *, tok::TokenKind> RevertibleTypeTraits;
3864 PushParsingClass(
Decl *TagOrTemplate,
bool TopLevelClass,
bool IsInterface);
3868 void DeallocateParsedClasses(ParsingClass *
Class);
4089 bool isAddressOfOperand,
bool &NotCastExpr,
4091 bool isVectorLiteral =
false,
4092 bool *NotPrimaryExpression =
nullptr);
4094 bool isAddressOfOperand =
false,
4097 bool isVectorLiteral =
false,
4098 bool *NotPrimaryExpression =
nullptr);
4101 bool isNotExpressionStart();
4105 bool isPostfixExpressionSuffixStart() {
4107 return (K == tok::l_square || K == tok::l_paren || K == tok::period ||
4108 K == tok::arrow || K == tok::plusplus || K == tok::minusminus);
4150 ExprResult ParseUnaryExprOrTypeTraitExpression();
4179 ExprResult ParseSYCLUniqueStableNameExpression();
4241 llvm::function_ref<
void()> ExpressionStarts =
4242 llvm::function_ref<
void()>(),
4243 bool FailImmediatelyOnInvalidExpr =
false);
4288 bool StopIfCastExpr,
4325 ExprResult ParseGenericSelectionExpression();
4344 void injectEmbedTokens();
4370 ExprResult ParseAssignmentExprWithObjCMessageExprStart(
4372 Expr *ReceiverExpr);
4377 bool isKnownToBeDeclarationSpecifier() {
4391 bool isTypeIdForGenericSelection() {
4397 return isTypeSpecifierQualifier(Tok);
4403 bool isTypeIdUnambiguously() {
4408 return isTypeSpecifierQualifier(Tok);
4417 void ParseBlockId(SourceLocation CaretLoc);
4426 std::optional<AvailabilitySpec> ParseAvailabilitySpec();
4427 ExprResult ParseAvailabilityCheckExpr(SourceLocation StartLoc);
4433 bool tryParseOpenMPArrayShapingCastPart();
4435 ExprResult ParseBuiltinPtrauthTypeDiscriminator();
4488 bool ObjectHadErrors,
bool EnteringContext,
4489 bool AllowDestructorName,
bool AllowConstructorName,
4490 bool AllowDeductionGuide,
4491 SourceLocation *TemplateKWLoc, UnqualifiedId &
Result);
4509 ExprResult tryParseCXXIdExpression(CXXScopeSpec &SS,
bool isAddressOfOperand);
4560 ExprResult ParseCXXIdExpression(
bool isAddressOfOperand =
false);
4563 bool areTokensAdjacent(
const Token &A,
const Token &B);
4567 void CheckForTemplateAndDigraph(Token &
Next,
ParsedType ObjectTypePtr,
4568 bool EnteringContext, IdentifierInfo &II,
4631 bool ParseOptionalCXXScopeSpecifier(
4632 CXXScopeSpec &SS,
ParsedType ObjectType,
bool ObjectHasErrors,
4633 bool EnteringContext,
bool *MayBePseudoDestructor =
nullptr,
4634 bool IsTypename =
false,
const IdentifierInfo **LastII =
nullptr,
4635 bool OnlyNamespace =
false,
bool InUsingDeclaration =
false,
4636 bool Disambiguation =
false,
bool IsAddressOfOperand =
false,
4637 bool IsInDeclarationContext =
false);
4639 bool ParseOptionalCXXScopeSpecifier(CXXScopeSpec &SS,
ParsedType ObjectType,
4640 bool ObjectHasErrors,
4641 bool EnteringContext,
4642 bool IsAddressOfOperand) {
4643 return ParseOptionalCXXScopeSpecifier(
4644 SS, ObjectType, ObjectHasErrors, EnteringContext,
4651 IsAddressOfOperand);
4658 enum class LambdaIntroducerTentativeParse {
4736 ParseLambdaIntroducer(LambdaIntroducer &Intro,
4737 LambdaIntroducerTentativeParse *Tentative =
nullptr);
4741 ExprResult ParseLambdaExpressionAfterIntroducer(LambdaIntroducer &Intro);
4825 ExprResult ParseCXXPseudoDestructor(Expr *Base, SourceLocation OpLoc,
4880 ExprResult ParseCXXTypeConstructExpression(
const DeclSpec &DS);
4910 void ParseCXXSimpleTypeSpecifier(DeclSpec &DS);
4925 bool ParseCXXTypeSpecifierSeq(
4943 bool ParseExpressionListOrTypeId(SmallVectorImpl<Expr *> &Exprs,
4955 void ParseDirectNewDeclarator(Declarator &D);
4988 ExprResult ParseCXXNewExpression(
bool UseGlobal, SourceLocation Start);
5003 ExprResult ParseCXXDeleteExpression(
bool UseGlobal, SourceLocation Start);
5039 Sema::ConditionResult ParseCXXCondition(
StmtResult *InitStmt,
5043 ForRangeInfo *FRI =
nullptr);
5045 ParsedAttributes &Attrs);
5092 bool isTypeIdInParens(
bool &isAmbiguous) {
5095 isAmbiguous =
false;
5096 return isTypeSpecifierQualifier(Tok);
5098 bool isTypeIdInParens() {
5100 return isTypeIdInParens(isAmbiguous);
5138 bool ParseUnqualifiedIdTemplateId(CXXScopeSpec &SS,
ParsedType ObjectType,
5139 bool ObjectHadErrors,
5140 SourceLocation TemplateKWLoc,
5141 IdentifierInfo *Name,
5142 SourceLocation NameLoc,
5143 bool EnteringContext, UnqualifiedId &Id,
5144 bool AssumeTemplateId);
5186 bool ParseUnqualifiedIdOperator(CXXScopeSpec &SS,
bool EnteringContext,
5253 bool MaybeParseHLSLAnnotations(Declarator &D,
5254 SourceLocation *EndLoc =
nullptr,
5255 bool CouldBeBitField =
false) {
5256 assert(
getLangOpts().
HLSL &&
"MaybeParseHLSLAnnotations is for HLSL only");
5257 if (Tok.is(tok::colon)) {
5258 ParsedAttributes Attrs(AttrFactory);
5259 ParseHLSLAnnotations(Attrs, EndLoc, CouldBeBitField);
5260 D.takeAttributesAppending(Attrs);
5266 void MaybeParseHLSLAnnotations(ParsedAttributes &Attrs,
5267 SourceLocation *EndLoc =
nullptr) {
5268 assert(
getLangOpts().
HLSL &&
"MaybeParseHLSLAnnotations is for HLSL only");
5269 if (Tok.is(tok::colon))
5270 ParseHLSLAnnotations(Attrs, EndLoc);
5273 struct ParsedSemantic {
5274 StringRef Name =
"";
5276 bool Explicit =
false;
5279 ParsedSemantic ParseHLSLSemantic();
5281 void ParseHLSLAnnotations(ParsedAttributes &Attrs,
5282 SourceLocation *EndLoc =
nullptr,
5283 bool CouldBeBitField =
false);
5284 Decl *ParseHLSLBuffer(SourceLocation &DeclEnd, ParsedAttributes &Attrs);
5308 ExprResult ParseInitializer(Decl *DeclForInitializer =
nullptr);
5313 bool MayBeDesignationStart();
5331 struct DesignatorCompletionInfo {
5332 SmallVectorImpl<Expr *> &InitExprs;
5333 QualType PreferredBaseType;
5382 ExprResult ParseInitializerWithPotentialDesignator(DesignatorCompletionInfo);
5387 typedef SmallVector<Expr *, 12> ExprVector;
5391 bool ParseMicrosoftIfExistsBraceInitializer(ExprVector &InitExprs,
5408 friend class ObjCDeclContextSwitch;
5411 return Actions.ObjC().getObjCDeclContext();
5417 return Actions.getNullabilityKeyword(nullability);
5433 bool InMessageExpression;
5440 bool ParsingInObjCContainer;
5445 bool isObjCInstancetype() {
5447 if (
Tok.isAnnotation())
5449 if (!Ident_instancetype)
5451 return Tok.getIdentifierInfo() == Ident_instancetype;
5459 ObjCContainerDecl *DC;
5460 SaveAndRestore<bool> WithinObjCContainer;
5465 WithinObjCContainer(P.ParsingInObjCContainer, DC !=
nullptr) {
5467 P.Actions.ObjC().ActOnObjCTemporaryExitContainerContext(DC);
5469 ~ObjCDeclContextSwitch() {
5471 P.Actions.ObjC().ActOnObjCReenterContainerContext(DC);
5475 void CheckNestedObjCContexts(SourceLocation AtLoc);
5477 void ParseLexedObjCMethodDefs(LexedMethod &LM,
bool parseMethod);
5495 DeclGroupPtrTy ParseObjCAtDirectives(ParsedAttributes &DeclAttrs,
5496 ParsedAttributes &DeclSpecAttrs);
5507 DeclGroupPtrTy ParseObjCAtClassDeclaration(SourceLocation atLoc);
5540 Decl *ParseObjCAtInterfaceDeclaration(SourceLocation AtLoc,
5541 ParsedAttributes &prefixAttrs);
5547 ObjCTypeParamList *parseObjCTypeParamList();
5575 ObjCTypeParamList *parseObjCTypeParamListOrProtocolRefs(
5577 SmallVectorImpl<IdentifierLoc> &protocolIdents, SourceLocation &rAngleLoc,
5578 bool mayBeProtocolList =
true);
5580 void HelperActionsForIvarDeclarations(ObjCContainerDecl *interfaceDecl,
5581 SourceLocation atLoc,
5583 SmallVectorImpl<Decl *> &AllIvarDecls,
5584 bool RBraceMissing);
5609 void ParseObjCClassInstanceVariables(ObjCContainerDecl *interfaceDecl,
5611 SourceLocation atLoc);
5618 bool ParseObjCProtocolReferences(
5619 SmallVectorImpl<Decl *> &P, SmallVectorImpl<SourceLocation> &PLocs,
5620 bool WarnOnDeclarations,
bool ForObjCContainer, SourceLocation &LAngleLoc,
5621 SourceLocation &EndProtoLoc,
bool consumeLastToken);
5632 void parseObjCTypeArgsOrProtocolQualifiers(
5633 ParsedType baseType, SourceLocation &typeArgsLAngleLoc,
5634 SmallVectorImpl<ParsedType> &typeArgs, SourceLocation &typeArgsRAngleLoc,
5635 SourceLocation &protocolLAngleLoc, SmallVectorImpl<Decl *> &protocols,
5636 SmallVectorImpl<SourceLocation> &protocolLocs,
5637 SourceLocation &protocolRAngleLoc,
bool consumeLastToken,
5638 bool warnOnIncompleteProtocols);
5642 void parseObjCTypeArgsAndProtocolQualifiers(
5643 ParsedType baseType, SourceLocation &typeArgsLAngleLoc,
5644 SmallVectorImpl<ParsedType> &typeArgs, SourceLocation &typeArgsRAngleLoc,
5645 SourceLocation &protocolLAngleLoc, SmallVectorImpl<Decl *> &protocols,
5646 SmallVectorImpl<SourceLocation> &protocolLocs,
5647 SourceLocation &protocolRAngleLoc,
bool consumeLastToken);
5651 TypeResult parseObjCProtocolQualifierType(SourceLocation &rAngleLoc);
5655 TypeResult parseObjCTypeArgsAndProtocolQualifiers(SourceLocation loc,
5657 bool consumeLastToken,
5658 SourceLocation &endLoc);
5694 DeclGroupPtrTy ParseObjCAtProtocolDeclaration(SourceLocation atLoc,
5695 ParsedAttributes &prefixAttrs);
5697 struct ObjCImplParsingDataRAII {
5701 typedef SmallVector<LexedMethod *, 8> LateParsedObjCMethodContainer;
5702 LateParsedObjCMethodContainer LateParsedObjCMethods;
5704 ObjCImplParsingDataRAII(
Parser &parser, Decl *D)
5705 : P(parser), Dcl(D), HasCFunction(
false) {
5706 P.CurParsedObjCImpl =
this;
5709 ~ObjCImplParsingDataRAII();
5711 void finish(SourceRange AtEnd);
5712 bool isFinished()
const {
return Finished; }
5717 ObjCImplParsingDataRAII *CurParsedObjCImpl;
5721 void StashAwayMethodOrFunctionBodyTokens(Decl *MDecl);
5735 DeclGroupPtrTy ParseObjCAtImplementationDeclaration(SourceLocation AtLoc,
5736 ParsedAttributes &Attrs);
5744 Decl *ParseObjCAtAliasDeclaration(SourceLocation atLoc);
5759 Decl *ParseObjCPropertySynthesize(SourceLocation atLoc);
5770 Decl *ParseObjCPropertyDynamic(SourceLocation atLoc);
5782 IdentifierInfo *ParseObjCSelectorPiece(SourceLocation &MethodLocation);
5790 bool isTokIdentifier_in()
const;
5799 ParsedAttributes *ParamAttrs);
5813 Decl *ParseObjCMethodPrototype(
5815 bool MethodDefinition =
true);
5847 Decl *ParseObjCMethodDecl(
5850 bool MethodDefinition =
true);
5880 void ParseObjCPropertyAttribute(ObjCDeclSpec &DS);
5886 Decl *ParseObjCMethodDefinition();
5890 ExprResult ParseObjCAtExpression(SourceLocation AtLocation);
5891 ExprResult ParseObjCStringLiteral(SourceLocation AtLoc);
5898 ExprResult ParseObjCCharacterLiteral(SourceLocation AtLoc);
5907 ExprResult ParseObjCNumericLiteral(SourceLocation AtLoc);
5916 ExprResult ParseObjCBooleanLiteral(SourceLocation AtLoc,
bool ArgValue);
5918 ExprResult ParseObjCArrayLiteral(SourceLocation AtLoc);
5919 ExprResult ParseObjCDictionaryLiteral(SourceLocation AtLoc);
5926 ExprResult ParseObjCBoxedExpr(SourceLocation AtLoc);
5932 ExprResult ParseObjCEncodeExpression(SourceLocation AtLoc);
5938 ExprResult ParseObjCSelectorExpression(SourceLocation AtLoc);
5944 ExprResult ParseObjCProtocolExpression(SourceLocation AtLoc);
5951 bool isSimpleObjCMessageExpression();
6006 ExprResult ParseObjCMessageExpressionBody(SourceLocation LBracloc,
6007 SourceLocation SuperLoc,
6009 Expr *ReceiverExpr);
6035 bool ParseObjCXXMessageReceiver(
bool &IsExpr,
void *&TypeOrExpr);
6040 enum class ParsedStmtContext;
6042 StmtResult ParseObjCAtStatement(SourceLocation atLoc,
6043 ParsedStmtContext StmtCtx);
6058 StmtResult ParseObjCTryStmt(SourceLocation atLoc);
6065 StmtResult ParseObjCThrowStmt(SourceLocation atLoc);
6072 StmtResult ParseObjCSynchronizedStmt(SourceLocation atLoc);
6079 StmtResult ParseObjCAutoreleasePoolStmt(SourceLocation atLoc);
6106 bool isStartOfObjCClassMessageMissingOpenBracket();
6138 bool OpenACCDirectiveParsing =
false;
6142 bool AllowOpenACCArraySections =
false;
6146 class OpenACCArraySectionRAII {
6150 OpenACCArraySectionRAII(
Parser &P) : P(P) {
6151 assert(!P.AllowOpenACCArraySections);
6152 P.AllowOpenACCArraySections =
true;
6154 ~OpenACCArraySectionRAII() {
6155 assert(P.AllowOpenACCArraySections);
6156 P.AllowOpenACCArraySections =
false;
6163 struct OpenACCDirectiveParseInfo {
6165 SourceLocation StartLoc;
6166 SourceLocation DirLoc;
6167 SourceLocation LParenLoc;
6168 SourceLocation RParenLoc;
6169 SourceLocation EndLoc;
6170 SourceLocation MiscLoc;
6172 SmallVector<Expr *> Exprs;
6173 SmallVector<OpenACCClause *> Clauses;
6178 struct OpenACCWaitParseInfo {
6179 bool Failed =
false;
6180 Expr *DevNumExpr =
nullptr;
6181 SourceLocation QueuesLoc;
6182 SmallVector<Expr *> QueueIdExprs;
6184 SmallVector<Expr *> getAllExprs() {
6185 SmallVector<Expr *>
Out;
6186 Out.push_back(DevNumExpr);
6187 llvm::append_range(Out, QueueIdExprs);
6191 struct OpenACCCacheParseInfo {
6192 bool Failed =
false;
6193 SourceLocation ReadOnlyLoc;
6194 SmallVector<Expr *> Vars;
6199 enum class OpenACCParseCanContinue { Cannot = 0, Can = 1 };
6205 using OpenACCClauseParseResult =
6206 llvm::PointerIntPair<OpenACCClause *, 1, OpenACCParseCanContinue>;
6208 OpenACCClauseParseResult OpenACCCanContinue();
6209 OpenACCClauseParseResult OpenACCCannotContinue();
6210 OpenACCClauseParseResult OpenACCSuccess(OpenACCClause *Clause);
6214 OpenACCDirectiveParseInfo ParseOpenACCDirective();
6224 OpenACCCacheParseInfo ParseOpenACCCacheVarList();
6230 using OpenACCVarParseResult = std::pair<ExprResult, OpenACCParseCanContinue>;
6256 OpenACCClauseParseResult
6257 ParseOpenACCClauseParams(ArrayRef<const OpenACCClause *> ExistingClauses,
6259 SourceLocation ClauseLoc);
6263 OpenACCClauseParseResult
6264 ParseOpenACCClause(ArrayRef<const OpenACCClause *> ExistingClauses,
6274 SmallVector<OpenACCClause *>
6283 OpenACCWaitParseInfo ParseOpenACCWaitArgument(SourceLocation Loc,
6288 std::variant<std::monostate, StringLiteral *, IdentifierInfo *>
6289 ParseOpenACCBindClauseArgument();
6294 using OpenACCIntExprParseResult =
6295 std::pair<ExprResult, OpenACCParseCanContinue>;
6300 SourceLocation Loc);
6305 llvm::SmallVectorImpl<Expr *> &IntExprs);
6318 bool ParseOpenACCDeviceTypeList(llvm::SmallVector<IdentifierLoc> &Archs);
6332 SourceLocation Loc);
6347 llvm::SmallVectorImpl<Expr *> &SizeExprs);
6359 bool ParseOpenACCGangArgList(SourceLocation GangLoc,
6360 llvm::SmallVectorImpl<OpenACCGangKind> &GKs,
6361 llvm::SmallVectorImpl<Expr *> &IntExprs);
6363 using OpenACCGangArgRes = std::pair<OpenACCGangKind, ExprResult>;
6367 OpenACCGangArgRes ParseOpenACCGangArg(SourceLocation GangLoc);
6371 ParseOpenACCAfterRoutineDecl(
AccessSpecifier &AS, ParsedAttributes &Attrs,
6373 OpenACCDirectiveParseInfo &DirInfo);
6374 StmtResult ParseOpenACCAfterRoutineStmt(OpenACCDirectiveParseInfo &DirInfo);
6392 bool OpenMPDirectiveParsing =
false;
6397 void ReplayOpenMPAttributeTokens(
CachedTokens &OpenMPTokens) {
6400 if (!OpenMPTokens.empty()) {
6401 PP.EnterToken(Tok,
true);
6402 PP.EnterTokenStream(OpenMPTokens,
true,
6414 SourceLocation Loc);
6419 llvm::omp::TraitSet
Set,
6420 llvm::omp::TraitSelector Selector,
6421 llvm::StringMap<SourceLocation> &Seen);
6425 llvm::omp::TraitSet
Set,
6426 llvm::StringMap<SourceLocation> &Seen);
6430 llvm::StringMap<SourceLocation> &Seen);
6434 llvm::omp::TraitSet
Set,
6435 llvm::StringMap<SourceLocation> &Seen);
6443 llvm::omp::TraitSet
Set,
6444 llvm::StringMap<SourceLocation> &SeenSelectors);
6451 void parseOMPContextSelectorSet(
OMPTraitSet &TISet,
6452 llvm::StringMap<SourceLocation> &SeenSets);
6459 bool parseOMPContextSelectors(SourceLocation Loc,
OMPTraitInfo &TI);
6462 bool parseOpenMPAppendArgs(SmallVectorImpl<OMPInteropInfo> &InteropInfos);
6466 bool parseOMPDeclareVariantMatchClause(SourceLocation Loc,
OMPTraitInfo &TI,
6472 SourceLocation Loc);
6491 void ParseOpenMPAssumesDirective(OpenMPDirectiveKind DKind,
6492 SourceLocation Loc);
6495 void ParseOpenMPEndAssumesDirective(SourceLocation Loc);
6512 void ParseOpenMPClauses(OpenMPDirectiveKind DKind,
6513 SmallVectorImpl<clang::OMPClause *> &Clauses,
6514 SourceLocation Loc);
6517 void ParseOMPDeclareTargetClauses(SemaOpenMP::DeclareTargetContextInfo &DTCI);
6520 void ParseOMPEndDeclareTargetDirective(OpenMPDirectiveKind BeginDKind,
6521 OpenMPDirectiveKind EndDKind,
6522 SourceLocation Loc);
6526 void skipUntilPragmaOpenMPEnd(OpenMPDirectiveKind DKind);
6532 void parseOMPEndDirective(OpenMPDirectiveKind BeginKind,
6533 OpenMPDirectiveKind ExpectedKind,
6534 OpenMPDirectiveKind FoundKind,
6535 SourceLocation MatchingLoc, SourceLocation FoundLoc,
6536 bool SkipUntilOpenMPEnd);
6577 AccessSpecifier &AS, ParsedAttributes &Attrs,
bool Delayed =
false,
6579 Decl *TagDecl =
nullptr);
6593 DeclGroupPtrTy ParseOpenMPDeclareReductionDirective(AccessSpecifier AS);
6597 void ParseOpenMPReductionInitializerForDecl(VarDecl *OmpPrivParm);
6609 DeclGroupPtrTy ParseOpenMPDeclareMapperDirective(AccessSpecifier AS);
6612 TypeResult parseOpenMPDeclareMapperVarDecl(SourceRange &Range,
6613 DeclarationName &Name,
6614 AccessSpecifier AS =
AS_none);
6628 bool ParseOpenMPSimpleVarList(
6629 OpenMPDirectiveKind Kind,
6630 const llvm::function_ref<
void(CXXScopeSpec &, DeclarationNameInfo)>
6632 bool AllowScopeSpecifier);
6681 StmtResult ParseOpenMPDeclarativeOrExecutableDirective(
6682 ParsedStmtContext StmtCtx,
bool ReadDirectiveWithinMetadirective =
false);
6692 ParseOpenMPExecutableDirective(ParsedStmtContext StmtCtx,
6693 OpenMPDirectiveKind DKind, SourceLocation Loc,
6694 bool ReadDirectiveWithinMetadirective);
6703 StmtResult ParseOpenMPInformationalDirective(
6704 ParsedStmtContext StmtCtx, OpenMPDirectiveKind DKind, SourceLocation Loc,
6705 bool ReadDirectiveWithinMetadirective);
6734 OMPClause *ParseOpenMPClause(OpenMPDirectiveKind DKind,
6819 bool ParseOpenMPIndirectClause(SemaOpenMP::DeclareTargetContextInfo &DTCI,
6844 OMPClause *ParseOpenMPSingleExprWithArgClause(OpenMPDirectiveKind DKind,
6849 OMPClause *ParseOpenMPLoopRangeClause();
6858 OMPClause *ParseOpenMPPermutationClause();
6962 OMPClause *ParseOpenMPVarListClause(OpenMPDirectiveKind DKind,
6976 SourceLocation &ClauseNameLoc,
6977 SourceLocation &OpenLoc,
6978 SourceLocation &CloseLoc,
6979 SmallVectorImpl<Expr *> &Exprs,
6980 bool ReqIntConst =
false);
6995 OMPClause *ParseOpenMPUsesAllocatorClause(OpenMPDirectiveKind DKind);
6998 bool ParseOMPInteropInfo(OMPInteropInfo &InteropInfo,
OpenMPClauseKind Kind);
7036 OMPClause *ParseOpenMPOMPXAttributesClause(
bool ParseOnly);
7043 bool IsAddressOfOperand =
false);
7047 SemaOpenMP::OpenMPVarListDataTy &
Data,
7048 const LangOptions &LangOpts);
7051 SmallVectorImpl<Expr *> &Vars,
7052 SemaOpenMP::OpenMPVarListDataTy &
Data);
7087 std::unique_ptr<PragmaHandler> AlignHandler;
7088 std::unique_ptr<PragmaHandler> GCCVisibilityHandler;
7089 std::unique_ptr<PragmaHandler> OptionsHandler;
7090 std::unique_ptr<PragmaHandler> PackHandler;
7091 std::unique_ptr<PragmaHandler> MSStructHandler;
7092 std::unique_ptr<PragmaHandler> UnusedHandler;
7093 std::unique_ptr<PragmaHandler> WeakHandler;
7094 std::unique_ptr<PragmaHandler> RedefineExtnameHandler;
7095 std::unique_ptr<PragmaHandler> FPContractHandler;
7096 std::unique_ptr<PragmaHandler> OpenCLExtensionHandler;
7097 std::unique_ptr<PragmaHandler> OpenMPHandler;
7098 std::unique_ptr<PragmaHandler> OpenACCHandler;
7099 std::unique_ptr<PragmaHandler> PCSectionHandler;
7100 std::unique_ptr<PragmaHandler> MSCommentHandler;
7101 std::unique_ptr<PragmaHandler> MSDetectMismatchHandler;
7102 std::unique_ptr<PragmaHandler> FPEvalMethodHandler;
7103 std::unique_ptr<PragmaHandler> FloatControlHandler;
7104 std::unique_ptr<PragmaHandler> MSPointersToMembers;
7105 std::unique_ptr<PragmaHandler> MSVtorDisp;
7106 std::unique_ptr<PragmaHandler> MSInitSeg;
7107 std::unique_ptr<PragmaHandler> MSDataSeg;
7108 std::unique_ptr<PragmaHandler> MSBSSSeg;
7109 std::unique_ptr<PragmaHandler> MSConstSeg;
7110 std::unique_ptr<PragmaHandler> MSCodeSeg;
7111 std::unique_ptr<PragmaHandler> MSSection;
7112 std::unique_ptr<PragmaHandler> MSStrictGuardStackCheck;
7113 std::unique_ptr<PragmaHandler> MSRuntimeChecks;
7114 std::unique_ptr<PragmaHandler> MSIntrinsic;
7115 std::unique_ptr<PragmaHandler> MSFunction;
7116 std::unique_ptr<PragmaHandler> MSOptimize;
7117 std::unique_ptr<PragmaHandler> MSFenvAccess;
7118 std::unique_ptr<PragmaHandler> MSAllocText;
7119 std::unique_ptr<PragmaHandler> CUDAForceHostDeviceHandler;
7120 std::unique_ptr<PragmaHandler> OptimizeHandler;
7121 std::unique_ptr<PragmaHandler> LoopHintHandler;
7122 std::unique_ptr<PragmaHandler> UnrollHintHandler;
7123 std::unique_ptr<PragmaHandler> NoUnrollHintHandler;
7124 std::unique_ptr<PragmaHandler> UnrollAndJamHintHandler;
7125 std::unique_ptr<PragmaHandler> NoUnrollAndJamHintHandler;
7126 std::unique_ptr<PragmaHandler> FPHandler;
7127 std::unique_ptr<PragmaHandler> STDCFenvAccessHandler;
7128 std::unique_ptr<PragmaHandler> STDCFenvRoundHandler;
7129 std::unique_ptr<PragmaHandler> STDCCXLIMITHandler;
7130 std::unique_ptr<PragmaHandler> STDCUnknownHandler;
7131 std::unique_ptr<PragmaHandler> AttributePragmaHandler;
7132 std::unique_ptr<PragmaHandler> MaxTokensHerePragmaHandler;
7133 std::unique_ptr<PragmaHandler> MaxTokensTotalPragmaHandler;
7134 std::unique_ptr<PragmaHandler> ExportHandler;
7135 std::unique_ptr<PragmaHandler> RISCVPragmaHandler;
7138 void initializePragmaHandlers();
7141 void resetPragmaHandlers();
7148 void HandlePragmaUnused();
7152 void HandlePragmaVisibility();
7156 void HandlePragmaPack();
7160 void HandlePragmaMSStruct();
7162 void HandlePragmaMSPointersToMembers();
7164 void HandlePragmaMSVtorDisp();
7166 void HandlePragmaMSPragma();
7167 bool HandlePragmaMSSection(StringRef PragmaName,
7168 SourceLocation PragmaLocation);
7169 bool HandlePragmaMSSegment(StringRef PragmaName,
7170 SourceLocation PragmaLocation);
7173 bool HandlePragmaMSInitSeg(StringRef PragmaName,
7174 SourceLocation PragmaLocation);
7179 bool HandlePragmaMSStrictGuardStackCheck(StringRef PragmaName,
7180 SourceLocation PragmaLocation);
7181 bool HandlePragmaMSFunction(StringRef PragmaName,
7182 SourceLocation PragmaLocation);
7183 bool HandlePragmaMSAllocText(StringRef PragmaName,
7184 SourceLocation PragmaLocation);
7187 bool HandlePragmaMSOptimize(StringRef PragmaName,
7188 SourceLocation PragmaLocation);
7191 bool HandlePragmaMSIntrinsic(StringRef PragmaName,
7192 SourceLocation PragmaLocation);
7196 void HandlePragmaAlign();
7200 void HandlePragmaDump();
7204 void HandlePragmaWeak();
7208 void HandlePragmaWeakAlias();
7212 void HandlePragmaRedefineExtname();
7216 void HandlePragmaFPContract();
7220 void HandlePragmaFEnvAccess();
7224 void HandlePragmaFEnvRound();
7228 void HandlePragmaCXLimitedRange();
7232 void HandlePragmaFloatControl();
7236 void HandlePragmaFP();
7240 void HandlePragmaOpenCLExtension();
7244 StmtResult HandlePragmaCaptured();
7248 bool HandlePragmaLoopHint(LoopHint &Hint);
7250 bool ParsePragmaAttributeSubjectMatchRuleSet(
7252 SourceLocation &AnyLoc, SourceLocation &LastMatchRuleEndLoc);
7254 void HandlePragmaAttribute();
7260 void HandlePragmaExport();
7286 enum class ParsedStmtContext {
7289 AllowDeclarationsInC = 0x1,
7291 AllowStandaloneOpenMPDirectives = 0x2,
7298 Compound = AllowDeclarationsInC | AllowStandaloneOpenMPDirectives,
7315 ParsedStmtContext StmtCtx = ParsedStmtContext::SubStmt,
7370 ParseStatementOrDeclaration(
StmtVector &Stmts, ParsedStmtContext StmtCtx,
7374 StmtResult ParseStatementOrDeclarationAfterAttributes(
7375 StmtVector &Stmts, ParsedStmtContext StmtCtx,
7380 StmtResult ParseExprStatement(ParsedStmtContext StmtCtx);
7394 ParsedStmtContext StmtCtx);
7403 StmtResult ParseCaseStatement(ParsedStmtContext StmtCtx,
7404 bool MissingCase =
false,
7414 StmtResult ParseDefaultStatement(ParsedStmtContext StmtCtx);
7416 StmtResult ParseCompoundStatement(
bool isStmtExpr =
false);
7442 StmtResult ParseCompoundStatement(
bool isStmtExpr,
unsigned ScopeFlags);
7447 void ParseCompoundStatementLeadingPragmas();
7449 void DiagnoseLabelAtEndOfCompoundStatement();
7459 StmtResult ParseCompoundStatementBody(
bool isStmtExpr =
false);
7477 bool ParseParenExprOrCondition(
StmtResult *InitStmt,
7593 StmtResult ParseBreakOrContinueStatement(
bool IsContinue);
7610 void ParseMicrosoftIfExistsStatement(
StmtVector &Stmts);
7657 StmtResult ParseCXXCatchBlock(
bool FnCatch =
false);
7695 Decl *ParseFunctionStatementBody(
Decl *
Decl, ParseScope &BodyScope);
7704 Decl *ParseFunctionTryBlock(
Decl *
Decl, ParseScope &BodyScope);
7710 bool trySkippingFunctionBody();
7718 bool isDeclarationStatement(
bool DisambiguatingWithExpression =
false) {
7720 return isCXXDeclarationStatement(DisambiguatingWithExpression);
7728 bool isForInitDeclaration() {
7732 return Tok.is(tok::kw_using) ||
7733 isCXXSimpleDeclaration(
true);
7738 bool isForRangeIdentifier();
7755 unsigned &NumLineToksConsumed,
7756 bool IsUnevaluated);
7799 StmtResult ParseMicrosoftAsmStatement(SourceLocation AsmLoc);
7815 bool ParseAsmOperandsOpt(SmallVectorImpl<IdentifierInfo *> &Names,
7816 SmallVectorImpl<Expr *> &Constraints,
7817 SmallVectorImpl<Expr *> &Exprs);
7819 class GNUAsmQualifiers {
7820 unsigned Qualifiers = AQ_unspecified;
7829 static const char *getQualifierName(AQ Qualifier);
7830 bool setAsmQualifier(AQ Qualifier);
7831 inline bool isVolatile()
const {
return Qualifiers & AQ_volatile; };
7832 inline bool isInline()
const {
return Qualifiers & AQ_inline; };
7833 inline bool isGoto()
const {
return Qualifiers & AQ_goto; }
7837 bool isGCCAsmStatement(
const Token &TokAfterAsm)
const;
7839 bool isGNUAsmQualifier(
const Token &TokAfterAsm)
const;
7840 GNUAsmQualifiers::AQ getGNUAsmQualifier(
const Token &Tok)
const;
7853 bool parseGNUAsmQualifierListOpt(GNUAsmQualifiers &AQ);
7877 unsigned TemplateParameterDepth;
7880 class TemplateParameterDepthRAII {
7882 unsigned AddedLevels;
7885 explicit TemplateParameterDepthRAII(
unsigned &Depth)
7886 : Depth(Depth), AddedLevels(0) {}
7888 ~TemplateParameterDepthRAII() { Depth -= AddedLevels; }
7894 void addDepth(
unsigned D) {
7898 void setAddedDepth(
unsigned D) {
7899 Depth = Depth - AddedLevels + D;
7903 unsigned getDepth()
const {
return Depth; }
7904 unsigned getOriginalDepth()
const {
return Depth - AddedLevels; }
7909 SmallVector<TemplateIdAnnotation *, 16> TemplateIds;
7915 bool DelayTemplateIdDestruction =
false;
7917 void MaybeDestroyTemplateIds() {
7918 if (DelayTemplateIdDestruction)
7920 if (!TemplateIds.empty() &&
7921 (Tok.is(tok::eof) || !PP.mightHavePendingAnnotationTokens()))
7922 DestroyTemplateIds();
7924 void DestroyTemplateIds();
7928 struct DestroyTemplateIdAnnotationsRAIIObj {
7931 DestroyTemplateIdAnnotationsRAIIObj(
Parser &Self) : Self(Self) {}
7932 ~DestroyTemplateIdAnnotationsRAIIObj() { Self.MaybeDestroyTemplateIds(); }
7935 struct DelayTemplateIdDestructionRAII {
7937 bool PrevDelayTemplateIdDestruction;
7939 DelayTemplateIdDestructionRAII(
Parser &Self,
7940 bool DelayTemplateIdDestruction) noexcept
7942 PrevDelayTemplateIdDestruction(Self.DelayTemplateIdDestruction) {
7943 Self.DelayTemplateIdDestruction = DelayTemplateIdDestruction;
7946 ~DelayTemplateIdDestructionRAII() noexcept {
7947 Self.DelayTemplateIdDestruction = PrevDelayTemplateIdDestruction;
7952 SmallVector<const IdentifierInfo *, 8> TentativelyDeclaredIdentifiers;
7964 struct AngleBracketTracker {
7967 enum Priority :
unsigned short {
7969 PotentialTypo = 0x0,
7971 DependentName = 0x2,
7974 SpaceBeforeLess = 0x0,
7976 NoSpaceBeforeLess = 0x1,
8007 if (!Locs.empty() && Locs.back().isActive(P)) {
8008 if (Locs.back().Priority <= Prio) {
8010 Locs.back().LessLoc = LessLoc;
8011 Locs.back().Priority = Prio;
8014 Locs.push_back({
TemplateName, LessLoc, Prio, P.ParenCount,
8015 P.BracketCount, P.BraceCount});
8023 while (!Locs.empty() && Locs.back().isActiveOrNested(P))
8030 if (!Locs.empty() && Locs.back().isActive(P))
8031 return &Locs.back();
8036 AngleBracketTracker AngleBrackets;
8041 struct ParsedTemplateInfo {
8042 ParsedTemplateInfo()
8046 bool isSpecialization,
8047 bool lastParameterListWasEmpty =
false)
8050 TemplateParams(TemplateParams),
8051 LastParameterListWasEmpty(lastParameterListWasEmpty) {}
8053 explicit ParsedTemplateInfo(SourceLocation ExternLoc,
8054 SourceLocation TemplateLoc)
8056 TemplateParams(
nullptr), ExternLoc(ExternLoc),
8057 TemplateLoc(TemplateLoc), LastParameterListWasEmpty(
false) {}
8067 SourceLocation ExternLoc;
8071 SourceLocation TemplateLoc;
8074 bool LastParameterListWasEmpty;
8076 SourceRange getSourceRange() const LLVM_READONLY;
8080 void LexTemplateFunctionForLateParsing(
CachedTokens &Toks);
8083 void ParseLateTemplatedFuncDef(LateParsedTemplate &LPT);
8085 static
void LateTemplateParserCallback(
void *P, LateParsedTemplate &LPT);
8093 void checkPotentialAngleBracket(
ExprResult &PotentialTemplateName);
8094 bool checkPotentialAngleBracketDelimiter(const AngleBracketTracker::Loc &,
8095 const Token &OpToken);
8096 bool checkPotentialAngleBracketDelimiter(const Token &OpToken) {
8097 if (
auto *Info = AngleBrackets.getCurrent(*
this))
8098 return checkPotentialAngleBracketDelimiter(*Info, OpToken);
8109 SourceLocation &DeclEnd,
8110 ParsedAttributes &AccessAttrs);
8157 ParsingDeclRAIIObject &DiagsFromParams, SourceLocation &DeclEnd,
8169 bool ParseTemplateParameters(MultiParseScope &TemplateScopes,
unsigned Depth,
8170 SmallVectorImpl<NamedDecl *> &TemplateParams,
8171 SourceLocation &LAngleLoc,
8172 SourceLocation &RAngleLoc);
8184 bool ParseTemplateParameterList(
unsigned Depth,
8185 SmallVectorImpl<NamedDecl *> &TemplateParams);
8187 enum class TPResult;
8191 TPResult isStartOfTemplateTypeParameter();
8215 NamedDecl *ParseTemplateParameter(
unsigned Depth,
unsigned Position);
8228 NamedDecl *ParseTypeParameter(
unsigned Depth,
unsigned Position);
8244 NamedDecl *ParseTemplateTemplateParameter(
unsigned Depth,
unsigned Position);
8254 NamedDecl *ParseNonTypeTemplateParameter(
unsigned Depth,
unsigned Position);
8258 bool isTypeConstraintAnnotation();
8270 bool TryAnnotateTypeConstraint();
8272 void DiagnoseMisplacedEllipsis(SourceLocation EllipsisLoc,
8273 SourceLocation CorrectLoc,
8274 bool AlreadyHasEllipsis,
8275 bool IdentifierHasName);
8276 void DiagnoseMisplacedEllipsisInDeclarator(SourceLocation EllipsisLoc,
8279 typedef SmallVector<ParsedTemplateArgument, 16> TemplateArgList;
8296 bool ParseGreaterThanInTemplateList(SourceLocation LAngleLoc,
8297 SourceLocation &RAngleLoc,
8298 bool ConsumeLastToken,
8299 bool ObjCGenericList);
8312 bool ParseTemplateIdAfterTemplateName(
bool ConsumeLastToken,
8313 SourceLocation &LAngleLoc,
8314 TemplateArgList &TemplateArgs,
8315 SourceLocation &RAngleLoc,
8360 CXXScopeSpec &SS, SourceLocation TemplateKWLoc,
8362 bool AllowTypeAnnotation =
true,
8363 bool TypeConstraint =
false);
8381 AnnotateTemplateIdTokenAsType(CXXScopeSpec &SS,
8383 bool IsClassName =
false);
8395 bool ParseTemplateArgumentList(TemplateArgList &TemplateArgs,
8399 ParsedTemplateArgument ParseTemplateTemplateArgument();
8411 ParsedTemplateArgument ParseTemplateArgument();
8423 SourceLocation ExternLoc,
8424 SourceLocation TemplateLoc,
8425 SourceLocation &DeclEnd,
8426 ParsedAttributes &AccessAttrs,
8435 Decl *ParseConceptDefinition(
const ParsedTemplateInfo &TemplateInfo,
8436 SourceLocation &DeclEnd);
8464 class TentativeParsingAction {
8466 PreferredTypeBuilder PrevPreferredType;
8468 size_t PrevTentativelyDeclaredIdentifierCount;
8469 unsigned short PrevParenCount, PrevBracketCount, PrevBraceCount;
8473 explicit TentativeParsingAction(Parser &p,
bool Unannotated =
false)
8474 : P(p), PrevPreferredType(P.PreferredType) {
8476 PrevTentativelyDeclaredIdentifierCount =
8477 P.TentativelyDeclaredIdentifiers.size();
8478 PrevParenCount = P.ParenCount;
8479 PrevBracketCount = P.BracketCount;
8480 PrevBraceCount = P.BraceCount;
8481 P.PP.EnableBacktrackAtThisPos(Unannotated);
8485 assert(isActive &&
"Parsing action was finished!");
8486 P.TentativelyDeclaredIdentifiers.resize(
8487 PrevTentativelyDeclaredIdentifierCount);
8488 P.PP.CommitBacktrackedTokens();
8492 assert(isActive &&
"Parsing action was finished!");
8494 P.PreferredType = PrevPreferredType;
8496 P.TentativelyDeclaredIdentifiers.resize(
8497 PrevTentativelyDeclaredIdentifierCount);
8498 P.ParenCount = PrevParenCount;
8499 P.BracketCount = PrevBracketCount;
8500 P.BraceCount = PrevBraceCount;
8503 ~TentativeParsingAction() {
8504 assert(!isActive &&
"Forgot to call Commit or Revert!");
8510 class RevertingTentativeParsingAction
8511 :
private Parser::TentativeParsingAction {
8513 using TentativeParsingAction::TentativeParsingAction;
8515 ~RevertingTentativeParsingAction() { Revert(); }
8550 bool isCXXDeclarationStatement(
bool DisambiguatingWithExpression =
false);
8576 bool isCXXSimpleDeclaration(
bool AllowForRangeDecl);
8589 bool isCXXFunctionDeclarator(
bool *IsAmbiguous =
nullptr,
8593 struct ConditionDeclarationOrInitStatementState;
8594 enum class ConditionOrInitStatement {
8621 ConditionOrInitStatement
8622 isCXXConditionDeclarationOrInitStatement(
bool CanBeInitStmt,
8623 bool CanBeForRangeDecl);
8649 return isCXXTypeId(Context, isAmbiguous);
8663 bool isEnumBase(
bool AllowSemi);
8783 TPResult BracedCastResult = TPResult::False,
8784 bool *InvalidAsDeclSpec =
nullptr);
8789 bool isCXXDeclarationSpecifierAType();
8795 TPResult isTemplateArgumentList(
unsigned TokensToSkip);
8800 TPResult isExplicitBool();
8805 bool isTentativelyDeclared(IdentifierInfo *II);
8824 TPResult TryParseSimpleDeclaration(
bool AllowForRangeDecl);
8832 TPResult TryParseTypeofSpecifier();
8836 TPResult TryParseProtocolQualifiers();
8838 TPResult TryParsePtrOperatorSeq();
8860 TPResult TryParseOperatorId();
8891 TPResult TryParseInitDeclaratorList(
bool MayHaveTrailingReturnType =
false);
8948 TPResult TryParseDeclarator(
bool mayBeAbstract,
bool mayHaveIdentifier =
true,
8949 bool mayHaveDirectInit =
false,
8950 bool mayHaveTrailingReturnType =
false);
8971 TPResult TryParseParameterDeclarationClause(
8972 bool *InvalidAsDeclaration =
nullptr,
bool VersusTemplateArg =
false,
8989 TPResult TryParseFunctionDeclarator(
bool MayHaveTrailingReturnType =
false);
8995 bool NameAfterArrowIsNonType();
9001 TPResult TryParseBracketDeclarator();
9005 TPResult TryConsumeDeclarationSpecifier();
9009 bool TrySkipAttributes();
9051 isCXX11AttributeSpecifier(
bool Disambiguate =
false,
9052 bool OuterMightBeMessageSend =
false);