[cfe-commits] r76443 - in /cfe/trunk/lib: AST/ASTContext.cpp Sema/Sema.h Sema/SemaExpr.cpp Sema/SemaExprObjC.cpp Sema/SemaType.cpp
Steve Naroff
snaroff at apple.com
Mon Jul 20 10:56:54 PDT 2009
Author: snaroff
Date: Mon Jul 20 12:56:53 2009
New Revision: 76443
URL: http://llvm.org/viewvc/llvm-project?rev=76443&view=rev
Log:
5 cleanups to ObjCObjectPointerType work:
- Remove Sema::CheckPointeeTypesForAssignment(), a temporary API I added to ease migration to ObjCObjectPointerType. Convert Sema::CheckAssignmentConstraints() to no longer depend on the temporary API.
- Sema::ConvertDeclSpecToType(): Replace a couple FIXME's with an important comment/example.
- Sema::GetTypeForDeclarator(): Get the protocol's from the interface, NOT the declspec (to support the following C typedef idiom: "typedef C<P> T; T *obj").
- Sema::ObjCQualifiedIdTypesAreCompatible(): Removed some dead code.
- ASTContext::getObjCEncodingForTypeImpl(): Some minor cleanups.
Modified:
cfe/trunk/lib/AST/ASTContext.cpp
cfe/trunk/lib/Sema/Sema.h
cfe/trunk/lib/Sema/SemaExpr.cpp
cfe/trunk/lib/Sema/SemaExprObjC.cpp
cfe/trunk/lib/Sema/SemaType.cpp
Modified: cfe/trunk/lib/AST/ASTContext.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTContext.cpp?rev=76443&r1=76442&r2=76443&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ASTContext.cpp (original)
+++ cfe/trunk/lib/AST/ASTContext.cpp Mon Jul 20 12:56:53 2009
@@ -2758,10 +2758,9 @@
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 += '>';
@@ -2786,12 +2785,10 @@
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 += '>';
Modified: cfe/trunk/lib/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/Sema.h?rev=76443&r1=76442&r2=76443&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/Sema.h (original)
+++ cfe/trunk/lib/Sema/Sema.h Mon Jul 20 12:56:53 2009
@@ -3033,8 +3033,6 @@
// 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.
Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=76443&r1=76442&r2=76443&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Mon Jul 20 12:56:53 2009
@@ -2398,8 +2398,8 @@
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))
@@ -3303,7 +3303,6 @@
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.
@@ -3317,11 +3316,6 @@
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);
@@ -3495,12 +3489,12 @@
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;
@@ -3533,18 +3527,19 @@
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())
@@ -3579,10 +3574,11 @@
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())
Modified: cfe/trunk/lib/Sema/SemaExprObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprObjC.cpp?rev=76443&r1=76442&r2=76443&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExprObjC.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprObjC.cpp Mon Jul 20 12:56:53 2009
@@ -854,34 +854,6 @@
}
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;
}
Modified: cfe/trunk/lib/Sema/SemaType.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=76443&r1=76442&r2=76443&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaType.cpp (original)
+++ cfe/trunk/lib/Sema/SemaType.cpp Mon Jul 20 12:56:53 2009
@@ -205,12 +205,16 @@
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());
@@ -901,10 +905,10 @@
// 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);
More information about the cfe-commits
mailing list