Unify the implementation of getLValueIvar and getLValueField of store managers.

llvm-svn: 95535
This commit is contained in:
Zhongxing Xu 2010-02-08 07:58:06 +00:00
parent 08515a5242
commit f7f0cdc517
5 changed files with 45 additions and 124 deletions

View File

@ -102,9 +102,13 @@ public:
return loc::MemRegionVal(MRMgr.getCompoundLiteralRegion(CL, LC));
}
virtual SVal getLValueIvar(const ObjCIvarDecl* decl, SVal base) = 0;
virtual SVal getLValueIvar(const ObjCIvarDecl* decl, SVal base) {
return getLValueFieldOrIvar(decl, base);
}
virtual SVal getLValueField(const FieldDecl* D, SVal Base) = 0;
virtual SVal getLValueField(const FieldDecl* D, SVal Base) {
return getLValueFieldOrIvar(D, Base);
}
virtual SVal getLValueElement(QualType elementType, SVal offset, SVal Base)=0;
@ -195,6 +199,9 @@ protected:
/// as another region.
SVal CastRetrievedVal(SVal val, const TypedRegion *R, QualType castTy,
bool performTestOnly = true);
private:
SVal getLValueFieldOrIvar(const Decl* D, SVal Base);
};
// FIXME: Do we still need this?

View File

