]> granicus.if.org Git - clang/commitdiff
Add a new expression class, ObjCSuperExpr, to handle the Objective-C 'super'. Remove...
authorDouglas Gregor <dgregor@apple.com>
Tue, 4 Nov 2008 14:56:14 +0000 (14:56 +0000)
committerDouglas Gregor <dgregor@apple.com>
Tue, 4 Nov 2008 14:56:14 +0000 (14:56 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@58698 91177308-0d34-0410-b5e6-96231b3b80d8

14 files changed:
Driver/RewriteObjC.cpp
include/clang/AST/Expr.h
include/clang/AST/ExprObjC.h
include/clang/AST/StmtNodes.def
lib/AST/Expr.cpp
lib/AST/StmtDumper.cpp
lib/AST/StmtPrinter.cpp
lib/AST/StmtSerialization.cpp
lib/Analysis/CheckObjCDealloc.cpp
lib/CodeGen/CGExpr.cpp
lib/CodeGen/CGObjC.cpp
lib/CodeGen/CodeGenFunction.h
lib/Sema/SemaExpr.cpp
lib/Sema/SemaExprObjC.cpp

index d2aa398e04c39cabf0521e6af147ff6a459c9997..35d7cc8e1fa7c60ed753323c093b415946ce4434 100644 (file)
@@ -1899,9 +1899,8 @@ ObjCInterfaceDecl *RewriteObjC::isSuperReceiver(Expr *recExpr) {
   // check if we are sending a message to 'super'
   if (!CurMethodDef || !CurMethodDef->isInstance()) return 0;
   
-  if (PredefinedExpr *PDE = dyn_cast<PredefinedExpr>(recExpr))
-    if (PDE->getIdentType() == PredefinedExpr::ObjCSuper) {
-      const PointerType *PT = PDE->getType()->getAsPointerType();
+  if (ObjCSuperExpr *Super = dyn_cast<ObjCSuperExpr>(recExpr)) {
+      const PointerType *PT = Super->getType()->getAsPointerType();
       assert(PT);
       ObjCInterfaceType *IT = cast<ObjCInterfaceType>(PT->getPointeeType());
       return IT->getDecl();
index bc6c454ca1778d2f46921c7159d61b4d546ad0cd..2c25fcd123c60f6078b16524e41147c576ba6ed4 100644 (file)
@@ -222,8 +222,7 @@ public:
   enum IdentType {
     Func,
     Function,
-    PrettyFunction,
-    ObjCSuper // super
+    PrettyFunction
   };
   
 private:
index 3b19fe95273fc726080305322c6e907ae570d22b..7f519a861c6c362585cd4ecd3e773b98b7f2c474 100644 (file)
@@ -416,6 +416,30 @@ public:
   static ObjCMessageExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C);
 };
 
+/// ObjCSuperExpr - Represents the "super" expression in Objective-C,
+/// which refers to the object on which the current method is executing.
+class ObjCSuperExpr : public Expr {
+  SourceLocation Loc;
+
+public:
+  ObjCSuperExpr(SourceLocation L, QualType Type) 
+    : Expr(ObjCSuperExprClass, Type), Loc(L) { }
+
+  virtual SourceRange getSourceRange() const { return SourceRange(Loc); }
+
+  static bool classof(const Stmt *T) { 
+    return T->getStmtClass() == ObjCSuperExprClass;
+  }
+  static bool classof(const ObjCSuperExpr *) { return true; }
+
+  // Iterators
+  virtual child_iterator child_begin();
+  virtual child_iterator child_end();
+  
+  virtual void EmitImpl(llvm::Serializer& S) const;
+  static ObjCSuperExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C);  
+};
+
 }  // end namespace clang
 
 #endif
index 4382fb427b6f3990c17770e9108426d81b9718d7..7b60fcf675635fb85875866ee8cdfdd304fdbcf7 100644 (file)
@@ -111,6 +111,7 @@ STMT(83, ObjCSelectorExpr     , Expr)
 STMT(84, ObjCProtocolExpr     , Expr)
 STMT(85, ObjCIvarRefExpr      , Expr)
 STMT(86, ObjCPropertyRefExpr  , Expr)
