Some simple refactoring
authorRaja R Harinath <harinath@hurrynot.org>
Fri, 4 Apr 2008 20:17:10 +0000 (20:17 -0000)
committerRaja R Harinath <harinath@hurrynot.org>
Fri, 4 Apr 2008 20:17:10 +0000 (20:17 -0000)
* statement.cs (ResumableStatement): New.  Common base class for
YieldReturn and ExceptionStatement.
(ExitStatement): New.  Common base class for Return and YieldBreak.
(Return): Update to changes.
* iterator.cs (YieldBreak): Likewise.
* lambda.cs (ContextualReturn): Likewise.

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

mcs/mcs/ChangeLog
mcs/mcs/iterators.cs
mcs/mcs/lambda.cs
mcs/mcs/statement.cs

index 122aff4676e7f692d9a80dad0ff77e7dc0de16ee..3d15a1ad8aea0491a19c0a34e4639de3335fea82 100644 (file)
@@ -1,5 +1,12 @@
 2008-04-04  Raja R Harinath  <harinath@hurrynot.org>
 
+       * statement.cs (ResumableStatement): New.  Common base class for
+       YieldReturn and ExceptionStatement.
+       (ExitStatement): New.  Common base class for Return and YieldBreak.
+       (Return): Update to changes.
+       * iterator.cs (YieldBreak): Likewise.
+       * lambda.cs (ContextualReturn): Likewise.
+
        Fix #377028
        * ecore.cs (Expression.ResolveAsTypeStep): If '!silent' attempt to
        emit a meaningful error message.
index 374cfb2292c882e1b42797b9a3a398cf436f6594..8fc11cc94127689c3b3fee573203abe5145ef47b 100644 (file)
@@ -21,7 +21,7 @@ using System.Reflection.Emit;
 
 namespace Mono.CSharp {
 
-       public class Yield : Statement {
+       public class Yield : ResumableStatement {
                Expression expr;
                ArrayList finally_blocks;
                bool unwind_protect;
@@ -113,22 +113,15 @@ namespace Mono.CSharp {
                }
        }
 
-       public class YieldBreak : Statement {
-               bool unwind_protect;
+       public class YieldBreak : ExitStatement {
                public YieldBreak (Location l)
                {
                        loc = l;
                }
 
-               public override bool Resolve (EmitContext ec)
+               protected override bool DoResolve (EmitContext ec)
                {
-                       if (!Yield.CheckContext (ec, loc, true))
-                               return false;
-
-                       // not exactly a 'return' but close enough
-                       unwind_protect = ec.CurrentBranching.AddReturnOrigin (ec.CurrentBranching.CurrentUsageVector, loc);
-                       ec.CurrentBranching.CurrentUsageVector.Goto ();
-                       return true;
+                       return Yield.CheckContext (ec, loc, true);
                }
 
                protected override void DoEmit (EmitContext ec)
index 22c904b7b897cab91b73699c2285862b9e265c53..9d8c996e5db72456a90c077bb46efe7af9a6647e 100644 (file)
@@ -176,7 +176,7 @@ namespace Mono.CSharp {
                                base.Emit (ec);
                }
 
-               public override bool Resolve (EmitContext ec)
+               protected override bool DoResolve (EmitContext ec)
                {       
                        //
                        // When delegate returns void, only expression statements can be used
@@ -196,7 +196,7 @@ namespace Mono.CSharp {
                                return false;
                        }
 
-                       return base.Resolve (ec);
+                       return base.DoResolve (ec);
                }
        }
 }
index 1f13e7216727bcb5ad7a51c591ae3ad674726c80..da68b786f22164675a12e40208a66e868fa2c066 100644 (file)
@@ -741,20 +741,37 @@ namespace Mono.CSharp {
                }
        }
 
+       // A 'return' or a 'yield break'
+       public abstract class ExitStatement : Statement
+       {
+               protected bool unwind_protect;
+               protected abstract bool DoResolve (EmitContext ec);
+
+               public sealed override bool Resolve (EmitContext ec)
+               {
+                       if (!DoResolve (ec))
+                               return false;
+
+                       unwind_protect = ec.CurrentBranching.AddReturnOrigin (ec.CurrentBranching.CurrentUsageVector, loc);
+                       if (unwind_protect)
+                               ec.NeedReturnLabel ();
+                       ec.CurrentBranching.CurrentUsageVector.Goto ();
+                       return true;
+               }
+       }
+
        /// <summary>
        ///   Implements the return statement
        /// </summary>
-       public class Return : Statement {
+       public class Return : ExitStatement {
                protected Expression Expr;
-               bool unwind_protect;
-               
                public Return (Expression expr, Location l)
                {
                        Expr = expr;
                        loc = l;
                }
                
-               bool DoResolve (EmitContext ec)
+               protected override bool DoResolve (EmitContext ec)
                {
                        if (Expr == null) {
                                if (ec.ReturnType == TypeManager.void_type)
@@ -808,18 +825,6 @@ namespace Mono.CSharp {
 
                        return true;                    
                }
-
-               public override bool Resolve (EmitContext ec)
-               {
-                       if (!DoResolve (ec))
-                               return false;
-                       
-                       unwind_protect = ec.CurrentBranching.AddReturnOrigin (ec.CurrentBranching.CurrentUsageVector, loc);
-                       if (unwind_protect)
-                               ec.NeedReturnLabel ();
-                       ec.CurrentBranching.CurrentUsageVector.Goto ();
-                       return true;
-               }
                
                protected override void DoEmit (EmitContext ec)
                {
@@ -3771,7 +3776,13 @@ namespace Mono.CSharp {
                }
        }
 
-       public abstract class ExceptionStatement : Statement
+       // A place where execution can restart in an iterator
+       public abstract class ResumableStatement : Statement
+       {
+               public Label ResumePoint;
+       }
+
+       public abstract class ExceptionStatement : ResumableStatement
        {
                public abstract void EmitFinallyBody (EmitContext ec);