Author: martin
Date: 2005-05-02 05:06:34 -0400 (Mon, 02 May 2005)
New Revision: 43870

Modified:
   trunk/mcs/gmcs/ChangeLog
   trunk/mcs/gmcs/class.cs
   trunk/mcs/gmcs/codegen.cs
   trunk/mcs/gmcs/expression.cs
   trunk/mcs/gmcs/statement.cs
Log:
2005-05-02  Martin Baulig  <[EMAIL PROTECTED]>

        Fix #70140.

        * class.cs (ConstructorInitializer.Resolve): Added `Block block'
        arguments; use it instead of creating a new TopLevelBlock.
        (Constructor.Emit): Call `block.ResolveMeta ()' before resolving
        our ConstructorInitializer.

        * statement.cs (Block.IsConstructor): New public property.
        (TopLevelBlock.TopLevelBranching): New public property.
        (TopLevelBlock.ResolveMeta): New public method; call ResolveMeta()
        and create our `TopLevelBranching'.

        * codegen.cs (EmitContext.ResolveTopBlock): If we're not an
        anonymous method host, use `block.TopLevelBranching' rather than
        creating a new branching.

        * expression.cs (This.DoResolve): Don't report a CS0188 if we're
        inside the constructor.



Modified: trunk/mcs/gmcs/ChangeLog
===================================================================
--- trunk/mcs/gmcs/ChangeLog    2005-05-02 08:16:35 UTC (rev 43869)
+++ trunk/mcs/gmcs/ChangeLog    2005-05-02 09:06:34 UTC (rev 43870)
@@ -1,3 +1,24 @@
+2005-05-02  Martin Baulig  <[EMAIL PROTECTED]>
+
+       Fix #70140.
+
+       * class.cs (ConstructorInitializer.Resolve): Added `Block block'
+       arguments; use it instead of creating a new TopLevelBlock.
+       (Constructor.Emit): Call `block.ResolveMeta ()' before resolving
+       our ConstructorInitializer.
+
+       * statement.cs (Block.IsConstructor): New public property.
+       (TopLevelBlock.TopLevelBranching): New public property.
+       (TopLevelBlock.ResolveMeta): New public method; call ResolveMeta()
+       and create our `TopLevelBranching'.
+
+       * codegen.cs (EmitContext.ResolveTopBlock): If we're not an
+       anonymous method host, use `block.TopLevelBranching' rather than
+       creating a new branching.
+
+       * expression.cs (This.DoResolve): Don't report a CS0188 if we're
+       inside the constructor.
+
 2005-04-30  Martin Baulig  <[EMAIL PROTECTED]>
 
        * statement.cs (Switch.SimpleSwitchEmit): Reset `default_at_end'

Modified: trunk/mcs/gmcs/class.cs
===================================================================
--- trunk/mcs/gmcs/class.cs     2005-05-02 08:16:35 UTC (rev 43869)
+++ trunk/mcs/gmcs/class.cs     2005-05-02 09:06:34 UTC (rev 43870)
@@ -4429,13 +4429,13 @@
                        }
                }
 
-               public bool Resolve (ConstructorBuilder caller_builder, 
EmitContext ec)
+               public bool Resolve (ConstructorBuilder caller_builder, Block 
block, EmitContext ec)
                {
                        Expression base_constructor_group;
                        Type t;
                        bool error = false;
 
-                       ec.CurrentBlock = new ToplevelBlock 
(Block.Flags.Implicit, parameters, loc);
+                       ec.CurrentBlock = block;
 
                        if (argument_list != null){
                                foreach (Argument a in argument_list){
@@ -4806,6 +4806,15 @@
                                return;
                        }
 
+                       // If this is a non-static `struct' constructor and 
doesn't have any
+                       // initializer, it must initialize all of the struct's 
fields.
+                       if ((Parent.Kind == Kind.Struct) &&
+                           ((ModFlags & Modifiers.STATIC) == 0) && 
(Initializer == null))
+                               Block.AddThisVariable (Parent, Location);
+
+                       if (block != null)
+                               block.ResolveMeta (ec, ParameterInfo);
+
                        if ((ModFlags & Modifiers.STATIC) == 0){
                                if (Parent.Kind == Kind.Class && Initializer == 
null)
                                        Initializer = new 
ConstructorBaseInitializer (
@@ -4817,7 +4826,8 @@
                                // `this' access
                                //
                                ec.IsStatic = true;
-                               if (Initializer != null && !Initializer.Resolve 
(ConstructorBuilder, ec))
+                               if ((Initializer != null) &&
+                                   !Initializer.Resolve (ConstructorBuilder, 
block, ec))
                                        return;
                                ec.IsStatic = false;
                        }
@@ -4855,12 +4865,6 @@
                        if (OptAttributes != null) 
                                OptAttributes.Emit (ec, this);
 
-                       // If this is a non-static `struct' constructor and 
doesn't have any
-                       // initializer, it must initialize all of the struct's 
fields.
-                       if ((Parent.Kind == Kind.Struct) &&
-                           ((ModFlags & Modifiers.STATIC) == 0) && 
(Initializer == null))
-                               Block.AddThisVariable (Parent, Location);
-
                        ec.EmitTopBlock (block, ParameterInfo, Location);
 
                        if (source != null)

Modified: trunk/mcs/gmcs/codegen.cs
===================================================================
--- trunk/mcs/gmcs/codegen.cs   2005-05-02 08:16:35 UTC (rev 43869)
+++ trunk/mcs/gmcs/codegen.cs   2005-05-02 09:06:34 UTC (rev 43870)
@@ -332,7 +332,7 @@
                ///   Whether we're control flow analysis enabled
                /// </summary>
                public bool DoFlowAnalysis;
-               
+
                /// <summary>
                ///   Keeps track of the Type to LocalBuilder temporary storage 
created
                ///   to store structures (used to compute the address of the 
structure
@@ -516,12 +516,16 @@
                {
                        FlowBranching.BranchingType type;
 
-                       if (CurrentBranching.Type == 
FlowBranching.BranchingType.Switch)
+                       if ((CurrentBranching != null) &&
+                           (CurrentBranching.Type == 
FlowBranching.BranchingType.Switch))
                                type = 
FlowBranching.BranchingType.SwitchSection;
                        else
                                type = FlowBranching.BranchingType.Block;
 
-                       current_flow_branching = FlowBranching.CreateBranching 
(CurrentBranching, type, block, block.StartLocation);
+                       DoFlowAnalysis = true;
+
+                       current_flow_branching = FlowBranching.CreateBranching (
+                               CurrentBranching, type, block, 
block.StartLocation);
                        return current_flow_branching;
                }
 
@@ -682,12 +686,9 @@
                                CurrentFile = loc.File;
 
 #if PRODUCTION
-                           try {
+                       try {
 #endif
-                               int errors = Report.Errors;
-
-                               block.ResolveMeta (block, this, ip);
-                               if (Report.Errors != errors)
+                               if (!block.ResolveMeta (this, ip))
                                        return false;
 
                                bool old_do_flow_analysis = DoFlowAnalysis;
@@ -695,11 +696,10 @@
 
                                if (anonymous_method_host != null)
                                        current_flow_branching = 
FlowBranching.CreateBranching (
-                                               
anonymous_method_host.CurrentBranching, FlowBranching.BranchingType.Block,
-                                               block, loc);
+                                               
anonymous_method_host.CurrentBranching,
+                                               
FlowBranching.BranchingType.Block, block, loc);
                                else 
-                                       current_flow_branching = 
FlowBranching.CreateBranching (
-                                               null, 
FlowBranching.BranchingType.Block, block, loc);
+                                       current_flow_branching = 
block.TopLevelBranching;
 
                                if (!block.Resolve (this)) {
                                        current_flow_branching = null;
@@ -717,7 +717,7 @@
                                    reachability.IsUnreachable)
                                        unreachable = true;
 #if PRODUCTION
-                           } catch (Exception e) {
+                       } catch (Exception e) {
                                        Console.WriteLine ("Exception caught by 
the compiler while compiling:");
                                        Console.WriteLine ("   Block that 
caused the problem begin at: " + loc);
                                        

Modified: trunk/mcs/gmcs/expression.cs
===================================================================
--- trunk/mcs/gmcs/expression.cs        2005-05-02 08:16:35 UTC (rev 43869)
+++ trunk/mcs/gmcs/expression.cs        2005-05-02 09:06:34 UTC (rev 43870)
@@ -6980,7 +6980,9 @@
                        if (!ResolveBase (ec))
                                return null;
 
-                       if ((variable_info != null) && 
!variable_info.IsAssigned (ec)) {
+                       bool is_ctor = (block == null) || block.IsConstructor;
+
+                       if ((variable_info != null) && !is_ctor && 
!variable_info.IsAssigned (ec)) {
                                Error (188, "The this object cannot be used 
before all " +
                                       "of its fields are assigned to");
                                variable_info.SetAssigned (ec);

Modified: trunk/mcs/gmcs/statement.cs
===================================================================
--- trunk/mcs/gmcs/statement.cs 2005-05-02 08:16:35 UTC (rev 43869)
+++ trunk/mcs/gmcs/statement.cs 2005-05-02 09:06:34 UTC (rev 43870)
@@ -1187,6 +1187,12 @@
                }
                Flags flags;
 
+               public bool IsConstructor {
+                       get {
+                               return this_variable != null;
+                       }
+               }
+
                public bool Implicit {
                        get {
                                return (flags & Flags.Implicit) != 0;
@@ -2113,6 +2119,7 @@
                //
                public ToplevelBlock Container;
                CaptureContext capture_context;
+               FlowBranching top_level_branching;
 
                Hashtable capture_contexts;
 
@@ -2185,6 +2192,26 @@
                                return capture_context;
                        }
                }
+
+               public FlowBranching TopLevelBranching {
+                       get {
+                               return top_level_branching;
+                       }
+               }
+
+               public bool ResolveMeta (EmitContext ec, InternalParameters ip)
+               {
+                       int errors = Report.Errors;
+
+                       if (top_level_branching != null)
+                               return true;
+
+                       ResolveMeta (this, ec, ip);
+
+                       top_level_branching = ec.StartFlowBranching (this);
+
+                       return Report.Errors == errors;
+               }
        }
        
        public class SwitchLabel {

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

Reply via email to