Author: raja
Date: 2006-07-23 07:08:04 -0400 (Sun, 23 Jul 2006)
New Revision: 62901

Modified:
   trunk/mcs/gmcs/ChangeLog
   trunk/mcs/gmcs/codegen.cs
   trunk/mcs/gmcs/ecore.cs
   trunk/mcs/gmcs/expression.cs
   trunk/mcs/gmcs/statement.cs
   trunk/mcs/mcs/ChangeLog
   trunk/mcs/mcs/codegen.cs
   trunk/mcs/mcs/ecore.cs
   trunk/mcs/mcs/expression.cs
   trunk/mcs/mcs/statement.cs
Log:
* codegen.cs (EmitContext.Flags): Move InCatch, InFinally,
DoFlowAnalysis and OmitStructFlowAnalysis here.
(ec.With): Rename from WithUnsafe and generalize.
(ec.WithCheckState): Remove.  All users can be handled by 'With'.
(ec.WithFlowAnalyis): New.
* ecore.cs, expression.cs, statement.cs: Update.


Modified: trunk/mcs/gmcs/ChangeLog
===================================================================
--- trunk/mcs/gmcs/ChangeLog    2006-07-23 10:45:56 UTC (rev 62900)
+++ trunk/mcs/gmcs/ChangeLog    2006-07-23 11:08:04 UTC (rev 62901)
@@ -1,3 +1,12 @@
+2006-07-23  Raja R Harinath  <[EMAIL PROTECTED]>
+
+       * codegen.cs (EmitContext.Flags): Move InCatch, InFinally,
+       DoFlowAnalysis and OmitStructFlowAnalysis here.
+       (ec.With): Rename from WithUnsafe and generalize.
+       (ec.WithCheckState): Remove.  All users can be handled by 'With'.
+       (ec.WithFlowAnalyis): New.
+       * ecore.cs, expression.cs, statement.cs: Update.
+
 2006-07-22  Raja R Harinath  <[EMAIL PROTECTED]>
 
        * statement.cs (Block.ResolveMeta): Simplify slightly.

Modified: trunk/mcs/gmcs/codegen.cs
===================================================================
--- trunk/mcs/gmcs/codegen.cs   2006-07-23 10:45:56 UTC (rev 62900)
+++ trunk/mcs/gmcs/codegen.cs   2006-07-23 11:08:04 UTC (rev 62901)
@@ -210,7 +210,7 @@
                public ILGenerator   ig;
 
                [Flags]
-               internal enum Flags : byte {
+               public enum Flags : byte {
                        /// <summary>
                        ///   This flag tracks the `checked' state of the 
compilation,
                        ///   it controls whether we should generate code that 
does overflow
@@ -230,10 +230,26 @@
                        /// </summary>
                        ConstantCheckState = 1 << 1,
 
+                       AllCheckStateFlags = CheckState | ConstantCheckState,
+
                        /// <summary>
                        ///  Whether we are inside an unsafe block
                        /// </summary>
-                       InUnsafe = 1 << 2
+                       InUnsafe = 1 << 2,
+
+                       InCatch = 1 << 3,
+                       InFinally = 1 << 4,
+
+                       /// <summary>
+                       ///   Whether control flow analysis is enabled
+                       /// </summary>
+                       DoFlowAnalysis = 1 << 5,
+
+                       /// <summary>
+                       ///   Whether control flow analysis is disabled on 
structs
+                       ///   (only meaningful when DoFlowAnalysis is set)
+                       /// </summary>
+                       OmitStructFlowAnalysis = 1 << 6
                }
 
                Flags flags;
@@ -276,16 +292,6 @@
                public bool IsConstructor;
 
                /// <summary>
-               ///   Whether we're control flow analysis enabled
-               /// </summary>
-               public bool DoFlowAnalysis;
-
-               /// <summary>
-               ///   Whether we're control flow analysis disabled on struct
-               /// </summary>
-               public bool OmitStructFlowAnalysis;
-
-               /// <summary>
                ///   Keeps track of the Type to LocalBuilder temporary storage 
created
                ///   to store structures (used to compute the address of the 
structure
                ///   value on structure method invocations)
@@ -324,9 +330,6 @@
                /// </summary>
                public bool InFixedInitializer;
 
-               public bool InCatch;
-               public bool InFinally;
-
                /// <summary>
                ///  Whether we are inside an anonymous method.
                /// </summary>
@@ -456,6 +459,22 @@
                        get { return (flags & Flags.InUnsafe) != 0; }
                }
 
+               public bool InCatch {
+                       get { return (flags & Flags.InCatch) != 0; }
+               }
+
+               public bool InFinally {
+                       get { return (flags & Flags.InFinally) != 0; }
+               }
+
+               public bool DoFlowAnalysis {
+                       get { return (flags & Flags.DoFlowAnalysis) != 0; }
+               }
+
+               public bool OmitStructFlowAnalysis {
+                       get { return (flags & Flags.OmitStructFlowAnalysis) != 
0; }
+               }
+
                // utility helper for CheckExpr, UnCheckExpr, Checked and 
Unchecked statements
                // it's public so that we can use a struct at the callsite
                public struct FlagsHandle : IDisposable
