This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[treelang PATCH] Fix option decoder and a cleanup for parse.y(applied)


Pre-approved by Tim Josling.

2003-04-27  Steven Bosscher  <steven@gcc.gnu.org>

	* parse.y (make_plus_expression): New function.
	(expression:): Use make_plus_expression for PLUS, MINUS,
	ASSIGN and EQUALS.
	* tree1.c (treelang_decode_option): Don't fall through to
	options that start with a different character when an option
	was not recognized.


Index: ChangeLog
===================================================================
RCS file: /cvs/gcc/gcc/gcc/treelang/ChangeLog,v
retrieving revision 1.35
diff -c -3 -p -r1.35 ChangeLog
*** ChangeLog	30 Apr 2003 18:27:42 -0000	1.35
--- ChangeLog	30 Apr 2003 19:07:00 -0000
***************
*** 1,3 ****
--- 1,12 ----
+ 2003-04-30  Steven Bosscher  <steven@gcc.gnu.org>
+ 
+ 	* parse.y (make_plus_expression): New function.
+ 	(expression production): Use make_plus_expression for PLUS,
+ 	MINUS, ASSIGN and EQUALS.
+ 	* tree1.c (treelang_decode_option): Don't fall through to
+ 	options that start with a different characyer when an option
+ 	was not recognized.
+ 
  2003-04-30  Nathan Sidwell  <nathan@codesourcery.com>
  
  	* Make-lang.in (parse.c): Reorder bison arguments for POSIXLY_CORRECT.
