Browse Source

Work towards getting `fixed' to work. We are going to need a custom
hack for this to fully work.

2002-01-29 Miguel de Icaza <[email protected]>

* support.cs (Pair): Remove un-needed method. I figured why I was
getting the error in cs-parser.jay, the variable in a foreach loop
is readonly, and the compiler does not really treat this as a variable.

* cs-parser.jay (fixed_statement): Fix grammar. Use ASSIGN
instead of EQUALS in grammar.

* typemanager.cs (VerifyUnmanaged): Report correct error (208)

* expression.cs (Unary.DoResolve): Check whether the argument is
managed or not.

svn path=/trunk/mcs/; revision=2285

Miguel de Icaza 24 years ago
parent
commit
dbc5683917

+ 2 - 0
mcs/class/corlib/System.Globalization/CultureInfo.cs

@@ -1,8 +1,10 @@
+//
 // System.Globalization.CultureInfo
 //
 // Miguel de Icaza ([email protected])
 //
 // (C) Ximian, Inc. 2001 (http://www.ximian.com)
+//
 
 using System.Threading;
 

+ 4 - 4
mcs/errors/cs-12.cs

@@ -6,10 +6,10 @@ class Y {
 		return i.b;
 	}
 
-	public static implicit operator byte (Y i)
-	{
-		return i.b;
-	}
+//	public static implicit operator byte (Y i)
+//	{
+//		return i.b;
+//	}
 
 	public Y (byte b)
 	{

+ 14 - 0
mcs/mcs/ChangeLog

@@ -1,3 +1,17 @@
+2002-01-29  Miguel de Icaza  <[email protected]>
+
+	* support.cs (Pair): Remove un-needed method.  I figured why I was
+	getting the error in cs-parser.jay, the variable in a foreach loop
+	is readonly, and the compiler does not really treat this as a variable.
+
+	* cs-parser.jay (fixed_statement): Fix grammar.  Use ASSIGN
+	instead of EQUALS in grammar.  
+
+	* typemanager.cs (VerifyUnmanaged): Report correct error (208)
+
+	* expression.cs (Unary.DoResolve): Check whether the argument is
+	managed or not.
+
 2002-01-28  Miguel de Icaza  <[email protected]>
 
 	* support.cs: Api for Pair to set a value.  Despite the fact that

+ 3 - 1
mcs/mcs/TODO

@@ -1,6 +1,9 @@
 Major tasks:
 ------------
 
+	Pinned and volatile require type modifiers that can not be encoded
+	with Reflection.Emit.
+
 	Properties and 17.6.3: Finish it.
 
 	Implement base indexer access.
@@ -30,7 +33,6 @@ AddressOf
 Unsafe code:
 	Pointer arithmetic operators (++ and -- are done)
 	Test for ++ and -- for non-builtin-types
-	sizeof
 	fixed
 
 readonly variables and ref/out

+ 12 - 6
mcs/mcs/cs-parser.jay

@@ -3305,11 +3305,13 @@ fixed_statement
 	  CLOSE_PARENS 
 	  {
 		Block assign_block = new Block (current_block, true);
-
+		ArrayList list = (ArrayList) $4;
 		string type = (string) $3;
 		Location l = lexer.Location;
+		int top = list.Count;
 
-		foreach (Pair p in (ArrayList) $4){
+		for (int i = 0; i < top; i++){
+			Pair p = (Pair) list [i];
 			VariableInfo v;
 
 			v = current_block.AddVariable (type, (string) p.First,current_local_parameters, l);
@@ -3319,17 +3321,21 @@ fixed_statement
 					"defined in this scope");
 			}
 			v.ReadOnly = true;
-			// Replace the name with the VariableInfo.
-			p.SetFirst (v);
+			p.First = v;
+			list [i] = p;
 		}
 		current_block.AddStatement (assign_block);
 		current_block = assign_block;
+		oob_stack.Push (assign_block);
 		oob_stack.Push (l);
 	  }
 	  embedded_statement 
 	  {
-		Block assign_block = (Block) oob_stack.Pop ();
 		Location l = (Location) oob_stack.Pop ();
+		Block assign_block = (Block) oob_stack.Pop ();
+
+		ArrayList list = (ArrayList) $4;
+		int top = list.Count;
 
 		$$ = new Fixed ((string) $3, (ArrayList) $4, (Statement) $6, l);
 	  }
@@ -3350,7 +3356,7 @@ fixed_pointer_declarators
 	;
 
 fixed_pointer_declarator
-	: IDENTIFIER EQUALS expression
+	: IDENTIFIER ASSIGN expression
 	  {	
 		$$ = new Pair ($1, $3);
 	  }

+ 10 - 2
mcs/mcs/expression.cs

@@ -406,11 +406,19 @@ namespace Mono.CSharp {
 					return null;
 				}
 
+				if (!TypeManager.VerifyUnManaged (expr.Type, loc)){
+					return null;
+				}
+				
+				//
+				// This construct is needed because dynamic types
+				// are not known by Type.GetType, so we have to try then to use
+				// ModuleBuilder.GetType.
+				//
 				string ptr_type_name = expr.Type.FullName + "*";
 				type = Type.GetType (ptr_type_name);
-				if (type == null){
+				if (type == null)
 					type = RootContext.ModuleBuilder.GetType (ptr_type_name);
-				}
 				
 				return this;
 			}

+ 14 - 1
mcs/mcs/statement.cs

@@ -1738,12 +1738,25 @@ namespace Mono.CSharp {
 				// So we have to enforce these rules here
 				//
 				if (e is Unary && ((Unary) e).Oper == Unary.Operator.AddressOf){
+					Expression child = ((Unary) e).Expr;
+
+					if (child is ParameterReference || child is LocalVariableReference){
+						Report.Error (
+							213, loc, 
+							"No need to use fixed statement for parameters or " +
+							"local variable declarations (address is already " +
+							"fixed)");
+						continue;
+					}
+					
 					e = e.Resolve (ec);
 					if (e == null)
 						continue;
 
-					if (!TypeManager.VerifyUnManaged (e.Type))
+					if (!TypeManager.VerifyUnManaged (e.Type, loc))
 						continue;
+
+					
 				}
 				
 				e = e.Resolve (ec);

+ 0 - 5
mcs/mcs/support.cs

@@ -226,10 +226,5 @@ namespace Mono.CSharp {
 			First = f;
 			Second = s;
 		}
-
-		public void SetFirst (object n)
-		{
-			First = n;
-		}
 	}
 }

+ 13 - 3
mcs/mcs/typemanager.cs

@@ -885,11 +885,21 @@ public class TypeManager {
 	///   Utility function that can be used to probe whether a type
 	///   is managed or not.  
 	/// </summary>
-	public static bool VerifyUnManaged (Type t)
+	public static bool VerifyUnManaged (Type t, Location loc)
 	{
-		if (t.IsValueType)
+		if (t.IsValueType){
+			//
+			// FIXME: this is more complex, we actually need to
+			// make sure that the type does not contain any
+			// classes itself
+			//
 			return true;
-		Report.Error (10000, "Not a managed type");
+		}
+
+		Report.Error (
+			208, loc,
+			"Cannot take the address or size of a variable of a managed type ('" +
+			CSharpName (t) + "')");
 		return false;	
 	}