+STMT(87, ObjCSuperExpr        , Expr)
 
 // Clang Extensions.
 STMT(90, OverloadExpr         , Expr)
index 171f7dbde2e49b34d942ac8eb1a3ee3235a2a012..ce0856033d6e7b92d30ab11244cd5325ba3726d9 100644 (file)
@@ -1311,6 +1311,10 @@ Stmt::child_iterator ObjCIvarRefExpr::child_end() { return &Base+1; }
 Stmt::child_iterator ObjCPropertyRefExpr::child_begin() { return &Base; }
 Stmt::child_iterator ObjCPropertyRefExpr::child_end() { return &Base+1; }
 
+// ObjCSuperExpr
+Stmt::child_iterator ObjCSuperExpr::child_begin() { return child_iterator(); }
+Stmt::child_iterator ObjCSuperExpr::child_end() { return child_iterator(); }
+
 // PredefinedExpr
 Stmt::child_iterator PredefinedExpr::child_begin() { return child_iterator(); }
 Stmt::child_iterator PredefinedExpr::child_end() { return child_iterator(); }
index 349b6fb6e366c90f20c56651f7b8ccf432507c74..ecfdbf78d27f0242e20b4f1a4d294ff262c54e33 100644 (file)
@@ -130,8 +130,9 @@ namespace  {
     // C++
     void VisitCXXNamedCastExpr(CXXNamedCastExpr *Node);
     void VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *Node);
+    void VisitCXXThisExpr(CXXThisExpr *Node);
     void VisitCXXFunctionalCastExpr(CXXFunctionalCastExpr *Node);
-
+    
     // ObjC
     void VisitObjCEncodeExpr(ObjCEncodeExpr *Node);
     void VisitObjCMessageExpr(ObjCMessageExpr* Node);
@@ -139,6 +140,7 @@ namespace  {
     void VisitObjCProtocolExpr(ObjCProtocolExpr *Node);
     void VisitObjCPropertyRefExpr(ObjCPropertyRefExpr *Node);
     void VisitObjCIvarRefExpr(ObjCIvarRefExpr *Node);
+    void VisitObjCSuperExpr(ObjCSuperExpr *Node);
   };
 }
 
@@ -312,7 +314,6 @@ void StmtDumper::VisitPredefinedExpr(PredefinedExpr *Node) {
   case PredefinedExpr::Func:           fprintf(F, " __func__"); break;
   case PredefinedExpr::Function:       fprintf(F, " __FUNCTION__"); break;
   case PredefinedExpr::PrettyFunction: fprintf(F, " __PRETTY_FUNCTION__");break;
-  case PredefinedExpr::ObjCSuper:      fprintf(F, "super"); break;
   }
 }
 
@@ -418,6 +419,11 @@ void StmtDumper::VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *Node) {
   fprintf(F, " %s", Node->getValue() ? "true" : "false");
 }
 
+void StmtDumper::VisitCXXThisExpr(CXXThisExpr *Node) {
+  DumpExpr(Node);
+  fprintf(F, " this");
+}
+
 void StmtDumper::VisitCXXFunctionalCastExpr(CXXFunctionalCastExpr *Node) {
   DumpExpr(Node);
   fprintf(F, " functional cast to %s", 
@@ -471,6 +477,11 @@ void StmtDumper::VisitObjCPropertyRefExpr(ObjCPropertyRefExpr *Node) {
   }
 }
 
+void StmtDumper::VisitObjCSuperExpr(ObjCSuperExpr *Node) {
+  DumpExpr(Node);
+  fprintf(F, " super");
+}
+
 //===----------------------------------------------------------------------===//
 // Stmt method implementations
 //===----------------------------------------------------------------------===//
index 34aefc2c4c2ab68f1e7b68af16288e3c8c8fa6e7..420bdbdee90fe2a05ce50d141f4a7779accec05d 100644 (file)
@@ -515,9 +515,6 @@ void StmtPrinter::VisitPredefinedExpr(PredefinedExpr *Node) {
     case PredefinedExpr::PrettyFunction:
       OS << "__PRETTY_FUNCTION__";
       break;
-    case PredefinedExpr::ObjCSuper:
-      OS << "super";
-      break;
   }
 }
 
