- //
- // This class is used during the Statement.Clone operation
- // to remap objects that have been cloned.
- //
- // Since blocks are cloned by Block.Clone, we need a way for
- // expressions that must reference the block to be cloned
- // pointing to the new cloned block.
- //
- public class CloneContext {
- Hashtable block_map = new Hashtable ();
- Hashtable variable_map;
-
- public void AddBlockMap (Block from, Block to)
- {
- if (block_map.Contains (from))
- return;
- block_map [from] = to;
- }
-
- public Block LookupBlock (Block from)
- {
- Block result = (Block) block_map [from];
-
- if (result == null){
- result = (Block) from.Clone (this);
- block_map [from] = result;
- }
-
- return result;
- }
-
- ///
- /// Remaps block to cloned copy if one exists.
- ///
- public Block RemapBlockCopy (Block from)
- {
- Block mapped_to = (Block)block_map[from];
- if (mapped_to == null)
- return from;
-
- return mapped_to;
- }
-
- public void AddVariableMap (LocalInfo from, LocalInfo to)
- {
- if (variable_map == null)
- variable_map = new Hashtable ();
-
- if (variable_map.Contains (from))
- return;
- variable_map [from] = to;
- }
-
- public LocalInfo LookupVariable (LocalInfo from)
- {
- LocalInfo result = (LocalInfo) variable_map [from];
-
- if (result == null)
- throw new Exception ("LookupVariable: looking up a variable that has not been registered yet");
-
- return result;
- }
- }
-