22#include "llvm/ADT/ScopeExit.h"
27 if (!Tok.is(tok::l_paren))
29 StringLiteral *
Message =
nullptr;
33 if (isTokenStringLiteral()) {
41 Diag(Tok.getLocation(), diag::err_expected_string_literal)
50void Parser::SkipDeletedFunctionBody() {
51 if (!Tok.is(tok::l_paren))
59 if (Tok.is(tok::r_paren))
63NamedDecl *Parser::ParseCXXInlineMethodDef(
68 assert(Tok.isOneOf(tok::l_brace, tok::colon, tok::kw_try, tok::equal) &&
69 "Current token not a '{', ':', '=', or 'try'!");
72 TemplateInfo.TemplateParams ? TemplateInfo.TemplateParams->data()
74 TemplateInfo.TemplateParams ? TemplateInfo.TemplateParams->size() : 0);
78 FnD = Actions.ActOnFriendFunctionDecl(
getCurScope(), D,
81 FnD = Actions.ActOnCXXMemberDeclarator(
getCurScope(), AS, D,
82 TemplateParams,
nullptr,
85 Actions.ProcessDeclAttributeList(
getCurScope(), FnD, AccessAttrs);
87 Actions.ActOnPureSpecifier(FnD, PureSpecLoc);
92 HandleMemberFunctionDeclDelays(D, FnD);
103 SourceLocation KWLoc;
105 DiagCompat(KWLoc, diag_compat::defaulted_deleted_function)
107 StringLiteral *
Message = ParseCXXDeletedFunctionMessage();
108 Actions.SetDeclDeleted(FnD, KWLoc, Message);
110 if (
auto *DeclAsFunction = dyn_cast<FunctionDecl>(FnD)) {
111 DeclAsFunction->setRangeEnd(PrevTokLocation);
114 DiagCompat(KWLoc, diag_compat::defaulted_deleted_function)
116 Actions.SetDeclDefaulted(FnD, KWLoc);
117 if (
auto *DeclAsFunction = dyn_cast<FunctionDecl>(FnD)) {
118 DeclAsFunction->setRangeEnd(PrevTokLocation);
121 llvm_unreachable(
"function definition after = not 'delete' or 'default'");
124 if (Tok.is(tok::comma)) {
125 Diag(KWLoc, diag::err_default_delete_in_multiple_declaration)
128 }
else if (ExpectAndConsume(tok::semi, diag::err_expected_after,
129 Delete ?
"delete" :
"default") &&
130 !isLikelyAtStartOfNewDeclaration()) {
137 if (SkipFunctionBodies && (!FnD || Actions.canSkipFunctionBody(FnD)) &&
138 trySkippingFunctionBody()) {
139 Actions.ActOnSkippedFunctionBody(FnD);
151 ((Actions.CurContext->isDependentContext() ||
154 !Actions.IsInsideALocalClassWithinATemplateFunction())) {
157 LexTemplateFunctionForLateParsing(Toks);
161 Actions.CheckForFunctionRedefinition(FD);
162 Actions.MarkAsLateParsedTemplate(FD, FnD, Toks);
170 LexedMethod* LM =
new LexedMethod(
this, FnD);
171 getCurrentClass().LateParsedDeclarations.push_back(LM);
177 if (ConsumeAndStoreFunctionPrologue(Toks)) {
183 if (PP.isCodeCompletionEnabled() &&
184 llvm::any_of(Toks, [](
const Token &Tok) {
185 return Tok.is(tok::code_completion);
198 delete getCurrentClass().LateParsedDeclarations.back();
199 getCurrentClass().LateParsedDeclarations.pop_back();
203 ConsumeAndStoreUntil(tok::r_brace, Toks,
false);
207 if (
kind == tok::kw_try) {
208 while (Tok.is(tok::kw_catch)) {
209 ConsumeAndStoreUntil(tok::l_brace, Toks,
false);
210 ConsumeAndStoreUntil(tok::r_brace, Toks,
false);
218 Actions.CheckForFunctionRedefinition(FD);
223 delete getCurrentClass().LateParsedDeclarations.back();
224 getCurrentClass().LateParsedDeclarations.pop_back();
230void Parser::ParseCXXNonStaticMemberInitializer(
Decl *VarD) {
231 assert(Tok.isOneOf(tok::l_brace, tok::equal) &&
232 "Current token not a '{' or '='!");
234 LateParsedMemberInitializer *MI =
235 new LateParsedMemberInitializer(
this, VarD);
236 getCurrentClass().LateParsedDeclarations.push_back(MI);
240 if (
kind == tok::equal) {
245 if (
kind == tok::l_brace) {
251 ConsumeAndStoreUntil(tok::r_brace, Toks,
true);
270Parser::LateParsedClass::LateParsedClass(
Parser *P, ParsingClass *
C)
273Parser::LateParsedClass::~LateParsedClass() {
274 Self->DeallocateParsedClasses(Class);
278 Self->ParseLexedMethodDeclarations(*
Class);
282 Self->ParseLexedMemberInitializers(*
Class);
298 Self->ParseLexedMethodDeclaration(*
this);
302 Self->ParseLexedMethodDef(*
this);
306 Self->ParseLexedMemberInitializer(*
this);
310 Self->ParseLexedAttribute(*
this,
true,
false);
316 Self->ParseLexedPragma(*
this);
328 P.ReenterTemplateScopes(
Scopes, MaybeTemplated));
338 !
Class.TopLevelClass),
341 if (
Class.TopLevelClass)
346 P.Actions.ActOnStartDelayedMemberDeclarations(
P.getCurScope(),
347 Class.TagOrTemplate);
350 if (
Class.TopLevelClass)
353 P.Actions.ActOnFinishDelayedMemberDeclarations(
P.getCurScope(),
354 Class.TagOrTemplate);
358void Parser::ParseLexedMethodDeclarations(ParsingClass &
Class) {
359 ReenterClassScopeRAII InClassScope(*
this,
Class);
365void Parser::ParseLexedMethodDeclaration(LateParsedMethodDeclaration &LM) {
367 ReenterTemplateScopeRAII InFunctionTemplateScope(*
this, LM.Method);
391 for (
unsigned I = 0, N = LM.DefaultArgs.size(); I != N; ++I) {
394 bool HasUnparsed = Param->hasUnparsedDefaultArg();
396 std::unique_ptr<CachedTokens> Toks = std::move(LM.DefaultArgs[I].Toks);
402 Token LastDefaultArgToken = Toks->back();
405 Toks->push_back(DefArgEnd);
408 Toks->push_back(
Tok);
409 PP.EnterTokenStream(*Toks,
true,
true);
415 assert(
Tok.is(tok::equal) &&
"Default argument not starting with '='");
426 Diag(
Tok, diag::compat_cxx11_generalized_initializer_lists);
427 DefArgResult = ParseBraceInitializer();
431 Actions.ActOnParamDefaultArgumentError(Param, EqualLoc,
434 if (Tok.isNot(tok::eof) || Tok.getEofData() != Param) {
438 assert(Toks->size() >= 3 &&
"expected a token in default arg");
439 Diag(Tok.getLocation(), diag::err_default_arg_unparsed)
440 << SourceRange(Tok.getLocation(),
441 (*Toks)[Toks->size() - 3].getLocation());
443 Actions.ActOnParamDefaultArgument(Param, EqualLoc,
449 while (Tok.isNot(tok::eof))
452 if (Tok.is(tok::eof) && Tok.getEofData() == Param)
454 }
else if (HasUnparsed) {
455 assert(Param->hasInheritedDefaultArg());
457 if (
const auto *FunTmpl = dyn_cast<FunctionTemplateDecl>(LM.Method))
466 Param->setUninstantiatedDefaultArg(
469 Param->setDefaultArg(OldParam->
getInit());
479 Token LastExceptionSpecToken = Toks->back();
480 Token ExceptionSpecEnd =
482 Toks->push_back(ExceptionSpecEnd);
485 Toks->push_back(Tok);
486 PP.EnterTokenStream(*Toks,
true,
true);
498 FunctionDecl *FunctionToPush;
499 if (FunctionTemplateDecl *FunTmpl
500 = dyn_cast<FunctionTemplateDecl>(LM.Method))
501 FunctionToPush = FunTmpl->getTemplatedDecl();
504 Method = dyn_cast<CXXMethodDecl>(FunctionToPush);
509 Sema::ContextRAII FnContext(Actions, FunctionToPush,
512 Sema::CXXThisScopeRAII ThisScope(
518 SourceRange SpecificationRange;
519 SmallVector<ParsedType, 4> DynamicExceptions;
520 SmallVector<SourceRange, 4> DynamicExceptionRanges;
525 = tryParseExceptionSpecification(
false, SpecificationRange,
527 DynamicExceptionRanges, NoexceptExpr,
528 ExceptionSpecTokens);
530 if (Tok.isNot(tok::eof) || Tok.getEofData() != LM.Method)
531 Diag(Tok.getLocation(), diag::err_except_spec_unparsed);
534 Actions.actOnDelayedExceptionSpecification(LM.Method, EST,
537 DynamicExceptionRanges,
539 NoexceptExpr.
get() :
nullptr);
543 while (Tok.isNot(tok::eof))
547 if (Tok.is(tok::eof) && Tok.getEofData() == LM.Method)
551 LM.ExceptionSpecTokens =
nullptr;
554 InFunctionTemplateScope.Scopes.Exit();
557 Actions.ActOnFinishDelayedCXXMethodDeclaration(
getCurScope(), LM.Method);
560void Parser::ParseLexedMethodDefs(ParsingClass &
Class) {
563 for (LateParsedDeclaration *D :
Class.LateParsedDeclarations)
567void Parser::ParseLexedMethodDef(LexedMethod &LM) {
573 assert(!LM.Toks.empty() &&
"Empty body!");
574 Token LastBodyToken = LM.Toks.back();
576 LM.Toks.push_back(BodyEnd);
579 LM.Toks.push_back(Tok);
580 PP.EnterTokenStream(LM.Toks,
true,
true);
584 assert(Tok.isOneOf(tok::l_brace, tok::colon, tok::kw_try)
585 &&
"Inline method not starting with '{', ':' or 'try'");
591 Sema::FPFeaturesStateRAII SaveFPFeatures(Actions);
593 Actions.ActOnStartOfFunctionDef(
getCurScope(), LM.D);
595 llvm::scope_exit _([&]() {
596 while (Tok.isNot(tok::eof))
599 if (Tok.is(tok::eof) && Tok.getEofData() == LM.D)
602 if (
auto *FD = dyn_cast_or_null<FunctionDecl>(LM.D))
605 Actions.ActOnFinishInlineFunctionDef(FD);
608 assert((Actions.getDiagnostics().hasErrorOccurred() ||
611 < TemplateParameterDepth) &&
612 "TemplateParameterDepth should be greater than the depth of "
613 "current template being instantiated!");
615 ParseFunctionBody(LM.D, FnScope);
618void Parser::ParseLexedMemberInitializers(ParsingClass &
Class) {
621 if (!
Class.LateParsedDeclarations.empty()) {
628 Sema::CXXThisScopeRAII ThisScope(Actions,
Class.TagOrTemplate,
631 for (LateParsedDeclaration *D :
Class.LateParsedDeclarations)
635 Actions.ActOnFinishDelayedMemberInitializers(
Class.TagOrTemplate);
638void Parser::ParseLexedMemberInitializer(LateParsedMemberInitializer &MI) {
639 if (!MI.Field || MI.Field->isInvalidDecl())
646 MI.Toks.push_back(Tok);
647 PP.EnterTokenStream(MI.Toks,
true,
true);
652 SourceLocation EqualLoc;
654 Actions.ActOnStartCXXInClassMemberInitializer();
658 EnterExpressionEvaluationContext Eval(
664 Actions.ActOnFinishCXXInClassMemberInitializer(MI.Field, EqualLoc,
Init);
667 if (Tok.isNot(tok::eof)) {
668 if (!
Init.isInvalid()) {
669 SourceLocation EndLoc = PP.getLocForEndOfToken(PrevTokLocation);
671 EndLoc = Tok.getLocation();
673 Diag(EndLoc, diag::err_expected_semi_decl_list);
677 while (Tok.isNot(tok::eof))
681 if (Tok.getEofData() == MI.Field)
685void Parser::ParseLexedAttributes(ParsingClass &
Class) {
688 for (LateParsedDeclaration *LateD :
Class.LateParsedDeclarations)
692void Parser::ParseLexedAttributeList(LateParsedAttrList &LAs, Decl *D,
694 ParsedAttributes *OutAttrs) {
696 "Attribute list should be marked for immediate parsing.");
697 for (
unsigned i = 0, ni = LAs.size(); i < ni; ++i) {
700 ParseLexedAttribute(*LAs[i],
EnterScope, OnDefinition, OutAttrs);
711 for (
unsigned I = 0, E = AL.getNumArgs(); I != E; ++I)
713 Worklist.push_back(AL.getArgAsExpr(I));
714 while (!Worklist.empty()) {
715 const Stmt *S = Worklist.pop_back_val();
718 if (
const auto *DRE = dyn_cast<DeclRefExpr>(S);
721 llvm::append_range(Worklist, S->
children());
725bool Parser::checkLateAttributeParamRefs(
727 bool ReenteredProtoParams) {
728 auto IsPointeeParam = [&](
const ParmVarDecl *PVD) {
729 return ReenteredProtoParams && llvm::is_contained(LPA.
ProtoParams, PVD);
737 for (
const DeclRefExpr *DRE : ParamRefs) {
739 if (!IsPointeeParam(PVD))
741 LookupResult
R(Actions, PVD->getDeclName(), DRE->getLocation(),
743 if (!Actions.LookupName(R,
getCurScope()) ||
R.isAmbiguous())
745 Diag(DRE->getLocation(), diag::err_ambiguous_reference)
746 << PVD->getDeclName();
747 Diag(PVD->getLocation(), diag::note_ambiguous_candidate) << PVD;
748 for (
const NamedDecl *
Other : R)
749 Diag(
Other->getLocation(), diag::note_ambiguous_candidate) <<
Other;
758 if (Actions.CurContext->isDependentContext() ||
760 Actions.getCurGenericLambda()) {
761 for (
const DeclRefExpr *DRE : ParamRefs) {
763 if (!IsPointeeParam(PVD))
765 Diag(DRE->getLocation(), diag::err_late_attribute_param_in_template)
775 ParsedAttributes *OutAttrs) {
776 ParsedAttributes Attrs(AttrFactory);
778 if (LPA.
Decls.size() > 0) {
784 NamedDecl *ND = dyn_cast<NamedDecl>(D);
785 RecordDecl *RD = dyn_cast_or_null<RecordDecl>(D->
getDeclContext());
788 Sema::CXXThisScopeRAII ThisScope(Actions, RD, Qualifiers(),
799 Actions.ActOnReenterFunctionContext(Actions.CurScope, D);
808 bool HasProtoParams = !HasFuncScope && !LPA.
ProtoParams.empty();
812 HasProtoParams && !InCStruct);
814 Actions.ActOnReenterFunctionPrototypeParams(Actions.getCurScope(),
817 ParsedAttributes Parsed = ParseLexedAttributeTokens(LPA);
819 if (HasProtoParams && InCStruct)
820 Actions.ActOnExitFunctionPrototypeParams(Actions.getCurScope(),
824 SmallVector<const DeclRefExpr *, 4> ParamRefs;
826 if (!ParamRefs.empty() &&
827 checkLateAttributeParamRefs(LPA, ParamRefs, HasProtoParams))
829 Attrs.takeAllAppendingFrom(Parsed);
832 Actions.ActOnExitFunctionContext();
838 if (OnDefinition && !Attrs.empty() && !Attrs.begin()->isCXX11Attribute() &&
839 Attrs.begin()->isKnownToGCC())
840 Diag(Tok, diag::warn_attribute_on_function_definition) << &LPA.
AttrName;
842 for (
auto *D : LPA.
Decls)
843 Actions.ActOnFinishDelayedAttribute(
getCurScope(), D, Attrs);
849void Parser::ParseLexedPragmas(ParsingClass &
Class) {
852 for (LateParsedDeclaration *D :
Class.LateParsedDeclarations)
856void Parser::ParseLexedPragma(LateParsedPragma &LP) {
857 PP.EnterToken(Tok,
true);
858 PP.EnterTokenStream(LP.toks(),
true,
863 assert(Tok.isAnnotation() &&
"Expected annotation token.");
864 switch (Tok.getKind()) {
865 case tok::annot_attr_openmp:
866 case tok::annot_pragma_openmp: {
868 ParsedAttributes Attrs(AttrFactory);
869 (void)ParseOpenMPDeclarativeDirectiveWithExtDecl(AS, Attrs);
873 llvm_unreachable(
"Unexpected token.");
882 bool isFirstTokenConsumed =
true;
885 if (Tok.is(T1) || Tok.is(T2)) {
886 if (ConsumeFinalToken) {
893 switch (Tok.getKind()) {
895 case tok::annot_module_begin:
896 case tok::annot_module_end:
897 case tok::annot_module_include:
901 case tok::annot_pragma_openacc:
902 case tok::annot_pragma_openmp:
903 case tok::annot_attr_openmp: {
907 ? tok::annot_pragma_openacc_end
908 : tok::annot_pragma_openmp_end;
910 ConsumeAnnotationToken();
911 while (Tok.isNot(EndKind) && Tok.isNot(tok::eof)) {
915 if (Tok.is(EndKind)) {
917 ConsumeAnnotationToken();
926 ConsumeAndStoreUntil(tok::r_paren, Toks,
false);
932 ConsumeAndStoreUntil(tok::r_square, Toks,
false);
938 ConsumeAndStoreUntil(tok::r_brace, Toks,
false);
947 if (ParenCount && !isFirstTokenConsumed)
953 if (BracketCount && !isFirstTokenConsumed)
959 if (BraceCount && !isFirstTokenConsumed)
975 isFirstTokenConsumed =
false;
979bool Parser::ConsumeAndStoreFunctionPrologue(
CachedTokens &Toks) {
980 if (Tok.is(tok::kw_try)) {
985 if (Tok.isNot(tok::colon)) {
991 ConsumeAndStoreUntil(tok::l_brace, tok::r_brace, Toks,
994 if (Tok.isNot(tok::l_brace))
995 return Diag(Tok.getLocation(), diag::err_expected) << tok::l_brace;
1002 Toks.push_back(Tok);
1015 bool MightBeTemplateArgument =
false;
1019 if (Tok.is(tok::kw_decltype)) {
1020 Toks.push_back(Tok);
1022 if (Tok.isNot(tok::l_paren))
1023 return Diag(Tok.getLocation(), diag::err_expected_lparen_after)
1025 Toks.push_back(Tok);
1027 if (!ConsumeAndStoreUntil(tok::r_paren, Toks,
true)) {
1028 Diag(Tok.getLocation(), diag::err_expected) << tok::r_paren;
1029 Diag(OpenLoc, diag::note_matching) << tok::l_paren;
1035 if (Tok.is(tok::coloncolon)) {
1036 Toks.push_back(Tok);
1039 if (Tok.is(tok::kw_template)) {
1040 Toks.push_back(Tok);
1045 if (Tok.is(tok::identifier)) {
1046 Toks.push_back(Tok);
1052 if (Tok.is(tok::ellipsis) &&
NextToken().
is(tok::l_square)) {
1053 Toks.push_back(Tok);
1055 Toks.push_back(Tok);
1057 if (!ConsumeAndStoreUntil(tok::r_square, Toks,
true)) {
1058 Diag(Tok.getLocation(), diag::err_expected) << tok::r_square;
1059 Diag(OpenLoc, diag::note_matching) << tok::l_square;
1064 }
while (Tok.is(tok::coloncolon));
1066 if (Tok.is(tok::code_completion)) {
1067 Toks.push_back(Tok);
1068 ConsumeCodeCompletionToken();
1069 if (Tok.isOneOf(tok::identifier, tok::coloncolon, tok::kw_decltype)) {
1076 if (Tok.is(tok::comma)) {
1078 Toks.push_back(Tok);
1082 if (Tok.is(tok::less))
1083 MightBeTemplateArgument =
true;
1085 if (MightBeTemplateArgument) {
1092 if (!ConsumeAndStoreUntil(tok::l_paren, tok::l_brace, Toks,
1097 return Diag(Tok.getLocation(), diag::err_expected) << tok::l_brace;
1099 }
else if (Tok.isNot(tok::l_paren) && Tok.isNot(tok::l_brace)) {
1102 return Diag(Tok.getLocation(), diag::err_expected_either)
1103 << tok::l_paren << tok::l_brace;
1105 return Diag(Tok.getLocation(), diag::err_expected) << tok::l_paren;
1109 Toks.push_back(Tok);
1110 bool IsLParen = (
kind == tok::l_paren);
1111 SourceLocation OpenLoc = Tok.getLocation();
1116 assert(
kind == tok::l_brace &&
"Must be left paren or brace here.");
1123 const Token &PreviousToken = Toks[Toks.size() - 2];
1124 if (!MightBeTemplateArgument &&
1125 !PreviousToken.
isOneOf(tok::identifier, tok::greater,
1126 tok::greatergreater)) {
1132 TentativeParsingAction PA(*
this);
1134 !Tok.isOneOf(tok::comma, tok::ellipsis, tok::l_brace)) {
1147 tok::TokenKind CloseKind = IsLParen ? tok::r_paren : tok::r_brace;
1148 if (!ConsumeAndStoreUntil(CloseKind, Toks,
true)) {
1149 Diag(Tok, diag::err_expected) << CloseKind;
1150 Diag(OpenLoc, diag::note_matching) <<
kind;
1155 if (Tok.is(tok::ellipsis)) {
1156 Toks.push_back(Tok);
1162 if (Tok.is(tok::comma)) {
1163 Toks.push_back(Tok);
1165 }
else if (Tok.is(tok::l_brace)) {
1180 Toks.push_back(Tok);
1183 }
else if (!MightBeTemplateArgument) {
1184 return Diag(Tok.getLocation(), diag::err_expected_either) << tok::l_brace
1190bool Parser::ConsumeAndStoreConditional(
CachedTokens &Toks) {
1192 assert(Tok.is(tok::question));
1193 Toks.push_back(Tok);
1196 while (Tok.isNot(tok::colon)) {
1197 if (!ConsumeAndStoreUntil(tok::question, tok::colon, Toks,
1203 if (Tok.is(tok::question) && !ConsumeAndStoreConditional(Toks))
1208 Toks.push_back(Tok);
1213bool Parser::ConsumeAndStoreInitializer(
CachedTokens &Toks,
1216 bool IsFirstToken =
true;
1221 unsigned AngleCount = 0;
1222 unsigned KnownTemplateCount = 0;
1225 switch (Tok.getKind()) {
1229 if (ParenCount == 1 &&
NextToken().
is(tok::r_paren))
1237 if (KnownTemplateCount)
1250 TentativeParsingAction TPA(*
this,
true);
1251 Sema::TentativeAnalysisScope Scope(Actions);
1253 TPResult
Result = TPResult::Error;
1257 Result = TryParseInitDeclaratorList();
1260 if (
Result == TPResult::Ambiguous && Tok.isNot(tok::semi))
1261 Result = TPResult::False;
1265 bool InvalidAsDeclaration =
false;
1266 Result = TryParseParameterDeclarationClause(
1267 &InvalidAsDeclaration,
true);
1270 if (
Result == TPResult::Ambiguous && InvalidAsDeclaration)
1271 Result = TPResult::False;
1281 if (
Result != TPResult::False &&
Result != TPResult::Error)
1286 ++KnownTemplateCount;
1302 if (!ConsumeAndStoreConditional(Toks))
1306 case tok::greatergreatergreater:
1309 if (AngleCount) --AngleCount;
1310 if (KnownTemplateCount) --KnownTemplateCount;
1312 case tok::greatergreater:
1315 if (AngleCount) --AngleCount;
1316 if (KnownTemplateCount) --KnownTemplateCount;
1319 if (AngleCount) --AngleCount;
1320 if (KnownTemplateCount) --KnownTemplateCount;
1323 case tok::kw_template:
1327 Toks.push_back(Tok);
1329 if (Tok.is(tok::identifier)) {
1330 Toks.push_back(Tok);
1332 if (Tok.is(tok::less)) {
1334 ++KnownTemplateCount;
1335 Toks.push_back(Tok);
1341 case tok::kw_operator:
1344 Toks.push_back(Tok);
1346 switch (Tok.getKind()) {
1348 case tok::greatergreatergreater:
1349 case tok::greatergreater:
1352 Toks.push_back(Tok);
1362 Toks.push_back(Tok);
1364 ConsumeAndStoreUntil(tok::r_paren, Toks,
false);
1368 Toks.push_back(Tok);
1370 ConsumeAndStoreUntil(tok::r_square, Toks,
false);
1374 Toks.push_back(Tok);
1376 ConsumeAndStoreUntil(tok::r_brace, Toks,
false);
1388 if (ParenCount && !IsFirstToken)
1390 Toks.push_back(Tok);
1394 if (BracketCount && !IsFirstToken)
1396 Toks.push_back(Tok);
1400 if (BraceCount && !IsFirstToken)
1402 Toks.push_back(Tok);
1406 case tok::code_completion:
1407 Toks.push_back(Tok);
1408 ConsumeCodeCompletionToken();
1411 case tok::string_literal:
1412 case tok::wide_string_literal:
1413 case tok::utf8_string_literal:
1414 case tok::utf16_string_literal:
1415 case tok::utf32_string_literal:
1416 Toks.push_back(Tok);
1417 ConsumeStringToken();
1427 if (Tok.isAnnotation())
1430 Toks.push_back(Tok);
1434 IsFirstToken =
false;
This file defines the classes used to store parsed information about declaration-specifiers and decla...
Defines the C++ template declaration subclasses.
*collection of selector each with an associated kind and an ordered *collection of selectors A selector has a kind
static void collectParamRefs(const ParsedAttributes &Attrs, SmallVectorImpl< const DeclRefExpr * > &Refs)
Collect the references to parameters in Attrs' arguments.
FriendSpecified isFriendSpecified() const
bool hasConstexprSpecifier() const
Decl - This represents one declaration (or definition), e.g.
bool isFunctionOrFunctionTemplate() const
Whether this declaration is a function or function template.
bool isInIdentifierNamespace(unsigned NS) const
FunctionDecl * getAsFunction() LLVM_READONLY
Returns the function itself, or the templated function if this is a function template.
@ IDNS_OrdinaryFriend
This declaration is a friend function.
DeclContext * getDeclContext()
bool isFunctionDeclarator(unsigned &idx) const
isFunctionDeclarator - This method returns true if the declarator is a function declarator (looking t...
FunctionDefinitionKind getFunctionDefinitionKind() const
RAII object that enters a new expression evaluation context.
const ParmVarDecl * getParamDecl(unsigned i) const
QualType getReturnType() const
void setWillHaveBody(bool V=true)
StringRef getName() const
Return the actual identifier string.
[class.mem]p1: "... the class is regarded as complete within
virtual ~LateParsedDeclaration()
virtual void ParseLexedMethodDefs()
virtual void ParseLexedAttributes()
virtual void ParseLexedPragmas()
virtual void ParseLexedMethodDeclarations()
virtual void ParseLexedMemberInitializers()
This represents a decl that may have a name.
bool isCXXInstanceMember() const
Determine whether the given declaration is an instance member of a C++ class.
RAII object that makes sure paren/bracket/brace count is correct after declaration/statement parsing,...
bool hasUnparsedDefaultArg() const
Determines whether this parameter has a default argument that has not yet been parsed.
bool hasUninstantiatedDefaultArg() const
Expr * getUninstantiatedDefaultArg()
ParsedAttr - Represents a syntactic attribute.
ParsedAttributes - A collection of parsed attributes.
void takeAllAppendingFrom(ParsedAttributes &Other)
Introduces zero or more scopes for parsing.
ParseScope - Introduces a new scope for parsing.
Parser - This implements a parser for the C family of languages.
DiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID)
DiagnosticBuilder DiagCompat(SourceLocation Loc, unsigned CompatDiagId)
SourceLocation ConsumeToken()
ConsumeToken - Consume the current 'peek token' and lex the next one.
Parser(Preprocessor &PP, Sema &Actions, bool SkipFunctionBodies)
void EnterScope(unsigned ScopeFlags)
EnterScope - Start a new scope.
SourceLocation ConsumeAnyToken(bool ConsumeCodeCompletionTok=false)
ConsumeAnyToken - Dispatch to the right Consume* method based on the current token type.
bool TryConsumeToken(tok::TokenKind Expected)
Scope * getCurScope() const
friend struct LateParsedAttribute
bool SkipUntil(tok::TokenKind T, SkipUntilFlags Flags=static_cast< SkipUntilFlags >(0))
SkipUntil - Read tokens until we get to the specified token, then consume it (unless StopBeforeMatch ...
void SkipMalformedDecl()
SkipMalformedDecl - Read tokens until we get to some likely good stopping point for skipping past a s...
const LangOptions & getLangOpts() const
friend class ParenBraceBracketBalancer
@ StopBeforeMatch
Stop skipping at specified token, but don't skip the token itself.
@ StopAtSemi
Stop skipping at semicolon.
ExprResult ParseUnevaluatedStringLiteralExpression()
const Token & NextToken()
NextToken - This peeks ahead one token and returns it without consuming it.
ExprResult ParseAssignmentExpression(TypoCorrectionTypeBehavior CorrectionBehavior=TypoCorrectionTypeBehavior::AllowNonTypes)
Parse an expr that doesn't include (top-level) commas.
friend class BalancedDelimiterTracker
A class for parsing a declarator.
const ParsingDeclSpec & getDeclSpec() const
bool isClassScope() const
isClassScope - Return true if this scope is a class/struct/union scope.
@ FunctionPrototypeScope
This is a scope that corresponds to the parameters within a function prototype.
@ CompoundStmtScope
This is a compound statement scope.
@ ClassScope
The scope of a struct/union/class definition.
@ FunctionDeclarationScope
This is a scope that corresponds to the parameters within a function prototype for a function declara...
@ 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.
@ LookupOrdinaryName
Ordinary name lookup, which finds ordinary names (functions, variables, typedefs, etc....
void PushFunctionScope()
Enter a new function scope.
@ PotentiallyEvaluatedIfUsed
The current expression is potentially evaluated, but any declarations referenced inside that expressi...
void ActOnStartDelayedCXXMethodDeclaration(Scope *S, Decl *Method)
ActOnStartDelayedCXXMethodDeclaration - We have completed parsing a top-level (non-nested) C++ class,...
void ActOnDelayedCXXMethodParameter(Scope *S, Decl *Param)
ActOnDelayedCXXMethodParameter - We've already started a delayed C++ method declaration.
Encodes a location in the source.
bool isValid() const
Return true if this is a valid SourceLocation object.
Stmt - This represents one statement.
StringLiteral - This represents a string literal expression, e.g.
Token - This structure provides full information about a lexed token.
SourceLocation getEndLoc() const
static Token createEof(SourceLocation Loc=SourceLocation(), const void *Data=nullptr)
bool isOneOf(Ts... Ks) const
AutoType * getContainedAutoType() const
Get the AutoType whose type will be deduced for a variable with an initializer of this type.
const Expr * getInit() const
Represents a C++11 virt-specifier-seq.
std::variant< struct RequiresDecl, struct HeaderDecl, struct UmbrellaDirDecl, struct ModuleDecl, struct ExcludeDecl, struct ExportDecl, struct ExportAsDecl, struct ExternModuleDecl, struct UseDecl, struct LinkDecl, struct ConfigMacrosDecl, struct ConflictDecl > Decl
All declarations that can appear in a module declaration.
TokenKind
Provides a simple uniform namespace for tokens from all C languages.
Top level wrappers for InstallAPI frontend operations.
bool isa(CodeGen::Address addr)
MutableArrayRef< TemplateParameterList * > MultiTemplateParamsArg
@ ICIS_NoInit
No in-class initializer.
@ Self
'self' clause, allowed on Compute and Combined Constructs, plus 'update'.
@ Delete
'delete' clause, allowed on the 'exit data' construct.
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.
@ ExplicitSpecialization
We are parsing an explicit specialization.
@ NonTemplate
We are not parsing a template at all.
U cast(CodeGen::Address addr)
SmallVector< Token, 4 > CachedTokens
A set of tokens that has been cached for later parsing.
@ Class
The "class" keyword introduces the elaborated-type-specifier.
ActionResult< Expr * > ExprResult
@ Other
Other implicit parameter.
ExceptionSpecificationType
The various types of exception specifications that exist in C++11.
ReenterClassScopeRAII(Parser &P, ParsingClass &Class)
ReenterTemplateScopeRAII(Parser &P, Decl *MaybeTemplated, bool Enter=true)
TemplateParameterDepthRAII CurTemplateDepthTracker
SmallVector< ParmVarDecl *, 4 > ProtoParams
Parameters of the prototype the attribute was written on, kept because late parsing runs after their ...
IdentifierInfo & AttrName
void ParseLexedAttributes() override
SourceLocation AttrNameLoc
SmallVector< Decl *, 2 > Decls
void ParseLexedAttributes() override
An RAII helper that pops function a function scope on exit.