2 // flowanalyis.cs: The control flow analysis code
5 // Martin Baulig (martin@ximian.com)
7 // (C) 2001, 2002, 2003 Ximian, Inc.
12 using System.Collections;
13 using System.Reflection;
14 using System.Reflection.Emit;
15 using System.Diagnostics;
20 // A new instance of this class is created every time a new block is resolved
21 // and if there's branching in the block's control flow.
23 public abstract class FlowBranching
26 // The type of a FlowBranching.
28 public enum BranchingType : byte {
29 // Normal (conditional or toplevel) block.
49 // The type of one sibling of a branching.
51 public enum SiblingType : byte {
61 // This is used in the control flow analysis code to specify whether the
62 // current code block may return to its enclosing block before reaching
65 public enum FlowReturns : byte {
68 // It can never return.
71 // This means that the block contains a conditional return statement
75 // The code always returns, ie. there's an unconditional return / break
80 public sealed class Reachability
82 FlowReturns returns, breaks, throws, barrier;
84 public FlowReturns Returns {
85 get { return returns; }
87 public FlowReturns Breaks {
88 get { return breaks; }
90 public FlowReturns Throws {
91 get { return throws; }
93 public FlowReturns Barrier {
94 get { return barrier; }
96 public Reachability (FlowReturns returns, FlowReturns breaks,
97 FlowReturns throws, FlowReturns barrier)
99 this.returns = returns;
100 this.breaks = breaks;
101 this.throws = throws;
102 this.barrier = barrier;
105 public Reachability Clone ()
107 return new Reachability (returns, breaks, throws, barrier);
111 // Performs an `And' operation on the FlowReturns status
112 // (for instance, a block only returns Always if all its siblings
115 public static FlowReturns AndFlowReturns (FlowReturns a, FlowReturns b)
117 if (a == FlowReturns.Undefined)
121 case FlowReturns.Never:
122 if (b == FlowReturns.Never)
123 return FlowReturns.Never;
125 return FlowReturns.Sometimes;
127 case FlowReturns.Sometimes:
128 return FlowReturns.Sometimes;
130 case FlowReturns.Always:
131 if (b == FlowReturns.Always)
132 return FlowReturns.Always;
134 return FlowReturns.Sometimes;
137 throw new ArgumentException ();
141 public static FlowReturns OrFlowReturns (FlowReturns a, FlowReturns b)
143 if (a == FlowReturns.Undefined)
147 case FlowReturns.Never:
150 case FlowReturns.Sometimes:
151 if (b == FlowReturns.Always)
152 return FlowReturns.Always;
154 return FlowReturns.Sometimes;
156 case FlowReturns.Always:
157 return FlowReturns.Always;
160 throw new ArgumentException ();
164 public static void And (ref Reachability a, Reachability b, bool do_break)
174 public void And (Reachability b, bool do_break)
177 // `break' does not "break" in a Switch or a LoopBlock
179 bool a_breaks = do_break && AlwaysBreaks;
180 bool b_breaks = do_break && b.AlwaysBreaks;
182 bool a_has_barrier, b_has_barrier;
185 // This is the normal case: the code following a barrier
186 // cannot be reached.
188 a_has_barrier = AlwaysHasBarrier;
189 b_has_barrier = b.AlwaysHasBarrier;
192 // Special case for Switch and LoopBlocks: we can reach the
193 // code after the barrier via the `break'.
195 a_has_barrier = !AlwaysBreaks && AlwaysHasBarrier;
196 b_has_barrier = !b.AlwaysBreaks && b.AlwaysHasBarrier;
199 bool a_unreachable = a_breaks || AlwaysThrows || a_has_barrier;
200 bool b_unreachable = b_breaks || b.AlwaysThrows || b_has_barrier;
203 // Do all code paths always return ?
206 if (b.AlwaysReturns || b_unreachable)
207 returns = FlowReturns.Always;
209 returns = FlowReturns.Sometimes;
210 } else if (b.AlwaysReturns) {
211 if (AlwaysReturns || a_unreachable)
212 returns = FlowReturns.Always;
214 returns = FlowReturns.Sometimes;
215 } else if (!MayReturn) {
217 returns = FlowReturns.Sometimes;
219 returns = FlowReturns.Never;
220 } else if (!b.MayReturn) {
222 returns = FlowReturns.Sometimes;
224 returns = FlowReturns.Never;
227 breaks = AndFlowReturns (breaks, b.breaks);
228 throws = AndFlowReturns (throws, b.throws);
229 barrier = AndFlowReturns (barrier, b.barrier);
231 if (a_unreachable && b_unreachable)
232 barrier = FlowReturns.Always;
233 else if (a_unreachable || b_unreachable)
234 barrier = FlowReturns.Sometimes;
236 barrier = FlowReturns.Never;
239 public void Or (Reachability b)
241 returns = OrFlowReturns (returns, b.returns);
242 breaks = OrFlowReturns (breaks, b.breaks);
243 throws = OrFlowReturns (throws, b.throws);
244 barrier = OrFlowReturns (barrier, b.barrier);
247 public static Reachability Never ()
249 return new Reachability (
250 FlowReturns.Never, FlowReturns.Never,
251 FlowReturns.Never, FlowReturns.Never);
254 public FlowReturns Reachable {
256 if ((returns == FlowReturns.Always) ||
257 (breaks == FlowReturns.Always) ||
258 (throws == FlowReturns.Always) ||
259 (barrier == FlowReturns.Always))
260 return FlowReturns.Never;
261 else if ((returns == FlowReturns.Never) &&
262 (breaks == FlowReturns.Never) &&
263 (throws == FlowReturns.Never) &&
264 (barrier == FlowReturns.Never))
265 return FlowReturns.Always;
267 return FlowReturns.Sometimes;
271 public bool AlwaysBreaks {
272 get { return breaks == FlowReturns.Always; }
275 public bool MayBreak {
276 get { return breaks != FlowReturns.Never; }
279 public bool AlwaysReturns {
280 get { return returns == FlowReturns.Always; }
283 public bool MayReturn {
284 get { return returns != FlowReturns.Never; }
287 public bool AlwaysThrows {
288 get { return throws == FlowReturns.Always; }
291 public bool MayThrow {
292 get { return throws != FlowReturns.Never; }
295 public bool AlwaysHasBarrier {
296 get { return barrier == FlowReturns.Always; }
299 public bool MayHaveBarrier {
300 get { return barrier != FlowReturns.Never; }
303 public bool IsUnreachable {
304 get { return Reachable == FlowReturns.Never; }
307 public void SetReturns ()
309 returns = FlowReturns.Always;
312 public void SetReturnsSometimes ()
314 returns = FlowReturns.Sometimes;
317 public void SetBreaks ()
319 breaks = FlowReturns.Always;
322 public void ResetBreaks ()
324 breaks = FlowReturns.Never;
327 public void SetThrows ()
329 throws = FlowReturns.Always;
332 public void SetThrowsSometimes ()
334 throws = FlowReturns.Sometimes;
337 public void SetBarrier ()
339 barrier = FlowReturns.Always;
342 public void ResetBarrier ()
344 barrier = FlowReturns.Never;
347 static string ShortName (FlowReturns returns)
350 case FlowReturns.Never:
352 case FlowReturns.Sometimes:
359 public override string ToString ()
361 return String.Format ("[{0}:{1}:{2}:{3}:{4}]",
362 ShortName (returns), ShortName (breaks),
363 ShortName (throws), ShortName (barrier),
364 ShortName (Reachable));
368 public static FlowBranching CreateBranching (FlowBranching parent, BranchingType type, Block block, Location loc)
371 case BranchingType.Exception:
372 throw new InvalidOperationException ();
374 case BranchingType.Switch:
375 return new FlowBranchingSwitch (parent, block, loc);
377 case BranchingType.SwitchSection:
378 return new FlowBranchingBlock (parent, type, SiblingType.Block, block, loc);
380 case BranchingType.Block:
381 return new FlowBranchingBlock (parent, type, SiblingType.Block, block, loc);
383 case BranchingType.Loop:
384 return new FlowBranchingLoop (parent, block, loc);
387 return new FlowBranchingBlock (parent, type, SiblingType.Conditional, block, loc);
392 // The type of this flow branching.
394 public readonly BranchingType Type;
397 // The block this branching is contained in. This may be null if it's not
398 // a top-level block and it doesn't declare any local variables.
400 public readonly Block Block;
403 // The parent of this branching or null if this is the top-block.
405 public readonly FlowBranching Parent;
408 // Start-Location of this flow branching.
410 public readonly Location Location;
413 // If this is an infinite loop.
415 public bool Infinite;
420 VariableMap param_map, local_map;
422 static int next_id = 0;
426 // The vector contains a BitArray with information about which local variables
427 // and parameters are already initialized at the current code position.
429 public class UsageVector {
431 // The type of this branching.
433 public readonly SiblingType Type;
436 // Start location of this branching.
438 public readonly Location Location;
441 // This is only valid for SwitchSection, Try, Catch and Finally.
443 public readonly Block Block;
446 // If this is true, then the usage vector has been modified and must be
447 // merged when we're done with this branching.
452 // The number of parameters in this block.
454 public readonly int CountParameters;
457 // The number of locals in this block.
459 public readonly int CountLocals;
462 // If not null, then we inherit our state from this vector and do a
463 // copy-on-write. If null, then we're the first sibling in a top-level
464 // block and inherit from the empty vector.
466 public readonly UsageVector InheritsFrom;
469 // This is used to construct a list of UsageVector's.
471 public UsageVector Next;
476 MyBitVector locals, parameters;
477 Reachability reachability;
479 static int next_id = 0;
483 // Normally, you should not use any of these constructors.
485 public UsageVector (SiblingType type, UsageVector parent,
486 Block block, Location loc,
487 int num_params, int num_locals)
492 this.InheritsFrom = parent;
493 this.CountParameters = num_params;
494 this.CountLocals = num_locals;
496 if (parent != null) {
498 locals = new MyBitVector (parent.locals, CountLocals);
501 parameters = new MyBitVector (parent.parameters, num_params);
503 reachability = parent.Reachability.Clone ();
506 locals = new MyBitVector (null, CountLocals);
509 parameters = new MyBitVector (null, num_params);
511 reachability = Reachability.Never ();
517 public UsageVector (SiblingType type, UsageVector parent,
518 Block block, Location loc)
519 : this (type, parent, block, loc,
520 parent.CountParameters, parent.CountLocals)
523 public UsageVector (MyBitVector parameters, MyBitVector locals,
524 Reachability reachability, Block block,
527 this.Type = SiblingType.Block;
531 this.reachability = reachability;
532 this.parameters = parameters;
533 this.locals = locals;
539 // This does a deep copy of the usage vector.
541 public UsageVector Clone ()
543 UsageVector retval = new UsageVector (
544 Type, null, Block, Location,
545 CountParameters, CountLocals);
547 if (retval.locals != null)
548 retval.locals = locals.Clone ();
550 if (parameters != null)
551 retval.parameters = parameters.Clone ();
553 retval.reachability = reachability.Clone ();
558 public bool IsAssigned (VariableInfo var)
560 if (!var.IsParameter && Reachability.IsUnreachable)
563 return var.IsAssigned (var.IsParameter ? parameters : locals);
566 public void SetAssigned (VariableInfo var)
568 if (!var.IsParameter && Reachability.IsUnreachable)
572 var.SetAssigned (var.IsParameter ? parameters : locals);
575 public bool IsFieldAssigned (VariableInfo var, string name)
577 if (!var.IsParameter && Reachability.IsUnreachable)
580 return var.IsFieldAssigned (var.IsParameter ? parameters : locals, name);
583 public void SetFieldAssigned (VariableInfo var, string name)
585 if (!var.IsParameter && Reachability.IsUnreachable)
589 var.SetFieldAssigned (var.IsParameter ? parameters : locals, name);
592 public Reachability Reachability {
598 public void Return ()
600 if (!reachability.IsUnreachable) {
602 reachability.SetReturns ();
608 if (!reachability.IsUnreachable) {
610 reachability.SetBreaks ();
616 if (!reachability.IsUnreachable) {
618 reachability.SetThrows ();
624 if (!reachability.IsUnreachable) {
626 reachability.SetBarrier ();
631 // Merges a child branching.
633 public UsageVector MergeChild (FlowBranching branching)
635 UsageVector result = branching.Merge ();
637 Report.Debug (2, " MERGING CHILD", this, branching, IsDirty,
638 result.ParameterVector, result.LocalVector,
639 result.Reachability, reachability, Type);
641 Reachability new_r = result.Reachability;
643 if (branching.Type == BranchingType.Loop) {
644 bool may_leave_loop = new_r.MayBreak;
645 new_r.ResetBreaks ();
647 if (branching.Infinite && !may_leave_loop) {
648 if (new_r.Returns == FlowReturns.Sometimes) {
649 // If we're an infinite loop and do not break,
650 // the code after the loop can never be reached.
651 // However, if we may return from the loop,
652 // then we do always return (or stay in the
661 new_r.ResetBarrier ();
662 } else if (branching.Type == BranchingType.Switch) {
663 if (new_r.MayBreak || new_r.MayReturn)
664 new_r.ResetBarrier ();
666 new_r.ResetBreaks ();
670 // We've now either reached the point after the branching or we will
671 // never get there since we always return or always throw an exception.
673 // If we can reach the point after the branching, mark all locals and
674 // parameters as initialized which have been initialized in all branches
675 // we need to look at (see above).
678 if ((Type == SiblingType.SwitchSection) && !new_r.IsUnreachable) {
679 Report.Error (163, Location,
680 "Control cannot fall through from one " +
681 "case label to another");
685 if (locals != null && result.LocalVector != null)
686 locals.Or (result.LocalVector);
688 if (result.ParameterVector != null)
689 parameters.Or (result.ParameterVector);
691 if ((branching.Type == BranchingType.Block) && branching.Block.Implicit)
692 reachability = new_r.Clone ();
694 reachability.Or (new_r);
696 Report.Debug (2, " MERGING CHILD DONE", this, result,
697 new_r, reachability);
704 protected void MergeFinally (FlowBranching branching, UsageVector f_origins,
705 MyBitVector f_params)
707 for (UsageVector vector = f_origins; vector != null; vector = vector.Next) {
708 MyBitVector temp_params = f_params.Clone ();
709 temp_params.Or (vector.Parameters);
713 public void MergeFinally (FlowBranching branching, UsageVector f_vector,
714 UsageVector f_origins)
716 if (parameters != null) {
717 if (f_vector != null) {
718 MergeFinally (branching, f_origins, f_vector.Parameters);
719 MyBitVector.Or (ref parameters, f_vector.ParameterVector);
721 MergeFinally (branching, f_origins, parameters);
724 if (f_vector != null && f_vector.LocalVector != null)
725 MyBitVector.Or (ref locals, f_vector.LocalVector);
729 // Tells control flow analysis that the current code position may be reached with
730 // a forward jump from any of the origins listed in `origin_vectors' which is a
731 // list of UsageVectors.
733 // This is used when resolving forward gotos - in the following example, the
734 // variable `a' is uninitialized in line 8 becase this line may be reached via
735 // the goto in line 4:
745 // 8 Console.WriteLine (a);
748 public void MergeJumpOrigins (UsageVector o_vectors)
750 Report.Debug (1, " MERGING JUMP ORIGINS", this);
752 reachability = Reachability.Never ();
754 if (o_vectors == null) {
755 reachability.SetBarrier ();
761 for (UsageVector vector = o_vectors; vector != null;
762 vector = vector.Next) {
763 Report.Debug (1, " MERGING JUMP ORIGIN", vector,
764 first, locals, vector.Locals);
767 if (locals != null && vector.Locals != null)
768 locals.Or (vector.locals);
770 if (parameters != null)
771 parameters.Or (vector.parameters);
775 locals.And (vector.locals);
776 if (parameters != null)
777 parameters.And (vector.parameters);
780 Reachability.And (ref reachability, vector.Reachability, true);
782 Report.Debug (1, " MERGING JUMP ORIGIN #1", vector);
785 Report.Debug (1, " MERGING JUMP ORIGINS DONE", this);
789 // This is used at the beginning of a finally block if there were
790 // any return statements in the try block or one of the catch blocks.
792 public void MergeFinallyOrigins (UsageVector f_origins)
794 Report.Debug (1, " MERGING FINALLY ORIGIN", this);
796 reachability = Reachability.Never ();
798 for (UsageVector vector = f_origins; vector != null; vector = vector.Next) {
799 Report.Debug (1, " MERGING FINALLY ORIGIN", vector);
801 if (parameters != null)
802 parameters.And (vector.parameters);
804 Reachability.And (ref reachability, vector.Reachability, true);
807 Report.Debug (1, " MERGING FINALLY ORIGIN DONE", this);
810 public void MergeBreakOrigins (FlowBranching branching, UsageVector o_vectors)
812 Report.Debug (1, " MERGING BREAK ORIGINS", this);
814 if (o_vectors == null)
817 bool first = branching.Infinite;
819 for (UsageVector vector = o_vectors; vector != null;
820 vector = vector.Next) {
821 Report.Debug (1, " MERGING BREAK ORIGIN", vector, first);
824 if (locals != null && vector.Locals != null)
825 locals.Or (vector.locals);
827 if (parameters != null)
828 parameters.Or (vector.parameters);
831 if (locals != null && vector.Locals != null)
832 locals.And (vector.locals);
833 if (parameters != null)
834 parameters.And (vector.parameters);
837 reachability.And (vector.Reachability, false);
840 Report.Debug (1, " MERGING BREAK ORIGINS DONE", this);
843 public void CheckOutParameters (FlowBranching branching)
845 if (parameters != null)
846 branching.CheckOutParameters (parameters, branching.Location);
850 // Performs an `or' operation on the locals and the parameters.
852 public void Or (UsageVector new_vector)
855 locals.Or (new_vector.locals);
856 if (parameters != null)
857 parameters.Or (new_vector.parameters);
861 // Performs an `and' operation on the locals.
863 public void AndLocals (UsageVector new_vector)
866 locals.And (new_vector.locals);
869 public bool HasParameters {
871 return parameters != null;
875 public bool HasLocals {
877 return locals != null;
882 // Returns a deep copy of the parameters.
884 public MyBitVector Parameters {
886 if (parameters != null)
887 return parameters.Clone ();
894 // Returns a deep copy of the locals.
896 public MyBitVector Locals {
899 return locals.Clone ();
905 public MyBitVector ParameterVector {
911 public MyBitVector LocalVector {
921 public override string ToString ()
923 StringBuilder sb = new StringBuilder ();
925 sb.Append ("Vector (");
932 sb.Append (reachability);
933 if (parameters != null) {
935 sb.Append (parameters);
941 return sb.ToString ();
946 // Creates a new flow branching which is contained in `parent'.
947 // You should only pass non-null for the `block' argument if this block
948 // introduces any new variables - in this case, we need to create a new
949 // usage vector with a different size than our parent's one.
951 protected FlowBranching (FlowBranching parent, BranchingType type, SiblingType stype,
952 Block block, Location loc)
962 param_map = Block.ParameterMap;
963 local_map = Block.LocalMap;
965 UsageVector parent_vector = parent != null ? parent.CurrentUsageVector : null;
966 vector = new UsageVector (
967 stype, parent_vector, Block, loc,
968 param_map.Length, local_map.Length);
970 param_map = Parent.param_map;
971 local_map = Parent.local_map;
972 vector = new UsageVector (
973 stype, Parent.CurrentUsageVector, null, loc);
979 public abstract UsageVector CurrentUsageVector {
984 // Creates a sibling of the current usage vector.
986 public virtual void CreateSibling (Block block, SiblingType type)
988 UsageVector vector = new UsageVector (
989 type, Parent.CurrentUsageVector, block, Location);
992 Report.Debug (1, " CREATED SIBLING", CurrentUsageVector);
995 public void CreateSibling ()
997 CreateSibling (null, SiblingType.Conditional);
1000 protected abstract void AddSibling (UsageVector uv);
1002 public virtual LabeledStatement LookupLabel (string name, Location loc)
1005 return Parent.LookupLabel (name, loc);
1009 "No such label `" + name + "' in this scope");
1013 public abstract void Label (UsageVector origin_vectors);
1016 // Check whether all `out' parameters have been assigned.
1018 public void CheckOutParameters (MyBitVector parameters, Location loc)
1020 for (int i = 0; i < param_map.Count; i++) {
1021 VariableInfo var = param_map [i];
1026 if (var.IsAssigned (parameters))
1029 Report.Error (177, loc, "The out parameter `{0}' must be assigned to before control leaves the current method",
1034 protected UsageVector Merge (UsageVector sibling_list)
1036 if (sibling_list.Next == null)
1037 return sibling_list;
1039 MyBitVector locals = null;
1040 MyBitVector parameters = null;
1042 Reachability reachability = null;
1044 Report.Debug (2, " MERGING SIBLINGS", this, Name);
1046 for (UsageVector child = sibling_list; child != null; child = child.Next) {
1047 bool do_break = (Type != BranchingType.Switch) &&
1048 (Type != BranchingType.Loop);
1050 Report.Debug (2, " MERGING SIBLING ", child,
1051 child.ParameterVector, child.LocalVector,
1052 reachability, child.Reachability, do_break);
1054 Reachability.And (ref reachability, child.Reachability, do_break);
1056 // A local variable is initialized after a flow branching if it
1057 // has been initialized in all its branches which do neither
1058 // always return or always throw an exception.
1060 // If a branch may return, but does not always return, then we
1061 // can treat it like a never-returning branch here: control will
1062 // only reach the code position after the branching if we did not
1065 // It's important to distinguish between always and sometimes
1066 // returning branches here:
1069 // 2 if (something) {
1073 // 6 Console.WriteLine (a);
1075 // The if block in lines 3-4 always returns, so we must not look
1076 // at the initialization of `a' in line 4 - thus it'll still be
1077 // uninitialized in line 6.
1079 // On the other hand, the following is allowed:
1086 // 6 Console.WriteLine (a);
1088 // Here, `a' is initialized in line 3 and we must not look at
1089 // line 5 since it always returns.
1091 bool do_break_2 = (child.Type != SiblingType.Block) &&
1092 (child.Type != SiblingType.SwitchSection);
1093 bool always_throws = (child.Type != SiblingType.Try) &&
1094 child.Reachability.AlwaysThrows;
1095 bool unreachable = always_throws ||
1096 (do_break_2 && child.Reachability.AlwaysBreaks) ||
1097 child.Reachability.AlwaysReturns ||
1098 child.Reachability.AlwaysHasBarrier;
1100 Report.Debug (2, " MERGING SIBLING #1", reachability,
1101 Type, child.Type, child.Reachability.IsUnreachable,
1102 do_break_2, always_throws, unreachable);
1104 if (!unreachable && (child.LocalVector != null))
1105 MyBitVector.And (ref locals, child.LocalVector);
1107 // An `out' parameter must be assigned in all branches which do
1108 // not always throw an exception.
1109 if ((child.ParameterVector != null) && !child.Reachability.AlwaysThrows)
1110 MyBitVector.And (ref parameters, child.ParameterVector);
1112 Report.Debug (2, " MERGING SIBLING #2", parameters, locals);
1115 if (reachability == null)
1116 reachability = Reachability.Never ();
1118 Report.Debug (2, " MERGING SIBLINGS DONE", parameters, locals,
1119 reachability, Infinite);
1121 return new UsageVector (
1122 parameters, locals, reachability, null, Location);
1125 protected abstract UsageVector Merge ();
1128 // Merge a child branching.
1130 public UsageVector MergeChild (FlowBranching child)
1132 return CurrentUsageVector.MergeChild (child);
1136 // Does the toplevel merging.
1138 public Reachability MergeTopBlock ()
1140 if ((Type != BranchingType.Block) || (Block == null))
1141 throw new NotSupportedException ();
1143 UsageVector vector = new UsageVector (
1144 SiblingType.Block, null, Block, Location,
1145 param_map.Length, local_map.Length);
1147 UsageVector result = vector.MergeChild (this);
1149 Report.Debug (4, "MERGE TOP BLOCK", Location, vector, result.Reachability);
1151 if ((vector.Reachability.Throws != FlowReturns.Always) &&
1152 (vector.Reachability.Barrier != FlowReturns.Always))
1153 CheckOutParameters (vector.Parameters, Location);
1155 return result.Reachability;
1159 // Checks whether we're in a `try' block.
1161 public virtual bool InTryOrCatch (bool is_return)
1163 if ((Block != null) && Block.IsDestructor)
1165 else if (!is_return &&
1166 ((Type == BranchingType.Loop) || (Type == BranchingType.Switch)))
1168 else if (Parent != null)
1169 return Parent.InTryOrCatch (is_return);
1174 public virtual bool InTryWithCatch ()
1177 return Parent.InTryWithCatch ();
1181 public virtual bool InLoop ()
1183 if (Type == BranchingType.Loop)
1185 else if (Parent != null)
1186 return Parent.InLoop ();
1191 public virtual bool InSwitch ()
1193 if (Type == BranchingType.Switch)
1195 else if (Parent != null)
1196 return Parent.InSwitch ();
1201 public virtual bool BreakCrossesTryCatchBoundary ()
1203 if ((Type == BranchingType.Loop) || (Type == BranchingType.Switch))
1205 else if (Parent != null)
1206 return Parent.BreakCrossesTryCatchBoundary ();
1211 public virtual void AddFinallyVector (UsageVector vector)
1214 Parent.AddFinallyVector (vector);
1215 else if ((Block == null) || !Block.IsDestructor)
1216 throw new NotSupportedException ();
1219 public virtual void AddBreakVector (UsageVector vector)
1222 Parent.AddBreakVector (vector);
1223 else if ((Block == null) || !Block.IsDestructor)
1224 throw new NotSupportedException ();
1227 public virtual void StealFinallyClauses (ref ArrayList list)
1230 Parent.StealFinallyClauses (ref list);
1233 public bool IsAssigned (VariableInfo vi)
1235 return CurrentUsageVector.IsAssigned (vi);
1238 public bool IsFieldAssigned (VariableInfo vi, string field_name)
1240 if (CurrentUsageVector.IsAssigned (vi))
1243 return CurrentUsageVector.IsFieldAssigned (vi, field_name);
1246 public void SetAssigned (VariableInfo vi)
1248 CurrentUsageVector.SetAssigned (vi);
1251 public void SetFieldAssigned (VariableInfo vi, string name)
1253 CurrentUsageVector.SetFieldAssigned (vi, name);
1256 public override string ToString ()
1258 StringBuilder sb = new StringBuilder ();
1259 sb.Append (GetType ());
1265 if (Block != null) {
1267 sb.Append (Block.ID);
1269 sb.Append (Block.StartLocation);
1272 // sb.Append (Siblings.Length);
1273 // sb.Append (" - ");
1274 sb.Append (CurrentUsageVector);
1276 return sb.ToString ();
1279 public string Name {
1281 return String.Format ("{0} ({1}:{2}:{3})",
1282 GetType (), id, Type, Location);
1287 public class FlowBranchingBlock : FlowBranching
1289 UsageVector sibling_list = null;
1291 public FlowBranchingBlock (FlowBranching parent, BranchingType type,
1292 SiblingType stype, Block block, Location loc)
1293 : base (parent, type, stype, block, loc)
1296 public override UsageVector CurrentUsageVector {
1297 get { return sibling_list; }
1300 protected override void AddSibling (UsageVector sibling)
1302 sibling.Next = sibling_list;
1303 sibling_list = sibling;
1306 public override LabeledStatement LookupLabel (string name, Location loc)
1309 return base.LookupLabel (name, loc);
1311 LabeledStatement s = Block.LookupLabel (name);
1315 return base.LookupLabel (name, loc);
1318 public override void Label (UsageVector origin_vectors)
1320 if (!CurrentUsageVector.Reachability.IsUnreachable) {
1321 UsageVector vector = CurrentUsageVector.Clone ();
1322 vector.Next = origin_vectors;
1323 origin_vectors = vector;
1326 CurrentUsageVector.MergeJumpOrigins (origin_vectors);
1329 protected override UsageVector Merge ()
1331 return Merge (sibling_list);
1335 public class FlowBranchingLoop : FlowBranchingBlock
1337 UsageVector break_origins;
1339 public FlowBranchingLoop (FlowBranching parent, Block block, Location loc)
1340 : base (parent, BranchingType.Loop, SiblingType.Conditional, block, loc)
1343 public override void AddBreakVector (UsageVector vector)
1345 vector = vector.Clone ();
1346 vector.Next = break_origins;
1347 break_origins = vector;
1350 protected override UsageVector Merge ()
1352 UsageVector vector = base.Merge ();
1354 vector.MergeBreakOrigins (this, break_origins);
1360 public class FlowBranchingSwitch : FlowBranchingBlock
1362 UsageVector break_origins;
1364 public FlowBranchingSwitch (FlowBranching parent, Block block, Location loc)
1365 : base (parent, BranchingType.Switch, SiblingType.SwitchSection, block, loc)
1368 public override void AddBreakVector (UsageVector vector)
1370 vector = vector.Clone ();
1371 vector.Next = break_origins;
1372 break_origins = vector;
1375 protected override UsageVector Merge ()
1377 UsageVector vector = base.Merge ();
1379 vector.MergeBreakOrigins (this, break_origins);
1385 public class FlowBranchingException : FlowBranching
1387 ExceptionStatement stmt;
1388 UsageVector current_vector;
1389 UsageVector catch_vectors;
1390 UsageVector finally_vector;
1391 UsageVector finally_origins;
1394 public FlowBranchingException (FlowBranching parent,
1395 ExceptionStatement stmt)
1396 : base (parent, BranchingType.Exception, SiblingType.Try,
1400 this.emit_finally = true;
1403 protected override void AddSibling (UsageVector sibling)
1405 if (sibling.Type == SiblingType.Try) {
1406 sibling.Next = catch_vectors;
1407 catch_vectors = sibling;
1408 } else if (sibling.Type == SiblingType.Catch) {
1409 sibling.Next = catch_vectors;
1410 catch_vectors = sibling;
1411 } else if (sibling.Type == SiblingType.Finally) {
1412 sibling.MergeFinallyOrigins (finally_origins);
1413 finally_vector = sibling;
1415 throw new InvalidOperationException ();
1417 current_vector = sibling;
1420 public override UsageVector CurrentUsageVector {
1421 get { return current_vector; }
1424 public override bool InTryOrCatch (bool is_return)
1426 return finally_vector == null;
1429 public override bool InTryWithCatch ()
1431 if (finally_vector == null) {
1432 Try t = stmt as Try;
1433 if (t != null && t.HasCatch)
1438 return Parent.InTryWithCatch ();
1443 public override bool BreakCrossesTryCatchBoundary ()
1448 public override void AddFinallyVector (UsageVector vector)
1450 vector = vector.Clone ();
1451 vector.Next = finally_origins;
1452 finally_origins = vector;
1455 public override void StealFinallyClauses (ref ArrayList list)
1458 list = new ArrayList ();
1460 emit_finally = false;
1461 base.StealFinallyClauses (ref list);
1464 public bool EmitFinally {
1465 get { return emit_finally; }
1468 public override LabeledStatement LookupLabel (string name, Location loc)
1470 if (current_vector.Block == null)
1471 return base.LookupLabel (name, loc);
1473 LabeledStatement s = current_vector.Block.LookupLabel (name);
1477 if (finally_vector != null) {
1478 Report.Error (157, loc,
1479 "Control cannot leave the body of a finally clause");
1483 return base.LookupLabel (name, loc);
1486 public override void Label (UsageVector origin_vectors)
1488 CurrentUsageVector.MergeJumpOrigins (origin_vectors);
1491 protected override UsageVector Merge ()
1493 UsageVector vector = Merge (catch_vectors);
1495 vector.MergeFinally (this, finally_vector, finally_origins);
1502 // This is used by the flow analysis code to keep track of the type of local variables
1505 // The flow code uses a BitVector to keep track of whether a variable has been assigned
1506 // or not. This is easy for fundamental types (int, char etc.) or reference types since
1507 // you can only assign the whole variable as such.
1509 // For structs, we also need to keep track of all its fields. To do this, we allocate one
1510 // bit for the struct itself (it's used if you assign/access the whole struct) followed by
1511 // one bit for each of its fields.
1513 // This class computes this `layout' for each type.
1515 public class TypeInfo
1517 public readonly Type Type;
1520 // Total number of bits a variable of this type consumes in the flow vector.
1522 public readonly int TotalLength;
1525 // Number of bits the simple fields of a variable of this type consume
1526 // in the flow vector.
1528 public readonly int Length;
1531 // This is only used by sub-structs.
1533 public readonly int Offset;
1536 // If this is a struct.
1538 public readonly bool IsStruct;
1541 // If this is a struct, all fields which are structs theirselves.
1543 public TypeInfo[] SubStructInfo;
1545 protected readonly StructInfo struct_info;
1546 private static Hashtable type_hash = new Hashtable ();
1548 public static TypeInfo GetTypeInfo (Type type)
1550 TypeInfo info = (TypeInfo) type_hash [type];
1554 info = new TypeInfo (type);
1555 type_hash.Add (type, info);
1559 public static TypeInfo GetTypeInfo (TypeContainer tc)
1561 TypeInfo info = (TypeInfo) type_hash [tc.TypeBuilder];
1565 info = new TypeInfo (tc);
1566 type_hash.Add (tc.TypeBuilder, info);
1570 private TypeInfo (Type type)
1574 struct_info = StructInfo.GetStructInfo (type);
1575 if (struct_info != null) {
1576 Length = struct_info.Length;
1577 TotalLength = struct_info.TotalLength;
1578 SubStructInfo = struct_info.StructFields;
1587 private TypeInfo (TypeContainer tc)
1589 this.Type = tc.TypeBuilder;
1591 struct_info = StructInfo.GetStructInfo (tc);
1592 if (struct_info != null) {
1593 Length = struct_info.Length;
1594 TotalLength = struct_info.TotalLength;
1595 SubStructInfo = struct_info.StructFields;
1604 protected TypeInfo (StructInfo struct_info, int offset)
1606 this.struct_info = struct_info;
1607 this.Offset = offset;
1608 this.Length = struct_info.Length;
1609 this.TotalLength = struct_info.TotalLength;
1610 this.SubStructInfo = struct_info.StructFields;
1611 this.Type = struct_info.Type;
1612 this.IsStruct = true;
1615 public int GetFieldIndex (string name)
1617 if (struct_info == null)
1620 return struct_info [name];
1623 public TypeInfo GetSubStruct (string name)
1625 if (struct_info == null)
1628 return struct_info.GetStructField (name);
1632 // A struct's constructor must always assign all fields.
1633 // This method checks whether it actually does so.
1635 public bool IsFullyInitialized (FlowBranching branching, VariableInfo vi, Location loc)
1637 if (struct_info == null)
1641 for (int i = 0; i < struct_info.Count; i++) {
1642 FieldInfo field = struct_info.Fields [i];
1644 if (!branching.IsFieldAssigned (vi, field.Name)) {
1645 Report.Error (171, loc,
1646 "Field `{0}' must be fully assigned before control leaves the constructor",
1647 TypeManager.GetFullNameSignature (field));
1655 public override string ToString ()
1657 return String.Format ("TypeInfo ({0}:{1}:{2}:{3})",
1658 Type, Offset, Length, TotalLength);
1661 protected class StructInfo {
1662 public readonly Type Type;
1663 public readonly FieldInfo[] Fields;
1664 public readonly TypeInfo[] StructFields;
1665 public readonly int Count;
1666 public readonly int CountPublic;
1667 public readonly int CountNonPublic;
1668 public readonly int Length;
1669 public readonly int TotalLength;
1670 public readonly bool HasStructFields;
1672 private static Hashtable field_type_hash = new Hashtable ();
1673 private Hashtable struct_field_hash;
1674 private Hashtable field_hash;
1676 protected bool InTransit = false;
1678 // Private constructor. To save memory usage, we only need to create one instance
1679 // of this class per struct type.
1680 private StructInfo (Type type)
1684 field_type_hash.Add (type, this);
1686 if (type is TypeBuilder) {
1687 TypeContainer tc = TypeManager.LookupTypeContainer (type);
1689 ArrayList fields = null;
1693 ArrayList public_fields = new ArrayList ();
1694 ArrayList non_public_fields = new ArrayList ();
1696 if (fields != null) {
1697 foreach (FieldMember field in fields) {
1698 if ((field.ModFlags & Modifiers.STATIC) != 0)
1700 if ((field.ModFlags & Modifiers.PUBLIC) != 0)
1701 public_fields.Add (field.FieldBuilder);
1703 non_public_fields.Add (field.FieldBuilder);
1707 CountPublic = public_fields.Count;
1708 CountNonPublic = non_public_fields.Count;
1709 Count = CountPublic + CountNonPublic;
1711 Fields = new FieldInfo [Count];
1712 public_fields.CopyTo (Fields, 0);
1713 non_public_fields.CopyTo (Fields, CountPublic);
1715 FieldInfo[] public_fields = type.GetFields (
1716 BindingFlags.Instance|BindingFlags.Public);
1717 FieldInfo[] non_public_fields = type.GetFields (
1718 BindingFlags.Instance|BindingFlags.NonPublic);
1720 CountPublic = public_fields.Length;
1721 CountNonPublic = non_public_fields.Length;
1722 Count = CountPublic + CountNonPublic;
1724 Fields = new FieldInfo [Count];
1725 public_fields.CopyTo (Fields, 0);
1726 non_public_fields.CopyTo (Fields, CountPublic);
1729 struct_field_hash = new Hashtable ();
1730 field_hash = new Hashtable ();
1733 StructFields = new TypeInfo [Count];
1734 StructInfo[] sinfo = new StructInfo [Count];
1738 for (int i = 0; i < Count; i++) {
1739 FieldInfo field = (FieldInfo) Fields [i];
1741 sinfo [i] = GetStructInfo (field.FieldType);
1742 if (sinfo [i] == null)
1743 field_hash.Add (field.Name, ++Length);
1744 else if (sinfo [i].InTransit) {
1745 Report.Error (523, String.Format (
1746 "Struct member `{0}.{1}' of type `{2}' causes " +
1747 "a cycle in the structure layout",
1748 type, field.Name, sinfo [i].Type));
1756 TotalLength = Length + 1;
1757 for (int i = 0; i < Count; i++) {
1758 FieldInfo field = (FieldInfo) Fields [i];
1760 if (sinfo [i] == null)
1763 field_hash.Add (field.Name, TotalLength);
1765 HasStructFields = true;
1766 StructFields [i] = new TypeInfo (sinfo [i], TotalLength);
1767 struct_field_hash.Add (field.Name, StructFields [i]);
1768 TotalLength += sinfo [i].TotalLength;
1772 public int this [string name] {
1774 if (field_hash.Contains (name))
1775 return (int) field_hash [name];
1781 public TypeInfo GetStructField (string name)
1783 return (TypeInfo) struct_field_hash [name];
1786 public static StructInfo GetStructInfo (Type type)
1788 if (!TypeManager.IsValueType (type) || TypeManager.IsEnumType (type) ||
1789 TypeManager.IsBuiltinType (type))
1792 StructInfo info = (StructInfo) field_type_hash [type];
1796 return new StructInfo (type);
1799 public static StructInfo GetStructInfo (TypeContainer tc)
1801 StructInfo info = (StructInfo) field_type_hash [tc.TypeBuilder];
1805 return new StructInfo (tc.TypeBuilder);
1811 // This is used by the flow analysis code to store information about a single local variable
1812 // or parameter. Depending on the variable's type, we need to allocate one or more elements
1813 // in the BitVector - if it's a fundamental or reference type, we just need to know whether
1814 // it has been assigned or not, but for structs, we need this information for each of its fields.
1816 public class VariableInfo {
1817 public readonly string Name;
1818 public readonly TypeInfo TypeInfo;
1821 // The bit offset of this variable in the flow vector.
1823 public readonly int Offset;
1826 // The number of bits this variable needs in the flow vector.
1827 // The first bit always specifies whether the variable as such has been assigned while
1828 // the remaining bits contain this information for each of a struct's fields.
1830 public readonly int Length;
1833 // If this is a parameter of local variable.
1835 public readonly bool IsParameter;
1837 public readonly LocalInfo LocalInfo;
1838 public readonly int ParameterIndex;
1840 readonly VariableInfo Parent;
1841 VariableInfo[] sub_info;
1843 protected VariableInfo (string name, Type type, int offset)
1846 this.Offset = offset;
1847 this.TypeInfo = TypeInfo.GetTypeInfo (type);
1849 Length = TypeInfo.TotalLength;
1854 protected VariableInfo (VariableInfo parent, TypeInfo type)
1856 this.Name = parent.Name;
1857 this.TypeInfo = type;
1858 this.Offset = parent.Offset + type.Offset;
1859 this.Parent = parent;
1860 this.Length = type.TotalLength;
1862 this.IsParameter = parent.IsParameter;
1863 this.LocalInfo = parent.LocalInfo;
1864 this.ParameterIndex = parent.ParameterIndex;
1869 protected void Initialize ()
1871 TypeInfo[] sub_fields = TypeInfo.SubStructInfo;
1872 if (sub_fields != null) {
1873 sub_info = new VariableInfo [sub_fields.Length];
1874 for (int i = 0; i < sub_fields.Length; i++) {
1875 if (sub_fields [i] != null)
1876 sub_info [i] = new VariableInfo (this, sub_fields [i]);
1879 sub_info = new VariableInfo [0];
1882 public VariableInfo (LocalInfo local_info, int offset)
1883 : this (local_info.Name, local_info.VariableType, offset)
1885 this.LocalInfo = local_info;
1886 this.IsParameter = false;
1889 public VariableInfo (string name, Type type, int param_idx, int offset)
1890 : this (name, type, offset)
1892 this.ParameterIndex = param_idx;
1893 this.IsParameter = true;
1896 public bool IsAssigned (EmitContext ec)
1898 return !ec.DoFlowAnalysis || ec.CurrentBranching.IsAssigned (this);
1901 public bool IsAssigned (EmitContext ec, Location loc)
1903 if (IsAssigned (ec))
1906 Report.Error (165, loc,
1907 "Use of unassigned local variable `" + Name + "'");
1908 ec.CurrentBranching.SetAssigned (this);
1912 public bool IsAssigned (MyBitVector vector)
1914 if (vector [Offset])
1917 for (VariableInfo parent = Parent; parent != null; parent = parent.Parent)
1918 if (vector [parent.Offset])
1921 // Return unless this is a struct.
1922 if (!TypeInfo.IsStruct)
1925 // Ok, so each field must be assigned.
1926 for (int i = 0; i < TypeInfo.Length; i++) {
1927 if (!vector [Offset + i + 1])
1931 // Ok, now check all fields which are structs.
1932 for (int i = 0; i < sub_info.Length; i++) {
1933 VariableInfo sinfo = sub_info [i];
1937 if (!sinfo.IsAssigned (vector))
1941 vector [Offset] = true;
1945 public void SetAssigned (EmitContext ec)
1947 if (ec.DoFlowAnalysis)
1948 ec.CurrentBranching.SetAssigned (this);
1951 public void SetAssigned (MyBitVector vector)
1953 vector [Offset] = true;
1956 public bool IsFieldAssigned (EmitContext ec, string name, Location loc)
1958 if (!ec.DoFlowAnalysis || ec.CurrentBranching.IsFieldAssigned (this, name))
1961 Report.Error (170, loc,
1962 "Use of possibly unassigned field `" + name + "'");
1963 ec.CurrentBranching.SetFieldAssigned (this, name);
1967 public bool IsFieldAssigned (MyBitVector vector, string field_name)
1969 int field_idx = TypeInfo.GetFieldIndex (field_name);
1974 return vector [Offset + field_idx];
1977 public void SetFieldAssigned (EmitContext ec, string name)
1979 if (ec.DoFlowAnalysis)
1980 ec.CurrentBranching.SetFieldAssigned (this, name);
1983 public void SetFieldAssigned (MyBitVector vector, string field_name)
1985 int field_idx = TypeInfo.GetFieldIndex (field_name);
1990 vector [Offset + field_idx] = true;
1993 public VariableInfo GetSubStruct (string name)
1995 TypeInfo type = TypeInfo.GetSubStruct (name);
2000 return new VariableInfo (this, type);
2003 public override string ToString ()
2005 return String.Format ("VariableInfo ({0}:{1}:{2}:{3}:{4})",
2006 Name, TypeInfo, Offset, Length, IsParameter);
2011 // This is used by the flow code to hold the `layout' of the flow vector for
2012 // all locals and all parameters (ie. we create one instance of this class for the
2013 // locals and another one for the params).
2015 public class VariableMap {
2017 // The number of variables in the map.
2019 public readonly int Count;
2022 // Total length of the flow vector for this map.
2024 public readonly int Length;
2028 public VariableMap (InternalParameters ip)
2030 Count = ip != null ? ip.Count : 0;
2032 // Dont bother allocating anything!
2038 for (int i = 0; i < Count; i++) {
2039 Parameter.Modifier mod = ip.ParameterModifier (i);
2041 if ((mod & Parameter.Modifier.OUT) == 0)
2044 // Dont allocate till we find an out var.
2046 map = new VariableInfo [Count];
2048 map [i] = new VariableInfo (ip.ParameterName (i),
2049 TypeManager.GetElementType (ip.ParameterType (i)), i, Length);
2051 Length += map [i].Length;
2055 public VariableMap (LocalInfo[] locals)
2056 : this (null, locals)
2059 public VariableMap (VariableMap parent, LocalInfo[] locals)
2061 int offset = 0, start = 0;
2062 if (parent != null && parent.map != null) {
2063 offset = parent.Length;
2064 start = parent.Count;
2067 Count = locals.Length + start;
2072 map = new VariableInfo [Count];
2075 if (parent != null && parent.map != null) {
2076 parent.map.CopyTo (map, 0);
2079 for (int i = start; i < Count; i++) {
2080 LocalInfo li = locals [i-start];
2082 if (li.VariableType == null)
2085 map [i] = li.VariableInfo = new VariableInfo (li, Length);
2086 Length += map [i].Length;
2091 // Returns the VariableInfo for variable @index or null if we don't need to
2092 // compute assignment info for this variable.
2094 public VariableInfo this [int index] {
2103 public override string ToString ()
2105 return String.Format ("VariableMap ({0}:{1})", Count, Length);
2110 // This is a special bit vector which can inherit from another bit vector doing a
2111 // copy-on-write strategy. The inherited vector may have a smaller size than the
2114 public class MyBitVector {
2115 public readonly int Count;
2116 public readonly MyBitVector InheritsFrom;
2121 public MyBitVector (int Count)
2122 : this (null, Count)
2125 public MyBitVector (MyBitVector InheritsFrom, int Count)
2127 this.InheritsFrom = InheritsFrom;
2132 // Checks whether this bit vector has been modified. After setting this to true,
2133 // we won't use the inherited vector anymore, but our own copy of it.
2135 public bool IsDirty {
2142 initialize_vector ();
2147 // Get/set bit `index' in the bit vector.
2149 public bool this [int index]
2153 throw new ArgumentOutOfRangeException ();
2155 // We're doing a "copy-on-write" strategy here; as long
2156 // as nobody writes to the array, we can use our parent's
2157 // copy instead of duplicating the vector.
2160 return vector [index];
2161 else if (InheritsFrom != null) {
2162 BitArray inherited = InheritsFrom.Vector;
2164 if (index < inherited.Count)
2165 return inherited [index];
2174 throw new ArgumentOutOfRangeException ();
2176 // Only copy the vector if we're actually modifying it.
2178 if (this [index] != value) {
2179 initialize_vector ();
2181 vector [index] = value;
2187 // If you explicitly convert the MyBitVector to a BitArray, you will get a deep
2188 // copy of the bit vector.
2190 public static explicit operator BitArray (MyBitVector vector)
2192 vector.initialize_vector ();
2193 return vector.Vector;
2197 // Performs an `or' operation on the bit vector. The `new_vector' may have a
2198 // different size than the current one.
2200 public void Or (MyBitVector new_vector)
2202 BitArray new_array = new_vector.Vector;
2204 initialize_vector ();
2207 if (vector.Count < new_array.Count)
2208 upper = vector.Count;
2210 upper = new_array.Count;
2212 for (int i = 0; i < upper; i++)
2213 vector [i] = vector [i] | new_array [i];
2217 // Perfonrms an `and' operation on the bit vector. The `new_vector' may have
2218 // a different size than the current one.
2220 public void And (MyBitVector new_vector)
2224 if (new_vector != null)
2225 new_array = new_vector.Vector;
2227 new_array = new BitArray (Count, false);
2229 initialize_vector ();
2232 if (vector.Count < new_array.Count)
2233 lower = upper = vector.Count;
2235 lower = new_array.Count;
2236 upper = vector.Count;
2239 for (int i = 0; i < lower; i++)
2240 vector [i] = vector [i] & new_array [i];
2242 for (int i = lower; i < upper; i++)
2246 public static void And (ref MyBitVector target, MyBitVector vector)
2249 target.And (vector);
2251 target = vector.Clone ();
2254 public static void Or (ref MyBitVector target, MyBitVector vector)
2259 target = vector.Clone ();
2263 // This does a deep copy of the bit vector.
2265 public MyBitVector Clone ()
2267 MyBitVector retval = new MyBitVector (Count);
2269 retval.Vector = Vector;
2278 else if (!is_dirty && (InheritsFrom != null))
2279 return InheritsFrom.Vector;
2281 initialize_vector ();
2287 initialize_vector ();
2289 for (int i = 0; i < System.Math.Min (vector.Count, value.Count); i++)
2290 vector [i] = value [i];
2294 void initialize_vector ()
2299 vector = new BitArray (Count, false);
2300 if (InheritsFrom != null)
2301 Vector = InheritsFrom.Vector;
2306 public override string ToString ()
2308 StringBuilder sb = new StringBuilder ("{");
2310 BitArray vector = Vector;
2313 for (int i = 0; i < vector.Count; i++) {
2314 sb.Append (vector [i] ? "1" : "0");
2318 return sb.ToString ();