parse.y: Use gcc_assert and gcc_unreachable instead of abort.
authorJames A. Morrison <phython@gcc.gnu.org>
Sat, 2 Oct 2004 17:42:44 +0000 (17:42 +0000)
committerJames A. Morrison <phython@gcc.gnu.org>
Sat, 2 Oct 2004 17:42:44 +0000 (17:42 +0000)
2004-10-02  James A. Morrison  <phython@gcc.gnu.org>

        * parse.y: Use gcc_assert and gcc_unreachable instead of abort.
        * tree1.c: Likewise.
        * treetree.c: Likewise.

From-SVN: r88429

gcc/treelang/ChangeLog
gcc/treelang/parse.y
gcc/treelang/tree1.c
gcc/treelang/treetree.c

index 88e85408612030b04778001adab34fb3e032902c..21837cd488239924b37ef0db53eeffc429858187 100644 (file)
@@ -1,3 +1,9 @@
+2004-10-02  James A. Morrison  <phython@gcc.gnu.org>
+
+       * parse.y: Use gcc_assert and gcc_unreachable instead of abort.
+       * tree1.c: Likewise.
+       * treetree.c: Likewise.
+
 2004-10-02  James A. Morrison  <phython@gcc.gnu.org>
 
        * lex.l: Remove random whitespace.
