21 #include "llvm/Support/TimeProfiler.h" 22 using namespace clang;
26 Decl *Parser::ParseDeclarationStartingWithTemplate(
33 DeclEnd, AccessAttrs, AS);
35 return ParseTemplateDeclarationOrSpecialization(Context, DeclEnd, AccessAttrs,
63 Decl *Parser::ParseTemplateDeclarationOrSpecialization(
66 assert(Tok.
isOneOf(tok::kw_export, tok::kw_template) &&
67 "Token does not start a template declaration.");
98 bool isSpecialization =
true;
99 bool LastParamListWasEmpty =
false;
101 TemplateParameterDepthRAII CurTemplateDepthTracker(TemplateParameterDepth);
118 if (ParseTemplateParameters(CurTemplateDepthTracker.getDepth(),
119 TemplateParams, LAngleLoc, RAngleLoc)) {
126 ExprResult OptionalRequiresClauseConstraintER;
127 if (!TemplateParams.empty()) {
128 isSpecialization =
false;
129 ++CurTemplateDepthTracker;
132 OptionalRequiresClauseConstraintER =
134 if (!OptionalRequiresClauseConstraintER.
isUsable()) {
142 LastParamListWasEmpty =
true;
146 CurTemplateDepthTracker.getDepth(), ExportLoc, TemplateLoc, LAngleLoc,
147 TemplateParams, RAngleLoc, OptionalRequiresClauseConstraintER.
get()));
148 }
while (Tok.
isOneOf(tok::kw_export, tok::kw_template));
151 ParseScopeFlags TemplateScopeFlags(
this, NewFlags, isSpecialization);
154 if (Tok.
is(tok::kw_concept))
155 return ParseConceptDefinition(
156 ParsedTemplateInfo(&ParamLists, isSpecialization,
157 LastParamListWasEmpty),
160 return ParseSingleDeclarationAfterTemplate(
162 ParsedTemplateInfo(&ParamLists, isSpecialization, LastParamListWasEmpty),
163 ParsingTemplateParams, DeclEnd, AccessAttrs, AS);
176 Decl *Parser::ParseSingleDeclarationAfterTemplate(
180 assert(TemplateInfo.Kind != ParsedTemplateInfo::NonTemplate &&
181 "Template information required");
183 if (Tok.
is(tok::kw_static_assert)) {
186 << TemplateInfo.getSourceRange();
188 return ParseStaticAssertDeclaration(DeclEnd);
193 ParseCXXClassMemberDeclaration(AS, AccessAttrs, TemplateInfo,
198 ParsedAttributesWithRange prefixAttrs(AttrFactory);
199 MaybeParseCXX11Attributes(prefixAttrs);
201 if (Tok.
is(tok::kw_using)) {
202 auto usingDeclPtr = ParseUsingDirectiveOrDeclaration(Context, TemplateInfo, DeclEnd,
204 if (!usingDeclPtr || !usingDeclPtr.get().isSingleDecl())
206 return usingDeclPtr.get().getSingleDecl();
213 ParseDeclarationSpecifiers(DS, TemplateInfo, AS,
214 getDeclSpecContextFromDeclaratorContext(Context));
216 if (Tok.
is(tok::semi)) {
217 ProhibitAttributes(prefixAttrs);
222 TemplateInfo.TemplateParams ? *TemplateInfo.TemplateParams
224 TemplateInfo.Kind == ParsedTemplateInfo::ExplicitInstantiation,
226 assert(!AnonRecord &&
227 "Anonymous unions/structs should not be valid with template");
233 if (TemplateInfo.Kind == ParsedTemplateInfo::ExplicitInstantiation)
234 ProhibitAttributes(prefixAttrs);
236 DS.takeAttributesFrom(prefixAttrs);
240 ParseDeclarator(DeclaratorInfo);
242 if (!DeclaratorInfo.hasName()) {
245 if (Tok.
is(tok::semi))
250 llvm::TimeTraceScope TimeScope(
"ParseTemplate", [&]() {
251 return DeclaratorInfo.getIdentifier() !=
nullptr 252 ? DeclaratorInfo.getIdentifier()->getName()
256 LateParsedAttrList LateParsedAttrs(
true);
257 if (DeclaratorInfo.isFunctionDeclarator())
258 MaybeParseGNUAttributes(DeclaratorInfo, &LateParsedAttrs);
260 if (DeclaratorInfo.isFunctionDeclarator() &&
261 isStartOfFunctionDefinition(DeclaratorInfo)) {
267 Diag(Tok, diag::err_function_definition_not_allowed);
276 Diag(DS.getStorageClassSpecLoc(), diag::err_function_declared_typedef)
278 DS.ClearStorageClassSpecs();
281 if (TemplateInfo.Kind == ParsedTemplateInfo::ExplicitInstantiation) {
282 if (DeclaratorInfo.getName().getKind() !=
286 Diag(Tok, diag::err_template_defn_explicit_instantiation) << 0;
287 return ParseFunctionDefinition(DeclaratorInfo, ParsedTemplateInfo(),
292 Diag(DeclaratorInfo.getIdentifierLoc(),
293 diag::err_explicit_instantiation_with_definition)
301 LAngleLoc,
nullptr));
303 return ParseFunctionDefinition(
304 DeclaratorInfo, ParsedTemplateInfo(&FakedParamLists,
310 return ParseFunctionDefinition(DeclaratorInfo, TemplateInfo,
315 Decl *ThisDecl = ParseDeclarationAfterDeclarator(DeclaratorInfo,
318 if (Tok.
is(tok::comma)) {
319 Diag(Tok, diag::err_multiple_template_declarators)
320 << (int)TemplateInfo.Kind;
326 ExpectAndConsumeSemi(diag::err_expected_semi_declaration);
327 if (LateParsedAttrs.size() > 0)
328 ParseLexedAttributeList(LateParsedAttrs, ThisDecl,
true,
false);
329 DeclaratorInfo.complete(ThisDecl);
340 Parser::ParseConceptDefinition(
const ParsedTemplateInfo &TemplateInfo,
342 assert(TemplateInfo.Kind != ParsedTemplateInfo::NonTemplate &&
343 "Template information required");
344 assert(Tok.
is(tok::kw_concept) &&
345 "ParseConceptDefinition must be called when at a 'concept' keyword");
354 DiagnoseAndSkipCXX11Attributes();
357 if (ParseOptionalCXXScopeSpecifier(SS,
ParsedType(),
359 false,
nullptr,
true) ||
367 diag::err_concept_definition_not_identifier);
381 Diag(Result.
getBeginLoc(), diag::err_concept_definition_not_identifier);
389 DiagnoseAndSkipCXX11Attributes();
405 ExpectAndConsumeSemi(diag::err_expected_semi_declaration);
406 Expr *ConstraintExpr = ConstraintExprResult.
get();
408 *TemplateInfo.TemplateParams,
409 Id, IdLoc, ConstraintExpr);
421 bool Parser::ParseTemplateParameters(
432 if (!Tok.
is(tok::greater) && !Tok.
is(tok::greatergreater))
433 Failed = ParseTemplateParameterList(Depth, TemplateParams);
435 if (Tok.
is(tok::greatergreater)) {
460 Parser::ParseTemplateParameterList(
const unsigned Depth,
465 = ParseTemplateParameter(Depth, TemplateParams.size())) {
466 TemplateParams.push_back(TmpParam);
470 SkipUntil(tok::comma, tok::greater, tok::greatergreater,
475 if (Tok.
is(tok::comma)) {
477 }
else if (Tok.
isOneOf(tok::greater, tok::greatergreater)) {
485 SkipUntil(tok::comma, tok::greater, tok::greatergreater,
495 bool Parser::isStartOfTemplateTypeParameter() {
496 if (Tok.
is(tok::kw_class)) {
503 case tok::greatergreater:
507 case tok::identifier:
516 switch (GetLookAheadToken(2).
getKind()) {
520 case tok::greatergreater:
530 if (Tok.
isNot(tok::kw_typename) && Tok.
isNot(tok::kw_typedef))
542 if (Next.
getKind() == tok::identifier)
543 Next = GetLookAheadToken(2);
549 case tok::greatergreater:
553 case tok::kw_typename:
554 case tok::kw_typedef:
580 NamedDecl *Parser::ParseTemplateParameter(
unsigned Depth,
unsigned Position) {
581 if (isStartOfTemplateTypeParameter()) {
583 if (Tok.
is(tok::kw_typedef)) {
594 return ParseTypeParameter(Depth, Position);
597 if (Tok.
is(tok::kw_template))
598 return ParseTemplateTemplateParameter(Depth, Position);
603 return ParseNonTypeTemplateParameter(Depth, Position);
615 NamedDecl *Parser::ParseTypeParameter(
unsigned Depth,
unsigned Position) {
616 assert(Tok.
isOneOf(tok::kw_class, tok::kw_typename) &&
617 "A type-parameter starts with 'class' or 'typename'");
620 bool TypenameKeyword = Tok.
is(tok::kw_typename);
628 ? diag::warn_cxx98_compat_variadic_templates
629 : diag::ext_variadic_templates);
635 if (Tok.
is(tok::identifier)) {
638 }
else if (Tok.
isOneOf(tok::equal, tok::comma, tok::greater,
639 tok::greatergreater)) {
648 bool AlreadyHasEllipsis = EllipsisLoc.
isValid();
650 DiagnoseMisplacedEllipsis(EllipsisLoc, NameLoc, AlreadyHasEllipsis,
true);
662 KeyLoc, ParamName, NameLoc, Depth, Position,
663 EqualLoc, DefaultArg);
678 Parser::ParseTemplateTemplateParameter(
unsigned Depth,
unsigned Position) {
679 assert(Tok.
is(tok::kw_template) &&
"Expected 'template' keyword");
687 if (ParseTemplateParameters(Depth + 1, TemplateParams, LAngleLoc,
699 bool Replace = Tok.
isOneOf(tok::kw_typename, tok::kw_struct);
701 if (Tok.
is(tok::kw_typename)) {
704 ? diag::warn_cxx14_compat_template_template_param_typename
705 : diag::ext_template_template_param_typename)
709 }
else if (Next.
isOneOf(tok::identifier, tok::comma, tok::greater,
710 tok::greatergreater, tok::ellipsis)) {
726 ? diag::warn_cxx98_compat_variadic_templates
727 : diag::ext_variadic_templates);
732 if (Tok.
is(tok::identifier)) {
735 }
else if (Tok.
isOneOf(tok::equal, tok::comma, tok::greater,
736 tok::greatergreater)) {
745 bool AlreadyHasEllipsis = EllipsisLoc.
isValid();
747 DiagnoseMisplacedEllipsis(EllipsisLoc, NameLoc, AlreadyHasEllipsis,
true);
751 TemplateLoc, LAngleLoc,
761 DefaultArg = ParseTemplateTemplateArgument();
764 diag::err_default_template_template_parameter_not_template);
765 SkipUntil(tok::comma, tok::greater, tok::greatergreater,
771 ParamList, EllipsisLoc,
772 ParamName, NameLoc, Depth,
773 Position, EqualLoc, DefaultArg);
783 Parser::ParseNonTypeTemplateParameter(
unsigned Depth,
unsigned Position) {
788 ParseDeclarationSpecifiers(DS, ParsedTemplateInfo(),
AS_none,
789 DeclSpecContext::DSC_template_param);
793 ParseDeclarator(ParamDecl);
802 DiagnoseMisplacedEllipsisInDeclarator(EllipsisLoc, ParamDecl);
826 Depth, Position, EqualLoc,
830 void Parser::DiagnoseMisplacedEllipsis(
SourceLocation EllipsisLoc,
832 bool AlreadyHasEllipsis,
833 bool IdentifierHasName) {
835 if (!AlreadyHasEllipsis)
837 Diag(EllipsisLoc, diag::err_misplaced_ellipsis_in_declaration)
839 << !IdentifierHasName;
842 void Parser::DiagnoseMisplacedEllipsisInDeclarator(
SourceLocation EllipsisLoc,
846 if (!AlreadyHasEllipsis)
849 AlreadyHasEllipsis, D.
hasName());
867 bool Parser::ParseGreaterThanInTemplateList(
SourceLocation &RAngleLoc,
868 bool ConsumeLastToken,
869 bool ObjCGenericList) {
872 const char *ReplacementStr =
"> >";
873 bool MergeWithNextToken =
false;
884 if (ConsumeLastToken)
888 case tok::greatergreater:
889 RemainingToken = tok::greater;
892 case tok::greatergreatergreater:
893 RemainingToken = tok::greatergreater;
896 case tok::greaterequal:
897 RemainingToken = tok::equal;
898 ReplacementStr =
"> =";
905 RemainingToken = tok::equalequal;
906 MergeWithNextToken =
true;
910 case tok::greatergreaterequal:
911 RemainingToken = tok::greaterequal;
930 bool PreventMergeWithNextToken =
931 (RemainingToken == tok::greater ||
932 RemainingToken == tok::greatergreater) &&
933 (Next.
isOneOf(tok::greater, tok::greatergreater,
934 tok::greatergreatergreater, tok::equal, tok::greaterequal,
935 tok::greatergreaterequal, tok::equalequal)) &&
936 areTokensAdjacent(Tok, Next);
939 if (!ObjCGenericList) {
954 if (PreventMergeWithNextToken)
957 unsigned DiagId = diag::err_two_right_angle_brackets_need_space;
959 (Tok.
is(tok::greatergreater) || Tok.
is(tok::greatergreatergreater)))
960 DiagId = diag::warn_cxx98_compat_two_right_angle_brackets;
961 else if (Tok.
is(tok::greaterequal))
962 DiagId = diag::err_right_angle_bracket_equal_needs_space;
963 Diag(TokLoc, DiagId) << Hint1 << Hint2;
974 RAngleLoc = PP.
SplitToken(TokLoc, GreaterLength);
985 if (MergeWithNextToken) {
991 Tok.
setLength(OldLength - GreaterLength);
996 if (PreventMergeWithNextToken)
1001 if (CachingTokens) {
1003 if (MergeWithNextToken)
1006 if (ConsumeLastToken)
1012 if (ConsumeLastToken) {
1013 PrevTokLocation = RAngleLoc;
1015 PrevTokLocation = TokBeforeGreaterLoc;
1036 Parser::ParseTemplateIdAfterTemplateName(
bool ConsumeLastToken,
1038 TemplateArgList &TemplateArgs,
1040 assert(Tok.
is(tok::less) &&
"Must have already parsed the template-name");
1049 if (!Tok.
isOneOf(tok::greater, tok::greatergreater,
1050 tok::greatergreatergreater, tok::greaterequal,
1051 tok::greatergreaterequal))
1052 Invalid = ParseTemplateArgumentList(TemplateArgs);
1056 if (ConsumeLastToken)
1064 return ParseGreaterThanInTemplateList(RAngleLoc, ConsumeLastToken,
1109 bool AllowTypeAnnotation) {
1111 assert(Template && Tok.
is(tok::less) &&
1112 "Parser isn't at the beginning of a template-id");
1119 TemplateArgList TemplateArgs;
1120 bool Invalid = ParseTemplateIdAfterTemplateName(
false, LAngleLoc,
1139 TemplateNameLoc, LAngleLoc, TemplateArgsPtr, RAngleLoc);
1150 Tok.
setKind(tok::annot_typename);
1151 setTypeAnnotation(Tok, Type.
get());
1154 else if (TemplateKWLoc.
isValid())
1161 Tok.
setKind(tok::annot_template_id);
1174 SS, TemplateKWLoc, TemplateNameLoc, TemplateII, OpKind, Template, TNK,
1175 LAngleLoc, RAngleLoc, TemplateArgs, TemplateIds);
1204 void Parser::AnnotateTemplateIdTokenAsType(
bool IsClassName) {
1205 assert(Tok.
is(tok::annot_template_id) &&
"Requires template-id tokens");
1211 "Only works for type and dependent templates");
1214 TemplateId->NumArgs);
1219 TemplateId->TemplateKWLoc,
1220 TemplateId->Template,
1222 TemplateId->TemplateNameLoc,
1223 TemplateId->LAngleLoc,
1225 TemplateId->RAngleLoc,
1229 Tok.
setKind(tok::annot_typename);
1230 setTypeAnnotation(Tok, Type.isInvalid() ? nullptr : Type.get());
1231 if (TemplateId->SS.isNotEmpty())
1242 return Tok.
isOneOf(tok::comma, tok::greater, tok::greatergreater);
1247 if (!Tok.
is(tok::identifier) && !Tok.
is(tok::coloncolon) &&
1248 !Tok.
is(tok::annot_cxxscope))
1263 ParseOptionalCXXScopeSpecifier(SS,
nullptr,
1268 if (SS.
isSet() && Tok.
is(tok::kw_template)) {
1273 if (Tok.
is(tok::identifier)) {
1292 }
else if (Tok.
is(tok::identifier)) {
1302 bool MemberOfUnknownSpecialization;
1307 false, Template, MemberOfUnknownSpecialization);
1344 if (isCXXTypeId(TypeIdAsTemplateArgument)) {
1352 TentativeParsingAction TPA(*
this);
1355 = ParseTemplateTemplateArgument();
1356 if (!TemplateTemplateArgument.
isInvalid()) {
1358 return TemplateTemplateArgument;
1372 ExprArg.
get(), Loc);
1382 Parser::ParseTemplateArgumentList(TemplateArgList &TemplateArgs) {
1398 TemplateArgs.push_back(Arg);
1424 return ParseSingleDeclarationAfterTemplate(
1425 Context, ParsedTemplateInfo(ExternLoc, TemplateLoc),
1426 ParsingTemplateParams, DeclEnd, AccessAttrs, AS);
1432 TemplateParams->size());
1436 R.setBegin(ExternLoc);
1441 ((
Parser *)P)->ParseLateTemplatedFuncDef(LPT);
1452 TemplateParameterDepthRAII CurTemplateDepthTracker(TemplateParameterDepth);
1464 struct ContainingDC {
1465 ContainingDC(
DeclContext *DC,
bool ShouldPush) : Pair(DC, ShouldPush) {}
1466 llvm::PointerIntPair<DeclContext *, 1, bool> Pair;
1467 DeclContext *getDC() {
return Pair.getPointer(); }
1468 bool shouldPushDC() {
return Pair.getInt(); }
1472 DeclContext *NextContaining = Actions.getContainingDC(DD);
1474 bool ShouldPush = DD == NextContaining;
1475 DeclContextsToReenter.push_back({DD, ShouldPush});
1477 NextContaining = Actions.getContainingDC(DD);
1482 for (ContainingDC CDC : reverse(DeclContextsToReenter)) {
1483 TemplateParamScopeStack.push_back(
1485 unsigned NumParamLists = Actions.ActOnReenterTemplateScope(
1487 CurTemplateDepthTracker.addDepth(NumParamLists);
1488 if (CDC.shouldPushDC()) {
1490 Actions.PushDeclContext(Actions.getCurScope(), CDC.getDC());
1494 assert(!LPT.
Toks.empty() &&
"Empty body!");
1498 LPT.
Toks.push_back(Tok);
1499 PP.EnterTokenStream(LPT.
Toks,
true,
true);
1503 assert(Tok.
isOneOf(tok::l_brace, tok::colon, tok::kw_try) &&
1504 "Inline method not starting with '{', ':' or 'try'");
1513 Actions.getContainingDC(FunD));
1515 Actions.ActOnStartOfFunctionDef(
getCurScope(), FunD);
1517 if (Tok.
is(tok::kw_try)) {
1518 ParseFunctionTryBlock(LPT.
D, FnScope);
1520 if (Tok.
is(tok::colon))
1521 ParseConstructorInitializer(LPT.
D);
1523 Actions.ActOnDefaultCtorInitializers(LPT.
D);
1525 if (Tok.
is(tok::l_brace)) {
1526 assert((!isa<FunctionTemplateDecl>(LPT.
D) ||
1527 cast<FunctionTemplateDecl>(LPT.
D)
1528 ->getTemplateParameters()
1529 ->getDepth() == TemplateParameterDepth - 1) &&
1530 "TemplateParameterDepth should be greater than the depth of " 1531 "current template being instantiated!");
1532 ParseFunctionStatementBody(LPT.
D, FnScope);
1533 Actions.UnmarkAsLateParsedTemplate(FunD);
1535 Actions.ActOnFinishFunctionBody(LPT.
D,
nullptr);
1541 TemplateParamScopeStack.rbegin();
1542 for (; I != TemplateParamScopeStack.rend(); ++I)
1547 void Parser::LexTemplateFunctionForLateParsing(
CachedTokens &Toks) {
1549 if (!ConsumeAndStoreFunctionPrologue(Toks)) {
1551 ConsumeAndStoreUntil(tok::r_brace, Toks,
false);
1555 if (kind == tok::kw_try) {
1556 while (Tok.
is(tok::kw_catch)) {
1557 ConsumeAndStoreUntil(tok::l_brace, Toks,
false);
1558 ConsumeAndStoreUntil(tok::r_brace, Toks,
false);
1568 TentativeParsingAction TPA(*
this);
1570 if (
SkipUntil(tok::greater, tok::greatergreater, tok::greatergreatergreater,
1575 ParseGreaterThanInTemplateList(Greater,
true,
false);
1576 Actions.diagnoseExprIntendedAsTemplateName(
getCurScope(), LHS,
1587 void Parser::checkPotentialAngleBracket(
ExprResult &PotentialTemplateName) {
1588 assert(Tok.
is(tok::less) &&
"not at a potential angle bracket");
1591 if (!Actions.mightBeIntendedToBeTemplateName(PotentialTemplateName,
1592 DependentTemplateName))
1604 ParseGreaterThanInTemplateList(Greater,
true,
false);
1605 Actions.diagnoseExprIntendedAsTemplateName(
1606 getCurScope(), PotentialTemplateName, Less, Greater);
1616 TentativeParsingAction TPA(*
this);
1618 if (isTypeIdUnambiguously() &&
1619 diagnoseUnknownTemplateId(PotentialTemplateName, Less)) {
1630 AngleBracketTracker::Priority Priority =
1631 (DependentTemplateName ? AngleBracketTracker::DependentName
1632 : AngleBracketTracker::PotentialTypo) |
1633 (Tok.hasLeadingSpace() ? AngleBracketTracker::SpaceBeforeLess
1634 : AngleBracketTracker::NoSpaceBeforeLess);
1635 AngleBrackets.add(*
this, PotentialTemplateName.
get(), Tok.getLocation(),
1639 bool Parser::checkPotentialAngleBracketDelimiter(
1640 const AngleBracketTracker::Loc &LAngle,
const Token &OpToken) {
1644 if (OpToken.
is(tok::comma) && isTypeIdUnambiguously() &&
1645 diagnoseUnknownTemplateId(LAngle.TemplateName, LAngle.LessLoc)) {
1646 AngleBrackets.clear(*
this);
1653 if (OpToken.
is(tok::greater) && Tok.
is(tok::l_paren) &&
1655 Actions.diagnoseExprIntendedAsTemplateName(
1656 getCurScope(), LAngle.TemplateName, LAngle.LessLoc,
1658 AngleBrackets.clear(*
this);
1664 if (OpToken.
is(tok::greater) ||
1666 OpToken.
isOneOf(tok::greatergreater, tok::greatergreatergreater)))
1667 AngleBrackets.clear(*
this);
Defines the clang::ASTContext interface.
void ReplacePreviousCachedToken(ArrayRef< Token > NewToks)
Replace token in CachedLexPos - 1 in CachedTokens by the tokens in NewToks.
Represents a function declaration or definition.
SourceLocation getLocWithOffset(int Offset) const
Return a source location with the specified offset from this SourceLocation.
SourceRange getSourceRange() const LLVM_READONLY
Return the source range that covers this unqualified-id.
SourceLocation StartLocation
The location of the first token that describes this unqualified-id, which will be the location of the...
IdentifierInfo * Identifier
When Kind == IK_Identifier, the parsed identifier, or when Kind == IK_UserLiteralId, the identifier suffix.
TemplateNameKind isTemplateName(Scope *S, CXXScopeSpec &SS, bool hasTemplateKeyword, const UnqualifiedId &Name, ParsedType ObjectType, bool EnteringContext, TemplateTy &Template, bool &MemberOfUnknownSpecialization)
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)) {...
The name refers to a dependent template name:
Decl - This represents one declaration (or definition), e.g.
RAII object used to inform the actions that we're currently parsing a declaration.
Defines the C++ template declaration subclasses.
The base class of the type hierarchy.
This indicates that the scope corresponds to a function, which means that labels are set here...
AccessSpecifier
A C++ access specifier (public, private, protected), plus the special value "none" which means differ...
Parser - This implements a parser for the C family of languages.
static TemplateIdAnnotation * Create(CXXScopeSpec SS, SourceLocation TemplateKWLoc, SourceLocation TemplateNameLoc, IdentifierInfo *Name, OverloadedOperatorKind OperatorKind, ParsedTemplateTy OpaqueTemplateName, TemplateNameKind TemplateKind, SourceLocation LAngleLoc, SourceLocation RAngleLoc, ArrayRef< ParsedTemplateArgument > TemplateArgs, SmallVectorImpl< TemplateIdAnnotation *> &CleanupList)
Creates a new TemplateIdAnnotation with NumArgs arguments and appends it to List. ...
RAII object that enters a new expression evaluation context.
Information about one declarator, including the parsed type information and the identifier.
Stores a list of template parameters for a TemplateDecl and its derived classes.
friend class ObjCDeclContextSwitch
ColonProtectionRAIIObject - This sets the Parser::ColonIsSacred bool and restores it when destroyed...
tok::TokenKind getKind() const
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 ...
Information about a template-id annotation token.
Represents a struct/union/class.
const Token & NextToken()
NextToken - This peeks ahead one token and returns it without consuming it.
SourceLocation getLocForEndOfToken(SourceLocation Loc, unsigned Offset=0)
Computes the source location just past the end of the token at this source location.
bool TryConsumeToken(tok::TokenKind Expected)
One of these records is kept for each identifier that is lexed.
Lookup for the name failed, but we're assuming it was a template name anyway.
Represents a dependent template name that cannot be resolved prior to template instantiation.
OverloadedOperatorKind Operator
The kind of overloaded operator.
struct OFI OperatorFunctionId
When Kind == IK_OperatorFunctionId, the overloaded operator that we parsed.
Token - This structure provides full information about a lexed token.
A non-type template parameter, stored as an expression.
void setKind(tok::TokenKind K)
OpaquePtr< QualType > ParsedType
An opaque type for threading parsed type information through the parser.
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.g.
Represents a C++ unqualified-id that has been parsed.
ExprResult CorrectDelayedTyposInExpr(Expr *E, VarDecl *InitDecl=nullptr, 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...
Scope - A scope is a transient data structure that is used while parsing the program.
bool IsPreviousCachedToken(const Token &Tok) const
Whether Tok is the most recent token (CachedLexPos - 1) in CachedTokens.
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...
Represents a C++ nested-name-specifier or a global scope specifier.
SourceLocation ConsumeAnyToken(bool ConsumeCodeCompletionTok=false)
ConsumeAnyToken - Dispatch to the right Consume* method based on the current token type...
The current context is "potentially evaluated" in C++11 terms, but the expression is evaluated at com...
unsigned getFlags() const
getFlags - Return the flags for this scope.
SourceLocation getBeginLoc() const LLVM_READONLY
A class for parsing a declarator.
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...
DeclContext * getLexicalParent()
getLexicalParent - Returns the containing lexical DeclContext.
void setAnnotationValue(void *val)
This represents one expression.
Decl * ParsedFreeStandingDeclSpec(Scope *S, AccessSpecifier AS, DeclSpec &DS, RecordDecl *&AnonRecord)
ParsedFreeStandingDeclSpec - This method is invoked when a declspec with no declarator (e...
Represents a character-granular source range.
void AnnotateCachedTokens(const Token &Tok)
We notify the Preprocessor that if it is caching tokens (because backtrack is enabled) it should repl...
This file defines the classes used to store parsed information about declaration-specifiers and decla...
void SkipMalformedDecl()
SkipMalformedDecl - Read tokens until we get to some likely good stopping point for skipping past a s...
bool ParseUnqualifiedId(CXXScopeSpec &SS, bool EnteringContext, bool AllowDestructorName, bool AllowConstructorName, bool AllowDeductionGuide, ParsedType ObjectType, SourceLocation *TemplateKWLoc, UnqualifiedId &Result)
Parse a C++ unqualified-id (or a C identifier), which describes the name of an entity.
OpaquePtr< TemplateName > TemplateTy
SourceLocation getLocation() const
Return a source location identifier for the specified offset in the current file. ...
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...
SourceLocation getBeginLoc() const
static bool isEndOfTemplateArgument(Token Tok)
Determine whether the given token can end a template argument.
Represents a C++ template name within the type system.
This is a compound statement scope.
UnqualifiedIdKind getKind() const
Determine what kind of name we have.
TemplateNameKind
Specifies the kind of template name that an identifier refers to.
void setEllipsisLoc(SourceLocation EL)
The result type of a method or function.
ParsedTemplateArgument ActOnPackExpansion(const ParsedTemplateArgument &Arg, SourceLocation EllipsisLoc)
Invoked when parsing a template argument followed by an ellipsis, which creates a pack expansion...
RAII object that makes '>' behave either as an operator or as the closing angle bracket for a templat...
const LangOptions & getLangOpts() const
static CharSourceRange getCharRange(SourceRange R)
SourceManager & getSourceManager() const
A class for parsing a DeclSpec.
Stop skipping at semicolon.
ActionResult - This structure is used while parsing/acting on expressions, stmts, etc...
Represents the parsed form of a C++ template argument.
FunctionDecl * getAsFunction() LLVM_READONLY
Returns the function itself, or the templated function if this is a function template.
bool hasName() const
hasName - Whether this declarator has a name, which might be an identifier (accessible via getIdentif...
Encodes a location in the source.
void setLength(unsigned Len)
IdentifierInfo * getIdentifierInfo() const
void setAnnotationEndLoc(SourceLocation L)
NamedDecl * ActOnNonTypeTemplateParameter(Scope *S, Declarator &D, unsigned Depth, unsigned Position, SourceLocation EqualLoc, Expr *DefaultArg)
TemplateNameKind ActOnDependentTemplateName(Scope *S, CXXScopeSpec &SS, SourceLocation TemplateKWLoc, const UnqualifiedId &Name, ParsedType ObjectType, bool EnteringContext, TemplateTy &Template, bool AllowInjectedClassName=false)
Form a dependent template name.
TokenKind
Provides a simple uniform namespace for tokens from all C languages.
void EnterToken(const Token &Tok, bool IsReinject)
Enters a token in the token stream to be lexed next.
Scope * getCurScope() const
ExprResult ParseConstantExpressionInExprEvalContext(TypeCastState isTypeCast=NotTypeCast)
bool isInvalid() const
An error occurred during parsing of the scope specifier.
TypeResult ActOnTemplateIdType(Scope *S, CXXScopeSpec &SS, SourceLocation TemplateKWLoc, TemplateTy Template, IdentifierInfo *TemplateII, SourceLocation TemplateIILoc, SourceLocation LAngleLoc, ASTTemplateArgsPtr TemplateArgs, SourceLocation RAngleLoc, bool IsCtorOrDtorName=false, bool IsClassName=false)
bool isNot(tok::TokenKind K) const
SourceLocation SplitToken(SourceLocation TokLoc, unsigned Length)
Split the first Length characters out of the token starting at TokLoc and return a location pointing ...
Dataflow Directional Tag Classes.
bool isValid() const
Return true if this is a valid SourceLocation object.
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
OverloadedOperatorKind
Enumeration specifying the different kinds of C++ overloaded operators.
static FixItHint CreateRemoval(CharSourceRange RemoveRange)
Create a code modification hint that removes the given source range.
This is a scope that corresponds to the template parameters of a C++ template.
ExprResult ParseConstraintExpression()
Parse a constraint-expression.
bool isInvalid() const
Determine whether the given template argument is invalid.
bool isOneOf(tok::TokenKind K1, tok::TokenKind K2) const
The name refers to a template whose specialization produces a type.
static const TST TST_unspecified
unsigned getLength() const
NamedDecl * ActOnTypeParameter(Scope *S, bool Typename, SourceLocation EllipsisLoc, SourceLocation KeyLoc, IdentifierInfo *ParamName, SourceLocation ParamNameLoc, unsigned Depth, unsigned Position, SourceLocation EqualLoc, ParsedType DefaultArg)
ActOnTypeParameter - Called when a C++ template type parameter (e.g., "typename T") has been parsed...
Not an overloaded operator.
DiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID)
ParsedTemplateArgument ActOnTemplateTypeArgument(TypeResult ParsedType)
Convert a parsed type into a parsed template argument.
SourceRange getTemplateParamsRange(TemplateParameterList const *const *Params, unsigned NumParams)
Retrieves the range of the given template parameter lists.
ExprResult ParseAssignmentExpression(TypeCastState isTypeCast=NotTypeCast)
Parse an expr that doesn't include (top-level) commas.
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.
SmallVector< TemplateParameterList *, 4 > TemplateParameterLists
This is a scope that can contain a declaration.
SourceLocation getIdentifierLoc() const
bool isSet() const
Deprecated.
TranslationUnitDecl * getTranslationUnitDecl() const
Captures information about "declaration specifiers".
SourceLocation ConsumeToken()
ConsumeToken - Consume the current 'peek token' and lex the next one.
SourceLocation getEllipsisLoc() const
Decl * D
The template function declaration to be late parsed.
bool isNotEmpty() const
A scope specifier is present, but may be valid or invalid.
unsigned kind
All of the diagnostics that can be emitted by the frontend.
static FixItHint CreateReplacement(CharSourceRange RemoveRange, StringRef Code)
Create a code modification hint that replaces the given source range with the given code string...
A template-id, e.g., f<int>.
Contains a late templated function.
Annotates a diagnostic with some code that should be inserted, removed, or replaced to fix the proble...
void setLocation(SourceLocation L)
A trivial tuple used to represent a source range.
This represents a decl that may have a name.
void setIdentifier(const IdentifierInfo *Id, SourceLocation IdLoc)
Specify that this unqualified-id was parsed as an identifier.
bool isTranslationUnit() const
Decl * ActOnConceptDefinition(Scope *S, MultiTemplateParamsArg TemplateParameterLists, IdentifierInfo *Name, SourceLocation NameLoc, Expr *ConstraintExpr)
SourceLocation getBegin() const
ParsedAttributes - A collection of parsed attributes.
TypeResult ParseTypeName(SourceRange *Range=nullptr, DeclaratorContext Context=DeclaratorContext::TypeNameContext, AccessSpecifier AS=AS_none, Decl **OwnedType=nullptr, ParsedAttributes *Attrs=nullptr)
ParseTypeName type-name: [C99 6.7.6] specifier-qualifier-list abstract-declarator[opt].
Stop skipping at specified token, but don't skip the token itself.
SourceLocation getEndLoc() const