mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-10 13:06:59 -04:00
Fixed bug in dependency checker that caused it to overwrite variables outside its scope
git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@1063 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
@@ -265,12 +265,22 @@ ScriptValueP Context::makeClosure(const ScriptValueP& fun) {
|
||||
|
||||
size_t Context::openScope() {
|
||||
level += 1;
|
||||
#ifdef _DEBUG
|
||||
scopes.push_back(shadowed.size());
|
||||
assert(scopes.size() == level);
|
||||
#endif
|
||||
return shadowed.size();
|
||||
}
|
||||
void Context::closeScope(size_t scope) {
|
||||
assert(level > 0);
|
||||
assert(scope <= shadowed.size());
|
||||
level -= 1;
|
||||
#ifdef _DEBUG
|
||||
assert(!scopes.empty());
|
||||
assert(scopes.back() == scope);
|
||||
scopes.pop_back();
|
||||
assert(scopes.size() == level);
|
||||
#endif
|
||||
// restore shadowed variables
|
||||
while (shadowed.size() > scope) {
|
||||
variables[shadowed.back().variable] = shadowed.back().value;
|
||||
|
||||
@@ -102,7 +102,11 @@ class Context {
|
||||
/// Number of scopes opened
|
||||
unsigned int level;
|
||||
/// Stack of values
|
||||
vector<ScriptValueP> stack;
|
||||
vector<ScriptValueP> stack;
|
||||
#ifdef _DEBUG
|
||||
/// The opened scopes, for sanity checking
|
||||
vector<size_t> scopes;
|
||||
#endif
|
||||
|
||||
// utility types for dependency analysis
|
||||
struct Jump;
|
||||
|
||||
@@ -159,7 +159,7 @@ ScriptValueP Context::dependencies(const Dependency& dep, const Script& script)
|
||||
}
|
||||
// unify bindings
|
||||
FOR_EACH(v, j->bindings) {
|
||||
unify(variables[v.variable].value, v.value.value);
|
||||
setVariable(v.variable, unified(variables[v.variable].value, v.value.value) );
|
||||
}
|
||||
delete j;
|
||||
}
|
||||
@@ -368,9 +368,8 @@ void Context::getBindings(size_t scope, vector<Binding>& bindings) {
|
||||
}
|
||||
|
||||
void Context::resetBindings(size_t scope) {
|
||||
// same as closeScope()
|
||||
while (shadowed.size() > scope) {
|
||||
variables[shadowed.back().variable] = shadowed.back().value;
|
||||
shadowed.pop_back();
|
||||
}
|
||||
// close and re-open the scope
|
||||
closeScope(scope);
|
||||
size_t same_scope = openScope();
|
||||
assert(scope == same_scope);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user