@@ -469,27 +488,26 @@
                                oldval = ec.flags & mask;
                                ec.flags = (ec.flags & invmask) | (val & mask);
                        }
-                       void IDisposable.Dispose ()
+                       public void Dispose ()
                        {
                                ec.flags = (ec.flags & invmask) | oldval;
                        }
                }
 
-               // Temporarily set 'CheckState' and 'ConstantCheckState' to the 
given values.
-               // Should be used in an 'using' statement
-               public FlagsHandle WithCheckState (bool check_state, bool 
constant_check_state)
+               // Temporarily set all the given flags to the given value.  
Should be used in an 'using' statement
+               public FlagsHandle With (Flags bits, bool enable)
                {
-                       Flags newflags = 0;
-                       newflags |= check_state          ? Flags.CheckState     
    : 0;
-                       newflags |= constant_check_state ? 
Flags.ConstantCheckState : 0;
-                       return new FlagsHandle (this, Flags.CheckState | 
Flags.ConstantCheckState, newflags);
+                       return new FlagsHandle (this, bits, enable ? bits : 0);
                }
 
-               public FlagsHandle WithUnsafe (bool in_unsafe)
+               public FlagsHandle WithFlowAnalysis (bool do_flow_analysis, 
bool omit_struct_analysis)
                {
-                       return new FlagsHandle (this, Flags.InUnsafe, in_unsafe 
? Flags.InUnsafe : 0);
+                       Flags newflags = 
+                               (do_flow_analysis ? Flags.DoFlowAnalysis : 0) |
+                               (omit_struct_analysis ? 
Flags.OmitStructFlowAnalysis : 0);
+                       return new FlagsHandle (this, Flags.DoFlowAnalysis | 
Flags.OmitStructFlowAnalysis, newflags);
                }
-               
+
                public bool IsInObsoleteScope {
                        get { return ResolveContext.IsInObsoleteScope; }
                }
@@ -540,7 +558,7 @@
                        else
                                type = FlowBranching.BranchingType.Block;
 
-                       DoFlowAnalysis = true;
+                       flags |= Flags.DoFlowAnalysis;
 
                        current_flow_branching = FlowBranching.CreateBranching (
                                CurrentBranching, type, block, 
block.StartLocation);
@@ -727,27 +745,24 @@
                                if (!block.ResolveMeta (this, ip))
                                        return false;
 
