if (FD || EncodingProperty) {
// Note that we do extended encoding of protocol qualifer list
// Only when doing ivar or property encoding.
- const ObjCObjectPointerType *QIDT = T->getAsObjCQualifiedIdType();
S += '"';
- for (ObjCObjectPointerType::qual_iterator I = QIDT->qual_begin(),
- E = QIDT->qual_end(); I != E; ++I) {
+ for (ObjCObjectPointerType::qual_iterator I = OPT->qual_begin(),
+ E = OPT->qual_end(); I != E; ++I) {
S += '<';
S += (*I)->getNameAsString();
S += '>';
S += '@';
if (FD || EncodingProperty) {
- const ObjCInterfaceType *OIT = OPT->getInterfaceType();
- ObjCInterfaceDecl *OI = OIT->getDecl();
S += '"';
- S += OI->getNameAsCString();
- for (ObjCInterfaceType::qual_iterator I = OIT->qual_begin(),
- E = OIT->qual_end(); I != E; ++I) {
+ S += OPT->getInterfaceDecl()->getNameAsCString();
+ for (ObjCObjectPointerType::qual_iterator I = OPT->qual_begin(),
+ E = OPT->qual_end(); I != E; ++I) {
S += '<';
S += (*I)->getNameAsString();
S += '>';
// Helper function for CheckAssignmentConstraints (C99 6.5.16.1p1)
AssignConvertType CheckPointerTypesForAssignment(QualType lhsType,
QualType rhsType);
- AssignConvertType CheckPointeeTypesForAssignment(QualType lhsType,
- QualType rhsType);
// Helper function for CheckAssignmentConstraints involving two
// block pointer types.
MemberLoc, BaseExpr));
}
// Check protocols on qualified interfaces.
- for (ObjCObjectPointerType::qual_iterator I = IFaceT->qual_begin(),
- E = IFaceT->qual_end(); I != E; ++I)
+ for (ObjCObjectPointerType::qual_iterator I = OPT->qual_begin(),
+ E = OPT->qual_end(); I != E; ++I)
if (ObjCPropertyDecl *PD = (*I)->FindPropertyDeclaration(&Member)) {
// Check whether we can reference this property.
if (DiagnoseUseOfDecl(PD, MemberLoc))
RHSExpr, result));
}
-
// CheckPointerTypesForAssignment - This is a very tricky routine (despite
// being closely modeled after the C99 spec:-). The odd characteristic of this
// routine is it effectively iqnores the qualifiers on the top level pointee.
lhptee = lhsType->getAsPointerType()->getPointeeType();
rhptee = rhsType->getAsPointerType()->getPointeeType();
- return CheckPointeeTypesForAssignment(lhptee, rhptee);
-}
-
-Sema::AssignConvertType
-Sema::CheckPointeeTypesForAssignment(QualType lhptee, QualType rhptee) {
// make sure we operate on the canonical type
lhptee = Context.getCanonicalType(lhptee);
rhptee = Context.getCanonicalType(rhptee);
if (isa<PointerType>(rhsType))
return CheckPointerTypesForAssignment(lhsType, rhsType);
+ // In general, C pointers are not compatible with ObjC object pointers.
if (isa<ObjCObjectPointerType>(rhsType)) {
- QualType rhptee = rhsType->getAsObjCObjectPointerType()->getPointeeType();
- QualType lhptee = lhsType->getAsPointerType()->getPointeeType();
- return CheckPointeeTypesForAssignment(lhptee, rhptee);
+ if (lhsType->isVoidPointerType()) // an exception to the rule.
+ return Compatible;
+ return IncompatiblePointer;
}
-
if (rhsType->getAsBlockPointerType()) {
if (lhsType->getAsPointerType()->getPointeeType()->isVoidType())
return Compatible;
if (isa<ObjCObjectPointerType>(lhsType)) {
if (rhsType->isIntegerType())
return IntToPointer;
-
+
+ // In general, C pointers are not compatible with ObjC object pointers.
if (isa<PointerType>(rhsType)) {
- QualType lhptee = lhsType->getAsObjCObjectPointerType()->getPointeeType();
- QualType rhptee = rhsType->getAsPointerType()->getPointeeType();
- return CheckPointeeTypesForAssignment(lhptee, rhptee);
+ if (rhsType->isVoidPointerType()) // an exception to the rule.
+ return Compatible;
+ return IncompatiblePointer;
}
if (rhsType->isObjCObjectPointerType()) {
if (lhsType->isObjCBuiltinType() || rhsType->isObjCBuiltinType())
return Compatible;
- QualType lhptee = lhsType->getAsObjCObjectPointerType()->getPointeeType();
- QualType rhptee = rhsType->getAsObjCObjectPointerType()->getPointeeType();
- return CheckPointeeTypesForAssignment(lhptee, rhptee);
+ if (Context.typesAreCompatible(lhsType, rhsType))
+ return Compatible;
+ return IncompatiblePointer;
}
if (const PointerType *RHSPT = rhsType->getAsPointerType()) {
if (RHSPT->getPointeeType()->isVoidType())
if (lhsType->isIntegerType())
return PointerToInt;
+ // In general, C pointers are not compatible with ObjC object pointers.
if (isa<PointerType>(lhsType)) {
- QualType rhptee = lhsType->getAsObjCObjectPointerType()->getPointeeType();
- QualType lhptee = rhsType->getAsPointerType()->getPointeeType();
- return CheckPointeeTypesForAssignment(lhptee, rhptee);
+ if (lhsType->isVoidPointerType()) // an exception to the rule.
+ return Compatible;
+ return IncompatiblePointer;
}
if (isa<BlockPointerType>(lhsType) &&
rhsType->getAsPointerType()->getPointeeType()->isVoidType())
}
return true;
}
- // FIXME: The code below will be removed when ObjCQualifiedInterfaceType is
- // removed.
- if (!lhs->isPointerType())
- return false;
-
- QualType ltype = lhs->getAsPointerType()->getPointeeType();
- if (const ObjCInterfaceType *lhsQI =
- ltype->getAsObjCQualifiedInterfaceType()) {
- ObjCObjectPointerType::qual_iterator LHSProtoI = lhsQI->qual_begin();
- ObjCObjectPointerType::qual_iterator LHSProtoE = lhsQI->qual_end();
- for (; LHSProtoI != LHSProtoE; ++LHSProtoI) {
- bool match = false;
- ObjCProtocolDecl *lhsProto = *LHSProtoI;
- for (ObjCObjectPointerType::qual_iterator I = rhsQID->qual_begin(),
- E = rhsQID->qual_end(); I != E; ++I) {
- ObjCProtocolDecl *rhsProto = *I;
- if (ProtocolCompatibleWithProtocol(lhsProto, rhsProto) ||
- (compare && ProtocolCompatibleWithProtocol(rhsProto, lhsProto))) {
- match = true;
- break;
- }
- }
- if (!match)
- return false;
- }
- return true;
- }
-
return false;
}
Result = QualType::getFromOpaquePtr(DS.getTypeRep());
if (DeclSpec::ProtocolQualifierListTy PQ = DS.getProtocolQualifiers()) {
- // FIXME: Adding a TST_objcInterface clause doesn't seem ideal, so we have
- // this "hack" for now...
if (const ObjCInterfaceType *Interface = Result->getAsObjCInterfaceType())
- // FIXME: Investigate removing the protocol list in ObjCInterfaceType.
- // To simply this, Sema::GetTypeForDeclarator() uses the declspec
- // protocol list, not the list we are storing here.
+ // It would be nice if protocol qualifiers were only stored with the
+ // ObjCObjectPointerType. Unfortunately, this isn't possible due
+ // to the following typedef idiom (which is uncommon, but allowed):
+ //
+ // typedef Foo<P> T;
+ // static void func() {
+ // Foo<P> *yy;
+ // T *zz;
+ // }
Result = Context.getObjCInterfaceType(Interface->getDecl(),
(ObjCProtocolDecl**)PQ,
DS.getNumProtocolQualifiers());
// Build the type anyway.
}
if (getLangOptions().ObjC1 && T->isObjCInterfaceType()) {
- const DeclSpec &DS = D.getDeclSpec();
+ const ObjCInterfaceType *OIT = T->getAsObjCInterfaceType();
T = Context.getObjCObjectPointerType(T,
- (ObjCProtocolDecl **)DS.getProtocolQualifiers(),
- DS.getNumProtocolQualifiers());
+ (ObjCProtocolDecl **)OIT->qual_begin(),
+ OIT->getNumProtocols());
break;
}
T = BuildPointerType(T, DeclType.Ptr.TypeQuals, DeclType.Loc, Name);