[cfe-commits] r58698 - in /cfe/trunk: 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
Douglas Gregor
doug.gregor at gmail.com
Tue Nov 4 06:56:15 PST 2008
Author: dgregor
Date: Tue Nov 4 08:56:14 2008
New Revision: 58698
URL: http://llvm.org/viewvc/llvm-project?rev=58698&view=rev
Log:
Add a new expression class, ObjCSuperExpr, to handle the Objective-C 'super'. Remove ObjCThis from PredefinedExpr
Modified:
cfe/trunk/Driver/RewriteObjC.cpp
cfe/trunk/include/clang/AST/Expr.h
cfe/trunk/include/clang/AST/ExprObjC.h
cfe/trunk/include/clang/AST/StmtNodes.def
cfe/trunk/lib/AST/Expr.cpp
cfe/trunk/lib/AST/StmtDumper.cpp
cfe/trunk/lib/AST/StmtPrinter.cpp
cfe/trunk/lib/AST/StmtSerialization.cpp
cfe/trunk/lib/Analysis/CheckObjCDealloc.cpp
cfe/trunk/lib/CodeGen/CGExpr.cpp
cfe/trunk/lib/CodeGen/CGObjC.cpp
cfe/trunk/lib/CodeGen/CodeGenFunction.h
cfe/trunk/lib/Sema/SemaExpr.cpp
cfe/trunk/lib/Sema/SemaExprObjC.cpp
Modified: cfe/trunk/Driver/RewriteObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/RewriteObjC.cpp?rev=58698&r1=58697&r2=58698&view=diff
==============================================================================
--- cfe/trunk/Driver/RewriteObjC.cpp (original)
+++ cfe/trunk/Driver/RewriteObjC.cpp Tue Nov 4 08:56:14 2008
@@ -1899,9 +1899,8 @@
// 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();
Modified: cfe/trunk/include/clang/AST/Expr.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Expr.h?rev=58698&r1=58697&r2=58698&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Expr.h (original)
+++ cfe/trunk/include/clang/AST/Expr.h Tue Nov 4 08:56:14 2008
@@ -222,8 +222,7 @@
enum IdentType {
Func,
Function,
- PrettyFunction,
- ObjCSuper // super
+ PrettyFunction
};
private:
Modified: cfe/trunk/include/clang/AST/ExprObjC.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ExprObjC.h?rev=58698&r1=58697&r2=58698&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/ExprObjC.h (original)
+++ cfe/trunk/include/clang/AST/ExprObjC.h Tue Nov 4 08:56:14 2008
@@ -416,6 +416,30 @@
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
Modified: cfe/trunk/include/clang/AST/StmtNodes.def
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/StmtNodes.def?rev=58698&r1=58697&r2=58698&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/StmtNodes.def (original)
+++ cfe/trunk/include/clang/AST/StmtNodes.def Tue Nov 4 08:56:14 2008
@@ -111,6 +111,7 @@
STMT(84, ObjCProtocolExpr , Expr)
STMT(85, ObjCIvarRefExpr , Expr)
STMT(86, ObjCPropertyRefExpr , Expr)
+STMT(87, ObjCSuperExpr , Expr)
// Clang Extensions.
STMT(90, OverloadExpr , Expr)
Modified: cfe/trunk/lib/AST/Expr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Expr.cpp?rev=58698&r1=58697&r2=58698&view=diff
==============================================================================
--- cfe/trunk/lib/AST/Expr.cpp (original)
+++ cfe/trunk/lib/AST/Expr.cpp Tue Nov 4 08:56:14 2008
@@ -1311,6 +1311,10 @@
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(); }
Modified: cfe/trunk/lib/AST/StmtDumper.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/StmtDumper.cpp?rev=58698&r1=58697&r2=58698&view=diff
==============================================================================
--- cfe/trunk/lib/AST/StmtDumper.cpp (original)
+++ cfe/trunk/lib/AST/StmtDumper.cpp Tue Nov 4 08:56:14 2008
@@ -130,8 +130,9 @@
// 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 @@
void VisitObjCProtocolExpr(ObjCProtocolExpr *Node);
void VisitObjCPropertyRefExpr(ObjCPropertyRefExpr *Node);
void VisitObjCIvarRefExpr(ObjCIvarRefExpr *Node);
+ void VisitObjCSuperExpr(ObjCSuperExpr *Node);
};
}
@@ -312,7 +314,6 @@
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 @@
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::VisitObjCSuperExpr(ObjCSuperExpr *Node) {
+ DumpExpr(Node);
+ fprintf(F, " super");
+}
+
//===----------------------------------------------------------------------===//
// Stmt method implementations
//===----------------------------------------------------------------------===//
Modified: cfe/trunk/lib/AST/StmtPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/StmtPrinter.cpp?rev=58698&r1=58697&r2=58698&view=diff
==============================================================================
--- cfe/trunk/lib/AST/StmtPrinter.cpp (original)
+++ cfe/trunk/lib/AST/StmtPrinter.cpp Tue Nov 4 08:56:14 2008
@@ -515,9 +515,6 @@
case PredefinedExpr::PrettyFunction:
OS << "__PRETTY_FUNCTION__";
break;
- case PredefinedExpr::ObjCSuper:
- OS << "super";
- break;
}
}
@@ -917,6 +914,10 @@
OS << "]";
}
+void StmtPrinter::VisitObjCSuperExpr(ObjCSuperExpr *) {
+ OS << "super";
+}
+
void StmtPrinter::VisitBlockExpr(BlockExpr *Node) {
BlockDecl *BD = Node->getBlockDecl();
OS << "^";
Modified: cfe/trunk/lib/AST/StmtSerialization.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/StmtSerialization.cpp?rev=58698&r1=58697&r2=58698&view=diff
==============================================================================
--- cfe/trunk/lib/AST/StmtSerialization.cpp (original)
+++ cfe/trunk/lib/AST/StmtSerialization.cpp Tue Nov 4 08:56:14 2008
@@ -191,6 +191,9 @@
case ObjCStringLiteralClass:
return ObjCStringLiteral::CreateImpl(D, C);
+ case ObjCSuperExprClass:
+ return ObjCSuperExpr::CreateImpl(D, C);
+
//==--------------------------------------==//
// C++
//==--------------------------------------==//
@@ -1232,6 +1235,17 @@
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.
//===----------------------------------------------------------------------===//
Modified: cfe/trunk/lib/Analysis/CheckObjCDealloc.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/CheckObjCDealloc.cpp?rev=58698&r1=58697&r2=58698&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/CheckObjCDealloc.cpp (original)
+++ cfe/trunk/lib/Analysis/CheckObjCDealloc.cpp Tue Nov 4 08:56:14 2008
@@ -30,9 +30,7 @@
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.
Modified: cfe/trunk/lib/CodeGen/CGExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExpr.cpp?rev=58698&r1=58697&r2=58698&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGExpr.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExpr.cpp Tue Nov 4 08:56:14 2008
@@ -130,7 +130,9 @@
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 @@
case PredefinedExpr::Function:
case PredefinedExpr::PrettyFunction:
return EmitPredefinedFunctionName(E->getIdentType());
- case PredefinedExpr::ObjCSuper:
- return EmitUnsupportedLValue(E, "use of super");
}
}
@@ -875,6 +875,11 @@
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) {
Modified: cfe/trunk/lib/CodeGen/CGObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGObjC.cpp?rev=58698&r1=58697&r2=58698&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGObjC.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGObjC.cpp Tue Nov 4 08:56:14 2008
@@ -72,9 +72,7 @@
}
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 {
Modified: cfe/trunk/lib/CodeGen/CodeGenFunction.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenFunction.h?rev=58698&r1=58697&r2=58698&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenFunction.h (original)
+++ cfe/trunk/lib/CodeGen/CodeGenFunction.h Tue Nov 4 08:56:14 2008
@@ -402,6 +402,7 @@
LValue EmitObjCMessageExprLValue(const ObjCMessageExpr *E);
LValue EmitObjCIvarRefLValue(const ObjCIvarRefExpr *E);
LValue EmitObjCPropertyRefLValue(const ObjCPropertyRefExpr *E);
+ LValue EmitObjCSuperExpr(const ObjCSuperExpr *E);
//===--------------------------------------------------------------------===//
// Scalar Expression Emission
Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=58698&r1=58697&r2=58698&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Tue Nov 4 08:56:14 2008
@@ -365,7 +365,7 @@
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) {
Modified: cfe/trunk/lib/Sema/SemaExprObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprObjC.cpp?rev=58698&r1=58697&r2=58698&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExprObjC.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprObjC.cpp Tue Nov 4 08:56:14 2008
@@ -193,8 +193,7 @@
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);
More information about the cfe-commits
mailing list