[cfe-commits] r50528 - in /cfe/trunk: include/clang/AST/Expr.h lib/AST/Expr.cpp lib/AST/StmtDumper.cpp lib/AST/StmtSerialization.cpp
Ted Kremenek
kremenek at apple.com
Thu May 1 10:26:20 PDT 2008
Author: kremenek
Date: Thu May 1 12:26:20 2008
New Revision: 50528
URL: http://llvm.org/viewvc/llvm-project?rev=50528&view=rev
Log:
Use pointer swizziling to unify in ObjCMessageExpr the receiver and classname "fields". This saves us a pointer.
Implemented serialization for ObjCMessageExpr.
Modified:
cfe/trunk/include/clang/AST/Expr.h
cfe/trunk/lib/AST/Expr.cpp
cfe/trunk/lib/AST/StmtDumper.cpp
cfe/trunk/lib/AST/StmtSerialization.cpp
Modified: cfe/trunk/include/clang/AST/Expr.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Expr.h?rev=50528&r1=50527&r2=50528&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Expr.h (original)
+++ cfe/trunk/include/clang/AST/Expr.h Thu May 1 12:26:20 2008
@@ -1518,10 +1518,16 @@
// FIXME: Since method decls contain the selector, and most messages have a
// prototype, consider devising a scheme for unifying SelName/MethodProto.
ObjCMethodDecl *MethodProto;
+
+ SourceLocation LBracloc, RBracloc;
- IdentifierInfo *ClassName; // optional - 0 for instance messages.
+ // constructor used during deserialization
+ ObjCMessageExpr(Selector selInfo, QualType retType,
+ SourceLocation LBrac, SourceLocation RBrac,
+ Expr **ArgExprs, unsigned nargs)
+ : Expr(ObjCMessageExprClass, retType), NumArgs(nargs), SelName(selInfo),
+ MethodProto(NULL), LBracloc(LBrac), RBracloc(RBrac) {}
- SourceLocation LBracloc, RBracloc;
public:
// constructor for class messages.
// FIXME: clsName should be typed to ObjCInterfaceType
@@ -1534,6 +1540,7 @@
QualType retType, ObjCMethodDecl *methDecl,
SourceLocation LBrac, SourceLocation RBrac,
Expr **ArgExprs, unsigned NumArgs);
+
~ObjCMessageExpr() {
delete [] SubExprs;
}
@@ -1541,8 +1548,13 @@
/// getReceiver - Returns the receiver of the message expression.
/// This can be NULL if the message is for instance methods. For
/// instance methods, use getClassName.
- const Expr *getReceiver() const { return SubExprs[RECEIVER]; }
- Expr *getReceiver() { return SubExprs[RECEIVER]; }
+ Expr *getReceiver() {
+ uintptr_t x = (uintptr_t) SubExprs[RECEIVER];
+ return x & 0x1 ? NULL : (Expr*) x;
+ }
+ const Expr *getReceiver() const {
+ return const_cast<ObjCMessageExpr*>(this)->getReceiver();
+ }
Selector getSelector() const { return SelName; }
@@ -1551,8 +1563,13 @@
/// getClassName - For instance methods, this returns the invoked class,
/// and returns NULL otherwise. For regular methods, use getReceiver.
- const IdentifierInfo *getClassName() const { return ClassName; }
- IdentifierInfo *getClassName() { return ClassName; }
+ IdentifierInfo *getClassName() {
+ uintptr_t x = (uintptr_t) SubExprs[RECEIVER];
+ return x & 0x1 ? (IdentifierInfo*) (x & ~0x1) : NULL;
+ }
+ const IdentifierInfo *getClassName() const {
+ return const_cast<ObjCMessageExpr*>(this)->getClassName();
+ }
/// getNumArgs - Return the number of actual arguments to this call.
unsigned getNumArgs() const { return NumArgs; }
@@ -1591,7 +1608,11 @@
arg_iterator arg_begin() { return &SubExprs[ARGS_START]; }
arg_iterator arg_end() { return arg_begin() + NumArgs; }
const_arg_iterator arg_begin() const { return &SubExprs[ARGS_START]; }
- const_arg_iterator arg_end() const { return arg_begin() + NumArgs; }
+ const_arg_iterator arg_end() const { return arg_begin() + NumArgs; }
+
+ // Serialization.
+ virtual void EmitImpl(llvm::Serializer& S) const;
+ static ObjCMessageExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C);
};
} // end namespace clang
Modified: cfe/trunk/lib/AST/Expr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Expr.cpp?rev=50528&r1=50527&r2=50528&view=diff
==============================================================================
--- cfe/trunk/lib/AST/Expr.cpp (original)
+++ cfe/trunk/lib/AST/Expr.cpp Thu May 1 12:26:20 2008
@@ -1091,7 +1091,7 @@
SourceLocation LBrac, SourceLocation RBrac,
Expr **ArgExprs, unsigned nargs)
: Expr(ObjCMessageExprClass, retType), SelName(selInfo),
- MethodProto(mproto), ClassName(0) {
+ MethodProto(mproto) {
NumArgs = nargs;
SubExprs = new Expr*[NumArgs+1];
SubExprs[RECEIVER] = receiver;
@@ -1110,10 +1110,10 @@
SourceLocation LBrac, SourceLocation RBrac,
Expr **ArgExprs, unsigned nargs)
: Expr(ObjCMessageExprClass, retType), SelName(selInfo),
- MethodProto(mproto), ClassName(clsName) {
+ MethodProto(mproto) {
NumArgs = nargs;
SubExprs = new Expr*[NumArgs+1];
- SubExprs[RECEIVER] = 0;
+ SubExprs[RECEIVER] = (Expr*) ((uintptr_t) clsName | 0x1);
if (NumArgs) {
for (unsigned i = 0; i != NumArgs; ++i)
SubExprs[i+ARGS_START] = static_cast<Expr *>(ArgExprs[i]);
@@ -1122,7 +1122,6 @@
RBracloc = RBrac;
}
-
bool ChooseExpr::isConditionTrue(ASTContext &C) const {
llvm::APSInt CondVal(32);
bool IsConst = getCond()->isIntegerConstantExpr(CondVal, C);
@@ -1397,8 +1396,8 @@
}
// ObjCMessageExpr
-Stmt::child_iterator ObjCMessageExpr::child_begin() {
- return reinterpret_cast<Stmt**>(&SubExprs[0]);
+Stmt::child_iterator ObjCMessageExpr::child_begin() {
+ return reinterpret_cast<Stmt**>(&SubExprs[ getReceiver() ? 0 : ARGS_START ]);
}
Stmt::child_iterator ObjCMessageExpr::child_end() {
return reinterpret_cast<Stmt**>(&SubExprs[getNumArgs()+ARGS_START]);
Modified: cfe/trunk/lib/AST/StmtDumper.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/StmtDumper.cpp?rev=50528&r1=50527&r2=50528&view=diff
==============================================================================
--- cfe/trunk/lib/AST/StmtDumper.cpp (original)
+++ cfe/trunk/lib/AST/StmtDumper.cpp Thu May 1 12:26:20 2008
@@ -428,6 +428,8 @@
void StmtDumper::VisitObjCMessageExpr(ObjCMessageExpr* Node) {
DumpExpr(Node);
fprintf(F, " selector=%s", Node->getSelector().getName().c_str());
+ IdentifierInfo* clsName = Node->getClassName();
+ if (clsName) fprintf(F, " class=%s", clsName->getName());
}
void StmtDumper::VisitObjCEncodeExpr(ObjCEncodeExpr *Node) {
Modified: cfe/trunk/lib/AST/StmtSerialization.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/StmtSerialization.cpp?rev=50528&r1=50527&r2=50528&view=diff
==============================================================================
--- cfe/trunk/lib/AST/StmtSerialization.cpp (original)
+++ cfe/trunk/lib/AST/StmtSerialization.cpp Thu May 1 12:26:20 2008
@@ -181,6 +181,9 @@
case ObjCIvarRefExprClass:
return ObjCIvarRefExpr::CreateImpl(D, C);
+ case ObjCMessageExprClass:
+ return ObjCMessageExpr::CreateImpl(D, C);
+
case ObjCSelectorExprClass:
return ObjCSelectorExpr::CreateImpl(D, C);
@@ -190,9 +193,9 @@
//==--------------------------------------==//
// C++
//==--------------------------------------==//
- case CXXDefaultArgExprClass:
- return CXXDefaultArgExpr::CreateImpl(D, C);
+ case CXXDefaultArgExprClass:
+ return CXXDefaultArgExpr::CreateImpl(D, C);
}
}
@@ -327,7 +330,7 @@
S.Emit(getType());
S.Emit(RParenLoc);
S.EmitInt(NumArgs);
- S.BatchEmitOwnedPtrs(NumArgs+1,SubExprs);
+ S.BatchEmitOwnedPtrs(NumArgs+1, SubExprs);
}
CallExpr* CallExpr::CreateImpl(Deserializer& D, ASTContext& C) {
@@ -984,6 +987,58 @@
return dr;
}
+void ObjCMessageExpr::EmitImpl(Serializer& S) const {
+ S.EmitBool(getReceiver() ? true : false);
+ S.Emit(getType());
+ S.Emit(SelName);
+ S.Emit(LBracloc);
+ S.Emit(RBracloc);
+ S.EmitInt(NumArgs);
+ S.EmitPtr(MethodProto);
+
+ if (getReceiver())
+ S.BatchEmitOwnedPtrs(NumArgs+1, SubExprs);
+ else {
+ S.EmitPtr(getClassName());
+ S.BatchEmitOwnedPtrs(NumArgs, &SubExprs[ARGS_START]);
+ }
+}
+
+ObjCMessageExpr* ObjCMessageExpr::CreateImpl(Deserializer& D, ASTContext& C) {
+ bool isReceiver = D.ReadBool();
+ QualType t = QualType::ReadVal(D);
+ Selector S = Selector::ReadVal(D);
+ SourceLocation L = SourceLocation::ReadVal(D);
+ SourceLocation R = SourceLocation::ReadVal(D);
+
+ // Construct an array for the subexpressions.
+ unsigned NumArgs = D.ReadInt();
+ Expr** SubExprs = new Expr*[NumArgs+1];
+
+ // Construct the ObjCMessageExpr object using the special ctor.
+ ObjCMessageExpr* ME = new ObjCMessageExpr(S, t, L, R, SubExprs, NumArgs);
+
+ // Read in the MethodProto. Read the instance variable directly
+ // allows it to be backpatched.
+ D.ReadPtr(ME->MethodProto);
+
+ // Now read in the arguments.
+
+ if (isReceiver)
+ D.BatchReadOwnedPtrs(NumArgs+1, SubExprs, C);
+ else {
+ // Read the pointer for ClassName. The Deserializer will handle the
+ // bit-mangling automatically.
+ SubExprs[RECEIVER] = (Expr*) ((uintptr_t) 0x1);
+ D.ReadUIntPtr((uintptr_t&) SubExprs[RECEIVER]);
+
+ // Read the arguments.
+ D.BatchReadOwnedPtrs(NumArgs, &SubExprs[ARGS_START], C);
+ }
+
+ return ME;
+}
+
void ObjCSelectorExpr::EmitImpl(Serializer& S) const {
S.Emit(AtLoc);
S.Emit(RParenLoc);
More information about the cfe-commits
mailing list