class TypeDecl;
class TypedefDecl;
class TemplateTypeParmDecl;
-
+ class FieldDecl;
+ class ObjCIvarRefExpr;
+ class ObjCIvarDecl;
+
/// ASTContext - This class holds long-lived AST nodes (such as types and
/// decls) that can be referred to throughout the semantic analysis of a file.
class ASTContext {
llvm::DenseMap<const ObjCInterfaceDecl*,
const RecordDecl*> ASTRecordForInterface;
+ llvm::DenseMap<const ObjCIvarRefExpr*, const FieldDecl*> ASTFieldForIvarRef;
/// BuiltinVaListType - built-in va list type.
/// This is initially null and set by Sema::LazilyCreateBuiltin when
const ASTRecordLayout &getASTObjCInterfaceLayout(const ObjCInterfaceDecl *D);
const RecordDecl *addRecordToClass(const ObjCInterfaceDecl *D);
+ const FieldDecl *getFieldDecl(const ObjCIvarRefExpr *MRef) {
+ llvm::DenseMap<const ObjCIvarRefExpr *, const FieldDecl*>::iterator I
+ = ASTFieldForIvarRef.find(MRef);
+ assert (I != ASTFieldForIvarRef.end() && "Unable to find field_decl");
+ return I->second;
+ }
+ void setFieldDecl(const ObjCInterfaceDecl *OI,
+ const ObjCIvarDecl *Ivar,
+ const ObjCIvarRefExpr *MRef);
//===--------------------------------------------------------------------===//
// Type Operators
//===--------------------------------------------------------------------===//
/// ObjCIvarRefExpr - A reference to an ObjC instance variable.
class ObjCIvarRefExpr : public Expr {
class ObjCIvarDecl *D;
- FieldDecl *FD;
SourceLocation Loc;
Stmt *Base;
bool IsArrow:1; // True if this is "X->F", false if this is "X.F".
bool IsFreeIvar:1; // True if ivar reference has no base (self assumed).
public:
- ObjCIvarRefExpr(ObjCIvarDecl *d, FieldDecl *fd,
+ ObjCIvarRefExpr(ObjCIvarDecl *d,
QualType t, SourceLocation l, Expr *base=0,
bool arrow = false, bool freeIvar = false) :
- Expr(ObjCIvarRefExprClass, t), D(d), FD(fd),
+ Expr(ObjCIvarRefExprClass, t), D(d),
Loc(l), Base(base), IsArrow(arrow),
IsFreeIvar(freeIvar) {}
ObjCIvarDecl *getDecl() { return D; }
- FieldDecl *getFieldDecl() { return FD; }
- const FieldDecl *getFieldDecl() const { return FD; }
const ObjCIvarDecl *getDecl() const { return D; }
virtual SourceRange getSourceRange() const {
return isFreeIvar() ? SourceRange(Loc)
return RD;
}
+/// setFieldDecl - maps a field for the given Ivar reference node.
+//
+void ASTContext::setFieldDecl(const ObjCInterfaceDecl *OI,
+ const ObjCIvarDecl *Ivar,
+ const ObjCIvarRefExpr *MRef) {
+ FieldDecl *FD = (const_cast<ObjCInterfaceDecl *>(OI))->
+ lookupFieldDeclForIvar(*this, Ivar);
+ ASTFieldForIvarRef[MRef] = FD;
+}
+
/// getASTObjcInterfaceLayout - Get or compute information about the layout of
/// the specified Objective C, which indicates its size and ivar
/// position information.
ObjCIvarRefExpr* ObjCIvarRefExpr::CreateImpl(Deserializer& D, ASTContext& C) {
SourceLocation Loc = SourceLocation::ReadVal(D);
QualType T = QualType::ReadVal(D);
- ObjCIvarRefExpr* dr = new ObjCIvarRefExpr(NULL,NULL,T,Loc);
+ ObjCIvarRefExpr* dr = new ObjCIvarRefExpr(NULL,T,Loc);
D.ReadPtr(dr->D,false);
return dr;
}
CVRQualifiers = BaseExpr->getType().getCVRQualifiers();
}
- return EmitLValueForIvar(BaseValue, E->getDecl(), E->getFieldDecl(),
- CVRQualifiers);
+ return EmitLValueForIvar(BaseValue, E->getDecl(),
+ getContext().getFieldDecl(E), CVRQualifiers);
}
LValue
ParmVarDecl *ArgDecl = OMD->getParamDecl(0);
DeclRefExpr Arg(ArgDecl, ArgDecl->getType(), Loc);
ObjCInterfaceDecl *OI = IMP->getClassInterface();
- FieldDecl *FD = OI->lookupFieldDeclForIvar(getContext(), Ivar);
- ObjCIvarRefExpr IvarRef(Ivar, FD, Ivar->getType(), Loc, &Base,
+ ObjCIvarRefExpr IvarRef(Ivar, Ivar->getType(), Loc, &Base,
true, true);
+ getContext().setFieldDecl(OI, Ivar, &IvarRef);
BinaryOperator Assign(&IvarRef, &Arg, BinaryOperator::Assign,
Ivar->getType(), Loc);
EmitStmt(&Assign);
if (SD == 0 || SD->isDefinedOutsideFunctionOrMethod()) {
ObjCInterfaceDecl *IFace = getCurMethodDecl()->getClassInterface();
if (ObjCIvarDecl *IV = IFace->lookupInstanceVariable(II)) {
- FieldDecl *FD = IFace->lookupFieldDeclForIvar(Context, IV);
// FIXME: This should use a new expr for a direct reference, don't turn
// this into Self->ivar, just return a BareIVarExpr or something.
IdentifierInfo &II = Context.Idents.get("self");
ExprResult SelfExpr = ActOnIdentifierExpr(S, Loc, II, false);
- return new ObjCIvarRefExpr(IV, FD, IV->getType(), Loc,
- static_cast<Expr*>(SelfExpr.Val), true, true);
+ ObjCIvarRefExpr *MRef= new ObjCIvarRefExpr(IV, IV->getType(), Loc,
+ static_cast<Expr*>(SelfExpr.Val), true, true);
+ Context.setFieldDecl(IFace, IV, MRef);
+ return MRef;
}
}
// Needed to implement property "super.method" notation.
// (*Obj).ivar.
if (const ObjCInterfaceType *IFTy = BaseType->getAsObjCInterfaceType()) {
if (ObjCIvarDecl *IV = IFTy->getDecl()->lookupInstanceVariable(&Member)) {
- FieldDecl *FD = IFTy->getDecl()->lookupFieldDeclForIvar(Context, IV);
- return new ObjCIvarRefExpr(IV, FD, IV->getType(), MemberLoc, BaseExpr,
- OpKind == tok::arrow);
+ ObjCIvarRefExpr *MRef= new ObjCIvarRefExpr(IV, IV->getType(), MemberLoc,
+ BaseExpr,
+ OpKind == tok::arrow);
+ Context.setFieldDecl(IFTy->getDecl(), IV, MRef);
+ return MRef;
}
return Diag(MemberLoc, diag::err_typecheck_member_reference_ivar)
<< IFTy->getDecl()->getDeclName() << &Member