Author: martin
Date: 2005-04-18 07:35:30 -0400 (Mon, 18 Apr 2005)
New Revision: 43207

Modified:
   trunk/mcs/gmcs/ChangeLog
   trunk/mcs/gmcs/cs-parser.jay
   trunk/mcs/gmcs/decl.cs
   trunk/mcs/gmcs/ecore.cs
   trunk/mcs/gmcs/expression.cs
   trunk/mcs/gmcs/statement.cs
Log:
**** Merged r42330-r42364 from MCS ****


Modified: trunk/mcs/gmcs/ChangeLog
===================================================================
--- trunk/mcs/gmcs/ChangeLog    2005-04-18 11:14:20 UTC (rev 43206)
+++ trunk/mcs/gmcs/ChangeLog    2005-04-18 11:35:30 UTC (rev 43207)
@@ -1,3 +1,45 @@
+2005-03-30  Raja R Harinath  <[EMAIL PROTECTED]>
+
+       * ecore.cs (PropertyExpr): Derive from Expression, not
+       ExpressionStatement.
+       (PropertyExpr.EmitStatement): Remove.
+
+2005-03-29  Raja R Harinath  <[EMAIL PROTECTED]>
+
+       Fix #74060.
+       * expression.cs (MemberAccess.ResolveMemberAccess): Allow the
+       internal field "value__" of an enum be private.  The examples for
+       "value__" that I found on MSDN all used FieldAttributes.Private.
+
+       * decl.cs (MemberCache.AddMethods): Use C# terminology in warning.
+       Don't mention IL method attribute names.
+
+       Fix #47991.  Remove a TODO.
+       * statement.cs (Block.Toplevel): Make into a field.
+       (Block.Parameters): Move into ToplevelBlock.
+       (Block.known_variables): Rename from child_variable_names.
+       (Block.Block): Remove variants that take Parameters.  Initialize
+       'Toplevel' with the immediately surrounding toplevel block.
+       (Block.AddKnownVariable): Rename from AddChildVariableName.  Add a
+       LocalInfo parameter.
+       (Block.GetKnownVariableInfo): New.
+       (Block.IsVariableNameUsedInChildBlock): Update.
+       (Block.IsVariableNameUsedInBlock): New.  Checks if a name is used in
+       the block, even though it may not be in scope.
+       (Block.AddVariable): Remove Parameters parameter.  Use
+       Toplevel.Parameters instead.
+       (Block.AddConstant): Remove Parameters parameter.
+       (Block.GetParameterReference): Update to use Toplevel.Parameters.
+       (Block.IsParamaterReference): Likewise.
+       (Block.IsLocalParameter): Likewise.  Simplify a lot.
+       (ToplevelBlock.Parameters): New.  Moved from Block.
+       (ToplevelBlock.ToplevelBlock): Update to changes.  Always
+       initialize Parameters to a non-null value.
+       * cs-parser.jay: Update to changes.
+       * ecore.cs (SimpleName.SimpleNameResolve): Emit cs0136 error for
+       simple names that mean different things in the same block.  Use
+       Block.IsVariableNameUsedInBlock.
+
 2005-03-28  Raja R Harinath  <[EMAIL PROTECTED]>
 
        * enum.cs (Enum.LookupEnumValue): Remove debugging code.

Modified: trunk/mcs/gmcs/cs-parser.jay
===================================================================
--- trunk/mcs/gmcs/cs-parser.jay        2005-04-18 11:14:20 UTC (rev 43206)
+++ trunk/mcs/gmcs/cs-parser.jay        2005-04-18 11:35:30 UTC (rev 43207)
@@ -3830,8 +3830,7 @@
                        current_block = new ToplevelBlock ((ToplevelBlock) 
top_current_block, current_local_parameters, lexer.Location);
                        top_current_block = current_block;
                } else {
-                       current_block = new Block (current_block, 
current_local_parameters,
-                                                  lexer.Location, 
Location.Null);
+                       current_block = new Block (current_block, 
lexer.Location, Location.Null);
                }
          } 
          opt_statement_list CLOSE_BRACE 
@@ -4243,8 +4242,7 @@
 
                                LocalInfo vi;
 
-                               vi = current_block.AddVariable (
-                                       type, decl.identifier, 
current_local_parameters, decl.Location);
+                               vi = current_block.AddVariable (type, 
decl.identifier, decl.Location);
                                if (vi == null)
                                        continue;
 
