24#include "llvm/Support/TimeProfiler.h"
39Decl *Parser::ParseDeclarationStartingWithTemplate(
42 ObjCDeclContextSwitch ObjCDC(*
this);
44 if (Tok.
is(tok::kw_template) &&
NextToken().isNot(tok::less)) {
46 DeclEnd, AccessAttrs, AS);
48 return ParseTemplateDeclarationOrSpecialization(Context, DeclEnd, AccessAttrs,
76Decl *Parser::ParseTemplateDeclarationOrSpecialization(
79 assert(Tok.
isOneOf(tok::kw_export, tok::kw_template) &&
80 "Token does not start a template declaration.");
82 MultiParseScope TemplateParamScopes(*
this);
110 bool isSpecialization =
true;
111 bool LastParamListWasEmpty =
false;
113 TemplateParameterDepthRAII CurTemplateDepthTracker(TemplateParameterDepth);
130 if (ParseTemplateParameters(TemplateParamScopes,
131 CurTemplateDepthTracker.getDepth(),
132 TemplateParams, LAngleLoc, RAngleLoc)) {
139 ExprResult OptionalRequiresClauseConstraintER;
140 if (!TemplateParams.empty()) {
141 isSpecialization =
false;
142 ++CurTemplateDepthTracker;
145 OptionalRequiresClauseConstraintER =
148 if (!OptionalRequiresClauseConstraintER.
isUsable()) {
156 LastParamListWasEmpty =
true;
160 CurTemplateDepthTracker.getDepth(), ExportLoc, TemplateLoc, LAngleLoc,
161 TemplateParams, RAngleLoc, OptionalRequiresClauseConstraintER.
get()));
162 }
while (Tok.
isOneOf(tok::kw_export, tok::kw_template));
165 if (Tok.
is(tok::kw_concept))
166 return ParseConceptDefinition(
167 ParsedTemplateInfo(&ParamLists, isSpecialization,
168 LastParamListWasEmpty),
171 return ParseSingleDeclarationAfterTemplate(
173 ParsedTemplateInfo(&ParamLists, isSpecialization, LastParamListWasEmpty),
174 ParsingTemplateParams, DeclEnd, AccessAttrs, AS);
187Decl *Parser::ParseSingleDeclarationAfterTemplate(
191 assert(TemplateInfo.Kind != ParsedTemplateInfo::NonTemplate &&
192 "Template information required");
194 if (Tok.
is(tok::kw_static_assert)) {
197 << TemplateInfo.getSourceRange();
199 return ParseStaticAssertDeclaration(DeclEnd);
205 AS, AccessAttrs, TemplateInfo, &DiagsFromTParams);
207 if (!D || !D.get().isSingleDecl())
209 return D.get().getSingleDecl();
219 while (MaybeParseCXX11Attributes(prefixAttrs) ||
220 MaybeParseGNUAttributes(DeclSpecAttrs))
223 if (Tok.
is(tok::kw_using)) {
224 auto usingDeclPtr = ParseUsingDirectiveOrDeclaration(Context, TemplateInfo, DeclEnd,
226 if (!usingDeclPtr || !usingDeclPtr.get().isSingleDecl())
228 return usingDeclPtr.get().getSingleDecl();
234 DS.SetRangeStart(DeclSpecAttrs.Range.getBegin());
235 DS.SetRangeEnd(DeclSpecAttrs.Range.getEnd());
236 DS.takeAttributesFrom(DeclSpecAttrs);
238 ParseDeclarationSpecifiers(DS, TemplateInfo, AS,
239 getDeclSpecContextFromDeclaratorContext(Context));
241 if (Tok.
is(tok::semi)) {
242 ProhibitAttributes(prefixAttrs);
247 TemplateInfo.TemplateParams ? *TemplateInfo.TemplateParams
249 TemplateInfo.Kind == ParsedTemplateInfo::ExplicitInstantiation,
252 assert(!AnonRecord &&
253 "Anonymous unions/structs should not be valid with template");
258 if (DS.hasTagDefinition())
262 if (TemplateInfo.Kind == ParsedTemplateInfo::ExplicitInstantiation)
263 ProhibitAttributes(prefixAttrs);
268 if (TemplateInfo.TemplateParams)
269 DeclaratorInfo.setTemplateParameterLists(*TemplateInfo.TemplateParams);
281 bool IsTemplateSpecOrInst =
282 (TemplateInfo.Kind == ParsedTemplateInfo::ExplicitInstantiation ||
283 TemplateInfo.Kind == ParsedTemplateInfo::ExplicitSpecialization);
286 ParseDeclarator(DeclaratorInfo);
288 if (IsTemplateSpecOrInst)
292 if (!DeclaratorInfo.hasName()) {
297 LateParsedAttrList LateParsedAttrs(
true);
298 if (DeclaratorInfo.isFunctionDeclarator()) {
299 if (Tok.
is(tok::kw_requires)) {
300 CXXScopeSpec &ScopeSpec = DeclaratorInfo.getCXXScopeSpec();
301 DeclaratorScopeObj DeclScopeObj(*
this, ScopeSpec);
304 DeclScopeObj.EnterDeclaratorScope();
305 ParseTrailingRequiresClause(DeclaratorInfo);
308 MaybeParseGNUAttributes(DeclaratorInfo, &LateParsedAttrs);
311 if (DeclaratorInfo.isFunctionDeclarator() &&
312 isStartOfFunctionDefinition(DeclaratorInfo)) {
318 Diag(Tok, diag::err_function_definition_not_allowed);
327 Diag(DS.getStorageClassSpecLoc(), diag::err_function_declared_typedef)
329 DS.ClearStorageClassSpecs();
332 if (TemplateInfo.Kind == ParsedTemplateInfo::ExplicitInstantiation) {
333 if (DeclaratorInfo.getName().getKind() !=
337 Diag(Tok, diag::err_template_defn_explicit_instantiation) << 0;
338 return ParseFunctionDefinition(DeclaratorInfo, ParsedTemplateInfo(),
343 Diag(DeclaratorInfo.getIdentifierLoc(),
344 diag::err_explicit_instantiation_with_definition)
352 std::nullopt, LAngleLoc,
nullptr));
354 return ParseFunctionDefinition(
355 DeclaratorInfo, ParsedTemplateInfo(&FakedParamLists,
361 return ParseFunctionDefinition(DeclaratorInfo, TemplateInfo,
366 Decl *ThisDecl = ParseDeclarationAfterDeclarator(DeclaratorInfo,
369 if (Tok.
is(tok::comma)) {
370 Diag(Tok, diag::err_multiple_template_declarators)
371 << (
int)TemplateInfo.Kind;
377 ExpectAndConsumeSemi(diag::err_expected_semi_declaration);
378 if (LateParsedAttrs.size() > 0)
379 ParseLexedAttributeList(LateParsedAttrs, ThisDecl,
true,
false);
380 DeclaratorInfo.complete(ThisDecl);
391Parser::ParseConceptDefinition(
const ParsedTemplateInfo &TemplateInfo,
393 assert(TemplateInfo.Kind != ParsedTemplateInfo::NonTemplate &&
394 "Template information required");
395 assert(Tok.
is(tok::kw_concept) &&
396 "ParseConceptDefinition must be called when at a 'concept' keyword");
405 DiagnoseAndSkipCXX11Attributes();
408 if (ParseOptionalCXXScopeSpecifier(
412 false,
nullptr,
true) ||
420 diag::err_concept_definition_not_identifier);
434 Diag(
Result.getBeginLoc(), diag::err_concept_definition_not_identifier);
442 DiagnoseAndSkipCXX11Attributes();
458 ExpectAndConsumeSemi(diag::err_expected_semi_declaration);
459 Expr *ConstraintExpr = ConstraintExprResult.
get();
461 *TemplateInfo.TemplateParams,
462 Id, IdLoc, ConstraintExpr);
474bool Parser::ParseTemplateParameters(
475 MultiParseScope &TemplateScopes,
unsigned Depth,
487 if (!Tok.
is(tok::greater) && !Tok.
is(tok::greatergreater)) {
489 Failed = ParseTemplateParameterList(Depth, TemplateParams);
492 if (Tok.
is(tok::greatergreater)) {
517Parser::ParseTemplateParameterList(
const unsigned Depth,
522 = ParseTemplateParameter(Depth, TemplateParams.size())) {
523 TemplateParams.push_back(TmpParam);
527 SkipUntil(tok::comma, tok::greater, tok::greatergreater,
532 if (Tok.
is(tok::comma)) {
534 }
else if (Tok.
isOneOf(tok::greater, tok::greatergreater)) {
542 SkipUntil(tok::comma, tok::greater, tok::greatergreater,
552Parser::TPResult Parser::isStartOfTemplateTypeParameter() {
553 if (Tok.
is(tok::kw_class)) {
560 case tok::greatergreater:
562 return TPResult::True;
564 case tok::identifier:
570 return TPResult::False;
573 switch (GetLookAheadToken(2).
getKind()) {
577 case tok::greatergreater:
578 return TPResult::True;
581 return TPResult::False;
585 if (TryAnnotateTypeConstraint())
586 return TPResult::Error;
588 if (isTypeConstraintAnnotation() &&
592 !GetLookAheadToken(Tok.
is(tok::annot_cxxscope) ? 2 : 1)
593 .
isOneOf(tok::kw_auto, tok::kw_decltype))
594 return TPResult::True;
598 if (Tok.
isNot(tok::kw_typename) && Tok.
isNot(tok::kw_typedef))
599 return TPResult::False;
610 if (Next.getKind() == tok::identifier)
611 Next = GetLookAheadToken(2);
613 switch (Next.getKind()) {
617 case tok::greatergreater:
619 return TPResult::True;
621 case tok::kw_typename:
622 case tok::kw_typedef:
626 return TPResult::True;
629 return TPResult::False;
653NamedDecl *Parser::ParseTemplateParameter(
unsigned Depth,
unsigned Position) {
655 switch (isStartOfTemplateTypeParameter()) {
659 if (Tok.
is(tok::kw_typedef)) {
671 return ParseTypeParameter(Depth, Position);
672 case TPResult::False:
675 case TPResult::Error: {
683 DS.SetTypeSpecError();
687 D.setInvalidType(
true);
692 SkipUntil(tok::comma, tok::greater, tok::greatergreater,
697 case TPResult::Ambiguous:
698 llvm_unreachable(
"template param classification can't be ambiguous");
701 if (Tok.
is(tok::kw_template))
702 return ParseTemplateTemplateParameter(Depth, Position);
707 return ParseNonTypeTemplateParameter(Depth, Position);
712bool Parser::isTypeConstraintAnnotation() {
714 if (T.
isNot(tok::annot_template_id))
716 const auto *ExistingAnnot =
729bool Parser::TryAnnotateTypeConstraint() {
733 bool WasScopeAnnotation = Tok.
is(tok::annot_cxxscope);
734 if (ParseOptionalCXXScopeSpecifier(SS,
nullptr,
749 if (Tok.
is(tok::identifier)) {
755 bool MemberOfUnknownSpecialization =
false;
762 MemberOfUnknownSpecialization,
764 if (MemberOfUnknownSpecialization || !PossibleConcept ||
767 AnnotateScopeToken(SS, !WasScopeAnnotation);
774 if (AnnotateTemplateIdToken(PossibleConcept, TNK, SS,
783 AnnotateScopeToken(SS, !WasScopeAnnotation);
796NamedDecl *Parser::ParseTypeParameter(
unsigned Depth,
unsigned Position) {
797 assert((Tok.
isOneOf(tok::kw_class, tok::kw_typename) ||
798 isTypeConstraintAnnotation()) &&
799 "A type-parameter starts with 'class', 'typename' or a "
804 bool TypenameKeyword =
false;
806 ParseOptionalCXXScopeSpecifier(TypeConstraintSS,
nullptr,
809 if (Tok.
is(tok::annot_template_id)) {
814 "stray non-concept template-id annotation");
815 KeyLoc = ConsumeAnnotationToken();
817 assert(TypeConstraintSS.
isEmpty() &&
818 "expected type constraint after scope specifier");
821 TypenameKeyword = Tok.
is(tok::kw_typename);
830 ? diag::warn_cxx98_compat_variadic_templates
831 : diag::ext_variadic_templates);
837 if (Tok.
is(tok::identifier)) {
840 }
else if (Tok.
isOneOf(tok::equal, tok::comma, tok::greater,
841 tok::greatergreater)) {
850 bool AlreadyHasEllipsis = EllipsisLoc.
isValid();
852 DiagnoseMisplacedEllipsis(EllipsisLoc, NameLoc, AlreadyHasEllipsis,
true);
864 TemplateParameterDepthRAII CurTemplateDepthTracker(TemplateParameterDepth);
865 ++CurTemplateDepthTracker;
872 TypenameKeyword, EllipsisLoc,
873 KeyLoc, ParamName, NameLoc,
874 Depth, Position, EqualLoc,
880 cast<TemplateTypeParmDecl>(NewDecl),
899NamedDecl *Parser::ParseTemplateTemplateParameter(
unsigned Depth,
901 assert(Tok.
is(tok::kw_template) &&
"Expected 'template' keyword");
907 ExprResult OptionalRequiresClauseConstraintER;
909 MultiParseScope TemplateParmScope(*
this);
910 if (ParseTemplateParameters(TemplateParmScope, Depth + 1, TemplateParams,
911 LAngleLoc, RAngleLoc)) {
915 OptionalRequiresClauseConstraintER =
918 if (!OptionalRequiresClauseConstraintER.
isUsable()) {
919 SkipUntil(tok::comma, tok::greater, tok::greatergreater,
932 bool Replace = Tok.
isOneOf(tok::kw_typename, tok::kw_struct);
934 if (Tok.
is(tok::kw_typename)) {
937 ? diag::warn_cxx14_compat_template_template_param_typename
938 : diag::ext_template_template_param_typename)
942 }
else if (Next.isOneOf(tok::identifier, tok::comma, tok::greater,
943 tok::greatergreater, tok::ellipsis)) {
948 :
FixItHint::CreateInsertion(Tok.getLocation(),
"class "));
962 ? diag::warn_cxx98_compat_variadic_templates
963 : diag::ext_variadic_templates);
968 if (Tok.
is(tok::identifier)) {
971 }
else if (Tok.
isOneOf(tok::equal, tok::comma, tok::greater,
972 tok::greatergreater)) {
981 bool AlreadyHasEllipsis = EllipsisLoc.
isValid();
983 DiagnoseMisplacedEllipsis(EllipsisLoc, NameLoc, AlreadyHasEllipsis,
true);
987 RAngleLoc, OptionalRequiresClauseConstraintER.
get());
995 DefaultArg = ParseTemplateTemplateArgument();
998 diag::err_default_template_template_parameter_not_template);
999 SkipUntil(tok::comma, tok::greater, tok::greatergreater,
1005 ParamList, EllipsisLoc,
1006 ParamName, NameLoc, Depth,
1007 Position, EqualLoc, DefaultArg);
1017Parser::ParseNonTypeTemplateParameter(
unsigned Depth,
unsigned Position) {
1022 ParseDeclarationSpecifiers(DS, ParsedTemplateInfo(),
AS_none,
1023 DeclSpecContext::DSC_template_param);
1028 ParseDeclarator(ParamDecl);
1037 DiagnoseMisplacedEllipsisInDeclarator(EllipsisLoc, ParamDecl);
1045 if (Tok.
is(tok::l_paren) &&
NextToken().is(tok::l_brace)) {
1060 TemplateParameterDepthRAII CurTemplateDepthTracker(
1061 TemplateParameterDepth);
1062 ++CurTemplateDepthTracker;
1074 Depth, Position, EqualLoc,
1078void Parser::DiagnoseMisplacedEllipsis(
SourceLocation EllipsisLoc,
1080 bool AlreadyHasEllipsis,
1081 bool IdentifierHasName) {
1083 if (!AlreadyHasEllipsis)
1085 Diag(EllipsisLoc, diag::err_misplaced_ellipsis_in_declaration)
1087 << !IdentifierHasName;
1090void Parser::DiagnoseMisplacedEllipsisInDeclarator(
SourceLocation EllipsisLoc,
1092 assert(EllipsisLoc.
isValid());
1094 if (!AlreadyHasEllipsis)
1097 AlreadyHasEllipsis, D.
hasName());
1115bool Parser::ParseGreaterThanInTemplateList(
SourceLocation LAngleLoc,
1117 bool ConsumeLastToken,
1118 bool ObjCGenericList) {
1121 const char *ReplacementStr =
"> >";
1122 bool MergeWithNextToken =
false;
1127 Diag(LAngleLoc, diag::note_matching) << tok::less;
1134 if (ConsumeLastToken)
1138 case tok::greatergreater:
1139 RemainingToken = tok::greater;
1142 case tok::greatergreatergreater:
1143 RemainingToken = tok::greatergreater;
1146 case tok::greaterequal:
1147 RemainingToken = tok::equal;
1148 ReplacementStr =
"> =";
1155 RemainingToken = tok::equalequal;
1156 MergeWithNextToken =
true;
1160 case tok::greatergreaterequal:
1161 RemainingToken = tok::greaterequal;
1180 bool PreventMergeWithNextToken =
1181 (RemainingToken == tok::greater ||
1182 RemainingToken == tok::greatergreater) &&
1183 (Next.isOneOf(tok::greater, tok::greatergreater,
1184 tok::greatergreatergreater, tok::equal, tok::greaterequal,
1185 tok::greatergreaterequal, tok::equalequal)) &&
1186 areTokensAdjacent(Tok, Next);
1189 if (!ObjCGenericList) {
1204 if (PreventMergeWithNextToken)
1207 unsigned DiagId = diag::err_two_right_angle_brackets_need_space;
1209 (Tok.
is(tok::greatergreater) || Tok.
is(tok::greatergreatergreater)))
1210 DiagId = diag::warn_cxx98_compat_two_right_angle_brackets;
1211 else if (Tok.
is(tok::greaterequal))
1212 DiagId = diag::err_right_angle_bracket_equal_needs_space;
1213 Diag(TokLoc, DiagId) << Hint1 << Hint2;
1224 RAngleLoc = PP.
SplitToken(TokLoc, GreaterLength);
1230 Greater.setLocation(RAngleLoc);
1231 Greater.setKind(tok::greater);
1232 Greater.setLength(GreaterLength);
1235 if (MergeWithNextToken) {
1241 Tok.
setLength(OldLength - GreaterLength);
1246 if (PreventMergeWithNextToken)
1251 if (CachingTokens) {
1253 if (MergeWithNextToken)
1256 if (ConsumeLastToken)
1262 if (ConsumeLastToken) {
1263 PrevTokLocation = RAngleLoc;
1265 PrevTokLocation = TokBeforeGreaterLoc;
1284bool Parser::ParseTemplateIdAfterTemplateName(
bool ConsumeLastToken,
1286 TemplateArgList &TemplateArgs,
1288 TemplateTy Template) {
1289 assert(Tok.
is(tok::less) &&
"Must have already parsed the template-name");
1298 if (!Tok.
isOneOf(tok::greater, tok::greatergreater,
1299 tok::greatergreatergreater, tok::greaterequal,
1300 tok::greatergreaterequal))
1301 Invalid = ParseTemplateArgumentList(TemplateArgs, Template, LAngleLoc);
1306 SkipUntil(tok::greater, tok::greatergreater,
1313 return ParseGreaterThanInTemplateList(LAngleLoc, RAngleLoc, ConsumeLastToken,
1359bool Parser::AnnotateTemplateIdToken(TemplateTy Template,
TemplateNameKind TNK,
1363 bool AllowTypeAnnotation,
1367 "Parser isn't at the beginning of a template-id");
1368 assert(!(
TypeConstraint && AllowTypeAnnotation) &&
"type-constraint can't be "
1369 "a type annotation");
1371 "must accompany a concept name");
1379 TemplateArgList TemplateArgs;
1380 bool ArgsInvalid =
false;
1382 ArgsInvalid = ParseTemplateIdAfterTemplateName(
1383 false, LAngleLoc, TemplateArgs, RAngleLoc, Template);
1398 : Actions.ActOnTemplateIdType(
1401 LAngleLoc, TemplateArgsPtr, RAngleLoc);
1403 Tok.
setKind(tok::annot_typename);
1404 setTypeAnnotation(Tok,
Type);
1407 else if (TemplateKWLoc.
isValid())
1414 Tok.
setKind(tok::annot_template_id);
1427 TemplateKWLoc, TemplateNameLoc, TemplateII, OpKind, Template, TNK,
1428 LAngleLoc, RAngleLoc, TemplateArgs, ArgsInvalid, TemplateIds);
1461void Parser::AnnotateTemplateIdTokenAsType(
1464 assert(Tok.
is(tok::annot_template_id) &&
"Requires template-id tokens");
1468 "Only works for type and dependent templates");
1476 : Actions.ActOnTemplateIdType(
1478 TemplateId->Template, TemplateId->Name,
1479 TemplateId->TemplateNameLoc, TemplateId->LAngleLoc,
1480 TemplateArgsPtr, TemplateId->RAngleLoc,
1481 false, IsClassName, AllowImplicitTypename);
1483 Tok.
setKind(tok::annot_typename);
1484 setTypeAnnotation(Tok,
Type);
1497 return Tok.
isOneOf(tok::comma, tok::greater, tok::greatergreater,
1498 tok::greatergreatergreater);
1503 if (!Tok.
is(tok::identifier) && !Tok.
is(tok::coloncolon) &&
1504 !Tok.
is(tok::annot_cxxscope))
1519 ParseOptionalCXXScopeSpecifier(SS,
nullptr,
1525 if (SS.
isSet() && Tok.
is(tok::kw_template)) {
1530 if (Tok.
is(tok::identifier)) {
1548 }
else if (Tok.
is(tok::identifier)) {
1558 bool MemberOfUnknownSpecialization;
1563 false, Template, MemberOfUnknownSpecialization);
1600 if (isCXXTypeId(TypeIdAsTemplateArgument)) {
1608 TentativeParsingAction TPA(*
this);
1611 = ParseTemplateTemplateArgument();
1612 if (!TemplateTemplateArgument.
isInvalid()) {
1614 return TemplateTemplateArgument;
1629 ExprArg.
get(), Loc);
1640bool Parser::ParseTemplateArgumentList(TemplateArgList &TemplateArgs,
1641 TemplateTy Template,
1646 auto RunSignatureHelp = [&] {
1649 CalledSignatureHelp =
true;
1668 TemplateArgs.push_back(Arg);
1694 return ParseSingleDeclarationAfterTemplate(
1695 Context, ParsedTemplateInfo(ExternLoc, TemplateLoc),
1696 ParsingTemplateParams, DeclEnd, AccessAttrs, AS);
1699SourceRange Parser::ParsedTemplateInfo::getSourceRange()
const {
1702 TemplateParams->size());
1706 R.setBegin(ExternLoc);
1711 ((
Parser *)
P)->ParseLateTemplatedFuncDef(LPT);
1720 DestroyTemplateIdAnnotationsRAIIObj CleanupRAII(*
this);
1725 TemplateParameterDepthRAII CurTemplateDepthTracker(TemplateParameterDepth);
1731 MultiParseScope Scopes(*
this);
1736 DC = DC->getLexicalParent())
1737 DeclContextsToReenter.push_back(DC);
1740 for (
DeclContext *DC : reverse(DeclContextsToReenter)) {
1741 CurTemplateDepthTracker.addDepth(
1754 assert(!LPT.
Toks.empty() &&
"Empty body!");
1758 LPT.
Toks.push_back(Tok);
1759 PP.EnterTokenStream(LPT.
Toks,
true,
true);
1763 assert(Tok.
isOneOf(tok::l_brace, tok::colon, tok::kw_try) &&
1764 "Inline method not starting with '{', ':' or 'try'");
1776 if (Tok.
is(tok::kw_try)) {
1777 ParseFunctionTryBlock(LPT.
D, FnScope);
1779 if (Tok.
is(tok::colon))
1780 ParseConstructorInitializer(LPT.
D);
1784 if (Tok.
is(tok::l_brace)) {
1785 assert((!isa<FunctionTemplateDecl>(LPT.
D) ||
1786 cast<FunctionTemplateDecl>(LPT.
D)
1787 ->getTemplateParameters()
1788 ->getDepth() == TemplateParameterDepth - 1) &&
1789 "TemplateParameterDepth should be greater than the depth of "
1790 "current template being instantiated!");
1791 ParseFunctionStatementBody(LPT.
D, FnScope);
1799void Parser::LexTemplateFunctionForLateParsing(
CachedTokens &Toks) {
1801 if (!ConsumeAndStoreFunctionPrologue(Toks)) {
1803 ConsumeAndStoreUntil(tok::r_brace, Toks,
false);
1807 if (kind == tok::kw_try) {
1808 while (Tok.
is(tok::kw_catch)) {
1809 ConsumeAndStoreUntil(tok::l_brace, Toks,
false);
1810 ConsumeAndStoreUntil(tok::r_brace, Toks,
false);
1820 TentativeParsingAction TPA(*
this);
1822 if (
SkipUntil(tok::greater, tok::greatergreater, tok::greatergreatergreater,
1827 ParseGreaterThanInTemplateList(
Less,
Greater,
true,
false);
1839void Parser::checkPotentialAngleBracket(
ExprResult &PotentialTemplateName) {
1840 assert(Tok.
is(tok::less) &&
"not at a potential angle bracket");
1856 ParseGreaterThanInTemplateList(
Less,
Greater,
true,
false);
1868 TentativeParsingAction TPA(*
this);
1870 if (isTypeIdUnambiguously() &&
1871 diagnoseUnknownTemplateId(PotentialTemplateName,
Less)) {
1882 AngleBracketTracker::Priority
Priority =
1884 : AngleBracketTracker::PotentialTypo) |
1886 : AngleBracketTracker::NoSpaceBeforeLess);
1887 AngleBrackets.add(*
this, PotentialTemplateName.
get(), Tok.
getLocation(),
1891bool Parser::checkPotentialAngleBracketDelimiter(
1892 const AngleBracketTracker::Loc &LAngle,
const Token &OpToken) {
1896 if (OpToken.
is(tok::comma) && isTypeIdUnambiguously() &&
1897 diagnoseUnknownTemplateId(LAngle.TemplateName, LAngle.LessLoc)) {
1898 AngleBrackets.clear(*
this);
1905 if (OpToken.
is(tok::greater) && Tok.
is(tok::l_paren) &&
1908 getCurScope(), LAngle.TemplateName, LAngle.LessLoc,
1910 AngleBrackets.clear(*
this);
1916 if (OpToken.
is(tok::greater) ||
1918 OpToken.
isOneOf(tok::greatergreater, tok::greatergreatergreater)))
1919 AngleBrackets.clear(*
this);
Defines the clang::ASTContext interface.
static Decl::Kind getKind(const Decl *D)
Defines the C++ template declaration subclasses.
Defines the clang::Expr interface and subclasses for C++ expressions.
static bool isEndOfTemplateArgument(Token Tok)
Determine whether the given token can end a template argument.
static constexpr bool isOneOf()
TranslationUnitDecl * getTranslationUnitDecl() const
Represents a C++ nested-name-specifier or a global scope specifier.
bool isNotEmpty() const
A scope specifier is present, but may be valid or invalid.
bool isValid() const
A scope specifier is present, and it refers to a real scope.
SourceLocation getBeginLoc() const
bool isSet() const
Deprecated.
bool isInvalid() const
An error occurred during parsing of the scope specifier.
bool isEmpty() const
No scope specifier.
Represents a character-granular source range.
static CharSourceRange getCharRange(SourceRange R)
ColonProtectionRAIIObject - This sets the Parser::ColonIsSacred bool and restores it when destroyed.
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
DeclContext * getLexicalParent()
getLexicalParent - Returns the containing lexical DeclContext.
bool isTranslationUnit() const
Captures information about "declaration specifiers".
static const TST TST_unspecified
Decl - This represents one declaration (or definition), e.g.
void setInvalidDecl(bool Invalid=true)
setInvalidDecl - Indicates the Decl had a semantic error.
FunctionDecl * getAsFunction() LLVM_READONLY
Returns the function itself, or the templated function if this is a function template.
Information about one declarator, including the parsed type information and the identifier.
SourceLocation getIdentifierLoc() const
SourceLocation getEllipsisLoc() const
bool hasName() const
hasName - Whether this declarator has a name, which might be an identifier (accessible via getIdentif...
void setEllipsisLoc(SourceLocation EL)
Represents a dependent template name that cannot be resolved prior to template instantiation.
RAII object that enters a new expression evaluation context.
This represents one expression.
Annotates a diagnostic with some code that should be inserted, removed, or replaced to fix the proble...
static FixItHint CreateReplacement(CharSourceRange RemoveRange, StringRef Code)
Create a code modification hint that replaces the given source range with the given code string.
static FixItHint CreateRemoval(CharSourceRange RemoveRange)
Create a code modification hint that removes the given source range.
static FixItHint CreateInsertion(SourceLocation InsertionLoc, StringRef Code, bool BeforePreviousInsertions=false)
Create a code modification hint that inserts the given code string at a specific location.
Represents a function declaration or definition.
RAII object that makes '>' behave either as an operator or as the closing angle bracket for a templat...
One of these records is kept for each identifier that is lexed.
static SourceLocation AdvanceToTokenCharacter(SourceLocation TokStart, unsigned Characters, const SourceManager &SM, const LangOptions &LangOpts)
AdvanceToTokenCharacter - If the current SourceLocation specifies a location at the start of a token,...
static unsigned getTokenPrefixLength(SourceLocation TokStart, unsigned CharNo, const SourceManager &SM, const LangOptions &LangOpts)
Get the physical length (including trigraphs and escaped newlines) of the first Characters characters...
This represents a decl that may have a name.
static const ParsedAttributesView & none()
ParsedAttributes - A collection of parsed attributes.
Represents the parsed form of a C++ template argument.
@ NonType
A non-type template parameter, stored as an expression.
bool isInvalid() const
Determine whether the given template argument is invalid.
Introduces zero or more scopes for parsing.
Parser - This implements a parser for the C family of languages.
TypeResult ParseTypeName(SourceRange *Range=nullptr, DeclaratorContext Context=DeclaratorContext::TypeName, AccessSpecifier AS=AS_none, Decl **OwnedType=nullptr, ParsedAttributes *Attrs=nullptr)
ParseTypeName type-name: [C99 6.7.6] specifier-qualifier-list abstract-declarator[opt].
DiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID)
SourceLocation ConsumeToken()
ConsumeToken - Consume the current 'peek token' and lex the next one.
AttributeFactory & getAttrFactory()
ExprResult ParseConstraintLogicalOrExpression(bool IsTrailingRequiresClause)
Parse a constraint-logical-or-expression.
bool ParseUnqualifiedId(CXXScopeSpec &SS, ParsedType ObjectType, bool ObjectHadErrors, bool EnteringContext, bool AllowDestructorName, bool AllowConstructorName, bool AllowDeductionGuide, SourceLocation *TemplateKWLoc, UnqualifiedId &Result)
Parse a C++ unqualified-id (or a C identifier), which describes the name of an entity.
SourceLocation ConsumeAnyToken(bool ConsumeCodeCompletionTok=false)
ConsumeAnyToken - Dispatch to the right Consume* method based on the current token type.
bool TryConsumeToken(tok::TokenKind Expected)
OpaquePtr< DeclGroupRef > DeclGroupPtrTy
Scope * getCurScope() const
SourceLocation getEndOfPreviousToken()
OpaquePtr< TemplateName > TemplateTy
bool SkipUntil(tok::TokenKind T, SkipUntilFlags Flags=static_cast< SkipUntilFlags >(0))
SkipUntil - Read tokens until we get to the specified token, then consume it (unless StopBeforeMatch ...
void SkipMalformedDecl()
SkipMalformedDecl - Read tokens until we get to some likely good stopping point for skipping past a s...
ExprResult ParseAssignmentExpression(TypeCastState isTypeCast=NotTypeCast)
Parse an expr that doesn't include (top-level) commas.
ExprResult ParseConstantExpressionInExprEvalContext(TypeCastState isTypeCast=NotTypeCast)
const LangOptions & getLangOpts() const
@ StopBeforeMatch
Stop skipping at specified token, but don't skip the token itself.
@ StopAtSemi
Stop skipping at semicolon.
const Token & NextToken()
NextToken - This peeks ahead one token and returns it without consuming it.
ExprResult ParseConstraintExpression()
Parse a constraint-expression.
SmallVector< TemplateParameterList *, 4 > TemplateParameterLists
unsigned ReenterTemplateScopes(MultiParseScope &S, Decl *D)
Re-enter the template scopes for a declaration that might be a template.
RAII object used to inform the actions that we're currently parsing a declaration.
A class for parsing a DeclSpec.
A class for parsing a declarator.
void enterFunctionArgument(SourceLocation Tok, llvm::function_ref< QualType()> ComputeType)
Computing a type for the function argument may require running overloading, so we postpone its comput...
void EnterToken(const Token &Tok, bool IsReinject)
Enters a token in the token stream to be lexed next.
bool IsPreviousCachedToken(const Token &Tok) const
Whether Tok is the most recent token (CachedLexPos - 1) in CachedTokens.
void AnnotateCachedTokens(const Token &Tok)
We notify the Preprocessor that if it is caching tokens (because backtrack is enabled) it should repl...
SourceManager & getSourceManager() const
SourceLocation SplitToken(SourceLocation TokLoc, unsigned Length)
Split the first Length characters out of the token starting at TokLoc and return a location pointing ...
void ReplacePreviousCachedToken(ArrayRef< Token > NewToks)
Replace token in CachedLexPos - 1 in CachedTokens by the tokens in NewToks.
bool isCodeCompletionReached() const
Returns true if code-completion is enabled and we have hit the code-completion point.
SourceLocation getLocForEndOfToken(SourceLocation Loc, unsigned Offset=0)
Computes the source location just past the end of the token at this source location.
A (possibly-)qualified type.
Represents a struct/union/class.
@ TemplateParamScope
This is a scope that corresponds to the template parameters of a C++ template.
@ CompoundStmtScope
This is a compound statement scope.
@ FnScope
This indicates that the scope corresponds to a function, which means that labels are set here.
@ DeclScope
This is a scope that can contain a declaration.
Scope * getCurScope() const
Retrieve the parser's current scope.
void ActOnDefinedDeclarationSpecifier(Decl *D)
Called once it is known whether a tag declaration is an anonymous union or struct.
TemplateParameterList * ActOnTemplateParameterList(unsigned Depth, SourceLocation ExportLoc, SourceLocation TemplateLoc, SourceLocation LAngleLoc, ArrayRef< NamedDecl * > Params, SourceLocation RAngleLoc, Expr *RequiresClause)
ActOnTemplateParameterList - Builds a TemplateParameterList, optionally constrained by RequiresClause...
NamedDecl * ActOnTemplateTemplateParameter(Scope *S, SourceLocation TmpLoc, TemplateParameterList *Params, SourceLocation EllipsisLoc, IdentifierInfo *ParamName, SourceLocation ParamNameLoc, unsigned Depth, unsigned Position, SourceLocation EqualLoc, ParsedTemplateArgument DefaultArg)
ActOnTemplateTemplateParameter - Called when a C++ template template parameter (e....
bool ActOnTypeConstraint(const CXXScopeSpec &SS, TemplateIdAnnotation *TypeConstraint, TemplateTypeParmDecl *ConstrainedParameter, SourceLocation EllipsisLoc)
void UnmarkAsLateParsedTemplate(FunctionDecl *FD)
TemplateNameKind isTemplateName(Scope *S, CXXScopeSpec &SS, bool hasTemplateKeyword, const UnqualifiedId &Name, ParsedType ObjectType, bool EnteringContext, TemplateTy &Template, bool &MemberOfUnknownSpecialization, bool Disambiguation=false)
ParsedTemplateArgument ActOnTemplateTypeArgument(TypeResult ParsedType)
Convert a parsed type into a parsed template argument.
void resetFPOptions(FPOptions FPO)
QualType ProduceTemplateArgumentSignatureHelp(TemplateTy, ArrayRef< ParsedTemplateArgument >, SourceLocation LAngleLoc)
NamedDecl * ActOnTypeParameter(Scope *S, bool Typename, SourceLocation EllipsisLoc, SourceLocation KeyLoc, IdentifierInfo *ParamName, SourceLocation ParamNameLoc, unsigned Depth, unsigned Position, SourceLocation EqualLoc, ParsedType DefaultArg, bool HasTypeConstraint)
ActOnTypeParameter - Called when a C++ template type parameter (e.g., "typename T") has been parsed.
bool ShouldEnterDeclaratorScope(Scope *S, const CXXScopeSpec &SS)
Decl * ActOnStartOfFunctionDef(Scope *S, Declarator &D, MultiTemplateParamsArg TemplateParamLists, SkipBodyInfo *SkipBody=nullptr, FnBodyKind BodyKind=FnBodyKind::Other)
Decl * ActOnConceptDefinition(Scope *S, MultiTemplateParamsArg TemplateParameterLists, IdentifierInfo *Name, SourceLocation NameLoc, Expr *ConstraintExpr)
bool mightBeIntendedToBeTemplateName(ExprResult E, bool &Dependent)
Determine whether it's plausible that E was intended to be a template-name.
TemplateNameKind ActOnTemplateName(Scope *S, CXXScopeSpec &SS, SourceLocation TemplateKWLoc, const UnqualifiedId &Name, ParsedType ObjectType, bool EnteringContext, TemplateTy &Template, bool AllowInjectedClassName=false)
Form a template name from a name that is syntactically required to name a template,...
unsigned ActOnReenterTemplateScope(Decl *Template, llvm::function_ref< Scope *()> EnterScope)
void diagnoseExprIntendedAsTemplateName(Scope *S, ExprResult TemplateName, SourceLocation Less, SourceLocation Greater)
Decl * ActOnFinishFunctionBody(Decl *Decl, Stmt *Body)
void ActOnDefaultCtorInitializers(Decl *CDtorDecl)
ParsedTemplateArgument ActOnPackExpansion(const ParsedTemplateArgument &Arg, SourceLocation EllipsisLoc)
Invoked when parsing a template argument followed by an ellipsis, which creates a pack expansion.
ExprResult ActOnRequiresClause(ExprResult ConstraintExpr)
@ ConstantEvaluated
The current context is "potentially evaluated" in C++11 terms, but the expression is evaluated at com...
Decl * ParsedFreeStandingDeclSpec(Scope *S, AccessSpecifier AS, DeclSpec &DS, const ParsedAttributesView &DeclAttrs, RecordDecl *&AnonRecord)
ParsedFreeStandingDeclSpec - This method is invoked when a declspec with no declarator (e....
void PushDeclContext(Scope *S, DeclContext *DC)
Set the current declaration context until it gets popped.
NamedDecl * ActOnNonTypeTemplateParameter(Scope *S, Declarator &D, unsigned Depth, unsigned Position, SourceLocation EqualLoc, Expr *DefaultArg)
ExprResult CorrectDelayedTyposInExpr(Expr *E, VarDecl *InitDecl=nullptr, bool RecoverUncorrectedTypos=false, llvm::function_ref< ExprResult(Expr *)> Filter=[](Expr *E) -> ExprResult { return E;})
Process any TypoExprs in the given Expr and its children, generating diagnostics as appropriate and r...
Encodes a location in the source.
bool isValid() const
Return true if this is a valid SourceLocation object.
SourceLocation getLocWithOffset(IntTy Offset) const
Return a source location with the specified offset from this SourceLocation.
A trivial tuple used to represent a source range.
A RAII object used to temporarily suppress access-like checking.
Represents a C++ template name within the type system.
Stores a list of template parameters for a TemplateDecl and its derived classes.
Token - This structure provides full information about a lexed token.
IdentifierInfo * getIdentifierInfo() const
SourceLocation getEndLoc() const
void setAnnotationEndLoc(SourceLocation L)
SourceLocation getLocation() const
Return a source location identifier for the specified offset in the current file.
unsigned getLength() const
void setLength(unsigned Len)
void setKind(tok::TokenKind K)
bool is(tok::TokenKind K) const
is/isNot - Predicates to check if this token is a specific kind, as in "if (Tok.is(tok::l_brace)) {....
void * getAnnotationValue() const
tok::TokenKind getKind() const
bool hasLeadingSpace() const
Return true if this token has whitespace before it.
void setLocation(SourceLocation L)
bool isOneOf(tok::TokenKind K1, tok::TokenKind K2) const
bool isNot(tok::TokenKind K) const
void setAnnotationValue(void *val)
Models the abbreviated syntax to constrain a template type parameter: template <convertible_to<string...
The base class of the type hierarchy.
Represents a C++ unqualified-id that has been parsed.
void setIdentifier(const IdentifierInfo *Id, SourceLocation IdLoc)
Specify that this unqualified-id was parsed as an identifier.
unsigned kind
All of the diagnostics that can be emitted by the frontend.
TokenKind
Provides a simple uniform namespace for tokens from all C languages.
OverloadedOperatorKind
Enumeration specifying the different kinds of C++ overloaded operators.
@ OO_None
Not an overloaded operator.
@ IK_TemplateId
A template-id, e.g., f<int>.
@ IK_Identifier
An identifier.
@ Result
The result type of a method or function.
SourceRange getTemplateParamsRange(TemplateParameterList const *const *Params, unsigned NumParams)
Retrieves the range of the given template parameter lists.
TemplateNameKind
Specifies the kind of template name that an identifier refers to.
@ TNK_Type_template
The name refers to a template whose specialization produces a type.
@ TNK_Dependent_template_name
The name refers to a dependent template name:
@ TNK_Concept_template
The name refers to a concept.
@ TNK_Non_template
The name does not refer to a template.
OpaquePtr< QualType > ParsedType
An opaque type for threading parsed type information through the parser.
AccessSpecifier
A C++ access specifier (public, private, protected), plus the special value "none" which means differ...
Contains a late templated function.
FPOptions FPO
Floating-point options in the point of definition.
Decl * D
The template function declaration to be late parsed.
Information about a template-id annotation token.
TemplateNameKind Kind
The kind of template that Template refers to.
unsigned NumArgs
NumArgs - The number of template arguments.
ParsedTemplateArgument * getTemplateArgs()
Retrieves a pointer to the template arguments.
static TemplateIdAnnotation * Create(SourceLocation TemplateKWLoc, SourceLocation TemplateNameLoc, IdentifierInfo *Name, OverloadedOperatorKind OperatorKind, ParsedTemplateTy OpaqueTemplateName, TemplateNameKind TemplateKind, SourceLocation LAngleLoc, SourceLocation RAngleLoc, ArrayRef< ParsedTemplateArgument > TemplateArgs, bool ArgsInvalid, SmallVectorImpl< TemplateIdAnnotation * > &CleanupList)
Creates a new TemplateIdAnnotation with NumArgs arguments and appends it to List.
bool mightBeType() const
Determine whether this might be a type template.