@ -70,8 +70,6 @@ public:
return store;
}
SVal getLValueIvar(const ObjCIvarDecl* D, SVal Base);
SVal getLValueField(const FieldDecl *D, SVal Base);
SVal getLValueElement(QualType elementType, SVal Offset, SVal Base);
/// ArrayToPointer - Used by GRExprEngine::VistCast to handle implicit
@ -113,52 +111,6 @@ StoreManager* clang::CreateBasicStoreManager(GRStateManager& StMgr) {
return new BasicStoreManager(StMgr);
}
SVal BasicStoreManager::getLValueIvar(const ObjCIvarDecl* D, SVal Base) {
if (Base.isUnknownOrUndef())
return Base;
Loc BaseL = cast<Loc>(Base);
if (isa<loc::MemRegionVal>(BaseL)) {
const MemRegion *BaseR = cast<loc::MemRegionVal>(BaseL).getRegion();
return ValMgr.makeLoc(MRMgr.getObjCIvarRegion(D, BaseR));
}
return UnknownVal();
}
SVal BasicStoreManager::getLValueField(const FieldDecl* D, SVal Base) {
if (Base.isUnknownOrUndef())
return Base;
Loc BaseL = cast<Loc>(Base);
const MemRegion* BaseR = 0;
switch(BaseL.getSubKind()) {
case loc::GotoLabelKind:
return UndefinedVal();
case loc::MemRegionKind:
BaseR = cast<loc::MemRegionVal>(BaseL).getRegion();
break;
case loc::ConcreteIntKind:
// While these seem funny, this can happen through casts.
// FIXME: What we should return is the field offset. For example,
// add the field offset to the integer value. That way funny things
// like this work properly: &(((struct foo *) 0xa)->f)
return Base;
default:
assert ("Unhandled Base.");
return Base;
}
return ValMgr.makeLoc(MRMgr.getFieldRegion(D, BaseR));
}
SVal BasicStoreManager::getLValueElement(QualType elementType,
SVal Offset, SVal Base) {

View File

@ -42,13 +42,6 @@ public:
return 0;
}
SVal getLValueVar(const VarDecl *VD, const LocationContext *LC) {
return loc::MemRegionVal(MRMgr.getVarRegion(VD, LC));
}
SVal getLValueString(const StringLiteral* sl);
SVal getLValueIvar(const ObjCIvarDecl* decl, SVal base);
SVal getLValueField(const FieldDecl* D, SVal Base);
SVal getLValueElement(QualType elementType, SVal offset, SVal Base);
SVal ArrayToPointer(Loc Array);
Store RemoveDeadBindings(Store store, Stmt* Loc, SymbolReaper& SymReaper,
@ -133,18 +126,6 @@ Store FlatStoreManager::BindCompoundLiteral(Store store,
return store;
}
SVal FlatStoreManager::getLValueString(const StringLiteral* sl) {
return UnknownVal();
}
SVal FlatStoreManager::getLValueIvar(const ObjCIvarDecl* decl, SVal base) {
return UnknownVal();
}
SVal FlatStoreManager::getLValueField(const FieldDecl* D, SVal Base) {
return UnknownVal();
}
SVal FlatStoreManager::getLValueElement(QualType elementType, SVal offset,
SVal Base) {
return UnknownVal();

View File

@ -232,12 +232,6 @@ public:
/// the value is not specified.
Store setImplicitDefaultValue(Store store, const MemRegion *R, QualType T);
SVal getLValueIvar(const ObjCIvarDecl* D, SVal Base);
SVal getLValueField(const FieldDecl* D, SVal Base);
SVal getLValueFieldOrIvar(const Decl* D, SVal Base);
SVal getLValueElement(QualType elementType, SVal Offset, SVal Base);
@ -658,55 +652,6 @@ Store RegionStoreManager::InvalidateRegions(Store store,
StateMgr.getValueManager());
}
//===----------------------------------------------------------------------===//
// getLValueXXX methods.
//===----------------------------------------------------------------------===//
SVal RegionStoreManager::getLValueIvar(const ObjCIvarDecl* D, SVal Base) {
return getLValueFieldOrIvar(D, Base);
}
SVal RegionStoreManager::getLValueField(const FieldDecl* D, SVal Base) {
return getLValueFieldOrIvar(D, Base);
}
SVal RegionStoreManager::getLValueFieldOrIvar(const Decl* D, SVal Base) {
if (Base.isUnknownOrUndef())
return Base;
Loc BaseL = cast<Loc>(Base);
const MemRegion* BaseR = 0;
switch (BaseL.getSubKind()) {
case loc::MemRegionKind:
BaseR = cast<loc::MemRegionVal>(BaseL).getRegion();
break;
case loc::GotoLabelKind:
// These are anormal cases. Flag an undefined value.
return UndefinedVal();
case loc::ConcreteIntKind:
// While these seem funny, this can happen through casts.
// FIXME: What we should return is the field offset. For example,
// add the field offset to the integer value. That way funny things
// like this work properly: &(((struct foo *) 0xa)->f)
return Base;
default:
assert(0 && "Unhandled Base.");
return Base;
}
// NOTE: We must have this check first because ObjCIvarDecl is a subclass
// of FieldDecl.
if (const ObjCIvarDecl *ID = dyn_cast<ObjCIvarDecl>(D))
return loc::MemRegionVal(MRMgr.getObjCIvarRegion(ID, BaseR));
return loc::MemRegionVal(MRMgr.getFieldRegion(cast<FieldDecl>(D), BaseR));
}
SVal RegionStoreManager::getLValueElement(QualType elementType, SVal Offset,
SVal Base) {

View File

@ -234,3 +234,39 @@ Store StoreManager::InvalidateRegions(Store store,
return store;
}
SVal StoreManager::getLValueFieldOrIvar(const Decl* D, SVal Base) {
if (Base.isUnknownOrUndef())
return Base;
Loc BaseL = cast<Loc>(Base);
const MemRegion* BaseR = 0;
switch (BaseL.getSubKind()) {
case loc::MemRegionKind:
BaseR = cast<loc::MemRegionVal>(BaseL).getRegion();
break;
case loc::GotoLabelKind:
// These are anormal cases. Flag an undefined value.
return UndefinedVal();
case loc::ConcreteIntKind:
// While these seem funny, this can happen through casts.
// FIXME: What we should return is the field offset. For example,
// add the field offset to the integer value. That way funny things
// like this work properly: &(((struct foo *) 0xa)->f)
return Base;
default:
assert(0 && "Unhandled Base.");
return Base;
}
// NOTE: We must have this check first because ObjCIvarDecl is a subclass
// of FieldDecl.
if (const ObjCIvarDecl *ID = dyn_cast<ObjCIvarDecl>(D))
return loc::MemRegionVal(MRMgr.getObjCIvarRegion(ID, BaseR));
return loc::MemRegionVal(MRMgr.getFieldRegion(cast<FieldDecl>(D), BaseR));
}