215 return Actions.incrementMSManglingNumber();
264 assert(!isTokenSpecial() &&
265 "Should consume special tokens with Consume*Token");
266 PrevTokLocation = Tok.getLocation();
268 return PrevTokLocation;
274 assert(!isTokenSpecial() &&
275 "Should consume special tokens with Consume*Token");
276 PrevTokLocation = Tok.getLocation();
284 Loc = PrevTokLocation;
293 return ConsumeParen();
294 if (isTokenBracket())
295 return ConsumeBracket();
297 return ConsumeBrace();
298 if (isTokenStringLiteral())
299 return ConsumeStringToken();
300 if (Tok.is(tok::code_completion))
301 return ConsumeCodeCompletionTok ? ConsumeCodeCompletionToken()
302 : handleUnexpectedCodeCompletionToken();
303 if (Tok.isAnnotation())
304 return ConsumeAnnotationToken();
318 if (N == 0 || Tok.is(tok::eof))
320 return PP.LookAhead(N - 1);
329 if (!Tok.getAnnotationValue())
379 (Tok.is(tok::identifier) || Tok.is(tok::coloncolon) ||
380 (Tok.is(tok::annot_template_id) &&
382 Tok.is(tok::kw_decltype) || Tok.is(tok::kw___super));
399 ParseScope(
const ParseScope &) =
delete;
400 void operator=(
const ParseScope &) =
delete;
407 bool BeforeCompoundStmt =
false)
409 if (EnteredScope && !BeforeCompoundStmt)
410 Self->EnterScope(ScopeFlags);
412 if (BeforeCompoundStmt)
413 Self->incrementMSManglingNumber();
415 this->Self = nullptr;
433 class MultiParseScope {
435 unsigned NumScopes = 0;
437 MultiParseScope(
const MultiParseScope &) =
delete;
442 Self.EnterScope(ScopeFlags);
484 static_cast<unsigned>(R));
539 unsigned short ParenCount = 0, BracketCount = 0,
BraceCount = 0;
540 unsigned short MisplacedModuleBeginCount = 0;
551 static constexpr int ScopeCacheSize = 16;
552 unsigned NumCachedScopes;
553 Scope *ScopeCache[ScopeCacheSize];
559 *Ident_GetExceptionCode;
562 *Ident_GetExceptionInfo;
564 IdentifierInfo *Ident__abnormal_termination, *Ident___abnormal_termination,
565 *Ident_AbnormalTermination;
570 std::unique_ptr<CommentHandler> CommentSemaHandler;
575 bool CalledSignatureHelp =
false;
583 bool SkipFunctionBodies;
590 bool isTokenParen()
const {
return Tok.isOneOf(tok::l_paren, tok::r_paren); }
592 bool isTokenBracket()
const {
593 return Tok.isOneOf(tok::l_square, tok::r_square);
596 bool isTokenBrace()
const {
return Tok.isOneOf(tok::l_brace, tok::r_brace); }
598 bool isTokenStringLiteral()
const {
602 bool isTokenSpecial()
const {
603 return isTokenStringLiteral() || isTokenParen() || isTokenBracket() ||
604 isTokenBrace() || Tok.is(tok::code_completion) || Tok.isAnnotation();
609 bool isTokenEqualOrEqualTypo();
613 void UnconsumeToken(Token &Consumed) {
615 PP.EnterToken(Consumed,
true);
617 PP.EnterToken(
Next,
true);
620 SourceLocation ConsumeAnnotationToken() {
621 assert(Tok.isAnnotation() &&
"wrong consume method");
622 SourceLocation Loc = Tok.getLocation();
623 PrevTokLocation = Tok.getAnnotationEndLoc();
630 SourceLocation ConsumeParen() {
631 assert(isTokenParen() &&
"wrong consume method");
632 if (Tok.getKind() == tok::l_paren)
634 else if (ParenCount) {
635 AngleBrackets.clear(*
this);
638 PrevTokLocation = Tok.getLocation();
640 return PrevTokLocation;
645 SourceLocation ConsumeBracket() {
646 assert(isTokenBracket() &&
"wrong consume method");
647 if (Tok.getKind() == tok::l_square)
649 else if (BracketCount) {
650 AngleBrackets.clear(*
this);
654 PrevTokLocation = Tok.getLocation();
656 return PrevTokLocation;
661 SourceLocation ConsumeBrace() {
662 assert(isTokenBrace() &&
"wrong consume method");
663 if (Tok.getKind() == tok::l_brace)
665 else if (BraceCount) {
666 AngleBrackets.clear(*
this);
670 PrevTokLocation = Tok.getLocation();
672 return PrevTokLocation;
679 SourceLocation ConsumeStringToken() {
680 assert(isTokenStringLiteral() &&
681 "Should only consume string literals with this method");
682 PrevTokLocation = Tok.getLocation();
684 return PrevTokLocation;
692 SourceLocation ConsumeCodeCompletionToken() {
693 assert(Tok.is(tok::code_completion));
694 PrevTokLocation = Tok.getLocation();
696 return PrevTokLocation;
704 SourceLocation handleUnexpectedCodeCompletionToken();
708 void cutOffParsing() {
709 if (PP.isCodeCompletionEnabled())
710 PP.setCodeCompletionReached();
712 Tok.setKind(tok::eof);
719 return Kind == tok::eof ||
Kind == tok::annot_module_begin ||
720 Kind == tok::annot_module_end ||
Kind == tok::annot_module_include ||
721 Kind == tok::annot_repl_input_end;
724 static void setTypeAnnotation(Token &Tok,
TypeResult T) {
725 assert((T.isInvalid() || T.get()) &&
726 "produced a valid-but-null type annotation?");
727 Tok.setAnnotationValue(T.isInvalid() ?
nullptr : T.get().getAsOpaquePtr());
730 static NamedDecl *getNonTypeAnnotation(
const Token &Tok) {
731 return static_cast<NamedDecl *
>(Tok.getAnnotationValue());
734 static void setNonTypeAnnotation(Token &Tok, NamedDecl *ND) {
735 Tok.setAnnotationValue(ND);
738 static IdentifierInfo *getIdentifierAnnotation(
const Token &Tok) {
739 return static_cast<IdentifierInfo *
>(Tok.getAnnotationValue());
742 static void setIdentifierAnnotation(Token &Tok, IdentifierInfo *ND) {
743 Tok.setAnnotationValue(ND);
748 static ExprResult getExprAnnotation(
const Token &Tok) {
749 return ExprResult::getFromOpaquePointer(Tok.getAnnotationValue());
754 static void setExprAnnotation(Token &Tok,
ExprResult ER) {
755 Tok.setAnnotationValue(ER.getAsOpaquePointer());
769 TryAnnotateName(CorrectionCandidateCallback *CCC =
nullptr,
774 void AnnotateScopeToken(CXXScopeSpec &SS,
bool IsNewAnnotation);
781 bool TryKeywordIdentFallback(
bool DisableKeyword);
786 TemplateIdAnnotation *takeTemplateIdAnnotation(
const Token &tok);
797 unsigned Diag = diag::err_expected,
798 StringRef DiagMsg =
"");
805 bool ExpectAndConsumeSemi(
unsigned DiagID, StringRef TokenUsed =
"");
816 bool expectIdentifier();
819 enum class CompoundToken {
834 void checkCompoundToken(SourceLocation FirstTokLoc,
837 void diagnoseUseOfC11Keyword(
const Token &Tok);
840 class ParseScopeFlags {
842 unsigned OldFlags = 0;
843 ParseScopeFlags(
const ParseScopeFlags &) =
delete;
844 void operator=(
const ParseScopeFlags &) =
delete;
849 ParseScopeFlags(
Parser *
Self,
unsigned ScopeFlags,
bool ManageFlags =
true);
863 void SuggestParentheses(SourceLocation Loc,
unsigned DK,
864 SourceRange ParenRange);
900 DeclGroupPtrTy ParseExternalDeclaration(ParsedAttributes &DeclAttrs,
901 ParsedAttributes &DeclSpecAttrs,
902 ParsingDeclSpec *DS =
nullptr);
906 bool isDeclarationAfterDeclarator();
910 bool isStartOfFunctionDefinition(
const ParsingDeclarator &Declarator);
913 ParsedAttributes &DeclAttrs, ParsedAttributes &DeclSpecAttrs,
934 DeclGroupPtrTy ParseDeclOrFunctionDefInternal(ParsedAttributes &Attrs,
935 ParsedAttributes &DeclSpecAttrs,
939 void SkipFunctionBody();
941 struct ParsedTemplateInfo;
942 class LateParsedAttrList;
960 Decl *ParseFunctionDefinition(
961 ParsingDeclarator &D,
962 const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo(),
963 LateParsedAttrList *LateParsedAttrs =
nullptr);
967 void ParseKNRParamDeclarations(Declarator &D);
977 ExprResult ParseSimpleAsm(
bool ForAsmLabel, SourceLocation *EndLoc);
990 ExprResult ParseAsmStringLiteral(
bool ForAsmLabel);
994 struct IfExistsCondition {
996 SourceLocation KeywordLoc;
1012 bool ParseMicrosoftIfExistsCondition(IfExistsCondition &
Result);
1013 void ParseMicrosoftIfExistsExternalDeclaration();
1052 Decl *ParseModuleImport(SourceLocation AtLoc,
1059 bool parseMisplacedModuleImport();
1061 bool tryParseMisplacedModuleImport() {
1063 if (Kind == tok::annot_module_begin || Kind == tok::annot_module_end ||
1064 Kind == tok::annot_module_include)
1065 return parseMisplacedModuleImport();
1078 bool ParseModuleName(SourceLocation UseLoc,
1079 SmallVectorImpl<IdentifierLoc> &Path,
bool IsImport);
1082 void DiagnoseInvalidCXXModuleImport();
1086 void CodeCompleteDirective(
bool InConditional)
override;
1088 void CodeCompleteMacroName(
bool IsDefinition)
override;
1090 void CodeCompleteMacroArgument(IdentifierInfo *
Macro, MacroInfo *MacroInfo,
1091 unsigned ArgumentIndex)
override;
1092 void CodeCompleteIncludedFile(llvm::StringRef Dir,
bool IsAngled)
override;
1094 void CodeCompleteModuleImport(SourceLocation ImportLoc,
1110 struct ParsingClass;
1120 class LateParsedDeclaration {
1122 virtual ~LateParsedDeclaration();
1124 virtual void ParseLexedMethodDeclarations();
1125 virtual void ParseLexedMemberInitializers();
1126 virtual void ParseLexedMethodDefs();
1127 virtual void ParseLexedAttributes();
1128 virtual void ParseLexedPragmas();
1133 class LateParsedClass :
public LateParsedDeclaration {
1135 LateParsedClass(
Parser *P, ParsingClass *
C);
1136 ~LateParsedClass()
override;
1138 void ParseLexedMethodDeclarations()
override;
1139 void ParseLexedMemberInitializers()
override;
1140 void ParseLexedMethodDefs()
override;
1141 void ParseLexedAttributes()
override;
1142 void ParseLexedPragmas()
override;
1145 LateParsedClass(
const LateParsedClass &) =
delete;
1146 LateParsedClass &operator=(
const LateParsedClass &) =
delete;
1150 ParsingClass *Class;
1159 struct LateParsedAttribute :
public LateParsedDeclaration {
1162 IdentifierInfo &AttrName;
1163 IdentifierInfo *MacroII =
nullptr;
1164 SourceLocation AttrNameLoc;
1165 SmallVector<Decl *, 2> Decls;
1167 explicit LateParsedAttribute(
Parser *P, IdentifierInfo &Name,
1169 : Self(P), AttrName(Name), AttrNameLoc(Loc) {}
1171 void ParseLexedAttributes()
override;
1173 void addDecl(Decl *D) { Decls.push_back(D); }
1180 class LateParsedPragma :
public LateParsedDeclaration {
1187 : Self(P), AS(AS) {}
1189 void takeToks(
CachedTokens &Cached) { Toks.swap(Cached); }
1193 void ParseLexedPragmas()
override;
1197 class LateParsedAttrList :
public SmallVector<LateParsedAttribute *, 2> {
1199 LateParsedAttrList(
bool PSoon =
false,
1200 bool LateAttrParseExperimentalExtOnly =
false)
1202 LateAttrParseExperimentalExtOnly(LateAttrParseExperimentalExtOnly) {}
1204 bool parseSoon() {
return ParseSoon; }
1207 bool lateAttrParseExperimentalExtOnly() {
1208 return LateAttrParseExperimentalExtOnly;
1213 bool LateAttrParseExperimentalExtOnly;
1219 struct LexedMethod :
public LateParsedDeclaration {
1224 explicit LexedMethod(
Parser *P, Decl *MD) : Self(P), D(MD) {}
1226 void ParseLexedMethodDefs()
override;
1233 struct LateParsedDefaultArgument {
1234 explicit LateParsedDefaultArgument(
1235 Decl *P, std::unique_ptr<CachedTokens> Toks =
nullptr)
1236 : Param(P), Toks(std::move(Toks)) {}
1245 std::unique_ptr<CachedTokens> Toks;
1252 struct LateParsedMethodDeclaration :
public LateParsedDeclaration {
1253 explicit LateParsedMethodDeclaration(
Parser *P, Decl *M)
1254 : Self(P), Method(M), ExceptionSpecTokens(
nullptr) {}
1256 void ParseLexedMethodDeclarations()
override;
1268 SmallVector<LateParsedDefaultArgument, 8> DefaultArgs;
1278 struct LateParsedMemberInitializer :
public LateParsedDeclaration {
1279 LateParsedMemberInitializer(
Parser *P, Decl *FD) : Self(P), Field(FD) {}
1281 void ParseLexedMemberInitializers()
override;
1299 typedef SmallVector<LateParsedDeclaration *, 2>
1300 LateParsedDeclarationsContainer;
1314 const ParsedAttributesView &AccessAttrs,
1315 ParsingDeclarator &D,
1316 const ParsedTemplateInfo &TemplateInfo,
1317 const VirtSpecifiers &VS,
1318 SourceLocation PureSpecLoc);
1321 StringLiteral *ParseCXXDeletedFunctionMessage();
1326 void SkipDeletedFunctionBody();
1332 void ParseCXXNonStaticMemberInitializer(Decl *VarD);
1336 void ParseLexedAttributes(ParsingClass &
Class);
1339 void ParseLexedAttributeList(LateParsedAttrList &LAs, Decl *D,
1347 void ParseLexedAttribute(LateParsedAttribute &LA,
bool EnterScope,
1354 void ParseLexedMethodDeclarations(ParsingClass &
Class);
1355 void ParseLexedMethodDeclaration(LateParsedMethodDeclaration &LM);
1360 void ParseLexedMethodDefs(ParsingClass &
Class);
1361 void ParseLexedMethodDef(LexedMethod &LM);
1367 void ParseLexedMemberInitializers(ParsingClass &
Class);
1368 void ParseLexedMemberInitializer(LateParsedMemberInitializer &MI);
1402 ParsedAttributes *Attrs =
nullptr);
1408 IdentifierInfo *Ident_vector;
1409 IdentifierInfo *Ident_bool;
1410 IdentifierInfo *Ident_Bool;
1414 IdentifierInfo *Ident_pixel;
1417 IdentifierInfo *Ident_introduced;
1420 IdentifierInfo *Ident_deprecated;
1423 IdentifierInfo *Ident_obsoleted;
1426 IdentifierInfo *Ident_unavailable;
1429 IdentifierInfo *Ident_message;
1432 IdentifierInfo *Ident_strict;
1435 IdentifierInfo *Ident_replacement;
1438 IdentifierInfo *Ident_environment;
1441 IdentifierInfo *Ident_language, *Ident_defined_in,
1442 *Ident_generated_declaration, *Ident_USR;
1445 AttributeFactory AttrFactory;
1450 bool TryAltiVecToken(DeclSpec &DS, SourceLocation Loc,
const char *&PrevSpec,
1455 if (Tok.getIdentifierInfo() != Ident_vector &&
1456 Tok.getIdentifierInfo() != Ident_bool &&
1457 Tok.getIdentifierInfo() != Ident_Bool &&
1458 (!
getLangOpts().AltiVec || Tok.getIdentifierInfo() != Ident_pixel))
1461 return TryAltiVecTokenOutOfLine(DS, Loc, PrevSpec, DiagID,
isInvalid);
1467 bool TryAltiVecVectorToken() {
1469 Tok.getIdentifierInfo() != Ident_vector)
1471 return TryAltiVecVectorTokenOutOfLine();
1476 bool TryAltiVecVectorTokenOutOfLine();
1477 bool TryAltiVecTokenOutOfLine(DeclSpec &DS, SourceLocation Loc,
1478 const char *&PrevSpec,
unsigned &DiagID,
1481 void ParseLexedCAttributeList(LateParsedAttrList &LA,
bool EnterScope,
1482 ParsedAttributes *OutAttrs =
nullptr);
1489 void ParseLexedCAttribute(LateParsedAttribute &LA,
bool EnterScope,
1490 ParsedAttributes *OutAttrs =
nullptr);
1492 void ParseLexedPragmas(ParsingClass &
Class);
1493 void ParseLexedPragma(LateParsedPragma &LP);
1501 bool ConsumeAndStoreFunctionPrologue(
CachedTokens &Toks);
1517 bool ConsumeFinalToken =
true) {
1518 return ConsumeAndStoreUntil(T1, T1, Toks,
StopAtSemi, ConsumeFinalToken);
1529 bool ConsumeFinalToken =
true);
1537 enum class DeclSpecContext {
1542 DSC_alias_declaration,
1547 DSC_template_type_arg,
1548 DSC_objc_method_result,
1557 static bool isTypeSpecifier(DeclSpecContext DSC) {
1559 case DeclSpecContext::DSC_normal:
1560 case DeclSpecContext::DSC_template_param:
1561 case DeclSpecContext::DSC_template_arg:
1562 case DeclSpecContext::DSC_class:
1563 case DeclSpecContext::DSC_top_level:
1564 case DeclSpecContext::DSC_objc_method_result:
1565 case DeclSpecContext::DSC_condition:
1568 case DeclSpecContext::DSC_template_type_arg:
1569 case DeclSpecContext::DSC_type_specifier:
1570 case DeclSpecContext::DSC_conv_operator:
1571 case DeclSpecContext::DSC_trailing:
1572 case DeclSpecContext::DSC_alias_declaration:
1573 case DeclSpecContext::DSC_association:
1574 case DeclSpecContext::DSC_new:
1577 llvm_unreachable(
"Missing DeclSpecContext case");
1581 enum class AllowDefiningTypeSpec {
1598 static AllowDefiningTypeSpec
1599 isDefiningTypeSpecifierContext(DeclSpecContext DSC,
bool IsCPlusPlus) {
1601 case DeclSpecContext::DSC_normal:
1602 case DeclSpecContext::DSC_class:
1603 case DeclSpecContext::DSC_top_level:
1604 case DeclSpecContext::DSC_alias_declaration:
1605 case DeclSpecContext::DSC_objc_method_result:
1606 return AllowDefiningTypeSpec::Yes;
1608 case DeclSpecContext::DSC_condition:
1609 case DeclSpecContext::DSC_template_param:
1610 return AllowDefiningTypeSpec::YesButInvalid;
1612 case DeclSpecContext::DSC_template_type_arg:
1613 case DeclSpecContext::DSC_type_specifier:
1614 return AllowDefiningTypeSpec::NoButErrorRecovery;
1616 case DeclSpecContext::DSC_association:
1617 return IsCPlusPlus ? AllowDefiningTypeSpec::NoButErrorRecovery
1618 : AllowDefiningTypeSpec::Yes;
1620 case DeclSpecContext::DSC_trailing:
1621 case DeclSpecContext::DSC_conv_operator:
1622 case DeclSpecContext::DSC_template_arg:
1623 case DeclSpecContext::DSC_new:
1624 return AllowDefiningTypeSpec::No;
1626 llvm_unreachable(
"Missing DeclSpecContext case");
1630 static bool isOpaqueEnumDeclarationContext(DeclSpecContext DSC) {
1632 case DeclSpecContext::DSC_normal:
1633 case DeclSpecContext::DSC_class:
1634 case DeclSpecContext::DSC_top_level:
1637 case DeclSpecContext::DSC_alias_declaration:
1638 case DeclSpecContext::DSC_objc_method_result:
1639 case DeclSpecContext::DSC_condition:
1640 case DeclSpecContext::DSC_template_param:
1641 case DeclSpecContext::DSC_template_type_arg:
1642 case DeclSpecContext::DSC_type_specifier:
1643 case DeclSpecContext::DSC_trailing:
1644 case DeclSpecContext::DSC_association:
1645 case DeclSpecContext::DSC_conv_operator:
1646 case DeclSpecContext::DSC_template_arg:
1647 case DeclSpecContext::DSC_new:
1651 llvm_unreachable(
"Missing DeclSpecContext case");
1656 static bool isClassTemplateDeductionContext(DeclSpecContext DSC) {
1658 case DeclSpecContext::DSC_normal:
1659 case DeclSpecContext::DSC_template_param:
1660 case DeclSpecContext::DSC_template_arg:
1661 case DeclSpecContext::DSC_class:
1662 case DeclSpecContext::DSC_top_level:
1663 case DeclSpecContext::DSC_condition:
1664 case DeclSpecContext::DSC_type_specifier:
1665 case DeclSpecContext::DSC_association:
1666 case DeclSpecContext::DSC_conv_operator:
1667 case DeclSpecContext::DSC_new:
1670 case DeclSpecContext::DSC_objc_method_result:
1671 case DeclSpecContext::DSC_template_type_arg:
1672 case DeclSpecContext::DSC_trailing:
1673 case DeclSpecContext::DSC_alias_declaration:
1676 llvm_unreachable(
"Missing DeclSpecContext case");
1681 getImplicitTypenameContext(DeclSpecContext DSC) {
1683 case DeclSpecContext::DSC_class:
1684 case DeclSpecContext::DSC_top_level:
1685 case DeclSpecContext::DSC_type_specifier:
1686 case DeclSpecContext::DSC_template_type_arg:
1687 case DeclSpecContext::DSC_trailing:
1688 case DeclSpecContext::DSC_alias_declaration:
1689 case DeclSpecContext::DSC_template_param:
1690 case DeclSpecContext::DSC_new:
1693 case DeclSpecContext::DSC_normal:
1694 case DeclSpecContext::DSC_objc_method_result:
1695 case DeclSpecContext::DSC_condition:
1696 case DeclSpecContext::DSC_template_arg:
1697 case DeclSpecContext::DSC_conv_operator:
1698 case DeclSpecContext::DSC_association:
1701 llvm_unreachable(
"Missing DeclSpecContext case");
1706 struct ForRangeInit {
1707 SourceLocation ColonLoc;
1709 SmallVector<MaterializeTemporaryExpr *, 8> LifetimeExtendTemps;
1710 bool ParsedForRangeDecl() {
return !ColonLoc.
isInvalid(); }
1712 struct ForRangeInfo : ForRangeInit {
1735 SourceLocation &DeclEnd,
1736 ParsedAttributes &DeclAttrs,
1737 ParsedAttributes &DeclSpecAttrs,
1738 SourceLocation *DeclSpecStart =
nullptr);
1765 ParsedAttributes &DeclAttrs,
1766 ParsedAttributes &DeclSpecAttrs,
bool RequireSemi,
1767 ForRangeInit *FRI =
nullptr,
1768 SourceLocation *DeclSpecStart =
nullptr);
1778 ParsedAttributes &Attrs,
1779 ParsedTemplateInfo &TemplateInfo,
1780 SourceLocation *DeclEnd =
nullptr,
1781 ForRangeInit *FRI =
nullptr);
1807 Decl *ParseDeclarationAfterDeclarator(
1809 const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo());
1813 bool ParseAsmAttributesAfterDeclarator(Declarator &D);
1814 Decl *ParseDeclarationAfterDeclaratorAndAttributes(
1816 const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo(),
1817 ForRangeInit *FRI =
nullptr);
1828 bool ParseImplicitInt(DeclSpec &DS, CXXScopeSpec *SS,
1830 DeclSpecContext DSC, ParsedAttributes &Attrs);
1840 ParseDeclarationSpecifiers(DeclSpec &DS, ParsedTemplateInfo &TemplateInfo,
1842 DeclSpecContext DSC = DeclSpecContext::DSC_normal,
1843 LateParsedAttrList *LateAttrs =
nullptr) {
1844 return ParseDeclarationSpecifiers(DS, TemplateInfo, AS, DSC, LateAttrs,
1845 getImplicitTypenameContext(DSC));
1878 ParseDeclarationSpecifiers(DeclSpec &DS, ParsedTemplateInfo &TemplateInfo,
1880 LateParsedAttrList *LateAttrs,
1890 bool DiagnoseMissingSemiAfterTagDefinition(
1892 LateParsedAttrList *LateAttrs =
nullptr);
1894 void ParseSpecifierQualifierList(
1896 DeclSpecContext DSC = DeclSpecContext::DSC_normal) {
1897 ParseSpecifierQualifierList(DS, getImplicitTypenameContext(DSC), AS, DSC);
1908 void ParseSpecifierQualifierList(
1911 DeclSpecContext DSC = DeclSpecContext::DSC_normal);
1945 void ParseEnumSpecifier(SourceLocation TagLoc, DeclSpec &DS,
1946 const ParsedTemplateInfo &TemplateInfo,
1961 void ParseEnumBody(SourceLocation StartLoc, Decl *TagDecl,
1962 SkipBodyInfo *SkipBody =
nullptr);
1976 void ParseStructUnionBody(SourceLocation StartLoc,
DeclSpec::TST TagType,
1977 RecordDecl *TagDecl);
2002 void ParseStructDeclaration(
2003 ParsingDeclSpec &DS,
2004 llvm::function_ref<Decl *(ParsingFieldDeclarator &)> FieldsCallback,
2005 LateParsedAttrList *LateFieldAttrs =
nullptr);
2017 bool DisambiguatingWithExpression =
false);
2021 bool isTypeSpecifierQualifier();
2026 bool isKnownToBeTypeSpecifier(
const Token &Tok)
const;
2031 bool isConstructorDeclarator(
2034 const ParsedTemplateInfo *TemplateInfo =
nullptr);
2038 void DiagnoseBitIntUse(
const Token &Tok);
2042 bool CheckProhibitedCXX11Attribute() {
2043 assert(Tok.is(tok::l_square));
2046 return DiagnoseProhibitedCXX11Attribute();
2057 bool DiagnoseProhibitedCXX11Attribute();
2059 void CheckMisplacedCXX11Attribute(ParsedAttributes &Attrs,
2060 SourceLocation CorrectLocation) {
2061 if (!Tok.isRegularKeywordAttribute() &&
2062 (Tok.isNot(tok::l_square) ||
NextToken().
isNot(tok::l_square)) &&
2063 Tok.isNot(tok::kw_alignas))
2065 DiagnoseMisplacedCXX11Attribute(Attrs, CorrectLocation);
2072 void DiagnoseMisplacedCXX11Attribute(ParsedAttributes &Attrs,
2073 SourceLocation CorrectLocation);
2083 void stripTypeAttributesOffDeclSpec(ParsedAttributes &Attrs, DeclSpec &DS,
2087 void ProhibitAttributes(ParsedAttributes &Attrs,
2088 SourceLocation FixItLoc = SourceLocation()) {
2089 if (Attrs.Range.isInvalid())
2091 DiagnoseProhibitedAttributes(Attrs, FixItLoc);
2095 void ProhibitAttributes(ParsedAttributesView &Attrs,
2096 SourceLocation FixItLoc = SourceLocation()) {
2097 if (Attrs.Range.isInvalid())
2099 DiagnoseProhibitedAttributes(Attrs, FixItLoc);
2100 Attrs.clearListOnly();
2102 void DiagnoseProhibitedAttributes(
const ParsedAttributesView &Attrs,
2103 SourceLocation FixItLoc);
2111 void ProhibitCXX11Attributes(ParsedAttributes &Attrs,
unsigned AttrDiagID,
2112 unsigned KeywordDiagId,
2113 bool DiagnoseEmptyAttrs =
false,
2114 bool WarnOnUnknownAttrs =
false);
2118 void DiagnoseCXX11AttributeExtension(ParsedAttributes &Attrs);
2120 ExprResult ParseUnevaluatedStringInAttribute(
const IdentifierInfo &AttrName);
2127 bool ParseAttributeArgumentList(
2128 const IdentifierInfo &AttrName, SmallVectorImpl<Expr *> &Exprs,
2129 ParsedAttributeArgumentsProperties ArgsProperties,
unsigned Arg);
2136 ParseAttributeArgsCommon(IdentifierInfo *AttrName, SourceLocation AttrNameLoc,
2137 ParsedAttributes &Attrs, SourceLocation *EndLoc,
2138 IdentifierInfo *ScopeName, SourceLocation ScopeLoc,
2139 ParsedAttr::Form Form);
2141 enum ParseAttrKindMask {
2143 PAKM_Declspec = 1 << 1,
2144 PAKM_CXX11 = 1 << 2,
2163 void ParseAttributes(
unsigned WhichAttrKinds, ParsedAttributes &Attrs,
2164 LateParsedAttrList *LateAttrs =
nullptr);
2167 bool MaybeParseAttributes(
unsigned WhichAttrKinds, ParsedAttributes &Attrs,
2168 LateParsedAttrList *LateAttrs =
nullptr) {
2169 if (Tok.isOneOf(tok::kw___attribute, tok::kw___declspec) ||
2170 isAllowedCXX11AttributeSpecifier()) {
2171 ParseAttributes(WhichAttrKinds, Attrs, LateAttrs);
2177 void MaybeParseGNUAttributes(Declarator &D,
2178 LateParsedAttrList *LateAttrs =
nullptr) {
2179 if (Tok.is(tok::kw___attribute)) {
2180 ParsedAttributes Attrs(AttrFactory);
2181 ParseGNUAttributes(Attrs, LateAttrs, &D);
2182 D.takeAttributesAppending(Attrs);
2186 bool MaybeParseGNUAttributes(ParsedAttributes &Attrs,
2187 LateParsedAttrList *LateAttrs =
nullptr) {
2188 if (Tok.is(tok::kw___attribute)) {
2189 ParseGNUAttributes(Attrs, LateAttrs);
2211 bool ParseSingleGNUAttribute(ParsedAttributes &Attrs, SourceLocation &EndLoc,
2212 LateParsedAttrList *LateAttrs =
nullptr,
2213 Declarator *D =
nullptr);
2258 void ParseGNUAttributes(ParsedAttributes &Attrs,
2259 LateParsedAttrList *LateAttrs =
nullptr,
2260 Declarator *D =
nullptr);
2264 void ParseGNUAttributeArgs(IdentifierInfo *AttrName,
2265 SourceLocation AttrNameLoc,
2266 ParsedAttributes &Attrs, SourceLocation *EndLoc,
2267 IdentifierInfo *ScopeName, SourceLocation ScopeLoc,
2268 ParsedAttr::Form Form, Declarator *D);
2269 IdentifierLoc *ParseIdentifierLoc();
2272 ParseClangAttributeArgs(IdentifierInfo *AttrName, SourceLocation AttrNameLoc,
2273 ParsedAttributes &Attrs, SourceLocation *EndLoc,
2274 IdentifierInfo *ScopeName, SourceLocation ScopeLoc,
2275 ParsedAttr::Form Form);
2277 void MaybeParseCXX11Attributes(Declarator &D) {
2278 if (isAllowedCXX11AttributeSpecifier()) {
2279 ParsedAttributes Attrs(AttrFactory);
2280 ParseCXX11Attributes(Attrs);
2281 D.takeAttributesAppending(Attrs);
2285 bool MaybeParseCXX11Attributes(ParsedAttributes &Attrs,
2286 bool OuterMightBeMessageSend =
false) {
2287 if (isAllowedCXX11AttributeSpecifier(
false, OuterMightBeMessageSend)) {
2288 ParseCXX11Attributes(Attrs);
2294 bool MaybeParseMicrosoftAttributes(ParsedAttributes &Attrs) {
2295 bool AttrsParsed =
false;
2297 Tok.is(tok::l_square)) {
2298 ParsedAttributes AttrsWithRange(AttrFactory);
2299 ParseMicrosoftAttributes(AttrsWithRange);
2300 AttrsParsed = !AttrsWithRange.empty();
2301 Attrs.takeAllAppendingFrom(AttrsWithRange);
2305 bool MaybeParseMicrosoftDeclSpecs(ParsedAttributes &Attrs) {
2306 if (
getLangOpts().DeclSpecKeyword && Tok.is(tok::kw___declspec)) {
2307 ParseMicrosoftDeclSpecs(Attrs);
2321 void ParseMicrosoftDeclSpecs(ParsedAttributes &Attrs);
2322 bool ParseMicrosoftDeclSpecArgs(IdentifierInfo *AttrName,
2323 SourceLocation AttrNameLoc,
2324 ParsedAttributes &Attrs);
2325 void ParseMicrosoftTypeAttributes(ParsedAttributes &attrs);
2326 void ParseWebAssemblyFuncrefTypeAttribute(ParsedAttributes &Attrs);
2327 void DiagnoseAndSkipExtendedMicrosoftTypeAttributes();
2328 SourceLocation SkipExtendedMicrosoftTypeAttributes();
2330 void ParseBorlandTypeAttributes(ParsedAttributes &attrs);
2331 void ParseOpenCLKernelAttributes(ParsedAttributes &attrs);
2332 void ParseOpenCLQualifiers(ParsedAttributes &Attrs);
2333 void ParseNullabilityTypeSpecifiers(ParsedAttributes &attrs);
2334 void ParseCUDAFunctionAttributes(ParsedAttributes &attrs);
2335 bool isHLSLQualifier(
const Token &Tok)
const;
2336 void ParseHLSLQualifiers(ParsedAttributes &Attrs);
2348 VersionTuple ParseVersionTuple(SourceRange &Range);
2377 void ParseAvailabilityAttribute(IdentifierInfo &Availability,
2378 SourceLocation AvailabilityLoc,
2379 ParsedAttributes &attrs,
2380 SourceLocation *endLoc,
2381 IdentifierInfo *ScopeName,
2382 SourceLocation ScopeLoc,
2383 ParsedAttr::Form Form);
2401 void ParseExternalSourceSymbolAttribute(IdentifierInfo &ExternalSourceSymbol,
2403 ParsedAttributes &Attrs,
2404 SourceLocation *EndLoc,
2405 IdentifierInfo *ScopeName,
2406 SourceLocation ScopeLoc,
2407 ParsedAttr::Form Form);
2422 void ParseObjCBridgeRelatedAttribute(IdentifierInfo &ObjCBridgeRelated,
2423 SourceLocation ObjCBridgeRelatedLoc,
2424 ParsedAttributes &Attrs,
2425 SourceLocation *EndLoc,
2426 IdentifierInfo *ScopeName,
2427 SourceLocation ScopeLoc,
2428 ParsedAttr::Form Form);
2430 void ParseSwiftNewTypeAttribute(IdentifierInfo &AttrName,
2431 SourceLocation AttrNameLoc,
2432 ParsedAttributes &Attrs,
2433 SourceLocation *EndLoc,
2434 IdentifierInfo *ScopeName,
2435 SourceLocation ScopeLoc,
2436 ParsedAttr::Form Form);
2438 void ParseTypeTagForDatatypeAttribute(IdentifierInfo &AttrName,
2439 SourceLocation AttrNameLoc,
2440 ParsedAttributes &Attrs,
2441 SourceLocation *EndLoc,
2442 IdentifierInfo *ScopeName,
2443 SourceLocation ScopeLoc,
2444 ParsedAttr::Form Form);
2446 void ParseAttributeWithTypeArg(IdentifierInfo &AttrName,
2447 SourceLocation AttrNameLoc,
2448 ParsedAttributes &Attrs,
2449 IdentifierInfo *ScopeName,
2450 SourceLocation ScopeLoc,
2451 ParsedAttr::Form Form);
2453 void DistributeCLateParsedAttrs(Decl *Dcl, LateParsedAttrList *LateAttrs);
2459 void ParseBoundsAttribute(IdentifierInfo &AttrName,
2460 SourceLocation AttrNameLoc, ParsedAttributes &Attrs,
2461 IdentifierInfo *ScopeName, SourceLocation ScopeLoc,
2462 ParsedAttr::Form Form);
2478 void ParseTypeofSpecifier(DeclSpec &DS);
2485 void ParseAtomicSpecifier(DeclSpec &DS);
2495 ExprResult ParseAlignArgument(StringRef KWName, SourceLocation Start,
2496 SourceLocation &EllipsisLoc,
bool &IsType,
2509 void ParseAlignmentSpecifier(ParsedAttributes &Attrs,
2510 SourceLocation *endLoc =
nullptr);
2519 void ParsePtrauthQualifier(ParsedAttributes &Attrs);
2524 class DeclaratorScopeObj {
2531 DeclaratorScopeObj(
Parser &p, CXXScopeSpec &ss)
2532 : P(p), SS(ss), EnteredScope(
false), CreatedScope(
false) {}
2534 void EnterDeclaratorScope() {
2535 assert(!EnteredScope &&
"Already entered the scope!");
2536 assert(SS.isSet() &&
"C++ scope was not set!");
2538 CreatedScope =
true;
2541 if (!P.Actions.ActOnCXXEnterDeclaratorScope(P.getCurScope(), SS))
2542 EnteredScope =
true;
2545 ~DeclaratorScopeObj() {
2547 assert(SS.isSet() &&
"C++ scope was cleared ?");
2548 P.Actions.ActOnCXXExitDeclaratorScope(P.getCurScope(), SS);
2556 void ParseDeclarator(Declarator &D);
2587 void ParseDeclaratorInternal(Declarator &D,
2588 DirectDeclParseFunction DirectDeclParser);
2590 enum AttrRequirements {
2591 AR_NoAttributesParsed = 0,
2592 AR_GNUAttributesParsedAndRejected = 1 << 0,
2593 AR_GNUAttributesParsed = 1 << 1,
2594 AR_CXX11AttributesParsed = 1 << 2,
2595 AR_DeclspecAttributesParsed = 1 << 3,
2596 AR_AllAttributesParsed = AR_GNUAttributesParsed | AR_CXX11AttributesParsed |
2597 AR_DeclspecAttributesParsed,
2598 AR_VendorAttributesParsed =
2599 AR_GNUAttributesParsed | AR_DeclspecAttributesParsed
2616 void ParseTypeQualifierListOpt(
2617 DeclSpec &DS,
unsigned AttrReqs = AR_AllAttributesParsed,
2618 bool AtomicOrPtrauthAllowed =
true,
bool IdentifierRequired =
false,
2619 llvm::function_ref<
void()> CodeCompletionHandler = {});
2669 void ParseDirectDeclarator(Declarator &D);
2670 void ParseDecompositionDeclarator(Declarator &D);
2688 void ParseParenDeclarator(Declarator &D);
2713 void ParseFunctionDeclarator(Declarator &D, ParsedAttributes &FirstArgAttrs,
2715 bool IsAmbiguous,
bool RequiresArg =
false);
2716 void InitCXXThisScopeForDeclaratorIfRelevant(
2717 const Declarator &D,
const DeclSpec &DS,
2718 std::optional<Sema::CXXThisScopeRAII> &ThisScope);
2722 bool ParseRefQualifier(
bool &RefQualifierIsLValueRef,
2723 SourceLocation &RefQualifierLoc);
2730 bool isFunctionDeclaratorIdentifierList();
2744 void ParseFunctionDeclaratorIdentifierList(
2745 Declarator &D, SmallVectorImpl<DeclaratorChunk::ParamInfo> &ParamInfo);
2746 void ParseParameterDeclarationClause(
2747 Declarator &D, ParsedAttributes &attrs,
2748 SmallVectorImpl<DeclaratorChunk::ParamInfo> &ParamInfo,
2749 SourceLocation &EllipsisLoc) {
2750 return ParseParameterDeclarationClause(
2751 D.getContext(), attrs, ParamInfo, EllipsisLoc,
2752 D.getCXXScopeSpec().isSet() &&
2753 D.isFunctionDeclaratorAFunctionDeclaration());
2791 void ParseParameterDeclarationClause(
2793 SmallVectorImpl<DeclaratorChunk::ParamInfo> &ParamInfo,
2794 SourceLocation &EllipsisLoc,
bool IsACXXFunctionDeclaration =
false);
2805 void ParseBracketDeclarator(Declarator &D);
2808 void ParseMisplacedBracketDeclarator(Declarator &D);
2819 TypeResult ParseTypeFromString(StringRef TypeStr, StringRef Context,
2820 SourceLocation IncludeLoc);
2836 mutable IdentifierInfo *Ident_sealed;
2837 mutable IdentifierInfo *Ident_abstract;
2840 mutable IdentifierInfo *Ident_final;
2841 mutable IdentifierInfo *Ident_GNU_final;
2842 mutable IdentifierInfo *Ident_override;
2847 struct ParsingClass {
2848 ParsingClass(Decl *TagOrTemplate,
bool TopLevelClass,
bool IsInterface)
2849 : TopLevelClass(TopLevelClass), IsInterface(IsInterface),
2850 TagOrTemplate(TagOrTemplate) {}
2854 bool TopLevelClass : 1;
2857 bool IsInterface : 1;
2860 Decl *TagOrTemplate;
2865 LateParsedDeclarationsContainer LateParsedDeclarations;
2871 std::stack<ParsingClass *> ClassStack;
2873 ParsingClass &getCurrentClass() {
2874 assert(!ClassStack.empty() &&
"No lexed method stacks!");
2875 return *ClassStack.top();
2879 class ParsingClassDefinition {
2885 ParsingClassDefinition(
Parser &P, Decl *TagOrTemplate,
bool TopLevelClass,
2887 : P(P), Popped(
false),
2888 State(P.PushParsingClass(TagOrTemplate, TopLevelClass, IsInterface)) {
2893 assert(!Popped &&
"Nested class has already been popped");
2895 P.PopParsingClass(State);
2898 ~ParsingClassDefinition() {
2900 P.PopParsingClass(State);
2916 bool Delayed, SourceRange &SpecificationRange,
2917 SmallVectorImpl<ParsedType> &DynamicExceptions,
2918 SmallVectorImpl<SourceRange> &DynamicExceptionRanges,
2936 ParseDynamicExceptionSpecification(SourceRange &SpecificationRange,
2937 SmallVectorImpl<ParsedType> &Exceptions,
2938 SmallVectorImpl<SourceRange> &Ranges);
2945 TypeResult ParseTrailingReturnType(SourceRange &Range,
2946 bool MayBeFollowedByDirectInit);
2949 void ParseTrailingRequiresClause(Declarator &D);
2951 void ParseMicrosoftIfExistsClassDeclaration(
DeclSpec::TST TagType,
2952 ParsedAttributes &AccessAttrs,
2955 SourceLocation ParsePackIndexingType(DeclSpec &DS);
2956 void AnnotateExistingIndexedTypeNamePack(
ParsedType T,
2957 SourceLocation StartLoc,
2958 SourceLocation EndLoc);
2965 bool isAllowedCXX11AttributeSpecifier(
bool Disambiguate =
false,
2966 bool OuterMightBeMessageSend =
false) {
2967 return (Tok.isRegularKeywordAttribute() ||
2968 isCXX11AttributeSpecifier(Disambiguate, OuterMightBeMessageSend) !=
2975 SourceLocation SkipCXX11Attributes();
2979 void DiagnoseAndSkipCXX11Attributes();
2981 void ParseOpenMPAttributeArgs(
const IdentifierInfo *AttrName,
3010 void ParseCXX11AttributeSpecifierInternal(ParsedAttributes &Attrs,
3012 SourceLocation *EndLoc =
nullptr);
3013 void ParseCXX11AttributeSpecifier(ParsedAttributes &Attrs,
3014 SourceLocation *EndLoc =
nullptr) {
3016 ParseCXX11AttributeSpecifierInternal(Attrs, OpenMPTokens, EndLoc);
3017 ReplayOpenMPAttributeTokens(OpenMPTokens);
3026 void ParseCXX11Attributes(ParsedAttributes &attrs);
3046 bool ParseCXX11AttributeArgs(IdentifierInfo *AttrName,
3047 SourceLocation AttrNameLoc,
3048 ParsedAttributes &Attrs, SourceLocation *EndLoc,
3049 IdentifierInfo *ScopeName,
3050 SourceLocation ScopeLoc,
3056 ParseCXXAssumeAttributeArg(ParsedAttributes &Attrs, IdentifierInfo *AttrName,
3057 SourceLocation AttrNameLoc,
3058 IdentifierInfo *ScopeName, SourceLocation ScopeLoc,
3059 SourceLocation *EndLoc, ParsedAttr::Form Form);
3070 IdentifierInfo *TryParseCXX11AttributeIdentifier(
3071 SourceLocation &Loc,
3074 const IdentifierInfo *EnclosingScope =
nullptr);
3077 void ParseMicrosoftUuidAttributeArgs(ParsedAttributes &Attrs);
3089 void ParseMicrosoftAttributes(ParsedAttributes &Attrs);
3091 void ParseMicrosoftInheritanceClassAttributes(ParsedAttributes &attrs);
3092 void ParseNullabilityClassAttributes(ParsedAttributes &attrs);
3101 SourceLocation ParseDecltypeSpecifier(DeclSpec &DS);
3102 void AnnotateExistingDecltypeSpecifier(
const DeclSpec &DS,
3103 SourceLocation StartLoc,
3104 SourceLocation EndLoc);
3117 return isCXX11VirtSpecifier(Tok);
3127 void ParseOptionalCXX11VirtSpecifierSeq(VirtSpecifiers &VS,
bool IsInterface,
3128 SourceLocation FriendLoc);
3132 bool isCXX11FinalKeyword()
const;
3138 bool isClassCompatibleKeyword()
const;
3140 bool MaybeParseTypeTransformTypeSpecifier(DeclSpec &DS);
3143 void DiagnoseUnexpectedNamespace(NamedDecl *Context);
3175 SourceLocation &DeclEnd,
3176 SourceLocation InlineLoc = SourceLocation());
3178 struct InnerNamespaceInfo {
3179 SourceLocation NamespaceLoc;
3180 SourceLocation InlineLoc;
3181 SourceLocation IdentLoc;
3182 IdentifierInfo *Ident;
3184 using InnerNamespaceInfoList = llvm::SmallVector<InnerNamespaceInfo, 4>;
3187 void ParseInnerNamespace(
const InnerNamespaceInfoList &InnerNSs,
3188 unsigned int index, SourceLocation &InlineLoc,
3189 ParsedAttributes &attrs,
3221 Decl *ParseExportDeclaration();
3227 SourceLocation &DeclEnd, ParsedAttributes &Attrs);
3242 SourceLocation &DeclEnd, ParsedAttributes &attrs);
3244 struct UsingDeclarator {
3245 SourceLocation TypenameLoc;
3248 SourceLocation EllipsisLoc;
3251 TypenameLoc = EllipsisLoc = SourceLocation();
3292 const ParsedTemplateInfo &TemplateInfo,
3293 SourceLocation UsingLoc,
3294 SourceLocation &DeclEnd,
3295 ParsedAttributes &Attrs,
3297 Decl *ParseAliasDeclarationAfterDeclarator(
3298 const ParsedTemplateInfo &TemplateInfo, SourceLocation UsingLoc,
3300 ParsedAttributes &Attrs, Decl **OwnedType =
nullptr);
3313 Decl *ParseStaticAssertDeclaration(SourceLocation &DeclEnd);
3318 Decl *ParseNamespaceAlias(SourceLocation NamespaceLoc,
3319 SourceLocation AliasLoc, IdentifierInfo *Alias,
3320 SourceLocation &DeclEnd);
3328 bool isValidAfterTypeSpecifier(
bool CouldBeBitfield);
3372 void ParseClassSpecifier(
tok::TokenKind TagTokKind, SourceLocation TagLoc,
3373 DeclSpec &DS, ParsedTemplateInfo &TemplateInfo,
3375 DeclSpecContext DSC, ParsedAttributes &Attributes);
3376 void SkipCXXMemberSpecification(SourceLocation StartLoc,
3377 SourceLocation AttrFixitLoc,
unsigned TagType,
3388 void ParseCXXMemberSpecification(SourceLocation StartLoc,
3389 SourceLocation AttrFixitLoc,
3390 ParsedAttributes &Attrs,
unsigned TagType,
3415 ExprResult ParseCXXMemberInitializer(Decl *D,
bool IsFunction,
3416 SourceLocation &EqualLoc);
3420 bool ParseCXXMemberDeclaratorBeforeInitializer(Declarator &DeclaratorInfo,
3423 LateParsedAttrList &LateAttrs);
3428 MaybeParseAndDiagnoseDeclSpecAfterCXX11VirtSpecifierSeq(Declarator &D,
3429 VirtSpecifiers &VS);
3485 ParsedTemplateInfo &TemplateInfo,
3486 ParsingDeclRAIIObject *DiagsFromTParams =
nullptr);
3489 ParsedAttributes &AccessAttrs,
3515 void ParseConstructorInitializer(Decl *ConstructorDecl);
3537 void HandleMemberFunctionDeclDelays(Declarator &DeclaratorInfo,
3565 TypeResult ParseBaseTypeSpecifier(SourceLocation &BaseLoc,
3566 SourceLocation &EndLocation);
3578 void ParseBaseClause(Decl *ClassDecl);
3593 BaseResult ParseBaseSpecifier(Decl *ClassDecl);
3609 bool isClassCompatibleKeyword(Token Tok)
const;
3611 void ParseHLSLRootSignatureAttributeArgs(ParsedAttributes &Attrs);
3786 bool GreaterThanIsOperator;
3790 llvm::SmallDenseMap<IdentifierInfo *, tok::TokenKind> RevertibleTypeTraits;
3809 PushParsingClass(
Decl *TagOrTemplate,
bool TopLevelClass,
bool IsInterface);
3813 void DeallocateParsedClasses(ParsingClass *
Class);
4031 bool isAddressOfOperand,
bool &NotCastExpr,
4033 bool isVectorLiteral =
false,
4034 bool *NotPrimaryExpression =
nullptr);
4036 bool isAddressOfOperand =
false,
4039 bool isVectorLiteral =
false,
4040 bool *NotPrimaryExpression =
nullptr);
4043 bool isNotExpressionStart();
4047 bool isPostfixExpressionSuffixStart() {
4049 return (K == tok::l_square || K == tok::l_paren || K == tok::period ||
4050 K == tok::arrow || K == tok::plusplus || K == tok::minusminus);
4092 ExprResult ParseUnaryExprOrTypeTraitExpression();
4121 ExprResult ParseSYCLUniqueStableNameExpression();
4183 llvm::function_ref<
void()> ExpressionStarts =
4184 llvm::function_ref<
void()>(),
4185 bool FailImmediatelyOnInvalidExpr =
false);
4230 bool StopIfCastExpr,
4267 ExprResult ParseGenericSelectionExpression();
4286 void injectEmbedTokens();
4312 ExprResult ParseAssignmentExprWithObjCMessageExprStart(
4314 Expr *ReceiverExpr);
4319 bool isKnownToBeDeclarationSpecifier() {
4333 bool isTypeIdForGenericSelection() {
4339 return isTypeSpecifierQualifier();
4345 bool isTypeIdUnambiguously() {
4350 return isTypeSpecifierQualifier();
4359 void ParseBlockId(SourceLocation CaretLoc);
4368 std::optional<AvailabilitySpec> ParseAvailabilitySpec();
4369 ExprResult ParseAvailabilityCheckExpr(SourceLocation StartLoc);
4375 bool tryParseOpenMPArrayShapingCastPart();
4377 ExprResult ParseBuiltinPtrauthTypeDiscriminator();
4430 bool ObjectHadErrors,
bool EnteringContext,
4431 bool AllowDestructorName,
bool AllowConstructorName,
4432 bool AllowDeductionGuide,
4433 SourceLocation *TemplateKWLoc, UnqualifiedId &
Result);
4451 ExprResult tryParseCXXIdExpression(CXXScopeSpec &SS,
bool isAddressOfOperand,
4452 Token &Replacement);
4503 ExprResult ParseCXXIdExpression(
bool isAddressOfOperand =
false);
4506 bool areTokensAdjacent(
const Token &A,
const Token &B);
4510 void CheckForTemplateAndDigraph(Token &
Next,
ParsedType ObjectTypePtr,
4511 bool EnteringContext, IdentifierInfo &II,
4566 bool ParseOptionalCXXScopeSpecifier(
4567 CXXScopeSpec &SS,
ParsedType ObjectType,
bool ObjectHasErrors,
4568 bool EnteringContext,
bool *MayBePseudoDestructor =
nullptr,
4569 bool IsTypename =
false,
const IdentifierInfo **LastII =
nullptr,
4570 bool OnlyNamespace =
false,
bool InUsingDeclaration =
false,
4571 bool Disambiguation =
false);
4577 enum class LambdaIntroducerTentativeParse {
4655 ParseLambdaIntroducer(LambdaIntroducer &Intro,
4656 LambdaIntroducerTentativeParse *Tentative =
nullptr);
4660 ExprResult ParseLambdaExpressionAfterIntroducer(LambdaIntroducer &Intro);
4744 ExprResult ParseCXXPseudoDestructor(Expr *Base, SourceLocation OpLoc,
4799 ExprResult ParseCXXTypeConstructExpression(
const DeclSpec &DS);
4829 void ParseCXXSimpleTypeSpecifier(DeclSpec &DS);
4844 bool ParseCXXTypeSpecifierSeq(
4862 bool ParseExpressionListOrTypeId(SmallVectorImpl<Expr *> &Exprs,
4874 void ParseDirectNewDeclarator(Declarator &D);
4907 ExprResult ParseCXXNewExpression(
bool UseGlobal, SourceLocation Start);
4922 ExprResult ParseCXXDeleteExpression(
bool UseGlobal, SourceLocation Start);
4961 Sema::ConditionResult ParseCXXCondition(
StmtResult *InitStmt,
4965 ForRangeInfo *FRI =
nullptr,
4966 bool EnterForConditionScope =
false);
4968 ParsedAttributes &Attrs);
5015 bool isTypeIdInParens(
bool &isAmbiguous) {
5018 isAmbiguous =
false;
5019 return isTypeSpecifierQualifier();
5021 bool isTypeIdInParens() {
5023 return isTypeIdInParens(isAmbiguous);
5061 bool ParseUnqualifiedIdTemplateId(CXXScopeSpec &SS,
ParsedType ObjectType,
5062 bool ObjectHadErrors,
5063 SourceLocation TemplateKWLoc,
5064 IdentifierInfo *Name,
5065 SourceLocation NameLoc,
5066 bool EnteringContext, UnqualifiedId &Id,
5067 bool AssumeTemplateId);
5109 bool ParseUnqualifiedIdOperator(CXXScopeSpec &SS,
bool EnteringContext,
5176 bool MaybeParseHLSLAnnotations(Declarator &D,
5177 SourceLocation *EndLoc =
nullptr,
5178 bool CouldBeBitField =
false) {
5179 assert(
getLangOpts().
HLSL &&
"MaybeParseHLSLAnnotations is for HLSL only");
5180 if (Tok.is(tok::colon)) {
5181 ParsedAttributes Attrs(AttrFactory);
5182 ParseHLSLAnnotations(Attrs, EndLoc, CouldBeBitField);
5183 D.takeAttributesAppending(Attrs);
5189 void MaybeParseHLSLAnnotations(ParsedAttributes &Attrs,
5190 SourceLocation *EndLoc =
nullptr) {
5191 assert(
getLangOpts().
HLSL &&
"MaybeParseHLSLAnnotations is for HLSL only");
5192 if (Tok.is(tok::colon))
5193 ParseHLSLAnnotations(Attrs, EndLoc);
5196 struct ParsedSemantic {
5197 StringRef Name =
"";
5199 bool Explicit =
false;
5202 ParsedSemantic ParseHLSLSemantic();
5204 void ParseHLSLAnnotations(ParsedAttributes &Attrs,
5205 SourceLocation *EndLoc =
nullptr,
5206 bool CouldBeBitField =
false);
5207 Decl *ParseHLSLBuffer(SourceLocation &DeclEnd, ParsedAttributes &Attrs);
5231 ExprResult ParseInitializer(Decl *DeclForInitializer =
nullptr);
5236 bool MayBeDesignationStart();
5254 struct DesignatorCompletionInfo {
5255 SmallVectorImpl<Expr *> &InitExprs;
5256 QualType PreferredBaseType;
5305 ExprResult ParseInitializerWithPotentialDesignator(DesignatorCompletionInfo);
5310 typedef SmallVector<Expr *, 12> ExprVector;
5314 bool ParseMicrosoftIfExistsBraceInitializer(ExprVector &InitExprs,
5331 friend class ObjCDeclContextSwitch;
5334 return Actions.ObjC().getObjCDeclContext();
5340 return Actions.getNullabilityKeyword(nullability);
5356 bool InMessageExpression;
5363 bool ParsingInObjCContainer;
5368 bool isObjCInstancetype() {
5370 if (
Tok.isAnnotation())
5372 if (!Ident_instancetype)
5374 return Tok.getIdentifierInfo() == Ident_instancetype;
5382 ObjCContainerDecl *DC;
5383 SaveAndRestore<bool> WithinObjCContainer;
5388 WithinObjCContainer(P.ParsingInObjCContainer, DC !=
nullptr) {
5390 P.Actions.ObjC().ActOnObjCTemporaryExitContainerContext(DC);
5392 ~ObjCDeclContextSwitch() {
5394 P.Actions.ObjC().ActOnObjCReenterContainerContext(DC);
5398 void CheckNestedObjCContexts(SourceLocation AtLoc);
5400 void ParseLexedObjCMethodDefs(LexedMethod &LM,
bool parseMethod);
5418 DeclGroupPtrTy ParseObjCAtDirectives(ParsedAttributes &DeclAttrs,
5419 ParsedAttributes &DeclSpecAttrs);
5430 DeclGroupPtrTy ParseObjCAtClassDeclaration(SourceLocation atLoc);
5463 Decl *ParseObjCAtInterfaceDeclaration(SourceLocation AtLoc,
5464 ParsedAttributes &prefixAttrs);
5470 ObjCTypeParamList *parseObjCTypeParamList();
5498 ObjCTypeParamList *parseObjCTypeParamListOrProtocolRefs(
5500 SmallVectorImpl<IdentifierLoc> &protocolIdents, SourceLocation &rAngleLoc,
5501 bool mayBeProtocolList =
true);
5503 void HelperActionsForIvarDeclarations(ObjCContainerDecl *interfaceDecl,
5504 SourceLocation atLoc,
5506 SmallVectorImpl<Decl *> &AllIvarDecls,
5507 bool RBraceMissing);
5532 void ParseObjCClassInstanceVariables(ObjCContainerDecl *interfaceDecl,
5534 SourceLocation atLoc);
5541 bool ParseObjCProtocolReferences(
5542 SmallVectorImpl<Decl *> &P, SmallVectorImpl<SourceLocation> &PLocs,
5543 bool WarnOnDeclarations,
bool ForObjCContainer, SourceLocation &LAngleLoc,
5544 SourceLocation &EndProtoLoc,
bool consumeLastToken);
5555 void parseObjCTypeArgsOrProtocolQualifiers(
5556 ParsedType baseType, SourceLocation &typeArgsLAngleLoc,
5557 SmallVectorImpl<ParsedType> &typeArgs, SourceLocation &typeArgsRAngleLoc,
5558 SourceLocation &protocolLAngleLoc, SmallVectorImpl<Decl *> &protocols,
5559 SmallVectorImpl<SourceLocation> &protocolLocs,
5560 SourceLocation &protocolRAngleLoc,
bool consumeLastToken,
5561 bool warnOnIncompleteProtocols);
5565 void parseObjCTypeArgsAndProtocolQualifiers(
5566 ParsedType baseType, SourceLocation &typeArgsLAngleLoc,
5567 SmallVectorImpl<ParsedType> &typeArgs, SourceLocation &typeArgsRAngleLoc,
5568 SourceLocation &protocolLAngleLoc, SmallVectorImpl<Decl *> &protocols,
5569 SmallVectorImpl<SourceLocation> &protocolLocs,
5570 SourceLocation &protocolRAngleLoc,
bool consumeLastToken);
5574 TypeResult parseObjCProtocolQualifierType(SourceLocation &rAngleLoc);
5578 TypeResult parseObjCTypeArgsAndProtocolQualifiers(SourceLocation loc,
5580 bool consumeLastToken,
5581 SourceLocation &endLoc);
5617 DeclGroupPtrTy ParseObjCAtProtocolDeclaration(SourceLocation atLoc,
5618 ParsedAttributes &prefixAttrs);
5620 struct ObjCImplParsingDataRAII {
5624 typedef SmallVector<LexedMethod *, 8> LateParsedObjCMethodContainer;
5625 LateParsedObjCMethodContainer LateParsedObjCMethods;
5627 ObjCImplParsingDataRAII(
Parser &parser, Decl *D)
5628 : P(parser), Dcl(D), HasCFunction(
false) {
5629 P.CurParsedObjCImpl =
this;
5632 ~ObjCImplParsingDataRAII();
5634 void finish(SourceRange AtEnd);
5635 bool isFinished()
const {
return Finished; }
5640 ObjCImplParsingDataRAII *CurParsedObjCImpl;
5644 void StashAwayMethodOrFunctionBodyTokens(Decl *MDecl);
5658 DeclGroupPtrTy ParseObjCAtImplementationDeclaration(SourceLocation AtLoc,
5659 ParsedAttributes &Attrs);
5667 Decl *ParseObjCAtAliasDeclaration(SourceLocation atLoc);
5682 Decl *ParseObjCPropertySynthesize(SourceLocation atLoc);
5693 Decl *ParseObjCPropertyDynamic(SourceLocation atLoc);
5705 IdentifierInfo *ParseObjCSelectorPiece(SourceLocation &MethodLocation);
5713 bool isTokIdentifier_in()
const;
5722 ParsedAttributes *ParamAttrs);
5736 Decl *ParseObjCMethodPrototype(
5738 bool MethodDefinition =
true);
5770 Decl *ParseObjCMethodDecl(
5773 bool MethodDefinition =
true);
5803 void ParseObjCPropertyAttribute(ObjCDeclSpec &DS);
5809 Decl *ParseObjCMethodDefinition();
5813 ExprResult ParseObjCAtExpression(SourceLocation AtLocation);
5814 ExprResult ParseObjCStringLiteral(SourceLocation AtLoc);
5821 ExprResult ParseObjCCharacterLiteral(SourceLocation AtLoc);
5830 ExprResult ParseObjCNumericLiteral(SourceLocation AtLoc);
5839 ExprResult ParseObjCBooleanLiteral(SourceLocation AtLoc,
bool ArgValue);
5841 ExprResult ParseObjCArrayLiteral(SourceLocation AtLoc);
5842 ExprResult ParseObjCDictionaryLiteral(SourceLocation AtLoc);
5849 ExprResult ParseObjCBoxedExpr(SourceLocation AtLoc);
5855 ExprResult ParseObjCEncodeExpression(SourceLocation AtLoc);
5861 ExprResult ParseObjCSelectorExpression(SourceLocation AtLoc);
5867 ExprResult ParseObjCProtocolExpression(SourceLocation AtLoc);
5874 bool isSimpleObjCMessageExpression();
5929 ExprResult ParseObjCMessageExpressionBody(SourceLocation LBracloc,
5930 SourceLocation SuperLoc,
5932 Expr *ReceiverExpr);
5958 bool ParseObjCXXMessageReceiver(
bool &IsExpr,
void *&TypeOrExpr);
5963 enum class ParsedStmtContext;
5965 StmtResult ParseObjCAtStatement(SourceLocation atLoc,
5966 ParsedStmtContext StmtCtx);
5981 StmtResult ParseObjCTryStmt(SourceLocation atLoc);
5988 StmtResult ParseObjCThrowStmt(SourceLocation atLoc);
5995 StmtResult ParseObjCSynchronizedStmt(SourceLocation atLoc);
6002 StmtResult ParseObjCAutoreleasePoolStmt(SourceLocation atLoc);
6029 bool isStartOfObjCClassMessageMissingOpenBracket();
6061 bool OpenACCDirectiveParsing =
false;
6065 bool AllowOpenACCArraySections =
false;
6069 class OpenACCArraySectionRAII {
6073 OpenACCArraySectionRAII(
Parser &P) : P(P) {
6074 assert(!P.AllowOpenACCArraySections);
6075 P.AllowOpenACCArraySections =
true;
6077 ~OpenACCArraySectionRAII() {
6078 assert(P.AllowOpenACCArraySections);
6079 P.AllowOpenACCArraySections =
false;
6086 struct OpenACCDirectiveParseInfo {
6088 SourceLocation StartLoc;
6089 SourceLocation DirLoc;
6090 SourceLocation LParenLoc;
6091 SourceLocation RParenLoc;
6092 SourceLocation EndLoc;
6093 SourceLocation MiscLoc;
6095 SmallVector<Expr *> Exprs;
6096 SmallVector<OpenACCClause *> Clauses;
6101 struct OpenACCWaitParseInfo {
6102 bool Failed =
false;
6103 Expr *DevNumExpr =
nullptr;
6104 SourceLocation QueuesLoc;
6105 SmallVector<Expr *> QueueIdExprs;
6107 SmallVector<Expr *> getAllExprs() {
6108 SmallVector<Expr *>
Out;
6109 Out.push_back(DevNumExpr);
6110 llvm::append_range(Out, QueueIdExprs);
6114 struct OpenACCCacheParseInfo {
6115 bool Failed =
false;
6116 SourceLocation ReadOnlyLoc;
6117 SmallVector<Expr *> Vars;
6122 enum class OpenACCParseCanContinue { Cannot = 0, Can = 1 };
6128 using OpenACCClauseParseResult =
6129 llvm::PointerIntPair<OpenACCClause *, 1, OpenACCParseCanContinue>;
6131 OpenACCClauseParseResult OpenACCCanContinue();
6132 OpenACCClauseParseResult OpenACCCannotContinue();
6133 OpenACCClauseParseResult OpenACCSuccess(OpenACCClause *Clause);
6137 OpenACCDirectiveParseInfo ParseOpenACCDirective();
6147 OpenACCCacheParseInfo ParseOpenACCCacheVarList();
6153 using OpenACCVarParseResult = std::pair<ExprResult, OpenACCParseCanContinue>;
6179 OpenACCClauseParseResult
6180 ParseOpenACCClauseParams(ArrayRef<const OpenACCClause *> ExistingClauses,
6182 SourceLocation ClauseLoc);
6186 OpenACCClauseParseResult
6187 ParseOpenACCClause(ArrayRef<const OpenACCClause *> ExistingClauses,
6197 SmallVector<OpenACCClause *>
6206 OpenACCWaitParseInfo ParseOpenACCWaitArgument(SourceLocation Loc,
6211 std::variant<std::monostate, StringLiteral *, IdentifierInfo *>
6212 ParseOpenACCBindClauseArgument();
6217 using OpenACCIntExprParseResult =
6218 std::pair<ExprResult, OpenACCParseCanContinue>;
6223 SourceLocation Loc);
6228 llvm::SmallVectorImpl<Expr *> &IntExprs);
6241 bool ParseOpenACCDeviceTypeList(llvm::SmallVector<IdentifierLoc> &Archs);
6255 SourceLocation Loc);
6270 llvm::SmallVectorImpl<Expr *> &SizeExprs);
6282 bool ParseOpenACCGangArgList(SourceLocation GangLoc,
6283 llvm::SmallVectorImpl<OpenACCGangKind> &GKs,
6284 llvm::SmallVectorImpl<Expr *> &IntExprs);
6286 using OpenACCGangArgRes = std::pair<OpenACCGangKind, ExprResult>;
6290 OpenACCGangArgRes ParseOpenACCGangArg(SourceLocation GangLoc);
6294 ParseOpenACCAfterRoutineDecl(
AccessSpecifier &AS, ParsedAttributes &Attrs,
6296 OpenACCDirectiveParseInfo &DirInfo);
6297 StmtResult ParseOpenACCAfterRoutineStmt(OpenACCDirectiveParseInfo &DirInfo);
6315 bool OpenMPDirectiveParsing =
false;
6320 void ReplayOpenMPAttributeTokens(
CachedTokens &OpenMPTokens) {
6323 if (!OpenMPTokens.empty()) {
6324 PP.EnterToken(Tok,
true);
6325 PP.EnterTokenStream(OpenMPTokens,
true,
6337 SourceLocation Loc);
6342 llvm::omp::TraitSet
Set,
6343 llvm::omp::TraitSelector Selector,
6344 llvm::StringMap<SourceLocation> &Seen);
6348 llvm::omp::TraitSet
Set,
6349 llvm::StringMap<SourceLocation> &Seen);
6353 llvm::StringMap<SourceLocation> &Seen);
6357 llvm::omp::TraitSet
Set,
6358 llvm::StringMap<SourceLocation> &Seen);
6366 llvm::omp::TraitSet
Set,
6367 llvm::StringMap<SourceLocation> &SeenSelectors);
6374 void parseOMPContextSelectorSet(
OMPTraitSet &TISet,
6375 llvm::StringMap<SourceLocation> &SeenSets);
6382 bool parseOMPContextSelectors(SourceLocation Loc,
OMPTraitInfo &TI);
6385 bool parseOpenMPAppendArgs(SmallVectorImpl<OMPInteropInfo> &InteropInfos);
6389 bool parseOMPDeclareVariantMatchClause(SourceLocation Loc,
OMPTraitInfo &TI,
6395 SourceLocation Loc);
6414 void ParseOpenMPAssumesDirective(OpenMPDirectiveKind DKind,
6415 SourceLocation Loc);
6418 void ParseOpenMPEndAssumesDirective(SourceLocation Loc);
6435 void ParseOpenMPClauses(OpenMPDirectiveKind DKind,
6436 SmallVectorImpl<clang::OMPClause *> &Clauses,
6437 SourceLocation Loc);
6440 void ParseOMPDeclareTargetClauses(SemaOpenMP::DeclareTargetContextInfo &DTCI);
6443 void ParseOMPEndDeclareTargetDirective(OpenMPDirectiveKind BeginDKind,
6444 OpenMPDirectiveKind EndDKind,
6445 SourceLocation Loc);
6449 void skipUntilPragmaOpenMPEnd(OpenMPDirectiveKind DKind);
6455 void parseOMPEndDirective(OpenMPDirectiveKind BeginKind,
6456 OpenMPDirectiveKind ExpectedKind,
6457 OpenMPDirectiveKind FoundKind,
6458 SourceLocation MatchingLoc, SourceLocation FoundLoc,
6459 bool SkipUntilOpenMPEnd);
6500 AccessSpecifier &AS, ParsedAttributes &Attrs,
bool Delayed =
false,
6502 Decl *TagDecl =
nullptr);
6516 DeclGroupPtrTy ParseOpenMPDeclareReductionDirective(AccessSpecifier AS);
6520 void ParseOpenMPReductionInitializerForDecl(VarDecl *OmpPrivParm);
6532 DeclGroupPtrTy ParseOpenMPDeclareMapperDirective(AccessSpecifier AS);
6535 TypeResult parseOpenMPDeclareMapperVarDecl(SourceRange &Range,
6536 DeclarationName &Name,
6537 AccessSpecifier AS =
AS_none);
6551 bool ParseOpenMPSimpleVarList(
6552 OpenMPDirectiveKind Kind,
6553 const llvm::function_ref<
void(CXXScopeSpec &, DeclarationNameInfo)>
6555 bool AllowScopeSpecifier);
6604 StmtResult ParseOpenMPDeclarativeOrExecutableDirective(
6605 ParsedStmtContext StmtCtx,
bool ReadDirectiveWithinMetadirective =
false);
6615 ParseOpenMPExecutableDirective(ParsedStmtContext StmtCtx,
6616 OpenMPDirectiveKind DKind, SourceLocation Loc,
6617 bool ReadDirectiveWithinMetadirective);
6626 StmtResult ParseOpenMPInformationalDirective(
6627 ParsedStmtContext StmtCtx, OpenMPDirectiveKind DKind, SourceLocation Loc,
6628 bool ReadDirectiveWithinMetadirective);
6657 OMPClause *ParseOpenMPClause(OpenMPDirectiveKind DKind,
6742 bool ParseOpenMPIndirectClause(SemaOpenMP::DeclareTargetContextInfo &DTCI,
6767 OMPClause *ParseOpenMPSingleExprWithArgClause(OpenMPDirectiveKind DKind,
6772 OMPClause *ParseOpenMPLoopRangeClause();
6778 OMPClause *ParseOpenMPPermutationClause();
6882 OMPClause *ParseOpenMPVarListClause(OpenMPDirectiveKind DKind,
6896 SourceLocation &ClauseNameLoc,
6897 SourceLocation &OpenLoc,
6898 SourceLocation &CloseLoc,
6899 SmallVectorImpl<Expr *> &Exprs,
6900 bool ReqIntConst =
false);
6915 OMPClause *ParseOpenMPUsesAllocatorClause(OpenMPDirectiveKind DKind);
6918 bool ParseOMPInteropInfo(OMPInteropInfo &InteropInfo,
OpenMPClauseKind Kind);
6956 OMPClause *ParseOpenMPOMPXAttributesClause(
bool ParseOnly);
6963 bool IsAddressOfOperand =
false);
6967 SemaOpenMP::OpenMPVarListDataTy &
Data,
6968 const LangOptions &LangOpts);
6971 SmallVectorImpl<Expr *> &Vars,
6972 SemaOpenMP::OpenMPVarListDataTy &
Data);
7007 std::unique_ptr<PragmaHandler> AlignHandler;
7008 std::unique_ptr<PragmaHandler> GCCVisibilityHandler;
7009 std::unique_ptr<PragmaHandler> OptionsHandler;
7010 std::unique_ptr<PragmaHandler> PackHandler;
7011 std::unique_ptr<PragmaHandler> MSStructHandler;
7012 std::unique_ptr<PragmaHandler> UnusedHandler;
7013 std::unique_ptr<PragmaHandler> WeakHandler;
7014 std::unique_ptr<PragmaHandler> RedefineExtnameHandler;
7015 std::unique_ptr<PragmaHandler> FPContractHandler;
7016 std::unique_ptr<PragmaHandler> OpenCLExtensionHandler;
7017 std::unique_ptr<PragmaHandler> OpenMPHandler;
7018 std::unique_ptr<PragmaHandler> OpenACCHandler;
7019 std::unique_ptr<PragmaHandler> PCSectionHandler;
7020 std::unique_ptr<PragmaHandler> MSCommentHandler;
7021 std::unique_ptr<PragmaHandler> MSDetectMismatchHandler;
7022 std::unique_ptr<PragmaHandler> FPEvalMethodHandler;
7023 std::unique_ptr<PragmaHandler> FloatControlHandler;
7024 std::unique_ptr<PragmaHandler> MSPointersToMembers;
7025 std::unique_ptr<PragmaHandler> MSVtorDisp;
7026 std::unique_ptr<PragmaHandler> MSInitSeg;
7027 std::unique_ptr<PragmaHandler> MSDataSeg;
7028 std::unique_ptr<PragmaHandler> MSBSSSeg;
7029 std::unique_ptr<PragmaHandler> MSConstSeg;
7030 std::unique_ptr<PragmaHandler> MSCodeSeg;
7031 std::unique_ptr<PragmaHandler> MSSection;
7032 std::unique_ptr<PragmaHandler> MSStrictGuardStackCheck;
7033 std::unique_ptr<PragmaHandler> MSRuntimeChecks;
7034 std::unique_ptr<PragmaHandler> MSIntrinsic;
7035 std::unique_ptr<PragmaHandler> MSFunction;
7036 std::unique_ptr<PragmaHandler> MSOptimize;
7037 std::unique_ptr<PragmaHandler> MSFenvAccess;
7038 std::unique_ptr<PragmaHandler> MSAllocText;
7039 std::unique_ptr<PragmaHandler> CUDAForceHostDeviceHandler;
7040 std::unique_ptr<PragmaHandler> OptimizeHandler;
7041 std::unique_ptr<PragmaHandler> LoopHintHandler;
7042 std::unique_ptr<PragmaHandler> UnrollHintHandler;
7043 std::unique_ptr<PragmaHandler> NoUnrollHintHandler;
7044 std::unique_ptr<PragmaHandler> UnrollAndJamHintHandler;
7045 std::unique_ptr<PragmaHandler> NoUnrollAndJamHintHandler;
7046 std::unique_ptr<PragmaHandler> FPHandler;
7047 std::unique_ptr<PragmaHandler> STDCFenvAccessHandler;
7048 std::unique_ptr<PragmaHandler> STDCFenvRoundHandler;
7049 std::unique_ptr<PragmaHandler> STDCCXLIMITHandler;
7050 std::unique_ptr<PragmaHandler> STDCUnknownHandler;
7051 std::unique_ptr<PragmaHandler> AttributePragmaHandler;
7052 std::unique_ptr<PragmaHandler> MaxTokensHerePragmaHandler;
7053 std::unique_ptr<PragmaHandler> MaxTokensTotalPragmaHandler;
7054 std::unique_ptr<PragmaHandler> ExportHandler;
7055 std::unique_ptr<PragmaHandler> RISCVPragmaHandler;
7058 void initializePragmaHandlers();
7061 void resetPragmaHandlers();
7068 void HandlePragmaUnused();
7072 void HandlePragmaVisibility();
7076 void HandlePragmaPack();
7080 void HandlePragmaMSStruct();
7082 void HandlePragmaMSPointersToMembers();
7084 void HandlePragmaMSVtorDisp();
7086 void HandlePragmaMSPragma();
7087 bool HandlePragmaMSSection(StringRef PragmaName,
7088 SourceLocation PragmaLocation);
7089 bool HandlePragmaMSSegment(StringRef PragmaName,
7090 SourceLocation PragmaLocation);
7093 bool HandlePragmaMSInitSeg(StringRef PragmaName,
7094 SourceLocation PragmaLocation);
7099 bool HandlePragmaMSStrictGuardStackCheck(StringRef PragmaName,
7100 SourceLocation PragmaLocation);
7101 bool HandlePragmaMSFunction(StringRef PragmaName,
7102 SourceLocation PragmaLocation);
7103 bool HandlePragmaMSAllocText(StringRef PragmaName,
7104 SourceLocation PragmaLocation);
7107 bool HandlePragmaMSOptimize(StringRef PragmaName,
7108 SourceLocation PragmaLocation);
7111 bool HandlePragmaMSIntrinsic(StringRef PragmaName,
7112 SourceLocation PragmaLocation);
7116 void HandlePragmaAlign();
7120 void HandlePragmaDump();
7124 void HandlePragmaWeak();
7128 void HandlePragmaWeakAlias();
7132 void HandlePragmaRedefineExtname();
7136 void HandlePragmaFPContract();
7140 void HandlePragmaFEnvAccess();
7144 void HandlePragmaFEnvRound();
7148 void HandlePragmaCXLimitedRange();
7152 void HandlePragmaFloatControl();
7156 void HandlePragmaFP();
7160 void HandlePragmaOpenCLExtension();
7164 StmtResult HandlePragmaCaptured();
7168 bool HandlePragmaLoopHint(LoopHint &Hint);
7170 bool ParsePragmaAttributeSubjectMatchRuleSet(
7172 SourceLocation &AnyLoc, SourceLocation &LastMatchRuleEndLoc);
7174 void HandlePragmaAttribute();
7180 void HandlePragmaExport();
7206 enum class ParsedStmtContext {
7209 AllowDeclarationsInC = 0x1,
7211 AllowStandaloneOpenMPDirectives = 0x2,
7218 Compound = AllowDeclarationsInC | AllowStandaloneOpenMPDirectives,
7235 ParsedStmtContext StmtCtx = ParsedStmtContext::SubStmt,
7290 ParseStatementOrDeclaration(
StmtVector &Stmts, ParsedStmtContext StmtCtx,
7294 StmtResult ParseStatementOrDeclarationAfterAttributes(
7295 StmtVector &Stmts, ParsedStmtContext StmtCtx,
7300 StmtResult ParseExprStatement(ParsedStmtContext StmtCtx);
7314 ParsedStmtContext StmtCtx);
7323 StmtResult ParseCaseStatement(ParsedStmtContext StmtCtx,
7324 bool MissingCase =
false,
7334 StmtResult ParseDefaultStatement(ParsedStmtContext StmtCtx);
7336 StmtResult ParseCompoundStatement(
bool isStmtExpr =
false);
7362 StmtResult ParseCompoundStatement(
bool isStmtExpr,
unsigned ScopeFlags);
7367 void ParseCompoundStatementLeadingPragmas();
7369 void DiagnoseLabelAtEndOfCompoundStatement();
7379 StmtResult ParseCompoundStatementBody(
bool isStmtExpr =
false);
7397 bool ParseParenExprOrCondition(
StmtResult *InitStmt,
7513 StmtResult ParseBreakOrContinueStatement(
bool IsContinue);
7530 void ParseMicrosoftIfExistsStatement(
StmtVector &Stmts);
7577 StmtResult ParseCXXCatchBlock(
bool FnCatch =
false);
7615 Decl *ParseFunctionStatementBody(
Decl *
Decl, ParseScope &BodyScope);
7624 Decl *ParseFunctionTryBlock(
Decl *
Decl, ParseScope &BodyScope);
7630 bool trySkippingFunctionBody();
7638 bool isDeclarationStatement(
bool DisambiguatingWithExpression =
false) {
7640 return isCXXDeclarationStatement(DisambiguatingWithExpression);
7648 bool isForInitDeclaration() {
7652 return Tok.is(tok::kw_using) ||
7653 isCXXSimpleDeclaration(
true);
7658 bool isForRangeIdentifier();
7675 unsigned &NumLineToksConsumed,
7676 bool IsUnevaluated);
7719 StmtResult ParseMicrosoftAsmStatement(SourceLocation AsmLoc);
7735 bool ParseAsmOperandsOpt(SmallVectorImpl<IdentifierInfo *> &Names,
7736 SmallVectorImpl<Expr *> &Constraints,
7737 SmallVectorImpl<Expr *> &Exprs);
7739 class GNUAsmQualifiers {
7740 unsigned Qualifiers = AQ_unspecified;
7749 static const char *getQualifierName(AQ Qualifier);
7750 bool setAsmQualifier(AQ Qualifier);
7751 inline bool isVolatile()
const {
return Qualifiers & AQ_volatile; };
7752 inline bool isInline()
const {
return Qualifiers & AQ_inline; };
7753 inline bool isGoto()
const {
return Qualifiers & AQ_goto; }
7757 bool isGCCAsmStatement(
const Token &TokAfterAsm)
const;
7759 bool isGNUAsmQualifier(
const Token &TokAfterAsm)
const;
7760 GNUAsmQualifiers::AQ getGNUAsmQualifier(
const Token &Tok)
const;
7773 bool parseGNUAsmQualifierListOpt(GNUAsmQualifiers &AQ);
7797 unsigned TemplateParameterDepth;
7800 class TemplateParameterDepthRAII {
7802 unsigned AddedLevels;
7805 explicit TemplateParameterDepthRAII(
unsigned &Depth)
7806 : Depth(Depth), AddedLevels(0) {}
7808 ~TemplateParameterDepthRAII() { Depth -= AddedLevels; }
7814 void addDepth(
unsigned D) {
7818 void setAddedDepth(
unsigned D) {
7819 Depth = Depth - AddedLevels + D;
7823 unsigned getDepth()
const {
return Depth; }
7824 unsigned getOriginalDepth()
const {
return Depth - AddedLevels; }
7829 SmallVector<TemplateIdAnnotation *, 16> TemplateIds;
7835 bool DelayTemplateIdDestruction =
false;
7837 void MaybeDestroyTemplateIds() {
7838 if (DelayTemplateIdDestruction)
7840 if (!TemplateIds.empty() &&
7841 (Tok.is(tok::eof) || !PP.mightHavePendingAnnotationTokens()))
7842 DestroyTemplateIds();
7844 void DestroyTemplateIds();
7848 struct DestroyTemplateIdAnnotationsRAIIObj {
7851 DestroyTemplateIdAnnotationsRAIIObj(
Parser &Self) : Self(Self) {}
7852 ~DestroyTemplateIdAnnotationsRAIIObj() { Self.MaybeDestroyTemplateIds(); }
7855 struct DelayTemplateIdDestructionRAII {
7857 bool PrevDelayTemplateIdDestruction;
7859 DelayTemplateIdDestructionRAII(
Parser &Self,
7860 bool DelayTemplateIdDestruction) noexcept
7862 PrevDelayTemplateIdDestruction(Self.DelayTemplateIdDestruction) {
7863 Self.DelayTemplateIdDestruction = DelayTemplateIdDestruction;
7866 ~DelayTemplateIdDestructionRAII() noexcept {
7867 Self.DelayTemplateIdDestruction = PrevDelayTemplateIdDestruction;
7872 SmallVector<const IdentifierInfo *, 8> TentativelyDeclaredIdentifiers;
7884 struct AngleBracketTracker {
7887 enum Priority :
unsigned short {
7889 PotentialTypo = 0x0,
7891 DependentName = 0x2,
7894 SpaceBeforeLess = 0x0,
7896 NoSpaceBeforeLess = 0x1,
7927 if (!Locs.empty() && Locs.back().isActive(P)) {
7928 if (Locs.back().Priority <= Prio) {
7930 Locs.back().LessLoc = LessLoc;
7931 Locs.back().Priority = Prio;
7934 Locs.push_back({
TemplateName, LessLoc, Prio, P.ParenCount,
7935 P.BracketCount, P.BraceCount});
7943 while (!Locs.empty() && Locs.back().isActiveOrNested(P))
7950 if (!Locs.empty() && Locs.back().isActive(P))
7951 return &Locs.back();
7956 AngleBracketTracker AngleBrackets;
7961 struct ParsedTemplateInfo {
7962 ParsedTemplateInfo()
7966 bool isSpecialization,
7967 bool lastParameterListWasEmpty =
false)
7970 TemplateParams(TemplateParams),
7971 LastParameterListWasEmpty(lastParameterListWasEmpty) {}
7973 explicit ParsedTemplateInfo(SourceLocation ExternLoc,
7974 SourceLocation TemplateLoc)
7976 TemplateParams(
nullptr), ExternLoc(ExternLoc),
7977 TemplateLoc(TemplateLoc), LastParameterListWasEmpty(
false) {}
7987 SourceLocation ExternLoc;
7991 SourceLocation TemplateLoc;
7994 bool LastParameterListWasEmpty;
7996 SourceRange getSourceRange() const LLVM_READONLY;
8000 void LexTemplateFunctionForLateParsing(
CachedTokens &Toks);
8003 void ParseLateTemplatedFuncDef(LateParsedTemplate &LPT);
8005 static
void LateTemplateParserCallback(
void *P, LateParsedTemplate &LPT);
8013 void checkPotentialAngleBracket(
ExprResult &PotentialTemplateName);
8014 bool checkPotentialAngleBracketDelimiter(const AngleBracketTracker::Loc &,
8015 const Token &OpToken);
8016 bool checkPotentialAngleBracketDelimiter(const Token &OpToken) {
8017 if (
auto *Info = AngleBrackets.getCurrent(*
this))
8018 return checkPotentialAngleBracketDelimiter(*Info, OpToken);
8029 SourceLocation &DeclEnd,
8030 ParsedAttributes &AccessAttrs);
8077 ParsingDeclRAIIObject &DiagsFromParams, SourceLocation &DeclEnd,
8089 bool ParseTemplateParameters(MultiParseScope &TemplateScopes,
unsigned Depth,
8090 SmallVectorImpl<NamedDecl *> &TemplateParams,
8091 SourceLocation &LAngleLoc,
8092 SourceLocation &RAngleLoc);
8104 bool ParseTemplateParameterList(
unsigned Depth,
8105 SmallVectorImpl<NamedDecl *> &TemplateParams);
8107 enum class TPResult;
8111 TPResult isStartOfTemplateTypeParameter();
8135 NamedDecl *ParseTemplateParameter(
unsigned Depth,
unsigned Position);
8148 NamedDecl *ParseTypeParameter(
unsigned Depth,
unsigned Position);
8164 NamedDecl *ParseTemplateTemplateParameter(
unsigned Depth,
unsigned Position);
8174 NamedDecl *ParseNonTypeTemplateParameter(
unsigned Depth,
unsigned Position);
8178 bool isTypeConstraintAnnotation();
8190 bool TryAnnotateTypeConstraint();
8192 void DiagnoseMisplacedEllipsis(SourceLocation EllipsisLoc,
8193 SourceLocation CorrectLoc,
8194 bool AlreadyHasEllipsis,
8195 bool IdentifierHasName);
8196 void DiagnoseMisplacedEllipsisInDeclarator(SourceLocation EllipsisLoc,
8199 typedef SmallVector<ParsedTemplateArgument, 16> TemplateArgList;
8216 bool ParseGreaterThanInTemplateList(SourceLocation LAngleLoc,
8217 SourceLocation &RAngleLoc,
8218 bool ConsumeLastToken,
8219 bool ObjCGenericList);
8232 bool ParseTemplateIdAfterTemplateName(
bool ConsumeLastToken,
8233 SourceLocation &LAngleLoc,
8234 TemplateArgList &TemplateArgs,
8235 SourceLocation &RAngleLoc,
8280 CXXScopeSpec &SS, SourceLocation TemplateKWLoc,
8282 bool AllowTypeAnnotation =
true,
8283 bool TypeConstraint =
false);
8301 AnnotateTemplateIdTokenAsType(CXXScopeSpec &SS,
8303 bool IsClassName =
false);
8315 bool ParseTemplateArgumentList(TemplateArgList &TemplateArgs,
8319 ParsedTemplateArgument ParseTemplateTemplateArgument();
8331 ParsedTemplateArgument ParseTemplateArgument();
8343 SourceLocation ExternLoc,
8344 SourceLocation TemplateLoc,
8345 SourceLocation &DeclEnd,
8346 ParsedAttributes &AccessAttrs,
8355 Decl *ParseConceptDefinition(
const ParsedTemplateInfo &TemplateInfo,
8356 SourceLocation &DeclEnd);
8384 class TentativeParsingAction {
8386 PreferredTypeBuilder PrevPreferredType;
8388 size_t PrevTentativelyDeclaredIdentifierCount;
8389 unsigned short PrevParenCount, PrevBracketCount, PrevBraceCount;
8393 explicit TentativeParsingAction(Parser &p,
bool Unannotated =
false)
8394 : P(p), PrevPreferredType(P.PreferredType) {
8396 PrevTentativelyDeclaredIdentifierCount =
8397 P.TentativelyDeclaredIdentifiers.size();
8398 PrevParenCount = P.ParenCount;
8399 PrevBracketCount = P.BracketCount;
8400 PrevBraceCount = P.BraceCount;
8401 P.PP.EnableBacktrackAtThisPos(Unannotated);
8405 assert(isActive &&
"Parsing action was finished!");
8406 P.TentativelyDeclaredIdentifiers.resize(
8407 PrevTentativelyDeclaredIdentifierCount);
8408 P.PP.CommitBacktrackedTokens();
8412 assert(isActive &&
"Parsing action was finished!");
8414 P.PreferredType = PrevPreferredType;
8416 P.TentativelyDeclaredIdentifiers.resize(
8417 PrevTentativelyDeclaredIdentifierCount);
8418 P.ParenCount = PrevParenCount;
8419 P.BracketCount = PrevBracketCount;
8420 P.BraceCount = PrevBraceCount;
8423 ~TentativeParsingAction() {
8424 assert(!isActive &&
"Forgot to call Commit or Revert!");
8430 class RevertingTentativeParsingAction
8431 :
private Parser::TentativeParsingAction {
8433 using TentativeParsingAction::TentativeParsingAction;
8435 ~RevertingTentativeParsingAction() { Revert(); }
8470 bool isCXXDeclarationStatement(
bool DisambiguatingWithExpression =
false);
8496 bool isCXXSimpleDeclaration(
bool AllowForRangeDecl);
8509 bool isCXXFunctionDeclarator(
bool *IsAmbiguous =
nullptr,
8513 struct ConditionDeclarationOrInitStatementState;
8514 enum class ConditionOrInitStatement {
8541 ConditionOrInitStatement
8542 isCXXConditionDeclarationOrInitStatement(
bool CanBeInitStmt,
8543 bool CanBeForRangeDecl);
8569 return isCXXTypeId(Context, isAmbiguous);
8583 bool isEnumBase(
bool AllowSemi);
8703 TPResult BracedCastResult = TPResult::False,
8704 bool *InvalidAsDeclSpec =
nullptr);
8709 bool isCXXDeclarationSpecifierAType();
8715 TPResult isTemplateArgumentList(
unsigned TokensToSkip);
8720 TPResult isExplicitBool();
8725 bool isTentativelyDeclared(IdentifierInfo *II);
8744 TPResult TryParseSimpleDeclaration(
bool AllowForRangeDecl);
8752 TPResult TryParseTypeofSpecifier();
8756 TPResult TryParseProtocolQualifiers();
8758 TPResult TryParsePtrOperatorSeq();
8780 TPResult TryParseOperatorId();
8811 TPResult TryParseInitDeclaratorList(
bool MayHaveTrailingReturnType =
false);
8868 TPResult TryParseDeclarator(
bool mayBeAbstract,
bool mayHaveIdentifier =
true,
8869 bool mayHaveDirectInit =
false,
8870 bool mayHaveTrailingReturnType =
false);
8891 TPResult TryParseParameterDeclarationClause(
8892 bool *InvalidAsDeclaration =
nullptr,
bool VersusTemplateArg =
false,
8909 TPResult TryParseFunctionDeclarator(
bool MayHaveTrailingReturnType =
false);
8915 bool NameAfterArrowIsNonType();
8921 TPResult TryParseBracketDeclarator();
8925 TPResult TryConsumeDeclarationSpecifier();
8929 bool TrySkipAttributes();
8971 isCXX11AttributeSpecifier(
bool Disambiguate =
false,
8972 bool OuterMightBeMessageSend =
false);