Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLEANUP: Remove unnecessary params from findObject #156

Merged
merged 1 commit into from
Apr 3, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 6 additions & 11 deletions core/vm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -565,33 +565,28 @@ class Interpreter {
* with the given field. Call with offset initially set to 0.
*
* \param f The field we're looking for.
* \param curr The root object.
* \param start_from Step over this many leaves first.
* \param counter Return the level of "super" that contained the field.
* \param self Return the new root.
* \returns The first object with the field, or nullptr if it could not be found.
*/
HeapLeafObject *findObject(const Identifier *f, HeapObject *root, HeapObject *curr,
unsigned start_from, unsigned &counter,
HeapObject *&self)
HeapLeafObject *findObject(const Identifier *f, HeapObject *curr,
unsigned start_from, unsigned &counter)
{
if (auto *ext = dynamic_cast<HeapExtendedObject*>(curr)) {
auto *r = findObject(f, root, ext->right, start_from, counter, self);
auto *r = findObject(f, ext->right, start_from, counter);
if (r) return r;
auto *l = findObject(f, root, ext->left, start_from, counter, self);
auto *l = findObject(f, ext->left, start_from, counter);
if (l) return l;
} else {
if (counter >= start_from) {
if (auto *simp = dynamic_cast<HeapSimpleObject*>(curr)) {
auto it = simp->fields.find(f);
if (it != simp->fields.end()) {
self = root;
return simp;
}
} else if (auto *comp = dynamic_cast<HeapComprehensionObject*>(curr)) {
auto it = comp->compValues.find(f);
if (it != comp->compValues.end()) {
self = root;
return comp;
}
}
Expand Down Expand Up @@ -847,8 +842,8 @@ class Interpreter {
const Identifier *f, unsigned offset)
{
unsigned found_at = 0;
HeapObject *self = nullptr;
HeapLeafObject *found = findObject(f, obj, obj, offset, found_at, self);
HeapObject *self = obj;
HeapLeafObject *found = findObject(f, obj, offset, found_at);
if (found == nullptr) {
throw makeError(loc, "Field does not exist: " + encode_utf8(f->name));
}
Expand Down