[cfe-commits] r51719 - in /cfe/trunk: include/clang/AST/ExprObjC.h include/clang/AST/StmtNodes.def lib/AST/Expr.cpp lib/AST/StmtPrinter.cpp lib/AST/StmtSerialization.cpp lib/Sema/SemaExpr.cpp

Steve Naroff snaroff at apple.com
Thu May 29 17:40:33 PDT 2008


Author: snaroff
Date: Thu May 29 19:40:33 2008
New Revision: 51719

URL: http://llvm.org/viewvc/llvm-project?rev=51719&view=rev
Log:
Add basic support for properties references (a missing feature).

While it is far from complete, it does fix the following <rdar://problem/5967199> clang on xcode: error: member reference is not to a structure or union


Modified:
    cfe/trunk/include/clang/AST/ExprObjC.h
    cfe/trunk/include/clang/AST/StmtNodes.def
    cfe/trunk/lib/AST/Expr.cpp
    cfe/trunk/lib/AST/StmtPrinter.cpp
    cfe/trunk/lib/AST/StmtSerialization.cpp
    cfe/trunk/lib/Sema/SemaExpr.cpp

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

==============================================================================
--- cfe/trunk/include/clang/AST/ExprObjC.h (original)
+++ cfe/trunk/include/clang/AST/ExprObjC.h Thu May 29 19:40:33 2008
@@ -189,6 +189,41 @@
   static ObjCIvarRefExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C);
 };
 
+/// ObjCPropertyRefExpr - A reference to an ObjC property.
+class ObjCPropertyRefExpr : public Expr {
+  class Decl *D; // an ObjCMethodDecl or ObjCPropertyDecl
+  SourceLocation Loc;
+  Expr *Base;
+  
+public:
+  ObjCPropertyRefExpr(Decl *d, QualType t, SourceLocation l, Expr *base) : 
+    Expr(ObjCPropertyRefExprClass, t), D(d), Loc(l), Base(base) {}
+  
+  Decl *getDecl() { return D; }
+  const Decl *getDecl() const { return D; }
+  
+  virtual SourceRange getSourceRange() const { 
+    return SourceRange(getBase()->getLocStart(), Loc); 
+  }
+  const Expr *getBase() const { return Base; }
+  Expr *getBase() { return Base; }
+  void setBase(Expr * base) { Base = base; }
+  
+  SourceLocation getLocation() const { return Loc; }
+
+  static bool classof(const Stmt *T) { 
+    return T->getStmtClass() == ObjCPropertyRefExprClass; 
+  }
+  static bool classof(const ObjCPropertyRefExpr *) { return true; }
+  
+  // Iterators
+  virtual child_iterator child_begin();
+  virtual child_iterator child_end();
+  
+  virtual void EmitImpl(llvm::Serializer& S) const;
+  static ObjCPropertyRefExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C);
+};
+
 class ObjCMessageExpr : public Expr {
   enum { RECEIVER=0, ARGS_START=1 };
 

Modified: cfe/trunk/include/clang/AST/StmtNodes.def
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/StmtNodes.def?rev=51719&r1=51718&r2=51719&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/StmtNodes.def (original)
+++ cfe/trunk/include/clang/AST/StmtNodes.def Thu May 29 19:40:33 2008
@@ -100,12 +100,13 @@
 STMT(73, ObjCSelectorExpr     , Expr)
 STMT(74, ObjCProtocolExpr     , Expr)
 STMT(75, ObjCIvarRefExpr      , Expr)
+STMT(76, ObjCPropertyRefExpr  , Expr)
 
 // Clang Extensions.
-STMT(76, OverloadExpr         , Expr)
-STMT(77, ShuffleVectorExpr    , Expr)
+STMT(77, OverloadExpr         , Expr)
+STMT(78, ShuffleVectorExpr    , Expr)
 
-LAST_EXPR(77)
+LAST_EXPR(78)
 
 #undef STMT
 #undef FIRST_STMT

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

==============================================================================
--- cfe/trunk/lib/AST/Expr.cpp (original)
+++ cfe/trunk/lib/AST/Expr.cpp Thu May 29 19:40:33 2008
@@ -1187,6 +1187,15 @@
   return reinterpret_cast<Stmt**>(&Base)+1;
 }
 
