215 return Actions.incrementMSManglingNumber();
264 assert(!isTokenSpecial() &&
265 "Should consume special tokens with Consume*Token");
266 PrevTokLocation = Tok.getLocation();
268 return PrevTokLocation;
274 assert(!isTokenSpecial() &&
275 "Should consume special tokens with Consume*Token");
276 PrevTokLocation = Tok.getLocation();
284 Loc = PrevTokLocation;
293 return ConsumeParen();
294 if (isTokenBracket())
295 return ConsumeBracket();
297 return ConsumeBrace();
298 if (isTokenStringLiteral())
299 return ConsumeStringToken();
300 if (Tok.is(tok::code_completion))
301 return ConsumeCodeCompletionTok ? ConsumeCodeCompletionToken()
302 : handleUnexpectedCodeCompletionToken();
303 if (Tok.isAnnotation())
304 return ConsumeAnnotationToken();
318 if (N == 0 || Tok.is(tok::eof))
320 return PP.LookAhead(N - 1);
329 if (!Tok.getAnnotationValue())
364 bool IsAddressOfOperand =
false);
390 (Tok.is(tok::identifier) || Tok.is(tok::coloncolon) ||
391 (Tok.is(tok::annot_template_id) &&
393 Tok.is(tok::kw_decltype) || Tok.is(tok::kw___super));
410 ParseScope(
const ParseScope &) =
delete;
411 void operator=(
const ParseScope &) =
delete;
418 bool BeforeCompoundStmt =
false)
420 if (EnteredScope && !BeforeCompoundStmt)
421 Self->EnterScope(ScopeFlags);
423 if (BeforeCompoundStmt)
424 Self->incrementMSManglingNumber();
426 this->Self = nullptr;
444 class MultiParseScope {
446 unsigned NumScopes = 0;
448 MultiParseScope(
const MultiParseScope &) =
delete;
453 Self.EnterScope(ScopeFlags);
495 static_cast<unsigned>(R));
550 unsigned short ParenCount = 0, BracketCount = 0,
BraceCount = 0;
551 unsigned short MisplacedModuleBeginCount = 0;
562 static constexpr int ScopeCacheSize = 16;
563 unsigned NumCachedScopes;
564 Scope *ScopeCache[ScopeCacheSize];
570 *Ident_GetExceptionCode;
573 *Ident_GetExceptionInfo;
575 IdentifierInfo *Ident__abnormal_termination, *Ident___abnormal_termination,
576 *Ident_AbnormalTermination;
581 std::unique_ptr<CommentHandler> CommentSemaHandler;
586 bool CalledSignatureHelp =
false;
594 bool SkipFunctionBodies;
601 bool isTokenParen()
const {
return Tok.isOneOf(tok::l_paren, tok::r_paren); }
603 bool isTokenBracket()
const {
604 return Tok.isOneOf(tok::l_square, tok::r_square);
607 bool isTokenBrace()
const {
return Tok.isOneOf(tok::l_brace, tok::r_brace); }
609 bool isTokenStringLiteral()
const {
613 bool isTokenSpecial()
const {
614 return isTokenStringLiteral() || isTokenParen() || isTokenBracket() ||
615 isTokenBrace() || Tok.is(tok::code_completion) || Tok.isAnnotation();
620 bool isTokenEqualOrEqualTypo();
624 void UnconsumeToken(Token &Consumed) {
626 PP.EnterToken(Consumed,
true);
628 PP.EnterToken(
Next,
true);
631 SourceLocation ConsumeAnnotationToken() {
632 assert(Tok.isAnnotation() &&
"wrong consume method");
633 SourceLocation Loc = Tok.getLocation();
634 PrevTokLocation = Tok.getAnnotationEndLoc();
641 SourceLocation ConsumeParen() {
642 assert(isTokenParen() &&
"wrong consume method");
643 if (Tok.getKind() == tok::l_paren)
645 else if (ParenCount) {
646 AngleBrackets.clear(*
this);
649 PrevTokLocation = Tok.getLocation();
651 return PrevTokLocation;
656 SourceLocation ConsumeBracket() {
657 assert(isTokenBracket() &&
"wrong consume method");
658 if (Tok.getKind() == tok::l_square)
660 else if (BracketCount) {
661 AngleBrackets.clear(*
this);
665 PrevTokLocation = Tok.getLocation();
667 return PrevTokLocation;
672 SourceLocation ConsumeBrace() {
673 assert(isTokenBrace() &&
"wrong consume method");
674 if (Tok.getKind() == tok::l_brace)
676 else if (BraceCount) {
677 AngleBrackets.clear(*
this);
681 PrevTokLocation = Tok.getLocation();
683 return PrevTokLocation;
690 SourceLocation ConsumeStringToken() {
691 assert(isTokenStringLiteral() &&
692 "Should only consume string literals with this method");
693 PrevTokLocation = Tok.getLocation();
695 return PrevTokLocation;
703 SourceLocation ConsumeCodeCompletionToken() {
704 assert(Tok.is(tok::code_completion));
705 PrevTokLocation = Tok.getLocation();
707 return PrevTokLocation;
715 SourceLocation handleUnexpectedCodeCompletionToken();
719 void cutOffParsing() {
720 if (PP.isCodeCompletionEnabled())
721 PP.setCodeCompletionReached();
723 Tok.setKind(tok::eof);
730 return Kind == tok::eof ||
Kind == tok::annot_module_begin ||
731 Kind == tok::annot_module_end ||
Kind == tok::annot_module_include ||
732 Kind == tok::annot_repl_input_end;
735 static void setTypeAnnotation(Token &Tok,
TypeResult T) {
736 assert((T.isInvalid() || T.get()) &&
737 "produced a valid-but-null type annotation?");
738 Tok.setAnnotationValue(T.isInvalid() ?
nullptr : T.get().getAsOpaquePtr());
741 static NamedDecl *getNonTypeAnnotation(
const Token &Tok) {
742 return static_cast<NamedDecl *
>(Tok.getAnnotationValue());
745 static void setNonTypeAnnotation(Token &Tok, NamedDecl *ND) {
746 Tok.setAnnotationValue(ND);
749 static IdentifierInfo *getIdentifierAnnotation(
const Token &Tok) {
750 return static_cast<IdentifierInfo *
>(Tok.getAnnotationValue());
753 static void setIdentifierAnnotation(Token &Tok, IdentifierInfo *ND) {
754 Tok.setAnnotationValue(ND);
759 static ExprResult getExprAnnotation(
const Token &Tok) {
760 return ExprResult::getFromOpaquePointer(Tok.getAnnotationValue());
765 static void setExprAnnotation(Token &Tok,
ExprResult ER) {
766 Tok.setAnnotationValue(ER.getAsOpaquePointer());
780 TryAnnotateName(CorrectionCandidateCallback *CCC =
nullptr,
785 void AnnotateScopeToken(CXXScopeSpec &SS,
bool IsNewAnnotation);
792 bool TryKeywordIdentFallback(
bool DisableKeyword);
797 TemplateIdAnnotation *takeTemplateIdAnnotation(
const Token &tok);
808 unsigned Diag = diag::err_expected,
809 StringRef DiagMsg =
"");
816 bool ExpectAndConsumeSemi(
unsigned DiagID, StringRef TokenUsed =
"");
827 bool expectIdentifier();
830 enum class CompoundToken {
845 void checkCompoundToken(SourceLocation FirstTokLoc,
848 void diagnoseUseOfC11Keyword(
const Token &Tok);
851 class ParseScopeFlags {
853 unsigned OldFlags = 0;
854 ParseScopeFlags(
const ParseScopeFlags &) =
delete;
855 void operator=(
const ParseScopeFlags &) =
delete;
860 ParseScopeFlags(
Parser *
Self,
unsigned ScopeFlags,
bool ManageFlags =
true);
874 void SuggestParentheses(SourceLocation Loc,
unsigned DK,
875 SourceRange ParenRange);
911 DeclGroupPtrTy ParseExternalDeclaration(ParsedAttributes &DeclAttrs,
912 ParsedAttributes &DeclSpecAttrs,
913 ParsingDeclSpec *DS =
nullptr);
917 bool isDeclarationAfterDeclarator();
921 bool isStartOfFunctionDefinition(
const ParsingDeclarator &Declarator);
924 ParsedAttributes &DeclAttrs, ParsedAttributes &DeclSpecAttrs,
945 DeclGroupPtrTy ParseDeclOrFunctionDefInternal(ParsedAttributes &Attrs,
946 ParsedAttributes &DeclSpecAttrs,
950 void SkipFunctionBody();
952 struct ParsedTemplateInfo;
953 class LateParsedAttrList;
971 Decl *ParseFunctionDefinition(
972 ParsingDeclarator &D,
973 const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo(),
974 LateParsedAttrList *LateParsedAttrs =
nullptr);
978 void ParseKNRParamDeclarations(Declarator &D);
988 ExprResult ParseSimpleAsm(
bool ForAsmLabel, SourceLocation *EndLoc);
1001 ExprResult ParseAsmStringLiteral(
bool ForAsmLabel);
1005 struct IfExistsCondition {
1007 SourceLocation KeywordLoc;
1023 bool ParseMicrosoftIfExistsCondition(IfExistsCondition &
Result);
1024 void ParseMicrosoftIfExistsExternalDeclaration();
1063 Decl *ParseModuleImport(SourceLocation AtLoc,
1070 bool parseMisplacedModuleImport();
1072 bool tryParseMisplacedModuleImport() {
1074 if (Kind == tok::annot_module_begin || Kind == tok::annot_module_end ||
1075 Kind == tok::annot_module_include)
1076 return parseMisplacedModuleImport();
1089 bool ParseModuleName(SourceLocation UseLoc,
1090 SmallVectorImpl<IdentifierLoc> &Path,
bool IsImport);
1093 void DiagnoseInvalidCXXModuleImport();
1097 void CodeCompleteDirective(
bool InConditional)
override;
1099 void CodeCompleteMacroName(
bool IsDefinition)
override;
1101 void CodeCompleteMacroArgument(IdentifierInfo *
Macro, MacroInfo *MacroInfo,
1102 unsigned ArgumentIndex)
override;
1103 void CodeCompleteIncludedFile(llvm::StringRef Dir,
bool IsAngled)
override;
1105 void CodeCompleteModuleImport(SourceLocation ImportLoc,
1121 struct ParsingClass;
1131 class LateParsedDeclaration {
1133 virtual ~LateParsedDeclaration();
1135 virtual void ParseLexedMethodDeclarations();
1136 virtual void ParseLexedMemberInitializers();
1137 virtual void ParseLexedMethodDefs();
1138 virtual void ParseLexedAttributes();
1139 virtual void ParseLexedPragmas();
1144 class LateParsedClass :
public LateParsedDeclaration {
1146 LateParsedClass(
Parser *P, ParsingClass *
C);
1147 ~LateParsedClass()
override;
1149 void ParseLexedMethodDeclarations()
override;
1150 void ParseLexedMemberInitializers()
override;
1151 void ParseLexedMethodDefs()
override;
1152 void ParseLexedAttributes()
override;
1153 void ParseLexedPragmas()
override;
1156 LateParsedClass(
const LateParsedClass &) =
delete;
1157 LateParsedClass &operator=(
const LateParsedClass &) =
delete;
1161 ParsingClass *Class;
1170 struct LateParsedAttribute :
public LateParsedDeclaration {
1173 IdentifierInfo &AttrName;
1174 IdentifierInfo *MacroII =
nullptr;
1175 SourceLocation AttrNameLoc;
1176 SmallVector<Decl *, 2> Decls;
1178 explicit LateParsedAttribute(
Parser *P, IdentifierInfo &Name,
1180 : Self(P), AttrName(Name), AttrNameLoc(Loc) {}
1182 void ParseLexedAttributes()
override;
1184 void addDecl(Decl *D) { Decls.push_back(D); }
1191 class LateParsedPragma :
public LateParsedDeclaration {
1198 : Self(P), AS(AS) {}
1200 void takeToks(
CachedTokens &Cached) { Toks.swap(Cached); }
1204 void ParseLexedPragmas()
override;
1208 class LateParsedAttrList :
public SmallVector<LateParsedAttribute *, 2> {
1210 LateParsedAttrList(
bool PSoon =
false,
1211 bool LateAttrParseExperimentalExtOnly =
false)
1213 LateAttrParseExperimentalExtOnly(LateAttrParseExperimentalExtOnly) {}
1215 bool parseSoon() {
return ParseSoon; }
1218 bool lateAttrParseExperimentalExtOnly() {
1219 return LateAttrParseExperimentalExtOnly;
1224 bool LateAttrParseExperimentalExtOnly;
1230 struct LexedMethod :
public LateParsedDeclaration {
1235 explicit LexedMethod(
Parser *P, Decl *MD) : Self(P), D(MD) {}
1237 void ParseLexedMethodDefs()
override;
1244 struct LateParsedDefaultArgument {
1245 explicit LateParsedDefaultArgument(
1246 Decl *P, std::unique_ptr<CachedTokens> Toks =
nullptr)
1247 : Param(P), Toks(std::move(Toks)) {}
1256 std::unique_ptr<CachedTokens> Toks;
1263 struct LateParsedMethodDeclaration :
public LateParsedDeclaration {
1264 explicit LateParsedMethodDeclaration(
Parser *P, Decl *M)
1265 : Self(P), Method(M), ExceptionSpecTokens(
nullptr) {}
1267 void ParseLexedMethodDeclarations()
override;
1279 SmallVector<LateParsedDefaultArgument, 8> DefaultArgs;
1289 struct LateParsedMemberInitializer :
public LateParsedDeclaration {
1290 LateParsedMemberInitializer(
Parser *P, Decl *FD) : Self(P), Field(FD) {}
1292 void ParseLexedMemberInitializers()
override;
1310 typedef SmallVector<LateParsedDeclaration *, 2>
1311 LateParsedDeclarationsContainer;
1325 const ParsedAttributesView &AccessAttrs,
1326 ParsingDeclarator &D,
1327 const ParsedTemplateInfo &TemplateInfo,
1328 const VirtSpecifiers &VS,
1329 SourceLocation PureSpecLoc);
1332 StringLiteral *ParseCXXDeletedFunctionMessage();
1337 void SkipDeletedFunctionBody();
1343 void ParseCXXNonStaticMemberInitializer(Decl *VarD);
1347 void ParseLexedAttributes(ParsingClass &
Class);
1350 void ParseLexedAttributeList(LateParsedAttrList &LAs, Decl *D,
1358 void ParseLexedAttribute(LateParsedAttribute &LA,
bool EnterScope,
1365 void ParseLexedMethodDeclarations(ParsingClass &
Class);
1366 void ParseLexedMethodDeclaration(LateParsedMethodDeclaration &LM);
1371 void ParseLexedMethodDefs(ParsingClass &
Class);
1372 void ParseLexedMethodDef(LexedMethod &LM);
1378 void ParseLexedMemberInitializers(ParsingClass &
Class);
1379 void ParseLexedMemberInitializer(LateParsedMemberInitializer &MI);
1413 ParsedAttributes *Attrs =
nullptr);
1419 IdentifierInfo *Ident_vector;
1420 IdentifierInfo *Ident_bool;
1421 IdentifierInfo *Ident_Bool;
1425 IdentifierInfo *Ident_pixel;
1428 IdentifierInfo *Ident_introduced;
1431 IdentifierInfo *Ident_deprecated;
1434 IdentifierInfo *Ident_obsoleted;
1437 IdentifierInfo *Ident_unavailable;
1440 IdentifierInfo *Ident_message;
1443 IdentifierInfo *Ident_strict;
1446 IdentifierInfo *Ident_replacement;
1449 IdentifierInfo *Ident_environment;
1452 IdentifierInfo *Ident_language, *Ident_defined_in,
1453 *Ident_generated_declaration, *Ident_USR;
1456 AttributeFactory AttrFactory;
1461 bool TryAltiVecToken(DeclSpec &DS, SourceLocation Loc,
const char *&PrevSpec,
1466 if (Tok.getIdentifierInfo() != Ident_vector &&
1467 Tok.getIdentifierInfo() != Ident_bool &&
1468 Tok.getIdentifierInfo() != Ident_Bool &&
1469 (!
getLangOpts().AltiVec || Tok.getIdentifierInfo() != Ident_pixel))
1472 return TryAltiVecTokenOutOfLine(DS, Loc, PrevSpec, DiagID,
isInvalid);
1478 bool TryAltiVecVectorToken() {
1480 Tok.getIdentifierInfo() != Ident_vector)
1482 return TryAltiVecVectorTokenOutOfLine();
1487 bool TryAltiVecVectorTokenOutOfLine();
1488 bool TryAltiVecTokenOutOfLine(DeclSpec &DS, SourceLocation Loc,
1489 const char *&PrevSpec,
unsigned &DiagID,
1492 void ParseLexedCAttributeList(LateParsedAttrList &LA,
bool EnterScope,
1493 ParsedAttributes *OutAttrs =
nullptr);
1500 void ParseLexedCAttribute(LateParsedAttribute &LA,
bool EnterScope,
1501 ParsedAttributes *OutAttrs =
nullptr);
1503 void ParseLexedPragmas(ParsingClass &
Class);
1504 void ParseLexedPragma(LateParsedPragma &LP);
1512 bool ConsumeAndStoreFunctionPrologue(
CachedTokens &Toks);
1528 bool ConsumeFinalToken =
true) {
1529 return ConsumeAndStoreUntil(T1, T1, Toks,
StopAtSemi, ConsumeFinalToken);
1540 bool ConsumeFinalToken =
true);
1548 enum class DeclSpecContext {
1553 DSC_alias_declaration,
1558 DSC_template_type_arg,
1559 DSC_objc_method_result,
1568 static bool isTypeSpecifier(DeclSpecContext DSC) {
1570 case DeclSpecContext::DSC_normal:
1571 case DeclSpecContext::DSC_template_param:
1572 case DeclSpecContext::DSC_template_arg:
1573 case DeclSpecContext::DSC_class:
1574 case DeclSpecContext::DSC_top_level:
1575 case DeclSpecContext::DSC_objc_method_result:
1576 case DeclSpecContext::DSC_condition:
1579 case DeclSpecContext::DSC_template_type_arg:
1580 case DeclSpecContext::DSC_type_specifier:
1581 case DeclSpecContext::DSC_conv_operator:
1582 case DeclSpecContext::DSC_trailing:
1583 case DeclSpecContext::DSC_alias_declaration:
1584 case DeclSpecContext::DSC_association:
1585 case DeclSpecContext::DSC_new:
1588 llvm_unreachable(
"Missing DeclSpecContext case");
1592 enum class AllowDefiningTypeSpec {
1609 static AllowDefiningTypeSpec
1610 isDefiningTypeSpecifierContext(DeclSpecContext DSC,
bool IsCPlusPlus) {
1612 case DeclSpecContext::DSC_normal:
1613 case DeclSpecContext::DSC_class:
1614 case DeclSpecContext::DSC_top_level:
1615 case DeclSpecContext::DSC_alias_declaration:
1616 case DeclSpecContext::DSC_objc_method_result:
1617 return AllowDefiningTypeSpec::Yes;
1619 case DeclSpecContext::DSC_condition:
1620 case DeclSpecContext::DSC_template_param:
1621 return AllowDefiningTypeSpec::YesButInvalid;
1623 case DeclSpecContext::DSC_template_type_arg:
1624 case DeclSpecContext::DSC_type_specifier:
1625 return AllowDefiningTypeSpec::NoButErrorRecovery;
1627 case DeclSpecContext::DSC_association:
1628 return IsCPlusPlus ? AllowDefiningTypeSpec::NoButErrorRecovery
1629 : AllowDefiningTypeSpec::Yes;
1631 case DeclSpecContext::DSC_trailing:
1632 case DeclSpecContext::DSC_conv_operator:
1633 case DeclSpecContext::DSC_template_arg:
1634 case DeclSpecContext::DSC_new:
1635 return AllowDefiningTypeSpec::No;
1637 llvm_unreachable(
"Missing DeclSpecContext case");
1641 static bool isOpaqueEnumDeclarationContext(DeclSpecContext DSC) {
1643 case DeclSpecContext::DSC_normal:
1644 case DeclSpecContext::DSC_class:
1645 case DeclSpecContext::DSC_top_level:
1648 case DeclSpecContext::DSC_alias_declaration:
1649 case DeclSpecContext::DSC_objc_method_result:
1650 case DeclSpecContext::DSC_condition:
1651 case DeclSpecContext::DSC_template_param:
1652 case DeclSpecContext::DSC_template_type_arg:
1653 case DeclSpecContext::DSC_type_specifier:
1654 case DeclSpecContext::DSC_trailing:
1655 case DeclSpecContext::DSC_association:
1656 case DeclSpecContext::DSC_conv_operator:
1657 case DeclSpecContext::DSC_template_arg:
1658 case DeclSpecContext::DSC_new:
1662 llvm_unreachable(
"Missing DeclSpecContext case");
1667 static bool isClassTemplateDeductionContext(DeclSpecContext DSC) {
1669 case DeclSpecContext::DSC_normal:
1670 case DeclSpecContext::DSC_template_param:
1671 case DeclSpecContext::DSC_template_arg:
1672 case DeclSpecContext::DSC_class:
1673 case DeclSpecContext::DSC_top_level:
1674 case DeclSpecContext::DSC_condition:
1675 case DeclSpecContext::DSC_type_specifier:
1676 case DeclSpecContext::DSC_association:
1677 case DeclSpecContext::DSC_conv_operator:
1678 case DeclSpecContext::DSC_new:
1681 case DeclSpecContext::DSC_objc_method_result:
1682 case DeclSpecContext::DSC_template_type_arg:
1683 case DeclSpecContext::DSC_trailing:
1684 case DeclSpecContext::DSC_alias_declaration:
1687 llvm_unreachable(
"Missing DeclSpecContext case");
1692 getImplicitTypenameContext(DeclSpecContext DSC) {
1694 case DeclSpecContext::DSC_class:
1695 case DeclSpecContext::DSC_top_level:
1696 case DeclSpecContext::DSC_type_specifier:
1697 case DeclSpecContext::DSC_template_type_arg:
1698 case DeclSpecContext::DSC_trailing:
1699 case DeclSpecContext::DSC_alias_declaration:
1700 case DeclSpecContext::DSC_template_param:
1701 case DeclSpecContext::DSC_new:
1704 case DeclSpecContext::DSC_normal:
1705 case DeclSpecContext::DSC_objc_method_result:
1706 case DeclSpecContext::DSC_condition:
1707 case DeclSpecContext::DSC_template_arg:
1708 case DeclSpecContext::DSC_conv_operator:
1709 case DeclSpecContext::DSC_association:
1712 llvm_unreachable(
"Missing DeclSpecContext case");
1717 struct ForRangeInit {
1718 SourceLocation ColonLoc;
1720 SmallVector<MaterializeTemporaryExpr *, 8> LifetimeExtendTemps;
1721 bool ParsedForRangeDecl() {
return !ColonLoc.
isInvalid(); }
1723 struct ForRangeInfo : ForRangeInit {
1746 SourceLocation &DeclEnd,
1747 ParsedAttributes &DeclAttrs,
1748 ParsedAttributes &DeclSpecAttrs,
1749 SourceLocation *DeclSpecStart =
nullptr);
1776 ParsedAttributes &DeclAttrs,
1777 ParsedAttributes &DeclSpecAttrs,
bool RequireSemi,
1778 ForRangeInit *FRI =
nullptr,
1779 SourceLocation *DeclSpecStart =
nullptr);
1789 ParsedAttributes &Attrs,
1790 ParsedTemplateInfo &TemplateInfo,
1791 SourceLocation *DeclEnd =
nullptr,
1792 ForRangeInit *FRI =
nullptr);
1818 Decl *ParseDeclarationAfterDeclarator(
1820 const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo());
1824 bool ParseAsmAttributesAfterDeclarator(Declarator &D);
1825 Decl *ParseDeclarationAfterDeclaratorAndAttributes(
1827 const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo(),
1828 ForRangeInit *FRI =
nullptr);
1839 bool ParseImplicitInt(DeclSpec &DS, CXXScopeSpec *SS,
1841 DeclSpecContext DSC, ParsedAttributes &Attrs);
1851 ParseDeclarationSpecifiers(DeclSpec &DS, ParsedTemplateInfo &TemplateInfo,
1853 DeclSpecContext DSC = DeclSpecContext::DSC_normal,
1854 LateParsedAttrList *LateAttrs =
nullptr) {
1855 return ParseDeclarationSpecifiers(DS, TemplateInfo, AS, DSC, LateAttrs,
1856 getImplicitTypenameContext(DSC));
1889 ParseDeclarationSpecifiers(DeclSpec &DS, ParsedTemplateInfo &TemplateInfo,
1891 LateParsedAttrList *LateAttrs,
1901 bool DiagnoseMissingSemiAfterTagDefinition(
1903 LateParsedAttrList *LateAttrs =
nullptr);
1905 void ParseSpecifierQualifierList(
1907 DeclSpecContext DSC = DeclSpecContext::DSC_normal) {
1908 ParseSpecifierQualifierList(DS, getImplicitTypenameContext(DSC), AS, DSC);
1919 void ParseSpecifierQualifierList(
1922 DeclSpecContext DSC = DeclSpecContext::DSC_normal);
1956 void ParseEnumSpecifier(SourceLocation TagLoc, DeclSpec &DS,
1957 const ParsedTemplateInfo &TemplateInfo,
1972 void ParseEnumBody(SourceLocation StartLoc, Decl *TagDecl,
1973 SkipBodyInfo *SkipBody =
nullptr);
1987 void ParseStructUnionBody(SourceLocation StartLoc,
DeclSpec::TST TagType,
1988 RecordDecl *TagDecl);
2013 void ParseStructDeclaration(
2014 ParsingDeclSpec &DS,
2015 llvm::function_ref<Decl *(ParsingFieldDeclarator &)> FieldsCallback,
2016 LateParsedAttrList *LateFieldAttrs =
nullptr);
2028 bool DisambiguatingWithExpression =
false);
2032 bool isTypeSpecifierQualifier();
2037 bool isKnownToBeTypeSpecifier(
const Token &Tok)
const;
2042 bool isConstructorDeclarator(
2045 const ParsedTemplateInfo *TemplateInfo =
nullptr);
2049 void DiagnoseBitIntUse(
const Token &Tok);
2053 bool CheckProhibitedCXX11Attribute() {
2054 assert(Tok.is(tok::l_square));
2057 return DiagnoseProhibitedCXX11Attribute();
2068 bool DiagnoseProhibitedCXX11Attribute();
2070 void CheckMisplacedCXX11Attribute(ParsedAttributes &Attrs,
2071 SourceLocation CorrectLocation) {
2072 if (!Tok.isRegularKeywordAttribute() &&
2073 (Tok.isNot(tok::l_square) ||
NextToken().
isNot(tok::l_square)) &&
2074 Tok.isNot(tok::kw_alignas))
2076 DiagnoseMisplacedCXX11Attribute(Attrs, CorrectLocation);
2083 void DiagnoseMisplacedCXX11Attribute(ParsedAttributes &Attrs,
2084 SourceLocation CorrectLocation);
2094 void stripTypeAttributesOffDeclSpec(ParsedAttributes &Attrs, DeclSpec &DS,
2098 void ProhibitAttributes(ParsedAttributes &Attrs,
2099 SourceLocation FixItLoc = SourceLocation()) {
2100 if (Attrs.Range.isInvalid())
2102 DiagnoseProhibitedAttributes(Attrs, FixItLoc);
2106 void ProhibitAttributes(ParsedAttributesView &Attrs,
2107 SourceLocation FixItLoc = SourceLocation()) {
2108 if (Attrs.Range.isInvalid())
2110 DiagnoseProhibitedAttributes(Attrs, FixItLoc);
2111 Attrs.clearListOnly();
2113 void DiagnoseProhibitedAttributes(
const ParsedAttributesView &Attrs,
2114 SourceLocation FixItLoc);
2122 void ProhibitCXX11Attributes(ParsedAttributes &Attrs,
unsigned AttrDiagID,
2123 unsigned KeywordDiagId,
2124 bool DiagnoseEmptyAttrs =
false,
2125 bool WarnOnUnknownAttrs =
false);
2129 void DiagnoseCXX11AttributeExtension(ParsedAttributes &Attrs);
2131 ExprResult ParseUnevaluatedStringInAttribute(
const IdentifierInfo &AttrName);
2138 bool ParseAttributeArgumentList(
2139 const IdentifierInfo &AttrName, SmallVectorImpl<Expr *> &Exprs,
2140 ParsedAttributeArgumentsProperties ArgsProperties,
unsigned Arg);
2147 ParseAttributeArgsCommon(IdentifierInfo *AttrName, SourceLocation AttrNameLoc,
2148 ParsedAttributes &Attrs, SourceLocation *EndLoc,
2149 IdentifierInfo *ScopeName, SourceLocation ScopeLoc,
2150 ParsedAttr::Form Form);
2152 enum ParseAttrKindMask {
2154 PAKM_Declspec = 1 << 1,
2155 PAKM_CXX11 = 1 << 2,
2174 void ParseAttributes(
unsigned WhichAttrKinds, ParsedAttributes &Attrs,
2175 LateParsedAttrList *LateAttrs =
nullptr);
2178 bool MaybeParseAttributes(
unsigned WhichAttrKinds, ParsedAttributes &Attrs,
2179 LateParsedAttrList *LateAttrs =
nullptr) {
2180 if (Tok.isOneOf(tok::kw___attribute, tok::kw___declspec) ||
2181 isAllowedCXX11AttributeSpecifier()) {
2182 ParseAttributes(WhichAttrKinds, Attrs, LateAttrs);
2188 void MaybeParseGNUAttributes(Declarator &D,
2189 LateParsedAttrList *LateAttrs =
nullptr) {
2190 if (Tok.is(tok::kw___attribute)) {
2191 ParsedAttributes Attrs(AttrFactory);
2192 ParseGNUAttributes(Attrs, LateAttrs, &D);
2193 D.takeAttributesAppending(Attrs);
2197 bool MaybeParseGNUAttributes(ParsedAttributes &Attrs,
2198 LateParsedAttrList *LateAttrs =
nullptr) {
2199 if (Tok.is(tok::kw___attribute)) {
2200 ParseGNUAttributes(Attrs, LateAttrs);
2222 bool ParseSingleGNUAttribute(ParsedAttributes &Attrs, SourceLocation &EndLoc,
2223 LateParsedAttrList *LateAttrs =
nullptr,
2224 Declarator *D =
nullptr);
2269 void ParseGNUAttributes(ParsedAttributes &Attrs,
2270 LateParsedAttrList *LateAttrs =
nullptr,
2271 Declarator *D =
nullptr);
2275 void ParseGNUAttributeArgs(IdentifierInfo *AttrName,
2276 SourceLocation AttrNameLoc,
2277 ParsedAttributes &Attrs, SourceLocation *EndLoc,
2278 IdentifierInfo *ScopeName, SourceLocation ScopeLoc,
2279 ParsedAttr::Form Form, Declarator *D);
2280 IdentifierLoc *ParseIdentifierLoc();
2283 ParseClangAttributeArgs(IdentifierInfo *AttrName, SourceLocation AttrNameLoc,
2284 ParsedAttributes &Attrs, SourceLocation *EndLoc,
2285 IdentifierInfo *ScopeName, SourceLocation ScopeLoc,
2286 ParsedAttr::Form Form);
2288 void MaybeParseCXX11Attributes(Declarator &D) {
2289 if (isAllowedCXX11AttributeSpecifier()) {
2290 ParsedAttributes Attrs(AttrFactory);
2291 ParseCXX11Attributes(Attrs);
2292 D.takeAttributesAppending(Attrs);
2296 bool MaybeParseCXX11Attributes(ParsedAttributes &Attrs,
2297 bool OuterMightBeMessageSend =
false) {
2298 if (isAllowedCXX11AttributeSpecifier(
false, OuterMightBeMessageSend)) {
2299 ParseCXX11Attributes(Attrs);
2305 bool MaybeParseMicrosoftAttributes(ParsedAttributes &Attrs) {
2306 bool AttrsParsed =
false;
2308 Tok.is(tok::l_square)) {
2309 ParsedAttributes AttrsWithRange(AttrFactory);
2310 ParseMicrosoftAttributes(AttrsWithRange);
2311 AttrsParsed = !AttrsWithRange.empty();
2312 Attrs.takeAllAppendingFrom(AttrsWithRange);
2316 bool MaybeParseMicrosoftDeclSpecs(ParsedAttributes &Attrs) {
2317 if (
getLangOpts().DeclSpecKeyword && Tok.is(tok::kw___declspec)) {
2318 ParseMicrosoftDeclSpecs(Attrs);
2332 void ParseMicrosoftDeclSpecs(ParsedAttributes &Attrs);
2333 bool ParseMicrosoftDeclSpecArgs(IdentifierInfo *AttrName,
2334 SourceLocation AttrNameLoc,
2335 ParsedAttributes &Attrs);
2336 void ParseMicrosoftTypeAttributes(ParsedAttributes &attrs);
2337 void ParseWebAssemblyFuncrefTypeAttribute(ParsedAttributes &Attrs);
2338 void DiagnoseAndSkipExtendedMicrosoftTypeAttributes();
2339 SourceLocation SkipExtendedMicrosoftTypeAttributes();
2341 void ParseBorlandTypeAttributes(ParsedAttributes &attrs);
2342 void ParseOpenCLKernelAttributes(ParsedAttributes &attrs);
2343 void ParseOpenCLQualifiers(ParsedAttributes &Attrs);
2344 void ParseNullabilityTypeSpecifiers(ParsedAttributes &attrs);
2345 void ParseCUDAFunctionAttributes(ParsedAttributes &attrs);
2346 bool isHLSLQualifier(
const Token &Tok)
const;
2347 void ParseHLSLQualifiers(ParsedAttributes &Attrs);
2359 VersionTuple ParseVersionTuple(SourceRange &Range);
2388 void ParseAvailabilityAttribute(IdentifierInfo &Availability,
2389 SourceLocation AvailabilityLoc,
2390 ParsedAttributes &attrs,
2391 SourceLocation *endLoc,
2392 IdentifierInfo *ScopeName,
2393 SourceLocation ScopeLoc,
2394 ParsedAttr::Form Form);
2412 void ParseExternalSourceSymbolAttribute(IdentifierInfo &ExternalSourceSymbol,
2414 ParsedAttributes &Attrs,
2415 SourceLocation *EndLoc,
2416 IdentifierInfo *ScopeName,
2417 SourceLocation ScopeLoc,
2418 ParsedAttr::Form Form);
2433 void ParseObjCBridgeRelatedAttribute(IdentifierInfo &ObjCBridgeRelated,
2434 SourceLocation ObjCBridgeRelatedLoc,
2435 ParsedAttributes &Attrs,
2436 SourceLocation *EndLoc,
2437 IdentifierInfo *ScopeName,
2438 SourceLocation ScopeLoc,
2439 ParsedAttr::Form Form);
2441 void ParseSwiftNewTypeAttribute(IdentifierInfo &AttrName,
2442 SourceLocation AttrNameLoc,
2443 ParsedAttributes &Attrs,
2444 SourceLocation *EndLoc,
2445 IdentifierInfo *ScopeName,
2446 SourceLocation ScopeLoc,
2447 ParsedAttr::Form Form);
2449 void ParseTypeTagForDatatypeAttribute(IdentifierInfo &AttrName,
2450 SourceLocation AttrNameLoc,
2451 ParsedAttributes &Attrs,
2452 SourceLocation *EndLoc,
2453 IdentifierInfo *ScopeName,
2454 SourceLocation ScopeLoc,
2455 ParsedAttr::Form Form);
2457 void ParseAttributeWithTypeArg(IdentifierInfo &AttrName,
2458 SourceLocation AttrNameLoc,
2459 ParsedAttributes &Attrs,
2460 IdentifierInfo *ScopeName,
2461 SourceLocation ScopeLoc,
2462 ParsedAttr::Form Form);
2464 void DistributeCLateParsedAttrs(Decl *Dcl, LateParsedAttrList *LateAttrs);
2470 void ParseBoundsAttribute(IdentifierInfo &AttrName,
2471 SourceLocation AttrNameLoc, ParsedAttributes &Attrs,
2472 IdentifierInfo *ScopeName, SourceLocation ScopeLoc,
2473 ParsedAttr::Form Form);
2489 void ParseTypeofSpecifier(DeclSpec &DS);
2496 void ParseAtomicSpecifier(DeclSpec &DS);
2506 ExprResult ParseAlignArgument(StringRef KWName, SourceLocation Start,
2507 SourceLocation &EllipsisLoc,
bool &IsType,
2520 void ParseAlignmentSpecifier(ParsedAttributes &Attrs,
2521 SourceLocation *endLoc =
nullptr);
2530 void ParsePtrauthQualifier(ParsedAttributes &Attrs);
2535 class DeclaratorScopeObj {
2542 DeclaratorScopeObj(
Parser &p, CXXScopeSpec &ss)
2543 : P(p), SS(ss), EnteredScope(
false), CreatedScope(
false) {}
2545 void EnterDeclaratorScope() {
2546 assert(!EnteredScope &&
"Already entered the scope!");
2547 assert(SS.isSet() &&
"C++ scope was not set!");
2549 CreatedScope =
true;
2552 if (!P.Actions.ActOnCXXEnterDeclaratorScope(P.getCurScope(), SS))
2553 EnteredScope =
true;
2556 ~DeclaratorScopeObj() {
2558 assert(SS.isSet() &&
"C++ scope was cleared ?");
2559 P.Actions.ActOnCXXExitDeclaratorScope(P.getCurScope(), SS);
2567 void ParseDeclarator(Declarator &D);
2598 void ParseDeclaratorInternal(Declarator &D,
2599 DirectDeclParseFunction DirectDeclParser);
2601 enum AttrRequirements {
2602 AR_NoAttributesParsed = 0,
2603 AR_GNUAttributesParsedAndRejected = 1 << 0,
2604 AR_GNUAttributesParsed = 1 << 1,
2605 AR_CXX11AttributesParsed = 1 << 2,
2606 AR_DeclspecAttributesParsed = 1 << 3,
2607 AR_AllAttributesParsed = AR_GNUAttributesParsed | AR_CXX11AttributesParsed |
2608 AR_DeclspecAttributesParsed,
2609 AR_VendorAttributesParsed =
2610 AR_GNUAttributesParsed | AR_DeclspecAttributesParsed
2627 void ParseTypeQualifierListOpt(
2628 DeclSpec &DS,
unsigned AttrReqs = AR_AllAttributesParsed,
2629 bool AtomicOrPtrauthAllowed =
true,
bool IdentifierRequired =
false,
2630 llvm::function_ref<
void()> CodeCompletionHandler = {});
2680 void ParseDirectDeclarator(Declarator &D);
2681 void ParseDecompositionDeclarator(Declarator &D);
2699 void ParseParenDeclarator(Declarator &D);
2724 void ParseFunctionDeclarator(Declarator &D, ParsedAttributes &FirstArgAttrs,
2726 bool IsAmbiguous,
bool RequiresArg =
false);
2727 void InitCXXThisScopeForDeclaratorIfRelevant(
2728 const Declarator &D,
const DeclSpec &DS,
2729 std::optional<Sema::CXXThisScopeRAII> &ThisScope);
2733 bool ParseRefQualifier(
bool &RefQualifierIsLValueRef,
2734 SourceLocation &RefQualifierLoc);
2741 bool isFunctionDeclaratorIdentifierList();
2755 void ParseFunctionDeclaratorIdentifierList(
2756 Declarator &D, SmallVectorImpl<DeclaratorChunk::ParamInfo> &ParamInfo);
2757 void ParseParameterDeclarationClause(
2758 Declarator &D, ParsedAttributes &attrs,
2759 SmallVectorImpl<DeclaratorChunk::ParamInfo> &ParamInfo,
2760 SourceLocation &EllipsisLoc) {
2761 return ParseParameterDeclarationClause(
2762 D.getContext(), attrs, ParamInfo, EllipsisLoc,
2763 D.getCXXScopeSpec().isSet() &&
2764 D.isFunctionDeclaratorAFunctionDeclaration());
2802 void ParseParameterDeclarationClause(
2804 SmallVectorImpl<DeclaratorChunk::ParamInfo> &ParamInfo,
2805 SourceLocation &EllipsisLoc,
bool IsACXXFunctionDeclaration =
false);
2816 void ParseBracketDeclarator(Declarator &D);
2819 void ParseMisplacedBracketDeclarator(Declarator &D);
2830 TypeResult ParseTypeFromString(StringRef TypeStr, StringRef Context,
2831 SourceLocation IncludeLoc);
2847 mutable IdentifierInfo *Ident_sealed;
2848 mutable IdentifierInfo *Ident_abstract;
2851 mutable IdentifierInfo *Ident_final;
2852 mutable IdentifierInfo *Ident_GNU_final;
2853 mutable IdentifierInfo *Ident_override;
2858 struct ParsingClass {
2859 ParsingClass(Decl *TagOrTemplate,
bool TopLevelClass,
bool IsInterface)
2860 : TopLevelClass(TopLevelClass), IsInterface(IsInterface),
2861 TagOrTemplate(TagOrTemplate) {}
2865 bool TopLevelClass : 1;
2868 bool IsInterface : 1;
2871 Decl *TagOrTemplate;
2876 LateParsedDeclarationsContainer LateParsedDeclarations;
2882 std::stack<ParsingClass *> ClassStack;
2884 ParsingClass &getCurrentClass() {
2885 assert(!ClassStack.empty() &&
"No lexed method stacks!");
2886 return *ClassStack.top();
2890 class ParsingClassDefinition {
2896 ParsingClassDefinition(
Parser &P, Decl *TagOrTemplate,
bool TopLevelClass,
2898 : P(P), Popped(
false),
2899 State(P.PushParsingClass(TagOrTemplate, TopLevelClass, IsInterface)) {
2904 assert(!Popped &&
"Nested class has already been popped");
2906 P.PopParsingClass(State);
2909 ~ParsingClassDefinition() {
2911 P.PopParsingClass(State);
2927 bool Delayed, SourceRange &SpecificationRange,
2928 SmallVectorImpl<ParsedType> &DynamicExceptions,
2929 SmallVectorImpl<SourceRange> &DynamicExceptionRanges,
2947 ParseDynamicExceptionSpecification(SourceRange &SpecificationRange,
2948 SmallVectorImpl<ParsedType> &Exceptions,
2949 SmallVectorImpl<SourceRange> &Ranges);
2956 TypeResult ParseTrailingReturnType(SourceRange &Range,
2957 bool MayBeFollowedByDirectInit);
2960 void ParseTrailingRequiresClause(Declarator &D);
2962 void ParseMicrosoftIfExistsClassDeclaration(
DeclSpec::TST TagType,
2963 ParsedAttributes &AccessAttrs,
2966 SourceLocation ParsePackIndexingType(DeclSpec &DS);
2967 void AnnotateExistingIndexedTypeNamePack(
ParsedType T,
2968 SourceLocation StartLoc,
2969 SourceLocation EndLoc);
2976 bool isAllowedCXX11AttributeSpecifier(
bool Disambiguate =
false,
2977 bool OuterMightBeMessageSend =
false) {
2978 return (Tok.isRegularKeywordAttribute() ||
2979 isCXX11AttributeSpecifier(Disambiguate, OuterMightBeMessageSend) !=
2986 SourceLocation SkipCXX11Attributes();
2990 void DiagnoseAndSkipCXX11Attributes();
2992 void ParseOpenMPAttributeArgs(
const IdentifierInfo *AttrName,
3021 void ParseCXX11AttributeSpecifierInternal(ParsedAttributes &Attrs,
3023 SourceLocation *EndLoc =
nullptr);
3024 void ParseCXX11AttributeSpecifier(ParsedAttributes &Attrs,
3025 SourceLocation *EndLoc =
nullptr) {
3027 ParseCXX11AttributeSpecifierInternal(Attrs, OpenMPTokens, EndLoc);
3028 ReplayOpenMPAttributeTokens(OpenMPTokens);
3037 void ParseCXX11Attributes(ParsedAttributes &attrs);
3057 bool ParseCXX11AttributeArgs(IdentifierInfo *AttrName,
3058 SourceLocation AttrNameLoc,
3059 ParsedAttributes &Attrs, SourceLocation *EndLoc,
3060 IdentifierInfo *ScopeName,
3061 SourceLocation ScopeLoc,
3067 ParseCXXAssumeAttributeArg(ParsedAttributes &Attrs, IdentifierInfo *AttrName,
3068 SourceLocation AttrNameLoc,
3069 IdentifierInfo *ScopeName, SourceLocation ScopeLoc,
3070 SourceLocation *EndLoc, ParsedAttr::Form Form);
3081 IdentifierInfo *TryParseCXX11AttributeIdentifier(
3082 SourceLocation &Loc,
3085 const IdentifierInfo *EnclosingScope =
nullptr);
3088 void ParseMicrosoftUuidAttributeArgs(ParsedAttributes &Attrs);
3100 void ParseMicrosoftAttributes(ParsedAttributes &Attrs);
3102 void ParseMicrosoftInheritanceClassAttributes(ParsedAttributes &attrs);
3103 void ParseNullabilityClassAttributes(ParsedAttributes &attrs);
3112 SourceLocation ParseDecltypeSpecifier(DeclSpec &DS);
3113 void AnnotateExistingDecltypeSpecifier(
const DeclSpec &DS,
3114 SourceLocation StartLoc,
3115 SourceLocation EndLoc);
3128 return isCXX11VirtSpecifier(Tok);
3138 void ParseOptionalCXX11VirtSpecifierSeq(VirtSpecifiers &VS,
bool IsInterface,
3139 SourceLocation FriendLoc);
3143 bool isCXX11FinalKeyword()
const;
3149 bool isClassCompatibleKeyword()
const;
3151 bool MaybeParseTypeTransformTypeSpecifier(DeclSpec &DS);
3154 void DiagnoseUnexpectedNamespace(NamedDecl *Context);
3186 SourceLocation &DeclEnd,
3187 SourceLocation InlineLoc = SourceLocation());
3189 struct InnerNamespaceInfo {
3190 SourceLocation NamespaceLoc;
3191 SourceLocation InlineLoc;
3192 SourceLocation IdentLoc;
3193 IdentifierInfo *Ident;
3195 using InnerNamespaceInfoList = llvm::SmallVector<InnerNamespaceInfo, 4>;
3198 void ParseInnerNamespace(
const InnerNamespaceInfoList &InnerNSs,
3199 unsigned int index, SourceLocation &InlineLoc,
3200 ParsedAttributes &attrs,
3232 Decl *ParseExportDeclaration();
3238 SourceLocation &DeclEnd, ParsedAttributes &Attrs);
3253 SourceLocation &DeclEnd, ParsedAttributes &attrs);
3255 struct UsingDeclarator {
3256 SourceLocation TypenameLoc;
3259 SourceLocation EllipsisLoc;
3262 TypenameLoc = EllipsisLoc = SourceLocation();
3303 const ParsedTemplateInfo &TemplateInfo,
3304 SourceLocation UsingLoc,
3305 SourceLocation &DeclEnd,
3306 ParsedAttributes &Attrs,
3308 Decl *ParseAliasDeclarationAfterDeclarator(
3309 const ParsedTemplateInfo &TemplateInfo, SourceLocation UsingLoc,
3311 ParsedAttributes &Attrs, Decl **OwnedType =
nullptr);
3324 Decl *ParseStaticAssertDeclaration(SourceLocation &DeclEnd);
3329 Decl *ParseNamespaceAlias(SourceLocation NamespaceLoc,
3330 SourceLocation AliasLoc, IdentifierInfo *Alias,
3331 SourceLocation &DeclEnd);
3339 bool isValidAfterTypeSpecifier(
bool CouldBeBitfield);
3383 void ParseClassSpecifier(
tok::TokenKind TagTokKind, SourceLocation TagLoc,
3384 DeclSpec &DS, ParsedTemplateInfo &TemplateInfo,
3386 DeclSpecContext DSC, ParsedAttributes &Attributes);
3387 void SkipCXXMemberSpecification(SourceLocation StartLoc,
3388 SourceLocation AttrFixitLoc,
unsigned TagType,
3399 void ParseCXXMemberSpecification(SourceLocation StartLoc,
3400 SourceLocation AttrFixitLoc,
3401 ParsedAttributes &Attrs,
unsigned TagType,
3426 ExprResult ParseCXXMemberInitializer(Decl *D,
bool IsFunction,
3427 SourceLocation &EqualLoc);
3431 bool ParseCXXMemberDeclaratorBeforeInitializer(Declarator &DeclaratorInfo,
3434 LateParsedAttrList &LateAttrs);
3439 MaybeParseAndDiagnoseDeclSpecAfterCXX11VirtSpecifierSeq(Declarator &D,
3440 VirtSpecifiers &VS);
3496 ParsedTemplateInfo &TemplateInfo,
3497 ParsingDeclRAIIObject *DiagsFromTParams =
nullptr);
3500 ParsedAttributes &AccessAttrs,
3526 void ParseConstructorInitializer(Decl *ConstructorDecl);
3548 void HandleMemberFunctionDeclDelays(Declarator &DeclaratorInfo,
3576 TypeResult ParseBaseTypeSpecifier(SourceLocation &BaseLoc,
3577 SourceLocation &EndLocation);
3589 void ParseBaseClause(Decl *ClassDecl);
3604 BaseResult ParseBaseSpecifier(Decl *ClassDecl);
3620 bool isClassCompatibleKeyword(Token Tok)
const;
3622 void ParseHLSLRootSignatureAttributeArgs(ParsedAttributes &Attrs);
3797 bool GreaterThanIsOperator;
3801 llvm::SmallDenseMap<IdentifierInfo *, tok::TokenKind> RevertibleTypeTraits;
3820 PushParsingClass(
Decl *TagOrTemplate,
bool TopLevelClass,
bool IsInterface);
3824 void DeallocateParsedClasses(ParsingClass *
Class);
4045 bool isAddressOfOperand,
bool &NotCastExpr,
4047 bool isVectorLiteral =
false,
4048 bool *NotPrimaryExpression =
nullptr);
4050 bool isAddressOfOperand =
false,
4053 bool isVectorLiteral =
false,
4054 bool *NotPrimaryExpression =
nullptr);
4057 bool isNotExpressionStart();
4061 bool isPostfixExpressionSuffixStart() {
4063 return (K == tok::l_square || K == tok::l_paren || K == tok::period ||
4064 K == tok::arrow || K == tok::plusplus || K == tok::minusminus);
4106 ExprResult ParseUnaryExprOrTypeTraitExpression();
4135 ExprResult ParseSYCLUniqueStableNameExpression();
4197 llvm::function_ref<
void()> ExpressionStarts =
4198 llvm::function_ref<
void()>(),
4199 bool FailImmediatelyOnInvalidExpr =
false);
4244 bool StopIfCastExpr,
4281 ExprResult ParseGenericSelectionExpression();
4300 void injectEmbedTokens();
4326 ExprResult ParseAssignmentExprWithObjCMessageExprStart(
4328 Expr *ReceiverExpr);
4333 bool isKnownToBeDeclarationSpecifier() {
4347 bool isTypeIdForGenericSelection() {
4353 return isTypeSpecifierQualifier();
4359 bool isTypeIdUnambiguously() {
4364 return isTypeSpecifierQualifier();
4373 void ParseBlockId(SourceLocation CaretLoc);
4382 std::optional<AvailabilitySpec> ParseAvailabilitySpec();
4383 ExprResult ParseAvailabilityCheckExpr(SourceLocation StartLoc);
4389 bool tryParseOpenMPArrayShapingCastPart();
4391 ExprResult ParseBuiltinPtrauthTypeDiscriminator();
4444 bool ObjectHadErrors,
bool EnteringContext,
4445 bool AllowDestructorName,
bool AllowConstructorName,
4446 bool AllowDeductionGuide,
4447 SourceLocation *TemplateKWLoc, UnqualifiedId &
Result);
4465 ExprResult tryParseCXXIdExpression(CXXScopeSpec &SS,
bool isAddressOfOperand,
4466 Token &Replacement);
4517 ExprResult ParseCXXIdExpression(
bool isAddressOfOperand =
false);
4520 bool areTokensAdjacent(
const Token &A,
const Token &B);
4524 void CheckForTemplateAndDigraph(Token &
Next,
ParsedType ObjectTypePtr,
4525 bool EnteringContext, IdentifierInfo &II,
4588 bool ParseOptionalCXXScopeSpecifier(
4589 CXXScopeSpec &SS,
ParsedType ObjectType,
bool ObjectHasErrors,
4590 bool EnteringContext,
bool *MayBePseudoDestructor =
nullptr,
4591 bool IsTypename =
false,
const IdentifierInfo **LastII =
nullptr,
4592 bool OnlyNamespace =
false,
bool InUsingDeclaration =
false,
4593 bool Disambiguation =
false,
bool IsAddressOfOperand =
false,
4594 bool IsInDeclarationContext =
false);
4596 bool ParseOptionalCXXScopeSpecifier(CXXScopeSpec &SS,
ParsedType ObjectType,
4597 bool ObjectHasErrors,
4598 bool EnteringContext,
4599 bool IsAddressOfOperand) {
4600 return ParseOptionalCXXScopeSpecifier(
4601 SS, ObjectType, ObjectHasErrors, EnteringContext,
4608 IsAddressOfOperand);
4615 enum class LambdaIntroducerTentativeParse {
4693 ParseLambdaIntroducer(LambdaIntroducer &Intro,
4694 LambdaIntroducerTentativeParse *Tentative =
nullptr);
4698 ExprResult ParseLambdaExpressionAfterIntroducer(LambdaIntroducer &Intro);
4782 ExprResult ParseCXXPseudoDestructor(Expr *Base, SourceLocation OpLoc,
4837 ExprResult ParseCXXTypeConstructExpression(
const DeclSpec &DS);
4867 void ParseCXXSimpleTypeSpecifier(DeclSpec &DS);
4882 bool ParseCXXTypeSpecifierSeq(
4900 bool ParseExpressionListOrTypeId(SmallVectorImpl<Expr *> &Exprs,
4912 void ParseDirectNewDeclarator(Declarator &D);
4945 ExprResult ParseCXXNewExpression(
bool UseGlobal, SourceLocation Start);
4960 ExprResult ParseCXXDeleteExpression(
bool UseGlobal, SourceLocation Start);
4999 Sema::ConditionResult ParseCXXCondition(
StmtResult *InitStmt,
5003 ForRangeInfo *FRI =
nullptr,
5004 bool EnterForConditionScope =
false);
5006 ParsedAttributes &Attrs);
5053 bool isTypeIdInParens(
bool &isAmbiguous) {
5056 isAmbiguous =
false;
5057 return isTypeSpecifierQualifier();
5059 bool isTypeIdInParens() {
5061 return isTypeIdInParens(isAmbiguous);
5099 bool ParseUnqualifiedIdTemplateId(CXXScopeSpec &SS,
ParsedType ObjectType,
5100 bool ObjectHadErrors,
5101 SourceLocation TemplateKWLoc,
5102 IdentifierInfo *Name,
5103 SourceLocation NameLoc,
5104 bool EnteringContext, UnqualifiedId &Id,
5105 bool AssumeTemplateId);
5147 bool ParseUnqualifiedIdOperator(CXXScopeSpec &SS,
bool EnteringContext,
5214 bool MaybeParseHLSLAnnotations(Declarator &D,
5215 SourceLocation *EndLoc =
nullptr,
5216 bool CouldBeBitField =
false) {
5217 assert(
getLangOpts().
HLSL &&
"MaybeParseHLSLAnnotations is for HLSL only");
5218 if (Tok.is(tok::colon)) {
5219 ParsedAttributes Attrs(AttrFactory);
5220 ParseHLSLAnnotations(Attrs, EndLoc, CouldBeBitField);
5221 D.takeAttributesAppending(Attrs);
5227 void MaybeParseHLSLAnnotations(ParsedAttributes &Attrs,
5228 SourceLocation *EndLoc =
nullptr) {
5229 assert(
getLangOpts().
HLSL &&
"MaybeParseHLSLAnnotations is for HLSL only");
5230 if (Tok.is(tok::colon))
5231 ParseHLSLAnnotations(Attrs, EndLoc);
5234 struct ParsedSemantic {
5235 StringRef Name =
"";
5237 bool Explicit =
false;
5240 ParsedSemantic ParseHLSLSemantic();
5242 void ParseHLSLAnnotations(ParsedAttributes &Attrs,
5243 SourceLocation *EndLoc =
nullptr,
5244 bool CouldBeBitField =
false);
5245 Decl *ParseHLSLBuffer(SourceLocation &DeclEnd, ParsedAttributes &Attrs);
5269 ExprResult ParseInitializer(Decl *DeclForInitializer =
nullptr);
5274 bool MayBeDesignationStart();
5292 struct DesignatorCompletionInfo {
5293 SmallVectorImpl<Expr *> &InitExprs;
5294 QualType PreferredBaseType;
5343 ExprResult ParseInitializerWithPotentialDesignator(DesignatorCompletionInfo);
5348 typedef SmallVector<Expr *, 12> ExprVector;
5352 bool ParseMicrosoftIfExistsBraceInitializer(ExprVector &InitExprs,
5369 friend class ObjCDeclContextSwitch;
5372 return Actions.ObjC().getObjCDeclContext();
5378 return Actions.getNullabilityKeyword(nullability);
5394 bool InMessageExpression;
5401 bool ParsingInObjCContainer;
5406 bool isObjCInstancetype() {
5408 if (
Tok.isAnnotation())
5410 if (!Ident_instancetype)
5412 return Tok.getIdentifierInfo() == Ident_instancetype;
5420 ObjCContainerDecl *DC;
5421 SaveAndRestore<bool> WithinObjCContainer;
5426 WithinObjCContainer(P.ParsingInObjCContainer, DC !=
nullptr) {
5428 P.Actions.ObjC().ActOnObjCTemporaryExitContainerContext(DC);
5430 ~ObjCDeclContextSwitch() {
5432 P.Actions.ObjC().ActOnObjCReenterContainerContext(DC);
5436 void CheckNestedObjCContexts(SourceLocation AtLoc);
5438 void ParseLexedObjCMethodDefs(LexedMethod &LM,
bool parseMethod);
5456 DeclGroupPtrTy ParseObjCAtDirectives(ParsedAttributes &DeclAttrs,
5457 ParsedAttributes &DeclSpecAttrs);
5468 DeclGroupPtrTy ParseObjCAtClassDeclaration(SourceLocation atLoc);
5501 Decl *ParseObjCAtInterfaceDeclaration(SourceLocation AtLoc,
5502 ParsedAttributes &prefixAttrs);
5508 ObjCTypeParamList *parseObjCTypeParamList();
5536 ObjCTypeParamList *parseObjCTypeParamListOrProtocolRefs(
5538 SmallVectorImpl<IdentifierLoc> &protocolIdents, SourceLocation &rAngleLoc,
5539 bool mayBeProtocolList =
true);
5541 void HelperActionsForIvarDeclarations(ObjCContainerDecl *interfaceDecl,
5542 SourceLocation atLoc,
5544 SmallVectorImpl<Decl *> &AllIvarDecls,
5545 bool RBraceMissing);
5570 void ParseObjCClassInstanceVariables(ObjCContainerDecl *interfaceDecl,
5572 SourceLocation atLoc);
5579 bool ParseObjCProtocolReferences(
5580 SmallVectorImpl<Decl *> &P, SmallVectorImpl<SourceLocation> &PLocs,
5581 bool WarnOnDeclarations,
bool ForObjCContainer, SourceLocation &LAngleLoc,
5582 SourceLocation &EndProtoLoc,
bool consumeLastToken);
5593 void parseObjCTypeArgsOrProtocolQualifiers(
5594 ParsedType baseType, SourceLocation &typeArgsLAngleLoc,
5595 SmallVectorImpl<ParsedType> &typeArgs, SourceLocation &typeArgsRAngleLoc,
5596 SourceLocation &protocolLAngleLoc, SmallVectorImpl<Decl *> &protocols,
5597 SmallVectorImpl<SourceLocation> &protocolLocs,
5598 SourceLocation &protocolRAngleLoc,
bool consumeLastToken,
5599 bool warnOnIncompleteProtocols);
5603 void parseObjCTypeArgsAndProtocolQualifiers(
5604 ParsedType baseType, SourceLocation &typeArgsLAngleLoc,
5605 SmallVectorImpl<ParsedType> &typeArgs, SourceLocation &typeArgsRAngleLoc,
5606 SourceLocation &protocolLAngleLoc, SmallVectorImpl<Decl *> &protocols,
5607 SmallVectorImpl<SourceLocation> &protocolLocs,
5608 SourceLocation &protocolRAngleLoc,
bool consumeLastToken);
5612 TypeResult parseObjCProtocolQualifierType(SourceLocation &rAngleLoc);
5616 TypeResult parseObjCTypeArgsAndProtocolQualifiers(SourceLocation loc,
5618 bool consumeLastToken,
5619 SourceLocation &endLoc);
5655 DeclGroupPtrTy ParseObjCAtProtocolDeclaration(SourceLocation atLoc,
5656 ParsedAttributes &prefixAttrs);
5658 struct ObjCImplParsingDataRAII {
5662 typedef SmallVector<LexedMethod *, 8> LateParsedObjCMethodContainer;
5663 LateParsedObjCMethodContainer LateParsedObjCMethods;
5665 ObjCImplParsingDataRAII(
Parser &parser, Decl *D)
5666 : P(parser), Dcl(D), HasCFunction(
false) {
5667 P.CurParsedObjCImpl =
this;
5670 ~ObjCImplParsingDataRAII();
5672 void finish(SourceRange AtEnd);
5673 bool isFinished()
const {
return Finished; }
5678 ObjCImplParsingDataRAII *CurParsedObjCImpl;
5682 void StashAwayMethodOrFunctionBodyTokens(Decl *MDecl);
5696 DeclGroupPtrTy ParseObjCAtImplementationDeclaration(SourceLocation AtLoc,
5697 ParsedAttributes &Attrs);
5705 Decl *ParseObjCAtAliasDeclaration(SourceLocation atLoc);
5720 Decl *ParseObjCPropertySynthesize(SourceLocation atLoc);
5731 Decl *ParseObjCPropertyDynamic(SourceLocation atLoc);
5743 IdentifierInfo *ParseObjCSelectorPiece(SourceLocation &MethodLocation);
5751 bool isTokIdentifier_in()
const;
5760 ParsedAttributes *ParamAttrs);
5774 Decl *ParseObjCMethodPrototype(
5776 bool MethodDefinition =
true);
5808 Decl *ParseObjCMethodDecl(
5811 bool MethodDefinition =
true);
5841 void ParseObjCPropertyAttribute(ObjCDeclSpec &DS);
5847 Decl *ParseObjCMethodDefinition();
5851 ExprResult ParseObjCAtExpression(SourceLocation AtLocation);
5852 ExprResult ParseObjCStringLiteral(SourceLocation AtLoc);
5859 ExprResult ParseObjCCharacterLiteral(SourceLocation AtLoc);
5868 ExprResult ParseObjCNumericLiteral(SourceLocation AtLoc);
5877 ExprResult ParseObjCBooleanLiteral(SourceLocation AtLoc,
bool ArgValue);
5879 ExprResult ParseObjCArrayLiteral(SourceLocation AtLoc);
5880 ExprResult ParseObjCDictionaryLiteral(SourceLocation AtLoc);
5887 ExprResult ParseObjCBoxedExpr(SourceLocation AtLoc);
5893 ExprResult ParseObjCEncodeExpression(SourceLocation AtLoc);
5899 ExprResult ParseObjCSelectorExpression(SourceLocation AtLoc);
5905 ExprResult ParseObjCProtocolExpression(SourceLocation AtLoc);
5912 bool isSimpleObjCMessageExpression();
5967 ExprResult ParseObjCMessageExpressionBody(SourceLocation LBracloc,
5968 SourceLocation SuperLoc,
5970 Expr *ReceiverExpr);
5996 bool ParseObjCXXMessageReceiver(
bool &IsExpr,
void *&TypeOrExpr);
6001 enum class ParsedStmtContext;
6003 StmtResult ParseObjCAtStatement(SourceLocation atLoc,
6004 ParsedStmtContext StmtCtx);
6019 StmtResult ParseObjCTryStmt(SourceLocation atLoc);
6026 StmtResult ParseObjCThrowStmt(SourceLocation atLoc);
6033 StmtResult ParseObjCSynchronizedStmt(SourceLocation atLoc);
6040 StmtResult ParseObjCAutoreleasePoolStmt(SourceLocation atLoc);
6067 bool isStartOfObjCClassMessageMissingOpenBracket();
6099 bool OpenACCDirectiveParsing =
false;
6103 bool AllowOpenACCArraySections =
false;
6107 class OpenACCArraySectionRAII {
6111 OpenACCArraySectionRAII(
Parser &P) : P(P) {
6112 assert(!P.AllowOpenACCArraySections);
6113 P.AllowOpenACCArraySections =
true;
6115 ~OpenACCArraySectionRAII() {
6116 assert(P.AllowOpenACCArraySections);
6117 P.AllowOpenACCArraySections =
false;
6124 struct OpenACCDirectiveParseInfo {
6126 SourceLocation StartLoc;
6127 SourceLocation DirLoc;
6128 SourceLocation LParenLoc;
6129 SourceLocation RParenLoc;
6130 SourceLocation EndLoc;
6131 SourceLocation MiscLoc;
6133 SmallVector<Expr *> Exprs;
6134 SmallVector<OpenACCClause *> Clauses;
6139 struct OpenACCWaitParseInfo {
6140 bool Failed =
false;
6141 Expr *DevNumExpr =
nullptr;
6142 SourceLocation QueuesLoc;
6143 SmallVector<Expr *> QueueIdExprs;
6145 SmallVector<Expr *> getAllExprs() {
6146 SmallVector<Expr *>
Out;
6147 Out.push_back(DevNumExpr);
6148 llvm::append_range(Out, QueueIdExprs);
6152 struct OpenACCCacheParseInfo {
6153 bool Failed =
false;
6154 SourceLocation ReadOnlyLoc;
6155 SmallVector<Expr *> Vars;
6160 enum class OpenACCParseCanContinue { Cannot = 0, Can = 1 };
6166 using OpenACCClauseParseResult =
6167 llvm::PointerIntPair<OpenACCClause *, 1, OpenACCParseCanContinue>;
6169 OpenACCClauseParseResult OpenACCCanContinue();
6170 OpenACCClauseParseResult OpenACCCannotContinue();
6171 OpenACCClauseParseResult OpenACCSuccess(OpenACCClause *Clause);
6175 OpenACCDirectiveParseInfo ParseOpenACCDirective();
6185 OpenACCCacheParseInfo ParseOpenACCCacheVarList();
6191 using OpenACCVarParseResult = std::pair<ExprResult, OpenACCParseCanContinue>;
6217 OpenACCClauseParseResult
6218 ParseOpenACCClauseParams(ArrayRef<const OpenACCClause *> ExistingClauses,
6220 SourceLocation ClauseLoc);
6224 OpenACCClauseParseResult
6225 ParseOpenACCClause(ArrayRef<const OpenACCClause *> ExistingClauses,
6235 SmallVector<OpenACCClause *>
6244 OpenACCWaitParseInfo ParseOpenACCWaitArgument(SourceLocation Loc,
6249 std::variant<std::monostate, StringLiteral *, IdentifierInfo *>
6250 ParseOpenACCBindClauseArgument();
6255 using OpenACCIntExprParseResult =
6256 std::pair<ExprResult, OpenACCParseCanContinue>;
6261 SourceLocation Loc);
6266 llvm::SmallVectorImpl<Expr *> &IntExprs);
6279 bool ParseOpenACCDeviceTypeList(llvm::SmallVector<IdentifierLoc> &Archs);
6293 SourceLocation Loc);
6308 llvm::SmallVectorImpl<Expr *> &SizeExprs);
6320 bool ParseOpenACCGangArgList(SourceLocation GangLoc,
6321 llvm::SmallVectorImpl<OpenACCGangKind> &GKs,
6322 llvm::SmallVectorImpl<Expr *> &IntExprs);
6324 using OpenACCGangArgRes = std::pair<OpenACCGangKind, ExprResult>;
6328 OpenACCGangArgRes ParseOpenACCGangArg(SourceLocation GangLoc);
6332 ParseOpenACCAfterRoutineDecl(
AccessSpecifier &AS, ParsedAttributes &Attrs,
6334 OpenACCDirectiveParseInfo &DirInfo);
6335 StmtResult ParseOpenACCAfterRoutineStmt(OpenACCDirectiveParseInfo &DirInfo);
6353 bool OpenMPDirectiveParsing =
false;
6358 void ReplayOpenMPAttributeTokens(
CachedTokens &OpenMPTokens) {
6361 if (!OpenMPTokens.empty()) {
6362 PP.EnterToken(Tok,
true);
6363 PP.EnterTokenStream(OpenMPTokens,
true,
6375 SourceLocation Loc);
6380 llvm::omp::TraitSet
Set,
6381 llvm::omp::TraitSelector Selector,
6382 llvm::StringMap<SourceLocation> &Seen);
6386 llvm::omp::TraitSet
Set,
6387 llvm::StringMap<SourceLocation> &Seen);
6391 llvm::StringMap<SourceLocation> &Seen);
6395 llvm::omp::TraitSet
Set,
6396 llvm::StringMap<SourceLocation> &Seen);
6404 llvm::omp::TraitSet
Set,
6405 llvm::StringMap<SourceLocation> &SeenSelectors);
6412 void parseOMPContextSelectorSet(
OMPTraitSet &TISet,
6413 llvm::StringMap<SourceLocation> &SeenSets);
6420 bool parseOMPContextSelectors(SourceLocation Loc,
OMPTraitInfo &TI);
6423 bool parseOpenMPAppendArgs(SmallVectorImpl<OMPInteropInfo> &InteropInfos);
6427 bool parseOMPDeclareVariantMatchClause(SourceLocation Loc,
OMPTraitInfo &TI,
6433 SourceLocation Loc);
6452 void ParseOpenMPAssumesDirective(OpenMPDirectiveKind DKind,
6453 SourceLocation Loc);
6456 void ParseOpenMPEndAssumesDirective(SourceLocation Loc);
6473 void ParseOpenMPClauses(OpenMPDirectiveKind DKind,
6474 SmallVectorImpl<clang::OMPClause *> &Clauses,
6475 SourceLocation Loc);
6478 void ParseOMPDeclareTargetClauses(SemaOpenMP::DeclareTargetContextInfo &DTCI);
6481 void ParseOMPEndDeclareTargetDirective(OpenMPDirectiveKind BeginDKind,
6482 OpenMPDirectiveKind EndDKind,
6483 SourceLocation Loc);
6487 void skipUntilPragmaOpenMPEnd(OpenMPDirectiveKind DKind);
6493 void parseOMPEndDirective(OpenMPDirectiveKind BeginKind,
6494 OpenMPDirectiveKind ExpectedKind,
6495 OpenMPDirectiveKind FoundKind,
6496 SourceLocation MatchingLoc, SourceLocation FoundLoc,
6497 bool SkipUntilOpenMPEnd);
6538 AccessSpecifier &AS, ParsedAttributes &Attrs,
bool Delayed =
false,
6540 Decl *TagDecl =
nullptr);
6554 DeclGroupPtrTy ParseOpenMPDeclareReductionDirective(AccessSpecifier AS);
6558 void ParseOpenMPReductionInitializerForDecl(VarDecl *OmpPrivParm);
6570 DeclGroupPtrTy ParseOpenMPDeclareMapperDirective(AccessSpecifier AS);
6573 TypeResult parseOpenMPDeclareMapperVarDecl(SourceRange &Range,
6574 DeclarationName &Name,
6575 AccessSpecifier AS =
AS_none);
6589 bool ParseOpenMPSimpleVarList(
6590 OpenMPDirectiveKind Kind,
6591 const llvm::function_ref<
void(CXXScopeSpec &, DeclarationNameInfo)>
6593 bool AllowScopeSpecifier);
6642 StmtResult ParseOpenMPDeclarativeOrExecutableDirective(
6643 ParsedStmtContext StmtCtx,
bool ReadDirectiveWithinMetadirective =
false);
6653 ParseOpenMPExecutableDirective(ParsedStmtContext StmtCtx,
6654 OpenMPDirectiveKind DKind, SourceLocation Loc,
6655 bool ReadDirectiveWithinMetadirective);
6664 StmtResult ParseOpenMPInformationalDirective(
6665 ParsedStmtContext StmtCtx, OpenMPDirectiveKind DKind, SourceLocation Loc,
6666 bool ReadDirectiveWithinMetadirective);
6695 OMPClause *ParseOpenMPClause(OpenMPDirectiveKind DKind,
6780 bool ParseOpenMPIndirectClause(SemaOpenMP::DeclareTargetContextInfo &DTCI,
6805 OMPClause *ParseOpenMPSingleExprWithArgClause(OpenMPDirectiveKind DKind,
6810 OMPClause *ParseOpenMPLoopRangeClause();
6816 OMPClause *ParseOpenMPPermutationClause();
6920 OMPClause *ParseOpenMPVarListClause(OpenMPDirectiveKind DKind,
6934 SourceLocation &ClauseNameLoc,
6935 SourceLocation &OpenLoc,
6936 SourceLocation &CloseLoc,
6937 SmallVectorImpl<Expr *> &Exprs,
6938 bool ReqIntConst =
false);
6953 OMPClause *ParseOpenMPUsesAllocatorClause(OpenMPDirectiveKind DKind);
6956 bool ParseOMPInteropInfo(OMPInteropInfo &InteropInfo,
OpenMPClauseKind Kind);
6994 OMPClause *ParseOpenMPOMPXAttributesClause(
bool ParseOnly);
7001 bool IsAddressOfOperand =
false);
7005 SemaOpenMP::OpenMPVarListDataTy &
Data,
7006 const LangOptions &LangOpts);
7009 SmallVectorImpl<Expr *> &Vars,
7010 SemaOpenMP::OpenMPVarListDataTy &
Data);
7045 std::unique_ptr<PragmaHandler> AlignHandler;
7046 std::unique_ptr<PragmaHandler> GCCVisibilityHandler;
7047 std::unique_ptr<PragmaHandler> OptionsHandler;
7048 std::unique_ptr<PragmaHandler> PackHandler;
7049 std::unique_ptr<PragmaHandler> MSStructHandler;
7050 std::unique_ptr<PragmaHandler> UnusedHandler;
7051 std::unique_ptr<PragmaHandler> WeakHandler;
7052 std::unique_ptr<PragmaHandler> RedefineExtnameHandler;
7053 std::unique_ptr<PragmaHandler> FPContractHandler;
7054 std::unique_ptr<PragmaHandler> OpenCLExtensionHandler;
7055 std::unique_ptr<PragmaHandler> OpenMPHandler;
7056 std::unique_ptr<PragmaHandler> OpenACCHandler;
7057 std::unique_ptr<PragmaHandler> PCSectionHandler;
7058 std::unique_ptr<PragmaHandler> MSCommentHandler;
7059 std::unique_ptr<PragmaHandler> MSDetectMismatchHandler;
7060 std::unique_ptr<PragmaHandler> FPEvalMethodHandler;
7061 std::unique_ptr<PragmaHandler> FloatControlHandler;
7062 std::unique_ptr<PragmaHandler> MSPointersToMembers;
7063 std::unique_ptr<PragmaHandler> MSVtorDisp;
7064 std::unique_ptr<PragmaHandler> MSInitSeg;
7065 std::unique_ptr<PragmaHandler> MSDataSeg;
7066 std::unique_ptr<PragmaHandler> MSBSSSeg;
7067 std::unique_ptr<PragmaHandler> MSConstSeg;
7068 std::unique_ptr<PragmaHandler> MSCodeSeg;
7069 std::unique_ptr<PragmaHandler> MSSection;
7070 std::unique_ptr<PragmaHandler> MSStrictGuardStackCheck;
7071 std::unique_ptr<PragmaHandler> MSRuntimeChecks;
7072 std::unique_ptr<PragmaHandler> MSIntrinsic;
7073 std::unique_ptr<PragmaHandler> MSFunction;
7074 std::unique_ptr<PragmaHandler> MSOptimize;
7075 std::unique_ptr<PragmaHandler> MSFenvAccess;
7076 std::unique_ptr<PragmaHandler> MSAllocText;
7077 std::unique_ptr<PragmaHandler> CUDAForceHostDeviceHandler;
7078 std::unique_ptr<PragmaHandler> OptimizeHandler;
7079 std::unique_ptr<PragmaHandler> LoopHintHandler;
7080 std::unique_ptr<PragmaHandler> UnrollHintHandler;
7081 std::unique_ptr<PragmaHandler> NoUnrollHintHandler;
7082 std::unique_ptr<PragmaHandler> UnrollAndJamHintHandler;
7083 std::unique_ptr<PragmaHandler> NoUnrollAndJamHintHandler;
7084 std::unique_ptr<PragmaHandler> FPHandler;
7085 std::unique_ptr<PragmaHandler> STDCFenvAccessHandler;
7086 std::unique_ptr<PragmaHandler> STDCFenvRoundHandler;
7087 std::unique_ptr<PragmaHandler> STDCCXLIMITHandler;
7088 std::unique_ptr<PragmaHandler> STDCUnknownHandler;
7089 std::unique_ptr<PragmaHandler> AttributePragmaHandler;
7090 std::unique_ptr<PragmaHandler> MaxTokensHerePragmaHandler;
7091 std::unique_ptr<PragmaHandler> MaxTokensTotalPragmaHandler;
7092 std::unique_ptr<PragmaHandler> ExportHandler;
7093 std::unique_ptr<PragmaHandler> RISCVPragmaHandler;
7096 void initializePragmaHandlers();
7099 void resetPragmaHandlers();
7106 void HandlePragmaUnused();
7110 void HandlePragmaVisibility();
7114 void HandlePragmaPack();
7118 void HandlePragmaMSStruct();
7120 void HandlePragmaMSPointersToMembers();
7122 void HandlePragmaMSVtorDisp();
7124 void HandlePragmaMSPragma();
7125 bool HandlePragmaMSSection(StringRef PragmaName,
7126 SourceLocation PragmaLocation);
7127 bool HandlePragmaMSSegment(StringRef PragmaName,
7128 SourceLocation PragmaLocation);
7131 bool HandlePragmaMSInitSeg(StringRef PragmaName,
7132 SourceLocation PragmaLocation);
7137 bool HandlePragmaMSStrictGuardStackCheck(StringRef PragmaName,
7138 SourceLocation PragmaLocation);
7139 bool HandlePragmaMSFunction(StringRef PragmaName,
7140 SourceLocation PragmaLocation);
7141 bool HandlePragmaMSAllocText(StringRef PragmaName,
7142 SourceLocation PragmaLocation);
7145 bool HandlePragmaMSOptimize(StringRef PragmaName,
7146 SourceLocation PragmaLocation);
7149 bool HandlePragmaMSIntrinsic(StringRef PragmaName,
7150 SourceLocation PragmaLocation);
7154 void HandlePragmaAlign();
7158 void HandlePragmaDump();
7162 void HandlePragmaWeak();
7166 void HandlePragmaWeakAlias();
7170 void HandlePragmaRedefineExtname();
7174 void HandlePragmaFPContract();
7178 void HandlePragmaFEnvAccess();
7182 void HandlePragmaFEnvRound();
7186 void HandlePragmaCXLimitedRange();
7190 void HandlePragmaFloatControl();
7194 void HandlePragmaFP();
7198 void HandlePragmaOpenCLExtension();
7202 StmtResult HandlePragmaCaptured();
7206 bool HandlePragmaLoopHint(LoopHint &Hint);
7208 bool ParsePragmaAttributeSubjectMatchRuleSet(
7210 SourceLocation &AnyLoc, SourceLocation &LastMatchRuleEndLoc);
7212 void HandlePragmaAttribute();
7218 void HandlePragmaExport();
7244 enum class ParsedStmtContext {
7247 AllowDeclarationsInC = 0x1,
7249 AllowStandaloneOpenMPDirectives = 0x2,
7256 Compound = AllowDeclarationsInC | AllowStandaloneOpenMPDirectives,
7273 ParsedStmtContext StmtCtx = ParsedStmtContext::SubStmt,
7328 ParseStatementOrDeclaration(
StmtVector &Stmts, ParsedStmtContext StmtCtx,
7332 StmtResult ParseStatementOrDeclarationAfterAttributes(
7333 StmtVector &Stmts, ParsedStmtContext StmtCtx,
7338 StmtResult ParseExprStatement(ParsedStmtContext StmtCtx);
7352 ParsedStmtContext StmtCtx);
7361 StmtResult ParseCaseStatement(ParsedStmtContext StmtCtx,
7362 bool MissingCase =
false,
7372 StmtResult ParseDefaultStatement(ParsedStmtContext StmtCtx);
7374 StmtResult ParseCompoundStatement(
bool isStmtExpr =
false);
7400 StmtResult ParseCompoundStatement(
bool isStmtExpr,
unsigned ScopeFlags);
7405 void ParseCompoundStatementLeadingPragmas();
7407 void DiagnoseLabelAtEndOfCompoundStatement();
7417 StmtResult ParseCompoundStatementBody(
bool isStmtExpr =
false);
7435 bool ParseParenExprOrCondition(
StmtResult *InitStmt,
7551 StmtResult ParseBreakOrContinueStatement(
bool IsContinue);
7568 void ParseMicrosoftIfExistsStatement(
StmtVector &Stmts);
7615 StmtResult ParseCXXCatchBlock(
bool FnCatch =
false);
7653 Decl *ParseFunctionStatementBody(
Decl *
Decl, ParseScope &BodyScope);
7662 Decl *ParseFunctionTryBlock(
Decl *
Decl, ParseScope &BodyScope);
7668 bool trySkippingFunctionBody();
7676 bool isDeclarationStatement(
bool DisambiguatingWithExpression =
false) {
7678 return isCXXDeclarationStatement(DisambiguatingWithExpression);
7686 bool isForInitDeclaration() {
7690 return Tok.is(tok::kw_using) ||
7691 isCXXSimpleDeclaration(
true);
7696 bool isForRangeIdentifier();
7713 unsigned &NumLineToksConsumed,
7714 bool IsUnevaluated);
7757 StmtResult ParseMicrosoftAsmStatement(SourceLocation AsmLoc);
7773 bool ParseAsmOperandsOpt(SmallVectorImpl<IdentifierInfo *> &Names,
7774 SmallVectorImpl<Expr *> &Constraints,
7775 SmallVectorImpl<Expr *> &Exprs);
7777 class GNUAsmQualifiers {
7778 unsigned Qualifiers = AQ_unspecified;
7787 static const char *getQualifierName(AQ Qualifier);
7788 bool setAsmQualifier(AQ Qualifier);
7789 inline bool isVolatile()
const {
return Qualifiers & AQ_volatile; };
7790 inline bool isInline()
const {
return Qualifiers & AQ_inline; };
7791 inline bool isGoto()
const {
return Qualifiers & AQ_goto; }
7795 bool isGCCAsmStatement(
const Token &TokAfterAsm)
const;
7797 bool isGNUAsmQualifier(
const Token &TokAfterAsm)
const;
7798 GNUAsmQualifiers::AQ getGNUAsmQualifier(
const Token &Tok)
const;
7811 bool parseGNUAsmQualifierListOpt(GNUAsmQualifiers &AQ);
7835 unsigned TemplateParameterDepth;
7838 class TemplateParameterDepthRAII {
7840 unsigned AddedLevels;
7843 explicit TemplateParameterDepthRAII(
unsigned &Depth)
7844 : Depth(Depth), AddedLevels(0) {}
7846 ~TemplateParameterDepthRAII() { Depth -= AddedLevels; }
7852 void addDepth(
unsigned D) {
7856 void setAddedDepth(
unsigned D) {
7857 Depth = Depth - AddedLevels + D;
7861 unsigned getDepth()
const {
return Depth; }
7862 unsigned getOriginalDepth()
const {
return Depth - AddedLevels; }
7867 SmallVector<TemplateIdAnnotation *, 16> TemplateIds;
7873 bool DelayTemplateIdDestruction =
false;
7875 void MaybeDestroyTemplateIds() {
7876 if (DelayTemplateIdDestruction)
7878 if (!TemplateIds.empty() &&
7879 (Tok.is(tok::eof) || !PP.mightHavePendingAnnotationTokens()))
7880 DestroyTemplateIds();
7882 void DestroyTemplateIds();
7886 struct DestroyTemplateIdAnnotationsRAIIObj {
7889 DestroyTemplateIdAnnotationsRAIIObj(
Parser &Self) : Self(Self) {}
7890 ~DestroyTemplateIdAnnotationsRAIIObj() { Self.MaybeDestroyTemplateIds(); }
7893 struct DelayTemplateIdDestructionRAII {
7895 bool PrevDelayTemplateIdDestruction;
7897 DelayTemplateIdDestructionRAII(
Parser &Self,
7898 bool DelayTemplateIdDestruction) noexcept
7900 PrevDelayTemplateIdDestruction(Self.DelayTemplateIdDestruction) {
7901 Self.DelayTemplateIdDestruction = DelayTemplateIdDestruction;
7904 ~DelayTemplateIdDestructionRAII() noexcept {
7905 Self.DelayTemplateIdDestruction = PrevDelayTemplateIdDestruction;
7910 SmallVector<const IdentifierInfo *, 8> TentativelyDeclaredIdentifiers;
7922 struct AngleBracketTracker {
7925 enum Priority :
unsigned short {
7927 PotentialTypo = 0x0,
7929 DependentName = 0x2,
7932 SpaceBeforeLess = 0x0,
7934 NoSpaceBeforeLess = 0x1,
7965 if (!Locs.empty() && Locs.back().isActive(P)) {
7966 if (Locs.back().Priority <= Prio) {
7968 Locs.back().LessLoc = LessLoc;
7969 Locs.back().Priority = Prio;
7972 Locs.push_back({
TemplateName, LessLoc, Prio, P.ParenCount,
7973 P.BracketCount, P.BraceCount});
7981 while (!Locs.empty() && Locs.back().isActiveOrNested(P))
7988 if (!Locs.empty() && Locs.back().isActive(P))
7989 return &Locs.back();
7994 AngleBracketTracker AngleBrackets;
7999 struct ParsedTemplateInfo {
8000 ParsedTemplateInfo()
8004 bool isSpecialization,
8005 bool lastParameterListWasEmpty =
false)
8008 TemplateParams(TemplateParams),
8009 LastParameterListWasEmpty(lastParameterListWasEmpty) {}
8011 explicit ParsedTemplateInfo(SourceLocation ExternLoc,
8012 SourceLocation TemplateLoc)
8014 TemplateParams(
nullptr), ExternLoc(ExternLoc),
8015 TemplateLoc(TemplateLoc), LastParameterListWasEmpty(
false) {}
8025 SourceLocation ExternLoc;
8029 SourceLocation TemplateLoc;
8032 bool LastParameterListWasEmpty;
8034 SourceRange getSourceRange() const LLVM_READONLY;
8038 void LexTemplateFunctionForLateParsing(
CachedTokens &Toks);
8041 void ParseLateTemplatedFuncDef(LateParsedTemplate &LPT);
8043 static
void LateTemplateParserCallback(
void *P, LateParsedTemplate &LPT);
8051 void checkPotentialAngleBracket(
ExprResult &PotentialTemplateName);
8052 bool checkPotentialAngleBracketDelimiter(const AngleBracketTracker::Loc &,
8053 const Token &OpToken);
8054 bool checkPotentialAngleBracketDelimiter(const Token &OpToken) {
8055 if (
auto *Info = AngleBrackets.getCurrent(*
this))
8056 return checkPotentialAngleBracketDelimiter(*Info, OpToken);
8067 SourceLocation &DeclEnd,
8068 ParsedAttributes &AccessAttrs);
8115 ParsingDeclRAIIObject &DiagsFromParams, SourceLocation &DeclEnd,
8127 bool ParseTemplateParameters(MultiParseScope &TemplateScopes,
unsigned Depth,
8128 SmallVectorImpl<NamedDecl *> &TemplateParams,
8129 SourceLocation &LAngleLoc,
8130 SourceLocation &RAngleLoc);
8142 bool ParseTemplateParameterList(
unsigned Depth,
8143 SmallVectorImpl<NamedDecl *> &TemplateParams);
8145 enum class TPResult;
8149 TPResult isStartOfTemplateTypeParameter();
8173 NamedDecl *ParseTemplateParameter(
unsigned Depth,
unsigned Position);
8186 NamedDecl *ParseTypeParameter(
unsigned Depth,
unsigned Position);
8202 NamedDecl *ParseTemplateTemplateParameter(
unsigned Depth,
unsigned Position);
8212 NamedDecl *ParseNonTypeTemplateParameter(
unsigned Depth,
unsigned Position);
8216 bool isTypeConstraintAnnotation();
8228 bool TryAnnotateTypeConstraint();
8230 void DiagnoseMisplacedEllipsis(SourceLocation EllipsisLoc,
8231 SourceLocation CorrectLoc,
8232 bool AlreadyHasEllipsis,
8233 bool IdentifierHasName);
8234 void DiagnoseMisplacedEllipsisInDeclarator(SourceLocation EllipsisLoc,
8237 typedef SmallVector<ParsedTemplateArgument, 16> TemplateArgList;
8254 bool ParseGreaterThanInTemplateList(SourceLocation LAngleLoc,
8255 SourceLocation &RAngleLoc,
8256 bool ConsumeLastToken,
8257 bool ObjCGenericList);
8270 bool ParseTemplateIdAfterTemplateName(
bool ConsumeLastToken,
8271 SourceLocation &LAngleLoc,
8272 TemplateArgList &TemplateArgs,
8273 SourceLocation &RAngleLoc,
8318 CXXScopeSpec &SS, SourceLocation TemplateKWLoc,
8320 bool AllowTypeAnnotation =
true,
8321 bool TypeConstraint =
false);
8339 AnnotateTemplateIdTokenAsType(CXXScopeSpec &SS,
8341 bool IsClassName =
false);
8353 bool ParseTemplateArgumentList(TemplateArgList &TemplateArgs,
8357 ParsedTemplateArgument ParseTemplateTemplateArgument();
8369 ParsedTemplateArgument ParseTemplateArgument();
8381 SourceLocation ExternLoc,
8382 SourceLocation TemplateLoc,
8383 SourceLocation &DeclEnd,
8384 ParsedAttributes &AccessAttrs,
8393 Decl *ParseConceptDefinition(
const ParsedTemplateInfo &TemplateInfo,
8394 SourceLocation &DeclEnd);
8422 class TentativeParsingAction {
8424 PreferredTypeBuilder PrevPreferredType;
8426 size_t PrevTentativelyDeclaredIdentifierCount;
8427 unsigned short PrevParenCount, PrevBracketCount, PrevBraceCount;
8431 explicit TentativeParsingAction(Parser &p,
bool Unannotated =
false)
8432 : P(p), PrevPreferredType(P.PreferredType) {
8434 PrevTentativelyDeclaredIdentifierCount =
8435 P.TentativelyDeclaredIdentifiers.size();
8436 PrevParenCount = P.ParenCount;
8437 PrevBracketCount = P.BracketCount;
8438 PrevBraceCount = P.BraceCount;
8439 P.PP.EnableBacktrackAtThisPos(Unannotated);
8443 assert(isActive &&
"Parsing action was finished!");
8444 P.TentativelyDeclaredIdentifiers.resize(
8445 PrevTentativelyDeclaredIdentifierCount);
8446 P.PP.CommitBacktrackedTokens();
8450 assert(isActive &&
"Parsing action was finished!");
8452 P.PreferredType = PrevPreferredType;
8454 P.TentativelyDeclaredIdentifiers.resize(
8455 PrevTentativelyDeclaredIdentifierCount);
8456 P.ParenCount = PrevParenCount;
8457 P.BracketCount = PrevBracketCount;
8458 P.BraceCount = PrevBraceCount;
8461 ~TentativeParsingAction() {
8462 assert(!isActive &&
"Forgot to call Commit or Revert!");
8468 class RevertingTentativeParsingAction
8469 :
private Parser::TentativeParsingAction {
8471 using TentativeParsingAction::TentativeParsingAction;
8473 ~RevertingTentativeParsingAction() { Revert(); }
8508 bool isCXXDeclarationStatement(
bool DisambiguatingWithExpression =
false);
8534 bool isCXXSimpleDeclaration(
bool AllowForRangeDecl);
8547 bool isCXXFunctionDeclarator(
bool *IsAmbiguous =
nullptr,
8551 struct ConditionDeclarationOrInitStatementState;
8552 enum class ConditionOrInitStatement {
8579 ConditionOrInitStatement
8580 isCXXConditionDeclarationOrInitStatement(
bool CanBeInitStmt,
8581 bool CanBeForRangeDecl);
8607 return isCXXTypeId(Context, isAmbiguous);
8621 bool isEnumBase(
bool AllowSemi);
8741 TPResult BracedCastResult = TPResult::False,
8742 bool *InvalidAsDeclSpec =
nullptr);
8747 bool isCXXDeclarationSpecifierAType();
8753 TPResult isTemplateArgumentList(
unsigned TokensToSkip);
8758 TPResult isExplicitBool();
8763 bool isTentativelyDeclared(IdentifierInfo *II);
8782 TPResult TryParseSimpleDeclaration(
bool AllowForRangeDecl);
8790 TPResult TryParseTypeofSpecifier();
8794 TPResult TryParseProtocolQualifiers();
8796 TPResult TryParsePtrOperatorSeq();
8818 TPResult TryParseOperatorId();
8849 TPResult TryParseInitDeclaratorList(
bool MayHaveTrailingReturnType =
false);
8906 TPResult TryParseDeclarator(
bool mayBeAbstract,
bool mayHaveIdentifier =
true,
8907 bool mayHaveDirectInit =
false,
8908 bool mayHaveTrailingReturnType =
false);
8929 TPResult TryParseParameterDeclarationClause(
8930 bool *InvalidAsDeclaration =
nullptr,
bool VersusTemplateArg =
false,
8947 TPResult TryParseFunctionDeclarator(
bool MayHaveTrailingReturnType =
false);
8953 bool NameAfterArrowIsNonType();
8959 TPResult TryParseBracketDeclarator();
8963 TPResult TryConsumeDeclarationSpecifier();
8967 bool TrySkipAttributes();
9009 isCXX11AttributeSpecifier(
bool Disambiguate =
false,
9010 bool OuterMightBeMessageSend =
false);