00001 #ifndef SUIFKERNEL__GROUP_WALKER 00002 #define SUIFKERNEL__GROUP_WALKER 00003 00004 #include "suif_walker.h" 00005 #include "suif_object.h" 00006 00007 #include "common/sparse_vector.h" 00008 #include "common/suif_hash_map.h" 00009 00028 class SelectiveWalker : public SuifWalker { 00029 private: 00030 bool is_visitable(Address address,const MetaClass *_meta) const; 00031 public: 00036 SelectiveWalker(SuifEnv *the_env,const LString &the_type); 00037 00042 Walker::ApplyStatus operator () (SuifObject *x) = 0; 00043 00047 const LString & get_type() const; 00048 private: 00049 const LString type; 00050 }; 00051 00052 /* 00053 * The typeless implementation for the TypeBasedDispatch template. 00054 */ 00055 class TypeBasedDispatchHelper { 00056 SparseVector<void *> _vector; 00057 bool _locked; 00058 public: 00059 TypeBasedDispatchHelper(); 00065 void set_value(const LString &index, void *val); 00073 void *lookup_value(SuifObject *x); 00078 void *get_value(SuifObject *x) const; 00079 }; 00080 00090 template <class T> 00091 class TypeBasedDispatch { 00092 TypeBasedDispatchHelper _helper; 00093 public: 00094 TypeBasedDispatch() {} 00100 void set_value(const LString &index, T val) { 00101 _helper.set_value(index, (void*)val); 00102 } 00103 00111 T lookup_value(SuifObject *x) { 00112 return((T)_helper.lookup_value(x)); 00113 } 00118 T get_value(SuifObject *x) const { 00119 return((T)_helper.get_value(index)); 00120 } 00121 }; 00122 00129 class GroupWalker : public SuifWalker { 00130 TypeBasedDispatch <SelectiveWalker*> *_vector; 00131 protected: 00132 Walker::ApplyStatus operator () (SuifObject *x); 00133 public: 00134 GroupWalker(SuifEnv *the_env); 00135 virtual ~GroupWalker(); 00136 00137 void append_walker(SelectiveWalker &x); 00138 00139 }; 00140 00161 class ReplacingWalker : public GroupWalker { 00162 suif_hash_map<Address,Object *> _map; 00163 public: 00164 ReplacingWalker(SuifEnv *the_env); 00165 virtual bool is_walkable(Address address,bool is_owned, 00166 const MetaClass *_meta); 00167 Walker::ApplyStatus operator () (SuifObject *x); 00168 00173 void add_replacement(Object *from,Object *to); 00174 00177 Object *get_replacement(Object *x) const; 00178 00180 bool get_makes_changes() const; 00181 00185 bool is_changed(Address addr) const; 00186 00188 suif_hash_map<Address,Object *>::iterator get_map_begin() {return _map.begin();} 00189 suif_hash_map<Address,Object *>::iterator get_map_end() {return _map.end();} 00190 suif_hash_map<Address,Object *>::const_iterator get_map_begin() const {return _map.begin();} 00191 suif_hash_map<Address,Object *>::const_iterator get_map_end() const {return _map.end();} 00192 00193 00194 00195 }; 00196 00197 00198 #endif