Author: martin
Date: 2005-04-19 05:07:08 -0400 (Tue, 19 Apr 2005)
New Revision: 43241

Modified:
   trunk/mcs/gmcs/ChangeLog
   trunk/mcs/gmcs/cs-parser.jay
   trunk/mcs/gmcs/cs-tokenizer.cs
   trunk/mcs/gmcs/ecore.cs
   trunk/mcs/gmcs/parameter.cs
   trunk/mcs/gmcs/rootcontext.cs
   trunk/mcs/gmcs/statement.cs
Log:
**** Merged r42459 from MCS ****


Modified: trunk/mcs/gmcs/ChangeLog
===================================================================
--- trunk/mcs/gmcs/ChangeLog    2005-04-19 08:54:04 UTC (rev 43240)
+++ trunk/mcs/gmcs/ChangeLog    2005-04-19 09:07:08 UTC (rev 43241)
@@ -1,3 +1,26 @@
+2005-04-01  Raja R Harinath  <[EMAIL PROTECTED]>
+
+       * cs-tokenizer.cs (consume_identifier): Treat 'partial' as a
+       keyword in 'partial enum' too.
+       * cs-parser.jay (enum_declaration): Add CS0267 check ('partial enum'
+       is not allowed).
+       Report from Kamil Skalski <[EMAIL PROTECTED]>.
+
+       Fix #74309.
+       * rootcontext.cs (ResolveTree): The 'root.Interfaces' list can
+       have partial containers too.
+
+       * ecore.cs (SimpleName.SimpleNameResolve): Move 'invariant meaning
+       in block' checks to Block.CheckInvariantMeaningInBlock.
+       * statement.cs (Block.GetKnownVariableInfo): Make private.
+       (Block.IsVariableUsedInChildBlock): Remove.
+       (Block.IsVariableUsedInBlock): Likewise.
+       (Block.CheckInvariantMeaningInBlock): New.  Show location of
+       conflicting declaration.
+       (Block.AddVariable): Make error messages less long-winded and more
+       specific.  Show location of conflicting declaration.
+       * parameter.cs (Parameters.Location): New readonly property.
+
 2005-03-31  Raja R Harinath  <[EMAIL PROTECTED]>
 
        Clean up semantics of invoking ResolveMemberAccess.

Modified: trunk/mcs/gmcs/cs-parser.jay
===================================================================
--- trunk/mcs/gmcs/cs-parser.jay        2005-04-19 08:54:04 UTC (rev 43240)
+++ trunk/mcs/gmcs/cs-parser.jay        2005-04-19 09:07:08 UTC (rev 43241)
@@ -2380,6 +2380,7 @@
 enum_declaration
        : opt_attributes
          opt_modifiers
+         opt_partial
          ENUM IDENTIFIER 
          opt_enum_base {
                if (RootContext.Documentation != null)
@@ -2387,17 +2388,24 @@
          }
          enum_body
          opt_semicolon
