In mcs:
[mono.git] / mcs / mcs / flowanalysis.cs
index 3f342422a0392f4708a42c670f12a496373f6d58..f24ede7b7f99cce46c7aec29a8d39c8da1fc35dc 100644 (file)
@@ -16,6 +16,13 @@ using System.Diagnostics;
 
 namespace Mono.CSharp
 {
+       public enum TriState : byte {
+               // Never < Sometimes < Always
+               Never,
+               Sometimes,
+               Always
+       }
+
        // <summary>
        //   A new instance of this class is created every time a new block is resolved
        //   and if there's branching in the block's control flow.
@@ -25,7 +32,7 @@ namespace Mono.CSharp
                // <summary>
                //   The type of a FlowBranching.
                // </summary>
-               public enum BranchingType {
+               public enum BranchingType : byte {
                        // Normal (conditional or toplevel) block.
                        Block,
 
@@ -33,7 +40,13 @@ namespace Mono.CSharp
                        Conditional,
 
                        // A loop block.
-                       LoopBlock,
+                       Loop,
+
+                       // The statement embedded inside a loop
+                       Embedded,
+
+                       // part of a block headed by a jump target
+                       Labeled,
 
                        // Try/Catch block.
                        Exception,
@@ -42,13 +55,16 @@ namespace Mono.CSharp
                        Switch,
 
                        // Switch section.
-                       SwitchSection
+                       SwitchSection,
+
+                       // The toplevel block of a function
+                       Toplevel
                }
 
                // <summary>
                //   The type of one sibling of a branching.
                // </summary>
-               public enum SiblingType {
+               public enum SiblingType : byte {
                        Block,
                        Conditional,
                        SwitchSection,
@@ -57,228 +73,119 @@ namespace Mono.CSharp
                        Finally
                }
 
-               // <summary>
-               //   This is used in the control flow analysis code to specify whether the
-               //   current code block may return to its enclosing block before reaching
-               //   its end.
-               // </summary>
-               public enum FlowReturns {
-                       Undefined = 0,
-
-                       // It can never return.
-                       Never,
-
-                       // This means that the block contains a conditional return statement
-                       // somewhere.
-                       Sometimes,
-
-                       // The code always returns, ie. there's an unconditional return / break
-                       // statement in it.
-                       Always
-               }
-
                public sealed class Reachability
                {
-                       FlowReturns returns, breaks, throws, barrier, reachable;
+                       TriState returns, throws, barrier;
 
-                       public FlowReturns Returns {
+                       public TriState Returns {
                                get { return returns; }
                        }
-                       public FlowReturns Breaks {
-                               get { return breaks; }
-                       }
-                       public FlowReturns Throws {
+                       public TriState Throws {
                                get { return throws; }
                        }
-                       public FlowReturns Barrier {
+                       public TriState Barrier {
                                get { return barrier; }
                        }
-                       public FlowReturns Reachable {
-                               get { return reachable; }
-                       }
 
-                       public Reachability (FlowReturns returns, FlowReturns breaks,
-                                            FlowReturns throws, FlowReturns barrier)
+                       Reachability (TriState returns, TriState throws, TriState barrier)
                        {
                                this.returns = returns;
-                               this.breaks = breaks;
                                this.throws = throws;
                                this.barrier = barrier;
-
-                               update ();
                        }
 
                        public Reachability Clone ()
                        {
-                               Reachability cloned = new Reachability (returns, breaks, throws, barrier);
-                               cloned.reachable = reachable;
-                               return cloned;
+                               return new Reachability (returns, throws, barrier);
                        }
 
-                       public static void And (ref Reachability a, Reachability b, bool do_break)
+                       public static TriState TriState_Meet (TriState a, TriState b)
                        {
-                               if (a == null) {
-                                       a = b.Clone ();
-                                       return;
-                               }
-
-                               Report.Debug (4, "AND REACHABILITY", a, b, do_break);
-
-                               //
-                               // `break' does not "break" in a Switch or a LoopBlock
-                               //
-                               bool a_breaks = do_break && a.AlwaysBreaks;
-                               bool b_breaks = do_break && b.AlwaysBreaks;
-
-                               bool a_has_barrier, b_has_barrier;
-                               if (do_break) {
-                                       //
-                                       // This is the normal case: the code following a barrier
-                                       // cannot be reached.
-                                       //
-                                       a_has_barrier = a.AlwaysHasBarrier;
-                                       b_has_barrier = b.AlwaysHasBarrier;
-                               } else {
-                                       //
-                                       // Special case for Switch and LoopBlocks: we can reach the
-                                       // code after the barrier via the `break'.
-                                       //
-                                       a_has_barrier = !a.AlwaysBreaks && a.AlwaysHasBarrier;
-                                       b_has_barrier = !b.AlwaysBreaks && b.AlwaysHasBarrier;
-                               }
-
-                               bool a_unreachable = a_breaks || a.AlwaysThrows || a_has_barrier;
-                               bool b_unreachable = b_breaks || b.AlwaysThrows || b_has_barrier;
-
-                               //
-                               // Do all code paths always return ?
-                               //
-                               if (a.AlwaysReturns) {
-                                       if (b.AlwaysReturns || b_unreachable)
-                                               a.returns = FlowReturns.Always;
-                                       else
-                                               a.returns = FlowReturns.Sometimes;
-                               } else if (b.AlwaysReturns) {
-                                       if (a.AlwaysReturns || a_unreachable)
-                                               a.returns = FlowReturns.Always;
-                                       else
-                                               a.returns = FlowReturns.Sometimes;
-                               } else if (!a.MayReturn) {
-                                       if (b.MayReturn)
-                                               a.returns = FlowReturns.Sometimes;
-                                       else
-                                               a.returns = FlowReturns.Never;
-                               } else if (!b.MayReturn) {
-                                       if (a.MayReturn)
-                                               a.returns = FlowReturns.Sometimes;
-                                       else
-                                               a.returns = FlowReturns.Never;
-                               }
-
-                               a.breaks = AndFlowReturns (a.breaks, b.breaks);
-                               a.throws = AndFlowReturns (a.throws, b.throws);
-                               a.barrier = AndFlowReturns (a.barrier, b.barrier);
-
-                               a.reachable = AndFlowReturns (a.reachable, b.reachable);
+                               // (1) if both are Never, return Never
+                               // (2) if both are Always, return Always
+                               // (3) otherwise, return Sometimes
+                               // note that (3) => (3') if both are Sometimes, return Sometimes
+                               return a == b ? a : TriState.Sometimes;
                        }
 
-                       public static Reachability Never ()
+                       public static TriState TriState_Max (TriState a, TriState b)
                        {
-                               return new Reachability (
-                                       FlowReturns.Never, FlowReturns.Never,
-                                       FlowReturns.Never, FlowReturns.Never);
+                               return ((byte) a > (byte) b) ? a : b;
                        }
 
-                       void update ()
+                       public void Meet (Reachability b)
                        {
-                               if ((returns == FlowReturns.Always) || (breaks == FlowReturns.Always) ||
-                                   (throws == FlowReturns.Always) || (barrier == FlowReturns.Always))
-                                       reachable = FlowReturns.Never;
-                               else if ((returns == FlowReturns.Never) && (breaks == FlowReturns.Never) &&
-                                        (throws == FlowReturns.Never) && (barrier == FlowReturns.Never))
-                                       reachable = FlowReturns.Always;
+                               if ((AlwaysReturns && b.AlwaysHasBarrier) || (AlwaysHasBarrier && b.AlwaysReturns))
+                                       returns = TriState.Always;
                                else
-                                       reachable = FlowReturns.Sometimes;
-                       }
+                                       returns = TriState_Meet (returns, b.returns);
 
-                       public bool AlwaysBreaks {
-                               get { return breaks == FlowReturns.Always; }
+                               throws = TriState_Meet (throws, b.throws);
+                               barrier = TriState_Meet (barrier, b.barrier);
                        }
 
-                       public bool MayBreak {
-                               get { return breaks != FlowReturns.Never; }
+                       public void Or (Reachability b)
+                       {
+                               returns = TriState_Max (returns, b.returns);
+                               throws = TriState_Max (throws, b.throws);
+                               barrier = TriState_Max (barrier, b.barrier);
                        }
 
-                       public bool AlwaysReturns {
-                               get { return returns == FlowReturns.Always; }
+                       public static Reachability Always ()
+                       {
+                               return new Reachability (TriState.Never, TriState.Never, TriState.Never);
                        }
 
-                       public bool MayReturn {
-                               get { return returns != FlowReturns.Never; }
+                       TriState Unreachable {
+                               get { return TriState_Max (returns, TriState_Max (throws, barrier)); }
                        }
 
-                       public bool AlwaysThrows {
-                               get { return throws == FlowReturns.Always; }
+                       TriState Reachable {
+                               get {
+                                       TriState unreachable = Unreachable;
+                                       if (unreachable == TriState.Sometimes)
+                                               return TriState.Sometimes;
+                                       return unreachable == TriState.Always ? TriState.Never : TriState.Always;
+                               }
                        }
 
-                       public bool MayThrow {
-                               get { return throws != FlowReturns.Never; }
+                       public bool AlwaysReturns {
+                               get { return returns == TriState.Always; }
                        }
 
-                       public bool AlwaysHasBarrier {
-                               get { return barrier == FlowReturns.Always; }
+                       public bool AlwaysThrows {
+                               get { return throws == TriState.Always; }
                        }
 
-                       public bool MayHaveBarrier {
-                               get { return barrier != FlowReturns.Never; }
+                       public bool AlwaysHasBarrier {
+                               get { return barrier == TriState.Always; }
                        }
 
                        public bool IsUnreachable {
-                               get { return reachable == FlowReturns.Never; }
+                               get { return Unreachable == TriState.Always; }
                        }
 
                        public void SetReturns ()
                        {
-                               returns = FlowReturns.Always;
-                               update ();
-                       }
-
-                       public void SetReturnsSometimes ()
-                       {
-                               returns = FlowReturns.Sometimes;
-                               update ();
-                       }
-
-                       public void SetBreaks ()
-                       {
-                               breaks = FlowReturns.Always;
-                               update ();
-                       }
-
-                       public void ResetBreaks ()
-                       {
-                               breaks = FlowReturns.Never;
-                               update ();
+                               returns = TriState.Always;
                        }
 
                        public void SetThrows ()
                        {
-                               throws = FlowReturns.Always;
-                               update ();
+                               throws = TriState.Always;
                        }
 
                        public void SetBarrier ()
                        {
-                               barrier = FlowReturns.Always;
-                               update ();
+                               barrier = TriState.Always;
                        }
 
-                       static string ShortName (FlowReturns returns)
+                       static string ShortName (TriState returns)
                        {
                                switch (returns) {
-                               case FlowReturns.Never:
+                               case TriState.Never:
                                        return "N";
-                               case FlowReturns.Sometimes:
+                               case TriState.Sometimes:
                                        return "S";
                                default:
                                        return "A";
@@ -287,10 +194,9 @@ namespace Mono.CSharp
 
                        public override string ToString ()
                        {
-                               return String.Format ("[{0}:{1}:{2}:{3}:{4}]",
-                                                     ShortName (returns), ShortName (breaks),
-                                                     ShortName (throws), ShortName (barrier),
-                                                     ShortName (reachable));
+                               return String.Format ("[{0}:{1}:{2}:{3}]",
+                                                     ShortName (returns), ShortName (throws), ShortName (barrier),
+                                                     ShortName (Reachable));
                        }
                }
 
@@ -298,10 +204,12 @@ namespace Mono.CSharp
                {
                        switch (type) {
                        case BranchingType.Exception:
-                               return new FlowBranchingException (parent, type, block, loc);
+                       case BranchingType.Labeled:
+                       case BranchingType.Toplevel:
+                               throw new InvalidOperationException ();
 
                        case BranchingType.Switch:
-                               return new FlowBranchingBlock (parent, type, SiblingType.SwitchSection, block, loc);
+                               return new FlowBranchingBreakable (parent, type, SiblingType.SwitchSection, block, loc);
 
                        case BranchingType.SwitchSection:
                                return new FlowBranchingBlock (parent, type, SiblingType.Block, block, loc);
@@ -309,6 +217,12 @@ namespace Mono.CSharp
                        case BranchingType.Block:
                                return new FlowBranchingBlock (parent, type, SiblingType.Block, block, loc);
 
+                       case BranchingType.Loop:
+                               return new FlowBranchingBreakable (parent, type, SiblingType.Conditional, block, loc);
+
+                       case BranchingType.Embedded:
+                               return new FlowBranchingContinuable (parent, type, SiblingType.Conditional, block, loc);
+
                        default:
                                return new FlowBranchingBlock (parent, type, SiblingType.Conditional, block, loc);
                        }
@@ -335,11 +249,6 @@ namespace Mono.CSharp
                // </summary>
                public readonly Location Location;
 
-               // <summary>
-               //   If this is an infinite loop.
-               // </summary>
-               public bool Infinite;
-
                //
                // Private
                //
@@ -348,39 +257,6 @@ namespace Mono.CSharp
                static int next_id = 0;
                int id;
 
-               // <summary>
-               //   Performs an `And' operation on the FlowReturns status
-               //   (for instance, a block only returns Always if all its siblings
-               //   always return).
-               // </summary>
-               public static FlowReturns AndFlowReturns (FlowReturns a, FlowReturns b)
-               {
-                       if (a == FlowReturns.Undefined)
-                               return b;
-
-                       switch (a) {
-                       case FlowReturns.Never:
-                               if (b == FlowReturns.Never)
-                                       return FlowReturns.Never;
-                               else
-                                       return FlowReturns.Sometimes;
-
-                       case FlowReturns.Sometimes:
-                               return FlowReturns.Sometimes;
-
-                       case FlowReturns.Always:
-                               if (b == FlowReturns.Always)
-                                       return FlowReturns.Always;
-                               else
-                                       return FlowReturns.Sometimes;
-
-                       default:
-                               throw new ArgumentException ();
-                       }
-
-                       return b;
-               }
-
                // <summary>
                //   The vector contains a BitArray with information about which local variables
                //   and parameters are already initialized at the current code position.
@@ -394,7 +270,12 @@ namespace Mono.CSharp
                        // <summary>
                        //   Start location of this branching.
                        // </summary>
-                       public readonly Location Location;
+                       public Location Location;
+
+                       // <summary>
+                       //   This is only valid for SwitchSection, Try, Catch and Finally.
+                       // </summary>
+                       public readonly Block Block;
 
                        // <summary>
                        //   If this is true, then the usage vector has been modified and must be
@@ -429,7 +310,6 @@ namespace Mono.CSharp
                        //
                        MyBitVector locals, parameters;
                        Reachability reachability;
-                       bool is_finally;
 
                        static int next_id = 0;
                        int id;
@@ -437,40 +317,51 @@ namespace Mono.CSharp
                        //
                        // Normally, you should not use any of these constructors.
                        //
-                       public UsageVector (SiblingType type, UsageVector parent, Location loc, int num_params, int num_locals)
+                       public UsageVector (SiblingType type, UsageVector parent,
+                                           Block block, Location loc,
+                                           int num_params, int num_locals)
                        {
                                this.Type = type;
+                               this.Block = block;
                                this.Location = loc;
                                this.InheritsFrom = parent;
                                this.CountParameters = num_params;
                                this.CountLocals = num_locals;
 
                                if (parent != null) {
-                                       locals = new MyBitVector (parent.locals, CountLocals);
+                                       if (num_locals > 0)
+                                               locals = new MyBitVector (parent.locals, CountLocals);
+                                       
                                        if (num_params > 0)
                                                parameters = new MyBitVector (parent.parameters, num_params);
 
                                        reachability = parent.Reachability.Clone ();
                                } else {
-                                       locals = new MyBitVector (null, CountLocals);
+                                       if (num_locals > 0)
+                                               locals = new MyBitVector (null, CountLocals);
+                                       
                                        if (num_params > 0)
                                                parameters = new MyBitVector (null, num_params);
 
-                                       reachability = Reachability.Never ();
+                                       reachability = Reachability.Always ();
                                }
 
                                id = ++next_id;
                        }
 
-                       public UsageVector (SiblingType type, UsageVector parent, Location loc)
-                               : this (type, parent, loc, parent.CountParameters, parent.CountLocals)
+                       public UsageVector (SiblingType type, UsageVector parent,
+                                           Block block, Location loc)
+                               : this (type, parent, block, loc,
+                                       parent.CountParameters, parent.CountLocals)
                        { }
 
                        public UsageVector (MyBitVector parameters, MyBitVector locals,
-                                           Reachability reachability, Location loc)
+                                           Reachability reachability, Block block,
+                                           Location loc)
                        {
                                this.Type = SiblingType.Block;
                                this.Location = loc;
+                               this.Block = block;
 
                                this.reachability = reachability;
                                this.parameters = parameters;
@@ -484,19 +375,24 @@ namespace Mono.CSharp
                        // </summary>
                        public UsageVector Clone ()
                        {
-                               UsageVector retval = new UsageVector (Type, null, Location, CountParameters, CountLocals);
+                               UsageVector retval = new UsageVector (
+                                       Type, null, Block, Location,
+                                       CountParameters, CountLocals);
 
-                               retval.locals = locals.Clone ();
+                               if (retval.locals != null)
+                                       retval.locals = locals.Clone ();
+                               
                                if (parameters != null)
                                        retval.parameters = parameters.Clone ();
+                               
                                retval.reachability = reachability.Clone ();
 
                                return retval;
                        }
 
-                       public bool IsAssigned (VariableInfo var)
+                       public bool IsAssigned (VariableInfo var, bool ignoreReachability)
                        {
-                               if (!var.IsParameter && Reachability.AlwaysBreaks)
+                               if (!ignoreReachability && !var.IsParameter && Reachability.IsUnreachable)
                                        return true;
 
                                return var.IsAssigned (var.IsParameter ? parameters : locals);
@@ -504,7 +400,7 @@ namespace Mono.CSharp
 
                        public void SetAssigned (VariableInfo var)
                        {
-                               if (!var.IsParameter && Reachability.AlwaysBreaks)
+                               if (!var.IsParameter && Reachability.IsUnreachable)
                                        return;
 
                                IsDirty = true;
@@ -513,7 +409,7 @@ namespace Mono.CSharp
 
                        public bool IsFieldAssigned (VariableInfo var, string name)
                        {
-                               if (!var.IsParameter && Reachability.AlwaysBreaks)
+                               if (!var.IsParameter && Reachability.IsUnreachable)
                                        return true;
 
                                return var.IsFieldAssigned (var.IsParameter ? parameters : locals, name);
@@ -521,7 +417,7 @@ namespace Mono.CSharp
 
                        public void SetFieldAssigned (VariableInfo var, string name)
                        {
-                               if (!var.IsParameter && Reachability.AlwaysBreaks)
+                               if (!var.IsParameter && Reachability.IsUnreachable)
                                        return;
 
                                IsDirty = true;
@@ -529,9 +425,7 @@ namespace Mono.CSharp
                        }
 
                        public Reachability Reachability {
-                               get {
-                                       return reachability;
-                               }
+                               get { return reachability; }
                        }
 
                        public void Return ()
@@ -542,19 +436,12 @@ namespace Mono.CSharp
                                }
                        }
 
-                       public void Break ()
-                       {
-                               if (!reachability.IsUnreachable) {
-                                       IsDirty = true;
-                                       reachability.SetBreaks ();
-                               }
-                       }
-
                        public void Throw ()
                        {
                                if (!reachability.IsUnreachable) {
                                        IsDirty = true;
                                        reachability.SetThrows ();
+                                       reachability.SetBarrier ();
                                }
                        }
 
@@ -569,13 +456,11 @@ namespace Mono.CSharp
                        // <summary>
                        //   Merges a child branching.
                        // </summary>
-                       public void MergeResult (MyBitVector new_params, MyBitVector new_locals,
-                                               Reachability new_reachability)
+                       public UsageVector MergeChild (UsageVector child, bool implicit_block)
                        {
-                               Report.Debug (2, "  MERGING RESULT", this, IsDirty,
-                                             new_params, new_locals, new_reachability, Type);
+                               Report.Debug (2, "    MERGING CHILD EFFECTS", this, child, IsDirty, reachability, Type);
 
-                               reachability = new_reachability;
+                               Reachability new_r = child.Reachability;
 
                                //
                                // We've now either reached the point after the branching or we will
@@ -586,48 +471,27 @@ namespace Mono.CSharp
                                // we need to look at (see above).
                                //
 
-                               if ((Type == SiblingType.SwitchSection) && !reachability.IsUnreachable) {
+                               if ((Type == SiblingType.SwitchSection) && !new_r.IsUnreachable) {
                                        Report.Error (163, Location,
                                                      "Control cannot fall through from one " +
                                                      "case label to another");
-                                       return;
+                                       return child;
                                }
 
-                               if (new_locals != null)
-                                       locals.Or (new_locals);
+                               if (locals != null && child.LocalVector != null)
+                                       locals.Or (child.LocalVector);
 
-                               if (new_params != null)
-                                       parameters.Or (new_params);
+                               if (child.ParameterVector != null)
+                                       parameters.Or (child.ParameterVector);
 
-                               Report.Debug (2, "  MERGING RESULT DONE", this);
+                               if (implicit_block)
+                                       reachability = new_r.Clone ();
+                               else
+                                       reachability.Or (new_r);
 
                                IsDirty = true;
-                       }
-
-                       protected void MergeFinally (FlowBranching branching, UsageVector f_origins,
-                                                    MyBitVector f_params)
-                       {
-                               for (UsageVector vector = f_origins; vector != null; vector = vector.Next) {
-                                       MyBitVector temp_params = f_params.Clone ();
-                                       temp_params.Or (vector.Parameters);
-
-                                       branching.CheckOutParameters (temp_params, branching.Location);
-                               }
-                       }
 
-                       public void MergeFinally (FlowBranching branching, UsageVector f_vector,
-                                                 UsageVector f_origins)
-                       {
-                               if (parameters != null) {
-                                       if (f_vector != null) {
-                                               MergeFinally (branching, f_origins, f_vector.Parameters);
-                                               MyBitVector.Or (ref parameters, f_vector.ParameterVector);
-                                       } else
-                                               MergeFinally (branching, f_origins, parameters);
-                               }
-
-                               if (f_vector != null)
-                                       MyBitVector.Or (ref locals, f_vector.LocalVector);
+                               return child;
                        }
 
                        // <summary>
@@ -650,60 +514,66 @@ namespace Mono.CSharp
                        //      8     Console.WriteLine (a);
                        //
                        // </summary>
-                       public void MergeJumpOrigins (ICollection origin_vectors)
+                       public void MergeJumpOrigins (UsageVector o_vectors)
                        {
-                               Report.Debug (1, "  MERGING JUMP ORIGIN", this);
-
-                               reachability = Reachability.Never ();
+                               Report.Debug (1, "  MERGING JUMP ORIGINS", this);
 
-                               if (origin_vectors == null)
+                               if (o_vectors == null)
                                        return;
 
-                               foreach (UsageVector vector in origin_vectors) {
-                                       Report.Debug (1, "    MERGING JUMP ORIGIN", vector);
+                               UsageVector vector = o_vectors;
+                               if (reachability.IsUnreachable) {
+                                       Report.Debug (1, "  MERGING JUMP ORIGIN INTO UNREACHABLE", this, vector);
+                                       if (locals != null && vector.Locals != null)
+                                               locals.Or (vector.locals);
+                                       if (parameters != null)
+                                               parameters.Or (vector.parameters);
+                                       reachability.Meet (vector.Reachability);
+                                       vector = vector.Next;
+                               }
+
+                               for (; vector != null; vector = vector.Next) {
+                                       Report.Debug (1, "  MERGING JUMP ORIGIN", this, vector);
 
-                                       locals.And (vector.locals);
+                                       if (locals != null)
+                                               locals.And (vector.locals);
                                        if (parameters != null)
                                                parameters.And (vector.parameters);
+                                       reachability.Meet (vector.Reachability);
 
-                                       Reachability.And (ref reachability, vector.Reachability, true);
+                                       Report.Debug (1, "  MERGING JUMP ORIGIN #1", vector);
                                }
 
-                               Report.Debug (1, "  MERGING JUMP ORIGIN DONE", this);
+                               Report.Debug (1, "  MERGING JUMP ORIGINS DONE", this);
                        }
 
-                       // <summary>
-                       //   This is used at the beginning of a finally block if there were
-                       //   any return statements in the try block or one of the catch blocks.
-                       // </summary>
-                       public void MergeFinallyOrigins (ICollection finally_vectors)
+                       public void MergeOrigins (UsageVector o_vectors)
                        {
-                               Report.Debug (1, "  MERGING FINALLY ORIGIN", this);
+                               Report.Debug (1, "  MERGING BREAK ORIGINS", this);
 
-#if FIXME
-                               RealBreaks = FlowReturns.Never;
-#endif
+                               if (o_vectors == null)
+                                       return;
 
-                               foreach (UsageVector vector in finally_vectors) {
-                                       Report.Debug (1, "    MERGING FINALLY ORIGIN", vector);
+                               UsageVector vector = o_vectors;
 
-                                       if (parameters != null)
-                                               parameters.And (vector.parameters);
-
-#if FIXME
-                                       RealBreaks = AndFlowReturns (Breaks, vector.Breaks);
-#endif
+                               if (reachability.IsUnreachable) {
+                                       Report.Debug (1, "    MERGING BREAK ORIGIN INTO UNREACHABLE", vector);
+                                       locals = vector.Locals;
+                                       parameters = vector.Parameters;
+                                       reachability.Meet (vector.Reachability);
+                                       vector = vector.Next;
                                }
 
-                               is_finally = true;
-
-                               Report.Debug (1, "  MERGING FINALLY ORIGIN DONE", this);
-                       }
+                               for (; vector != null; vector = vector.Next) {
+                                       Report.Debug (1, "    MERGING BREAK ORIGIN", vector);
+                                       if (locals != null && vector.locals != null)
+                                               locals.And (vector.locals);
+                                       if (parameters != null && vector.parameters != null)
+                                               parameters.And (vector.parameters);
+                                       reachability.Meet (vector.Reachability);
+                               }
 
-                       public void CheckOutParameters (FlowBranching branching)
-                       {
-                               if (parameters != null)
-                                       branching.CheckOutParameters (parameters, branching.Location);
+                               Report.Debug (1, "  MERGING BREAK ORIGINS DONE", this);
                        }
 
                        // <summary>
@@ -727,48 +597,33 @@ namespace Mono.CSharp
                        }
 
                        public bool HasParameters {
-                               get {
-                                       return parameters != null;
-                               }
+                               get { return parameters != null; }
                        }
 
                        public bool HasLocals {
-                               get {
-                                       return locals != null;
-                               }
+                               get { return locals != null; }
                        }
 
                        // <summary>
                        //   Returns a deep copy of the parameters.
                        // </summary>
                        public MyBitVector Parameters {
-                               get {
-                                       if (parameters != null)
-                                               return parameters.Clone ();
-                                       else
-                                               return null;
-                               }
+                               get { return parameters == null ? null : parameters.Clone (); }
                        }
 
                        // <summary>
                        //   Returns a deep copy of the locals.
                        // </summary>
                        public MyBitVector Locals {
-                               get {
-                                       return locals.Clone ();
-                               }
+                               get { return locals == null ? null : locals.Clone (); }
                        }
 
                        public MyBitVector ParameterVector {
-                               get {
-                                       return parameters;
-                               }
+                               get { return parameters; }
                        }
 
                        public MyBitVector LocalVector {
-                               get {
-                                       return locals;
-                               }
+                               get { return locals; }
                        }
 
                        //
@@ -780,6 +635,8 @@ namespace Mono.CSharp
                                StringBuilder sb = new StringBuilder ();
 
                                sb.Append ("Vector (");
+                               sb.Append (Type);
+                               sb.Append (",");
                                sb.Append (id);
                                sb.Append (",");
                                sb.Append (IsDirty);
@@ -818,11 +675,14 @@ namespace Mono.CSharp
                                local_map = Block.LocalMap;
 
                                UsageVector parent_vector = parent != null ? parent.CurrentUsageVector : null;
-                               vector = new UsageVector (stype, parent_vector, loc, param_map.Length, local_map.Length);
+                               vector = new UsageVector (
+                                       stype, parent_vector, Block, loc,
+                                       param_map.Length, local_map.Length);
                        } else {
                                param_map = Parent.param_map;
                                local_map = Parent.local_map;
-                               vector = new UsageVector (stype, Parent.CurrentUsageVector, loc);
+                               vector = new UsageVector (
+                                       stype, Parent.CurrentUsageVector, null, loc);
                        }
 
                        AddSibling (vector);
@@ -835,22 +695,43 @@ namespace Mono.CSharp
                // <summary>
                //   Creates a sibling of the current usage vector.
                // </summary>
-               public virtual void CreateSibling (SiblingType type)
+               public virtual void CreateSibling (Block block, SiblingType type)
                {
-                       AddSibling (new UsageVector (type, Parent.CurrentUsageVector, Location));
+                       UsageVector vector = new UsageVector (
+                               type, Parent.CurrentUsageVector, block, Location);
+                       AddSibling (vector);
 
                        Report.Debug (1, "  CREATED SIBLING", CurrentUsageVector);
                }
 
+               public void CreateSibling ()
+               {
+                       CreateSibling (null, SiblingType.Conditional);
+               }
+
                protected abstract void AddSibling (UsageVector uv);
 
-               public abstract void Label (ArrayList origin_vectors);
+               public virtual LabeledStatement LookupLabel (string name, Location loc)
+               {
+                       if (Parent != null)
+                               return Parent.LookupLabel (name, loc);
+
+                       Report.Error (
+                               159, loc,
+                               "No such label `" + name + "' in this scope");
+                       return null;
+               }
+
+               public abstract void Label (UsageVector origin_vectors);
 
                // <summary>
                //   Check whether all `out' parameters have been assigned.
                // </summary>
                public void CheckOutParameters (MyBitVector parameters, Location loc)
                {
+                       if (parameters == null)
+                               return;
+
                        for (int i = 0; i < param_map.Count; i++) {
                                VariableInfo var = param_map [i];
 
@@ -860,30 +741,30 @@ namespace Mono.CSharp
                                if (var.IsAssigned (parameters))
                                        continue;
 
-                               Report.Error (177, loc, "The out parameter `" +
-                                             param_map.VariableNames [i] + "' must be " +
-                                             "assigned before control leave the current method.");
+                               Report.Error (177, loc, "The out parameter `{0}' must be assigned to before control leaves the current method",
+                                       var.Name);
                        }
                }
 
                protected UsageVector Merge (UsageVector sibling_list)
                {
+                       if (sibling_list.Next == null)
+                               return sibling_list;
+
                        MyBitVector locals = null;
                        MyBitVector parameters = null;
 
                        Reachability reachability = null;
 
-                       Report.Debug (2, "  MERGING CHILDREN", Name);
+                       Report.Debug (2, "  MERGING SIBLINGS", this, Name);
 
                        for (UsageVector child = sibling_list; child != null; child = child.Next) {
-                               bool do_break = (Type != BranchingType.Switch) &&
-                                       (Type != BranchingType.LoopBlock);
+                               Report.Debug (2, "    MERGING SIBLING   ", reachability, child);
 
-                               Report.Debug (2, "    MERGING CHILD   ", child,
-                                             child.Locals, child.Parameters,
-                                             reachability, child.Reachability, do_break);
-
-                               Reachability.And (ref reachability, child.Reachability, do_break);
+                               if (reachability == null)
+                                       reachability = child.Reachability.Clone ();
+                               else
+                                       reachability.Meet (child.Reachability);
 
                                // A local variable is initialized after a flow branching if it
                                // has been initialized in all its branches which do neither
@@ -920,60 +801,28 @@ namespace Mono.CSharp
                                // Here, `a' is initialized in line 3 and we must not look at
                                // line 5 since it always returns.
                                // 
-                               bool do_break_2 = (child.Type != SiblingType.Block) &&
-                                       (child.Type != SiblingType.SwitchSection);
-                               bool unreachable = (do_break_2 && child.Reachability.AlwaysBreaks) ||
-                                       child.Reachability.AlwaysThrows ||
-                                       child.Reachability.AlwaysReturns ||
-                                       child.Reachability.AlwaysHasBarrier;
-
-                               Report.Debug (2, "    MERGING CHILD #1", reachability,
-                                             Type, child.Type, child.Reachability.IsUnreachable,
-                                             do_break_2, unreachable);
-
-                               if (!unreachable)
+                               bool unreachable = child.Reachability.IsUnreachable;
+
+                               Report.Debug (2, "    MERGING SIBLING #1", reachability,
+                                             Type, child.Type, child.Reachability.IsUnreachable, unreachable);
+
+                               if (!unreachable && (child.LocalVector != null))
                                        MyBitVector.And (ref locals, child.LocalVector);
 
                                // An `out' parameter must be assigned in all branches which do
                                // not always throw an exception.
-                               if ((child.Type != SiblingType.Catch) &&
-                                   (child.ParameterVector != null) && !child.Reachability.AlwaysThrows)
+                               if ((child.ParameterVector != null) && !child.Reachability.AlwaysThrows)
                                        MyBitVector.And (ref parameters, child.ParameterVector);
+
+                               Report.Debug (2, "    MERGING SIBLING #2", parameters, locals);
                        }
 
                        if (reachability == null)
-                               reachability = Reachability.Never ();
-
-                       Report.Debug (2, "  MERGING CHILDREN #1  ", Type, reachability,
-                                     Infinite, reachability.MayBreak);
-
-                       if (Type == BranchingType.LoopBlock) {
-                               bool may_leave_loop = reachability.MayBreak;
-                               reachability.ResetBreaks ();
-
-                               if (Infinite && !may_leave_loop) {
-                                       if (reachability.Returns == FlowReturns.Sometimes) {
-                                               // If we're an infinite loop and do not break, the code
-                                               // after the loop can never be reached.  However, if we
-                                               // may return from the loop, then we do always return
-                                               // (or stay in the loop forever).
-                                               reachability.SetReturns ();
-                                       }
-
-                                       reachability.SetBarrier ();
-                               } else {
-                                       if (reachability.Returns == FlowReturns.Always) {
-                                               // We're either finite or we may leave the loop.
-                                               reachability.SetReturnsSometimes ();
-                                       }
-                               }
-                       } else if (Type == BranchingType.Switch)
-                               reachability.ResetBreaks ();
+                               throw new InternalErrorException ("Cannot happen: the loop above runs at least twice");
 
-                       Report.Debug (2, "  MERGING CHILDREN DONE", parameters, locals,
-                                     reachability, Infinite);
+                       Report.Debug (2, "  MERGING SIBLINGS DONE", parameters, locals, reachability);
 
-                       return new UsageVector (parameters, locals, reachability, Location);
+                       return new UsageVector (parameters, locals, reachability, null, Location);
                }
 
                protected abstract UsageVector Merge ();
@@ -981,17 +830,13 @@ namespace Mono.CSharp
                // <summary>
                //   Merge a child branching.
                // </summary>
-               public Reachability MergeChild (FlowBranching child)
+               public UsageVector MergeChild (FlowBranching child)
                {
-                       UsageVector result = child.Merge ();
-
-                       CurrentUsageVector.MergeResult (
-                               result.ParameterVector, result.LocalVector, result.Reachability);
-
-                       Report.Debug (4, "  MERGE CHILD", Location, child, CurrentUsageVector,
-                                     result.Reachability);
-
-                       return result.Reachability;
+                       bool implicit_block = child.Type == BranchingType.Block && child.Block.Implicit;
+                       Report.Debug (2, "  MERGING CHILD", this, child);
+                       UsageVector result = CurrentUsageVector.MergeChild (child.Merge (), implicit_block);
+                       Report.Debug (2, "  MERGING CHILD DONE", this, result);
+                       return result;
                }
 
                // <summary>
@@ -999,51 +844,68 @@ namespace Mono.CSharp
                // </summary>
                public Reachability MergeTopBlock ()
                {
-                       if ((Type != BranchingType.Block) || (Block == null))
+                       if ((Type != BranchingType.Toplevel) || (Block == null))
                                throw new NotSupportedException ();
 
-                       UsageVector vector = new UsageVector (
-                               SiblingType.Conditional, null, Location, param_map.Length, local_map.Length);
-
                        UsageVector result = Merge ();
-                       vector.MergeResult (result.ParameterVector, result.LocalVector,
-                                           result.Reachability);
 
-                       Report.Debug (4, "MERGE TOP BLOCK", Location, vector, result.Reachability);
+                       Report.Debug (4, "MERGE TOP BLOCK", Location, result);
 
-                       if (vector.Reachability.Throws != FlowReturns.Always)
-                               CheckOutParameters (vector.Parameters, Location);
+                       if (!result.Reachability.AlwaysThrows && !result.Reachability.AlwaysHasBarrier)
+                               CheckOutParameters (result.Parameters, Location);
 
                        return result.Reachability;
                }
 
-               public virtual bool InTryBlock ()
+               public virtual bool InTryWithCatch ()
+               {
+                       return Parent != null && Parent.InTryWithCatch ();
+               }
+
+               // returns true if we crossed an unwind-protected region (try/catch/finally, lock, using, ...)
+               public virtual bool AddBreakOrigin (UsageVector vector, Location loc)
                {
                        if (Parent != null)
-                               return Parent.InTryBlock ();
-                       else
-                               return false;
+                               return Parent.AddBreakOrigin (vector, loc);
+
+                       Report.Error (139, loc, "No enclosing loop out of which to break or continue");
+                       return false;
                }
 
-               public virtual void AddFinallyVector (UsageVector vector)
+               // returns true if we crossed an unwind-protected region (try/catch/finally, lock, using, ...)
+               public virtual bool AddContinueOrigin (UsageVector vector, Location loc)
                {
                        if (Parent != null)
-                               Parent.AddFinallyVector (vector);
-                       else
-                               throw new NotSupportedException ();
+                               return Parent.AddContinueOrigin (vector, loc);
+
+                       Report.Error (139, loc, "No enclosing loop out of which to break or continue");
+                       return false;
+               }
+
+               // returns true if we crossed an unwind-protected region (try/catch/finally, lock, using, ...)
+               public virtual bool AddReturnOrigin (UsageVector vector, Location loc)
+               {
+                       if (Parent != null)
+                               return Parent.AddReturnOrigin (vector, loc);
+
+                       CheckOutParameters (vector.Parameters, loc);
+                       return false;
+               }
+
+               public virtual void StealFinallyClauses (ref ArrayList list)
+               {
+                       if (Parent != null)
+                               Parent.StealFinallyClauses (ref list);
                }
 
                public bool IsAssigned (VariableInfo vi)
                {
-                       return CurrentUsageVector.IsAssigned (vi);
+                       return CurrentUsageVector.IsAssigned (vi, false);
                }
 
                public bool IsFieldAssigned (VariableInfo vi, string field_name)
                {
-                       if (CurrentUsageVector.IsAssigned (vi))
-                               return true;
-
-                       return CurrentUsageVector.IsFieldAssigned (vi, field_name);
+                       return CurrentUsageVector.IsAssigned (vi, false) || CurrentUsageVector.IsFieldAssigned (vi, field_name);
                }
 
                public void SetAssigned (VariableInfo vi)
@@ -1080,10 +942,7 @@ namespace Mono.CSharp
                }
 
                public string Name {
-                       get {
-                               return String.Format ("{0} ({1}:{2}:{3})",
-                                                     GetType (), id, Type, Location);
-                       }
+                       get { return String.Format ("{0} ({1}:{2}:{3})", GetType (), id, Type, Location); }
                }
        }
 
@@ -1091,8 +950,8 @@ namespace Mono.CSharp
        {
                UsageVector sibling_list = null;
 
-               public FlowBranchingBlock (FlowBranching parent, BranchingType type, SiblingType stype,
-                                          Block block, Location loc)
+               public FlowBranchingBlock (FlowBranching parent, BranchingType type,
+                                          SiblingType stype, Block block, Location loc)
                        : base (parent, type, stype, block, loc)
                { }
 
@@ -1106,8 +965,26 @@ namespace Mono.CSharp
                        sibling_list = sibling;
                }
 
-               public override void Label (ArrayList origin_vectors)
+               public override LabeledStatement LookupLabel (string name, Location loc)
+               {
+                       if (Block == null)
+                               return base.LookupLabel (name, loc);
+
+                       LabeledStatement s = Block.LookupLabel (name);
+                       if (s != null)
+                               return s;
+
+                       return base.LookupLabel (name, loc);
+               }
+
+               public override void Label (UsageVector origin_vectors)
                {
+                       if (!CurrentUsageVector.Reachability.IsUnreachable) {
+                               UsageVector vector = CurrentUsageVector.Clone ();
+                               vector.Next = origin_vectors;
+                               origin_vectors = vector;
+                       }
+
                        CurrentUsageVector.MergeJumpOrigins (origin_vectors);
                }
 
@@ -1117,33 +994,109 @@ namespace Mono.CSharp
                }
        }
 
+       public class FlowBranchingBreakable : FlowBranchingBlock
+       {
+               UsageVector break_origins;
+
+               public FlowBranchingBreakable (FlowBranching parent, BranchingType type, SiblingType stype, Block block, Location loc)
+                       : base (parent, type, stype, block, loc)
+               { }
+
+               public override bool AddBreakOrigin (UsageVector vector, Location loc)
+               {
+                       vector = vector.Clone ();
+                       vector.Next = break_origins;
+                       break_origins = vector;
+                       return false;
+               }
+
+               protected override UsageVector Merge ()
+               {
+                       UsageVector vector = base.Merge ();
+                       vector.MergeOrigins (break_origins);
+                       return vector;
+               }
+       }
+
+       public class FlowBranchingContinuable : FlowBranchingBlock
+       {
+               UsageVector continue_origins;
+
+               public FlowBranchingContinuable (FlowBranching parent, BranchingType type, SiblingType stype, Block block, Location loc)
+                       : base (parent, type, stype, block, loc)
+               { }
+
+               public override bool AddContinueOrigin (UsageVector vector, Location loc)
+               {
+                       vector = vector.Clone ();
+                       vector.Next = continue_origins;
+                       continue_origins = vector;
+                       return false;
+               }
+
+               protected override UsageVector Merge ()
+               {
+                       UsageVector vector = base.Merge ();
+                       vector.MergeOrigins (continue_origins);
+                       return vector;
+               }
+       }
+
+       public class FlowBranchingLabeled : FlowBranchingBlock
+       {
+               LabeledStatement stmt;
+               public FlowBranchingLabeled (FlowBranching parent, LabeledStatement stmt)
+                       : base (parent, BranchingType.Labeled, SiblingType.Conditional, null, stmt.loc)
+               {
+                       this.stmt = stmt;
+               }
+       }
+
+       public class FlowBranchingToplevel : FlowBranchingBlock
+       {
+               public FlowBranchingToplevel (FlowBranching parent, ToplevelBlock stmt)
+                       : base (parent, BranchingType.Toplevel, SiblingType.Conditional, stmt, stmt.loc)
+               {
+               }
+       }
+
+
        public class FlowBranchingException : FlowBranching
        {
+               ExceptionStatement stmt;
                UsageVector current_vector;
-               UsageVector try_vector;
                UsageVector catch_vectors;
                UsageVector finally_vector;
-               UsageVector finally_origins;
 
-               public FlowBranchingException (FlowBranching parent, BranchingType type, Block block, Location loc)
-                       : base (parent, type, SiblingType.Try, block, loc)
-               { }
+               UsageVector break_origins;
+               UsageVector continue_origins;
+               UsageVector return_origins;
+
+               bool emit_finally;
+
+               public FlowBranchingException (FlowBranching parent,
+                                              ExceptionStatement stmt)
+                       : base (parent, BranchingType.Exception, SiblingType.Try,
+                               null, stmt.loc)
+               {
+                       this.stmt = stmt;
+                       this.emit_finally = true;
+               }
 
                protected override void AddSibling (UsageVector sibling)
                {
-                       if (sibling.Type == SiblingType.Try) {
-                               try_vector = sibling;
+                       switch (sibling.Type) {
+                       case SiblingType.Try:
+                       case SiblingType.Catch:
                                sibling.Next = catch_vectors;
                                catch_vectors = sibling;
-                       } else if (sibling.Type == SiblingType.Catch) {
-                               sibling.Next = catch_vectors;
-                               catch_vectors = sibling;
-                       } else if (sibling.Type == SiblingType.Finally) {
-                               // sibling.MergeFinallyOrigins (finally_vectors);
+                               break;
+                       case SiblingType.Finally:
                                finally_vector = sibling;
-                       } else
+                               break;
+                       default:
                                throw new InvalidOperationException ();
-
+                       }
                        current_vector = sibling;
                }
 
@@ -1151,19 +1104,88 @@ namespace Mono.CSharp
                        get { return current_vector; }
                }
 
-               public override bool InTryBlock ()
+               public override bool InTryWithCatch ()
+               {
+                       if (finally_vector == null) {
+                               Try t = stmt as Try;
+                               if (t != null && t.HasCatch)
+                                       return true;
+                       }
+
+                       return base.InTryWithCatch ();
+               }
+
+               public override bool AddBreakOrigin (UsageVector vector, Location loc)
                {
+                       if (finally_vector != null) {
+                               Report.Error (157, loc, "Control cannot leave the body of a finally clause");
+                       } else {
+                               vector = vector.Clone ();
+                               vector.Location = loc;
+                               vector.Next = break_origins;
+                               break_origins = vector;
+                       }
                        return true;
                }
 
-               public override void AddFinallyVector (UsageVector vector)
+               public override bool AddContinueOrigin (UsageVector vector, Location loc)
                {
-                       vector = vector.Clone ();
-                       vector.Next = finally_origins;
-                       finally_origins = vector;
+                       if (finally_vector != null) {
+                               Report.Error (157, loc, "Control cannot leave the body of a finally clause");
+                       } else {
+                               vector = vector.Clone ();
+                               vector.Location = loc;
+                               vector.Next = continue_origins;
+                               continue_origins = vector;
+                       }
+                       return true;
+               }
+
+               public override bool AddReturnOrigin (UsageVector vector, Location loc)
+               {
+                       if (finally_vector != null) {
+                               Report.Error (157, loc, "Control cannot leave the body of a finally clause");
+                       } else {
+                               vector = vector.Clone ();
+                               vector.Location = loc;
+                               vector.Next = return_origins;
+                               return_origins = vector;
+                       }
+                       return true;
+               }
+
+               public override void StealFinallyClauses (ref ArrayList list)
+               {
+                       if (list == null)
+                               list = new ArrayList ();
+                       list.Add (stmt);
+                       emit_finally = false;
+                       base.StealFinallyClauses (ref list);
+               }
+
+               public bool EmitFinally {
+                       get { return emit_finally; }
                }
 
-               public override void Label (ArrayList origin_vectors)
+               public override LabeledStatement LookupLabel (string name, Location loc)
+               {
+                       if (current_vector.Block == null)
+                               return base.LookupLabel (name, loc);
+
+                       LabeledStatement s = current_vector.Block.LookupLabel (name);
+                       if (s != null)
+                               return s;
+
+                       if (finally_vector != null) {
+                               Report.Error (157, loc,
+                                       "Control cannot leave the body of a finally clause");
+                               return null;
+                       }
+
+                       return base.LookupLabel (name, loc);
+               }
+
+               public override void Label (UsageVector origin_vectors)
                {
                        CurrentUsageVector.MergeJumpOrigins (origin_vectors);
                }
@@ -1172,7 +1194,29 @@ namespace Mono.CSharp
                {
                        UsageVector vector = Merge (catch_vectors);
 
-                       vector.MergeFinally (this, finally_vector, finally_origins);
+                       if (finally_vector != null)
+                               vector.MergeChild (finally_vector, false);
+
+                       for (UsageVector origin = break_origins; origin != null; origin = origin.Next) {
+                               if (finally_vector != null)
+                                       origin.MergeChild (finally_vector, false);
+                               if (!origin.Reachability.IsUnreachable)
+                                       Parent.AddBreakOrigin (origin, origin.Location);
+                       }
+
+                       for (UsageVector origin = continue_origins; origin != null; origin = origin.Next) {
+                               if (finally_vector != null)
+                                       origin.MergeChild (finally_vector, false);
+                               if (!origin.Reachability.IsUnreachable)
+                                       Parent.AddContinueOrigin (origin, origin.Location);
+                       }
+
+                       for (UsageVector origin = return_origins; origin != null; origin = origin.Next) {
+                               if (finally_vector != null)
+                                       origin.MergeChild (finally_vector, false);
+                               if (!origin.Reachability.IsUnreachable)
+                                       Parent.AddReturnOrigin (origin, origin.Location);
+                       }
 
                        return vector;
                }
@@ -1323,9 +1367,8 @@ namespace Mono.CSharp
 
                                if (!branching.IsFieldAssigned (vi, field.Name)) {
                                        Report.Error (171, loc,
-                                                     "Field `" + TypeManager.CSharpName (Type) +
-                                                     "." + field.Name + "' must be fully initialized " +
-                                                     "before control leaves the constructor");
+                                               "Field `{0}' must be fully assigned before control leaves the constructor",
+                                               TypeManager.GetFullNameSignature (field));
                                        ok = false;
                                }
                        }
@@ -1367,13 +1410,15 @@ namespace Mono.CSharp
                                if (type is TypeBuilder) {
                                        TypeContainer tc = TypeManager.LookupTypeContainer (type);
 
-                                       ArrayList fields = tc.Fields;
+                                       ArrayList fields = null;
+                                       if (tc != null)
+                                               fields = tc.Fields;
 
                                        ArrayList public_fields = new ArrayList ();
                                        ArrayList non_public_fields = new ArrayList ();
 
                                        if (fields != null) {
-                                               foreach (Field field in fields) {
+                                               foreach (FieldMember field in fields) {
                                                        if ((field.ModFlags & Modifiers.STATIC) != 0)
                                                                continue;
                                                        if ((field.ModFlags & Modifiers.PUBLIC) != 0)
@@ -1422,7 +1467,7 @@ namespace Mono.CSharp
                                                field_hash.Add (field.Name, ++Length);
                                        else if (sinfo [i].InTransit) {
                                                Report.Error (523, String.Format (
-                                                                     "Struct member '{0}.{1}' of type '{2}' causes " +
+                                                                     "Struct member `{0}.{1}' of type `{2}' causes " +
                                                                      "a cycle in the structure layout",
                                                                      type, field.Name, sinfo [i].Type));
                                                sinfo [i] = null;
@@ -1574,7 +1619,9 @@ namespace Mono.CSharp
 
                public bool IsAssigned (EmitContext ec)
                {
-                       return !ec.DoFlowAnalysis || ec.CurrentBranching.IsAssigned (this);
+                       return !ec.DoFlowAnalysis ||
+                               ec.OmitStructFlowAnalysis && TypeInfo.IsStruct ||
+                               ec.CurrentBranching.IsAssigned (this);
                }
 
                public bool IsAssigned (EmitContext ec, Location loc)
@@ -1634,7 +1681,9 @@ namespace Mono.CSharp
 
                public bool IsFieldAssigned (EmitContext ec, string name, Location loc)
                {
-                       if (!ec.DoFlowAnalysis || ec.CurrentBranching.IsFieldAssigned (this, name))
+                       if (!ec.DoFlowAnalysis ||
+                               ec.OmitStructFlowAnalysis && TypeInfo.IsStruct ||
+                               ec.CurrentBranching.IsFieldAssigned (this, name))
                                return true;
 
                        Report.Error (170, loc,
@@ -1702,34 +1751,31 @@ namespace Mono.CSharp
                // <summary>
                public readonly int Length;
 
-               // <summary>
-               //   Type and name of all the variables.
-               //   Note that this is null for variables for which we do not need to compute
-               //   assignment info.
-               // </summary>
-               public readonly Type[] VariableTypes;
-               public readonly string[] VariableNames;
-
                VariableInfo[] map;
 
-               public VariableMap (InternalParameters ip)
+               public VariableMap (Parameters ip)
                {
                        Count = ip != null ? ip.Count : 0;
-                       map = new VariableInfo [Count];
-                       VariableNames = new string [Count];
-                       VariableTypes = new Type [Count];
+                       
+                       // Dont bother allocating anything!
+                       if (Count == 0)
+                               return;
+                       
                        Length = 0;
 
                        for (int i = 0; i < Count; i++) {
                                Parameter.Modifier mod = ip.ParameterModifier (i);
 
-                               if ((mod & Parameter.Modifier.OUT) == 0)
+                               if ((mod & Parameter.Modifier.OUT) != Parameter.Modifier.OUT)
                                        continue;
 
-                               VariableNames [i] = ip.ParameterName (i);
-                               VariableTypes [i] = TypeManager.GetElementType (ip.ParameterType (i));
+                               // Dont allocate till we find an out var.
+                               if (map == null)
+                                       map = new VariableInfo [Count];
+
+                               map [i] = new VariableInfo (ip.ParameterName (i),
+                                       TypeManager.GetElementType (ip.ParameterType (i)), i, Length);
 
-                               map [i] = new VariableInfo (VariableNames [i], VariableTypes [i], i, Length);
                                Length += map [i].Length;
                        }
                }
@@ -1741,21 +1787,21 @@ namespace Mono.CSharp
                public VariableMap (VariableMap parent, LocalInfo[] locals)
                {
                        int offset = 0, start = 0;
-                       if (parent != null) {
+                       if (parent != null && parent.map != null) {
                                offset = parent.Length;
                                start = parent.Count;
                        }
 
                        Count = locals.Length + start;
+                       
+                       if (Count == 0)
+                               return;
+                       
                        map = new VariableInfo [Count];
-                       VariableNames = new string [Count];
-                       VariableTypes = new Type [Count];
                        Length = offset;
 
-                       if (parent != null) {
+                       if (parent != null && parent.map != null) {
                                parent.map.CopyTo (map, 0);
-                               parent.VariableNames.CopyTo (VariableNames, 0);
-                               parent.VariableTypes.CopyTo (VariableTypes, 0);
                        }
 
                        for (int i = start; i < Count; i++) {
@@ -1764,9 +1810,6 @@ namespace Mono.CSharp
                                if (li.VariableType == null)
                                        continue;
 
-                               VariableNames [i] = li.Name;
-                               VariableTypes [i] = li.VariableType;
-
                                map [i] = li.VariableInfo = new VariableInfo (li, Length);
                                Length += map [i].Length;
                        }
@@ -1778,6 +1821,9 @@ namespace Mono.CSharp
                // </summary>
                public VariableInfo this [int index] {
                        get {
+                               if (map == null)
+                                       return null;
+                               
                                return map [index];
                        }
                }
@@ -1815,9 +1861,7 @@ namespace Mono.CSharp
                //   we won't use the inherited vector anymore, but our own copy of it.
                // </summary>
                public bool IsDirty {
-                       get {
-                               return is_dirty;
-                       }
+                       get { return is_dirty; }
 
                        set {
                                if (!is_dirty)
@@ -1881,6 +1925,9 @@ namespace Mono.CSharp
                // </summary>
                public void Or (MyBitVector new_vector)
                {
+                       // Treat null 'new_vector' as all false, just like the And() below
+                       if (new_vector == null)
+                               return;
                        BitArray new_array = new_vector.Vector;
 
                        initialize_vector ();
@@ -1901,7 +1948,12 @@ namespace Mono.CSharp
                // </summary>
                public void And (MyBitVector new_vector)
                {
-                       BitArray new_array = new_vector.Vector;
+                       BitArray new_array;
+
+                       if (new_vector != null)
+                               new_array = new_vector.Vector;
+                       else
+                               new_array = new BitArray (Count, false);
 
                        initialize_vector ();
 
@@ -1972,7 +2024,7 @@ namespace Mono.CSharp
                {
                        if (vector != null)
                                return;
-
+                       
                        vector = new BitArray (Count, false);
                        if (InheritsFrom != null)
                                Vector = InheritsFrom.Vector;