22 using namespace clang;
26 Decl *Parser::ParseDeclarationStartingWithTemplate(
33 DeclEnd, AccessAttrs, AS);
35 return ParseTemplateDeclarationOrSpecialization(Context, DeclEnd, AccessAttrs,
54 Decl *Parser::ParseTemplateDeclarationOrSpecialization(
57 assert(Tok.
isOneOf(tok::kw_export, tok::kw_template) &&
58 "Token does not start a template declaration.");
89 bool isSpecialization =
true;
90 bool LastParamListWasEmpty =
false;
92 TemplateParameterDepthRAII CurTemplateDepthTracker(TemplateParameterDepth);
109 if (ParseTemplateParameters(CurTemplateDepthTracker.getDepth(),
110 TemplateParams, LAngleLoc, RAngleLoc)) {
117 ExprResult OptionalRequiresClauseConstraintER;
118 if (!TemplateParams.empty()) {
119 isSpecialization =
false;
120 ++CurTemplateDepthTracker;
123 OptionalRequiresClauseConstraintER =
125 if (!OptionalRequiresClauseConstraintER.
isUsable()) {
133 LastParamListWasEmpty =
true;
137 CurTemplateDepthTracker.getDepth(), ExportLoc, TemplateLoc, LAngleLoc,
138 TemplateParams, RAngleLoc, OptionalRequiresClauseConstraintER.
get()));
139 }
while (Tok.
isOneOf(tok::kw_export, tok::kw_template));
142 ParseScopeFlags TemplateScopeFlags(
this, NewFlags, isSpecialization);
145 return ParseSingleDeclarationAfterTemplate(
147 ParsedTemplateInfo(&ParamLists, isSpecialization, LastParamListWasEmpty),
148 ParsingTemplateParams, DeclEnd, AccessAttrs, AS);
161 Decl *Parser::ParseSingleDeclarationAfterTemplate(
165 assert(TemplateInfo.Kind != ParsedTemplateInfo::NonTemplate &&
166 "Template information required");
168 if (Tok.
is(tok::kw_static_assert)) {
171 << TemplateInfo.getSourceRange();
173 return ParseStaticAssertDeclaration(DeclEnd);
178 ParseCXXClassMemberDeclaration(AS, AccessAttrs, TemplateInfo,
183 ParsedAttributesWithRange prefixAttrs(AttrFactory);
184 MaybeParseCXX11Attributes(prefixAttrs);
186 if (Tok.
is(tok::kw_using)) {
187 auto usingDeclPtr = ParseUsingDirectiveOrDeclaration(Context, TemplateInfo, DeclEnd,
189 if (!usingDeclPtr || !usingDeclPtr.get().isSingleDecl())
191 return usingDeclPtr.get().getSingleDecl();
198 ParseDeclarationSpecifiers(DS, TemplateInfo, AS,
199 getDeclSpecContextFromDeclaratorContext(Context));
201 if (Tok.
is(tok::semi)) {
202 ProhibitAttributes(prefixAttrs);
207 TemplateInfo.TemplateParams ? *TemplateInfo.TemplateParams
209 TemplateInfo.Kind == ParsedTemplateInfo::ExplicitInstantiation,
211 assert(!AnonRecord &&
212 "Anonymous unions/structs should not be valid with template");
218 if (TemplateInfo.Kind == ParsedTemplateInfo::ExplicitInstantiation)
219 ProhibitAttributes(prefixAttrs);
221 DS.takeAttributesFrom(prefixAttrs);
225 ParseDeclarator(DeclaratorInfo);
227 if (!DeclaratorInfo.hasName()) {
230 if (Tok.
is(tok::semi))
235 LateParsedAttrList LateParsedAttrs(
true);
236 if (DeclaratorInfo.isFunctionDeclarator())
237 MaybeParseGNUAttributes(DeclaratorInfo, &LateParsedAttrs);
239 if (DeclaratorInfo.isFunctionDeclarator() &&
240 isStartOfFunctionDefinition(DeclaratorInfo)) {
246 Diag(Tok, diag::err_function_definition_not_allowed);
255 Diag(DS.getStorageClassSpecLoc(), diag::err_function_declared_typedef)
257 DS.ClearStorageClassSpecs();
260 if (TemplateInfo.Kind == ParsedTemplateInfo::ExplicitInstantiation) {
261 if (DeclaratorInfo.getName().getKind() !=
265 Diag(Tok, diag::err_template_defn_explicit_instantiation) << 0;
266 return ParseFunctionDefinition(DeclaratorInfo, ParsedTemplateInfo(),
271 Diag(DeclaratorInfo.getIdentifierLoc(),
272 diag::err_explicit_instantiation_with_definition)
280 LAngleLoc,
nullptr));
282 return ParseFunctionDefinition(
283 DeclaratorInfo, ParsedTemplateInfo(&FakedParamLists,
289 return ParseFunctionDefinition(DeclaratorInfo, TemplateInfo,
294 Decl *ThisDecl = ParseDeclarationAfterDeclarator(DeclaratorInfo,
297 if (Tok.
is(tok::comma)) {
298 Diag(Tok, diag::err_multiple_template_declarators)
299 << (int)TemplateInfo.Kind;
305 ExpectAndConsumeSemi(diag::err_expected_semi_declaration);
306 if (LateParsedAttrs.size() > 0)
307 ParseLexedAttributeList(LateParsedAttrs, ThisDecl,
true,
false);
308 DeclaratorInfo.complete(ThisDecl);
321 bool Parser::ParseTemplateParameters(
332 if (!Tok.
is(tok::greater) && !Tok.
is(tok::greatergreater))
333 Failed = ParseTemplateParameterList(Depth, TemplateParams);
335 if (Tok.
is(tok::greatergreater)) {
360 Parser::ParseTemplateParameterList(
const unsigned Depth,
365 = ParseTemplateParameter(Depth, TemplateParams.size())) {
366 TemplateParams.push_back(TmpParam);
370 SkipUntil(tok::comma, tok::greater, tok::greatergreater,
375 if (Tok.
is(tok::comma)) {
377 }
else if (Tok.
isOneOf(tok::greater, tok::greatergreater)) {
385 SkipUntil(tok::comma, tok::greater, tok::greatergreater,
395 bool Parser::isStartOfTemplateTypeParameter() {
396 if (Tok.
is(tok::kw_class)) {
403 case tok::greatergreater:
407 case tok::identifier:
416 switch (GetLookAheadToken(2).
getKind()) {
420 case tok::greatergreater:
430 if (Tok.
isNot(tok::kw_typename) && Tok.
isNot(tok::kw_typedef))
442 if (Next.
getKind() == tok::identifier)
443 Next = GetLookAheadToken(2);
449 case tok::greatergreater:
453 case tok::kw_typename:
454 case tok::kw_typedef:
480 NamedDecl *Parser::ParseTemplateParameter(
unsigned Depth,
unsigned Position) {
481 if (isStartOfTemplateTypeParameter()) {
483 if (Tok.
is(tok::kw_typedef)) {
494 return ParseTypeParameter(Depth, Position);
497 if (Tok.
is(tok::kw_template))
498 return ParseTemplateTemplateParameter(Depth, Position);
503 return ParseNonTypeTemplateParameter(Depth, Position);
515 NamedDecl *Parser::ParseTypeParameter(
unsigned Depth,
unsigned Position) {
516 assert(Tok.
isOneOf(tok::kw_class, tok::kw_typename) &&
517 "A type-parameter starts with 'class' or 'typename'");
520 bool TypenameKeyword = Tok.
is(tok::kw_typename);
528 ? diag::warn_cxx98_compat_variadic_templates
529 : diag::ext_variadic_templates);
535 if (Tok.
is(tok::identifier)) {
538 }
else if (Tok.
isOneOf(tok::equal, tok::comma, tok::greater,
539 tok::greatergreater)) {
548 bool AlreadyHasEllipsis = EllipsisLoc.
isValid();
550 DiagnoseMisplacedEllipsis(EllipsisLoc, NameLoc, AlreadyHasEllipsis,
true);
562 KeyLoc, ParamName, NameLoc, Depth, Position,
563 EqualLoc, DefaultArg);
578 Parser::ParseTemplateTemplateParameter(
unsigned Depth,
unsigned Position) {
579 assert(Tok.
is(tok::kw_template) &&
"Expected 'template' keyword");
587 if (ParseTemplateParameters(Depth + 1, TemplateParams, LAngleLoc,
599 bool Replace = Tok.
isOneOf(tok::kw_typename, tok::kw_struct);
601 if (Tok.
is(tok::kw_typename)) {
604 ? diag::warn_cxx14_compat_template_template_param_typename
605 : diag::ext_template_template_param_typename)
609 }
else if (Next.
isOneOf(tok::identifier, tok::comma, tok::greater,
610 tok::greatergreater, tok::ellipsis)) {
626 ? diag::warn_cxx98_compat_variadic_templates
627 : 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);
651 TemplateLoc, LAngleLoc,
661 DefaultArg = ParseTemplateTemplateArgument();
664 diag::err_default_template_template_parameter_not_template);
665 SkipUntil(tok::comma, tok::greater, tok::greatergreater,
671 ParamList, EllipsisLoc,
672 ParamName, NameLoc, Depth,
673 Position, EqualLoc, DefaultArg);
683 Parser::ParseNonTypeTemplateParameter(
unsigned Depth,
unsigned Position) {
688 ParseDeclarationSpecifiers(DS, ParsedTemplateInfo(),
AS_none,
689 DeclSpecContext::DSC_template_param);
693 ParseDeclarator(ParamDecl);
702 DiagnoseMisplacedEllipsisInDeclarator(EllipsisLoc, ParamDecl);
726 Depth, Position, EqualLoc,
730 void Parser::DiagnoseMisplacedEllipsis(
SourceLocation EllipsisLoc,
732 bool AlreadyHasEllipsis,
733 bool IdentifierHasName) {
735 if (!AlreadyHasEllipsis)
737 Diag(EllipsisLoc, diag::err_misplaced_ellipsis_in_declaration)
739 << !IdentifierHasName;
742 void Parser::DiagnoseMisplacedEllipsisInDeclarator(
SourceLocation EllipsisLoc,
746 if (!AlreadyHasEllipsis)
749 AlreadyHasEllipsis, D.
hasName());
767 bool Parser::ParseGreaterThanInTemplateList(
SourceLocation &RAngleLoc,
768 bool ConsumeLastToken,
769 bool ObjCGenericList) {
772 const char *ReplacementStr =
"> >";
773 bool MergeWithNextToken =
false;
784 if (ConsumeLastToken)
788 case tok::greatergreater:
789 RemainingToken = tok::greater;
792 case tok::greatergreatergreater:
793 RemainingToken = tok::greatergreater;
796 case tok::greaterequal:
797 RemainingToken = tok::equal;
798 ReplacementStr =
"> =";
805 RemainingToken = tok::equalequal;
806 MergeWithNextToken =
true;
810 case tok::greatergreaterequal:
811 RemainingToken = tok::greaterequal;
830 bool PreventMergeWithNextToken =
831 (RemainingToken == tok::greater ||
832 RemainingToken == tok::greatergreater) &&
833 (Next.
isOneOf(tok::greater, tok::greatergreater,
834 tok::greatergreatergreater, tok::equal, tok::greaterequal,
835 tok::greatergreaterequal, tok::equalequal)) &&
836 areTokensAdjacent(Tok, Next);
839 if (!ObjCGenericList) {
854 if (PreventMergeWithNextToken)
857 unsigned DiagId = diag::err_two_right_angle_brackets_need_space;
859 (Tok.
is(tok::greatergreater) || Tok.
is(tok::greatergreatergreater)))
860 DiagId = diag::warn_cxx98_compat_two_right_angle_brackets;
861 else if (Tok.
is(tok::greaterequal))
862 DiagId = diag::err_right_angle_bracket_equal_needs_space;
863 Diag(TokLoc, DiagId) << Hint1 << Hint2;
874 RAngleLoc = PP.
SplitToken(TokLoc, GreaterLength);
885 if (MergeWithNextToken) {
891 Tok.
setLength(OldLength - GreaterLength);
896 if (PreventMergeWithNextToken)
903 if (MergeWithNextToken)
906 if (ConsumeLastToken)
912 if (ConsumeLastToken) {
913 PrevTokLocation = RAngleLoc;
915 PrevTokLocation = TokBeforeGreaterLoc;
936 Parser::ParseTemplateIdAfterTemplateName(
bool ConsumeLastToken,
938 TemplateArgList &TemplateArgs,
940 assert(Tok.
is(tok::less) &&
"Must have already parsed the template-name");
949 if (!Tok.
isOneOf(tok::greater, tok::greatergreater,
950 tok::greatergreatergreater, tok::greaterequal,
951 tok::greatergreaterequal))
952 Invalid = ParseTemplateArgumentList(TemplateArgs);
956 if (ConsumeLastToken)
964 return ParseGreaterThanInTemplateList(RAngleLoc, ConsumeLastToken,
1009 bool AllowTypeAnnotation) {
1011 assert(Template && Tok.
is(tok::less) &&
1012 "Parser isn't at the beginning of a template-id");
1019 TemplateArgList TemplateArgs;
1020 bool Invalid = ParseTemplateIdAfterTemplateName(
false, LAngleLoc,
1036 SS, TemplateKWLoc, Template, TemplateName.
Identifier,
1037 TemplateNameLoc, LAngleLoc, TemplateArgsPtr, RAngleLoc);
1046 Tok.
setKind(tok::annot_typename);
1047 setTypeAnnotation(Tok, Type.
get());
1050 else if (TemplateKWLoc.
isValid())
1057 Tok.
setKind(tok::annot_template_id);
1070 SS, TemplateKWLoc, TemplateNameLoc, TemplateII, OpKind, Template, TNK,
1071 LAngleLoc, RAngleLoc, TemplateArgs, TemplateIds);
1100 void Parser::AnnotateTemplateIdTokenAsType(
bool IsClassName) {
1101 assert(Tok.
is(tok::annot_template_id) &&
"Requires template-id tokens");
1106 "Only works for type and dependent templates");
1109 TemplateId->NumArgs);
1113 TemplateId->TemplateKWLoc,
1114 TemplateId->Template,
1116 TemplateId->TemplateNameLoc,
1117 TemplateId->LAngleLoc,
1119 TemplateId->RAngleLoc,
1123 Tok.
setKind(tok::annot_typename);
1124 setTypeAnnotation(Tok, Type.isInvalid() ? nullptr : Type.get());
1125 if (TemplateId->SS.isNotEmpty())
1136 return Tok.
isOneOf(tok::comma, tok::greater, tok::greatergreater);
1141 if (!Tok.
is(tok::identifier) && !Tok.
is(tok::coloncolon) &&
1142 !Tok.
is(tok::annot_cxxscope))
1157 ParseOptionalCXXScopeSpecifier(SS,
nullptr,
1162 if (SS.
isSet() && Tok.
is(tok::kw_template)) {
1167 if (Tok.
is(tok::identifier)) {
1186 }
else if (Tok.
is(tok::identifier)) {
1196 bool MemberOfUnknownSpecialization;
1201 false, Template, MemberOfUnknownSpecialization);
1238 if (isCXXTypeId(TypeIdAsTemplateArgument)) {
1246 TentativeParsingAction TPA(*
this);
1249 = ParseTemplateTemplateArgument();
1250 if (!TemplateTemplateArgument.
isInvalid()) {
1252 return TemplateTemplateArgument;
1266 ExprArg.
get(), Loc);
1272 bool Parser::IsTemplateArgumentList(
unsigned Skip) {
1273 struct AlwaysRevertAction : TentativeParsingAction {
1274 AlwaysRevertAction(
Parser &
P) : TentativeParsingAction(P) { }
1275 ~AlwaysRevertAction() { Revert(); }
1288 if (Tok.
is(tok::greater))
1292 while (isCXXDeclarationSpecifier() == TPResult::True)
1296 return Tok.
isOneOf(tok::greater, tok::comma);
1306 Parser::ParseTemplateArgumentList(TemplateArgList &TemplateArgs) {
1314 Arg = Actions.ActOnPackExpansion(Arg, EllipsisLoc);
1322 TemplateArgs.push_back(Arg);
1348 return ParseSingleDeclarationAfterTemplate(
1349 Context, ParsedTemplateInfo(ExternLoc, TemplateLoc),
1350 ParsingTemplateParams, DeclEnd, AccessAttrs, AS);
1356 TemplateParams->size());
1360 R.setBegin(ExternLoc);
1365 ((
Parser *)P)->ParseLateTemplatedFuncDef(LPT);
1376 TemplateParameterDepthRAII CurTemplateDepthTracker(TemplateParameterDepth);
1380 Actions, Actions.Context.getTranslationUnitDecl());
1388 struct ContainingDC {
1389 ContainingDC(
DeclContext *DC,
bool ShouldPush) : Pair(DC, ShouldPush) {}
1390 llvm::PointerIntPair<DeclContext *, 1, bool> Pair;
1391 DeclContext *getDC() {
return Pair.getPointer(); }
1392 bool shouldPushDC() {
return Pair.getInt(); }
1396 DeclContext *NextContaining = Actions.getContainingDC(DD);
1398 bool ShouldPush = DD == NextContaining;
1399 DeclContextsToReenter.push_back({DD, ShouldPush});
1401 NextContaining = Actions.getContainingDC(DD);
1406 for (ContainingDC CDC : reverse(DeclContextsToReenter)) {
1407 TemplateParamScopeStack.push_back(
1409 unsigned NumParamLists = Actions.ActOnReenterTemplateScope(
1411 CurTemplateDepthTracker.addDepth(NumParamLists);
1412 if (CDC.shouldPushDC()) {
1414 Actions.PushDeclContext(Actions.getCurScope(), CDC.getDC());
1418 assert(!LPT.
Toks.empty() &&
"Empty body!");
1422 LPT.
Toks.push_back(Tok);
1423 PP.EnterTokenStream(LPT.
Toks,
true);
1427 assert(Tok.
isOneOf(tok::l_brace, tok::colon, tok::kw_try) &&
1428 "Inline method not starting with '{', ':' or 'try'");
1437 Actions.getContainingDC(FunD));
1439 Actions.ActOnStartOfFunctionDef(
getCurScope(), FunD);
1441 if (Tok.
is(tok::kw_try)) {
1442 ParseFunctionTryBlock(LPT.
D, FnScope);
1444 if (Tok.
is(tok::colon))
1445 ParseConstructorInitializer(LPT.
D);
1447 Actions.ActOnDefaultCtorInitializers(LPT.
D);
1449 if (Tok.
is(tok::l_brace)) {
1450 assert((!isa<FunctionTemplateDecl>(LPT.
D) ||
1451 cast<FunctionTemplateDecl>(LPT.
D)
1452 ->getTemplateParameters()
1453 ->getDepth() == TemplateParameterDepth - 1) &&
1454 "TemplateParameterDepth should be greater than the depth of " 1455 "current template being instantiated!");
1456 ParseFunctionStatementBody(LPT.
D, FnScope);
1457 Actions.UnmarkAsLateParsedTemplate(FunD);
1459 Actions.ActOnFinishFunctionBody(LPT.
D,
nullptr);
1465 TemplateParamScopeStack.rbegin();
1466 for (; I != TemplateParamScopeStack.rend(); ++I)
1471 void Parser::LexTemplateFunctionForLateParsing(
CachedTokens &Toks) {
1473 if (!ConsumeAndStoreFunctionPrologue(Toks)) {
1475 ConsumeAndStoreUntil(tok::r_brace, Toks,
false);
1479 if (kind == tok::kw_try) {
1480 while (Tok.
is(tok::kw_catch)) {
1481 ConsumeAndStoreUntil(tok::l_brace, Toks,
false);
1482 ConsumeAndStoreUntil(tok::r_brace, Toks,
false);
1492 TentativeParsingAction TPA(*
this);
1494 if (
SkipUntil(tok::greater, tok::greatergreater, tok::greatergreatergreater,
1499 ParseGreaterThanInTemplateList(Greater,
true,
false);
1500 Actions.diagnoseExprIntendedAsTemplateName(
getCurScope(), LHS,
1511 void Parser::checkPotentialAngleBracket(
ExprResult &PotentialTemplateName) {
1512 assert(Tok.
is(tok::less) &&
"not at a potential angle bracket");
1515 if (!Actions.mightBeIntendedToBeTemplateName(PotentialTemplateName,
1516 DependentTemplateName))
1528 ParseGreaterThanInTemplateList(Greater,
true,
false);
1529 Actions.diagnoseExprIntendedAsTemplateName(
1530 getCurScope(), PotentialTemplateName, Less, Greater);
1540 TentativeParsingAction TPA(*
this);
1542 if (isTypeIdUnambiguously() &&
1543 diagnoseUnknownTemplateId(PotentialTemplateName, Less)) {
1554 AngleBracketTracker::Priority Priority =
1555 (DependentTemplateName ? AngleBracketTracker::DependentName
1556 : AngleBracketTracker::PotentialTypo) |
1557 (Tok.hasLeadingSpace() ? AngleBracketTracker::SpaceBeforeLess
1558 : AngleBracketTracker::NoSpaceBeforeLess);
1559 AngleBrackets.add(*
this, PotentialTemplateName.
get(), Tok.getLocation(),
1563 bool Parser::checkPotentialAngleBracketDelimiter(
1564 const AngleBracketTracker::Loc &LAngle,
const Token &OpToken) {
1568 if (OpToken.
is(tok::comma) && isTypeIdUnambiguously() &&
1569 diagnoseUnknownTemplateId(LAngle.TemplateName, LAngle.LessLoc)) {
1570 AngleBrackets.clear(*
this);
1577 if (OpToken.
is(tok::greater) && Tok.
is(tok::l_paren) &&
1579 Actions.diagnoseExprIntendedAsTemplateName(
1580 getCurScope(), LAngle.TemplateName, LAngle.LessLoc,
1582 AngleBrackets.clear(*
this);
1588 if (OpToken.
is(tok::greater) ||
1590 OpToken.
isOneOf(tok::greatergreater, tok::greatergreatergreater)))
1591 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.
void EnterToken(const Token &Tok)
Enters a token in the token stream to be lexed next.
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.
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)
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.
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)
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...
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.
Scope * getCurScope() const
ExprResult ParseConstantExpressionInExprEvalContext(TypeCastState isTypeCast=NotTypeCast)
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.
TypeResult ActOnTemplateIdType(CXXScopeSpec &SS, SourceLocation TemplateKWLoc, TemplateTy Template, IdentifierInfo *TemplateII, SourceLocation TemplateIILoc, SourceLocation LAngleLoc, ASTTemplateArgsPtr TemplateArgs, SourceLocation RAngleLoc, bool IsCtorOrDtorName=false, bool IsClassName=false)
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
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