Author: marek
Date: 2005-05-13 05:39:13 -0400 (Fri, 13 May 2005)
New Revision: 44491

Modified:
   trunk/mcs/mcs/ChangeLog
   trunk/mcs/mcs/cs-parser.jay
   trunk/mcs/mcs/expression.cs
   trunk/mcs/mcs/rootcontext.cs
   trunk/mcs/mcs/statement.cs
Log:
2005-05-13  Marek Safar  <[EMAIL PROTECTED]>
        
        * cs-parser.jay: Set readonly context based on special constructs.
        
        * expression.cs (LocalVariableReference.DoResolveBase): Improved
        readonly variable error handling.
        
        * rootcontext.cs (EmitCode): Don't verify members when error
        occurred.
        
        * statement.cs (LocalInfo): Add reaodnly context information.
        (SetReadOnlyContext, GetReadOnlyContext): New methods.

Modified: trunk/mcs/mcs/ChangeLog
===================================================================
--- trunk/mcs/mcs/ChangeLog     2005-05-13 09:31:11 UTC (rev 44490)
+++ trunk/mcs/mcs/ChangeLog     2005-05-13 09:39:13 UTC (rev 44491)
@@ -1,3 +1,16 @@
+2005-05-13  Marek Safar  <[EMAIL PROTECTED]>
+       
+       * cs-parser.jay: Set readonly context based on special constructs.
+       
+       * expression.cs (LocalVariableReference.DoResolveBase): Improved
+       readonly variable error handling.
+       
+       * rootcontext.cs (EmitCode): Don't verify members when error
+       occurred.
+       
+       * statement.cs (LocalInfo): Add reaodnly context information.
+       (SetReadOnlyContext, GetReadOnlyContext): New methods.
+
 2005-05-13  Raja R Harinath  <[EMAIL PROTECTED]>
 
        * statement.cs (Block.Resolve): Revert change below.  Modify fix

Modified: trunk/mcs/mcs/cs-parser.jay
===================================================================
--- trunk/mcs/mcs/cs-parser.jay 2005-05-13 09:31:11 UTC (rev 44490)
+++ trunk/mcs/mcs/cs-parser.jay 2005-05-13 09:39:13 UTC (rev 44491)
@@ -4047,7 +4047,7 @@
 
                vi = foreach_block.AddVariable ((Expression) $3, (string) $4, 
l);
                if (vi != null) {
-                       vi.ReadOnly = true;
+                       vi.SetReadOnlyContext 
(LocalInfo.ReadOnlyContext.Foreach);
 
                        // Get a writable reference to this read-only variable.
                        //
@@ -4351,7 +4351,7 @@
                        if (v == null)
                                continue;
 
-                       v.ReadOnly = true;
+                       v.SetReadOnlyContext (LocalInfo.ReadOnlyContext.Fixed);
                        v.Pinned = true;
                        p.First = v;
                        list [i] = p;
@@ -4435,7 +4435,7 @@
                                LocalInfo vi = current_block.AddVariable (type, 
decl.identifier, decl.Location);
                                if (vi == null)
                                        continue;
-                               vi.ReadOnly = true;
+                               vi.SetReadOnlyContext 
(LocalInfo.ReadOnlyContext.Using);
 
                                Expression expr;
                                if (decl.expression_or_array_initializer is 
Expression){

Modified: trunk/mcs/mcs/expression.cs
===================================================================
--- trunk/mcs/mcs/expression.cs 2005-05-13 09:31:11 UTC (rev 44490)
+++ trunk/mcs/mcs/expression.cs 2005-05-13 09:39:13 UTC (rev 44491)
@@ -3673,7 +3673,13 @@
                        VariableInfo variable_info = local_info.VariableInfo;
                        if (lvalue_right_side != null){
                                if (is_readonly){
-                                       Error (1604, "cannot assign to `" + 
Name + "' because it is readonly");
+                                       if (lvalue_right_side is 
LocalVariableReference || lvalue_right_side == EmptyExpression.Null)
+                                               Report.Error (1657, loc, 
"Cannot pass '{0}' with '{1}' modifier because it is a '{2}'",
+                                                       Name, lvalue_right_side 
== EmptyExpression.Null ? "out" : "ref",
+                                                       
local_info.GetReadOnlyContext ());
+                                       else
+                                               Report.Error (1656, loc, 
"Cannot assign to '{0}' because it is a '{1}'",
+                                                       Name, 
local_info.GetReadOnlyContext ());
                                        return null;
                                }
                                

Modified: trunk/mcs/mcs/rootcontext.cs
===================================================================
--- trunk/mcs/mcs/rootcontext.cs        2005-05-13 09:31:11 UTC (rev 44490)
+++ trunk/mcs/mcs/rootcontext.cs        2005-05-13 09:39:13 UTC (rev 44491)
@@ -615,6 +615,9 @@
                                foreach (TypeContainer tc in 
type_container_resolve_order)
                                        tc.EmitType ();
 
+                               if (Report.Errors > 0)
+                                       return;
+
                                foreach (TypeContainer tc in 
type_container_resolve_order)
                                        tc.VerifyMembers ();
                        }

Modified: trunk/mcs/mcs/statement.cs
===================================================================
--- trunk/mcs/mcs/statement.cs  2005-05-13 09:31:11 UTC (rev 44490)
+++ trunk/mcs/mcs/statement.cs  2005-05-13 09:39:13 UTC (rev 44491)
@@ -1012,7 +1012,14 @@
                        AddressTaken = 32
                }
 
+               public enum ReadOnlyContext: byte {
+                       Using,
+                       Foreach,
+                       Fixed
+               }
+
                Flags flags;
+               ReadOnlyContext ro_context;
                
                public LocalInfo (Expression type, string name, Block block, 
Location l)
                {
@@ -1126,9 +1133,28 @@
                        get {
                                return (flags & Flags.ReadOnly) != 0;
                        }
-                       set {
-                               flags = value ? (flags | Flags.ReadOnly) : 
(unchecked (flags & ~Flags.ReadOnly));
+               }
+
+               public void SetReadOnlyContext (ReadOnlyContext context)
+               {
+                       flags |= Flags.ReadOnly;
+                       ro_context = context;
+               }
+
+               public string GetReadOnlyContext ()
+               {
+                       if (!ReadOnly)
+                               throw new InternalErrorException ("Variable is 
not readonly");
+
+                       switch (ro_context) {
+                               case ReadOnlyContext.Fixed:
+                                       return "fixed variable";
+                               case ReadOnlyContext.Foreach:
+                                       return "foreach iteration variable";
+                               case ReadOnlyContext.Using:
+                                       return "using variable";
                        }
+                       throw new NotImplementedException ();
                }
 
                //
@@ -3418,7 +3444,7 @@
                                Expression e = (Expression) p.Second;
 
                                vi.VariableInfo.SetAssigned (ec);
-                               vi.ReadOnly = true;
+                               vi.SetReadOnlyContext 
(LocalInfo.ReadOnlyContext.Fixed);
 
                                //
                                // The rules for the possible declarators are 
pretty wise,

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

Reply via email to