- // <summary>
- // This is used by the flow code to hold the `layout' of the flow vector for
- // all locals and all parameters (ie. we create one instance of this class for the
- // locals and another one for the params).
- // </summary>
- public class VariableMap {
- // <summary>
- // The number of variables in the map.
- // </summary>
- public readonly int Count;
-
- // <summary>
- // Total length of the flow vector for this map.
- // <summary>
- public readonly int Length;
-
- VariableInfo[] map;
-
- public VariableMap (Parameters ip)
- {
- Count = ip != null ? ip.Count : 0;
-
- // Dont bother allocating anything!
- if (Count == 0)
- return;
-
- Length = 0;
-
- for (int i = 0; i < Count; i++) {
- Parameter.Modifier mod = ip.ParameterModifier (i);
-
- if ((mod & Parameter.Modifier.OUT) != Parameter.Modifier.OUT)
- continue;
-
- // Dont allocate till we find an out var.
- if (map == null)
- map = new VariableInfo [Count];
-
- map [i] = new VariableInfo (ip.ParameterName (i),
- TypeManager.GetElementType (ip.ParameterType (i)), i, Length);
-
- Length += map [i].Length;
- }
- }
-
- public VariableMap (LocalInfo[] locals)
- : this (null, locals)
- { }
-
- public VariableMap (VariableMap parent, LocalInfo[] locals)
- {
- int offset = 0, start = 0;
- if (parent != null && parent.map != null) {
- offset = parent.Length;
- start = parent.Count;
- }
-
- Count = locals.Length + start;
-
- if (Count == 0)
- return;
-
- map = new VariableInfo [Count];
- Length = offset;
-
- if (parent != null && parent.map != null) {
- parent.map.CopyTo (map, 0);
- }
-
- for (int i = start; i < Count; i++) {
- LocalInfo li = locals [i-start];
-
- if (li.VariableType == null)
- continue;
-
- map [i] = li.VariableInfo = new VariableInfo (li, Length);
- Length += map [i].Length;
- }
- }
-
- // <summary>
- // Returns the VariableInfo for variable @index or null if we don't need to
- // compute assignment info for this variable.
- // </summary>
- public VariableInfo this [int index] {
- get {
- if (map == null)
- return null;
-
- return map [index];
- }
- }
-
- public override string ToString ()
- {
- return String.Format ("VariableMap ({0}:{1})", Count, Length);
- }
- }
-