V4: change variable renumbering algorithm from recursive to iterative.

Replace the recursive calls and subsequent clean-ups by pushing actions
on a to-do stack, and processing that stack in a loop.

Change-Id: I83536e88d400592b6e9f5fda3d795e41711a131a
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
Reviewed-by: Fawzi Mohamed <fawzi.mohamed@digia.com>