23 #include "llvm/Support/Path.h"
24 using namespace clang;
34 explicit ActionCommentHandler(
Sema &S) : S(S) { }
52 : PP(pp), PreferredType(pp.isCodeCompletionEnabled()), Actions(actions),
53 Diags(PP.getDiagnostics()), GreaterThanIsOperator(
true),
54 ColonIsSacred(
false), InMessageExpression(
false),
55 TemplateParameterDepth(0), ParsingInObjCContainer(
false) {
59 Actions.CurScope =
nullptr;
61 CurParsedObjCImpl =
nullptr;
65 initializePragmaHandlers();
67 CommentSemaHandler.reset(
new ActionCommentHandler(actions));
74 return Diags.
Report(Loc, DiagID);
103 switch (ExpectedTok) {
105 return Tok.
is(tok::colon) || Tok.
is(tok::comma);
106 default:
return false;
110 bool Parser::ExpectAndConsume(
tok::TokenKind ExpectedTok,
unsigned DiagID,
112 if (Tok.
is(ExpectedTok) || Tok.
is(tok::code_completion)) {
124 if (DiagID == diag::err_expected)
126 else if (DiagID == diag::err_expected_after)
127 DB << Msg << ExpectedTok;
138 const char *Spelling =
nullptr;
146 if (DiagID == diag::err_expected)
148 else if (DiagID == diag::err_expected_after)
149 DB << Msg << ExpectedTok;
156 bool Parser::ExpectAndConsumeSemi(
unsigned DiagID) {
160 if (Tok.
is(tok::code_completion)) {
161 handleUnexpectedCodeCompletionToken();
165 if ((Tok.
is(tok::r_paren) || Tok.
is(tok::r_square)) &&
167 Diag(Tok, diag::err_extraneous_token_before_semi)
175 return ExpectAndConsume(tok::semi, DiagID);
179 if (!Tok.
is(tok::semi))
return;
181 bool HadMultipleSemis =
false;
187 HadMultipleSemis =
true;
196 Diag(StartLoc, diag::warn_cxx98_compat_top_level_semi)
199 Diag(StartLoc, diag::ext_extra_semi_cxx11)
204 if (
Kind != AfterMemberFunctionDefinition || HadMultipleSemis)
205 Diag(StartLoc, diag::ext_extra_semi)
211 Diag(StartLoc, diag::warn_extra_semi_after_mem_fn_def)
215 bool Parser::expectIdentifier() {
216 if (Tok.
is(tok::identifier))
220 Diag(Tok, diag::err_expected_token_instead_of_objcxx_keyword)
226 Diag(Tok, diag::err_expected) << tok::identifier;
241 Diag(FirstTokLoc, diag::warn_compound_token_split_by_macro)
242 << (FirstTokKind == Tok.
getKind()) << FirstTokKind << Tok.
getKind()
243 <<
static_cast<int>(Op) <<
SourceRange(FirstTokLoc);
244 Diag(SecondTokLoc, diag::note_compound_token_split_second_token_here)
254 SpaceLoc = FirstTokLoc;
255 Diag(SpaceLoc, diag::warn_compound_token_split_by_whitespace)
256 << (FirstTokKind == Tok.
getKind()) << FirstTokKind << Tok.
getKind()
257 <<
static_cast<int>(Op) <<
SourceRange(FirstTokLoc, SecondTokLoc);
267 return (
static_cast<unsigned>(L) &
static_cast<unsigned>(R)) != 0;
281 bool isFirstTokenSkipped =
true;
284 for (
unsigned i = 0, NumToks = Toks.size(); i != NumToks; ++i) {
285 if (Tok.
is(Toks[i])) {
298 if (Toks.size() == 1 && Toks[0] ==
tok::eof &&
311 case tok::annot_pragma_openmp:
312 case tok::annot_attr_openmp:
313 case tok::annot_pragma_openmp_end:
315 if (OpenMPDirectiveParsing)
317 ConsumeAnnotationToken();
319 case tok::annot_module_begin:
320 case tok::annot_module_end:
321 case tok::annot_module_include:
327 case tok::code_completion:
329 handleUnexpectedCodeCompletionToken();
371 if (ParenCount && !isFirstTokenSkipped)
376 if (BracketCount && !isFirstTokenSkipped)
381 if (BraceCount && !isFirstTokenSkipped)
395 isFirstTokenSkipped =
false;
405 if (NumCachedScopes) {
406 Scope *N = ScopeCache[--NumCachedScopes];
408 Actions.CurScope = N;
423 Actions.CurScope = OldScope->
getParent();
425 if (NumCachedScopes == ScopeCacheSize)
428 ScopeCache[NumCachedScopes++] = OldScope;
433 Parser::ParseScopeFlags::ParseScopeFlags(
Parser *Self,
unsigned ScopeFlags,
435 : CurScope(ManageFlags ? Self->getCurScope() : nullptr) {
437 OldFlags = CurScope->getFlags();
438 CurScope->setFlags(ScopeFlags);
444 Parser::ParseScopeFlags::~ParseScopeFlags() {
446 CurScope->setFlags(OldFlags);
457 Actions.CurScope =
nullptr;
460 for (
unsigned i = 0, e = NumCachedScopes; i != e; ++i)
461 delete ScopeCache[i];
463 resetPragmaHandlers();
469 DestroyTemplateIds();
476 assert(
getCurScope() ==
nullptr &&
"A scope is already active?");
491 ObjCTypeQuals[objc_null_unspecified]
495 Ident_instancetype =
nullptr;
496 Ident_final =
nullptr;
497 Ident_sealed =
nullptr;
498 Ident_abstract =
nullptr;
499 Ident_override =
nullptr;
500 Ident_GNU_final =
nullptr;
501 Ident_import =
nullptr;
502 Ident_module =
nullptr;
506 Ident_vector =
nullptr;
507 Ident_bool =
nullptr;
508 Ident_Bool =
nullptr;
509 Ident_pixel =
nullptr;
518 Ident_introduced =
nullptr;
519 Ident_deprecated =
nullptr;
520 Ident_obsoleted =
nullptr;
521 Ident_unavailable =
nullptr;
522 Ident_strict =
nullptr;
523 Ident_replacement =
nullptr;
525 Ident_language = Ident_defined_in = Ident_generated_declaration =
nullptr;
527 Ident__except =
nullptr;
529 Ident__exception_code = Ident__exception_info =
nullptr;
530 Ident__abnormal_termination = Ident___exception_code =
nullptr;
531 Ident___exception_info = Ident___abnormal_termination =
nullptr;
532 Ident_GetExceptionCode = Ident_GetExceptionInfo =
nullptr;
533 Ident_AbnormalTermination =
nullptr;
546 PP.
SetPoisonReason(Ident__exception_code,diag::err_seh___except_block);
547 PP.
SetPoisonReason(Ident___exception_code,diag::err_seh___except_block);
548 PP.
SetPoisonReason(Ident_GetExceptionCode,diag::err_seh___except_block);
549 PP.
SetPoisonReason(Ident__exception_info,diag::err_seh___except_filter);
550 PP.
SetPoisonReason(Ident___exception_info,diag::err_seh___except_filter);
551 PP.
SetPoisonReason(Ident_GetExceptionInfo,diag::err_seh___except_filter);
552 PP.
SetPoisonReason(Ident__abnormal_termination,diag::err_seh___finally_block);
553 PP.
SetPoisonReason(Ident___abnormal_termination,diag::err_seh___finally_block);
554 PP.
SetPoisonReason(Ident_AbnormalTermination,diag::err_seh___finally_block);
568 void Parser::DestroyTemplateIds() {
600 Diag(diag::ext_empty_translation_unit);
602 return NoTopLevelDecls;
613 DestroyTemplateIdAnnotationsRAIIObj CleanupRAII(*
this);
622 case tok::annot_pragma_unused:
623 HandlePragmaUnused();
637 case tok::identifier: {
639 if ((II == Ident_module || II == Ident_import) &&
640 GetLookAheadToken(2).isNot(tok::coloncolon)) {
641 if (II == Ident_module)
656 Result = ParseModuleDecl(ImportState);
666 case tok::annot_module_include:
668 reinterpret_cast<Module *
>(
670 ConsumeAnnotationToken();
673 case tok::annot_module_begin:
676 ConsumeAnnotationToken();
680 case tok::annot_module_end:
683 ConsumeAnnotationToken();
694 PP.
Diag(OverrideLoc, diag::note_max_tokens_total_override);
705 case tok::identifier:
725 MaybeParseCXX11Attributes(attrs);
727 Result = ParseExternalDeclaration(attrs);
769 DestroyTemplateIdAnnotationsRAIIObj CleanupRAII(*
this);
777 Decl *SingleDecl =
nullptr;
779 case tok::annot_pragma_vis:
780 HandlePragmaVisibility();
782 case tok::annot_pragma_pack:
785 case tok::annot_pragma_msstruct:
786 HandlePragmaMSStruct();
788 case tok::annot_pragma_align:
791 case tok::annot_pragma_weak:
794 case tok::annot_pragma_weakalias:
795 HandlePragmaWeakAlias();
797 case tok::annot_pragma_redefine_extname:
798 HandlePragmaRedefineExtname();
800 case tok::annot_pragma_fp_contract:
801 HandlePragmaFPContract();
803 case tok::annot_pragma_fenv_access:
804 case tok::annot_pragma_fenv_access_ms:
805 HandlePragmaFEnvAccess();
807 case tok::annot_pragma_fenv_round:
808 HandlePragmaFEnvRound();
810 case tok::annot_pragma_float_control:
811 HandlePragmaFloatControl();
813 case tok::annot_pragma_fp:
816 case tok::annot_pragma_opencl_extension:
817 HandlePragmaOpenCLExtension();
819 case tok::annot_attr_openmp:
820 case tok::annot_pragma_openmp: {
822 return ParseOpenMPDeclarativeDirectiveWithExtDecl(AS, Attrs);
824 case tok::annot_pragma_ms_pointers_to_members:
825 HandlePragmaMSPointersToMembers();
827 case tok::annot_pragma_ms_vtordisp:
828 HandlePragmaMSVtorDisp();
830 case tok::annot_pragma_ms_pragma:
831 HandlePragmaMSPragma();
833 case tok::annot_pragma_dump:
836 case tok::annot_pragma_attribute:
837 HandlePragmaAttribute();
843 ConsumeExtraSemi(OutsideFunction);
846 Diag(Tok, diag::err_extraneous_closing_brace);
850 Diag(Tok, diag::err_expected_external_declaration);
852 case tok::kw___extension__: {
856 return ParseExternalDeclaration(Attrs);
859 ProhibitAttributes(Attrs);
864 ExprResult Result(ParseSimpleAsm(
false, &EndLoc));
869 if (!(
getLangOpts().GNUAsm || Result.isInvalid())) {
870 const auto *SL = cast<StringLiteral>(Result.get());
871 if (!SL->getString().trim().empty())
872 Diag(StartLoc, diag::err_gnu_inline_asm_disabled);
875 ExpectAndConsume(tok::semi, diag::err_expected_after,
876 "top-level asm block");
878 if (Result.isInvalid())
884 return ParseObjCAtDirectives(Attrs);
888 Diag(Tok, diag::err_expected_external_declaration);
892 SingleDecl = ParseObjCMethodDefinition();
894 case tok::code_completion:
896 if (CurParsedObjCImpl) {
906 case tok::kw_import: {
909 llvm_unreachable(
"not expecting a c++20 import here");
910 ProhibitAttributes(Attrs);
916 ProhibitAttributes(Attrs);
917 SingleDecl = ParseExportDeclaration();
924 case tok::kw_namespace:
925 case tok::kw_typedef:
926 case tok::kw_template:
927 case tok::kw_static_assert:
928 case tok::kw__Static_assert:
951 if (NextKind == tok::kw_namespace) {
958 if (NextKind == tok::kw_template) {
973 diag::warn_cxx98_compat_extern_template :
974 diag::ext_extern_template) <<
SourceRange(ExternLoc, TemplateLoc);
981 case tok::kw___if_exists:
982 case tok::kw___if_not_exists:
983 ParseMicrosoftIfExistsExternalDeclaration();
987 Diag(Tok, diag::err_unexpected_module_decl);
998 return ParseDeclarationOrFunctionDefinition(Attrs, DS);
1008 bool Parser::isDeclarationAfterDeclarator() {
1012 if (KW.
is(tok::kw_default) || KW.
is(tok::kw_delete))
1016 return Tok.
is(tok::equal) ||
1017 Tok.
is(tok::comma) ||
1018 Tok.
is(tok::semi) ||
1019 Tok.
is(tok::kw_asm) ||
1020 Tok.
is(tok::kw___attribute) ||
1022 Tok.
is(tok::l_paren));
1029 if (Tok.
is(tok::l_brace))
1035 return isDeclarationSpecifier();
1039 return KW.
is(tok::kw_default) || KW.
is(tok::kw_delete);
1042 return Tok.
is(tok::colon) ||
1043 Tok.
is(tok::kw_try);
1066 ParseDeclarationSpecifiers(DS, ParsedTemplateInfo(), AS,
1067 DeclSpecContext::DSC_top_level);
1072 DS, AS, DeclSpecContext::DSC_top_level))
1077 if (Tok.
is(tok::semi)) {
1092 llvm_unreachable(
"we only expect to get the length of the class/struct/union/enum");
1102 ProhibitAttributes(Attrs, CorrectLocationForAttributes);
1109 Decl* decls[] = {AnonRecord, TheDecl};
1125 Diag(Tok, diag::err_objc_unexpected_attr);
1132 const char *PrevSpec =
nullptr;
1136 Diag(AtLoc, DiagID) << PrevSpec;
1139 return ParseObjCAtProtocolDeclaration(AtLoc, DS.
getAttributes());
1142 return ParseObjCAtImplementationDeclaration(AtLoc, DS.
getAttributes());
1145 ParseObjCAtInterfaceDeclaration(AtLoc, DS.
getAttributes()));
1164 return ParseDeclOrFunctionDefInternal(Attrs, *DS, AS);
1172 return ParseDeclOrFunctionDefInternal(Attrs, PDS, AS);
1191 const ParsedTemplateInfo &TemplateInfo,
1192 LateParsedAttrList *LateParsedAttrs) {
1196 TemplateParameterDepthRAII CurTemplateDepthTracker(TemplateParameterDepth);
1204 const char *PrevSpec;
1218 ParseKNRParamDeclarations(D);
1222 if (Tok.
isNot(tok::l_brace) &&
1224 (Tok.
isNot(tok::colon) && Tok.
isNot(tok::kw_try) &&
1225 Tok.
isNot(tok::equal)))) {
1226 Diag(Tok, diag::err_expected_fn_body);
1232 if (Tok.
isNot(tok::l_brace))
1238 if (Tok.
isNot(tok::equal)) {
1240 if (AL.isKnownToGCC() && !AL.isStandardAttributeSyntax())
1241 Diag(AL.getLoc(), diag::warn_attribute_on_function_definition) << AL;
1247 TemplateInfo.Kind == ParsedTemplateInfo::Template &&
1262 trySkippingFunctionBody()) {
1268 LexTemplateFunctionForLateParsing(Toks);
1277 else if (CurParsedObjCImpl &&
1278 !TemplateInfo.TemplateParams &&
1279 (Tok.
is(tok::l_brace) || Tok.
is(tok::kw_try) ||
1280 Tok.
is(tok::colon)) &&
1293 StashAwayMethodOrFunctionBodyTokens(FuncDecl);
1294 CurParsedObjCImpl->HasCFunction =
true;
1313 ? diag::warn_cxx98_compat_defaulted_deleted_function
1314 : diag::ext_defaulted_deleted_function)
1319 ? diag::warn_cxx98_compat_defaulted_deleted_function
1320 : diag::ext_defaulted_deleted_function)
1324 llvm_unreachable(
"function definition after = not 'delete' or 'default'");
1327 if (Tok.
is(tok::comma)) {
1328 Diag(KWLoc, diag::err_default_delete_in_multiple_declaration)
1331 }
else if (ExpectAndConsume(tok::semi, diag::err_expected_after,
1343 TemplateInfo.TemplateParams
1344 ? *TemplateInfo.TemplateParams
1346 &SkipBody, BodyKind);
1365 Stmt *GeneratedBody = Res ? Res->
getBody() :
nullptr;
1372 if (
auto *Template = dyn_cast_or_null<FunctionTemplateDecl>(Res))
1373 if (Template->isAbbreviated() &&
1374 Template->getTemplateParameters()->getParam(0)->isImplicit())
1377 CurTemplateDepthTracker.addDepth(1);
1380 trySkippingFunctionBody()) {
1386 if (Tok.
is(tok::kw_try))
1387 return ParseFunctionTryBlock(Res, BodyScope);
1391 if (Tok.
is(tok::colon)) {
1392 ParseConstructorInitializer(Res);
1395 if (!Tok.
is(tok::l_brace)) {
1404 if (LateParsedAttrs)
1405 ParseLexedAttributeList(*LateParsedAttrs, Res,
false,
true);
1407 return ParseFunctionStatementBody(Res, BodyScope);
1410 void Parser::SkipFunctionBody() {
1411 if (Tok.
is(tok::equal)) {
1416 bool IsFunctionTryBlock = Tok.
is(tok::kw_try);
1417 if (IsFunctionTryBlock)
1421 if (ConsumeAndStoreFunctionPrologue(Skipped))
1425 while (IsFunctionTryBlock && Tok.
is(tok::kw_catch)) {
1434 void Parser::ParseKNRParamDeclarations(
Declarator &D) {
1444 while (isDeclarationSpecifier()) {
1449 ParseDeclarationSpecifiers(DS);
1457 Diag(DSStart, diag::err_declaration_does_not_declare_param);
1466 diag::err_invalid_storage_class_in_func_decl);
1471 diag::err_invalid_storage_class_in_func_decl);
1477 ParseDeclarator(ParmDeclarator);
1482 MaybeParseGNUAttributes(ParmDeclarator);
1490 ParmDeclarator.getIdentifier()) {
1494 for (
unsigned i = 0; ; ++i) {
1498 Diag(ParmDeclarator.getIdentifierLoc(), diag::err_no_matching_param)
1499 << ParmDeclarator.getIdentifier();
1503 if (FTI.
Params[i].
Ident == ParmDeclarator.getIdentifier()) {
1506 Diag(ParmDeclarator.getIdentifierLoc(),
1507 diag::err_param_redefinition)
1508 << ParmDeclarator.getIdentifier();
1519 if (Tok.
isNot(tok::comma))
1522 ParmDeclarator.clear();
1528 ParseDeclarator(ParmDeclarator);
1532 if (!ExpectAndConsumeSemi(diag::err_expected_semi_declaration))
1555 ExprResult Parser::ParseAsmStringLiteral(
bool ForAsmLabel) {
1556 if (!isTokenStringLiteral()) {
1557 Diag(Tok, diag::err_expected_string_literal)
1563 if (!AsmString.isInvalid()) {
1564 const auto *SL = cast<StringLiteral>(AsmString.get());
1565 if (!SL->isAscii()) {
1566 Diag(Tok, diag::err_asm_operand_wide_string_literal)
1568 << SL->getSourceRange();
1571 if (ForAsmLabel && SL->getString().empty()) {
1572 Diag(Tok, diag::err_asm_operand_wide_string_literal)
1573 << 2 << SL->getSourceRange();
1586 assert(Tok.
is(tok::kw_asm) &&
"Not an asm!");
1589 if (isGNUAsmQualifier(Tok)) {
1593 Diag(Tok, diag::err_global_asm_qualifier_ignored)
1594 << GNUAsmQualifiers::getQualifierName(getGNUAsmQualifier(Tok))
1600 if (T.consumeOpen()) {
1601 Diag(Tok, diag::err_expected_lparen_after) <<
"asm";
1605 ExprResult Result(ParseAsmStringLiteral(ForAsmLabel));
1607 if (!Result.isInvalid()) {
1611 *EndLoc = T.getCloseLocation();
1625 assert(tok.
is(tok::annot_template_id) &&
"Expected template-id token");
1631 void Parser::AnnotateScopeToken(
CXXScopeSpec &SS,
bool IsNewAnnotation) {
1638 Tok.
setKind(tok::annot_cxxscope);
1645 if (IsNewAnnotation)
1656 Parser::AnnotatedNameKind
1658 assert(Tok.
is(tok::identifier) || Tok.
is(tok::annot_cxxscope));
1660 const bool EnteringContext =
false;
1661 const bool WasScopeAnnotation = Tok.
is(tok::annot_cxxscope);
1665 ParseOptionalCXXScopeSpecifier(SS,
nullptr,
1673 return ANK_Unresolved;
1681 if (isTentativelyDeclared(Name)) {
1686 return Tok.
is(tok::annot_typename) ? ANK_Success : ANK_TentativeDecl;
1703 isTemplateArgumentList(1) == TPResult::False) {
1705 Token FakeNext = Next;
1706 FakeNext.
setKind(tok::unknown);
1709 SS.
isEmpty() ? CCC :
nullptr);
1712 switch (Classification.
getKind()) {
1719 Tok.
setKind(Name->getTokenID());
1722 AnnotateScopeToken(SS, !WasScopeAnnotation);
1731 if (TryAltiVecVectorToken())
1759 Tok.
setKind(tok::annot_typename);
1760 setTypeAnnotation(Tok, Ty);
1768 Tok.
setKind(tok::annot_overload_set);
1777 if (TryAltiVecVectorToken())
1782 Tok.
setKind(tok::annot_non_type);
1788 AnnotateScopeToken(SS, !WasScopeAnnotation);
1794 ? tok::annot_non_type_undeclared
1795 : tok::annot_non_type_dependent);
1796 setIdentifierAnnotation(Tok, Name);
1801 AnnotateScopeToken(SS, !WasScopeAnnotation);
1805 if (Next.isNot(tok::less)) {
1808 AnnotateScopeToken(SS, !WasScopeAnnotation);
1809 return ANK_TemplateName;
1818 Id.setIdentifier(Name, NameLoc);
1819 if (AnnotateTemplateIdToken(
1827 Id.setIdentifier(Name, NameLoc);
1828 if (Next.is(tok::less))
1832 if (AnnotateTemplateIdToken(
1843 AnnotateScopeToken(SS, !WasScopeAnnotation);
1844 return ANK_Unresolved;
1847 bool Parser::TryKeywordIdentFallback(
bool DisableKeyword) {
1848 assert(Tok.
isNot(tok::identifier));
1849 Diag(Tok, diag::ext_keyword_as_ident)
1881 assert((Tok.
is(tok::identifier) || Tok.
is(tok::coloncolon) ||
1882 Tok.
is(tok::kw_typename) || Tok.
is(tok::annot_cxxscope) ||
1883 Tok.
is(tok::kw_decltype) || Tok.
is(tok::annot_template_id) ||
1884 Tok.
is(tok::kw___super)) &&
1885 "Cannot be a type or scope token!");
1887 if (Tok.
is(tok::kw_typename)) {
1896 PP.
Lex(TypedefToken);
1901 Diag(Tok.
getLocation(), diag::warn_expected_qualified_after_typename);
1913 if (ParseOptionalCXXScopeSpecifier(SS,
nullptr,
1919 if (Tok.
is(tok::identifier) || Tok.
is(tok::annot_template_id) ||
1920 Tok.
is(tok::annot_decltype)) {
1922 if (Tok.
is(tok::annot_decltype) ||
1924 unsigned DiagID = diag::err_expected_qualified_after_typename;
1928 DiagID = diag::warn_expected_qualified_after_typename;
1941 if (Tok.
is(tok::identifier)) {
1946 }
else if (Tok.
is(tok::annot_template_id)) {
1949 Diag(Tok, diag::err_typename_refers_to_non_type_template)
1963 TemplateArgsPtr, TemplateId->
RAngleLoc);
1965 Diag(Tok, diag::err_expected_type_name_after_typename)
1971 Tok.
setKind(tok::annot_typename);
1972 setTypeAnnotation(Tok, Ty);
1980 bool WasScopeAnnotation = Tok.
is(tok::annot_cxxscope);
1984 if (ParseOptionalCXXScopeSpecifier(SS,
nullptr,
1997 if (Tok.
is(tok::identifier)) {
2001 false,
NextToken().is(tok::period),
nullptr,
2029 Tok.
setKind(tok::annot_typename);
2030 setTypeAnnotation(Tok, Ty);
2054 bool MemberOfUnknownSpecialization;
2058 nullptr,
false, Template,
2059 MemberOfUnknownSpecialization)) {
2063 isTemplateArgumentList(1) != TPResult::False) {
2083 if (Tok.
is(tok::annot_template_id)) {
2090 AnnotateTemplateIdTokenAsType(SS);
2099 AnnotateScopeToken(SS, IsNewScope);
2111 "Call sites of this function should be guarded by checking for C++");
2115 if (ParseOptionalCXXScopeSpecifier(SS,
nullptr,
2122 AnnotateScopeToken(SS,
true);
2126 bool Parser::isTokenEqualOrEqualTypo() {
2132 case tok::starequal:
2133 case tok::plusequal:
2134 case tok::minusequal:
2135 case tok::exclaimequal:
2136 case tok::slashequal:
2137 case tok::percentequal:
2138 case tok::lessequal:
2139 case tok::lesslessequal:
2140 case tok::greaterequal:
2141 case tok::greatergreaterequal:
2142 case tok::caretequal:
2143 case tok::pipeequal:
2144 case tok::equalequal:
2145 Diag(Tok, diag::err_invalid_token_after_declarator_suggest_equal)
2155 assert(Tok.
is(tok::code_completion));
2159 if (S->isFunctionScope()) {
2163 return PrevTokLocation;
2166 if (S->isClassScope()) {
2169 return PrevTokLocation;
2175 return PrevTokLocation;
2180 void Parser::CodeCompleteDirective(
bool InConditional) {
2184 void Parser::CodeCompleteInConditionalExclusion() {
2188 void Parser::CodeCompleteMacroName(
bool IsDefinition) {
2192 void Parser::CodeCompletePreprocessorExpression() {
2198 unsigned ArgumentIndex) {
2203 void Parser::CodeCompleteIncludedFile(llvm::StringRef Dir,
bool IsAngled) {
2207 void Parser::CodeCompleteNaturalLanguage() {
2211 bool Parser::ParseMicrosoftIfExistsCondition(IfExistsCondition& Result) {
2212 assert((Tok.
is(tok::kw___if_exists) || Tok.
is(tok::kw___if_not_exists)) &&
2213 "Expected '__if_exists' or '__if_not_exists'");
2214 Result.IsIfExists = Tok.
is(tok::kw___if_exists);
2218 if (T.consumeOpen()) {
2219 Diag(Tok, diag::err_expected_lparen_after)
2220 << (Result.IsIfExists?
"__if_exists" :
"__if_not_exists");
2226 ParseOptionalCXXScopeSpecifier(Result.SS,
nullptr,
2231 if (Result.SS.isInvalid()) {
2242 false, &TemplateKWLoc,
2248 if (T.consumeClose())
2253 Result.IsIfExists, Result.SS,
2256 Result.Behavior = Result.IsIfExists ? IEB_Parse : IEB_Skip;
2260 Result.Behavior = !Result.IsIfExists ? IEB_Parse : IEB_Skip;
2264 Result.Behavior = IEB_Dependent;
2274 void Parser::ParseMicrosoftIfExistsExternalDeclaration() {
2275 IfExistsCondition Result;
2276 if (ParseMicrosoftIfExistsCondition(Result))
2280 if (Braces.consumeOpen()) {
2281 Diag(Tok, diag::err_expected) << tok::l_brace;
2285 switch (Result.Behavior) {
2291 llvm_unreachable(
"Cannot have a dependent external declaration");
2300 while (Tok.
isNot(tok::r_brace) && !isEofOrEom()) {
2302 MaybeParseCXX11Attributes(Attrs);
2307 Braces.consumeClose();
2332 (Tok.
is(tok::kw_module) ||
2334 "not a module declaration");
2339 DiagnoseAndSkipCXX11Attributes();
2345 Diag(StartLoc, diag::err_global_module_introducer_not_at_start)
2350 Diag(StartLoc, diag::err_module_fragment_exported)
2361 Diag(StartLoc, diag::err_module_fragment_exported)
2366 DiagnoseAndSkipCXX11Attributes();
2367 ExpectAndConsumeSemi(diag::err_private_module_fragment_expected_semi);
2373 if (ParseModuleName(ModuleLoc, Path,
false))
2378 if (Tok.
is(tok::colon)) {
2381 Diag(ColonLoc, diag::err_unsupported_module_partition)
2382 <<
SourceRange(ColonLoc, Partition.back().second);
2384 else if (ParseModuleName(ModuleLoc, Partition,
false))
2390 MaybeParseCXX11Attributes(Attrs);
2391 ProhibitCXX11Attributes(Attrs, diag::err_attribute_not_module_attr,
2395 ExpectAndConsumeSemi(diag::err_module_expected_semi);
2397 return Actions.
ActOnModuleDecl(StartLoc, ModuleLoc, MDK, Path, Partition,
2425 "Improper start to module import");
2431 bool IsPartition =
false;
2432 Module *HeaderUnit =
nullptr;
2433 if (Tok.
is(tok::header_name)) {
2438 }
else if (Tok.
is(tok::annot_header_unit)) {
2441 ConsumeAnnotationToken();
2442 }
else if (Tok.
is(tok::colon)) {
2445 Diag(ColonLoc, diag::err_unsupported_module_partition)
2448 else if (ParseModuleName(ColonLoc, Path,
true))
2453 if (ParseModuleName(ImportLoc, Path,
true))
2458 MaybeParseCXX11Attributes(Attrs);
2460 ProhibitCXX11Attributes(Attrs, diag::err_attribute_not_import_attr,
2471 bool SeenError =
true;
2472 switch (ImportState) {
2480 Diag(ImportLoc, diag::err_partition_import_outside_module);
2488 if (!HeaderUnit || HeaderUnit->
Kind != Module::ModuleKind::ModuleHeaderUnit)
2489 Diag(ImportLoc, diag::err_import_in_wrong_fragment) << IsPartition << 0;
2495 Diag(ImportLoc, diag::err_import_not_allowed_here);
2500 Diag(ImportLoc, diag::err_import_in_wrong_fragment) << IsPartition << 1;
2504 ExpectAndConsumeSemi(diag::err_module_expected_semi);
2512 else if (!Path.empty())
2515 ExpectAndConsumeSemi(diag::err_module_expected_semi);
2521 if (IsObjCAtImport && AtLoc.
isValid()) {
2524 if (FE && llvm::sys::path::parent_path(FE->getDir().getName())
2525 .endswith(
".framework"))
2526 Diags.
Report(AtLoc, diag::warn_atimport_in_framework_header);
2529 return Import.
get();
2539 bool Parser::ParseModuleName(
2545 if (!Tok.
is(tok::identifier)) {
2546 if (Tok.
is(tok::code_completion)) {
2552 Diag(Tok, diag::err_module_expected_ident) << IsImport;
2561 if (Tok.
isNot(tok::period))
2572 bool Parser::parseMisplacedModuleImport() {
2575 case tok::annot_module_end:
2579 if (MisplacedModuleBeginCount) {
2580 --MisplacedModuleBeginCount;
2582 reinterpret_cast<Module *
>(
2584 ConsumeAnnotationToken();
2591 case tok::annot_module_begin:
2594 reinterpret_cast<Module *
>(
2596 ConsumeAnnotationToken();
2597 ++MisplacedModuleBeginCount;
2599 case tok::annot_module_include:
2603 reinterpret_cast<Module *
>(
2605 ConsumeAnnotationToken();
2615 bool BalancedDelimiterTracker::diagnoseOverflow() {
2616 P.
Diag(P.Tok, diag::err_bracket_depth_exceeded)
2618 P.
Diag(P.Tok, diag::note_bracket_depth);
2627 if (P.ExpectAndConsume(Kind, DiagID, Msg)) {
2628 if (SkipToTok != tok::unknown)
2636 return diagnoseOverflow();
2639 bool BalancedDelimiterTracker::diagnoseMissingClose() {
2640 assert(!P.Tok.
is(Close) &&
"Should have consumed closing delimiter");
2642 if (P.Tok.
is(tok::annot_module_end))
2643 P.
Diag(P.Tok, diag::err_missing_before_module_end) << Close;
2645 P.
Diag(P.Tok, diag::err_expected) << Close;
2646 P.
Diag(LOpen, diag::note_matching) << Kind;
2650 if (P.Tok.
isNot(tok::r_paren) && P.Tok.
isNot(tok::r_brace) &&
2651 P.Tok.
isNot(tok::r_square) &&