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);
3012 bool isAllowedCXX11AttributeSpecifier(
bool Disambiguate =
false,
3013 bool OuterMightBeMessageSend =
false) {
3014 return (Tok.isRegularKeywordAttribute() ||
3015 isCXX11AttributeSpecifier(Disambiguate, OuterMightBeMessageSend) !=
3022 SourceLocation SkipCXX11Attributes();
3026 void DiagnoseAndSkipCXX11Attributes();
3028 void ParseOpenMPAttributeArgs(
const IdentifierInfo *AttrName,
3057 void ParseCXX11AttributeSpecifierInternal(ParsedAttributes &Attrs,
3059 SourceLocation *EndLoc =
nullptr);
3060 void ParseCXX11AttributeSpecifier(ParsedAttributes &Attrs,
3061 SourceLocation *EndLoc =
nullptr) {
3063 ParseCXX11AttributeSpecifierInternal(Attrs, OpenMPTokens, EndLoc);
3064 ReplayOpenMPAttributeTokens(OpenMPTokens);
3073 void ParseCXX11Attributes(ParsedAttributes &attrs);
3093 bool ParseCXX11AttributeArgs(IdentifierInfo *AttrName,
3094 SourceLocation AttrNameLoc,
3095 ParsedAttributes &Attrs, SourceLocation *EndLoc,
3096 IdentifierInfo *ScopeName,
3097 SourceLocation ScopeLoc,
3103 ParseCXXAssumeAttributeArg(ParsedAttributes &Attrs, IdentifierInfo *AttrName,
3104 SourceLocation AttrNameLoc,
3105 IdentifierInfo *ScopeName, SourceLocation ScopeLoc,
3106 SourceLocation *EndLoc, ParsedAttr::Form Form);
3117 IdentifierInfo *TryParseCXX11AttributeIdentifier(
3118 SourceLocation &Loc,
3121 const IdentifierInfo *EnclosingScope =
nullptr);
3124 void ParseMicrosoftUuidAttributeArgs(ParsedAttributes &Attrs);
3136 void ParseMicrosoftAttributes(ParsedAttributes &Attrs);
3138 void ParseMicrosoftInheritanceClassAttributes(ParsedAttributes &attrs);
3139 void ParseNullabilityClassAttributes(ParsedAttributes &attrs);
3148 SourceLocation ParseDecltypeSpecifier(DeclSpec &DS);
3149 void AnnotateExistingDecltypeSpecifier(
const DeclSpec &DS,
3150 SourceLocation StartLoc,
3151 SourceLocation EndLoc);
3164 return isCXX11VirtSpecifier(Tok);
3174 void ParseOptionalCXX11VirtSpecifierSeq(VirtSpecifiers &VS,
bool IsInterface,
3175 SourceLocation FriendLoc);
3179 bool isCXX11FinalKeyword()
const;
3185 bool isClassCompatibleKeyword()
const;
3187 bool MaybeParseTypeTransformTypeSpecifier(DeclSpec &DS);
3190 void DiagnoseUnexpectedNamespace(NamedDecl *Context);
3222 SourceLocation &DeclEnd,
3223 SourceLocation InlineLoc = SourceLocation());
3225 struct InnerNamespaceInfo {
3226 SourceLocation NamespaceLoc;
3227 SourceLocation InlineLoc;
3228 SourceLocation IdentLoc;
3229 IdentifierInfo *Ident;
3231 using InnerNamespaceInfoList = llvm::SmallVector<InnerNamespaceInfo, 4>;
3234 void ParseInnerNamespace(
const InnerNamespaceInfoList &InnerNSs,
3235 unsigned int index, SourceLocation &InlineLoc,
3236 ParsedAttributes &attrs,
3268 Decl *ParseExportDeclaration();
3274 SourceLocation &DeclEnd, ParsedAttributes &Attrs);
3289 SourceLocation &DeclEnd, ParsedAttributes &attrs);
3291 struct UsingDeclarator {
3292 SourceLocation TypenameLoc;
3295 SourceLocation EllipsisLoc;
3298 TypenameLoc = EllipsisLoc = SourceLocation();
3339 const ParsedTemplateInfo &TemplateInfo,
3340 SourceLocation UsingLoc,
3341 SourceLocation &DeclEnd,
3342 ParsedAttributes &Attrs,
3344 Decl *ParseAliasDeclarationAfterDeclarator(
3345 const ParsedTemplateInfo &TemplateInfo, SourceLocation UsingLoc,
3347 ParsedAttributes &Attrs, Decl **OwnedType =
nullptr);
3360 Decl *ParseStaticAssertDeclaration(SourceLocation &DeclEnd);
3365 Decl *ParseNamespaceAlias(SourceLocation NamespaceLoc,
3366 SourceLocation AliasLoc, IdentifierInfo *Alias,
3367 SourceLocation &DeclEnd);
3375 bool isValidAfterTypeSpecifier(
bool CouldBeBitfield);
3419 void ParseClassSpecifier(
tok::TokenKind TagTokKind, SourceLocation TagLoc,
3420 DeclSpec &DS, ParsedTemplateInfo &TemplateInfo,
3422 DeclSpecContext DSC, ParsedAttributes &Attributes);
3423 void SkipCXXMemberSpecification(SourceLocation StartLoc,
3424 SourceLocation AttrFixitLoc,
unsigned TagType,
3435 void ParseCXXMemberSpecification(SourceLocation StartLoc,
3436 SourceLocation AttrFixitLoc,
3437 ParsedAttributes &Attrs,
unsigned TagType,
3462 ExprResult ParseCXXMemberInitializer(Decl *D,
bool IsFunction,
3463 SourceLocation &EqualLoc);
3467 bool ParseCXXMemberDeclaratorBeforeInitializer(Declarator &DeclaratorInfo,
3470 LateParsedAttrList &LateAttrs);
3475 MaybeParseAndDiagnoseDeclSpecAfterCXX11VirtSpecifierSeq(Declarator &D,
3476 VirtSpecifiers &VS);
3532 ParsedTemplateInfo &TemplateInfo,
3533 ParsingDeclRAIIObject *DiagsFromTParams =
nullptr);
3536 ParsedAttributes &AccessAttrs,
3562 void ParseConstructorInitializer(Decl *ConstructorDecl);
3584 void HandleMemberFunctionDeclDelays(Declarator &DeclaratorInfo,
3612 TypeResult ParseBaseTypeSpecifier(SourceLocation &BaseLoc,
3613 SourceLocation &EndLocation);
3625 void ParseBaseClause(Decl *ClassDecl);
3640 BaseResult ParseBaseSpecifier(Decl *ClassDecl);
3656 bool isClassCompatibleKeyword(Token Tok)
const;
3658 void ParseHLSLRootSignatureAttributeArgs(ParsedAttributes &Attrs);
3833 bool GreaterThanIsOperator;
3837 llvm::SmallDenseMap<IdentifierInfo *, tok::TokenKind> RevertibleTypeTraits;
3856 PushParsingClass(
Decl *TagOrTemplate,
bool TopLevelClass,
bool IsInterface);
3860 void DeallocateParsedClasses(ParsingClass *
Class);
4081 bool isAddressOfOperand,
bool &NotCastExpr,
4083 bool isVectorLiteral =
false,
4084 bool *NotPrimaryExpression =
nullptr);
4086 bool isAddressOfOperand =
false,
4089 bool isVectorLiteral =
false,
4090 bool *NotPrimaryExpression =
nullptr);
4093 bool isNotExpressionStart();
4097 bool isPostfixExpressionSuffixStart() {
4099 return (K == tok::l_square || K == tok::l_paren || K == tok::period ||
4100 K == tok::arrow || K == tok::plusplus || K == tok::minusminus);
4142 ExprResult ParseUnaryExprOrTypeTraitExpression();
4171 ExprResult ParseSYCLUniqueStableNameExpression();
4233 llvm::function_ref<
void()> ExpressionStarts =
4234 llvm::function_ref<
void()>(),
4235 bool FailImmediatelyOnInvalidExpr =
false,
4236 bool ParsingExpansionStmtInitList =
false);
4281 bool StopIfCastExpr,
4318 ExprResult ParseGenericSelectionExpression();
4337 void injectEmbedTokens();
4363 ExprResult ParseAssignmentExprWithObjCMessageExprStart(
4365 Expr *ReceiverExpr);
4370 bool isKnownToBeDeclarationSpecifier() {
4384 bool isTypeIdForGenericSelection() {
4390 return isTypeSpecifierQualifier(Tok);
4396 bool isTypeIdUnambiguously() {
4401 return isTypeSpecifierQualifier(Tok);
4410 void ParseBlockId(SourceLocation CaretLoc);
4419 std::optional<AvailabilitySpec> ParseAvailabilitySpec();
4420 ExprResult ParseAvailabilityCheckExpr(SourceLocation StartLoc);
4426 bool tryParseOpenMPArrayShapingCastPart();
4428 ExprResult ParseBuiltinPtrauthTypeDiscriminator();
4481 bool ObjectHadErrors,
bool EnteringContext,
4482 bool AllowDestructorName,
bool AllowConstructorName,
4483 bool AllowDeductionGuide,
4484 SourceLocation *TemplateKWLoc, UnqualifiedId &
Result);
4502 ExprResult tryParseCXXIdExpression(CXXScopeSpec &SS,
bool isAddressOfOperand);
4553 ExprResult ParseCXXIdExpression(
bool isAddressOfOperand =
false);
4556 bool areTokensAdjacent(
const Token &A,
const Token &B);
4560 void CheckForTemplateAndDigraph(Token &
Next,
ParsedType ObjectTypePtr,
4561 bool EnteringContext, IdentifierInfo &II,
4624 bool ParseOptionalCXXScopeSpecifier(
4625 CXXScopeSpec &SS,
ParsedType ObjectType,
bool ObjectHasErrors,
4626 bool EnteringContext,
bool *MayBePseudoDestructor =
nullptr,
4627 bool IsTypename =
false,
const IdentifierInfo **LastII =
nullptr,
4628 bool OnlyNamespace =
false,
bool InUsingDeclaration =
false,
4629 bool Disambiguation =
false,
bool IsAddressOfOperand =
false,
4630 bool IsInDeclarationContext =
false);
4632 bool ParseOptionalCXXScopeSpecifier(CXXScopeSpec &SS,
ParsedType ObjectType,
4633 bool ObjectHasErrors,
4634 bool EnteringContext,
4635 bool IsAddressOfOperand) {
4636 return ParseOptionalCXXScopeSpecifier(
4637 SS, ObjectType, ObjectHasErrors, EnteringContext,
4644 IsAddressOfOperand);
4651 enum class LambdaIntroducerTentativeParse {
4729 ParseLambdaIntroducer(LambdaIntroducer &Intro,
4730 LambdaIntroducerTentativeParse *Tentative =
nullptr);
4734 ExprResult ParseLambdaExpressionAfterIntroducer(LambdaIntroducer &Intro);
4818 ExprResult ParseCXXPseudoDestructor(Expr *Base, SourceLocation OpLoc,
4873 ExprResult ParseCXXTypeConstructExpression(
const DeclSpec &DS);
4903 void ParseCXXSimpleTypeSpecifier(DeclSpec &DS);
4918 bool ParseCXXTypeSpecifierSeq(
4936 bool ParseExpressionListOrTypeId(SmallVectorImpl<Expr *> &Exprs,
4948 void ParseDirectNewDeclarator(Declarator &D);
4981 ExprResult ParseCXXNewExpression(
bool UseGlobal, SourceLocation Start);
4996 ExprResult ParseCXXDeleteExpression(
bool UseGlobal, SourceLocation Start);
5032 Sema::ConditionResult ParseCondition(
StmtResult *InitStmt, SourceLocation Loc,
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();
5332 struct DesignatorCompletionInfo {
5333 SmallVectorImpl<Expr *> &InitExprs;
5334 QualType PreferredBaseType;
5383 ExprResult ParseInitializerWithPotentialDesignator(DesignatorCompletionInfo);
5388 typedef SmallVector<Expr *, 12> ExprVector;
5392 bool ParseMicrosoftIfExistsBraceInitializer(ExprVector &InitExprs,
5409 friend class ObjCDeclContextSwitch;
5412 return Actions.ObjC().getObjCDeclContext();
5418 return Actions.getNullabilityKeyword(nullability);
5434 bool InMessageExpression;
5441 bool ParsingInObjCContainer;
5446 bool isObjCInstancetype() {
5448 if (
Tok.isAnnotation())
5450 if (!Ident_instancetype)
5452 return Tok.getIdentifierInfo() == Ident_instancetype;
5460 ObjCContainerDecl *DC;
5461 SaveAndRestore<bool> WithinObjCContainer;
5466 WithinObjCContainer(P.ParsingInObjCContainer, DC !=
nullptr) {
5468 P.Actions.ObjC().ActOnObjCTemporaryExitContainerContext(DC);
5470 ~ObjCDeclContextSwitch() {
5472 P.Actions.ObjC().ActOnObjCReenterContainerContext(DC);
5476 void CheckNestedObjCContexts(SourceLocation AtLoc);
5478 void ParseLexedObjCMethodDefs(LexedMethod &LM,
bool parseMethod);
5496 DeclGroupPtrTy ParseObjCAtDirectives(ParsedAttributes &DeclAttrs,
5497 ParsedAttributes &DeclSpecAttrs);
5508 DeclGroupPtrTy ParseObjCAtClassDeclaration(SourceLocation atLoc);
5541 Decl *ParseObjCAtInterfaceDeclaration(SourceLocation AtLoc,
5542 ParsedAttributes &prefixAttrs);
5548 ObjCTypeParamList *parseObjCTypeParamList();
5576 ObjCTypeParamList *parseObjCTypeParamListOrProtocolRefs(
5578 SmallVectorImpl<IdentifierLoc> &protocolIdents, SourceLocation &rAngleLoc,
5579 bool mayBeProtocolList =
true);
5581 void HelperActionsForIvarDeclarations(ObjCContainerDecl *interfaceDecl,
5582 SourceLocation atLoc,
5584 SmallVectorImpl<Decl *> &AllIvarDecls,
5585 bool RBraceMissing);
5610 void ParseObjCClassInstanceVariables(ObjCContainerDecl *interfaceDecl,
5612 SourceLocation atLoc);
5619 bool ParseObjCProtocolReferences(
5620 SmallVectorImpl<Decl *> &P, SmallVectorImpl<SourceLocation> &PLocs,
5621 bool WarnOnDeclarations,
bool ForObjCContainer, SourceLocation &LAngleLoc,
5622 SourceLocation &EndProtoLoc,
bool consumeLastToken);
5633 void parseObjCTypeArgsOrProtocolQualifiers(
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,
5639 bool warnOnIncompleteProtocols);
5643 void parseObjCTypeArgsAndProtocolQualifiers(
5644 ParsedType baseType, SourceLocation &typeArgsLAngleLoc,
5645 SmallVectorImpl<ParsedType> &typeArgs, SourceLocation &typeArgsRAngleLoc,
5646 SourceLocation &protocolLAngleLoc, SmallVectorImpl<Decl *> &protocols,
5647 SmallVectorImpl<SourceLocation> &protocolLocs,
5648 SourceLocation &protocolRAngleLoc,
bool consumeLastToken);
5652 TypeResult parseObjCProtocolQualifierType(SourceLocation &rAngleLoc);
5656 TypeResult parseObjCTypeArgsAndProtocolQualifiers(SourceLocation loc,
5658 bool consumeLastToken,
5659 SourceLocation &endLoc);
5695 DeclGroupPtrTy ParseObjCAtProtocolDeclaration(SourceLocation atLoc,
5696 ParsedAttributes &prefixAttrs);
5698 struct ObjCImplParsingDataRAII {
5702 typedef SmallVector<LexedMethod *, 8> LateParsedObjCMethodContainer;
5703 LateParsedObjCMethodContainer LateParsedObjCMethods;
5705 ObjCImplParsingDataRAII(
Parser &parser, Decl *D)
5706 : P(parser), Dcl(D), HasCFunction(
false) {
5707 P.CurParsedObjCImpl =
this;
5710 ~ObjCImplParsingDataRAII();
5712 void finish(SourceRange AtEnd);
5713 bool isFinished()
const {
return Finished; }
5718 ObjCImplParsingDataRAII *CurParsedObjCImpl;
5722 void StashAwayMethodOrFunctionBodyTokens(Decl *MDecl);
5736 DeclGroupPtrTy ParseObjCAtImplementationDeclaration(SourceLocation AtLoc,
5737 ParsedAttributes &Attrs);
5745 Decl *ParseObjCAtAliasDeclaration(SourceLocation atLoc);
5760 Decl *ParseObjCPropertySynthesize(SourceLocation atLoc);
5771 Decl *ParseObjCPropertyDynamic(SourceLocation atLoc);
5783 IdentifierInfo *ParseObjCSelectorPiece(SourceLocation &MethodLocation);
5791 bool isTokIdentifier_in()
const;
5800 ParsedAttributes *ParamAttrs);
5814 Decl *ParseObjCMethodPrototype(
5816 bool MethodDefinition =
true);
5848 Decl *ParseObjCMethodDecl(
5851 bool MethodDefinition =
true);
5881 void ParseObjCPropertyAttribute(ObjCDeclSpec &DS);
5887 Decl *ParseObjCMethodDefinition();
5891 ExprResult ParseObjCAtExpression(SourceLocation AtLocation);
5892 ExprResult ParseObjCStringLiteral(SourceLocation AtLoc);
5899 ExprResult ParseObjCCharacterLiteral(SourceLocation AtLoc);
5908 ExprResult ParseObjCNumericLiteral(SourceLocation AtLoc);
5917 ExprResult ParseObjCBooleanLiteral(SourceLocation AtLoc,
bool ArgValue);
5919 ExprResult ParseObjCArrayLiteral(SourceLocation AtLoc);
5920 ExprResult ParseObjCDictionaryLiteral(SourceLocation AtLoc);
5927 ExprResult ParseObjCBoxedExpr(SourceLocation AtLoc);
5933 ExprResult ParseObjCEncodeExpression(SourceLocation AtLoc);
5939 ExprResult ParseObjCSelectorExpression(SourceLocation AtLoc);
5945 ExprResult ParseObjCProtocolExpression(SourceLocation AtLoc);
5952 bool isSimpleObjCMessageExpression();
6007 ExprResult ParseObjCMessageExpressionBody(SourceLocation LBracloc,
6008 SourceLocation SuperLoc,
6010 Expr *ReceiverExpr);
6036 bool ParseObjCXXMessageReceiver(
bool &IsExpr,
void *&TypeOrExpr);
6041 enum class ParsedStmtContext;
6043 StmtResult ParseObjCAtStatement(SourceLocation atLoc,
6044 ParsedStmtContext StmtCtx);
6059 StmtResult ParseObjCTryStmt(SourceLocation atLoc);
6066 StmtResult ParseObjCThrowStmt(SourceLocation atLoc);
6073 StmtResult ParseObjCSynchronizedStmt(SourceLocation atLoc);
6080 StmtResult ParseObjCAutoreleasePoolStmt(SourceLocation atLoc);
6107 bool isStartOfObjCClassMessageMissingOpenBracket();
6139 bool OpenACCDirectiveParsing =
false;
6143 bool AllowOpenACCArraySections =
false;
6147 class OpenACCArraySectionRAII {
6151 OpenACCArraySectionRAII(
Parser &P) : P(P) {
6152 assert(!P.AllowOpenACCArraySections);
6153 P.AllowOpenACCArraySections =
true;
6155 ~OpenACCArraySectionRAII() {
6156 assert(P.AllowOpenACCArraySections);
6157 P.AllowOpenACCArraySections =
false;
6164 struct OpenACCDirectiveParseInfo {
6166 SourceLocation StartLoc;
6167 SourceLocation DirLoc;
6168 SourceLocation LParenLoc;
6169 SourceLocation RParenLoc;
6170 SourceLocation EndLoc;
6171 SourceLocation MiscLoc;
6173 SmallVector<Expr *> Exprs;
6174 SmallVector<OpenACCClause *> Clauses;
6179 struct OpenACCWaitParseInfo {
6180 bool Failed =
false;
6181 Expr *DevNumExpr =
nullptr;
6182 SourceLocation QueuesLoc;
6183 SmallVector<Expr *> QueueIdExprs;
6185 SmallVector<Expr *> getAllExprs() {
6186 SmallVector<Expr *>
Out;
6187 Out.push_back(DevNumExpr);
6188 llvm::append_range(Out, QueueIdExprs);
6192 struct OpenACCCacheParseInfo {
6193 bool Failed =
false;
6194 SourceLocation ReadOnlyLoc;
6195 SmallVector<Expr *> Vars;
6200 enum class OpenACCParseCanContinue { Cannot = 0, Can = 1 };
6206 using OpenACCClauseParseResult =
6207 llvm::PointerIntPair<OpenACCClause *, 1, OpenACCParseCanContinue>;
6209 OpenACCClauseParseResult OpenACCCanContinue();
6210 OpenACCClauseParseResult OpenACCCannotContinue();
6211 OpenACCClauseParseResult OpenACCSuccess(OpenACCClause *Clause);
6215 OpenACCDirectiveParseInfo ParseOpenACCDirective();
6225 OpenACCCacheParseInfo ParseOpenACCCacheVarList();
6231 using OpenACCVarParseResult = std::pair<ExprResult, OpenACCParseCanContinue>;
6257 OpenACCClauseParseResult
6258 ParseOpenACCClauseParams(ArrayRef<const OpenACCClause *> ExistingClauses,
6260 SourceLocation ClauseLoc);
6264 OpenACCClauseParseResult
6265 ParseOpenACCClause(ArrayRef<const OpenACCClause *> ExistingClauses,
6275 SmallVector<OpenACCClause *>
6284 OpenACCWaitParseInfo ParseOpenACCWaitArgument(SourceLocation Loc,
6289 std::variant<std::monostate, StringLiteral *, IdentifierInfo *>
6290 ParseOpenACCBindClauseArgument();
6295 using OpenACCIntExprParseResult =
6296 std::pair<ExprResult, OpenACCParseCanContinue>;
6301 SourceLocation Loc);
6306 llvm::SmallVectorImpl<Expr *> &IntExprs);
6319 bool ParseOpenACCDeviceTypeList(llvm::SmallVector<IdentifierLoc> &Archs);
6333 SourceLocation Loc);
6348 llvm::SmallVectorImpl<Expr *> &SizeExprs);
6360 bool ParseOpenACCGangArgList(SourceLocation GangLoc,
6361 llvm::SmallVectorImpl<OpenACCGangKind> &GKs,
6362 llvm::SmallVectorImpl<Expr *> &IntExprs);
6364 using OpenACCGangArgRes = std::pair<OpenACCGangKind, ExprResult>;
6368 OpenACCGangArgRes ParseOpenACCGangArg(SourceLocation GangLoc);
6372 ParseOpenACCAfterRoutineDecl(
AccessSpecifier &AS, ParsedAttributes &Attrs,
6374 OpenACCDirectiveParseInfo &DirInfo);
6375 StmtResult ParseOpenACCAfterRoutineStmt(OpenACCDirectiveParseInfo &DirInfo);
6393 bool OpenMPDirectiveParsing =
false;
6398 void ReplayOpenMPAttributeTokens(
CachedTokens &OpenMPTokens) {
6401 if (!OpenMPTokens.empty()) {
6402 PP.EnterToken(Tok,
true);
6403 PP.EnterTokenStream(OpenMPTokens,
true,
6415 SourceLocation Loc);
6420 llvm::omp::TraitSet
Set,
6421 llvm::omp::TraitSelector Selector,
6422 llvm::StringMap<SourceLocation> &Seen);
6426 llvm::omp::TraitSet
Set,
6427 llvm::StringMap<SourceLocation> &Seen);
6431 llvm::StringMap<SourceLocation> &Seen);
6435 llvm::omp::TraitSet
Set,
6436 llvm::StringMap<SourceLocation> &Seen);
6444 llvm::omp::TraitSet
Set,
6445 llvm::StringMap<SourceLocation> &SeenSelectors);
6452 void parseOMPContextSelectorSet(
OMPTraitSet &TISet,
6453 llvm::StringMap<SourceLocation> &SeenSets);
6460 bool parseOMPContextSelectors(SourceLocation Loc,
OMPTraitInfo &TI);
6463 bool parseOpenMPAppendArgs(SmallVectorImpl<OMPInteropInfo> &InteropInfos);
6467 bool parseOMPDeclareVariantMatchClause(SourceLocation Loc,
OMPTraitInfo &TI,
6473 SourceLocation Loc);
6492 void ParseOpenMPAssumesDirective(OpenMPDirectiveKind DKind,
6493 SourceLocation Loc);
6496 void ParseOpenMPEndAssumesDirective(SourceLocation Loc);
6513 void ParseOpenMPClauses(OpenMPDirectiveKind DKind,
6514 SmallVectorImpl<clang::OMPClause *> &Clauses,
6515 SourceLocation Loc);
6518 void ParseOMPDeclareTargetClauses(SemaOpenMP::DeclareTargetContextInfo &DTCI);
6521 void ParseOMPEndDeclareTargetDirective(OpenMPDirectiveKind BeginDKind,
6522 OpenMPDirectiveKind EndDKind,
6523 SourceLocation Loc);
6527 void skipUntilPragmaOpenMPEnd(OpenMPDirectiveKind DKind);
6533 void parseOMPEndDirective(OpenMPDirectiveKind BeginKind,
6534 OpenMPDirectiveKind ExpectedKind,
6535 OpenMPDirectiveKind FoundKind,
6536 SourceLocation MatchingLoc, SourceLocation FoundLoc,
6537 bool SkipUntilOpenMPEnd);
6578 AccessSpecifier &AS, ParsedAttributes &Attrs,
bool Delayed =
false,
6580 Decl *TagDecl =
nullptr);
6594 DeclGroupPtrTy ParseOpenMPDeclareReductionDirective(AccessSpecifier AS);
6598 void ParseOpenMPReductionInitializerForDecl(VarDecl *OmpPrivParm);
6610 DeclGroupPtrTy ParseOpenMPDeclareMapperDirective(AccessSpecifier AS);
6613 TypeResult parseOpenMPDeclareMapperVarDecl(SourceRange &Range,
6614 DeclarationName &Name,
6615 AccessSpecifier AS =
AS_none);
6629 bool ParseOpenMPSimpleVarList(
6630 OpenMPDirectiveKind Kind,
6631 const llvm::function_ref<
void(CXXScopeSpec &, DeclarationNameInfo)>
6633 bool AllowScopeSpecifier);
6682 StmtResult ParseOpenMPDeclarativeOrExecutableDirective(
6683 ParsedStmtContext StmtCtx,
bool ReadDirectiveWithinMetadirective =
false);
6693 ParseOpenMPExecutableDirective(ParsedStmtContext StmtCtx,
6694 OpenMPDirectiveKind DKind, SourceLocation Loc,
6695 bool ReadDirectiveWithinMetadirective);
6704 StmtResult ParseOpenMPInformationalDirective(
6705 ParsedStmtContext StmtCtx, OpenMPDirectiveKind DKind, SourceLocation Loc,
6706 bool ReadDirectiveWithinMetadirective);
6735 OMPClause *ParseOpenMPClause(OpenMPDirectiveKind DKind,
6820 bool ParseOpenMPIndirectClause(SemaOpenMP::DeclareTargetContextInfo &DTCI,
6845 OMPClause *ParseOpenMPSingleExprWithArgClause(OpenMPDirectiveKind DKind,
6850 OMPClause *ParseOpenMPLoopRangeClause();
6859 OMPClause *ParseOpenMPPermutationClause();
6963 OMPClause *ParseOpenMPVarListClause(OpenMPDirectiveKind DKind,
6977 SourceLocation &ClauseNameLoc,
6978 SourceLocation &OpenLoc,
6979 SourceLocation &CloseLoc,
6980 SmallVectorImpl<Expr *> &Exprs,
6981 bool ReqIntConst =
false);
6996 OMPClause *ParseOpenMPUsesAllocatorClause(OpenMPDirectiveKind DKind);
6999 bool ParseOMPInteropInfo(OMPInteropInfo &InteropInfo,
OpenMPClauseKind Kind);
7005 bool ParseOMPInteropAttrSelector(SmallVectorImpl<Expr *> &Attrs);
7043 OMPClause *ParseOpenMPOMPXAttributesClause(
bool ParseOnly);
7050 bool IsAddressOfOperand =
false);
7054 SemaOpenMP::OpenMPVarListDataTy &
Data,
7055 const LangOptions &LangOpts);
7058 SmallVectorImpl<Expr *> &Vars,
7059 SemaOpenMP::OpenMPVarListDataTy &
Data);
7094 std::unique_ptr<PragmaHandler> AlignHandler;
7095 std::unique_ptr<PragmaHandler> GCCVisibilityHandler;
7096 std::unique_ptr<PragmaHandler> OptionsHandler;
7097 std::unique_ptr<PragmaHandler> PackHandler;
7098 std::unique_ptr<PragmaHandler> MSStructHandler;
7099 std::unique_ptr<PragmaHandler> UnusedHandler;
7100 std::unique_ptr<PragmaHandler> WeakHandler;
7101 std::unique_ptr<PragmaHandler> RedefineExtnameHandler;
7102 std::unique_ptr<PragmaHandler> FPContractHandler;
7103 std::unique_ptr<PragmaHandler> OpenCLExtensionHandler;
7104 std::unique_ptr<PragmaHandler> OpenMPHandler;
7105 std::unique_ptr<PragmaHandler> OpenACCHandler;
7106 std::unique_ptr<PragmaHandler> PCSectionHandler;
7107 std::unique_ptr<PragmaHandler> MSCommentHandler;
7108 std::unique_ptr<PragmaHandler> MSDetectMismatchHandler;
7109 std::unique_ptr<PragmaHandler> FPEvalMethodHandler;
7110 std::unique_ptr<PragmaHandler> FloatControlHandler;
7111 std::unique_ptr<PragmaHandler> MSPointersToMembers;
7112 std::unique_ptr<PragmaHandler> MSVtorDisp;
7113 std::unique_ptr<PragmaHandler> MSInitSeg;
7114 std::unique_ptr<PragmaHandler> MSDataSeg;
7115 std::unique_ptr<PragmaHandler> MSBSSSeg;
7116 std::unique_ptr<PragmaHandler> MSConstSeg;
7117 std::unique_ptr<PragmaHandler> MSCodeSeg;
7118 std::unique_ptr<PragmaHandler> MSSection;
7119 std::unique_ptr<PragmaHandler> MSStrictGuardStackCheck;
7120 std::unique_ptr<PragmaHandler> MSRuntimeChecks;
7121 std::unique_ptr<PragmaHandler> MSIntrinsic;
7122 std::unique_ptr<PragmaHandler> MSFunction;
7123 std::unique_ptr<PragmaHandler> MSOptimize;
7124 std::unique_ptr<PragmaHandler> MSFenvAccess;
7125 std::unique_ptr<PragmaHandler> MSAllocText;
7126 std::unique_ptr<PragmaHandler> CUDAForceHostDeviceHandler;
7127 std::unique_ptr<PragmaHandler> OptimizeHandler;
7128 std::unique_ptr<PragmaHandler> LoopHintHandler;
7129 std::unique_ptr<PragmaHandler> UnrollHintHandler;
7130 std::unique_ptr<PragmaHandler> NoUnrollHintHandler;
7131 std::unique_ptr<PragmaHandler> UnrollAndJamHintHandler;
7132 std::unique_ptr<PragmaHandler> NoUnrollAndJamHintHandler;
7133 std::unique_ptr<PragmaHandler> FPHandler;
7134 std::unique_ptr<PragmaHandler> STDCFenvAccessHandler;
7135 std::unique_ptr<PragmaHandler> STDCFenvRoundHandler;
7136 std::unique_ptr<PragmaHandler> STDCCXLIMITHandler;
7137 std::unique_ptr<PragmaHandler> STDCUnknownHandler;
7138 std::unique_ptr<PragmaHandler> AttributePragmaHandler;
7139 std::unique_ptr<PragmaHandler> MaxTokensHerePragmaHandler;
7140 std::unique_ptr<PragmaHandler> MaxTokensTotalPragmaHandler;
7141 std::unique_ptr<PragmaHandler> ExportHandler;
7142 std::unique_ptr<PragmaHandler> RISCVPragmaHandler;
7145 void initializePragmaHandlers();
7148 void resetPragmaHandlers();
7155 void HandlePragmaUnused();
7159 void HandlePragmaVisibility();
7163 void HandlePragmaPack();
7167 void HandlePragmaMSStruct();
7169 void HandlePragmaMSPointersToMembers();
7171 void HandlePragmaMSVtorDisp();
7173 void HandlePragmaMSPragma();
7174 bool HandlePragmaMSSection(StringRef PragmaName,
7175 SourceLocation PragmaLocation);
7176 bool HandlePragmaMSSegment(StringRef PragmaName,
7177 SourceLocation PragmaLocation);
7180 bool HandlePragmaMSInitSeg(StringRef PragmaName,
7181 SourceLocation PragmaLocation);
7186 bool HandlePragmaMSStrictGuardStackCheck(StringRef PragmaName,
7187 SourceLocation PragmaLocation);
7188 bool HandlePragmaMSFunction(StringRef PragmaName,
7189 SourceLocation PragmaLocation);
7190 bool HandlePragmaMSAllocText(StringRef PragmaName,
7191 SourceLocation PragmaLocation);
7194 bool HandlePragmaMSOptimize(StringRef PragmaName,
7195 SourceLocation PragmaLocation);
7198 bool HandlePragmaMSIntrinsic(StringRef PragmaName,
7199 SourceLocation PragmaLocation);
7203 void HandlePragmaAlign();
7207 void HandlePragmaDump();
7211 void HandlePragmaWeak();
7215 void HandlePragmaWeakAlias();
7219 void HandlePragmaRedefineExtname();
7223 void HandlePragmaFPContract();
7227 void HandlePragmaFEnvAccess();
7231 void HandlePragmaFEnvRound();
7235 void HandlePragmaCXLimitedRange();
7239 void HandlePragmaFloatControl();
7243 void HandlePragmaFP();
7247 void HandlePragmaOpenCLExtension();
7251 StmtResult HandlePragmaCaptured();
7255 bool HandlePragmaLoopHint(LoopHint &Hint);
7257 bool ParsePragmaAttributeSubjectMatchRuleSet(
7259 SourceLocation &AnyLoc, SourceLocation &LastMatchRuleEndLoc);
7261 void HandlePragmaAttribute();
7267 void HandlePragmaExport();
7293 enum class ParsedStmtContext {
7296 AllowDeclarationsInC = 0x1,
7298 AllowStandaloneOpenMPDirectives = 0x2,
7305 Compound = AllowDeclarationsInC | AllowStandaloneOpenMPDirectives,
7322 ParsedStmtContext StmtCtx = ParsedStmtContext::SubStmt,
7377 ParseStatementOrDeclaration(
StmtVector &Stmts, ParsedStmtContext StmtCtx,
7381 StmtResult ParseStatementOrDeclarationAfterAttributes(
7382 StmtVector &Stmts, ParsedStmtContext StmtCtx,
7387 StmtResult ParseExprStatement(ParsedStmtContext StmtCtx);
7401 ParsedStmtContext StmtCtx);
7410 StmtResult ParseCaseStatement(ParsedStmtContext StmtCtx,
7411 bool MissingCase =
false,
7421 StmtResult ParseDefaultStatement(ParsedStmtContext StmtCtx);
7423 StmtResult ParseCompoundStatement(
bool isStmtExpr =
false);
7449 StmtResult ParseCompoundStatement(
bool isStmtExpr,
unsigned ScopeFlags);
7454 void ParseCompoundStatementLeadingPragmas();
7456 void DiagnoseLabelAtEndOfCompoundStatement();
7466 StmtResult ParseCompoundStatementBody(
bool isStmtExpr =
false);
7484 bool ParseParenExprOrCondition(
StmtResult *InitStmt,
7558 void ParseForRangeInitializerAfterColon(ForRangeInit &FRI,
7604 StmtResult ParseBreakOrContinueStatement(
bool IsContinue);
7638 void ParseMicrosoftIfExistsStatement(
StmtVector &Stmts);
7685 StmtResult ParseCXXCatchBlock(
bool FnCatch =
false);
7723 Decl *ParseFunctionStatementBody(
Decl *
Decl, ParseScope &BodyScope);
7732 Decl *ParseFunctionTryBlock(
Decl *
Decl, ParseScope &BodyScope);
7738 bool trySkippingFunctionBody();
7746 bool isDeclarationStatement(
bool DisambiguatingWithExpression =
false) {
7748 return isCXXDeclarationStatement(DisambiguatingWithExpression);
7756 bool isForInitDeclaration() {
7760 return Tok.is(tok::kw_using) ||
7761 isCXXSimpleDeclaration(
true);
7766 bool isForRangeIdentifier();
7783 unsigned &NumLineToksConsumed,
7784 bool IsUnevaluated);
7827 StmtResult ParseMicrosoftAsmStatement(SourceLocation AsmLoc);
7843 bool ParseAsmOperandsOpt(SmallVectorImpl<IdentifierInfo *> &Names,
7844 SmallVectorImpl<Expr *> &Constraints,
7845 SmallVectorImpl<Expr *> &Exprs);
7847 class GNUAsmQualifiers {
7848 unsigned Qualifiers = AQ_unspecified;
7857 static const char *getQualifierName(AQ Qualifier);
7858 bool setAsmQualifier(AQ Qualifier);
7859 inline bool isVolatile()
const {
return Qualifiers & AQ_volatile; };
7860 inline bool isInline()
const {
return Qualifiers & AQ_inline; };
7861 inline bool isGoto()
const {
return Qualifiers & AQ_goto; }
7865 bool isGCCAsmStatement(
const Token &TokAfterAsm)
const;
7867 bool isGNUAsmQualifier(
const Token &TokAfterAsm)
const;
7868 GNUAsmQualifiers::AQ getGNUAsmQualifier(
const Token &Tok)
const;
7881 bool parseGNUAsmQualifierListOpt(GNUAsmQualifiers &AQ);
7905 unsigned TemplateParameterDepth;
7908 class TemplateParameterDepthRAII {
7910 unsigned AddedLevels;
7913 explicit TemplateParameterDepthRAII(
unsigned &Depth)
7914 : Depth(Depth), AddedLevels(0) {}
7916 ~TemplateParameterDepthRAII() { Depth -= AddedLevels; }
7922 void addDepth(
unsigned D) {
7926 void setAddedDepth(
unsigned D) {
7927 Depth = Depth - AddedLevels + D;
7931 unsigned getDepth()
const {
return Depth; }
7932 unsigned getOriginalDepth()
const {
return Depth - AddedLevels; }
7937 SmallVector<TemplateIdAnnotation *, 16> TemplateIds;
7943 bool DelayTemplateIdDestruction =
false;
7945 void MaybeDestroyTemplateIds() {
7946 if (DelayTemplateIdDestruction)
7948 if (!TemplateIds.empty() &&
7949 (Tok.is(tok::eof) || !PP.mightHavePendingAnnotationTokens()))
7950 DestroyTemplateIds();
7952 void DestroyTemplateIds();
7956 struct DestroyTemplateIdAnnotationsRAIIObj {
7959 DestroyTemplateIdAnnotationsRAIIObj(
Parser &Self) : Self(Self) {}
7960 ~DestroyTemplateIdAnnotationsRAIIObj() { Self.MaybeDestroyTemplateIds(); }
7963 struct DelayTemplateIdDestructionRAII {
7965 bool PrevDelayTemplateIdDestruction;
7967 DelayTemplateIdDestructionRAII(
Parser &Self,
7968 bool DelayTemplateIdDestruction) noexcept
7970 PrevDelayTemplateIdDestruction(Self.DelayTemplateIdDestruction) {
7971 Self.DelayTemplateIdDestruction = DelayTemplateIdDestruction;
7974 ~DelayTemplateIdDestructionRAII() noexcept {
7975 Self.DelayTemplateIdDestruction = PrevDelayTemplateIdDestruction;
7980 SmallVector<const IdentifierInfo *, 8> TentativelyDeclaredIdentifiers;
7992 struct AngleBracketTracker {
7995 enum Priority :
unsigned short {
7997 PotentialTypo = 0x0,
7999 DependentName = 0x2,
8002 SpaceBeforeLess = 0x0,
8004 NoSpaceBeforeLess = 0x1,
8035 if (!Locs.empty() && Locs.back().isActive(P)) {
8036 if (Locs.back().Priority <= Prio) {
8038 Locs.back().LessLoc = LessLoc;
8039 Locs.back().Priority = Prio;
8042 Locs.push_back({
TemplateName, LessLoc, Prio, P.ParenCount,
8043 P.BracketCount, P.BraceCount});
8051 while (!Locs.empty() && Locs.back().isActiveOrNested(P))
8058 if (!Locs.empty() && Locs.back().isActive(P))
8059 return &Locs.back();
8064 AngleBracketTracker AngleBrackets;
8069 struct ParsedTemplateInfo {
8070 ParsedTemplateInfo()
8074 bool isSpecialization,
8075 bool lastParameterListWasEmpty =
false)
8078 TemplateParams(TemplateParams),
8079 LastParameterListWasEmpty(lastParameterListWasEmpty) {}
8081 explicit ParsedTemplateInfo(SourceLocation ExternLoc,
8082 SourceLocation TemplateLoc)
8084 TemplateParams(
nullptr), ExternLoc(ExternLoc),
8085 TemplateLoc(TemplateLoc), LastParameterListWasEmpty(
false) {}
8095 SourceLocation ExternLoc;
8099 SourceLocation TemplateLoc;
8102 bool LastParameterListWasEmpty;
8104 SourceRange getSourceRange() const LLVM_READONLY;
8108 void LexTemplateFunctionForLateParsing(
CachedTokens &Toks);
8111 void ParseLateTemplatedFuncDef(LateParsedTemplate &LPT);
8113 static
void LateTemplateParserCallback(
void *P, LateParsedTemplate &LPT);
8121 void checkPotentialAngleBracket(
ExprResult &PotentialTemplateName);
8122 bool checkPotentialAngleBracketDelimiter(const AngleBracketTracker::Loc &,
8123 const Token &OpToken);
8124 bool checkPotentialAngleBracketDelimiter(const Token &OpToken) {
8125 if (
auto *Info = AngleBrackets.getCurrent(*
this))
8126 return checkPotentialAngleBracketDelimiter(*Info, OpToken);
8137 SourceLocation &DeclEnd,
8138 ParsedAttributes &AccessAttrs);
8185 ParsingDeclRAIIObject &DiagsFromParams, SourceLocation &DeclEnd,
8197 bool ParseTemplateParameters(MultiParseScope &TemplateScopes,
unsigned Depth,
8198 SmallVectorImpl<NamedDecl *> &TemplateParams,
8199 SourceLocation &LAngleLoc,
8200 SourceLocation &RAngleLoc);
8212 bool ParseTemplateParameterList(
unsigned Depth,
8213 SmallVectorImpl<NamedDecl *> &TemplateParams);
8215 enum class TPResult;
8219 TPResult isStartOfTemplateTypeParameter();
8243 NamedDecl *ParseTemplateParameter(
unsigned Depth,
unsigned Position);
8256 NamedDecl *ParseTypeParameter(
unsigned Depth,
unsigned Position);
8272 NamedDecl *ParseTemplateTemplateParameter(
unsigned Depth,
unsigned Position);
8282 NamedDecl *ParseNonTypeTemplateParameter(
unsigned Depth,
unsigned Position);
8286 bool isTypeConstraintAnnotation();
8298 bool TryAnnotateTypeConstraint();
8300 void DiagnoseMisplacedEllipsis(SourceLocation EllipsisLoc,
8301 SourceLocation CorrectLoc,
8302 bool AlreadyHasEllipsis,
8303 bool IdentifierHasName);
8304 void DiagnoseMisplacedEllipsisInDeclarator(SourceLocation EllipsisLoc,
8307 typedef SmallVector<ParsedTemplateArgument, 16> TemplateArgList;
8324 bool ParseGreaterThanInTemplateList(SourceLocation LAngleLoc,
8325 SourceLocation &RAngleLoc,
8326 bool ConsumeLastToken,
8327 bool ObjCGenericList);
8340 bool ParseTemplateIdAfterTemplateName(
bool ConsumeLastToken,
8341 SourceLocation &LAngleLoc,
8342 TemplateArgList &TemplateArgs,
8343 SourceLocation &RAngleLoc,
8388 CXXScopeSpec &SS, SourceLocation TemplateKWLoc,
8390 bool AllowTypeAnnotation =
true,
8391 bool TypeConstraint =
false);
8409 AnnotateTemplateIdTokenAsType(CXXScopeSpec &SS,
8411 bool IsClassName =
false);
8423 bool ParseTemplateArgumentList(TemplateArgList &TemplateArgs,
8427 ParsedTemplateArgument ParseTemplateTemplateArgument();
8439 ParsedTemplateArgument ParseTemplateArgument();
8451 SourceLocation ExternLoc,
8452 SourceLocation TemplateLoc,
8453 SourceLocation &DeclEnd,
8454 ParsedAttributes &AccessAttrs,
8463 Decl *ParseConceptDefinition(
const ParsedTemplateInfo &TemplateInfo,
8464 SourceLocation &DeclEnd);
8492 class TentativeParsingAction {
8494 PreferredTypeBuilder PrevPreferredType;
8496 size_t PrevTentativelyDeclaredIdentifierCount;
8497 unsigned short PrevParenCount, PrevBracketCount, PrevBraceCount;
8501 explicit TentativeParsingAction(Parser &p,
bool Unannotated =
false)
8502 : P(p), PrevPreferredType(P.PreferredType) {
8504 PrevTentativelyDeclaredIdentifierCount =
8505 P.TentativelyDeclaredIdentifiers.size();
8506 PrevParenCount = P.ParenCount;
8507 PrevBracketCount = P.BracketCount;
8508 PrevBraceCount = P.BraceCount;
8509 P.PP.EnableBacktrackAtThisPos(Unannotated);
8513 assert(isActive &&
"Parsing action was finished!");
8514 P.TentativelyDeclaredIdentifiers.resize(
8515 PrevTentativelyDeclaredIdentifierCount);
8516 P.PP.CommitBacktrackedTokens();
8520 assert(isActive &&
"Parsing action was finished!");
8522 P.PreferredType = PrevPreferredType;
8524 P.TentativelyDeclaredIdentifiers.resize(
8525 PrevTentativelyDeclaredIdentifierCount);
8526 P.ParenCount = PrevParenCount;
8527 P.BracketCount = PrevBracketCount;
8528 P.BraceCount = PrevBraceCount;
8531 ~TentativeParsingAction() {
8532 assert(!isActive &&
"Forgot to call Commit or Revert!");
8538 class RevertingTentativeParsingAction
8539 :
private Parser::TentativeParsingAction {
8541 using TentativeParsingAction::TentativeParsingAction;
8543 ~RevertingTentativeParsingAction() { Revert(); }
8578 bool isCXXDeclarationStatement(
bool DisambiguatingWithExpression =
false);
8604 bool isCXXSimpleDeclaration(
bool AllowForRangeDecl);
8617 bool isCXXFunctionDeclarator(
bool *IsAmbiguous =
nullptr,
8621 struct ConditionDeclarationOrInitStatementState;
8622 enum class ConditionOrInitStatement {
8649 ConditionOrInitStatement
8650 isCXXConditionDeclarationOrInitStatement(
bool CanBeInitStmt,
8651 bool CanBeForRangeDecl);
8677 return isCXXTypeId(Context, isAmbiguous);
8691 bool isEnumBase(
bool AllowSemi);
8811 TPResult BracedCastResult = TPResult::False,
8812 bool *InvalidAsDeclSpec =
nullptr);
8817 bool isCXXDeclarationSpecifierAType();
8823 TPResult isTemplateArgumentList(
unsigned TokensToSkip);
8828 TPResult isExplicitBool();
8833 bool isTentativelyDeclared(IdentifierInfo *II);
8852 TPResult TryParseSimpleDeclaration(
bool AllowForRangeDecl);
8860 TPResult TryParseTypeofSpecifier();
8864 TPResult TryParseProtocolQualifiers();
8866 TPResult TryParsePtrOperatorSeq();
8888 TPResult TryParseOperatorId();
8919 TPResult TryParseInitDeclaratorList(
bool MayHaveTrailingReturnType =
false);
8976 TPResult TryParseDeclarator(
bool mayBeAbstract,
bool mayHaveIdentifier =
true,
8977 bool mayHaveDirectInit =
false,
8978 bool mayHaveTrailingReturnType =
false);
8999 TPResult TryParseParameterDeclarationClause(
9000 bool *InvalidAsDeclaration =
nullptr,
bool VersusTemplateArg =
false,
9017 TPResult TryParseFunctionDeclarator(
bool MayHaveTrailingReturnType =
false);
9023 bool NameAfterArrowIsNonType();
9029 TPResult TryParseBracketDeclarator();
9033 TPResult TryConsumeDeclarationSpecifier();
9037 bool TrySkipAttributes();
9079 isCXX11AttributeSpecifier(
bool Disambiguate =
false,
9080 bool OuterMightBeMessageSend =
false);