virtual child_iterator child_end();
};
+/// ObjCIsaExpr - Represent X->isa and X.isa (similiar in spirit to MemberExpr).
+class ObjCIsaExpr : public Expr {
+ /// Base - the expression for the base object pointer.
+ Stmt *Base;
+
+ /// IsaMemberLoc - This is the location of the 'isa'.
+ SourceLocation IsaMemberLoc;
+
+ /// IsArrow - True if this is "X->F", false if this is "X.F".
+ bool IsArrow;
+public:
+ ObjCIsaExpr(Expr *base, bool isarrow, SourceLocation l, QualType ty)
+ : Expr(ObjCIsaExprClass, ty),
+ Base(base), IsaMemberLoc(l), IsArrow(isarrow) {}
+
+ /// \brief Build an empty expression.
+ explicit ObjCIsaExpr(EmptyShell Empty) : Expr(ObjCIsaExprClass, Empty) { }
+
+ void setBase(Expr *E) { Base = E; }
+ Expr *getBase() const { return cast<Expr>(Base); }
+
+ bool isArrow() const { return IsArrow; }
+ void setArrow(bool A) { IsArrow = A; }
+
+ /// getMemberLoc - Return the location of the "member", in X->F, it is the
+ /// location of 'F'.
+ SourceLocation getIsaMemberLoc() const { return IsaMemberLoc; }
+ void setIsaMemberLoc(SourceLocation L) { IsaMemberLoc = L; }
+
+ virtual SourceRange getSourceRange() const {
+ return SourceRange(getBase()->getLocStart(), IsaMemberLoc);
+ }
+
+ virtual SourceLocation getExprLoc() const { return IsaMemberLoc; }
+
+ static bool classof(const Stmt *T) {
+ return T->getStmtClass() == ObjCIsaExprClass;
+ }
+ static bool classof(const ObjCIsaExpr *) { return true; }
+
+ // Iterators
+ virtual child_iterator child_begin();
+ virtual child_iterator child_end();
+};
+
} // end namespace clang
#endif
EXPR(ObjCPropertyRefExpr , Expr)
EXPR(ObjCKVCRefExpr , Expr)
EXPR(ObjCSuperExpr , Expr)
+EXPR(ObjCIsaExpr , Expr)
// Clang Extensions.
EXPR(ShuffleVectorExpr , Expr)
inline bool Type::isObjCBuiltinType() const {
return isObjCIdType() || isObjCClassType();
}
-
inline bool Type::isTemplateTypeParmType() const {
return isa<TemplateTypeParmType>(CanonicalType.getUnqualifiedType());
}
EXPR_OBJC_MESSAGE_EXPR,
/// \brief An ObjCSuperExpr record.
EXPR_OBJC_SUPER_EXPR,
-
+ /// \brief An ObjCIsa Expr record.
+ EXPR_OBJC_ISA,
+
/// \brief An ObjCForCollectionStmt record.
STMT_OBJC_FOR_COLLECTION,
/// \brief An ObjCAtCatchStmt record.
Stmt::child_iterator ObjCSuperExpr::child_begin() { return child_iterator(); }
Stmt::child_iterator ObjCSuperExpr::child_end() { return child_iterator(); }
+// ObjCIsaExpr
+Stmt::child_iterator ObjCIsaExpr::child_begin() { return &Base; }
+Stmt::child_iterator ObjCIsaExpr::child_end() { return &Base+1; }
+
// PredefinedExpr
Stmt::child_iterator PredefinedExpr::child_begin() { return child_iterator(); }
Stmt::child_iterator PredefinedExpr::child_end() { return child_iterator(); }
// representing anonymous unions/structs
OS << Node->getMemberDecl()->getNameAsString();
}
+void StmtPrinter::VisitObjCIsaExpr(ObjCIsaExpr *Node) {
+ PrintExpr(Node->getBase());
+ OS << (Node->isArrow() ? "->isa" : ".isa");
+}
+
void StmtPrinter::VisitExtVectorElementExpr(ExtVectorElementExpr *Node) {
PrintExpr(Node->getBase());
OS << ".";
unsigned VisitObjCKVCRefExpr(ObjCKVCRefExpr *E);
unsigned VisitObjCMessageExpr(ObjCMessageExpr *E);
unsigned VisitObjCSuperExpr(ObjCSuperExpr *E);
+ unsigned VisitObjCIsaExpr(ObjCIsaExpr *E);
unsigned VisitObjCForCollectionStmt(ObjCForCollectionStmt *);
unsigned VisitObjCAtCatchStmt(ObjCAtCatchStmt *);
return 1;
}
+unsigned PCHStmtReader::VisitObjCIsaExpr(ObjCIsaExpr *E) {
+ VisitExpr(E);
+ E->setBase(cast<Expr>(StmtStack.back()));
+ E->setIsaMemberLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
+ E->setArrow(Record[Idx++]);
+ return 1;
+}
+
unsigned PCHStmtReader::VisitCastExpr(CastExpr *E) {
VisitExpr(E);
E->setSubExpr(cast<Expr>(StmtStack.back()));
case pch::EXPR_OBJC_SUPER_EXPR:
S = new (Context) ObjCSuperExpr(Empty);
break;
+ case pch::EXPR_OBJC_ISA:
+ S = new (Context) ObjCIsaExpr(Empty);
+ break;
case pch::STMT_OBJC_FOR_COLLECTION:
S = new (Context) ObjCForCollectionStmt(Empty);
break;
void VisitObjCKVCRefExpr(ObjCKVCRefExpr *E);
void VisitObjCMessageExpr(ObjCMessageExpr *E);
void VisitObjCSuperExpr(ObjCSuperExpr *E);
+ void VisitObjCIsaExpr(ObjCIsaExpr *E);
// Objective-C Statements
void VisitObjCForCollectionStmt(ObjCForCollectionStmt *);
Code = pch::EXPR_MEMBER;
}
+void PCHStmtWriter::VisitObjCIsaExpr(ObjCIsaExpr *E) {
+ VisitExpr(E);
+ Writer.WriteSubStmt(E->getBase());
+ Writer.AddSourceLocation(E->getIsaMemberLoc(), Record);
+ Record.push_back(E->isArrow());
+ Code = pch::EXPR_OBJC_ISA;
+}
+
void PCHStmtWriter::VisitCastExpr(CastExpr *E) {
VisitExpr(E);
Writer.WriteSubStmt(E->getSubExpr());
const ObjCObjectPointerType *OPT = BaseType->getAsObjCObjectPointerType();
const ObjCInterfaceType *IFaceT =
OPT ? OPT->getInterfaceType() : BaseType->getAsObjCInterfaceType();
-
if (IFaceT) {
ObjCInterfaceDecl *IDecl = IFaceT->getDecl();
ObjCInterfaceDecl *ClassDeclared;
<< IDecl->getDeclName() << &Member
<< BaseExpr->getSourceRange());
}
- // We don't have an interface. FIXME: deal with ObjC builtin 'id' type.
+ // We have an 'id' type. Rather than fall through, we check if this
+ // is a reference to 'isa'.
+ if (&Member == &Context.Idents.get("isa"))
+ return Owned(new (Context) ObjCIsaExpr(BaseExpr, true, MemberLoc,
+ Context.getObjCIdType()));
}
// Handle properties on 'id' and qualified "id".
if (OpKind == tok::period && (BaseType->isObjCIdType() ||
<< &Member << BaseType);
}
+ // Handle the following exceptional case (*Obj).isa.
+ if (OpKind == tok::period &&
+ BaseType->isSpecificBuiltinType(BuiltinType::ObjCId) &&
+ &Member == &Context.Idents.get("isa"))
+ return Owned(new (Context) ObjCIsaExpr(BaseExpr, false, MemberLoc,
+ Context.getObjCIdType()));
+
// Handle 'field access' to vectors, such as 'V.xx'.
if (BaseType->isExtVectorType()) {
QualType ret = CheckExtVectorComponent(BaseType, OpLoc, Member, MemberLoc);
return SemaRef.ExprError();
}
+Sema::OwningExprResult
+TemplateExprInstantiator::VisitObjCIsaExpr(ObjCIsaExpr *E) {
+ assert(false && "FIXME: Template instantiations for ObjC expressions");
+ return SemaRef.ExprError();
+}
+
Sema::OwningExprResult
Sema::InstantiateExpr(Expr *E, const TemplateArgumentList &TemplateArgs) {
if (!E)
struct objc_class *isa;
} *id;
-@interface Whatever
+@interface NSObject {
+ struct objc_class *isa;
+}
+@end
+@interface Whatever : NSObject
+self;
@end
id x;
- // FIXME: The following needs to compile without error. I will fix this tomorrow (7/15/09). Until I do, we will produce an error.
- [x->isa self]; // expected-error {{member reference base type 'id' is not a structure or union}}
+ [(*x).isa self];
+ [x->isa self];
+
+ Whatever *y;
+
+ // GCC allows this, with the following warning:
+ // instance variable ‘isa’ is @protected; this will be a hard error in the future
+ //
+ // FIXME: see if we can avoid the 2 warnings that follow the error.
+ [(*y).isa self]; // expected-error {{instance variable 'isa' is protected}} \
+ expected-warning{{receiver type 'struct objc_class *' is not 'id' or interface pointer, consider casting it to 'id'}} \
+ expected-warning{{method '-self' not found (return type defaults to 'id')}}
+ [y->isa self]; // expected-error {{instance variable 'isa' is protected}} \
+ expected-warning{{receiver type 'struct objc_class *' is not 'id' or interface pointer, consider casting it to 'id'}} \
+ expected-warning{{method '-self' not found (return type defaults to 'id')}}
}