index b55795d256d0dd3abd6e4392d488ad01178d3b56..8a1db64954f21861fbe3df6c60bd5029715304b6 100644 (file)
@@ -197,8 +197,7 @@ storage typename NAME init_opt SEMICOLON {
 
   if (VAR_INIT (prod))
     {
-      if (! ((struct prod_token_parm_item*)VAR_INIT (prod))->tp.pro.code)
-        abort ();
+      gcc_assert (((struct prod_token_parm_item*)VAR_INIT (prod))->tp.pro.code);
     if (STORAGE_CLASS (prod) == EXTERNAL_REFERENCE_STORAGE)
       {
         fprintf (stderr, "%s:%i:%i: External reference variables may not have initial value\n",
@@ -217,8 +216,7 @@ storage typename NAME init_opt SEMICOLON {
      VAR_INIT (prod) ?
      ((struct prod_token_parm_item*)VAR_INIT (prod))->tp.pro.code : NULL,
      tok->tp.tok.location);
-  if (!prod->tp.pro.code) 
-    abort ();
+  gcc_assert (prod->tp.pro.code);
 }
 ;
 
@@ -287,7 +285,7 @@ storage typename NAME LEFT_PARENTHESIS parameters_opt RIGHT_PARENTHESIS SEMICOLO
       break;
 
     default:
-      abort ();
+      gcc_unreachable ();
     }
   type = EXPRESSION_TYPE (prod);
   /* Create a parameter list in a non-front end specific format.  */
@@ -295,16 +293,15 @@ storage typename NAME LEFT_PARENTHESIS parameters_opt RIGHT_PARENTHESIS SEMICOLO
        this_parm;
        this_parm = this_parm->tp.pro.next)
     {
-      if (this_parm->category != production_category)
-        abort ();
+      gcc_assert (this_parm->category == production_category);
+
       this_parm_var = VARIABLE (this_parm);
-      if (!this_parm_var)
-        abort ();
-      if (this_parm_var->category != production_category)
-        abort ();
+
+      gcc_assert (this_parm_var);
+      gcc_assert (this_parm_var->category == production_category);
+
       this_parms = my_malloc (sizeof (struct prod_token_parm_item));
-      if (!this_parm_var->tp.pro.main_token)
-        abort ();
+      gcc_assert (this_parm_var->tp.pro.main_token);
 
       this_parms->tp.par.variable_name =
        this_parm_var->tp.pro.main_token->tp.tok.chars;
@@ -353,22 +350,21 @@ NAME LEFT_BRACE {
       errorcount++;
       YYERROR;
     }
-  if (!proto->tp.pro.code)
-    abort ();
-  tree_code_create_function_initial
-    (proto->tp.pro.code, tok->tp.tok.location,
-     FIRST_PARMS (current_function));
+  gcc_assert (proto->tp.pro.code);
 
+  tree_code_create_function_initial (proto->tp.pro.code, tok->tp.tok.location,
+                                     FIRST_PARMS (current_function));
+
+#ifdef ENABLE_CHECKING
   /* Check all the parameters have code.  */
   for (this_parm = PARAMETERS (proto);
        this_parm;
        this_parm = this_parm->tp.pro.next)
     {
-      if (! (struct prod_token_parm_item*)VARIABLE (this_parm))
-        abort ();
-      if (! (( (struct prod_token_parm_item*)VARIABLE (this_parm))->tp.pro.code))
-        abort ();
+      gcc_assert ((struct prod_token_parm_item*)VARIABLE (this_parm));
+      gcc_assert ((( (struct prod_token_parm_item*)VARIABLE (this_parm))->tp.pro.code));
     }
+#endif
 }
 variable_defs_opt statements_opt RIGHT_BRACE {
   struct prod_token_parm_item* tok;
@@ -555,12 +551,12 @@ tl_RETURN expression_opt {
         /* Check same type.  */
         if (check_type_match (NUMERIC_TYPE (type_prod), $2))
           {
-            if (!type_prod->tp.pro.code)
-              abort ();
-            if (!exp->tp.pro.code)
-              abort ();
+            gcc_assert (type_prod->tp.pro.code);
+            gcc_assert (exp->tp.pro.code);
+
             /* Generate the code. */
-            tree_code_generate_return (type_prod->tp.pro.code, exp->tp.pro.code);
+            tree_code_generate_return (type_prod->tp.pro.code,
+                                       exp->tp.pro.code);
           }
       }
 }
@@ -573,8 +569,7 @@ expression_opt:
 |expression {
   struct prod_token_parm_item *exp;
   exp = $1;
-  if (!exp->tp.pro.code)
-    abort ();
+  gcc_assert (exp->tp.pro.code);
   
   $$ = $1;
 }
@@ -680,20 +675,19 @@ NAME LEFT_PARENTHESIS expressions_with_commas RIGHT_PARENTHESIS {
   for (exp_proto = PARAMETERS (proto), exp = PARAMETERS (prod);
        exp_proto;
        exp = exp->tp.pro.next, exp_proto = exp_proto->tp.pro.next)
-  {
-    if (!exp)
-      abort ();
-    if (!exp_proto)
-      abort ();
-    if (!exp->tp.pro.code)
-      abort ();
-    var = VARIABLE (exp_proto);
-    if (!var)
-      abort ();
-    if (!var->tp.pro.code)
-      abort ();
-    parms = tree_code_add_parameter (parms, var->tp.pro.code, exp->tp.pro.code);
-  }
+    {
+      gcc_assert (exp);
+      gcc_assert (exp_proto);
+      gcc_assert (exp->tp.pro.code);
+
+      var = VARIABLE (exp_proto);
+
+      gcc_assert (var);
+      gcc_assert (var->tp.pro.code);
+
+      parms = tree_code_add_parameter (parms, var->tp.pro.code,
+                                       exp->tp.pro.code);
+    }
   type = tree_code_get_type (NUMERIC_TYPE (prod));
   prod->tp.pro.code = tree_code_get_expression (EXP_FUNCTION_INVOCATION, type,
                                                 proto->tp.pro.code, parms,
@@ -826,8 +820,7 @@ reverse_prod_list (struct prod_token_parm_item *old_first)
 
   while (current) 
     {
-      if (current->category != production_category)
-        abort ();
+      gcc_assert (current->category == production_category);
       next = current->tp.pro.next;
       current->tp.pro.next = prev;
       prev = current;
@@ -888,18 +881,14 @@ check_type_match (int type_num, struct prod_token_parm_item *exp)
           return 1;
           
         case VOID_TYPE:
-          abort ();
-      
         default: 
-          abort ();
+          gcc_unreachable ();
         }
       break;
       
     case VOID_TYPE:
-      abort ();
-      
     default:
-      abort ();
+      gcc_unreachable ();
       
     }
 }
@@ -943,8 +932,7 @@ make_plus_expression (struct prod_token_parm_item* tok,
 
   NUMERIC_TYPE (prod) = type_code;
   type = tree_code_get_type (type_code);
-  if (!type)
-    abort ();
+  gcc_assert (type);
   OP1 (prod) = op1;
   OP2 (prod) = op2;
       
@@ -982,7 +970,7 @@ set_storage (struct prod_token_parm_item *prod)
       break;
 
     default:
-      abort ();
+      gcc_unreachable ();
     }
 }
 
