[cfe-commits] r60996 - in /cfe/trunk: include/clang/AST/DeclObjC.h include/clang/AST/ExprObjC.h lib/AST/DeclObjC.cpp lib/AST/StmtSerialization.cpp lib/CodeGen/CGObjC.cpp lib/Sema/SemaExpr.cpp

Fariborz Jahanian fjahanian at apple.com
Sat Dec 13 14:20:28 PST 2008


Author: fjahanian
Date: Sat Dec 13 16:20:28 2008
New Revision: 60996

URL: http://llvm.org/viewvc/llvm-project?rev=60996&view=rev
Log:
Patch for ObjCIvarRefExpr containing the field
matching the storage layout for this ivar

Modified:
    cfe/trunk/include/clang/AST/DeclObjC.h
    cfe/trunk/include/clang/AST/ExprObjC.h
    cfe/trunk/lib/AST/DeclObjC.cpp
    cfe/trunk/lib/AST/StmtSerialization.cpp
    cfe/trunk/lib/CodeGen/CGObjC.cpp
    cfe/trunk/lib/Sema/SemaExpr.cpp

Modified: cfe/trunk/include/clang/AST/DeclObjC.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclObjC.h?rev=60996&r1=60995&r2=60996&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/DeclObjC.h (original)
+++ cfe/trunk/include/clang/AST/DeclObjC.h Sat Dec 13 16:20:28 2008
@@ -353,6 +353,7 @@
   void CollectObjCIvars(std::vector<FieldDecl*> &Fields);
   void setRecordForDecl(RecordDecl *Decl) { RecordForDecl = Decl; }
   RecordDecl *getRecordForDecl() const { return RecordForDecl; }
+  RecordDecl *getRecordForDecl() { return RecordForDecl; }
   
   typedef ObjCIvarDecl * const *ivar_iterator;
   ivar_iterator ivar_begin() const { return Ivars; }
@@ -383,7 +384,7 @@
    
   void addInstanceVariablesToClass(ObjCIvarDecl **ivars, unsigned numIvars,
                                    SourceLocation RBracLoc);
