Parcourir la source

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

	* driver.cs: Allow negative numbers as an error code to flag.

	* cs-parser.jay: Handle 1551.

	* namespace.cs: Add 1537 checking (repeated using alias namespaces).

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

	* cs-parser.jay: Report 1518 (type declaration can only contain
	class, struct, interface, enum or delegate)

	(switch_label): Report 1523 (keywords `case' or `default' must
	preced code)

	(opt_switch_sections): Report 1522 (empty switch)

	* driver.cs: Report 1515 (response file specified multiple times)
	Report 1516 (Source file specified multiple times).

	* expression.cs (Argument.Resolve): Signal 1510

	(BaseAccess.Resolve, BaseIndexer.Resolve): Signal 1511 (base
	access not allowed in static code)

svn path=/trunk/mcs/; revision=2004
Miguel de Icaza il y a 24 ans
Parent
commit
a0d9e27a2b
5 fichiers modifiés avec 131 ajouts et 16 suppressions
  1. 26 0
      mcs/mcs/ChangeLog
  2. 40 9
      mcs/mcs/cs-parser.jay
  3. 27 1
      mcs/mcs/driver.cs
  4. 26 3
      mcs/mcs/expression.cs
  5. 12 3
      mcs/mcs/namespace.cs

+ 26 - 0
mcs/mcs/ChangeLog

@@ -1,3 +1,29 @@
+2002-01-16  Miguel de Icaza  <[email protected]>
+
+	* driver.cs: Allow negative numbers as an error code to flag.
+
+	* cs-parser.jay: Handle 1551.
+
+	* namespace.cs: Add 1537 checking (repeated using alias namespaces).
+
+2002-01-15  Miguel de Icaza  <[email protected]>
+
+	* cs-parser.jay: Report 1518 (type declaration can only contain
+	class, struct, interface, enum or delegate)
+
+	(switch_label): Report 1523 (keywords `case' or `default' must
+	preced code)
+
+	(opt_switch_sections): Report 1522 (empty switch)
+
+	* driver.cs: Report 1515 (response file specified multiple times)
+	Report 1516 (Source file specified multiple times).
+
+	* expression.cs (Argument.Resolve): Signal 1510
+
+	(BaseAccess.Resolve, BaseIndexer.Resolve): Signal 1511 (base
+	access not allowed in static code)
+
 2002-01-11  Ravi Pratap  <[email protected]>
 
 	* typemanager.cs (IsPointerType): Utility method which we are going

+ 40 - 9
mcs/mcs/cs-parser.jay

@@ -278,7 +278,7 @@ using_alias_directive
 	: USING IDENTIFIER ASSIGN 
 	  namespace_or_type_name SEMICOLON
 	  {
-		  current_namespace.UsingAlias ((string) $2, (string) $4);
+		  current_namespace.UsingAlias ((string) $2, (string) $4, lexer.Location);
 	  }
 	;
 
@@ -367,8 +367,10 @@ namespace_member_declaration
 			break;
 
 		if ((mod_flags & (Modifiers.PRIVATE|Modifiers.PROTECTED)) != 0){
-			error (1527, "Namespace elements cant be explicitly " +
-			             "declared private or protected in `" + name + "'");
+			Report.Error (
+				1527, lexer.Location, 
+				"Namespace elements cant be explicitly " +
+			        "declared private or protected in `" + name + "'");
 		}
 	  }
 	| namespace_declaration
@@ -379,7 +381,13 @@ type_declaration
 	| struct_declaration		
 	| interface_declaration		
 	| enum_declaration		
-	| delegate_declaration	       
+	| delegate_declaration
+//
+// Enable this when we have handled all errors, because this acts as a generic fallback
+//
+//	| error {
+//		Report.Error (1518, lexer.Location, "Expected class, struct, interface, enum or delegate");
+//	  }
 	;
 
 //
@@ -1535,13 +1543,24 @@ indexer_declaration
 	;
 
 indexer_declarator
-	: type THIS OPEN_BRACKET formal_parameter_list CLOSE_BRACKET
+	: type THIS OPEN_BRACKET opt_formal_parameter_list CLOSE_BRACKET
 	  {
-		$$ = new IndexerDeclaration ((string) $1, null, (Parameters) $4);
+		Parameters pars = (Parameters) $4;
+
+		if (pars.FixedParameters == null){
+			Report.Error (1551, lexer.Location, "Indexers must have at least one parameter");
+		}
+
+		$$ = new IndexerDeclaration ((string) $1, null, pars);
 	  }
-	| type qualified_identifier DOT THIS OPEN_BRACKET formal_parameter_list CLOSE_BRACKET
+	| type qualified_identifier DOT THIS OPEN_BRACKET opt_formal_parameter_list CLOSE_BRACKET
 	  {
-		$$ = new IndexerDeclaration ((string) $1, (string) $2, (Parameters) $6);
+		Parameters pars = (Parameters) $6;
+
+		if (pars.FixedParameters == null){
+			Report.Error (1551, lexer.Location, "Indexers must have at least one parameter");
+		}
+		$$ = new IndexerDeclaration ((string) $1, (string) $2, pars);
 	  }
 	;
 
@@ -2004,6 +2023,10 @@ array_creation_expression
 	  {
 		$$ = new ArrayCreation ((string) $2, (string) $3, (ArrayList) $4, lexer.Location);
 	  }
+	| NEW type error 
+	  {
+		Report.Error (1526, lexer.Location, "new expression requires () or [] after type");
+	  }
 	;
 
 opt_rank_specifier
@@ -2795,7 +2818,10 @@ switch_block
 	;
 
 opt_switch_sections
