21 #include "llvm/ADT/SmallVector.h" 22 #include "llvm/ADT/StringExtras.h" 24 using namespace clang;
29 if (Tok.
is(tok::kw___attribute)) {
30 if (Kind == tok::objc_interface || Kind == tok::objc_protocol)
31 Diag(Tok, diag::err_objc_postfix_attribute_hint)
32 << (Kind == tok::objc_protocol);
34 Diag(Tok, diag::err_objc_postfix_attribute);
35 ParseGNUAttributes(attrs);
48 Parser::ParseObjCAtDirectives(ParsedAttributesWithRange &Attrs) {
51 if (Tok.
is(tok::code_completion)) {
57 Decl *SingleDecl =
nullptr;
60 return ParseObjCAtClassDeclaration(AtLoc);
61 case tok::objc_interface:
62 SingleDecl = ParseObjCAtInterfaceDeclaration(AtLoc, Attrs);
64 case tok::objc_protocol:
65 return ParseObjCAtProtocolDeclaration(AtLoc, Attrs);
66 case tok::objc_implementation:
67 return ParseObjCAtImplementationDeclaration(AtLoc, Attrs);
69 return ParseObjCAtEndDeclaration(AtLoc);
70 case tok::objc_compatibility_alias:
71 SingleDecl = ParseObjCAtAliasDeclaration(AtLoc);
73 case tok::objc_synthesize:
74 SingleDecl = ParseObjCPropertySynthesize(AtLoc);
76 case tok::objc_dynamic:
77 SingleDecl = ParseObjCPropertyDynamic(AtLoc);
79 case tok::objc_import:
81 SingleDecl = ParseModuleImport(AtLoc);
84 Diag(AtLoc, diag::err_atimport);
88 Diag(AtLoc, diag::err_unexpected_at);
104 : Actions(Actions), S(S), Params(nullptr) {}
137 MaybeSkipAttributes(tok::objc_class);
138 if (expectIdentifier()) {
140 return Actions.ConvertDeclToDeclGroup(
nullptr);
142 ClassNames.push_back(Tok.getIdentifierInfo());
143 ClassLocs.push_back(Tok.getLocation());
148 if (Tok.
is(tok::less))
149 TypeParams = parseObjCTypeParamList();
150 ClassTypeParams.push_back(TypeParams);
156 if (ExpectAndConsume(tok::semi, diag::err_expected_after,
"@class"))
157 return Actions.ConvertDeclToDeclGroup(
nullptr);
159 return Actions.ActOnForwardClassDeclaration(atLoc, ClassNames.data(),
171 Decl *
Decl = Actions.getObjCDeclContext();
172 if (CurParsedObjCImpl) {
173 CurParsedObjCImpl->finish(AtLoc);
177 Diag(AtLoc, diag::err_objc_missing_end)
180 Diag(Decl->
getBeginLoc(), diag::note_objc_container_start) << (
int)ock;
215 "ParseObjCAtInterfaceDeclaration(): Expected @interface");
216 CheckNestedObjCContexts(AtLoc);
220 if (Tok.
is(tok::code_completion)) {
221 Actions.CodeCompleteObjCInterfaceDecl(
getCurScope());
226 MaybeSkipAttributes(tok::objc_interface);
228 if (expectIdentifier())
242 if (Tok.
is(tok::less))
243 typeParameterList = parseObjCTypeParamListOrProtocolRefs(
244 typeParamScope, LAngleLoc, ProtocolIdents, EndProtoLoc);
246 if (Tok.
is(tok::l_paren) &&
247 !isKnownToBeTypeSpecifier(GetLookAheadToken(1))) {
254 if (Tok.
is(tok::code_completion)) {
255 Actions.CodeCompleteObjCInterfaceCategory(
getCurScope(), nameId, nameLoc);
261 if (Tok.
is(tok::identifier)) {
262 categoryId = Tok.getIdentifierInfo();
266 Diag(Tok, diag::err_expected)
276 assert(LAngleLoc.
isInvalid() &&
"Cannot have already parsed protocols");
279 if (Tok.
is(tok::less) &&
280 ParseObjCProtocolReferences(ProtocolRefs, ProtocolLocs,
true,
true,
281 LAngleLoc, EndProtoLoc,
285 Decl *CategoryType = Actions.ActOnStartCategoryInterface(
286 AtLoc, nameId, nameLoc, typeParameterList, categoryId, categoryLoc,
287 ProtocolRefs.data(), ProtocolRefs.size(), ProtocolLocs.data(),
290 if (Tok.
is(tok::l_brace))
291 ParseObjCClassInstanceVariables(CategoryType, tok::objc_private, AtLoc);
293 ParseObjCInterfaceDeclList(tok::objc_not_keyword, CategoryType);
305 if (Tok.
is(tok::colon)) {
309 if (Tok.
is(tok::code_completion)) {
310 Actions.CodeCompleteObjCSuperclass(
getCurScope(), nameId, nameLoc);
315 if (expectIdentifier())
317 superClassId = Tok.getIdentifierInfo();
321 if (Tok.
is(tok::less)) {
322 parseObjCTypeArgsOrProtocolQualifiers(
323 nullptr, typeArgsLAngleLoc, typeArgs, typeArgsRAngleLoc, LAngleLoc,
324 protocols, protocolLocs, EndProtoLoc,
334 if (!ProtocolIdents.empty()) {
337 for (
const auto &pair : ProtocolIdents) {
338 protocolLocs.push_back(pair.second);
340 Actions.FindProtocolDeclaration(
true,
342 ProtocolIdents, protocols);
344 }
else if (protocols.empty() && Tok.
is(tok::less) &&
345 ParseObjCProtocolReferences(protocols, protocolLocs,
true,
true,
346 LAngleLoc, EndProtoLoc,
351 if (Tok.
isNot(tok::less))
352 Actions.ActOnTypedefedProtocols(protocols, protocolLocs,
353 superClassId, superClassLoc);
355 Decl *ClsType = Actions.ActOnStartClassInterface(
356 getCurScope(), AtLoc, nameId, nameLoc, typeParameterList, superClassId,
357 superClassLoc, typeArgs,
358 SourceRange(typeArgsLAngleLoc, typeArgsRAngleLoc), protocols.data(),
359 protocols.size(), protocolLocs.data(), EndProtoLoc, attrs);
361 if (Tok.
is(tok::l_brace))
362 ParseObjCClassInstanceVariables(ClsType, tok::objc_protected, AtLoc);
364 ParseObjCInterfaceDeclList(tok::objc_interface, ClsType);
375 bool &addedToDeclSpec) {
387 }
else if (!addedToDeclSpec) {
392 addedToDeclSpec =
true;
424 assert(Tok.
is(tok::less) &&
"Not at the beginning of a type parameter list");
432 auto makeProtocolIdentsIntoTypeParameters = [&]() {
434 for (
const auto &pair : protocolIdents) {
435 DeclResult typeParam = Actions.actOnObjCTypeParam(
439 typeParams.push_back(typeParam.
get());
442 protocolIdents.clear();
443 mayBeProtocolList =
false;
446 bool invalid =
false;
453 if (Tok.
is(tok::kw___covariant) || Tok.
is(tok::kw___contravariant)) {
454 variance = Tok.
is(tok::kw___covariant)
461 if (mayBeProtocolList) {
464 makeProtocolIdentsIntoTypeParameters();
469 if (!Tok.
is(tok::identifier)) {
471 if (Tok.
is(tok::code_completion)) {
474 Actions.CodeCompleteObjCProtocolReferences(protocolIdents);
481 Diag(Tok, diag::err_objc_expected_type_parameter);
495 if (mayBeProtocolList) {
498 makeProtocolIdentsIntoTypeParameters();
505 }
else if (mayBeProtocolList) {
508 protocolIdents.push_back(std::make_pair(paramName, paramLoc));
513 DeclResult typeParam = Actions.actOnObjCTypeParam(
514 getCurScope(), variance, varianceLoc, typeParams.size(), paramName,
515 paramLoc, colonLoc, boundType.
isUsable() ? boundType.
get() :
nullptr);
517 typeParams.push_back(typeParam.
get());
523 if (Tok.
is(tok::greater))
525 }
else if (ParseGreaterThanInTemplateList(rAngleLoc,
528 Diag(lAngleLoc, diag::note_matching) <<
"'<'";
529 SkipUntil({tok::greater, tok::greaterequal, tok::at, tok::minus,
530 tok::minus, tok::plus, tok::colon, tok::l_paren, tok::l_brace,
531 tok::comma, tok::semi },
533 if (Tok.
is(tok::greater))
537 if (mayBeProtocolList) {
542 if (Tok.
isNot(tok::colon) && Tok.
isNot(tok::l_paren)) {
551 makeProtocolIdentsIntoTypeParameters();
566 return invalid ? nullptr : list;
575 ObjCTypeParamListScope Scope(Actions,
getCurScope());
576 return parseObjCTypeParamListOrProtocolRefs(Scope, lAngleLoc, protocolIdents,
603 if (Tok.
isOneOf(tok::minus, tok::plus)) {
604 if (
Decl *methodPrototype =
605 ParseObjCMethodPrototype(MethodImplKind,
false))
606 allMethods.push_back(methodPrototype);
609 if (ExpectAndConsumeSemi(diag::err_expected_semi_after_method_proto)) {
612 if (Tok.
is(tok::semi))
617 if (Tok.
is(tok::l_paren)) {
618 Diag(Tok, diag::err_expected_minus_or_plus);
619 ParseObjCMethodDecl(Tok.getLocation(),
621 MethodImplKind,
false);
625 if (Tok.
is(tok::semi)) {
637 if (Tok.
is(tok::code_completion)) {
641 return cutOffParsing();
645 if (Tok.
isNot(tok::at)) {
649 if (Tok.
is(tok::r_brace))
652 ParsedAttributesWithRange attrs(AttrFactory);
657 if (Tok.
isOneOf(tok::kw_static_assert, tok::kw__Static_assert)) {
659 allTUVariables.push_back(
664 allTUVariables.push_back(ParseDeclarationOrFunctionDefinition(attrs));
670 if (Tok.
is(tok::code_completion)) {
671 Actions.CodeCompleteObjCAtDirective(
getCurScope());
672 return cutOffParsing();
677 if (DirectiveKind == tok::objc_end) {
679 AtEnd.
setEnd(Tok.getLocation());
681 }
else if (DirectiveKind == tok::objc_not_keyword) {
682 Diag(Tok, diag::err_objc_unknown_at);
690 switch (DirectiveKind) {
696 Diag(AtLoc, diag::err_objc_illegal_interface_qual);
701 case tok::objc_implementation:
702 case tok::objc_interface:
703 Diag(AtLoc, diag::err_objc_missing_end)
706 << (
int)Actions.getObjCContainerKind();
710 case tok::objc_required:
711 case tok::objc_optional:
714 if (contextKey != tok::objc_protocol)
715 Diag(AtLoc, diag::err_objc_directive_only_in_protocol);
717 MethodImplKind = DirectiveKind;
720 case tok::objc_property:
722 Diag(AtLoc, diag::err_objc_properties_require_objc2);
727 if (Tok.
is(tok::l_paren)) {
728 LParenLoc = Tok.getLocation();
729 ParseObjCPropertyAttribute(OCDS);
732 bool addedToDeclSpec =
false;
734 if (FD.D.getIdentifier() ==
nullptr) {
735 Diag(AtLoc, diag::err_objc_property_requires_field_name)
736 << FD.D.getSourceRange();
739 if (FD.BitfieldSize) {
740 Diag(AtLoc, diag::err_objc_property_bitfield)
741 << FD.D.getSourceRange();
756 Selector GetterSel = PP.getSelectorTable().getNullarySelector(SelName);
760 SetterSel = PP.getSelectorTable().getSelector(1, &SetterName);
763 PP.getIdentifierTable(), PP.getSelectorTable(),
764 FD.D.getIdentifier());
766 getCurScope(), AtLoc, LParenLoc, FD, OCDS, GetterSel, SetterSel,
769 FD.complete(Property);
774 ParseStructDeclaration(DS, ObjCPropertyCallback);
776 ExpectAndConsume(tok::semi, diag::err_expected_semi_decl_list);
783 if (Tok.
is(tok::code_completion)) {
784 Actions.CodeCompleteObjCAtDirective(
getCurScope());
785 return cutOffParsing();
789 Diag(Tok, diag::err_objc_missing_end)
792 << (
int)Actions.getObjCContainerKind();
794 AtEnd.
setEnd(Tok.getLocation());
799 Actions.ActOnAtEnd(
getCurScope(), AtEnd, allMethods, allTUVariables);
808 P.
Diag(nullabilityLoc, diag::warn_nullability_duplicate)
814 P.
Diag(nullabilityLoc, diag::err_nullability_conflicting)
845 void Parser::ParseObjCPropertyAttribute(
ObjCDeclSpec &DS) {
846 assert(Tok.getKind() == tok::l_paren);
851 if (Tok.
is(tok::code_completion)) {
852 Actions.CodeCompleteObjCPropertyFlags(
getCurScope(), DS);
853 return cutOffParsing();
865 if (II->
isStr(
"readonly"))
867 else if (II->
isStr(
"assign"))
869 else if (II->
isStr(
"unsafe_unretained"))
871 else if (II->
isStr(
"readwrite"))
873 else if (II->
isStr(
"retain"))
875 else if (II->
isStr(
"strong"))
877 else if (II->
isStr(
"copy"))
879 else if (II->
isStr(
"nonatomic"))
881 else if (II->
isStr(
"atomic"))
883 else if (II->
isStr(
"weak"))
885 else if (II->
isStr(
"getter") || II->
isStr(
"setter")) {
889 unsigned DiagID = IsSetter ? diag::err_objc_expected_equal_for_setter :
890 diag::err_objc_expected_equal_for_getter;
892 if (ExpectAndConsume(tok::equal, DiagID)) {
897 if (Tok.
is(tok::code_completion)) {
899 Actions.CodeCompleteObjCPropertySetter(
getCurScope());
901 Actions.CodeCompleteObjCPropertyGetter(
getCurScope());
902 return cutOffParsing();
909 Diag(Tok, diag::err_objc_expected_selector_for_getter_setter)
919 if (ExpectAndConsume(tok::colon,
920 diag::err_expected_colon_after_setter_name)) {
928 }
else if (II->
isStr(
"nonnull")) {
935 }
else if (II->
isStr(
"nullable")) {
942 }
else if (II->
isStr(
"null_unspecified")) {
949 }
else if (II->
isStr(
"null_resettable")) {
959 }
else if (II->
isStr(
"class")) {
962 Diag(AttrName, diag::err_objc_expected_property_attr) << II;
967 if (Tok.
isNot(tok::comma))
987 bool MethodDefinition) {
988 assert(Tok.
isOneOf(tok::minus, tok::plus) &&
"expected +/-");
992 Decl *MDecl = ParseObjCMethodDecl(mLoc, methodType, MethodImplKind,
1009 switch (Tok.getKind()) {
1014 SelectorLoc = Tok.getLocation();
1022 case tok::exclaimequal:
1024 case tok::pipeequal:
1026 case tok::caretequal: {
1027 std::string ThisTok(PP.getSpelling(Tok));
1030 Tok.setKind(tok::identifier);
1037 case tok::identifier:
1047 case tok::kw_const_cast:
1048 case tok::kw_continue:
1049 case tok::kw_default:
1050 case tok::kw_delete:
1052 case tok::kw_double:
1053 case tok::kw_dynamic_cast:
1056 case tok::kw_explicit:
1057 case tok::kw_export:
1058 case tok::kw_extern:
1062 case tok::kw_friend:
1065 case tok::kw_inline:
1068 case tok::kw_mutable:
1069 case tok::kw_namespace:
1071 case tok::kw_operator:
1072 case tok::kw_private:
1073 case tok::kw_protected:
1074 case tok::kw_public:
1075 case tok::kw_register:
1076 case tok::kw_reinterpret_cast:
1077 case tok::kw_restrict:
1078 case tok::kw_return:
1080 case tok::kw_signed:
1081 case tok::kw_sizeof:
1082 case tok::kw_static:
1083 case tok::kw_static_cast:
1084 case tok::kw_struct:
1085 case tok::kw_switch:
1086 case tok::kw_template:
1091 case tok::kw_typedef:
1092 case tok::kw_typeid:
1093 case tok::kw_typename:
1094 case tok::kw_typeof:
1096 case tok::kw_unsigned:
1098 case tok::kw_virtual:
1100 case tok::kw_volatile:
1101 case tok::kw_wchar_t:
1104 case tok::kw__Complex:
1105 case tok::kw___alignof:
1106 case tok::kw___auto_type:
1115 bool Parser::isTokIdentifier_in()
const {
1120 Tok.getIdentifierInfo() == ObjCTypeQuals[objc_in]);
1142 void Parser::ParseObjCTypeQualifierList(
ObjCDeclSpec &DS,
1148 if (Tok.
is(tok::code_completion)) {
1149 Actions.CodeCompleteObjCPassingType(
getCurScope(), DS,
1151 return cutOffParsing();
1154 if (Tok.
isNot(tok::identifier))
1158 for (
unsigned i = 0;
i != objc_NumQuals; ++
i) {
1159 if (II != ObjCTypeQuals[
i] ||
1167 default: llvm_unreachable(
"Unknown decl qualifier");
1185 case objc_null_unspecified:
1210 for (
auto &AL : llvm::reverse(from)) {
1211 if (!AL.isUsedAsTypeAttr()) {
1242 assert((paramAttrs !=
nullptr) ==
1245 assert(Tok.
is(tok::l_paren) &&
"expected (");
1253 ParseObjCTypeQualifierList(DS, context);
1257 if (isTypeSpecifierQualifier() || isObjCInstancetype()) {
1261 DeclSpecContext dsContext = DeclSpecContext::DSC_normal;
1263 dsContext = DeclSpecContext::DSC_objc_method_result;
1264 ParseSpecifierQualifierList(declSpec,
AS_none, dsContext);
1266 ParseDeclarator(declarator);
1271 bool addedToDeclSpec =
false;
1289 if (Tok.
is(tok::r_paren))
1291 else if (Tok.getLocation() == TypeStartLoc) {
1293 Diag(Tok, diag::err_expected_type);
1334 bool MethodDefinition) {
1337 if (Tok.
is(tok::code_completion)) {
1338 Actions.CodeCompleteObjCMethodDecl(
getCurScope(), mType == tok::minus,
1347 if (Tok.
is(tok::l_paren))
1354 MaybeParseGNUAttributes(methodAttrs);
1355 MaybeParseCXX11Attributes(methodAttrs);
1357 if (Tok.
is(tok::code_completion)) {
1358 Actions.CodeCompleteObjCMethodDecl(
getCurScope(), mType == tok::minus,
1369 if (!SelIdent && Tok.
isNot(tok::colon)) {
1370 Diag(Tok, diag::err_expected_selector_for_method)
1378 if (Tok.
isNot(tok::colon)) {
1381 MaybeParseGNUAttributes(methodAttrs);
1382 MaybeParseCXX11Attributes(methodAttrs);
1384 Selector Sel = PP.getSelectorTable().getNullarySelector(SelIdent);
1385 Decl *
Result = Actions.ActOnMethodDeclaration(
1386 getCurScope(), mLoc, Tok.getLocation(), mType, DSRet, ReturnType,
1387 selLoc, Sel,
nullptr, CParamInfo.data(), CParamInfo.size(), methodAttrs,
1388 MethodImplKind,
false, MethodDefinition);
1405 if (ExpectAndConsume(tok::colon))
1408 ArgInfo.
Type =
nullptr;
1409 if (Tok.
is(tok::l_paren))
1417 MaybeParseGNUAttributes(paramAttrs);
1418 MaybeParseCXX11Attributes(paramAttrs);
1422 if (Tok.
is(tok::code_completion)) {
1423 KeyIdents.push_back(SelIdent);
1424 Actions.CodeCompleteObjCMethodDeclSelector(
getCurScope(),
1425 mType == tok::minus,
1427 ReturnType, KeyIdents);
1432 if (expectIdentifier())
1435 ArgInfo.
Name = Tok.getIdentifierInfo();
1436 ArgInfo.
NameLoc = Tok.getLocation();
1439 ArgInfos.push_back(ArgInfo);
1440 KeyIdents.push_back(SelIdent);
1441 KeyLocs.push_back(selLoc);
1447 if (Tok.
is(tok::code_completion)) {
1448 Actions.CodeCompleteObjCMethodDeclSelector(
getCurScope(),
1449 mType == tok::minus,
1451 ReturnType, KeyIdents);
1457 SelIdent = ParseObjCSelectorPiece(selLoc);
1458 if (!SelIdent && Tok.
isNot(tok::colon))
1463 Diag(ArgInfo.
NameLoc, diag::warn_missing_selector_name) << ArgInfo.
Name;
1464 Diag(ArgInfo.
NameLoc, diag::note_missing_selector_name) << ArgInfo.
Name;
1465 Diag(ColonLoc, diag::note_force_empty_selector_name) << ArgInfo.
Name;
1471 bool isVariadic =
false;
1472 bool cStyleParamWarned =
false;
1474 while (Tok.
is(tok::comma)) {
1476 if (Tok.
is(tok::ellipsis)) {
1481 if (!cStyleParamWarned) {
1482 Diag(Tok, diag::warn_cstyle_param);
1483 cStyleParamWarned =
true;
1486 ParseDeclarationSpecifiers(DS);
1489 ParseDeclarator(ParmDecl);
1501 MaybeParseGNUAttributes(methodAttrs);
1502 MaybeParseCXX11Attributes(methodAttrs);
1504 if (KeyIdents.size() == 0)
1507 Selector Sel = PP.getSelectorTable().getSelector(KeyIdents.size(),
1509 Decl *
Result = Actions.ActOnMethodDeclaration(
1510 getCurScope(), mLoc, Tok.getLocation(), mType, DSRet, ReturnType, KeyLocs,
1511 Sel, &ArgInfos[0], CParamInfo.data(), CParamInfo.size(), methodAttrs,
1512 MethodImplKind, isVariadic, MethodDefinition);
1524 bool WarnOnDeclarations,
bool ForObjCContainer,
1526 bool consumeLastToken) {
1527 assert(Tok.
is(tok::less) &&
"expected <");
1534 if (Tok.
is(tok::code_completion)) {
1535 Actions.CodeCompleteObjCProtocolReferences(ProtocolIdents);
1540 if (expectIdentifier()) {
1544 ProtocolIdents.push_back(std::make_pair(Tok.getIdentifierInfo(),
1545 Tok.getLocation()));
1546 ProtocolLocs.push_back(Tok.getLocation());
1554 if (ParseGreaterThanInTemplateList(EndLoc, consumeLastToken,
1559 Actions.FindProtocolDeclaration(WarnOnDeclarations, ForObjCContainer,
1560 ProtocolIdents, Protocols);
1565 assert(Tok.
is(tok::less) &&
"Protocol qualifiers start with '<'");
1566 assert(
getLangOpts().ObjC &&
"Protocol qualifiers only exist in Objective-C");
1571 (void)ParseObjCProtocolReferences(protocols, protocolLocs,
false,
false,
1572 lAngleLoc, rAngleLoc,
1579 Diag(lAngleLoc, diag::warn_objc_protocol_qualifier_missing_id)
1592 void Parser::parseObjCTypeArgsOrProtocolQualifiers(
1601 bool consumeLastToken,
1602 bool warnOnIncompleteProtocols) {
1603 assert(Tok.
is(tok::less) &&
"Not at the start of type args or protocols");
1608 bool allSingleIdentifiers =
true;
1616 if (Tok.
is(tok::identifier) &&
1620 identifiers.push_back(Tok.getIdentifierInfo());
1625 if (Tok.
is(tok::code_completion)) {
1628 for (
unsigned i = 0, n = identifiers.size();
i != n; ++
i) {
1630 identifierLocs[i]));
1633 QualType BaseT = Actions.GetTypeFromParser(baseType);
1637 Actions.CodeCompleteObjCProtocolReferences(identifierLocPairs);
1643 allSingleIdentifiers =
false;
1649 if (allSingleIdentifiers) {
1652 (void)ParseGreaterThanInTemplateList(rAngleLoc, consumeLastToken,
1656 Actions.actOnObjCTypeArgsOrProtocolQualifiers(
getCurScope(),
1668 warnOnIncompleteProtocols);
1678 bool invalid =
false;
1679 IdentifierInfo *foundProtocolId =
nullptr, *foundValidTypeId =
nullptr;
1684 for (
unsigned i = 0, n = identifiers.size();
i != n; ++
i) {
1686 = Actions.getTypeName(*identifiers[
i], identifierLocs[i],
getCurScope());
1689 const char *prevSpec =
nullptr;
1692 typeArg, Actions.getASTContext().getPrintingPolicy());
1698 typeArgs.push_back(fullTypeArg.
get());
1699 if (!foundValidTypeId) {
1700 foundValidTypeId = identifiers[
i];
1701 foundValidTypeSrcLoc = identifierLocs[
i];
1705 unknownTypeArgs.push_back(identifiers[i]);
1706 unknownTypeArgsLoc.push_back(identifierLocs[i]);
1710 if (!Actions.LookupProtocol(identifiers[i], identifierLocs[i])) {
1711 unknownTypeArgs.push_back(identifiers[i]);
1712 unknownTypeArgsLoc.push_back(identifierLocs[i]);
1713 }
else if (!foundProtocolId) {
1714 foundProtocolId = identifiers[
i];
1715 foundProtocolSrcLoc = identifierLocs[
i];
1722 Token CurTypeTok = Tok;
1729 typeArg = Actions.ActOnPackExpansion(typeArg.
get(), ellipsisLoc);
1733 typeArgs.push_back(typeArg.
get());
1734 if (!foundValidTypeId) {
1744 if (foundProtocolId && foundValidTypeId)
1745 Actions.DiagnoseTypeArgsAndProtocols(foundProtocolId, foundProtocolSrcLoc,
1747 foundValidTypeSrcLoc);
1751 if (unknownTypeArgs.size())
1752 for (
unsigned i = 0, e = unknownTypeArgsLoc.size();
i < e; ++
i)
1753 Actions.DiagnoseUnknownTypeName(unknownTypeArgs[
i], unknownTypeArgsLoc[i],
1758 (void)ParseGreaterThanInTemplateList(rAngleLoc, consumeLastToken,
1767 typeArgsLAngleLoc = lAngleLoc;
1768 typeArgsRAngleLoc = rAngleLoc;
1771 void Parser::parseObjCTypeArgsAndProtocolQualifiers(
1780 bool consumeLastToken) {
1781 assert(Tok.
is(tok::less));
1784 parseObjCTypeArgsOrProtocolQualifiers(baseType,
1800 if ((consumeLastToken && Tok.
is(tok::less)) ||
1801 (!consumeLastToken &&
NextToken().
is(tok::less))) {
1804 if (!consumeLastToken)
1807 if (!protocols.empty()) {
1809 if (!consumeLastToken)
1811 Diag(Tok, diag::err_objc_type_args_after_protocols)
1812 <<
SourceRange(protocolLAngleLoc, protocolRAngleLoc);
1813 SkipUntil(tok::greater, tok::greatergreater, skipFlags);
1815 ParseObjCProtocolReferences(protocols, protocolLocs,
1818 protocolLAngleLoc, protocolRAngleLoc,
1824 TypeResult Parser::parseObjCTypeArgsAndProtocolQualifiers(
1827 bool consumeLastToken,
1829 assert(Tok.
is(tok::less));
1839 parseObjCTypeArgsAndProtocolQualifiers(type, typeArgsLAngleLoc, typeArgs,
1840 typeArgsRAngleLoc, protocolLAngleLoc,
1841 protocols, protocolLocs,
1842 protocolRAngleLoc, consumeLastToken);
1848 if (consumeLastToken)
1849 endLoc = PrevTokLocation;
1851 endLoc = Tok.getLocation();
1853 return Actions.actOnObjCTypeArgsAndProtocolQualifiers(
1866 void Parser::HelperActionsForIvarDeclarations(
Decl *interfaceDecl,
SourceLocation atLoc,
1869 bool RBraceMissing) {
1873 Actions.ActOnObjCContainerStartDefinition(interfaceDecl);
1875 Actions.ActOnObjCContainerFinishDefinition();
1878 Actions.ActOnFields(
getCurScope(), atLoc, interfaceDecl, AllIvarDecls,
1904 void Parser::ParseObjCClassInstanceVariables(
Decl *interfaceDecl,
1907 assert(Tok.
is(tok::l_brace) &&
"expected {");
1916 while (Tok.
isNot(tok::r_brace) && !isEofOrEom()) {
1920 if (Tok.
is(tok::semi)) {
1921 ConsumeExtraSemi(InstanceVariableList);
1927 if (Tok.
is(tok::code_completion)) {
1928 Actions.CodeCompleteObjCAtVisibility(
getCurScope());
1929 return cutOffParsing();
1932 switch (Tok.getObjCKeywordID()) {
1933 case tok::objc_private:
1934 case tok::objc_public:
1935 case tok::objc_protected:
1936 case tok::objc_package:
1937 visibility = Tok.getObjCKeywordID();
1942 Diag(Tok, diag::err_objc_unexpected_atend);
1943 Tok.setLocation(Tok.getLocation().getLocWithOffset(-1));
1944 Tok.setKind(tok::at);
1946 PP.EnterToken(Tok,
true);
1947 HelperActionsForIvarDeclarations(interfaceDecl, atLoc,
1948 T, AllIvarDecls,
true);
1952 Diag(Tok, diag::err_objc_illegal_visibility_spec);
1957 if (Tok.
is(tok::code_completion)) {
1960 return cutOffParsing();
1966 if (Tok.
isOneOf(tok::kw_static_assert, tok::kw__Static_assert)) {
1968 ParseStaticAssertDeclaration(DeclEnd);
1973 Actions.ActOnObjCContainerStartDefinition(interfaceDecl);
1975 FD.D.setObjCIvar(
true);
1976 Decl *Field = Actions.ActOnIvar(
1977 getCurScope(), FD.D.getDeclSpec().getSourceRange().getBegin(), FD.D,
1978 FD.BitfieldSize, visibility);
1979 Actions.ActOnObjCContainerFinishDefinition();
1981 AllIvarDecls.push_back(Field);
1987 ParseStructDeclaration(DS, ObjCIvarCallback);
1989 if (Tok.
is(tok::semi)) {
1992 Diag(Tok, diag::err_expected_semi_decl_list);
1997 HelperActionsForIvarDeclarations(interfaceDecl, atLoc,
1998 T, AllIvarDecls,
false);
2021 "ParseObjCAtProtocolDeclaration(): Expected @protocol");
2024 if (Tok.
is(tok::code_completion)) {
2025 Actions.CodeCompleteObjCProtocolDecl(
getCurScope());
2030 MaybeSkipAttributes(tok::objc_protocol);
2032 if (expectIdentifier())
2040 return Actions.ActOnForwardProtocolDeclaration(AtLoc, ProtoInfo, attrs);
2043 CheckNestedObjCContexts(AtLoc);
2045 if (Tok.
is(tok::comma)) {
2047 ProtocolRefs.push_back(std::make_pair(protocolName, nameLoc));
2052 if (expectIdentifier()) {
2057 Tok.getLocation()));
2060 if (Tok.
isNot(tok::comma))
2064 if (ExpectAndConsume(tok::semi, diag::err_expected_after,
"@protocol"))
2067 return Actions.ActOnForwardProtocolDeclaration(AtLoc, ProtocolRefs, attrs);
2075 if (Tok.
is(tok::less) &&
2076 ParseObjCProtocolReferences(ProtocolRefs, ProtocolLocs,
false,
true,
2077 LAngleLoc, EndProtoLoc,
2081 Decl *ProtoType = Actions.ActOnStartProtocolInterface(
2082 AtLoc, protocolName, nameLoc, ProtocolRefs.data(), ProtocolRefs.size(),
2083 ProtocolLocs.data(), EndProtoLoc, attrs);
2085 ParseObjCInterfaceDeclList(tok::objc_protocol, ProtoType);
2086 return Actions.ConvertDeclToDeclGroup(ProtoType);
2100 Parser::ParseObjCAtImplementationDeclaration(
SourceLocation AtLoc,
2103 "ParseObjCAtImplementationDeclaration(): Expected @implementation");
2104 CheckNestedObjCContexts(AtLoc);
2108 if (Tok.
is(tok::code_completion)) {
2109 Actions.CodeCompleteObjCImplementationDecl(
getCurScope());
2114 MaybeSkipAttributes(tok::objc_implementation);
2116 if (expectIdentifier())
2121 Decl *ObjCImpDecl =
nullptr;
2125 if (Tok.
is(tok::less)) {
2129 ObjCTypeParamListScope typeParamScope(Actions,
getCurScope());
2130 if (parseObjCTypeParamListOrProtocolRefs(typeParamScope, lAngleLoc,
2131 protocolIdents, rAngleLoc)) {
2132 Diag(diagLoc, diag::err_objc_parameterized_implementation)
2134 }
else if (lAngleLoc.
isValid()) {
2135 Diag(lAngleLoc, diag::err_unexpected_protocol_qualifier)
2140 if (Tok.
is(tok::l_paren)) {
2146 if (Tok.
is(tok::code_completion)) {
2147 Actions.CodeCompleteObjCImplementationCategory(
getCurScope(), nameId, nameLoc);
2152 if (Tok.
is(tok::identifier)) {
2153 categoryId = Tok.getIdentifierInfo();
2156 Diag(Tok, diag::err_expected)
2160 if (Tok.
isNot(tok::r_paren)) {
2161 Diag(Tok, diag::err_expected) << tok::r_paren;
2165 rparenLoc = ConsumeParen();
2166 if (Tok.
is(tok::less)) {
2167 Diag(Tok, diag::err_unexpected_protocol_qualifier);
2171 (void)ParseObjCProtocolReferences(protocols, protocolLocs,
2174 protocolLAngleLoc, protocolRAngleLoc,
2177 ObjCImpDecl = Actions.ActOnStartCategoryImplementation(
2178 AtLoc, nameId, nameLoc, categoryId, categoryLoc, Attrs);
2186 if (expectIdentifier())
2188 superClassId = Tok.getIdentifierInfo();
2191 ObjCImpDecl = Actions.ActOnStartClassImplementation(
2192 AtLoc, nameId, nameLoc, superClassId, superClassLoc, Attrs);
2194 if (Tok.
is(tok::l_brace))
2195 ParseObjCClassInstanceVariables(ObjCImpDecl, tok::objc_private, AtLoc);
2196 else if (Tok.
is(tok::less)) {
2197 Diag(Tok, diag::err_unexpected_protocol_qualifier);
2202 (void)ParseObjCProtocolReferences(protocols, protocolLocs,
2205 protocolLAngleLoc, protocolRAngleLoc,
2209 assert(ObjCImpDecl);
2214 ObjCImplParsingDataRAII ObjCImplParsing(*
this, ObjCImpDecl);
2215 while (!ObjCImplParsing.isFinished() && !isEofOrEom()) {
2216 ParsedAttributesWithRange attrs(AttrFactory);
2217 MaybeParseCXX11Attributes(attrs);
2220 DeclsInGroup.append(DG.
begin(), DG.
end());
2225 return Actions.ActOnFinishObjCImplementation(ObjCImpDecl, DeclsInGroup);
2229 Parser::ParseObjCAtEndDeclaration(
SourceRange atEnd) {
2231 "ParseObjCAtEndDeclaration(): Expected @end");
2233 if (CurParsedObjCImpl)
2234 CurParsedObjCImpl->finish(atEnd);
2237 Diag(atEnd.
getBegin(), diag::err_expected_objc_container);
2241 Parser::ObjCImplParsingDataRAII::~ObjCImplParsingDataRAII() {
2243 finish(
P.Tok.getLocation());
2244 if (
P.isEofOrEom()) {
2245 P.Diag(
P.Tok, diag::err_objc_missing_end)
2247 P.Diag(Dcl->getBeginLoc(), diag::note_objc_container_start)
2251 P.CurParsedObjCImpl =
nullptr;
2252 assert(LateParsedObjCMethods.empty());
2255 void Parser::ObjCImplParsingDataRAII::finish(
SourceRange AtEnd) {
2257 P.Actions.DefaultSynthesizeProperties(
P.getCurScope(), Dcl, AtEnd.
getBegin());
2258 for (
size_t i = 0;
i < LateParsedObjCMethods.size(); ++
i)
2259 P.ParseLexedObjCMethodDefs(*LateParsedObjCMethods[
i],
2262 P.Actions.ActOnAtEnd(
P.getCurScope(), AtEnd);
2265 for (
size_t i = 0; i < LateParsedObjCMethods.size(); ++
i)
2266 P.ParseLexedObjCMethodDefs(*LateParsedObjCMethods[i],
2270 for (LateParsedObjCMethodContainer::iterator
2271 I = LateParsedObjCMethods.begin(),
2272 E = LateParsedObjCMethods.end(); I != E; ++I)
2274 LateParsedObjCMethods.clear();
2284 "ParseObjCAtAliasDeclaration(): Expected @compatibility_alias");
2286 if (expectIdentifier())
2290 if (expectIdentifier())
2294 ExpectAndConsume(tok::semi, diag::err_expected_after,
"@compatibility_alias");
2295 return Actions.ActOnCompatibilityAlias(atLoc, aliasId, aliasLoc,
2312 "ParseObjCPropertySynthesize(): Expected '@synthesize'");
2316 if (Tok.
is(tok::code_completion)) {
2317 Actions.CodeCompleteObjCPropertyDefinition(
getCurScope());
2322 if (Tok.
isNot(tok::identifier)) {
2323 Diag(Tok, diag::err_synthesized_property_name);
2334 if (Tok.
is(tok::code_completion)) {
2335 Actions.CodeCompleteObjCPropertySynthesizeIvar(
getCurScope(), propertyId);
2340 if (expectIdentifier())
2342 propertyIvar = Tok.getIdentifierInfo();
2345 Actions.ActOnPropertyImplDecl(
2347 propertyId, propertyIvar, propertyIvarLoc,
2349 if (Tok.
isNot(tok::comma))
2353 ExpectAndConsume(tok::semi, diag::err_expected_after,
"@synthesize");
2366 "ParseObjCPropertyDynamic(): Expected '@dynamic'");
2369 bool isClassProperty =
false;
2370 if (Tok.
is(tok::l_paren)) {
2375 Diag(Tok, diag::err_objc_expected_property_attr) << II;
2379 if (II->
isStr(
"class")) {
2380 isClassProperty =
true;
2381 if (Tok.
isNot(tok::r_paren)) {
2382 Diag(Tok, diag::err_expected) << tok::r_paren;
2387 Diag(AttrName, diag::err_objc_expected_property_attr) << II;
2394 if (Tok.
is(tok::code_completion)) {
2395 Actions.CodeCompleteObjCPropertyDefinition(
getCurScope());
2400 if (expectIdentifier()) {
2407 Actions.ActOnPropertyImplDecl(
2413 if (Tok.
isNot(tok::comma))
2417 ExpectAndConsume(tok::semi, diag::err_expected_after,
"@dynamic");
2427 if (Tok.
isNot(tok::semi)) {
2435 ExpectAndConsume(tok::semi, diag::err_expected_after,
"@throw");
2436 return Actions.ActOnObjCAtThrowStmt(atLoc, Res.
get(),
getCurScope());
2445 if (Tok.
isNot(tok::l_paren)) {
2446 Diag(Tok, diag::err_expected_lparen_after) <<
"@synchronized";
2454 if (Tok.
is(tok::r_paren)) {
2458 Diag(Tok, diag::err_expected) << tok::r_paren;
2465 if (Tok.
isNot(tok::l_brace)) {
2467 Diag(Tok, diag::err_expected) << tok::l_brace;
2473 operand = Actions.ActOnObjCAtSynchronizedOperand(atLoc, operand.
get());
2477 StmtResult body(ParseCompoundStatementBody());
2485 if (body.isInvalid())
2486 body = Actions.ActOnNullStmt(Tok.getLocation());
2488 return Actions.ActOnObjCAtSynchronizedStmt(atLoc, operand.
get(), body.get());
2503 bool catch_or_finally_seen =
false;
2506 if (Tok.
isNot(tok::l_brace)) {
2507 Diag(Tok, diag::err_expected) << tok::l_brace;
2510 StmtVector CatchStmts;
2513 StmtResult TryBody(ParseCompoundStatementBody());
2515 if (TryBody.isInvalid())
2516 TryBody = Actions.ActOnNullStmt(Tok.getLocation());
2518 while (Tok.
is(tok::at)) {
2522 Token AfterAt = GetLookAheadToken(1);
2529 Decl *FirstPart =
nullptr;
2531 if (Tok.
is(tok::l_paren)) {
2536 if (Tok.
isNot(tok::ellipsis)) {
2538 ParseDeclarationSpecifiers(DS);
2540 ParseDeclarator(ParmDecl);
2544 FirstPart = Actions.ActOnObjCExceptionDecl(
getCurScope(), ParmDecl);
2550 if (Tok.
is(tok::r_paren))
2551 RParenLoc = ConsumeParen();
2556 if (Tok.
is(tok::l_brace))
2557 CatchBody = ParseCompoundStatementBody();
2559 Diag(Tok, diag::err_expected) << tok::l_brace;
2560 if (CatchBody.isInvalid())
2561 CatchBody = Actions.ActOnNullStmt(Tok.getLocation());
2563 StmtResult Catch = Actions.ActOnObjCAtCatchStmt(AtCatchFinallyLoc,
2567 if (!Catch.isInvalid())
2568 CatchStmts.push_back(Catch.get());
2571 Diag(AtCatchFinallyLoc, diag::err_expected_lparen_after)
2575 catch_or_finally_seen =
true;
2577 assert(Tok.
isObjCAtKeyword(tok::objc_finally) &&
"Lookahead confused?");
2579 ParseScope FinallyScope(
this,
2582 bool ShouldCapture =
2585 Actions.ActOnCapturedRegionStart(Tok.getLocation(),
getCurScope(),
2589 if (Tok.
is(tok::l_brace))
2590 FinallyBody = ParseCompoundStatementBody();
2592 Diag(Tok, diag::err_expected) << tok::l_brace;
2594 if (FinallyBody.isInvalid()) {
2595 FinallyBody = Actions.ActOnNullStmt(Tok.getLocation());
2597 Actions.ActOnCapturedRegionError();
2598 }
else if (ShouldCapture) {
2599 FinallyBody = Actions.ActOnCapturedRegionEnd(FinallyBody.get());
2602 FinallyStmt = Actions.ActOnObjCAtFinallyStmt(AtCatchFinallyLoc,
2604 catch_or_finally_seen =
true;
2608 if (!catch_or_finally_seen) {
2609 Diag(atLoc, diag::err_missing_catch_finally);
2613 return Actions.ActOnObjCAtTryStmt(atLoc, TryBody.get(),
2624 if (Tok.
isNot(tok::l_brace)) {
2625 Diag(Tok, diag::err_expected) << tok::l_brace;
2632 StmtResult AutoreleasePoolBody(ParseCompoundStatementBody());
2635 if (AutoreleasePoolBody.isInvalid())
2636 AutoreleasePoolBody = Actions.ActOnNullStmt(Tok.getLocation());
2637 return Actions.ActOnObjCAutoreleasePoolStmt(atLoc,
2638 AutoreleasePoolBody.get());
2643 void Parser::StashAwayMethodOrFunctionBodyTokens(
Decl *MDecl) {
2644 if (SkipFunctionBodies && (!MDecl || Actions.canSkipFunctionBody(MDecl)) &&
2645 trySkippingFunctionBody()) {
2646 Actions.ActOnSkippedFunctionBody(MDecl);
2650 LexedMethod* LM =
new LexedMethod(
this, MDecl);
2651 CurParsedObjCImpl->LateParsedObjCMethods.push_back(LM);
2654 Toks.push_back(Tok);
2655 if (Tok.
is(tok::kw_try)) {
2657 if (Tok.
is(tok::colon)) {
2658 Toks.push_back(Tok);
2660 while (Tok.
isNot(tok::l_brace)) {
2661 ConsumeAndStoreUntil(tok::l_paren, Toks,
false);
2662 ConsumeAndStoreUntil(tok::r_paren, Toks,
false);
2665 Toks.push_back(Tok);
2667 else if (Tok.
is(tok::colon)) {
2670 while (Tok.
isNot(tok::l_brace)) {
2671 ConsumeAndStoreUntil(tok::l_paren, Toks,
false);
2672 ConsumeAndStoreUntil(tok::r_paren, Toks,
false);
2674 Toks.push_back(Tok);
2678 ConsumeAndStoreUntil(tok::r_brace, Toks,
false);
2679 while (Tok.
is(tok::kw_catch)) {
2680 ConsumeAndStoreUntil(tok::l_brace, Toks,
false);
2681 ConsumeAndStoreUntil(tok::r_brace, Toks,
false);
2687 Decl *Parser::ParseObjCMethodDefinition() {
2688 Decl *MDecl = ParseObjCMethodPrototype();
2691 "parsing Objective-C method");
2694 if (Tok.
is(tok::semi)) {
2695 if (CurParsedObjCImpl) {
2696 Diag(Tok, diag::warn_semicolon_before_method_body)
2703 if (Tok.
isNot(tok::l_brace)) {
2704 Diag(Tok, diag::err_expected_method_body);
2710 if (Tok.
isNot(tok::l_brace))
2721 Actions.AddAnyMethodToGlobalPool(MDecl);
2722 assert (CurParsedObjCImpl
2723 &&
"ParseObjCMethodDefinition - Method out of @implementation");
2725 StashAwayMethodOrFunctionBodyTokens(MDecl);
2730 ParsedStmtContext StmtCtx) {
2731 if (Tok.
is(tok::code_completion)) {
2732 Actions.CodeCompleteObjCAtStatement(
getCurScope());
2738 return ParseObjCTryStmt(AtLoc);
2741 return ParseObjCThrowStmt(AtLoc);
2744 return ParseObjCSynchronizedStmt(AtLoc);
2747 return ParseObjCAutoreleasePoolStmt(AtLoc);
2752 return Actions.ActOnNullStmt(Tok.getLocation());
2755 ExprStatementTokLoc = AtLoc;
2756 ExprResult Res(ParseExpressionWithLeadingAt(AtLoc));
2766 ExpectAndConsumeSemi(diag::err_expected_semi_after_expr);
2767 return handleExprStmt(Res, StmtCtx);
2771 switch (Tok.getKind()) {
2772 case tok::code_completion:
2773 Actions.CodeCompleteObjCAtExpression(
getCurScope());
2782 if (!Tok.
is(tok::numeric_constant)) {
2783 const char *Symbol =
nullptr;
2785 case tok::minus: Symbol =
"-";
break;
2786 case tok::plus: Symbol =
"+";
break;
2787 default: llvm_unreachable(
"missing unary operator case");
2789 Diag(Tok, diag::err_nsnumber_nonliteral_unary)
2794 ExprResult Lit(Actions.ActOnNumericConstant(Tok));
2795 if (Lit.isInvalid()) {
2800 Lit = Actions.ActOnUnaryOp(
getCurScope(), OpLoc, Kind, Lit.get());
2801 if (Lit.isInvalid())
2804 return ParsePostfixExpressionSuffix(
2805 Actions.BuildObjCNumericLiteral(AtLoc, Lit.get()));
2808 case tok::string_literal:
2809 case tok::wide_string_literal:
2810 return ParsePostfixExpressionSuffix(ParseObjCStringLiteral(AtLoc));
2812 case tok::char_constant:
2813 return ParsePostfixExpressionSuffix(ParseObjCCharacterLiteral(AtLoc));
2815 case tok::numeric_constant:
2816 return ParsePostfixExpressionSuffix(ParseObjCNumericLiteral(AtLoc));
2819 case tok::kw___objc_yes:
2820 return ParsePostfixExpressionSuffix(ParseObjCBooleanLiteral(AtLoc,
true));
2822 case tok::kw___objc_no:
2823 return ParsePostfixExpressionSuffix(ParseObjCBooleanLiteral(AtLoc,
false));
2827 return ParsePostfixExpressionSuffix(ParseObjCArrayLiteral(AtLoc));
2831 return ParsePostfixExpressionSuffix(ParseObjCDictionaryLiteral(AtLoc));
2835 return ParsePostfixExpressionSuffix(ParseObjCBoxedExpr(AtLoc));
2838 if (Tok.getIdentifierInfo() ==
nullptr)
2841 switch (Tok.getIdentifierInfo()->getObjCKeywordID()) {
2842 case tok::objc_encode:
2843 return ParsePostfixExpressionSuffix(ParseObjCEncodeExpression(AtLoc));
2844 case tok::objc_protocol:
2845 return ParsePostfixExpressionSuffix(ParseObjCProtocolExpression(AtLoc));
2846 case tok::objc_selector:
2847 return ParsePostfixExpressionSuffix(ParseObjCSelectorExpression(AtLoc));
2848 case tok::objc_available:
2849 return ParseAvailabilityCheckExpr(AtLoc);
2851 const char *str =
nullptr;
2855 if (GetLookAheadToken(1).is(tok::l_brace) &&
2856 ExprStatementTokLoc == AtLoc) {
2857 char ch = Tok.getIdentifierInfo()->getNameStart()[0];
2860 : (ch ==
'f' ?
"finally" 2861 : (ch ==
'a' ?
"autoreleasepool" :
nullptr));
2897 bool Parser::ParseObjCXXMessageReceiver(
bool &IsExpr,
void *&TypeOrExpr) {
2900 if (Tok.
isOneOf(tok::identifier, tok::coloncolon, tok::kw_typename,
2901 tok::annot_cxxscope))
2904 if (!Actions.isSimpleTypeSpecifier(Tok.getKind())) {
2915 TypeOrExpr = Receiver.
get();
2924 ParseCXXSimpleTypeSpecifier(DS);
2926 if (Tok.
is(tok::l_paren)) {
2939 ExprResult Receiver = ParseCXXTypeConstructExpression(DS);
2941 Receiver = ParsePostfixExpressionSuffix(Receiver.
get());
2943 Receiver = ParseRHSOfBinaryExpression(Receiver.
get(),
prec::Comma);
2948 TypeOrExpr = Receiver.
get();
2961 TypeOrExpr = Type.
get().getAsOpaquePtr();
2970 bool Parser::isSimpleObjCMessageExpression() {
2972 "Incorrect start for isSimpleObjCMessageExpression");
2973 return GetLookAheadToken(1).is(tok::identifier) &&
2974 GetLookAheadToken(2).is(tok::identifier);
2977 bool Parser::isStartOfObjCClassMessageMissingOpenBracket() {
2979 InMessageExpression)
2984 if (Tok.
is(tok::annot_typename))
2986 else if (Tok.
is(tok::identifier))
2987 Type = Actions.getTypeName(*Tok.getIdentifierInfo(), Tok.getLocation(),
2992 if (!Type.
get().isNull() && Type.
get()->isObjCObjectOrInterfaceType()) {
2993 const Token &AfterNext = GetLookAheadToken(2);
2994 if (AfterNext.
isOneOf(tok::colon, tok::r_square)) {
2995 if (Tok.
is(tok::identifier))
2998 return Tok.
is(tok::annot_typename);
3014 ExprResult Parser::ParseObjCMessageExpression() {
3015 assert(Tok.
is(tok::l_square) &&
"'[' expected");
3018 if (Tok.
is(tok::code_completion)) {
3019 Actions.CodeCompleteObjCMessageReceiver(
getCurScope());
3033 if (Tok.
is(tok::identifier) && Tok.getIdentifierInfo() == Ident_super &&
3035 return ParseObjCMessageExpressionBody(LBracLoc,
ConsumeToken(),
nullptr,
3040 void *TypeOrExpr =
nullptr;
3041 if (ParseObjCXXMessageReceiver(IsExpr, TypeOrExpr)) {
3047 return ParseObjCMessageExpressionBody(LBracLoc,
SourceLocation(),
nullptr,
3048 static_cast<Expr *>(TypeOrExpr));
3050 return ParseObjCMessageExpressionBody(LBracLoc,
SourceLocation(),
3055 if (Tok.
is(tok::identifier)) {
3059 switch (Actions.getObjCMessageKind(
getCurScope(), Name, NameLoc,
3060 Name == Ident_super,
3064 return ParseObjCMessageExpressionBody(LBracLoc,
ConsumeToken(),
nullptr,
3068 if (!ReceiverType) {
3076 if (Tok.
is(tok::less)) {
3079 = parseObjCTypeArgsAndProtocolQualifiers(NameLoc, ReceiverType,
3087 ReceiverType = NewReceiverType.
get();
3090 return ParseObjCMessageExpressionBody(LBracLoc,
SourceLocation(),
3091 ReceiverType,
nullptr);
3106 return ParseObjCMessageExpressionBody(LBracLoc,
SourceLocation(),
nullptr,
3152 Expr *ReceiverExpr) {
3155 if (Tok.
is(tok::code_completion)) {
3159 else if (ReceiverType)
3160 Actions.CodeCompleteObjCClassMessage(
getCurScope(), ReceiverType,
None,
3163 Actions.CodeCompleteObjCInstanceMessage(
getCurScope(), ReceiverExpr,
3175 ExprVector KeyExprs;
3177 if (Tok.
is(tok::colon)) {
3180 KeyIdents.push_back(selIdent);
3181 KeyLocs.push_back(Loc);
3183 if (ExpectAndConsume(tok::colon)) {
3193 if (Tok.
is(tok::code_completion)) {
3195 Actions.CodeCompleteObjCSuperMessage(
getCurScope(), SuperLoc,
3198 else if (ReceiverType)
3199 Actions.CodeCompleteObjCClassMessage(
getCurScope(), ReceiverType,
3203 Actions.CodeCompleteObjCInstanceMessage(
getCurScope(), ReceiverExpr,
3213 Diag(Tok, diag::warn_cxx98_compat_generalized_initializer_lists);
3214 Expr = ParseBraceInitializer();
3228 KeyExprs.push_back(Res.
get());
3231 if (Tok.
is(tok::code_completion)) {
3233 Actions.CodeCompleteObjCSuperMessage(
getCurScope(), SuperLoc,
3236 else if (ReceiverType)
3237 Actions.CodeCompleteObjCClassMessage(
getCurScope(), ReceiverType,
3241 Actions.CodeCompleteObjCInstanceMessage(
getCurScope(), ReceiverExpr,
3249 selIdent = ParseObjCSelectorPiece(Loc);
3250 if (!selIdent && Tok.
isNot(tok::colon))
3255 while (Tok.
is(tok::comma)) {
3259 if (Tok.
is(tok::colon))
3260 Res = Actions.CorrectDelayedTyposInExpr(Res);
3262 if (Tok.
is(tok::colon)) {
3263 Diag(commaLoc, diag::note_extra_comma_message_arg) <<
3274 KeyExprs.push_back(Res.
get());
3276 }
else if (!selIdent) {
3277 Diag(Tok, diag::err_expected) << tok::identifier;
3286 if (Tok.
isNot(tok::r_square)) {
3287 Diag(Tok, diag::err_expected)
3288 << (Tok.
is(tok::identifier) ? tok::colon : tok::r_square);
3298 unsigned nKeys = KeyIdents.size();
3300 KeyIdents.push_back(selIdent);
3301 KeyLocs.push_back(Loc);
3303 Selector Sel = PP.getSelectorTable().getSelector(nKeys, &KeyIdents[0]);
3306 return Actions.ActOnSuperMessage(
getCurScope(), SuperLoc, Sel,
3307 LBracLoc, KeyLocs, RBracLoc, KeyExprs);
3308 else if (ReceiverType)
3309 return Actions.ActOnClassMessage(
getCurScope(), ReceiverType, Sel,
3310 LBracLoc, KeyLocs, RBracLoc, KeyExprs);
3311 return Actions.ActOnInstanceMessage(
getCurScope(), ReceiverExpr, Sel,
3312 LBracLoc, KeyLocs, RBracLoc, KeyExprs);
3316 ExprResult Res(ParseStringLiteralExpression());
3323 ExprVector AtStrings;
3324 AtLocs.push_back(AtLoc);
3325 AtStrings.push_back(Res.
get());
3327 while (Tok.
is(tok::at)) {
3331 if (!isTokenStringLiteral())
3334 ExprResult Lit(ParseStringLiteralExpression());
3338 AtStrings.push_back(Lit.
get());
3341 return Actions.ParseObjCStringLiteral(AtLocs.data(), AtStrings);
3352 return Actions.ActOnObjCBoolLiteral(AtLoc, EndLoc, ArgValue);
3359 ExprResult Lit(Actions.ActOnCharacterConstant(Tok));
3360 if (Lit.isInvalid()) {
3364 return Actions.BuildObjCNumericLiteral(AtLoc, Lit.get());
3373 ExprResult Lit(Actions.ActOnNumericConstant(Tok));
3374 if (Lit.isInvalid()) {
3378 return Actions.BuildObjCNumericLiteral(AtLoc, Lit.get());
3386 if (Tok.
isNot(tok::l_paren))
3387 return ExprError(
Diag(Tok, diag::err_expected_lparen_after) <<
"@");
3401 ValueExpr = Actions.ActOnParenExpr(LPLoc, RPLoc, ValueExpr.
get());
3402 return Actions.BuildObjCBoxedExpr(
SourceRange(AtLoc, RPLoc),
3407 ExprVector ElementExprs;
3410 bool HasInvalidEltExpr =
false;
3411 while (Tok.
isNot(tok::r_square)) {
3422 Res = Actions.CorrectDelayedTyposInExpr(Res.
get());
3424 HasInvalidEltExpr =
true;
3427 if (Tok.
is(tok::ellipsis))
3430 HasInvalidEltExpr =
true;
3432 ElementExprs.push_back(Res.
get());
3434 if (Tok.
is(tok::comma))
3436 else if (Tok.
isNot(tok::r_square))
3437 return ExprError(
Diag(Tok, diag::err_expected_either) << tok::r_square
3442 if (HasInvalidEltExpr)
3446 return Actions.BuildObjCArrayLiteral(
SourceRange(AtLoc, EndLoc), Args);
3452 bool HasInvalidEltExpr =
false;
3453 while (Tok.
isNot(tok::r_brace)) {
3468 if (ExpectAndConsume(tok::colon)) {
3483 KeyExpr = Actions.CorrectDelayedTyposInExpr(KeyExpr.
get());
3484 ValueExpr = Actions.CorrectDelayedTyposInExpr(ValueExpr.
get());
3486 HasInvalidEltExpr =
true;
3498 KeyExpr.
get(), ValueExpr.
get(), EllipsisLoc,
None 3500 Elements.push_back(Element);
3503 return ExprError(
Diag(Tok, diag::err_expected_either) << tok::r_brace
3508 if (HasInvalidEltExpr)
3512 return Actions.BuildObjCDictionaryLiteral(
SourceRange(AtLoc, EndLoc),
3520 assert(Tok.
isObjCAtKeyword(tok::objc_encode) &&
"Not an @encode expression!");
3524 if (Tok.
isNot(tok::l_paren))
3525 return ExprError(
Diag(Tok, diag::err_expected_lparen_after) <<
"@encode");
3537 return Actions.ParseObjCEncodeExpression(AtLoc, EncLoc, T.
getOpenLocation(),
3547 if (Tok.
isNot(tok::l_paren))
3548 return ExprError(
Diag(Tok, diag::err_expected_lparen_after) <<
"@protocol");
3553 if (expectIdentifier())
3561 return Actions.ParseObjCProtocolExpression(protocolId, AtLoc, ProtoLoc,
3571 if (Tok.
isNot(tok::l_paren))
3572 return ExprError(
Diag(Tok, diag::err_expected_lparen_after) <<
"@selector");
3579 bool HasOptionalParen = Tok.
is(tok::l_paren);
3580 if (HasOptionalParen)
3583 if (Tok.
is(tok::code_completion)) {
3584 Actions.CodeCompleteObjCSelector(
getCurScope(), KeyIdents);
3591 Tok.
isNot(tok::colon) && Tok.
isNot(tok::coloncolon))
3592 return ExprError(
Diag(Tok, diag::err_expected) << tok::identifier);
3594 KeyIdents.push_back(SelIdent);
3596 unsigned nColons = 0;
3597 if (Tok.
isNot(tok::r_paren)) {
3601 KeyIdents.push_back(
nullptr);
3602 }
else if (ExpectAndConsume(tok::colon))
3606 if (Tok.
is(tok::r_paren))
3609 if (Tok.
is(tok::code_completion)) {
3610 Actions.CodeCompleteObjCSelector(
getCurScope(), KeyIdents);
3617 SelIdent = ParseObjCSelectorPiece(Loc);
3618 KeyIdents.push_back(SelIdent);
3619 if (!SelIdent && Tok.
isNot(tok::colon) && Tok.
isNot(tok::coloncolon))
3623 if (HasOptionalParen && Tok.
is(tok::r_paren))
3626 Selector Sel = PP.getSelectorTable().getSelector(nColons, &KeyIdents[0]);
3627 return Actions.ParseObjCSelectorExpression(Sel, AtLoc, SelectorLoc,
3633 void Parser::ParseLexedObjCMethodDefs(LexedMethod &LM,
bool parseMethod) {
3635 Decl *MCDecl = LM.D;
3636 bool skip = MCDecl &&
3637 ((parseMethod && !Actions.isObjCMethodDecl(MCDecl)) ||
3638 (!parseMethod && Actions.isObjCMethodDecl(MCDecl)));
3645 assert(!LM.Toks.empty() &&
"ParseLexedObjCMethodDef - Empty body!");
3651 Eof.setEofData(MCDecl);
3652 Eof.setLocation(OrigLoc);
3653 LM.Toks.push_back(Eof);
3656 LM.Toks.push_back(Tok);
3657 PP.EnterTokenStream(LM.Toks,
true,
true);
3662 assert(Tok.
isOneOf(tok::l_brace, tok::kw_try, tok::colon) &&
3663 "Inline objective-c method not starting with '{' or 'try' or ':'");
3672 Actions.ActOnStartOfObjCMethodDef(
getCurScope(), MCDecl);
3674 Actions.ActOnStartOfFunctionDef(
getCurScope(), MCDecl);
3675 if (Tok.
is(tok::kw_try))
3676 ParseFunctionTryBlock(MCDecl, BodyScope);
3678 if (Tok.
is(tok::colon))
3679 ParseConstructorInitializer(MCDecl);
3681 Actions.ActOnDefaultCtorInitializers(MCDecl);
3682 ParseFunctionStatementBody(MCDecl, BodyScope);
3685 if (Tok.getLocation() != OrigLoc) {
3691 if (PP.getSourceManager().isBeforeInTranslationUnit(Tok.getLocation(),
AttributePool & getAttributePool() const
Defines the clang::ASTContext interface.
IdentifierInfo * getNullabilityKeyword(NullabilityKind nullability)
Retrieve the underscored keyword (_Nonnull, _Nullable) that corresponds to the given nullability kind...
Smart pointer class that efficiently represents Objective-C method names.
ExprResult ParseExpression(TypeCastState isTypeCast=NotTypeCast)
Simple precedence-based parser for binary/ternary operators.
A (possibly-)qualified type.
This is a scope that corresponds to the parameters within a function prototype.
ObjCDeclQualifier getObjCDeclQualifier() const
Class to handle popping type parameters when leaving the scope.
const DeclaratorChunk & getTypeObject(unsigned i) const
Return the specified TypeInfo from this declarator.
NullabilityKind
Describes the nullability of a particular type.
const llvm::Triple & getTriple() const
Returns the target triple of the primary target.
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 setPropertyAttributes(ObjCPropertyAttributeKind PRVal)
Decl - This represents one declaration (or definition), e.g.
SourceLocation getBeginLoc() const LLVM_READONLY
RAII object used to inform the actions that we're currently parsing a declaration.
Captures information about "declaration specifiers" specific to Objective-C.
The base class of the type hierarchy.
SourceLocation getCloseLocation() const
This indicates that the scope corresponds to a function, which means that labels are set here...
The parameter is covariant, e.g., X<T> is a subtype of X<U> when the type parameter is covariant and ...
Wrapper for void* pointer.
Parser - This implements a parser for the C family of languages.
const ParsedAttributes & getAttributes() const
~ObjCTypeParamListScope()
void setObjCQualifiers(ObjCDeclSpec *quals)
ActionResult< Stmt * > StmtResult
Information about one declarator, including the parsed type information and the identifier.
bool isInObjcMethodScope() const
isInObjcMethodScope - Return true if this scope is, or is contained in, an Objective-C method body...
void setBegin(SourceLocation b)
Code completion occurs within an Objective-C implementation or category implementation.
friend class ObjCDeclContextSwitch
const IdentifierInfo * getSetterName() const
ColonProtectionRAIIObject - This sets the Parser::ColonIsSacred bool and restores it when destroyed...
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 ...
const Token & NextToken()
NextToken - This peeks ahead one token and returns it without consuming it.
bool TryConsumeToken(tok::TokenKind Expected)
The message is a class message, and the identifier is a type name.
One of these records is kept for each identifier that is lexed.
An element in an Objective-C dictionary literal.
bool isStr(const char(&Str)[StrLen]) const
Return true if this is the identifier for the specified string.
The parameter is contravariant, e.g., X<T> is a subtype of X<U> when the type parameter is covariant ...
LLVM_READONLY bool isLetter(unsigned char c)
Return true if this character is an ASCII letter: [a-zA-Z].
DeclGroupPtrTy ConvertDeclToDeclGroup(Decl *Ptr, Decl *OwnedType=nullptr)
Token - This structure provides full information about a lexed token.
RAII class that helps handle the parsing of an open/close delimiter pair, such as braces { ...
Code completion occurs where only a type is permitted.
bool isInvalidType() const
Values of this type can be null.
bool isObjCAtKeyword(tok::ObjCKeywordKind objcKey) const
Return true if we have an ObjC keyword identifier.
static Selector constructSetterSelector(IdentifierTable &Idents, SelectorTable &SelTable, const IdentifierInfo *Name)
Return the default setter selector for the given identifier.
ParsedAttributesView ArgAttrs
ArgAttrs - Attribute list for this argument.
static ParsedType getTypeAnnotation(const Token &Tok)
getTypeAnnotation - Read a parsed type out of an annotation token.
Whether values of this type can be null is (explicitly) unspecified.
unsigned getNumTypeObjects() const
Return the number of types applied to this declarator.
Values of this type can never be null.
Scope - A scope is a transient data structure that is used while parsing the program.
SourceLocation ConsumeAnyToken(bool ConsumeCodeCompletionTok=false)
ConsumeAnyToken - Dispatch to the right Consume* method based on the current token type...
void addAtEnd(ParsedAttr *newAttr)
IdentifierInfo * getIdentifier() const
DeclSpec & getMutableDeclSpec()
getMutableDeclSpec - Return a non-const version of the DeclSpec.
Sema - This implements semantic analysis and AST building for C.
bool acceptsObjCTypeParams() const
Determines if this is an ObjC interface type that may accept type parameters.
void setSetterName(IdentifierInfo *name, SourceLocation loc)
const ParsedAttributesView & getAttrs() const
If there are attributes applied to this declaratorchunk, return them.
This represents one expression.
The message is an instance message.
This file defines the classes used to store parsed information about declaration-specifiers and decla...
ObjCTypeParamListScope(Sema &Actions, Scope *S)
Code completion occurs within an Objective-C interface, protocol, or category.
SourceLocation getLocation() const
Return a source location identifier for the specified offset in the current file. ...
This is a compound statement scope.
A class for parsing a field declarator.
static void diagnoseRedundantPropertyNullability(Parser &P, ObjCDeclSpec &DS, NullabilityKind nullability, SourceLocation nullabilityLoc)
Diagnose redundant or conflicting nullability information.
SourceLocation getOpenLocation() const
The result type of a method or function.
Code completion occurs within the list of instance variables in an Objective-C interface, protocol, category, or implementation.
bool isNull() const
Return true if this QualType doesn't point to a type yet.
ObjCTypeParamVariance
Describes the variance of a given generic parameter.
ObjCKeywordKind
Provides a namespace for Objective-C keywords which start with an '@'.
RAII object that makes '>' behave either as an operator or as the closing angle bracket for a templat...
OpaquePtr< DeclGroupRef > DeclGroupPtrTy
PrettyDeclStackTraceEntry - If a crash occurs in the parser while parsing something related to a decl...
const LangOptions & getLangOpts() const
This is a scope that corresponds to the parameters within a function prototype for a function declara...
NullabilityKind getNullability() const
A class for parsing a DeclSpec.
ObjCDeclQualifier
ObjCDeclQualifier - Qualifier used on types in method declarations.
void CodeCompleteObjCAtDirective(Scope *S)
Stop skipping at semicolon.
ActionResult - This structure is used while parsing/acting on expressions, stmts, etc...
Encodes a location in the source.
bool TryAnnotateTypeOrScopeToken()
TryAnnotateTypeOrScopeToken - If the current token position is on a typename (possibly qualified in C...
std::pair< NullabilityKind, bool > DiagNullabilityKind
A nullability kind paired with a bit indicating whether it used a context-sensitive keyword...
This is a scope that corresponds to the Objective-C @catch statement.
IdentifierInfo * getIdentifierInfo() const
ParsedAttr - Represents a syntactic attribute.
const char * getNameStart() const
Return the beginning of the actual null-terminated string for this identifier.
ObjCPropertyAttributeKind getPropertyAttributes() const
The message is sent to 'super'.
TokenKind
Provides a simple uniform namespace for tokens from all C languages.
void remove(ParsedAttr *ToBeRemoved)
Scope * getCurScope() const
tok::ObjCKeywordKind getObjCKeywordID() const
Return the ObjC keyword kind.
void popObjCTypeParamList(Scope *S, ObjCTypeParamList *typeParamList)
The scope of a struct/union/class definition.
bool isNot(tok::TokenKind K) const
Dataflow Directional Tag Classes.
std::pair< IdentifierInfo *, SourceLocation > IdentifierLocPair
A simple pair of identifier info and location.
bool isValid() const
Return true if this is a valid SourceLocation object.
static FixItHint CreateRemoval(CharSourceRange RemoveRange)
Create a code modification hint that removes the given source range.
void takeAllFrom(AttributePool &pool)
Take the given pool's allocations and add them to this pool.
bool isOneOf(tok::TokenKind K1, tok::TokenKind K2) const
SkipUntilFlags
Control flags for SkipUntil functions.
void setObjCDeclQualifier(ObjCDeclQualifier DQVal)
const TargetInfo & getTargetInfo() const
DiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID)
SourceLocation getNullabilityLoc() const
void setNullability(SourceLocation loc, NullabilityKind kind)
ExprResult ParseAssignmentExpression(TypeCastState isTypeCast=NotTypeCast)
Parse an expr that doesn't include (top-level) commas.
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.
This is a scope that can contain a declaration.
bool SetTypeSpecType(TST T, SourceLocation Loc, const char *&PrevSpec, unsigned &DiagID, const PrintingPolicy &Policy)
SourceLocation getIdentifierLoc() const
X
Add a minimal nested name specifier fixit hint to allow lookup of a tag name from an outer enclosing ...
Context-sensitive version of a keyword attribute.
Captures information about "declaration specifiers".
void setEnd(SourceLocation e)
SourceLocation ConsumeToken()
ConsumeToken - Consume the current 'peek token' and lex the next one.
const DeclSpec & getDeclSpec() const
getDeclSpec - Return the declaration-specifier that this declarator was declared with.
Stores a list of Objective-C type parameters for a parameterized class or a category/extension thereo...
static FixItHint CreateReplacement(CharSourceRange RemoveRange, StringRef Code)
Create a code modification hint that replaces the given source range with the given code string...
AttributePool & getPool() const
const IdentifierInfo * getGetterName() const
ParamInfo - An array of paraminfo objects is allocated whenever a function declarator is parsed...
static void addContextSensitiveTypeNullability(Parser &P, Declarator &D, NullabilityKind nullability, SourceLocation nullabilityLoc, bool &addedToDeclSpec)
Add an attribute for a context-sensitive type nullability to the given declarator.
A trivial tuple used to represent a source range.
static void takeDeclAttributes(ParsedAttributesView &attrs, ParsedAttributesView &from)
Take all the decl attributes out of the given list and add them to the given attribute set...
void setGetterName(IdentifierInfo *name, SourceLocation loc)
void enter(ObjCTypeParamList *P)
static OpaquePtr getFromOpaquePtr(void *P)
AttributePool & getAttributePool() const
SourceLocation getBegin() const
ParsedAttributes - A collection of parsed attributes.
SourceLocation ColonLoc
Location of ':'.
This scope corresponds to an Objective-C method body.
The parameter is invariant: must match exactly.
TypeResult ParseTypeName(SourceRange *Range=nullptr, DeclaratorContext Context=DeclaratorContext::TypeNameContext, AccessSpecifier AS=AS_none, Decl **OwnedType=nullptr, ParsedAttributes *Attrs=nullptr)
ParseTypeName type-name: [C99 6.7.6] specifier-qualifier-list abstract-declarator[opt].
ParsedAttributes & getAttributes()
void startToken()
Reset all flags to cleared.
Stop skipping at specified token, but don't skip the token itself.