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 `" +
1030 var.Name + "' must be " +
1031 "assigned before control leaves the current method.");
1035 protected UsageVector Merge (UsageVector sibling_list)
1037 if (sibling_list.Next == null)
1038 return sibling_list;
1040 MyBitVector locals = null;
1041 MyBitVector parameters = null;
1043 Reachability reachability = null;
1045 Report.Debug (2, " MERGING SIBLINGS", this, Name);
1047 for (UsageVector child = sibling_list; child != null; child = child.Next) {
1048 bool do_break = (Type != BranchingType.Switch) &&
1049 (Type != BranchingType.Loop);
1051 Report.Debug (2, " MERGING SIBLING ", child,
1052 child.ParameterVector, child.LocalVector,
1053 reachability, child.Reachability, do_break);
1055 Reachability.And (ref reachability, child.Reachability, do_break);
1057 // A local variable is initialized after a flow branching if it
1058 // has been initialized in all its branches which do neither
1059 // always return or always throw an exception.
1061 // If a branch may return, but does not always return, then we
1062 // can treat it like a never-returning branch here: control will
1063 // only reach the code position after the branching if we did not
1066 // It's important to distinguish between always and sometimes
1067 // returning branches here:
1070 // 2 if (something) {
1074 // 6 Console.WriteLine (a);
1076 // The if block in lines 3-4 always returns, so we must not look
1077 // at the initialization of `a' in line 4 - thus it'll still be
1078 // uninitialized in line 6.
1080 // On the other hand, the following is allowed:
1087 // 6 Console.WriteLine (a);
1089 // Here, `a' is initialized in line 3 and we must not look at
1090 // line 5 since it always returns.
1092 bool do_break_2 = (child.Type != SiblingType.Block) &&
1093 (child.Type != SiblingType.SwitchSection);
1094 bool always_throws = (child.Type != SiblingType.Try) &&
1095 child.Reachability.AlwaysThrows;
1096 bool unreachable = always_throws ||
1097 (do_break_2 && child.Reachability.AlwaysBreaks) ||
1098 child.Reachability.AlwaysReturns ||
1099 child.Reachability.AlwaysHasBarrier;
1101 Report.Debug (2, " MERGING SIBLING #1", reachability,
1102 Type, child.Type, child.Reachability.IsUnreachable,
1103 do_break_2, always_throws, unreachable);
1105 if (!unreachable && (child.LocalVector != null))
1106 MyBitVector.And (ref locals, child.LocalVector);
1108 // An `out' parameter must be assigned in all branches which do
1109 // not always throw an exception.
1110 if ((child.ParameterVector != null) && !child.Reachability.AlwaysThrows)
1111 MyBitVector.And (ref parameters, child.ParameterVector);
1113 Report.Debug (2, " MERGING SIBLING #2", parameters, locals);
1116 if (reachability == null)
1117 reachability = Reachability.Never ();
1119 Report.Debug (2, " MERGING SIBLINGS DONE", parameters, locals,
1120 reachability, Infinite);
1122 return new UsageVector (
1123 parameters, locals, reachability, null, Location);
1126 protected abstract UsageVector Merge ();
1129 // Merge a child branching.
1131 public UsageVector MergeChild (FlowBranching child)
1133 return CurrentUsageVector.MergeChild (child);
1137 // Does the toplevel merging.
1139 public Reachability MergeTopBlock ()
1141 if ((Type != BranchingType.Block) || (Block == null))
1142 throw new NotSupportedException ();
1144 UsageVector vector = new UsageVector (
1145 SiblingType.Block, null, Block, Location,
1146 param_map.Length, local_map.Length);
1148 UsageVector result = vector.MergeChild (this);
1150 Report.Debug (4, "MERGE TOP BLOCK", Location, vector, result.Reachability);
1152 if ((vector.Reachability.Throws != FlowReturns.Always) &&
1153 (vector.Reachability.Barrier != FlowReturns.Always))
1154 CheckOutParameters (vector.Parameters, Location);
1156 return result.Reachability;
1160 // Checks whether we're in a `try' block.
1162 public virtual bool InTryOrCatch (bool is_return)
1164 if ((Block != null) && Block.IsDestructor)
1166 else if (!is_return &&
1167 ((Type == BranchingType.Loop) || (Type == BranchingType.Switch)))
1169 else if (Parent != null)
1170 return Parent.InTryOrCatch (is_return);
1175 public virtual bool InTryWithCatch ()
1178 return Parent.InTryWithCatch ();
1182 public virtual bool InLoop ()
1184 if (Type == BranchingType.Loop)
1186 else if (Parent != null)
1187 return Parent.InLoop ();
1192 public virtual bool InSwitch ()
1194 if (Type == BranchingType.Switch)
1196 else if (Parent != null)
1197 return Parent.InSwitch ();
1202 public virtual bool BreakCrossesTryCatchBoundary ()
1204 if ((Type == BranchingType.Loop) || (Type == BranchingType.Switch))
1206 else if (Parent != null)
1207 return Parent.BreakCrossesTryCatchBoundary ();
1212 public virtual void AddFinallyVector (UsageVector vector)
1215 Parent.AddFinallyVector (vector);
1216 else if ((Block == null) || !Block.IsDestructor)
1217 throw new NotSupportedException ();
1220 public virtual void AddBreakVector (UsageVector vector)
1223 Parent.AddBreakVector (vector);
1224 else if ((Block == null) || !Block.IsDestructor)
1225 throw new NotSupportedException ();
1228 public virtual void StealFinallyClauses (ref ArrayList list)
1231 Parent.StealFinallyClauses (ref list);
1234 public bool IsAssigned (VariableInfo vi)
1236 return CurrentUsageVector.IsAssigned (vi);
1239 public bool IsFieldAssigned (VariableInfo vi, string field_name)
1241 if (CurrentUsageVector.IsAssigned (vi))
1244 return CurrentUsageVector.IsFieldAssigned (vi, field_name);
1247 public void SetAssigned (VariableInfo vi)
1249 CurrentUsageVector.SetAssigned (vi);
1252 public void SetFieldAssigned (VariableInfo vi, string name)
1254 CurrentUsageVector.SetFieldAssigned (vi, name);
1257 public override string ToString ()
1259 StringBuilder sb = new StringBuilder ();
1260 sb.Append (GetType ());
1266 if (Block != null) {
1268 sb.Append (Block.ID);
1270 sb.Append (Block.StartLocation);
1273 // sb.Append (Siblings.Length);
1274 // sb.Append (" - ");
1275 sb.Append (CurrentUsageVector);
1277 return sb.ToString ();
1280 public string Name {
1282 return String.Format ("{0} ({1}:{2}:{3})",
1283 GetType (), id, Type, Location);
1288 public class FlowBranchingBlock : FlowBranching
1290 UsageVector sibling_list = null;
1292 public FlowBranchingBlock (FlowBranching parent, BranchingType type,
1293 SiblingType stype, Block block, Location loc)
1294 : base (parent, type, stype, block, loc)
1297 public override UsageVector CurrentUsageVector {
1298 get { return sibling_list; }
1301 protected override void AddSibling (UsageVector sibling)
1303 sibling.Next = sibling_list;
1304 sibling_list = sibling;
1307 public override LabeledStatement LookupLabel (string name, Location loc)
1310 return base.LookupLabel (name, loc);
1312 LabeledStatement s = Block.LookupLabel (name);
1316 return base.LookupLabel (name, loc);
1319 public override void Label (UsageVector origin_vectors)
1321 if (!CurrentUsageVector.Reachability.IsUnreachable) {
1322 UsageVector vector = CurrentUsageVector.Clone ();
1323 vector.Next = origin_vectors;
1324 origin_vectors = vector;
1327 CurrentUsageVector.MergeJumpOrigins (origin_vectors);
1330 protected override UsageVector Merge ()
1332 return Merge (sibling_list);
1336 public class FlowBranchingLoop : FlowBranchingBlock
1338 UsageVector break_origins;
1340 public FlowBranchingLoop (FlowBranching parent, Block block, Location loc)
1341 : base (parent, BranchingType.Loop, SiblingType.Conditional, block, loc)
1344 public override void AddBreakVector (UsageVector vector)
1346 vector = vector.Clone ();
1347 vector.Next = break_origins;
1348 break_origins = vector;
1351 protected override UsageVector Merge ()
1353 UsageVector vector = base.Merge ();
1355 vector.MergeBreakOrigins (this, break_origins);
1361 public class FlowBranchingSwitch : FlowBranchingBlock
1363 UsageVector break_origins;
1365 public FlowBranchingSwitch (FlowBranching parent, Block block, Location loc)
1366 : base (parent, BranchingType.Switch, SiblingType.SwitchSection, block, loc)
1369 public override void AddBreakVector (UsageVector vector)
1371 vector = vector.Clone ();
1372 vector.Next = break_origins;
1373 break_origins = vector;
1376 protected override UsageVector Merge ()
1378 UsageVector vector = base.Merge ();
1380 vector.MergeBreakOrigins (this, break_origins);
1386 public class FlowBranchingException : FlowBranching
1388 ExceptionStatement stmt;
1389 UsageVector current_vector;
1390 UsageVector catch_vectors;
1391 UsageVector finally_vector;
1392 UsageVector finally_origins;
1395 public FlowBranchingException (FlowBranching parent,
1396 ExceptionStatement stmt)
1397 : base (parent, BranchingType.Exception, SiblingType.Try,
1401 this.emit_finally = true;
1404 protected override void AddSibling (UsageVector sibling)
1406 if (sibling.Type == SiblingType.Try) {
1407 sibling.Next = catch_vectors;
1408 catch_vectors = sibling;
1409 } else if (sibling.Type == SiblingType.Catch) {
1410 sibling.Next = catch_vectors;
1411 catch_vectors = sibling;
1412 } else if (sibling.Type == SiblingType.Finally) {
1413 sibling.MergeFinallyOrigins (finally_origins);
1414 finally_vector = sibling;
1416 throw new InvalidOperationException ();
1418 current_vector = sibling;
1421 public override UsageVector CurrentUsageVector {
1422 get { return current_vector; }
1425 public override bool InTryOrCatch (bool is_return)
1427 return finally_vector == null;
1430 public override bool InTryWithCatch ()
1432 if (finally_vector == null) {
1433 Try t = stmt as Try;
1434 if (t != null && t.HasCatch)
1439 return Parent.InTryWithCatch ();
1444 public override bool BreakCrossesTryCatchBoundary ()
1449 public override void AddFinallyVector (UsageVector vector)
1451 vector = vector.Clone ();
1452 vector.Next = finally_origins;
1453 finally_origins = vector;
1456 public override void StealFinallyClauses (ref ArrayList list)
1459 list = new ArrayList ();
1461 emit_finally = false;
1462 base.StealFinallyClauses (ref list);
1465 public bool EmitFinally {
1466 get { return emit_finally; }
1469 public override LabeledStatement LookupLabel (string name, Location loc)
1471 if (current_vector.Block == null)
1472 return base.LookupLabel (name, loc);
1474 LabeledStatement s = current_vector.Block.LookupLabel (name);
1478 if (finally_vector != null) {
1480 157, loc, "Control can not leave the body " +
1481 "of the finally block");
1485 return base.LookupLabel (name, loc);
1488 public override void Label (UsageVector origin_vectors)
1490 CurrentUsageVector.MergeJumpOrigins (origin_vectors);
1493 protected override UsageVector Merge ()
1495 UsageVector vector = Merge (catch_vectors);
1497 vector.MergeFinally (this, finally_vector, finally_origins);
1504 // This is used by the flow analysis code to keep track of the type of local variables
1507 // The flow code uses a BitVector to keep track of whether a variable has been assigned
1508 // or not. This is easy for fundamental types (int, char etc.) or reference types since
1509 // you can only assign the whole variable as such.
1511 // For structs, we also need to keep track of all its fields. To do this, we allocate one
1512 // bit for the struct itself (it's used if you assign/access the whole struct) followed by
1513 // one bit for each of its fields.
1515 // This class computes this `layout' for each type.
1517 public class TypeInfo
1519 public readonly Type Type;
1522 // Total number of bits a variable of this type consumes in the flow vector.
1524 public readonly int TotalLength;
1527 // Number of bits the simple fields of a variable of this type consume
1528 // in the flow vector.
1530 public readonly int Length;
1533 // This is only used by sub-structs.
1535 public readonly int Offset;
1538 // If this is a struct.
1540 public readonly bool IsStruct;
1543 // If this is a struct, all fields which are structs theirselves.
1545 public TypeInfo[] SubStructInfo;
1547 protected readonly StructInfo struct_info;
1548 private static Hashtable type_hash = new Hashtable ();
1550 public static TypeInfo GetTypeInfo (Type type)
1552 TypeInfo info = (TypeInfo) type_hash [type];
1556 info = new TypeInfo (type);
1557 type_hash.Add (type, info);
1561 public static TypeInfo GetTypeInfo (TypeContainer tc)
1563 TypeInfo info = (TypeInfo) type_hash [tc.TypeBuilder];
1567 info = new TypeInfo (tc);
1568 type_hash.Add (tc.TypeBuilder, info);
1572 private TypeInfo (Type type)
1576 struct_info = StructInfo.GetStructInfo (type);
1577 if (struct_info != null) {
1578 Length = struct_info.Length;
1579 TotalLength = struct_info.TotalLength;
1580 SubStructInfo = struct_info.StructFields;
1589 private TypeInfo (TypeContainer tc)
1591 this.Type = tc.TypeBuilder;
1593 struct_info = StructInfo.GetStructInfo (tc);
1594 if (struct_info != null) {
1595 Length = struct_info.Length;
1596 TotalLength = struct_info.TotalLength;
1597 SubStructInfo = struct_info.StructFields;
1606 protected TypeInfo (StructInfo struct_info, int offset)
1608 this.struct_info = struct_info;
1609 this.Offset = offset;
1610 this.Length = struct_info.Length;
1611 this.TotalLength = struct_info.TotalLength;
1612 this.SubStructInfo = struct_info.StructFields;
1613 this.Type = struct_info.Type;
1614 this.IsStruct = true;
1617 public int GetFieldIndex (string name)
1619 if (struct_info == null)
1622 return struct_info [name];
1625 public TypeInfo GetSubStruct (string name)
1627 if (struct_info == null)
1630 return struct_info.GetStructField (name);
1634 // A struct's constructor must always assign all fields.
1635 // This method checks whether it actually does so.
1637 public bool IsFullyInitialized (FlowBranching branching, VariableInfo vi, Location loc)
1639 if (struct_info == null)
1643 for (int i = 0; i < struct_info.Count; i++) {
1644 FieldInfo field = struct_info.Fields [i];
1646 if (!branching.IsFieldAssigned (vi, field.Name)) {
1647 Report.Error (171, loc,
1648 "Field `" + TypeManager.CSharpName (Type) +
1649 "." + field.Name + "' must be fully initialized " +
1650 "before control leaves the constructor");
1658 public override string ToString ()
1660 return String.Format ("TypeInfo ({0}:{1}:{2}:{3})",
1661 Type, Offset, Length, TotalLength);
1664 protected class StructInfo {
1665 public readonly Type Type;
1666 public readonly FieldInfo[] Fields;
1667 public readonly TypeInfo[] StructFields;
1668 public readonly int Count;
1669 public readonly int CountPublic;
1670 public readonly int CountNonPublic;
1671 public readonly int Length;
1672 public readonly int TotalLength;
1673 public readonly bool HasStructFields;
1675 private static Hashtable field_type_hash = new Hashtable ();
1676 private Hashtable struct_field_hash;
1677 private Hashtable field_hash;
1679 protected bool InTransit = false;
1681 // Private constructor. To save memory usage, we only need to create one instance
1682 // of this class per struct type.
1683 private StructInfo (Type type)
1687 field_type_hash.Add (type, this);
1689 if (type is TypeBuilder) {
1690 TypeContainer tc = TypeManager.LookupTypeContainer (type);
1692 ArrayList fields = null;
1696 ArrayList public_fields = new ArrayList ();
1697 ArrayList non_public_fields = new ArrayList ();
1699 if (fields != null) {
1700 foreach (FieldMember field in fields) {
1701 if ((field.ModFlags & Modifiers.STATIC) != 0)
1703 if ((field.ModFlags & Modifiers.PUBLIC) != 0)
1704 public_fields.Add (field.FieldBuilder);
1706 non_public_fields.Add (field.FieldBuilder);
1710 CountPublic = public_fields.Count;
1711 CountNonPublic = non_public_fields.Count;
1712 Count = CountPublic + CountNonPublic;
1714 Fields = new FieldInfo [Count];
1715 public_fields.CopyTo (Fields, 0);
1716 non_public_fields.CopyTo (Fields, CountPublic);
1717 } else if (type is GenericTypeParameterBuilder) {
1718 CountPublic = CountNonPublic = Count = 0;
1720 Fields = new FieldInfo [0];
1722 FieldInfo[] public_fields = type.GetFields (
1723 BindingFlags.Instance|BindingFlags.Public);
1724 FieldInfo[] non_public_fields = type.GetFields (
1725 BindingFlags.Instance|BindingFlags.NonPublic);
1727 CountPublic = public_fields.Length;
1728 CountNonPublic = non_public_fields.Length;
1729 Count = CountPublic + CountNonPublic;
1731 Fields = new FieldInfo [Count];
1732 public_fields.CopyTo (Fields, 0);
1733 non_public_fields.CopyTo (Fields, CountPublic);
1736 struct_field_hash = new Hashtable ();
1737 field_hash = new Hashtable ();
1740 StructFields = new TypeInfo [Count];
1741 StructInfo[] sinfo = new StructInfo [Count];
1745 for (int i = 0; i < Count; i++) {
1746 FieldInfo field = (FieldInfo) Fields [i];
1748 sinfo [i] = GetStructInfo (field.FieldType);
1749 if (sinfo [i] == null)
1750 field_hash.Add (field.Name, ++Length);
1751 else if (sinfo [i].InTransit) {
1752 Report.Error (523, String.Format (
1753 "Struct member '{0}.{1}' of type '{2}' causes " +
1754 "a cycle in the structure layout",
1755 type, field.Name, sinfo [i].Type));
1763 TotalLength = Length + 1;
1764 for (int i = 0; i < Count; i++) {
1765 FieldInfo field = (FieldInfo) Fields [i];
1767 if (sinfo [i] == null)
1770 field_hash.Add (field.Name, TotalLength);
1772 HasStructFields = true;
1773 StructFields [i] = new TypeInfo (sinfo [i], TotalLength);
1774 struct_field_hash.Add (field.Name, StructFields [i]);
1775 TotalLength += sinfo [i].TotalLength;
1779 public int this [string name] {
1781 if (field_hash.Contains (name))
1782 return (int) field_hash [name];
1788 public TypeInfo GetStructField (string name)
1790 return (TypeInfo) struct_field_hash [name];
1793 public static StructInfo GetStructInfo (Type type)
1795 if (!TypeManager.IsValueType (type) || TypeManager.IsEnumType (type) ||
1796 TypeManager.IsBuiltinType (type))
1799 StructInfo info = (StructInfo) field_type_hash [type];
1803 return new StructInfo (type);
1806 public static StructInfo GetStructInfo (TypeContainer tc)
1808 StructInfo info = (StructInfo) field_type_hash [tc.TypeBuilder];
1812 return new StructInfo (tc.TypeBuilder);
1818 // This is used by the flow analysis code to store information about a single local variable
1819 // or parameter. Depending on the variable's type, we need to allocate one or more elements
1820 // in the BitVector - if it's a fundamental or reference type, we just need to know whether
1821 // it has been assigned or not, but for structs, we need this information for each of its fields.
1823 public class VariableInfo {
1824 public readonly string Name;
1825 public readonly TypeInfo TypeInfo;
1828 // The bit offset of this variable in the flow vector.
1830 public readonly int Offset;
1833 // The number of bits this variable needs in the flow vector.
1834 // The first bit always specifies whether the variable as such has been assigned while
1835 // the remaining bits contain this information for each of a struct's fields.
1837 public readonly int Length;
1840 // If this is a parameter of local variable.
1842 public readonly bool IsParameter;
1844 public readonly LocalInfo LocalInfo;
1845 public readonly int ParameterIndex;
1847 readonly VariableInfo Parent;
1848 VariableInfo[] sub_info;
1850 protected VariableInfo (string name, Type type, int offset)
1853 this.Offset = offset;
1854 this.TypeInfo = TypeInfo.GetTypeInfo (type);
1856 Length = TypeInfo.TotalLength;
1861 protected VariableInfo (VariableInfo parent, TypeInfo type)
1863 this.Name = parent.Name;
1864 this.TypeInfo = type;
1865 this.Offset = parent.Offset + type.Offset;
1866 this.Parent = parent;
1867 this.Length = type.TotalLength;
1869 this.IsParameter = parent.IsParameter;
1870 this.LocalInfo = parent.LocalInfo;
1871 this.ParameterIndex = parent.ParameterIndex;
1876 protected void Initialize ()
1878 TypeInfo[] sub_fields = TypeInfo.SubStructInfo;
1879 if (sub_fields != null) {
1880 sub_info = new VariableInfo [sub_fields.Length];
1881 for (int i = 0; i < sub_fields.Length; i++) {
1882 if (sub_fields [i] != null)
1883 sub_info [i] = new VariableInfo (this, sub_fields [i]);
1886 sub_info = new VariableInfo [0];
1889 public VariableInfo (LocalInfo local_info, int offset)
1890 : this (local_info.Name, local_info.VariableType, offset)
1892 this.LocalInfo = local_info;
1893 this.IsParameter = false;
1896 public VariableInfo (string name, Type type, int param_idx, int offset)
1897 : this (name, type, offset)
1899 this.ParameterIndex = param_idx;
1900 this.IsParameter = true;
1903 public bool IsAssigned (EmitContext ec)
1905 return !ec.DoFlowAnalysis || ec.CurrentBranching.IsAssigned (this);
1908 public bool IsAssigned (EmitContext ec, Location loc)
1910 if (IsAssigned (ec))
1913 Report.Error (165, loc,
1914 "Use of unassigned local variable `" + Name + "'");
1915 ec.CurrentBranching.SetAssigned (this);
1919 public bool IsAssigned (MyBitVector vector)
1921 if (vector [Offset])
1924 for (VariableInfo parent = Parent; parent != null; parent = parent.Parent)
1925 if (vector [parent.Offset])
1928 // Return unless this is a struct.
1929 if (!TypeInfo.IsStruct)
1932 // Ok, so each field must be assigned.
1933 for (int i = 0; i < TypeInfo.Length; i++) {
1934 if (!vector [Offset + i + 1])
1938 // Ok, now check all fields which are structs.
1939 for (int i = 0; i < sub_info.Length; i++) {
1940 VariableInfo sinfo = sub_info [i];
1944 if (!sinfo.IsAssigned (vector))
1948 vector [Offset] = true;
1952 public void SetAssigned (EmitContext ec)
1954 if (ec.DoFlowAnalysis)
1955 ec.CurrentBranching.SetAssigned (this);
1958 public void SetAssigned (MyBitVector vector)
1960 vector [Offset] = true;
1963 public bool IsFieldAssigned (EmitContext ec, string name, Location loc)
1965 if (!ec.DoFlowAnalysis || ec.CurrentBranching.IsFieldAssigned (this, name))
1968 Report.Error (170, loc,
1969 "Use of possibly unassigned field `" + name + "'");
1970 ec.CurrentBranching.SetFieldAssigned (this, name);
1974 public bool IsFieldAssigned (MyBitVector vector, string field_name)
1976 int field_idx = TypeInfo.GetFieldIndex (field_name);
1981 return vector [Offset + field_idx];
1984 public void SetFieldAssigned (EmitContext ec, string name)
1986 if (ec.DoFlowAnalysis)
1987 ec.CurrentBranching.SetFieldAssigned (this, name);
1990 public void SetFieldAssigned (MyBitVector vector, string field_name)
1992 int field_idx = TypeInfo.GetFieldIndex (field_name);
1997 vector [Offset + field_idx] = true;
2000 public VariableInfo GetSubStruct (string name)
2002 TypeInfo type = TypeInfo.GetSubStruct (name);
2007 return new VariableInfo (this, type);
2010 public override string ToString ()
2012 return String.Format ("VariableInfo ({0}:{1}:{2}:{3}:{4})",
2013 Name, TypeInfo, Offset, Length, IsParameter);
2018 // This is used by the flow code to hold the `layout' of the flow vector for
2019 // all locals and all parameters (ie. we create one instance of this class for the
2020 // locals and another one for the params).
2022 public class VariableMap {
2024 // The number of variables in the map.
2026 public readonly int Count;
2029 // Total length of the flow vector for this map.
2031 public readonly int Length;
2035 public VariableMap (InternalParameters ip)
2037 Count = ip != null ? ip.Count : 0;
2039 // Dont bother allocating anything!
2045 for (int i = 0; i < Count; i++) {
2046 Parameter.Modifier mod = ip.ParameterModifier (i);
2048 if ((mod & Parameter.Modifier.OUT) == 0)
2051 // Dont allocate till we find an out var.
2053 map = new VariableInfo [Count];
2055 map [i] = new VariableInfo (ip.ParameterName (i),
2056 TypeManager.GetElementType (ip.ParameterType (i)), i, Length);
2058 Length += map [i].Length;
2062 public VariableMap (LocalInfo[] locals)
2063 : this (null, locals)
2066 public VariableMap (VariableMap parent, LocalInfo[] locals)
2068 int offset = 0, start = 0;
2069 if (parent != null && parent.map != null) {
2070 offset = parent.Length;
2071 start = parent.Count;
2074 Count = locals.Length + start;
2079 map = new VariableInfo [Count];
2082 if (parent != null && parent.map != null) {
2083 parent.map.CopyTo (map, 0);
2086 for (int i = start; i < Count; i++) {
2087 LocalInfo li = locals [i-start];
2089 if (li.VariableType == null)
2092 map [i] = li.VariableInfo = new VariableInfo (li, Length);
2093 Length += map [i].Length;
2098 // Returns the VariableInfo for variable @index or null if we don't need to
2099 // compute assignment info for this variable.
2101 public VariableInfo this [int index] {
2110 public override string ToString ()
2112 return String.Format ("VariableMap ({0}:{1})", Count, Length);
2117 // This is a special bit vector which can inherit from another bit vector doing a
2118 // copy-on-write strategy. The inherited vector may have a smaller size than the
2121 public class MyBitVector {
2122 public readonly int Count;
2123 public readonly MyBitVector InheritsFrom;
2128 public MyBitVector (int Count)
2129 : this (null, Count)
2132 public MyBitVector (MyBitVector InheritsFrom, int Count)
2134 this.InheritsFrom = InheritsFrom;
2139 // Checks whether this bit vector has been modified. After setting this to true,
2140 // we won't use the inherited vector anymore, but our own copy of it.
2142 public bool IsDirty {
2149 initialize_vector ();
2154 // Get/set bit `index' in the bit vector.
2156 public bool this [int index]
2160 throw new ArgumentOutOfRangeException ();
2162 // We're doing a "copy-on-write" strategy here; as long
2163 // as nobody writes to the array, we can use our parent's
2164 // copy instead of duplicating the vector.
2167 return vector [index];
2168 else if (InheritsFrom != null) {
2169 BitArray inherited = InheritsFrom.Vector;
2171 if (index < inherited.Count)
2172 return inherited [index];
2181 throw new ArgumentOutOfRangeException ();
2183 // Only copy the vector if we're actually modifying it.
2185 if (this [index] != value) {
2186 initialize_vector ();
2188 vector [index] = value;
2194 // If you explicitly convert the MyBitVector to a BitArray, you will get a deep
2195 // copy of the bit vector.
2197 public static explicit operator BitArray (MyBitVector vector)
2199 vector.initialize_vector ();
2200 return vector.Vector;
2204 // Performs an `or' operation on the bit vector. The `new_vector' may have a
2205 // different size than the current one.
2207 public void Or (MyBitVector new_vector)
2209 BitArray new_array = new_vector.Vector;
2211 initialize_vector ();
2214 if (vector.Count < new_array.Count)
2215 upper = vector.Count;
2217 upper = new_array.Count;
2219 for (int i = 0; i < upper; i++)
2220 vector [i] = vector [i] | new_array [i];
2224 // Perfonrms an `and' operation on the bit vector. The `new_vector' may have
2225 // a different size than the current one.
2227 public void And (MyBitVector new_vector)
2231 if (new_vector != null)
2232 new_array = new_vector.Vector;
2234 new_array = new BitArray (Count, false);
2236 initialize_vector ();
2239 if (vector.Count < new_array.Count)
2240 lower = upper = vector.Count;
2242 lower = new_array.Count;
2243 upper = vector.Count;
2246 for (int i = 0; i < lower; i++)
2247 vector [i] = vector [i] & new_array [i];
2249 for (int i = lower; i < upper; i++)
2253 public static void And (ref MyBitVector target, MyBitVector vector)
2256 target.And (vector);
2258 target = vector.Clone ();
2261 public static void Or (ref MyBitVector target, MyBitVector vector)
2266 target = vector.Clone ();
2270 // This does a deep copy of the bit vector.
2272 public MyBitVector Clone ()
2274 MyBitVector retval = new MyBitVector (Count);
2276 retval.Vector = Vector;
2285 else if (!is_dirty && (InheritsFrom != null))
2286 return InheritsFrom.Vector;
2288 initialize_vector ();
2294 initialize_vector ();
2296 for (int i = 0; i < System.Math.Min (vector.Count, value.Count); i++)
2297 vector [i] = value [i];
2301 void initialize_vector ()
2306 vector = new BitArray (Count, false);
2307 if (InheritsFrom != null)
2308 Vector = InheritsFrom.Vector;
2313 public override string ToString ()
2315 StringBuilder sb = new StringBuilder ("{");
2317 BitArray vector = Vector;
2320 for (int i = 0; i < vector.Count; i++) {
2321 sb.Append (vector [i] ? "1" : "0");
2325 return sb.ToString ();