23 #include "llvm/Support/raw_ostream.h"
24 using namespace clang;
34 explicit ActionCommentHandler(
Sema &
S) : S(S) { }
44 class DestroyTemplateIdAnnotationsRAIIObj {
48 DestroyTemplateIdAnnotationsRAIIObj(
50 : Container(Container) {}
52 ~DestroyTemplateIdAnnotationsRAIIObj() {
72 : PP(pp), Actions(actions), Diags(PP.getDiagnostics()),
73 GreaterThanIsOperator(
true), ColonIsSacred(
false),
74 InMessageExpression(
false), TemplateParameterDepth(0),
75 ParsingInObjCContainer(
false) {
79 Actions.CurScope =
nullptr;
81 ParenCount = BracketCount = BraceCount = 0;
82 CurParsedObjCImpl =
nullptr;
86 initializePragmaHandlers();
88 CommentSemaHandler.reset(
new ActionCommentHandler(actions));
95 return Diags.
Report(Loc, DiagID);
124 switch (ExpectedTok) {
126 return Tok.
is(tok::colon) || Tok.
is(tok::comma);
127 default:
return false;
131 bool Parser::ExpectAndConsume(
tok::TokenKind ExpectedTok,
unsigned DiagID,
133 if (Tok.
is(ExpectedTok) || Tok.
is(tok::code_completion)) {
145 if (DiagID == diag::err_expected)
147 else if (DiagID == diag::err_expected_after)
148 DB << Msg << ExpectedTok;
159 const char *Spelling =
nullptr;
167 if (DiagID == diag::err_expected)
169 else if (DiagID == diag::err_expected_after)
170 DB << Msg << ExpectedTok;
177 bool Parser::ExpectAndConsumeSemi(
unsigned DiagID) {
181 if (Tok.
is(tok::code_completion)) {
182 handleUnexpectedCodeCompletionToken();
186 if ((Tok.
is(tok::r_paren) || Tok.
is(tok::r_square)) &&
188 Diag(Tok, diag::err_extraneous_token_before_semi)
196 return ExpectAndConsume(tok::semi, DiagID);
199 void Parser::ConsumeExtraSemi(ExtraSemiKind
Kind,
unsigned TST) {
200 if (!Tok.
is(tok::semi))
return;
202 bool HadMultipleSemis =
false;
208 HadMultipleSemis =
true;
217 Diag(StartLoc, diag::warn_cxx98_compat_top_level_semi)
220 Diag(StartLoc, diag::ext_extra_semi_cxx11)
225 if (Kind != AfterMemberFunctionDefinition || HadMultipleSemis)
226 Diag(StartLoc, diag::ext_extra_semi)
232 Diag(StartLoc, diag::warn_extra_semi_after_mem_fn_def)
241 return (static_cast<unsigned>(L) & static_cast<unsigned>(R)) != 0;
255 bool isFirstTokenSkipped =
true;
258 for (
unsigned i = 0, NumToks = Toks.size(); i != NumToks; ++i) {
259 if (Tok.
is(Toks[i])) {
272 if (Toks.size() == 1 && Toks[0] ==
tok::eof &&
285 case tok::annot_pragma_openmp_end:
287 case tok::annot_module_begin:
288 case tok::annot_module_end:
289 case tok::annot_module_include:
295 case tok::code_completion:
297 handleUnexpectedCodeCompletionToken();
331 if (ParenCount && !isFirstTokenSkipped)
336 if (BracketCount && !isFirstTokenSkipped)
341 if (BraceCount && !isFirstTokenSkipped)
346 case tok::string_literal:
347 case tok::wide_string_literal:
348 case tok::utf8_string_literal:
349 case tok::utf16_string_literal:
350 case tok::utf32_string_literal:
351 ConsumeStringToken();
363 isFirstTokenSkipped =
false;
373 if (NumCachedScopes) {
374 Scope *N = ScopeCache[--NumCachedScopes];
376 Actions.CurScope = N;
391 Actions.CurScope = OldScope->
getParent();
393 if (NumCachedScopes == ScopeCacheSize)
396 ScopeCache[NumCachedScopes++] = OldScope;
401 Parser::ParseScopeFlags::ParseScopeFlags(
Parser *Self,
unsigned ScopeFlags,
403 : CurScope(ManageFlags ? Self->getCurScope() : nullptr) {
405 OldFlags = CurScope->getFlags();
406 CurScope->setFlags(ScopeFlags);
412 Parser::ParseScopeFlags::~ParseScopeFlags() {
414 CurScope->setFlags(OldFlags);
425 Actions.CurScope =
nullptr;
428 for (
unsigned i = 0, e = NumCachedScopes; i != e; ++i)
429 delete ScopeCache[i];
431 resetPragmaHandlers();
443 DestroyTemplateIdAnnotationsRAIIObj CleanupRAII(TemplateIds);
446 assert(TemplateIds.empty() &&
"Still alive TemplateIdAnnotations around?");
453 assert(
getCurScope() ==
nullptr &&
"A scope is already active?");
468 ObjCTypeQuals[objc_null_unspecified]
472 Ident_instancetype =
nullptr;
473 Ident_final =
nullptr;
474 Ident_sealed =
nullptr;
475 Ident_override =
nullptr;
479 Ident_vector =
nullptr;
480 Ident_bool =
nullptr;
481 Ident_pixel =
nullptr;
489 Ident_introduced =
nullptr;
490 Ident_deprecated =
nullptr;
491 Ident_obsoleted =
nullptr;
492 Ident_unavailable =
nullptr;
494 Ident__except =
nullptr;
496 Ident__exception_code = Ident__exception_info =
nullptr;
497 Ident__abnormal_termination = Ident___exception_code =
nullptr;
498 Ident___exception_info = Ident___abnormal_termination =
nullptr;
499 Ident_GetExceptionCode = Ident_GetExceptionInfo =
nullptr;
500 Ident_AbnormalTermination =
nullptr;
513 PP.
SetPoisonReason(Ident__exception_code,diag::err_seh___except_block);
514 PP.
SetPoisonReason(Ident___exception_code,diag::err_seh___except_block);
515 PP.
SetPoisonReason(Ident_GetExceptionCode,diag::err_seh___except_block);
516 PP.
SetPoisonReason(Ident__exception_info,diag::err_seh___except_filter);
517 PP.
SetPoisonReason(Ident___exception_info,diag::err_seh___except_filter);
518 PP.
SetPoisonReason(Ident_GetExceptionInfo,diag::err_seh___except_filter);
519 PP.
SetPoisonReason(Ident__abnormal_termination,diag::err_seh___finally_block);
520 PP.
SetPoisonReason(Ident___abnormal_termination,diag::err_seh___finally_block);
521 PP.
SetPoisonReason(Ident_AbnormalTermination,diag::err_seh___finally_block);
530 void Parser::LateTemplateParserCleanupCallback(
void *
P) {
534 DestroyTemplateIdAnnotationsRAIIObj CleanupRAII(((
Parser *)P)->TemplateIds);
540 DestroyTemplateIdAnnotationsRAIIObj CleanupRAII(TemplateIds);
549 case tok::annot_pragma_unused:
550 HandlePragmaUnused();
553 case tok::annot_module_include:
555 reinterpret_cast<Module *
>(
560 case tok::annot_module_begin:
566 case tok::annot_module_end:
577 LateTemplateParserCleanupCallback :
nullptr,
588 ParsedAttributesWithRange attrs(AttrFactory);
589 MaybeParseCXX11Attributes(attrs);
590 MaybeParseMicrosoftAttributes(attrs);
592 Result = ParseExternalDeclaration(attrs);
620 Parser::ParseExternalDeclaration(ParsedAttributesWithRange &attrs,
622 DestroyTemplateIdAnnotationsRAIIObj CleanupRAII(TemplateIds);
630 Decl *SingleDecl =
nullptr;
632 case tok::annot_pragma_vis:
633 HandlePragmaVisibility();
635 case tok::annot_pragma_pack:
638 case tok::annot_pragma_msstruct:
639 HandlePragmaMSStruct();
641 case tok::annot_pragma_align:
644 case tok::annot_pragma_weak:
647 case tok::annot_pragma_weakalias:
648 HandlePragmaWeakAlias();
650 case tok::annot_pragma_redefine_extname:
651 HandlePragmaRedefineExtname();
653 case tok::annot_pragma_fp_contract:
654 HandlePragmaFPContract();
656 case tok::annot_pragma_opencl_extension:
657 HandlePragmaOpenCLExtension();
659 case tok::annot_pragma_openmp:
660 return ParseOpenMPDeclarativeDirective();
661 case tok::annot_pragma_ms_pointers_to_members:
662 HandlePragmaMSPointersToMembers();
664 case tok::annot_pragma_ms_vtordisp:
665 HandlePragmaMSVtorDisp();
667 case tok::annot_pragma_ms_pragma:
668 HandlePragmaMSPragma();
675 ConsumeExtraSemi(OutsideFunction);
678 Diag(Tok, diag::err_extraneous_closing_brace);
682 Diag(Tok, diag::err_expected_external_declaration);
684 case tok::kw___extension__: {
688 return ParseExternalDeclaration(attrs);
691 ProhibitAttributes(attrs);
702 const auto *SL = cast<StringLiteral>(
Result.get());
703 if (!SL->getString().trim().empty())
704 Diag(StartLoc, diag::err_gnu_inline_asm_disabled);
707 ExpectAndConsume(tok::semi, diag::err_expected_after,
708 "top-level asm block");
716 return ParseObjCAtDirectives();
720 Diag(Tok, diag::err_expected_external_declaration);
724 SingleDecl = ParseObjCMethodDefinition();
726 case tok::code_completion:
733 case tok::kw_namespace:
734 case tok::kw_typedef:
735 case tok::kw_template:
737 case tok::kw_static_assert:
738 case tok::kw__Static_assert:
761 if (NextKind == tok::kw_namespace) {
768 if (NextKind == tok::kw_template) {
783 diag::warn_cxx98_compat_extern_template :
784 diag::ext_extern_template) <<
SourceRange(ExternLoc, TemplateLoc);
788 ExternLoc, TemplateLoc, DeclEnd));
792 case tok::kw___if_exists:
793 case tok::kw___if_not_exists:
794 ParseMicrosoftIfExistsExternalDeclaration();
800 return ParseDeclarationOrFunctionDefinition(attrs, DS);
810 bool Parser::isDeclarationAfterDeclarator() {
814 if (KW.
is(tok::kw_default) || KW.
is(tok::kw_delete))
818 return Tok.
is(tok::equal) ||
819 Tok.
is(tok::comma) ||
821 Tok.
is(tok::kw_asm) ||
822 Tok.
is(tok::kw___attribute) ||
824 Tok.
is(tok::l_paren));
831 if (Tok.
is(tok::l_brace))
837 return isDeclarationSpecifier();
841 return KW.
is(tok::kw_default) || KW.
is(tok::kw_delete);
844 return Tok.
is(tok::colon) ||
865 Parser::ParseDeclOrFunctionDefInternal(ParsedAttributesWithRange &attrs,
869 ParseDeclarationSpecifiers(DS, ParsedTemplateInfo(), AS, DSC_top_level);
874 DiagnoseMissingSemiAfterTagDefinition(DS, AS, DSC_top_level))
879 if (Tok.
is(tok::semi)) {
880 ProhibitAttributes(attrs);
896 Diag(Tok, diag::err_objc_unexpected_attr);
903 const char *PrevSpec =
nullptr;
907 Diag(AtLoc, DiagID) << PrevSpec;
910 return ParseObjCAtProtocolDeclaration(AtLoc, DS.
getAttributes());
919 if (
getLangOpts().CPlusPlus && isTokenStringLiteral() &&
930 Parser::ParseDeclarationOrFunctionDefinition(ParsedAttributesWithRange &attrs,
934 return ParseDeclOrFunctionDefInternal(attrs, *DS, AS);
942 return ParseDeclOrFunctionDefInternal(attrs, PDS, AS);
961 const ParsedTemplateInfo &TemplateInfo,
962 LateParsedAttrList *LateParsedAttrs) {
971 const char *PrevSpec;
985 ParseKNRParamDeclarations(D);
989 if (Tok.
isNot(tok::l_brace) &&
991 (Tok.
isNot(tok::colon) && Tok.
isNot(tok::kw_try) &&
992 Tok.
isNot(tok::equal)))) {
993 Diag(Tok, diag::err_expected_fn_body);
999 if (Tok.
isNot(tok::l_brace))
1005 if (Tok.
isNot(tok::equal)) {
1010 Diag(DtorAttrs->
getLoc(), diag::warn_attribute_on_function_definition)
1013 DtorAttrs = DtorAttrs->
getNext();
1020 TemplateInfo.Kind == ParsedTemplateInfo::Template &&
1034 LexTemplateFunctionForLateParsing(Toks);
1043 else if (CurParsedObjCImpl &&
1044 !TemplateInfo.TemplateParams &&
1045 (Tok.
is(tok::l_brace) || Tok.
is(tok::kw_try) ||
1046 Tok.
is(tok::colon)) &&
1058 StashAwayMethodOrFunctionBodyTokens(FuncDecl);
1059 CurParsedObjCImpl->HasCFunction =
true;
1070 Decl *Res = TemplateInfo.TemplateParams?
1072 *TemplateInfo.TemplateParams, D)
1085 bool Delete =
false;
1089 ? diag::warn_cxx98_compat_deleted_function
1090 : diag::ext_deleted_function);
1095 ? diag::warn_cxx98_compat_defaulted_function
1096 : diag::ext_defaulted_function);
1099 llvm_unreachable(
"function definition after = not 'delete' or 'default'");
1102 if (Tok.
is(tok::comma)) {
1103 Diag(KWLoc, diag::err_default_delete_in_multiple_declaration)
1106 }
else if (ExpectAndConsume(tok::semi, diag::err_expected_after,
1107 Delete ?
"delete" :
"default")) {
1111 Stmt *GeneratedBody = Res ? Res->
getBody() :
nullptr;
1116 if (Tok.
is(tok::kw_try))
1117 return ParseFunctionTryBlock(Res, BodyScope);
1121 if (Tok.
is(tok::colon)) {
1122 ParseConstructorInitializer(Res);
1125 if (!Tok.
is(tok::l_brace)) {
1134 if (LateParsedAttrs)
1135 ParseLexedAttributeList(*LateParsedAttrs, Res,
false,
true);
1137 return ParseFunctionStatementBody(Res, BodyScope);
1142 void Parser::ParseKNRParamDeclarations(Declarator &D) {
1152 while (isDeclarationSpecifier()) {
1157 ParseDeclarationSpecifiers(DS);
1165 Diag(DSStart, diag::err_declaration_does_not_declare_param);
1174 diag::err_invalid_storage_class_in_func_decl);
1179 diag::err_invalid_storage_class_in_func_decl);
1185 ParseDeclarator(ParmDeclarator);
1190 MaybeParseGNUAttributes(ParmDeclarator);
1198 ParmDeclarator.getIdentifier()) {
1202 for (
unsigned i = 0; ; ++i) {
1206 Diag(ParmDeclarator.getIdentifierLoc(), diag::err_no_matching_param)
1207 << ParmDeclarator.getIdentifier();
1211 if (FTI.
Params[i].
Ident == ParmDeclarator.getIdentifier()) {
1214 Diag(ParmDeclarator.getIdentifierLoc(),
1215 diag::err_param_redefinition)
1216 << ParmDeclarator.getIdentifier();
1227 if (Tok.
isNot(tok::comma))
1230 ParmDeclarator.clear();
1236 ParseDeclarator(ParmDeclarator);
1240 if (!ExpectAndConsumeSemi(diag::err_expected_semi_declaration))
1261 if (!isTokenStringLiteral()) {
1262 Diag(Tok, diag::err_expected_string_literal)
1267 ExprResult AsmString(ParseStringLiteralExpression());
1268 if (!AsmString.isInvalid()) {
1269 const auto *SL = cast<StringLiteral>(AsmString.get());
1270 if (!SL->isAscii()) {
1271 Diag(Tok, diag::err_asm_operand_wide_string_literal)
1273 << SL->getSourceRange();
1286 assert(Tok.
is(tok::kw_asm) &&
"Not an asm!");
1289 if (Tok.
is(tok::kw_volatile)) {
1294 Diag(Tok, diag::warn_file_asm_volatile)
1300 if (T.consumeOpen()) {
1301 Diag(Tok, diag::err_expected_lparen_after) <<
"asm";
1307 if (!
Result.isInvalid()) {
1311 *EndLoc = T.getCloseLocation();
1325 assert(tok.
is(tok::annot_template_id) &&
"Expected template-id token");
1331 void Parser::AnnotateScopeToken(
CXXScopeSpec &SS,
bool IsNewAnnotation) {
1338 Tok.
setKind(tok::annot_cxxscope);
1345 if (IsNewAnnotation)
1358 Parser::AnnotatedNameKind
1359 Parser::TryAnnotateName(
bool IsAddressOfOperand,
1360 std::unique_ptr<CorrectionCandidateCallback> CCC) {
1361 assert(Tok.
is(tok::identifier) || Tok.
is(tok::annot_cxxscope));
1363 const bool EnteringContext =
false;
1364 const bool WasScopeAnnotation = Tok.
is(tok::annot_cxxscope);
1368 ParseOptionalCXXScopeSpecifier(SS,
ParsedType(), EnteringContext))
1373 !WasScopeAnnotation))
1375 return ANK_Unresolved;
1383 if (isTentativelyDeclared(Name)) {
1387 !WasScopeAnnotation))
1389 return Tok.
is(tok::annot_typename) ? ANK_Success : ANK_TentativeDecl;
1399 getCurScope(), SS, Name, NameLoc, Next, IsAddressOfOperand,
1400 SS.
isEmpty() ? std::move(CCC) : nullptr);
1402 switch (Classification.
getKind()) {
1412 AnnotateScopeToken(SS, !WasScopeAnnotation);
1435 = parseObjCTypeArgsAndProtocolQualifiers(IdentifierLoc, Ty,
1442 Tok.
setKind(tok::annot_typename);
1443 setTypeAnnotation(Tok, Ty);
1451 Tok.
setKind(tok::annot_primary_expr);
1460 if (Next.
isNot(tok::less)) {
1463 AnnotateScopeToken(SS, !WasScopeAnnotation);
1464 return ANK_TemplateName;
1473 if (AnnotateTemplateIdToken(
1481 llvm_unreachable(
"already parsed nested name specifier");
1486 AnnotateScopeToken(SS, !WasScopeAnnotation);
1487 return ANK_Unresolved;
1490 bool Parser::TryKeywordIdentFallback(
bool DisableKeyword) {
1491 assert(Tok.
isNot(tok::identifier));
1492 Diag(Tok, diag::ext_keyword_as_ident)
1524 assert((Tok.
is(tok::identifier) || Tok.
is(tok::coloncolon) ||
1525 Tok.
is(tok::kw_typename) || Tok.
is(tok::annot_cxxscope) ||
1526 Tok.
is(tok::kw_decltype) || Tok.
is(tok::annot_template_id) ||
1527 Tok.
is(tok::kw___super)) &&
1528 "Cannot be a type or scope token!");
1530 if (Tok.
is(tok::kw_typename)) {
1539 PP.
Lex(TypedefToken);
1544 Diag(Tok.
getLocation(), diag::warn_expected_qualified_after_typename);
1556 if (ParseOptionalCXXScopeSpecifier(SS,
ParsedType(),
1561 if (Tok.
is(tok::identifier) || Tok.
is(tok::annot_template_id) ||
1562 Tok.
is(tok::annot_decltype)) {
1564 if (Tok.
is(tok::annot_decltype) ||
1567 unsigned DiagID = diag::err_expected_qualified_after_typename;
1571 DiagID = diag::warn_expected_qualified_after_typename;
1582 if (Tok.
is(tok::identifier)) {
1587 }
else if (Tok.
is(tok::annot_template_id)) {
1591 Diag(Tok, diag::err_typename_refers_to_non_type_template)
1607 Diag(Tok, diag::err_expected_type_name_after_typename)
1613 Tok.
setKind(tok::annot_typename);
1622 bool WasScopeAnnotation = Tok.
is(tok::annot_cxxscope);
1626 if (ParseOptionalCXXScopeSpecifier(SS,
ParsedType(), EnteringContext))
1630 SS, !WasScopeAnnotation);
1640 if (Tok.
is(tok::identifier)) {
1650 NeedType ? &CorrectedII
1669 = parseObjCTypeArgsAndProtocolQualifiers(IdentifierLoc, Ty,
1678 Tok.
setKind(tok::annot_typename);
1679 setTypeAnnotation(Tok, Ty);
1701 bool MemberOfUnknownSpecialization;
1704 false, TemplateName,
1707 Template, MemberOfUnknownSpecialization)) {
1726 if (Tok.
is(tok::annot_template_id)) {
1733 AnnotateTemplateIdTokenAsType();
1742 AnnotateScopeToken(SS, IsNewScope);
1754 "Call sites of this function should be guarded by checking for C++");
1755 assert((Tok.
is(tok::identifier) || Tok.
is(tok::coloncolon) ||
1756 (Tok.
is(tok::annot_template_id) &&
NextToken().
is(tok::coloncolon)) ||
1757 Tok.
is(tok::kw_decltype) || Tok.
is(tok::kw___super)) &&
1758 "Cannot be a type or scope token!");
1761 if (ParseOptionalCXXScopeSpecifier(SS,
ParsedType(), EnteringContext))
1766 AnnotateScopeToken(SS,
true);
1770 bool Parser::isTokenEqualOrEqualTypo() {
1776 case tok::starequal:
1777 case tok::plusequal:
1778 case tok::minusequal:
1779 case tok::exclaimequal:
1780 case tok::slashequal:
1781 case tok::percentequal:
1782 case tok::lessequal:
1783 case tok::lesslessequal:
1784 case tok::greaterequal:
1785 case tok::greatergreaterequal:
1786 case tok::caretequal:
1787 case tok::pipeequal:
1788 case tok::equalequal:
1789 Diag(Tok, diag::err_invalid_token_after_declarator_suggest_equal)
1798 assert(Tok.
is(tok::code_completion));
1806 return PrevTokLocation;
1812 return PrevTokLocation;
1818 return PrevTokLocation;
1823 void Parser::CodeCompleteDirective(
bool InConditional) {
1827 void Parser::CodeCompleteInConditionalExclusion() {
1831 void Parser::CodeCompleteMacroName(
bool IsDefinition) {
1835 void Parser::CodeCompletePreprocessorExpression() {
1841 unsigned ArgumentIndex) {
1846 void Parser::CodeCompleteNaturalLanguage() {
1850 bool Parser::ParseMicrosoftIfExistsCondition(IfExistsCondition& Result) {
1851 assert((Tok.
is(tok::kw___if_exists) || Tok.
is(tok::kw___if_not_exists)) &&
1852 "Expected '__if_exists' or '__if_not_exists'");
1853 Result.IsIfExists = Tok.
is(tok::kw___if_exists);
1857 if (T.consumeOpen()) {
1858 Diag(Tok, diag::err_expected_lparen_after)
1859 << (Result.IsIfExists?
"__if_exists" :
"__if_not_exists");
1865 ParseOptionalCXXScopeSpecifier(Result.SS,
ParsedType(),
1869 if (Result.SS.isInvalid()) {
1877 TemplateKWLoc, Result.Name)) {
1882 if (T.consumeClose())
1887 Result.IsIfExists, Result.SS,
1890 Result.Behavior = Result.IsIfExists ? IEB_Parse : IEB_Skip;
1894 Result.Behavior = !Result.IsIfExists ? IEB_Parse : IEB_Skip;
1898 Result.Behavior = IEB_Dependent;
1908 void Parser::ParseMicrosoftIfExistsExternalDeclaration() {
1909 IfExistsCondition
Result;
1910 if (ParseMicrosoftIfExistsCondition(Result))
1914 if (Braces.consumeOpen()) {
1915 Diag(Tok, diag::err_expected) << tok::l_brace;
1919 switch (Result.Behavior) {
1925 llvm_unreachable(
"Cannot have a dependent external declaration");
1934 while (Tok.
isNot(tok::r_brace) && !isEofOrEom()) {
1935 ParsedAttributesWithRange attrs(AttrFactory);
1936 MaybeParseCXX11Attributes(attrs);
1937 MaybeParseMicrosoftAttributes(attrs);
1942 Braces.consumeClose();
1947 "Improper start to module import");
1954 if (!Tok.
is(tok::identifier)) {
1955 if (Tok.
is(tok::code_completion)) {
1961 Diag(Tok, diag::err_module_expected_ident);
1970 if (Tok.
is(tok::period)) {
1985 ExpectAndConsumeSemi(diag::err_module_expected_semi);
1992 bool BalancedDelimiterTracker::diagnoseOverflow() {
1993 P.Diag(P.Tok, diag::err_bracket_depth_exceeded)
1994 << P.getLangOpts().BracketDepth;
1995 P.Diag(P.Tok, diag::note_bracket_depth);
2003 LOpen = P.Tok.getLocation();
2004 if (P.ExpectAndConsume(Kind, DiagID, Msg)) {
2005 if (SkipToTok != tok::unknown)
2010 if (getDepth() < MaxDepth)
2013 return diagnoseOverflow();
2016 bool BalancedDelimiterTracker::diagnoseMissingClose() {
2017 assert(!P.Tok.is(Close) &&
"Should have consumed closing delimiter");
2019 P.Diag(P.Tok, diag::err_expected) << Close;
2020 P.Diag(LOpen, diag::note_matching) << Kind;
2024 if (P.Tok.isNot(tok::r_paren) && P.Tok.isNot(tok::r_brace) &&
2025 P.Tok.isNot(tok::r_square) &&
2026 P.SkipUntil(Close, FinalToken,
2029 LClose = P.ConsumeAnyToken();
MutableArrayRef< TemplateParameterList * > MultiTemplateParamsArg
bool isAtStartOfLine() const
SourceLocation getThreadStorageClassSpecLoc() const
Defines the clang::ASTContext interface.
SourceLocation getEnd() const
DeclaratorChunk::FunctionTypeInfo & getFunctionTypeInfo()
This is a scope that corresponds to the parameters within a function prototype.
void Initialize()
Perform initialization that occurs after the parser has been initialized but before it parses anythin...
Code completion occurs within a class, struct, or union.
const LangOptions & getLangOpts() const
SourceLocation TemplateNameLoc
const Scope * getParent() const
IdentifierInfo * getIdentifierInfo(StringRef Name) const
Defines the C++ template declaration subclasses.
SCS getStorageClassSpec() const
void CodeCompleteNaturalLanguage()
bool TryAnnotateCXXScopeToken(bool EnteringContext=false)
This indicates that the scope corresponds to a function, which means that labels are set here...
DiagnosticBuilder Report(SourceLocation Loc, unsigned DiagID)
Issue the message to the client.
static const char * getSpecifierName(DeclSpec::TST T, const PrintingPolicy &Policy)
Turn a type-specifier-type into a string like "_Bool" or "union".
AccessSpecifier
A C++ access specifier (public, private, protected), plus the special value "none" which means differ...
TemplateNameKind Kind
The kind of template that Template refers to.
Wrapper for void* pointer.
void * SaveNestedNameSpecifierAnnotation(CXXScopeSpec &SS)
Given a C++ nested-name-specifier, produce an annotation value that the parser can use later to recon...
void ActOnDefaultCtorInitializers(Decl *CDtorDecl)
static const TSCS TSCS_unspecified
void EnterToken(const Token &Tok)
Enters a token in the token stream to be lexed next.
Information about one declarator, including the parsed type information and the identifier.
TypeSpecifierType
Specifies the kind of type.
Describes how types, statements, expressions, and declarations should be printed. ...
Code completion occurs within an Objective-C implementation or category implementation.
RAII object that makes sure paren/bracket/brace count is correct after declaration/statement parsing...
Decl * ActOnParamDeclarator(Scope *S, Declarator &D)
const ParsingDeclSpec & getDeclSpec() const
friend class ObjCDeclContextSwitch
void MarkAsLateParsedTemplate(FunctionDecl *FD, Decl *FnD, CachedTokens &Toks)
StringRef getSpelling(SourceLocation loc, SmallVectorImpl< char > &buffer, bool *invalid=nullptr) const
bool isEmpty() const
No scope specifier.
bool SkipUntil(tok::TokenKind T, SkipUntilFlags Flags=static_cast< SkipUntilFlags >(0))
Information about a template-id annotation token.
void CodeCompleteOrdinaryName(Scope *S, ParserCompletionContext CompletionContext)
const Token & NextToken()
SourceLocation getLocForEndOfToken(SourceLocation Loc, unsigned Offset=0)
Computes the source location just past the end of the token at this source location.
bool TryConsumeToken(tok::TokenKind Expected)
void SetPoisonReason(IdentifierInfo *II, unsigned DiagID)
Specifies the reason for poisoning an identifier.
OpaquePtr< QualType > ParsedType
DeclGroupPtrTy ConvertDeclToDeclGroup(Decl *Ptr, Decl *OwnedType=nullptr)
void ActOnEndOfTranslationUnit()
bool isTranslationUnit() const
void CodeCompletePreprocessorMacroArgument(Scope *S, IdentifierInfo *Macro, MacroInfo *MacroInfo, unsigned Argument)
void setKind(tok::TokenKind K)
RAII class that helps handle the parsing of an open/close delimiter pair, such as braces { ...
void removeCommentHandler(CommentHandler *Handler)
Remove the specified comment handler.
void ClearStorageClassSpecs()
Describes a module or submodule.
Code completion occurs at top-level or namespace context.
static bool HasFlagsSet(Parser::SkipUntilFlags L, Parser::SkipUntilFlags R)
Code completion occurs within the body of a function on a recovery path, where we do not have a speci...
Represents a C++ unqualified-id that has been parsed.
ParsedType getTypeName(const IdentifierInfo &II, SourceLocation NameLoc, Scope *S, CXXScopeSpec *SS=nullptr, bool isClassName=false, bool HasTrailingDot=false, ParsedType ObjectType=ParsedType(), bool IsCtorOrDtorName=false, bool WantNontrivialTypeSourceInfo=false, IdentifierInfo **CorrectedII=nullptr)
If the identifier refers to a type name within this scope, return the declaration of that type...
void SetRangeBegin(SourceLocation Loc)
tok::TokenKind getTokenID() const
void CodeCompleteModuleImport(SourceLocation ImportLoc, ModuleIdPath Path)
ParsedTemplateArgument * getTemplateArgs()
Retrieves a pointer to the template arguments.
bool hadModuleLoaderFatalFailure() const
IfExistsResult CheckMicrosoftIfExistsSymbol(Scope *S, CXXScopeSpec &SS, const DeclarationNameInfo &TargetNameInfo)
void ActOnModuleInclude(SourceLocation DirectiveLoc, Module *Mod)
The parser has processed a module import translated from a #include or similar preprocessing directiv...
Decl * ActOnFileScopeAsmDecl(Expr *expr, SourceLocation AsmLoc, SourceLocation RParenLoc)
Represents a C++ nested-name-specifier or a global scope specifier.
tok::TokenKind getKind() const
void setCodeCompletionHandler(CodeCompletionHandler &Handler)
Set the code completion handler to the given object.
Decl * ActOnFinishFunctionBody(Decl *Decl, Stmt *Body)
const SourceRange & getSourceRange() const LLVM_READONLY
SourceLocation TemplateKWLoc
void * getAnnotationValue() const
Decl * ActOnStartOfFunctionDef(Scope *S, Declarator &D)
Sema - This implements semantic analysis and AST building for C.
Decl * ActOnEmptyDeclaration(Scope *S, AttributeList *AttrList, SourceLocation SemiLoc)
Handle a C++11 empty-declaration and attribute-declaration.
bool isFunctionDeclarator(unsigned &idx) const
A little helper class used to produce diagnostics.
A class for parsing a declarator.
void clearCodeCompletionHandler()
Clear out the code completion handler.
NameClassificationKind getKind() const
void setAnnotationRange(SourceRange R)
SourceRange getAnnotationRange() const
SourceRange of the group of tokens that this annotation token represents.
void setAnnotationValue(void *val)
TemplateNameKind getTemplateNameKind() const
void AnnotateCachedTokens(const Token &Tok)
This file defines the classes used to store parsed information about declaration-specifiers and decla...
void RevertCachedTokens(unsigned N)
When backtracking is enabled and tokens are cached, this allows to revert a specific number of tokens...
Represents a C++ template name within the type system.
void CodeCompletePreprocessorExpression()
const char * getPunctuatorSpelling(TokenKind Kind) LLVM_READNONE
Determines the spelling of simple punctuation tokens like '!' or '', and returns NULL for literal and...
SourceLocation getLocation() const
Return a source location identifier for the specified offset in the current file. ...
TemplateNameKind
Specifies the kind of template name that an identifier refers to. Be careful when changing this: this...
bool isNot(tok::TokenKind K) const
const SourceRange & getRange() const
void SetDeclDeleted(Decl *dcl, SourceLocation DelLoc)
Wraps an identifier and optional source location for the identifier.
TemplateNameKind isTemplateName(Scope *S, CXXScopeSpec &SS, bool hasTemplateKeyword, UnqualifiedId &Name, ParsedType ObjectType, bool EnteringContext, TemplateTy &Template, bool &MemberOfUnknownSpecialization)
The result type of a method or function.
SourceLocation getStorageClassSpecLoc() const
OpaquePtr< DeclGroupRef > DeclGroupPtrTy
const clang::PrintingPolicy & getPrintingPolicy() const
NameClassification ClassifyName(Scope *S, CXXScopeSpec &SS, IdentifierInfo *&Name, SourceLocation NameLoc, const Token &NextToken, bool IsAddressOfOperand, std::unique_ptr< CorrectionCandidateCallback > CCC=nullptr)
Perform name lookup on the given name, classifying it based on the results of name lookup and the fol...
This is a scope that corresponds to the parameters within a function prototype for a function declara...
A class for parsing a DeclSpec.
bool isKNRPrototype() const
void ActOnFinishKNRParamDeclarations(Scope *S, Declarator &D, SourceLocation LocAfterDecls)
void TypoCorrectToken(const Token &Tok)
FunctionDecl * getAsFunction() LLVM_READONLY
Returns the function itself, or the templated function if this is a function template.
Encodes a location in the source. The SourceManager can decode this to get at the full include stack...
bool isIncrementalProcessingEnabled() const
Returns true if incremental processing is enabled.
IdentifierInfo & get(StringRef Name)
Return the identifier token info for the specified named identifier.
bool isValid() const
Return true if this is a valid SourceLocation object.
void ExitScope()
ExitScope - Pop a scope off the scope stack.
ASTContext & getASTContext() const
bool isCodeCompletionReached() const
Returns true if code-completion is enabled and we have hit the code-completion point.
Parser(Preprocessor &PP, Sema &Actions, bool SkipFunctionBodies)
void setAnnotationEndLoc(SourceLocation L)
IdentifierTable & getIdentifierTable()
Scope * getCurScope() const
bool isObjCAtKeyword(tok::ObjCKeywordKind objcKey) const
Return true if we have an ObjC keyword identifier.
void setIdentifierInfo(IdentifierInfo *II)
void SetDeclDefaulted(Decl *dcl, SourceLocation DefaultLoc)
bool canDelayFunctionBody(const Declarator &D)
Determine whether we can delay parsing the body of a function or function template until it is used...
void CodeCompletePreprocessorDirective(bool InConditional)
void Lex(Token &Result)
Lex the next token for this preprocessor.
void EnterScope(unsigned ScopeFlags)
EnterScope - Start a new scope.
bool isInvalid() const
An error occurred during parsing of the scope specifier.
bool TryAnnotateTypeOrScopeTokenAfterScopeSpec(bool EnteringContext, bool NeedType, CXXScopeSpec &SS, bool IsNewScope)
Try to annotate a type or scope token, having already parsed an optional scope specifier. IsNewScope should be true unless the scope specifier was extracted from an existing tok::annot_cxxscope annotation.
SourceLocation getLastLoc() const
virtual Stmt * getBody() const
ASTConsumer & getASTConsumer() const
TokenKind
Provides a simple uniform namespace for tokens from all C languages.
static bool IsCommonTypo(tok::TokenKind ExpectedTok, const Token &Tok)
void SetLateTemplateParser(LateTemplateParserCB *LTP, LateTemplateParserCleanupCB *LTPCleanup, void *P)
SourceLocation getBegin() const
SourceLocation getBeginLoc() const
bool is(tok::TokenKind K) const
The name is a dependent name, so the results will differ from one instantiation to the next...
void Init(Scope *parent, unsigned flags)
bool ParseUnqualifiedId(CXXScopeSpec &SS, bool EnteringContext, bool AllowDestructorName, bool AllowConstructorName, ParsedType ObjectType, SourceLocation &TemplateKWLoc, UnqualifiedId &Result)
Parse a C++ unqualified-id (or a C identifier), which describes the name of an entity.
void CodeCompletePreprocessorMacroName(bool IsDefinition)
void setFunctionDefinitionKind(FunctionDefinitionKind Val)
The scope of a struct/union/class definition.
void RevertTokenIDToIdentifier()
Revert TokenID to tok::identifier; used for GNU libstdc++ 4.2 compatibility.
TSCS getThreadStorageClassSpec() const
bool expectAndConsume(unsigned DiagID=diag::err_expected, const char *Msg="", tok::TokenKind SkipToTok=tok::unknown)
void addCommentHandler(CommentHandler *Handler)
Add the specified comment handler to the preprocessor.
void ActOnModuleBegin(SourceLocation DirectiveLoc, Module *Mod)
The parsed has entered a submodule.
bool hasTagDefinition() const
static FixItHint CreateRemoval(CharSourceRange RemoveRange)
Create a code modification hint that removes the given source range.
ParsingDeclSpec & getMutableDeclSpec() const
SkipUntilFlags
Control flags for SkipUntil functions.
TypeResult ActOnTypenameType(Scope *S, SourceLocation TypenameLoc, const CXXScopeSpec &SS, const IdentifierInfo &II, SourceLocation IdLoc)
Called when the parser has parsed a C++ typename specifier, e.g., "typename T::type".
static const TST TST_unspecified
Encapsulates the data about a macro definition (e.g. its tokens).
bool isObjCObjectType() const
bool isNotEmpty() const
A scope specifier is present, but may be valid or invalid.
ExprResult getExpression() const
IdentifierInfo * getName() const
void takeAttributesFrom(ParsedAttributes &attrs)
DiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID)
bool isKnownToGCC() const
void CheckForFunctionRedefinition(FunctionDecl *FD, const FunctionDecl *EffectiveDefinition=nullptr)
bool isCodeCompletionEnabled() const
Determine if we are performing code completion.
TemplateName getTemplateName() const
SourceLocation getLoc() const
static FixItHint CreateInsertion(SourceLocation InsertionLoc, StringRef Code, bool BeforePreviousInsertions=false)
Create a code modification hint that inserts the given code string at a specific location.
SmallVector< TemplateParameterList *, 4 > TemplateParameterLists
DeclResult ActOnModuleImport(SourceLocation AtLoc, SourceLocation ImportLoc, ModuleIdPath Path)
The parser has processed a module import declaration.
This is a scope that can contain a declaration. Some scopes just contain loop constructs but don't co...
bool SetTypeSpecType(TST T, SourceLocation Loc, const char *&PrevSpec, unsigned &DiagID, const PrintingPolicy &Policy)
NamedDecl * HandleDeclarator(Scope *S, Declarator &D, MultiTemplateParamsArg TemplateParameterLists)
void ActOnTranslationUnitScope(Scope *S)
Decl * ParsedFreeStandingDeclSpec(Scope *S, AccessSpecifier AS, DeclSpec &DS)
bool isCXX11Attribute() const
Captures information about "declaration specifiers".
SourceLocation getIdentifierLoc() const
SourceLocation ConsumeToken()
bool isObjCObjectPointerType() const
Decl * ActOnStartOfFunctionTemplateDef(Scope *FnBodyScope, MultiTemplateParamsArg TemplateParameterLists, Declarator &D)
bool TryAnnotateTypeOrScopeToken(bool EnteringContext=false, bool NeedType=false)
DeclContext * CurContext
CurContext - This is the current declaration context of parsing.
void ActOnPopScope(SourceLocation Loc, Scope *S)
Scope actions.
static FixItHint CreateReplacement(CharSourceRange RemoveRange, StringRef Code)
Create a code modification hint that replaces the given source range with the given code string...
void ActOnComment(SourceRange Comment)
static OpaquePtr make(TemplateNameP)
unsigned getParsedSpecifiers() const
Return a bitmask of which flavors of specifiers this DeclSpec includes.
virtual bool HandleTopLevelDecl(DeclGroupRef D)
void setLocation(SourceLocation L)
void ActOnModuleEnd(SourceLocation DirectiveLoc, Module *Mod)
The parser has left a submodule.
AttributeList * getNext() const
A trivial tuple used to represent a source range.
void setIdentifier(const IdentifierInfo *Id, SourceLocation IdLoc)
Specify that this unqualified-id was parsed as an identifier.
unsigned NumArgs
NumArgs - The number of template arguments.
bool isAnnotation() const
Return true if this is any of tok::annot_* kind tokens.
ParsedType getType() const
The symbol does not exist.
void CodeCompleteInPreprocessorConditionalExclusion(Scope *S)
ParsedAttributes & getAttributes()
void startToken()
Reset all flags to cleared.
ParsedTemplateTy Template
Engages in a tight little dance with the lexer to efficiently preprocess tokens.
bool isBacktrackEnabled() const
True if EnableBacktrackAtThisPos() was called and caching of tokens is on.
Stop skipping at specified token, but don't skip the token itself.
IdentifierInfo * getIdentifierInfo() const
const AttributeList * getAttributes() const