-  
+  FieldDecl *lookupFieldDeclForIvar(ASTContext &Context, ObjCIvarDecl *ivar);
   void addLayoutToClass(ASTContext &Context);
 
   void addMethods(ObjCMethodDecl **insMethods, unsigned numInsMembers,

Modified: cfe/trunk/include/clang/AST/ExprObjC.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ExprObjC.h?rev=60996&r1=60995&r2=60996&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/ExprObjC.h (original)
+++ cfe/trunk/include/clang/AST/ExprObjC.h Sat Dec 13 16:20:28 2008
@@ -155,19 +155,24 @@
 
 /// ObjCIvarRefExpr - A reference to an ObjC instance variable.
 class ObjCIvarRefExpr : public Expr {
-  class ObjCIvarDecl *D; 
+  class ObjCIvarDecl *D;
+  FieldDecl *FD;
   SourceLocation Loc;
   Stmt *Base;
   bool IsArrow:1;      // True if this is "X->F", false if this is "X.F".
   bool IsFreeIvar:1;   // True if ivar reference has no base (self assumed).
   
 public:
-  ObjCIvarRefExpr(ObjCIvarDecl *d, QualType t, SourceLocation l, Expr *base=0, 
+  ObjCIvarRefExpr(ObjCIvarDecl *d, FieldDecl *fd,
+                  QualType t, SourceLocation l, Expr *base=0, 
                   bool arrow = false, bool freeIvar = false) : 
-    Expr(ObjCIvarRefExprClass, t), D(d), Loc(l), Base(base), IsArrow(arrow),
+    Expr(ObjCIvarRefExprClass, t), D(d), FD(fd),
+    Loc(l), Base(base), IsArrow(arrow),
     IsFreeIvar(freeIvar) {}
   
   ObjCIvarDecl *getDecl() { return D; }
+  FieldDecl *getFieldDecl() { return FD; }
+  const FieldDecl *getFieldDecl() const { return FD; }
   const ObjCIvarDecl *getDecl() const { return D; }
   virtual SourceRange getSourceRange() const { 
     return isFreeIvar() ? SourceRange(Loc)

Modified: cfe/trunk/lib/AST/DeclObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclObjC.cpp?rev=60996&r1=60995&r2=60996&view=diff

==============================================================================
--- cfe/trunk/lib/AST/DeclObjC.cpp (original)
+++ cfe/trunk/lib/AST/DeclObjC.cpp Sat Dec 13 16:20:28 2008
@@ -363,7 +363,21 @@
   setLocEnd(RBrac);
 }
 
-/// addInstanceVariablesToClass - produces layout info. for the class for its
+/// lookupFieldDeclForIvar - looks up a field decl' in the laid out
+/// storage which matches this 'ivar'.
+///
+FieldDecl *ObjCInterfaceDecl::lookupFieldDeclForIvar(ASTContext &Context, 
+                                                     ObjCIvarDecl *ivar) {
+  assert(RecordForDecl && "lookupFieldDeclForIvar no storage for class");
+  DeclarationName Member = ivar->getDeclName();
+  DeclContext::lookup_result Lookup = RecordForDecl->lookup(Context, Member);
+  assert((Lookup.first != Lookup.second) && "field decl not found");
+  FieldDecl *MemberDecl = dyn_cast<FieldDecl>(*Lookup.first);
+  assert(MemberDecl && "field decl not found");
+  return MemberDecl;
+}
+
+/// addLayoutToClass - produces layout info. for the class for its
 /// ivars and all those inherited.
 ///
 void ObjCInterfaceDecl::addLayoutToClass(ASTContext &Context)

Modified: cfe/trunk/lib/AST/StmtSerialization.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/StmtSerialization.cpp?rev=60996&r1=60995&r2=60996&view=diff

==============================================================================
--- cfe/trunk/lib/AST/StmtSerialization.cpp (original)
+++ cfe/trunk/lib/AST/StmtSerialization.cpp Sat Dec 13 16:20:28 2008
@@ -1162,7 +1162,7 @@
 ObjCIvarRefExpr* ObjCIvarRefExpr::CreateImpl(Deserializer& D, ASTContext& C) {
   SourceLocation Loc = SourceLocation::ReadVal(D);
   QualType T = QualType::ReadVal(D);
-  ObjCIvarRefExpr* dr = new ObjCIvarRefExpr(NULL,T,Loc);
+  ObjCIvarRefExpr* dr = new ObjCIvarRefExpr(NULL,NULL,T,Loc);
   D.ReadPtr(dr->D,false);  
   return dr;
 }

Modified: cfe/trunk/lib/CodeGen/CGObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGObjC.cpp?rev=60996&r1=60995&r2=60996&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CGObjC.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGObjC.cpp Sat Dec 13 16:20:28 2008
@@ -272,7 +272,9 @@
     DeclRefExpr Base(Self, Self->getType(), Loc);
     ParmVarDecl *ArgDecl = OMD->getParamDecl(0);
     DeclRefExpr Arg(ArgDecl, ArgDecl->getType(), Loc);
-    ObjCIvarRefExpr IvarRef(Ivar, Ivar->getType(), Loc, &Base,
+    ObjCInterfaceDecl *OI = IMP->getClassInterface();
+    FieldDecl *FD = OI->lookupFieldDeclForIvar(getContext(), Ivar);
+    ObjCIvarRefExpr IvarRef(Ivar, FD, Ivar->getType(), Loc, &Base,
                             true, true);
     BinaryOperator Assign(&IvarRef, &Arg, BinaryOperator::Assign,
                           Ivar->getType(), Loc);

Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=60996&r1=60995&r2=60996&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Sat Dec 13 16:20:28 2008
@@ -418,11 +418,12 @@
     if (SD == 0 || SD->isDefinedOutsideFunctionOrMethod()) {
       ObjCInterfaceDecl *IFace = getCurMethodDecl()->getClassInterface();
       if (ObjCIvarDecl *IV = IFace->lookupInstanceVariable(II)) {
+        FieldDecl *FD = IFace->lookupFieldDeclForIvar(Context, IV);
         // FIXME: This should use a new expr for a direct reference, don't turn
         // this into Self->ivar, just return a BareIVarExpr or something.
         IdentifierInfo &II = Context.Idents.get("self");
         ExprResult SelfExpr = ActOnIdentifierExpr(S, Loc, II, false);
-        return new ObjCIvarRefExpr(IV, IV->getType(), Loc, 
+        return new ObjCIvarRefExpr(IV, FD, IV->getType(), Loc, 
                                  static_cast<Expr*>(SelfExpr.Val), true, true);
       }
     }
@@ -1264,9 +1265,11 @@
   // Handle access to Objective-C instance variables, such as "Obj->ivar" and
   // (*Obj).ivar.
   if (const ObjCInterfaceType *IFTy = BaseType->getAsObjCInterfaceType()) {
-    if (ObjCIvarDecl *IV = IFTy->getDecl()->lookupInstanceVariable(&Member))
-      return new ObjCIvarRefExpr(IV, IV->getType(), MemberLoc, BaseExpr, 
+    if (ObjCIvarDecl *IV = IFTy->getDecl()->lookupInstanceVariable(&Member)) {
+      FieldDecl *FD = IFTy->getDecl()->lookupFieldDeclForIvar(Context, IV);
+      return new ObjCIvarRefExpr(IV, FD, IV->getType(), MemberLoc, BaseExpr, 
                                  OpKind == tok::arrow);
+    }
     return Diag(MemberLoc, diag::err_typecheck_member_reference_ivar)
              << IFTy->getDecl()->getDeclName() << &Member
              << BaseExpr->getSourceRange();





More information about the cfe-commits mailing list