215 return Actions.incrementMSManglingNumber();
264 assert(!isTokenSpecial() &&
265 "Should consume special tokens with Consume*Token");
266 PrevTokLocation = Tok.getLocation();
268 return PrevTokLocation;
274 assert(!isTokenSpecial() &&
275 "Should consume special tokens with Consume*Token");
276 PrevTokLocation = Tok.getLocation();
284 Loc = PrevTokLocation;
293 return ConsumeParen();
294 if (isTokenBracket())
295 return ConsumeBracket();
297 return ConsumeBrace();
298 if (isTokenStringLiteral())
299 return ConsumeStringToken();
300 if (Tok.is(tok::code_completion))
301 return ConsumeCodeCompletionTok ? ConsumeCodeCompletionToken()
302 : handleUnexpectedCodeCompletionToken();
303 if (Tok.isAnnotation())
304 return ConsumeAnnotationToken();
318 if (N == 0 || Tok.is(tok::eof))
320 return PP.LookAhead(N - 1);
329 if (!Tok.getAnnotationValue())
364 bool IsAddressOfOperand =
false);
390 (Tok.is(tok::identifier) || Tok.is(tok::coloncolon) ||
391 (Tok.is(tok::annot_template_id) &&
393 Tok.is(tok::kw_decltype) || Tok.is(tok::kw___super));
410 ParseScope(
const ParseScope &) =
delete;
411 void operator=(
const ParseScope &) =
delete;
418 bool BeforeCompoundStmt =
false)
420 if (EnteredScope && !BeforeCompoundStmt)
421 Self->EnterScope(ScopeFlags);
423 if (BeforeCompoundStmt)
424 Self->incrementMSManglingNumber();
426 this->Self = nullptr;
444 class MultiParseScope {
446 unsigned NumScopes = 0;
448 MultiParseScope(
const MultiParseScope &) =
delete;
453 Self.EnterScope(ScopeFlags);
495 static_cast<unsigned>(R));
550 unsigned short ParenCount = 0, BracketCount = 0,
BraceCount = 0;
551 unsigned short MisplacedModuleBeginCount = 0;
562 static constexpr int ScopeCacheSize = 16;
563 unsigned NumCachedScopes;
564 Scope *ScopeCache[ScopeCacheSize];
570 *Ident_GetExceptionCode;
573 *Ident_GetExceptionInfo;
575 IdentifierInfo *Ident__abnormal_termination, *Ident___abnormal_termination,
576 *Ident_AbnormalTermination;
581 std::unique_ptr<CommentHandler> CommentSemaHandler;
586 bool CalledSignatureHelp =
false;
594 bool SkipFunctionBodies;
601 bool isTokenParen()
const {
return Tok.isOneOf(tok::l_paren, tok::r_paren); }
603 bool isTokenBracket()
const {
604 return Tok.isOneOf(tok::l_square, tok::r_square);
607 bool isTokenBrace()
const {
return Tok.isOneOf(tok::l_brace, tok::r_brace); }
609 bool isTokenStringLiteral()
const {
613 bool isTokenSpecial()
const {
614 return isTokenStringLiteral() || isTokenParen() || isTokenBracket() ||
615 isTokenBrace() || Tok.is(tok::code_completion) || Tok.isAnnotation();
620 bool isTokenEqualOrEqualTypo();
624 void UnconsumeToken(Token &Consumed) {
626 PP.EnterToken(Consumed,
true);
628 PP.EnterToken(
Next,
true);
631 SourceLocation ConsumeAnnotationToken() {
632 assert(Tok.isAnnotation() &&
"wrong consume method");
633 SourceLocation Loc = Tok.getLocation();
634 PrevTokLocation = Tok.getAnnotationEndLoc();
641 SourceLocation ConsumeParen() {
642 assert(isTokenParen() &&
"wrong consume method");
643 if (Tok.getKind() == tok::l_paren)
645 else if (ParenCount) {
646 AngleBrackets.clear(*
this);
649 PrevTokLocation = Tok.getLocation();
651 return PrevTokLocation;
656 SourceLocation ConsumeBracket() {
657 assert(isTokenBracket() &&
"wrong consume method");
658 if (Tok.getKind() == tok::l_square)
660 else if (BracketCount) {
661 AngleBrackets.clear(*
this);
665 PrevTokLocation = Tok.getLocation();
667 return PrevTokLocation;
672 SourceLocation ConsumeBrace() {
673 assert(isTokenBrace() &&
"wrong consume method");
674 if (Tok.getKind() == tok::l_brace)
676 else if (BraceCount) {
677 AngleBrackets.clear(*
this);
681 PrevTokLocation = Tok.getLocation();
683 return PrevTokLocation;
690 SourceLocation ConsumeStringToken() {
691 assert(isTokenStringLiteral() &&
692 "Should only consume string literals with this method");
693 PrevTokLocation = Tok.getLocation();
695 return PrevTokLocation;
703 SourceLocation ConsumeCodeCompletionToken() {
704 assert(Tok.is(tok::code_completion));
705 PrevTokLocation = Tok.getLocation();
707 return PrevTokLocation;
715 SourceLocation handleUnexpectedCodeCompletionToken();
719 void cutOffParsing() {
720 if (PP.isCodeCompletionEnabled())
721 PP.setCodeCompletionReached();
723 Tok.setKind(tok::eof);
730 return Kind == tok::eof ||
Kind == tok::annot_module_begin ||
731 Kind == tok::annot_module_end ||
Kind == tok::annot_module_include ||
732 Kind == tok::annot_repl_input_end;
735 static void setTypeAnnotation(Token &Tok,
TypeResult T) {
736 assert((T.isInvalid() || T.get()) &&
737 "produced a valid-but-null type annotation?");
738 Tok.setAnnotationValue(T.isInvalid() ?
nullptr : T.get().getAsOpaquePtr());
741 static NamedDecl *getNonTypeAnnotation(
const Token &Tok) {
742 return static_cast<NamedDecl *
>(Tok.getAnnotationValue());
745 static void setNonTypeAnnotation(Token &Tok, NamedDecl *ND) {
746 Tok.setAnnotationValue(ND);
749 static IdentifierInfo *getIdentifierAnnotation(
const Token &Tok) {
750 return static_cast<IdentifierInfo *
>(Tok.getAnnotationValue());
753 static void setIdentifierAnnotation(Token &Tok, IdentifierInfo *ND) {
754 Tok.setAnnotationValue(ND);
759 static ExprResult getExprAnnotation(
const Token &Tok) {
760 return ExprResult::getFromOpaquePointer(Tok.getAnnotationValue());
765 static void setExprAnnotation(Token &Tok,
ExprResult ER) {
766 Tok.setAnnotationValue(ER.getAsOpaquePointer());
780 TryAnnotateName(CorrectionCandidateCallback *CCC =
nullptr,
785 void AnnotateScopeToken(CXXScopeSpec &SS,
bool IsNewAnnotation);
792 bool TryKeywordIdentFallback(
bool DisableKeyword);
797 TemplateIdAnnotation *takeTemplateIdAnnotation(
const Token &tok);
808 unsigned Diag = diag::err_expected,
809 StringRef DiagMsg =
"");
816 bool ExpectAndConsumeSemi(
unsigned DiagID, StringRef TokenUsed =
"");
821 bool isLikelyAtStartOfNewDeclaration();
832 bool expectIdentifier();
835 enum class CompoundToken {
850 void checkCompoundToken(SourceLocation FirstTokLoc,
853 void diagnoseUseOfC11Keyword(
const Token &Tok);
856 class ParseScopeFlags {
858 unsigned OldFlags = 0;
859 ParseScopeFlags(
const ParseScopeFlags &) =
delete;
860 void operator=(
const ParseScopeFlags &) =
delete;
865 ParseScopeFlags(
Parser *
Self,
unsigned ScopeFlags,
bool ManageFlags =
true);
879 void SuggestParentheses(SourceLocation Loc,
unsigned DK,
880 SourceRange ParenRange);
916 DeclGroupPtrTy ParseExternalDeclaration(ParsedAttributes &DeclAttrs,
917 ParsedAttributes &DeclSpecAttrs,
918 ParsingDeclSpec *DS =
nullptr);
922 bool isDeclarationAfterDeclarator();
926 bool isStartOfFunctionDefinition(
const ParsingDeclarator &Declarator);
929 ParsedAttributes &DeclAttrs, ParsedAttributes &DeclSpecAttrs,
950 DeclGroupPtrTy ParseDeclOrFunctionDefInternal(ParsedAttributes &Attrs,
951 ParsedAttributes &DeclSpecAttrs,
955 void SkipFunctionBody();
957 struct ParsedTemplateInfo;
958 class LateParsedAttrList;
976 Decl *ParseFunctionDefinition(
977 ParsingDeclarator &D,
978 const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo(),
979 LateParsedAttrList *LateParsedAttrs =
nullptr);
983 void ParseKNRParamDeclarations(Declarator &D);
993 ExprResult ParseSimpleAsm(
bool ForAsmLabel, SourceLocation *EndLoc);
1006 ExprResult ParseAsmStringLiteral(
bool ForAsmLabel);
1010 struct IfExistsCondition {
1012 SourceLocation KeywordLoc;
1028 bool ParseMicrosoftIfExistsCondition(IfExistsCondition &
Result);
1029 void ParseMicrosoftIfExistsExternalDeclaration();
1068 Decl *ParseModuleImport(SourceLocation AtLoc,
1075 bool parseMisplacedModuleImport();
1077 bool tryParseMisplacedModuleImport() {
1079 if (Kind == tok::annot_module_begin || Kind == tok::annot_module_end ||
1080 Kind == tok::annot_module_include)
1081 return parseMisplacedModuleImport();
1094 bool ParseModuleName(SourceLocation UseLoc,
1095 SmallVectorImpl<IdentifierLoc> &Path,
bool IsImport);
1098 void DiagnoseInvalidCXXModuleImport();
1102 void CodeCompleteDirective(
bool InConditional)
override;
1104 void CodeCompleteMacroName(
bool IsDefinition)
override;
1106 void CodeCompleteMacroArgument(IdentifierInfo *
Macro, MacroInfo *MacroInfo,
1107 unsigned ArgumentIndex)
override;
1108 void CodeCompleteIncludedFile(llvm::StringRef Dir,
bool IsAngled)
override;
1110 void CodeCompleteModuleImport(SourceLocation ImportLoc,
1126 struct ParsingClass;
1136 class LateParsedDeclaration {
1138 virtual ~LateParsedDeclaration();
1140 virtual void ParseLexedMethodDeclarations();
1141 virtual void ParseLexedMemberInitializers();
1142 virtual void ParseLexedMethodDefs();
1143 virtual void ParseLexedAttributes();
1144 virtual void ParseLexedPragmas();
1149 class LateParsedClass :
public LateParsedDeclaration {
1151 LateParsedClass(
Parser *P, ParsingClass *
C);
1152 ~LateParsedClass()
override;
1154 void ParseLexedMethodDeclarations()
override;
1155 void ParseLexedMemberInitializers()
override;
1156 void ParseLexedMethodDefs()
override;
1157 void ParseLexedAttributes()
override;
1158 void ParseLexedPragmas()
override;
1161 LateParsedClass(
const LateParsedClass &) =
delete;
1162 LateParsedClass &operator=(
const LateParsedClass &) =
delete;
1166 ParsingClass *Class;
1175 struct LateParsedAttribute :
public LateParsedDeclaration {
1178 IdentifierInfo &AttrName;
1179 IdentifierInfo *MacroII =
nullptr;
1180 SourceLocation AttrNameLoc;
1181 SmallVector<Decl *, 2> Decls;
1183 explicit LateParsedAttribute(
Parser *P, IdentifierInfo &Name,
1185 : Self(P), AttrName(Name), AttrNameLoc(Loc) {}
1187 void ParseLexedAttributes()
override;
1189 void addDecl(Decl *D) { Decls.push_back(D); }
1196 class LateParsedPragma :
public LateParsedDeclaration {
1203 : Self(P), AS(AS) {}
1205 void takeToks(
CachedTokens &Cached) { Toks.swap(Cached); }
1209 void ParseLexedPragmas()
override;
1213 class LateParsedAttrList :
public SmallVector<LateParsedAttribute *, 2> {
1215 LateParsedAttrList(
bool PSoon =
false,
1216 bool LateAttrParseExperimentalExtOnly =
false)
1218 LateAttrParseExperimentalExtOnly(LateAttrParseExperimentalExtOnly) {}
1220 bool parseSoon() {
return ParseSoon; }
1223 bool lateAttrParseExperimentalExtOnly() {
1224 return LateAttrParseExperimentalExtOnly;
1229 bool LateAttrParseExperimentalExtOnly;
1235 struct LexedMethod :
public LateParsedDeclaration {
1240 explicit LexedMethod(
Parser *P, Decl *MD) : Self(P), D(MD) {}
1242 void ParseLexedMethodDefs()
override;
1249 struct LateParsedDefaultArgument {
1250 explicit LateParsedDefaultArgument(
1251 Decl *P, std::unique_ptr<CachedTokens> Toks =
nullptr)
1252 : Param(P), Toks(std::move(Toks)) {}
1261 std::unique_ptr<CachedTokens> Toks;
1268 struct LateParsedMethodDeclaration :
public LateParsedDeclaration {
1269 explicit LateParsedMethodDeclaration(
Parser *P, Decl *M)
1270 : Self(P), Method(M), ExceptionSpecTokens(
nullptr) {}
1272 void ParseLexedMethodDeclarations()
override;
1284 SmallVector<LateParsedDefaultArgument, 8> DefaultArgs;
1294 struct LateParsedMemberInitializer :
public LateParsedDeclaration {
1295 LateParsedMemberInitializer(
Parser *P, Decl *FD) : Self(P), Field(FD) {}
1297 void ParseLexedMemberInitializers()
override;
1315 typedef SmallVector<LateParsedDeclaration *, 2>
1316 LateParsedDeclarationsContainer;
1330 const ParsedAttributesView &AccessAttrs,
1331 ParsingDeclarator &D,
1332 const ParsedTemplateInfo &TemplateInfo,
1333 const VirtSpecifiers &VS,
1334 SourceLocation PureSpecLoc);
1337 StringLiteral *ParseCXXDeletedFunctionMessage();
1342 void SkipDeletedFunctionBody();
1348 void ParseCXXNonStaticMemberInitializer(Decl *VarD);
1352 void ParseLexedAttributes(ParsingClass &
Class);
1355 void ParseLexedAttributeList(LateParsedAttrList &LAs, Decl *D,
1363 void ParseLexedAttribute(LateParsedAttribute &LA,
bool EnterScope,
1370 void ParseLexedMethodDeclarations(ParsingClass &
Class);
1371 void ParseLexedMethodDeclaration(LateParsedMethodDeclaration &LM);
1376 void ParseLexedMethodDefs(ParsingClass &
Class);
1377 void ParseLexedMethodDef(LexedMethod &LM);
1383 void ParseLexedMemberInitializers(ParsingClass &
Class);
1384 void ParseLexedMemberInitializer(LateParsedMemberInitializer &MI);
1418 ParsedAttributes *Attrs =
nullptr);
1424 IdentifierInfo *Ident_vector;
1425 IdentifierInfo *Ident_bool;
1426 IdentifierInfo *Ident_Bool;
1430 IdentifierInfo *Ident_pixel;
1433 IdentifierInfo *Ident_introduced;
1436 IdentifierInfo *Ident_deprecated;
1439 IdentifierInfo *Ident_obsoleted;
1442 IdentifierInfo *Ident_unavailable;
1445 IdentifierInfo *Ident_message;
1448 IdentifierInfo *Ident_strict;
1451 IdentifierInfo *Ident_replacement;
1454 IdentifierInfo *Ident_environment;
1457 IdentifierInfo *Ident_language, *Ident_defined_in,
1458 *Ident_generated_declaration, *Ident_USR;
1461 AttributeFactory AttrFactory;
1466 bool TryAltiVecToken(DeclSpec &DS, SourceLocation Loc,
const char *&PrevSpec,
1471 if (Tok.getIdentifierInfo() != Ident_vector &&
1472 Tok.getIdentifierInfo() != Ident_bool &&
1473 Tok.getIdentifierInfo() != Ident_Bool &&
1474 (!
getLangOpts().AltiVec || Tok.getIdentifierInfo() != Ident_pixel))
1477 return TryAltiVecTokenOutOfLine(DS, Loc, PrevSpec, DiagID,
isInvalid);
1483 bool TryAltiVecVectorToken() {
1485 Tok.getIdentifierInfo() != Ident_vector)
1487 return TryAltiVecVectorTokenOutOfLine();
1492 bool TryAltiVecVectorTokenOutOfLine();
1493 bool TryAltiVecTokenOutOfLine(DeclSpec &DS, SourceLocation Loc,
1494 const char *&PrevSpec,
unsigned &DiagID,
1497 void ParseLexedCAttributeList(LateParsedAttrList &LA,
bool EnterScope,
1498 ParsedAttributes *OutAttrs =
nullptr);
1505 void ParseLexedCAttribute(LateParsedAttribute &LA,
bool EnterScope,
1506 ParsedAttributes *OutAttrs =
nullptr);
1508 void ParseLexedPragmas(ParsingClass &
Class);
1509 void ParseLexedPragma(LateParsedPragma &LP);
1517 bool ConsumeAndStoreFunctionPrologue(
CachedTokens &Toks);
1533 bool ConsumeFinalToken =
true) {
1534 return ConsumeAndStoreUntil(T1, T1, Toks,
StopAtSemi, ConsumeFinalToken);
1545 bool ConsumeFinalToken =
true);
1553 enum class DeclSpecContext {
1558 DSC_alias_declaration,
1563 DSC_template_type_arg,
1564 DSC_objc_method_result,
1573 static bool isTypeSpecifier(DeclSpecContext DSC) {
1575 case DeclSpecContext::DSC_normal:
1576 case DeclSpecContext::DSC_template_param:
1577 case DeclSpecContext::DSC_template_arg:
1578 case DeclSpecContext::DSC_class:
1579 case DeclSpecContext::DSC_top_level:
1580 case DeclSpecContext::DSC_objc_method_result:
1581 case DeclSpecContext::DSC_condition:
1584 case DeclSpecContext::DSC_template_type_arg:
1585 case DeclSpecContext::DSC_type_specifier:
1586 case DeclSpecContext::DSC_conv_operator:
1587 case DeclSpecContext::DSC_trailing:
1588 case DeclSpecContext::DSC_alias_declaration:
1589 case DeclSpecContext::DSC_association:
1590 case DeclSpecContext::DSC_new:
1593 llvm_unreachable(
"Missing DeclSpecContext case");
1597 enum class AllowDefiningTypeSpec {
1614 static AllowDefiningTypeSpec
1615 isDefiningTypeSpecifierContext(DeclSpecContext DSC,
bool IsCPlusPlus) {
1617 case DeclSpecContext::DSC_normal:
1618 case DeclSpecContext::DSC_class:
1619 case DeclSpecContext::DSC_top_level:
1620 case DeclSpecContext::DSC_alias_declaration:
1621 case DeclSpecContext::DSC_objc_method_result:
1622 return AllowDefiningTypeSpec::Yes;
1624 case DeclSpecContext::DSC_condition:
1625 case DeclSpecContext::DSC_template_param:
1626 return AllowDefiningTypeSpec::YesButInvalid;
1628 case DeclSpecContext::DSC_template_type_arg:
1629 case DeclSpecContext::DSC_type_specifier:
1630 return AllowDefiningTypeSpec::NoButErrorRecovery;
1632 case DeclSpecContext::DSC_association:
1633 return IsCPlusPlus ? AllowDefiningTypeSpec::NoButErrorRecovery
1634 : AllowDefiningTypeSpec::Yes;
1636 case DeclSpecContext::DSC_trailing:
1637 case DeclSpecContext::DSC_conv_operator:
1638 case DeclSpecContext::DSC_template_arg:
1639 case DeclSpecContext::DSC_new:
1640 return AllowDefiningTypeSpec::No;
1642 llvm_unreachable(
"Missing DeclSpecContext case");
1646 static bool isOpaqueEnumDeclarationContext(DeclSpecContext DSC) {
1648 case DeclSpecContext::DSC_normal:
1649 case DeclSpecContext::DSC_class:
1650 case DeclSpecContext::DSC_top_level:
1653 case DeclSpecContext::DSC_alias_declaration:
1654 case DeclSpecContext::DSC_objc_method_result:
1655 case DeclSpecContext::DSC_condition:
1656 case DeclSpecContext::DSC_template_param:
1657 case DeclSpecContext::DSC_template_type_arg:
1658 case DeclSpecContext::DSC_type_specifier:
1659 case DeclSpecContext::DSC_trailing:
1660 case DeclSpecContext::DSC_association:
1661 case DeclSpecContext::DSC_conv_operator:
1662 case DeclSpecContext::DSC_template_arg:
1663 case DeclSpecContext::DSC_new:
1667 llvm_unreachable(
"Missing DeclSpecContext case");
1672 static bool isClassTemplateDeductionContext(DeclSpecContext DSC) {
1674 case DeclSpecContext::DSC_normal:
1675 case DeclSpecContext::DSC_template_param:
1676 case DeclSpecContext::DSC_template_arg:
1677 case DeclSpecContext::DSC_class:
1678 case DeclSpecContext::DSC_top_level:
1679 case DeclSpecContext::DSC_condition:
1680 case DeclSpecContext::DSC_type_specifier:
1681 case DeclSpecContext::DSC_association:
1682 case DeclSpecContext::DSC_conv_operator:
1683 case DeclSpecContext::DSC_new:
1686 case DeclSpecContext::DSC_objc_method_result:
1687 case DeclSpecContext::DSC_template_type_arg:
1688 case DeclSpecContext::DSC_trailing:
1689 case DeclSpecContext::DSC_alias_declaration:
1692 llvm_unreachable(
"Missing DeclSpecContext case");
1697 getImplicitTypenameContext(DeclSpecContext DSC) {
1699 case DeclSpecContext::DSC_class:
1700 case DeclSpecContext::DSC_top_level:
1701 case DeclSpecContext::DSC_type_specifier:
1702 case DeclSpecContext::DSC_template_type_arg:
1703 case DeclSpecContext::DSC_trailing:
1704 case DeclSpecContext::DSC_alias_declaration:
1705 case DeclSpecContext::DSC_template_param:
1706 case DeclSpecContext::DSC_new:
1709 case DeclSpecContext::DSC_normal:
1710 case DeclSpecContext::DSC_objc_method_result:
1711 case DeclSpecContext::DSC_condition:
1712 case DeclSpecContext::DSC_template_arg:
1713 case DeclSpecContext::DSC_conv_operator:
1714 case DeclSpecContext::DSC_association:
1717 llvm_unreachable(
"Missing DeclSpecContext case");
1722 struct ForRangeInit {
1723 SourceLocation ColonLoc;
1725 SmallVector<MaterializeTemporaryExpr *, 8> LifetimeExtendTemps;
1726 bool ParsedForRangeDecl() {
return !ColonLoc.
isInvalid(); }
1728 struct ForRangeInfo : ForRangeInit {
1751 SourceLocation &DeclEnd,
1752 ParsedAttributes &DeclAttrs,
1753 ParsedAttributes &DeclSpecAttrs,
1754 SourceLocation *DeclSpecStart =
nullptr);
1781 ParsedAttributes &DeclAttrs,
1782 ParsedAttributes &DeclSpecAttrs,
bool RequireSemi,
1783 ForRangeInit *FRI =
nullptr,
1784 SourceLocation *DeclSpecStart =
nullptr);
1794 ParsedAttributes &Attrs,
1795 ParsedTemplateInfo &TemplateInfo,
1796 SourceLocation *DeclEnd =
nullptr,
1797 ForRangeInit *FRI =
nullptr);
1823 Decl *ParseDeclarationAfterDeclarator(
1825 const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo());
1829 bool ParseAsmAttributesAfterDeclarator(Declarator &D);
1830 Decl *ParseDeclarationAfterDeclaratorAndAttributes(
1832 const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo(),
1833 ForRangeInit *FRI =
nullptr);
1844 bool ParseImplicitInt(DeclSpec &DS, CXXScopeSpec *SS,
1846 DeclSpecContext DSC, ParsedAttributes &Attrs);
1856 ParseDeclarationSpecifiers(DeclSpec &DS, ParsedTemplateInfo &TemplateInfo,
1858 DeclSpecContext DSC = DeclSpecContext::DSC_normal,
1859 LateParsedAttrList *LateAttrs =
nullptr) {
1860 return ParseDeclarationSpecifiers(DS, TemplateInfo, AS, DSC, LateAttrs,
1861 getImplicitTypenameContext(DSC));
1894 ParseDeclarationSpecifiers(DeclSpec &DS, ParsedTemplateInfo &TemplateInfo,
1896 LateParsedAttrList *LateAttrs,
1906 bool DiagnoseMissingSemiAfterTagDefinition(
1908 LateParsedAttrList *LateAttrs =
nullptr);
1910 void ParseSpecifierQualifierList(
1912 DeclSpecContext DSC = DeclSpecContext::DSC_normal) {
1913 ParseSpecifierQualifierList(DS, getImplicitTypenameContext(DSC), AS, DSC);
1924 void ParseSpecifierQualifierList(
1927 DeclSpecContext DSC = DeclSpecContext::DSC_normal);
1961 void ParseEnumSpecifier(SourceLocation TagLoc, DeclSpec &DS,
1962 const ParsedTemplateInfo &TemplateInfo,
1977 void ParseEnumBody(SourceLocation StartLoc, Decl *TagDecl,
1978 SkipBodyInfo *SkipBody =
nullptr);
1992 void ParseStructUnionBody(SourceLocation StartLoc,
DeclSpec::TST TagType,
1993 RecordDecl *TagDecl);
2018 void ParseStructDeclaration(
2019 ParsingDeclSpec &DS,
2020 llvm::function_ref<Decl *(ParsingFieldDeclarator &)> FieldsCallback,
2021 LateParsedAttrList *LateFieldAttrs =
nullptr);
2033 bool DisambiguatingWithExpression =
false);
2037 bool isTypeSpecifierQualifier(
const Token &Tok);
2042 bool isKnownToBeTypeSpecifier(
const Token &Tok)
const;
2047 bool isConstructorDeclarator(
2050 const ParsedTemplateInfo *TemplateInfo =
nullptr);
2054 void DiagnoseBitIntUse(
const Token &Tok);
2058 bool CheckProhibitedCXX11Attribute() {
2059 assert(Tok.is(tok::l_square));
2062 return DiagnoseProhibitedCXX11Attribute();
2073 bool DiagnoseProhibitedCXX11Attribute();
2075 void CheckMisplacedCXX11Attribute(ParsedAttributes &Attrs,
2076 SourceLocation CorrectLocation) {
2077 if (!Tok.isRegularKeywordAttribute() &&
2078 (Tok.isNot(tok::l_square) ||
NextToken().
isNot(tok::l_square)) &&
2079 Tok.isNot(tok::kw_alignas))
2081 DiagnoseMisplacedCXX11Attribute(Attrs, CorrectLocation);
2088 void DiagnoseMisplacedCXX11Attribute(ParsedAttributes &Attrs,
2089 SourceLocation CorrectLocation);
2099 void stripTypeAttributesOffDeclSpec(ParsedAttributes &Attrs, DeclSpec &DS,
2103 void ProhibitAttributes(ParsedAttributes &Attrs,
2104 SourceLocation FixItLoc = SourceLocation()) {
2105 if (Attrs.Range.isInvalid())
2107 DiagnoseProhibitedAttributes(Attrs, FixItLoc);
2111 void ProhibitAttributes(ParsedAttributesView &Attrs,
2112 SourceLocation FixItLoc = SourceLocation()) {
2113 if (Attrs.Range.isInvalid())
2115 DiagnoseProhibitedAttributes(Attrs, FixItLoc);
2116 Attrs.clearListOnly();
2118 void DiagnoseProhibitedAttributes(
const ParsedAttributesView &Attrs,
2119 SourceLocation FixItLoc);
2127 void ProhibitCXX11Attributes(ParsedAttributes &Attrs,
unsigned AttrDiagID,
2128 unsigned KeywordDiagId,
2129 bool DiagnoseEmptyAttrs =
false,
2130 bool WarnOnUnknownAttrs =
false);
2134 void DiagnoseCXX11AttributeExtension(ParsedAttributes &Attrs);
2136 ExprResult ParseUnevaluatedStringInAttribute(
const IdentifierInfo &AttrName);
2143 bool ParseAttributeArgumentList(
2144 const IdentifierInfo &AttrName, SmallVectorImpl<Expr *> &Exprs,
2145 ParsedAttributeArgumentsProperties ArgsProperties,
unsigned Arg);
2152 ParseAttributeArgsCommon(IdentifierInfo *AttrName, SourceLocation AttrNameLoc,
2153 ParsedAttributes &Attrs, SourceLocation *EndLoc,
2154 IdentifierInfo *ScopeName, SourceLocation ScopeLoc,
2155 ParsedAttr::Form Form);
2157 enum ParseAttrKindMask {
2159 PAKM_Declspec = 1 << 1,
2160 PAKM_CXX11 = 1 << 2,
2179 void ParseAttributes(
unsigned WhichAttrKinds, ParsedAttributes &Attrs,
2180 LateParsedAttrList *LateAttrs =
nullptr);
2183 bool MaybeParseAttributes(
unsigned WhichAttrKinds, ParsedAttributes &Attrs,
2184 LateParsedAttrList *LateAttrs =
nullptr) {
2185 if (Tok.isOneOf(tok::kw___attribute, tok::kw___declspec) ||
2186 isAllowedCXX11AttributeSpecifier()) {
2187 ParseAttributes(WhichAttrKinds, Attrs, LateAttrs);
2193 void MaybeParseGNUAttributes(Declarator &D,
2194 LateParsedAttrList *LateAttrs =
nullptr) {
2195 if (Tok.is(tok::kw___attribute)) {
2196 ParsedAttributes Attrs(AttrFactory);
2197 ParseGNUAttributes(Attrs, LateAttrs, &D);
2198 D.takeAttributesAppending(Attrs);
2202 bool MaybeParseGNUAttributes(ParsedAttributes &Attrs,
2203 LateParsedAttrList *LateAttrs =
nullptr) {
2204 if (Tok.is(tok::kw___attribute)) {
2205 ParseGNUAttributes(Attrs, LateAttrs);
2227 bool ParseSingleGNUAttribute(ParsedAttributes &Attrs, SourceLocation &EndLoc,
2228 LateParsedAttrList *LateAttrs =
nullptr,
2229 Declarator *D =
nullptr);
2274 void ParseGNUAttributes(ParsedAttributes &Attrs,
2275 LateParsedAttrList *LateAttrs =
nullptr,
2276 Declarator *D =
nullptr);
2280 void ParseGNUAttributeArgs(IdentifierInfo *AttrName,
2281 SourceLocation AttrNameLoc,
2282 ParsedAttributes &Attrs, SourceLocation *EndLoc,
2283 IdentifierInfo *ScopeName, SourceLocation ScopeLoc,
2284 ParsedAttr::Form Form, Declarator *D);
2285 IdentifierLoc *ParseIdentifierLoc();
2288 ParseClangAttributeArgs(IdentifierInfo *AttrName, SourceLocation AttrNameLoc,
2289 ParsedAttributes &Attrs, SourceLocation *EndLoc,
2290 IdentifierInfo *ScopeName, SourceLocation ScopeLoc,
2291 ParsedAttr::Form Form);
2293 void MaybeParseCXX11Attributes(Declarator &D) {
2294 if (isAllowedCXX11AttributeSpecifier()) {
2295 ParsedAttributes Attrs(AttrFactory);
2296 ParseCXX11Attributes(Attrs);
2297 D.takeAttributesAppending(Attrs);
2301 bool MaybeParseCXX11Attributes(ParsedAttributes &Attrs,
2302 bool OuterMightBeMessageSend =
false) {
2303 if (isAllowedCXX11AttributeSpecifier(
false, OuterMightBeMessageSend)) {
2304 ParseCXX11Attributes(Attrs);
2310 bool MaybeParseMicrosoftAttributes(ParsedAttributes &Attrs) {
2311 bool AttrsParsed =
false;
2313 Tok.is(tok::l_square)) {
2314 ParsedAttributes AttrsWithRange(AttrFactory);
2315 ParseMicrosoftAttributes(AttrsWithRange);
2316 AttrsParsed = !AttrsWithRange.empty();
2317 Attrs.takeAllAppendingFrom(AttrsWithRange);
2321 bool MaybeParseMicrosoftDeclSpecs(ParsedAttributes &Attrs) {
2322 if (
getLangOpts().DeclSpecKeyword && Tok.is(tok::kw___declspec)) {
2323 ParseMicrosoftDeclSpecs(Attrs);
2337 void ParseMicrosoftDeclSpecs(ParsedAttributes &Attrs);
2338 bool ParseMicrosoftDeclSpecArgs(IdentifierInfo *AttrName,
2339 SourceLocation AttrNameLoc,
2340 ParsedAttributes &Attrs);
2341 void ParseMicrosoftTypeAttributes(ParsedAttributes &attrs);
2342 void ParseWebAssemblyFuncrefTypeAttribute(ParsedAttributes &Attrs);
2343 void DiagnoseAndSkipExtendedMicrosoftTypeAttributes();
2344 SourceLocation SkipExtendedMicrosoftTypeAttributes();
2346 void ParseBorlandTypeAttributes(ParsedAttributes &attrs);
2347 void ParseOpenCLKernelAttributes(ParsedAttributes &attrs);
2348 void ParseOpenCLQualifiers(ParsedAttributes &Attrs);
2349 void ParseNullabilityTypeSpecifiers(ParsedAttributes &attrs);
2350 void ParseCUDAFunctionAttributes(ParsedAttributes &attrs);
2351 bool isHLSLQualifier(
const Token &Tok)
const;
2352 void ParseHLSLQualifiers(ParsedAttributes &Attrs);
2364 VersionTuple ParseVersionTuple(SourceRange &Range);
2393 void ParseAvailabilityAttribute(IdentifierInfo &Availability,
2394 SourceLocation AvailabilityLoc,
2395 ParsedAttributes &attrs,
2396 SourceLocation *endLoc,
2397 IdentifierInfo *ScopeName,
2398 SourceLocation ScopeLoc,
2399 ParsedAttr::Form Form);
2417 void ParseExternalSourceSymbolAttribute(IdentifierInfo &ExternalSourceSymbol,
2419 ParsedAttributes &Attrs,
2420 SourceLocation *EndLoc,
2421 IdentifierInfo *ScopeName,
2422 SourceLocation ScopeLoc,
2423 ParsedAttr::Form Form);
2438 void ParseObjCBridgeRelatedAttribute(IdentifierInfo &ObjCBridgeRelated,
2439 SourceLocation ObjCBridgeRelatedLoc,
2440 ParsedAttributes &Attrs,
2441 SourceLocation *EndLoc,
2442 IdentifierInfo *ScopeName,
2443 SourceLocation ScopeLoc,
2444 ParsedAttr::Form Form);
2446 void ParseSwiftNewTypeAttribute(IdentifierInfo &AttrName,
2447 SourceLocation AttrNameLoc,
2448 ParsedAttributes &Attrs,
2449 SourceLocation *EndLoc,
2450 IdentifierInfo *ScopeName,
2451 SourceLocation ScopeLoc,
2452 ParsedAttr::Form Form);
2454 void ParseTypeTagForDatatypeAttribute(IdentifierInfo &AttrName,
2455 SourceLocation AttrNameLoc,
2456 ParsedAttributes &Attrs,
2457 SourceLocation *EndLoc,
2458 IdentifierInfo *ScopeName,
2459 SourceLocation ScopeLoc,
2460 ParsedAttr::Form Form);
2462 void ParseAttributeWithTypeArg(IdentifierInfo &AttrName,
2463 SourceLocation AttrNameLoc,
2464 ParsedAttributes &Attrs,
2465 IdentifierInfo *ScopeName,
2466 SourceLocation ScopeLoc,
2467 ParsedAttr::Form Form);
2469 void DistributeCLateParsedAttrs(Decl *Dcl, LateParsedAttrList *LateAttrs);
2475 void ParseBoundsAttribute(IdentifierInfo &AttrName,
2476 SourceLocation AttrNameLoc, ParsedAttributes &Attrs,
2477 IdentifierInfo *ScopeName, SourceLocation ScopeLoc,
2478 ParsedAttr::Form Form);
2494 void ParseTypeofSpecifier(DeclSpec &DS);
2501 void ParseAtomicSpecifier(DeclSpec &DS);
2511 ExprResult ParseAlignArgument(StringRef KWName, SourceLocation Start,
2512 SourceLocation &EllipsisLoc,
bool &IsType,
2525 void ParseAlignmentSpecifier(ParsedAttributes &Attrs,
2526 SourceLocation *endLoc =
nullptr);
2535 void ParsePtrauthQualifier(ParsedAttributes &Attrs);
2540 class DeclaratorScopeObj {
2547 DeclaratorScopeObj(
Parser &p, CXXScopeSpec &ss)
2548 : P(p), SS(ss), EnteredScope(
false), CreatedScope(
false) {}
2550 void EnterDeclaratorScope() {
2551 assert(!EnteredScope &&
"Already entered the scope!");
2552 assert(SS.isSet() &&
"C++ scope was not set!");
2554 CreatedScope =
true;
2557 if (!P.Actions.ActOnCXXEnterDeclaratorScope(P.getCurScope(), SS))
2558 EnteredScope =
true;
2561 ~DeclaratorScopeObj() {
2563 assert(SS.isSet() &&
"C++ scope was cleared ?");
2564 P.Actions.ActOnCXXExitDeclaratorScope(P.getCurScope(), SS);
2572 void ParseDeclarator(Declarator &D);
2603 void ParseDeclaratorInternal(Declarator &D,
2604 DirectDeclParseFunction DirectDeclParser);
2606 enum AttrRequirements {
2607 AR_NoAttributesParsed = 0,
2608 AR_GNUAttributesParsedAndRejected = 1 << 0,
2609 AR_GNUAttributesParsed = 1 << 1,
2610 AR_CXX11AttributesParsed = 1 << 2,
2611 AR_DeclspecAttributesParsed = 1 << 3,
2612 AR_AllAttributesParsed = AR_GNUAttributesParsed | AR_CXX11AttributesParsed |
2613 AR_DeclspecAttributesParsed,
2614 AR_VendorAttributesParsed =
2615 AR_GNUAttributesParsed | AR_DeclspecAttributesParsed
2632 void ParseTypeQualifierListOpt(
2633 DeclSpec &DS,
unsigned AttrReqs = AR_AllAttributesParsed,
2634 bool AtomicOrPtrauthAllowed =
true,
bool IdentifierRequired =
false,
2635 llvm::function_ref<
void()> CodeCompletionHandler = {});
2685 void ParseDirectDeclarator(Declarator &D);
2686 void ParseDecompositionDeclarator(Declarator &D);
2704 void ParseParenDeclarator(Declarator &D);
2729 void ParseFunctionDeclarator(Declarator &D, ParsedAttributes &FirstArgAttrs,
2731 bool IsAmbiguous,
bool RequiresArg =
false);
2732 void InitCXXThisScopeForDeclaratorIfRelevant(
2733 const Declarator &D,
const DeclSpec &DS,
2734 std::optional<Sema::CXXThisScopeRAII> &ThisScope);
2738 bool ParseRefQualifier(
bool &RefQualifierIsLValueRef,
2739 SourceLocation &RefQualifierLoc);
2746 bool isFunctionDeclaratorIdentifierList();
2760 void ParseFunctionDeclaratorIdentifierList(
2761 Declarator &D, SmallVectorImpl<DeclaratorChunk::ParamInfo> &ParamInfo);
2762 void ParseParameterDeclarationClause(
2763 Declarator &D, ParsedAttributes &attrs,
2764 SmallVectorImpl<DeclaratorChunk::ParamInfo> &ParamInfo,
2765 SourceLocation &EllipsisLoc) {
2766 return ParseParameterDeclarationClause(
2767 D.getContext(), attrs, ParamInfo, EllipsisLoc,
2768 D.getCXXScopeSpec().isSet() &&
2769 D.isFunctionDeclaratorAFunctionDeclaration());
2807 void ParseParameterDeclarationClause(
2809 SmallVectorImpl<DeclaratorChunk::ParamInfo> &ParamInfo,
2810 SourceLocation &EllipsisLoc,
bool IsACXXFunctionDeclaration =
false);
2821 void ParseBracketDeclarator(Declarator &D);
2824 void ParseMisplacedBracketDeclarator(Declarator &D);
2835 TypeResult ParseTypeFromString(StringRef TypeStr, StringRef Context,
2836 SourceLocation IncludeLoc);
2852 mutable IdentifierInfo *Ident_sealed;
2853 mutable IdentifierInfo *Ident_abstract;
2856 mutable IdentifierInfo *Ident_final;
2857 mutable IdentifierInfo *Ident_GNU_final;
2858 mutable IdentifierInfo *Ident_override;
2863 struct ParsingClass {
2864 ParsingClass(Decl *TagOrTemplate,
bool TopLevelClass,
bool IsInterface)
2865 : TopLevelClass(TopLevelClass), IsInterface(IsInterface),
2866 TagOrTemplate(TagOrTemplate) {}
2870 bool TopLevelClass : 1;
2873 bool IsInterface : 1;
2876 Decl *TagOrTemplate;
2881 LateParsedDeclarationsContainer LateParsedDeclarations;
2887 std::stack<ParsingClass *> ClassStack;
2889 ParsingClass &getCurrentClass() {
2890 assert(!ClassStack.empty() &&
"No lexed method stacks!");
2891 return *ClassStack.top();
2895 class ParsingClassDefinition {
2901 ParsingClassDefinition(
Parser &P, Decl *TagOrTemplate,
bool TopLevelClass,
2903 : P(P), Popped(
false),
2904 State(P.PushParsingClass(TagOrTemplate, TopLevelClass, IsInterface)) {
2909 assert(!Popped &&
"Nested class has already been popped");
2911 P.PopParsingClass(State);
2914 ~ParsingClassDefinition() {
2916 P.PopParsingClass(State);
2932 bool Delayed, SourceRange &SpecificationRange,
2933 SmallVectorImpl<ParsedType> &DynamicExceptions,
2934 SmallVectorImpl<SourceRange> &DynamicExceptionRanges,
2952 ParseDynamicExceptionSpecification(SourceRange &SpecificationRange,
2953 SmallVectorImpl<ParsedType> &Exceptions,
2954 SmallVectorImpl<SourceRange> &Ranges);
2961 TypeResult ParseTrailingReturnType(SourceRange &Range,
2962 bool MayBeFollowedByDirectInit);
2965 void ParseTrailingRequiresClause(Declarator &D);
2967 void ParseMicrosoftIfExistsClassDeclaration(
DeclSpec::TST TagType,
2968 ParsedAttributes &AccessAttrs,
2971 SourceLocation ParsePackIndexingType(DeclSpec &DS);
2972 void AnnotateExistingIndexedTypeNamePack(
ParsedType T,
2973 SourceLocation StartLoc,
2974 SourceLocation EndLoc);
2981 bool isAllowedCXX11AttributeSpecifier(
bool Disambiguate =
false,
2982 bool OuterMightBeMessageSend =
false) {
2983 return (Tok.isRegularKeywordAttribute() ||
2984 isCXX11AttributeSpecifier(Disambiguate, OuterMightBeMessageSend) !=
2991 SourceLocation SkipCXX11Attributes();
2995 void DiagnoseAndSkipCXX11Attributes();
2997 void ParseOpenMPAttributeArgs(
const IdentifierInfo *AttrName,
3026 void ParseCXX11AttributeSpecifierInternal(ParsedAttributes &Attrs,
3028 SourceLocation *EndLoc =
nullptr);
3029 void ParseCXX11AttributeSpecifier(ParsedAttributes &Attrs,
3030 SourceLocation *EndLoc =
nullptr) {
3032 ParseCXX11AttributeSpecifierInternal(Attrs, OpenMPTokens, EndLoc);
3033 ReplayOpenMPAttributeTokens(OpenMPTokens);
3042 void ParseCXX11Attributes(ParsedAttributes &attrs);
3062 bool ParseCXX11AttributeArgs(IdentifierInfo *AttrName,
3063 SourceLocation AttrNameLoc,
3064 ParsedAttributes &Attrs, SourceLocation *EndLoc,
3065 IdentifierInfo *ScopeName,
3066 SourceLocation ScopeLoc,
3072 ParseCXXAssumeAttributeArg(ParsedAttributes &Attrs, IdentifierInfo *AttrName,
3073 SourceLocation AttrNameLoc,
3074 IdentifierInfo *ScopeName, SourceLocation ScopeLoc,
3075 SourceLocation *EndLoc, ParsedAttr::Form Form);
3086 IdentifierInfo *TryParseCXX11AttributeIdentifier(
3087 SourceLocation &Loc,
3090 const IdentifierInfo *EnclosingScope =
nullptr);
3093 void ParseMicrosoftUuidAttributeArgs(ParsedAttributes &Attrs);
3105 void ParseMicrosoftAttributes(ParsedAttributes &Attrs);
3107 void ParseMicrosoftInheritanceClassAttributes(ParsedAttributes &attrs);
3108 void ParseNullabilityClassAttributes(ParsedAttributes &attrs);
3117 SourceLocation ParseDecltypeSpecifier(DeclSpec &DS);
3118 void AnnotateExistingDecltypeSpecifier(
const DeclSpec &DS,
3119 SourceLocation StartLoc,
3120 SourceLocation EndLoc);
3133 return isCXX11VirtSpecifier(Tok);
3143 void ParseOptionalCXX11VirtSpecifierSeq(VirtSpecifiers &VS,
bool IsInterface,
3144 SourceLocation FriendLoc);
3148 bool isCXX11FinalKeyword()
const;
3154 bool isClassCompatibleKeyword()
const;
3156 bool MaybeParseTypeTransformTypeSpecifier(DeclSpec &DS);
3159 void DiagnoseUnexpectedNamespace(NamedDecl *Context);
3191 SourceLocation &DeclEnd,
3192 SourceLocation InlineLoc = SourceLocation());
3194 struct InnerNamespaceInfo {
3195 SourceLocation NamespaceLoc;
3196 SourceLocation InlineLoc;
3197 SourceLocation IdentLoc;
3198 IdentifierInfo *Ident;
3200 using InnerNamespaceInfoList = llvm::SmallVector<InnerNamespaceInfo, 4>;
3203 void ParseInnerNamespace(
const InnerNamespaceInfoList &InnerNSs,
3204 unsigned int index, SourceLocation &InlineLoc,
3205 ParsedAttributes &attrs,
3237 Decl *ParseExportDeclaration();
3243 SourceLocation &DeclEnd, ParsedAttributes &Attrs);
3258 SourceLocation &DeclEnd, ParsedAttributes &attrs);
3260 struct UsingDeclarator {
3261 SourceLocation TypenameLoc;
3264 SourceLocation EllipsisLoc;
3267 TypenameLoc = EllipsisLoc = SourceLocation();
3308 const ParsedTemplateInfo &TemplateInfo,
3309 SourceLocation UsingLoc,
3310 SourceLocation &DeclEnd,
3311 ParsedAttributes &Attrs,
3313 Decl *ParseAliasDeclarationAfterDeclarator(
3314 const ParsedTemplateInfo &TemplateInfo, SourceLocation UsingLoc,
3316 ParsedAttributes &Attrs, Decl **OwnedType =
nullptr);
3329 Decl *ParseStaticAssertDeclaration(SourceLocation &DeclEnd);
3334 Decl *ParseNamespaceAlias(SourceLocation NamespaceLoc,
3335 SourceLocation AliasLoc, IdentifierInfo *Alias,
3336 SourceLocation &DeclEnd);
3344 bool isValidAfterTypeSpecifier(
bool CouldBeBitfield);
3388 void ParseClassSpecifier(
tok::TokenKind TagTokKind, SourceLocation TagLoc,
3389 DeclSpec &DS, ParsedTemplateInfo &TemplateInfo,
3391 DeclSpecContext DSC, ParsedAttributes &Attributes);
3392 void SkipCXXMemberSpecification(SourceLocation StartLoc,
3393 SourceLocation AttrFixitLoc,
unsigned TagType,
3404 void ParseCXXMemberSpecification(SourceLocation StartLoc,
3405 SourceLocation AttrFixitLoc,
3406 ParsedAttributes &Attrs,
unsigned TagType,
3431 ExprResult ParseCXXMemberInitializer(Decl *D,
bool IsFunction,
3432 SourceLocation &EqualLoc);
3436 bool ParseCXXMemberDeclaratorBeforeInitializer(Declarator &DeclaratorInfo,
3439 LateParsedAttrList &LateAttrs);
3444 MaybeParseAndDiagnoseDeclSpecAfterCXX11VirtSpecifierSeq(Declarator &D,
3445 VirtSpecifiers &VS);
3501 ParsedTemplateInfo &TemplateInfo,
3502 ParsingDeclRAIIObject *DiagsFromTParams =
nullptr);
3505 ParsedAttributes &AccessAttrs,
3531 void ParseConstructorInitializer(Decl *ConstructorDecl);
3553 void HandleMemberFunctionDeclDelays(Declarator &DeclaratorInfo,
3581 TypeResult ParseBaseTypeSpecifier(SourceLocation &BaseLoc,
3582 SourceLocation &EndLocation);
3594 void ParseBaseClause(Decl *ClassDecl);
3609 BaseResult ParseBaseSpecifier(Decl *ClassDecl);
3625 bool isClassCompatibleKeyword(Token Tok)
const;
3627 void ParseHLSLRootSignatureAttributeArgs(ParsedAttributes &Attrs);
3802 bool GreaterThanIsOperator;
3806 llvm::SmallDenseMap<IdentifierInfo *, tok::TokenKind> RevertibleTypeTraits;
3825 PushParsingClass(
Decl *TagOrTemplate,
bool TopLevelClass,
bool IsInterface);
3829 void DeallocateParsedClasses(ParsingClass *
Class);
4050 bool isAddressOfOperand,
bool &NotCastExpr,
4052 bool isVectorLiteral =
false,
4053 bool *NotPrimaryExpression =
nullptr);
4055 bool isAddressOfOperand =
false,
4058 bool isVectorLiteral =
false,
4059 bool *NotPrimaryExpression =
nullptr);
4062 bool isNotExpressionStart();
4066 bool isPostfixExpressionSuffixStart() {
4068 return (K == tok::l_square || K == tok::l_paren || K == tok::period ||
4069 K == tok::arrow || K == tok::plusplus || K == tok::minusminus);
4111 ExprResult ParseUnaryExprOrTypeTraitExpression();
4140 ExprResult ParseSYCLUniqueStableNameExpression();
4202 llvm::function_ref<
void()> ExpressionStarts =
4203 llvm::function_ref<
void()>(),
4204 bool FailImmediatelyOnInvalidExpr =
false);
4249 bool StopIfCastExpr,
4286 ExprResult ParseGenericSelectionExpression();
4305 void injectEmbedTokens();
4331 ExprResult ParseAssignmentExprWithObjCMessageExprStart(
4333 Expr *ReceiverExpr);
4338 bool isKnownToBeDeclarationSpecifier() {
4352 bool isTypeIdForGenericSelection() {
4358 return isTypeSpecifierQualifier(Tok);
4364 bool isTypeIdUnambiguously() {
4369 return isTypeSpecifierQualifier(Tok);
4378 void ParseBlockId(SourceLocation CaretLoc);
4387 std::optional<AvailabilitySpec> ParseAvailabilitySpec();
4388 ExprResult ParseAvailabilityCheckExpr(SourceLocation StartLoc);
4394 bool tryParseOpenMPArrayShapingCastPart();
4396 ExprResult ParseBuiltinPtrauthTypeDiscriminator();
4449 bool ObjectHadErrors,
bool EnteringContext,
4450 bool AllowDestructorName,
bool AllowConstructorName,
4451 bool AllowDeductionGuide,
4452 SourceLocation *TemplateKWLoc, UnqualifiedId &
Result);
4470 ExprResult tryParseCXXIdExpression(CXXScopeSpec &SS,
bool isAddressOfOperand,
4471 Token &Replacement);
4522 ExprResult ParseCXXIdExpression(
bool isAddressOfOperand =
false);
4525 bool areTokensAdjacent(
const Token &A,
const Token &B);
4529 void CheckForTemplateAndDigraph(Token &
Next,
ParsedType ObjectTypePtr,
4530 bool EnteringContext, IdentifierInfo &II,
4593 bool ParseOptionalCXXScopeSpecifier(
4594 CXXScopeSpec &SS,
ParsedType ObjectType,
bool ObjectHasErrors,
4595 bool EnteringContext,
bool *MayBePseudoDestructor =
nullptr,
4596 bool IsTypename =
false,
const IdentifierInfo **LastII =
nullptr,
4597 bool OnlyNamespace =
false,
bool InUsingDeclaration =
false,
4598 bool Disambiguation =
false,
bool IsAddressOfOperand =
false,
4599 bool IsInDeclarationContext =
false);
4601 bool ParseOptionalCXXScopeSpecifier(CXXScopeSpec &SS,
ParsedType ObjectType,
4602 bool ObjectHasErrors,
4603 bool EnteringContext,
4604 bool IsAddressOfOperand) {
4605 return ParseOptionalCXXScopeSpecifier(
4606 SS, ObjectType, ObjectHasErrors, EnteringContext,
4613 IsAddressOfOperand);
4620 enum class LambdaIntroducerTentativeParse {
4698 ParseLambdaIntroducer(LambdaIntroducer &Intro,
4699 LambdaIntroducerTentativeParse *Tentative =
nullptr);
4703 ExprResult ParseLambdaExpressionAfterIntroducer(LambdaIntroducer &Intro);
4787 ExprResult ParseCXXPseudoDestructor(Expr *Base, SourceLocation OpLoc,
4842 ExprResult ParseCXXTypeConstructExpression(
const DeclSpec &DS);
4872 void ParseCXXSimpleTypeSpecifier(DeclSpec &DS);
4887 bool ParseCXXTypeSpecifierSeq(
4905 bool ParseExpressionListOrTypeId(SmallVectorImpl<Expr *> &Exprs,
4917 void ParseDirectNewDeclarator(Declarator &D);
4950 ExprResult ParseCXXNewExpression(
bool UseGlobal, SourceLocation Start);
4965 ExprResult ParseCXXDeleteExpression(
bool UseGlobal, SourceLocation Start);
5004 Sema::ConditionResult ParseCXXCondition(
StmtResult *InitStmt,
5008 ForRangeInfo *FRI =
nullptr,
5009 bool EnterForConditionScope =
false);
5011 ParsedAttributes &Attrs);
5058 bool isTypeIdInParens(
bool &isAmbiguous) {
5061 isAmbiguous =
false;
5062 return isTypeSpecifierQualifier(Tok);
5064 bool isTypeIdInParens() {
5066 return isTypeIdInParens(isAmbiguous);
5104 bool ParseUnqualifiedIdTemplateId(CXXScopeSpec &SS,
ParsedType ObjectType,
5105 bool ObjectHadErrors,
5106 SourceLocation TemplateKWLoc,
5107 IdentifierInfo *Name,
5108 SourceLocation NameLoc,
5109 bool EnteringContext, UnqualifiedId &Id,
5110 bool AssumeTemplateId);
5152 bool ParseUnqualifiedIdOperator(CXXScopeSpec &SS,
bool EnteringContext,
5219 bool MaybeParseHLSLAnnotations(Declarator &D,
5220 SourceLocation *EndLoc =
nullptr,
5221 bool CouldBeBitField =
false) {
5222 assert(
getLangOpts().
HLSL &&
"MaybeParseHLSLAnnotations is for HLSL only");
5223 if (Tok.is(tok::colon)) {
5224 ParsedAttributes Attrs(AttrFactory);
5225 ParseHLSLAnnotations(Attrs, EndLoc, CouldBeBitField);
5226 D.takeAttributesAppending(Attrs);
5232 void MaybeParseHLSLAnnotations(ParsedAttributes &Attrs,
5233 SourceLocation *EndLoc =
nullptr) {
5234 assert(
getLangOpts().
HLSL &&
"MaybeParseHLSLAnnotations is for HLSL only");
5235 if (Tok.is(tok::colon))
5236 ParseHLSLAnnotations(Attrs, EndLoc);
5239 struct ParsedSemantic {
5240 StringRef Name =
"";
5242 bool Explicit =
false;
5245 ParsedSemantic ParseHLSLSemantic();
5247 void ParseHLSLAnnotations(ParsedAttributes &Attrs,
5248 SourceLocation *EndLoc =
nullptr,
5249 bool CouldBeBitField =
false);
5250 Decl *ParseHLSLBuffer(SourceLocation &DeclEnd, ParsedAttributes &Attrs);
5274 ExprResult ParseInitializer(Decl *DeclForInitializer =
nullptr);
5279 bool MayBeDesignationStart();
5297 struct DesignatorCompletionInfo {
5298 SmallVectorImpl<Expr *> &InitExprs;
5299 QualType PreferredBaseType;
5348 ExprResult ParseInitializerWithPotentialDesignator(DesignatorCompletionInfo);
5353 typedef SmallVector<Expr *, 12> ExprVector;
5357 bool ParseMicrosoftIfExistsBraceInitializer(ExprVector &InitExprs,
5374 friend class ObjCDeclContextSwitch;
5377 return Actions.ObjC().getObjCDeclContext();
5383 return Actions.getNullabilityKeyword(nullability);
5399 bool InMessageExpression;
5406 bool ParsingInObjCContainer;
5411 bool isObjCInstancetype() {
5413 if (
Tok.isAnnotation())
5415 if (!Ident_instancetype)
5417 return Tok.getIdentifierInfo() == Ident_instancetype;
5425 ObjCContainerDecl *DC;
5426 SaveAndRestore<bool> WithinObjCContainer;
5431 WithinObjCContainer(P.ParsingInObjCContainer, DC !=
nullptr) {
5433 P.Actions.ObjC().ActOnObjCTemporaryExitContainerContext(DC);
5435 ~ObjCDeclContextSwitch() {
5437 P.Actions.ObjC().ActOnObjCReenterContainerContext(DC);
5441 void CheckNestedObjCContexts(SourceLocation AtLoc);
5443 void ParseLexedObjCMethodDefs(LexedMethod &LM,
bool parseMethod);
5461 DeclGroupPtrTy ParseObjCAtDirectives(ParsedAttributes &DeclAttrs,
5462 ParsedAttributes &DeclSpecAttrs);
5473 DeclGroupPtrTy ParseObjCAtClassDeclaration(SourceLocation atLoc);
5506 Decl *ParseObjCAtInterfaceDeclaration(SourceLocation AtLoc,
5507 ParsedAttributes &prefixAttrs);
5513 ObjCTypeParamList *parseObjCTypeParamList();
5541 ObjCTypeParamList *parseObjCTypeParamListOrProtocolRefs(
5543 SmallVectorImpl<IdentifierLoc> &protocolIdents, SourceLocation &rAngleLoc,
5544 bool mayBeProtocolList =
true);
5546 void HelperActionsForIvarDeclarations(ObjCContainerDecl *interfaceDecl,
5547 SourceLocation atLoc,
5549 SmallVectorImpl<Decl *> &AllIvarDecls,
5550 bool RBraceMissing);
5575 void ParseObjCClassInstanceVariables(ObjCContainerDecl *interfaceDecl,
5577 SourceLocation atLoc);
5584 bool ParseObjCProtocolReferences(
5585 SmallVectorImpl<Decl *> &P, SmallVectorImpl<SourceLocation> &PLocs,
5586 bool WarnOnDeclarations,
bool ForObjCContainer, SourceLocation &LAngleLoc,
5587 SourceLocation &EndProtoLoc,
bool consumeLastToken);
5598 void parseObjCTypeArgsOrProtocolQualifiers(
5599 ParsedType baseType, SourceLocation &typeArgsLAngleLoc,
5600 SmallVectorImpl<ParsedType> &typeArgs, SourceLocation &typeArgsRAngleLoc,
5601 SourceLocation &protocolLAngleLoc, SmallVectorImpl<Decl *> &protocols,
5602 SmallVectorImpl<SourceLocation> &protocolLocs,
5603 SourceLocation &protocolRAngleLoc,
bool consumeLastToken,
5604 bool warnOnIncompleteProtocols);
5608 void parseObjCTypeArgsAndProtocolQualifiers(
5609 ParsedType baseType, SourceLocation &typeArgsLAngleLoc,
5610 SmallVectorImpl<ParsedType> &typeArgs, SourceLocation &typeArgsRAngleLoc,
5611 SourceLocation &protocolLAngleLoc, SmallVectorImpl<Decl *> &protocols,
5612 SmallVectorImpl<SourceLocation> &protocolLocs,
5613 SourceLocation &protocolRAngleLoc,
bool consumeLastToken);
5617 TypeResult parseObjCProtocolQualifierType(SourceLocation &rAngleLoc);
5621 TypeResult parseObjCTypeArgsAndProtocolQualifiers(SourceLocation loc,
5623 bool consumeLastToken,
5624 SourceLocation &endLoc);
5660 DeclGroupPtrTy ParseObjCAtProtocolDeclaration(SourceLocation atLoc,
5661 ParsedAttributes &prefixAttrs);
5663 struct ObjCImplParsingDataRAII {
5667 typedef SmallVector<LexedMethod *, 8> LateParsedObjCMethodContainer;
5668 LateParsedObjCMethodContainer LateParsedObjCMethods;
5670 ObjCImplParsingDataRAII(
Parser &parser, Decl *D)
5671 : P(parser), Dcl(D), HasCFunction(
false) {
5672 P.CurParsedObjCImpl =
this;
5675 ~ObjCImplParsingDataRAII();
5677 void finish(SourceRange AtEnd);
5678 bool isFinished()
const {
return Finished; }
5683 ObjCImplParsingDataRAII *CurParsedObjCImpl;
5687 void StashAwayMethodOrFunctionBodyTokens(Decl *MDecl);
5701 DeclGroupPtrTy ParseObjCAtImplementationDeclaration(SourceLocation AtLoc,
5702 ParsedAttributes &Attrs);
5710 Decl *ParseObjCAtAliasDeclaration(SourceLocation atLoc);
5725 Decl *ParseObjCPropertySynthesize(SourceLocation atLoc);
5736 Decl *ParseObjCPropertyDynamic(SourceLocation atLoc);
5748 IdentifierInfo *ParseObjCSelectorPiece(SourceLocation &MethodLocation);
5756 bool isTokIdentifier_in()
const;
5765 ParsedAttributes *ParamAttrs);
5779 Decl *ParseObjCMethodPrototype(
5781 bool MethodDefinition =
true);
5813 Decl *ParseObjCMethodDecl(
5816 bool MethodDefinition =
true);
5846 void ParseObjCPropertyAttribute(ObjCDeclSpec &DS);
5852 Decl *ParseObjCMethodDefinition();
5856 ExprResult ParseObjCAtExpression(SourceLocation AtLocation);
5857 ExprResult ParseObjCStringLiteral(SourceLocation AtLoc);
5864 ExprResult ParseObjCCharacterLiteral(SourceLocation AtLoc);
5873 ExprResult ParseObjCNumericLiteral(SourceLocation AtLoc);
5882 ExprResult ParseObjCBooleanLiteral(SourceLocation AtLoc,
bool ArgValue);
5884 ExprResult ParseObjCArrayLiteral(SourceLocation AtLoc);
5885 ExprResult ParseObjCDictionaryLiteral(SourceLocation AtLoc);
5892 ExprResult ParseObjCBoxedExpr(SourceLocation AtLoc);
5898 ExprResult ParseObjCEncodeExpression(SourceLocation AtLoc);
5904 ExprResult ParseObjCSelectorExpression(SourceLocation AtLoc);
5910 ExprResult ParseObjCProtocolExpression(SourceLocation AtLoc);
5917 bool isSimpleObjCMessageExpression();
5972 ExprResult ParseObjCMessageExpressionBody(SourceLocation LBracloc,
5973 SourceLocation SuperLoc,
5975 Expr *ReceiverExpr);
6001 bool ParseObjCXXMessageReceiver(
bool &IsExpr,
void *&TypeOrExpr);
6006 enum class ParsedStmtContext;
6008 StmtResult ParseObjCAtStatement(SourceLocation atLoc,
6009 ParsedStmtContext StmtCtx);
6024 StmtResult ParseObjCTryStmt(SourceLocation atLoc);
6031 StmtResult ParseObjCThrowStmt(SourceLocation atLoc);
6038 StmtResult ParseObjCSynchronizedStmt(SourceLocation atLoc);
6045 StmtResult ParseObjCAutoreleasePoolStmt(SourceLocation atLoc);
6072 bool isStartOfObjCClassMessageMissingOpenBracket();
6104 bool OpenACCDirectiveParsing =
false;
6108 bool AllowOpenACCArraySections =
false;
6112 class OpenACCArraySectionRAII {
6116 OpenACCArraySectionRAII(
Parser &P) : P(P) {
6117 assert(!P.AllowOpenACCArraySections);
6118 P.AllowOpenACCArraySections =
true;
6120 ~OpenACCArraySectionRAII() {
6121 assert(P.AllowOpenACCArraySections);
6122 P.AllowOpenACCArraySections =
false;
6129 struct OpenACCDirectiveParseInfo {
6131 SourceLocation StartLoc;
6132 SourceLocation DirLoc;
6133 SourceLocation LParenLoc;
6134 SourceLocation RParenLoc;
6135 SourceLocation EndLoc;
6136 SourceLocation MiscLoc;
6138 SmallVector<Expr *> Exprs;
6139 SmallVector<OpenACCClause *> Clauses;
6144 struct OpenACCWaitParseInfo {
6145 bool Failed =
false;
6146 Expr *DevNumExpr =
nullptr;
6147 SourceLocation QueuesLoc;
6148 SmallVector<Expr *> QueueIdExprs;
6150 SmallVector<Expr *> getAllExprs() {
6151 SmallVector<Expr *>
Out;
6152 Out.push_back(DevNumExpr);
6153 llvm::append_range(Out, QueueIdExprs);
6157 struct OpenACCCacheParseInfo {
6158 bool Failed =
false;
6159 SourceLocation ReadOnlyLoc;
6160 SmallVector<Expr *> Vars;
6165 enum class OpenACCParseCanContinue { Cannot = 0, Can = 1 };
6171 using OpenACCClauseParseResult =
6172 llvm::PointerIntPair<OpenACCClause *, 1, OpenACCParseCanContinue>;
6174 OpenACCClauseParseResult OpenACCCanContinue();
6175 OpenACCClauseParseResult OpenACCCannotContinue();
6176 OpenACCClauseParseResult OpenACCSuccess(OpenACCClause *Clause);
6180 OpenACCDirectiveParseInfo ParseOpenACCDirective();
6190 OpenACCCacheParseInfo ParseOpenACCCacheVarList();
6196 using OpenACCVarParseResult = std::pair<ExprResult, OpenACCParseCanContinue>;
6222 OpenACCClauseParseResult
6223 ParseOpenACCClauseParams(ArrayRef<const OpenACCClause *> ExistingClauses,
6225 SourceLocation ClauseLoc);
6229 OpenACCClauseParseResult
6230 ParseOpenACCClause(ArrayRef<const OpenACCClause *> ExistingClauses,
6240 SmallVector<OpenACCClause *>
6249 OpenACCWaitParseInfo ParseOpenACCWaitArgument(SourceLocation Loc,
6254 std::variant<std::monostate, StringLiteral *, IdentifierInfo *>
6255 ParseOpenACCBindClauseArgument();
6260 using OpenACCIntExprParseResult =
6261 std::pair<ExprResult, OpenACCParseCanContinue>;
6266 SourceLocation Loc);
6271 llvm::SmallVectorImpl<Expr *> &IntExprs);
6284 bool ParseOpenACCDeviceTypeList(llvm::SmallVector<IdentifierLoc> &Archs);
6298 SourceLocation Loc);
6313 llvm::SmallVectorImpl<Expr *> &SizeExprs);
6325 bool ParseOpenACCGangArgList(SourceLocation GangLoc,
6326 llvm::SmallVectorImpl<OpenACCGangKind> &GKs,
6327 llvm::SmallVectorImpl<Expr *> &IntExprs);
6329 using OpenACCGangArgRes = std::pair<OpenACCGangKind, ExprResult>;
6333 OpenACCGangArgRes ParseOpenACCGangArg(SourceLocation GangLoc);
6337 ParseOpenACCAfterRoutineDecl(
AccessSpecifier &AS, ParsedAttributes &Attrs,
6339 OpenACCDirectiveParseInfo &DirInfo);
6340 StmtResult ParseOpenACCAfterRoutineStmt(OpenACCDirectiveParseInfo &DirInfo);
6358 bool OpenMPDirectiveParsing =
false;
6363 void ReplayOpenMPAttributeTokens(
CachedTokens &OpenMPTokens) {
6366 if (!OpenMPTokens.empty()) {
6367 PP.EnterToken(Tok,
true);
6368 PP.EnterTokenStream(OpenMPTokens,
true,
6380 SourceLocation Loc);
6385 llvm::omp::TraitSet
Set,
6386 llvm::omp::TraitSelector Selector,
6387 llvm::StringMap<SourceLocation> &Seen);
6391 llvm::omp::TraitSet
Set,
6392 llvm::StringMap<SourceLocation> &Seen);
6396 llvm::StringMap<SourceLocation> &Seen);
6400 llvm::omp::TraitSet
Set,
6401 llvm::StringMap<SourceLocation> &Seen);
6409 llvm::omp::TraitSet
Set,
6410 llvm::StringMap<SourceLocation> &SeenSelectors);
6417 void parseOMPContextSelectorSet(
OMPTraitSet &TISet,
6418 llvm::StringMap<SourceLocation> &SeenSets);
6425 bool parseOMPContextSelectors(SourceLocation Loc,
OMPTraitInfo &TI);
6428 bool parseOpenMPAppendArgs(SmallVectorImpl<OMPInteropInfo> &InteropInfos);
6432 bool parseOMPDeclareVariantMatchClause(SourceLocation Loc,
OMPTraitInfo &TI,
6438 SourceLocation Loc);
6457 void ParseOpenMPAssumesDirective(OpenMPDirectiveKind DKind,
6458 SourceLocation Loc);
6461 void ParseOpenMPEndAssumesDirective(SourceLocation Loc);
6478 void ParseOpenMPClauses(OpenMPDirectiveKind DKind,
6479 SmallVectorImpl<clang::OMPClause *> &Clauses,
6480 SourceLocation Loc);
6483 void ParseOMPDeclareTargetClauses(SemaOpenMP::DeclareTargetContextInfo &DTCI);
6486 void ParseOMPEndDeclareTargetDirective(OpenMPDirectiveKind BeginDKind,
6487 OpenMPDirectiveKind EndDKind,
6488 SourceLocation Loc);
6492 void skipUntilPragmaOpenMPEnd(OpenMPDirectiveKind DKind);
6498 void parseOMPEndDirective(OpenMPDirectiveKind BeginKind,
6499 OpenMPDirectiveKind ExpectedKind,
6500 OpenMPDirectiveKind FoundKind,
6501 SourceLocation MatchingLoc, SourceLocation FoundLoc,
6502 bool SkipUntilOpenMPEnd);
6543 AccessSpecifier &AS, ParsedAttributes &Attrs,
bool Delayed =
false,
6545 Decl *TagDecl =
nullptr);
6559 DeclGroupPtrTy ParseOpenMPDeclareReductionDirective(AccessSpecifier AS);
6563 void ParseOpenMPReductionInitializerForDecl(VarDecl *OmpPrivParm);
6575 DeclGroupPtrTy ParseOpenMPDeclareMapperDirective(AccessSpecifier AS);
6578 TypeResult parseOpenMPDeclareMapperVarDecl(SourceRange &Range,
6579 DeclarationName &Name,
6580 AccessSpecifier AS =
AS_none);
6594 bool ParseOpenMPSimpleVarList(
6595 OpenMPDirectiveKind Kind,
6596 const llvm::function_ref<
void(CXXScopeSpec &, DeclarationNameInfo)>
6598 bool AllowScopeSpecifier);
6647 StmtResult ParseOpenMPDeclarativeOrExecutableDirective(
6648 ParsedStmtContext StmtCtx,
bool ReadDirectiveWithinMetadirective =
false);
6658 ParseOpenMPExecutableDirective(ParsedStmtContext StmtCtx,
6659 OpenMPDirectiveKind DKind, SourceLocation Loc,
6660 bool ReadDirectiveWithinMetadirective);
6669 StmtResult ParseOpenMPInformationalDirective(
6670 ParsedStmtContext StmtCtx, OpenMPDirectiveKind DKind, SourceLocation Loc,
6671 bool ReadDirectiveWithinMetadirective);
6700 OMPClause *ParseOpenMPClause(OpenMPDirectiveKind DKind,
6785 bool ParseOpenMPIndirectClause(SemaOpenMP::DeclareTargetContextInfo &DTCI,
6810 OMPClause *ParseOpenMPSingleExprWithArgClause(OpenMPDirectiveKind DKind,
6815 OMPClause *ParseOpenMPLoopRangeClause();
6824 OMPClause *ParseOpenMPPermutationClause();
6928 OMPClause *ParseOpenMPVarListClause(OpenMPDirectiveKind DKind,
6942 SourceLocation &ClauseNameLoc,
6943 SourceLocation &OpenLoc,
6944 SourceLocation &CloseLoc,
6945 SmallVectorImpl<Expr *> &Exprs,
6946 bool ReqIntConst =
false);
6961 OMPClause *ParseOpenMPUsesAllocatorClause(OpenMPDirectiveKind DKind);
6964 bool ParseOMPInteropInfo(OMPInteropInfo &InteropInfo,
OpenMPClauseKind Kind);
7002 OMPClause *ParseOpenMPOMPXAttributesClause(
bool ParseOnly);
7009 bool IsAddressOfOperand =
false);
7013 SemaOpenMP::OpenMPVarListDataTy &
Data,
7014 const LangOptions &LangOpts);
7017 SmallVectorImpl<Expr *> &Vars,
7018 SemaOpenMP::OpenMPVarListDataTy &
Data);
7053 std::unique_ptr<PragmaHandler> AlignHandler;
7054 std::unique_ptr<PragmaHandler> GCCVisibilityHandler;
7055 std::unique_ptr<PragmaHandler> OptionsHandler;
7056 std::unique_ptr<PragmaHandler> PackHandler;
7057 std::unique_ptr<PragmaHandler> MSStructHandler;
7058 std::unique_ptr<PragmaHandler> UnusedHandler;
7059 std::unique_ptr<PragmaHandler> WeakHandler;
7060 std::unique_ptr<PragmaHandler> RedefineExtnameHandler;
7061 std::unique_ptr<PragmaHandler> FPContractHandler;
7062 std::unique_ptr<PragmaHandler> OpenCLExtensionHandler;
7063 std::unique_ptr<PragmaHandler> OpenMPHandler;
7064 std::unique_ptr<PragmaHandler> OpenACCHandler;
7065 std::unique_ptr<PragmaHandler> PCSectionHandler;
7066 std::unique_ptr<PragmaHandler> MSCommentHandler;
7067 std::unique_ptr<PragmaHandler> MSDetectMismatchHandler;
7068 std::unique_ptr<PragmaHandler> FPEvalMethodHandler;
7069 std::unique_ptr<PragmaHandler> FloatControlHandler;
7070 std::unique_ptr<PragmaHandler> MSPointersToMembers;
7071 std::unique_ptr<PragmaHandler> MSVtorDisp;
7072 std::unique_ptr<PragmaHandler> MSInitSeg;
7073 std::unique_ptr<PragmaHandler> MSDataSeg;
7074 std::unique_ptr<PragmaHandler> MSBSSSeg;
7075 std::unique_ptr<PragmaHandler> MSConstSeg;
7076 std::unique_ptr<PragmaHandler> MSCodeSeg;
7077 std::unique_ptr<PragmaHandler> MSSection;
7078 std::unique_ptr<PragmaHandler> MSStrictGuardStackCheck;
7079 std::unique_ptr<PragmaHandler> MSRuntimeChecks;
7080 std::unique_ptr<PragmaHandler> MSIntrinsic;
7081 std::unique_ptr<PragmaHandler> MSFunction;
7082 std::unique_ptr<PragmaHandler> MSOptimize;
7083 std::unique_ptr<PragmaHandler> MSFenvAccess;
7084 std::unique_ptr<PragmaHandler> MSAllocText;
7085 std::unique_ptr<PragmaHandler> CUDAForceHostDeviceHandler;
7086 std::unique_ptr<PragmaHandler> OptimizeHandler;
7087 std::unique_ptr<PragmaHandler> LoopHintHandler;
7088 std::unique_ptr<PragmaHandler> UnrollHintHandler;
7089 std::unique_ptr<PragmaHandler> NoUnrollHintHandler;
7090 std::unique_ptr<PragmaHandler> UnrollAndJamHintHandler;
7091 std::unique_ptr<PragmaHandler> NoUnrollAndJamHintHandler;
7092 std::unique_ptr<PragmaHandler> FPHandler;
7093 std::unique_ptr<PragmaHandler> STDCFenvAccessHandler;
7094 std::unique_ptr<PragmaHandler> STDCFenvRoundHandler;
7095 std::unique_ptr<PragmaHandler> STDCCXLIMITHandler;
7096 std::unique_ptr<PragmaHandler> STDCUnknownHandler;
7097 std::unique_ptr<PragmaHandler> AttributePragmaHandler;
7098 std::unique_ptr<PragmaHandler> MaxTokensHerePragmaHandler;
7099 std::unique_ptr<PragmaHandler> MaxTokensTotalPragmaHandler;
7100 std::unique_ptr<PragmaHandler> ExportHandler;
7101 std::unique_ptr<PragmaHandler> RISCVPragmaHandler;
7104 void initializePragmaHandlers();
7107 void resetPragmaHandlers();
7114 void HandlePragmaUnused();
7118 void HandlePragmaVisibility();
7122 void HandlePragmaPack();
7126 void HandlePragmaMSStruct();
7128 void HandlePragmaMSPointersToMembers();
7130 void HandlePragmaMSVtorDisp();
7132 void HandlePragmaMSPragma();
7133 bool HandlePragmaMSSection(StringRef PragmaName,
7134 SourceLocation PragmaLocation);
7135 bool HandlePragmaMSSegment(StringRef PragmaName,
7136 SourceLocation PragmaLocation);
7139 bool HandlePragmaMSInitSeg(StringRef PragmaName,
7140 SourceLocation PragmaLocation);
7145 bool HandlePragmaMSStrictGuardStackCheck(StringRef PragmaName,
7146 SourceLocation PragmaLocation);
7147 bool HandlePragmaMSFunction(StringRef PragmaName,
7148 SourceLocation PragmaLocation);
7149 bool HandlePragmaMSAllocText(StringRef PragmaName,
7150 SourceLocation PragmaLocation);
7153 bool HandlePragmaMSOptimize(StringRef PragmaName,
7154 SourceLocation PragmaLocation);
7157 bool HandlePragmaMSIntrinsic(StringRef PragmaName,
7158 SourceLocation PragmaLocation);
7162 void HandlePragmaAlign();
7166 void HandlePragmaDump();
7170 void HandlePragmaWeak();
7174 void HandlePragmaWeakAlias();
7178 void HandlePragmaRedefineExtname();
7182 void HandlePragmaFPContract();
7186 void HandlePragmaFEnvAccess();
7190 void HandlePragmaFEnvRound();
7194 void HandlePragmaCXLimitedRange();
7198 void HandlePragmaFloatControl();
7202 void HandlePragmaFP();
7206 void HandlePragmaOpenCLExtension();
7210 StmtResult HandlePragmaCaptured();
7214 bool HandlePragmaLoopHint(LoopHint &Hint);
7216 bool ParsePragmaAttributeSubjectMatchRuleSet(
7218 SourceLocation &AnyLoc, SourceLocation &LastMatchRuleEndLoc);
7220 void HandlePragmaAttribute();
7226 void HandlePragmaExport();
7252 enum class ParsedStmtContext {
7255 AllowDeclarationsInC = 0x1,
7257 AllowStandaloneOpenMPDirectives = 0x2,
7264 Compound = AllowDeclarationsInC | AllowStandaloneOpenMPDirectives,
7281 ParsedStmtContext StmtCtx = ParsedStmtContext::SubStmt,
7336 ParseStatementOrDeclaration(
StmtVector &Stmts, ParsedStmtContext StmtCtx,
7340 StmtResult ParseStatementOrDeclarationAfterAttributes(
7341 StmtVector &Stmts, ParsedStmtContext StmtCtx,
7346 StmtResult ParseExprStatement(ParsedStmtContext StmtCtx);
7360 ParsedStmtContext StmtCtx);
7369 StmtResult ParseCaseStatement(ParsedStmtContext StmtCtx,
7370 bool MissingCase =
false,
7380 StmtResult ParseDefaultStatement(ParsedStmtContext StmtCtx);
7382 StmtResult ParseCompoundStatement(
bool isStmtExpr =
false);
7408 StmtResult ParseCompoundStatement(
bool isStmtExpr,
unsigned ScopeFlags);
7413 void ParseCompoundStatementLeadingPragmas();
7415 void DiagnoseLabelAtEndOfCompoundStatement();
7425 StmtResult ParseCompoundStatementBody(
bool isStmtExpr =
false);
7443 bool ParseParenExprOrCondition(
StmtResult *InitStmt,
7559 StmtResult ParseBreakOrContinueStatement(
bool IsContinue);
7576 void ParseMicrosoftIfExistsStatement(
StmtVector &Stmts);
7623 StmtResult ParseCXXCatchBlock(
bool FnCatch =
false);
7661 Decl *ParseFunctionStatementBody(
Decl *
Decl, ParseScope &BodyScope);
7670 Decl *ParseFunctionTryBlock(
Decl *
Decl, ParseScope &BodyScope);
7676 bool trySkippingFunctionBody();
7684 bool isDeclarationStatement(
bool DisambiguatingWithExpression =
false) {
7686 return isCXXDeclarationStatement(DisambiguatingWithExpression);
7694 bool isForInitDeclaration() {
7698 return Tok.is(tok::kw_using) ||
7699 isCXXSimpleDeclaration(
true);
7704 bool isForRangeIdentifier();
7721 unsigned &NumLineToksConsumed,
7722 bool IsUnevaluated);
7765 StmtResult ParseMicrosoftAsmStatement(SourceLocation AsmLoc);
7781 bool ParseAsmOperandsOpt(SmallVectorImpl<IdentifierInfo *> &Names,
7782 SmallVectorImpl<Expr *> &Constraints,
7783 SmallVectorImpl<Expr *> &Exprs);
7785 class GNUAsmQualifiers {
7786 unsigned Qualifiers = AQ_unspecified;
7795 static const char *getQualifierName(AQ Qualifier);
7796 bool setAsmQualifier(AQ Qualifier);
7797 inline bool isVolatile()
const {
return Qualifiers & AQ_volatile; };
7798 inline bool isInline()
const {
return Qualifiers & AQ_inline; };
7799 inline bool isGoto()
const {
return Qualifiers & AQ_goto; }
7803 bool isGCCAsmStatement(
const Token &TokAfterAsm)
const;
7805 bool isGNUAsmQualifier(
const Token &TokAfterAsm)
const;
7806 GNUAsmQualifiers::AQ getGNUAsmQualifier(
const Token &Tok)
const;
7819 bool parseGNUAsmQualifierListOpt(GNUAsmQualifiers &AQ);
7843 unsigned TemplateParameterDepth;
7846 class TemplateParameterDepthRAII {
7848 unsigned AddedLevels;
7851 explicit TemplateParameterDepthRAII(
unsigned &Depth)
7852 : Depth(Depth), AddedLevels(0) {}
7854 ~TemplateParameterDepthRAII() { Depth -= AddedLevels; }
7860 void addDepth(
unsigned D) {
7864 void setAddedDepth(
unsigned D) {
7865 Depth = Depth - AddedLevels + D;
7869 unsigned getDepth()
const {
return Depth; }
7870 unsigned getOriginalDepth()
const {
return Depth - AddedLevels; }
7875 SmallVector<TemplateIdAnnotation *, 16> TemplateIds;
7881 bool DelayTemplateIdDestruction =
false;
7883 void MaybeDestroyTemplateIds() {
7884 if (DelayTemplateIdDestruction)
7886 if (!TemplateIds.empty() &&
7887 (Tok.is(tok::eof) || !PP.mightHavePendingAnnotationTokens()))
7888 DestroyTemplateIds();
7890 void DestroyTemplateIds();
7894 struct DestroyTemplateIdAnnotationsRAIIObj {
7897 DestroyTemplateIdAnnotationsRAIIObj(
Parser &Self) : Self(Self) {}
7898 ~DestroyTemplateIdAnnotationsRAIIObj() { Self.MaybeDestroyTemplateIds(); }
7901 struct DelayTemplateIdDestructionRAII {
7903 bool PrevDelayTemplateIdDestruction;
7905 DelayTemplateIdDestructionRAII(
Parser &Self,
7906 bool DelayTemplateIdDestruction) noexcept
7908 PrevDelayTemplateIdDestruction(Self.DelayTemplateIdDestruction) {
7909 Self.DelayTemplateIdDestruction = DelayTemplateIdDestruction;
7912 ~DelayTemplateIdDestructionRAII() noexcept {
7913 Self.DelayTemplateIdDestruction = PrevDelayTemplateIdDestruction;
7918 SmallVector<const IdentifierInfo *, 8> TentativelyDeclaredIdentifiers;
7930 struct AngleBracketTracker {
7933 enum Priority :
unsigned short {
7935 PotentialTypo = 0x0,
7937 DependentName = 0x2,
7940 SpaceBeforeLess = 0x0,
7942 NoSpaceBeforeLess = 0x1,
7973 if (!Locs.empty() && Locs.back().isActive(P)) {
7974 if (Locs.back().Priority <= Prio) {
7976 Locs.back().LessLoc = LessLoc;
7977 Locs.back().Priority = Prio;
7980 Locs.push_back({
TemplateName, LessLoc, Prio, P.ParenCount,
7981 P.BracketCount, P.BraceCount});
7989 while (!Locs.empty() && Locs.back().isActiveOrNested(P))
7996 if (!Locs.empty() && Locs.back().isActive(P))
7997 return &Locs.back();
8002 AngleBracketTracker AngleBrackets;
8007 struct ParsedTemplateInfo {
8008 ParsedTemplateInfo()
8012 bool isSpecialization,
8013 bool lastParameterListWasEmpty =
false)
8016 TemplateParams(TemplateParams),
8017 LastParameterListWasEmpty(lastParameterListWasEmpty) {}
8019 explicit ParsedTemplateInfo(SourceLocation ExternLoc,
8020 SourceLocation TemplateLoc)
8022 TemplateParams(
nullptr), ExternLoc(ExternLoc),
8023 TemplateLoc(TemplateLoc), LastParameterListWasEmpty(
false) {}
8033 SourceLocation ExternLoc;
8037 SourceLocation TemplateLoc;
8040 bool LastParameterListWasEmpty;
8042 SourceRange getSourceRange() const LLVM_READONLY;
8046 void LexTemplateFunctionForLateParsing(
CachedTokens &Toks);
8049 void ParseLateTemplatedFuncDef(LateParsedTemplate &LPT);
8051 static
void LateTemplateParserCallback(
void *P, LateParsedTemplate &LPT);
8059 void checkPotentialAngleBracket(
ExprResult &PotentialTemplateName);
8060 bool checkPotentialAngleBracketDelimiter(const AngleBracketTracker::Loc &,
8061 const Token &OpToken);
8062 bool checkPotentialAngleBracketDelimiter(const Token &OpToken) {
8063 if (
auto *Info = AngleBrackets.getCurrent(*
this))
8064 return checkPotentialAngleBracketDelimiter(*Info, OpToken);
8075 SourceLocation &DeclEnd,
8076 ParsedAttributes &AccessAttrs);
8123 ParsingDeclRAIIObject &DiagsFromParams, SourceLocation &DeclEnd,
8135 bool ParseTemplateParameters(MultiParseScope &TemplateScopes,
unsigned Depth,
8136 SmallVectorImpl<NamedDecl *> &TemplateParams,
8137 SourceLocation &LAngleLoc,
8138 SourceLocation &RAngleLoc);
8150 bool ParseTemplateParameterList(
unsigned Depth,
8151 SmallVectorImpl<NamedDecl *> &TemplateParams);
8153 enum class TPResult;
8157 TPResult isStartOfTemplateTypeParameter();
8181 NamedDecl *ParseTemplateParameter(
unsigned Depth,
unsigned Position);
8194 NamedDecl *ParseTypeParameter(
unsigned Depth,
unsigned Position);
8210 NamedDecl *ParseTemplateTemplateParameter(
unsigned Depth,
unsigned Position);
8220 NamedDecl *ParseNonTypeTemplateParameter(
unsigned Depth,
unsigned Position);
8224 bool isTypeConstraintAnnotation();
8236 bool TryAnnotateTypeConstraint();
8238 void DiagnoseMisplacedEllipsis(SourceLocation EllipsisLoc,
8239 SourceLocation CorrectLoc,
8240 bool AlreadyHasEllipsis,
8241 bool IdentifierHasName);
8242 void DiagnoseMisplacedEllipsisInDeclarator(SourceLocation EllipsisLoc,
8245 typedef SmallVector<ParsedTemplateArgument, 16> TemplateArgList;
8262 bool ParseGreaterThanInTemplateList(SourceLocation LAngleLoc,
8263 SourceLocation &RAngleLoc,
8264 bool ConsumeLastToken,
8265 bool ObjCGenericList);
8278 bool ParseTemplateIdAfterTemplateName(
bool ConsumeLastToken,
8279 SourceLocation &LAngleLoc,
8280 TemplateArgList &TemplateArgs,
8281 SourceLocation &RAngleLoc,
8326 CXXScopeSpec &SS, SourceLocation TemplateKWLoc,
8328 bool AllowTypeAnnotation =
true,
8329 bool TypeConstraint =
false);
8347 AnnotateTemplateIdTokenAsType(CXXScopeSpec &SS,
8349 bool IsClassName =
false);
8361 bool ParseTemplateArgumentList(TemplateArgList &TemplateArgs,
8365 ParsedTemplateArgument ParseTemplateTemplateArgument();
8377 ParsedTemplateArgument ParseTemplateArgument();
8389 SourceLocation ExternLoc,
8390 SourceLocation TemplateLoc,
8391 SourceLocation &DeclEnd,
8392 ParsedAttributes &AccessAttrs,
8401 Decl *ParseConceptDefinition(
const ParsedTemplateInfo &TemplateInfo,
8402 SourceLocation &DeclEnd);
8430 class TentativeParsingAction {
8432 PreferredTypeBuilder PrevPreferredType;
8434 size_t PrevTentativelyDeclaredIdentifierCount;
8435 unsigned short PrevParenCount, PrevBracketCount, PrevBraceCount;
8439 explicit TentativeParsingAction(Parser &p,
bool Unannotated =
false)
8440 : P(p), PrevPreferredType(P.PreferredType) {
8442 PrevTentativelyDeclaredIdentifierCount =
8443 P.TentativelyDeclaredIdentifiers.size();
8444 PrevParenCount = P.ParenCount;
8445 PrevBracketCount = P.BracketCount;
8446 PrevBraceCount = P.BraceCount;
8447 P.PP.EnableBacktrackAtThisPos(Unannotated);
8451 assert(isActive &&
"Parsing action was finished!");
8452 P.TentativelyDeclaredIdentifiers.resize(
8453 PrevTentativelyDeclaredIdentifierCount);
8454 P.PP.CommitBacktrackedTokens();
8458 assert(isActive &&
"Parsing action was finished!");
8460 P.PreferredType = PrevPreferredType;
8462 P.TentativelyDeclaredIdentifiers.resize(
8463 PrevTentativelyDeclaredIdentifierCount);
8464 P.ParenCount = PrevParenCount;
8465 P.BracketCount = PrevBracketCount;
8466 P.BraceCount = PrevBraceCount;
8469 ~TentativeParsingAction() {
8470 assert(!isActive &&
"Forgot to call Commit or Revert!");
8476 class RevertingTentativeParsingAction
8477 :
private Parser::TentativeParsingAction {
8479 using TentativeParsingAction::TentativeParsingAction;
8481 ~RevertingTentativeParsingAction() { Revert(); }
8516 bool isCXXDeclarationStatement(
bool DisambiguatingWithExpression =
false);
8542 bool isCXXSimpleDeclaration(
bool AllowForRangeDecl);
8555 bool isCXXFunctionDeclarator(
bool *IsAmbiguous =
nullptr,
8559 struct ConditionDeclarationOrInitStatementState;
8560 enum class ConditionOrInitStatement {
8587 ConditionOrInitStatement
8588 isCXXConditionDeclarationOrInitStatement(
bool CanBeInitStmt,
8589 bool CanBeForRangeDecl);
8615 return isCXXTypeId(Context, isAmbiguous);
8629 bool isEnumBase(
bool AllowSemi);
8749 TPResult BracedCastResult = TPResult::False,
8750 bool *InvalidAsDeclSpec =
nullptr);
8755 bool isCXXDeclarationSpecifierAType();
8761 TPResult isTemplateArgumentList(
unsigned TokensToSkip);
8766 TPResult isExplicitBool();
8771 bool isTentativelyDeclared(IdentifierInfo *II);
8790 TPResult TryParseSimpleDeclaration(
bool AllowForRangeDecl);
8798 TPResult TryParseTypeofSpecifier();
8802 TPResult TryParseProtocolQualifiers();
8804 TPResult TryParsePtrOperatorSeq();
8826 TPResult TryParseOperatorId();
8857 TPResult TryParseInitDeclaratorList(
bool MayHaveTrailingReturnType =
false);
8914 TPResult TryParseDeclarator(
bool mayBeAbstract,
bool mayHaveIdentifier =
true,
8915 bool mayHaveDirectInit =
false,
8916 bool mayHaveTrailingReturnType =
false);
8937 TPResult TryParseParameterDeclarationClause(
8938 bool *InvalidAsDeclaration =
nullptr,
bool VersusTemplateArg =
false,
8955 TPResult TryParseFunctionDeclarator(
bool MayHaveTrailingReturnType =
false);
8961 bool NameAfterArrowIsNonType();
8967 TPResult TryParseBracketDeclarator();
8971 TPResult TryConsumeDeclarationSpecifier();
8975 bool TrySkipAttributes();
9017 isCXX11AttributeSpecifier(
bool Disambiguate =
false,
9018 bool OuterMightBeMessageSend =
false);