2002-09-25 Miguel de Icaza <miguel@ximian.com>
authorMiguel de Icaza <miguel@gnome.org>
Wed, 25 Sep 2002 22:34:49 +0000 (22:34 -0000)
committerMiguel de Icaza <miguel@gnome.org>
Wed, 25 Sep 2002 22:34:49 +0000 (22:34 -0000)
* cs-parser.jay: Improve error reporting when we get a different
kind of expression in local_variable_type and
local_variable_pointer_type.

Propagate this to avoid missleading errors being reported.

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

mcs/mcs/ChangeLog
mcs/mcs/cs-parser.jay

index fcd2520c4eacaea2a4e61c65f8b7a554554a5325..461873004af00c47a7b759da624f3122a41498f8 100755 (executable)
@@ -1,5 +1,11 @@
 2002-09-25  Miguel de Icaza  <miguel@ximian.com>
 
+       * cs-parser.jay: Improve error reporting when we get a different
+       kind of expression in local_variable_type and
+       local_variable_pointer_type. 
+
+       Propagate this to avoid missleading errors being reported.
+
        * ecore.cs (ImplicitReferenceConversion): treat
        TypeManager.value_type as a target just like object_type.   As
        code like this:
index 32af7841207e349a138045718a39bd349e40ff0c..e319838a45f97bad53cb72d8e3608c2d748180e4 100755 (executable)
@@ -2026,16 +2026,15 @@ element_access
                  
                Expression expr = (Expression) $1;  
                if (!(expr is SimpleName || expr is MemberAccess)) {
-                       Location l = lexer.Location;
-                       Report.Error (-1, l, "Invalid Type definition");
-                       $$ = "System.Object";
+                       Error_ExpectingTypeName (lexer.Location, expr);
+                       $$ = TypeManager.system_object_expr;
+               } else {
+                       //
+                       // So we extract the string corresponding to the SimpleName
+                       // or MemberAccess
+                       // 
+                       $$ = new SimpleName (GetQualifiedIdentifier (expr) + (string) $2, lexer.Location);
                }
-               
-               //
-               // So we extract the string corresponding to the SimpleName
-               // or MemberAccess
-               // 
-               $$ = new SimpleName (GetQualifiedIdentifier (expr) + (string) $2, lexer.Location);
          }
        ;
 
@@ -2675,7 +2674,7 @@ statement_list
 statement
        : declaration_statement
          {
-               if ((Block) $1 != current_block){
+               if ($1 != null && (Block) $1 != current_block){
                        current_block.AddStatement ((Statement) $1);
                        current_block = (Block) $1;
                }
@@ -2730,16 +2729,20 @@ labeled_statement
 declaration_statement
        : local_variable_declaration SEMICOLON
          {
-               DictionaryEntry de = (DictionaryEntry) $1;
+               if ($1 != null){
+                       DictionaryEntry de = (DictionaryEntry) $1;
 
-               $$ = declare_local_variables ((Expression) de.Key, (ArrayList) de.Value, lexer.Location);
+                       $$ = declare_local_variables ((Expression) de.Key, (ArrayList) de.Value, lexer.Location);
+               }
          }
 
        | local_constant_declaration SEMICOLON
          {
-               DictionaryEntry de = (DictionaryEntry) $1;
+               if ($1 != null){
+                       DictionaryEntry de = (DictionaryEntry) $1;
 
-               $$ = declare_local_constant ((Expression) de.Key, (VariableDeclaration) de.Value);
+                       $$ = declare_local_constant ((Expression) de.Key, (VariableDeclaration) de.Value);
+               }
          }
        ;
 
@@ -2770,19 +2773,18 @@ local_variable_type
                  
                Expression expr = (Expression) $1;  
                if (!(expr is SimpleName || expr is MemberAccess)) {
-                       Location l = lexer.Location;
-                       Report.Error (-1, l, "Invalid Type definition");
-                       $$ = TypeManager.system_object_expr;
+                       Error_ExpectingTypeName (lexer.Location, expr);
+                       $$ = null;
+               } else {
+                       //
+                       // So we extract the string corresponding to the SimpleName
+                       // or MemberAccess
+                       // 
+                       if ((string) $2 == "")
+                               $$ = $1;
+                       else
+                               $$ = new ComposedCast ((Expression) $1, (string) $2, lexer.Location);
                }
-               
-               //
-               // So we extract the string corresponding to the SimpleName
-               // or MemberAccess
-               // 
-               if ((string) $2 == "")
-                       $$ = $1;
-               else
-                       $$ = new ComposedCast ((Expression) $1, (string) $2, lexer.Location);
          }
        | builtin_types opt_rank_specifier
          {
@@ -2797,13 +2799,14 @@ local_variable_pointer_type
        : primary_expression STAR
          {
                Expression expr = (Expression) $1;  
+               Location l = lexer.Location;
+
                if (!(expr is SimpleName || expr is MemberAccess)) {
-                       Location l = lexer.Location;
-                       Report.Error (-1, l, "Invalid Type definition");
-                       $$ = "System.Object";
-               }
-               
-               $$ = new ComposedCast ((Expression) $1, "*", lexer.Location);
+                       Error_ExpectingTypeName (l, expr);
+
+                       $$ = null;
+               } else 
+                       $$ = new ComposedCast ((Expression) $1, "*", l);
          }
         | builtin_types STAR
          {
@@ -2822,24 +2825,33 @@ local_variable_pointer_type
 local_variable_declaration
        : local_variable_type variable_declarators
          {
-               $$ = new DictionaryEntry ($1, $2);
+               if ($1 != null)
+                       $$ = new DictionaryEntry ($1, $2);
+               else
+                       $$ = null;
          }
         | local_variable_pointer_type opt_rank_specifier variable_declarators
        {
-               Expression t;
+               if ($1 != null){
+                       Expression t;
 
-               if ((string) $2 == "")
-                       t = (Expression) $1;
-               else
-                       t = new ComposedCast ((Expression) $1, (string) $2, lexer.Location);
-               $$ = new DictionaryEntry (t, $3);
+                       if ((string) $2 == "")
+                               t = (Expression) $1;
+                       else
+                               t = new ComposedCast ((Expression) $1, (string) $2, lexer.Location);
+                       $$ = new DictionaryEntry (t, $3);
+               } else 
+                       $$ = null;
        }
        ;
 
 local_constant_declaration
        : CONST local_variable_type constant_declarator
          {
-               $$ = new DictionaryEntry ($2, $3);
+               if ($2 != null)
+                       $$ = new DictionaryEntry ($2, $3);
+               else
+                       $$ = null;
          }
        ;
 
@@ -3596,6 +3608,15 @@ public class OperatorDeclaration {
 
 }
 
+void Error_ExpectingTypeName (Location l, Expression expr)
+{
+       if (expr is Invocation){
+               Report.Error (1002, l, "; expected");
+       } else {
+               Report.Error (-1, l, "Invalid Type definition");
+       }
+}
+
 // <summary>
 //   Given the @class_name name, it creates a fully qualified name
 //   based on the containing declaration space