2002-01-16 Miguel de Icaza <miguel@ximian.com>
authorMiguel de Icaza <miguel@gnome.org>
Wed, 16 Jan 2002 18:53:16 +0000 (18:53 -0000)
committerMiguel de Icaza <miguel@gnome.org>
Wed, 16 Jan 2002 18:53:16 +0000 (18:53 -0000)
* 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  <miguel@ximian.com>

* 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

mcs/mcs/ChangeLog
mcs/mcs/cs-parser.jay
mcs/mcs/driver.cs
mcs/mcs/expression.cs
mcs/mcs/namespace.cs

index ae0121aa9590d1f4967f7c5452b7c9279b561232..5a6fb69d05bf95e74ac268474c9ffbe9474e4317 100755 (executable)
@@ -1,3 +1,29 @@
+2002-01-16  Miguel de Icaza  <miguel@ximian.com>
+
+       * 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  <miguel@ximian.com>
+
+       * 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  <ravi@ximian.com>
 
        * typemanager.cs (IsPointerType): Utility method which we are going
index 615cccbc8741269442eccbe869cc02b3b149377f..d75ed49c0689f44a58b9668c5e7f75a3174117e2 100755 (executable)
@@ -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
index a9dbf9cc010b3b8f151d8f8b85beea9604d10071..431d1e3d40d63ee462202164ca07702a41bf1c2d 100755 (executable)
@@ -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 {
index dd164412570aca348389a16d4e8c2424e9a33925..21a51530a3154f8a86053640e4babf3108ba7eb2 100755 (executable)
@@ -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;
index a84347060dadd6359292f2b8cbda84235a872057..f9ccd2e9369531c93b1863c6fd934eba6df323a2 100755 (executable)
@@ -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);