Преглед изворни кода

*** empty log message ***

svn path=/trunk/mcs/; revision=1098
Miguel de Icaza пре 24 година
родитељ
комит
f554a0c2e0
9 измењених фајлова са 115 додато и 85 уклоњено
  1. 27 0
      mcs/errors/makefile
  2. 13 0
      mcs/mcs/ChangeLog
  3. 6 5
      mcs/mcs/class.cs
  4. 25 1
      mcs/mcs/codegen.cs
  5. 1 33
      mcs/mcs/cs-parser.jay
  6. 8 1
      mcs/mcs/driver.cs
  7. 7 1
      mcs/mcs/report.cs
  8. 25 41
      mcs/mcs/statement.cs
  9. 3 3
      mcs/mcs/typemanager.cs

+ 27 - 0
mcs/errors/makefile

@@ -0,0 +1,27 @@
+MCS=../mcs/compiler.exe
+
+all:
+	failed=false; \
+	for i in cs*.cs; do \
+		error=`echo $$i | sed -e 's/cs0*//' -e 's/.cs//'`; \
+		echo $(MCS) --probe $$error 1 $$i; \
+		$(MCS) --probe $$error 1 $$i > /dev/null; \
+		code=$$?; \
+		if test $$code != 123; then \
+			echo Code is: $$code; \
+			if [ x$$code = x124 ]; then \
+				echo "Compiler failed to flag $$i"; \
+			else \
+				echo "Compiler failed to compile $$i"; \
+			fi; \
+			flist="$$flist $$i"; \
+			failed=true; \
+		else \
+			echo test $$i ok; \
+		fi; \
+	done; \
+	if $$failed; then \
+		echo "The following tests failed: $$flist"; \
+	else \
+		echo All tests passed; \
+	fi

+ 13 - 0
mcs/mcs/ChangeLog

@@ -1,3 +1,16 @@
+2001-10-05  Miguel de Icaza  <[email protected]>
+
+	* typemanager.cs: Make the LookupTypeContainer function static,
+	and not per-instance.  
+
+	* class.cs: Make static FindMembers (the one that takes a Type
+	argument). 
+
+	* codegen.cs: Add EmitForeach here.
+
+	* cs-parser.jay: Make foreach a toplevel object instead of the
+	inline expansion, as we need to perform semantic analysis on it. 
+
 2001-10-05  Ravi Pratap  <[email protected]>
 
 	* expression.cs (Expression::ImplicitUserConversion): Rename to

+ 6 - 5
mcs/mcs/class.cs

@@ -859,10 +859,10 @@ namespace CIR {
 			return null;
 		}
 
