26#include "llvm/ADT/STLForwardCompat.h"
27#include "llvm/Support/Path.h"
28#include "llvm/Support/TimeProfiler.h"
39 explicit ActionCommentHandler(
Sema &S) : S(S) { }
58 PreferredType(&actions.getASTContext(), pp.isCodeCompletionEnabled()),
59 Actions(actions), Diags(PP.getDiagnostics()), StackHandler(Diags),
60 GreaterThanIsOperator(
true), ColonIsSacred(
false),
61 InMessageExpression(
false), ParsingInObjCContainer(
false),
62 TemplateParameterDepth(0) {
66 Actions.CurScope =
nullptr;
68 CurParsedObjCImpl =
nullptr;
72 initializePragmaHandlers();
74 CommentSemaHandler.reset(
new ActionCommentHandler(actions));
80 [
this](StringRef TypeStr, StringRef Context,
SourceLocation IncludeLoc) {
81 return this->ParseTypeFromString(TypeStr, Context, IncludeLoc);
94 unsigned CompatDiagId) {
119 switch (ExpectedTok) {
121 return Tok.
is(tok::colon) || Tok.
is(tok::comma);
122 default:
return false;
126bool Parser::ExpectAndConsume(
tok::TokenKind ExpectedTok,
unsigned DiagID,
128 if (Tok.
is(ExpectedTok) || Tok.
is(tok::code_completion)) {
140 if (DiagID == diag::err_expected)
142 else if (DiagID == diag::err_expected_after)
143 DB << Msg << ExpectedTok;
154 const char *Spelling =
nullptr;
162 if (DiagID == diag::err_expected)
164 else if (DiagID == diag::err_expected_after)
165 DB << Msg << ExpectedTok;
172bool Parser::ExpectAndConsumeSemi(
unsigned DiagID, StringRef TokenUsed) {
176 if (Tok.
is(tok::code_completion)) {
177 handleUnexpectedCodeCompletionToken();
181 if ((Tok.
is(tok::r_paren) || Tok.
is(tok::r_square)) &&
183 Diag(Tok, diag::err_extraneous_token_before_semi)
191 return ExpectAndConsume(tok::semi, DiagID , TokenUsed);
195 if (!Tok.
is(tok::semi))
return;
197 bool HadMultipleSemis =
false;
203 HadMultipleSemis =
true;
212 Diag(StartLoc, diag::warn_cxx98_compat_top_level_semi)
215 Diag(StartLoc, diag::ext_extra_semi_cxx11)
221 Diag(StartLoc, diag::ext_extra_semi)
228 Diag(StartLoc, diag::warn_extra_semi_after_mem_fn_def)
232bool Parser::expectIdentifier() {
233 if (Tok.
is(tok::identifier))
237 Diag(Tok, diag::err_expected_token_instead_of_objcxx_keyword)
243 Diag(Tok, diag::err_expected) << tok::identifier;
258 Diag(FirstTokLoc, diag::warn_compound_token_split_by_macro)
259 << (FirstTokKind == Tok.
getKind()) << FirstTokKind << Tok.
getKind()
260 <<
static_cast<int>(Op) <<
SourceRange(FirstTokLoc);
261 Diag(SecondTokLoc, diag::note_compound_token_split_second_token_here)
271 SpaceLoc = FirstTokLoc;
272 Diag(SpaceLoc, diag::warn_compound_token_split_by_whitespace)
273 << (FirstTokKind == Tok.
getKind()) << FirstTokKind << Tok.
getKind()
274 <<
static_cast<int>(Op) <<
SourceRange(FirstTokLoc, SecondTokLoc);
284 return (
static_cast<unsigned>(L) &
static_cast<unsigned>(R)) != 0;
290 bool isFirstTokenSkipped =
true;
293 for (
unsigned i = 0, NumToks = Toks.size(); i != NumToks; ++i) {
294 if (Tok.
is(Toks[i])) {
307 if (Toks.size() == 1 && Toks[0] == tok::eof &&
310 while (Tok.
isNot(tok::eof))
320 case tok::annot_pragma_openmp:
321 case tok::annot_attr_openmp:
322 case tok::annot_pragma_openmp_end:
324 if (OpenMPDirectiveParsing)
326 ConsumeAnnotationToken();
328 case tok::annot_pragma_openacc:
329 case tok::annot_pragma_openacc_end:
331 if (OpenACCDirectiveParsing)
333 ConsumeAnnotationToken();
335 case tok::annot_module_begin:
336 case tok::annot_module_end:
337 case tok::annot_module_include:
338 case tok::annot_repl_input_end:
344 case tok::code_completion:
346 handleUnexpectedCodeCompletionToken();
388 if (ParenCount && !isFirstTokenSkipped)
393 if (BracketCount && !isFirstTokenSkipped)
398 if (BraceCount && !isFirstTokenSkipped)
412 isFirstTokenSkipped =
false;
421 if (NumCachedScopes) {
422 Scope *N = ScopeCache[--NumCachedScopes];
424 Actions.CurScope = N;
438 Actions.CurScope = OldScope->
getParent();
440 if (NumCachedScopes == ScopeCacheSize)
443 ScopeCache[NumCachedScopes++] = OldScope;
446Parser::ParseScopeFlags::ParseScopeFlags(
Parser *
Self,
unsigned ScopeFlags,
448 : CurScope(ManageFlags ?
Self->getCurScope() : nullptr) {
450 OldFlags = CurScope->getFlags();
451 CurScope->setFlags(ScopeFlags);
455Parser::ParseScopeFlags::~ParseScopeFlags() {
457 CurScope->setFlags(OldFlags);
468 Actions.CurScope =
nullptr;
471 for (
unsigned i = 0, e = NumCachedScopes; i != e; ++i)
472 delete ScopeCache[i];
474 resetPragmaHandlers();
480 DestroyTemplateIds();
485 assert(
getCurScope() ==
nullptr &&
"A scope is already active?");
512 Ident_instancetype =
nullptr;
513 Ident_final =
nullptr;
514 Ident_sealed =
nullptr;
515 Ident_abstract =
nullptr;
516 Ident_override =
nullptr;
517 Ident_trivially_relocatable_if_eligible =
nullptr;
518 Ident_replaceable_if_eligible =
nullptr;
519 Ident_GNU_final =
nullptr;
520 Ident_import =
nullptr;
521 Ident_module =
nullptr;
525 Ident_vector =
nullptr;
526 Ident_bool =
nullptr;
527 Ident_Bool =
nullptr;
528 Ident_pixel =
nullptr;
537 Ident_introduced =
nullptr;
538 Ident_deprecated =
nullptr;
539 Ident_obsoleted =
nullptr;
540 Ident_unavailable =
nullptr;
541 Ident_strict =
nullptr;
542 Ident_replacement =
nullptr;
544 Ident_language = Ident_defined_in = Ident_generated_declaration = Ident_USR =
547 Ident__except =
nullptr;
549 Ident__exception_code = Ident__exception_info =
nullptr;
550 Ident__abnormal_termination = Ident___exception_code =
nullptr;
551 Ident___exception_info = Ident___abnormal_termination =
nullptr;
552 Ident_GetExceptionCode = Ident_GetExceptionInfo =
nullptr;
553 Ident_AbnormalTermination =
nullptr;
566 PP.
SetPoisonReason(Ident__exception_code,diag::err_seh___except_block);
567 PP.
SetPoisonReason(Ident___exception_code,diag::err_seh___except_block);
568 PP.
SetPoisonReason(Ident_GetExceptionCode,diag::err_seh___except_block);
569 PP.
SetPoisonReason(Ident__exception_info,diag::err_seh___except_filter);
570 PP.
SetPoisonReason(Ident___exception_info,diag::err_seh___except_filter);
571 PP.
SetPoisonReason(Ident_GetExceptionInfo,diag::err_seh___except_filter);
572 PP.
SetPoisonReason(Ident__abnormal_termination,diag::err_seh___finally_block);
573 PP.
SetPoisonReason(Ident___abnormal_termination,diag::err_seh___finally_block);
574 PP.
SetPoisonReason(Ident_AbnormalTermination,diag::err_seh___finally_block);
588void Parser::DestroyTemplateIds() {
610 Diag(diag::ext_empty_translation_unit);
612 return NoTopLevelDecls;
617 DestroyTemplateIdAnnotationsRAIIObj CleanupRAII(*
this);
621 case tok::annot_pragma_unused:
622 HandlePragmaUnused();
636 case tok::identifier: {
638 if ((II == Ident_module || II == Ident_import) &&
640 if (II == Ident_module)
655 Result = ParseModuleDecl(ImportState);
665 case tok::annot_module_include: {
678 ConsumeAnnotationToken();
682 case tok::annot_module_begin:
686 ConsumeAnnotationToken();
690 case tok::annot_module_end:
694 ConsumeAnnotationToken();
699 case tok::annot_repl_input_end:
706 PP.
Diag(OverrideLoc, diag::note_max_tokens_total_override);
716 case tok::identifier:
741 while (MaybeParseCXX11Attributes(DeclAttrs) ||
742 MaybeParseGNUAttributes(DeclSpecAttrs))
745 Result = ParseExternalDeclaration(DeclAttrs, DeclSpecAttrs);
755 else if (ImportState ==
767 DestroyTemplateIdAnnotationsRAIIObj CleanupRAII(*
this);
775 Decl *SingleDecl =
nullptr;
777 case tok::annot_pragma_vis:
778 HandlePragmaVisibility();
780 case tok::annot_pragma_pack:
783 case tok::annot_pragma_msstruct:
784 HandlePragmaMSStruct();
786 case tok::annot_pragma_align:
789 case tok::annot_pragma_weak:
792 case tok::annot_pragma_weakalias:
793 HandlePragmaWeakAlias();
795 case tok::annot_pragma_redefine_extname:
796 HandlePragmaRedefineExtname();
798 case tok::annot_pragma_fp_contract:
799 HandlePragmaFPContract();
801 case tok::annot_pragma_fenv_access:
802 case tok::annot_pragma_fenv_access_ms:
803 HandlePragmaFEnvAccess();
805 case tok::annot_pragma_fenv_round:
806 HandlePragmaFEnvRound();
808 case tok::annot_pragma_cx_limited_range:
809 HandlePragmaCXLimitedRange();
811 case tok::annot_pragma_float_control:
812 HandlePragmaFloatControl();
814 case tok::annot_pragma_fp:
817 case tok::annot_pragma_opencl_extension:
818 HandlePragmaOpenCLExtension();
820 case tok::annot_attr_openmp:
821 case tok::annot_pragma_openmp: {
823 return ParseOpenMPDeclarativeDirectiveWithExtDecl(AS, Attrs);
825 case tok::annot_pragma_openacc: {
830 case tok::annot_pragma_ms_pointers_to_members:
831 HandlePragmaMSPointersToMembers();
833 case tok::annot_pragma_ms_vtordisp:
834 HandlePragmaMSVtorDisp();
836 case tok::annot_pragma_ms_pragma:
837 HandlePragmaMSPragma();
839 case tok::annot_pragma_dump:
842 case tok::annot_pragma_attribute:
843 HandlePragmaAttribute();
852 Diag(Tok, diag::err_extraneous_closing_brace);
856 Diag(Tok, diag::err_expected_external_declaration);
858 case tok::kw___extension__: {
862 return ParseExternalDeclaration(Attrs, DeclSpecAttrs);
865 ProhibitAttributes(Attrs);
876 const auto *SL = cast<StringLiteral>(
Result.get());
877 if (!SL->getString().trim().empty())
878 Diag(StartLoc, diag::err_gnu_inline_asm_disabled);
881 ExpectAndConsume(tok::semi, diag::err_expected_after,
882 "top-level asm block");
890 return ParseObjCAtDirectives(Attrs, DeclSpecAttrs);
894 Diag(Tok, diag::err_expected_external_declaration);
898 SingleDecl = ParseObjCMethodDefinition();
900 case tok::code_completion:
902 if (CurParsedObjCImpl) {
911 if (CurParsedObjCImpl) {
920 case tok::kw_import: {
923 llvm_unreachable(
"not expecting a c++20 import here");
924 ProhibitAttributes(Attrs);
930 ProhibitAttributes(Attrs);
931 SingleDecl = ParseExportDeclaration();
938 case tok::kw_namespace:
939 case tok::kw_typedef:
940 case tok::kw_template:
941 case tok::kw_static_assert:
942 case tok::kw__Static_assert:
950 case tok::kw_cbuffer:
951 case tok::kw_tbuffer:
976 if (NextKind == tok::kw_namespace) {
984 if (NextKind == tok::kw_template) {
996 ProhibitAttributes(Attrs);
997 ProhibitAttributes(DeclSpecAttrs);
1002 diag::warn_cxx98_compat_extern_template :
1003 diag::ext_extern_template) <<
SourceRange(ExternLoc, TemplateLoc);
1006 TemplateLoc, DeclEnd, Attrs);
1010 case tok::kw___if_exists:
1011 case tok::kw___if_not_exists:
1012 ParseMicrosoftIfExistsExternalDeclaration();
1015 case tok::kw_module:
1016 Diag(Tok, diag::err_unexpected_module_decl);
1027 !isDeclarationStatement(
true))
1028 return ParseTopLevelStmtDecl();
1032 return ParseDeclarationOrFunctionDefinition(Attrs, DeclSpecAttrs, DS);
1040bool Parser::isDeclarationAfterDeclarator() {
1044 if (KW.
is(tok::kw_default) || KW.
is(tok::kw_delete))
1048 return Tok.
is(tok::equal) ||
1049 Tok.
is(tok::comma) ||
1050 Tok.
is(tok::semi) ||
1051 Tok.
is(tok::kw_asm) ||
1052 Tok.
is(tok::kw___attribute) ||
1054 Tok.
is(tok::l_paren));
1059 if (Tok.
is(tok::l_brace))
1069 return KW.
is(tok::kw_default) || KW.
is(tok::kw_delete);
1072 return Tok.
is(tok::colon) ||
1073 Tok.
is(tok::kw_try);
1083 "expected uninitialised source range");
1088 ParsedTemplateInfo TemplateInfo;
1091 ParseDeclarationSpecifiers(DS, TemplateInfo, AS,
1092 DeclSpecContext::DSC_top_level);
1097 DS, AS, DeclSpecContext::DSC_top_level))
1102 if (Tok.
is(tok::semi)) {
1117 llvm_unreachable(
"we only expect to get the length of the class/struct/union/enum");
1127 ProhibitAttributes(Attrs, CorrectLocationForAttributes);
1135 Decl* decls[] = {AnonRecord, TheDecl};
1152 Diag(Tok, diag::err_objc_unexpected_attr);
1160 const char *PrevSpec =
nullptr;
1164 Diag(AtLoc, DiagID) << PrevSpec;
1167 return ParseObjCAtProtocolDeclaration(AtLoc, DS.
getAttributes());
1170 return ParseObjCAtImplementationDeclaration(AtLoc, DS.
getAttributes());
1173 ParseObjCAtInterfaceDeclaration(AtLoc, DS.
getAttributes()));
1182 ProhibitAttributes(Attrs);
1195 llvm::TimeTraceScope TimeScope(
"ParseDeclarationOrFunctionDefinition", [&]() {
1201 return ParseDeclOrFunctionDefInternal(Attrs, DeclSpecAttrs, *DS, AS);
1209 return ParseDeclOrFunctionDefInternal(Attrs, DeclSpecAttrs, PDS, AS);
1214 const ParsedTemplateInfo &TemplateInfo,
1215 LateParsedAttrList *LateParsedAttrs) {
1216 llvm::TimeTraceScope TimeScope(
"ParseFunctionDefinition", [&]() {
1223 TemplateParameterDepthRAII CurTemplateDepthTracker(TemplateParameterDepth);
1228 if (
getLangOpts().isImplicitIntRequired() &&
D.getDeclSpec().isEmpty()) {
1229 Diag(
D.getIdentifierLoc(), diag::warn_missing_type_specifier)
1231 const char *PrevSpec;
1235 D.getIdentifierLoc(),
1245 ParseKNRParamDeclarations(
D);
1249 if (Tok.
isNot(tok::l_brace) &&
1251 (Tok.
isNot(tok::colon) && Tok.
isNot(tok::kw_try) &&
1252 Tok.
isNot(tok::equal)))) {
1253 Diag(Tok, diag::err_expected_fn_body);
1259 if (Tok.
isNot(tok::l_brace))
1265 if (Tok.
isNot(tok::equal)) {
1267 if (AL.isKnownToGCC() && !AL.isStandardAttributeSyntax())
1268 Diag(AL.getLoc(), diag::warn_attribute_on_function_definition) << AL;
1286 D.getMutableDeclSpec().abort();
1289 trySkippingFunctionBody()) {
1295 LexTemplateFunctionForLateParsing(Toks);
1304 else if (CurParsedObjCImpl &&
1305 !TemplateInfo.TemplateParams &&
1306 (Tok.
is(tok::l_brace) || Tok.
is(tok::kw_try) ||
1307 Tok.
is(tok::colon)) &&
1316 D.complete(FuncDecl);
1317 D.getMutableDeclSpec().abort();
1320 StashAwayMethodOrFunctionBodyTokens(FuncDecl);
1321 CurParsedObjCImpl->HasCFunction =
true;
1341 ? diag::warn_cxx98_compat_defaulted_deleted_function
1342 : diag::ext_defaulted_deleted_function)
1345 DeletedMessage = ParseCXXDeletedFunctionMessage();
1348 ? diag::warn_cxx98_compat_defaulted_deleted_function
1349 : diag::ext_defaulted_deleted_function)
1353 llvm_unreachable(
"function definition after = not 'delete' or 'default'");
1356 if (Tok.
is(tok::comma)) {
1357 Diag(KWLoc, diag::err_default_delete_in_multiple_declaration)
1360 }
else if (ExpectAndConsume(tok::semi, diag::err_expected_after,
1374 TemplateInfo.TemplateParams
1375 ? *TemplateInfo.TemplateParams
1377 &SkipBody, BodyKind);
1403 D.getMutableDeclSpec().abort();
1407 Stmt *GeneratedBody = Res ? Res->
getBody() :
nullptr;
1414 if (
const auto *
Template = dyn_cast_if_present<FunctionTemplateDecl>(Res);
1416 Template->getTemplateParameters()->getParam(0)->isImplicit())
1419 CurTemplateDepthTracker.addDepth(1);
1422 if (LateParsedAttrs)
1423 ParseLexedAttributeList(*LateParsedAttrs, Res,
false,
true);
1426 trySkippingFunctionBody()) {
1432 if (Tok.
is(tok::kw_try))
1433 return ParseFunctionTryBlock(Res, BodyScope);
1437 if (Tok.
is(tok::colon)) {
1438 ParseConstructorInitializer(Res);
1441 if (!Tok.
is(tok::l_brace)) {
1449 return ParseFunctionStatementBody(Res, BodyScope);
1452void Parser::SkipFunctionBody() {
1453 if (Tok.
is(tok::equal)) {
1458 bool IsFunctionTryBlock = Tok.
is(tok::kw_try);
1459 if (IsFunctionTryBlock)
1463 if (ConsumeAndStoreFunctionPrologue(Skipped))
1467 while (IsFunctionTryBlock && Tok.
is(tok::kw_catch)) {
1474void Parser::ParseKNRParamDeclarations(
Declarator &
D) {
1489 ParsedTemplateInfo TemplateInfo;
1490 ParseDeclarationSpecifiers(DS, TemplateInfo);
1498 Diag(DSStart, diag::err_declaration_does_not_declare_param);
1507 diag::err_invalid_storage_class_in_func_decl);
1512 diag::err_invalid_storage_class_in_func_decl);
1519 ParseDeclarator(ParmDeclarator);
1524 MaybeParseGNUAttributes(ParmDeclarator);
1532 ParmDeclarator.getIdentifier()) {
1536 for (
unsigned i = 0; ; ++i) {
1540 Diag(ParmDeclarator.getIdentifierLoc(), diag::err_no_matching_param)
1541 << ParmDeclarator.getIdentifier();
1545 if (FTI.
Params[i].
Ident == ParmDeclarator.getIdentifier()) {
1548 Diag(ParmDeclarator.getIdentifierLoc(),
1549 diag::err_param_redefinition)
1550 << ParmDeclarator.getIdentifier();
1561 if (Tok.
isNot(tok::comma))
1564 ParmDeclarator.clear();
1570 ParseDeclarator(ParmDeclarator);
1574 if (!ExpectAndConsumeSemi(diag::err_expected_semi_declaration))
1587ExprResult Parser::ParseAsmStringLiteral(
bool ForAsmLabel) {
1590 if (isTokenStringLiteral()) {
1595 const auto *SL = cast<StringLiteral>(AsmString.
get());
1596 if (!SL->isOrdinary()) {
1597 Diag(Tok, diag::err_asm_operand_wide_string_literal)
1598 << SL->isWide() << SL->getSourceRange();
1602 Tok.
is(tok::l_paren)) {
1609 AsmString = ParseParenExpression(
1618 Diag(Tok, diag::err_asm_expected_string) << (
1619 (
getLangOpts().CPlusPlus11 && !ForAsmLabel) ? 0 : 1);
1626 assert(Tok.
is(tok::kw_asm) &&
"Not an asm!");
1629 if (isGNUAsmQualifier(Tok)) {
1633 Diag(Tok, diag::err_global_asm_qualifier_ignored)
1634 << GNUAsmQualifiers::getQualifierName(getGNUAsmQualifier(Tok))
1640 if (
T.consumeOpen()) {
1641 Diag(Tok, diag::err_expected_lparen_after) <<
"asm";
1647 if (!
Result.isInvalid()) {
1651 *EndLoc =
T.getCloseLocation();
1662 assert(tok.
is(tok::annot_template_id) &&
"Expected template-id token");
1668void Parser::AnnotateScopeToken(
CXXScopeSpec &SS,
bool IsNewAnnotation) {
1675 Tok.
setKind(tok::annot_cxxscope);
1682 if (IsNewAnnotation)
1689 assert(Tok.
is(tok::identifier) || Tok.
is(tok::annot_cxxscope));
1691 const bool EnteringContext =
false;
1692 const bool WasScopeAnnotation = Tok.
is(tok::annot_cxxscope);
1696 ParseOptionalCXXScopeSpecifier(SS,
nullptr,
1703 AllowImplicitTypename))
1713 if (isTentativelyDeclared(Name) && SS.
isEmpty()) {
1717 AllowImplicitTypename))
1737 isTemplateArgumentList(1) == TPResult::False) {
1739 Token FakeNext = Next;
1740 FakeNext.
setKind(tok::unknown);
1743 SS.
isEmpty() ? CCC :
nullptr);
1746 switch (Classification.
getKind()) {
1753 Tok.
setKind(Name->getTokenID());
1756 AnnotateScopeToken(SS, !WasScopeAnnotation);
1765 if (TryAltiVecVectorToken())
1789 else if (Tok.
is(tok::eof))
1793 Tok.
setKind(tok::annot_typename);
1794 setTypeAnnotation(Tok, Ty);
1802 Tok.
setKind(tok::annot_overload_set);
1811 if (TryAltiVecVectorToken())
1816 Tok.
setKind(tok::annot_non_type);
1822 AnnotateScopeToken(SS, !WasScopeAnnotation);
1829 ? tok::annot_non_type_undeclared
1830 : tok::annot_non_type_dependent);
1831 setIdentifierAnnotation(Tok, Name);
1836 AnnotateScopeToken(SS, !WasScopeAnnotation);
1840 if (Next.isNot(tok::less)) {
1844 AnnotateScopeToken(SS, !WasScopeAnnotation);
1852 bool IsConceptName =
1857 Id.setIdentifier(Name, NameLoc);
1858 if (Next.is(tok::less))
1860 if (AnnotateTemplateIdToken(
1867 AnnotateScopeToken(SS, !WasScopeAnnotation);
1874 AnnotateScopeToken(SS, !WasScopeAnnotation);
1883bool Parser::TryKeywordIdentFallback(
bool DisableKeyword) {
1884 assert(Tok.
isNot(tok::identifier));
1885 Diag(Tok, diag::ext_keyword_as_ident)
1896 assert((Tok.
is(tok::identifier) || Tok.
is(tok::coloncolon) ||
1897 Tok.
is(tok::kw_typename) || Tok.
is(tok::annot_cxxscope) ||
1898 Tok.
is(tok::kw_decltype) || Tok.
is(tok::annot_template_id) ||
1899 Tok.
is(tok::kw___super) || Tok.
is(tok::kw_auto) ||
1900 Tok.
is(tok::annot_pack_indexing_type)) &&
1901 "Cannot be a type or scope token!");
1903 if (Tok.
is(tok::kw_typename)) {
1912 PP.
Lex(TypedefToken);
1917 Diag(Tok.
getLocation(), diag::warn_expected_qualified_after_typename);
1929 if (ParseOptionalCXXScopeSpecifier(SS,
nullptr,
1935 if (Tok.
is(tok::identifier) || Tok.
is(tok::annot_template_id) ||
1936 Tok.
is(tok::annot_decltype)) {
1938 if (Tok.
is(tok::annot_decltype) ||
1941 unsigned DiagID = diag::err_expected_qualified_after_typename;
1945 DiagID = diag::warn_expected_qualified_after_typename;
1957 bool TemplateKWPresent =
false;
1958 if (Tok.
is(tok::kw_template)) {
1960 TemplateKWPresent =
true;
1964 if (Tok.
is(tok::identifier)) {
1965 if (TemplateKWPresent &&
NextToken().isNot(tok::less)) {
1967 diag::missing_template_arg_list_after_template_kw);
1973 }
else if (Tok.
is(tok::annot_template_id)) {
1976 Diag(Tok, diag::err_typename_refers_to_non_type_template)
1990 TemplateArgsPtr, TemplateId->
RAngleLoc);
1992 Diag(Tok, diag::err_expected_type_name_after_typename)
1998 Tok.
setKind(tok::annot_typename);
1999 setTypeAnnotation(Tok, Ty);
2007 bool WasScopeAnnotation = Tok.
is(tok::annot_cxxscope);
2011 if (ParseOptionalCXXScopeSpecifier(SS,
nullptr,
2017 AllowImplicitTypename);
2023 if (Tok.
is(tok::identifier)) {
2027 false,
NextToken().is(tok::period),
nullptr,
2030 true, AllowImplicitTypename)) {
2050 else if (Tok.
is(tok::eof))
2056 Tok.
setKind(tok::annot_typename);
2057 setTypeAnnotation(Tok, Ty);
2081 bool MemberOfUnknownSpecialization;
2086 MemberOfUnknownSpecialization)) {
2090 isTemplateArgumentList(1) != TPResult::False) {
2110 if (Tok.
is(tok::annot_template_id)) {
2117 AnnotateTemplateIdTokenAsType(SS, AllowImplicitTypename);
2124 Tok.
is(tok::coloncolon)) {
2133 AnnotateScopeToken(SS, IsNewScope);
2139 "Call sites of this function should be guarded by checking for C++");
2143 if (ParseOptionalCXXScopeSpecifier(SS,
nullptr,
2150 AnnotateScopeToken(SS,
true);
2154bool Parser::isTokenEqualOrEqualTypo() {
2160 case tok::starequal:
2161 case tok::plusequal:
2162 case tok::minusequal:
2163 case tok::exclaimequal:
2164 case tok::slashequal:
2165 case tok::percentequal:
2166 case tok::lessequal:
2167 case tok::lesslessequal:
2168 case tok::greaterequal:
2169 case tok::greatergreaterequal:
2170 case tok::caretequal:
2171 case tok::pipeequal:
2172 case tok::equalequal:
2173 Diag(Tok, diag::err_invalid_token_after_declarator_suggest_equal)
2183 assert(Tok.
is(tok::code_completion));
2187 if (S->isFunctionScope()) {
2191 return PrevTokLocation;
2194 if (S->isClassScope()) {
2198 return PrevTokLocation;
2205 return PrevTokLocation;
2210void Parser::CodeCompleteDirective(
bool InConditional) {
2214void Parser::CodeCompleteInConditionalExclusion() {
2219void Parser::CodeCompleteMacroName(
bool IsDefinition) {
2223void Parser::CodeCompletePreprocessorExpression() {
2229 unsigned ArgumentIndex) {
2234void Parser::CodeCompleteIncludedFile(llvm::StringRef Dir,
bool IsAngled) {
2238void Parser::CodeCompleteNaturalLanguage() {
2242bool Parser::ParseMicrosoftIfExistsCondition(IfExistsCondition&
Result) {
2243 assert((Tok.
is(tok::kw___if_exists) || Tok.
is(tok::kw___if_not_exists)) &&
2244 "Expected '__if_exists' or '__if_not_exists'");
2245 Result.IsIfExists = Tok.
is(tok::kw___if_exists);
2249 if (
T.consumeOpen()) {
2250 Diag(Tok, diag::err_expected_lparen_after)
2251 << (
Result.IsIfExists?
"__if_exists" :
"__if_not_exists");
2257 ParseOptionalCXXScopeSpecifier(
Result.SS,
nullptr,
2262 if (
Result.SS.isInvalid()) {
2273 false, &TemplateKWLoc,
2279 if (
T.consumeClose())
2307void Parser::ParseMicrosoftIfExistsExternalDeclaration() {
2308 IfExistsCondition
Result;
2309 if (ParseMicrosoftIfExistsCondition(
Result))
2313 if (
Braces.consumeOpen()) {
2314 Diag(Tok, diag::err_expected) << tok::l_brace;
2318 switch (
Result.Behavior) {
2324 llvm_unreachable(
"Cannot have a dependent external declaration");
2333 while (Tok.
isNot(tok::r_brace) && !isEofOrEom()) {
2335 MaybeParseCXX11Attributes(Attrs);
2346 Token Introducer = Tok;
2354 (Tok.
is(tok::kw_module) ||
2356 "not a module declaration");
2361 DiagnoseAndSkipCXX11Attributes();
2368 Diag(StartLoc, diag::err_global_module_introducer_not_at_start)
2373 Diag(StartLoc, diag::err_module_fragment_exported)
2384 Diag(StartLoc, diag::err_module_fragment_exported)
2389 DiagnoseAndSkipCXX11Attributes();
2390 ExpectAndConsumeSemi(diag::err_private_module_fragment_expected_semi);
2398 if (ParseModuleName(ModuleLoc,
Path,
false))
2403 if (Tok.
is(tok::colon)) {
2406 Diag(ColonLoc, diag::err_unsupported_module_partition)
2407 <<
SourceRange(ColonLoc, Partition.back().getLoc());
2409 else if (ParseModuleName(ModuleLoc, Partition,
false))
2415 MaybeParseCXX11Attributes(Attrs);
2416 ProhibitCXX11Attributes(Attrs, diag::err_attribute_not_module_attr,
2417 diag::err_keyword_not_module_attr,
2421 ExpectAndConsumeSemi(diag::err_module_expected_semi);
2437 "Improper start to module import");
2443 bool IsPartition =
false;
2444 Module *HeaderUnit =
nullptr;
2445 if (Tok.
is(tok::header_name)) {
2450 }
else if (Tok.
is(tok::annot_header_unit)) {
2453 ConsumeAnnotationToken();
2454 }
else if (Tok.
is(tok::colon)) {
2457 Diag(ColonLoc, diag::err_unsupported_module_partition)
2460 else if (ParseModuleName(ColonLoc,
Path,
true))
2465 if (ParseModuleName(ImportLoc,
Path,
true))
2470 MaybeParseCXX11Attributes(Attrs);
2472 ProhibitCXX11Attributes(Attrs, diag::err_attribute_not_import_attr,
2473 diag::err_keyword_not_import_attr,
2484 bool SeenError =
true;
2485 switch (ImportState) {
2497 Diag(ImportLoc, diag::err_partition_import_outside_module);
2509 if (IsPartition || (HeaderUnit && HeaderUnit->
Kind !=
2511 Diag(ImportLoc, diag::err_import_in_wrong_fragment)
2520 Diag(ImportLoc, diag::err_import_not_allowed_here);
2525 ExpectAndConsumeSemi(diag::err_module_expected_semi);
2535 else if (!
Path.empty())
2543 if (IsObjCAtImport && AtLoc.
isValid()) {
2546 if (FE && llvm::sys::path::parent_path(FE->getDir().getName())
2547 .ends_with(
".framework"))
2548 Diags.
Report(AtLoc, diag::warn_atimport_in_framework_header);
2559 if (!Tok.
is(tok::identifier)) {
2560 if (Tok.
is(tok::code_completion)) {
2566 Diag(Tok, diag::err_module_expected_ident) << IsImport;
2575 if (Tok.
isNot(tok::period))
2582bool Parser::parseMisplacedModuleImport() {
2585 case tok::annot_module_end:
2589 if (MisplacedModuleBeginCount) {
2590 --MisplacedModuleBeginCount;
2594 ConsumeAnnotationToken();
2601 case tok::annot_module_begin:
2606 ConsumeAnnotationToken();
2607 ++MisplacedModuleBeginCount;
2609 case tok::annot_module_include:
2615 ConsumeAnnotationToken();
2625void Parser::diagnoseUseOfC11Keyword(
const Token &Tok) {
2630 : diag::ext_c11_feature)
2634bool BalancedDelimiterTracker::diagnoseOverflow() {
2635 P.
Diag(P.Tok, diag::err_bracket_depth_exceeded)
2637 P.
Diag(P.Tok, diag::note_bracket_depth);
2646 if (P.ExpectAndConsume(Kind, DiagID, Msg)) {
2647 if (SkipToTok != tok::unknown)
2655 return diagnoseOverflow();
2658bool BalancedDelimiterTracker::diagnoseMissingClose() {
2659 assert(!P.Tok.
is(Close) &&
"Should have consumed closing delimiter");
2661 if (P.Tok.
is(tok::annot_module_end))
2662 P.
Diag(P.Tok, diag::err_missing_before_module_end) << Close;
2664 P.
Diag(P.Tok, diag::err_expected) << Close;
2665 P.
Diag(LOpen, diag::note_matching) << Kind;
2669 if (P.Tok.
isNot(tok::r_paren) && P.Tok.
isNot(tok::r_brace) &&
2670 P.Tok.
isNot(tok::r_square) &&
Defines the clang::ASTContext interface.
This file provides some common utility functions for processing Lambda related AST Constructs.
static Decl::Kind getKind(const Decl *D)
Defines the C++ template declaration subclasses.
static bool IsCommonTypo(tok::TokenKind ExpectedTok, const Token &Tok)
static bool HasFlagsSet(Parser::SkipUntilFlags L, Parser::SkipUntilFlags R)
This file declares facilities that support code completion.
Defines a utilitiy for warning once when close to out of stack space.
virtual bool HandleTopLevelDecl(DeclGroupRef D)
HandleTopLevelDecl - Handle the specified top-level declaration.
SourceManager & getSourceManager()
const clang::PrintingPolicy & getPrintingPolicy() const
ExternalASTSource * getExternalSource() const
Retrieve a pointer to the external AST source associated with this AST context, if any.
The result of parsing/analyzing an expression, statement etc.
RAII class that helps handle the parsing of an open/close delimiter pair, such as braces { ....
bool expectAndConsume(unsigned DiagID=diag::err_expected, const char *Msg="", tok::TokenKind SkipToTok=tok::unknown)
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.
SourceRange getRange() const
SourceLocation getBeginLoc() const
bool isInvalid() const
An error occurred during parsing of the scope specifier.
bool isEmpty() const
No scope specifier.
Base class for callback objects used by Sema::CorrectTypo to check the validity of a potential typo c...
bool isTranslationUnit() const
Captures information about "declaration specifiers".
void ClearStorageClassSpecs()
TST getTypeSpecType() const
SourceLocation getStorageClassSpecLoc() const
SCS getStorageClassSpec() const
bool SetTypeSpecType(TST T, SourceLocation Loc, const char *&PrevSpec, unsigned &DiagID, const PrintingPolicy &Policy)
SourceRange getSourceRange() const LLVM_READONLY
void SetRangeEnd(SourceLocation Loc)
static const TST TST_interface
void SetRangeStart(SourceLocation Loc)
static const TST TST_union
TSCS getThreadStorageClassSpec() const
ParsedAttributes & getAttributes()
static const TST TST_enum
static bool isDeclRep(TST T)
static const TST TST_class
bool hasTagDefinition() const
unsigned getParsedSpecifiers() const
Return a bitmask of which flavors of specifiers this DeclSpec includes.
static const TSCS TSCS_unspecified
static const char * getSpecifierName(DeclSpec::TST T, const PrintingPolicy &Policy)
Turn a type-specifier-type into a string like "_Bool" or "union".
SourceLocation getThreadStorageClassSpecLoc() const
Decl * getRepAsDecl() const
static const TST TST_unspecified
SourceLocation getTypeSpecTypeLoc() const
void takeAttributesFrom(ParsedAttributes &attrs)
@ PQ_StorageClassSpecifier
static const TST TST_struct
Decl - This represents one declaration (or definition), e.g.
virtual Stmt * getBody() const
getBody - If this Decl represents a declaration for a body of code, such as a function or method defi...
FunctionDecl * getAsFunction() LLVM_READONLY
Returns the function itself, or the templated function if this is a function template.
virtual SourceRange getSourceRange() const LLVM_READONLY
Source range that this declaration covers.
Information about one declarator, including the parsed type information and the identifier.
bool isFunctionDeclarator(unsigned &idx) const
isFunctionDeclarator - This method returns true if the declarator is a function declarator (looking t...
DeclaratorChunk::FunctionTypeInfo & getFunctionTypeInfo()
getFunctionTypeInfo - Retrieves the function type info object (looking through parentheses).
A little helper class used to produce diagnostics.
static unsigned getCXXCompatDiagId(const LangOptions &LangOpts, unsigned CompatDiagId)
Get the appropriate diagnostic Id to use for issuing a compatibility diagnostic.
DiagnosticBuilder Report(SourceLocation Loc, unsigned DiagID)
Issue the message to the client.
RAII object that enters a new expression evaluation context.
ExtensionRAIIObject - This saves the state of extension warnings when constructed and disables them.
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.
One of these records is kept for each identifier that is lexed.
void revertTokenIDToIdentifier()
Revert TokenID to tok::identifier; used for GNU libstdc++ 4.2 compatibility.
A simple pair of identifier info and location.
IdentifierInfo & get(StringRef Name)
Return the identifier token info for the specified named identifier.
Describes a module import declaration, which makes the contents of the named module visible in the cu...
Encapsulates the data about a macro definition (e.g.
Describes a module or submodule.
ModuleKind Kind
The kind of this module.
bool isHeaderUnit() const
Is this module a header unit.
@ ModuleHeaderUnit
This is a C++20 header unit.
Wrapper for void* pointer.
static OpaquePtr make(TemplateName P)
RAII object that makes sure paren/bracket/brace count is correct after declaration/statement parsing,...
ParsedAttr - Represents a syntactic attribute.
static const ParsedAttributesView & none()
ParsedAttributes - A collection of parsed attributes.
Parser - This implements a parser for the C family of languages.
DiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID)
SourceLocation getEndOfPreviousToken() const
bool TryAnnotateTypeOrScopeTokenAfterScopeSpec(CXXScopeSpec &SS, bool IsNewScope, ImplicitTypenameContext AllowImplicitTypename)
Try to annotate a type or scope token, having already parsed an optional scope specifier.
DiagnosticBuilder DiagCompat(SourceLocation Loc, unsigned CompatDiagId)
ExprResult ParseStringLiteralExpression(bool AllowUserDefinedLiteral=false)
ParseStringLiteralExpression - This handles the various token types that form string literals,...
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.
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.
DeclGroupPtrTy ParseOpenACCDirectiveDecl(AccessSpecifier &AS, ParsedAttributes &Attrs, DeclSpec::TST TagType, Decl *TagDecl)
Parse OpenACC directive on a declaration.
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)
OpaquePtr< DeclGroupRef > DeclGroupPtrTy
Scope * getCurScope() 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 ...
void SkipMalformedDecl()
SkipMalformedDecl - Read tokens until we get to some likely good stopping point for skipping past a s...
friend class ObjCDeclContextSwitch
void ExitScope()
ExitScope - Pop a scope off the scope stack.
const LangOptions & getLangOpts() const
bool ParseFirstTopLevelDecl(DeclGroupPtrTy &Result, Sema::ModuleImportState &ImportState)
Parse the first top-level declaration in a translation unit.
SkipUntilFlags
Control flags for SkipUntil functions.
@ StopBeforeMatch
Stop skipping at specified token, but don't skip the token itself.
@ StopAtCodeCompletion
Stop at code completion.
@ StopAtSemi
Stop skipping at semicolon.
bool TryAnnotateTypeOrScopeToken(ImplicitTypenameContext AllowImplicitTypename=ImplicitTypenameContext::No)
TryAnnotateTypeOrScopeToken - If the current token position is on a typename (possibly qualified in C...
bool MightBeCXXScopeToken()
const Token & NextToken()
NextToken - This peeks ahead one token and returns it without consuming it.
SmallVector< TemplateParameterList *, 4 > TemplateParameterLists
void Initialize()
Initialize - Warm up the parser.
bool TryAnnotateCXXScopeToken(bool EnteringContext=false)
TryAnnotateScopeToken - Like TryAnnotateTypeOrScopeToken but only annotates C++ scope specifiers and ...
A class for parsing a DeclSpec.
A class for parsing a declarator.
Engages in a tight little dance with the lexer to efficiently preprocess tokens.
void setCodeCompletionHandler(CodeCompletionHandler &Handler)
Set the code completion handler to the given object.
bool isIncrementalProcessingEnabled() const
Returns true if incremental processing is enabled.
void EnterToken(const Token &Tok, bool IsReinject)
Enters a token in the token stream to be lexed next.
void TypoCorrectToken(const Token &Tok)
Update the current token to represent the provided identifier, in order to cache an action performed ...
void AnnotateCachedTokens(const Token &Tok)
We notify the Preprocessor that if it is caching tokens (because backtrack is enabled) it should repl...
void Lex(Token &Result)
Lex the next token for this preprocessor.
void addCommentHandler(CommentHandler *Handler)
Add the specified comment handler to the preprocessor.
void removeCommentHandler(CommentHandler *Handler)
Remove the specified comment handler.
IdentifierInfo * getIdentifierInfo(StringRef Name) const
Return information about the specified preprocessor identifier token.
SourceManager & getSourceManager() const
bool isBacktrackEnabled() const
True if EnableBacktrackAtThisPos() was called and caching of tokens is on.
void SetPoisonReason(IdentifierInfo *II, unsigned DiagID)
Specifies the reason for poisoning an identifier.
void RevertCachedTokens(unsigned N)
When backtracking is enabled and tokens are cached, this allows to revert a specific number of tokens...
unsigned getTokenCount() const
Get the number of tokens processed so far.
unsigned getMaxTokens() const
Get the max number of tokens before issuing a -Wmax-tokens warning.
SourceLocation getMaxTokensOverrideLoc() const
bool hadModuleLoaderFatalFailure() const
StringRef getSpelling(SourceLocation loc, SmallVectorImpl< char > &buffer, bool *invalid=nullptr) const
Return the 'spelling' of the token at the given location; does not go up to the spelling location or ...
bool isCodeCompletionEnabled() const
Determine if we are performing code completion.
IdentifierTable & getIdentifierTable()
void clearCodeCompletionHandler()
Clear out the code completion handler.
bool isCodeCompletionReached() const
Returns true if code-completion is enabled and we have hit the code-completion point.
SourceLocation getLocForEndOfToken(SourceLocation Loc, unsigned Offset=0)
Computes the source location just past the end of the token at this source location.
DiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID) const
Forwarding function for diagnostics.
A (possibly-)qualified type.
Represents a struct/union/class.
Scope - A scope is a transient data structure that is used while parsing the program.
void Init(Scope *parent, unsigned flags)
Init - This is used by the parser to implement scope caching.
const Scope * getParent() const
getParent - Return the scope that this is nested in.
@ FunctionPrototypeScope
This is a scope that corresponds to the parameters within a function prototype.
@ CompoundStmtScope
This is a compound statement scope.
@ 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.
ParserCompletionContext
Describes the context in which code completion occurs.
@ PCC_TopLevelOrExpression
Code completion occurs at top-level in a REPL session.
@ PCC_Class
Code completion occurs within a class, struct, or union.
@ PCC_ObjCImplementation
Code completion occurs within an Objective-C implementation or category implementation.
@ PCC_Namespace
Code completion occurs at top-level or namespace context.
@ PCC_RecoveryInFunction
Code completion occurs within the body of a function on a recovery path, where we do not have a speci...
void CodeCompletePreprocessorMacroName(bool IsDefinition)
void CodeCompleteInPreprocessorConditionalExclusion(Scope *S)
void CodeCompletePreprocessorExpression()
void CodeCompleteIncludedFile(llvm::StringRef Dir, bool IsAngled)
void CodeCompletePreprocessorMacroArgument(Scope *S, IdentifierInfo *Macro, MacroInfo *MacroInfo, unsigned Argument)
void CodeCompleteModuleImport(SourceLocation ImportLoc, ModuleIdPath Path)
void CodeCompleteObjCMethodDecl(Scope *S, std::optional< bool > IsInstanceMethod, ParsedType ReturnType)
void CodeCompleteOrdinaryName(Scope *S, ParserCompletionContext CompletionContext)
void CodeCompleteNaturalLanguage()
void CodeCompletePreprocessorDirective(bool InConditional)
Records and restores the CurFPFeatures state on entry/exit of compound statements.
ExprResult getExpression() const
NameClassificationKind getKind() const
NamedDecl * getNonTypeDecl() const
TemplateName getTemplateName() const
ParsedType getType() const
TemplateNameKind getTemplateNameKind() const
Sema - This implements semantic analysis and AST building for C.
IfExistsResult CheckMicrosoftIfExistsSymbol(Scope *S, CXXScopeSpec &SS, const DeclarationNameInfo &TargetNameInfo)
void ActOnPopScope(SourceLocation Loc, Scope *S)
void ActOnDefinedDeclarationSpecifier(Decl *D)
Called once it is known whether a tag declaration is an anonymous union or struct.
ExprResult ActOnConstantExpression(ExprResult Res)
Decl * ActOnSkippedFunctionBody(Decl *Decl)
void ActOnAnnotModuleBegin(SourceLocation DirectiveLoc, Module *Mod)
The parsed has entered a submodule.
void ActOnAnnotModuleInclude(SourceLocation DirectiveLoc, Module *Mod)
The parser has processed a module import translated from a #include or similar preprocessing directiv...
Decl * ActOnParamDeclarator(Scope *S, Declarator &D, SourceLocation ExplicitThisLoc={})
ActOnParamDeclarator - Called from Parser::ParseFunctionDeclarator() to introduce parameters into fun...
void Initialize()
Perform initialization that occurs after the parser has been initialized but before it parses anythin...
@ Interface
'export module X;'
@ Implementation
'module X;'
void SetFunctionBodyKind(Decl *D, SourceLocation Loc, FnBodyKind BodyKind, StringLiteral *DeletedMessage=nullptr)
NamedDecl * HandleDeclarator(Scope *S, Declarator &D, MultiTemplateParamsArg TemplateParameterLists)
void ActOnComment(SourceRange Comment)
@ Other
C++26 [dcl.fct.def.general]p1 function-body: ctor-initializer[opt] compound-statement function-try-bl...
@ Delete
deleted-function-body
void ActOnEndOfTranslationUnit()
ActOnEndOfTranslationUnit - This is called at the very end of the translation unit when EOF is reache...
Decl * ActOnFinishFunctionBody(Decl *Decl, Stmt *Body, bool IsInstantiation=false, bool RetainFunctionScopeInfo=false)
Performs semantic analysis at the end of a function body.
void ActOnTranslationUnitScope(Scope *S)
Scope actions.
TemplateNameKind isTemplateName(Scope *S, CXXScopeSpec &SS, bool hasTemplateKeyword, const UnqualifiedId &Name, ParsedType ObjectType, bool EnteringContext, TemplateTy &Template, bool &MemberOfUnknownSpecialization, bool Disambiguation=false)
Decl * ActOnFileScopeAsmDecl(Expr *expr, SourceLocation AsmLoc, SourceLocation RParenLoc)
DeclarationNameInfo GetNameForDeclarator(Declarator &D)
GetNameForDeclarator - Determine the full declaration name for the given Declarator.
void ActOnAnnotModuleEnd(SourceLocation DirectiveLoc, Module *Mod)
The parser has left a submodule.
DeclResult ActOnModuleImport(SourceLocation StartLoc, SourceLocation ExportLoc, SourceLocation ImportLoc, ModuleIdPath Path, bool IsPartition=false)
The parser has processed a module import declaration.
DeclGroupPtrTy ConvertDeclToDeclGroup(Decl *Ptr, Decl *OwnedType=nullptr)
ASTContext & getASTContext() const
void PopExpressionEvaluationContext()
void MarkAsLateParsedTemplate(FunctionDecl *FD, Decl *FnD, CachedTokens &Toks)
void * SaveNestedNameSpecifierAnnotation(CXXScopeSpec &SS)
Given a C++ nested-name-specifier, produce an annotation value that the parser can use later to recon...
void SetLateTemplateParser(LateTemplateParserCB *LTP, LateTemplateParserCleanupCB *LTPCleanup, void *P)
SemaCodeCompletion & CodeCompletion()
ASTConsumer & getASTConsumer() const
Decl * ActOnStartOfFunctionDef(Scope *S, Declarator &D, MultiTemplateParamsArg TemplateParamLists, SkipBodyInfo *SkipBody=nullptr, FnBodyKind BodyKind=FnBodyKind::Other)
bool canDelayFunctionBody(const Declarator &D)
Determine whether we can delay parsing the body of a function or function template until it is used,...
std::function< TypeResult(StringRef, StringRef, SourceLocation)> ParseTypeFromStringCallback
Callback to the parser to parse a type expressed as a string.
NameClassification ClassifyName(Scope *S, CXXScopeSpec &SS, IdentifierInfo *&Name, SourceLocation NameLoc, const Token &NextToken, CorrectionCandidateCallback *CCC=nullptr)
Perform name lookup on the given name, classifying it based on the results of name lookup and the fol...
DeclGroupPtrTy ActOnGlobalModuleFragmentDecl(SourceLocation ModuleLoc)
The parser has processed a global-module-fragment declaration that begins the definition of the globa...
DeclGroupPtrTy BuildDeclaratorGroup(MutableArrayRef< Decl * > Group)
BuildDeclaratorGroup - convert a list of declarations into a declaration group, performing any necess...
DeclGroupPtrTy ActOnModuleDecl(SourceLocation StartLoc, SourceLocation ModuleLoc, ModuleDeclKind MDK, ModuleIdPath Path, ModuleIdPath Partition, ModuleImportState &ImportState, bool SeenNoTrivialPPDirective)
The parser has processed a module-declaration that begins the definition of a module interface or imp...
void CheckForFunctionRedefinition(FunctionDecl *FD, const FunctionDecl *EffectiveDefinition=nullptr, SkipBodyInfo *SkipBody=nullptr)
DeclContext * CurContext
CurContext - This is the current declaration context of parsing.
DeclGroupPtrTy ActOnPrivateModuleFragmentDecl(SourceLocation ModuleLoc, SourceLocation PrivateLoc)
The parser has processed a private-module-fragment declaration that begins the definition of the priv...
bool canSkipFunctionBody(Decl *D)
Determine whether we can skip parsing the body of a function definition, assuming we don't care about...
void ActOnDefaultCtorInitializers(Decl *CDtorDecl)
TypeResult ActOnTypenameType(Scope *S, SourceLocation TypenameLoc, const CXXScopeSpec &SS, const IdentifierInfo &II, SourceLocation IdLoc, ImplicitTypenameContext IsImplicitTypename=ImplicitTypenameContext::No)
Called when the parser has parsed a C++ typename specifier, e.g., "typename T::type".
void ActOnStartOfTranslationUnit()
This is called before the very first declaration in the translation unit is parsed.
ParsedType getTypeName(const IdentifierInfo &II, SourceLocation NameLoc, Scope *S, CXXScopeSpec *SS=nullptr, bool isClassName=false, bool HasTrailingDot=false, ParsedType ObjectType=nullptr, bool IsCtorOrDtorName=false, bool WantNontrivialTypeSourceInfo=false, bool IsClassTemplateDeductionContext=true, ImplicitTypenameContext AllowImplicitTypename=ImplicitTypenameContext::No, IdentifierInfo **CorrectedII=nullptr)
If the identifier refers to a type name within this scope, return the declaration of that type.
ModuleImportState
An enumeration to represent the transition of states in parsing module fragments and imports.
@ PrivateFragmentImportFinished
after 'module :private;' but a non-import decl has already been seen.
@ ImportFinished
after any non-import decl.
@ PrivateFragmentImportAllowed
after 'module :private;' but before any non-import decl.
@ FirstDecl
Parsing the first decl in a TU.
@ GlobalFragment
after 'module;' but before 'module X;'
@ NotACXX20Module
Not a C++20 TU, or an invalid state was found.
@ ImportAllowed
after 'module X;' but before any non-import decl.
@ 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 ActOnFinishKNRParamDeclarations(Scope *S, Declarator &D, SourceLocation LocAfterDecls)
Decl * ActOnEmptyDeclaration(Scope *S, const ParsedAttributesView &AttrList, SourceLocation SemiLoc)
Handle a C++11 empty-declaration and attribute-declaration.
ExprResult ActOnGCCAsmStmtString(Expr *Stm, bool ForAsmLabel)
static QualType GetTypeFromParser(ParsedType Ty, TypeSourceInfo **TInfo=nullptr)
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.
FileID getFileID(SourceLocation SpellingLoc) const
Return the FileID for a SourceLocation.
OptionalFileEntryRef getFileEntryRefForID(FileID FID) const
Returns the FileEntryRef for the provided FileID.
A trivial tuple used to represent a source range.
SourceLocation getEnd() const
SourceLocation getBegin() const
Stmt - This represents one statement.
StringLiteral - This represents a string literal expression, e.g.
Represents a C++ template name within the type system.
Token - This structure provides full information about a lexed token.
IdentifierInfo * getIdentifierInfo() const
void setAnnotationEndLoc(SourceLocation L)
SourceLocation getLocation() const
Return a source location identifier for the specified offset in the current file.
const char * getName() const
bool isEditorPlaceholder() const
Returns true if this token is an editor placeholder.
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 isAtStartOfLine() const
isAtStartOfLine - Return true if this token is at the start of a line.
bool isOneOf(Ts... Ks) const
bool hasLeadingSpace() const
Return true if this token has whitespace before it.
SourceRange getAnnotationRange() const
SourceRange of the group of tokens that this annotation token represents.
void setLocation(SourceLocation L)
bool isNot(tok::TokenKind K) const
bool isAnnotation() const
Return true if this is any of tok::annot_* kind tokens.
void setAnnotationValue(void *val)
bool isObjCAtKeyword(tok::ObjCKeywordKind objcKey) const
Return true if we have an ObjC keyword identifier.
void setAnnotationRange(SourceRange R)
void startToken()
Reset all flags to cleared.
bool hasSeenNoTrivialPPDirective() const
void setIdentifierInfo(IdentifierInfo *II)
SourceLocation getLastLoc() const
bool isObjCObjectType() const
bool isObjCObjectPointerType() const
Represents a C++ unqualified-id that has been parsed.
StringRef getName(const HeaderType T)
TokenKind
Provides a simple uniform namespace for tokens from all C languages.
const char * getPunctuatorSpelling(TokenKind Kind) LLVM_READNONE
Determines the spelling of simple punctuation tokens like '!' or '', and returns NULL for literal and...
The JSON file list parser is used to communicate input to InstallAPI.
TypeSpecifierType
Specifies the kind of type.
@ Unresolved
The identifier can't be resolved.
@ Success
Annotation was successful.
@ Error
Annotation has failed and emitted an error.
@ TentativeDecl
The identifier is a tentatively-declared name.
@ TemplateName
The identifier is a template name. FIXME: Add an annotation for that.
@ Self
'self' clause, allowed on Compute and Combined Constructs, plus 'update'.
AccessSpecifier
A C++ access specifier (public, private, protected), plus the special value "none" which means differ...
@ Dependent
Parse the block as a dependent block, which may be used in some template instantiations but not other...
@ Skip
Skip the block entirely; this code is never used.
@ Parse
Parse the block; this code is always used.
bool isLambdaCallOperator(const CXXMethodDecl *MD)
@ Result
The result type of a method or function.
@ Template
We are parsing a template declaration.
MutableArrayRef< TemplateParameterList * > MultiTemplateParamsArg
@ FunctionTemplate
The name was classified as a function template name.
@ Keyword
The name has been typo-corrected to a keyword.
@ DependentNonType
The name denotes a member of a dependent type that could not be resolved.
@ UndeclaredTemplate
The name was classified as an ADL-only function template name.
@ NonType
The name was classified as a specific non-type, non-template declaration.
@ Unknown
This name is not a type or template in this context, but might be something else.
@ Error
Classification failed; an error has been produced.
@ Type
The name was classified as a type.
@ TypeTemplate
The name was classified as a template whose specializations are types.
@ Concept
The name was classified as a concept name.
@ OverloadSet
The name was classified as an overload set, and an expression representing that overload set has been...
@ UndeclaredNonType
The name was classified as an ADL-only function name.
@ VarTemplate
The name was classified as a variable template name.
ExtraSemiKind
The kind of extra semi diagnostic to emit.
@ AfterMemberFunctionDefinition
TemplateNameKind
Specifies the kind of template name that an identifier refers to.
@ TNK_Type_template
The name refers to a template whose specialization produces a type.
@ TNK_Undeclared_template
Lookup for the name failed, but we're assuming it was a template name anyway.
const FunctionProtoType * T
@ Dependent
The name is a dependent name, so the results will differ from one instantiation to the next.
@ Exists
The symbol exists.
@ Error
An error occurred.
@ DoesNotExist
The symbol does not exist.
llvm::StringRef getAsString(SyncScope S)
ParenParseOption
ParenParseOption - Control what ParseParenExpression will parse.
@ Braces
New-expression has a C++11 list-initializer.
ParamInfo * Params
Params - This is a pointer to a new[]'d array of ParamInfo objects that describe the parameters speci...
unsigned NumParams
NumParams - This is the number of formal parameters specified by the declarator.
bool isKNRPrototype() const
isKNRPrototype - Return true if this is a K&R style identifier list, like "void foo(a,...
const IdentifierInfo * Ident
Describes how types, statements, expressions, and declarations should be printed.
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.
SourceLocation TemplateNameLoc
TemplateNameLoc - The location of the template name within the source.
ParsedTemplateArgument * getTemplateArgs()
Retrieves a pointer to the template arguments.
SourceLocation RAngleLoc
The location of the '>' after the template argument list.
SourceLocation LAngleLoc
The location of the '<' before the template argument list.
SourceLocation TemplateKWLoc
TemplateKWLoc - The location of the template keyword.
bool mightBeType() const
Determine whether this might be a type template.
ParsedTemplateTy Template
The declaration of the template corresponding to the template-name.