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,
1381 ParsedAttributes *OutAttrs =
nullptr);
1390 ParsedAttributes *OutAttrs =
nullptr);
1396 void ParseLexedMethodDeclarations(ParsingClass &
Class);
1397 void ParseLexedMethodDeclaration(LateParsedMethodDeclaration &LM);
1402 void ParseLexedMethodDefs(ParsingClass &
Class);
1403 void ParseLexedMethodDef(LexedMethod &LM);
1409 void ParseLexedMemberInitializers(ParsingClass &
Class);
1410 void ParseLexedMemberInitializer(LateParsedMemberInitializer &MI);
1444 ParsedAttributes *Attrs =
nullptr);
1450 IdentifierInfo *Ident_vector;
1451 IdentifierInfo *Ident_bool;
1452 IdentifierInfo *Ident_Bool;
1456 IdentifierInfo *Ident_pixel;
1459 IdentifierInfo *Ident_introduced;
1462 IdentifierInfo *Ident_deprecated;
1465 IdentifierInfo *Ident_obsoleted;
1468 IdentifierInfo *Ident_unavailable;
1471 IdentifierInfo *Ident_message;
1474 IdentifierInfo *Ident_strict;
1477 IdentifierInfo *Ident_replacement;
1480 IdentifierInfo *Ident_environment;
1483 IdentifierInfo *Ident_language, *Ident_defined_in,
1484 *Ident_generated_declaration, *Ident_USR;
1487 AttributeFactory AttrFactory;
1492 bool TryAltiVecToken(DeclSpec &DS, SourceLocation Loc,
const char *&PrevSpec,
1497 if (Tok.getIdentifierInfo() != Ident_vector &&
1498 Tok.getIdentifierInfo() != Ident_bool &&
1499 Tok.getIdentifierInfo() != Ident_Bool &&
1500 (!
getLangOpts().AltiVec || Tok.getIdentifierInfo() != Ident_pixel))
1503 return TryAltiVecTokenOutOfLine(DS, Loc, PrevSpec, DiagID,
isInvalid);
1509 bool TryAltiVecVectorToken() {
1511 Tok.getIdentifierInfo() != Ident_vector)
1513 return TryAltiVecVectorTokenOutOfLine();
1518 bool TryAltiVecVectorTokenOutOfLine();
1519 bool TryAltiVecTokenOutOfLine(DeclSpec &DS, SourceLocation Loc,
1520 const char *&PrevSpec,
unsigned &DiagID,
1524 ParsedAttributes &OutAttrs);
1534 static void TakeTypeAttrsAppendingFrom(LateParsedAttrList &To,
1535 LateParsedAttrList &From);
1537 void ParseLexedPragmas(ParsingClass &
Class);
1538 void ParseLexedPragma(LateParsedPragma &LP);
1546 bool ConsumeAndStoreFunctionPrologue(
CachedTokens &Toks);
1562 bool ConsumeFinalToken =
true) {
1563 return ConsumeAndStoreUntil(T1, T1, Toks,
StopAtSemi, ConsumeFinalToken);
1574 bool ConsumeFinalToken =
true);
1582 enum class DeclSpecContext {
1587 DSC_alias_declaration,
1592 DSC_template_type_arg,
1593 DSC_objc_method_result,
1602 static bool isTypeSpecifier(DeclSpecContext DSC) {
1604 case DeclSpecContext::DSC_normal:
1605 case DeclSpecContext::DSC_template_param:
1606 case DeclSpecContext::DSC_template_arg:
1607 case DeclSpecContext::DSC_class:
1608 case DeclSpecContext::DSC_top_level:
1609 case DeclSpecContext::DSC_objc_method_result:
1610 case DeclSpecContext::DSC_condition:
1613 case DeclSpecContext::DSC_template_type_arg:
1614 case DeclSpecContext::DSC_type_specifier:
1615 case DeclSpecContext::DSC_conv_operator:
1616 case DeclSpecContext::DSC_trailing:
1617 case DeclSpecContext::DSC_alias_declaration:
1618 case DeclSpecContext::DSC_association:
1619 case DeclSpecContext::DSC_new:
1622 llvm_unreachable(
"Missing DeclSpecContext case");
1626 enum class AllowDefiningTypeSpec {
1643 static AllowDefiningTypeSpec
1644 isDefiningTypeSpecifierContext(DeclSpecContext DSC,
bool IsCPlusPlus) {
1646 case DeclSpecContext::DSC_normal:
1647 case DeclSpecContext::DSC_class:
1648 case DeclSpecContext::DSC_top_level:
1649 case DeclSpecContext::DSC_alias_declaration:
1650 case DeclSpecContext::DSC_objc_method_result:
1651 return AllowDefiningTypeSpec::Yes;
1653 case DeclSpecContext::DSC_condition:
1654 case DeclSpecContext::DSC_template_param:
1655 return AllowDefiningTypeSpec::YesButInvalid;
1657 case DeclSpecContext::DSC_template_type_arg:
1658 case DeclSpecContext::DSC_type_specifier:
1659 return AllowDefiningTypeSpec::NoButErrorRecovery;
1661 case DeclSpecContext::DSC_association:
1662 return IsCPlusPlus ? AllowDefiningTypeSpec::NoButErrorRecovery
1663 : AllowDefiningTypeSpec::Yes;
1665 case DeclSpecContext::DSC_trailing:
1666 case DeclSpecContext::DSC_conv_operator:
1667 case DeclSpecContext::DSC_template_arg:
1668 case DeclSpecContext::DSC_new:
1669 return AllowDefiningTypeSpec::No;
1671 llvm_unreachable(
"Missing DeclSpecContext case");
1675 static bool isOpaqueEnumDeclarationContext(DeclSpecContext DSC) {
1677 case DeclSpecContext::DSC_normal:
1678 case DeclSpecContext::DSC_class:
1679 case DeclSpecContext::DSC_top_level:
1682 case DeclSpecContext::DSC_alias_declaration:
1683 case DeclSpecContext::DSC_objc_method_result:
1684 case DeclSpecContext::DSC_condition:
1685 case DeclSpecContext::DSC_template_param:
1686 case DeclSpecContext::DSC_template_type_arg:
1687 case DeclSpecContext::DSC_type_specifier:
1688 case DeclSpecContext::DSC_trailing:
1689 case DeclSpecContext::DSC_association:
1690 case DeclSpecContext::DSC_conv_operator:
1691 case DeclSpecContext::DSC_template_arg:
1692 case DeclSpecContext::DSC_new:
1696 llvm_unreachable(
"Missing DeclSpecContext case");
1701 static bool isClassTemplateDeductionContext(DeclSpecContext DSC) {
1703 case DeclSpecContext::DSC_normal:
1704 case DeclSpecContext::DSC_template_param:
1705 case DeclSpecContext::DSC_template_arg:
1706 case DeclSpecContext::DSC_class:
1707 case DeclSpecContext::DSC_top_level:
1708 case DeclSpecContext::DSC_condition:
1709 case DeclSpecContext::DSC_type_specifier:
1710 case DeclSpecContext::DSC_association:
1711 case DeclSpecContext::DSC_conv_operator:
1712 case DeclSpecContext::DSC_new:
1715 case DeclSpecContext::DSC_objc_method_result:
1716 case DeclSpecContext::DSC_template_type_arg:
1717 case DeclSpecContext::DSC_trailing:
1718 case DeclSpecContext::DSC_alias_declaration:
1721 llvm_unreachable(
"Missing DeclSpecContext case");
1726 getImplicitTypenameContext(DeclSpecContext DSC) {
1728 case DeclSpecContext::DSC_class:
1729 case DeclSpecContext::DSC_top_level:
1730 case DeclSpecContext::DSC_type_specifier:
1731 case DeclSpecContext::DSC_template_type_arg:
1732 case DeclSpecContext::DSC_trailing:
1733 case DeclSpecContext::DSC_alias_declaration:
1734 case DeclSpecContext::DSC_template_param:
1735 case DeclSpecContext::DSC_new:
1736 case DeclSpecContext::DSC_conv_operator:
1739 case DeclSpecContext::DSC_normal:
1740 case DeclSpecContext::DSC_objc_method_result:
1741 case DeclSpecContext::DSC_condition:
1742 case DeclSpecContext::DSC_template_arg:
1743 case DeclSpecContext::DSC_association:
1746 llvm_unreachable(
"Missing DeclSpecContext case");
1751 struct ForRangeInit {
1752 SourceLocation ColonLoc;
1754 SmallVector<MaterializeTemporaryExpr *, 8> LifetimeExtendTemps;
1755 CXXExpansionStmtDecl *ExpansionStmt =
nullptr;
1756 bool ParsedForRangeDecl() {
return !ColonLoc.
isInvalid(); }
1758 struct ForRangeInfo : ForRangeInit {
1781 SourceLocation &DeclEnd,
1782 ParsedAttributes &DeclAttrs,
1783 ParsedAttributes &DeclSpecAttrs,
1784 SourceLocation *DeclSpecStart =
nullptr);
1811 ParsedAttributes &DeclAttrs,
1812 ParsedAttributes &DeclSpecAttrs,
bool RequireSemi,
1813 ForRangeInit *FRI =
nullptr,
1814 SourceLocation *DeclSpecStart =
nullptr);
1824 ParsedAttributes &Attrs,
1825 ParsedTemplateInfo &TemplateInfo,
1826 SourceLocation *DeclEnd =
nullptr,
1827 ForRangeInit *FRI =
nullptr);
1853 Decl *ParseDeclarationAfterDeclarator(
1855 const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo());
1859 bool ParseAsmAttributesAfterDeclarator(Declarator &D);
1860 Decl *ParseDeclarationAfterDeclaratorAndAttributes(
1862 const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo(),
1863 ForRangeInit *FRI =
nullptr);
1874 bool ParseImplicitInt(DeclSpec &DS, CXXScopeSpec *SS,
1876 DeclSpecContext DSC, ParsedAttributes &Attrs);
1886 ParseDeclarationSpecifiers(DeclSpec &DS, ParsedTemplateInfo &TemplateInfo,
1888 DeclSpecContext DSC = DeclSpecContext::DSC_normal,
1889 LateParsedAttrList *LateAttrs =
nullptr) {
1890 return ParseDeclarationSpecifiers(DS, TemplateInfo, AS, DSC, LateAttrs,
1891 getImplicitTypenameContext(DSC));
1924 ParseDeclarationSpecifiers(DeclSpec &DS, ParsedTemplateInfo &TemplateInfo,
1926 LateParsedAttrList *LateAttrs,
1936 bool DiagnoseMissingSemiAfterTagDefinition(
1938 LateParsedAttrList *LateAttrs =
nullptr);
1940 void ParseSpecifierQualifierList(
1942 DeclSpecContext DSC = DeclSpecContext::DSC_normal) {
1943 ParseSpecifierQualifierList(DS, getImplicitTypenameContext(DSC), AS, DSC);
1954 void ParseSpecifierQualifierList(
1957 DeclSpecContext DSC = DeclSpecContext::DSC_normal);
1991 void ParseEnumSpecifier(SourceLocation TagLoc, DeclSpec &DS,
1992 const ParsedTemplateInfo &TemplateInfo,
2007 void ParseEnumBody(SourceLocation StartLoc, Decl *TagDecl,
2008 SkipBodyInfo *SkipBody =
nullptr);
2022 void ParseStructUnionBody(SourceLocation StartLoc,
DeclSpec::TST TagType,
2023 RecordDecl *TagDecl);
2048 void ParseStructDeclaration(
2049 ParsingDeclSpec &DS,
2050 llvm::function_ref<Decl *(ParsingFieldDeclarator &)> FieldsCallback,
2051 LateParsedAttrList *LateFieldAttrs =
nullptr);
2063 bool DisambiguatingWithExpression =
false);
2067 bool isTypeSpecifierQualifier(
const Token &Tok);
2072 bool isKnownToBeTypeSpecifier(
const Token &Tok)
const;
2077 bool isConstructorDeclarator(
2080 const ParsedTemplateInfo *TemplateInfo =
nullptr);
2084 void DiagnoseBitIntUse(
const Token &Tok);
2088 bool CheckProhibitedCXX11Attribute() {
2089 assert(Tok.is(tok::l_square));
2092 return DiagnoseProhibitedCXX11Attribute();
2103 bool DiagnoseProhibitedCXX11Attribute();
2105 void CheckMisplacedCXX11Attribute(ParsedAttributes &Attrs,
2106 SourceLocation CorrectLocation) {
2107 if (!Tok.isRegularKeywordAttribute() &&
2108 (Tok.isNot(tok::l_square) ||
NextToken().
isNot(tok::l_square)) &&
2109 Tok.isNot(tok::kw_alignas))
2111 DiagnoseMisplacedCXX11Attribute(Attrs, CorrectLocation);
2118 void DiagnoseMisplacedCXX11Attribute(ParsedAttributes &Attrs,
2119 SourceLocation CorrectLocation);
2129 void stripTypeAttributesOffDeclSpec(ParsedAttributes &Attrs, DeclSpec &DS,
2133 void ProhibitAttributes(ParsedAttributes &Attrs,
2134 SourceLocation FixItLoc = SourceLocation()) {
2135 if (Attrs.Range.isInvalid())
2137 DiagnoseProhibitedAttributes(Attrs, FixItLoc);
2141 void ProhibitAttributes(ParsedAttributesView &Attrs,
2142 SourceLocation FixItLoc = SourceLocation()) {
2143 if (Attrs.Range.isInvalid())
2145 DiagnoseProhibitedAttributes(Attrs, FixItLoc);
2146 Attrs.clearListOnly();
2148 void DiagnoseProhibitedAttributes(
const ParsedAttributesView &Attrs,
2149 SourceLocation FixItLoc);
2157 void ProhibitCXX11Attributes(ParsedAttributes &Attrs,
unsigned AttrDiagID,
2158 unsigned KeywordDiagId,
2159 bool DiagnoseEmptyAttrs =
false,
2160 bool WarnOnUnknownAttrs =
false);
2164 void DiagnoseCXX11AttributeExtension(ParsedAttributes &Attrs);
2166 ExprResult ParseUnevaluatedStringInAttribute(
const IdentifierInfo &AttrName);
2173 bool ParseAttributeArgumentList(
2174 const IdentifierInfo &AttrName, SmallVectorImpl<Expr *> &Exprs,
2175 ParsedAttributeArgumentsProperties ArgsProperties,
unsigned Arg);
2182 ParseAttributeArgsCommon(IdentifierInfo *AttrName, SourceLocation AttrNameLoc,
2183 ParsedAttributes &Attrs, SourceLocation *EndLoc,
2184 IdentifierInfo *ScopeName, SourceLocation ScopeLoc,
2185 ParsedAttr::Form Form);
2187 enum ParseAttrKindMask {
2189 PAKM_Declspec = 1 << 1,
2190 PAKM_CXX11 = 1 << 2,
2209 void ParseAttributes(
unsigned WhichAttrKinds, ParsedAttributes &Attrs,
2210 LateParsedAttrList *LateAttrs =
nullptr);
2213 bool MaybeParseAttributes(
unsigned WhichAttrKinds, ParsedAttributes &Attrs,
2214 LateParsedAttrList *LateAttrs =
nullptr) {
2215 if (Tok.isOneOf(tok::kw___attribute, tok::kw___declspec) ||
2216 isAllowedCXX11AttributeSpecifier()) {
2217 ParseAttributes(WhichAttrKinds, Attrs, LateAttrs);
2223 void MaybeParseGNUAttributes(Declarator &D,
2224 LateParsedAttrList *LateAttrs =
nullptr) {
2225 if (Tok.is(tok::kw___attribute)) {
2226 ParsedAttributes Attrs(AttrFactory);
2227 ParseGNUAttributes(Attrs, LateAttrs, &D);
2228 D.takeAttributesAppending(Attrs);
2232 bool MaybeParseGNUAttributes(ParsedAttributes &Attrs,
2233 LateParsedAttrList *LateAttrs =
nullptr) {
2234 if (Tok.is(tok::kw___attribute)) {
2235 ParseGNUAttributes(Attrs, LateAttrs);
2257 bool ParseSingleGNUAttribute(ParsedAttributes &Attrs, SourceLocation &EndLoc,
2258 LateParsedAttrList *LateAttrs =
nullptr,
2259 Declarator *D =
nullptr);
2304 void ParseGNUAttributes(ParsedAttributes &Attrs,
2305 LateParsedAttrList *LateAttrs =
nullptr,
2306 Declarator *D =
nullptr);
2310 void ParseGNUAttributeArgs(IdentifierInfo *AttrName,
2311 SourceLocation AttrNameLoc,
2312 ParsedAttributes &Attrs, SourceLocation *EndLoc,
2313 IdentifierInfo *ScopeName, SourceLocation ScopeLoc,
2314 ParsedAttr::Form Form, Declarator *D);
2315 IdentifierLoc *ParseIdentifierLoc();
2318 ParseClangAttributeArgs(IdentifierInfo *AttrName, SourceLocation AttrNameLoc,
2319 ParsedAttributes &Attrs, SourceLocation *EndLoc,
2320 IdentifierInfo *ScopeName, SourceLocation ScopeLoc,
2321 ParsedAttr::Form Form);
2323 void MaybeParseCXX11Attributes(Declarator &D) {
2324 if (isAllowedCXX11AttributeSpecifier()) {
2325 ParsedAttributes Attrs(AttrFactory);
2326 ParseCXX11Attributes(Attrs);
2327 D.takeAttributesAppending(Attrs);
2331 bool MaybeParseCXX11Attributes(ParsedAttributes &Attrs,
2332 bool OuterMightBeMessageSend =
false) {
2333 if (isAllowedCXX11AttributeSpecifier(
false, OuterMightBeMessageSend)) {
2334 ParseCXX11Attributes(Attrs);
2340 bool MaybeParseMicrosoftAttributes(ParsedAttributes &Attrs) {
2341 bool AttrsParsed =
false;
2343 Tok.is(tok::l_square)) {
2344 ParsedAttributes AttrsWithRange(AttrFactory);
2345 ParseMicrosoftAttributes(AttrsWithRange);
2346 AttrsParsed = !AttrsWithRange.empty();
2347 Attrs.takeAllAppendingFrom(AttrsWithRange);
2351 bool MaybeParseMicrosoftDeclSpecs(ParsedAttributes &Attrs) {
2352 if (
getLangOpts().DeclSpecKeyword && Tok.is(tok::kw___declspec)) {
2353 ParseMicrosoftDeclSpecs(Attrs);
2367 void ParseMicrosoftDeclSpecs(ParsedAttributes &Attrs);
2368 bool ParseMicrosoftDeclSpecArgs(IdentifierInfo *AttrName,
2369 SourceLocation AttrNameLoc,
2370 ParsedAttributes &Attrs);
2371 void ParseMicrosoftTypeAttributes(ParsedAttributes &attrs);
2372 void ParseWebAssemblyFuncrefTypeAttribute(ParsedAttributes &Attrs);
2373 void DiagnoseAndSkipExtendedMicrosoftTypeAttributes();
2374 SourceLocation SkipExtendedMicrosoftTypeAttributes();
2376 void ParseBorlandTypeAttributes(ParsedAttributes &attrs);
2377 void ParseOpenCLKernelAttributes(ParsedAttributes &attrs);
2378 void ParseOpenCLQualifiers(ParsedAttributes &Attrs);
2379 void ParseNullabilityTypeSpecifiers(ParsedAttributes &attrs);
2380 void ParseCUDAFunctionAttributes(ParsedAttributes &attrs);
2381 bool isHLSLQualifier(
const Token &Tok)
const;
2382 void ParseHLSLQualifiers(ParsedAttributes &Attrs);
2394 VersionTuple ParseVersionTuple(SourceRange &Range);
2423 void ParseAvailabilityAttribute(IdentifierInfo &Availability,
2424 SourceLocation AvailabilityLoc,
2425 ParsedAttributes &attrs,
2426 SourceLocation *endLoc,
2427 IdentifierInfo *ScopeName,
2428 SourceLocation ScopeLoc,
2429 ParsedAttr::Form Form);
2447 void ParseExternalSourceSymbolAttribute(IdentifierInfo &ExternalSourceSymbol,
2449 ParsedAttributes &Attrs,
2450 SourceLocation *EndLoc,
2451 IdentifierInfo *ScopeName,
2452 SourceLocation ScopeLoc,
2453 ParsedAttr::Form Form);
2468 void ParseObjCBridgeRelatedAttribute(IdentifierInfo &ObjCBridgeRelated,
2469 SourceLocation ObjCBridgeRelatedLoc,
2470 ParsedAttributes &Attrs,
2471 SourceLocation *EndLoc,
2472 IdentifierInfo *ScopeName,
2473 SourceLocation ScopeLoc,
2474 ParsedAttr::Form Form);
2476 void ParseSwiftNewTypeAttribute(IdentifierInfo &AttrName,
2477 SourceLocation AttrNameLoc,
2478 ParsedAttributes &Attrs,
2479 SourceLocation *EndLoc,
2480 IdentifierInfo *ScopeName,
2481 SourceLocation ScopeLoc,
2482 ParsedAttr::Form Form);
2484 void ParseTypeTagForDatatypeAttribute(IdentifierInfo &AttrName,
2485 SourceLocation AttrNameLoc,
2486 ParsedAttributes &Attrs,
2487 SourceLocation *EndLoc,
2488 IdentifierInfo *ScopeName,
2489 SourceLocation ScopeLoc,
2490 ParsedAttr::Form Form);
2492 void ParseAttributeWithTypeArg(IdentifierInfo &AttrName,
2493 SourceLocation AttrNameLoc,
2494 ParsedAttributes &Attrs,
2495 IdentifierInfo *ScopeName,
2496 SourceLocation ScopeLoc,
2497 ParsedAttr::Form Form);
2499 void DistributeCLateParsedAttrs(Decl *Dcl, LateParsedAttrList *LateAttrs);
2505 void ParseBoundsAttribute(IdentifierInfo &AttrName,
2506 SourceLocation AttrNameLoc, ParsedAttributes &Attrs,
2507 IdentifierInfo *ScopeName, SourceLocation ScopeLoc,
2508 ParsedAttr::Form Form);
2524 void ParseTypeofSpecifier(DeclSpec &DS);
2531 void ParseAtomicSpecifier(DeclSpec &DS);
2541 ExprResult ParseAlignArgument(StringRef KWName, SourceLocation Start,
2542 SourceLocation &EllipsisLoc,
bool &IsType,
2555 void ParseAlignmentSpecifier(ParsedAttributes &Attrs,
2556 SourceLocation *endLoc =
nullptr);
2565 void ParsePtrauthQualifier(ParsedAttributes &Attrs);
2570 class DeclaratorScopeObj {
2577 DeclaratorScopeObj(
Parser &p, CXXScopeSpec &ss)
2578 : P(p), SS(ss), EnteredScope(
false), CreatedScope(
false) {}
2580 void EnterDeclaratorScope() {
2581 assert(!EnteredScope &&
"Already entered the scope!");
2582 assert(SS.isSet() &&
"C++ scope was not set!");
2584 CreatedScope =
true;
2587 if (!P.Actions.ActOnCXXEnterDeclaratorScope(P.getCurScope(), SS))
2588 EnteredScope =
true;
2591 ~DeclaratorScopeObj() {
2593 assert(SS.isSet() &&
"C++ scope was cleared ?");
2594 P.Actions.ActOnCXXExitDeclaratorScope(P.getCurScope(), SS);
2602 void ParseDeclarator(Declarator &D);
2633 void ParseDeclaratorInternal(Declarator &D,
2634 DirectDeclParseFunction DirectDeclParser);
2636 enum AttrRequirements {
2637 AR_NoAttributesParsed = 0,
2638 AR_GNUAttributesParsedAndRejected = 1 << 0,
2639 AR_GNUAttributesParsed = 1 << 1,
2640 AR_CXX11AttributesParsed = 1 << 2,
2641 AR_DeclspecAttributesParsed = 1 << 3,
2642 AR_AllAttributesParsed = AR_GNUAttributesParsed | AR_CXX11AttributesParsed |
2643 AR_DeclspecAttributesParsed,
2644 AR_VendorAttributesParsed =
2645 AR_GNUAttributesParsed | AR_DeclspecAttributesParsed
2662 void ParseTypeQualifierListOpt(
2663 DeclSpec &DS,
unsigned AttrReqs = AR_AllAttributesParsed,
2664 bool AtomicOrPtrauthAllowed =
true,
bool IdentifierRequired =
false,
2665 llvm::function_ref<
void()> CodeCompletionHandler = {});
2715 void ParseDirectDeclarator(Declarator &D);
2716 void ParseDecompositionDeclarator(Declarator &D);
2734 void ParseParenDeclarator(Declarator &D);
2759 void ParseFunctionDeclarator(Declarator &D, ParsedAttributes &FirstArgAttrs,
2761 bool IsAmbiguous,
bool RequiresArg =
false);
2762 void InitCXXThisScopeForDeclaratorIfRelevant(
2763 const Declarator &D,
const DeclSpec &DS,
2764 std::optional<Sema::CXXThisScopeRAII> &ThisScope);
2768 bool ParseRefQualifier(
bool &RefQualifierIsLValueRef,
2769 SourceLocation &RefQualifierLoc);
2776 bool isFunctionDeclaratorIdentifierList();
2790 void ParseFunctionDeclaratorIdentifierList(
2791 Declarator &D, SmallVectorImpl<DeclaratorChunk::ParamInfo> &ParamInfo);
2792 void ParseParameterDeclarationClause(
2793 Declarator &D, ParsedAttributes &attrs,
2794 SmallVectorImpl<DeclaratorChunk::ParamInfo> &ParamInfo,
2795 SourceLocation &EllipsisLoc) {
2796 return ParseParameterDeclarationClause(
2797 D.getContext(), attrs, ParamInfo, EllipsisLoc,
2798 D.getCXXScopeSpec().isSet() &&
2799 D.isFunctionDeclaratorAFunctionDeclaration());
2837 void ParseParameterDeclarationClause(
2839 SmallVectorImpl<DeclaratorChunk::ParamInfo> &ParamInfo,
2840 SourceLocation &EllipsisLoc,
bool IsACXXFunctionDeclaration =
false);
2851 void ParseBracketDeclarator(Declarator &D);
2854 void ParseMisplacedBracketDeclarator(Declarator &D);
2865 TypeResult ParseTypeFromString(StringRef TypeStr, StringRef Context,
2866 SourceLocation IncludeLoc);
2882 mutable IdentifierInfo *Ident_sealed;
2883 mutable IdentifierInfo *Ident_abstract;
2886 mutable IdentifierInfo *Ident_final;
2887 mutable IdentifierInfo *Ident_GNU_final;
2888 mutable IdentifierInfo *Ident_override;
2893 struct ParsingClass {
2894 ParsingClass(Decl *TagOrTemplate,
bool TopLevelClass,
bool IsInterface)
2895 : TopLevelClass(TopLevelClass), IsInterface(IsInterface),
2896 TagOrTemplate(TagOrTemplate) {}
2900 bool TopLevelClass : 1;
2903 bool IsInterface : 1;
2906 Decl *TagOrTemplate;
2911 LateParsedDeclarationsContainer LateParsedDeclarations;
2917 std::stack<ParsingClass *> ClassStack;
2919 ParsingClass &getCurrentClass() {
2920 assert(!ClassStack.empty() &&
"No lexed method stacks!");
2921 return *ClassStack.top();
2925 class ParsingClassDefinition {
2931 ParsingClassDefinition(
Parser &P, Decl *TagOrTemplate,
bool TopLevelClass,
2933 : P(P), Popped(
false),
2934 State(P.PushParsingClass(TagOrTemplate, TopLevelClass, IsInterface)) {
2939 assert(!Popped &&
"Nested class has already been popped");
2941 P.PopParsingClass(State);
2944 ~ParsingClassDefinition() {
2946 P.PopParsingClass(State);
2962 bool Delayed, SourceRange &SpecificationRange,
2963 SmallVectorImpl<ParsedType> &DynamicExceptions,
2964 SmallVectorImpl<SourceRange> &DynamicExceptionRanges,
2982 ParseDynamicExceptionSpecification(SourceRange &SpecificationRange,
2983 SmallVectorImpl<ParsedType> &Exceptions,
2984 SmallVectorImpl<SourceRange> &Ranges);
2991 TypeResult ParseTrailingReturnType(SourceRange &Range,
2992 bool MayBeFollowedByDirectInit);
2995 void ParseTrailingRequiresClauseWithScope(Declarator &D);
2996 void ParseTrailingRequiresClause(Declarator &D);
2998 void ParseMicrosoftIfExistsClassDeclaration(
DeclSpec::TST TagType,
2999 ParsedAttributes &AccessAttrs,
3002 SourceLocation ParsePackIndexingType(DeclSpec &DS);
3003 void AnnotateExistingIndexedTypeNamePack(
ParsedType T,
3004 SourceLocation StartLoc,
3005 SourceLocation EndLoc);
3010 bool AnnotatePackIndexingTemplateName(CXXScopeSpec &SS, UnqualifiedId &Name,
3019 bool isAllowedCXX11AttributeSpecifier(
bool Disambiguate =
false,
3020 bool OuterMightBeMessageSend =
false) {
3021 return (Tok.isRegularKeywordAttribute() ||
3022 isCXX11AttributeSpecifier(Disambiguate, OuterMightBeMessageSend) !=
3029 SourceLocation SkipCXX11Attributes();
3033 void DiagnoseAndSkipCXX11Attributes();
3035 void ParseOpenMPAttributeArgs(
const IdentifierInfo *AttrName,
3064 void ParseCXX11AttributeSpecifierInternal(ParsedAttributes &Attrs,
3066 SourceLocation *EndLoc =
nullptr);
3067 void ParseCXX11AttributeSpecifier(ParsedAttributes &Attrs,
3068 SourceLocation *EndLoc =
nullptr) {
3070 ParseCXX11AttributeSpecifierInternal(Attrs, OpenMPTokens, EndLoc);
3071 ReplayOpenMPAttributeTokens(OpenMPTokens);
3080 void ParseCXX11Attributes(ParsedAttributes &attrs);
3100 bool ParseCXX11AttributeArgs(IdentifierInfo *AttrName,
3101 SourceLocation AttrNameLoc,
3102 ParsedAttributes &Attrs, SourceLocation *EndLoc,
3103 IdentifierInfo *ScopeName,
3104 SourceLocation ScopeLoc,
3110 ParseCXXAssumeAttributeArg(ParsedAttributes &Attrs, IdentifierInfo *AttrName,
3111 SourceLocation AttrNameLoc,
3112 IdentifierInfo *ScopeName, SourceLocation ScopeLoc,
3113 SourceLocation *EndLoc, ParsedAttr::Form Form);
3124 IdentifierInfo *TryParseCXX11AttributeIdentifier(
3125 SourceLocation &Loc,
3128 const IdentifierInfo *EnclosingScope =
nullptr);
3131 void ParseMicrosoftUuidAttributeArgs(ParsedAttributes &Attrs);
3143 void ParseMicrosoftAttributes(ParsedAttributes &Attrs);
3145 void ParseMicrosoftInheritanceClassAttributes(ParsedAttributes &attrs);
3146 void ParseNullabilityClassAttributes(ParsedAttributes &attrs);
3155 SourceLocation ParseDecltypeSpecifier(DeclSpec &DS);
3156 void AnnotateExistingDecltypeSpecifier(
const DeclSpec &DS,
3157 SourceLocation StartLoc,
3158 SourceLocation EndLoc);
3171 return isCXX11VirtSpecifier(Tok);
3181 void ParseOptionalCXX11VirtSpecifierSeq(VirtSpecifiers &VS,
bool IsInterface,
3182 SourceLocation FriendLoc);
3186 bool isCXX11FinalKeyword()
const;
3192 bool isClassCompatibleKeyword()
const;
3194 bool MaybeParseTypeTransformTypeSpecifier(DeclSpec &DS);
3197 void DiagnoseUnexpectedNamespace(NamedDecl *Context);
3229 SourceLocation &DeclEnd,
3230 SourceLocation InlineLoc = SourceLocation());
3232 struct InnerNamespaceInfo {
3233 SourceLocation NamespaceLoc;
3234 SourceLocation InlineLoc;
3235 SourceLocation IdentLoc;
3236 IdentifierInfo *Ident;
3238 using InnerNamespaceInfoList = llvm::SmallVector<InnerNamespaceInfo, 4>;
3241 void ParseInnerNamespace(
const InnerNamespaceInfoList &InnerNSs,
3242 unsigned int index, SourceLocation &InlineLoc,
3243 ParsedAttributes &attrs,
3275 Decl *ParseExportDeclaration();
3281 SourceLocation &DeclEnd, ParsedAttributes &Attrs);
3296 SourceLocation &DeclEnd, ParsedAttributes &attrs);
3298 struct UsingDeclarator {
3299 SourceLocation TypenameLoc;
3302 SourceLocation EllipsisLoc;
3305 TypenameLoc = EllipsisLoc = SourceLocation();
3346 const ParsedTemplateInfo &TemplateInfo,
3347 SourceLocation UsingLoc,
3348 SourceLocation &DeclEnd,
3349 ParsedAttributes &Attrs,
3351 Decl *ParseAliasDeclarationAfterDeclarator(
3352 const ParsedTemplateInfo &TemplateInfo, SourceLocation UsingLoc,
3354 ParsedAttributes &Attrs, Decl **OwnedType =
nullptr);
3367 Decl *ParseStaticAssertDeclaration(SourceLocation &DeclEnd);
3372 Decl *ParseNamespaceAlias(SourceLocation NamespaceLoc,
3373 SourceLocation AliasLoc, IdentifierInfo *Alias,
3374 SourceLocation &DeclEnd);
3382 bool isValidAfterTypeSpecifier(
bool CouldBeBitfield);
3426 void ParseClassSpecifier(
tok::TokenKind TagTokKind, SourceLocation TagLoc,
3427 DeclSpec &DS, ParsedTemplateInfo &TemplateInfo,
3429 DeclSpecContext DSC, ParsedAttributes &Attributes);
3430 void SkipCXXMemberSpecification(SourceLocation StartLoc,
3431 SourceLocation AttrFixitLoc,
unsigned TagType,
3442 void ParseCXXMemberSpecification(SourceLocation StartLoc,
3443 SourceLocation AttrFixitLoc,
3444 ParsedAttributes &Attrs,
unsigned TagType,
3469 ExprResult ParseCXXMemberInitializer(Decl *D,
bool IsFunction,
3470 SourceLocation &EqualLoc);
3474 bool ParseCXXMemberDeclaratorBeforeInitializer(Declarator &DeclaratorInfo,
3477 LateParsedAttrList &LateAttrs);
3482 MaybeParseAndDiagnoseDeclSpecAfterCXX11VirtSpecifierSeq(Declarator &D,
3483 VirtSpecifiers &VS);
3539 ParsedTemplateInfo &TemplateInfo,
3540 ParsingDeclRAIIObject *DiagsFromTParams =
nullptr);
3543 ParsedAttributes &AccessAttrs,
3569 void ParseConstructorInitializer(Decl *ConstructorDecl);
3591 void HandleMemberFunctionDeclDelays(Declarator &DeclaratorInfo,
3619 TypeResult ParseBaseTypeSpecifier(SourceLocation &BaseLoc,
3620 SourceLocation &EndLocation);
3632 void ParseBaseClause(Decl *ClassDecl);
3647 BaseResult ParseBaseSpecifier(Decl *ClassDecl);
3663 bool isClassCompatibleKeyword(Token Tok)
const;
3665 void ParseHLSLRootSignatureAttributeArgs(ParsedAttributes &Attrs);
3840 bool GreaterThanIsOperator;
3844 llvm::SmallDenseMap<IdentifierInfo *, tok::TokenKind> RevertibleTypeTraits;
3863 PushParsingClass(
Decl *TagOrTemplate,
bool TopLevelClass,
bool IsInterface);
3867 void DeallocateParsedClasses(ParsingClass *
Class);
4088 bool isAddressOfOperand,
bool &NotCastExpr,
4090 bool isVectorLiteral =
false,
4091 bool *NotPrimaryExpression =
nullptr);
4093 bool isAddressOfOperand =
false,
4096 bool isVectorLiteral =
false,
4097 bool *NotPrimaryExpression =
nullptr);
4100 bool isNotExpressionStart();
4104 bool isPostfixExpressionSuffixStart() {
4106 return (K == tok::l_square || K == tok::l_paren || K == tok::period ||
4107 K == tok::arrow || K == tok::plusplus || K == tok::minusminus);
4149 ExprResult ParseUnaryExprOrTypeTraitExpression();
4178 ExprResult ParseSYCLUniqueStableNameExpression();
4240 llvm::function_ref<
void()> ExpressionStarts =
4241 llvm::function_ref<
void()>(),
4242 bool FailImmediatelyOnInvalidExpr =
false,
4243 bool ParsingExpansionStmtInitList =
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 ParseCondition(
StmtResult *InitStmt, SourceLocation Loc,
5041 ForRangeInfo *FRI =
nullptr);
5043 ParsedAttributes &Attrs);
5090 bool isTypeIdInParens(
bool &isAmbiguous) {
5093 isAmbiguous =
false;
5094 return isTypeSpecifierQualifier(Tok);
5096 bool isTypeIdInParens() {
5098 return isTypeIdInParens(isAmbiguous);
5136 bool ParseUnqualifiedIdTemplateId(CXXScopeSpec &SS,
ParsedType ObjectType,
5137 bool ObjectHadErrors,
5138 SourceLocation TemplateKWLoc,
5139 IdentifierInfo *Name,
5140 SourceLocation NameLoc,
5141 bool EnteringContext, UnqualifiedId &Id,
5142 bool AssumeTemplateId);
5184 bool ParseUnqualifiedIdOperator(CXXScopeSpec &SS,
bool EnteringContext,
5251 bool MaybeParseHLSLAnnotations(Declarator &D,
5252 SourceLocation *EndLoc =
nullptr,
5253 bool CouldBeBitField =
false) {
5254 assert(
getLangOpts().
HLSL &&
"MaybeParseHLSLAnnotations is for HLSL only");
5255 if (Tok.is(tok::colon)) {
5256 ParsedAttributes Attrs(AttrFactory);
5257 ParseHLSLAnnotations(Attrs, EndLoc, CouldBeBitField);
5258 D.takeAttributesAppending(Attrs);
5264 void MaybeParseHLSLAnnotations(ParsedAttributes &Attrs,
5265 SourceLocation *EndLoc =
nullptr) {
5266 assert(
getLangOpts().
HLSL &&
"MaybeParseHLSLAnnotations is for HLSL only");
5267 if (Tok.is(tok::colon))
5268 ParseHLSLAnnotations(Attrs, EndLoc);
5271 struct ParsedSemantic {
5272 StringRef Name =
"";
5274 bool Explicit =
false;
5277 ParsedSemantic ParseHLSLSemantic();
5279 void ParseHLSLAnnotations(ParsedAttributes &Attrs,
5280 SourceLocation *EndLoc =
nullptr,
5281 bool CouldBeBitField =
false);
5282 Decl *ParseHLSLBuffer(SourceLocation &DeclEnd, ParsedAttributes &Attrs);
5306 ExprResult ParseInitializer(Decl *DeclForInitializer =
nullptr);
5311 bool MayBeDesignationStart();
5339 struct DesignatorCompletionInfo {
5340 SmallVectorImpl<Expr *> &InitExprs;
5341 QualType PreferredBaseType;
5390 ExprResult ParseInitializerWithPotentialDesignator(DesignatorCompletionInfo);
5395 typedef SmallVector<Expr *, 12> ExprVector;
5399 bool ParseMicrosoftIfExistsBraceInitializer(ExprVector &InitExprs,
5416 friend class ObjCDeclContextSwitch;
5419 return Actions.ObjC().getObjCDeclContext();
5425 return Actions.getNullabilityKeyword(nullability);
5441 bool InMessageExpression;
5448 bool ParsingInObjCContainer;
5453 bool isObjCInstancetype() {
5455 if (
Tok.isAnnotation())
5457 if (!Ident_instancetype)
5459 return Tok.getIdentifierInfo() == Ident_instancetype;
5467 ObjCContainerDecl *DC;
5468 SaveAndRestore<bool> WithinObjCContainer;
5473 WithinObjCContainer(P.ParsingInObjCContainer, DC !=
nullptr) {
5475 P.Actions.ObjC().ActOnObjCTemporaryExitContainerContext(DC);
5477 ~ObjCDeclContextSwitch() {
5479 P.Actions.ObjC().ActOnObjCReenterContainerContext(DC);
5483 void CheckNestedObjCContexts(SourceLocation AtLoc);
5485 void ParseLexedObjCMethodDefs(LexedMethod &LM,
bool parseMethod);
5503 DeclGroupPtrTy ParseObjCAtDirectives(ParsedAttributes &DeclAttrs,
5504 ParsedAttributes &DeclSpecAttrs);
5515 DeclGroupPtrTy ParseObjCAtClassDeclaration(SourceLocation atLoc);
5548 Decl *ParseObjCAtInterfaceDeclaration(SourceLocation AtLoc,
5549 ParsedAttributes &prefixAttrs);
5555 ObjCTypeParamList *parseObjCTypeParamList();
5583 ObjCTypeParamList *parseObjCTypeParamListOrProtocolRefs(
5585 SmallVectorImpl<IdentifierLoc> &protocolIdents, SourceLocation &rAngleLoc,
5586 bool mayBeProtocolList =
true);
5588 void HelperActionsForIvarDeclarations(ObjCContainerDecl *interfaceDecl,
5589 SourceLocation atLoc,
5591 SmallVectorImpl<Decl *> &AllIvarDecls,
5592 bool RBraceMissing);
5617 void ParseObjCClassInstanceVariables(ObjCContainerDecl *interfaceDecl,
5619 SourceLocation atLoc);
5626 bool ParseObjCProtocolReferences(
5627 SmallVectorImpl<Decl *> &P, SmallVectorImpl<SourceLocation> &PLocs,
5628 bool WarnOnDeclarations,
bool ForObjCContainer, SourceLocation &LAngleLoc,
5629 SourceLocation &EndProtoLoc,
bool consumeLastToken);
5640 void parseObjCTypeArgsOrProtocolQualifiers(
5641 ParsedType baseType, SourceLocation &typeArgsLAngleLoc,
5642 SmallVectorImpl<ParsedType> &typeArgs, SourceLocation &typeArgsRAngleLoc,
5643 SourceLocation &protocolLAngleLoc, SmallVectorImpl<Decl *> &protocols,
5644 SmallVectorImpl<SourceLocation> &protocolLocs,
5645 SourceLocation &protocolRAngleLoc,
bool consumeLastToken,
5646 bool warnOnIncompleteProtocols);
5650 void parseObjCTypeArgsAndProtocolQualifiers(
5651 ParsedType baseType, SourceLocation &typeArgsLAngleLoc,
5652 SmallVectorImpl<ParsedType> &typeArgs, SourceLocation &typeArgsRAngleLoc,
5653 SourceLocation &protocolLAngleLoc, SmallVectorImpl<Decl *> &protocols,
5654 SmallVectorImpl<SourceLocation> &protocolLocs,
5655 SourceLocation &protocolRAngleLoc,
bool consumeLastToken);
5659 TypeResult parseObjCProtocolQualifierType(SourceLocation &rAngleLoc);
5663 TypeResult parseObjCTypeArgsAndProtocolQualifiers(SourceLocation loc,
5665 bool consumeLastToken,
5666 SourceLocation &endLoc);
5702 DeclGroupPtrTy ParseObjCAtProtocolDeclaration(SourceLocation atLoc,
5703 ParsedAttributes &prefixAttrs);
5705 struct ObjCImplParsingDataRAII {
5709 typedef SmallVector<LexedMethod *, 8> LateParsedObjCMethodContainer;
5710 LateParsedObjCMethodContainer LateParsedObjCMethods;
5712 ObjCImplParsingDataRAII(
Parser &parser, Decl *D)
5713 : P(parser), Dcl(D), HasCFunction(
false) {
5714 P.CurParsedObjCImpl =
this;
5717 ~ObjCImplParsingDataRAII();
5719 void finish(SourceRange AtEnd);
5720 bool isFinished()
const {
return Finished; }
5725 ObjCImplParsingDataRAII *CurParsedObjCImpl;
5729 void StashAwayMethodOrFunctionBodyTokens(Decl *MDecl);
5743 DeclGroupPtrTy ParseObjCAtImplementationDeclaration(SourceLocation AtLoc,
5744 ParsedAttributes &Attrs);
5752 Decl *ParseObjCAtAliasDeclaration(SourceLocation atLoc);
5767 Decl *ParseObjCPropertySynthesize(SourceLocation atLoc);
5778 Decl *ParseObjCPropertyDynamic(SourceLocation atLoc);
5790 IdentifierInfo *ParseObjCSelectorPiece(SourceLocation &MethodLocation);
5798 bool isTokIdentifier_in()
const;
5807 ParsedAttributes *ParamAttrs);
5821 Decl *ParseObjCMethodPrototype(
5823 bool MethodDefinition =
true);
5855 Decl *ParseObjCMethodDecl(
5858 bool MethodDefinition =
true);
5888 void ParseObjCPropertyAttribute(ObjCDeclSpec &DS);
5894 Decl *ParseObjCMethodDefinition();
5898 ExprResult ParseObjCAtExpression(SourceLocation AtLocation);
5899 ExprResult ParseObjCStringLiteral(SourceLocation AtLoc);
5906 ExprResult ParseObjCCharacterLiteral(SourceLocation AtLoc);
5915 ExprResult ParseObjCNumericLiteral(SourceLocation AtLoc);
5924 ExprResult ParseObjCBooleanLiteral(SourceLocation AtLoc,
bool ArgValue);
5926 ExprResult ParseObjCArrayLiteral(SourceLocation AtLoc);
5927 ExprResult ParseObjCDictionaryLiteral(SourceLocation AtLoc);
5934 ExprResult ParseObjCBoxedExpr(SourceLocation AtLoc);
5940 ExprResult ParseObjCEncodeExpression(SourceLocation AtLoc);
5946 ExprResult ParseObjCSelectorExpression(SourceLocation AtLoc);
5952 ExprResult ParseObjCProtocolExpression(SourceLocation AtLoc);
5959 bool isSimpleObjCMessageExpression();
6014 ExprResult ParseObjCMessageExpressionBody(SourceLocation LBracloc,
6015 SourceLocation SuperLoc,
6017 Expr *ReceiverExpr);
6043 bool ParseObjCXXMessageReceiver(
bool &IsExpr,
void *&TypeOrExpr);
6048 enum class ParsedStmtContext;
6050 StmtResult ParseObjCAtStatement(SourceLocation atLoc,
6051 ParsedStmtContext StmtCtx);
6066 StmtResult ParseObjCTryStmt(SourceLocation atLoc);
6073 StmtResult ParseObjCThrowStmt(SourceLocation atLoc);
6080 StmtResult ParseObjCSynchronizedStmt(SourceLocation atLoc);
6087 StmtResult ParseObjCAutoreleasePoolStmt(SourceLocation atLoc);
6114 bool isStartOfObjCClassMessageMissingOpenBracket();
6146 bool OpenACCDirectiveParsing =
false;
6150 bool AllowOpenACCArraySections =
false;
6154 class OpenACCArraySectionRAII {
6158 OpenACCArraySectionRAII(
Parser &P) : P(P) {
6159 assert(!P.AllowOpenACCArraySections);
6160 P.AllowOpenACCArraySections =
true;
6162 ~OpenACCArraySectionRAII() {
6163 assert(P.AllowOpenACCArraySections);
6164 P.AllowOpenACCArraySections =
false;
6171 struct OpenACCDirectiveParseInfo {
6173 SourceLocation StartLoc;
6174 SourceLocation DirLoc;
6175 SourceLocation LParenLoc;
6176 SourceLocation RParenLoc;
6177 SourceLocation EndLoc;
6178 SourceLocation MiscLoc;
6180 SmallVector<Expr *> Exprs;
6181 SmallVector<OpenACCClause *> Clauses;
6186 struct OpenACCWaitParseInfo {
6187 bool Failed =
false;
6188 Expr *DevNumExpr =
nullptr;
6189 SourceLocation QueuesLoc;
6190 SmallVector<Expr *> QueueIdExprs;
6192 SmallVector<Expr *> getAllExprs() {
6193 SmallVector<Expr *>
Out;
6194 Out.push_back(DevNumExpr);
6195 llvm::append_range(Out, QueueIdExprs);
6199 struct OpenACCCacheParseInfo {
6200 bool Failed =
false;
6201 SourceLocation ReadOnlyLoc;
6202 SmallVector<Expr *> Vars;
6207 enum class OpenACCParseCanContinue { Cannot = 0, Can = 1 };
6213 using OpenACCClauseParseResult =
6214 llvm::PointerIntPair<OpenACCClause *, 1, OpenACCParseCanContinue>;
6216 OpenACCClauseParseResult OpenACCCanContinue();
6217 OpenACCClauseParseResult OpenACCCannotContinue();
6218 OpenACCClauseParseResult OpenACCSuccess(OpenACCClause *Clause);
6222 OpenACCDirectiveParseInfo ParseOpenACCDirective();
6232 OpenACCCacheParseInfo ParseOpenACCCacheVarList();
6238 using OpenACCVarParseResult = std::pair<ExprResult, OpenACCParseCanContinue>;
6264 OpenACCClauseParseResult
6265 ParseOpenACCClauseParams(ArrayRef<const OpenACCClause *> ExistingClauses,
6267 SourceLocation ClauseLoc);
6271 OpenACCClauseParseResult
6272 ParseOpenACCClause(ArrayRef<const OpenACCClause *> ExistingClauses,
6282 SmallVector<OpenACCClause *>
6291 OpenACCWaitParseInfo ParseOpenACCWaitArgument(SourceLocation Loc,
6296 std::variant<std::monostate, StringLiteral *, IdentifierInfo *>
6297 ParseOpenACCBindClauseArgument();
6302 using OpenACCIntExprParseResult =
6303 std::pair<ExprResult, OpenACCParseCanContinue>;
6308 SourceLocation Loc);
6313 llvm::SmallVectorImpl<Expr *> &IntExprs);
6326 bool ParseOpenACCDeviceTypeList(llvm::SmallVector<IdentifierLoc> &Archs);
6340 SourceLocation Loc);
6355 llvm::SmallVectorImpl<Expr *> &SizeExprs);
6367 bool ParseOpenACCGangArgList(SourceLocation GangLoc,
6368 llvm::SmallVectorImpl<OpenACCGangKind> &GKs,
6369 llvm::SmallVectorImpl<Expr *> &IntExprs);
6371 using OpenACCGangArgRes = std::pair<OpenACCGangKind, ExprResult>;
6375 OpenACCGangArgRes ParseOpenACCGangArg(SourceLocation GangLoc);
6379 ParseOpenACCAfterRoutineDecl(
AccessSpecifier &AS, ParsedAttributes &Attrs,
6381 OpenACCDirectiveParseInfo &DirInfo);
6382 StmtResult ParseOpenACCAfterRoutineStmt(OpenACCDirectiveParseInfo &DirInfo);
6400 bool OpenMPDirectiveParsing =
false;
6405 void ReplayOpenMPAttributeTokens(
CachedTokens &OpenMPTokens) {
6408 if (!OpenMPTokens.empty()) {
6409 PP.EnterToken(Tok,
true);
6410 PP.EnterTokenStream(OpenMPTokens,
true,
6422 SourceLocation Loc);
6427 llvm::omp::TraitSet
Set,
6428 llvm::omp::TraitSelector Selector,
6429 llvm::StringMap<SourceLocation> &Seen);
6433 llvm::omp::TraitSet
Set,
6434 llvm::StringMap<SourceLocation> &Seen);
6438 llvm::StringMap<SourceLocation> &Seen);
6442 llvm::omp::TraitSet
Set,
6443 llvm::StringMap<SourceLocation> &Seen);
6451 llvm::omp::TraitSet
Set,
6452 llvm::StringMap<SourceLocation> &SeenSelectors);
6459 void parseOMPContextSelectorSet(
OMPTraitSet &TISet,
6460 llvm::StringMap<SourceLocation> &SeenSets);
6467 bool parseOMPContextSelectors(SourceLocation Loc,
OMPTraitInfo &TI);
6470 bool parseOpenMPAppendArgs(SmallVectorImpl<OMPInteropInfo> &InteropInfos);
6474 bool parseOMPDeclareVariantMatchClause(SourceLocation Loc,
OMPTraitInfo &TI,
6480 SourceLocation Loc);
6499 void ParseOpenMPAssumesDirective(OpenMPDirectiveKind DKind,
6500 SourceLocation Loc);
6503 void ParseOpenMPEndAssumesDirective(SourceLocation Loc);
6520 void ParseOpenMPClauses(OpenMPDirectiveKind DKind,
6521 SmallVectorImpl<clang::OMPClause *> &Clauses,
6522 SourceLocation Loc);
6525 void ParseOMPDeclareTargetClauses(SemaOpenMP::DeclareTargetContextInfo &DTCI);
6528 void ParseOMPEndDeclareTargetDirective(OpenMPDirectiveKind BeginDKind,
6529 OpenMPDirectiveKind EndDKind,
6530 SourceLocation Loc);
6534 void skipUntilPragmaOpenMPEnd(OpenMPDirectiveKind DKind);
6540 void parseOMPEndDirective(OpenMPDirectiveKind BeginKind,
6541 OpenMPDirectiveKind ExpectedKind,
6542 OpenMPDirectiveKind FoundKind,
6543 SourceLocation MatchingLoc, SourceLocation FoundLoc,
6544 bool SkipUntilOpenMPEnd);
6585 AccessSpecifier &AS, ParsedAttributes &Attrs,
bool Delayed =
false,
6587 Decl *TagDecl =
nullptr);
6601 DeclGroupPtrTy ParseOpenMPDeclareReductionDirective(AccessSpecifier AS);
6605 void ParseOpenMPReductionInitializerForDecl(VarDecl *OmpPrivParm);
6617 DeclGroupPtrTy ParseOpenMPDeclareMapperDirective(AccessSpecifier AS);
6620 TypeResult parseOpenMPDeclareMapperVarDecl(SourceRange &Range,
6621 DeclarationName &Name,
6622 AccessSpecifier AS =
AS_none);
6636 bool ParseOpenMPSimpleVarList(
6637 OpenMPDirectiveKind Kind,
6638 const llvm::function_ref<
void(CXXScopeSpec &, DeclarationNameInfo)>
6640 bool AllowScopeSpecifier);
6689 StmtResult ParseOpenMPDeclarativeOrExecutableDirective(
6690 ParsedStmtContext StmtCtx,
bool ReadDirectiveWithinMetadirective =
false);
6700 ParseOpenMPExecutableDirective(ParsedStmtContext StmtCtx,
6701 OpenMPDirectiveKind DKind, SourceLocation Loc,
6702 bool ReadDirectiveWithinMetadirective);
6711 StmtResult ParseOpenMPInformationalDirective(
6712 ParsedStmtContext StmtCtx, OpenMPDirectiveKind DKind, SourceLocation Loc,
6713 bool ReadDirectiveWithinMetadirective);
6742 OMPClause *ParseOpenMPClause(OpenMPDirectiveKind DKind,
6827 bool ParseOpenMPIndirectClause(SemaOpenMP::DeclareTargetContextInfo &DTCI,
6852 OMPClause *ParseOpenMPSingleExprWithArgClause(OpenMPDirectiveKind DKind,
6857 OMPClause *ParseOpenMPLoopRangeClause();
6866 OMPClause *ParseOpenMPPermutationClause();
6970 OMPClause *ParseOpenMPVarListClause(OpenMPDirectiveKind DKind,
6984 SourceLocation &ClauseNameLoc,
6985 SourceLocation &OpenLoc,
6986 SourceLocation &CloseLoc,
6987 SmallVectorImpl<Expr *> &Exprs,
6988 bool ReqIntConst =
false);
7003 OMPClause *ParseOpenMPUsesAllocatorClause(OpenMPDirectiveKind DKind);
7006 bool ParseOMPInteropInfo(OMPInteropInfo &InteropInfo,
OpenMPClauseKind Kind);
7012 bool ParseOMPInteropAttrSelector(SmallVectorImpl<Expr *> &Attrs);
7050 OMPClause *ParseOpenMPOMPXAttributesClause(
bool ParseOnly);
7057 bool IsAddressOfOperand =
false);
7061 SemaOpenMP::OpenMPVarListDataTy &
Data,
7062 const LangOptions &LangOpts);
7065 SmallVectorImpl<Expr *> &Vars,
7066 SemaOpenMP::OpenMPVarListDataTy &
Data);
7101 std::unique_ptr<PragmaHandler> AlignHandler;
7102 std::unique_ptr<PragmaHandler> GCCVisibilityHandler;
7103 std::unique_ptr<PragmaHandler> OptionsHandler;
7104 std::unique_ptr<PragmaHandler> PackHandler;
7105 std::unique_ptr<PragmaHandler> MSStructHandler;
7106 std::unique_ptr<PragmaHandler> UnusedHandler;
7107 std::unique_ptr<PragmaHandler> WeakHandler;
7108 std::unique_ptr<PragmaHandler> RedefineExtnameHandler;
7109 std::unique_ptr<PragmaHandler> FPContractHandler;
7110 std::unique_ptr<PragmaHandler> OpenCLExtensionHandler;
7111 std::unique_ptr<PragmaHandler> OpenMPHandler;
7112 std::unique_ptr<PragmaHandler> OpenACCHandler;
7113 std::unique_ptr<PragmaHandler> PCSectionHandler;
7114 std::unique_ptr<PragmaHandler> MSCommentHandler;
7115 std::unique_ptr<PragmaHandler> MSDetectMismatchHandler;
7116 std::unique_ptr<PragmaHandler> FPEvalMethodHandler;
7117 std::unique_ptr<PragmaHandler> FloatControlHandler;
7118 std::unique_ptr<PragmaHandler> MSPointersToMembers;
7119 std::unique_ptr<PragmaHandler> MSVtorDisp;
7120 std::unique_ptr<PragmaHandler> MSInitSeg;
7121 std::unique_ptr<PragmaHandler> MSDataSeg;
7122 std::unique_ptr<PragmaHandler> MSBSSSeg;
7123 std::unique_ptr<PragmaHandler> MSConstSeg;
7124 std::unique_ptr<PragmaHandler> MSCodeSeg;
7125 std::unique_ptr<PragmaHandler> MSSection;
7126 std::unique_ptr<PragmaHandler> MSStrictGuardStackCheck;
7127 std::unique_ptr<PragmaHandler> MSRuntimeChecks;
7128 std::unique_ptr<PragmaHandler> MSIntrinsic;
7129 std::unique_ptr<PragmaHandler> MSFunction;
7130 std::unique_ptr<PragmaHandler> MSOptimize;
7131 std::unique_ptr<PragmaHandler> MSFenvAccess;
7132 std::unique_ptr<PragmaHandler> MSAllocText;
7133 std::unique_ptr<PragmaHandler> CUDAForceHostDeviceHandler;
7134 std::unique_ptr<PragmaHandler> OptimizeHandler;
7135 std::unique_ptr<PragmaHandler> LoopHintHandler;
7136 std::unique_ptr<PragmaHandler> UnrollHintHandler;
7137 std::unique_ptr<PragmaHandler> NoUnrollHintHandler;
7138 std::unique_ptr<PragmaHandler> UnrollAndJamHintHandler;
7139 std::unique_ptr<PragmaHandler> NoUnrollAndJamHintHandler;
7140 std::unique_ptr<PragmaHandler> FPHandler;
7141 std::unique_ptr<PragmaHandler> STDCFenvAccessHandler;
7142 std::unique_ptr<PragmaHandler> STDCFenvRoundHandler;
7143 std::unique_ptr<PragmaHandler> STDCCXLIMITHandler;
7144 std::unique_ptr<PragmaHandler> STDCUnknownHandler;
7145 std::unique_ptr<PragmaHandler> AttributePragmaHandler;
7146 std::unique_ptr<PragmaHandler> MaxTokensHerePragmaHandler;
7147 std::unique_ptr<PragmaHandler> MaxTokensTotalPragmaHandler;
7148 std::unique_ptr<PragmaHandler> ExportHandler;
7149 std::unique_ptr<PragmaHandler> RISCVPragmaHandler;
7152 void initializePragmaHandlers();
7155 void resetPragmaHandlers();
7162 void HandlePragmaUnused();
7166 void HandlePragmaVisibility();
7170 void HandlePragmaPack();
7174 void HandlePragmaMSStruct();
7176 void HandlePragmaMSPointersToMembers();
7178 void HandlePragmaMSVtorDisp();
7180 void HandlePragmaMSPragma();
7181 bool HandlePragmaMSSection(StringRef PragmaName,
7182 SourceLocation PragmaLocation);
7183 bool HandlePragmaMSSegment(StringRef PragmaName,
7184 SourceLocation PragmaLocation);
7187 bool HandlePragmaMSInitSeg(StringRef PragmaName,
7188 SourceLocation PragmaLocation);
7193 bool HandlePragmaMSStrictGuardStackCheck(StringRef PragmaName,
7194 SourceLocation PragmaLocation);
7195 bool HandlePragmaMSFunction(StringRef PragmaName,
7196 SourceLocation PragmaLocation);
7197 bool HandlePragmaMSAllocText(StringRef PragmaName,
7198 SourceLocation PragmaLocation);
7201 bool HandlePragmaMSOptimize(StringRef PragmaName,
7202 SourceLocation PragmaLocation);
7205 bool HandlePragmaMSIntrinsic(StringRef PragmaName,
7206 SourceLocation PragmaLocation);
7210 void HandlePragmaAlign();
7214 void HandlePragmaDump();
7218 void HandlePragmaWeak();
7222 void HandlePragmaWeakAlias();
7226 void HandlePragmaRedefineExtname();
7230 void HandlePragmaFPContract();
7234 void HandlePragmaFEnvAccess();
7238 void HandlePragmaFEnvRound();
7242 void HandlePragmaCXLimitedRange();
7246 void HandlePragmaFloatControl();
7250 void HandlePragmaFP();
7254 void HandlePragmaOpenCLExtension();
7258 StmtResult HandlePragmaCaptured();
7262 bool HandlePragmaLoopHint(LoopHint &Hint);
7264 bool ParsePragmaAttributeSubjectMatchRuleSet(
7266 SourceLocation &AnyLoc, SourceLocation &LastMatchRuleEndLoc);
7268 void HandlePragmaAttribute();
7274 void HandlePragmaExport();
7300 enum class ParsedStmtContext {
7303 AllowDeclarationsInC = 0x1,
7305 AllowStandaloneOpenMPDirectives = 0x2,
7312 Compound = AllowDeclarationsInC | AllowStandaloneOpenMPDirectives,
7329 ParsedStmtContext StmtCtx = ParsedStmtContext::SubStmt,
7384 ParseStatementOrDeclaration(
StmtVector &Stmts, ParsedStmtContext StmtCtx,
7388 StmtResult ParseStatementOrDeclarationAfterAttributes(
7389 StmtVector &Stmts, ParsedStmtContext StmtCtx,
7394 StmtResult ParseExprStatement(ParsedStmtContext StmtCtx);
7408 ParsedStmtContext StmtCtx);
7417 StmtResult ParseCaseStatement(ParsedStmtContext StmtCtx,
7418 bool MissingCase =
false,
7428 StmtResult ParseDefaultStatement(ParsedStmtContext StmtCtx);
7430 StmtResult ParseCompoundStatement(
bool isStmtExpr =
false);
7456 StmtResult ParseCompoundStatement(
bool isStmtExpr,
unsigned ScopeFlags);
7461 void ParseCompoundStatementLeadingPragmas();
7463 void DiagnoseLabelAtEndOfCompoundStatement();
7473 StmtResult ParseCompoundStatementBody(
bool isStmtExpr =
false);
7491 bool ParseParenExprOrCondition(
StmtResult *InitStmt,
7565 void ParseForRangeInitializerAfterColon(ForRangeInit &FRI,
7611 StmtResult ParseBreakOrContinueStatement(
bool IsContinue);
7645 void ParseMicrosoftIfExistsStatement(
StmtVector &Stmts);
7692 StmtResult ParseCXXCatchBlock(
bool FnCatch =
false);
7730 Decl *ParseFunctionStatementBody(
Decl *
Decl, ParseScope &BodyScope);
7739 Decl *ParseFunctionTryBlock(
Decl *
Decl, ParseScope &BodyScope);
7750 Decl *ParseFunctionBody(
Decl *D, ParseScope &BodyScope);
7756 bool trySkippingFunctionBody();
7764 bool isDeclarationStatement(
bool DisambiguatingWithExpression =
false) {
7766 return isCXXDeclarationStatement(DisambiguatingWithExpression);
7774 bool isForInitDeclaration() {
7778 return Tok.is(tok::kw_using) ||
7779 isCXXSimpleDeclaration(
true);
7784 bool isForRangeIdentifier();
7801 unsigned &NumLineToksConsumed,
7802 bool IsUnevaluated);
7845 StmtResult ParseMicrosoftAsmStatement(SourceLocation AsmLoc);
7861 bool ParseAsmOperandsOpt(SmallVectorImpl<IdentifierInfo *> &Names,
7862 SmallVectorImpl<Expr *> &Constraints,
7863 SmallVectorImpl<Expr *> &Exprs);
7865 class GNUAsmQualifiers {
7866 unsigned Qualifiers = AQ_unspecified;
7875 static const char *getQualifierName(AQ Qualifier);
7876 bool setAsmQualifier(AQ Qualifier);
7877 inline bool isVolatile()
const {
return Qualifiers & AQ_volatile; };
7878 inline bool isInline()
const {
return Qualifiers & AQ_inline; };
7879 inline bool isGoto()
const {
return Qualifiers & AQ_goto; }
7883 bool isGCCAsmStatement(
const Token &TokAfterAsm)
const;
7885 bool isGNUAsmQualifier(
const Token &TokAfterAsm)
const;
7886 GNUAsmQualifiers::AQ getGNUAsmQualifier(
const Token &Tok)
const;
7899 bool parseGNUAsmQualifierListOpt(GNUAsmQualifiers &AQ);
7923 unsigned TemplateParameterDepth;
7926 class TemplateParameterDepthRAII {
7928 unsigned AddedLevels;
7931 explicit TemplateParameterDepthRAII(
unsigned &Depth)
7932 : Depth(Depth), AddedLevels(0) {}
7934 ~TemplateParameterDepthRAII() { Depth -= AddedLevels; }
7940 void addDepth(
unsigned D) {
7944 void setAddedDepth(
unsigned D) {
7945 Depth = Depth - AddedLevels + D;
7949 unsigned getDepth()
const {
return Depth; }
7950 unsigned getOriginalDepth()
const {
return Depth - AddedLevels; }
7955 SmallVector<TemplateIdAnnotation *, 16> TemplateIds;
7961 bool DelayTemplateIdDestruction =
false;
7963 void MaybeDestroyTemplateIds() {
7964 if (DelayTemplateIdDestruction)
7966 if (!TemplateIds.empty() &&
7967 (Tok.is(tok::eof) || !PP.mightHavePendingAnnotationTokens()))
7968 DestroyTemplateIds();
7970 void DestroyTemplateIds();
7974 struct DestroyTemplateIdAnnotationsRAIIObj {
7977 DestroyTemplateIdAnnotationsRAIIObj(
Parser &Self) : Self(Self) {}
7978 ~DestroyTemplateIdAnnotationsRAIIObj() { Self.MaybeDestroyTemplateIds(); }
7981 struct DelayTemplateIdDestructionRAII {
7983 bool PrevDelayTemplateIdDestruction;
7985 DelayTemplateIdDestructionRAII(
Parser &Self,
7986 bool DelayTemplateIdDestruction) noexcept
7988 PrevDelayTemplateIdDestruction(Self.DelayTemplateIdDestruction) {
7989 Self.DelayTemplateIdDestruction = DelayTemplateIdDestruction;
7992 ~DelayTemplateIdDestructionRAII() noexcept {
7993 Self.DelayTemplateIdDestruction = PrevDelayTemplateIdDestruction;
7998 SmallVector<const IdentifierInfo *, 8> TentativelyDeclaredIdentifiers;
8010 struct AngleBracketTracker {
8013 enum Priority :
unsigned short {
8015 PotentialTypo = 0x0,
8017 DependentName = 0x2,
8020 SpaceBeforeLess = 0x0,
8022 NoSpaceBeforeLess = 0x1,
8053 if (!Locs.empty() && Locs.back().isActive(P)) {
8054 if (Locs.back().Priority <= Prio) {
8056 Locs.back().LessLoc = LessLoc;
8057 Locs.back().Priority = Prio;
8060 Locs.push_back({
TemplateName, LessLoc, Prio, P.ParenCount,
8061 P.BracketCount, P.BraceCount});
8069 while (!Locs.empty() && Locs.back().isActiveOrNested(P))
8076 if (!Locs.empty() && Locs.back().isActive(P))
8077 return &Locs.back();
8082 AngleBracketTracker AngleBrackets;
8087 struct ParsedTemplateInfo {
8088 ParsedTemplateInfo()
8092 bool isSpecialization,
8093 bool lastParameterListWasEmpty =
false)
8096 TemplateParams(TemplateParams),
8097 LastParameterListWasEmpty(lastParameterListWasEmpty) {}
8099 explicit ParsedTemplateInfo(SourceLocation ExternLoc,
8100 SourceLocation TemplateLoc)
8102 TemplateParams(
nullptr), ExternLoc(ExternLoc),
8103 TemplateLoc(TemplateLoc), LastParameterListWasEmpty(
false) {}
8113 SourceLocation ExternLoc;
8117 SourceLocation TemplateLoc;
8120 bool LastParameterListWasEmpty;
8122 SourceRange getSourceRange() const LLVM_READONLY;
8126 void LexTemplateFunctionForLateParsing(
CachedTokens &Toks);
8129 void ParseLateTemplatedFuncDef(LateParsedTemplate &LPT);
8131 static
void LateTemplateParserCallback(
void *P, LateParsedTemplate &LPT);
8139 void checkPotentialAngleBracket(
ExprResult &PotentialTemplateName);
8140 bool checkPotentialAngleBracketDelimiter(const AngleBracketTracker::Loc &,
8141 const Token &OpToken);
8142 bool checkPotentialAngleBracketDelimiter(const Token &OpToken) {
8143 if (
auto *Info = AngleBrackets.getCurrent(*
this))
8144 return checkPotentialAngleBracketDelimiter(*Info, OpToken);
8155 SourceLocation &DeclEnd,
8156 ParsedAttributes &AccessAttrs);
8203 ParsingDeclRAIIObject &DiagsFromParams, SourceLocation &DeclEnd,
8215 bool ParseTemplateParameters(MultiParseScope &TemplateScopes,
unsigned Depth,
8216 SmallVectorImpl<NamedDecl *> &TemplateParams,
8217 SourceLocation &LAngleLoc,
8218 SourceLocation &RAngleLoc);
8230 bool ParseTemplateParameterList(
unsigned Depth,
8231 SmallVectorImpl<NamedDecl *> &TemplateParams);
8233 enum class TPResult;
8237 TPResult isStartOfTemplateTypeParameter();
8261 NamedDecl *ParseTemplateParameter(
unsigned Depth,
unsigned Position);
8274 NamedDecl *ParseTypeParameter(
unsigned Depth,
unsigned Position);
8290 NamedDecl *ParseTemplateTemplateParameter(
unsigned Depth,
unsigned Position);
8300 NamedDecl *ParseNonTypeTemplateParameter(
unsigned Depth,
unsigned Position);
8304 bool isTypeConstraintAnnotation();
8316 bool TryAnnotateTypeConstraint();
8318 void DiagnoseMisplacedEllipsis(SourceLocation EllipsisLoc,
8319 SourceLocation CorrectLoc,
8320 bool AlreadyHasEllipsis,
8321 bool IdentifierHasName);
8322 void DiagnoseMisplacedEllipsisInDeclarator(SourceLocation EllipsisLoc,
8325 typedef SmallVector<ParsedTemplateArgument, 16> TemplateArgList;
8342 bool ParseGreaterThanInTemplateList(SourceLocation LAngleLoc,
8343 SourceLocation &RAngleLoc,
8344 bool ConsumeLastToken,
8345 bool ObjCGenericList);
8358 bool ParseTemplateIdAfterTemplateName(
bool ConsumeLastToken,
8359 SourceLocation &LAngleLoc,
8360 TemplateArgList &TemplateArgs,
8361 SourceLocation &RAngleLoc,
8406 CXXScopeSpec &SS, SourceLocation TemplateKWLoc,
8408 bool AllowTypeAnnotation =
true,
8409 bool TypeConstraint =
false);
8427 AnnotateTemplateIdTokenAsType(CXXScopeSpec &SS,
8429 bool IsClassName =
false);
8441 bool ParseTemplateArgumentList(TemplateArgList &TemplateArgs,
8445 ParsedTemplateArgument ParseTemplateTemplateArgument();
8457 ParsedTemplateArgument ParseTemplateArgument();
8469 SourceLocation ExternLoc,
8470 SourceLocation TemplateLoc,
8471 SourceLocation &DeclEnd,
8472 ParsedAttributes &AccessAttrs,
8481 Decl *ParseConceptDefinition(
const ParsedTemplateInfo &TemplateInfo,
8482 SourceLocation &DeclEnd);
8510 class TentativeParsingAction {
8512 PreferredTypeBuilder PrevPreferredType;
8514 size_t PrevTentativelyDeclaredIdentifierCount;
8515 unsigned short PrevParenCount, PrevBracketCount, PrevBraceCount;
8519 explicit TentativeParsingAction(Parser &p,
bool Unannotated =
false)
8520 : P(p), PrevPreferredType(P.PreferredType) {
8522 PrevTentativelyDeclaredIdentifierCount =
8523 P.TentativelyDeclaredIdentifiers.size();
8524 PrevParenCount = P.ParenCount;
8525 PrevBracketCount = P.BracketCount;
8526 PrevBraceCount = P.BraceCount;
8527 P.PP.EnableBacktrackAtThisPos(Unannotated);
8531 assert(isActive &&
"Parsing action was finished!");
8532 P.TentativelyDeclaredIdentifiers.resize(
8533 PrevTentativelyDeclaredIdentifierCount);
8534 P.PP.CommitBacktrackedTokens();
8538 assert(isActive &&
"Parsing action was finished!");
8540 P.PreferredType = PrevPreferredType;
8542 P.TentativelyDeclaredIdentifiers.resize(
8543 PrevTentativelyDeclaredIdentifierCount);
8544 P.ParenCount = PrevParenCount;
8545 P.BracketCount = PrevBracketCount;
8546 P.BraceCount = PrevBraceCount;
8549 ~TentativeParsingAction() {
8550 assert(!isActive &&
"Forgot to call Commit or Revert!");
8556 class RevertingTentativeParsingAction
8557 :
private Parser::TentativeParsingAction {
8559 using TentativeParsingAction::TentativeParsingAction;
8561 ~RevertingTentativeParsingAction() { Revert(); }
8596 bool isCXXDeclarationStatement(
bool DisambiguatingWithExpression =
false);
8622 bool isCXXSimpleDeclaration(
bool AllowForRangeDecl);
8635 bool isCXXFunctionDeclarator(
bool *IsAmbiguous =
nullptr,
8639 struct ConditionDeclarationOrInitStatementState;
8640 enum class ConditionOrInitStatement {
8667 ConditionOrInitStatement
8668 isCXXConditionDeclarationOrInitStatement(
bool CanBeInitStmt,
8669 bool CanBeForRangeDecl);
8695 return isCXXTypeId(Context, isAmbiguous);
8709 bool isEnumBase(
bool AllowSemi);
8829 TPResult BracedCastResult = TPResult::False,
8830 bool *InvalidAsDeclSpec =
nullptr);
8835 bool isCXXDeclarationSpecifierAType();
8841 TPResult isTemplateArgumentList(
unsigned TokensToSkip);
8846 TPResult isExplicitBool();
8851 bool isTentativelyDeclared(IdentifierInfo *II);
8870 TPResult TryParseSimpleDeclaration(
bool AllowForRangeDecl);
8878 TPResult TryParseTypeofSpecifier();
8882 TPResult TryParseProtocolQualifiers();
8884 TPResult TryParsePtrOperatorSeq();
8906 TPResult TryParseOperatorId();
8937 TPResult TryParseInitDeclaratorList(
bool MayHaveTrailingReturnType =
false);
8994 TPResult TryParseDeclarator(
bool mayBeAbstract,
bool mayHaveIdentifier =
true,
8995 bool mayHaveDirectInit =
false,
8996 bool mayHaveTrailingReturnType =
false);
9017 TPResult TryParseParameterDeclarationClause(
9018 bool *InvalidAsDeclaration =
nullptr,
bool VersusTemplateArg =
false,
9035 TPResult TryParseFunctionDeclarator(
bool MayHaveTrailingReturnType =
false);
9041 bool NameAfterArrowIsNonType();
9047 TPResult TryParseBracketDeclarator();
9051 TPResult TryConsumeDeclarationSpecifier();
9055 bool TrySkipAttributes();
9097 isCXX11AttributeSpecifier(
bool Disambiguate =
false,
9098 bool OuterMightBeMessageSend =
false);