2008-11-05 Francisco Figueiredo Jr. <francisco@npgsql.org>
[mono.git] / mcs / mcs / cs-parser.jay
index 464143d14475663fbe3a04555a61d5f41082691b..82665c5e9d1b92c107b51f89c22c0e58908ec6ab 100644 (file)
@@ -1738,7 +1738,7 @@ get_accessor_declaration
          accessor_body
          {
                if (has_get) {
-                       Report.Error (1007, (Location) $3, "Property accessor already defined");
+                       Report.Error (1007, GetLocation ($3), "Property accessor already defined");
                        break;
                }
                Accessor accessor = new Accessor ((ToplevelBlock) $5, (int) $2, (Attributes) $1, current_local_parameters, (Location) $3);
@@ -1773,7 +1773,7 @@ set_accessor_declaration
          accessor_body
          {
                if (has_set) {
-                       Report.Error (1007, ((LocatedToken) $3).Location, "Property accessor already defined");
+                       Report.Error (1007, GetLocation ($3), "Property accessor already defined");
                        break;
                }
                Accessor accessor = new Accessor ((ToplevelBlock) $5, (int) $2, (Attributes) $1, current_local_parameters, (Location) $3);
@@ -2040,11 +2040,13 @@ conversion_operator_declarator
          }
        | IMPLICIT error 
          {
-               syntax_error ((Location) $1, "'operator' expected");
+               Error_SyntaxError (yyToken);
+               $$ = new OperatorDeclaration (Operator.OpType.Implicit, null, GetLocation ($1));
          }
        | EXPLICIT error 
          {
-               syntax_error ((Location) $1, "'operator' expected");
+               Error_SyntaxError (yyToken);
+               $$ = new OperatorDeclaration (Operator.OpType.Explicit, null, GetLocation ($1));
          }
        ;
 
@@ -2872,7 +2874,7 @@ base_type_name
        
 /*
  * replaces all the productions for isolating the various
- * simple types, but we need this to reuse it easily in local_variable_type
+ * simple types, but we need this to reuse it easily in variable_type
  */
 builtin_types
        : OBJECT        { $$ = TypeManager.system_object_expr; }
@@ -3242,16 +3244,14 @@ base_access
 post_increment_expression
        : primary_expression OP_INC
          {
-               $$ = new UnaryMutator (UnaryMutator.Mode.PostIncrement,
-                                      (Expression) $1, (Location) $2);
+               $$ = new UnaryMutator (UnaryMutator.Mode.PostIncrement, (Expression) $1);
          }
        ;
 
 post_decrement_expression
        : primary_expression OP_DEC
          {
-               $$ = new UnaryMutator (UnaryMutator.Mode.PostDecrement,
-                                      (Expression) $1, (Location) $2);
+               $$ = new UnaryMutator (UnaryMutator.Mode.PostDecrement, (Expression) $1);
          }
        ;
 
@@ -3598,7 +3598,7 @@ anonymous_method_expression
          }
          block
          {
-               $$ = end_anonymous ((ToplevelBlock) $4, (Location) $1);
+               $$ = end_anonymous ((ToplevelBlock) $4);
        }
        ;
 
@@ -3633,11 +3633,11 @@ unary_expression
        : primary_expression
        | BANG prefixed_unary_expression
          {
-               $$ = new Unary (Unary.Operator.LogicalNot, (Expression) $2, (Location) $1);
+               $$ = new Unary (Unary.Operator.LogicalNot, (Expression) $2);
          }
        | TILDE prefixed_unary_expression
          {
-               $$ = new Unary (Unary.Operator.OnesComplement, (Expression) $2, (Location) $1);
+               $$ = new Unary (Unary.Operator.OnesComplement, (Expression) $2);
          }
        | cast_expression
        ;
@@ -3661,29 +3661,27 @@ prefixed_unary_expression
        : unary_expression
        | PLUS prefixed_unary_expression
          { 
-               $$ = new Unary (Unary.Operator.UnaryPlus, (Expression) $2, (Location) $1);
+               $$ = new Unary (Unary.Operator.UnaryPlus, (Expression) $2);
          } 
        | MINUS prefixed_unary_expression 
          { 
-               $$ = new Unary (Unary.Operator.UnaryNegation, (Expression) $2, (Location) $1);
+               $$ = new Unary (Unary.Operator.UnaryNegation, (Expression) $2);
          }
        | OP_INC prefixed_unary_expression 
          {
-               $$ = new UnaryMutator (UnaryMutator.Mode.PreIncrement,
-                                      (Expression) $2, (Location) $1);
+               $$ = new UnaryMutator (UnaryMutator.Mode.PreIncrement, (Expression) $2);
          }
        | OP_DEC prefixed_unary_expression 
          {
-               $$ = new UnaryMutator (UnaryMutator.Mode.PreDecrement,
-                                      (Expression) $2, (Location) $1);
+               $$ = new UnaryMutator (UnaryMutator.Mode.PreDecrement, (Expression) $2);
          }
        | STAR prefixed_unary_expression
          {
-               $$ = new Indirection ((Expression) $2, (Location) $1);
+               $$ = new Indirection ((Expression) $2, GetLocation ($1));
          }
        | BITWISE_AND prefixed_unary_expression
          {
-               $$ = new Unary (Unary.Operator.AddressOf, (Expression) $2, (Location) $1);
+               $$ = new Unary (Unary.Operator.AddressOf, (Expression) $2);
          }
        ;
 
