24#include "llvm/Support/Path.h"
25#include "llvm/Support/TimeProfiler.h"
36 explicit ActionCommentHandler(
Sema &S) : S(S) { }
54 : PP(pp), PreferredType(pp.isCodeCompletionEnabled()), Actions(actions),
55 Diags(PP.getDiagnostics()), GreaterThanIsOperator(
true),
56 ColonIsSacred(
false), InMessageExpression(
false),
57 TemplateParameterDepth(0), ParsingInObjCContainer(
false) {
61 Actions.CurScope =
nullptr;
63 CurParsedObjCImpl =
nullptr;
67 initializePragmaHandlers();
69 CommentSemaHandler.reset(
new ActionCommentHandler(actions));
75 [
this](StringRef TypeStr, StringRef Context,
SourceLocation IncludeLoc) {
76 return this->ParseTypeFromString(TypeStr, Context, IncludeLoc);
81 return Diags.
Report(Loc, DiagID);
110 switch (ExpectedTok) {
112 return Tok.
is(tok::colon) || Tok.
is(tok::comma);
113 default:
return false;
117bool Parser::ExpectAndConsume(
tok::TokenKind ExpectedTok,
unsigned DiagID,
119 if (Tok.
is(ExpectedTok) || Tok.
is(tok::code_completion)) {
131 if (DiagID == diag::err_expected)
133 else if (DiagID == diag::err_expected_after)
134 DB << Msg << ExpectedTok;
145 const char *Spelling =
nullptr;
153 if (DiagID == diag::err_expected)
155 else if (DiagID == diag::err_expected_after)
156 DB << Msg << ExpectedTok;
163bool Parser::ExpectAndConsumeSemi(
unsigned DiagID, StringRef TokenUsed) {
167 if (Tok.
is(tok::code_completion)) {
168 handleUnexpectedCodeCompletionToken();
172 if ((Tok.
is(tok::r_paren) || Tok.
is(tok::r_square)) &&
174 Diag(Tok, diag::err_extraneous_token_before_semi)
182 return ExpectAndConsume(tok::semi, DiagID , TokenUsed);
185void Parser::ConsumeExtraSemi(ExtraSemiKind Kind,
DeclSpec::TST TST) {
186 if (!Tok.
is(tok::semi))
return;
188 bool HadMultipleSemis =
false;
194 HadMultipleSemis =
true;
203 Diag(StartLoc, diag::warn_cxx98_compat_top_level_semi)
206 Diag(StartLoc, diag::ext_extra_semi_cxx11)
211 if (Kind != AfterMemberFunctionDefinition || HadMultipleSemis)
212 Diag(StartLoc, diag::ext_extra_semi)
218 Diag(StartLoc, diag::warn_extra_semi_after_mem_fn_def)
222bool Parser::expectIdentifier() {
223 if (Tok.
is(tok::identifier))
227 Diag(Tok, diag::err_expected_token_instead_of_objcxx_keyword)
233 Diag(Tok, diag::err_expected) << tok::identifier;
248 Diag(FirstTokLoc, diag::warn_compound_token_split_by_macro)
249 << (FirstTokKind == Tok.
getKind()) << FirstTokKind << Tok.
getKind()
250 <<
static_cast<int>(Op) <<
SourceRange(FirstTokLoc);
251 Diag(SecondTokLoc, diag::note_compound_token_split_second_token_here)
261 SpaceLoc = FirstTokLoc;
262 Diag(SpaceLoc, diag::warn_compound_token_split_by_whitespace)
263 << (FirstTokKind == Tok.
getKind()) << FirstTokKind << Tok.
getKind()
264 <<
static_cast<int>(Op) <<
SourceRange(FirstTokLoc, SecondTokLoc);
274 return (
static_cast<unsigned>(L) &
static_cast<unsigned>(R)) != 0;
288 bool isFirstTokenSkipped =
true;
291 for (
unsigned i = 0, NumToks = Toks.size(); i != NumToks; ++i) {
292 if (Tok.
is(Toks[i])) {
305 if (Toks.size() == 1 && Toks[0] == tok::eof &&
308 while (Tok.
isNot(tok::eof))
318 case tok::annot_pragma_openmp:
319 case tok::annot_attr_openmp:
320 case tok::annot_pragma_openmp_end:
322 if (OpenMPDirectiveParsing)
324 ConsumeAnnotationToken();
326 case tok::annot_pragma_openacc:
327 case tok::annot_pragma_openacc_end:
329 if (OpenACCDirectiveParsing)
331 ConsumeAnnotationToken();
333 case tok::annot_module_begin:
334 case tok::annot_module_end:
335 case tok::annot_module_include:
336 case tok::annot_repl_input_end:
342 case tok::code_completion:
344 handleUnexpectedCodeCompletionToken();
386 if (ParenCount && !isFirstTokenSkipped)
391 if (BracketCount && !isFirstTokenSkipped)
396 if (BraceCount && !isFirstTokenSkipped)
410 isFirstTokenSkipped =
false;
420 if (NumCachedScopes) {
421 Scope *N = ScopeCache[--NumCachedScopes];
423 Actions.CurScope = N;
438 Actions.CurScope = OldScope->
getParent();
440 if (NumCachedScopes == ScopeCacheSize)
443 ScopeCache[NumCachedScopes++] = OldScope;
448Parser::ParseScopeFlags::ParseScopeFlags(
Parser *
Self,
unsigned ScopeFlags,
450 : CurScope(ManageFlags ?
Self->getCurScope() : nullptr) {
452 OldFlags = CurScope->getFlags();
453 CurScope->setFlags(ScopeFlags);
459Parser::ParseScopeFlags::~ParseScopeFlags() {
461 CurScope->setFlags(OldFlags);
472 Actions.CurScope =
nullptr;
475 for (
unsigned i = 0, e = NumCachedScopes; i != e; ++i)
476 delete ScopeCache[i];
478 resetPragmaHandlers();
484 DestroyTemplateIds();
491 assert(
getCurScope() ==
nullptr &&
"A scope is already active?");
506 ObjCTypeQuals[objc_null_unspecified]
510 Ident_instancetype =
nullptr;
511 Ident_final =
nullptr;
512 Ident_sealed =
nullptr;
513 Ident_abstract =
nullptr;
514 Ident_override =
nullptr;
515 Ident_GNU_final =
nullptr;
516 Ident_import =
nullptr;
517 Ident_module =
nullptr;
521 Ident_vector =
nullptr;
522 Ident_bool =
nullptr;
523 Ident_Bool =
nullptr;
524 Ident_pixel =
nullptr;
533 Ident_introduced =
nullptr;
534 Ident_deprecated =
nullptr;
535 Ident_obsoleted =
nullptr;
536 Ident_unavailable =
nullptr;
537 Ident_strict =
nullptr;
538 Ident_replacement =
nullptr;
540 Ident_language = Ident_defined_in = Ident_generated_declaration = Ident_USR =
543 Ident__except =
nullptr;
545 Ident__exception_code = Ident__exception_info =
nullptr;
546 Ident__abnormal_termination = Ident___exception_code =
nullptr;
547 Ident___exception_info = Ident___abnormal_termination =
nullptr;
548 Ident_GetExceptionCode = Ident_GetExceptionInfo =
nullptr;
549 Ident_AbnormalTermination =
nullptr;
562 PP.
SetPoisonReason(Ident__exception_code,diag::err_seh___except_block);
563 PP.
SetPoisonReason(Ident___exception_code,diag::err_seh___except_block);
564 PP.
SetPoisonReason(Ident_GetExceptionCode,diag::err_seh___except_block);
565 PP.
SetPoisonReason(Ident__exception_info,diag::err_seh___except_filter);
566 PP.
SetPoisonReason(Ident___exception_info,diag::err_seh___except_filter);
567 PP.
SetPoisonReason(Ident_GetExceptionInfo,diag::err_seh___except_filter);
568 PP.
SetPoisonReason(Ident__abnormal_termination,diag::err_seh___finally_block);
569 PP.
SetPoisonReason(Ident___abnormal_termination,diag::err_seh___finally_block);
570 PP.
SetPoisonReason(Ident_AbnormalTermination,diag::err_seh___finally_block);
584void Parser::DestroyTemplateIds() {
616 Diag(diag::ext_empty_translation_unit);
618 return NoTopLevelDecls;
629 DestroyTemplateIdAnnotationsRAIIObj CleanupRAII(*
this);
638 case tok::annot_pragma_unused:
639 HandlePragmaUnused();
653 case tok::identifier: {
655 if ((II == Ident_module || II == Ident_import) &&
656 GetLookAheadToken(2).isNot(tok::coloncolon)) {
657 if (II == Ident_module)
672 Result = ParseModuleDecl(ImportState);
682 case tok::annot_module_include: {
695 ConsumeAnnotationToken();
699 case tok::annot_module_begin:
703 ConsumeAnnotationToken();
707 case tok::annot_module_end:
711 ConsumeAnnotationToken();
716 case tok::annot_repl_input_end:
723 PP.
Diag(OverrideLoc, diag::note_max_tokens_total_override);
733 case tok::identifier:
758 while (MaybeParseCXX11Attributes(DeclAttrs) ||
759 MaybeParseGNUAttributes(DeclSpecAttrs))
762 Result = ParseExternalDeclaration(DeclAttrs, DeclSpecAttrs);
772 else if (ImportState ==
813 DestroyTemplateIdAnnotationsRAIIObj CleanupRAII(*
this);
821 Decl *SingleDecl =
nullptr;
823 case tok::annot_pragma_vis:
824 HandlePragmaVisibility();
826 case tok::annot_pragma_pack:
829 case tok::annot_pragma_msstruct:
830 HandlePragmaMSStruct();
832 case tok::annot_pragma_align:
835 case tok::annot_pragma_weak:
838 case tok::annot_pragma_weakalias:
839 HandlePragmaWeakAlias();
841 case tok::annot_pragma_redefine_extname:
842 HandlePragmaRedefineExtname();
844 case tok::annot_pragma_fp_contract:
845 HandlePragmaFPContract();
847 case tok::annot_pragma_fenv_access:
848 case tok::annot_pragma_fenv_access_ms:
849 HandlePragmaFEnvAccess();
851 case tok::annot_pragma_fenv_round:
852 HandlePragmaFEnvRound();
854 case tok::annot_pragma_cx_limited_range:
855 HandlePragmaCXLimitedRange();
857 case tok::annot_pragma_float_control:
858 HandlePragmaFloatControl();
860 case tok::annot_pragma_fp:
863 case tok::annot_pragma_opencl_extension:
864 HandlePragmaOpenCLExtension();
866 case tok::annot_attr_openmp:
867 case tok::annot_pragma_openmp: {
869 return ParseOpenMPDeclarativeDirectiveWithExtDecl(AS, Attrs);
871 case tok::annot_pragma_openacc:
873 case tok::annot_pragma_ms_pointers_to_members:
874 HandlePragmaMSPointersToMembers();
876 case tok::annot_pragma_ms_vtordisp:
877 HandlePragmaMSVtorDisp();
879 case tok::annot_pragma_ms_pragma:
880 HandlePragmaMSPragma();
882 case tok::annot_pragma_dump:
885 case tok::annot_pragma_attribute:
886 HandlePragmaAttribute();
892 ConsumeExtraSemi(OutsideFunction);
895 Diag(Tok, diag::err_extraneous_closing_brace);
899 Diag(Tok, diag::err_expected_external_declaration);
901 case tok::kw___extension__: {
905 return ParseExternalDeclaration(Attrs, DeclSpecAttrs);
908 ProhibitAttributes(Attrs);
919 const auto *SL = cast<StringLiteral>(
Result.get());
920 if (!SL->getString().trim().empty())
921 Diag(StartLoc, diag::err_gnu_inline_asm_disabled);
924 ExpectAndConsume(tok::semi, diag::err_expected_after,
925 "top-level asm block");
933 return ParseObjCAtDirectives(Attrs, DeclSpecAttrs);
937 Diag(Tok, diag::err_expected_external_declaration);
941 SingleDecl = ParseObjCMethodDefinition();
943 case tok::code_completion:
945 if (CurParsedObjCImpl) {
953 if (CurParsedObjCImpl) {
962 case tok::kw_import: {
965 llvm_unreachable(
"not expecting a c++20 import here");
966 ProhibitAttributes(Attrs);
972 ProhibitAttributes(Attrs);
973 SingleDecl = ParseExportDeclaration();
980 case tok::kw_namespace:
981 case tok::kw_typedef:
982 case tok::kw_template:
983 case tok::kw_static_assert:
984 case tok::kw__Static_assert:
992 case tok::kw_cbuffer:
993 case tok::kw_tbuffer:
1001 case tok::kw_static:
1013 case tok::kw_inline:
1018 if (NextKind == tok::kw_namespace) {
1026 if (NextKind == tok::kw_template) {
1036 case tok::kw_extern:
1042 diag::warn_cxx98_compat_extern_template :
1043 diag::ext_extern_template) <<
SourceRange(ExternLoc, TemplateLoc);
1046 TemplateLoc, DeclEnd, Attrs);
1050 case tok::kw___if_exists:
1051 case tok::kw___if_not_exists:
1052 ParseMicrosoftIfExistsExternalDeclaration();
1055 case tok::kw_module:
1056 Diag(Tok, diag::err_unexpected_module_decl);
1067 !isDeclarationStatement(
true))
1068 return ParseTopLevelStmtDecl();
1072 return ParseDeclarationOrFunctionDefinition(Attrs, DeclSpecAttrs, DS);
1082bool Parser::isDeclarationAfterDeclarator() {
1086 if (KW.
is(tok::kw_default) || KW.
is(tok::kw_delete))
1090 return Tok.
is(tok::equal) ||
1091 Tok.
is(tok::comma) ||
1092 Tok.
is(tok::semi) ||
1093 Tok.
is(tok::kw_asm) ||
1094 Tok.
is(tok::kw___attribute) ||
1096 Tok.
is(tok::l_paren));
1103 if (Tok.
is(tok::l_brace))
1113 return KW.
is(tok::kw_default) || KW.
is(tok::kw_delete);
1116 return Tok.
is(tok::colon) ||
1117 Tok.
is(tok::kw_try);
1143 "expected uninitialised source range");
1148 ParsedTemplateInfo TemplateInfo;
1151 ParseDeclarationSpecifiers(DS, TemplateInfo, AS,
1152 DeclSpecContext::DSC_top_level);
1157 DS, AS, DeclSpecContext::DSC_top_level))
1162 if (Tok.
is(tok::semi)) {
1177 llvm_unreachable(
"we only expect to get the length of the class/struct/union/enum");
1187 ProhibitAttributes(Attrs, CorrectLocationForAttributes);
1195 Decl* decls[] = {AnonRecord, TheDecl};
1212 Diag(Tok, diag::err_objc_unexpected_attr);
1220 const char *PrevSpec =
nullptr;
1224 Diag(AtLoc, DiagID) << PrevSpec;
1227 return ParseObjCAtProtocolDeclaration(AtLoc, DS.
getAttributes());
1230 return ParseObjCAtImplementationDeclaration(AtLoc, DS.
getAttributes());
1233 ParseObjCAtInterfaceDeclaration(AtLoc, DS.
getAttributes()));
1242 ProhibitAttributes(Attrs);
1255 llvm::TimeTraceScope TimeScope(
"ParseDeclarationOrFunctionDefinition", [&]() {
1261 return ParseDeclOrFunctionDefInternal(Attrs, DeclSpecAttrs, *DS, AS);
1269 return ParseDeclOrFunctionDefInternal(Attrs, DeclSpecAttrs, PDS, AS);
1288 const ParsedTemplateInfo &TemplateInfo,
1289 LateParsedAttrList *LateParsedAttrs) {
1290 llvm::TimeTraceScope TimeScope(
"ParseFunctionDefinition", [&]() {
1297 TemplateParameterDepthRAII CurTemplateDepthTracker(TemplateParameterDepth);
1305 const char *PrevSpec;
1319 ParseKNRParamDeclarations(D);
1323 if (Tok.
isNot(tok::l_brace) &&
1325 (Tok.
isNot(tok::colon) && Tok.
isNot(tok::kw_try) &&
1326 Tok.
isNot(tok::equal)))) {
1327 Diag(Tok, diag::err_expected_fn_body);
1333 if (Tok.
isNot(tok::l_brace))
1339 if (Tok.
isNot(tok::equal)) {
1341 if (AL.isKnownToGCC() && !AL.isStandardAttributeSyntax())
1342 Diag(AL.getLoc(), diag::warn_attribute_on_function_definition) << AL;
1348 TemplateInfo.Kind == ParsedTemplateInfo::Template &&
1363 trySkippingFunctionBody()) {
1369 LexTemplateFunctionForLateParsing(Toks);
1378 else if (CurParsedObjCImpl &&
1379 !TemplateInfo.TemplateParams &&
1380 (Tok.
is(tok::l_brace) || Tok.
is(tok::kw_try) ||
1381 Tok.
is(tok::colon)) &&
1394 StashAwayMethodOrFunctionBodyTokens(FuncDecl);
1395 CurParsedObjCImpl->HasCFunction =
true;
1415 ? diag::warn_cxx98_compat_defaulted_deleted_function
1416 : diag::ext_defaulted_deleted_function)
1419 DeletedMessage = ParseCXXDeletedFunctionMessage();
1422 ? diag::warn_cxx98_compat_defaulted_deleted_function
1423 : diag::ext_defaulted_deleted_function)
1427 llvm_unreachable(
"function definition after = not 'delete' or 'default'");
1430 if (Tok.
is(tok::comma)) {
1431 Diag(KWLoc, diag::err_default_delete_in_multiple_declaration)
1434 }
else if (ExpectAndConsume(tok::semi, diag::err_expected_after,
1446 TemplateInfo.TemplateParams
1447 ? *TemplateInfo.TemplateParams
1449 &SkipBody, BodyKind);
1479 Stmt *GeneratedBody = Res ? Res->
getBody() :
nullptr;
1486 if (
const auto *Template = dyn_cast_if_present<FunctionTemplateDecl>(Res);
1487 Template && Template->isAbbreviated() &&
1488 Template->getTemplateParameters()->getParam(0)->isImplicit())
1491 CurTemplateDepthTracker.addDepth(1);
1494 trySkippingFunctionBody()) {
1502 if (Tok.
is(tok::kw_try))
1503 return ParseFunctionTryBlock(Res, BodyScope);
1507 if (Tok.
is(tok::colon)) {
1508 ParseConstructorInitializer(Res);
1511 if (!Tok.
is(tok::l_brace)) {
1520 if (LateParsedAttrs)
1521 ParseLexedAttributeList(*LateParsedAttrs, Res,
false,
true);
1523 return ParseFunctionStatementBody(Res, BodyScope);
1526void Parser::SkipFunctionBody() {
1527 if (Tok.
is(tok::equal)) {
1532 bool IsFunctionTryBlock = Tok.
is(tok::kw_try);
1533 if (IsFunctionTryBlock)
1537 if (ConsumeAndStoreFunctionPrologue(Skipped))
1541 while (IsFunctionTryBlock && Tok.
is(tok::kw_catch)) {
1550void Parser::ParseKNRParamDeclarations(
Declarator &D) {
1565 ParseDeclarationSpecifiers(DS);
1573 Diag(DSStart, diag::err_declaration_does_not_declare_param);
1582 diag::err_invalid_storage_class_in_func_decl);
1587 diag::err_invalid_storage_class_in_func_decl);
1594 ParseDeclarator(ParmDeclarator);
1599 MaybeParseGNUAttributes(ParmDeclarator);
1607 ParmDeclarator.getIdentifier()) {
1611 for (
unsigned i = 0; ; ++i) {
1615 Diag(ParmDeclarator.getIdentifierLoc(), diag::err_no_matching_param)
1616 << ParmDeclarator.getIdentifier();
1620 if (FTI.
Params[i].
Ident == ParmDeclarator.getIdentifier()) {
1623 Diag(ParmDeclarator.getIdentifierLoc(),
1624 diag::err_param_redefinition)
1625 << ParmDeclarator.getIdentifier();
1636 if (Tok.
isNot(tok::comma))
1639 ParmDeclarator.clear();
1645 ParseDeclarator(ParmDeclarator);
1649 if (!ExpectAndConsumeSemi(diag::err_expected_semi_declaration))
1672ExprResult Parser::ParseAsmStringLiteral(
bool ForAsmLabel) {
1673 if (!isTokenStringLiteral()) {
1674 Diag(Tok, diag::err_expected_string_literal)
1680 if (!AsmString.isInvalid()) {
1681 const auto *SL = cast<StringLiteral>(AsmString.get());
1682 if (!SL->isOrdinary()) {
1683 Diag(Tok, diag::err_asm_operand_wide_string_literal)
1685 << SL->getSourceRange();
1688 if (ForAsmLabel && SL->getString().empty()) {
1689 Diag(Tok, diag::err_asm_operand_wide_string_literal)
1690 << 2 << SL->getSourceRange();
1703 assert(Tok.
is(tok::kw_asm) &&
"Not an asm!");
1706 if (isGNUAsmQualifier(Tok)) {
1710 Diag(Tok, diag::err_global_asm_qualifier_ignored)
1711 << GNUAsmQualifiers::getQualifierName(getGNUAsmQualifier(Tok))
1717 if (
T.consumeOpen()) {
1718 Diag(Tok, diag::err_expected_lparen_after) <<
"asm";
1724 if (!
Result.isInvalid()) {
1728 *EndLoc =
T.getCloseLocation();
1742 assert(tok.
is(tok::annot_template_id) &&
"Expected template-id token");
1748void Parser::AnnotateScopeToken(
CXXScopeSpec &SS,
bool IsNewAnnotation) {
1755 Tok.
setKind(tok::annot_cxxscope);
1762 if (IsNewAnnotation)
1776Parser::AnnotatedNameKind
1779 assert(Tok.
is(tok::identifier) || Tok.
is(tok::annot_cxxscope));
1781 const bool EnteringContext =
false;
1782 const bool WasScopeAnnotation = Tok.
is(tok::annot_cxxscope);
1786 ParseOptionalCXXScopeSpecifier(SS,
nullptr,
1793 AllowImplicitTypename))
1795 return ANK_Unresolved;
1803 if (isTentativelyDeclared(Name) && SS.
isEmpty()) {
1807 AllowImplicitTypename))
1809 return Tok.
is(tok::annot_typename) ? ANK_Success : ANK_TentativeDecl;
1826 isTemplateArgumentList(1) == TPResult::False) {
1828 Token FakeNext = Next;
1829 FakeNext.
setKind(tok::unknown);
1832 SS.
isEmpty() ? CCC :
nullptr);
1835 switch (Classification.
getKind()) {
1842 Tok.
setKind(Name->getTokenID());
1845 AnnotateScopeToken(SS, !WasScopeAnnotation);
1854 if (TryAltiVecVectorToken())
1878 else if (Tok.
is(tok::eof))
1882 Tok.
setKind(tok::annot_typename);
1883 setTypeAnnotation(Tok, Ty);
1891 Tok.
setKind(tok::annot_overload_set);
1900 if (TryAltiVecVectorToken())
1905 Tok.
setKind(tok::annot_non_type);
1911 AnnotateScopeToken(SS, !WasScopeAnnotation);
1917 ? tok::annot_non_type_undeclared
1918 : tok::annot_non_type_dependent);
1919 setIdentifierAnnotation(Tok, Name);
1924 AnnotateScopeToken(SS, !WasScopeAnnotation);
1928 if (Next.isNot(tok::less)) {
1931 AnnotateScopeToken(SS, !WasScopeAnnotation);
1932 return ANK_TemplateName;
1942 if (Next.is(tok::less))
1945 Id.setIdentifier(Name, NameLoc);
1946 if (AnnotateTemplateIdToken(
1953 AnnotateScopeToken(SS, !WasScopeAnnotation);
1960 AnnotateScopeToken(SS, !WasScopeAnnotation);
1961 return ANK_Unresolved;
1964bool Parser::TryKeywordIdentFallback(
bool DisableKeyword) {
1965 assert(Tok.
isNot(tok::identifier));
1966 Diag(Tok, diag::ext_keyword_as_ident)
1999 assert((Tok.
is(tok::identifier) || Tok.
is(tok::coloncolon) ||
2000 Tok.
is(tok::kw_typename) || Tok.
is(tok::annot_cxxscope) ||
2001 Tok.
is(tok::kw_decltype) || Tok.
is(tok::annot_template_id) ||
2002 Tok.
is(tok::kw___super) || Tok.
is(tok::kw_auto) ||
2003 Tok.
is(tok::annot_pack_indexing_type)) &&
2004 "Cannot be a type or scope token!");
2006 if (Tok.
is(tok::kw_typename)) {
2015 PP.
Lex(TypedefToken);
2020 Diag(Tok.
getLocation(), diag::warn_expected_qualified_after_typename);
2032 if (ParseOptionalCXXScopeSpecifier(SS,
nullptr,
2038 if (Tok.
is(tok::identifier) || Tok.
is(tok::annot_template_id) ||
2039 Tok.
is(tok::annot_decltype)) {
2041 if (Tok.
is(tok::annot_decltype) ||
2044 unsigned DiagID = diag::err_expected_qualified_after_typename;
2048 DiagID = diag::warn_expected_qualified_after_typename;
2061 if (Tok.
is(tok::identifier)) {
2066 }
else if (Tok.
is(tok::annot_template_id)) {
2069 Diag(Tok, diag::err_typename_refers_to_non_type_template)
2083 TemplateArgsPtr, TemplateId->
RAngleLoc);
2085 Diag(Tok, diag::err_expected_type_name_after_typename)
2091 Tok.
setKind(tok::annot_typename);
2092 setTypeAnnotation(Tok, Ty);
2100 bool WasScopeAnnotation = Tok.
is(tok::annot_cxxscope);
2104 if (ParseOptionalCXXScopeSpecifier(SS,
nullptr,
2110 AllowImplicitTypename);
2119 if (Tok.
is(tok::identifier)) {
2123 false,
NextToken().is(tok::period),
nullptr,
2126 true, AllowImplicitTypename)) {
2145 else if (Tok.
is(tok::eof))
2151 Tok.
setKind(tok::annot_typename);
2152 setTypeAnnotation(Tok, Ty);
2176 bool MemberOfUnknownSpecialization;
2180 nullptr,
false, Template,
2181 MemberOfUnknownSpecialization)) {
2185 isTemplateArgumentList(1) != TPResult::False) {
2205 if (Tok.
is(tok::annot_template_id)) {
2212 AnnotateTemplateIdTokenAsType(SS, AllowImplicitTypename);
2221 AnnotateScopeToken(SS, IsNewScope);
2233 "Call sites of this function should be guarded by checking for C++");
2237 if (ParseOptionalCXXScopeSpecifier(SS,
nullptr,
2244 AnnotateScopeToken(SS,
true);
2248bool Parser::isTokenEqualOrEqualTypo() {
2254 case tok::starequal:
2255 case tok::plusequal:
2256 case tok::minusequal:
2257 case tok::exclaimequal:
2258 case tok::slashequal:
2259 case tok::percentequal:
2260 case tok::lessequal:
2261 case tok::lesslessequal:
2262 case tok::greaterequal:
2263 case tok::greatergreaterequal:
2264 case tok::caretequal:
2265 case tok::pipeequal:
2266 case tok::equalequal:
2267 Diag(Tok, diag::err_invalid_token_after_declarator_suggest_equal)
2277 assert(Tok.
is(tok::code_completion));
2281 if (S->isFunctionScope()) {
2285 return PrevTokLocation;
2288 if (S->isClassScope()) {
2291 return PrevTokLocation;
2297 return PrevTokLocation;
2302void Parser::CodeCompleteDirective(
bool InConditional) {
2306void Parser::CodeCompleteInConditionalExclusion() {
2310void Parser::CodeCompleteMacroName(
bool IsDefinition) {
2314void Parser::CodeCompletePreprocessorExpression() {
2320 unsigned ArgumentIndex) {
2325void Parser::CodeCompleteIncludedFile(llvm::StringRef Dir,
bool IsAngled) {
2329void Parser::CodeCompleteNaturalLanguage() {
2333bool Parser::ParseMicrosoftIfExistsCondition(IfExistsCondition&
Result) {
2334 assert((Tok.
is(tok::kw___if_exists) || Tok.
is(tok::kw___if_not_exists)) &&
2335 "Expected '__if_exists' or '__if_not_exists'");
2336 Result.IsIfExists = Tok.
is(tok::kw___if_exists);
2340 if (
T.consumeOpen()) {
2341 Diag(Tok, diag::err_expected_lparen_after)
2342 << (
Result.IsIfExists?
"__if_exists" :
"__if_not_exists");
2348 ParseOptionalCXXScopeSpecifier(
Result.SS,
nullptr,
2353 if (
Result.SS.isInvalid()) {
2364 false, &TemplateKWLoc,
2370 if (
T.consumeClose())
2378 Result.Behavior =
Result.IsIfExists ? IEB_Parse : IEB_Skip;
2382 Result.Behavior = !
Result.IsIfExists ? IEB_Parse : IEB_Skip;
2386 Result.Behavior = IEB_Dependent;
2396void Parser::ParseMicrosoftIfExistsExternalDeclaration() {
2397 IfExistsCondition
Result;
2398 if (ParseMicrosoftIfExistsCondition(
Result))
2402 if (
Braces.consumeOpen()) {
2403 Diag(Tok, diag::err_expected) << tok::l_brace;
2407 switch (
Result.Behavior) {
2413 llvm_unreachable(
"Cannot have a dependent external declaration");
2422 while (Tok.
isNot(tok::r_brace) && !isEofOrEom()) {
2424 MaybeParseCXX11Attributes(Attrs);
2455 (Tok.
is(tok::kw_module) ||
2457 "not a module declaration");
2462 DiagnoseAndSkipCXX11Attributes();
2468 Diag(StartLoc, diag::err_global_module_introducer_not_at_start)
2473 Diag(StartLoc, diag::err_module_fragment_exported)
2484 Diag(StartLoc, diag::err_module_fragment_exported)
2489 DiagnoseAndSkipCXX11Attributes();
2490 ExpectAndConsumeSemi(diag::err_private_module_fragment_expected_semi);
2498 if (ParseModuleName(ModuleLoc, Path,
false))
2503 if (Tok.
is(tok::colon)) {
2506 Diag(ColonLoc, diag::err_unsupported_module_partition)
2507 <<
SourceRange(ColonLoc, Partition.back().second);
2509 else if (ParseModuleName(ModuleLoc, Partition,
false))
2515 MaybeParseCXX11Attributes(Attrs);
2516 ProhibitCXX11Attributes(Attrs, diag::err_attribute_not_module_attr,
2517 diag::err_keyword_not_module_attr,
2521 ExpectAndConsumeSemi(diag::err_module_expected_semi);
2523 return Actions.
ActOnModuleDecl(StartLoc, ModuleLoc, MDK, Path, Partition,
2551 "Improper start to module import");
2557 bool IsPartition =
false;
2558 Module *HeaderUnit =
nullptr;
2559 if (Tok.
is(tok::header_name)) {
2564 }
else if (Tok.
is(tok::annot_header_unit)) {
2567 ConsumeAnnotationToken();
2568 }
else if (Tok.
is(tok::colon)) {
2571 Diag(ColonLoc, diag::err_unsupported_module_partition)
2574 else if (ParseModuleName(ColonLoc, Path,
true))
2579 if (ParseModuleName(ImportLoc, Path,
true))
2584 MaybeParseCXX11Attributes(Attrs);
2586 ProhibitCXX11Attributes(Attrs, diag::err_attribute_not_import_attr,
2587 diag::err_keyword_not_import_attr,
2598 bool SeenError =
true;
2599 switch (ImportState) {
2611 Diag(ImportLoc, diag::err_partition_import_outside_module);
2623 if (IsPartition || (HeaderUnit && HeaderUnit->
Kind !=
2625 Diag(ImportLoc, diag::err_import_in_wrong_fragment)
2634 Diag(ImportLoc, diag::err_import_not_allowed_here);
2640 ExpectAndConsumeSemi(diag::err_module_expected_semi);
2648 else if (!Path.empty())
2651 ExpectAndConsumeSemi(diag::err_module_expected_semi);
2657 if (IsObjCAtImport && AtLoc.
isValid()) {
2660 if (FE && llvm::sys::path::parent_path(FE->getDir().getName())
2661 .ends_with(
".framework"))
2662 Diags.
Report(AtLoc, diag::warn_atimport_in_framework_header);
2675bool Parser::ParseModuleName(
2681 if (!Tok.
is(tok::identifier)) {
2682 if (Tok.
is(tok::code_completion)) {
2688 Diag(Tok, diag::err_module_expected_ident) << IsImport;
2697 if (Tok.
isNot(tok::period))
2708bool Parser::parseMisplacedModuleImport() {
2711 case tok::annot_module_end:
2715 if (MisplacedModuleBeginCount) {
2716 --MisplacedModuleBeginCount;
2720 ConsumeAnnotationToken();
2727 case tok::annot_module_begin:
2732 ConsumeAnnotationToken();
2733 ++MisplacedModuleBeginCount;
2735 case tok::annot_module_include:
2741 ConsumeAnnotationToken();
2751void Parser::diagnoseUseOfC11Keyword(
const Token &Tok) {
2756 : diag::ext_c11_feature)
2760bool BalancedDelimiterTracker::diagnoseOverflow() {
2761 P.
Diag(P.Tok, diag::err_bracket_depth_exceeded)
2763 P.
Diag(P.Tok, diag::note_bracket_depth);
2772 if (P.ExpectAndConsume(Kind, DiagID, Msg)) {
2773 if (SkipToTok != tok::unknown)
2781 return diagnoseOverflow();
2784bool BalancedDelimiterTracker::diagnoseMissingClose() {
2785 assert(!P.Tok.
is(Close) &&
"Should have consumed closing delimiter");
2787 if (P.Tok.
is(tok::annot_module_end))
2788 P.
Diag(P.Tok, diag::err_missing_before_module_end) << Close;
2790 P.
Diag(P.Tok, diag::err_expected) << Close;
2791 P.
Diag(LOpen, diag::note_matching) << Kind;
2795 if (P.Tok.
isNot(tok::r_paren) && P.Tok.
isNot(tok::r_brace) &&
2796 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.
Defines the clang::FileManager interface and associated types.
static bool IsCommonTypo(tok::TokenKind ExpectedTok, const Token &Tok)
static bool HasFlagsSet(Parser::SkipUntilFlags L, Parser::SkipUntilFlags R)
static std::string getName(const CallEvent &Call)
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
bool isEmpty() const
isEmpty - Return true if this declaration specifier is completely empty: no tokens were parsed in the...
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.
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...
void SetRangeBegin(SourceLocation Loc)
SetRangeBegin - Set the start of the source range to Loc, unless it's invalid.
const ParsedAttributes & getAttributes() const
SourceLocation getIdentifierLoc() const
void setFunctionDefinitionKind(FunctionDefinitionKind Val)
DeclaratorChunk::FunctionTypeInfo & getFunctionTypeInfo()
getFunctionTypeInfo - Retrieves the function type info object (looking through parentheses).
A little helper class used to produce diagnostics.
DiagnosticBuilder Report(SourceLocation Loc, unsigned DiagID)
Issue the message to the client.
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.
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)
bool TryAnnotateTypeOrScopeTokenAfterScopeSpec(CXXScopeSpec &SS, bool IsNewScope, ImplicitTypenameContext AllowImplicitTypename)
Try to annotate a type or scope token, having already parsed an optional scope specifier.
SourceLocation ConsumeToken()
ConsumeToken - Consume the current 'peek token' and lex the next one.
DeclGroupPtrTy ParseOpenACCDirectiveDecl()
Placeholder for now, should just ignore the directives after emitting a diagnostic.
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.
SourceLocation ConsumeAnyToken(bool ConsumeCodeCompletionTok=false)
ConsumeAnyToken - Dispatch to the right Consume* method based on the current token type.
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()
ExprResult ParseStringLiteralExpression(bool AllowUserDefinedLiteral=false)
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.
const ParsingDeclSpec & getDeclSpec() const
ParsingDeclSpec & getMutableDeclSpec() const
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.
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.
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.
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.
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...
@ IER_DoesNotExist
The symbol does not exist.
@ IER_Dependent
The name is a dependent name, so the results will differ from one instantiation to the next.
@ IER_Error
An error occurred.
@ IER_Exists
The symbol exists.
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 CodeCompletePreprocessorMacroArgument(Scope *S, IdentifierInfo *Macro, MacroInfo *MacroInfo, unsigned Argument)
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...
void ActOnTranslationUnitScope(Scope *S)
Scope actions.
DeclGroupPtrTy ActOnModuleDecl(SourceLocation StartLoc, SourceLocation ModuleLoc, ModuleDeclKind MDK, ModuleIdPath Path, ModuleIdPath Partition, ModuleImportState &ImportState)
The parser has processed a module-declaration that begins the definition of a module interface or imp...
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
@ NC_Unknown
This name is not a type or template in this context, but might be something else.
@ NC_VarTemplate
The name was classified as a variable template name.
@ NC_NonType
The name was classified as a specific non-type, non-template declaration.
@ NC_TypeTemplate
The name was classified as a template whose specializations are types.
@ NC_Error
Classification failed; an error has been produced.
@ NC_FunctionTemplate
The name was classified as a function template name.
@ NC_DependentNonType
The name denotes a member of a dependent type that could not be resolved.
@ NC_UndeclaredNonType
The name was classified as an ADL-only function name.
@ NC_UndeclaredTemplate
The name was classified as an ADL-only function template name.
@ NC_Keyword
The name has been typo-corrected to a keyword.
@ NC_Type
The name was classified as a type.
@ NC_OverloadSet
The name was classified as an overload set, and an expression representing that overload set has been...
@ NC_Concept
The name was classified as a concept name.
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 CodeCompleteInPreprocessorConditionalExclusion(Scope *S)
void SetLateTemplateParser(LateTemplateParserCB *LTP, LateTemplateParserCleanupCB *LTPCleanup, void *P)
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...
void CodeCompleteNaturalLanguage()
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...
void CodeCompleteIncludedFile(llvm::StringRef Dir, bool IsAngled)
void CheckForFunctionRedefinition(FunctionDecl *FD, const FunctionDecl *EffectiveDefinition=nullptr, SkipBodyInfo *SkipBody=nullptr)
IfExistsResult CheckMicrosoftIfExistsSymbol(Scope *S, CXXScopeSpec &SS, const DeclarationNameInfo &TargetNameInfo)
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...
ParserCompletionContext
Describes the context in which code completion occurs.
@ PCC_RecoveryInFunction
Code completion occurs within the body of a function on a recovery path, where we do not have a speci...
@ 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.
bool canSkipFunctionBody(Decl *D)
Determine whether we can skip parsing the body of a function definition, assuming we don't care about...
Decl * ActOnFinishFunctionBody(Decl *Decl, Stmt *Body)
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.
void CodeCompleteObjCMethodDecl(Scope *S, std::optional< bool > IsInstanceMethod, ParsedType ReturnType)
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.
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 CodeCompleteModuleImport(SourceLocation ImportLoc, ModuleIdPath Path)
void CodeCompletePreprocessorMacroName(bool IsDefinition)
void ActOnFinishKNRParamDeclarations(Scope *S, Declarator &D, SourceLocation LocAfterDecls)
void CodeCompleteOrdinaryName(Scope *S, ParserCompletionContext CompletionContext)
Decl * ActOnEmptyDeclaration(Scope *S, const ParsedAttributesView &AttrList, SourceLocation SemiLoc)
Handle a C++11 empty-declaration and attribute-declaration.
void CodeCompletePreprocessorDirective(bool InConditional)
void CodeCompletePreprocessorExpression()
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 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 isOneOf(tok::TokenKind K1, tok::TokenKind K2) const
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.
void setIdentifierInfo(IdentifierInfo *II)
SourceLocation getLastLoc() const
bool isObjCObjectType() const
bool isObjCObjectPointerType() const
Represents a C++ unqualified-id that has been parsed.
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.
@ Self
'self' clause, allowed on Compute and Combined Constructs, plus 'update'.
TypeSpecifierType
Specifies the kind of type.
bool isLambdaCallOperator(const CXXMethodDecl *MD)
@ Result
The result type of a method or function.
MutableArrayRef< TemplateParameterList * > MultiTemplateParamsArg
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
llvm::StringRef getAsString(SyncScope S)
@ Braces
New-expression has a C++11 list-initializer.
AccessSpecifier
A C++ access specifier (public, private, protected), plus the special value "none" which means differ...
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
Wraps an identifier and optional source location for the identifier.
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.