-                               bool old_do_flow_analysis = DoFlowAnalysis;
-                               DoFlowAnalysis = true;
+                               using (this.With 
(EmitContext.Flags.DoFlowAnalysis, true)) {
+                                       FlowBranchingToplevel top_level;
+                                       if (anonymous_method_host != null)
+                                               top_level = new 
FlowBranchingToplevel (anonymous_method_host.CurrentBranching, block);
+                                       else 
+                                               top_level = 
block.TopLevelBranching;
 
-                               if (anonymous_method_host != null)
-                                       current_flow_branching = new 
FlowBranchingToplevel (anonymous_method_host.CurrentBranching, block);
-                               else 
-                                       current_flow_branching = 
block.TopLevelBranching;
-
-                               if (!block.Resolve (this)) {
+                                       current_flow_branching = top_level;
+                                       bool ok = block.Resolve (this);
                                        current_flow_branching = null;
-                                       DoFlowAnalysis = old_do_flow_analysis;
-                                       return false;
-                               }
 
-                               FlowBranching.Reachability reachability = 
((FlowBranchingToplevel) current_flow_branching).End ();
-                               current_flow_branching = null;
+                                       if (!ok)
+                                               return false;
 
-                               DoFlowAnalysis = old_do_flow_analysis;
-
-                               if (reachability.IsUnreachable)
-                                       unreachable = true;
+                                       FlowBranching.Reachability reachability 
= top_level.End ();
+                                       if (reachability.IsUnreachable)
+                                               unreachable = true;
+                               }
 #if PRODUCTION
                        } catch (Exception e) {
                                Console.WriteLine ("Exception caught by the 
compiler while compiling:");

Modified: trunk/mcs/gmcs/ecore.cs
===================================================================
--- trunk/mcs/gmcs/ecore.cs     2006-07-23 10:45:56 UTC (rev 62900)
+++ trunk/mcs/gmcs/ecore.cs     2006-07-23 11:08:04 UTC (rev 62901)
@@ -384,24 +384,23 @@
                        if ((flags & ResolveFlags.MaskExprClass) == 
ResolveFlags.Type) 
                                return ResolveAsTypeStep (ec, false);
 
-                       bool old_do_flow_analysis = ec.DoFlowAnalysis;
-                       bool old_omit_struct_analysis = 
ec.OmitStructFlowAnalysis;
+                       bool do_flow_analysis = ec.DoFlowAnalysis;
+                       bool omit_struct_analysis = ec.OmitStructFlowAnalysis;
                        if ((flags & ResolveFlags.DisableFlowAnalysis) != 0)
-                               ec.DoFlowAnalysis = false;
+                               do_flow_analysis = false;
                        if ((flags & ResolveFlags.DisableStructFlowAnalysis) != 
0)
-                               ec.OmitStructFlowAnalysis = true;
+                               omit_struct_analysis = true;
 
                        Expression e;
-                       if (this is SimpleName) {
-                               bool intermediate = (flags & 
ResolveFlags.Intermediate) == ResolveFlags.Intermediate;
-                               e = ((SimpleName) this).DoResolve (ec, 
intermediate);
+                       using (ec.WithFlowAnalysis (do_flow_analysis, 
omit_struct_analysis)) {
+                               if (this is SimpleName) {
+                                       bool intermediate = (flags & 
ResolveFlags.Intermediate) == ResolveFlags.Intermediate;
+                                       e = ((SimpleName) this).DoResolve (ec, 
intermediate);
+                               } else {
+                                       e = DoResolve (ec);
+                               }
                        }
-                       else 
-                               e = DoResolve (ec);
 
-                       ec.DoFlowAnalysis = old_do_flow_analysis;
-                       ec.OmitStructFlowAnalysis = old_omit_struct_analysis;
-
                        if (e == null)
                                return null;
 
@@ -1098,7 +1097,7 @@
                {
                        Expression target;
                        
-                       using (ec.WithCheckState (true, ec.ConstantCheckState)) 
{
+                       using (ec.With (EmitContext.Flags.CheckState, true)) {
                                target = Convert.ImplicitConversion (ec, 
source, TypeManager.int32_type, loc);
                                if (target == null)
                                        target = Convert.ImplicitConversion 
(ec, source, TypeManager.uint32_type, loc);
@@ -3107,12 +3106,11 @@
                                // "a.b" is initialized, not whether the whole 
struct "a" is initialized.
 
                                if (lvalue_instance) {
-                                       bool old_do_flow_analysis = 
ec.DoFlowAnalysis;
-                                       ec.DoFlowAnalysis = false;
-                                       Expression right_side =
-                                               out_access ? 
EmptyExpression.LValueMemberOutAccess : EmptyExpression.LValueMemberAccess;
-                                       InstanceExpression = 
InstanceExpression.ResolveLValue (ec, right_side, loc);
-                                       ec.DoFlowAnalysis = 
old_do_flow_analysis;
+                                       using (ec.With 
(EmitContext.Flags.DoFlowAnalysis, false)) {
+                                               Expression right_side =
+                                                       out_access ? 
EmptyExpression.LValueMemberOutAccess : EmptyExpression.LValueMemberAccess;
+                                               InstanceExpression = 
InstanceExpression.ResolveLValue (ec, right_side, loc);
+                                       }
                                } else {
                                        ResolveFlags rf = 
ResolveFlags.VariableOrValue | ResolveFlags.DisableFlowAnalysis;
                                        InstanceExpression = 
InstanceExpression.Resolve (ec, rf);

Modified: trunk/mcs/gmcs/expression.cs
===================================================================
--- trunk/mcs/gmcs/expression.cs        2006-07-23 10:45:56 UTC (rev 62900)
+++ trunk/mcs/gmcs/expression.cs        2006-07-23 11:08:04 UTC (rev 62901)
@@ -3924,20 +3924,17 @@
 
                public bool Resolve (EmitContext ec, Location loc)
                {
-                       bool old_do_flow_analysis = ec.DoFlowAnalysis;
-                       ec.DoFlowAnalysis = true;
+                       using (ec.With (EmitContext.Flags.DoFlowAnalysis, 
true)) {
+                               // Verify that the argument is readable
+                               if (ArgType != AType.Out)
+                                       Expr = Expr.Resolve (ec);
 
-                       // Verify that the argument is readable
-                       if (ArgType != AType.Out)
-                               Expr = Expr.Resolve (ec);
+                               // Verify that the argument is writeable
+                               if (Expr != null && (ArgType == AType.Out || 
ArgType == AType.Ref))
+                                       Expr = Expr.ResolveLValue (ec, 
EmptyExpression.OutAccess, loc);
 
-                       // Verify that the argument is writeable
-                       if (Expr != null && (ArgType == AType.Out || ArgType == 
AType.Ref))
-                               Expr = Expr.ResolveLValue (ec, 
EmptyExpression.OutAccess, loc);
-
-                       ec.DoFlowAnalysis = old_do_flow_analysis;
-
-                       return Expr != null;
+                               return Expr != null;
+                       }
                }
 
                public void Emit (EmitContext ec)
@@ -7352,7 +7349,7 @@
 
                public override Expression DoResolve (EmitContext ec)
                {
-                       using (ec.WithCheckState (true, true))
+                       using (ec.With (EmitContext.Flags.AllCheckStateFlags, 
true))
                                Expr = Expr.Resolve (ec);
                        
                        if (Expr == null)
@@ -7368,13 +7365,13 @@
 
                public override void Emit (EmitContext ec)
                {
-                       using (ec.WithCheckState (true, true))
+                       using (ec.With (EmitContext.Flags.AllCheckStateFlags, 
true))
                                Expr.Emit (ec);
                }
 
                public override void EmitBranchable (EmitContext ec, Label 
target, bool onTrue)
                {
-                       using (ec.WithCheckState (true, true))
+                       using (ec.With (EmitContext.Flags.AllCheckStateFlags, 
true))
                                Expr.EmitBranchable (ec, target, onTrue);
                }
        }
@@ -7394,7 +7391,7 @@
 
                public override Expression DoResolve (EmitContext ec)
                {
-                       using (ec.WithCheckState (false, false))
+                       using (ec.With (EmitContext.Flags.AllCheckStateFlags, 
false))
                                Expr = Expr.Resolve (ec);
 
                        if (Expr == null)
@@ -7410,13 +7407,13 @@
 
                public override void Emit (EmitContext ec)
                {
-                       using (ec.WithCheckState (false, false))
+                       using (ec.With (EmitContext.Flags.AllCheckStateFlags, 
false))
                                Expr.Emit (ec);
                }
                
                public override void EmitBranchable (EmitContext ec, Label 
target, bool onTrue)
                {
-                       using (ec.WithCheckState (false, false))
+                       using (ec.With (EmitContext.Flags.AllCheckStateFlags, 
false))
                                Expr.EmitBranchable (ec, target, onTrue);
                }
        }

Modified: trunk/mcs/gmcs/statement.cs
===================================================================
--- trunk/mcs/gmcs/statement.cs 2006-07-23 10:45:56 UTC (rev 62900)
+++ trunk/mcs/gmcs/statement.cs 2006-07-23 11:08:04 UTC (rev 62901)
@@ -1690,7 +1690,7 @@
                {
                        // If some parent block was unsafe, we remain unsafe 
even if this block
                        // isn't explicitly marked as such.
-                       using (ec.WithUnsafe (ec.InUnsafe | Unsafe)) {
+                       using (ec.With (EmitContext.Flags.InUnsafe, ec.InUnsafe 
| Unsafe)) {
                                //
                                // Compute the VariableMap's.
                                //
@@ -1751,7 +1751,7 @@
                                                // which in turn causes the 
'must be constant' error to be triggered.
                                                constants.Remove (name);
 
-                                               using (ec.WithCheckState 
(ec.CheckState, (flags & Flags.Unchecked) == 0)) {
+                                               using (ec.With 
(EmitContext.Flags.ConstantCheckState, (flags & Flags.Unchecked) == 0)) {
                                                        ec.CurrentBlock = this;
                                                        Expression e = 
cv.Resolve (ec);
                                                        if (e == null)
@@ -2085,7 +2085,7 @@
                //
                ToplevelBlock container;
                CaptureContext capture_context;
-               FlowBranching top_level_branching;
+               FlowBranchingToplevel top_level_branching;
 
                Hashtable capture_contexts;
                ArrayList children;
@@ -2179,7 +2179,7 @@
                        get { return capture_context; }
                }
 
-               public FlowBranching TopLevelBranching {
+               public FlowBranchingToplevel TopLevelBranching {
                        get { return top_level_branching; }
                }
 
@@ -3221,13 +3221,13 @@
 
                public override bool Resolve (EmitContext ec)
                {
-                       using (ec.WithCheckState (false, false))
+                       using (ec.With (EmitContext.Flags.AllCheckStateFlags, 
false))
                                return Block.Resolve (ec);
                }
                
                protected override void DoEmit (EmitContext ec)
                {
-                       using (ec.WithCheckState (false, false))
+                       using (ec.With (EmitContext.Flags.AllCheckStateFlags, 
false))
                                Block.Emit (ec);
                }
        }
@@ -3243,13 +3243,13 @@
 
                public override bool Resolve (EmitContext ec)
                {
-                       using (ec.WithCheckState (true, true))
+                       using (ec.With (EmitContext.Flags.AllCheckStateFlags, 
true))
                                return Block.Resolve (ec);
                }
 
                protected override void DoEmit (EmitContext ec)
                {
-                       using (ec.WithCheckState (true, true))
+                       using (ec.With (EmitContext.Flags.AllCheckStateFlags, 
true))
                                Block.Emit (ec);
                }
        }
@@ -3265,13 +3265,13 @@
 
                public override bool Resolve (EmitContext ec)
                {
-                       using (ec.WithUnsafe (true))
+                       using (ec.With (EmitContext.Flags.InUnsafe, true))
                                return Block.Resolve (ec);
                }
                
                protected override void DoEmit (EmitContext ec)
                {
-                       using (ec.WithUnsafe (true))
+                       using (ec.With (EmitContext.Flags.InUnsafe, true))
                                Block.Emit (ec);
                }
        }
@@ -3600,9 +3600,7 @@
 
                public override bool Resolve (EmitContext ec)
                {
-                       bool was_catch = ec.InCatch;
-                       ec.InCatch = true;
-                       try {
+                       using (ec.With (EmitContext.Flags.InCatch, true)) {
                                if (type_expr != null) {
                                        TypeExpr te = 
type_expr.ResolveAsTypeTerminal (ec, false);
                                        if (te == null)
@@ -3627,9 +3625,6 @@
 
                                return true;
                        }
-                       finally {
-                               ec.InCatch = was_catch;
-                       }
                }
        }
 
@@ -3728,15 +3723,13 @@
 
                        if (Fini != null) {
                                if (ok)
-                                       ec.CurrentBranching.CreateSibling (
-                                               Fini, 
FlowBranching.SiblingType.Finally);
+                                       ec.CurrentBranching.CreateSibling 
(Fini, FlowBranching.SiblingType.Finally);
 
                                Report.Debug (1, "STARTED SIBLING FOR FINALLY", 
ec.CurrentBranching, vector);
-                               bool was_finally = ec.InFinally;
-                               ec.InFinally = true;
-                               if (!Fini.Resolve (ec))
-                                       ok = false;
-                               ec.InFinally = was_finally;
+                               using (ec.With (EmitContext.Flags.InFinally, 
true)) {
+                                       if (!Fini.Resolve (ec))
+                                               ok = false;
+                               }
 
                                if (!ec.InIterator)
                                        need_exc_block = true;

Modified: trunk/mcs/mcs/ChangeLog
===================================================================
--- trunk/mcs/mcs/ChangeLog     2006-07-23 10:45:56 UTC (rev 62900)
+++ trunk/mcs/mcs/ChangeLog     2006-07-23 11:08:04 UTC (rev 62901)
@@ -1,3 +1,12 @@
+2006-07-23  Raja R Harinath  <[EMAIL PROTECTED]>
+
+       * codegen.cs (EmitContext.Flags): Move InCatch, InFinally,
+       DoFlowAnalysis and OmitStructFlowAnalysis here.
+       (ec.With): Rename from WithUnsafe and generalize.
+       (ec.WithCheckState): Remove.  All users can be handled by 'With'.
+       (ec.WithFlowAnalyis): New.
+       * ecore.cs, expression.cs, statement.cs: Update.
+
 2006-07-22  Raja R Harinath  <[EMAIL PROTECTED]>
 
        * statement.cs (Block.ResolveMeta): Simplify slightly.

Modified: trunk/mcs/mcs/codegen.cs
===================================================================
--- trunk/mcs/mcs/codegen.cs    2006-07-23 10:45:56 UTC (rev 62900)
+++ trunk/mcs/mcs/codegen.cs    2006-07-23 11:08:04 UTC (rev 62901)
@@ -206,7 +206,7 @@
                public ILGenerator   ig;
 
                [Flags]
-               internal enum Flags : byte {
+               public enum Flags : byte {
                        /// <summary>
                        ///   This flag tracks the `checked' state of the 
compilation,
                        ///   it controls whether we should generate code that 
does overflow
@@ -226,10 +226,26 @@
                        /// </summary>
                        ConstantCheckState = 1 << 1,
 
+                       AllCheckStateFlags = CheckState | ConstantCheckState,
+
                        /// <summary>
                        ///  Whether we are inside an unsafe block
                        /// </summary>
-                       InUnsafe = 1 << 2
+                       InUnsafe = 1 << 2,
+
+                       InCatch = 1 << 3,
+                       InFinally = 1 << 4,
+
+                       /// <summary>
+                       ///   Whether control flow analysis is enabled
+                       /// </summary>
+                       DoFlowAnalysis = 1 << 5,
+
+                       /// <summary>
+                       ///   Whether control flow analysis is disabled on 
structs
+                       ///   (only meaningful when DoFlowAnalysis is set)
+                       /// </summary>
+                       OmitStructFlowAnalysis = 1 << 6
                }
 
                Flags flags;
@@ -272,16 +288,6 @@
                public bool IsConstructor;
 
                /// <summary>
-               ///   Whether we're control flow analysis enabled
-               /// </summary>
-               public bool DoFlowAnalysis;
-
-               /// <summary>
-               ///   Whether we're control flow analysis disabled on struct
-               /// </summary>
-               public bool OmitStructFlowAnalysis;
-
-               /// <summary>
                ///   Keeps track of the Type to LocalBuilder temporary storage 
created
                ///   to store structures (used to compute the address of the 
structure
                ///   value on structure method invocations)
@@ -320,9 +326,6 @@
                /// </summary>
                public bool InFixedInitializer;
 
-               public bool InCatch;
-               public bool InFinally;
-
                /// <summary>
                ///  Whether we are inside an anonymous method.
                /// </summary>
@@ -442,6 +445,22 @@
                        get { return (flags & Flags.InUnsafe) != 0; }
                }
 
+               public bool InCatch {
+                       get { return (flags & Flags.InCatch) != 0; }
+               }
+
+               public bool InFinally {
+                       get { return (flags & Flags.InFinally) != 0; }
+               }
+
+               public bool DoFlowAnalysis {
+                       get { return (flags & Flags.DoFlowAnalysis) != 0; }
+               }
+
+               public bool OmitStructFlowAnalysis {
+                       get { return (flags & Flags.OmitStructFlowAnalysis) != 
0; }
+               }
+
                // utility helper for CheckExpr, UnCheckExpr, Checked and 
Unchecked statements
                // it's public so that we can use a struct at the callsite
                public struct FlagsHandle : IDisposable
@@ -455,27 +474,26 @@
                                oldval = ec.flags & mask;
                                ec.flags = (ec.flags & invmask) | (val & mask);
                        }
-                       void IDisposable.Dispose ()
+                       public void Dispose ()
                        {
                                ec.flags = (ec.flags & invmask) | oldval;
                        }
                }
 
-               // Temporarily set 'CheckState' and 'ConstantCheckState' to the 
given values.
-               // Should be used in an 'using' statement
-               public FlagsHandle WithCheckState (bool check_state, bool 
constant_check_state)
+               // Temporarily set all the given flags to the given value.  
Should be used in an 'using' statement
+               public FlagsHandle With (Flags bits, bool enable)
                {
-                       Flags newflags = 0;
-                       newflags |= check_state          ? Flags.CheckState     
    : 0;
-                       newflags |= constant_check_state ? 
Flags.ConstantCheckState : 0;
-                       return new FlagsHandle (this, Flags.CheckState | 
Flags.ConstantCheckState, newflags);
+                       return new FlagsHandle (this, bits, enable ? bits : 0);
                }
 
-               public FlagsHandle WithUnsafe (bool in_unsafe)
+               public FlagsHandle WithFlowAnalysis (bool do_flow_analysis, 
bool omit_struct_analysis)
                {
-                       return new FlagsHandle (this, Flags.InUnsafe, in_unsafe 
? Flags.InUnsafe : 0);
+                       Flags newflags = 
+                               (do_flow_analysis ? Flags.DoFlowAnalysis : 0) |
+                               (omit_struct_analysis ? 
Flags.OmitStructFlowAnalysis : 0);
+                       return new FlagsHandle (this, Flags.DoFlowAnalysis | 
Flags.OmitStructFlowAnalysis, newflags);
                }
-               
+
                public bool IsInObsoleteScope {
                        get { return ResolveContext.IsInObsoleteScope; }
                }
@@ -526,7 +544,7 @@
                        else
                                type = FlowBranching.BranchingType.Block;
 
-                       DoFlowAnalysis = true;
+                       flags |= Flags.DoFlowAnalysis;
 
                        current_flow_branching = FlowBranching.CreateBranching (
                                CurrentBranching, type, block, 
block.StartLocation);
@@ -713,27 +731,24 @@
                                if (!block.ResolveMeta (this, ip))
                                        return false;
 
-                               bool old_do_flow_analysis = DoFlowAnalysis;
-                               DoFlowAnalysis = true;
+                               using (this.With 
(EmitContext.Flags.DoFlowAnalysis, true)) {
+                                       FlowBranchingToplevel top_level;
+                                       if (anonymous_method_host != null)
+                                               top_level = new 
FlowBranchingToplevel (anonymous_method_host.CurrentBranching, block);
+                                       else 
+                                               top_level = 
block.TopLevelBranching;
 
-                               if (anonymous_method_host != null)
-                                       current_flow_branching = new 
FlowBranchingToplevel (anonymous_method_host.CurrentBranching, block);
-                               else 
-                                       current_flow_branching = 
block.TopLevelBranching;
-
-                               if (!block.Resolve (this)) {
+                                       current_flow_branching = top_level;
+                                       bool ok = block.Resolve (this);
                                        current_flow_branching = null;
-                                       DoFlowAnalysis = old_do_flow_analysis;
-                                       return false;
-                               }
 
-                               FlowBranching.Reachability reachability = 
((FlowBranchingToplevel) current_flow_branching).End ();
-                               current_flow_branching = null;
+                                       if (!ok)
+                                               return false;
 
-                               DoFlowAnalysis = old_do_flow_analysis;
-
-                               if (reachability.IsUnreachable)
-                                       unreachable = true;
+                                       FlowBranching.Reachability reachability 
= top_level.End ();
+                                       if (reachability.IsUnreachable)
+                                               unreachable = true;
+                               }
 #if PRODUCTION
                        } catch (Exception e) {
                                Console.WriteLine ("Exception caught by the 
compiler while compiling:");

Modified: trunk/mcs/mcs/ecore.cs
===================================================================
--- trunk/mcs/mcs/ecore.cs      2006-07-23 10:45:56 UTC (rev 62900)
+++ trunk/mcs/mcs/ecore.cs      2006-07-23 11:08:04 UTC (rev 62901)
@@ -374,24 +374,23 @@
                        if ((flags & ResolveFlags.MaskExprClass) == 
ResolveFlags.Type) 
                                return ResolveAsTypeStep (ec, false);
 
-                       bool old_do_flow_analysis = ec.DoFlowAnalysis;
-                       bool old_omit_struct_analysis = 
ec.OmitStructFlowAnalysis;
+                       bool do_flow_analysis = ec.DoFlowAnalysis;
+                       bool omit_struct_analysis = ec.OmitStructFlowAnalysis;
                        if ((flags & ResolveFlags.DisableFlowAnalysis) != 0)
-                               ec.DoFlowAnalysis = false;
+                               do_flow_analysis = false;
                        if ((flags & ResolveFlags.DisableStructFlowAnalysis) != 
0)
-                               ec.OmitStructFlowAnalysis = true;
+                               omit_struct_analysis = true;
 
                        Expression e;
-                       if (this is SimpleName) {
-                               bool intermediate = (flags & 
ResolveFlags.Intermediate) == ResolveFlags.Intermediate;
-                               e = ((SimpleName) this).DoResolve (ec, 
intermediate);
+                       using (ec.WithFlowAnalysis (do_flow_analysis, 
omit_struct_analysis)) {
+                               if (this is SimpleName) {
+                                       bool intermediate = (flags & 
ResolveFlags.Intermediate) == ResolveFlags.Intermediate;
+                                       e = ((SimpleName) this).DoResolve (ec, 
intermediate);
+                               } else {
+                                       e = DoResolve (ec);
+                               }
                        }
-                       else 
-                               e = DoResolve (ec);
 
-                       ec.DoFlowAnalysis = old_do_flow_analysis;
-                       ec.OmitStructFlowAnalysis = old_omit_struct_analysis;
-
                        if (e == null)
                                return null;
 
@@ -1070,7 +1069,7 @@
                {
                        Expression target;
                        
-                       using (ec.WithCheckState (true, ec.ConstantCheckState)) 
{
+                       using (ec.With (EmitContext.Flags.CheckState, true)) {
                                target = Convert.ImplicitConversion (ec, 
source, TypeManager.int32_type, loc);
                                if (target == null)
                                        target = Convert.ImplicitConversion 
(ec, source, TypeManager.uint32_type, loc);
@@ -2788,12 +2787,11 @@
                                // "a.b" is initialized, not whether the whole 
struct "a" is initialized.
 
                                if (lvalue_instance) {
-                                       bool old_do_flow_analysis = 
ec.DoFlowAnalysis;
-                                       ec.DoFlowAnalysis = false;
-                                       Expression right_side =
-                                               out_access ? 
EmptyExpression.LValueMemberOutAccess : EmptyExpression.LValueMemberAccess;
-                                       InstanceExpression = 
InstanceExpression.ResolveLValue (ec, right_side, loc);
-                                       ec.DoFlowAnalysis = 
old_do_flow_analysis;
+                                       using (ec.With 
(EmitContext.Flags.DoFlowAnalysis, false)) {
+                                               Expression right_side =
+                                                       out_access ? 
EmptyExpression.LValueMemberOutAccess : EmptyExpression.LValueMemberAccess;
+                                               InstanceExpression = 
InstanceExpression.ResolveLValue (ec, right_side, loc);
+                                       }
                                } else {
                                        ResolveFlags rf = 
ResolveFlags.VariableOrValue | ResolveFlags.DisableFlowAnalysis;
                                        InstanceExpression = 
InstanceExpression.Resolve (ec, rf);

Modified: trunk/mcs/mcs/expression.cs
===================================================================
--- trunk/mcs/mcs/expression.cs 2006-07-23 10:45:56 UTC (rev 62900)
+++ trunk/mcs/mcs/expression.cs 2006-07-23 11:08:04 UTC (rev 62901)
@@ -3827,20 +3827,17 @@
 
                public bool Resolve (EmitContext ec, Location loc)
                {
-                       bool old_do_flow_analysis = ec.DoFlowAnalysis;
-                       ec.DoFlowAnalysis = true;
+                       using (ec.With (EmitContext.Flags.DoFlowAnalysis, 
true)) {
+                               // Verify that the argument is readable
+                               if (ArgType != AType.Out)
+                                       Expr = Expr.Resolve (ec);
 
-                       // Verify that the argument is readable
-                       if (ArgType != AType.Out)
-                               Expr = Expr.Resolve (ec);
+                               // Verify that the argument is writeable
+                               if (Expr != null && (ArgType == AType.Out || 
ArgType == AType.Ref))
+                                       Expr = Expr.ResolveLValue (ec, 
EmptyExpression.OutAccess, loc);
 
-                       // Verify that the argument is writeable
-                       if (Expr != null && (ArgType == AType.Out || ArgType == 
AType.Ref))
-                               Expr = Expr.ResolveLValue (ec, 
EmptyExpression.OutAccess, loc);
-
-                       ec.DoFlowAnalysis = old_do_flow_analysis;
-
-                       return Expr != null;
+                               return Expr != null;
+                       }
                }
 
                public void Emit (EmitContext ec)
@@ -6953,7 +6950,7 @@
 
                public override Expression DoResolve (EmitContext ec)
                {
-                       using (ec.WithCheckState (true, true))
+                       using (ec.With (EmitContext.Flags.AllCheckStateFlags, 
true))
                                Expr = Expr.Resolve (ec);
                        
                        if (Expr == null)
@@ -6969,13 +6966,13 @@
 
                public override void Emit (EmitContext ec)
                {
-                       using (ec.WithCheckState (true, true))
+                       using (ec.With (EmitContext.Flags.AllCheckStateFlags, 
true))
                                Expr.Emit (ec);
                }
 
                public override void EmitBranchable (EmitContext ec, Label 
target, bool onTrue)
                {
-                       using (ec.WithCheckState (true, true))
+                       using (ec.With (EmitContext.Flags.AllCheckStateFlags, 
true))
                                Expr.EmitBranchable (ec, target, onTrue);
                }
        }
@@ -6995,7 +6992,7 @@
 
                public override Expression DoResolve (EmitContext ec)
                {
-                       using (ec.WithCheckState (false, false))
+                       using (ec.With (EmitContext.Flags.AllCheckStateFlags, 
false))
                                Expr = Expr.Resolve (ec);
 
                        if (Expr == null)
@@ -7011,13 +7008,13 @@
 
                public override void Emit (EmitContext ec)
                {
-                       using (ec.WithCheckState (false, false))
+                       using (ec.With (EmitContext.Flags.AllCheckStateFlags, 
false))
                                Expr.Emit (ec);
                }
                
                public override void EmitBranchable (EmitContext ec, Label 
target, bool onTrue)
                {
-                       using (ec.WithCheckState (false, false))
+                       using (ec.With (EmitContext.Flags.AllCheckStateFlags, 
false))
                                Expr.EmitBranchable (ec, target, onTrue);
                }
        }

Modified: trunk/mcs/mcs/statement.cs
===================================================================
--- trunk/mcs/mcs/statement.cs  2006-07-23 10:45:56 UTC (rev 62900)
+++ trunk/mcs/mcs/statement.cs  2006-07-23 11:08:04 UTC (rev 62901)
@@ -1690,7 +1690,7 @@
                {
                        // If some parent block was unsafe, we remain unsafe 
even if this block
                        // isn't explicitly marked as such.
-                       using (ec.WithUnsafe (ec.InUnsafe | Unsafe)) {
+                       using (ec.With (EmitContext.Flags.InUnsafe, ec.InUnsafe 
| Unsafe)) {
                                //
                                // Compute the VariableMap's.
                                //
@@ -1751,7 +1751,7 @@
                                                // which in turn causes the 
'must be constant' error to be triggered.
                                                constants.Remove (name);
 
-                                               using (ec.WithCheckState 
(ec.CheckState, (flags & Flags.Unchecked) == 0)) {
+                                               using (ec.With 
(EmitContext.Flags.ConstantCheckState, (flags & Flags.Unchecked) == 0)) {
                                                        ec.CurrentBlock = this;
                                                        Expression e = 
cv.Resolve (ec);
                                                        if (e == null)
@@ -2090,7 +2090,7 @@
                //
                ToplevelBlock container;
                CaptureContext capture_context;
-               FlowBranching top_level_branching;
+               FlowBranchingToplevel top_level_branching;
 
                Hashtable capture_contexts;
                ArrayList children;
@@ -2181,7 +2181,7 @@
                        get { return capture_context; }
                }
 
-               public FlowBranching TopLevelBranching {
+               public FlowBranchingToplevel TopLevelBranching {
                        get { return top_level_branching; }
                }
 
@@ -3184,13 +3184,13 @@
 
                public override bool Resolve (EmitContext ec)
                {
-                       using (ec.WithCheckState (false, false))
+                       using (ec.With (EmitContext.Flags.AllCheckStateFlags, 
false))
                                return Block.Resolve (ec);
                }
                
                protected override void DoEmit (EmitContext ec)
                {
-                       using (ec.WithCheckState (false, false))
+                       using (ec.With (EmitContext.Flags.AllCheckStateFlags, 
false))
                                Block.Emit (ec);
                }
        }
@@ -3206,13 +3206,13 @@
 
                public override bool Resolve (EmitContext ec)
                {
-                       using (ec.WithCheckState (true, true))
+                       using (ec.With (EmitContext.Flags.AllCheckStateFlags, 
true))
                                return Block.Resolve (ec);
                }
 
                protected override void DoEmit (EmitContext ec)
                {
-                       using (ec.WithCheckState (true, true))
+                       using (ec.With (EmitContext.Flags.AllCheckStateFlags, 
true))
                                Block.Emit (ec);
                }
        }
@@ -3228,13 +3228,13 @@
 
                public override bool Resolve (EmitContext ec)
                {
-                       using (ec.WithUnsafe (true))
+                       using (ec.With (EmitContext.Flags.InUnsafe, true))
                                return Block.Resolve (ec);
                }
                
                protected override void DoEmit (EmitContext ec)
                {
-                       using (ec.WithUnsafe (true))
+                       using (ec.With (EmitContext.Flags.InUnsafe, true))
                                Block.Emit (ec);
                }
        }
@@ -3563,9 +3563,7 @@
 
                public override bool Resolve (EmitContext ec)
                {
-                       bool was_catch = ec.InCatch;
-                       ec.InCatch = true;
-                       try {
+                       using (ec.With (EmitContext.Flags.InCatch, true)) {
                                if (type_expr != null) {
                                        TypeExpr te = 
type_expr.ResolveAsTypeTerminal (ec, false);
                                        if (te == null)
@@ -3590,9 +3588,6 @@
 
                                return true;
                        }
-                       finally {
-                               ec.InCatch = was_catch;
-                       }
                }
        }
 
@@ -3691,15 +3686,13 @@
 
                        if (Fini != null) {
                                if (ok)
-                                       ec.CurrentBranching.CreateSibling (
-                                               Fini, 
FlowBranching.SiblingType.Finally);
+                                       ec.CurrentBranching.CreateSibling 
(Fini, FlowBranching.SiblingType.Finally);
 
                                Report.Debug (1, "STARTED SIBLING FOR FINALLY", 
ec.CurrentBranching, vector);
-                               bool was_finally = ec.InFinally;
-                               ec.InFinally = true;
-                               if (!Fini.Resolve (ec))
-                                       ok = false;
-                               ec.InFinally = was_finally;
+                               using (ec.With (EmitContext.Flags.InFinally, 
true)) {
+                                       if (!Fini.Resolve (ec))
+                                               ok = false;
+                               }
 
                                if (!ec.InIterator)
                                        need_exc_block = true;

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to