@@ -4354,7 +4352,7 @@
                Location l = lexer.Location;
                LocalInfo vi;
 
-               vi = foreach_block.AddVariable ((Expression) $3, (string) $4, 
current_local_parameters, l);
+               vi = foreach_block.AddVariable ((Expression) $3, (string) $4, 
l);
                if (vi != null) {
                        vi.ReadOnly = true;
 
@@ -4656,7 +4654,7 @@
                        Pair p = (Pair) list [i];
                        LocalInfo v;
 
-                       v = current_block.AddVariable (type, (string) 
p.First,current_local_parameters, l);
+                       v = current_block.AddVariable (type, (string) p.First, 
l);
                        if (v == null)
                                continue;
 
@@ -4741,9 +4739,7 @@
 
                        foreach (VariableDeclaration decl in var_declarators){
 
-                               LocalInfo vi    = current_block.AddVariable (
-                                       type, decl.identifier, 
-                                       current_local_parameters, 
decl.Location);
+                               LocalInfo vi = current_block.AddVariable (type, 
decl.identifier, decl.Location);
                                if (vi == null)
                                        continue;
                                vi.ReadOnly = true;
@@ -4983,7 +4979,7 @@
 
        foreach (VariableDeclaration decl in variable_declarators){
 
-               if (implicit_block.AddVariable (type, decl.identifier, 
current_local_parameters, decl.Location) != null) {
+               if (implicit_block.AddVariable (type, decl.identifier, 
decl.Location) != null) {
                        if (decl.expression_or_array_initializer != null){
                                if (inits == null)
                                        inits = new ArrayList (4);
@@ -5029,8 +5025,7 @@
                implicit_block = current_block;
 
        foreach (VariableDeclaration decl in declarators){
-               implicit_block.AddConstant (type, decl.identifier, (Expression) 
decl.expression_or_array_initializer,
-                                                 current_local_parameters, 
decl.Location);
+               implicit_block.AddConstant (type, decl.identifier, (Expression) 
decl.expression_or_array_initializer, decl.Location);
        }
        
        return implicit_block;

Modified: trunk/mcs/gmcs/decl.cs
===================================================================
--- trunk/mcs/gmcs/decl.cs      2005-04-18 11:14:20 UTC (rev 43206)
+++ trunk/mcs/gmcs/decl.cs      2005-04-18 11:35:30 UTC (rev 43207)
@@ -1763,8 +1763,9 @@
                                                    !TypeManager.IsDelegateType 
(type)) {
                                                        
Report.SymbolRelatedToPreviousError (base_method);
                                                        Report.Warning (-28, 
-                                                               "The method 
'{0}' is marked virtual, but doesn't appear to have a slot." + 
-                                                               "  It may be 
ignored during overload resolution", 
+                                                               "The method 
'{0}' is marked 'override'," + 
+                                                               " but doesn't 
appear to override any virtual or abstract method:" + 
+                                                               " it may be 
ignored during overload resolution",
                                                                
TypeManager.CSharpSignature (base_method));
                                                }
                                                goto skip;
@@ -1782,8 +1783,9 @@
                                                if (new_base_method == 
base_method) {
                                                        
Report.SymbolRelatedToPreviousError (base_method);
                                                        Report.Warning (-28, 
-                                                               "The method 
'{0}' is marked virtual, but doesn't appear to have a slot." + 
-                                                               "  The method 
may be ignored during overload resolution", 
+                                                               "The method 
'{0}' is marked 'override'," +
+                                                               " but doesn't 
appear to overrided any virtual or abstract method:" + 
+                                                               " it may be 
ignored during overload resolution",
                                                                
TypeManager.CSharpSignature (base_method));
                                                }
                                                base_method = new_base_method;

Modified: trunk/mcs/gmcs/ecore.cs
===================================================================
--- trunk/mcs/gmcs/ecore.cs     2005-04-18 11:14:20 UTC (rev 43206)
+++ trunk/mcs/gmcs/ecore.cs     2005-04-18 11:35:30 UTC (rev 43207)
@@ -2226,6 +2226,15 @@
                                                      "'{0}' has a different 
meaning in a child block", Name);
                                        return null;
                                }
+
+                               if (!(e is LocalVariableReference) && 
current_block.IsVariableNameUsedInBlock (Name)) {
+                                       // Catch some false positives, e.g., 
when a local variable resolves to a constant.
+                                       LocalInfo vi = 
current_block.GetLocalInfo (Name);
+                                       if (vi == null) {
+                                               Report.Error (136, Location, 
"'{0}' has a different meaning later in the block", Name);
+                                               return null;
+                                       }
+                               }
                        }
 
                        if (e.Type != null && e.Type.IsPointer && !ec.InUnsafe) 
{
@@ -3340,7 +3349,7 @@
        ///   This is not an LValue because we need to re-write the expression, 
we
        ///   can not take data from the stack and store it.  
        /// </summary>
-       public class PropertyExpr : ExpressionStatement, IAssignMethod, 
IMemberExpr {
+       public class PropertyExpr : Expression, IAssignMethod, IMemberExpr {
                public readonly PropertyInfo PropertyInfo;
 
                //
@@ -3729,12 +3738,6 @@
                        if (temp != null)
                                temp.Emit (ec);
                }
-
-               override public void EmitStatement (EmitContext ec)
-               {
-                       Emit (ec);
-                       ec.ig.Emit (OpCodes.Pop);
-               }
        }
 
        /// <summary>

Modified: trunk/mcs/gmcs/expression.cs
===================================================================
--- trunk/mcs/gmcs/expression.cs        2005-04-18 11:14:20 UTC (rev 43206)
+++ trunk/mcs/gmcs/expression.cs        2005-04-18 11:35:30 UTC (rev 43207)
@@ -7493,7 +7493,7 @@
                                                
                                                Expression enum_member = 
MemberLookup (
                                                        ec, decl_type, 
"value__", MemberTypes.Field,
-                                                       AllBindingFlags, loc); 
+                                                       AllBindingFlags | 
BindingFlags.NonPublic, loc); 
 
                                                Enum en = 
TypeManager.LookupEnum (decl_type);
 

Modified: trunk/mcs/gmcs/statement.cs
===================================================================
--- trunk/mcs/gmcs/statement.cs 2005-04-18 11:14:20 UTC (rev 43206)
+++ trunk/mcs/gmcs/statement.cs 2005-04-18 11:35:30 UTC (rev 43207)
@@ -1170,6 +1170,8 @@
                public readonly Location  StartLocation;
                public Location           EndLocation = Location.Null;
 
+               public readonly ToplevelBlock Toplevel;
+
                [Flags]
                public enum Flags {
                        Implicit  = 1,
@@ -1248,11 +1250,6 @@
                //
                // Keeps track of constants
                Hashtable constants;
-
-               //
-               // The parameters for the block, this is only needed on the 
toplevel block really
-               // TODO: move `parameters' into ToplevelBlock
-               Parameters parameters;
                
                //
                // If this is a switch section, the enclosing switch block.
@@ -1271,42 +1268,33 @@
                        : this (parent, flags, Location.Null, Location.Null)
                { }
 
-               public Block (Block parent, Flags flags, Parameters parameters)
-                       : this (parent, flags, parameters, Location.Null, 
Location.Null)
-               { }
-
                public Block (Block parent, Location start, Location end)
                        : this (parent, (Flags) 0, start, end)
                { }
 
-               public Block (Block parent, Parameters parameters, Location 
start, Location end)
-                       : this (parent, (Flags) 0, parameters, start, end)
-               { }
-
                public Block (Block parent, Flags flags, Location start, 
Location end)
-                       : this (parent, flags, 
Parameters.EmptyReadOnlyParameters, start, end)
-               { }
-
-               public Block (Block parent, Flags flags, Parameters parameters,
-                             Location start, Location end)
                {
                        if (parent != null)
                                parent.AddChild (this);
                        
                        this.Parent = parent;
                        this.flags = flags;
-                       this.parameters = parameters;
                        this.StartLocation = start;
                        this.EndLocation = end;
                        this.loc = start;
                        this_id = id++;
                        statements = new ArrayList ();
 
+                       if ((flags & Flags.IsToplevel) != 0)
+                               Toplevel = (ToplevelBlock) this;
+                       else
+                               Toplevel = parent.Toplevel;
+
                        if (parent != null && Implicit) {
-                               if (parent.child_variable_names == null)
-                                       parent.child_variable_names = new 
Hashtable();
+                               if (parent.known_variables == null)
+                                       parent.known_variables = new Hashtable 
();
                                // share with parent
-                               child_variable_names = 
parent.child_variable_names;
+                               known_variables = parent.known_variables;
                        }
                                
                }
@@ -1453,30 +1441,47 @@
                        }
                }
 
-               Hashtable child_variable_names;
+               Hashtable known_variables;
 
                // <summary>
-               //   Marks a variable with name @name as being used in a child 
block.
+               //   Marks a variable with name @name as being used in this or 
a child block.
                //   If a variable name has been used in a child block, it's 
illegal to
                //   declare a variable with the same name in the current block.
                // </summary>
-               public void AddChildVariableName (string name)
+               void AddKnownVariable (string name, LocalInfo info)
                {
-                       if (child_variable_names == null)
-                               child_variable_names = new Hashtable ();
+                       if (known_variables == null)
+                               known_variables = new Hashtable ();
 
-                       child_variable_names [name] = null;
+                       known_variables [name] = info;
                }
 
+               public LocalInfo GetKnownVariableInfo (string name)
+               {
+                       if (known_variables == null || 
!known_variables.Contains (name))
+                               return null;
+                       return (LocalInfo) known_variables [name];
+               }
+
                // <summary>
                //   Checks whether a variable name has already been used in a 
child block.
                // </summary>
                public bool IsVariableNameUsedInChildBlock (string name)
                {
-                       if (child_variable_names == null)
-                               return false;
+                       LocalInfo vi = GetKnownVariableInfo (name);
+                       // Cheeky little test that knows that 'known_variables' 
is shared between
+                       // an implicit block and its enclosing real block.
+                       return vi != null && known_variables != 
vi.Block.known_variables;
+               }
 
-                       return child_variable_names.Contains (name);
+               // <summary>
+               //   Checks whether a variable name has already been used in 
this block, possibly by
+               //   an implicit block.
+               // </summary>
+               public bool IsVariableNameUsedInBlock (string name)
+               {
+                       LocalInfo vi = GetKnownVariableInfo (name);
+                       return vi != null && known_variables == 
vi.Block.known_variables;
                }
 
                // <summary>
@@ -1503,7 +1508,7 @@
                        return this_variable;
                }
 
-               public LocalInfo AddVariable (Expression type, string name, 
Parameters pars, Location l)
+               public LocalInfo AddVariable (Expression type, string name, 
Location l)
                {
                        if (variables == null)
                                variables = new Hashtable ();
@@ -1538,27 +1543,23 @@
                                return null;
                        }
 
-                       if (pars != null) {
-                               int idx;
-                               Parameter p = pars.GetParameterByName (name, 
out idx);
-                               if (p != null) {
-                                       Report.Error (136, l, "A local variable 
named `" + name + "' " +
-                                                     "cannot be declared in 
this scope since it would " +
-                                                     "give a different meaning 
to `" + name + "', which " +
-                                                     "is already used in a 
`parent or current' scope to " +
-                                                     "denote something else");
-                                       return null;
-                               }
+                       int idx;
+                       Parameter p = Toplevel.Parameters.GetParameterByName 
(name, out idx);
+                       if (p != null) {
+                               Report.Error (136, l, "A local variable named 
`" + name + "' " +
+                                             "cannot be declared in this scope 
since it would " +
+                                             "give a different meaning to `" + 
name + "', which " +
+                                             "is already used in a `parent or 
current' scope to " +
+                                             "denote something else");
+                               return null;
                        }
 
                        vi = new LocalInfo (type, name, this, l);
 
                        variables.Add (name, vi);
 
-                       // Mark 'name' as "used by a child block" in every 
surrounding block
-                       if (cur != null)
-                               for (Block par = cur.Parent; par != null; par = 
par.Parent)
-                                       par.AddChildVariableName (name);
+                       for (Block b = cur; b != null; b = b.Parent)
+                               b.AddKnownVariable (name, vi);
 
                        if ((flags & Flags.VariablesInitialized) != 0)
                                throw new Exception ();
@@ -1567,9 +1568,9 @@
                        return vi;
                }
 
-               public bool AddConstant (Expression type, string name, 
Expression value, Parameters pars, Location l)
+               public bool AddConstant (Expression type, string name, 
Expression value, Location l)
                {
-                       if (AddVariable (type, name, pars, l) == null)
+                       if (AddVariable (type, name, l) == null)
                                return false;
                        
                        if (constants == null)
@@ -1637,24 +1638,17 @@
                //
                public ParameterReference GetParameterReference (string name, 
Location loc)
                {
-                               Block b = this;
+                       Parameter par;
+                       int idx;
 
-                       do {
-                               Parameters pars = b.parameters;
-                               
-                               if (pars != null){
-                                       Parameter par;
-                                       int idx;
-                                       
-                                       par = pars.GetParameterByName (name, 
out idx);
-                                       if (par != null){
-                                               return new ParameterReference 
(pars, this, idx, name, loc);
-                                       }
-                               }
-                                       b = b.Parent;
-                       } while (b != null);
-                       return null;
+                       for (Block b = this; b != null; b = b.Toplevel.Parent) {
+                               Parameters pars = b.Toplevel.Parameters;
+                               par = pars.GetParameterByName (name, out idx);
+                               if (par != null)
+                                       return new ParameterReference (pars, 
this, idx, name, loc);
                        }
+                       return null;
+               }
 
                //
                // Whether the parameter named `name' is local to this block, 
@@ -1662,41 +1656,22 @@
                //
                public bool IsLocalParameter (string name)
                {
-                               Block b = this;
-                       int toplevel_count = 0;
-
-                       do {
-                               if (this is ToplevelBlock)
-                                       toplevel_count++;
-
-                               Parameters pars = b.parameters;
-                               if (pars != null){
-                                       if (pars.GetParameterByName (name) != 
null)
-                                               return true;
-                                       return false;
-                               }
-                               if (toplevel_count > 0)
-                                       return false;
-                                       b = b.Parent;
-                       } while (b != null);
-                       return false;
-                       }
+                       return Toplevel.Parameters.GetParameterByName (name) != 
null;
+               }
                
                //
                // Whether the `name' is a parameter reference
                //
                public bool IsParameterReference (string name)
                {
-                       Block b = this;
+                       Parameter par;
+                       int idx;
 
-                       do {
-                               Parameters pars = b.parameters;
-                               
-                               if (pars != null)
-                                       if (pars.GetParameterByName (name) != 
null)
-                                               return true;
-                               b = b.Parent;
-                       } while (b != null);
+                       for (Block b = this; b != null; b = b.Toplevel.Parent) {
+                               par = b.Toplevel.Parameters.GetParameterByName 
(name, out idx);
+                               if (par != null)
+                                       return true;
+                       }
                        return false;
                }
 
@@ -2104,20 +2079,7 @@
                        ec.CurrentBlock = prev_block;
                }
 
