Vl-expr-increwrite-aux
Core routine for eliminating increment, decrement, and assignment
expressions. Doesn't try to defend against ambiguities.
- Signature
(vl-expr-increwrite-aux x pre post loc) → (mv new-x pre post)
- Arguments
- x — Expression to rewrite. May contain increments, decrements, or
assignment expressions.
Guard (vl-expr-p x).
- pre — Accumulator. List of assignment statements that should be done
"before" the rewritten expression. Backwards from the order
in which they should occur. This is subtle, see below.
Guard (vl-stmtlist-p pre).
- post — Accumulator. List of assignment statements that should be done
"after" the rewritten expression. Order is probably not
important assuming no ambiguities.
Guard (vl-stmtlist-p post).
- loc — Location to use for new assignments.
Guard (vl-location-p loc).
- Returns
- new-x — Rewritten version of x, free of increment, decrement, and
assignment operators. Equivalent to x assuming that:
(1) the pre-increment stuff is done first, (2) the
post-increment stuff is done afterwards, and (3) there are no
ambiguities.
Type (vl-expr-p new-x).
- pre — Type (vl-stmtlist-p pre).
- post — Type (vl-stmtlist-p post).
Note that the ordering of pre/post is subtle. These are true
accumulators. They need to be reversed and then processed in the
resulting order. This is important to correctly handle things
like:
lhs1 = (a=(b=(c=0)));
In particular, we first recur down all the way to the (c=0)
term and cons that assignment onto PRE. Then as we unwind we cons
(b=c) onto PRE, and then finally (a=b). So, the resulting
PRE assignments we produce are in backwards order, and they need to
be reversed before we use them.
Note that all fancy assignment-expression operators like +=,
*=, etc., as well as the ordinary = operator and act like
pre-increment operators, i.e., they act like ++a instead of
a++, and hence contribute to the list of PRE assignments. So
the situation for
lhs2 = (a += (b *= (c = 0))) ;
is much like the above: we push onto PRE first c=0, then
b=b*c, then finally a=a+b, and it is critical that these
be processed in the correct order.
The only post operators are a++ and a--. These can't
be chained together in the same way as the pre-operators, so it
seems unlikely that the order really matters. For instance, if we
have an expression like:
lhs3 = a++ * b++ * c++;
then it's fine to do the post-increments in any order.