[phc-general] Why isn't Tree_transform::pre_statement()implemented

Satyam Satyam at satyam.com.ar
Wed Aug 2 16:41:19 CEST 2006


----- Original Message ----- 
From: "Edsko de Vries" <edsko at phpcompiler.org>
>
> Aaah. Please allow me to refer you to tutorial3,
>
> http://www.phpcompiler.org/doc/tutorial3.html
>
> and in particular section "A Subtlety" (towards the end of the tutorial). 
> The
> problem you're experiencing is exactly what I've tried to explain there
> (although perhaps I didn't do a very good job, it *is* indeed a subtlety 
> :-) If
> you still don't understand what's happening after reading that, please do 
> come
> back to me.
>

When I read it I couldn't figure out what was the point.  Now that it 
happened to me I see it.
>
> Yes, as explained in tutorial 3, that is one solution, although the better
> solution is to use a post-transform rather than a pre-transform; but that 
> may
> not be possible, depending on the transform. Also, if you _are_ 
> implementing a
> pre_transform, you don't need to call transform; calling pre_transform is
> enough.
>

Indeed, I thought I needed to pick pre_ because I need to set up something 
before carying on with the transform, but then it proved not enough. 
Actually I have a stack in which I save the state of what I am doing, a 
state that influences what goes after.  Nevertheless, I find that is not 
enough at least in two cases.

For example, in an if, I have to provide the same stack for the expr, the 
iftrue and the iffalse parts.  Right now, I have the problem that in the 
iffalse part I get the stack as set by the iftrue part so I think I would 
have to redefine the children_if method to make a copy of the stack on entry 
and give each branch the same node.  I could pop the stack in the post_ 
method at each step, but I also need to check that the stack ends in the 
same state on each branch even if it gets to different depths.  Same with 
switches.

I'll try that out, though I will also break it into two passes, one to 
analyze what has to be done and make sure everything is consistent, leaving 
information along the tree in the 'attrs' map and then doing the actual 
transformations in the second pass.  Perhaps later I might find that I can 
do the analyzis on the pre_methods and then the transformation on the 
post_methods, but I bumped into a couple of things that I can't get a clear 
image of when trying to do everything at once.

Thanks

Satyam

> Edsko
>
> 




More information about the phc-general mailing list