SCI: Simplify SegManager::findObjectByName
svn-id: r50548
This commit is contained in:
parent
6c6d8b3fb3
commit
e309f05162
1 changed files with 36 additions and 56 deletions
|
@ -263,78 +263,58 @@ const char *SegManager::getObjectName(reg_t pos) {
|
||||||
}
|
}
|
||||||
|
|
||||||
reg_t SegManager::findObjectByName(const Common::String &name, int index) {
|
reg_t SegManager::findObjectByName(const Common::String &name, int index) {
|
||||||
reg_t retVal = NULL_REG;
|
Common::Array<reg_t> result;
|
||||||
|
uint i;
|
||||||
|
|
||||||
// Now all values are available; iterate over all objects.
|
// Now all values are available; iterate over all objects.
|
||||||
int timesFound = 0;
|
for (i = 0; i < _heap.size(); i++) {
|
||||||
for (uint i = 0; i < _heap.size(); i++) {
|
const SegmentObj *mobj = _heap[i];
|
||||||
SegmentObj *mobj = _heap[i];
|
|
||||||
int idx = 0;
|
|
||||||
int max_index = 0;
|
|
||||||
ObjMap::iterator it;
|
|
||||||
Script *scr = 0;
|
|
||||||
CloneTable *ct = 0;
|
|
||||||
|
|
||||||
if (mobj) {
|
if (!mobj)
|
||||||
if (mobj->getType() == SEG_TYPE_SCRIPT) {
|
continue;
|
||||||
scr = (Script *)mobj;
|
|
||||||
max_index = scr->_objects.size();
|
|
||||||
it = scr->_objects.begin();
|
|
||||||
} else if (mobj->getType() == SEG_TYPE_CLONES) {
|
|
||||||
ct = (CloneTable *)mobj;
|
|
||||||
max_index = ct->_table.size();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// It's a script or a clone table, scan all objects in it
|
reg_t objpos = make_reg(i, 0);
|
||||||
for (; idx < max_index; ++idx) {
|
|
||||||
const Object *obj = NULL;
|
|
||||||
reg_t objpos;
|
|
||||||
objpos.offset = 0;
|
|
||||||
objpos.segment = i;
|
|
||||||
|
|
||||||
if (mobj->getType() == SEG_TYPE_SCRIPT) {
|
if (mobj->getType() == SEG_TYPE_SCRIPT) {
|
||||||
obj = &(it->_value);
|
// It's a script, scan all objects in it
|
||||||
objpos.offset = obj->getPos().offset;
|
const Script *scr = (const Script *)mobj;
|
||||||
++it;
|
for (ObjMap::const_iterator it = scr->_objects.begin(); it != scr->_objects.end(); ++it) {
|
||||||
|
objpos.offset = it->_value.getPos().offset;
|
||||||
|
if (name == getObjectName(objpos))
|
||||||
|
result.push_back(objpos);
|
||||||
|
}
|
||||||
} else if (mobj->getType() == SEG_TYPE_CLONES) {
|
} else if (mobj->getType() == SEG_TYPE_CLONES) {
|
||||||
|
// It's clone table, scan all objects in it
|
||||||
|
const CloneTable *ct = (const CloneTable *)mobj;
|
||||||
|
for (uint idx = 0; idx < ct->_table.size(); ++idx) {
|
||||||
if (!ct->isValidEntry(idx))
|
if (!ct->isValidEntry(idx))
|
||||||
continue;
|
continue;
|
||||||
obj = &(ct->_table[idx]);
|
|
||||||
objpos.offset = idx;
|
objpos.offset = idx;
|
||||||
|
if (name == getObjectName(objpos))
|
||||||
|
result.push_back(objpos);
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *objname = getObjectName(objpos);
|
|
||||||
if (name == objname) {
|
|
||||||
// Found a match!
|
|
||||||
if ((index < 0) && (timesFound > 0)) {
|
|
||||||
if (timesFound == 1) {
|
|
||||||
// First time we realized the ambiguity
|
|
||||||
printf("Ambiguous:\n");
|
|
||||||
printf(" %3x: [%04x:%04x] %s\n", 0, PRINT_REG(retVal), name.c_str());
|
|
||||||
}
|
|
||||||
printf(" %3x: [%04x:%04x] %s\n", timesFound, PRINT_REG(objpos), name.c_str());
|
|
||||||
}
|
|
||||||
if (index < 0 || timesFound == index)
|
|
||||||
retVal = objpos;
|
|
||||||
++timesFound;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
if (result.empty())
|
||||||
|
|
||||||
if (!timesFound)
|
|
||||||
return NULL_REG;
|
return NULL_REG;
|
||||||
|
|
||||||
if (timesFound > 1 && index < 0) {
|
if (result.size() > 1) {
|
||||||
|
printf("Ambiguous:\n");
|
||||||
|
for (i = 0; i < result.size(); i++)
|
||||||
|
printf(" %3x: [%04x:%04x] %s\n", i, PRINT_REG(result[i]), name.c_str());
|
||||||
|
if (index < 0) {
|
||||||
printf("Ambiguous: Aborting.\n");
|
printf("Ambiguous: Aborting.\n");
|
||||||
return NULL_REG; // Ambiguous
|
return NULL_REG; // Ambiguous
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (timesFound <= index)
|
if (index < 0)
|
||||||
|
return result[0];
|
||||||
|
else if (result.size() <= (uint)index)
|
||||||
return NULL_REG; // Not found
|
return NULL_REG; // Not found
|
||||||
|
return result[index];
|
||||||
return retVal;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// validate the seg
|
// validate the seg
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue