36 ObjCDeclContextSwitch ObjCDC(*
this);
38 if (Tok.
is(tok::kw_template) &&
NextToken().isNot(tok::less)) {
43 return ParseTemplateDeclarationOrSpecialization(Context, DeclEnd, AccessAttrs,
50 assert(Tok.
isOneOf(tok::kw_export, tok::kw_template) &&
51 "Token does not start a template declaration.");
53 MultiParseScope TemplateParamScopes(*
this);
81 bool isSpecialization =
true;
82 bool LastParamListWasEmpty =
false;
84 TemplateParameterDepthRAII CurTemplateDepthTracker(TemplateParameterDepth);
101 if (ParseTemplateParameters(TemplateParamScopes,
102 CurTemplateDepthTracker.getDepth(),
103 TemplateParams, LAngleLoc, RAngleLoc)) {
110 ExprResult OptionalRequiresClauseConstraintER;
111 if (!TemplateParams.empty()) {
112 isSpecialization =
false;
113 ++CurTemplateDepthTracker;
116 OptionalRequiresClauseConstraintER =
119 if (!OptionalRequiresClauseConstraintER.
isUsable()) {
127 LastParamListWasEmpty =
true;
131 CurTemplateDepthTracker.getDepth(), ExportLoc, TemplateLoc, LAngleLoc,
132 TemplateParams, RAngleLoc, OptionalRequiresClauseConstraintER.
get()));
133 }
while (Tok.
isOneOf(tok::kw_export, tok::kw_template));
135 ParsedTemplateInfo TemplateInfo(&ParamLists, isSpecialization,
136 LastParamListWasEmpty);
139 if (Tok.
is(tok::kw_concept)) {
147 return ParseDeclarationAfterTemplate(
148 Context, TemplateInfo, ParsingTemplateParams, DeclEnd, AccessAttrs, AS);
154 return ParseTemplateDeclarationOrSpecialization(Context, DeclEnd, AccessAttrs,
163 "Template information required");
165 if (Tok.
is(tok::kw_static_assert)) {
168 << TemplateInfo.getSourceRange();
171 ParseStaticAssertDeclaration(DeclEnd));
176 return ParseCXXClassMemberDeclaration(AS, AccessAttrs, TemplateInfo,
186 while (MaybeParseCXX11Attributes(DeclAttrs) ||
187 MaybeParseGNUAttributes(DeclSpecAttrs))
190 if (Tok.
is(tok::kw_using))
191 return ParseUsingDirectiveOrDeclaration(Context, TemplateInfo, DeclEnd,
197 DS.SetRangeStart(DeclSpecAttrs.Range.getBegin());
198 DS.SetRangeEnd(DeclSpecAttrs.Range.getEnd());
199 DS.takeAttributesFrom(DeclSpecAttrs);
201 ParseDeclarationSpecifiers(DS, TemplateInfo, AS,
202 getDeclSpecContextFromDeclaratorContext(Context));
204 if (Tok.
is(tok::semi)) {
205 ProhibitAttributes(DeclAttrs);
210 TemplateInfo.TemplateParams ? *TemplateInfo.TemplateParams
215 assert(!AnonRecord &&
216 "Anonymous unions/structs should not be valid with template");
221 if (DS.hasTagDefinition())
226 ProhibitAttributes(DeclAttrs);
228 return ParseDeclGroup(DS, Context, DeclAttrs, TemplateInfo, &DeclEnd);
232Parser::ParseConceptDefinition(
const ParsedTemplateInfo &TemplateInfo,
235 "Template information required");
236 assert(Tok.
is(tok::kw_concept) &&
237 "ParseConceptDefinition must be called when at a 'concept' keyword");
246 DiagnoseAndSkipCXX11Attributes();
249 if (ParseOptionalCXXScopeSpecifier(
253 false,
nullptr,
true) ||
261 diag::err_concept_definition_not_identifier);
275 Diag(
Result.getBeginLoc(), diag::err_concept_definition_not_identifier);
289 MaybeParseAttributes(PAKM_GNU | PAKM_CXX11, Attrs);
308 ExpectAndConsumeSemi(diag::err_expected_semi_declaration);
309 Expr *ConstraintExpr = ConstraintExprResult.
get();
318bool Parser::ParseTemplateParameters(
319 MultiParseScope &TemplateScopes,
unsigned Depth,
331 if (!Tok.
is(tok::greater) && !Tok.
is(tok::greatergreater)) {
333 Failed = ParseTemplateParameterList(Depth, TemplateParams);
336 if (Tok.
is(tok::greatergreater)) {
353Parser::ParseTemplateParameterList(
const unsigned Depth,
358 = ParseTemplateParameter(Depth, TemplateParams.size())) {
359 TemplateParams.push_back(TmpParam);
363 SkipUntil(tok::comma, tok::greater, tok::greatergreater,
368 if (Tok.
is(tok::comma)) {
370 }
else if (Tok.
isOneOf(tok::greater, tok::greatergreater)) {
378 SkipUntil(tok::comma, tok::greater, tok::greatergreater,
386Parser::TPResult Parser::isStartOfTemplateTypeParameter() {
387 if (Tok.
is(tok::kw_class)) {
394 case tok::greatergreater:
396 return TPResult::True;
398 case tok::identifier:
404 return TPResult::False;
411 case tok::greatergreater:
412 return TPResult::True;
415 return TPResult::False;
419 if (TryAnnotateTypeConstraint())
420 return TPResult::Error;
422 if (isTypeConstraintAnnotation() &&
427 .
isOneOf(tok::kw_auto, tok::kw_decltype))
428 return TPResult::True;
432 if (Tok.
isNot(tok::kw_typename) && Tok.
isNot(tok::kw_typedef))
433 return TPResult::False;
444 if (Next.getKind() == tok::identifier)
447 switch (Next.getKind()) {
451 case tok::greatergreater:
453 return TPResult::True;
455 case tok::kw_typename:
456 case tok::kw_typedef:
460 return TPResult::True;
463 return TPResult::False;
467NamedDecl *Parser::ParseTemplateParameter(
unsigned Depth,
unsigned Position) {
469 switch (isStartOfTemplateTypeParameter()) {
473 if (Tok.
is(tok::kw_typedef)) {
485 return ParseTypeParameter(Depth, Position);
486 case TPResult::False:
489 case TPResult::Error: {
497 DS.SetTypeSpecError();
501 D.setInvalidType(
true);
506 SkipUntil(tok::comma, tok::greater, tok::greatergreater,
511 case TPResult::Ambiguous:
512 llvm_unreachable(
"template param classification can't be ambiguous");
515 if (Tok.
is(tok::kw_template))
516 return ParseTemplateTemplateParameter(Depth, Position);
521 return ParseNonTypeTemplateParameter(Depth, Position);
524bool Parser::isTypeConstraintAnnotation() {
526 if (
T.isNot(tok::annot_template_id))
528 const auto *ExistingAnnot =
533bool Parser::TryAnnotateTypeConstraint() {
537 bool WasScopeAnnotation = Tok.
is(tok::annot_cxxscope);
538 if (ParseOptionalCXXScopeSpecifier(SS,
nullptr,
553 if (Tok.
is(tok::identifier)) {
559 bool MemberOfUnknownSpecialization =
false;
566 MemberOfUnknownSpecialization,
568 if (MemberOfUnknownSpecialization || !PossibleConcept ||
571 AnnotateScopeToken(SS, !WasScopeAnnotation);
578 if (AnnotateTemplateIdToken(PossibleConcept, TNK, SS,
587 AnnotateScopeToken(SS, !WasScopeAnnotation);
591NamedDecl *Parser::ParseTypeParameter(
unsigned Depth,
unsigned Position) {
592 assert((Tok.
isOneOf(tok::kw_class, tok::kw_typename) ||
593 isTypeConstraintAnnotation()) &&
594 "A type-parameter starts with 'class', 'typename' or a "
599 bool TypenameKeyword =
false;
601 ParseOptionalCXXScopeSpecifier(TypeConstraintSS,
nullptr,
604 if (Tok.
is(tok::annot_template_id)) {
609 "stray non-concept template-id annotation");
610 KeyLoc = ConsumeAnnotationToken();
612 assert(TypeConstraintSS.
isEmpty() &&
613 "expected type constraint after scope specifier");
616 TypenameKeyword = Tok.
is(tok::kw_typename);
625 ? diag::warn_cxx98_compat_variadic_templates
626 : diag::ext_variadic_templates);
632 if (Tok.
is(tok::identifier)) {
635 }
else if (Tok.
isOneOf(tok::equal, tok::comma, tok::greater,
636 tok::greatergreater)) {
645 bool AlreadyHasEllipsis = EllipsisLoc.
isValid();
647 DiagnoseMisplacedEllipsis(EllipsisLoc, NameLoc, AlreadyHasEllipsis,
true);
654 std::optional<DelayTemplateIdDestructionRAII> DontDestructTemplateIds;
659 DontDestructTemplateIds.emplace(*
this,
true);
664 TemplateParameterDepthRAII CurTemplateDepthTracker(TemplateParameterDepth);
665 ++CurTemplateDepthTracker;
672 TypenameKeyword, EllipsisLoc,
673 KeyLoc, ParamName, NameLoc,
674 Depth, Position, EqualLoc,
680 cast<TemplateTypeParmDecl>(NewDecl),
687NamedDecl *Parser::ParseTemplateTemplateParameter(
unsigned Depth,
689 assert(Tok.
is(tok::kw_template) &&
"Expected 'template' keyword");
695 ExprResult OptionalRequiresClauseConstraintER;
697 MultiParseScope TemplateParmScope(*
this);
698 if (ParseTemplateParameters(TemplateParmScope, Depth + 1, TemplateParams,
699 LAngleLoc, RAngleLoc)) {
703 OptionalRequiresClauseConstraintER =
706 if (!OptionalRequiresClauseConstraintER.
isUsable()) {
707 SkipUntil(tok::comma, tok::greater, tok::greatergreater,
718 bool TypenameKeyword =
false;
729 bool Replace = Tok.
isOneOf(tok::kw_typename, tok::kw_struct);
731 if (Tok.
is(tok::kw_typename)) {
732 TypenameKeyword =
true;
736 ? diag::warn_cxx14_compat_template_template_param_typename
737 : diag::ext_template_template_param_typename)
746 }
else if (Next.isOneOf(tok::identifier, tok::comma, tok::greater,
747 tok::greatergreater, tok::ellipsis)) {
755 :
FixItHint::CreateInsertion(Tok.getLocation(),
"class "));
764 Diag(PrevTokLocation, diag::err_cxx26_template_template_params)
772 ? diag::warn_cxx98_compat_variadic_templates
773 : diag::ext_variadic_templates);
777 if (Tok.
is(tok::identifier)) {
780 }
else if (Tok.
isOneOf(tok::equal, tok::comma, tok::greater,
781 tok::greatergreater)) {
790 bool AlreadyHasEllipsis = EllipsisLoc.
isValid();
792 DiagnoseMisplacedEllipsis(EllipsisLoc, NameLoc, AlreadyHasEllipsis,
true);
796 RAngleLoc, OptionalRequiresClauseConstraintER.
get());
804 DefaultArg = ParseTemplateTemplateArgument();
807 diag::err_default_template_template_parameter_not_template);
808 SkipUntil(tok::comma, tok::greater, tok::greatergreater,
814 getCurScope(), TemplateLoc, Kind, TypenameKeyword, ParamList, EllipsisLoc,
815 ParamName, NameLoc, Depth, Position, EqualLoc, DefaultArg);
819Parser::ParseNonTypeTemplateParameter(
unsigned Depth,
unsigned Position) {
824 ParsedTemplateInfo TemplateInfo;
825 ParseDeclarationSpecifiers(DS, TemplateInfo,
AS_none,
826 DeclSpecContext::DSC_template_param);
831 ParseDeclarator(ParamDecl);
840 DiagnoseMisplacedEllipsisInDeclarator(EllipsisLoc, ParamDecl);
848 if (Tok.
is(tok::l_paren) &&
NextToken().is(tok::l_brace)) {
863 TemplateParameterDepthRAII CurTemplateDepthTracker(
864 TemplateParameterDepth);
865 ++CurTemplateDepthTracker;
876 Depth, Position, EqualLoc,
882 bool AlreadyHasEllipsis,
883 bool IdentifierHasName) {
885 if (!AlreadyHasEllipsis)
887 Diag(EllipsisLoc, diag::err_misplaced_ellipsis_in_declaration)
889 << !IdentifierHasName;
892void Parser::DiagnoseMisplacedEllipsisInDeclarator(
SourceLocation EllipsisLoc,
895 bool AlreadyHasEllipsis =
D.getEllipsisLoc().isValid();
896 if (!AlreadyHasEllipsis)
897 D.setEllipsisLoc(EllipsisLoc);
898 DiagnoseMisplacedEllipsis(EllipsisLoc,
D.getIdentifierLoc(),
899 AlreadyHasEllipsis,
D.hasName());
902bool Parser::ParseGreaterThanInTemplateList(
SourceLocation LAngleLoc,
904 bool ConsumeLastToken,
905 bool ObjCGenericList) {
908 const char *ReplacementStr =
"> >";
909 bool MergeWithNextToken =
false;
914 Diag(LAngleLoc, diag::note_matching) << tok::less;
921 if (ConsumeLastToken)
925 case tok::greatergreater:
926 RemainingToken = tok::greater;
929 case tok::greatergreatergreater:
930 RemainingToken = tok::greatergreater;
933 case tok::greaterequal:
934 RemainingToken = tok::equal;
935 ReplacementStr =
"> =";
942 RemainingToken = tok::equalequal;
943 MergeWithNextToken =
true;
947 case tok::greatergreaterequal:
948 RemainingToken = tok::greaterequal;
967 bool PreventMergeWithNextToken =
968 (RemainingToken == tok::greater ||
969 RemainingToken == tok::greatergreater) &&
970 (Next.isOneOf(tok::greater, tok::greatergreater,
971 tok::greatergreatergreater, tok::equal, tok::greaterequal,
972 tok::greatergreaterequal, tok::equalequal)) &&
973 areTokensAdjacent(Tok, Next);
976 if (!ObjCGenericList) {
991 if (PreventMergeWithNextToken)
994 unsigned DiagId = diag::err_two_right_angle_brackets_need_space;
996 (Tok.
is(tok::greatergreater) || Tok.
is(tok::greatergreatergreater)))
997 DiagId = diag::warn_cxx98_compat_two_right_angle_brackets;
998 else if (Tok.
is(tok::greaterequal))
999 DiagId = diag::err_right_angle_bracket_equal_needs_space;
1000 Diag(TokLoc, DiagId) << Hint1 << Hint2;
1011 RAngleLoc = PP.
SplitToken(TokLoc, GreaterLength);
1017 Greater.setLocation(RAngleLoc);
1018 Greater.setKind(tok::greater);
1019 Greater.setLength(GreaterLength);
1022 if (MergeWithNextToken) {
1028 Tok.
setLength(OldLength - GreaterLength);
1033 if (PreventMergeWithNextToken)
1038 if (CachingTokens) {
1040 if (MergeWithNextToken)
1043 if (ConsumeLastToken)
1049 if (ConsumeLastToken) {
1050 PrevTokLocation = RAngleLoc;
1052 PrevTokLocation = TokBeforeGreaterLoc;
1060bool Parser::ParseTemplateIdAfterTemplateName(
bool ConsumeLastToken,
1062 TemplateArgList &TemplateArgs,
1065 assert(Tok.
is(tok::less) &&
"Must have already parsed the template-name");
1074 if (!Tok.
isOneOf(tok::greater, tok::greatergreater,
1075 tok::greatergreatergreater, tok::greaterequal,
1076 tok::greatergreaterequal))
1077 Invalid = ParseTemplateArgumentList(TemplateArgs,
Template, LAngleLoc);
1082 SkipUntil(tok::greater, tok::greatergreater,
1089 return ParseGreaterThanInTemplateList(LAngleLoc, RAngleLoc, ConsumeLastToken,
1098 bool AllowTypeAnnotation,
1102 "Parser isn't at the beginning of a template-id");
1103 assert(!(
TypeConstraint && AllowTypeAnnotation) &&
"type-constraint can't be "
1104 "a type annotation");
1106 "must accompany a concept name");
1114 TemplateArgList TemplateArgs;
1115 bool ArgsInvalid =
false;
1117 ArgsInvalid = ParseTemplateIdAfterTemplateName(
1118 false, LAngleLoc, TemplateArgs, RAngleLoc,
Template);
1134 : Actions.ActOnTemplateIdType(
1138 TemplateArgsPtr, RAngleLoc);
1140 Tok.
setKind(tok::annot_typename);
1141 setTypeAnnotation(Tok,
Type);
1144 else if (TemplateKWLoc.
isValid())
1151 Tok.
setKind(tok::annot_template_id);
1164 TemplateKWLoc, TemplateNameLoc, TemplateII, OpKind,
Template, TNK,
1165 LAngleLoc, RAngleLoc, TemplateArgs, ArgsInvalid, TemplateIds);
1183void Parser::AnnotateTemplateIdTokenAsType(
1186 assert(Tok.
is(tok::annot_template_id) &&
"Requires template-id tokens");
1190 "Only works for type and dependent templates");
1198 : Actions.ActOnTemplateIdType(
1201 TemplateId->TemplateKWLoc, TemplateId->
Template,
1202 TemplateId->Name, TemplateId->TemplateNameLoc,
1203 TemplateId->LAngleLoc, TemplateArgsPtr, TemplateId->RAngleLoc,
1204 false, IsClassName, AllowImplicitTypename);
1206 Tok.
setKind(tok::annot_typename);
1207 setTypeAnnotation(Tok,
Type);
1220 return Tok.
isOneOf(tok::comma, tok::greater, tok::greatergreater,
1221 tok::greatergreatergreater);
1225 if (!Tok.
is(tok::identifier) && !Tok.
is(tok::coloncolon) &&
1226 !Tok.
is(tok::annot_cxxscope) && !Tok.
is(tok::annot_template_id) &&
1227 !Tok.
is(tok::annot_non_type))
1242 ParseOptionalCXXScopeSpecifier(SS,
nullptr,
1248 if (SS.
isSet() && Tok.
is(tok::kw_template)) {
1253 if (Tok.
is(tok::identifier)) {
1270 Name.StartLocation);
1272 }
else if (Tok.
is(tok::identifier) || Tok.
is(tok::annot_template_id) ||
1273 Tok.
is(tok::annot_non_type)) {
1277 if (Tok.
is(tok::annot_non_type)) {
1278 NamedDecl *ND = getNonTypeAnnotation(Tok);
1279 if (!isa<VarTemplateDecl>(ND))
1282 ConsumeAnnotationToken();
1283 }
else if (Tok.
is(tok::annot_template_id)) {
1288 ConsumeAnnotationToken();
1297 bool MemberOfUnknownSpecialization;
1302 false,
Template, MemberOfUnknownSpecialization);
1345 TentativeParsingAction TPA(*
this);
1348 ParseTemplateTemplateArgument();
1361 ExprArg = ParseBraceInitializer();
1373bool Parser::ParseTemplateArgumentList(TemplateArgList &TemplateArgs,
1379 auto RunSignatureHelp = [&] {
1382 CalledSignatureHelp =
true;
1401 TemplateArgs.push_back(Arg);
1417 ParsedTemplateInfo TemplateInfo(ExternLoc, TemplateLoc);
1418 return ParseDeclarationAfterTemplate(
1419 Context, TemplateInfo, ParsingTemplateParams, DeclEnd, AccessAttrs, AS);
1422SourceRange Parser::ParsedTemplateInfo::getSourceRange()
const {
1425 TemplateParams->size());
1428 if (ExternLoc.isValid())
1429 R.setBegin(ExternLoc);
1434 ((
Parser *)
P)->ParseLateTemplatedFuncDef(LPT);
1442 DestroyTemplateIdAnnotationsRAIIObj CleanupRAII(*
this);
1447 TemplateParameterDepthRAII CurTemplateDepthTracker(TemplateParameterDepth);
1453 MultiParseScope Scopes(*
this);
1458 DC = DC->getLexicalParent())
1459 DeclContextsToReenter.push_back(DC);
1462 for (
DeclContext *DC : reverse(DeclContextsToReenter)) {
1463 CurTemplateDepthTracker.addDepth(
1476 assert(!LPT.
Toks.empty() &&
"Empty body!");
1480 LPT.
Toks.push_back(Tok);
1481 PP.EnterTokenStream(LPT.
Toks,
true,
true);
1485 assert(Tok.
isOneOf(tok::l_brace, tok::colon, tok::kw_try) &&
1486 "Inline method not starting with '{', ':' or 'try'");
1498 if (Tok.
is(tok::kw_try)) {
1499 ParseFunctionTryBlock(LPT.
D, FnScope);
1501 if (Tok.
is(tok::colon))
1502 ParseConstructorInitializer(LPT.
D);
1506 if (Tok.
is(tok::l_brace)) {
1507 assert((!isa<FunctionTemplateDecl>(LPT.
D) ||
1508 cast<FunctionTemplateDecl>(LPT.
D)
1509 ->getTemplateParameters()
1510 ->getDepth() == TemplateParameterDepth - 1) &&
1511 "TemplateParameterDepth should be greater than the depth of "
1512 "current template being instantiated!");
1513 ParseFunctionStatementBody(LPT.
D, FnScope);
1520void Parser::LexTemplateFunctionForLateParsing(
CachedTokens &Toks) {
1522 if (!ConsumeAndStoreFunctionPrologue(Toks)) {
1524 ConsumeAndStoreUntil(tok::r_brace, Toks,
false);
1528 if (kind == tok::kw_try) {
1529 while (Tok.
is(tok::kw_catch)) {
1530 ConsumeAndStoreUntil(tok::l_brace, Toks,
false);
1531 ConsumeAndStoreUntil(tok::r_brace, Toks,
false);
1537 TentativeParsingAction TPA(*
this);
1539 if (
SkipUntil(tok::greater, tok::greatergreater, tok::greatergreatergreater,
1544 ParseGreaterThanInTemplateList(
Less,
Greater,
true,
false);
1556void Parser::checkPotentialAngleBracket(
ExprResult &PotentialTemplateName) {
1557 assert(Tok.
is(tok::less) &&
"not at a potential angle bracket");
1573 ParseGreaterThanInTemplateList(
Less,
Greater,
true,
false);
1585 TentativeParsingAction TPA(*
this);
1587 if (isTypeIdUnambiguously() &&
1588 diagnoseUnknownTemplateId(PotentialTemplateName,
Less)) {
1599 AngleBracketTracker::Priority
Priority =
1601 : AngleBracketTracker::PotentialTypo) |
1603 : AngleBracketTracker::NoSpaceBeforeLess);
1604 AngleBrackets.add(*
this, PotentialTemplateName.
get(), Tok.
getLocation(),
1608bool Parser::checkPotentialAngleBracketDelimiter(
1609 const AngleBracketTracker::Loc &LAngle,
const Token &OpToken) {
1613 if (OpToken.
is(tok::comma) && isTypeIdUnambiguously() &&
1614 diagnoseUnknownTemplateId(LAngle.TemplateName, LAngle.LessLoc)) {
1615 AngleBrackets.clear(*
this);
1622 if (OpToken.
is(tok::greater) && Tok.
is(tok::l_paren) &&
1625 getCurScope(), LAngle.TemplateName, LAngle.LessLoc,
1627 AngleBrackets.clear(*
this);
1633 if (OpToken.
is(tok::greater) ||
1635 OpToken.
isOneOf(tok::greatergreater, tok::greatergreatergreater)))
1636 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.
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.
Declaration of a C++20 concept.
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.
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.
IdentifierInfo * getIdentifier() const
Get the identifier that names this declaration, if there is one.
Wrapper for void* pointer.
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.
DiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID)
SourceLocation getEndOfPreviousToken() const
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.
ExprResult ParseConstantExpressionInExprEvalContext(TypoCorrectionTypeBehavior CorrectionBehavior=TypoCorrectionTypeBehavior::AllowNonTypes)
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.
const Token & GetLookAheadToken(unsigned N)
GetLookAheadToken - This peeks ahead N tokens and returns that token without consuming any tokens.
bool TryConsumeToken(tok::TokenKind Expected)
Scope * getCurScope() const
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 ...
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 a possible template scope, creating as many template parameter scopes as necessary.
RAII object used to inform the actions that we're currently parsing a declaration.
A class for parsing a DeclSpec.
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.
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.
QualType ProduceTemplateArgumentSignatureHelp(TemplateTy, ArrayRef< ParsedTemplateArgument >, SourceLocation LAngleLoc)
ConceptDecl * ActOnStartConceptDefinition(Scope *S, MultiTemplateParamsArg TemplateParameterLists, const IdentifierInfo *Name, SourceLocation NameLoc)
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.
ExprResult ActOnConstantExpression(ExprResult Res)
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...
bool ActOnTypeConstraint(const CXXScopeSpec &SS, TemplateIdAnnotation *TypeConstraint, TemplateTypeParmDecl *ConstrainedParameter, SourceLocation EllipsisLoc)
ConceptDecl * ActOnFinishConceptDefinition(Scope *S, ConceptDecl *C, Expr *ConstraintExpr, const ParsedAttributesView &Attrs)
Decl * ActOnFinishFunctionBody(Decl *Decl, Stmt *Body, bool IsInstantiation=false, bool RetainFunctionScopeInfo=false)
Performs semantic analysis at the end of a function body.
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)
DeclGroupPtrTy ConvertDeclToDeclGroup(Decl *Ptr, Decl *OwnedType=nullptr)
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.
NamedDecl * ActOnTemplateTemplateParameter(Scope *S, SourceLocation TmpLoc, TemplateNameKind Kind, bool TypenameKeyword, 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....
SemaCodeCompletion & CodeCompletion()
Decl * ActOnStartOfFunctionDef(Scope *S, Declarator &D, MultiTemplateParamsArg TemplateParamLists, SkipBodyInfo *SkipBody=nullptr, FnBodyKind BodyKind=FnBodyKind::Other)
bool mightBeIntendedToBeTemplateName(ExprResult E, bool &Dependent)
Determine whether it's plausible that E was intended to be a template-name.
ParsedTemplateArgument ActOnTemplateTemplateArgument(const ParsedTemplateArgument &Arg)
Invoked when parsing a template argument.
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)
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)
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.
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 isOneOf(Ts... Ks) const
bool hasLeadingSpace() const
Return true if this token has whitespace before it.
void setLocation(SourceLocation L)
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.
The JSON file list parser is used to communicate input to InstallAPI.
OverloadedOperatorKind
Enumeration specifying the different kinds of C++ overloaded operators.
@ OO_None
Not an overloaded operator.
@ TemplateTemplateArgument
@ IK_Identifier
An identifier.
AccessSpecifier
A C++ access specifier (public, private, protected), plus the special value "none" which means differ...
@ Result
The result type of a method or function.
@ Template
We are parsing a template declaration.
@ ExplicitInstantiation
We are parsing an explicit instantiation.
@ NonTemplate
We are not parsing a template at all.
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_Var_template
The name refers to a variable template whose specialization produces a variable.
@ 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.
const FunctionProtoType * T
@ None
The alignment was not explicit in code.
ElaboratedTypeKeyword
The elaboration keyword that precedes a qualified type name or introduces an elaborated-type-specifie...
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.
const IdentifierInfo * Name
FIXME: Temporarily stores the name of a specialization.
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.
SourceLocation LAngleLoc
The location of the '<' before the template argument list.
bool mightBeType() const
Determine whether this might be a type template.
static TemplateIdAnnotation * Create(SourceLocation TemplateKWLoc, SourceLocation TemplateNameLoc, const 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.