@@ -917,6 +914,10 @@ void StmtPrinter::VisitObjCMessageExpr(ObjCMessageExpr *Mess) {
   OS << "]";
 }
 
+void StmtPrinter::VisitObjCSuperExpr(ObjCSuperExpr *) {
+  OS << "super";
+}
+
 void StmtPrinter::VisitBlockExpr(BlockExpr *Node) {
   BlockDecl *BD = Node->getBlockDecl();
   OS << "^";
index aefaee38a4225bbe9f7130fbaece36b0d38e50fe..09aaceffda4f0e6a72ff497f4496324204ed009d 100644 (file)
@@ -191,6 +191,9 @@ Stmt* Stmt::Create(Deserializer& D, ASTContext& C) {
     case ObjCStringLiteralClass:
       return ObjCStringLiteral::CreateImpl(D, C);
       
+    case ObjCSuperExprClass:
+      return ObjCSuperExpr::CreateImpl(D, C);
+
     //==--------------------------------------==//
     //    C++
     //==--------------------------------------==//
@@ -1232,6 +1235,17 @@ ObjCStringLiteral* ObjCStringLiteral::CreateImpl(Deserializer& D, ASTContext& C)
   return new ObjCStringLiteral(String,T,L);
 }
 
+void ObjCSuperExpr::EmitImpl(llvm::Serializer& S) const {
+  S.Emit(getType());
+  S.Emit(Loc);
+}
+
+ObjCSuperExpr* ObjCSuperExpr::CreateImpl(llvm::Deserializer& D, ASTContext&) {
+  QualType Ty = QualType::ReadVal(D);
+  SourceLocation Loc = SourceLocation::ReadVal(D);
+  return new ObjCSuperExpr(Loc, Ty);
+}
+
 //===----------------------------------------------------------------------===//
 //   Serialization for Clang Extensions.
 //===----------------------------------------------------------------------===//
index e41c8271847278fe934b3e733d029bf87831cbfd..8628ff122cf99b281515843b7b54993fdc6f3e6e 100644 (file)
@@ -30,9 +30,7 @@ static bool scan_dealloc(Stmt* S, Selector Dealloc) {
     if (ME->getSelector() == Dealloc)
       if(ME->getReceiver())
         if (Expr* Receiver = ME->getReceiver()->IgnoreParenCasts())
-          if (PredefinedExpr* E = dyn_cast<PredefinedExpr>(Receiver))
-            if (E->getIdentType() == PredefinedExpr::ObjCSuper)
-              return true;
+          return isa<ObjCSuperExpr>(Receiver);
 
   // Recurse to children.
 
index fa70f47da9245f9615ee5c2a71fb808d0799b491..3d8d192a2d876054b960d0192816812674bdd96b 100644 (file)
@@ -130,7 +130,9 @@ LValue CodeGenFunction::EmitLValue(const Expr *E) {
     return EmitObjCIvarRefLValue(cast<ObjCIvarRefExpr>(E));
   case Expr::ObjCPropertyRefExprClass:
     return EmitObjCPropertyRefLValue(cast<ObjCPropertyRefExpr>(E));
-    
+  case Expr::ObjCSuperExprClass:
+    return EmitObjCSuperExpr(cast<ObjCSuperExpr>(E));
+
   case Expr::UnaryOperatorClass: 
     return EmitUnaryOpLValue(cast<UnaryOperator>(E));
   case Expr::ArraySubscriptExprClass:
@@ -571,8 +573,6 @@ LValue CodeGenFunction::EmitPredefinedLValue(const PredefinedExpr *E) {
   case PredefinedExpr::Function:
   case PredefinedExpr::PrettyFunction:
     return EmitPredefinedFunctionName(E->getIdentType());
-  case PredefinedExpr::ObjCSuper:
-    return EmitUnsupportedLValue(E, "use of super");
   }
 }
 
@@ -875,6 +875,11 @@ CodeGenFunction::EmitObjCPropertyRefLValue(const ObjCPropertyRefExpr *E) {
   return LValue::MakePropertyRef(E, E->getType().getCVRQualifiers());
 }
 
+LValue
+CodeGenFunction::EmitObjCSuperExpr(const ObjCSuperExpr *E) {
+  return EmitUnsupportedLValue(E, "use of super");
+}
+
 RValue CodeGenFunction::EmitCallExpr(llvm::Value *Callee, QualType FnType, 
                                      CallExpr::const_arg_iterator ArgBeg,
                                      CallExpr::const_arg_iterator ArgEnd) {
index c0260ad06b3a19c5bf115927070519c1e5012f51..cb820409d67d87aae9631fde8675dde7f841a8e1 100644 (file)
@@ -72,9 +72,7 @@ RValue CodeGenFunction::EmitObjCMessageExpr(const ObjCMessageExpr *E) {
     }
     
     isClassMessage = true;
-  } else if (isa<PredefinedExpr>(E->getReceiver())) {
-    assert(cast<PredefinedExpr>(E->getReceiver())->getIdentType() == 
-             PredefinedExpr::ObjCSuper);
+  } else if (isa<ObjCSuperExpr>(E->getReceiver())) {
     isSuperMessage = true;
     Receiver = LoadObjCSelf();
   } else {
index ccc5008aee11f455e5da45462d0c874b05f8c701..e6636ba27b691030738be836d272a104c9df0fce 100644 (file)
@@ -402,6 +402,7 @@ public:
   LValue EmitObjCMessageExprLValue(const ObjCMessageExpr *E);
   LValue EmitObjCIvarRefLValue(const ObjCIvarRefExpr *E);
   LValue EmitObjCPropertyRefLValue(const ObjCPropertyRefExpr *E);
+  LValue EmitObjCSuperExpr(const ObjCSuperExpr *E);
 
   //===--------------------------------------------------------------------===//
   //                         Scalar Expression Emission
index f06a04101b88b755b95965e282343cb32a770941..c0abc9e51ae67e45ebe205e0a320ae2667413a8a 100644 (file)
@@ -365,7 +365,7 @@ Sema::ExprResult Sema::ActOnIdentifierExpr(Scope *S, SourceLocation Loc,
     if (SD == 0 && &II == SuperID) {
       QualType T = Context.getPointerType(Context.getObjCInterfaceType(
                      getCurMethodDecl()->getClassInterface()));
-      return new PredefinedExpr(Loc, T, PredefinedExpr::ObjCSuper);
+      return new ObjCSuperExpr(Loc, T);
     }
   }
   if (D == 0) {
index a474b7eee78622501bb01b70e9c325e69ba92ed9..bc2f7f2d6f74f03d893cba9f77566c2812255732 100644 (file)
@@ -193,8 +193,7 @@ Sema::ExprResult Sema::ActOnClassMessage(
     if (getCurMethodDecl()->isInstance()) {
       QualType superTy = Context.getObjCInterfaceType(ClassDecl);
       superTy = Context.getPointerType(superTy);
-      ExprResult ReceiverExpr = new PredefinedExpr(SourceLocation(), superTy,
-          PredefinedExpr::ObjCSuper);
+      ExprResult ReceiverExpr = new ObjCSuperExpr(SourceLocation(), superTy);
       // We are really in an instance method, redirect.
       return ActOnInstanceMessage(ReceiverExpr.Val, Sel, lbrac, rbrac,
                                   Args, NumArgs);