23#include "llvm/Support/TimeProfiler.h"
38Decl *Parser::ParseDeclarationStartingWithTemplate(
41 ObjCDeclContextSwitch ObjCDC(*
this);
43 if (Tok.
is(tok::kw_template) &&
NextToken().isNot(tok::less)) {
45 DeclEnd, AccessAttrs, AS);
47 return ParseTemplateDeclarationOrSpecialization(Context, DeclEnd, AccessAttrs,
75Decl *Parser::ParseTemplateDeclarationOrSpecialization(
78 assert(Tok.
isOneOf(tok::kw_export, tok::kw_template) &&
79 "Token does not start a template declaration.");
81 MultiParseScope TemplateParamScopes(*
this);
109 bool isSpecialization =
true;
110 bool LastParamListWasEmpty =
false;
112 TemplateParameterDepthRAII CurTemplateDepthTracker(TemplateParameterDepth);
129 if (ParseTemplateParameters(TemplateParamScopes,
130 CurTemplateDepthTracker.getDepth(),
131 TemplateParams, LAngleLoc, RAngleLoc)) {
138 ExprResult OptionalRequiresClauseConstraintER;
139 if (!TemplateParams.empty()) {
140 isSpecialization =
false;
141 ++CurTemplateDepthTracker;
144 OptionalRequiresClauseConstraintER =
147 if (!OptionalRequiresClauseConstraintER.
isUsable()) {
155 LastParamListWasEmpty =
true;
159 CurTemplateDepthTracker.getDepth(), ExportLoc, TemplateLoc, LAngleLoc,
160 TemplateParams, RAngleLoc, OptionalRequiresClauseConstraintER.
get()));
161 }
while (Tok.
isOneOf(tok::kw_export, tok::kw_template));
164 if (Tok.
is(tok::kw_concept))
165 return ParseConceptDefinition(
166 ParsedTemplateInfo(&ParamLists, isSpecialization,
167 LastParamListWasEmpty),
170 return ParseSingleDeclarationAfterTemplate(
172 ParsedTemplateInfo(&ParamLists, isSpecialization, LastParamListWasEmpty),
173 ParsingTemplateParams, DeclEnd, AccessAttrs, AS);
186Decl *Parser::ParseSingleDeclarationAfterTemplate(
190 assert(TemplateInfo.Kind != ParsedTemplateInfo::NonTemplate &&
191 "Template information required");
193 if (Tok.
is(tok::kw_static_assert)) {
196 << TemplateInfo.getSourceRange();
198 return ParseStaticAssertDeclaration(DeclEnd);
204 AS, AccessAttrs, TemplateInfo, &DiagsFromTParams);
206 if (!D || !D.get().isSingleDecl())
208 return D.get().getSingleDecl();
212 MaybeParseCXX11Attributes(prefixAttrs);
214 if (Tok.
is(tok::kw_using)) {
215 auto usingDeclPtr = ParseUsingDirectiveOrDeclaration(Context, TemplateInfo, DeclEnd,
217 if (!usingDeclPtr || !usingDeclPtr.get().isSingleDecl())
219 return usingDeclPtr.get().getSingleDecl();
226 ParseDeclarationSpecifiers(DS, TemplateInfo, AS,
227 getDeclSpecContextFromDeclaratorContext(Context));
229 if (Tok.
is(tok::semi)) {
230 ProhibitAttributes(prefixAttrs);
235 TemplateInfo.TemplateParams ? *TemplateInfo.TemplateParams
237 TemplateInfo.Kind == ParsedTemplateInfo::ExplicitInstantiation,
239 assert(!AnonRecord &&
240 "Anonymous unions/structs should not be valid with template");
246 if (TemplateInfo.Kind == ParsedTemplateInfo::ExplicitInstantiation)
247 ProhibitAttributes(prefixAttrs);
252 if (TemplateInfo.TemplateParams)
253 DeclaratorInfo.setTemplateParameterLists(*TemplateInfo.TemplateParams);
265 bool IsTemplateSpecOrInst =
266 (TemplateInfo.Kind == ParsedTemplateInfo::ExplicitInstantiation ||
267 TemplateInfo.Kind == ParsedTemplateInfo::ExplicitSpecialization);
270 ParseDeclarator(DeclaratorInfo);
272 if (IsTemplateSpecOrInst)
276 if (!DeclaratorInfo.hasName()) {
279 if (Tok.
is(tok::semi))
284 llvm::TimeTraceScope TimeScope(
"ParseTemplate", [&]() {
285 return std::string(DeclaratorInfo.getIdentifier() !=
nullptr
286 ? DeclaratorInfo.getIdentifier()->getName()
290 LateParsedAttrList LateParsedAttrs(
true);
291 if (DeclaratorInfo.isFunctionDeclarator()) {
292 if (Tok.
is(tok::kw_requires)) {
293 CXXScopeSpec &ScopeSpec = DeclaratorInfo.getCXXScopeSpec();
294 DeclaratorScopeObj DeclScopeObj(*
this, ScopeSpec);
297 DeclScopeObj.EnterDeclaratorScope();
298 ParseTrailingRequiresClause(DeclaratorInfo);
301 MaybeParseGNUAttributes(DeclaratorInfo, &LateParsedAttrs);
304 if (DeclaratorInfo.isFunctionDeclarator() &&
305 isStartOfFunctionDefinition(DeclaratorInfo)) {
311 Diag(Tok, diag::err_function_definition_not_allowed);
320 Diag(DS.getStorageClassSpecLoc(), diag::err_function_declared_typedef)
322 DS.ClearStorageClassSpecs();
325 if (TemplateInfo.Kind == ParsedTemplateInfo::ExplicitInstantiation) {
326 if (DeclaratorInfo.getName().getKind() !=
330 Diag(Tok, diag::err_template_defn_explicit_instantiation) << 0;
331 return ParseFunctionDefinition(DeclaratorInfo, ParsedTemplateInfo(),
336 Diag(DeclaratorInfo.getIdentifierLoc(),
337 diag::err_explicit_instantiation_with_definition)
345 std::nullopt, LAngleLoc,
nullptr));
347 return ParseFunctionDefinition(
348 DeclaratorInfo, ParsedTemplateInfo(&FakedParamLists,
354 return ParseFunctionDefinition(DeclaratorInfo, TemplateInfo,
359 Decl *ThisDecl = ParseDeclarationAfterDeclarator(DeclaratorInfo,
362 if (Tok.
is(tok::comma)) {
363 Diag(Tok, diag::err_multiple_template_declarators)
364 << (
int)TemplateInfo.Kind;
370 ExpectAndConsumeSemi(diag::err_expected_semi_declaration);
371 if (LateParsedAttrs.size() > 0)
372 ParseLexedAttributeList(LateParsedAttrs, ThisDecl,
true,
false);
373 DeclaratorInfo.complete(ThisDecl);
384Parser::ParseConceptDefinition(
const ParsedTemplateInfo &TemplateInfo,
386 assert(TemplateInfo.Kind != ParsedTemplateInfo::NonTemplate &&
387 "Template information required");
388 assert(Tok.
is(tok::kw_concept) &&
389 "ParseConceptDefinition must be called when at a 'concept' keyword");
398 DiagnoseAndSkipCXX11Attributes();
401 if (ParseOptionalCXXScopeSpecifier(
405 false,
nullptr,
true) ||
413 diag::err_concept_definition_not_identifier);
427 Diag(
Result.getBeginLoc(), diag::err_concept_definition_not_identifier);
435 DiagnoseAndSkipCXX11Attributes();
451 ExpectAndConsumeSemi(diag::err_expected_semi_declaration);
452 Expr *ConstraintExpr = ConstraintExprResult.
get();
454 *TemplateInfo.TemplateParams,
455 Id, IdLoc, ConstraintExpr);
467bool Parser::ParseTemplateParameters(
468 MultiParseScope &TemplateScopes,
unsigned Depth,
480 if (!Tok.
is(tok::greater) && !Tok.
is(tok::greatergreater)) {
482 Failed = ParseTemplateParameterList(Depth, TemplateParams);
485 if (Tok.
is(tok::greatergreater)) {
510Parser::ParseTemplateParameterList(
const unsigned Depth,
515 = ParseTemplateParameter(Depth, TemplateParams.size())) {
516 TemplateParams.push_back(TmpParam);
520 SkipUntil(tok::comma, tok::greater, tok::greatergreater,
525 if (Tok.
is(tok::comma)) {
527 }
else if (Tok.
isOneOf(tok::greater, tok::greatergreater)) {
535 SkipUntil(tok::comma, tok::greater, tok::greatergreater,
545Parser::TPResult Parser::isStartOfTemplateTypeParameter() {
546 if (Tok.
is(tok::kw_class)) {
553 case tok::greatergreater:
555 return TPResult::True;
557 case tok::identifier:
563 return TPResult::False;
566 switch (GetLookAheadToken(2).
getKind()) {
570 case tok::greatergreater:
571 return TPResult::True;
574 return TPResult::False;
578 if (TryAnnotateTypeConstraint())
579 return TPResult::Error;
581 if (isTypeConstraintAnnotation() &&
585 !GetLookAheadToken(Tok.
is(tok::annot_cxxscope) ? 2 : 1)
586 .
isOneOf(tok::kw_auto, tok::kw_decltype))
587 return TPResult::True;
591 if (Tok.
isNot(tok::kw_typename) && Tok.
isNot(tok::kw_typedef))
592 return TPResult::False;
603 if (Next.getKind() == tok::identifier)
604 Next = GetLookAheadToken(2);
606 switch (Next.getKind()) {
610 case tok::greatergreater:
612 return TPResult::True;
614 case tok::kw_typename:
615 case tok::kw_typedef:
619 return TPResult::True;
622 return TPResult::False;
646NamedDecl *Parser::ParseTemplateParameter(
unsigned Depth,
unsigned Position) {
648 switch (isStartOfTemplateTypeParameter()) {
652 if (Tok.
is(tok::kw_typedef)) {
664 return ParseTypeParameter(Depth, Position);
665 case TPResult::False:
668 case TPResult::Error: {
676 DS.SetTypeSpecError();
680 D.setInvalidType(
true);
685 SkipUntil(tok::comma, tok::greater, tok::greatergreater,
690 case TPResult::Ambiguous:
691 llvm_unreachable(
"template param classification can't be ambiguous");
694 if (Tok.
is(tok::kw_template))
695 return ParseTemplateTemplateParameter(Depth, Position);
700 return ParseNonTypeTemplateParameter(Depth, Position);
705bool Parser::isTypeConstraintAnnotation() {
707 if (T.
isNot(tok::annot_template_id))
709 const auto *ExistingAnnot =
722bool Parser::TryAnnotateTypeConstraint() {
726 bool WasScopeAnnotation = Tok.
is(tok::annot_cxxscope);
727 if (ParseOptionalCXXScopeSpecifier(SS,
nullptr,
742 if (Tok.
is(tok::identifier)) {
748 bool MemberOfUnknownSpecialization =
false;
755 MemberOfUnknownSpecialization,
757 if (MemberOfUnknownSpecialization || !PossibleConcept ||
760 AnnotateScopeToken(SS, !WasScopeAnnotation);
767 if (AnnotateTemplateIdToken(PossibleConcept, TNK, SS,
776 AnnotateScopeToken(SS, !WasScopeAnnotation);
789NamedDecl *Parser::ParseTypeParameter(
unsigned Depth,
unsigned Position) {
790 assert((Tok.
isOneOf(tok::kw_class, tok::kw_typename) ||
791 isTypeConstraintAnnotation()) &&
792 "A type-parameter starts with 'class', 'typename' or a "
797 bool TypenameKeyword =
false;
799 ParseOptionalCXXScopeSpecifier(TypeConstraintSS,
nullptr,
802 if (Tok.
is(tok::annot_template_id)) {
807 "stray non-concept template-id annotation");
808 KeyLoc = ConsumeAnnotationToken();
810 assert(TypeConstraintSS.
isEmpty() &&
811 "expected type constraint after scope specifier");
814 TypenameKeyword = Tok.
is(tok::kw_typename);
823 ? diag::warn_cxx98_compat_variadic_templates
824 : diag::ext_variadic_templates);
830 if (Tok.
is(tok::identifier)) {
833 }
else if (Tok.
isOneOf(tok::equal, tok::comma, tok::greater,
834 tok::greatergreater)) {
843 bool AlreadyHasEllipsis = EllipsisLoc.
isValid();
845 DiagnoseMisplacedEllipsis(EllipsisLoc, NameLoc, AlreadyHasEllipsis,
true);
858 TypenameKeyword, EllipsisLoc,
859 KeyLoc, ParamName, NameLoc,
860 Depth, Position, EqualLoc,
866 cast<TemplateTypeParmDecl>(NewDecl),
885NamedDecl *Parser::ParseTemplateTemplateParameter(
unsigned Depth,
887 assert(Tok.
is(tok::kw_template) &&
"Expected 'template' keyword");
893 ExprResult OptionalRequiresClauseConstraintER;
895 MultiParseScope TemplateParmScope(*
this);
896 if (ParseTemplateParameters(TemplateParmScope, Depth + 1, TemplateParams,
897 LAngleLoc, RAngleLoc)) {
901 OptionalRequiresClauseConstraintER =
904 if (!OptionalRequiresClauseConstraintER.
isUsable()) {
905 SkipUntil(tok::comma, tok::greater, tok::greatergreater,
918 bool Replace = Tok.
isOneOf(tok::kw_typename, tok::kw_struct);
920 if (Tok.
is(tok::kw_typename)) {
923 ? diag::warn_cxx14_compat_template_template_param_typename
924 : diag::ext_template_template_param_typename)
928 }
else if (Next.isOneOf(tok::identifier, tok::comma, tok::greater,
929 tok::greatergreater, tok::ellipsis)) {
934 :
FixItHint::CreateInsertion(Tok.getLocation(),
"class "));
948 ? diag::warn_cxx98_compat_variadic_templates
949 : diag::ext_variadic_templates);
954 if (Tok.
is(tok::identifier)) {
957 }
else if (Tok.
isOneOf(tok::equal, tok::comma, tok::greater,
958 tok::greatergreater)) {
967 bool AlreadyHasEllipsis = EllipsisLoc.
isValid();
969 DiagnoseMisplacedEllipsis(EllipsisLoc, NameLoc, AlreadyHasEllipsis,
true);
973 RAngleLoc, OptionalRequiresClauseConstraintER.
get());
981 DefaultArg = ParseTemplateTemplateArgument();
984 diag::err_default_template_template_parameter_not_template);
985 SkipUntil(tok::comma, tok::greater, tok::greatergreater,
991 ParamList, EllipsisLoc,
992 ParamName, NameLoc, Depth,
993 Position, EqualLoc, DefaultArg);
1003Parser::ParseNonTypeTemplateParameter(
unsigned Depth,
unsigned Position) {
1008 ParseDeclarationSpecifiers(DS, ParsedTemplateInfo(),
AS_none,
1009 DeclSpecContext::DSC_template_param);
1014 ParseDeclarator(ParamDecl);
1023 DiagnoseMisplacedEllipsisInDeclarator(EllipsisLoc, ParamDecl);
1031 if (Tok.
is(tok::l_paren) &&
NextToken().is(tok::l_brace)) {
1052 Depth, Position, EqualLoc,
1056void Parser::DiagnoseMisplacedEllipsis(
SourceLocation EllipsisLoc,
1058 bool AlreadyHasEllipsis,
1059 bool IdentifierHasName) {
1061 if (!AlreadyHasEllipsis)
1063 Diag(EllipsisLoc, diag::err_misplaced_ellipsis_in_declaration)
1065 << !IdentifierHasName;
1068void Parser::DiagnoseMisplacedEllipsisInDeclarator(
SourceLocation EllipsisLoc,
1070 assert(EllipsisLoc.
isValid());
1072 if (!AlreadyHasEllipsis)
1075 AlreadyHasEllipsis, D.
hasName());
1093bool Parser::ParseGreaterThanInTemplateList(
SourceLocation LAngleLoc,
1095 bool ConsumeLastToken,
1096 bool ObjCGenericList) {
1099 const char *ReplacementStr =
"> >";
1100 bool MergeWithNextToken =
false;
1105 Diag(LAngleLoc, diag::note_matching) << tok::less;
1112 if (ConsumeLastToken)
1116 case tok::greatergreater:
1117 RemainingToken = tok::greater;
1120 case tok::greatergreatergreater:
1121 RemainingToken = tok::greatergreater;
1124 case tok::greaterequal:
1125 RemainingToken = tok::equal;
1126 ReplacementStr =
"> =";
1133 RemainingToken = tok::equalequal;
1134 MergeWithNextToken =
true;
1138 case tok::greatergreaterequal:
1139 RemainingToken = tok::greaterequal;
1158 bool PreventMergeWithNextToken =
1159 (RemainingToken == tok::greater ||
1160 RemainingToken == tok::greatergreater) &&
1161 (Next.isOneOf(tok::greater, tok::greatergreater,
1162 tok::greatergreatergreater, tok::equal, tok::greaterequal,
1163 tok::greatergreaterequal, tok::equalequal)) &&
1164 areTokensAdjacent(Tok, Next);
1167 if (!ObjCGenericList) {
1182 if (PreventMergeWithNextToken)
1185 unsigned DiagId = diag::err_two_right_angle_brackets_need_space;
1187 (Tok.
is(tok::greatergreater) || Tok.
is(tok::greatergreatergreater)))
1188 DiagId = diag::warn_cxx98_compat_two_right_angle_brackets;
1189 else if (Tok.
is(tok::greaterequal))
1190 DiagId = diag::err_right_angle_bracket_equal_needs_space;
1191 Diag(TokLoc, DiagId) << Hint1 << Hint2;
1202 RAngleLoc = PP.
SplitToken(TokLoc, GreaterLength);
1208 Greater.setLocation(RAngleLoc);
1209 Greater.setKind(tok::greater);
1210 Greater.setLength(GreaterLength);
1213 if (MergeWithNextToken) {
1219 Tok.
setLength(OldLength - GreaterLength);
1224 if (PreventMergeWithNextToken)
1229 if (CachingTokens) {
1231 if (MergeWithNextToken)
1234 if (ConsumeLastToken)
1240 if (ConsumeLastToken) {
1241 PrevTokLocation = RAngleLoc;
1243 PrevTokLocation = TokBeforeGreaterLoc;
1262bool Parser::ParseTemplateIdAfterTemplateName(
bool ConsumeLastToken,
1264 TemplateArgList &TemplateArgs,
1266 TemplateTy Template) {
1267 assert(Tok.
is(tok::less) &&
"Must have already parsed the template-name");
1276 if (!Tok.
isOneOf(tok::greater, tok::greatergreater,
1277 tok::greatergreatergreater, tok::greaterequal,
1278 tok::greatergreaterequal))
1279 Invalid = ParseTemplateArgumentList(TemplateArgs, Template, LAngleLoc);
1284 SkipUntil(tok::greater, tok::greatergreater,
1291 return ParseGreaterThanInTemplateList(LAngleLoc, RAngleLoc, ConsumeLastToken,
1337bool Parser::AnnotateTemplateIdToken(TemplateTy Template,
TemplateNameKind TNK,
1341 bool AllowTypeAnnotation,
1345 "Parser isn't at the beginning of a template-id");
1346 assert(!(
TypeConstraint && AllowTypeAnnotation) &&
"type-constraint can't be "
1347 "a type annotation");
1349 "must accompany a concept name");
1357 TemplateArgList TemplateArgs;
1358 bool ArgsInvalid =
false;
1360 ArgsInvalid = ParseTemplateIdAfterTemplateName(
1361 false, LAngleLoc, TemplateArgs, RAngleLoc, Template);
1376 : Actions.ActOnTemplateIdType(
1379 LAngleLoc, TemplateArgsPtr, RAngleLoc);
1381 Tok.
setKind(tok::annot_typename);
1382 setTypeAnnotation(Tok,
Type);
1385 else if (TemplateKWLoc.
isValid())
1392 Tok.
setKind(tok::annot_template_id);
1405 TemplateKWLoc, TemplateNameLoc, TemplateII, OpKind, Template, TNK,
1406 LAngleLoc, RAngleLoc, TemplateArgs, ArgsInvalid, TemplateIds);
1439void Parser::AnnotateTemplateIdTokenAsType(
1442 assert(Tok.
is(tok::annot_template_id) &&
"Requires template-id tokens");
1446 "Only works for type and dependent templates");
1454 : Actions.ActOnTemplateIdType(
1456 TemplateId->Template, TemplateId->Name,
1457 TemplateId->TemplateNameLoc, TemplateId->LAngleLoc,
1458 TemplateArgsPtr, TemplateId->RAngleLoc,
1459 false, IsClassName, AllowImplicitTypename);
1461 Tok.
setKind(tok::annot_typename);
1462 setTypeAnnotation(Tok,
Type);
1475 return Tok.
isOneOf(tok::comma, tok::greater, tok::greatergreater,
1476 tok::greatergreatergreater);
1481 if (!Tok.
is(tok::identifier) && !Tok.
is(tok::coloncolon) &&
1482 !Tok.
is(tok::annot_cxxscope))
1497 ParseOptionalCXXScopeSpecifier(SS,
nullptr,
1503 if (SS.
isSet() && Tok.
is(tok::kw_template)) {
1508 if (Tok.
is(tok::identifier)) {
1526 }
else if (Tok.
is(tok::identifier)) {
1536 bool MemberOfUnknownSpecialization;
1541 false, Template, MemberOfUnknownSpecialization);
1578 if (isCXXTypeId(TypeIdAsTemplateArgument)) {
1586 TentativeParsingAction TPA(*
this);
1589 = ParseTemplateTemplateArgument();
1590 if (!TemplateTemplateArgument.
isInvalid()) {
1592 return TemplateTemplateArgument;
1607 ExprArg.
get(), Loc);
1618bool Parser::ParseTemplateArgumentList(TemplateArgList &TemplateArgs,
1619 TemplateTy Template,
1624 auto RunSignatureHelp = [&] {
1627 CalledSignatureHelp =
true;
1646 TemplateArgs.push_back(Arg);
1672 return ParseSingleDeclarationAfterTemplate(
1673 Context, ParsedTemplateInfo(ExternLoc, TemplateLoc),
1674 ParsingTemplateParams, DeclEnd, AccessAttrs, AS);
1677SourceRange Parser::ParsedTemplateInfo::getSourceRange()
const {
1680 TemplateParams->size());
1684 R.setBegin(ExternLoc);
1689 ((
Parser *)
P)->ParseLateTemplatedFuncDef(LPT);
1698 DestroyTemplateIdAnnotationsRAIIObj CleanupRAII(*
this);
1703 TemplateParameterDepthRAII CurTemplateDepthTracker(TemplateParameterDepth);
1709 MultiParseScope Scopes(*
this);
1714 DC = DC->getLexicalParent())
1715 DeclContextsToReenter.push_back(DC);
1718 for (
DeclContext *DC : reverse(DeclContextsToReenter)) {
1719 CurTemplateDepthTracker.addDepth(
1727 assert(!LPT.
Toks.empty() &&
"Empty body!");
1731 LPT.
Toks.push_back(Tok);
1732 PP.EnterTokenStream(LPT.
Toks,
true,
true);
1736 assert(Tok.
isOneOf(tok::l_brace, tok::colon, tok::kw_try) &&
1737 "Inline method not starting with '{', ':' or 'try'");
1749 if (Tok.
is(tok::kw_try)) {
1750 ParseFunctionTryBlock(LPT.
D, FnScope);
1752 if (Tok.
is(tok::colon))
1753 ParseConstructorInitializer(LPT.
D);
1757 if (Tok.
is(tok::l_brace)) {
1758 assert((!isa<FunctionTemplateDecl>(LPT.
D) ||
1759 cast<FunctionTemplateDecl>(LPT.
D)
1760 ->getTemplateParameters()
1761 ->getDepth() == TemplateParameterDepth - 1) &&
1762 "TemplateParameterDepth should be greater than the depth of "
1763 "current template being instantiated!");
1764 ParseFunctionStatementBody(LPT.
D, FnScope);
1772void Parser::LexTemplateFunctionForLateParsing(
CachedTokens &Toks) {
1774 if (!ConsumeAndStoreFunctionPrologue(Toks)) {
1776 ConsumeAndStoreUntil(tok::r_brace, Toks,
false);
1780 if (kind == tok::kw_try) {
1781 while (Tok.
is(tok::kw_catch)) {
1782 ConsumeAndStoreUntil(tok::l_brace, Toks,
false);
1783 ConsumeAndStoreUntil(tok::r_brace, Toks,
false);
1793 TentativeParsingAction TPA(*
this);
1795 if (
SkipUntil(tok::greater, tok::greatergreater, tok::greatergreatergreater,
1800 ParseGreaterThanInTemplateList(
Less,
Greater,
true,
false);
1812void Parser::checkPotentialAngleBracket(
ExprResult &PotentialTemplateName) {
1813 assert(Tok.
is(tok::less) &&
"not at a potential angle bracket");
1829 ParseGreaterThanInTemplateList(
Less,
Greater,
true,
false);
1841 TentativeParsingAction TPA(*
this);
1843 if (isTypeIdUnambiguously() &&
1844 diagnoseUnknownTemplateId(PotentialTemplateName,
Less)) {
1855 AngleBracketTracker::Priority
Priority =
1857 : AngleBracketTracker::PotentialTypo) |
1859 : AngleBracketTracker::NoSpaceBeforeLess);
1860 AngleBrackets.add(*
this, PotentialTemplateName.
get(), Tok.
getLocation(),
1864bool Parser::checkPotentialAngleBracketDelimiter(
1865 const AngleBracketTracker::Loc &LAngle,
const Token &OpToken) {
1869 if (OpToken.
is(tok::comma) && isTypeIdUnambiguously() &&
1870 diagnoseUnknownTemplateId(LAngle.TemplateName, LAngle.LessLoc)) {
1871 AngleBrackets.clear(*
this);
1878 if (OpToken.
is(tok::greater) && Tok.
is(tok::l_paren) &&
1881 getCurScope(), LAngle.TemplateName, LAngle.LessLoc,
1883 AngleBrackets.clear(*
this);
1889 if (OpToken.
is(tok::greater) ||
1891 OpToken.
isOneOf(tok::greatergreater, tok::greatergreatergreater)))
1892 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.
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.
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)
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.
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.