-         { 
+         {
+               bool partial = (bool) $3;
+
+               if (partial) {
+                       Report.Error (267, lexer.Location, "The partial 
modifier can only appear before a 'class', 'struct', or 'interface'");
+                       break;  // assumes that the parser put us in a switch
+               }
+
                Location enum_location = lexer.Location;
 
-               MemberName name = MakeName (new MemberName ((string) $4));
-               Enum e = new Enum (current_namespace, current_class, 
(Expression) $5, (int) $2,
+               MemberName name = MakeName (new MemberName ((string) $5));
+               Enum e = new Enum (current_namespace, current_class, 
(Expression) $6, (int) $2,
                                   name, (Attributes) $1, enum_location);
                
                if (RootContext.Documentation != null)
                        e.DocComment = enumTypeComment;
 
-               foreach (VariableDeclaration ev in (ArrayList) $7) {
+               foreach (VariableDeclaration ev in (ArrayList) $8) {
                        e.AddEnumMember (ev.identifier, 
                                         (Expression) 
ev.expression_or_array_initializer,
                                         ev.Location, ev.OptAttributes,

Modified: trunk/mcs/gmcs/cs-tokenizer.cs
===================================================================
--- trunk/mcs/gmcs/cs-tokenizer.cs      2005-04-19 08:54:04 UTC (rev 43240)
+++ trunk/mcs/gmcs/cs-tokenizer.cs      2005-04-19 09:07:08 UTC (rev 43241)
@@ -1977,7 +1977,8 @@
                                int next_token = token ();
                                bool ok = (next_token == Token.CLASS) ||
                                        (next_token == Token.STRUCT) ||
-                                       (next_token == Token.INTERFACE);
+                                       (next_token == Token.INTERFACE) ||
+                                       (next_token == Token.ENUM); // 
"partial" is a keyword in 'partial enum', even though it's not valid
 
                                reader.Position = old;
                                putback_char = old_putback;

Modified: trunk/mcs/gmcs/ecore.cs
===================================================================
--- trunk/mcs/gmcs/ecore.cs     2005-04-19 08:54:04 UTC (rev 43240)
+++ trunk/mcs/gmcs/ecore.cs     2005-04-19 09:07:08 UTC (rev 43241)
@@ -2150,30 +2150,10 @@
                        if (e == null)
                                return null;
 
-                       Block current_block = ec.CurrentBlock;
-                       if (current_block != null){
-                               if 
(current_block.IsVariableNameUsedInChildBlock (Name)) {
-                                       Report.Error (135, Location,
-                                                     "'{0}' has a different 
meaning in a child block", Name);
-                                       return null;
-                               }
+                       if (ec.CurrentBlock == null || 
ec.CurrentBlock.CheckInvariantMeaningInBlock (Name, e, Location))
+                               return e;
 
-                               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) 
{
-                               UnsafeError (loc);
-                               return null;
-                       }
-
-                       return e;
+                       return null;
                }
 
                /// <remarks>

Modified: trunk/mcs/gmcs/parameter.cs
===================================================================
--- trunk/mcs/gmcs/parameter.cs 2005-04-19 08:54:04 UTC (rev 43240)
+++ trunk/mcs/gmcs/parameter.cs 2005-04-19 09:07:08 UTC (rev 43241)
@@ -386,6 +386,10 @@
                                return (FixedParameters == null) && 
(ArrayParameter == null);
                        }
                }
+
+               public Location Location {
+                       get { return loc; }
+               }
                
                public void ComputeSignature (EmitContext ec)
                {

Modified: trunk/mcs/gmcs/rootcontext.cs
===================================================================
--- trunk/mcs/gmcs/rootcontext.cs       2005-04-19 08:54:04 UTC (rev 43240)
+++ trunk/mcs/gmcs/rootcontext.cs       2005-04-19 09:07:08 UTC (rev 43241)
@@ -164,7 +164,7 @@
 
                        ArrayList ifaces = root.Interfaces;
                        if (ifaces != null){
-                               foreach (Interface i in ifaces) 
+                               foreach (TypeContainer i in ifaces) 
                                        i.DefineType ();
                        }
 

Modified: trunk/mcs/gmcs/statement.cs
===================================================================
--- trunk/mcs/gmcs/statement.cs 2005-04-19 08:54:04 UTC (rev 43240)
+++ trunk/mcs/gmcs/statement.cs 2005-04-19 09:07:08 UTC (rev 43241)
@@ -1459,32 +1459,39 @@
                        known_variables [name] = info;
                }
 
-               public LocalInfo GetKnownVariableInfo (string name)
+               LocalInfo GetKnownVariableInfo (string name)
                {
-                       if (known_variables == null || 
!known_variables.Contains (name))
+                       if (known_variables == null)
                                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)
+               public bool CheckInvariantMeaningInBlock (string name, 
Expression e, Location loc)
                {
-                       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;
-               }
+                       LocalInfo kvi = GetKnownVariableInfo (name);
+                       if (kvi == null || kvi.Block == this)
+                               return true;
 
-               // <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;
+                       if (known_variables != kvi.Block.known_variables) {
+                               Report.SymbolRelatedToPreviousError 
(kvi.Location, name);
+                               Report.Error (135, loc, "'{0}' has a different 
meaning in a child block", name);
+                               return false;
+                       }
+
+                       //
+                       // this block and kvi.Block are the same textual block.
+                       // However, different variables are extant.
+                       //
+                       // Check if the variable is in scope in both blocks.  
We use
+                       // an indirect check that depends on AddVariable doing 
its
+                       // part in maintaining the invariant-meaning-in-block 
property.
+                       //
+                       if (e is LocalVariableReference || (e is Constant && 
GetLocalInfo (name) != null))
+                               return true;
+
+                       Report.SymbolRelatedToPreviousError (kvi.Location, 
name);
+                       Report.Error (136, loc, "'{0}' has a different meaning 
later in the block", name);
+                       return false;
                }
 
                // <summary>
@@ -1516,44 +1523,33 @@
                        if (variables == null)
                                variables = new Hashtable ();
 
-                       Block cur = this;
-                       while (cur != null && cur.Implicit)
-                               cur = cur.Parent;
-
                        LocalInfo vi = GetLocalInfo (name);
                        if (vi != null) {
-                               Block var = vi.Block;
-                               while (var != null && var.Implicit)
-                                       var = var.Parent;
-                               if (var != cur)
-                                       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");
+                               Report.SymbolRelatedToPreviousError 
(vi.Location, name);
+                               if (known_variables == vi.Block.known_variables)
+                                       Report.Error (128, l,
+                                               "A local variable '{0}' is 
already declared in this scope", name);
                                else
-                                       Report.Error (128, l, "A local variable 
`" + name + "' is already " +
-                                                     "defined in this scope");
+                                       Report.Error (136, l,
+                                               "'{0}' hides the declaration of 
local variable '{0}' in a parent scope", name);
                                return null;
                        }
 
-                       if (IsVariableNameUsedInChildBlock (name)) {
-                               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 `child' 
scope to denote something " +
-                                             "else");
+                       vi = GetKnownVariableInfo (name);
+                       if (vi != null) {
+                               Report.SymbolRelatedToPreviousError 
(vi.Location, name);
+                               Report.Error (136, l,
+                                       "A child block already has a 
declaration of local variable '{0}':" +
+                                       " allowing this declaration would 
violate 'invariant meaning in a block'", 
+                                       name);
                                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");
+                               Report.SymbolRelatedToPreviousError 
(Toplevel.Parameters.Location, name);
+                               Report.Error (136, l, "'{0}' hides a method 
parameter", name);
                                return null;
                        }
 
@@ -1561,7 +1557,7 @@
 
                        variables.Add (name, vi);
 
-                       for (Block b = cur; b != null; b = b.Parent)
+                       for (Block b = this; b != null; b = b.Parent)
                                b.AddKnownVariable (name, vi);
 
                        if ((flags & Flags.VariablesInitialized) != 0)

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

Reply via email to