diff options
author | Marius Kintel <marius@kintel.net> | 2013-11-15 20:34:42 (GMT) |
---|---|---|
committer | Marius Kintel <marius@kintel.net> | 2013-11-15 20:34:42 (GMT) |
commit | 022f80e87b1df5af489414a01bf2b5bcef1c3acd (patch) | |
tree | d20c8d9df56f129880df6426c0f885479ebc014a /src/control.cc | |
parent | af8359993a6dfffed8f57bc5605f2ca77a353ffa (diff) | |
parent | f46bd3788f75e691b65aaf0e4ffb1db1029ef717 (diff) |
Merge pull request #542 from t-paul/issue500
Allow for statement with negative step value.
Diffstat (limited to 'src/control.cc')
-rw-r--r-- | src/control.cc | 24 |
1 files changed, 13 insertions, 11 deletions
diff --git a/src/control.cc b/src/control.cc index 10aadf0..d5f664e 100644 --- a/src/control.cc +++ b/src/control.cc @@ -78,12 +78,14 @@ void ControlModule::for_eval(AbstractNode &node, const ModuleInstantiation &inst Context c(ctx); if (it_values.type() == Value::RANGE) { Value::RangeType range = it_values.toRange(); - range.normalize(); - if (range.nbsteps()<10000) { - for (double i = range.begin; i <= range.end; i += range.step) { - c.set_variable(it_name, Value(i)); - for_eval(node, inst, l+1, &c, evalctx); - } + uint32_t steps = range.nbsteps(); + if (steps >= 10000) { + PRINTB("WARNING: Bad range parameter in for statement: too many elements (%lu).", steps); + } else { + for (Value::RangeType::iterator it = range.begin();it != range.end();it++) { + c.set_variable(it_name, Value(*it)); + for_eval(node, inst, l+1, &c, evalctx); + } } } else if (it_values.type() == Value::VECTOR) { @@ -227,13 +229,13 @@ AbstractNode *ControlModule::instantiate(const Context* /*ctx*/, const ModuleIns else if (value.type() == Value::RANGE) { AbstractNode* node = new AbstractNode(inst); Value::RangeType range = value.toRange(); - range.normalize(); - if (range.nbsteps()>=10000) { - PRINTB("WARNING: Bad range parameter for children: too many elements (%d).", (int)((range.begin-range.end)/range.step)); + uint32_t steps = range.nbsteps(); + if (steps >= 10000) { + PRINTB("WARNING: Bad range parameter for children: too many elements (%lu).", steps); return NULL; } - for (double i = range.begin; i <= range.end; i += range.step) { - AbstractNode* childnode = getChild(Value(i),modulectx); // with error cases + for (Value::RangeType::iterator it = range.begin();it != range.end();it++) { + AbstractNode* childnode = getChild(Value(*it),modulectx); // with error cases if (childnode==NULL) continue; // error node->children.push_back(childnode); } |