@@ -3980,19 +3978,19 @@ lambda_expression
          {
                LocatedToken lt = (LocatedToken) $1;
                Parameter p = new ImplicitLambdaParameter (lt.Value, lt.Location);
-               start_anonymous (true, new Parameters (p), (Location) $2);
+               start_anonymous (true, new Parameters (p), GetLocation ($1));
          }
          lambda_expression_body
          {
-               $$ = end_anonymous ((ToplevelBlock) $4, (Location) $2);
+               $$ = end_anonymous ((ToplevelBlock) $4);
          }
        | OPEN_PARENS_LAMBDA opt_lambda_parameter_list CLOSE_PARENS ARROW 
          {
-               start_anonymous (true, (Parameters) $2, (Location) $4);
+               start_anonymous (true, (Parameters) $2, GetLocation ($1));
          }
          lambda_expression_body 
          {
-               $$ = end_anonymous ((ToplevelBlock) $6, (Location) $4);
+               $$ = end_anonymous ((ToplevelBlock) $6);
          }
        ;
 
@@ -4359,7 +4357,7 @@ declaration_statement
  * > expressions to prevent reduce/reduce errors in the grammar.
  * > The expressions are converted into types during semantic analysis.
  */
-local_variable_type
+variable_type
        : primary_expression_no_array_creation opt_rank_specifier_or_nullable
          { 
                // FIXME: Do something smart here regarding the composition of the type.
@@ -4431,7 +4429,7 @@ local_variable_pointer_type
          }
        | builtin_types STAR
          {
-               $$ = new ComposedCast ((FullNamedExpression) $1, "*", lexer.Location);
+               $$ = new ComposedCast ((FullNamedExpression) $1, "*", GetLocation ($1));
          }
        | VOID STAR
          {
@@ -4443,6 +4441,23 @@ local_variable_pointer_type
          }
        ;
 
+local_variable_type
+       : variable_type
+       | local_variable_pointer_type opt_rank_specifier
+         {
+               if ($1 != null){
+                       string rank = (string)$2;
+
+                       if (rank == "")
+                               $$ = $1;
+                       else
+                               $$ = current_array_type = new ComposedCast ((FullNamedExpression) $1, rank);
+               } else {
+                       $$ = null;
+               }
+         }
+       ;
+
 local_variable_declaration
        : local_variable_type local_variable_declarators
          {
@@ -4455,23 +4470,10 @@ local_variable_declaration
                } else
                        $$ = null;
          }
-       | local_variable_pointer_type opt_rank_specifier local_variable_declarators
-         {
-               if ($1 != null){
-                       Expression t;
-
-                       if ((string) $2 == "")
-                               t = (Expression) $1;
-                       else
-                               t = new ComposedCast ((FullNamedExpression) $1, (string) $2);
-                       $$ = new DictionaryEntry (t, $3);
-               } else 
-                       $$ = null;
-         }
        ;
 
 local_constant_declaration
-       : CONST local_variable_type constant_declarators
+       : CONST variable_type constant_declarators
          {
                if ($2 != null)
                        $$ = new DictionaryEntry ($2, $3);
@@ -4502,10 +4504,9 @@ statement_expression
 
                if (s == null) {
                        expr.Error_InvalidExpressionStatement ();
-                       $$ = null;
-               } else {
-                       $$ = new StatementExpression (s);
                }
+
+               $$ = new StatementExpression (s);
          }
        | error
          {
@@ -5900,6 +5901,10 @@ end_block (Location loc)
 void
 start_anonymous (bool lambda, Parameters parameters, Location loc)
 {
+       if (RootContext.Version == LanguageVersion.ISO_1){
+               Report.FeatureIsNotAvailable (loc, "anonymous methods");
+       }
+
        oob_stack.Push (current_anonymous_method);
        oob_stack.Push (current_local_parameters);
 
@@ -5917,17 +5922,12 @@ start_anonymous (bool lambda, Parameters parameters, Location loc)
  * Completes the anonymous method processing, if lambda_expr is null, this
  * means that we have a Statement instead of an Expression embedded 
  */
-AnonymousMethodExpression end_anonymous (ToplevelBlock anon_block, Location loc)
+AnonymousMethodExpression end_anonymous (ToplevelBlock anon_block)
 {
        AnonymousMethodExpression retval;
 
-       if (RootContext.Version == LanguageVersion.ISO_1){
-               Report.FeatureIsNotAvailable (loc, "anonymous methods");
-               retval = null;
-       } else  {
-               current_anonymous_method.Block = anon_block;
-               retval = current_anonymous_method;
-       }
+       current_anonymous_method.Block = anon_block;
+       retval = current_anonymous_method;
 
        current_local_parameters = (Parameters) oob_stack.Pop ();
        current_anonymous_method = (AnonymousMethodExpression) oob_stack.Pop ();