From: Bob Wilson <bwilson@shasta.Stanford.EDU>
Date: Thu, 29 Sep 94 20:41:44 PDT
Subject: Re: tree_block
Message-Id: <199409300341.UAA17480@shasta.Stanford.EDU>


> I have a problem (once again). I want to take a specific part of a procedure,
> and make a tree_block of it. Something like this:
> 
>                            mrk
>    mrk                     BLOCK
>    tree_node 1               tree_node 1
>    tree_node 2               tree_node 2
>      .                         .
>      .             --->        .
>      .                         .
>    tree_node (n-1)           tree_node (n-1)
>    tree_node n               tree_node n
>    mrk                     BLOCK END
>                            mrk
> 
> The block should then become the `IF THEN' part of an IF.
> 
> All I have tried has ended in one of two cases:
> 
>  1. If I clone the code, I get a tree_block with the right tree_nodes,
>     but labels in the block are renamed.
> 
>  2. If I have made no clone, then all goes wrong with sym_tabs and parent-
>     pointers.
> 
> What can I do?

If you really need to make a tree_block, then do as Chris suggested.
However, unless I'm missing something, you may not even need to make
a tree_block.  The THEN part of an IF is just a tree_node_list, so
unless you are moving the code to another scope or adding new symbols
that you do not want to be visible outside the THEN, you can just move
the tree_nodes to the THEN tree_node_list.

--Bob


From: Chris Wilson <cwilson@CS.Stanford.EDU>
Date: Thu, 29 Sep 94 20:27:34 PDT
Subject: Re: tree_block
Message-Id: <CMM.0.90.4.780895654.cwilson@Xenon.Stanford.EDU>


> Hi !
> 
> I have a problem (once again). I want to take a specific part of a procedure,
> and make a tree_block of it. Something like this:
> 
>                            mrk
>    mrk                     BLOCK
>    tree_node 1               tree_node 1
>    tree_node 2               tree_node 2
>      .                         .
>      .             --->        .
>      .                         .
>    tree_node (n-1)           tree_node (n-1)
>    tree_node n               tree_node n
>    mrk                     BLOCK END
>                            mrk
> 
> The block should then become the `IF THEN' part of an IF.
> 
> All I have tried has ended in one of two cases:
> 
>  1. If I clone the code, I get a tree_block with the right tree_nodes,
>     but labels in the block are renamed.
> 
>  2. If I have made no clone, then all goes wrong with sym_tabs and parent-
>     pointers.
> 
> What can I do?

The problem that comes up with number 2 above is that you have to be
careful about parent pointers of block symbol tables.  All other
pointers should be fine.

One thing you could do is create the new tree_block, then append() all
the tree nodes to its body list.  After that, look at the parent
symbol table of the symbol table for the new tree_block.  Go through
that symbol table's children() list.  All the children() should be
block symbol tables.  For each such block symbol table, look at its
block and follow parent pointers along tree_nodes to see if it is
somewhere under the newly created tree_block.  If it is, remove that
symbol table from its old parent symbol table and add it as a child of
the new block symbol table.

        --Chris