summaryrefslogtreecommitdiffstats
path: root/clang/lib/Sema
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2011-09-27 16:10:05 +0000
committerDouglas Gregor <dgregor@apple.com>2011-09-27 16:10:05 +0000
commit486b74e596f19ea4340a21371a78c088554edce8 (patch)
tree1f1e0a4703f94911e0e684af067673636276d2ac /clang/lib/Sema
parent3c9029b06c1cca785495d2fa58cfc5eb2e1c2e24 (diff)
downloadbcm5719-llvm-486b74e596f19ea4340a21371a78c088554edce8.tar.gz
bcm5719-llvm-486b74e596f19ea4340a21371a78c088554edce8.zip
Revert r139989 and r140031, which implemented the Objective-C type
system change in <rdar://problem/10109725> that allows conversion from 'self' in class methods to the root of the class's hierarchy. This conversion rule is a hack that has non-trivial repurcussions (particularly with overload resolution). llvm-svn: 140605
Diffstat (limited to 'clang/lib/Sema')
-rw-r--r--clang/lib/Sema/SemaExpr.cpp26
-rw-r--r--clang/lib/Sema/SemaExprObjC.cpp16
2 files changed, 9 insertions, 33 deletions
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 3397680ee11..2a9abd4b384 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -5107,25 +5107,6 @@ ExprResult Sema::ActOnConditionalOp(SourceLocation QuestionLoc,
OK));
}
-/// ConvertObjCSelfToClassRootType - convet type of 'self' in class method
-/// to pointer to root of method's class.
-static QualType
-ConvertObjCSelfToClassRootType(Sema &S, Expr *selfExpr) {
- QualType SelfType;
- if (const ObjCMethodDecl *MD = S.GetMethodIfSelfExpr(selfExpr))
- if (MD->isClassMethod()) {
- const ObjCInterfaceDecl *Root = 0;
- if (const ObjCInterfaceDecl * IDecl = MD->getClassInterface())
- do {
- Root = IDecl;
- } while ((IDecl = IDecl->getSuperClass()));
- if (Root)
- SelfType = S.Context.getObjCObjectPointerType(
- S.Context.getObjCInterfaceType(Root));
- }
- return SelfType;
-}
-
// 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.
@@ -5453,7 +5434,7 @@ Sema::CheckAssignmentConstraints(QualType LHSType, ExprResult &RHS,
Kind = CK_BitCast;
return Compatible;
}
-
+
Kind = CK_BitCast;
return IncompatiblePointer;
}
@@ -5501,9 +5482,6 @@ Sema::CheckAssignmentConstraints(QualType LHSType, ExprResult &RHS,
// Conversions to Objective-C pointers.
if (isa<ObjCObjectPointerType>(LHSType)) {
- QualType RHSQT = ConvertObjCSelfToClassRootType(*this, RHS.get());
- if (!RHSQT.isNull())
- RHSType = RHSQT;
// A* -> B*
if (RHSType->isObjCObjectPointerType()) {
Kind = CK_BitCast;
@@ -9619,7 +9597,7 @@ void Sema::DiagnoseAssignmentAsCondition(Expr *E) {
Selector Sel = ME->getSelector();
// self = [<foo> init...]
- if (GetMethodIfSelfExpr(Op->getLHS()) && Sel.getNameForSlot(0).startswith("init"))
+ if (isSelfExpr(Op->getLHS()) && Sel.getNameForSlot(0).startswith("init"))
diagnostic = diag::warn_condition_is_idiomatic_assignment;
// <foo> = [<bar> nextObject]
diff --git a/clang/lib/Sema/SemaExprObjC.cpp b/clang/lib/Sema/SemaExprObjC.cpp
index 5858596205e..51b5e4fb63b 100644
--- a/clang/lib/Sema/SemaExprObjC.cpp
+++ b/clang/lib/Sema/SemaExprObjC.cpp
@@ -457,20 +457,18 @@ bool Sema::CheckMessageArgumentTypes(QualType ReceiverType,
return IsError;
}
-/// GetMethodIfSelfExpr - Check if receiver is an objc 'self' expression
-/// and return its method declaration if so; else return 0.
-const ObjCMethodDecl *Sema::GetMethodIfSelfExpr(Expr *receiver) {
+bool Sema::isSelfExpr(Expr *receiver) {
// 'self' is objc 'self' in an objc method only.
DeclContext *DC = CurContext;
while (isa<BlockDecl>(DC))
DC = DC->getParent();
if (DC && !isa<ObjCMethodDecl>(DC))
- return 0;
+ return false;
receiver = receiver->IgnoreParenLValueCasts();
if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(receiver))
if (DRE->getDecl()->getIdentifier() == &Context.Idents.get("self"))
- return static_cast<ObjCMethodDecl*>(DC);
- return 0;
+ return true;
+ return false;
}
// Helper method for ActOnClassMethod/ActOnInstanceMethod.
@@ -1274,7 +1272,7 @@ ExprResult Sema::BuildInstanceMessage(Expr *Receiver,
}
if (!Method) {
// If not messaging 'self', look for any factory method named 'Sel'.
- if (!Receiver || !GetMethodIfSelfExpr(Receiver)) {
+ if (!Receiver || !isSelfExpr(Receiver)) {
Method = LookupFactoryMethodInGlobalPool(Sel,
SourceRange(LBracLoc, RBracLoc),
true);
@@ -1338,7 +1336,7 @@ ExprResult Sema::BuildInstanceMessage(Expr *Receiver,
return ExprError();
}
- if (!Method && (!Receiver || !GetMethodIfSelfExpr(Receiver))) {
+ if (!Method && (!Receiver || !isSelfExpr(Receiver))) {
// If we still haven't found a method, look in the global pool. This
// behavior isn't very desirable, however we need it for GCC
// compatibility. FIXME: should we deviate??
@@ -1509,7 +1507,7 @@ ExprResult Sema::BuildInstanceMessage(Expr *Receiver,
if (getLangOptions().ObjCAutoRefCount) {
// In ARC, annotate delegate init calls.
if (Result->getMethodFamily() == OMF_init &&
- (SuperLoc.isValid() || GetMethodIfSelfExpr(Receiver))) {
+ (SuperLoc.isValid() || isSelfExpr(Receiver))) {
// Only consider init calls *directly* in init implementations,
// not within blocks.
ObjCMethodDecl *method = dyn_cast<ObjCMethodDecl>(CurContext);
OpenPOWER on IntegriCloud