-               public ToplevelBlock Toplevel {
-                       get {
-                               Block b = this;
-                               while (b.Parent != null){
-                                       if ((b.flags & Flags.IsToplevel) != 0)
-                                               break;
-                                       b = b.Parent;
-                               }
-
-                               return (ToplevelBlock) b;
-                       }
-       }
-
-       //
+               //
                // Returns true if we ar ea child of `b'.
                //
                public bool IsChildOf (Block b)
@@ -2152,7 +2114,11 @@
                Hashtable capture_contexts;
 
                static int did = 0;
-               
+
+               //
+               // The parameters for the block.
+               //
+               public readonly Parameters Parameters;
                        
                public void RegisterCaptureContext (CaptureContext cc)
                {
@@ -2182,25 +2148,31 @@
                // parents
                //
                public ToplevelBlock (ToplevelBlock container, Parameters 
parameters, Location start) :
-                       base (null, Flags.IsToplevel, parameters, start, 
Location.Null)
+                       this (container, (Flags) 0, parameters, start)
                {
-                       Container = container;
                }
                
                public ToplevelBlock (Parameters parameters, Location start) :
-                       base (null, Flags.IsToplevel, parameters, start, 
Location.Null)
+                       this (null, (Flags) 0, parameters, start)
                {
                }
 
                public ToplevelBlock (Flags flags, Parameters parameters, 
Location start) :
-                       base (null, flags | Flags.IsToplevel, parameters, 
start, Location.Null)
+                       this (null, flags, parameters, start)
                {
                }
 
-               public ToplevelBlock (Location loc) : base (null, 
Flags.IsToplevel, loc, loc)
+               public ToplevelBlock (ToplevelBlock container, Flags flags, 
Parameters parameters, Location start) :
+                       base (null, flags | Flags.IsToplevel, start, 
Location.Null)
                {
+                       Parameters = parameters == null ? 
Parameters.EmptyReadOnlyParameters : parameters;
+                       Container = container;
                }
 
+               public ToplevelBlock (Location loc) : this (null, (Flags) 0, 
null, loc)
+               {
+               }
+
                public void SetHaveAnonymousMethods (Location loc, 
AnonymousMethod host)
                {
                        if (capture_context == null)

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

Reply via email to