28 #include "llvm/ADT/SmallString.h" 30 using namespace clang;
32 using llvm::makeArrayRef;
43 if (Strings.size() != 1) {
48 for (
Expr *E : Strings) {
49 S = cast<StringLiteral>(E);
68 assert(CAT &&
"String literal not of constant array type!");
73 false, StrTy, &StrLocs[0],
77 return BuildObjCStringLiteral(AtLocs[0], S);
82 if (CheckObjCString(S))
92 }
else if (getLangOpts().NoConstantCFStrings) {
94 std::string StringClass(getLangOpts().ObjCConstantStringClass);
96 if (StringClass.empty())
97 NSIdent = &Context.
Idents.
get(
"NSConstantString");
99 NSIdent = &Context.
Idents.
get(StringClass);
101 NamedDecl *IF = LookupSingleName(TUScope, NSIdent, AtLoc,
110 Diag(S->
getLocStart(), diag::err_no_nsconstant_string_class) << NSIdent
116 NamedDecl *IF = LookupSingleName(TUScope, NSIdent, AtLoc,
151 S.
Diag(Loc, diag::err_undeclared_boxing_method) << Sel << Class->
getName();
158 S.
Diag(Loc, diag::err_objc_literal_method_sig)
171 switch (LiteralKind) {
189 llvm_unreachable(
"LiteralKind can't be converted into a ClassKind");
201 S.
Diag(Loc, diag::err_undeclared_objc_literal_class)
202 << II->
getName() << LiteralKind;
205 S.
Diag(Loc, diag::err_undeclared_objc_literal_class)
206 << Decl->
getName() << LiteralKind;
246 S.
NSAPIObj->getNSNumberFactoryMethodKind(NumberType);
250 S.
Diag(Loc, diag::err_invalid_nsnumber_type)
283 if (!Method && S.
getLangOpts().DebuggerObjCLiteral) {
320 switch (Char->getKind()) {
323 NumberType = Context.
CharTy;
352 ExprResult ConvertedNumber = PerformCopyInitialization(Entity,
357 Number = ConvertedNumber.
get();
360 return MaybeBindToTemporary(
370 Inner = ActOnCXXBoolLiteral(ValueLoc, Value? tok::kw_true : tok::kw_false);
374 Inner = ActOnIntegerConstant(ValueLoc, Value? 1 : 0);
375 Inner = ImpCastExprToType(Inner.
get(), Context.
BoolTy,
376 CK_IntegralToBoolean);
379 return BuildObjCNumericLiteral(AtLoc, Inner.
get());
386 bool ArrayLiteral =
false) {
394 Element = Result.
get();
407 return Seq.Perform(S, Entity, Kind, Element);
410 Expr *OrigElement = Element;
416 Element = Result.
get();
421 bool Recovered =
false;
424 if (isa<IntegerLiteral>(OrigElement) ||
425 isa<CharacterLiteral>(OrigElement) ||
426 isa<FloatingLiteral>(OrigElement) ||
427 isa<ObjCBoolLiteralExpr>(OrigElement) ||
428 isa<CXXBoolLiteralExpr>(OrigElement)) {
429 if (S.
NSAPIObj->getNSNumberFactoryMethodKind(OrigElement->
getType())) {
430 int Which = isa<CharacterLiteral>(OrigElement) ? 1
431 : (isa<CXXBoolLiteralExpr>(OrigElement) ||
432 isa<ObjCBoolLiteralExpr>(OrigElement)) ? 2
441 if (Result.isInvalid())
444 Element = Result.get();
449 else if (
StringLiteral *String = dyn_cast<StringLiteral>(OrigElement)) {
450 if (String->isAscii()) {
456 if (Result.isInvalid())
459 Element = Result.get();
472 dyn_cast<ObjCStringLiteral>(OrigElement)) {
474 unsigned numConcat = SL->getNumConcatenated();
477 bool hasMacro =
false;
478 for (
unsigned i = 0; i < numConcat ; ++i)
479 if (SL->getStrTokenLoc(i).isMacroID()) {
485 diag::warn_concatenated_nsarray_literal)
508 ExprResult RValue = DefaultFunctionArrayLvalueConversion(ValueExpr);
513 ValueExpr = RValue.
get();
529 if (!StringWithUTF8StringMethod) {
534 BoxingMethod = NSStringDecl->lookupClassMethod(stringWithUTF8String);
535 if (!BoxingMethod && getLangOpts().DebuggerObjCLiteral) {
540 NSStringPointer, ReturnTInfo, NSStringDecl,
559 stringWithUTF8String, BoxingMethod))
562 StringWithUTF8StringMethod = BoxingMethod;
565 BoxingMethod = StringWithUTF8StringMethod;
566 BoxedType = NSStringPointer;
575 }
else if (ValueType->isBuiltinType()) {
583 dyn_cast<CharacterLiteral>(ValueExpr->
IgnoreParens())) {
586 switch (Char->getKind()) {
589 ValueType = Context.
CharTy;
609 BoxedType = NSNumberPointer;
611 if (!ET->getDecl()->isComplete()) {
612 Diag(Loc, diag::err_objc_incomplete_boxed_expression_type)
618 ET->getDecl()->getIntegerType());
619 BoxedType = NSNumberPointer;
620 }
else if (ValueType->isObjCBoxableRecordType()) {
638 if (!ValueWithBytesObjCTypeMethod) {
646 BoxingMethod = NSValueDecl->lookupClassMethod(ValueWithBytesObjCType);
647 if (!BoxingMethod && getLangOpts().DebuggerObjCLiteral) {
654 ValueWithBytesObjCType,
675 Params.push_back(bytes);
685 Params.push_back(type);
692 ValueWithBytesObjCType, BoxingMethod))
695 ValueWithBytesObjCTypeMethod = BoxingMethod;
698 if (!ValueType.isTriviallyCopyableType(Context)) {
699 Diag(Loc, diag::err_objc_non_trivially_copyable_boxed_expression_type)
704 BoxingMethod = ValueWithBytesObjCTypeMethod;
705 BoxedType = NSValuePointer;
709 Diag(Loc, diag::err_objc_illegal_boxed_expression_type)
714 DiagnoseUseOfDecl(BoxingMethod, Loc);
717 if (ValueType->isObjCBoxableRecordType()) {
719 ConvertedValueExpr = PerformCopyInitialization(IE, ValueExpr->
getExprLoc(),
726 ConvertedValueExpr = PerformCopyInitialization(IE,
SourceLocation(),
732 ValueExpr = ConvertedValueExpr.
get();
737 return MaybeBindToTemporary(BoxedExpr);
746 assert(!LangOpts.isSubscriptPointerArithmetic());
751 "base or index cannot have dependent type here");
755 ExprResult Result = CheckPlaceholderExpr(IndexExpr);
758 IndexExpr = Result.
get();
761 Result = DefaultLvalueConversion(BaseExpr);
764 BaseExpr = Result.
get();
769 getterMethod, setterMethod, RB);
785 if (!ArrayWithObjectsMethod) {
789 if (!Method && getLangOpts().DebuggerObjCLiteral) {
806 Params.push_back(objects);
814 Params.push_back(cnt);
829 diag::note_objc_literal_method_param)
836 if (!Method->
parameters()[1]->getType()->isIntegerType()) {
840 diag::note_objc_literal_method_param)
848 ArrayWithObjectsMethod = Method;
851 QualType ObjectsType = ArrayWithObjectsMethod->parameters()[0]->getType();
856 Expr **ElementsBuffer = Elements.data();
857 for (
unsigned I = 0, N = Elements.size(); I != N; ++I) {
864 ElementsBuffer[I] = Converted.
get();
871 return MaybeBindToTemporary(
873 ArrayWithObjectsMethod, SR));
880 if (!NSDictionaryDecl) {
883 if (!NSDictionaryDecl) {
891 if (!DictionaryWithObjectsMethod) {
892 Selector Sel = NSAPIObj->getNSDictionarySelector(
894 ObjCMethodDecl *Method = NSDictionaryDecl->lookupClassMethod(Sel);
895 if (!Method && getLangOpts().DebuggerObjCLiteral) {
914 Params.push_back(objects);
922 Params.push_back(keys);
930 Params.push_back(cnt);
946 diag::note_objc_literal_method_param)
960 if (QIDNSCopying.isNull()) {
974 if (!QIDNSCopying.isNull())
983 diag::note_objc_literal_method_param)
996 diag::note_objc_literal_method_param)
1003 DictionaryWithObjectsMethod = Method;
1006 QualType ValuesT = DictionaryWithObjectsMethod->parameters()[0]->getType();
1008 QualType KeysT = DictionaryWithObjectsMethod->parameters()[1]->getType();
1013 bool HasPackExpansions =
false;
1027 Element.Key = Key.
get();
1028 Element.Value = Value.
get();
1030 if (Element.EllipsisLoc.isInvalid())
1033 if (!Element.Key->containsUnexpandedParameterPack() &&
1034 !Element.Value->containsUnexpandedParameterPack()) {
1035 Diag(Element.EllipsisLoc,
1036 diag::err_pack_expansion_without_parameter_packs)
1038 Element.Value->getLocEnd());
1042 HasPackExpansions =
true;
1049 Context, Elements, HasPackExpansions, Ty,
1050 DictionaryWithObjectsMethod, SR));
1063 if (RequireCompleteType(AtLoc, EncodedType,
1064 diag::err_incomplete_type_objc_at_encode,
1071 if (!NotEncodedT.
isNull())
1072 Diag(AtLoc, diag::warn_incomplete_encoded_type)
1073 << EncodedType << NotEncodedT;
1079 if (getLangOpts().CPlusPlus || getLangOpts().ConstStrings)
1085 return new (Context)
ObjCEncodeExpr(StrTy, EncodedTypeInfo, AtLoc, RParenLoc);
1095 QualType EncodedType = GetTypeFromParser(ty, &TInfo);
1098 getLocForEndOfToken(LParenLoc));
1100 return BuildObjCEncodeExpression(AtLoc, TInfo, RParenLoc);
1110 bool Warned =
false;
1113 if (MatchingMethodDecl == Method ||
1121 S.
Diag(AtLoc, diag::warn_multiple_selectors)
1127 S.
Diag(MatchingMethodDecl->
getLocation(), diag::note_method_declared_at)
1138 bool WarnMultipleSelectors) {
1139 if (!WarnMultipleSelectors ||
1142 bool Warned =
false;
1143 for (Sema::GlobalMethodPool::iterator b = S.
MethodPool.begin(),
1148 Method, InstMethList))
1154 Method, ClsMethList) || Warned)
1164 bool WarnMultipleSelectors) {
1168 Method = LookupFactoryMethodInGlobalPool(Sel,
1171 if (
const ObjCMethodDecl *OM = SelectorsForTypoCorrection(Sel)) {
1172 Selector MatchedSel = OM->getSelector();
1175 Diag(SelLoc, diag::warn_undeclared_selector_with_typo)
1176 << Sel << MatchedSel
1180 Diag(SelLoc, diag::warn_undeclared_selector) << Sel;
1183 WarnMultipleSelectors);
1187 !getSourceManager().isInSystemHeader(Method->
getLocation()))
1188 ReferencedSelectors.insert(std::make_pair(Sel, AtLoc));
1192 if (getLangOpts().ObjCAutoRefCount) {
1199 Diag(AtLoc, diag::err_arc_illegal_selector) <<
1228 Diag(ProtoLoc, diag::err_undeclared_protocol) << ProtocolId;
1238 return new (Context)
ObjCProtocolExpr(Ty, PDecl, AtLoc, ProtoIdLoc, RParenLoc);
1284 bool isClassMessage,
1285 bool isSuperMessage) {
1286 assert(Method &&
"Must have a method");
1321 if (isSuperMessage) {
1324 return transferNullability(
1343 return transferNullability(ReceiverType);
1348 bool isClassMessage,
1349 bool isSuperMessage) {
1361 unsigned receiverNullabilityIdx = 0;
1363 receiverNullabilityIdx = 1 + static_cast<unsigned>(*nullability);
1365 unsigned resultNullabilityIdx = 0;
1367 resultNullabilityIdx = 1 + static_cast<unsigned>(*nullability);
1371 static const uint8_t None = 0;
1372 static const uint8_t
NonNull = 1;
1375 static const uint8_t nullabilityMap[4][4] = {
1377 { None, None, Nullable, None },
1378 { None, NonNull, Nullable, Unspecified },
1379 { Nullable, Nullable, Nullable, Nullable },
1380 { None, Unspecified, Nullable, Unspecified }
1383 unsigned newResultNullabilityIdx
1384 = nullabilityMap[receiverNullabilityIdx][resultNullabilityIdx];
1385 if (newResultNullabilityIdx == resultNullabilityIdx)
1391 if (
auto attributed = dyn_cast<AttributedType>(resultType.
getTypePtr())) {
1392 resultType = attributed->getModifiedType();
1399 if (newResultNullabilityIdx > 0) {
1404 resultType, resultType);
1423 dyn_cast<ObjCCategoryImplDecl>(impl)) {
1424 iface = catImpl->getCategoryDecl();
1426 iface = impl->getClassInterface();
1436 for (
unsigned i = 0, e = overrides.size(); i != e; ++i) {
1457 SourceRange range = overridden->getReturnTypeSourceRange();
1460 loc = overridden->getLocation();
1461 Diag(loc, diag::note_related_result_type_explicit)
1505 bool isClassMessage,
bool isSuperMessage,
1510 if (!SelectorLocs.empty() && SelectorLocs.front().isValid())
1511 SelLoc = SelectorLocs.front();
1517 for (
unsigned i = 0, e = Args.size(); i != e; i++) {
1518 if (Args[i]->isTypeDependent())
1522 if (getLangOpts().DebuggerSupport) {
1524 result = checkUnknownAnyArg(SelLoc, Args[i], paramTy);
1526 result = DefaultArgumentPromotion(Args[i]);
1530 Args[i] = result.
get();
1534 if (getLangOpts().ObjCAutoRefCount)
1535 DiagID = diag::err_arc_method_not_found;
1537 DiagID = isClassMessage ? diag::warn_class_method_not_found
1538 : diag::warn_inst_method_not_found;
1539 if (!getLangOpts().DebuggerSupport) {
1540 const ObjCMethodDecl *OMD = SelectorsForTypoCorrection(Sel, ReceiverType);
1542 if (getLangOpts().ObjCAutoRefCount)
1543 DiagID = diag::err_method_not_found_with_typo;
1545 DiagID = isClassMessage ? diag::warn_class_method_not_found_with_typo
1546 : diag::warn_instance_method_not_found_with_typo;
1548 SourceRange SelectorRange(SelectorLocs.front(), SelectorLocs.back());
1550 Diag(SelLoc, DiagID)
1551 << Sel<< isClassMessage << MatchedSel
1554 Diag(SelLoc, DiagID) << Sel<< isClassMessage << MatchedSel;
1557 Diag(SelLoc, DiagID)
1558 << Sel << isClassMessage <<
SourceRange(SelectorLocs.front(),
1559 SelectorLocs.back());
1564 Diag(ThisClass->getLocation(), diag::note_receiver_class_declared);
1566 if (ThisClass->lookupClassMethod(Sel))
1567 Diag(RecRange.
getBegin(),diag::note_receiver_expr_here)
1569 ThisClass->getNameAsString());
1576 if (getLangOpts().DebuggerSupport) {
1585 ReturnType = getMessageSendResultType(ReceiverType, Method, isClassMessage,
1595 if (Args.size() < NumNamedArgs) {
1596 Diag(SelLoc, diag::err_typecheck_call_too_few_args)
1597 << 2 << NumNamedArgs << static_cast<unsigned>(Args.size());
1605 bool IsError =
false;
1606 for (
unsigned i = 0; i < NumNamedArgs; i++) {
1608 if (Args[i]->isTypeDependent())
1611 Expr *argExpr = Args[i];
1614 assert(argExpr &&
"CheckMessageArgumentTypes(): missing expression");
1619 !param->
hasAttr<CFConsumedAttr>())
1620 argExpr = stripARCUnbridgedCast(argExpr);
1626 ExprResult argE = checkUnknownAnyArg(SelLoc, argExpr, paramType);
1630 Args[i] = argE.
get();
1648 diag::err_call_incomplete_argument, argExpr))
1663 Args[i]->getType()->isBlockPointerType() &&
1666 maybeExtendBlockObject(arg);
1667 Args[i] = arg.
get();
1674 for (
unsigned i = NumNamedArgs, e = Args.size(); i < e; ++i) {
1675 if (Args[i]->isTypeDependent())
1678 ExprResult Arg = DefaultVariadicArgumentPromotion(Args[i], VariadicMethod,
1681 Args[i] = Arg.
get();
1685 if (Args.size() != NumNamedArgs) {
1686 Diag(Args[NumNamedArgs]->getLocStart(),
1687 diag::err_typecheck_call_too_many_args)
1688 << 2 << NumNamedArgs << static_cast<unsigned>(Args.size())
1691 Args.back()->getLocEnd());
1695 DiagnoseSentinelCalls(Method, SelLoc, Args);
1698 IsError |= CheckObjCMethodCall(
1699 Method, SelLoc, makeArrayRef(Args.data(), Args.size()));
1707 dyn_cast_or_null<ObjCMethodDecl>(CurContext->getNonClosureAncestor());
1708 return isSelfExpr(RExpr, Method);
1712 if (!method)
return false;
1715 if (
DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(receiver))
1727 if (
ObjCMethodDecl *method = iface->lookupMethod(sel, isInstance))
1732 if (
ObjCMethodDecl *method = iface->lookupPrivateMethod(sel, isInstance))
1737 for (
const auto *I : objType->
quals())
1751 for (
const auto *PROTO : OPT->
quals()) {
1752 if ((MD = PROTO->lookupMethod(Sel, Instance))) {
1772 Diag(MemberLoc, diag::err_invalid_property_name)
1782 diag::err_property_not_found_forward_class,
1783 MemberName, BaseRange))
1789 if (DiagnoseUseOfDecl(PD, MemberLoc))
1792 return new (Context)
1796 return new (Context)
1801 for (
const auto *I : OPT->
quals())
1805 if (DiagnoseUseOfDecl(PD, MemberLoc))
1811 SuperLoc, SuperType);
1813 return new (Context)
1823 Selector Sel = PP.getSelectorTable().getNullarySelector(Member);
1828 Getter = LookupMethodInQualifiedType(Sel, OPT,
true);
1836 if (DiagnoseUseOfDecl(Getter, MemberLoc))
1843 PP.getSelectorTable(), Member);
1848 Setter = LookupMethodInQualifiedType(SetterSel, OPT,
true);
1856 if (Setter && DiagnoseUseOfDecl(Setter, MemberLoc))
1862 if (Setter && Setter->isImplicit() && Setter->isPropertyAccessor() &&
1870 diag::warn_property_access_suggest)
1871 << MemberName <<
QualType(OPT, 0) << PDecl->getName()
1876 if (Getter || Setter) {
1878 return new (Context)
1882 return new (Context)
1891 LookupOrdinaryName,
nullptr,
nullptr,
1892 llvm::make_unique<DeclFilterCCC<ObjCPropertyDecl>>(),
1893 CTK_ErrorRecovery, IFace,
false, OPT)) {
1899 Corrected.isKeyword() ? nullptr : Corrected.getFoundDecl();
1900 if (ChosenDecl && isa<ObjCPropertyDecl>(ChosenDecl))
1901 if (cast<ObjCPropertyDecl>(ChosenDecl)->isClassProperty()) {
1904 Diag(MemberLoc, diag::err_class_property_found) << MemberName
1911 diagnoseTypo(Corrected, PDiag(diag::err_property_not_found_suggest)
1912 << MemberName <<
QualType(OPT, 0));
1913 return HandleExprPropertyRefExpr(OPT, BaseExpr, OpLoc,
1914 TypoResult, MemberLoc,
1915 SuperLoc, SuperType, Super);
1924 if (RequireCompleteType(MemberLoc, OBJPT->getPointeeType(),
1925 diag::err_property_not_as_forward_class,
1926 MemberName, BaseExpr))
1930 diag::err_ivar_access_using_property_syntax_suggest)
1931 << MemberName <<
QualType(OPT, 0) << Ivar->getDeclName()
1936 Diag(MemberLoc, diag::err_property_not_found)
1939 Diag(Setter->getLocation(), diag::note_getter_unavailable)
1958 if (receiverNamePtr->
isStr(
"super")) {
1959 if (
ObjCMethodDecl *CurMethod = tryCaptureObjCSelf(receiverNameLoc)) {
1960 if (
auto classDecl = CurMethod->getClassInterface()) {
1961 SuperType =
QualType(classDecl->getSuperClassType(), 0);
1962 if (CurMethod->isInstanceMethod()) {
1963 if (SuperType.
isNull()) {
1965 Diag(receiverNameLoc, diag::err_root_class_cannot_use_super)
1966 << CurMethod->getClassInterface()->getIdentifier();
1976 receiverNameLoc, T,
true);
1987 Diag(receiverNameLoc, diag::err_expected_either) << tok::identifier
1997 GetterSel = PD->getGetterName();
1998 SetterSel = PD->getSetterName();
2000 GetterSel = PP.getSelectorTable().getNullarySelector(&propertyName);
2002 PP.getIdentifierTable(), PP.getSelectorTable(), &propertyName);
2015 if (DiagnoseUseOfDecl(Getter, propertyNameLoc))
2030 if (Setter && DiagnoseUseOfDecl(Setter, propertyNameLoc))
2033 if (Getter || Setter) {
2035 return new (Context)
2042 propertyNameLoc, receiverNameLoc, IFace);
2044 return ExprError(
Diag(propertyNameLoc, diag::err_property_not_found)
2058 bool ValidateCandidate(
const TypoCorrection &candidate)
override {
2070 bool HasTrailingDot,
2072 ReceiverType =
nullptr;
2078 return HasTrailingDot? ObjCInstanceMessage : ObjCSuperMessage;
2080 LookupResult Result(*
this, Name, NameLoc, LookupOrdinaryName);
2081 LookupName(Result, S);
2090 if (!Method->getClassInterface()) {
2092 return ObjCInstanceMessage;
2096 if (Method->getClassInterface()->lookupInstanceVariable(Name,
2098 return ObjCInstanceMessage;
2109 return ObjCInstanceMessage;
2115 return ObjCInstanceMessage;
2124 DiagnoseUseOfDecl(
Type, NameLoc);
2127 return ObjCInstanceMessage;
2132 ReceiverType = CreateParsedType(T, TSInfo);
2133 return ObjCClassMessage;
2139 llvm::make_unique<ObjCInterfaceOrSuperCCC>(getCurMethodDecl()),
2140 CTK_ErrorRecovery,
nullptr,
false,
nullptr,
false)) {
2141 if (Corrected.isKeyword()) {
2144 diagnoseTypo(Corrected,
2145 PDiag(diag::err_unknown_receiver_suggest) << Name);
2146 return ObjCSuperMessage;
2151 diagnoseTypo(Corrected,
2152 PDiag(diag::err_unknown_receiver_suggest) << Name);
2155 ReceiverType = CreateParsedType(T, TSInfo);
2156 return ObjCClassMessage;
2161 return ObjCInstanceMessage;
2174 Diag(SuperLoc, diag::err_invalid_receiver_to_message_super);
2180 Diag(SuperLoc, diag::err_no_super_class_message)
2186 if (SuperTy.isNull()) {
2188 Diag(SuperLoc, diag::err_root_class_cannot_use_super)
2196 getCurFunction()->ObjCShouldCallSuper =
false;
2202 return BuildInstanceMessage(
nullptr, SuperTy, SuperLoc,
2204 LBracLoc, SelectorLocs, RBracLoc, Args);
2209 return BuildClassMessage(
nullptr,
2211 SuperLoc, Sel,
nullptr,
2212 LBracLoc, SelectorLocs, RBracLoc, Args);
2216 bool isSuperReceiver,
2222 if (!ReceiverType.
isNull())
2225 return BuildClassMessage(receiverTypeInfo, ReceiverType,
2227 Sel, Method, Loc, Loc, Loc, Args,
2241 if (refactor(Msg,*S.
NSAPIObj, ECommit)) {
2250 switch (Edit.
Kind) {
2278 bool IsClassObjectCall) {
2288 if (!IsClassObjectCall) {
2290 if (!OPT || !OPT->getInterfaceDecl())
2293 OPT->getInterfaceDecl()->lookupInstanceMethod(SE->getSelector());
2296 OPT->getInterfaceDecl()->lookupPrivateMethod(SE->getSelector());
2301 ImpliedMethod = IT->getDecl()->lookupClassMethod(SE->getSelector());
2304 IT->getDecl()->lookupPrivateClassMethod(SE->getSelector());
2311 S.
Diag(Loc, diag::warn_objc_unsafe_perform_selector)
2317 diag::note_objc_unsafe_perform_selector_method_declared_here)
2328 Expr **Args,
unsigned NumArgs) {
2330 bool Format =
false;
2344 if (!Format || NumArgs <= Idx)
2347 Expr *FormatExpr = Args[Idx];
2352 S.
Diag(FormatExpr->
getExprLoc(), diag::warn_objc_cdirective_format_string)
2402 Diag(Loc, diag::err_missing_open_square_message_send)
2407 if (!SelectorLocs.empty() && SelectorLocs.front().isValid())
2408 SelLoc = SelectorLocs.front();
2415 unsigned NumArgs = ArgsIn.size();
2416 Expr **Args = ArgsIn.data();
2417 assert(SuperLoc.
isInvalid() &&
"Message to super with dependent type");
2419 Context, ReceiverType,
VK_RValue, LBracLoc, ReceiverTypeInfo, Sel,
2420 SelectorLocs,
nullptr, makeArrayRef(Args, NumArgs), RBracLoc,
2427 if (!ClassType || !(Class = ClassType->
getInterface())) {
2428 Diag(Loc, diag::err_invalid_receiver_class_message)
2432 assert(Class &&
"We don't know which class we're messaging?");
2435 (void)DiagnoseUseOfDecl(Class, SelLoc);
2442 (getLangOpts().ObjCAutoRefCount
2443 ? diag::err_arc_receiver_forward_class
2444 : diag::warn_receiver_forward_class),
2447 Method = LookupFactoryMethodInGlobalPool(Sel,
2449 if (Method && !getLangOpts().ObjCAutoRefCount)
2460 if (Method && DiagnoseUseOfDecl(Method, SelLoc))
2468 unsigned NumArgs = ArgsIn.size();
2469 Expr **Args = ArgsIn.data();
2470 if (CheckMessageArgumentTypes(ReceiverType,
MultiExprArg(Args, NumArgs),
2473 SuperLoc.
isValid(), LBracLoc, RBracLoc,
2480 diag::err_illegal_message_expr_incomplete_type))
2489 Diag(Loc, diag::warn_direct_initialize_call);
2497 Diag(Loc, diag::warn_direct_super_initialize_call);
2500 Diag(CurMeth->getLocation(), diag::note_method_declared_at)
2501 << CurMeth->getDeclName();
2513 ReceiverType, Sel, SelectorLocs,
2514 Method, makeArrayRef(Args, NumArgs),
2515 RBracLoc, isImplicit);
2518 ReceiverTypeInfo, Sel, SelectorLocs,
2519 Method, makeArrayRef(Args, NumArgs),
2520 RBracLoc, isImplicit);
2526 ReceiverType,
true);
2527 return MaybeBindToTemporary(Result);
2541 QualType ReceiverType = GetTypeFromParser(Receiver, &ReceiverTypeInfo);
2542 if (ReceiverType.
isNull())
2545 if (!ReceiverTypeInfo)
2548 return BuildClassMessage(ReceiverTypeInfo, ReceiverType,
2550 nullptr, LBracLoc, SelectorLocs, RBracLoc,
2560 return BuildInstanceMessage(Receiver, ReceiverType,
2562 Sel, Method, Loc, Loc, Loc, Args,
2573 if (
const auto *RootClass = dyn_cast_or_null<ObjCInterfaceDecl>(
2577 if (
P->getCanonicalDecl() == Protocol->getCanonicalDecl())
2622 assert((Receiver || SuperLoc.
isValid()) &&
"If the Receiver is null, the " 2623 "SuperLoc must be valid so we can " 2631 if (!SelectorLocs.empty() && SelectorLocs.front().isValid())
2632 SelLoc = SelectorLocs.front();
2637 Diag(Loc, diag::err_missing_open_square_message_send)
2648 Result = forceUnknownAnyToType(Receiver, Context.
getObjCIdType());
2650 Result = CheckPlaceholderExpr(Receiver);
2652 Receiver = Result.
get();
2658 unsigned NumArgs = ArgsIn.size();
2659 Expr **Args = ArgsIn.data();
2660 assert(SuperLoc.
isInvalid() &&
"Message to super with dependent type");
2663 SelectorLocs,
nullptr, makeArrayRef(Args, NumArgs),
2664 RBracLoc, isImplicit);
2669 ExprResult Result = DefaultFunctionArrayLvalueConversion(Receiver);
2672 Receiver = Result.
get();
2673 ReceiverType = Receiver->
getType();
2680 }
else if (!getLangOpts().ObjCAutoRefCount &&
2686 Diag(Loc, diag::warn_bad_receiver_type)
2690 Receiver = ImpCastExprToType(Receiver, Context.
getObjCIdType(),
2691 CK_CPointerToObjCPointerCast).
get();
2696 CastKind Kind = IsNull ? CK_NullToPointer : CK_IntegralToPointer;
2697 Receiver = ImpCastExprToType(Receiver, Context.
getObjCIdType(),
2700 ReceiverType = Receiver->
getType();
2703 if (RequireCompleteType(Loc, Receiver->
getType(),
2704 diag::err_incomplete_receiver_type))
2707 ExprResult result = PerformContextuallyConvertToObjCPointer(Receiver);
2709 Receiver = result.
get();
2710 ReceiverType = Receiver->
getType();
2716 Diag(Receiver->
getExprLoc(), diag::warn_messaging_unqualified_id);
2732 CollectMultipleMethodsInGlobalPool(Sel, Methods,
true,
2734 if (!Methods.empty()) {
2737 Method = Methods[0];
2741 Method = BestMethod;
2743 if (!AreMultipleMethodsInGlobalPool(Sel, Method,
2745 receiverIsIdLike, Methods))
2746 DiagnoseUseOfDecl(Method, SelLoc);
2758 Method = LookupMethodInQualifiedType(Sel, QClassTy,
false);
2760 Method = LookupMethodInQualifiedType(Sel, QClassTy,
true);
2763 Diag(SelLoc, diag::warn_instance_method_on_class_found)
2773 Method = ClassDecl->lookupClassMethod(Sel);
2776 Method = ClassDecl->lookupPrivateClassMethod(Sel);
2778 if (Method && DiagnoseUseOfDecl(Method, SelLoc))
2783 if (!Receiver || !isSelfExpr(Receiver)) {
2787 CollectMultipleMethodsInGlobalPool(Sel, Methods,
2790 if (!Methods.empty()) {
2793 Method = Methods[0];
2799 if (
ID->getSuperClass())
2800 Diag(SelLoc, diag::warn_root_inst_method_not_found)
2808 Method = BestMethod;
2822 Method = LookupMethodInQualifiedType(Sel, QIdTy,
true);
2824 Method = LookupMethodInQualifiedType(Sel, QIdTy,
false);
2825 if (Method && DiagnoseUseOfDecl(Method, SelLoc))
2830 ClassDecl = OCIType->getInterfaceDecl();
2837 if (RequireCompleteType(Loc, OCIType->getPointeeType(),
2838 getLangOpts().ObjCAutoRefCount
2839 ? diag::err_arc_receiver_forward_instance
2840 : diag::warn_receiver_forward_instance,
2843 if (getLangOpts().ObjCAutoRefCount)
2846 forwardClass = OCIType->getInterfaceDecl();
2848 : SuperLoc, diag::note_receiver_is_id);
2856 Method = LookupMethodInQualifiedType(Sel, OCIType,
true);
2862 if (!Method && getLangOpts().ObjCAutoRefCount) {
2863 Diag(SelLoc, diag::err_arc_may_not_respond)
2864 << OCIType->getPointeeType() << Sel << RecRange
2865 <<
SourceRange(SelectorLocs.front(), SelectorLocs.back());
2869 if (!Method && (!Receiver || !isSelfExpr(Receiver))) {
2873 if (OCIType->qual_empty()) {
2875 CollectMultipleMethodsInGlobalPool(Sel, Methods,
2878 if (!Methods.empty()) {
2881 Method = Methods[0];
2886 Method = BestMethod;
2888 AreMultipleMethodsInGlobalPool(Sel, Method,
2893 if (Method && !forwardClass)
2894 Diag(SelLoc, diag::warn_maynot_respond)
2895 << OCIType->getInterfaceDecl()->getIdentifier()
2900 if (Method && DiagnoseUseOfDecl(Method, SelLoc, forwardClass))
2904 Diag(Loc, diag::err_bad_receiver_type)
2913 ? getEnclosingFunction() :
nullptr;
2915 if (DIFunctionScopeInfo &&
2917 (SuperLoc.
isValid() || isSelfExpr(Receiver))) {
2918 bool isDesignatedInitChain =
false;
2925 if (!
ID->declaresOrInheritsDesignatedInitializers() ||
2926 ID->isDesignatedInitializer(Sel)) {
2927 isDesignatedInitChain =
true;
2933 if (!isDesignatedInitChain) {
2937 assert(isDesignated && InitMethod);
2940 diag::warn_objc_designated_init_non_designated_init_call :
2941 diag::warn_objc_designated_init_non_super_designated_init_call);
2943 diag::note_objc_designated_init_marked_here);
2947 if (DIFunctionScopeInfo &&
2949 (SuperLoc.
isValid() || isSelfExpr(Receiver))) {
2951 Diag(SelLoc, diag::warn_objc_secondary_init_super_init_call);
2958 unsigned NumArgs = ArgsIn.size();
2959 Expr **Args = ArgsIn.data();
2964 if (CheckMessageArgumentTypes(ReceiverType,
MultiExprArg(Args, NumArgs),
2965 Sel, SelectorLocs, Method,
2966 ClassMessage, SuperLoc.
isValid(),
2967 LBracLoc, RBracLoc, RecRange, ReturnType, VK))
2972 diag::err_illegal_message_expr_incomplete_type))
2977 if (getLangOpts().ObjCAutoRefCount) {
2983 checkInitMethod(Method, ReceiverType);
3001 Diag(SelLoc, diag::err_arc_illegal_explicit_message)
3006 if (Method && NumArgs >= 1) {
3007 if (
const auto *SelExp =
3008 dyn_cast<ObjCSelectorExpr>(Args[0]->IgnoreParens())) {
3009 Selector ArgSel = SelExp->getSelector();
3011 LookupInstanceMethodInGlobalPool(ArgSel,
3012 SelExp->getSourceRange());
3015 LookupFactoryMethodInGlobalPool(ArgSel,
3016 SelExp->getSourceRange());
3019 switch (SelFamily) {
3026 if (!SelMethod->
hasAttr<NSReturnsNotRetainedAttr>()) {
3029 diag::err_arc_perform_selector_retains);
3036 if (SelMethod->
hasAttr<NSReturnsRetainedAttr>()) {
3039 diag::err_arc_perform_selector_retains);
3048 Diag(SelLoc, diag::warn_arc_perform_selector_leaks);
3049 Diag(Args[0]->getExprLoc(), diag::note_used_here);
3063 ReceiverType, Sel, SelectorLocs, Method,
3064 makeArrayRef(Args, NumArgs), RBracLoc,
3068 Receiver, Sel, SelectorLocs, Method,
3069 makeArrayRef(Args, NumArgs), RBracLoc,
3075 bool IsClassObjectCall = ClassMessage;
3080 if (Receiver && isSelfExpr(Receiver)) {
3082 if (OPT->getObjectType()->isObjCClass()) {
3083 if (
const auto *CurMeth = getCurMethodDecl()) {
3084 IsClassObjectCall =
true;
3092 ReceiverType, IsClassObjectCall);
3095 if (getLangOpts().ObjCAutoRefCount) {
3098 (SuperLoc.
isValid() || isSelfExpr(Receiver))) {
3112 checkRetainCycles(Result);
3115 if (getLangOpts().ObjCWeak) {
3116 if (!isImplicit && Method) {
3123 !Diags.isIgnored(diag::warn_arc_repeated_use_of_weak, LBracLoc))
3124 getCurFunction()->recordUseOfWeak(Result, Prop);
3129 CheckObjCCircularContainer(Result);
3131 return MaybeBindToTemporary(Result);
3159 if (isa<ParenListExpr>(Receiver)) {
3160 ExprResult Result = MaybeConvertParenListExprToParenExpr(S, Receiver);
3162 Receiver = Result.
get();
3165 if (RespondsToSelectorSel.isNull()) {
3169 if (Sel == RespondsToSelectorSel)
3172 return BuildInstanceMessage(Receiver, Receiver->
getType(),
3174 nullptr, LBracLoc, SelectorLocs,
3208 bool isIndirect =
false;
3227 type =
QualType(array->getElementType()->getBaseElementTypeUnsafe(), 0);
3262 if (left == right)
return left;
3263 if (left == ACC_bottom)
return right;
3264 if (right == ACC_bottom)
return left;
3270 class ARCCastChecker :
public StmtVisitor<ARCCastChecker, ACCResult> {
3286 : Context(Context), SourceClass(source), TargetClass(target),
3287 Diagnose(diagnose) {}
3317 case CK_NullToPointer:
3321 case CK_LValueToRValue:
3323 case CK_CPointerToObjCPointerCast:
3324 case CK_BlockPointerToObjCPointerCast:
3325 case CK_AnyPointerToBlockPointerCast:
3340 return Visit(e->
getRHS());
3346 if (left == ACC_invalid)
return ACC_invalid;
3376 return ACC_plusZero;
3386 if (
ACCResult result = checkCallToFunction(fn))
3389 return super::VisitCallExpr(e);
3401 if (fn->
hasAttr<CFReturnsNotRetainedAttr>())
3402 return ACC_plusZero;
3407 if (fn->
hasAttr<CFReturnsRetainedAttr>())
3408 return Diagnose ? ACC_plusOne
3413 if (builtinID == Builtin::BI__builtin___CFStringMakeConstantString)
3417 if (!fn->
hasAttr<CFAuditedTransferAttr>())
3422 return Diagnose ? ACC_plusOne
3425 return ACC_plusZero;
3438 return checkCallToMethod(method);
3442 if (!method)
return ACC_invalid;
3451 if (method->
hasAttr<CFReturnsNotRetainedAttr>())
3452 return ACC_plusZero;
3456 if (method->
hasAttr<CFReturnsRetainedAttr>())
3468 return ACC_plusZero;
3479 return LookupName(R, TUScope,
false);
3489 const char *bridgeKeyword,
3490 const char *CFBridgeName) {
3505 NCE->getAngleBrackets().getEnd());
3509 char PrevChar = *SM.
getCharacterData(range.getBegin().getLocWithOffset(-1));
3513 BridgeCall += CFBridgeName;
3520 castedE = CCE->getSubExpr();
3531 BridgeCall += CFBridgeName;
3533 if (isa<ParenExpr>(castedE)) {
3551 std::string castCode =
"(";
3552 castCode += bridgeKeyword;
3556 NCE->getAngleBrackets().getEnd());
3560 std::string castCode =
"(";
3561 castCode += bridgeKeyword;
3566 if (isa<ParenExpr>(castedE)) {
3580 template <
typename T>
3588 return RD->getAttr<
T>();
3596 TDNDecl = TD->getDecl();
3597 if (ObjCBridgeRelatedAttr *ObjCBAttr =
3598 getObjCBridgeAttr<ObjCBridgeRelatedAttr>(TD))
3615 UnavailableAttr::IR_ARCForbiddenConversion))
3628 unsigned srcKind = 0;
3650 S.
Diag(loc, diag::err_arc_cast_requires_bridge)
3660 ARCCastChecker(S.
Context, exprACTC, castACTC,
true).Visit(castExpr);
3661 assert(CreateRule != ACC_bottom &&
"This cast should already be accepted.");
3662 if (CreateRule != ACC_plusOne)
3666 : S.
Diag(noteLoc, diag::note_arc_cstyle_bridge);
3669 castType, castExpr, realCast,
"__bridge ",
3672 if (CreateRule != ACC_plusZero)
3676 S.
Diag(noteLoc, diag::note_arc_cstyle_bridge_transfer) << castExprType :
3678 diag::note_arc_bridge_transfer)
3679 << castExprType << br;
3682 castType, castExpr, realCast,
"__bridge_transfer ",
3683 br ?
"CFBridgingRelease" :
nullptr);
3692 S.
Diag(loc, diag::err_arc_cast_requires_bridge)
3701 ARCCastChecker(S.
Context, exprACTC, castACTC,
true).Visit(castExpr);
3702 assert(CreateRule != ACC_bottom &&
"This cast should already be accepted.");
3703 if (CreateRule != ACC_plusOne)
3707 : S.
Diag(noteLoc, diag::note_arc_cstyle_bridge);
3709 castType, castExpr, realCast,
"__bridge ",
3712 if (CreateRule != ACC_plusZero)
3716 S.
Diag(noteLoc, diag::note_arc_cstyle_bridge_retained) << castType :
3718 diag::note_arc_bridge_retained)
3722 castType, castExpr, realCast,
"__bridge_retained ",
3723 br ?
"CFBridgingRetain" :
nullptr);
3729 S.
Diag(loc, diag::err_arc_mismatched_cast)
3731 << srcKind << castExprType << castType
3735 template <
typename TB>
3737 bool &HadTheAttribute,
bool warn) {
3739 HadTheAttribute =
false;
3742 if (TB *ObjCBAttr = getObjCBridgeAttr<TB>(TD)) {
3744 HadTheAttribute =
true;
3745 if (Parm->isStr(
"id"))
3754 if (Target && isa<ObjCInterfaceDecl>(Target)) {
3759 = InterfacePointerType->getObjectType()->getInterface();
3760 if ((CastClass == ExprClass) ||
3769 castType, ExprClass)))
3777 << T << Target->
getName() << castType;
3785 S.
Diag(castExpr->
getLocStart(), diag::err_objc_cf_bridged_not_interface)
3786 << castExpr->
getType() << Parm;
3800 template <
typename TB>
3802 bool &HadTheAttribute,
bool warn) {
3804 HadTheAttribute =
false;
3807 if (TB *ObjCBAttr = getObjCBridgeAttr<TB>(TD)) {
3809 HadTheAttribute =
true;
3810 if (Parm->isStr(
"id"))
3819 if (Target && isa<ObjCInterfaceDecl>(Target)) {
3824 = InterfacePointerType->getObjectType()->getInterface();
3825 if ((CastClass == ExprClass) ||
3836 castExpr->
getType(), CastClass)))
3844 << castExpr->
getType() << castType;
3852 S.
Diag(castExpr->
getLocStart(), diag::err_objc_ns_bridged_invalid_cfobject)
3853 << castExpr->
getType() << castType;
3867 if (!getLangOpts().ObjC1)
3873 bool HasObjCBridgeAttr;
3874 bool ObjCBridgeAttrWillNotWarn =
3875 CheckObjCBridgeNSCast<ObjCBridgeAttr>(*
this, castType,
castExpr, HasObjCBridgeAttr,
3877 if (ObjCBridgeAttrWillNotWarn && HasObjCBridgeAttr)
3879 bool HasObjCBridgeMutableAttr;
3880 bool ObjCBridgeMutableAttrWillNotWarn =
3881 CheckObjCBridgeNSCast<ObjCBridgeMutableAttr>(*
this, castType,
castExpr,
3882 HasObjCBridgeMutableAttr,
false);
3883 if (ObjCBridgeMutableAttrWillNotWarn && HasObjCBridgeMutableAttr)
3886 if (HasObjCBridgeAttr)
3887 CheckObjCBridgeNSCast<ObjCBridgeAttr>(*
this, castType,
castExpr, HasObjCBridgeAttr,
3889 else if (HasObjCBridgeMutableAttr)
3890 CheckObjCBridgeNSCast<ObjCBridgeMutableAttr>(*
this, castType,
castExpr,
3891 HasObjCBridgeMutableAttr,
true);
3894 bool HasObjCBridgeAttr;
3895 bool ObjCBridgeAttrWillNotWarn =
3896 CheckObjCBridgeCFCast<ObjCBridgeAttr>(*
this, castType,
castExpr, HasObjCBridgeAttr,
3898 if (ObjCBridgeAttrWillNotWarn && HasObjCBridgeAttr)
3900 bool HasObjCBridgeMutableAttr;
3901 bool ObjCBridgeMutableAttrWillNotWarn =
3902 CheckObjCBridgeCFCast<ObjCBridgeMutableAttr>(*
this, castType,
castExpr,
3903 HasObjCBridgeMutableAttr,
false);
3904 if (ObjCBridgeMutableAttrWillNotWarn && HasObjCBridgeMutableAttr)
3907 if (HasObjCBridgeAttr)
3908 CheckObjCBridgeCFCast<ObjCBridgeAttr>(*
this, castType,
castExpr, HasObjCBridgeAttr,
3910 else if (HasObjCBridgeMutableAttr)
3911 CheckObjCBridgeCFCast<ObjCBridgeMutableAttr>(*
this, castType,
castExpr,
3912 HasObjCBridgeMutableAttr,
true);
3919 if (PRE->isExplicitProperty()) {
3921 SrcType = PDecl->getType();
3923 else if (PRE->isImplicitProperty()) {
3925 SrcType = Getter->getReturnType();
3933 CheckObjCBridgeRelatedConversions(castExpr->
getLocStart(),
3939 if (!getLangOpts().ObjC1)
3946 CheckTollFreeBridgeCast(castType, castExpr);
3948 : CK_CPointerToObjCPointerCast;
3960 bool CfToNs,
bool Diagnose) {
3961 QualType T = CfToNs ? SrcType : DestType;
3975 if (!LookupName(R, TUScope)) {
3977 Diag(Loc, diag::err_objc_bridged_related_invalid_class) << RCId
3978 << SrcType << DestType;
3984 if (Target && isa<ObjCInterfaceDecl>(Target))
3985 RelatedClass = cast<ObjCInterfaceDecl>(Target);
3988 Diag(Loc, diag::err_objc_bridged_related_invalid_class_name) << RCId
3989 << SrcType << DestType;
3998 if (CfToNs && CMId) {
4003 Diag(Loc, diag::err_objc_bridged_related_known_method)
4004 << SrcType << DestType << Sel <<
false;
4012 if (!CfToNs && IMId) {
4014 InstanceMethod = RelatedClass->
lookupMethod(Sel,
true);
4015 if (!InstanceMethod) {
4017 Diag(Loc, diag::err_objc_bridged_related_known_method)
4018 << SrcType << DestType << Sel <<
true;
4030 Expr *&SrcExpr,
bool Diagnose) {
4035 if (!CfToNs && !NsToCf)
4042 if (!checkObjCBridgeRelatedComponents(Loc, DestType, SrcType, RelatedClass,
4043 ClassMethod, InstanceMethod, TDNDecl,
4051 std::string ExpressionString =
"[";
4053 ExpressionString +=
" ";
4057 Diag(Loc, diag::err_objc_bridged_related_known_method)
4058 << SrcType << DestType << ClassMethod->
getSelector() <<
false 4066 Expr *args[] = { SrcExpr };
4067 ExprResult msg = BuildClassMessageImplicit(receiverType,
false,
4071 SrcExpr = msg.
get();
4078 if (InstanceMethod) {
4080 std::string ExpressionString;
4082 getLocForEndOfToken(SrcExpr->
getLocEnd());
4087 ExpressionString =
".";
4088 ExpressionString += PDecl->getNameAsString();
4089 Diag(Loc, diag::err_objc_bridged_related_known_method)
4090 << SrcType << DestType << InstanceMethod->
getSelector() <<
true 4093 if (ExpressionString.empty()) {
4095 ExpressionString =
" ";
4097 ExpressionString +=
"]";
4099 Diag(Loc, diag::err_objc_bridged_related_known_method)
4100 << SrcType << DestType << InstanceMethod->
getSelector() <<
true 4108 BuildInstanceMessageImplicit(SrcExpr, SrcType,
4111 InstanceMethod, None);
4112 SrcExpr = msg.get();
4123 bool Diagnose,
bool DiagnoseCFAudited,
4135 if (exprACTC == castACTC) {
4139 (CCK == CCK_CStyleCast || CCK == CCK_OtherCast) &&
4140 castType != castExprType) {
4146 if (
const ParenType *PT = dyn_cast<ParenType>(DT))
4147 QDT = PT->desugar();
4148 else if (
const TypeOfType *TP = dyn_cast<TypeOfType>(DT))
4149 QDT = TP->desugar();
4150 else if (
const AttributedType *AT = dyn_cast<AttributedType>(DT))
4151 QDT = AT->desugar();
4152 if (QDT != castType &&
4157 Diag(loc, diag::err_arc_nolifetime_behavior);
4167 if (!getLangOpts().ObjCAutoRefCount)
4183 CCK != CCK_ImplicitConversion)
4186 switch (ARCCastChecker(Context, exprACTC, castACTC,
false).Visit(castExpr)) {
4201 Cleanup.setExprNeedsCleanups(
true);
4209 CCK != CCK_ImplicitConversion)
4210 return ACR_unbridged;
4216 ConversionToObjCStringLiteralCheck(castType, castExpr, Diagnose))
4226 (Opc == BO_NE || Opc == BO_EQ))) {
4229 castExpr, exprACTC, CCK);
4248 castType =
cast->getTypeAsWritten();
4249 CCK = CCK_CStyleCast;
4251 castRange =
cast->getTypeInfoAsWritten()->getTypeLoc().getSourceRange();
4252 castType =
cast->getTypeAsWritten();
4253 CCK = CCK_OtherCast;
4255 llvm_unreachable(
"Unexpected ImplicitCastExpr");
4273 if (
ParenExpr *pe = dyn_cast<ParenExpr>(e)) {
4274 Expr *sub = stripARCUnbridgedCast(pe->getSubExpr());
4275 return new (Context)
ParenExpr(pe->getLParen(), pe->getRParen(), sub);
4276 }
else if (
UnaryOperator *uo = dyn_cast<UnaryOperator>(e)) {
4277 assert(uo->getOpcode() == UO_Extension);
4278 Expr *sub = stripARCUnbridgedCast(uo->getSubExpr());
4279 return new (Context)
UnaryOperator(sub, UO_Extension, sub->getType(),
4280 sub->getValueKind(), sub->getObjectKind(),
4281 uo->getOperatorLoc());
4283 assert(!gse->isResultDependent());
4285 unsigned n = gse->getNumAssocs();
4288 for (
unsigned i = 0; i != n; ++i) {
4289 subTypes[i] = gse->getAssocTypeSourceInfo(i);
4290 Expr *sub = gse->getAssocExpr(i);
4291 if (i == gse->getResultIndex())
4292 sub = stripARCUnbridgedCast(sub);
4297 gse->getControllingExpr(),
4299 gse->getDefaultLoc(),
4300 gse->getRParenLoc(),
4301 gse->containsUnexpandedParameterPack(),
4302 gse->getResultIndex());
4304 assert(isa<ImplicitCastExpr>(e) &&
"bad form of unbridged cast!");
4305 return cast<ImplicitCastExpr>(e)->getSubExpr();
4315 if (isa<ObjCObjectPointerType>(canCastType) &&
4321 return !ObjI->isArcWeakrefUnavailable();
4328 Expr *curExpr = e, *prevExpr =
nullptr;
4333 if (
auto *pe = dyn_cast<ParenExpr>(curExpr)) {
4335 curExpr = pe->getSubExpr();
4339 if (
auto *ce = dyn_cast<CastExpr>(curExpr)) {
4340 if (
auto *ice = dyn_cast<ImplicitCastExpr>(ce))
4341 if (ice->getCastKind() == CK_ARCReclaimReturnedObject) {
4343 return ice->getSubExpr();
4344 if (
auto *pe = dyn_cast<ParenExpr>(prevExpr))
4345 pe->setSubExpr(ice->getSubExpr());
4347 cast<CastExpr>(prevExpr)->setSubExpr(ice->getSubExpr());
4352 curExpr = ce->getSubExpr();
4368 ExprResult SubResult = UsualUnaryConversions(SubExpr);
4370 SubExpr = SubResult.
get();
4377 bool MustConsume =
false;
4384 : CK_CPointerToObjCPointerCast);
4390 bool br = isKnownName(
"CFBridgingRelease");
4391 Diag(BridgeKeywordLoc, diag::err_arc_bridge_cast_wrong_kind)
4398 Diag(BridgeKeywordLoc, diag::note_arc_bridge)
4400 Diag(BridgeKeywordLoc, diag::note_arc_bridge_transfer)
4403 br ?
"CFBridgingRelease " 4404 :
"__bridge_transfer ");
4428 CK_ARCProduceObject,
4433 bool br = isKnownName(
"CFBridgingRetain");
4434 Diag(BridgeKeywordLoc, diag::err_arc_bridge_cast_wrong_kind)
4442 Diag(BridgeKeywordLoc, diag::note_arc_bridge)
4444 Diag(BridgeKeywordLoc, diag::note_arc_bridge_retained)
4447 br ?
"CFBridgingRetain " :
"__bridge_retained");
4454 Diag(LParenLoc, diag::err_arc_bridge_cast_incompatible)
4455 << FromType << T << Kind
4466 Cleanup.setExprNeedsCleanups(
true);
4482 QualType T = GetTypeFromParser(Type, &TSInfo);
4484 CheckTollFreeBridgeCast(T, SubExpr);
4487 return BuildObjCBridgedCast(LParenLoc, Kind, BridgeKeywordLoc, TSInfo,
ObjCPropertyRefExpr - A dot-syntax expression to access an ObjC property.
ObjCMethodDecl * LookupMethodInQualifiedType(Selector Sel, const ObjCObjectPointerType *OPT, bool IsInstance)
LookupMethodInQualifiedType - Lookups up a method in protocol qualifier list of a qualified objective...
const ObjCInterfaceType * getInterfaceType() const
If this pointer points to an Objective C @interface type, gets the type for that interface.
const internal::VariadicAllOfMatcher< Type > type
Matches Types in the clang AST.
Defines the clang::ASTContext interface.
ObjCMethodDecl * lookupPrivateClassMethod(const Selector &Sel)
bool hasDefinition() const
Determine whether this class has been defined.
QualType withConst() const
Retrieves a version of this type with const applied.
QualType getObjCObjectType(QualType Base, ObjCProtocolDecl *const *Protocols, unsigned NumProtocols) const
Legacy interface: cannot provide type arguments or __kindof.
An instance of this class is created to represent a function declaration or definition.
Name lookup found a set of overloaded functions that met the criteria.
static DiagnosticBuilder Diag(DiagnosticsEngine *Diags, const LangOptions &Features, FullSourceLoc TokLoc, const char *TokBegin, const char *TokRangeBegin, const char *TokRangeEnd, unsigned DiagID)
Produce a diagnostic highlighting some portion of a literal.
bool isSelfExpr(Expr *RExpr)
Private Helper predicate to check for 'self'.
SourceLocation getLocWithOffset(int Offset) const
Return a source location with the specified offset from this SourceLocation.
static ObjCArrayLiteral * Create(const ASTContext &C, ArrayRef< Expr *> Elements, QualType T, ObjCMethodDecl *Method, SourceRange SR)
Smart pointer class that efficiently represents Objective-C method names.
QualType getObjCIdType() const
Represents the Objective-CC id type.
static void checkFoundationAPI(Sema &S, SourceLocation Loc, const ObjCMethodDecl *Method, ArrayRef< Expr *> Args, QualType ReceiverType, bool IsClassObjectCall)
if(T->getSizeExpr()) TRY_TO(TraverseStmt(T -> getSizeExpr()))
PointerType - C99 6.7.5.1 - Pointer Declarators.
QualType getPointeeType() const
A (possibly-)qualified type.
bool isBlockPointerType() const
QualType substObjCTypeArgs(ASTContext &ctx, ArrayRef< QualType > typeArgs, ObjCSubstitutionContext context) const
Substitute type arguments for the Objective-C type parameters used in the subject type...
Simple class containing the result of Sema::CorrectTypo.
unsigned param_size() const
Selector getSelector() const
ObjCInterfaceDecl * getClassInterface()
ExprResult ActOnSuperMessage(Scope *S, SourceLocation SuperLoc, Selector Sel, SourceLocation LBracLoc, ArrayRef< SourceLocation > SelectorLocs, SourceLocation RBracLoc, MultiExprArg Args)
A cast other than a C-style cast.
void* might be a normal C type, or it might a CF type.
void AddFixItHint(const FixItHint &Hint) const
QualType getDesugaredType(const ASTContext &Context) const
Return the specified type with any "sugar" removed from the type.
ObjCBridgeCastKind
The kind of bridging performed by the Objective-C bridge cast.
Ordinary name lookup, which finds ordinary names (functions, variables, typedefs, etc...
CompoundStmt * getSubStmt()
bool LookupName(LookupResult &R, Scope *S, bool AllowBuiltinCreation=false)
Perform unqualified name lookup starting from a given scope.
ObjCMessageKind
Describes the kind of message expression indicated by a message send that starts with an identifier...
Stmt - This represents one statement.
NullabilityKind
Describes the nullability of a particular type.
static void diagnoseObjCARCConversion(Sema &S, SourceRange castRange, QualType castType, ARCConversionTypeClass castACTC, Expr *castExpr, Expr *realCast, ARCConversionTypeClass exprACTC, Sema::CheckedConversionKind CCK)
bool isObjCClassOrClassKindOfType() const
Whether the type is Objective-C 'Class' or a __kindof type of an Class type, e.g., __kindof Class <NSCopying>.
ARCConversionResult CheckObjCConversion(SourceRange castRange, QualType castType, Expr *&op, CheckedConversionKind CCK, bool Diagnose=true, bool DiagnoseCFAudited=false, BinaryOperatorKind Opc=BO_PtrMemD)
Checks for invalid conversions and casts between retainable pointers and other pointer kinds for ARC ...
Bridging via __bridge, which does nothing but reinterpret the bits.
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee...
ObjCMethodDecl * LookupMethodInObjectType(Selector Sel, QualType Ty, bool IsInstance)
LookupMethodInType - Look up a method in an ObjCObjectType.
bool hasPlaceholderType() const
Returns whether this expression has a placeholder type.
static bool CheckObjCBridgeNSCast(Sema &S, QualType castType, Expr *castExpr, bool &HadTheAttribute, bool warn)
void addConst()
Add the const type qualifier to this QualType.
bool isObjCARCBridgableType() const
Determine whether the given type T is a "bridgable" Objective-C type, which is either an Objective-C ...
bool isRecordType() const
static InitializedEntity InitializeParameter(ASTContext &Context, const ParmVarDecl *Parm)
Create the initialization entity for a parameter.
const ObjCObjectType * getAsObjCInterfaceType() const
SemaDiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID)
Emit a diagnostic.
Decl - This represents one declaration (or definition), e.g.
static bool HelperToDiagnoseMismatchedMethodsInGlobalPool(Sema &S, SourceLocation AtLoc, SourceLocation LParenLoc, SourceLocation RParenLoc, ObjCMethodDecl *Method, ObjCMethodList &MethList)
bool isExtVectorType() const
Scope * TUScope
Translation Unit Scope - useful to Objective-C actions that need to lookup file scope declarations in...
ParenExpr - This represents a parethesized expression, e.g.
QualType getNonReferenceType() const
If Type is a reference type (e.g., const int&), returns the type that the reference refers to ("const...
const char * getCharacterData(SourceLocation SL, bool *Invalid=nullptr) const
Return a pointer to the start of the specified location in the appropriate spelling MemoryBuffer...
The base class of the type hierarchy.
CanQual< T > getUnqualifiedType() const
Retrieve the unqualified form of this type.
static void RemoveSelectorFromWarningCache(Sema &S, Expr *Arg)
Represents an array type, per C99 6.7.5.2 - Array Declarators.
SourceLocation getLocForEndOfToken(SourceLocation Loc, unsigned Offset=0)
Calls Lexer::getLocForEndOfToken()
ExprResult ActOnObjCBridgedCast(Scope *S, SourceLocation LParenLoc, ObjCBridgeCastKind Kind, SourceLocation BridgeKeywordLoc, ParsedType Type, SourceLocation RParenLoc, Expr *SubExpr)
static FixItHint CreateInsertionFromRange(SourceLocation InsertionLoc, CharSourceRange FromRange, bool BeforePreviousInsertions=false)
Create a code modification hint that inserts the given code from FromRange at a specific location...
ObjCSubscriptRefExpr - used for array and dictionary subscripting.
const ObjCObjectPointerType * getAsObjCInterfacePointerType() const
static ExprValueKind getValueKindForType(QualType T)
getValueKindForType - Given a formal return or parameter type, give its value kind.
QualType withConst() const
A container of type source information.
bool isCARCBridgableType() const
Determine whether the given type T is a "bridgeable" C type.
SourceLocation getLocStart() const LLVM_READONLY
static StringLiteral * Create(const ASTContext &C, StringRef Str, StringKind Kind, bool Pascal, QualType Ty, const SourceLocation *Loc, unsigned NumStrs)
This is the "fully general" constructor that allows representation of strings formed from multiple co...
ObjCMethodDecl * getMethod() const
void setDelegateInitCall(bool isDelegate)
QualType getElementType() const
static InitializedEntity InitializeTemporary(QualType Type)
Create the initialization entity for a temporary.
Retains information about a function, method, or block that is currently being parsed.
An Objective-C array/dictionary subscripting which reads an object or writes at the subscripted array...
VarDecl - An instance of this class is created to represent a variable declaration or definition...
QualType getReturnType() const
DiagnosticsEngine & Diags
ObjCMethodDecl * tryCaptureObjCSelf(SourceLocation Loc)
Try to capture an implicit reference to 'self'.
const T * getAs() const
Member-template getAs<specific type>'.
bool isInObjcMethodScope() const
isInObjcMethodScope - Return true if this scope is, or is contained in, an Objective-C method body...
SourceLocation getLocStart() const LLVM_READONLY
ObjCMethodDecl - Represents an instance or class method declaration.
DeclClass * getCorrectionDeclAs() const
bool isInvalidDecl() const
static ObjCPropertyDecl * findPropertyDecl(const DeclContext *DC, const IdentifierInfo *propertyID, ObjCPropertyQueryKind queryKind)
Lookup a property by name in the specified DeclContext.
static const ObjCMethodDecl * findExplicitInstancetypeDeclarer(const ObjCMethodDecl *MD, QualType instancetype)
Look for an ObjC method whose result type exactly matches the given type.
llvm::MapVector< Selector, SourceLocation > ReferencedSelectors
Method selectors used in a @selector expression.
static StringRef bytes(const std::vector< T, Allocator > &v)
ParmVarDecl - Represents a parameter to a function.
ObjCPropertyDecl * getExplicitProperty() const
IdentifierInfo * getIdentifier() const
getIdentifier - Get the identifier that names this declaration, if there is one.
Expr * IgnoreImpCasts() LLVM_READONLY
IgnoreImpCasts - Skip past any implicit casts which might surround this expression.
RecordDecl - Represents a struct/union/class.
DeclarationName getDeclName() const
getDeclName - Get the actual, stored name of the declaration, which may be a special name...
Selector getUnarySelector(IdentifierInfo *ID)
One of these records is kept for each identifier that is lexed.
std::unique_ptr< NSAPI > NSAPIObj
Caches identifiers/selectors for NSFoundation APIs.
bool isObjCIdOrObjectKindOfType(const ASTContext &ctx, const ObjCObjectType *&bound) const
Whether the type is Objective-C 'id' or a __kindof type of an object type, e.g., __kindof NSView * or...
Name lookup results in an ambiguity; use getAmbiguityKind to figure out what kind of ambiguity we hav...
Expr * getFalseExpr() const
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.
Represents a class type in Objective C.
edit_iterator edit_end() const
ObjCMethodDecl * lookupInstanceMethod(Selector Sel) const
Lookup an instance method for a given selector.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
void setObjCConstantStringInterface(ObjCInterfaceDecl *Decl)
ObjCMethodFamily
A family of Objective-C methods.
Base class for callback objects used by Sema::CorrectTypo to check the validity of a potential typo c...
bool isExplicitProperty() const
bool isObjCIdType() const
void diagnoseARCUnbridgedCast(Expr *e)
Given that we saw an expression with the ARCUnbridgedCastTy placeholder type, complain bitterly...
static ObjCMessageExpr * Create(const ASTContext &Context, QualType T, ExprValueKind VK, SourceLocation LBracLoc, SourceLocation SuperLoc, bool IsInstanceSuper, QualType SuperType, Selector Sel, ArrayRef< SourceLocation > SelLocs, ObjCMethodDecl *Method, ArrayRef< Expr *> Args, SourceLocation RBracLoc, bool isImplicit)
Create a message send to super.
const DeclarationNameInfo & getLookupNameInfo() const
Gets the name info to look up.
const ObjCObjectPointerType * getAsObjCQualifiedIdType() const
bool CheckObjCBridgeRelatedConversions(SourceLocation Loc, QualType DestType, QualType SrcType, Expr *&SrcExpr, bool Diagnose=true)
ExprResult BuildClassMessageImplicit(QualType ReceiverType, bool isSuperReceiver, SourceLocation Loc, Selector Sel, ObjCMethodDecl *Method, MultiExprArg Args)
ExprResult ActOnObjCBoolLiteral(SourceLocation OpLoc, tok::TokenKind Kind)
ActOnObjCBoolLiteral - Parse {__objc_yes,__objc_no} literals.
LookupResultKind getResultKind() const
static ObjCBridgeRelatedAttr * ObjCBridgeRelatedAttrFromType(QualType T, TypedefNameDecl *&TDNDecl)
bool isObjCQualifiedClassType() const
void CheckObjCBridgeRelatedCast(QualType castType, Expr *castExpr)
No entity found met the criteria within the current instantiation,, but there were dependent base cla...
bool ObjCObjectAdoptsQTypeProtocols(QualType QT, ObjCInterfaceDecl *Decl)
ObjCObjectAdoptsQTypeProtocols - Checks that protocols in IC's protocol list adopt all protocols in Q...
An r-value expression (a pr-value in the C++11 taxonomy) produces a temporary value.
Values of this type can be null.
bool isUnarySelector() const
ObjCMethodFamily getMethodFamily() const
Determines the family of this method.
static Selector constructSetterSelector(IdentifierTable &Idents, SelectorTable &SelTable, const IdentifierInfo *Name)
Return the default setter selector for the given identifier.
bool followsCreateRule(const FunctionDecl *FD)
Selector getNullarySelector(IdentifierInfo *ID)
Represents the results of name lookup.
static ObjCInterfaceDecl * Create(const ASTContext &C, DeclContext *DC, SourceLocation atLoc, IdentifierInfo *Id, ObjCTypeParamList *typeParamList, ObjCInterfaceDecl *PrevDecl, SourceLocation ClassLoc=SourceLocation(), bool isInternal=false)
ObjCContainerDecl - Represents a container for method declarations.
ObjCMethodDecl * getCurMethodDecl()
getCurMethodDecl - If inside of a method body, this returns a pointer to the method decl for the meth...
ExprResult BuildObjCNumericLiteral(SourceLocation AtLoc, Expr *Number)
BuildObjCNumericLiteral - builds an ObjCBoxedExpr AST node for the numeric literal expression...
const ArrayType * getAsArrayTypeUnsafe() const
A variant of getAs<> for array types which silently discards qualifiers from the outermost type...
static void applyCocoaAPICheck(Sema &S, const ObjCMessageExpr *Msg, unsigned DiagID, bool(*refactor)(const ObjCMessageExpr *, const NSAPI &, edit::Commit &))
Whether values of this type can be null is (explicitly) unspecified.
QualType getObjCNSStringType() const
const ObjCObjectPointerType * getAsObjCQualifiedClassType() const
GlobalMethodPool MethodPool
Method Pool - allows efficient lookup when typechecking messages to "id".
TypeDecl - Represents a declaration of a type.
A builtin binary operation expression such as "x + y" or "x <= y".
CanQualType PseudoObjectTy
tokloc_iterator tokloc_end() const
CheckedConversionKind
The kind of conversion being performed.
Expr * IgnoreParenCasts() LLVM_READONLY
IgnoreParenCasts - Ignore parentheses and casts.
ObjCStringLiteral, used for Objective-C string literals i.e.
Values of this type can never be null.
ObjCProtocolDecl * getDefinition()
Retrieve the definition of this protocol, if any.
Scope - A scope is a transient data structure that is used while parsing the program.
const Type * getTypePtr() const
Retrieves a pointer to the underlying (unqualified) type.
void getOverriddenMethods(SmallVectorImpl< const ObjCMethodDecl *> &Overridden) const
Return overridden methods for the given Method.
ObjCMethodDecl * lookupClassMethod(Selector Sel) const
Lookup a class method for a given selector.
void CheckTollFreeBridgeCast(QualType castType, Expr *castExpr)
CastExpr - Base class for type casts, including both implicit casts (ImplicitCastExpr) and explicit c...
Represents an Objective-C protocol declaration.
const internal::VariadicDynCastAllOfMatcher< Stmt, CastExpr > castExpr
Matches any cast nodes of Clang's AST.
ObjCInterfaceDecl * NSNumberDecl
The declaration of the Objective-C NSNumber class.
const LangOptions & getLangOpts() const
ExprResult BuildObjCDictionaryLiteral(SourceRange SR, MutableArrayRef< ObjCDictionaryElement > Elements)
bool isTypeDependent() const
isTypeDependent - Determines whether this expression is type-dependent (C++ [temp.dep.expr]), which means that its type could change from one template instantiation to the next.
Represents an ObjC class declaration.
Bridging via __bridge_transfer, which transfers ownership of an Objective-C pointer into ARC...
QualType getReturnType() const
ObjCInterfaceDecl * getInterface() const
Gets the interface declaration for this object type, if the base type really is an interface...
QualType getObjCProtoType() const
Retrieve the type of the Objective-C Protocol class.
void setMethodParams(ASTContext &C, ArrayRef< ParmVarDecl *> Params, ArrayRef< SourceLocation > SelLocs=llvm::None)
Sets the method's parameters and selector source locations.
const LangOptions & LangOpts
bool isKnownName(StringRef name)
ObjCMethodDecl * getCategoryClassMethod(Selector Sel) const
static bool isAnyRetainable(ARCConversionTypeClass ACTC)
ConditionalOperator - The ?: ternary operator.
Sema - This implements semantic analysis and AST building for C.
RecordDecl * getMostRecentDecl()
StringRef getString() const
CharSourceRange getFileRange(SourceManager &SM) const
void EmitRelatedResultTypeNoteForReturn(QualType destType)
Given that we had incompatible pointer types in a return statement, check whether we're in a method w...
A little helper class used to produce diagnostics.
SourceLocation getLocStart() const LLVM_READONLY
const ObjCObjectType * getSuperClassType() const
Retrieve the superclass type.
ExprResult BuildObjCBridgedCast(SourceLocation LParenLoc, ObjCBridgeCastKind Kind, SourceLocation BridgeKeywordLoc, TypeSourceInfo *TSInfo, Expr *SubExpr)
CastKind
CastKind - The kind of operation required for a conversion.
static bool validateBoxingMethod(Sema &S, SourceLocation Loc, const ObjCInterfaceDecl *Class, Selector Sel, const ObjCMethodDecl *Method)
Emits an error if the given method does not exist, or if the return type is not an Objective-C object...
static ObjCInterfaceDecl * LookupObjCInterfaceDeclForLiteral(Sema &S, SourceLocation Loc, Sema::ObjCLiteralKind LiteralKind)
Looks up ObjCInterfaceDecl of a given NSClassIdKindKind.
static ImplicitCastExpr * Create(const ASTContext &Context, QualType T, CastKind Kind, Expr *Operand, const CXXCastPath *BasePath, ExprValueKind Cat)
SourceLocation getLocEnd() const LLVM_READONLY
bool CheckMessageArgumentTypes(QualType ReceiverType, MultiExprArg Args, Selector Sel, ArrayRef< SourceLocation > SelectorLocs, ObjCMethodDecl *Method, bool isClassMessage, bool isSuperMessage, SourceLocation lbrac, SourceLocation rbrac, SourceRange RecRange, QualType &ReturnType, ExprValueKind &VK)
CheckMessageArgumentTypes - Check types in an Obj-C message send.
TypeSourceInfo * getTrivialTypeSourceInfo(QualType T, SourceLocation Loc=SourceLocation()) const
Allocate a TypeSourceInfo where all locations have been initialized to a given location, which defaults to the empty location.
bool hasDefinition() const
Determine whether this protocol has a definition.
An Objective-C property is a logical field of an Objective-C object which is read and written via Obj...
ObjCStringFormatFamily getStringFormatFamily() const
Expr - This represents one expression.
ObjCMethodList * getNext() const
static ObjCMethodDecl * Create(ASTContext &C, SourceLocation beginLoc, SourceLocation endLoc, Selector SelInfo, QualType T, TypeSourceInfo *ReturnTInfo, DeclContext *contextDecl, bool isInstance=true, bool isVariadic=false, bool isPropertyAccessor=false, bool isImplicitlyDeclared=false, bool isDefined=false, ImplementationControl impControl=None, bool HasRelatedResultType=false)
ExprValueKind
The categorization of expression values, currently following the C++11 scheme.
Expr * stripARCUnbridgedCast(Expr *e)
stripARCUnbridgedCast - Given an expression of ARCUnbridgedCast type, remove the placeholder cast...
bool checkObjCBridgeRelatedComponents(SourceLocation Loc, QualType DestType, QualType SrcType, ObjCInterfaceDecl *&RelatedClass, ObjCMethodDecl *&ClassMethod, ObjCMethodDecl *&InstanceMethod, TypedefNameDecl *&TDNDecl, bool CfToNs, bool Diagnose=true)
bool isInSystemHeader(SourceLocation Loc) const
Returns if a SourceLocation is in a system header.
static Kind getNullabilityAttrKind(NullabilityKind kind)
Retrieve the attribute kind corresponding to the given nullability kind.
const FunctionProtoType * T
const T * castAs() const
Member-template castAs<specific type>.
static bool isAnyCLike(ARCConversionTypeClass ACTC)
bool isObjCRetainableType() const
static ARCConversionTypeClass classifyTypeForARCConversion(QualType type)
static QualType stripObjCInstanceType(ASTContext &Context, QualType T)
bool hasRelatedResultType() const
Determine whether this method has a result type that is related to the message receiver's type...
Defines the clang::Preprocessor interface.
bool isObjCClassType() const
DeclContext * getDeclContext()
edit_iterator edit_begin() const
ObjCInterfaceDecl * getSuperClass() const
ObjCSelectorExpr used for @selector in Objective-C.
ExprResult CheckPlaceholderExpr(Expr *E)
Check for operands with placeholder types and complain if found.
static ObjCDictionaryLiteral * Create(const ASTContext &C, ArrayRef< ObjCDictionaryElement > VK, bool HasPackExpansions, QualType T, ObjCMethodDecl *method, SourceRange SR)
QualType NSNumberPointer
Pointer to NSNumber type (NSNumber *).
Defines the clang::TypeLoc interface and its subclasses.
IdentifierInfo * getAsIdentifierInfo() const
getAsIdentifierInfo - Retrieve the IdentifierInfo * stored in this declaration name, or NULL if this declaration name isn't a simple identifier.
Specifies that a value-dependent expression of integral or dependent type should be considered a null...
static Optional< NullabilityKind > stripOuterNullability(QualType &T)
Strip off the top-level nullability annotation on the given type, if it's there.
DefinitionKind hasDefinition(ASTContext &) const
Check whether this variable is defined in this translation unit.
ObjCIvarDecl * lookupInstanceVariable(IdentifierInfo *IVarName, ObjCInterfaceDecl *&ClassDeclared)
bool isIdentifier() const
Predicate functions for querying what type of name this is.
ObjCMessageKind getObjCMessageKind(Scope *S, IdentifierInfo *Name, SourceLocation NameLoc, bool IsSuper, bool HasTrailingDot, ParsedType &ReceiverType)
QualType getConstantArrayType(QualType EltTy, const llvm::APInt &ArySize, ArrayType::ArraySizeModifier ASM, unsigned IndexTypeQuals) const
Return the unique reference to the type for a constant array of the specified element type...
An expression that sends a message to the given Objective-C object or class.
ObjCMethodDecl * getImplicitPropertyGetter() const
QualType getObjCInterfaceType(const ObjCInterfaceDecl *Decl, ObjCInterfaceDecl *PrevDecl=nullptr) const
getObjCInterfaceType - Return the unique reference to the type for the specified ObjC interface decl...
SourceLocation getEnd() const
UnaryOperator - This represents the unary-expression's (except sizeof and alignof), the postinc/postdec operators from postfix-expression, and various extensions.
bool isInstanceMethod() const
ArraySizeModifier getSizeModifier() const
bool rewriteObjCRedundantCallWithLiteral(const ObjCMessageExpr *Msg, const NSAPI &NS, Commit &commit)
unsigned getNumArgs() const
Selector getSelector() const
bool CheckTollFreeBridgeStaticCast(QualType castType, Expr *castExpr, CastKind &Kind)
QualType getTypeDeclType(const TypeDecl *Decl, const TypeDecl *PrevDecl=nullptr) const
Return the unique reference to the type for the specified type declaration.
NamedDecl * LookupSingleName(Scope *S, DeclarationName Name, SourceLocation Loc, LookupNameKind NameKind, RedeclarationKind Redecl=NotForRedeclaration)
Look up a name, looking for a single declaration.
CStyleCastExpr - An explicit cast in C (C99 6.5.4) or a C-style cast in C++ (C++ [expr.cast]), which uses the syntax (Type)expr.
bool isNull() const
Return true if this QualType doesn't point to a type yet.
ImplicitParamDecl * getSelfDecl() const
static InitializationKind CreateCopy(SourceLocation InitLoc, SourceLocation EqualLoc, bool AllowExplicitConvs=false)
Create a copy initialization.
bool isConstQualified() const
Determine whether this type is const-qualified.
ExprResult ParseObjCProtocolExpression(IdentifierInfo *ProtocolName, SourceLocation AtLoc, SourceLocation ProtoLoc, SourceLocation LParenLoc, SourceLocation ProtoIdLoc, SourceLocation RParenLoc)
ParseObjCProtocolExpression - Build protocol expression for @protocol.
SourceLocation getLocStart() const LLVM_READONLY
QualType getWideCharType() const
Return the type of wide characters.
There is no lifetime qualification on this type.
static bool isMethodDeclaredInRootProtocol(Sema &S, const ObjCMethodDecl *M)
std::string getAsString() const
Derive the full selector name (e.g.
SelectorTable & Selectors
bool QIdProtocolsAdoptObjCObjectProtocols(QualType QT, ObjCInterfaceDecl *IDecl)
QIdProtocolsAdoptObjCObjectProtocols - Checks that protocols in QT's qualified-id protocol list adopt...
ActionResult - This structure is used while parsing/acting on expressions, stmts, etc...
PseudoObjectExpr - An expression which accesses a pseudo-object l-value.
ObjCMethodFamily getMethodFamily() const
Derive the conventional family of this method.
NullPointerConstantKind isNullPointerConstant(ASTContext &Ctx, NullPointerConstantValueDependence NPC) const
isNullPointerConstant - C99 6.3.2.3p3 - Test if this reduces down to a Null pointer constant...
Encodes a location in the source.
ObjCInterfaceDecl * getDecl() const
Get the declaration of this interface.
Sugar for parentheses used when specifying types.
IdentifierInfo & get(StringRef Name)
Return the identifier token info for the specified named identifier.
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of enums...
Expr * getSubExpr() const
Represents typeof(type), a GCC extension.
Interfaces are the core concept in Objective-C for object oriented design.
CastKind getCastKind() const
std::string getNameAsString() const
getNameAsString - Get a human-readable name for the declaration, even if it is one of the special kin...
ObjCMethodFamily getMethodFamily() const
ExprResult ActOnClassMessage(Scope *S, ParsedType Receiver, Selector Sel, SourceLocation LBracLoc, ArrayRef< SourceLocation > SelectorLocs, SourceLocation RBracLoc, MultiExprArg Args)
bool makeUnavailableInSystemHeader(SourceLocation loc, UnavailableAttr::ImplicitReason reason)
makeUnavailableInSystemHeader - There is an error in the current context.
QualType getObjCSelType() const
Retrieve the type that corresponds to the predefined Objective-C 'SEL' type.
bool ObjCWarnForNoDesignatedInitChain
This starts true for a method marked as designated initializer and will be set to false if there is a...
SmallVectorImpl< Edit >::const_iterator edit_iterator
bool isIntegralType(const ASTContext &Ctx) const
Determine whether this type is an integral type.
const ConstantArrayType * getAsConstantArrayType(QualType T) const
StmtVisitor - This class implements a simple visitor for Stmt subclasses.
ExprResult BuildObjCArrayLiteral(SourceRange SR, MultiExprArg Elements)
ExprResult DefaultLvalueConversion(Expr *E)
bool CheckObjCARCUnavailableWeakConversion(QualType castType, QualType ExprType)
bool isLiteral(TokenKind K)
Return true if this is a "literal" kind, like a numeric constant, string, etc.
Name lookup found an unresolvable value declaration and cannot yet complete.
Specifies that a value-dependent expression should be considered to never be a null pointer constant...
ObjCProtocolExpr used for protocol expression in Objective-C.
Describes the kind of initialization being performed, along with location information for tokens rela...
ExprResult ActOnClassPropertyRefExpr(IdentifierInfo &receiverName, IdentifierInfo &propertyName, SourceLocation receiverNameLoc, SourceLocation propertyNameLoc)
bool isObjCObjectPointerType() const
static ExprResult CheckObjCCollectionLiteralElement(Sema &S, Expr *Element, QualType T, bool ArrayLiteral=false)
Check that the given expression is a valid element of an Objective-C collection literal.
bool FormatStringHasSArg(const StringLiteral *FExpr)
Represents one property declaration in an Objective-C interface.
ExprResult BuildClassMessage(TypeSourceInfo *ReceiverTypeInfo, QualType ReceiverType, SourceLocation SuperLoc, Selector Sel, ObjCMethodDecl *Method, SourceLocation LBracLoc, ArrayRef< SourceLocation > SelectorLocs, SourceLocation RBracLoc, MultiExprArg Args, bool isImplicit=false)
Build an Objective-C class message expression.
bool isSuperClassOf(const ObjCInterfaceDecl *I) const
isSuperClassOf - Return true if this class is the specified class or is a super class of the specifie...
No entity found met the criteria.
QualType getAttributedType(AttributedType::Kind attrKind, QualType modifiedType, QualType equivalentType)
bool ObjCIsDesignatedInit
True when this is a method marked as a designated initializer.
static QualType getBaseMessageSendResultType(Sema &S, QualType ReceiverType, ObjCMethodDecl *Method, bool isClassMessage, bool isSuperMessage)
Determine the result type of a message send based on the receiver type, method, and the kind of messa...
const ObjCMethodDecl * getMethodDecl() const
bool isVectorType() const
StmtExpr - This is the GNU Statement Expression extension: ({int X=4; X;}).
ObjCBoxedExpr - used for generalized expression boxing.
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
ExprResult ParseObjCSelectorExpression(Selector Sel, SourceLocation AtLoc, SourceLocation SelLoc, SourceLocation LParenLoc, SourceLocation RParenLoc, bool WarnMultipleSelectors)
ParseObjCSelectorExpression - Build selector expression for @selector.
MutableArrayRef< Expr * > MultiExprArg
bool hasSameUnqualifiedType(QualType T1, QualType T2) const
Determine whether the given types are equivalent after cvr-qualifiers have been removed.
static Expr * maybeUndoReclaimObject(Expr *e)
Look for an ObjCReclaimReturnedObject cast and destroy it.
bool isDesignatedInitializerForTheInterface(const ObjCMethodDecl **InitMethod=nullptr) const
Returns true if the method selector resolves to a designated initializer in the class's interface...
SourceLocation getExprLoc() const LLVM_READONLY
getExprLoc - Return the preferred location for the arrow when diagnosing a problem with a generic exp...
QualType getObjCInstanceType()
Retrieve the Objective-C "instancetype" type, if already known; otherwise, returns a NULL type;...
Represents a C11 generic selection.
StringRef getName() const
Return the actual identifier string.
An Objective-C "bridged" cast expression, which casts between Objective-C pointers and C pointers...
Base class for declarations which introduce a typedef-name.
Expr * getResultExpr()
Return the result-bearing expression, or null if there is none.
ExprResult PerformCopyInitialization(const InitializedEntity &Entity, SourceLocation EqualLoc, ExprResult Init, bool TopLevelOfInitList=false, bool AllowExplicit=false)
CanQualType ObjCBuiltinIdTy
static ParmVarDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, IdentifierInfo *Id, QualType T, TypeSourceInfo *TInfo, StorageClass S, Expr *DefArg)
Dataflow Directional Tag Classes.
bool isValid() const
Return true if this is a valid SourceLocation object.
tokloc_iterator tokloc_begin() const
ObjCMethodDecl * lookupPrivateMethod(const Selector &Sel, bool Instance=true) const
Lookup a method in the classes implementation hierarchy.
ExprResult BuildObjCStringLiteral(SourceLocation AtLoc, StringLiteral *S)
ObjCPropertyDecl * FindPropertyDeclaration(const IdentifierInfo *PropertyId, ObjCPropertyQueryKind QueryKind) const
FindPropertyDeclaration - Finds declaration of the property given its name in 'PropertyId' and return...
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
ObjCMethodDecl * NSNumberLiteralMethods[NSAPI::NumNSNumberLiteralMethods]
The Objective-C NSNumber methods used to create NSNumber literals.
static bool GetFormatNSStringIdx(const FormatAttr *Format, unsigned &Idx)
FunctionDecl * getDirectCallee()
If the callee is a FunctionDecl, return it. Otherwise return 0.
bool isCommitable() const
static void addFixitForObjCARCConversion(Sema &S, DiagnosticBuilder &DiagB, Sema::CheckedConversionKind CCK, SourceLocation afterLParen, QualType castType, Expr *castExpr, Expr *realCast, const char *bridgeKeyword, const char *CFBridgeName)
CharSourceRange getInsertFromRange(SourceManager &SM) const
bool ObjCIsSecondaryInit
True when this is an initializer method not marked as a designated initializer within a class that ha...
QualType getUnderlyingType() const
static FixItHint CreateRemoval(CharSourceRange RemoveRange)
Create a code modification hint that removes the given source range.
DeclarationName - The name of a declaration.
NamedDecl * getFoundDecl() const
Fetch the unique decl found by this lookup.
static std::string getAsString(SplitQualType split, const PrintingPolicy &Policy)
U cast(CodeGen::Address addr)
bool ObjCWarnForNoInitDelegation
This starts true for a secondary initializer method and will be set to false if there is an invocatio...
ExplicitCastExpr - An explicit cast written in the source code.
DeclarationNameInfo - A collector data type for bundling together a DeclarationName and the correspnd...
Bridging via __bridge_retain, which makes an ARC object available as a +1 C pointer.
ACCResult
A result from the cast checker.
Expr * IgnoreParenImpCasts() LLVM_READONLY
IgnoreParenImpCasts - Ignore parentheses and implicit casts.
ExprResult BuildInstanceMessage(Expr *Receiver, QualType ReceiverType, SourceLocation SuperLoc, Selector Sel, ObjCMethodDecl *Method, SourceLocation LBracLoc, ArrayRef< SourceLocation > SelectorLocs, SourceLocation RBracLoc, MultiExprArg Args, bool isImplicit=false)
Build an Objective-C instance message expression.
Represents a pointer to an Objective C object.
SourceRange getSourceRange() const LLVM_READONLY
Get the full source range.
Name lookup found a single declaration that met the criteria.
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of structs/unions/cl...
ExprResult BuildObjCEncodeExpression(SourceLocation AtLoc, TypeSourceInfo *EncodedTypeInfo, SourceLocation RParenLoc)
static void DiagnoseCStringFormatDirectiveInObjCAPI(Sema &S, ObjCMethodDecl *Method, Selector Sel, Expr **Args, unsigned NumArgs)
Diagnose use of s directive in an NSString which is being passed as formatting string to formatting m...
unsigned getIndexTypeCVRQualifiers() const
ObjCInterfaceDecl * getInterfaceDecl() const
If this pointer points to an Objective @interface type, gets the declaration for that interface...
bool isIntegerType() const
isIntegerType() does not include complex integers (a GCC extension).
CanQualType UnsignedLongTy
ObjCEncodeExpr, used for @encode in Objective-C.
Selector getSelector(unsigned NumArgs, IdentifierInfo **IIV)
Can create any sort of selector.
ExprResult BuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr)
BuildObjCBoxedExpr - builds an ObjCBoxedExpr AST node for the '@' prefixed parenthesized expression...
void getObjCEncodingForType(QualType T, std::string &S, const FieldDecl *Field=nullptr, QualType *NotEncodedT=nullptr) const
Emit the Objective-CC type encoding for the given type T into S.
ExprResult HandleExprPropertyRefExpr(const ObjCObjectPointerType *OPT, Expr *BaseExpr, SourceLocation OpLoc, DeclarationName MemberName, SourceLocation MemberLoc, SourceLocation SuperLoc, QualType SuperType, bool Super)
HandleExprPropertyRefExpr - Handle foo.bar where foo is a pointer to an objective C interface...
Expr * IgnoreParenLValueCasts() LLVM_READONLY
Ignore parentheses and lvalue casts.
Base for LValueReferenceType and RValueReferenceType.
ExprResult ParseObjCEncodeExpression(SourceLocation AtLoc, SourceLocation EncodeLoc, SourceLocation LParenLoc, ParsedType Ty, SourceLocation RParenLoc)
Optional< ArrayRef< QualType > > getObjCSubstitutions(const DeclContext *dc) const
Retrieve the set of substitutions required when accessing a member of the Objective-C receiver type t...
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.
Sema::LookupNameKind getLookupKind() const
Gets the kind of lookup to perform.
ObjCMethodDecl * lookupMethod(Selector Sel, bool isInstance, bool shallowCategoryLookup=false, bool followSuper=true, const ObjCCategoryDecl *C=nullptr) const
lookupMethod - This method returns an instance/class method by looking in the class, its categories, and its super classes (using a linear search).
Optional< NullabilityKind > getNullability(const ASTContext &context) const
Determine the nullability of the given type.
QualType getObjCConstantStringInterface() const
SourceManager & getSourceManager()
static bool isIdentifierBodyChar(char c, const LangOptions &LangOpts)
Returns true if the given character could appear in an identifier.
ImplementationControl getImplementationControl() const
static NSAPI::NSClassIdKindKind ClassKindFromLiteralKind(Sema::ObjCLiteralKind LiteralKind)
Maps ObjCLiteralKind to NSClassIdKindKind.
CanQualType getCanonicalType(QualType T) const
Return the canonical (structural) type corresponding to the specified potentially non-canonical type ...
llvm::iterator_range< specific_attr_iterator< T > > specific_attrs() const
TypeLoc getTypeLoc() const
Return the TypeLoc wrapper for the type source info.
TypedefNameDecl * getDecl() const
Reading or writing from this object requires a barrier call.
No particular method family.
void setObjCNSStringType(QualType T)
An attributed type is a type to which a type attribute has been applied.
const ObjCPropertyDecl * findPropertyDecl(bool CheckOverrides=true) const
Returns the property associated with this method's selector.
TranslationUnitDecl * getTranslationUnitDecl() const
Describes the sequence of initializations required to initialize a given object or reference with a s...
ExprResult ActOnInstanceMessage(Scope *S, Expr *Receiver, Selector Sel, SourceLocation LBracLoc, ArrayRef< SourceLocation > SelectorLocs, SourceLocation RBracLoc, MultiExprArg Args)
Expr * getTrueExpr() const
unsigned getBuiltinID() const
Returns a value indicating whether this function corresponds to a builtin function.
bool MatchTwoMethodDeclarations(const ObjCMethodDecl *Method, const ObjCMethodDecl *PrevMethod, MethodMatchStrategy strategy=MMS_strict)
MatchTwoMethodDeclarations - Checks if two methods' type match and returns true, or false...
The parameter type of a method or function.
ObjCIvarDecl - Represents an ObjC instance variable.
static bool CheckObjCBridgeCFCast(Sema &S, QualType castType, Expr *castExpr, bool &HadTheAttribute, bool warn)
QualType getSendResultType() const
Determine the type of an expression that sends a message to this function.
QualType getPointerType(QualType T) const
Return the uniqued reference to the type for a pointer to the specified type.
static FixItHint CreateReplacement(CharSourceRange RemoveRange, StringRef Code)
Create a code modification hint that replaces the given source range with the given code string...
static T * getObjCBridgeAttr(const TypedefType *TD)
SourceManager & getSourceManager() const
SourceRange getSourceRange() const LLVM_READONLY
SourceLocation tokens are not useful in isolation - they are low level value objects created/interpre...
ExprResult BuildInstanceMessageImplicit(Expr *Receiver, QualType ReceiverType, SourceLocation Loc, Selector Sel, ObjCMethodDecl *Method, MultiExprArg Args)
StringLiteral - This represents a string literal expression, e.g.
CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
a linked list of methods with the same selector name but different signatures.
StringRef getName() const
getName - Get the name of identifier for this declaration as a StringRef.
QualType getMessageSendResultType(QualType ReceiverType, ObjCMethodDecl *Method, bool isClassMessage, bool isSuperMessage)
Determine the result of a message send expression based on the type of the receiver, the method expected to receive the message, and the form of the message send.
void EmitRelatedResultTypeNote(const Expr *E)
If the given expression involves a message send to a method with a related result type...
Abstract class common to all of the C++ "named"/"keyword" casts.
TranslationUnitDecl - The top declaration context.
bool isDependentType() const
Whether this type is a dependent type, meaning that its definition somehow depends on a template para...
static bool ValidateObjCLiteralInterfaceDecl(Sema &S, ObjCInterfaceDecl *Decl, SourceLocation Loc, Sema::ObjCLiteralKind LiteralKind)
Validates ObjCInterfaceDecl availability.
A reference to a declared variable, function, enum, etc.
bool isIgnored(unsigned DiagID, SourceLocation Loc) const
Determine whether the diagnostic is known to be ignored.
bool isPointerType() const
SourceManager & SourceMgr
void suppressDiagnostics()
Suppress the diagnostics that would normally fire because of this lookup.
An l-value expression is a reference to an object with independent storage.
A trivial tuple used to represent a source range.
ObjCMethodDecl * getMethod(Selector Sel, bool isInstance, bool AllowHidden=false) const
ObjCMethodDecl * getGetterMethodDecl() const
static void DiagnoseMismatchedSelectors(Sema &S, SourceLocation AtLoc, ObjCMethodDecl *Method, SourceLocation LParenLoc, SourceLocation RParenLoc, bool WarnMultipleSelectors)
NamedDecl - This represents a decl with a name.
QualType getObjCObjectPointerType(QualType OIT) const
Return a ObjCObjectPointerType type for the given ObjCObjectType.
ExprResult BuildObjCSubscriptExpression(SourceLocation RB, Expr *BaseExpr, Expr *IndexExpr, ObjCMethodDecl *getterMethod, ObjCMethodDecl *setterMethod)
Build an ObjC subscript pseudo-object expression, given that that's supported by the runtime...
static ObjCMethodDecl * getNSNumberFactoryMethod(Sema &S, SourceLocation Loc, QualType NumberType, bool isLiteral=false, SourceRange R=SourceRange())
Retrieve the NSNumber factory method that should be used to create an Objective-C literal for the giv...
bool isPropertyAccessor() const
static bool isObjCNSObjectType(QualType Ty)
Return true if this is an NSObject object with its NSObject attribute set.
Describes an entity that is being initialized.
SourceLocation getLocStart() const LLVM_READONLY
void setType(QualType newType)
SourceLocation getBegin() const
ObjCCategoryImplDecl - An object of this class encapsulates a category @implementation declaration...
This class handles loading and caching of source files into memory.
Represents the canonical version of C arrays with a specified constant size.
static void checkCocoaAPI(Sema &S, const ObjCMessageExpr *Msg)
SourceLocation getLocation() const
QualType getType() const
Return the type wrapped by this type source info.
ArrayRef< ParmVarDecl * > parameters() const
Expr * IgnoreParens() LLVM_READONLY
IgnoreParens - Ignore parentheses.
Qualifiers::ObjCLifetime getObjCLifetime() const
Returns lifetime attribute of this type.
ExprResult ParseObjCStringLiteral(SourceLocation *AtLocs, ArrayRef< Expr *> Strings)
QualType getPointeeType() const
Gets the type pointed to by this ObjC pointer.