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 bool ParsedForRangeDecl() {
return !ColonLoc.
isInvalid(); }
1757 struct ForRangeInfo : ForRangeInit {
1780 SourceLocation &DeclEnd,
1781 ParsedAttributes &DeclAttrs,
1782 ParsedAttributes &DeclSpecAttrs,
1783 SourceLocation *DeclSpecStart =
nullptr);
1810 ParsedAttributes &DeclAttrs,
1811 ParsedAttributes &DeclSpecAttrs,
bool RequireSemi,
1812 ForRangeInit *FRI =
nullptr,
1813 SourceLocation *DeclSpecStart =
nullptr);
1823 ParsedAttributes &Attrs,
1824 ParsedTemplateInfo &TemplateInfo,
1825 SourceLocation *DeclEnd =
nullptr,
1826 ForRangeInit *FRI =
nullptr);
1852 Decl *ParseDeclarationAfterDeclarator(
1854 const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo());
1858 bool ParseAsmAttributesAfterDeclarator(Declarator &D);
1859 Decl *ParseDeclarationAfterDeclaratorAndAttributes(
1861 const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo(),
1862 ForRangeInit *FRI =
nullptr);
1873 bool ParseImplicitInt(DeclSpec &DS, CXXScopeSpec *SS,
1875 DeclSpecContext DSC, ParsedAttributes &Attrs);
1885 ParseDeclarationSpecifiers(DeclSpec &DS, ParsedTemplateInfo &TemplateInfo,
1887 DeclSpecContext DSC = DeclSpecContext::DSC_normal,
1888 LateParsedAttrList *LateAttrs =
nullptr) {
1889 return ParseDeclarationSpecifiers(DS, TemplateInfo, AS, DSC, LateAttrs,
1890 getImplicitTypenameContext(DSC));
1923 ParseDeclarationSpecifiers(DeclSpec &DS, ParsedTemplateInfo &TemplateInfo,
1925 LateParsedAttrList *LateAttrs,
1935 bool DiagnoseMissingSemiAfterTagDefinition(
1937 LateParsedAttrList *LateAttrs =
nullptr);
1939 void ParseSpecifierQualifierList(
1941 DeclSpecContext DSC = DeclSpecContext::DSC_normal) {
1942 ParseSpecifierQualifierList(DS, getImplicitTypenameContext(DSC), AS, DSC);
1953 void ParseSpecifierQualifierList(
1956 DeclSpecContext DSC = DeclSpecContext::DSC_normal);
1990 void ParseEnumSpecifier(SourceLocation TagLoc, DeclSpec &DS,
1991 const ParsedTemplateInfo &TemplateInfo,
2006 void ParseEnumBody(SourceLocation StartLoc, Decl *TagDecl,
2007 SkipBodyInfo *SkipBody =
nullptr);
2021 void ParseStructUnionBody(SourceLocation StartLoc,
DeclSpec::TST TagType,
2022 RecordDecl *TagDecl);
2047 void ParseStructDeclaration(
2048 ParsingDeclSpec &DS,
2049 llvm::function_ref<Decl *(ParsingFieldDeclarator &)> FieldsCallback,
2050 LateParsedAttrList *LateFieldAttrs =
nullptr);
2062 bool DisambiguatingWithExpression =
false);
2066 bool isTypeSpecifierQualifier(
const Token &Tok);
2071 bool isKnownToBeTypeSpecifier(
const Token &Tok)
const;
2076 bool isConstructorDeclarator(
2079 const ParsedTemplateInfo *TemplateInfo =
nullptr);
2083 void DiagnoseBitIntUse(
const Token &Tok);
2087 bool CheckProhibitedCXX11Attribute() {
2088 assert(Tok.is(tok::l_square));
2091 return DiagnoseProhibitedCXX11Attribute();
2102 bool DiagnoseProhibitedCXX11Attribute();
2104 void CheckMisplacedCXX11Attribute(ParsedAttributes &Attrs,
2105 SourceLocation CorrectLocation) {
2106 if (!Tok.isRegularKeywordAttribute() &&
2107 (Tok.isNot(tok::l_square) ||
NextToken().
isNot(tok::l_square)) &&
2108 Tok.isNot(tok::kw_alignas))
2110 DiagnoseMisplacedCXX11Attribute(Attrs, CorrectLocation);
2117 void DiagnoseMisplacedCXX11Attribute(ParsedAttributes &Attrs,
2118 SourceLocation CorrectLocation);
2128 void stripTypeAttributesOffDeclSpec(ParsedAttributes &Attrs, DeclSpec &DS,
2132 void ProhibitAttributes(ParsedAttributes &Attrs,
2133 SourceLocation FixItLoc = SourceLocation()) {
2134 if (Attrs.Range.isInvalid())
2136 DiagnoseProhibitedAttributes(Attrs, FixItLoc);
2140 void ProhibitAttributes(ParsedAttributesView &Attrs,
2141 SourceLocation FixItLoc = SourceLocation()) {
2142 if (Attrs.Range.isInvalid())
2144 DiagnoseProhibitedAttributes(Attrs, FixItLoc);
2145 Attrs.clearListOnly();
2147 void DiagnoseProhibitedAttributes(
const ParsedAttributesView &Attrs,
2148 SourceLocation FixItLoc);
2156 void ProhibitCXX11Attributes(ParsedAttributes &Attrs,
unsigned AttrDiagID,
2157 unsigned KeywordDiagId,
2158 bool DiagnoseEmptyAttrs =
false,
2159 bool WarnOnUnknownAttrs =
false);
2163 void DiagnoseCXX11AttributeExtension(ParsedAttributes &Attrs);
2165 ExprResult ParseUnevaluatedStringInAttribute(
const IdentifierInfo &AttrName);
2172 bool ParseAttributeArgumentList(
2173 const IdentifierInfo &AttrName, SmallVectorImpl<Expr *> &Exprs,
2174 ParsedAttributeArgumentsProperties ArgsProperties,
unsigned Arg);
2181 ParseAttributeArgsCommon(IdentifierInfo *AttrName, SourceLocation AttrNameLoc,
2182 ParsedAttributes &Attrs, SourceLocation *EndLoc,
2183 IdentifierInfo *ScopeName, SourceLocation ScopeLoc,
2184 ParsedAttr::Form Form);
2186 enum ParseAttrKindMask {
2188 PAKM_Declspec = 1 << 1,
2189 PAKM_CXX11 = 1 << 2,
2208 void ParseAttributes(
unsigned WhichAttrKinds, ParsedAttributes &Attrs,
2209 LateParsedAttrList *LateAttrs =
nullptr);
2212 bool MaybeParseAttributes(
unsigned WhichAttrKinds, ParsedAttributes &Attrs,
2213 LateParsedAttrList *LateAttrs =
nullptr) {
2214 if (Tok.isOneOf(tok::kw___attribute, tok::kw___declspec) ||
2215 isAllowedCXX11AttributeSpecifier()) {
2216 ParseAttributes(WhichAttrKinds, Attrs, LateAttrs);
2222 void MaybeParseGNUAttributes(Declarator &D,
2223 LateParsedAttrList *LateAttrs =
nullptr) {
2224 if (Tok.is(tok::kw___attribute)) {
2225 ParsedAttributes Attrs(AttrFactory);
2226 ParseGNUAttributes(Attrs, LateAttrs, &D);
2227 D.takeAttributesAppending(Attrs);
2231 bool MaybeParseGNUAttributes(ParsedAttributes &Attrs,
2232 LateParsedAttrList *LateAttrs =
nullptr) {
2233 if (Tok.is(tok::kw___attribute)) {
2234 ParseGNUAttributes(Attrs, LateAttrs);
2256 bool ParseSingleGNUAttribute(ParsedAttributes &Attrs, SourceLocation &EndLoc,
2257 LateParsedAttrList *LateAttrs =
nullptr,
2258 Declarator *D =
nullptr);
2303 void ParseGNUAttributes(ParsedAttributes &Attrs,
2304 LateParsedAttrList *LateAttrs =
nullptr,
2305 Declarator *D =
nullptr);
2309 void ParseGNUAttributeArgs(IdentifierInfo *AttrName,
2310 SourceLocation AttrNameLoc,
2311 ParsedAttributes &Attrs, SourceLocation *EndLoc,
2312 IdentifierInfo *ScopeName, SourceLocation ScopeLoc,
2313 ParsedAttr::Form Form, Declarator *D);
2314 IdentifierLoc *ParseIdentifierLoc();
2317 ParseClangAttributeArgs(IdentifierInfo *AttrName, SourceLocation AttrNameLoc,
2318 ParsedAttributes &Attrs, SourceLocation *EndLoc,
2319 IdentifierInfo *ScopeName, SourceLocation ScopeLoc,
2320 ParsedAttr::Form Form);
2322 void MaybeParseCXX11Attributes(Declarator &D) {
2323 if (isAllowedCXX11AttributeSpecifier()) {
2324 ParsedAttributes Attrs(AttrFactory);
2325 ParseCXX11Attributes(Attrs);
2326 D.takeAttributesAppending(Attrs);
2330 bool MaybeParseCXX11Attributes(ParsedAttributes &Attrs,
2331 bool OuterMightBeMessageSend =
false) {
2332 if (isAllowedCXX11AttributeSpecifier(
false, OuterMightBeMessageSend)) {
2333 ParseCXX11Attributes(Attrs);
2339 bool MaybeParseMicrosoftAttributes(ParsedAttributes &Attrs) {
2340 bool AttrsParsed =
false;
2342 Tok.is(tok::l_square)) {
2343 ParsedAttributes AttrsWithRange(AttrFactory);
2344 ParseMicrosoftAttributes(AttrsWithRange);
2345 AttrsParsed = !AttrsWithRange.empty();
2346 Attrs.takeAllAppendingFrom(AttrsWithRange);
2350 bool MaybeParseMicrosoftDeclSpecs(ParsedAttributes &Attrs) {
2351 if (
getLangOpts().DeclSpecKeyword && Tok.is(tok::kw___declspec)) {
2352 ParseMicrosoftDeclSpecs(Attrs);
2366 void ParseMicrosoftDeclSpecs(ParsedAttributes &Attrs);
2367 bool ParseMicrosoftDeclSpecArgs(IdentifierInfo *AttrName,
2368 SourceLocation AttrNameLoc,
2369 ParsedAttributes &Attrs);
2370 void ParseMicrosoftTypeAttributes(ParsedAttributes &attrs);
2371 void ParseWebAssemblyFuncrefTypeAttribute(ParsedAttributes &Attrs);
2372 void DiagnoseAndSkipExtendedMicrosoftTypeAttributes();
2373 SourceLocation SkipExtendedMicrosoftTypeAttributes();
2375 void ParseBorlandTypeAttributes(ParsedAttributes &attrs);
2376 void ParseOpenCLKernelAttributes(ParsedAttributes &attrs);
2377 void ParseOpenCLQualifiers(ParsedAttributes &Attrs);
2378 void ParseNullabilityTypeSpecifiers(ParsedAttributes &attrs);
2379 void ParseCUDAFunctionAttributes(ParsedAttributes &attrs);
2380 bool isHLSLQualifier(
const Token &Tok)
const;
2381 void ParseHLSLQualifiers(ParsedAttributes &Attrs);
2393 VersionTuple ParseVersionTuple(SourceRange &Range);
2422 void ParseAvailabilityAttribute(IdentifierInfo &Availability,
2423 SourceLocation AvailabilityLoc,
2424 ParsedAttributes &attrs,
2425 SourceLocation *endLoc,
2426 IdentifierInfo *ScopeName,
2427 SourceLocation ScopeLoc,
2428 ParsedAttr::Form Form);
2446 void ParseExternalSourceSymbolAttribute(IdentifierInfo &ExternalSourceSymbol,
2448 ParsedAttributes &Attrs,
2449 SourceLocation *EndLoc,
2450 IdentifierInfo *ScopeName,
2451 SourceLocation ScopeLoc,
2452 ParsedAttr::Form Form);
2467 void ParseObjCBridgeRelatedAttribute(IdentifierInfo &ObjCBridgeRelated,
2468 SourceLocation ObjCBridgeRelatedLoc,
2469 ParsedAttributes &Attrs,
2470 SourceLocation *EndLoc,
2471 IdentifierInfo *ScopeName,
2472 SourceLocation ScopeLoc,
2473 ParsedAttr::Form Form);
2475 void ParseSwiftNewTypeAttribute(IdentifierInfo &AttrName,
2476 SourceLocation AttrNameLoc,
2477 ParsedAttributes &Attrs,
2478 SourceLocation *EndLoc,
2479 IdentifierInfo *ScopeName,
2480 SourceLocation ScopeLoc,
2481 ParsedAttr::Form Form);
2483 void ParseTypeTagForDatatypeAttribute(IdentifierInfo &AttrName,
2484 SourceLocation AttrNameLoc,
2485 ParsedAttributes &Attrs,
2486 SourceLocation *EndLoc,
2487 IdentifierInfo *ScopeName,
2488 SourceLocation ScopeLoc,
2489 ParsedAttr::Form Form);
2491 void ParseAttributeWithTypeArg(IdentifierInfo &AttrName,
2492 SourceLocation AttrNameLoc,
2493 ParsedAttributes &Attrs,
2494 IdentifierInfo *ScopeName,
2495 SourceLocation ScopeLoc,
2496 ParsedAttr::Form Form);
2498 void DistributeCLateParsedAttrs(Decl *Dcl, LateParsedAttrList *LateAttrs);
2504 void ParseBoundsAttribute(IdentifierInfo &AttrName,
2505 SourceLocation AttrNameLoc, ParsedAttributes &Attrs,
2506 IdentifierInfo *ScopeName, SourceLocation ScopeLoc,
2507 ParsedAttr::Form Form);
2523 void ParseTypeofSpecifier(DeclSpec &DS);
2530 void ParseAtomicSpecifier(DeclSpec &DS);
2540 ExprResult ParseAlignArgument(StringRef KWName, SourceLocation Start,
2541 SourceLocation &EllipsisLoc,
bool &IsType,
2554 void ParseAlignmentSpecifier(ParsedAttributes &Attrs,
2555 SourceLocation *endLoc =
nullptr);
2564 void ParsePtrauthQualifier(ParsedAttributes &Attrs);
2569 class DeclaratorScopeObj {
2576 DeclaratorScopeObj(
Parser &p, CXXScopeSpec &ss)
2577 : P(p), SS(ss), EnteredScope(
false), CreatedScope(
false) {}
2579 void EnterDeclaratorScope() {
2580 assert(!EnteredScope &&
"Already entered the scope!");
2581 assert(SS.isSet() &&
"C++ scope was not set!");
2583 CreatedScope =
true;
2586 if (!P.Actions.ActOnCXXEnterDeclaratorScope(P.getCurScope(), SS))
2587 EnteredScope =
true;
2590 ~DeclaratorScopeObj() {
2592 assert(SS.isSet() &&
"C++ scope was cleared ?");
2593 P.Actions.ActOnCXXExitDeclaratorScope(P.getCurScope(), SS);
2601 void ParseDeclarator(Declarator &D);
2632 void ParseDeclaratorInternal(Declarator &D,
2633 DirectDeclParseFunction DirectDeclParser);
2635 enum AttrRequirements {
2636 AR_NoAttributesParsed = 0,
2637 AR_GNUAttributesParsedAndRejected = 1 << 0,
2638 AR_GNUAttributesParsed = 1 << 1,
2639 AR_CXX11AttributesParsed = 1 << 2,
2640 AR_DeclspecAttributesParsed = 1 << 3,
2641 AR_AllAttributesParsed = AR_GNUAttributesParsed | AR_CXX11AttributesParsed |
2642 AR_DeclspecAttributesParsed,
2643 AR_VendorAttributesParsed =
2644 AR_GNUAttributesParsed | AR_DeclspecAttributesParsed
2661 void ParseTypeQualifierListOpt(
2662 DeclSpec &DS,
unsigned AttrReqs = AR_AllAttributesParsed,
2663 bool AtomicOrPtrauthAllowed =
true,
bool IdentifierRequired =
false,
2664 llvm::function_ref<
void()> CodeCompletionHandler = {});
2714 void ParseDirectDeclarator(Declarator &D);
2715 void ParseDecompositionDeclarator(Declarator &D);
2733 void ParseParenDeclarator(Declarator &D);
2758 void ParseFunctionDeclarator(Declarator &D, ParsedAttributes &FirstArgAttrs,
2760 bool IsAmbiguous,
bool RequiresArg =
false);
2761 void InitCXXThisScopeForDeclaratorIfRelevant(
2762 const Declarator &D,
const DeclSpec &DS,
2763 std::optional<Sema::CXXThisScopeRAII> &ThisScope);
2767 bool ParseRefQualifier(
bool &RefQualifierIsLValueRef,
2768 SourceLocation &RefQualifierLoc);
2775 bool isFunctionDeclaratorIdentifierList();
2789 void ParseFunctionDeclaratorIdentifierList(
2790 Declarator &D, SmallVectorImpl<DeclaratorChunk::ParamInfo> &ParamInfo);
2791 void ParseParameterDeclarationClause(
2792 Declarator &D, ParsedAttributes &attrs,
2793 SmallVectorImpl<DeclaratorChunk::ParamInfo> &ParamInfo,
2794 SourceLocation &EllipsisLoc) {
2795 return ParseParameterDeclarationClause(
2796 D.getContext(), attrs, ParamInfo, EllipsisLoc,
2797 D.getCXXScopeSpec().isSet() &&
2798 D.isFunctionDeclaratorAFunctionDeclaration());
2836 void ParseParameterDeclarationClause(
2838 SmallVectorImpl<DeclaratorChunk::ParamInfo> &ParamInfo,
2839 SourceLocation &EllipsisLoc,
bool IsACXXFunctionDeclaration =
false);
2850 void ParseBracketDeclarator(Declarator &D);
2853 void ParseMisplacedBracketDeclarator(Declarator &D);
2864 TypeResult ParseTypeFromString(StringRef TypeStr, StringRef Context,
2865 SourceLocation IncludeLoc);
2881 mutable IdentifierInfo *Ident_sealed;
2882 mutable IdentifierInfo *Ident_abstract;
2885 mutable IdentifierInfo *Ident_final;
2886 mutable IdentifierInfo *Ident_GNU_final;
2887 mutable IdentifierInfo *Ident_override;
2892 struct ParsingClass {
2893 ParsingClass(Decl *TagOrTemplate,
bool TopLevelClass,
bool IsInterface)
2894 : TopLevelClass(TopLevelClass), IsInterface(IsInterface),
2895 TagOrTemplate(TagOrTemplate) {}
2899 bool TopLevelClass : 1;
2902 bool IsInterface : 1;
2905 Decl *TagOrTemplate;
2910 LateParsedDeclarationsContainer LateParsedDeclarations;
2916 std::stack<ParsingClass *> ClassStack;
2918 ParsingClass &getCurrentClass() {
2919 assert(!ClassStack.empty() &&
"No lexed method stacks!");
2920 return *ClassStack.top();
2924 class ParsingClassDefinition {
2930 ParsingClassDefinition(
Parser &P, Decl *TagOrTemplate,
bool TopLevelClass,
2932 : P(P), Popped(
false),
2933 State(P.PushParsingClass(TagOrTemplate, TopLevelClass, IsInterface)) {
2938 assert(!Popped &&
"Nested class has already been popped");
2940 P.PopParsingClass(State);
2943 ~ParsingClassDefinition() {
2945 P.PopParsingClass(State);
2961 bool Delayed, SourceRange &SpecificationRange,
2962 SmallVectorImpl<ParsedType> &DynamicExceptions,
2963 SmallVectorImpl<SourceRange> &DynamicExceptionRanges,
2981 ParseDynamicExceptionSpecification(SourceRange &SpecificationRange,
2982 SmallVectorImpl<ParsedType> &Exceptions,
2983 SmallVectorImpl<SourceRange> &Ranges);
2990 TypeResult ParseTrailingReturnType(SourceRange &Range,
2991 bool MayBeFollowedByDirectInit);
2994 void ParseTrailingRequiresClauseWithScope(Declarator &D);
2995 void ParseTrailingRequiresClause(Declarator &D);
2997 void ParseMicrosoftIfExistsClassDeclaration(
DeclSpec::TST TagType,
2998 ParsedAttributes &AccessAttrs,
3001 SourceLocation ParsePackIndexingType(DeclSpec &DS);
3002 void AnnotateExistingIndexedTypeNamePack(
ParsedType T,
3003 SourceLocation StartLoc,
3004 SourceLocation EndLoc);
3011 bool isAllowedCXX11AttributeSpecifier(
bool Disambiguate =
false,
3012 bool OuterMightBeMessageSend =
false) {
3013 return (Tok.isRegularKeywordAttribute() ||
3014 isCXX11AttributeSpecifier(Disambiguate, OuterMightBeMessageSend) !=
3021 SourceLocation SkipCXX11Attributes();
3025 void DiagnoseAndSkipCXX11Attributes();
3027 void ParseOpenMPAttributeArgs(
const IdentifierInfo *AttrName,
3056 void ParseCXX11AttributeSpecifierInternal(ParsedAttributes &Attrs,
3058 SourceLocation *EndLoc =
nullptr);
3059 void ParseCXX11AttributeSpecifier(ParsedAttributes &Attrs,
3060 SourceLocation *EndLoc =
nullptr) {
3062 ParseCXX11AttributeSpecifierInternal(Attrs, OpenMPTokens, EndLoc);
3063 ReplayOpenMPAttributeTokens(OpenMPTokens);
3072 void ParseCXX11Attributes(ParsedAttributes &attrs);
3092 bool ParseCXX11AttributeArgs(IdentifierInfo *AttrName,
3093 SourceLocation AttrNameLoc,
3094 ParsedAttributes &Attrs, SourceLocation *EndLoc,
3095 IdentifierInfo *ScopeName,
3096 SourceLocation ScopeLoc,
3102 ParseCXXAssumeAttributeArg(ParsedAttributes &Attrs, IdentifierInfo *AttrName,
3103 SourceLocation AttrNameLoc,
3104 IdentifierInfo *ScopeName, SourceLocation ScopeLoc,
3105 SourceLocation *EndLoc, ParsedAttr::Form Form);
3116 IdentifierInfo *TryParseCXX11AttributeIdentifier(
3117 SourceLocation &Loc,
3120 const IdentifierInfo *EnclosingScope =
nullptr);
3123 void ParseMicrosoftUuidAttributeArgs(ParsedAttributes &Attrs);
3135 void ParseMicrosoftAttributes(ParsedAttributes &Attrs);
3137 void ParseMicrosoftInheritanceClassAttributes(ParsedAttributes &attrs);
3138 void ParseNullabilityClassAttributes(ParsedAttributes &attrs);
3147 SourceLocation ParseDecltypeSpecifier(DeclSpec &DS);
3148 void AnnotateExistingDecltypeSpecifier(
const DeclSpec &DS,
3149 SourceLocation StartLoc,
3150 SourceLocation EndLoc);
3163 return isCXX11VirtSpecifier(Tok);
3173 void ParseOptionalCXX11VirtSpecifierSeq(VirtSpecifiers &VS,
bool IsInterface,
3174 SourceLocation FriendLoc);
3178 bool isCXX11FinalKeyword()
const;
3184 bool isClassCompatibleKeyword()
const;
3186 bool MaybeParseTypeTransformTypeSpecifier(DeclSpec &DS);
3189 void DiagnoseUnexpectedNamespace(NamedDecl *Context);
3221 SourceLocation &DeclEnd,
3222 SourceLocation InlineLoc = SourceLocation());
3224 struct InnerNamespaceInfo {
3225 SourceLocation NamespaceLoc;
3226 SourceLocation InlineLoc;
3227 SourceLocation IdentLoc;
3228 IdentifierInfo *Ident;
3230 using InnerNamespaceInfoList = llvm::SmallVector<InnerNamespaceInfo, 4>;
3233 void ParseInnerNamespace(
const InnerNamespaceInfoList &InnerNSs,
3234 unsigned int index, SourceLocation &InlineLoc,
3235 ParsedAttributes &attrs,
3267 Decl *ParseExportDeclaration();
3273 SourceLocation &DeclEnd, ParsedAttributes &Attrs);
3288 SourceLocation &DeclEnd, ParsedAttributes &attrs);
3290 struct UsingDeclarator {
3291 SourceLocation TypenameLoc;
3294 SourceLocation EllipsisLoc;
3297 TypenameLoc = EllipsisLoc = SourceLocation();
3338 const ParsedTemplateInfo &TemplateInfo,
3339 SourceLocation UsingLoc,
3340 SourceLocation &DeclEnd,
3341 ParsedAttributes &Attrs,
3343 Decl *ParseAliasDeclarationAfterDeclarator(
3344 const ParsedTemplateInfo &TemplateInfo, SourceLocation UsingLoc,
3346 ParsedAttributes &Attrs, Decl **OwnedType =
nullptr);
3359 Decl *ParseStaticAssertDeclaration(SourceLocation &DeclEnd);
3364 Decl *ParseNamespaceAlias(SourceLocation NamespaceLoc,
3365 SourceLocation AliasLoc, IdentifierInfo *Alias,
3366 SourceLocation &DeclEnd);
3374 bool isValidAfterTypeSpecifier(
bool CouldBeBitfield);
3418 void ParseClassSpecifier(
tok::TokenKind TagTokKind, SourceLocation TagLoc,
3419 DeclSpec &DS, ParsedTemplateInfo &TemplateInfo,
3421 DeclSpecContext DSC, ParsedAttributes &Attributes);
3422 void SkipCXXMemberSpecification(SourceLocation StartLoc,
3423 SourceLocation AttrFixitLoc,
unsigned TagType,
3434 void ParseCXXMemberSpecification(SourceLocation StartLoc,
3435 SourceLocation AttrFixitLoc,
3436 ParsedAttributes &Attrs,
unsigned TagType,
3461 ExprResult ParseCXXMemberInitializer(Decl *D,
bool IsFunction,
3462 SourceLocation &EqualLoc);
3466 bool ParseCXXMemberDeclaratorBeforeInitializer(Declarator &DeclaratorInfo,
3469 LateParsedAttrList &LateAttrs);
3474 MaybeParseAndDiagnoseDeclSpecAfterCXX11VirtSpecifierSeq(Declarator &D,
3475 VirtSpecifiers &VS);
3531 ParsedTemplateInfo &TemplateInfo,
3532 ParsingDeclRAIIObject *DiagsFromTParams =
nullptr);
3535 ParsedAttributes &AccessAttrs,
3561 void ParseConstructorInitializer(Decl *ConstructorDecl);
3583 void HandleMemberFunctionDeclDelays(Declarator &DeclaratorInfo,
3611 TypeResult ParseBaseTypeSpecifier(SourceLocation &BaseLoc,
3612 SourceLocation &EndLocation);
3624 void ParseBaseClause(Decl *ClassDecl);
3639 BaseResult ParseBaseSpecifier(Decl *ClassDecl);
3655 bool isClassCompatibleKeyword(Token Tok)
const;
3657 void ParseHLSLRootSignatureAttributeArgs(ParsedAttributes &Attrs);
3832 bool GreaterThanIsOperator;
3836 llvm::SmallDenseMap<IdentifierInfo *, tok::TokenKind> RevertibleTypeTraits;
3855 PushParsingClass(
Decl *TagOrTemplate,
bool TopLevelClass,
bool IsInterface);
3859 void DeallocateParsedClasses(ParsingClass *
Class);
4080 bool isAddressOfOperand,
bool &NotCastExpr,
4082 bool isVectorLiteral =
false,
4083 bool *NotPrimaryExpression =
nullptr);
4085 bool isAddressOfOperand =
false,
4088 bool isVectorLiteral =
false,
4089 bool *NotPrimaryExpression =
nullptr);
4092 bool isNotExpressionStart();
4096 bool isPostfixExpressionSuffixStart() {
4098 return (K == tok::l_square || K == tok::l_paren || K == tok::period ||
4099 K == tok::arrow || K == tok::plusplus || K == tok::minusminus);
4141 ExprResult ParseUnaryExprOrTypeTraitExpression();
4170 ExprResult ParseSYCLUniqueStableNameExpression();
4232 llvm::function_ref<
void()> ExpressionStarts =
4233 llvm::function_ref<
void()>(),
4234 bool FailImmediatelyOnInvalidExpr =
false);
4279 bool StopIfCastExpr,
4316 ExprResult ParseGenericSelectionExpression();
4335 void injectEmbedTokens();
4361 ExprResult ParseAssignmentExprWithObjCMessageExprStart(
4363 Expr *ReceiverExpr);
4368 bool isKnownToBeDeclarationSpecifier() {
4382 bool isTypeIdForGenericSelection() {
4388 return isTypeSpecifierQualifier(Tok);
4394 bool isTypeIdUnambiguously() {
4399 return isTypeSpecifierQualifier(Tok);
4408 void ParseBlockId(SourceLocation CaretLoc);
4417 std::optional<AvailabilitySpec> ParseAvailabilitySpec();
4418 ExprResult ParseAvailabilityCheckExpr(SourceLocation StartLoc);
4424 bool tryParseOpenMPArrayShapingCastPart();
4426 ExprResult ParseBuiltinPtrauthTypeDiscriminator();
4479 bool ObjectHadErrors,
bool EnteringContext,
4480 bool AllowDestructorName,
bool AllowConstructorName,
4481 bool AllowDeductionGuide,
4482 SourceLocation *TemplateKWLoc, UnqualifiedId &
Result);
4500 ExprResult tryParseCXXIdExpression(CXXScopeSpec &SS,
bool isAddressOfOperand);
4551 ExprResult ParseCXXIdExpression(
bool isAddressOfOperand =
false);
4554 bool areTokensAdjacent(
const Token &A,
const Token &B);
4558 void CheckForTemplateAndDigraph(Token &
Next,
ParsedType ObjectTypePtr,
4559 bool EnteringContext, IdentifierInfo &II,
4622 bool ParseOptionalCXXScopeSpecifier(
4623 CXXScopeSpec &SS,
ParsedType ObjectType,
bool ObjectHasErrors,
4624 bool EnteringContext,
bool *MayBePseudoDestructor =
nullptr,
4625 bool IsTypename =
false,
const IdentifierInfo **LastII =
nullptr,
4626 bool OnlyNamespace =
false,
bool InUsingDeclaration =
false,
4627 bool Disambiguation =
false,
bool IsAddressOfOperand =
false,
4628 bool IsInDeclarationContext =
false);
4630 bool ParseOptionalCXXScopeSpecifier(CXXScopeSpec &SS,
ParsedType ObjectType,
4631 bool ObjectHasErrors,
4632 bool EnteringContext,
4633 bool IsAddressOfOperand) {
4634 return ParseOptionalCXXScopeSpecifier(
4635 SS, ObjectType, ObjectHasErrors, EnteringContext,
4642 IsAddressOfOperand);
4649 enum class LambdaIntroducerTentativeParse {
4727 ParseLambdaIntroducer(LambdaIntroducer &Intro,
4728 LambdaIntroducerTentativeParse *Tentative =
nullptr);
4732 ExprResult ParseLambdaExpressionAfterIntroducer(LambdaIntroducer &Intro);
4816 ExprResult ParseCXXPseudoDestructor(Expr *Base, SourceLocation OpLoc,
4871 ExprResult ParseCXXTypeConstructExpression(
const DeclSpec &DS);
4901 void ParseCXXSimpleTypeSpecifier(DeclSpec &DS);
4916 bool ParseCXXTypeSpecifierSeq(
4934 bool ParseExpressionListOrTypeId(SmallVectorImpl<Expr *> &Exprs,
4946 void ParseDirectNewDeclarator(Declarator &D);
4979 ExprResult ParseCXXNewExpression(
bool UseGlobal, SourceLocation Start);
4994 ExprResult ParseCXXDeleteExpression(
bool UseGlobal, SourceLocation Start);
5030 Sema::ConditionResult ParseCXXCondition(
StmtResult *InitStmt,
5034 ForRangeInfo *FRI =
nullptr);
5036 ParsedAttributes &Attrs);
5083 bool isTypeIdInParens(
bool &isAmbiguous) {
5086 isAmbiguous =
false;
5087 return isTypeSpecifierQualifier(Tok);
5089 bool isTypeIdInParens() {
5091 return isTypeIdInParens(isAmbiguous);
5129 bool ParseUnqualifiedIdTemplateId(CXXScopeSpec &SS,
ParsedType ObjectType,
5130 bool ObjectHadErrors,
5131 SourceLocation TemplateKWLoc,
5132 IdentifierInfo *Name,
5133 SourceLocation NameLoc,
5134 bool EnteringContext, UnqualifiedId &Id,
5135 bool AssumeTemplateId);
5177 bool ParseUnqualifiedIdOperator(CXXScopeSpec &SS,
bool EnteringContext,
5244 bool MaybeParseHLSLAnnotations(Declarator &D,
5245 SourceLocation *EndLoc =
nullptr,
5246 bool CouldBeBitField =
false) {
5247 assert(
getLangOpts().
HLSL &&
"MaybeParseHLSLAnnotations is for HLSL only");
5248 if (Tok.is(tok::colon)) {
5249 ParsedAttributes Attrs(AttrFactory);
5250 ParseHLSLAnnotations(Attrs, EndLoc, CouldBeBitField);
5251 D.takeAttributesAppending(Attrs);
5257 void MaybeParseHLSLAnnotations(ParsedAttributes &Attrs,
5258 SourceLocation *EndLoc =
nullptr) {
5259 assert(
getLangOpts().
HLSL &&
"MaybeParseHLSLAnnotations is for HLSL only");
5260 if (Tok.is(tok::colon))
5261 ParseHLSLAnnotations(Attrs, EndLoc);
5264 struct ParsedSemantic {
5265 StringRef Name =
"";
5267 bool Explicit =
false;
5270 ParsedSemantic ParseHLSLSemantic();
5272 void ParseHLSLAnnotations(ParsedAttributes &Attrs,
5273 SourceLocation *EndLoc =
nullptr,
5274 bool CouldBeBitField =
false);
5275 Decl *ParseHLSLBuffer(SourceLocation &DeclEnd, ParsedAttributes &Attrs);
5299 ExprResult ParseInitializer(Decl *DeclForInitializer =
nullptr);
5304 bool MayBeDesignationStart();
5322 struct DesignatorCompletionInfo {
5323 SmallVectorImpl<Expr *> &InitExprs;
5324 QualType PreferredBaseType;
5373 ExprResult ParseInitializerWithPotentialDesignator(DesignatorCompletionInfo);
5378 typedef SmallVector<Expr *, 12> ExprVector;
5382 bool ParseMicrosoftIfExistsBraceInitializer(ExprVector &InitExprs,
5399 friend class ObjCDeclContextSwitch;
5402 return Actions.ObjC().getObjCDeclContext();
5408 return Actions.getNullabilityKeyword(nullability);
5424 bool InMessageExpression;
5431 bool ParsingInObjCContainer;
5436 bool isObjCInstancetype() {
5438 if (
Tok.isAnnotation())
5440 if (!Ident_instancetype)
5442 return Tok.getIdentifierInfo() == Ident_instancetype;
5450 ObjCContainerDecl *DC;
5451 SaveAndRestore<bool> WithinObjCContainer;
5456 WithinObjCContainer(P.ParsingInObjCContainer, DC !=
nullptr) {
5458 P.Actions.ObjC().ActOnObjCTemporaryExitContainerContext(DC);
5460 ~ObjCDeclContextSwitch() {
5462 P.Actions.ObjC().ActOnObjCReenterContainerContext(DC);
5466 void CheckNestedObjCContexts(SourceLocation AtLoc);
5468 void ParseLexedObjCMethodDefs(LexedMethod &LM,
bool parseMethod);
5486 DeclGroupPtrTy ParseObjCAtDirectives(ParsedAttributes &DeclAttrs,
5487 ParsedAttributes &DeclSpecAttrs);
5498 DeclGroupPtrTy ParseObjCAtClassDeclaration(SourceLocation atLoc);
5531 Decl *ParseObjCAtInterfaceDeclaration(SourceLocation AtLoc,
5532 ParsedAttributes &prefixAttrs);
5538 ObjCTypeParamList *parseObjCTypeParamList();
5566 ObjCTypeParamList *parseObjCTypeParamListOrProtocolRefs(
5568 SmallVectorImpl<IdentifierLoc> &protocolIdents, SourceLocation &rAngleLoc,
5569 bool mayBeProtocolList =
true);
5571 void HelperActionsForIvarDeclarations(ObjCContainerDecl *interfaceDecl,
5572 SourceLocation atLoc,
5574 SmallVectorImpl<Decl *> &AllIvarDecls,
5575 bool RBraceMissing);
5600 void ParseObjCClassInstanceVariables(ObjCContainerDecl *interfaceDecl,
5602 SourceLocation atLoc);
5609 bool ParseObjCProtocolReferences(
5610 SmallVectorImpl<Decl *> &P, SmallVectorImpl<SourceLocation> &PLocs,
5611 bool WarnOnDeclarations,
bool ForObjCContainer, SourceLocation &LAngleLoc,
5612 SourceLocation &EndProtoLoc,
bool consumeLastToken);
5623 void parseObjCTypeArgsOrProtocolQualifiers(
5624 ParsedType baseType, SourceLocation &typeArgsLAngleLoc,
5625 SmallVectorImpl<ParsedType> &typeArgs, SourceLocation &typeArgsRAngleLoc,
5626 SourceLocation &protocolLAngleLoc, SmallVectorImpl<Decl *> &protocols,
5627 SmallVectorImpl<SourceLocation> &protocolLocs,
5628 SourceLocation &protocolRAngleLoc,
bool consumeLastToken,
5629 bool warnOnIncompleteProtocols);
5633 void parseObjCTypeArgsAndProtocolQualifiers(
5634 ParsedType baseType, SourceLocation &typeArgsLAngleLoc,
5635 SmallVectorImpl<ParsedType> &typeArgs, SourceLocation &typeArgsRAngleLoc,
5636 SourceLocation &protocolLAngleLoc, SmallVectorImpl<Decl *> &protocols,
5637 SmallVectorImpl<SourceLocation> &protocolLocs,
5638 SourceLocation &protocolRAngleLoc,
bool consumeLastToken);
5642 TypeResult parseObjCProtocolQualifierType(SourceLocation &rAngleLoc);
5646 TypeResult parseObjCTypeArgsAndProtocolQualifiers(SourceLocation loc,
5648 bool consumeLastToken,
5649 SourceLocation &endLoc);
5685 DeclGroupPtrTy ParseObjCAtProtocolDeclaration(SourceLocation atLoc,
5686 ParsedAttributes &prefixAttrs);
5688 struct ObjCImplParsingDataRAII {
5692 typedef SmallVector<LexedMethod *, 8> LateParsedObjCMethodContainer;
5693 LateParsedObjCMethodContainer LateParsedObjCMethods;
5695 ObjCImplParsingDataRAII(
Parser &parser, Decl *D)
5696 : P(parser), Dcl(D), HasCFunction(
false) {
5697 P.CurParsedObjCImpl =
this;
5700 ~ObjCImplParsingDataRAII();
5702 void finish(SourceRange AtEnd);
5703 bool isFinished()
const {
return Finished; }
5708 ObjCImplParsingDataRAII *CurParsedObjCImpl;
5712 void StashAwayMethodOrFunctionBodyTokens(Decl *MDecl);
5726 DeclGroupPtrTy ParseObjCAtImplementationDeclaration(SourceLocation AtLoc,
5727 ParsedAttributes &Attrs);
5735 Decl *ParseObjCAtAliasDeclaration(SourceLocation atLoc);
5750 Decl *ParseObjCPropertySynthesize(SourceLocation atLoc);
5761 Decl *ParseObjCPropertyDynamic(SourceLocation atLoc);
5773 IdentifierInfo *ParseObjCSelectorPiece(SourceLocation &MethodLocation);
5781 bool isTokIdentifier_in()
const;
5790 ParsedAttributes *ParamAttrs);
5804 Decl *ParseObjCMethodPrototype(
5806 bool MethodDefinition =
true);
5838 Decl *ParseObjCMethodDecl(
5841 bool MethodDefinition =
true);
5871 void ParseObjCPropertyAttribute(ObjCDeclSpec &DS);
5877 Decl *ParseObjCMethodDefinition();
5881 ExprResult ParseObjCAtExpression(SourceLocation AtLocation);
5882 ExprResult ParseObjCStringLiteral(SourceLocation AtLoc);
5889 ExprResult ParseObjCCharacterLiteral(SourceLocation AtLoc);
5898 ExprResult ParseObjCNumericLiteral(SourceLocation AtLoc);
5907 ExprResult ParseObjCBooleanLiteral(SourceLocation AtLoc,
bool ArgValue);
5909 ExprResult ParseObjCArrayLiteral(SourceLocation AtLoc);
5910 ExprResult ParseObjCDictionaryLiteral(SourceLocation AtLoc);
5917 ExprResult ParseObjCBoxedExpr(SourceLocation AtLoc);
5923 ExprResult ParseObjCEncodeExpression(SourceLocation AtLoc);
5929 ExprResult ParseObjCSelectorExpression(SourceLocation AtLoc);
5935 ExprResult ParseObjCProtocolExpression(SourceLocation AtLoc);
5942 bool isSimpleObjCMessageExpression();
5997 ExprResult ParseObjCMessageExpressionBody(SourceLocation LBracloc,
5998 SourceLocation SuperLoc,
6000 Expr *ReceiverExpr);
6026 bool ParseObjCXXMessageReceiver(
bool &IsExpr,
void *&TypeOrExpr);
6031 enum class ParsedStmtContext;
6033 StmtResult ParseObjCAtStatement(SourceLocation atLoc,
6034 ParsedStmtContext StmtCtx);
6049 StmtResult ParseObjCTryStmt(SourceLocation atLoc);
6056 StmtResult ParseObjCThrowStmt(SourceLocation atLoc);
6063 StmtResult ParseObjCSynchronizedStmt(SourceLocation atLoc);
6070 StmtResult ParseObjCAutoreleasePoolStmt(SourceLocation atLoc);
6097 bool isStartOfObjCClassMessageMissingOpenBracket();
6129 bool OpenACCDirectiveParsing =
false;
6133 bool AllowOpenACCArraySections =
false;
6137 class OpenACCArraySectionRAII {
6141 OpenACCArraySectionRAII(
Parser &P) : P(P) {
6142 assert(!P.AllowOpenACCArraySections);
6143 P.AllowOpenACCArraySections =
true;
6145 ~OpenACCArraySectionRAII() {
6146 assert(P.AllowOpenACCArraySections);
6147 P.AllowOpenACCArraySections =
false;
6154 struct OpenACCDirectiveParseInfo {
6156 SourceLocation StartLoc;
6157 SourceLocation DirLoc;
6158 SourceLocation LParenLoc;
6159 SourceLocation RParenLoc;
6160 SourceLocation EndLoc;
6161 SourceLocation MiscLoc;
6163 SmallVector<Expr *> Exprs;
6164 SmallVector<OpenACCClause *> Clauses;
6169 struct OpenACCWaitParseInfo {
6170 bool Failed =
false;
6171 Expr *DevNumExpr =
nullptr;
6172 SourceLocation QueuesLoc;
6173 SmallVector<Expr *> QueueIdExprs;
6175 SmallVector<Expr *> getAllExprs() {
6176 SmallVector<Expr *>
Out;
6177 Out.push_back(DevNumExpr);
6178 llvm::append_range(Out, QueueIdExprs);
6182 struct OpenACCCacheParseInfo {
6183 bool Failed =
false;
6184 SourceLocation ReadOnlyLoc;
6185 SmallVector<Expr *> Vars;
6190 enum class OpenACCParseCanContinue { Cannot = 0, Can = 1 };
6196 using OpenACCClauseParseResult =
6197 llvm::PointerIntPair<OpenACCClause *, 1, OpenACCParseCanContinue>;
6199 OpenACCClauseParseResult OpenACCCanContinue();
6200 OpenACCClauseParseResult OpenACCCannotContinue();
6201 OpenACCClauseParseResult OpenACCSuccess(OpenACCClause *Clause);
6205 OpenACCDirectiveParseInfo ParseOpenACCDirective();
6215 OpenACCCacheParseInfo ParseOpenACCCacheVarList();
6221 using OpenACCVarParseResult = std::pair<ExprResult, OpenACCParseCanContinue>;
6247 OpenACCClauseParseResult
6248 ParseOpenACCClauseParams(ArrayRef<const OpenACCClause *> ExistingClauses,
6250 SourceLocation ClauseLoc);
6254 OpenACCClauseParseResult
6255 ParseOpenACCClause(ArrayRef<const OpenACCClause *> ExistingClauses,
6265 SmallVector<OpenACCClause *>
6274 OpenACCWaitParseInfo ParseOpenACCWaitArgument(SourceLocation Loc,
6279 std::variant<std::monostate, StringLiteral *, IdentifierInfo *>
6280 ParseOpenACCBindClauseArgument();
6285 using OpenACCIntExprParseResult =
6286 std::pair<ExprResult, OpenACCParseCanContinue>;
6291 SourceLocation Loc);
6296 llvm::SmallVectorImpl<Expr *> &IntExprs);
6309 bool ParseOpenACCDeviceTypeList(llvm::SmallVector<IdentifierLoc> &Archs);
6323 SourceLocation Loc);
6338 llvm::SmallVectorImpl<Expr *> &SizeExprs);
6350 bool ParseOpenACCGangArgList(SourceLocation GangLoc,
6351 llvm::SmallVectorImpl<OpenACCGangKind> &GKs,
6352 llvm::SmallVectorImpl<Expr *> &IntExprs);
6354 using OpenACCGangArgRes = std::pair<OpenACCGangKind, ExprResult>;
6358 OpenACCGangArgRes ParseOpenACCGangArg(SourceLocation GangLoc);
6362 ParseOpenACCAfterRoutineDecl(
AccessSpecifier &AS, ParsedAttributes &Attrs,
6364 OpenACCDirectiveParseInfo &DirInfo);
6365 StmtResult ParseOpenACCAfterRoutineStmt(OpenACCDirectiveParseInfo &DirInfo);
6383 bool OpenMPDirectiveParsing =
false;
6388 void ReplayOpenMPAttributeTokens(
CachedTokens &OpenMPTokens) {
6391 if (!OpenMPTokens.empty()) {
6392 PP.EnterToken(Tok,
true);
6393 PP.EnterTokenStream(OpenMPTokens,
true,
6405 SourceLocation Loc);
6410 llvm::omp::TraitSet
Set,
6411 llvm::omp::TraitSelector Selector,
6412 llvm::StringMap<SourceLocation> &Seen);
6416 llvm::omp::TraitSet
Set,
6417 llvm::StringMap<SourceLocation> &Seen);
6421 llvm::StringMap<SourceLocation> &Seen);
6425 llvm::omp::TraitSet
Set,
6426 llvm::StringMap<SourceLocation> &Seen);
6434 llvm::omp::TraitSet
Set,
6435 llvm::StringMap<SourceLocation> &SeenSelectors);
6442 void parseOMPContextSelectorSet(
OMPTraitSet &TISet,
6443 llvm::StringMap<SourceLocation> &SeenSets);
6450 bool parseOMPContextSelectors(SourceLocation Loc,
OMPTraitInfo &TI);
6453 bool parseOpenMPAppendArgs(SmallVectorImpl<OMPInteropInfo> &InteropInfos);
6457 bool parseOMPDeclareVariantMatchClause(SourceLocation Loc,
OMPTraitInfo &TI,
6463 SourceLocation Loc);
6482 void ParseOpenMPAssumesDirective(OpenMPDirectiveKind DKind,
6483 SourceLocation Loc);
6486 void ParseOpenMPEndAssumesDirective(SourceLocation Loc);
6503 void ParseOpenMPClauses(OpenMPDirectiveKind DKind,
6504 SmallVectorImpl<clang::OMPClause *> &Clauses,
6505 SourceLocation Loc);
6508 void ParseOMPDeclareTargetClauses(SemaOpenMP::DeclareTargetContextInfo &DTCI);
6511 void ParseOMPEndDeclareTargetDirective(OpenMPDirectiveKind BeginDKind,
6512 OpenMPDirectiveKind EndDKind,
6513 SourceLocation Loc);
6517 void skipUntilPragmaOpenMPEnd(OpenMPDirectiveKind DKind);
6523 void parseOMPEndDirective(OpenMPDirectiveKind BeginKind,
6524 OpenMPDirectiveKind ExpectedKind,
6525 OpenMPDirectiveKind FoundKind,
6526 SourceLocation MatchingLoc, SourceLocation FoundLoc,
6527 bool SkipUntilOpenMPEnd);
6568 AccessSpecifier &AS, ParsedAttributes &Attrs,
bool Delayed =
false,
6570 Decl *TagDecl =
nullptr);
6584 DeclGroupPtrTy ParseOpenMPDeclareReductionDirective(AccessSpecifier AS);
6588 void ParseOpenMPReductionInitializerForDecl(VarDecl *OmpPrivParm);
6600 DeclGroupPtrTy ParseOpenMPDeclareMapperDirective(AccessSpecifier AS);
6603 TypeResult parseOpenMPDeclareMapperVarDecl(SourceRange &Range,
6604 DeclarationName &Name,
6605 AccessSpecifier AS =
AS_none);
6619 bool ParseOpenMPSimpleVarList(
6620 OpenMPDirectiveKind Kind,
6621 const llvm::function_ref<
void(CXXScopeSpec &, DeclarationNameInfo)>
6623 bool AllowScopeSpecifier);
6672 StmtResult ParseOpenMPDeclarativeOrExecutableDirective(
6673 ParsedStmtContext StmtCtx,
bool ReadDirectiveWithinMetadirective =
false);
6683 ParseOpenMPExecutableDirective(ParsedStmtContext StmtCtx,
6684 OpenMPDirectiveKind DKind, SourceLocation Loc,
6685 bool ReadDirectiveWithinMetadirective);
6694 StmtResult ParseOpenMPInformationalDirective(
6695 ParsedStmtContext StmtCtx, OpenMPDirectiveKind DKind, SourceLocation Loc,
6696 bool ReadDirectiveWithinMetadirective);
6725 OMPClause *ParseOpenMPClause(OpenMPDirectiveKind DKind,
6810 bool ParseOpenMPIndirectClause(SemaOpenMP::DeclareTargetContextInfo &DTCI,
6835 OMPClause *ParseOpenMPSingleExprWithArgClause(OpenMPDirectiveKind DKind,
6840 OMPClause *ParseOpenMPLoopRangeClause();
6849 OMPClause *ParseOpenMPPermutationClause();
6953 OMPClause *ParseOpenMPVarListClause(OpenMPDirectiveKind DKind,
6967 SourceLocation &ClauseNameLoc,
6968 SourceLocation &OpenLoc,
6969 SourceLocation &CloseLoc,
6970 SmallVectorImpl<Expr *> &Exprs,
6971 bool ReqIntConst =
false);
6986 OMPClause *ParseOpenMPUsesAllocatorClause(OpenMPDirectiveKind DKind);
6989 bool ParseOMPInteropInfo(OMPInteropInfo &InteropInfo,
OpenMPClauseKind Kind);
6995 bool ParseOMPInteropAttrSelector(SmallVectorImpl<Expr *> &Attrs);
7033 OMPClause *ParseOpenMPOMPXAttributesClause(
bool ParseOnly);
7040 bool IsAddressOfOperand =
false);
7044 SemaOpenMP::OpenMPVarListDataTy &
Data,
7045 const LangOptions &LangOpts);
7048 SmallVectorImpl<Expr *> &Vars,
7049 SemaOpenMP::OpenMPVarListDataTy &
Data);
7084 std::unique_ptr<PragmaHandler> AlignHandler;
7085 std::unique_ptr<PragmaHandler> GCCVisibilityHandler;
7086 std::unique_ptr<PragmaHandler> OptionsHandler;
7087 std::unique_ptr<PragmaHandler> PackHandler;
7088 std::unique_ptr<PragmaHandler> MSStructHandler;
7089 std::unique_ptr<PragmaHandler> UnusedHandler;
7090 std::unique_ptr<PragmaHandler> WeakHandler;
7091 std::unique_ptr<PragmaHandler> RedefineExtnameHandler;
7092 std::unique_ptr<PragmaHandler> FPContractHandler;
7093 std::unique_ptr<PragmaHandler> OpenCLExtensionHandler;
7094 std::unique_ptr<PragmaHandler> OpenMPHandler;
7095 std::unique_ptr<PragmaHandler> OpenACCHandler;
7096 std::unique_ptr<PragmaHandler> PCSectionHandler;
7097 std::unique_ptr<PragmaHandler> MSCommentHandler;
7098 std::unique_ptr<PragmaHandler> MSDetectMismatchHandler;
7099 std::unique_ptr<PragmaHandler> FPEvalMethodHandler;
7100 std::unique_ptr<PragmaHandler> FloatControlHandler;
7101 std::unique_ptr<PragmaHandler> MSPointersToMembers;
7102 std::unique_ptr<PragmaHandler> MSVtorDisp;
7103 std::unique_ptr<PragmaHandler> MSInitSeg;
7104 std::unique_ptr<PragmaHandler> MSDataSeg;
7105 std::unique_ptr<PragmaHandler> MSBSSSeg;
7106 std::unique_ptr<PragmaHandler> MSConstSeg;
7107 std::unique_ptr<PragmaHandler> MSCodeSeg;
7108 std::unique_ptr<PragmaHandler> MSSection;
7109 std::unique_ptr<PragmaHandler> MSStrictGuardStackCheck;
7110 std::unique_ptr<PragmaHandler> MSRuntimeChecks;
7111 std::unique_ptr<PragmaHandler> MSIntrinsic;
7112 std::unique_ptr<PragmaHandler> MSFunction;
7113 std::unique_ptr<PragmaHandler> MSOptimize;
7114 std::unique_ptr<PragmaHandler> MSFenvAccess;
7115 std::unique_ptr<PragmaHandler> MSAllocText;
7116 std::unique_ptr<PragmaHandler> CUDAForceHostDeviceHandler;
7117 std::unique_ptr<PragmaHandler> OptimizeHandler;
7118 std::unique_ptr<PragmaHandler> LoopHintHandler;
7119 std::unique_ptr<PragmaHandler> UnrollHintHandler;
7120 std::unique_ptr<PragmaHandler> NoUnrollHintHandler;
7121 std::unique_ptr<PragmaHandler> UnrollAndJamHintHandler;
7122 std::unique_ptr<PragmaHandler> NoUnrollAndJamHintHandler;
7123 std::unique_ptr<PragmaHandler> FPHandler;
7124 std::unique_ptr<PragmaHandler> STDCFenvAccessHandler;
7125 std::unique_ptr<PragmaHandler> STDCFenvRoundHandler;
7126 std::unique_ptr<PragmaHandler> STDCCXLIMITHandler;
7127 std::unique_ptr<PragmaHandler> STDCUnknownHandler;
7128 std::unique_ptr<PragmaHandler> AttributePragmaHandler;
7129 std::unique_ptr<PragmaHandler> MaxTokensHerePragmaHandler;
7130 std::unique_ptr<PragmaHandler> MaxTokensTotalPragmaHandler;
7131 std::unique_ptr<PragmaHandler> ExportHandler;
7132 std::unique_ptr<PragmaHandler> RISCVPragmaHandler;
7135 void initializePragmaHandlers();
7138 void resetPragmaHandlers();
7145 void HandlePragmaUnused();
7149 void HandlePragmaVisibility();
7153 void HandlePragmaPack();
7157 void HandlePragmaMSStruct();
7159 void HandlePragmaMSPointersToMembers();
7161 void HandlePragmaMSVtorDisp();
7163 void HandlePragmaMSPragma();
7164 bool HandlePragmaMSSection(StringRef PragmaName,
7165 SourceLocation PragmaLocation);
7166 bool HandlePragmaMSSegment(StringRef PragmaName,
7167 SourceLocation PragmaLocation);
7170 bool HandlePragmaMSInitSeg(StringRef PragmaName,
7171 SourceLocation PragmaLocation);
7176 bool HandlePragmaMSStrictGuardStackCheck(StringRef PragmaName,
7177 SourceLocation PragmaLocation);
7178 bool HandlePragmaMSFunction(StringRef PragmaName,
7179 SourceLocation PragmaLocation);
7180 bool HandlePragmaMSAllocText(StringRef PragmaName,
7181 SourceLocation PragmaLocation);
7184 bool HandlePragmaMSOptimize(StringRef PragmaName,
7185 SourceLocation PragmaLocation);
7188 bool HandlePragmaMSIntrinsic(StringRef PragmaName,
7189 SourceLocation PragmaLocation);
7193 void HandlePragmaAlign();
7197 void HandlePragmaDump();
7201 void HandlePragmaWeak();
7205 void HandlePragmaWeakAlias();
7209 void HandlePragmaRedefineExtname();
7213 void HandlePragmaFPContract();
7217 void HandlePragmaFEnvAccess();
7221 void HandlePragmaFEnvRound();
7225 void HandlePragmaCXLimitedRange();
7229 void HandlePragmaFloatControl();
7233 void HandlePragmaFP();
7237 void HandlePragmaOpenCLExtension();
7241 StmtResult HandlePragmaCaptured();
7245 bool HandlePragmaLoopHint(LoopHint &Hint);
7247 bool ParsePragmaAttributeSubjectMatchRuleSet(
7249 SourceLocation &AnyLoc, SourceLocation &LastMatchRuleEndLoc);
7251 void HandlePragmaAttribute();
7257 void HandlePragmaExport();
7283 enum class ParsedStmtContext {
7286 AllowDeclarationsInC = 0x1,
7288 AllowStandaloneOpenMPDirectives = 0x2,
7295 Compound = AllowDeclarationsInC | AllowStandaloneOpenMPDirectives,
7312 ParsedStmtContext StmtCtx = ParsedStmtContext::SubStmt,
7367 ParseStatementOrDeclaration(
StmtVector &Stmts, ParsedStmtContext StmtCtx,
7371 StmtResult ParseStatementOrDeclarationAfterAttributes(
7372 StmtVector &Stmts, ParsedStmtContext StmtCtx,
7377 StmtResult ParseExprStatement(ParsedStmtContext StmtCtx);
7391 ParsedStmtContext StmtCtx);
7400 StmtResult ParseCaseStatement(ParsedStmtContext StmtCtx,
7401 bool MissingCase =
false,
7411 StmtResult ParseDefaultStatement(ParsedStmtContext StmtCtx);
7413 StmtResult ParseCompoundStatement(
bool isStmtExpr =
false);
7439 StmtResult ParseCompoundStatement(
bool isStmtExpr,
unsigned ScopeFlags);
7444 void ParseCompoundStatementLeadingPragmas();
7446 void DiagnoseLabelAtEndOfCompoundStatement();
7456 StmtResult ParseCompoundStatementBody(
bool isStmtExpr =
false);
7474 bool ParseParenExprOrCondition(
StmtResult *InitStmt,
7590 StmtResult ParseBreakOrContinueStatement(
bool IsContinue);
7607 void ParseMicrosoftIfExistsStatement(
StmtVector &Stmts);
7654 StmtResult ParseCXXCatchBlock(
bool FnCatch =
false);
7692 Decl *ParseFunctionStatementBody(
Decl *
Decl, ParseScope &BodyScope);
7701 Decl *ParseFunctionTryBlock(
Decl *
Decl, ParseScope &BodyScope);
7707 bool trySkippingFunctionBody();
7715 bool isDeclarationStatement(
bool DisambiguatingWithExpression =
false) {
7717 return isCXXDeclarationStatement(DisambiguatingWithExpression);
7725 bool isForInitDeclaration() {
7729 return Tok.is(tok::kw_using) ||
7730 isCXXSimpleDeclaration(
true);
7735 bool isForRangeIdentifier();
7752 unsigned &NumLineToksConsumed,
7753 bool IsUnevaluated);
7796 StmtResult ParseMicrosoftAsmStatement(SourceLocation AsmLoc);
7812 bool ParseAsmOperandsOpt(SmallVectorImpl<IdentifierInfo *> &Names,
7813 SmallVectorImpl<Expr *> &Constraints,
7814 SmallVectorImpl<Expr *> &Exprs);
7816 class GNUAsmQualifiers {
7817 unsigned Qualifiers = AQ_unspecified;
7826 static const char *getQualifierName(AQ Qualifier);
7827 bool setAsmQualifier(AQ Qualifier);
7828 inline bool isVolatile()
const {
return Qualifiers & AQ_volatile; };
7829 inline bool isInline()
const {
return Qualifiers & AQ_inline; };
7830 inline bool isGoto()
const {
return Qualifiers & AQ_goto; }
7834 bool isGCCAsmStatement(
const Token &TokAfterAsm)
const;
7836 bool isGNUAsmQualifier(
const Token &TokAfterAsm)
const;
7837 GNUAsmQualifiers::AQ getGNUAsmQualifier(
const Token &Tok)
const;
7850 bool parseGNUAsmQualifierListOpt(GNUAsmQualifiers &AQ);
7874 unsigned TemplateParameterDepth;
7877 class TemplateParameterDepthRAII {
7879 unsigned AddedLevels;
7882 explicit TemplateParameterDepthRAII(
unsigned &Depth)
7883 : Depth(Depth), AddedLevels(0) {}
7885 ~TemplateParameterDepthRAII() { Depth -= AddedLevels; }
7891 void addDepth(
unsigned D) {
7895 void setAddedDepth(
unsigned D) {
7896 Depth = Depth - AddedLevels + D;
7900 unsigned getDepth()
const {
return Depth; }
7901 unsigned getOriginalDepth()
const {
return Depth - AddedLevels; }
7906 SmallVector<TemplateIdAnnotation *, 16> TemplateIds;
7912 bool DelayTemplateIdDestruction =
false;
7914 void MaybeDestroyTemplateIds() {
7915 if (DelayTemplateIdDestruction)
7917 if (!TemplateIds.empty() &&
7918 (Tok.is(tok::eof) || !PP.mightHavePendingAnnotationTokens()))
7919 DestroyTemplateIds();
7921 void DestroyTemplateIds();
7925 struct DestroyTemplateIdAnnotationsRAIIObj {
7928 DestroyTemplateIdAnnotationsRAIIObj(
Parser &Self) : Self(Self) {}
7929 ~DestroyTemplateIdAnnotationsRAIIObj() { Self.MaybeDestroyTemplateIds(); }
7932 struct DelayTemplateIdDestructionRAII {
7934 bool PrevDelayTemplateIdDestruction;
7936 DelayTemplateIdDestructionRAII(
Parser &Self,
7937 bool DelayTemplateIdDestruction) noexcept
7939 PrevDelayTemplateIdDestruction(Self.DelayTemplateIdDestruction) {
7940 Self.DelayTemplateIdDestruction = DelayTemplateIdDestruction;
7943 ~DelayTemplateIdDestructionRAII() noexcept {
7944 Self.DelayTemplateIdDestruction = PrevDelayTemplateIdDestruction;
7949 SmallVector<const IdentifierInfo *, 8> TentativelyDeclaredIdentifiers;
7961 struct AngleBracketTracker {
7964 enum Priority :
unsigned short {
7966 PotentialTypo = 0x0,
7968 DependentName = 0x2,
7971 SpaceBeforeLess = 0x0,
7973 NoSpaceBeforeLess = 0x1,
8004 if (!Locs.empty() && Locs.back().isActive(P)) {
8005 if (Locs.back().Priority <= Prio) {
8007 Locs.back().LessLoc = LessLoc;
8008 Locs.back().Priority = Prio;
8011 Locs.push_back({
TemplateName, LessLoc, Prio, P.ParenCount,
8012 P.BracketCount, P.BraceCount});
8020 while (!Locs.empty() && Locs.back().isActiveOrNested(P))
8027 if (!Locs.empty() && Locs.back().isActive(P))
8028 return &Locs.back();
8033 AngleBracketTracker AngleBrackets;
8038 struct ParsedTemplateInfo {
8039 ParsedTemplateInfo()
8043 bool isSpecialization,
8044 bool lastParameterListWasEmpty =
false)
8047 TemplateParams(TemplateParams),
8048 LastParameterListWasEmpty(lastParameterListWasEmpty) {}
8050 explicit ParsedTemplateInfo(SourceLocation ExternLoc,
8051 SourceLocation TemplateLoc)
8053 TemplateParams(
nullptr), ExternLoc(ExternLoc),
8054 TemplateLoc(TemplateLoc), LastParameterListWasEmpty(
false) {}
8064 SourceLocation ExternLoc;
8068 SourceLocation TemplateLoc;
8071 bool LastParameterListWasEmpty;
8073 SourceRange getSourceRange() const LLVM_READONLY;
8077 void LexTemplateFunctionForLateParsing(
CachedTokens &Toks);
8080 void ParseLateTemplatedFuncDef(LateParsedTemplate &LPT);
8082 static
void LateTemplateParserCallback(
void *P, LateParsedTemplate &LPT);
8090 void checkPotentialAngleBracket(
ExprResult &PotentialTemplateName);
8091 bool checkPotentialAngleBracketDelimiter(const AngleBracketTracker::Loc &,
8092 const Token &OpToken);
8093 bool checkPotentialAngleBracketDelimiter(const Token &OpToken) {
8094 if (
auto *Info = AngleBrackets.getCurrent(*
this))
8095 return checkPotentialAngleBracketDelimiter(*Info, OpToken);
8106 SourceLocation &DeclEnd,
8107 ParsedAttributes &AccessAttrs);
8154 ParsingDeclRAIIObject &DiagsFromParams, SourceLocation &DeclEnd,
8166 bool ParseTemplateParameters(MultiParseScope &TemplateScopes,
unsigned Depth,
8167 SmallVectorImpl<NamedDecl *> &TemplateParams,
8168 SourceLocation &LAngleLoc,
8169 SourceLocation &RAngleLoc);
8181 bool ParseTemplateParameterList(
unsigned Depth,
8182 SmallVectorImpl<NamedDecl *> &TemplateParams);
8184 enum class TPResult;
8188 TPResult isStartOfTemplateTypeParameter();
8212 NamedDecl *ParseTemplateParameter(
unsigned Depth,
unsigned Position);
8225 NamedDecl *ParseTypeParameter(
unsigned Depth,
unsigned Position);
8241 NamedDecl *ParseTemplateTemplateParameter(
unsigned Depth,
unsigned Position);
8251 NamedDecl *ParseNonTypeTemplateParameter(
unsigned Depth,
unsigned Position);
8255 bool isTypeConstraintAnnotation();
8267 bool TryAnnotateTypeConstraint();
8269 void DiagnoseMisplacedEllipsis(SourceLocation EllipsisLoc,
8270 SourceLocation CorrectLoc,
8271 bool AlreadyHasEllipsis,
8272 bool IdentifierHasName);
8273 void DiagnoseMisplacedEllipsisInDeclarator(SourceLocation EllipsisLoc,
8276 typedef SmallVector<ParsedTemplateArgument, 16> TemplateArgList;
8293 bool ParseGreaterThanInTemplateList(SourceLocation LAngleLoc,
8294 SourceLocation &RAngleLoc,
8295 bool ConsumeLastToken,
8296 bool ObjCGenericList);
8309 bool ParseTemplateIdAfterTemplateName(
bool ConsumeLastToken,
8310 SourceLocation &LAngleLoc,
8311 TemplateArgList &TemplateArgs,
8312 SourceLocation &RAngleLoc,
8357 CXXScopeSpec &SS, SourceLocation TemplateKWLoc,
8359 bool AllowTypeAnnotation =
true,
8360 bool TypeConstraint =
false);
8378 AnnotateTemplateIdTokenAsType(CXXScopeSpec &SS,
8380 bool IsClassName =
false);
8392 bool ParseTemplateArgumentList(TemplateArgList &TemplateArgs,
8396 ParsedTemplateArgument ParseTemplateTemplateArgument();
8408 ParsedTemplateArgument ParseTemplateArgument();
8420 SourceLocation ExternLoc,
8421 SourceLocation TemplateLoc,
8422 SourceLocation &DeclEnd,
8423 ParsedAttributes &AccessAttrs,
8432 Decl *ParseConceptDefinition(
const ParsedTemplateInfo &TemplateInfo,
8433 SourceLocation &DeclEnd);
8461 class TentativeParsingAction {
8463 PreferredTypeBuilder PrevPreferredType;
8465 size_t PrevTentativelyDeclaredIdentifierCount;
8466 unsigned short PrevParenCount, PrevBracketCount, PrevBraceCount;
8470 explicit TentativeParsingAction(Parser &p,
bool Unannotated =
false)
8471 : P(p), PrevPreferredType(P.PreferredType) {
8473 PrevTentativelyDeclaredIdentifierCount =
8474 P.TentativelyDeclaredIdentifiers.size();
8475 PrevParenCount = P.ParenCount;
8476 PrevBracketCount = P.BracketCount;
8477 PrevBraceCount = P.BraceCount;
8478 P.PP.EnableBacktrackAtThisPos(Unannotated);
8482 assert(isActive &&
"Parsing action was finished!");
8483 P.TentativelyDeclaredIdentifiers.resize(
8484 PrevTentativelyDeclaredIdentifierCount);
8485 P.PP.CommitBacktrackedTokens();
8489 assert(isActive &&
"Parsing action was finished!");
8491 P.PreferredType = PrevPreferredType;
8493 P.TentativelyDeclaredIdentifiers.resize(
8494 PrevTentativelyDeclaredIdentifierCount);
8495 P.ParenCount = PrevParenCount;
8496 P.BracketCount = PrevBracketCount;
8497 P.BraceCount = PrevBraceCount;
8500 ~TentativeParsingAction() {
8501 assert(!isActive &&
"Forgot to call Commit or Revert!");
8507 class RevertingTentativeParsingAction
8508 :
private Parser::TentativeParsingAction {
8510 using TentativeParsingAction::TentativeParsingAction;
8512 ~RevertingTentativeParsingAction() { Revert(); }
8547 bool isCXXDeclarationStatement(
bool DisambiguatingWithExpression =
false);
8573 bool isCXXSimpleDeclaration(
bool AllowForRangeDecl);
8586 bool isCXXFunctionDeclarator(
bool *IsAmbiguous =
nullptr,
8590 struct ConditionDeclarationOrInitStatementState;
8591 enum class ConditionOrInitStatement {
8618 ConditionOrInitStatement
8619 isCXXConditionDeclarationOrInitStatement(
bool CanBeInitStmt,
8620 bool CanBeForRangeDecl);
8646 return isCXXTypeId(Context, isAmbiguous);
8660 bool isEnumBase(
bool AllowSemi);
8780 TPResult BracedCastResult = TPResult::False,
8781 bool *InvalidAsDeclSpec =
nullptr);
8786 bool isCXXDeclarationSpecifierAType();
8792 TPResult isTemplateArgumentList(
unsigned TokensToSkip);
8797 TPResult isExplicitBool();
8802 bool isTentativelyDeclared(IdentifierInfo *II);
8821 TPResult TryParseSimpleDeclaration(
bool AllowForRangeDecl);
8829 TPResult TryParseTypeofSpecifier();
8833 TPResult TryParseProtocolQualifiers();
8835 TPResult TryParsePtrOperatorSeq();
8857 TPResult TryParseOperatorId();
8888 TPResult TryParseInitDeclaratorList(
bool MayHaveTrailingReturnType =
false);
8945 TPResult TryParseDeclarator(
bool mayBeAbstract,
bool mayHaveIdentifier =
true,
8946 bool mayHaveDirectInit =
false,
8947 bool mayHaveTrailingReturnType =
false);
8968 TPResult TryParseParameterDeclarationClause(
8969 bool *InvalidAsDeclaration =
nullptr,
bool VersusTemplateArg =
false,
8986 TPResult TryParseFunctionDeclarator(
bool MayHaveTrailingReturnType =
false);
8992 bool NameAfterArrowIsNonType();
8998 TPResult TryParseBracketDeclarator();
9002 TPResult TryConsumeDeclarationSpecifier();
9006 bool TrySkipAttributes();
9048 isCXX11AttributeSpecifier(
bool Disambiguate =
false,
9049 bool OuterMightBeMessageSend =
false);