Index: parse.y
===================================================================
RCS file: /cvs/gcc/gcc/gcc/treelang/parse.y,v
retrieving revision 1.6
diff -c -3 -p -r1.6 parse.y
*** parse.y	1 Mar 2003 12:03:50 -0000	1.6
--- parse.y	30 Apr 2003 19:07:01 -0000
*************** static void ensure_not_void (unsigned in
*** 83,88 ****
--- 83,91 ----
  static int check_type_match (int type_num, struct prod_token_parm_item *exp);
  static int get_common_type (struct prod_token_parm_item *type1, struct prod_token_parm_item *type2);
  static struct prod_token_parm_item *make_integer_constant (struct prod_token_parm_item* value);
+ static struct prod_token_parm_item *make_plus_expression
+   (struct prod_token_parm_item* tok, struct prod_token_parm_item* op1,
+    struct prod_token_parm_item* op2, int type_code, int prod_code);
  static void set_storage (struct prod_token_parm_item *prod);
  
  /* File global variables.  */
*************** INTEGER {
*** 569,686 ****
    $$ = $1;
  }
  |expression tl_PLUS expression {
!   struct prod_token_parm_item* tok;
!   struct prod_token_parm_item *prod;
!   struct prod_token_parm_item *op1;
!   struct prod_token_parm_item *op2;
!   tree type;
!   
!   op1 = $1;
!   op2 = $3;
!   tok = $2;
!   ensure_not_void (NUMERIC_TYPE (op1), op1->tp.pro.main_token);
!   ensure_not_void (NUMERIC_TYPE (op2), op2->tp.pro.main_token);
!   prod = make_production (PROD_PLUS_EXPRESSION, tok);
!   NUMERIC_TYPE (prod) = get_common_type (op1, op2);
!   if (!NUMERIC_TYPE (prod))
      YYERROR;
!   else 
!     {
!       type = get_type_for_numeric_type (NUMERIC_TYPE (prod));
!       if (!type)
!         abort ();
!       OP1 (prod) = $1;
!       OP2 (prod) = $3;
!       
!       prod->tp.pro.code = tree_code_get_expression
!         (EXP_PLUS, type, op1->tp.pro.code, op2->tp.pro.code, NULL);
!     }
!   $$ = prod;
  }
  |expression tl_MINUS expression %prec tl_PLUS {
!   struct prod_token_parm_item* tok;
!   struct prod_token_parm_item *prod;
!   struct prod_token_parm_item *op1;
!   struct prod_token_parm_item *op2;
!   tree type;
!   
!   op1 = $1;
!   op2 = $3;
!   ensure_not_void (NUMERIC_TYPE (op1), op1->tp.pro.main_token);
!   ensure_not_void (NUMERIC_TYPE (op2), op2->tp.pro.main_token);
!   tok = $2;
!   prod = make_production (PROD_PLUS_EXPRESSION, tok);
!   NUMERIC_TYPE (prod) = get_common_type (op1, op2);
!   if (!NUMERIC_TYPE (prod))
      YYERROR;
!   else 
!     {
!       type = get_type_for_numeric_type (NUMERIC_TYPE (prod));
!       if (!type)
!         abort ();
!       OP1 (prod) = $1;
!       OP2 (prod) = $3;
!       
!       prod->tp.pro.code = tree_code_get_expression (EXP_MINUS, 
!                                           type, op1->tp.pro.code, op2->tp.pro.code, NULL);
!     }
!   $$ = prod;
  }
  |expression EQUALS expression {
!   struct prod_token_parm_item* tok;
!   struct prod_token_parm_item *prod;
!   struct prod_token_parm_item *op1;
!   struct prod_token_parm_item *op2;
!   tree type;
!   
!   op1 = $1;
!   op2 = $3;
!   ensure_not_void (NUMERIC_TYPE (op1), op1->tp.pro.main_token);
!   ensure_not_void (NUMERIC_TYPE (op2), op2->tp.pro.main_token);
!   tok = $2;
!   prod = make_production (PROD_PLUS_EXPRESSION, tok);
!   NUMERIC_TYPE (prod) = SIGNED_INT;
!   if (!NUMERIC_TYPE (prod))
!     YYERROR;
!   else 
!     {
!       type = get_type_for_numeric_type (NUMERIC_TYPE (prod));
!       if (!type)
!         abort ();
!       OP1 (prod) = $1;
!       OP2 (prod) = $3;
!       
!       prod->tp.pro.code = tree_code_get_expression (EXP_EQUALS, 
!                                           type, op1->tp.pro.code, op2->tp.pro.code, NULL);
!     }
!   $$ = prod;
  }
  |variable_ref ASSIGN expression {
!   struct prod_token_parm_item* tok;
!   struct prod_token_parm_item *prod;
!   struct prod_token_parm_item *op1;
!   struct prod_token_parm_item *op2;
!   tree type;
!   
!   op1 = $1;
!   op2 = $3;
!   tok = $2;
!   ensure_not_void (NUMERIC_TYPE (op2), op2->tp.pro.main_token);
!   prod = make_production (PROD_ASSIGN_EXPRESSION, tok);
!   NUMERIC_TYPE (prod) = NUMERIC_TYPE (op1);
!   if (!NUMERIC_TYPE (prod))
      YYERROR;
!   else 
!     {
!       type = get_type_for_numeric_type (NUMERIC_TYPE (prod));
!       if (!type)
!         abort ();
!       OP1 (prod) = $1;
!       OP2 (prod) = $3;
!       prod->tp.pro.code = tree_code_get_expression (EXP_ASSIGN, 
!                                           type, op1->tp.pro.code, op2->tp.pro.code, NULL);
!     }
!   $$ = prod;
  }
  |function_invocation {
    $$ = $1;
--- 572,612 ----
    $$ = $1;
  }
  |expression tl_PLUS expression {
!   struct prod_token_parm_item *tok = $2;
!   struct prod_token_parm_item *op1 = $1;
!   struct prod_token_parm_item *op2 = $3;
!   int type_code = get_common_type (op1, op2);
!   if (!type_code)
      YYERROR;
!   $$ = make_plus_expression
!      (tok, op1, op2, type_code, EXP_PLUS);
  }
  |expression tl_MINUS expression %prec tl_PLUS {
!   struct prod_token_parm_item *tok = $2;
!   struct prod_token_parm_item *op1 = $1;
!   struct prod_token_parm_item *op2 = $3;
!   int type_code = get_common_type (op1, op2);
!   if (!type_code)
      YYERROR;
!   $$ = make_plus_expression
!      (tok, op1, op2, type_code, EXP_MINUS);
  }
  |expression EQUALS expression {
!   struct prod_token_parm_item *tok = $2;
!   struct prod_token_parm_item *op1 = $1;
!   struct prod_token_parm_item *op2 = $3;
!   $$ = make_plus_expression
!      (tok, op1, op2, SIGNED_INT, EXP_EQUALS);
  }
  |variable_ref ASSIGN expression {
!   struct prod_token_parm_item *tok = $2;
!   struct prod_token_parm_item *op1 = $1;
!   struct prod_token_parm_item *op2 = $3;
!   int type_code = NUMERIC_TYPE (op1);
!   if (!type_code)
      YYERROR;
!   $$ = make_plus_expression
!      (tok, op1, op2, type_code, EXP_ASSIGN);
  }
  |function_invocation {
    $$ = $1;
*************** make_integer_constant (struct prod_token
*** 973,978 ****
--- 899,937 ----
    return prod;
  }
  
+ 
+ /* Build a PROD_PLUS_EXPRESSION.  This is uses for PLUS, MINUS, ASSIGN
+    and EQUALS expressions.  */
+ 
+ static struct prod_token_parm_item *
+ make_plus_expression (struct prod_token_parm_item* tok,
+ 		      struct prod_token_parm_item* op1,
+ 		      struct prod_token_parm_item* op2,
+ 		      int type_code, int prod_code)
+ {
+   struct prod_token_parm_item *prod;
+   tree type;
+ 
+   ensure_not_void (NUMERIC_TYPE (op1), op1->tp.pro.main_token);
+   ensure_not_void (NUMERIC_TYPE (op2), op2->tp.pro.main_token);
+ 
+   prod = make_production (PROD_PLUS_EXPRESSION, tok);
+ 
+   NUMERIC_TYPE (prod) = type_code;
+   type = get_type_for_numeric_type (NUMERIC_TYPE (prod));
+   if (!type)
+     abort ();
+   OP1 (prod) = op1;
+   OP2 (prod) = op2;
+       
+   prod->tp.pro.code = tree_code_get_expression
+      (prod_code, type, op1->tp.pro.code,
+       op2->tp.pro.code, NULL);
+ 
+   return prod;
+ }
+ 
+ 
  /* Set STORAGE_CLASS in PROD according to CLASS_TOKEN.  */
  
  static void
*************** treelang_debug (void)
*** 1011,1013 ****
--- 970,973 ----
    if (option_parser_trace)
      yydebug = 1;
  }
+ 
Index: tree1.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/treelang/tree1.c,v
retrieving revision 1.5
diff -c -3 -p -r1.5 tree1.c
*** tree1.c	8 Mar 2003 21:12:26 -0000	1.5
--- tree1.c	30 Apr 2003 19:07:02 -0000
*************** treelang_decode_option (num_options_left
*** 121,126 ****
--- 121,128 ----
            fprintf (stdout, "Usage: tree1 [switches] -o output input\n");
            return 1;
          }
+       break;
+ 
      case 'v':
        if (!strcmp (first_option_left[0],"-v"))
          {
*************** treelang_decode_option (num_options_left
*** 133,138 ****
--- 135,142 ----
              }
            return 1;
          }
+       break;
+ 
      case 'y':
        if (!strcmp (first_option_left[0],"-y"))
          {
*************** treelang_decode_option (num_options_left
*** 140,145 ****
--- 144,151 ----
            option_parser_trace = 1;
            return 1;
          }
+       break;
+ 
      case 'f':
        if (!strcmp (first_option_left[0],"-fparser-trace"))
          {
*************** treelang_decode_option (num_options_left
*** 151,157 ****
            option_lexer_trace = 1;
            return 1;
          }
!       return 0;
  
      case 'w':
        if (!strcmp (first_option_left[0],"-w"))
--- 157,163 ----
            option_lexer_trace = 1;
            return 1;
          }
!       break;
  
      case 'w':
        if (!strcmp (first_option_left[0],"-w"))
*************** treelang_decode_option (num_options_left
*** 160,180 ****
               all warnings.  */
            return 1;
          }
!       return 0;
  
      case 'W':
        if (!strcmp (first_option_left[0],"-Wall"))
          {
            return 1;
          }
!       return 0;
  
      default:
!       return 0;
      }
  
    return 0;
- 
  }
  
  /* Language dependent parser setup.  */
--- 166,185 ----
               all warnings.  */
            return 1;
          }
!       break;
  
      case 'W':
        if (!strcmp (first_option_left[0],"-Wall"))
          {
            return 1;
          }
!       break;
  
      default:
!       break;
      }
  
    return 0;
  }
  
  /* Language dependent parser setup.  */

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]