2009-08-21 Marek Safar <marek.safar@gmail.com>
authorMarek Safar <marek.safar@gmail.com>
Fri, 21 Aug 2009 16:19:41 +0000 (16:19 -0000)
committerMarek Safar <marek.safar@gmail.com>
Fri, 21 Aug 2009 16:19:41 +0000 (16:19 -0000)
* codegen.cs: Moved flow-analysis to BlockContext.

svn path=/trunk/mcs/; revision=140421

mcs/mcs/ChangeLog
mcs/mcs/codegen.cs

index 812bee71e1033d67c7f0f09550e911845b3a4bec..7f53110b37c456f7db0481b7542b227fa9957db9 100644 (file)
@@ -1,3 +1,7 @@
+2009-08-21  Marek Safar  <marek.safar@gmail.com>
+
+       * codegen.cs: Moved flow-analysis to BlockContext.
+
 2009-08-21  Marek Safar  <marek.safar@gmail.com>
 
        * *.cs: Detached BlockContext from EmitContext.
index e3eba52e167c2f68e4e91352f7607b85e3e64ba7..7159a25fb95ac02921d8c85b99b3a204850bbaf3 100644 (file)
@@ -285,6 +285,8 @@ namespace Mono.CSharp {
        //
        public class BlockContext : EmitContext
        {
+               FlowBranching current_flow_branching;
+
                public BlockContext (IResolveContext mc, ExplicitBlock block, Type returnType)
                        : base (mc, null, returnType)
                {
@@ -292,6 +294,90 @@ namespace Mono.CSharp {
                        CurrentBlock = block;
                }
 
+               public override FlowBranching CurrentBranching {
+                       get { return current_flow_branching; }
+               }
+
+               // <summary>
+               //   Starts a new code branching.  This inherits the state of all local
+               //   variables and parameters from the current branching.
+               // </summary>
+               public FlowBranching StartFlowBranching (FlowBranching.BranchingType type, Location loc)
+               {
+                       current_flow_branching = FlowBranching.CreateBranching (CurrentBranching, type, null, loc);
+                       return current_flow_branching;
+               }
+
+               // <summary>
+               //   Starts a new code branching for block `block'.
+               // </summary>
+               public FlowBranching StartFlowBranching (Block block)
+               {
+                       Set (Options.DoFlowAnalysis);
+
+                       current_flow_branching = FlowBranching.CreateBranching (
+                               CurrentBranching, FlowBranching.BranchingType.Block, block, block.StartLocation);
+                       return current_flow_branching;
+               }
+
+               public FlowBranchingTryCatch StartFlowBranching (TryCatch stmt)
+               {
+                       FlowBranchingTryCatch branching = new FlowBranchingTryCatch (CurrentBranching, stmt);
+                       current_flow_branching = branching;
+                       return branching;
+               }
+
+               public FlowBranchingException StartFlowBranching (ExceptionStatement stmt)
+               {
+                       FlowBranchingException branching = new FlowBranchingException (CurrentBranching, stmt);
+                       current_flow_branching = branching;
+                       return branching;
+               }
+
+               public FlowBranchingLabeled StartFlowBranching (LabeledStatement stmt)
+               {
+                       FlowBranchingLabeled branching = new FlowBranchingLabeled (CurrentBranching, stmt);
+                       current_flow_branching = branching;
+                       return branching;
+               }
+
+               public FlowBranchingIterator StartFlowBranching (Iterator iterator)
+               {
+                       FlowBranchingIterator branching = new FlowBranchingIterator (CurrentBranching, iterator);
+                       current_flow_branching = branching;
+                       return branching;
+               }
+
+               public FlowBranchingToplevel StartFlowBranching (ToplevelBlock stmt, FlowBranching parent)
+               {
+                       FlowBranchingToplevel branching = new FlowBranchingToplevel (parent, stmt);
+                       current_flow_branching = branching;
+                       return branching;
+               }
+
+               // <summary>
+               //   Ends a code branching.  Merges the state of locals and parameters
+               //   from all the children of the ending branching.
+               // </summary>
+               public bool EndFlowBranching ()
+               {
+                       FlowBranching old = current_flow_branching;
+                       current_flow_branching = current_flow_branching.Parent;
+
+                       FlowBranching.UsageVector vector = current_flow_branching.MergeChild (old);
+                       return vector.IsUnreachable;
+               }
+
+               // <summary>
+               //   Kills the current code branching.  This throws away any changed state
+               //   information and should only be used in case of an error.
+               // </summary>
+               // FIXME: this is evil
+               public void KillFlowBranching ()
+               {
+                       current_flow_branching = current_flow_branching.Parent;
+               }
+
                //
                // This method is used during the Resolution phase to flag the
                // need to define the ReturnLabel
@@ -470,8 +556,6 @@ namespace Mono.CSharp {
                        get { return CurrentAnonymousMethod as Iterator; }
                }
 
-               FlowBranching current_flow_branching;
-
                public TypeInferenceContext ReturnTypeInference;
 
                public EmitContext (IResolveContext rc, ILGenerator ig, Type return_type)
@@ -496,6 +580,10 @@ namespace Mono.CSharp {
                        this.return_type = return_type;
                }
 
+               public virtual FlowBranching CurrentBranching {
+                       get { return null; }
+               }
+
                public Type CurrentType {
                        get { return ResolveContext.CurrentType; }
                }
@@ -579,10 +667,6 @@ namespace Mono.CSharp {
                        }
                }
 
-               public FlowBranching CurrentBranching {
-                       get { return current_flow_branching; }
-               }
-
                public bool OmitDebuggingInfo {
                        get { return (flags & Options.OmitDebuggingInfo) != 0; }
                        set {
@@ -593,86 +677,6 @@ namespace Mono.CSharp {
                        }
                }
 
-               // <summary>
-               //   Starts a new code branching.  This inherits the state of all local
-               //   variables and parameters from the current branching.
-               // </summary>
-               public FlowBranching StartFlowBranching (FlowBranching.BranchingType type, Location loc)
-               {
-                       current_flow_branching = FlowBranching.CreateBranching (CurrentBranching, type, null, loc);
-                       return current_flow_branching;
-               }
-
-               // <summary>
-               //   Starts a new code branching for block `block'.
-               // </summary>
-               public FlowBranching StartFlowBranching (Block block)
-               {
-                       flags |= Options.DoFlowAnalysis;
-
-                       current_flow_branching = FlowBranching.CreateBranching (
-                               CurrentBranching, FlowBranching.BranchingType.Block, block, block.StartLocation);
-                       return current_flow_branching;
-               }
-
-               public FlowBranchingTryCatch StartFlowBranching (TryCatch stmt)
-               {
-                       FlowBranchingTryCatch branching = new FlowBranchingTryCatch (CurrentBranching, stmt);
-                       current_flow_branching = branching;
-                       return branching;
-               }
-
-               public FlowBranchingException StartFlowBranching (ExceptionStatement stmt)
-               {
-                       FlowBranchingException branching = new FlowBranchingException (CurrentBranching, stmt);
-                       current_flow_branching = branching;
-                       return branching;
-               }
-
-               public FlowBranchingLabeled StartFlowBranching (LabeledStatement stmt)
-               {
-                       FlowBranchingLabeled branching = new FlowBranchingLabeled (CurrentBranching, stmt);
-                       current_flow_branching = branching;
-                       return branching;
-               }
-
-               public FlowBranchingIterator StartFlowBranching (Iterator iterator)
-               {
-                       FlowBranchingIterator branching = new FlowBranchingIterator (CurrentBranching, iterator);
-                       current_flow_branching = branching;
-                       return branching;
-               }
-
-               public FlowBranchingToplevel StartFlowBranching (ToplevelBlock stmt, FlowBranching parent)
-               {
-                       FlowBranchingToplevel branching = new FlowBranchingToplevel (parent, stmt);
-                       current_flow_branching = branching;
-                       return branching;
-               }
-
-               // <summary>
-               //   Ends a code branching.  Merges the state of locals and parameters
-               //   from all the children of the ending branching.
-               // </summary>
-               public bool EndFlowBranching ()
-               {
-                       FlowBranching old = current_flow_branching;
-                       current_flow_branching = current_flow_branching.Parent;
-
-                       FlowBranching.UsageVector vector = current_flow_branching.MergeChild (old);
-                       return vector.IsUnreachable;
-               }
-
-               // <summary>
-               //   Kills the current code branching.  This throws away any changed state
-               //   information and should only be used in case of an error.
-               // </summary>
-               // FIXME: this is evil
-               public void KillFlowBranching ()
-               {
-                       current_flow_branching = current_flow_branching.Parent;
-               }
-
                public bool MustCaptureVariable (LocalInfo local)
                {
                        if (CurrentAnonymousMethod == null)