From: Chris Lattner Date: Mon, 21 Jul 2008 04:36:39 +0000 (+0000) Subject: simplify a bunch of code, no functionality change. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=68a057b4292f5ff814ec8da53f6cda8cdcfbd2ae;p=clang simplify a bunch of code, no functionality change. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@53823 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/AST/DeclObjC.h b/include/clang/AST/DeclObjC.h index 641ebb4035..89499f65a7 100644 --- a/include/clang/AST/DeclObjC.h +++ b/include/clang/AST/DeclObjC.h @@ -383,8 +383,13 @@ public: return false; } - ObjCIvarDecl *lookupInstanceVariable(IdentifierInfo *ivarName, - ObjCInterfaceDecl *&clsDeclared); + ObjCIvarDecl *lookupInstanceVariable(IdentifierInfo *IVarName, + ObjCInterfaceDecl *&ClassDeclared); + ObjCIvarDecl *lookupInstanceVariable(IdentifierInfo *IVarName) { + ObjCInterfaceDecl *ClassDeclared; + return lookupInstanceVariable(IVarName, ClassDeclared); + } + // Get the local instance method declared in this interface. ObjCMethodDecl *getInstanceMethod(Selector Sel) { diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp index c31c610c51..7babcf9d4f 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/lib/Sema/SemaExpr.cpp @@ -583,6 +583,8 @@ ActOnMemberReferenceExpr(ExprTy *Base, SourceLocation OpLoc, QualType BaseType = BaseExpr->getType(); assert(!BaseType.isNull() && "no type for member expression"); + // Get the type being accessed in BaseType. If this is an arrow, the BaseExpr + // must have pointer type, and the accessed type is the pointee. if (OpKind == tok::arrow) { if (const PointerType *PT = BaseType->getAsPointerType()) BaseType = PT->getPointeeType(); @@ -591,7 +593,8 @@ ActOnMemberReferenceExpr(ExprTy *Base, SourceLocation OpLoc, SourceRange(MemberLoc)); } - // Handle field access to simple records. + // Handle field access to simple records. This also handles access to fields + // of the ObjC 'id' struct. if (const RecordType *RTy = BaseType->getAsRecordType()) { RecordDecl *RDecl = RTy->getDecl(); if (RTy->isIncompleteType()) @@ -610,26 +613,20 @@ ActOnMemberReferenceExpr(ExprTy *Base, SourceLocation OpLoc, MemberType.getCVRQualifiers() | BaseType.getCVRQualifiers(); MemberType = MemberType.getQualifiedType(combinedQualifiers); - return new MemberExpr(BaseExpr, OpKind==tok::arrow, MemberDecl, + return new MemberExpr(BaseExpr, OpKind == tok::arrow, MemberDecl, MemberLoc, MemberType); } // Handle access to Objective C instance variables, such as "Obj->ivar". - if (BaseType->isObjCInterfaceType()) { - ObjCInterfaceDecl *IFace; - QualType CanonType = BaseType.getCanonicalType(); - if (isa(CanonType)) - IFace = dyn_cast(CanonType)->getDecl(); - else - IFace = dyn_cast(CanonType)->getDecl(); - ObjCInterfaceDecl *clsDeclared; - if (ObjCIvarDecl *IV = IFace->lookupInstanceVariable(&Member, clsDeclared)) + if (const ObjCInterfaceType *IFTy = BaseType->getAsObjCInterfaceType()) { + if (ObjCIvarDecl *IV = IFTy->getDecl()->lookupInstanceVariable(&Member)) return new ObjCIvarRefExpr(IV, IV->getType(), MemberLoc, BaseExpr, OpKind == tok::arrow); return Diag(OpLoc, diag::err_typecheck_member_reference_structUnion, SourceRange(MemberLoc)); } + // Handle property access. if (isObjCObjectPointerType(BaseType)) { const PointerType *pointerType = BaseType->getAsPointerType(); BaseType = pointerType->getPointeeType();