-		public MemberInfo [] FindMembers (Type t, MemberTypes mt, BindingFlags bf,
+		public static MemberInfo [] FindMembers (Type t, MemberTypes mt, BindingFlags bf,
 						  MemberFilter filter, object criteria)
 		{
-			TypeContainer tc = RootContext.TypeManager.LookupTypeContainer (t);
+			TypeContainer tc = TypeManager.LookupTypeContainer (t);
 
 			if (tc != null)
 				return tc.FindMembers (mt, bf, filter, criteria);
@@ -1329,9 +1329,10 @@ namespace CIR {
 				MethodSignature ms = new MethodSignature (Name, ret_type, parameters);
 				MemberInfo [] mi;
 				
-				mi = parent.FindMembers (ptype, MemberTypes.Method,
-							 BindingFlags.Public, method_signature_filter,
-							 ms);
+				mi = TypeContainer.FindMembers (
+					ptype, MemberTypes.Method,
+					BindingFlags.Public, method_signature_filter,
+					ms);
 
 				if (mi != null && mi.Length > 0){
 					CheckMethod (parent, mi);

+ 25 - 1
mcs/mcs/codegen.cs

@@ -76,7 +76,8 @@ namespace CIR {
 	public struct EmitContext {
 		public TypeContainer parent;
 		public ILGenerator   ig;
-
+		Block current_block;
+		
 		// FIXME: FIXME: FIXME!
 		// This structure has to be kept small.  We need to figure
 		// out ways of moving the CheckState somewhere else
@@ -91,6 +92,7 @@ namespace CIR {
 			this.parent = parent;
 			this.ig = ig;
 			CheckState = false;
+			current_block = null;
 		}
 
 		public bool ConvertTo (Type target, Type source, bool verbose)
@@ -210,6 +212,23 @@ namespace CIR {
 			ig.MarkLabel (exit);
 		}
 
+		bool ProbeCollectionType (Type t)
+		{
+			return true;
+		}
+		
+		void EmitForeach (Foreach f)
+		{
+			Expression e = f.Expr;
+
+			e = e.Resolve (parent);
+			if (e == null)
+				return;
+
+			if (!ProbeCollectionType (e.Type))
+				return;
+		}
+		
 		void EmitReturn (Return s)
 		{
 			Expression ret_expr = s.Expr;
@@ -288,6 +307,8 @@ namespace CIR {
 				return EmitBlock ((Block) s);
 			else if (s is StatementExpression)
 				EmitStatementExpression ((StatementExpression) s);
+			else if (s is Foreach)
+				EmitForeach ((Foreach) s);
 			else {
 				Console.WriteLine ("Unhandled Statement type: " +
 						   s.GetType ().ToString ());
@@ -299,10 +320,13 @@ namespace CIR {
 		bool EmitBlock (Block block)
 		{
 			bool is_ret = false;
+			Block last_block = current_block;
 			
+			current_block = block;
 			foreach (Statement s in block.Statements){
 				is_ret = EmitStatement (s);
 			}
+			current_block = last_block;
 
 			return is_ret;
 		}

+ 1 - 33
mcs/mcs/cs-parser.jay

@@ -2643,39 +2643,7 @@ foreach_statement
 	: FOREACH OPEN_PARENS type IDENTIFIER IN expression CLOSE_PARENS 
 	  embedded_statement
 	  {
-		string temp_id = current_block.MakeInternalID ();
-		ExpressionStatement assign_e;
-		Expression ma;
-		Statement getcurrent;
-		Block foreach_block, child_block;
-		Location l = lexer.Location;
-
-		foreach_block = new Block (current_block, true);
-
-		foreach_block.AddVariable ("System.IEnumerator", temp_id, l);
-		foreach_block.AddVariable ((string) $3, (string) $4, l);
-		assign_e = new Assign (new LocalVariableReference (foreach_block, temp_id), 
-				       new Invocation (
-						new MemberAccess ((Expression) $6, "GetEnumerator"), 
-						null, lexer.Location), lexer.Location);
-		current_block.AddStatement (new StatementExpression (assign_e));
-		ma = new MemberAccess (new LocalVariableReference (foreach_block, temp_id), "MoveNext");
-		child_block = new Block (current_block);
-
-		getcurrent = new StatementExpression (
-			new Assign (
-				new LocalVariableReference (foreach_block, (string) $4),
-				new Cast (
-					(string) $3, 
-					new MemberAccess (
-				new LocalVariableReference (foreach_block, temp_id), "Current"), lexer.Location), 
-				lexer.Location));
-
-		child_block.AddStatement (getcurrent);
-		child_block.AddStatement ((Statement) $8);
-	 	foreach_block.AddStatement (new While (ma, (Statement) child_block));
-
-		$$ = foreach_block;
+		$$ = new Foreach ((string) $3, (string) $4, (Expression) $6, (Statement) $8);
 	  }
 	;
 

+ 8 - 1
mcs/mcs/driver.cs

@@ -222,7 +222,7 @@ namespace CIR
 						
 						if (arg == "--probe"){
 							int code, line;
-							
+
 							code = Int32.Parse (args [++i], 0);
 							line = Int32.Parse (args [++i], 0);
 							Report.SetProbe (code, line);
@@ -297,6 +297,10 @@ namespace CIR
 					Usage ();
 					error_count++;
 					return;
+				} catch (System.FormatException) {
+					Usage ();
+					error_count++;
+					return;
 				}
 				
 				if (!arg.EndsWith (".cs")){
@@ -445,6 +449,9 @@ namespace CIR
 			if (Report.Errors > 0){
 				error ("Compilation failed");
 				return;
+			} else if (Report.ProbeCode != 0){
+				error ("Failed to report code " + Report.ProbeCode);
+				Environment.Exit (124);
 			}
 		}
 

+ 7 - 1
mcs/mcs/report.cs

@@ -90,7 +90,13 @@ namespace CIR {
 			probe_error = code;
 			probe_line = line;
 		}
-	
+
+		static public int ProbeCode {
+			get {
+				return probe_error;
+			}
+		}
+		
 		static public int Errors {
 			get {
 				return errors;

+ 25 - 41
mcs/mcs/statement.cs

@@ -107,46 +107,21 @@ namespace CIR {
 	}
 
 	public class For : Statement {
-		Statement initStatement;
-		Expression test;
-		Statement increment;
-		Statement statement;
+		public readonly Statement InitStatement;
+		public readonly Expression Test;
+		public readonly Statement Increment;
+		public readonly Statement Statement;
 		
 		public For (Statement initStatement,
 			    Expression test,
 			    Statement increment,
 			    Statement statement)
 		{
-			this.initStatement = initStatement;
-			this.test = test;
-			this.increment = increment;
-			this.statement = statement;
-		}
-
-		public Statement InitStatement {
-			get {
-				return initStatement;
-			}
-		}
-
-		public Expression Test {
-			get {
-				return test;
-			}
-		}
-		
-		public Statement Increment {
-			get {
-				return increment;
-			}
-		}
-
-		public Statement Statement {
-			get {
-				return statement;
-			}
+			InitStatement = initStatement;
+			Test = test;
+			Increment = increment;
+			Statement = statement;
 		}
-
 	}
 	
 	public class StatementExpression : Statement {
@@ -165,17 +140,11 @@ namespace CIR {
 	}
 
 	public class Return : Statement {
-		Expression expr;
+		public readonly Expression Expr;
 		
 		public Return (Expression expr)
 		{
-			this.expr = expr;
-		}
-
-		public Expression Expr {
-			get {
-				return expr;
-			}
+			Expr = expr;
 		}
 	}
 
@@ -718,5 +687,20 @@ namespace CIR {
 			}
 		}
 	}
+
+	public class Foreach : Statement {
+		public readonly string Type;
+		public readonly string Identifier;
+		public readonly Expression Expr;
+		public readonly Statement Statement;
+
+		public Foreach (string type, string identifier, Expression expr, Statement stmt)
+		{
+			Type = type;
+			Identifier = identifier;
+			Expr = expr;
+			Statement = stmt;
+		}
+	}
 }
 

+ 3 - 3
mcs/mcs/typemanager.cs

@@ -74,7 +74,7 @@ public class TypeManager {
 	// <remarks>
 	//   Keeps a mapping between TypeBuilders and their TypeContainers
 	// </remarks>
-	Hashtable builder_to_container;
+	static Hashtable builder_to_container;
 
 	// <remarks>
 	//   Maps MethodBase.RuntimeTypeHandle to a Type array that contains
@@ -90,13 +90,13 @@ public class TypeManager {
 		user_types = new ArrayList ();
 		types = new Hashtable ();
 		typecontainers = new Hashtable ();
-		builder_to_container = new Hashtable ();
 		builder_to_interface = new Hashtable ();
 	}
 
 	static TypeManager ()
 	{
 		method_arguments = new Hashtable ();
+		builder_to_container = new Hashtable ();
 	}
 	
 	public void AddUserType (string name, TypeBuilder t)
@@ -122,7 +122,7 @@ public class TypeManager {
 	//   Returns the TypeContainer whose Type is `t' or null if there is no
 	//   TypeContainer for `t' (ie, the Type comes from a library)
 	// </summary>
-	public TypeContainer LookupTypeContainer (Type t)
+	public static TypeContainer LookupTypeContainer (Type t)
 	{
 		return (TypeContainer) builder_to_container [t];
 	}