Commit 16201fd3 authored by Maximilien Colange's avatar Maximilien Colange

Extend parsing capabilities: compound assignments (+=, -=, ...) are now properly understood.

parent aeeefb7c
......@@ -359,11 +359,54 @@ make_query(const expression_t &query)
CAMLreturn(result);
}
// transforms an assignment 'e @= f' into 'e = e @ f'
// where @ is one of +,-,*,/
expression_t
normalize_assignment(const expression_t &update)
{
switch (update.getKind())
{
case Constants::ASSPLUS:
case Constants::ASSMINUS:
case Constants::ASSMULT:
case Constants::ASSDIV:
{
expression_t new_rhs;
Constants::kind_t op;
switch (update.getKind())
{
case Constants::ASSPLUS:
op = Constants::PLUS;
break;
case Constants::ASSMINUS:
op = Constants::MINUS;
break;
case Constants::ASSMULT:
op = Constants::MULT;
break;
case Constants::ASSDIV:
op = Constants::DIV;
break;
default: // cannot happen
assert(false);
throw "cannot happen";
}
new_rhs = expression_t::createBinary(op, update[0], update[1]);
return expression_t::createBinary(Constants::ASSIGN, update[0], new_rhs);
}
default:
return update;
}
}
extern "C" CAMLprim value
make_update(value process, const expression_t &update)
make_update(value process, const expression_t &u)
{
CAMLparam1(process);
CAMLlocal4(result, lhs, rhs, tmp);
// remove compound assignments (+=, -=, *=, /=)
expression_t update = normalize_assignment(u);
result = caml_callback(*caml_named_value("cb_empty_list"), Val_unit);
switch (update.getKind())
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment