From 574dee8e1f57f126fc4e56e4e8ab839548a990a9 Mon Sep 17 00:00:00 2001 From: Max Horn Date: Fri, 8 May 2009 09:54:24 +0000 Subject: SCI: Got rid of last traces of class SegInterface svn-id: r40377 --- engines/sci/engine/gc.cpp | 19 +---- engines/sci/engine/seg_manager.cpp | 144 ++++--------------------------------- engines/sci/engine/seg_manager.h | 42 ----------- 3 files changed, 16 insertions(+), 189 deletions(-) diff --git a/engines/sci/engine/gc.cpp b/engines/sci/engine/gc.cpp index 610ed853af..7487e7a0c6 100644 --- a/engines/sci/engine/gc.cpp +++ b/engines/sci/engine/gc.cpp @@ -75,18 +75,10 @@ void add_outgoing_refs(void *refcon, reg_t addr) { reg_t_hash_map *find_all_used_references(EngineState *s) { SegManager *sm = s->seg_manager; - Common::Array interfaces; reg_t_hash_map *normal_map = NULL; WorklistManager wm; uint i; - interfaces.resize(sm->_heap.size()); - for (i = 1; i < sm->_heap.size(); i++) - if (sm->_heap[i] == NULL) - interfaces[i] = NULL; - else - interfaces[i] = sm->getSegInterface(i); - // Initialise // Init: Registers wm.push(s->r_acc); @@ -121,9 +113,9 @@ reg_t_hash_map *find_all_used_references(EngineState *s) { // Init: Explicitly loaded scripts for (i = 1; i < sm->_heap.size(); i++) - if (interfaces[i] - && interfaces[i]->getType() == MEM_OBJ_SCRIPT) { - Script *script = (Script *)(interfaces[i]->getMobj()); + if (sm->_heap[i] + && sm->_heap[i]->getType() == MEM_OBJ_SCRIPT) { + Script *script = (Script *)sm->_heap[i]; if (script->lockers) { // Explicitly loaded? int obj_nr; @@ -158,11 +150,6 @@ reg_t_hash_map *find_all_used_references(EngineState *s) { // Normalise normal_map = normalise_hashmap_ptrs(sm, wm._map); - // Cleanup - for (i = 1; i < sm->_heap.size(); i++) - if (interfaces[i]) - delete interfaces[i]; - return normal_map; } diff --git a/engines/sci/engine/seg_manager.cpp b/engines/sci/engine/seg_manager.cpp index 5dc2833773..35c46f5bc0 100644 --- a/engines/sci/engine/seg_manager.cpp +++ b/engines/sci/engine/seg_manager.cpp @@ -1182,46 +1182,12 @@ void SegManager::dbgPrint(const char* msg, void *i) { } -// ------------------- Segment interface ------------------ -SegInterface::SegInterface(SegManager *segmgr, MemObject *mobj, SegmentId segId, MemObjectType typeId) : - _segmgr(segmgr), _mobj(mobj), _segId(segId), _typeId(typeId) { - VERIFY(_mobj->getType() == _typeId, "Invalid MemObject type"); -} - -//-------------------- base -------------------- -class SegInterfaceBase : public SegInterface { -protected: - SegInterfaceBase(SegManager *segmgr, MemObject *mobj, SegmentId segId, MemObjectType typeId) : - SegInterface(segmgr, mobj, segId, typeId) {} -public: -}; - +//-------------------- script -------------------- reg_t Script::findCanonicAddress(SegManager *segmgr, reg_t addr) { addr.offset = 0; return addr; } -void Script::listAllDeallocatable(SegmentId segId, void *param, NoteCallback note) { - (*note)(param, make_reg(segId, 0)); -} - -reg_t DynMem::findCanonicAddress(SegManager *segmgr, reg_t addr) { - addr.offset = 0; - return addr; -} - -void DynMem::listAllDeallocatable(SegmentId segId, void *param, NoteCallback note) { - (*note)(param, make_reg(segId, 0)); -} - - -//-------------------- script -------------------- -class SegInterfaceScript : public SegInterfaceBase { -public: - SegInterfaceScript(SegManager *segmgr, MemObject *mobj, SegmentId segId) : - SegInterfaceBase(segmgr, mobj, segId, MEM_OBJ_SCRIPT) {} -}; - void Script::freeAtAddress(SegManager *segmgr, reg_t addr) { /* sciprintf("[GC] Freeing script "PREG"\n", PRINT_REG(addr)); @@ -1233,6 +1199,10 @@ void Script::freeAtAddress(SegManager *segmgr, reg_t addr) { segmgr->deallocateScript(nr); } +void Script::listAllDeallocatable(SegmentId segId, void *param, NoteCallback note) { + (*note)(param, make_reg(segId, 0)); +} + void Script::listAllOutgoingReferences(EngineState *s, reg_t addr, void *param, NoteCallback note) { Script *script = this; @@ -1259,11 +1229,6 @@ void Script::listAllOutgoingReferences(EngineState *s, reg_t addr, void *param, //-------------------- clones -------------------- -class SegInterfaceClones : public SegInterface { -public: - SegInterfaceClones(SegManager *segmgr, MemObject *mobj, SegmentId segId) : - SegInterface(segmgr, mobj, segId, MEM_OBJ_CLONES) {} -}; template void Table::listAllDeallocatable(SegmentId segId, void *param, NoteCallback note) { @@ -1323,12 +1288,6 @@ void CloneTable::freeAtAddress(SegManager *segmgr, reg_t addr) { //-------------------- locals -------------------- -class SegInterfaceLocals : public SegInterface { -public: - SegInterfaceLocals(SegManager *segmgr, MemObject *mobj, SegmentId segId) : - SegInterface(segmgr, mobj, segId, MEM_OBJ_LOCALS) {} -}; - reg_t LocalVariables::findCanonicAddress(SegManager *segmgr, reg_t addr) { // Reference the owning script SegmentId owner_seg = segmgr->segGet(script_id); @@ -1347,12 +1306,6 @@ void LocalVariables::listAllOutgoingReferences(EngineState *s, reg_t addr, void //-------------------- stack -------------------- -class SegInterfaceStack : public SegInterface { -public: - SegInterfaceStack(SegManager *segmgr, MemObject *mobj, SegmentId segId) : - SegInterface(segmgr, mobj, segId, MEM_OBJ_STACK) {} -}; - reg_t DataStack::findCanonicAddress(SegManager *segmgr, reg_t addr) { addr.offset = 0; return addr; @@ -1366,28 +1319,7 @@ void DataStack::listAllOutgoingReferences(EngineState *s, reg_t addr, void *para } -//-------------------- system strings -------------------- -class SegInterfaceSysStrings : public SegInterface { -public: - SegInterfaceSysStrings(SegManager *segmgr, MemObject *mobj, SegmentId segId) : - SegInterface(segmgr, mobj, segId, MEM_OBJ_SYS_STRINGS) {} -}; - -//-------------------- string frags -------------------- -class SegInterfaceStringFrag : public SegInterface { -public: - SegInterfaceStringFrag(SegManager *segmgr, MemObject *mobj, SegmentId segId) : - SegInterface(segmgr, mobj, segId, MEM_OBJ_STRING_FRAG) {} -}; - - //-------------------- lists -------------------- -class SegInterfaceLists : public SegInterface { -public: - SegInterfaceLists(SegManager *segmgr, MemObject *mobj, SegmentId segId) : - SegInterface(segmgr, mobj, segId, MEM_OBJ_LISTS) {} -}; - void ListTable::freeAtAddress(SegManager *segmgr, reg_t sub_addr) { freeEntry(sub_addr.offset); } @@ -1408,12 +1340,6 @@ void ListTable::listAllOutgoingReferences(EngineState *s, reg_t addr, void *para //-------------------- nodes -------------------- -class SegInterfaceNodes : public SegInterface { -public: - SegInterfaceNodes(SegManager *segmgr, MemObject *mobj, SegmentId segId) : - SegInterface(segmgr, mobj, segId, MEM_OBJ_NODES) {} -}; - void NodeTable::freeAtAddress(SegManager *segmgr, reg_t sub_addr) { freeEntry(sub_addr.offset); } @@ -1435,61 +1361,17 @@ void NodeTable::listAllOutgoingReferences(EngineState *s, reg_t addr, void *para //-------------------- hunk -------------------- -class SegInterfaceHunk : public SegInterface { -public: - SegInterfaceHunk(SegManager *segmgr, MemObject *mobj, SegmentId segId) : - SegInterface(segmgr, mobj, segId, MEM_OBJ_HUNK) {} -}; //-------------------- dynamic memory -------------------- -class SegInterfaceDynMem : public SegInterfaceBase { -public: - SegInterfaceDynMem(SegManager *segmgr, MemObject *mobj, SegmentId segId) : - SegInterfaceBase(segmgr, mobj, segId, MEM_OBJ_DYNMEM) {} -}; - -SegInterface *SegManager::getSegInterface(SegmentId segid) { - if (!check(segid)) - return NULL; // Invalid segment - - SegInterface *retval = NULL; - MemObject *mobj = _heap[segid]; - switch (mobj->getType()) { - case MEM_OBJ_SCRIPT: - retval = new SegInterfaceScript(this, mobj, segid); - break; - case MEM_OBJ_CLONES: - retval = new SegInterfaceClones(this, mobj, segid); - break; - case MEM_OBJ_LOCALS: - retval = new SegInterfaceLocals(this, mobj, segid); - break; - case MEM_OBJ_STACK: - retval = new SegInterfaceStack(this, mobj, segid); - break; - case MEM_OBJ_SYS_STRINGS: - retval = new SegInterfaceSysStrings(this, mobj, segid); - break; - case MEM_OBJ_LISTS: - retval = new SegInterfaceLists(this, mobj, segid); - break; - case MEM_OBJ_NODES: - retval = new SegInterfaceNodes(this, mobj, segid); - break; - case MEM_OBJ_HUNK: - retval = new SegInterfaceHunk(this, mobj, segid); - break; - case MEM_OBJ_DYNMEM: - retval = new SegInterfaceDynMem(this, mobj, segid); - break; - case MEM_OBJ_STRING_FRAG: - retval = new SegInterfaceStringFrag(this, mobj, segid); - break; - default: - error("Improper segment interface for %d", mobj->getType()); - } - return retval; +reg_t DynMem::findCanonicAddress(SegManager *segmgr, reg_t addr) { + addr.offset = 0; + return addr; } +void DynMem::listAllDeallocatable(SegmentId segId, void *param, NoteCallback note) { + (*note)(param, make_reg(segId, 0)); +} + + } // End of namespace Sci diff --git a/engines/sci/engine/seg_manager.h b/engines/sci/engine/seg_manager.h index ddeb09cbf1..75e75d2c90 100644 --- a/engines/sci/engine/seg_manager.h +++ b/engines/sci/engine/seg_manager.h @@ -48,8 +48,6 @@ enum idFlag { (((mgr)._heap[index] && ((mgr)._heap[index]->getType() == MEM_OBJ_SCRIPT || (mgr)._heap[index]->getType() == MEM_OBJ_CLONES))? (mgr)._heap[index] \ : NULL): NULL) -class SegInterface; - class SegManager : public Common::Serializable { public: // Initialize the segment manager @@ -368,13 +366,6 @@ public: byte *dereference(reg_t reg, int *size); - // Segment Interface - - // Retrieves the segment interface to the specified segment - // Parameters: (SegmentId) segid: ID of the segment to look up - // Returns : (SegInterface *): An interface to the specified segment ID, or NULL on error - // The returned interface must be deleted after use - SegInterface *getSegInterface(SegmentId segid); void heapRelocate(EngineState *s, reg_t block); @@ -434,39 +425,6 @@ private: //void sm_gc(EngineState *s); }; - -// 11. Segment interface, primarily for GC - -// TODO: Merge SegInterface and MemObject? -// After all, _mobj->type == _typeId -// and we make very little use of _segmgr (-> could get rid of that). -// Other code would benefit, e.g. the saveload code. -// But note that _mobj->segmgr_id != _segId ! -class SegInterface { -protected: - SegInterface(SegManager *segmgr, MemObject *mobj, SegmentId segId, MemObjectType typeId); - -public: - typedef void (*NoteCallback)(void *param, reg_t addr); - - // Deallocates the segment interface - virtual ~SegInterface() {} - - // Get the memory object - MemObject *getMobj() { return _mobj; } - - // Get the segment type - MemObjectType getType() { return _typeId; } - -protected: - SegManager *_segmgr; - MemObject *_mobj; - SegmentId _segId; - -private: - MemObjectType _typeId; // Segment type -}; - } // End of namespace Sci #endif // SCI_ENGINE_SEG_MANAGER -- cgit v1.2.3