-	: /* empty */ 		{ $$ = new ArrayList (); }
+	: /* empty */ 		
+          {
+	  	Report.Error (1522, lexer.Location, "Empty switch block"); 
+	  }
 	| switch_sections
 	;
 
@@ -2850,6 +2876,11 @@ switch_labels
 switch_label
 	: CASE constant_expression COLON 	{ $$ = new SwitchLabel ((Expression) $2, lexer.Location); }
 	| DEFAULT COLON				{ $$ = new SwitchLabel (null, lexer.Location); }
+	| error {
+		Report.Error (
+			1523, lexer.Location, 
+			"The keyword case or default must precede code in switch block");
+	  }
 	;
 
 iteration_statement

+ 27 - 1
mcs/mcs/driver.cs

@@ -15,6 +15,7 @@ namespace Mono.CSharp
 	using System.Reflection.Emit;
 	using System.Collections;
 	using System.IO;
+	using System.Globalization;
 	using Mono.Languages;
 
 	enum Target {
@@ -51,6 +52,9 @@ namespace Mono.CSharp
 		static bool parse_only = false;
 		static bool timestamps = false;
 
+		static Hashtable response_file_list;
+		static Hashtable source_files = new Hashtable ();
+		
 		//
 		// An array of the defines from the command line
 		//
@@ -304,7 +308,19 @@ namespace Mono.CSharp
 				if (arg.StartsWith ("@")){
 					string [] new_args, extra_args;
 					string response_file = arg.Substring (1);
+
+					if (response_file_list == null)
+						response_file_list = new Hashtable ();
+					
+					if (response_file_list.Contains (response_file)){
+						Report.Error (
+							1515, "Response file `" + response_file +
+							"' specified multiple times");
+						Environment.Exit (1);
+					}
 					
+					response_file_list.Add (response_file, response_file);
+						    
 					extra_args = LoadArgs (response_file);
 					if (extra_args == null){
 						Report.Error (2011, "Unable to open response file: " +
@@ -361,7 +377,8 @@ namespace Mono.CSharp
 					case "--probe": {
 						int code, line;
 						
-						code = Int32.Parse (args [++i], 0);
+						code = Int32.Parse (
+							args [++i], NumberStyles.AllowLeadingSign);
 						line = Int32.Parse (args [++i], 0);
 						Report.SetProbe (code, line);
 						continue;
@@ -507,6 +524,15 @@ namespace Mono.CSharp
 						errors++;
 						continue;
 					}
+
+					if (source_files.Contains (f)){
+						Report.Error (
+							1516,
+							"Source file `" + f + "' specified multiple times");
+						Environment.Exit (1);
+					} else
+						source_files.Add (f, f);
+					
 					if (tokenize)
 						tokenize_file (f);
 					else {

+ 26 - 3
mcs/mcs/expression.cs

@@ -2544,9 +2544,20 @@ namespace Mono.CSharp {
 				return expr != null;
 
 			if (expr.eclass != ExprClass.Variable){
-				Report.Error (206, loc,
-					      "A property or indexer can not be passed as an out or ref " +
-					      "parameter");
+				//
+				// We just probe to match the CSC output
+				//
+				if (expr.eclass == ExprClass.PropertyAccess ||
+				    expr.eclass == ExprClass.IndexerAccess){
+					Report.Error (
+						206, loc,
+						"A property or indexer can not be passed as an out or ref " +
+						"parameter");
+				} else {
+					Report.Error (
+						1510, loc,
+						"An lvalue is required as an argument to out or ref");
+				}
 				return false;
 			}
 				
@@ -5247,6 +5258,12 @@ namespace Mono.CSharp {
 			Type current_type = ec.TypeContainer.TypeBuilder;
 			Type base_type = current_type.BaseType;
 			Expression e;
+
+			if (ec.IsStatic){
+				Report.Error (1511, loc,
+					      "Keyword base is not allowed in static method");
+				return null;
+			}
 			
 			member_lookup = MemberLookup (ec, base_type, member, loc);
 			if (member_lookup == null)
@@ -5294,6 +5311,12 @@ namespace Mono.CSharp {
 			Type base_type = current_type.BaseType;
 			Expression member_lookup;
 
+			if (ec.IsStatic){
+				Report.Error (1511, loc,
+					      "Keyword base is not allowed in static method");
+				return null;
+			}
+			
 			member_lookup = MemberLookup (ec, base_type, "get_Item", loc);
 			if (member_lookup == null)
 				return null;

+ 12 - 3
mcs/mcs/namespace.cs

@@ -75,7 +75,7 @@ namespace Mono.CSharp {
 				CSharpParser.error (1529, "A using clause must precede all other namespace elements");
 				return;
 			}
-			
+
 			if (using_clauses == null)
 				using_clauses = new ArrayList ();
 
@@ -88,13 +88,22 @@ namespace Mono.CSharp {
 			}
 		}
 
-		public void UsingAlias (string alias, string namespace_or_type) {
+		public void UsingAlias (string alias, string namespace_or_type, Location loc)
+		{
 			if (aliases == null)
 				aliases = new Hashtable ();
+			
+			if (aliases.Contains (alias)){
+				Report.Error (1537, loc, "The using alias `" + alias +
+					      "' appeared previously in this namespace");
+				return;
+			}
+					
 			aliases [alias] = namespace_or_type;
 		}
 
-		public string LookupAlias (string alias) {
+		public string LookupAlias (string alias)
+		{
 			string value = null;
 
 			// System.Console.WriteLine ("Lookup " + alias + " in " + name);