index 5a3e3d10a93f5316d485a5da09e3804f755ba748..a734615f0910daa75d22367a63ce090580630936 100644 (file)
@@ -104,9 +104,6 @@ treelang_handle_option (size_t scode, const char *arg ATTRIBUTE_UNUSED,
 
   switch (code)
     {
-    default:
-      abort();
-
     case OPT_v:
       if (!version_done)
        {
@@ -129,6 +126,10 @@ treelang_handle_option (size_t scode, const char *arg ATTRIBUTE_UNUSED,
     case OPT_flexer_trace:
       option_lexer_trace = value;
       break;
+
+    default:
+      gcc_unreachable ();
+
     }
 
   return 1;
@@ -294,7 +295,7 @@ sanity_check (struct prod_token_parm_item *item)
       break;
       
     default:
-      abort ();
+      gcc_unreachable ();
     }
 }  
 
index a559c5d57a00656c606ad1a9e6df9ee2dac6ba6b..ade0d9d99c795e92076e44ff346a4d7bd7ef87ee 100644 (file)
@@ -245,7 +245,7 @@ tree_code_get_type (int type_num)
       return void_type_node;
 
     default:
-      abort ();
+      gcc_unreachable ();
     }
 }
 
@@ -330,8 +330,7 @@ tree_code_create_function_prototype (unsigned char* chars,
   id = get_identifier ((const char*)chars);
   for (parm = parms; parm; parm = parm->tp.par.next)
     {
-      if (parm->category != parameter_category)
-        abort ();
+      gcc_assert (parm->category == parameter_category);
       type_node = tree_code_get_type (parm->type);
       type_list = tree_cons (NULL_TREE, type_node, type_list);
     }
@@ -375,7 +374,7 @@ tree_code_create_function_prototype (unsigned char* chars,
 
     case AUTOMATIC_STORAGE:
     default:
-      abort ();
+      gcc_unreachable ();
     }
 
   /* Process declaration of function defined elsewhere.  */
@@ -403,8 +402,7 @@ tree_code_create_function_initial (tree prev_saved,
   struct prod_token_parm_item* parm;
 
   fn_decl = prev_saved;
-  if (!fn_decl)
-    abort ();
+  gcc_assert (fn_decl);
 
   /* Output message if not -quiet.  */
   announce_function (fn_decl);
@@ -437,10 +435,8 @@ tree_code_create_function_initial (tree prev_saved,
 
       /* Some languages have different nominal and real types.  */
       DECL_ARG_TYPE (parm_decl) = TREE_TYPE (parm_decl);
-      if (!DECL_ARG_TYPE (parm_decl))
-        abort ();
-      if (!fn_decl)
-        abort ();
+      gcc_assert (DECL_ARG_TYPE (parm_decl));
+      gcc_assert (fn_decl);
       DECL_CONTEXT (parm_decl) = fn_decl;
       DECL_SOURCE_LOCATION (parm_decl) = loc;
       parm_list = chainon (parm_decl, parm_list);
@@ -458,12 +454,10 @@ tree_code_create_function_initial (tree prev_saved,
        param_decl = TREE_CHAIN (param_decl),
          this_parm = this_parm->tp.par.next)
     {
-      if (!this_parm)
-        abort (); /* Too few.  */
+      gcc_assert (this_parm); /* Too few.  */
       *this_parm->tp.par.where_to_put_var_tree = param_decl;
     }
-  if (this_parm)
-    abort (); /* Too many.  */
+  gcc_assert (!this_parm); /* Too many.  */
 
   /* Create a new level at the start of the function.  */
 
@@ -541,8 +535,7 @@ tree_code_create_variable (unsigned int storage_class,
   var_type = tree_code_get_type (expression_type);
 
   /* 2. Build the name.  */
-  if (chars[length] != 0)
-    abort (); /* Should be null terminated.  */
+  gcc_assert (chars[length] == 0); /* Should be null terminated.  */
 
   var_id = get_identifier ((const char*)chars);
 
@@ -555,8 +548,7 @@ tree_code_create_variable (unsigned int storage_class,
   else
     DECL_INITIAL (var_decl) = NULL_TREE;
 
-  if (TYPE_SIZE (var_type) == 0)
-    abort (); /* Did not calculate size.  */
+  gcc_assert (TYPE_SIZE (var_type) != 0); /* Did not calculate size.  */
 
   DECL_CONTEXT (var_decl) = current_function_decl;
 
@@ -586,7 +578,7 @@ tree_code_create_variable (unsigned int storage_class,
       break;
 
     default:
-      abort ();
+      gcc_unreachable ();
     }
 
   /* This should really only be set if the variable is used.  */
@@ -611,13 +603,12 @@ tree_code_generate_return (tree type, tree exp)
   tree setret;
   tree param;
 
+#ifdef ENABLE_CHECKING
   for (param = DECL_ARGUMENTS (current_function_decl);
        param;
        param = TREE_CHAIN (param))
-    {
-      if (DECL_CONTEXT (param) != current_function_decl)
-        abort ();
-    }
+    gcc_assert (DECL_CONTEXT (param) == current_function_decl);
+#endif
 
   if (exp && TREE_TYPE (TREE_TYPE (current_function_decl)) != void_type_node)
     {
@@ -692,12 +683,10 @@ tree_code_get_expression (unsigned int exp_type,
   switch (exp_type)
     {
     case EXP_ASSIGN:
-      if (!op1 || !op2)
-        abort ();
+      gcc_assert (op1 && op2);
       operator = MODIFY_EXPR;
       ret1 = fold (build2 (operator, void_type_node, op1,
                            fold (build1 (CONVERT_EXPR, TREE_TYPE (op1), op2))));
-
       break;
 
     case EXP_PLUS:
@@ -714,8 +703,7 @@ tree_code_get_expression (unsigned int exp_type,
 
     /* Expand a binary expression.  Ensure the operands are the right type.  */
     binary_expression:
-      if (!op1 || !op2)
-        abort ();
+      gcc_assert (op1 && op2);
       ret1  =  fold (build2 (operator, type,
                        fold (build1 (CONVERT_EXPR, type, op1)),
                        fold (build1 (CONVERT_EXPR, type, op2))));
@@ -725,8 +713,7 @@ tree_code_get_expression (unsigned int exp_type,
          decl for the variable.  If the TYPE is different than the
          variable type, convert it.  */
     case EXP_REFERENCE:
-      if (!op1)
-        abort ();
+      gcc_assert (op1);
       if (type == TREE_TYPE (op1))
         ret1 = op1;
       else
@@ -734,9 +721,7 @@ tree_code_get_expression (unsigned int exp_type,
       break;
 
     case EXP_FUNCTION_INVOCATION:
-      if (!op1 || !op2)
-        abort ();
-
+      gcc_assert (op1 && op2);
       {
         tree fun_ptr;
         fun_ptr = fold (build1 (ADDR_EXPR,
@@ -746,7 +731,7 @@ tree_code_get_expression (unsigned int exp_type,
       break;
 
     default:
-      abort ();
+      gcc_unreachable ();
     }
 
   return ret1;