2004-01-19 Atsushi Enomoto <atsushi@ximian.com>
[mono.git] / mcs / gmcs / flowanalysis.cs
index 8f0e94e0e6434f73af909c01176258cb950dfc6d..18f5714392490aea3015ffdd0fffa4ec53737b3c 100644 (file)
@@ -334,6 +334,11 @@ namespace Mono.CSharp
                                barrier = FlowReturns.Always;
                        }
 
+                       public void ResetBarrier ()
+                       {
+                               barrier = FlowReturns.Never;
+                       }
+
                        static string ShortName (FlowReturns returns)
                        {
                                switch (returns) {
@@ -359,7 +364,7 @@ namespace Mono.CSharp
                {
                        switch (type) {
                        case BranchingType.Exception:
-                               return new FlowBranchingException (parent, block, loc);
+                               throw new InvalidOperationException ();
 
                        case BranchingType.Switch:
                                return new FlowBranchingBlock (parent, type, SiblingType.SwitchSection, block, loc);
@@ -624,7 +629,7 @@ namespace Mono.CSharp
                        {
                                UsageVector result = branching.Merge ();
 
-                               Report.Debug (2, "  MERGING CHILD", this, IsDirty,
+                               Report.Debug (2, "  MERGING CHILD", this, branching, IsDirty,
                                              result.ParameterVector, result.LocalVector,
                                              result.Reachability, reachability, Type);
 
@@ -655,8 +660,12 @@ namespace Mono.CSharp
                                                        new_r.SetThrowsSometimes ();
                                                }
                        }
-                               } else if (branching.Type == BranchingType.Switch)
+                               } else if (branching.Type == BranchingType.Switch) {
+                                       if (new_r.MayBreak || new_r.MayReturn)
+                                               new_r.ResetBarrier ();
+
                                        new_r.ResetBreaks ();
+                               }
 
                                //
                                // We've now either reached the point after the branching or we will
@@ -740,8 +749,10 @@ namespace Mono.CSharp
 
                                reachability = Reachability.Never ();
 
-                               if (o_vectors == null)
+                               if (o_vectors == null) {
+                                       reachability.SetBarrier ();
                                        return;
+                               }
 
                                bool first = true;
 
@@ -1225,6 +1236,12 @@ namespace Mono.CSharp
                                throw new NotSupportedException ();
                }
 
+               public virtual void StealFinallyClauses (ref ArrayList list)
+               {
+                       if (Parent != null)
+                               Parent.StealFinallyClauses (ref list);
+               }
+
                public bool IsAssigned (VariableInfo vi)
                {
                        return CurrentUsageVector.IsAssigned (vi);
@@ -1354,15 +1371,22 @@ namespace Mono.CSharp
 
        public class FlowBranchingException : FlowBranching
        {
+               ExceptionStatement stmt;
                UsageVector current_vector;
                UsageVector catch_vectors;
                UsageVector finally_vector;
                UsageVector finally_origins;
+               bool emit_finally;
                bool in_try;
 
-               public FlowBranchingException (FlowBranching parent, Block block, Location loc)
-                       : base (parent, BranchingType.Exception, SiblingType.Try, block, loc)
-               { }
+               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)
                {
@@ -1415,6 +1439,19 @@ namespace Mono.CSharp
                        finally_origins = vector;
                }
 
+               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 LabeledStatement LookupLabel (string name, Location loc)
                {
                        if (current_vector.Block == null)