summaryrefslogtreecommitdiff
path: root/src/modcontext.cc
diff options
context:
space:
mode:
authorMarius Kintel <marius@kintel.net>2013-06-13 14:29:39 (GMT)
committerMarius Kintel <marius@kintel.net>2013-06-13 14:29:39 (GMT)
commitb45a93aad28a6764aa9aa56d27ffb716353dc27c (patch)
tree747cffce89dab5a4038d2467dfe2fae339bdb5fe /src/modcontext.cc
parent2a8f188fca3476dd07222585237d3afbc2e7b6be (diff)
Related to #399, reverted assignment evaluation order to be the same as in 2013.01 as the new implementation broke existing scripts. Added some experimental commented out code, which can be used as reference in the future
Diffstat (limited to 'src/modcontext.cc')
-rw-r--r--src/modcontext.cc47
1 files changed, 47 insertions, 0 deletions
diff --git a/src/modcontext.cc b/src/modcontext.cc
index 8799af9..5b48009 100644
--- a/src/modcontext.cc
+++ b/src/modcontext.cc
@@ -17,6 +17,51 @@ ModuleContext::~ModuleContext()
{
}
+// Experimental code. See issue #399
+#if 0
+void ModuleContext::evaluateAssignments(const AssignmentList &assignments)
+{
+ // First, assign all simple variables
+ std::list<std::string> undefined_vars;
+ BOOST_FOREACH(const Assignment &ass, assignments) {
+ Value tmpval = ass.second->evaluate(this);
+ if (tmpval.isUndefined()) undefined_vars.push_back(ass.first);
+ else this->set_variable(ass.first, tmpval);
+ }
+
+ // Variables which couldn't be evaluated in the first pass is attempted again,
+ // to allow for initialization out of order
+
+ boost::unordered_map<std::string, Expression *> tmpass;
+ BOOST_FOREACH (const Assignment &ass, assignments) {
+ tmpass[ass.first] = ass.second;
+ }
+
+ bool changed = true;
+ while (changed) {
+ changed = false;
+ std::list<std::string>::iterator iter = undefined_vars.begin();
+ while (iter != undefined_vars.end()) {
+ std::list<std::string>::iterator curr = iter++;
+ boost::unordered_map<std::string, Expression *>::iterator found = tmpass.find(*curr);
+ if (found != tmpass.end()) {
+ const Expression *expr = found->second;
+ Value tmpval = expr->evaluate(this);
+ // FIXME: it's not enough to check for undefined;
+ // we need to check for any undefined variable in the subexpression
+ // For now, ignore this and revisit the validity and order of variable
+ // assignments later
+ if (!tmpval.isUndefined()) {
+ changed = true;
+ this->set_variable(*curr, tmpval);
+ undefined_vars.erase(curr);
+ }
+ }
+ }
+ }
+}
+#endif
+
void ModuleContext::initializeModule(const class Module &module)
{
this->setVariables(module.definition_arguments, evalctx);
@@ -26,6 +71,8 @@ void ModuleContext::initializeModule(const class Module &module)
BOOST_FOREACH(const Assignment &ass, module.scope.assignments) {
this->set_variable(ass.first, ass.second->evaluate(this));
}
+// Experimental code. See issue #399
+// evaluateAssignments(module.scope.assignments);
}
/*!
contact: Jan Huwald // Impressum