+// ObjCIvarRefExpr
+Stmt::child_iterator ObjCPropertyRefExpr::child_begin() {
+  return reinterpret_cast<Stmt**>(&Base);
+}
+
+Stmt::child_iterator ObjCPropertyRefExpr::child_end() {
+  return reinterpret_cast<Stmt**>(&Base)+1;
+}
+
 // PreDefinedExpr
 Stmt::child_iterator PreDefinedExpr::child_begin() { return child_iterator(); }
 Stmt::child_iterator PreDefinedExpr::child_end() { return child_iterator(); }

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

==============================================================================
--- cfe/trunk/lib/AST/StmtPrinter.cpp (original)
+++ cfe/trunk/lib/AST/StmtPrinter.cpp Thu May 29 19:40:33 2008
@@ -484,6 +484,14 @@
   OS << Node->getDecl()->getName();
 }
 
+void StmtPrinter::VisitObjCPropertyRefExpr(ObjCPropertyRefExpr *Node) {
+  if (Node->getBase()) {
+    PrintExpr(Node->getBase());
+    OS << ".";
+  }
+  // FIXME: OS << Node->getDecl()->getName();
+}
+
 void StmtPrinter::VisitPreDefinedExpr(PreDefinedExpr *Node) {
   switch (Node->getIdentType()) {
     default:

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

==============================================================================
--- cfe/trunk/lib/AST/StmtSerialization.cpp (original)
+++ cfe/trunk/lib/AST/StmtSerialization.cpp Thu May 29 19:40:33 2008
@@ -988,6 +988,21 @@
   return dr;
 }
 
+void ObjCPropertyRefExpr::EmitImpl(Serializer& S) const {
+  S.Emit(Loc);
+  S.Emit(getType());
+  S.EmitPtr(getDecl());
+}
+  
+ObjCPropertyRefExpr* ObjCPropertyRefExpr::CreateImpl(Deserializer& D, 
+                                                     ASTContext& C) {
+  SourceLocation Loc = SourceLocation::ReadVal(D);
+  QualType T = QualType::ReadVal(D);
+  ObjCPropertyRefExpr* dr = new ObjCPropertyRefExpr(NULL,T,Loc,0);
+  D.ReadPtr(dr->D,false);  
+  return dr;
+}
+
 void ObjCMessageExpr::EmitImpl(Serializer& S) const {
   S.EmitBool(getReceiver() ? true : false);
   S.Emit(getType());

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

==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Thu May 29 19:40:33 2008
@@ -605,6 +605,36 @@
     if (ObjCIvarDecl *IV = IFace->lookupInstanceVariable(&Member, clsDeclared))
       return new ObjCIvarRefExpr(IV, IV->getType(), MemberLoc, BaseExpr, 
                                  OpKind==tok::arrow);
+  } else if (isObjCObjectPointerType(BaseType)) {
+    PointerType *pointerType = static_cast<PointerType*>(BaseType.getTypePtr());
+    BaseType = pointerType->getPointeeType();
+    ObjCInterfaceDecl *IFace;
+    if (isa<ObjCInterfaceType>(BaseType.getCanonicalType()))
+      IFace = dyn_cast<ObjCInterfaceType>(BaseType)->getDecl();
+    else
+      IFace = dyn_cast<ObjCQualifiedInterfaceType>(BaseType)->getDecl();
+    ObjCInterfaceDecl *clsDeclared;
+    if (ObjCIvarDecl *IV = IFace->lookupInstanceVariable(&Member, clsDeclared))
+      return new ObjCIvarRefExpr(IV, IV->getType(), MemberLoc, BaseExpr, 
+                                 OpKind==tok::arrow);
+    // Check for properties.
+    if (OpKind==tok::period) {
+      // Before we look for explicit property declarations, we check for
+      // nullary methods (which allow '.' notation).
+      Selector Sel = PP.getSelectorTable().getNullarySelector(&Member);
+      ObjCMethodDecl *MD = IFace->lookupInstanceMethod(Sel);
+      if (MD) 
+        return new ObjCPropertyRefExpr(MD, MD->getResultType(), 
+                                       MemberLoc, BaseExpr);
+      // FIXME: Need to deal with setter methods that take 1 argument. E.g.:
+      // @interface NSBundle : NSObject {}
+      // - (NSString *)bundlePath;
+      // - (void)setBundlePath:(NSString *)x;
+      // @end
+      // void someMethod() { frameworkBundle.bundlePath = 0; }
+      //
+      // FIXME: lookup explicit properties...
+    }
   }
   return Diag(OpLoc, diag::err_typecheck_member_reference_structUnion,
               SourceRange(MemberLoc));





More information about the cfe-commits mailing list