OSDN Git Service

Fix aliasing bug that also caused memory usage problems.
[pf3gnuchains/gcc-fork.git] / gcc / c-pretty-print.c
index a2ef204..43bc1de 100644 (file)
@@ -225,7 +225,7 @@ void
 pp_c_type_qualifier_list (c_pretty_printer *pp, tree t)
 {
    int qualifiers;
-   
+
   if (!TYPE_P (t))
     t = TREE_TYPE (t);
 
@@ -261,6 +261,13 @@ pp_c_pointer (c_pretty_printer *pp, tree t)
       pp_c_type_qualifier_list (pp, t);
       break;
 
+      /* ??? This node is now in GENERIC and so shouldn't be here.  But
+        we'll fix that later.  */
+    case DECL_EXPR:
+      pp_declaration (pp, DECL_EXPR_DECL (t));
+      pp_needs_newline (pp) = true;
+      break;
+
     default:
       pp_unsupported_tree (pp, t);
     }
@@ -377,6 +384,8 @@ pp_c_specifier_qualifier_list (c_pretty_printer *pp, tree t)
             pp_c_whitespace (pp);
             pp_c_left_paren (pp);
           }
+       else if (!c_dialect_cxx ())
+         pp_c_whitespace (pp);
         pp_ptr_operator (pp, t);
       }
       break;
@@ -472,7 +481,7 @@ pp_c_direct_abstract_declarator (c_pretty_printer *pp, tree t)
     case POINTER_TYPE:
       pp_abstract_declarator (pp, t);
       break;
-      
+
     case FUNCTION_TYPE:
       pp_c_parameter_type_list (pp, t);
       pp_direct_abstract_declarator (pp, TREE_TYPE (t));
@@ -480,7 +489,7 @@ pp_c_direct_abstract_declarator (c_pretty_printer *pp, tree t)
 
     case ARRAY_TYPE:
       pp_c_left_bracket (pp);
-      if (TYPE_DOMAIN (t))
+      if (TYPE_DOMAIN (t) && TYPE_MAX_VALUE (TYPE_DOMAIN (t)))
         pp_expression (pp, TYPE_MAX_VALUE (TYPE_DOMAIN (t)));
       pp_c_right_bracket (pp);
       pp_direct_abstract_declarator (pp, TREE_TYPE (t));
@@ -498,7 +507,7 @@ pp_c_direct_abstract_declarator (c_pretty_printer *pp, tree t)
     case COMPLEX_TYPE:
     case TYPE_DECL:
       break;
-      
+
     default:
       pp_unsupported_tree (pp, t);
       break;
@@ -645,7 +654,7 @@ pp_c_declarator (c_pretty_printer *pp, tree t)
       pp_direct_declarator (pp, t);
     break;
 
-    
+
     default:
       pp_unsupported_tree (pp, t);
       break;
@@ -777,8 +786,10 @@ pp_c_integer_constant (c_pretty_printer *pp, tree i)
       if (tree_int_cst_sgn (i) < 0)
         {
           pp_c_char (pp, '-');
-          i = build_int_2 (-TREE_INT_CST_LOW (i),
-                           ~TREE_INT_CST_HIGH (i) + !TREE_INT_CST_LOW (i));
+          i = build_int_cst_wide (NULL_TREE,
+                                 -TREE_INT_CST_LOW (i),
+                                 ~TREE_INT_CST_HIGH (i)
+                                 + !TREE_INT_CST_LOW (i));
         }
       sprintf (pp_buffer (pp)->digit_buffer,
                HOST_WIDE_INT_PRINT_DOUBLE_HEX,
@@ -801,7 +812,7 @@ pp_c_character_constant (c_pretty_printer *pp, tree c)
 {
   tree type = TREE_TYPE (c);
   if (type == wchar_type_node)
-    pp_character (pp, 'L'); 
+    pp_character (pp, 'L');
   pp_quote (pp);
   if (host_integerp (c, TYPE_UNSIGNED (type)))
     pp_c_char (pp, tree_low_cst (c, TYPE_UNSIGNED (type)));
@@ -884,12 +895,12 @@ pp_c_floating_constant (c_pretty_printer *pp, tree r)
 }
 
 /* Pretty-print a compound literal expression.  GNU extensions include
-   vector constants.  */ 
+   vector constants.  */
 
 static void
 pp_c_compound_literal (c_pretty_printer *pp, tree e)
 {
-  tree type = TREE_TYPE (e);  
+  tree type = TREE_TYPE (e);
   pp_c_type_cast (pp, type);
 
   switch (TREE_CODE (type))
@@ -930,8 +941,8 @@ pp_c_constant (c_pretty_printer *pp, tree e)
           pp_c_character_constant (pp, e);
         else if (TREE_CODE (type) == ENUMERAL_TYPE
                  && pp_c_enumeration_constant (pp, e))
-          ; 
-        else 
+          ;
+        else
           pp_c_integer_constant (pp, e);
       }
       break;
@@ -955,8 +966,8 @@ pp_c_constant (c_pretty_printer *pp, tree e)
 void
 pp_c_identifier (c_pretty_printer *pp, const char *id)
 {
-  pp_c_maybe_whitespace (pp);            
-  pp_identifier (pp, id);  
+  pp_c_maybe_whitespace (pp);
+  pp_identifier (pp, id);
   pp_base (pp)->padding = pp_before;
 }
 
@@ -1242,6 +1253,62 @@ pp_c_postfix_expression (c_pretty_printer *pp, tree e)
       pp_c_call_argument_list (pp, TREE_OPERAND (e, 1));
       break;
 
+    case UNORDERED_EXPR:
+      pp_c_identifier (pp, flag_isoc99
+                          ? "isunordered"
+                          : "__builtin_isunordered");
+      goto two_args_fun;
+
+    case ORDERED_EXPR:
+      pp_c_identifier (pp, flag_isoc99
+                          ? "!isunordered"
+                          : "!__builtin_isunordered");
+      goto two_args_fun;
+
+    case UNLT_EXPR:
+      pp_c_identifier (pp, flag_isoc99
+                          ? "!isgreaterequal"
+                          : "!__builtin_isgreaterequal");
+      goto two_args_fun;
+
+    case UNLE_EXPR:
+      pp_c_identifier (pp, flag_isoc99
+                          ? "!isgreater"
+                          : "!__builtin_isgreater");
+      goto two_args_fun;
+
+    case UNGT_EXPR:
+      pp_c_identifier (pp, flag_isoc99
+                          ? "!islessequal"
+                          : "!__builtin_islessequal");
+      goto two_args_fun;
+
+    case UNGE_EXPR:
+      pp_c_identifier (pp, flag_isoc99
+                          ? "!isless"
+                          : "!__builtin_isless");
+      goto two_args_fun;
+
+    case UNEQ_EXPR:
+      pp_c_identifier (pp, flag_isoc99
+                          ? "!islessgreater"
+                          : "!__builtin_islessgreater");
+      goto two_args_fun;
+
+    case LTGT_EXPR:
+      pp_c_identifier (pp, flag_isoc99
+                          ? "islessgreater"
+                          : "__builtin_islessgreater");
+      goto two_args_fun;
+
+    two_args_fun:
+      pp_c_left_paren (pp);
+      pp_expression (pp, TREE_OPERAND (e, 0));
+      pp_separate_with (pp, ',');
+      pp_expression (pp, TREE_OPERAND (e, 1));
+      pp_c_right_paren (pp);
+      break;
+
     case ABS_EXPR:
       pp_c_identifier (pp, "__builtin_abs");
       pp_c_left_paren (pp);
@@ -1336,7 +1403,7 @@ pp_c_call_argument_list (c_pretty_printer *pp, tree t)
 
   unary-operator: one of
       * &  + - ! ~
-      
+
    GNU extensions.
    unary-expression:
       __alignof__ unary-expression
@@ -1473,7 +1540,7 @@ pp_c_additive_expression (c_pretty_printer *pp, tree e)
       else
        pp_minus (pp);
       pp_c_whitespace (pp);
-      pp_multiplicative_expression (pp, TREE_OPERAND (e, 1)); 
+      pp_multiplicative_expression (pp, TREE_OPERAND (e, 1));
       break;
 
     default:
@@ -1691,7 +1758,7 @@ pp_c_conditional_expression (c_pretty_printer *pp, tree e)
 
 /* assignment-expression:
       conditional-expression
-      unary-expression assignment-operator  assignment-expression 
+      unary-expression assignment-operator  assignment-expression
 
    assignment-expression: one of
       =    *=    /=    %=    +=    -=    >>=    <<=    &=    ^=    |=  */
@@ -1760,6 +1827,14 @@ pp_c_expression (c_pretty_printer *pp, tree e)
     case COMPLEX_CST:
     case COMPLEX_EXPR:
     case VECTOR_CST:
+    case ORDERED_EXPR:
+    case UNORDERED_EXPR:
+    case LTGT_EXPR:
+    case UNEQ_EXPR:
+    case UNLE_EXPR:
+    case UNLT_EXPR:
+    case UNGE_EXPR:
+    case UNGT_EXPR:
     case ABS_EXPR:
     case CONSTRUCTOR:
     case COMPOUND_LITERAL_EXPR:
@@ -1830,7 +1905,7 @@ pp_c_expression (c_pretty_printer *pp, tree e)
     case NE_EXPR:
       pp_c_equality_expression (pp, e);
       break;
-      
+
     case COND_EXPR:
       pp_conditional_expression (pp, e);
       break;
@@ -1856,14 +1931,13 @@ pp_c_expression (c_pretty_printer *pp, tree e)
     case NOP_EXPR:
     case NON_LVALUE_EXPR:
     case SAVE_EXPR:
-    case UNSAVE_EXPR:
       pp_expression (pp, TREE_OPERAND (e, 0));
       break;
 
     case TARGET_EXPR:
       pp_postfix_expression (pp, TREE_OPERAND (e, 1));
       break;
-      
+
     default:
       pp_unsupported_tree (pp, e);
       break;
@@ -1889,96 +1963,22 @@ pp_c_statement (c_pretty_printer *pp, tree stmt)
 
   if (stmt == NULL)
     return;
-  
+
+  if (pp_needs_newline (pp))
+    pp_newline_and_indent (pp, 0);
+
   code = TREE_CODE (stmt);
   switch (code)
     {
-    case STATEMENT_LIST:
-      {
-       tree_stmt_iterator tsi;
-
-        if (pp_needs_newline (pp))
-          pp_newline_and_indent (pp, 0);
-        pp_c_left_brace (pp);
-        pp_newline_and_indent (pp, 3);
-       for (tsi = tsi_start (stmt); !tsi_end_p (tsi); tsi_next (&tsi))
-          pp_statement (pp, tsi_stmt (tsi));
-        pp_newline_and_indent (pp, -3);
-        pp_c_right_brace (pp);
-        pp_needs_newline (pp) = true;
-      }
-      break;
-
-      /* compound-statement:
-            {  block-item-list(opt) }
-
-         block-item-list:
-            block-item
-            block-item-list block-item
-
-         block-item:
-            declaration
-            statement   */
-    case COMPOUND_STMT:
-      if (pp_needs_newline (pp))
-        pp_newline_and_indent (pp, 0);
-      pp_c_left_brace (pp);
-      pp_newline_and_indent (pp, 3);
-      pp_statement (pp, COMPOUND_BODY (stmt));
-      pp_newline_and_indent (pp, -3);
-      pp_c_right_brace (pp);
-      pp_needs_newline (pp) = true;
-      break;
-
       /* expression-statement:
             expression(opt) ;  */
     case EXPR_STMT:
-    case CLEANUP_STMT:
-      if (pp_needs_newline (pp))
-        pp_newline_and_indent (pp, 0);
-      {
-        tree e = code == EXPR_STMT
-          ? EXPR_STMT_EXPR (stmt)
-          : CLEANUP_EXPR (stmt);
-        if (e)
-          pp_expression (pp, e);
-      }
+      pp_expression (pp, EXPR_STMT_EXPR (stmt));
       pp_c_semicolon (pp);
       pp_needs_newline (pp) = true;
       break;
 
-      /* selection-statement:
-            if ( expression ) statement
-            if ( expression ) statement else statement
-            switch ( expression ) statement   */
-    case IF_STMT:
-      if (pp_needs_newline (pp))
-        pp_newline_and_indent (pp, 0);
-      pp_c_identifier (pp, "if");
-      pp_c_whitespace (pp);
-      pp_c_left_paren (pp);
-      pp_expression (pp, IF_COND (stmt));
-      pp_c_right_paren (pp);
-      pp_newline_and_indent (pp, 3);
-      pp_statement (pp, THEN_CLAUSE (stmt));
-      pp_newline_and_indent (pp, -3);
-      if (ELSE_CLAUSE (stmt))
-       {
-         tree else_clause = ELSE_CLAUSE (stmt);
-         pp_c_identifier (pp, "else");
-         if (TREE_CODE (else_clause) == IF_STMT)
-           pp_c_whitespace (pp);
-         else
-           pp_newline_and_indent (pp, 3);
-         pp_statement (pp, else_clause);
-         if (TREE_CODE (else_clause) != IF_STMT)
-           pp_newline_and_indent (pp, -3);
-       }
-      break;
-
     case SWITCH_STMT:
-      if (pp_needs_newline (pp))
-        pp_newline_and_indent (pp, 0);
       pp_c_identifier (pp, "switch");
       pp_space (pp);
       pp_c_left_paren (pp);
@@ -1996,8 +1996,6 @@ pp_c_statement (c_pretty_printer *pp, tree stmt)
             for ( expression(opt) ; expression(opt) ; expression(opt) ) statement
             for ( declaration expression(opt) ; expression(opt) ) statement  */
     case WHILE_STMT:
-      if (pp_needs_newline (pp))
-        pp_newline_and_indent (pp, 0);
       pp_c_identifier (pp, "while");
       pp_space (pp);
       pp_c_left_paren (pp);
@@ -2010,8 +2008,6 @@ pp_c_statement (c_pretty_printer *pp, tree stmt)
       break;
 
     case DO_STMT:
-      if (pp_needs_newline (pp))
-        pp_newline_and_indent (pp, 0);
       pp_c_identifier (pp, "do");
       pp_newline_and_indent (pp, 3);
       pp_statement (pp, DO_BODY (stmt));
@@ -2026,8 +2022,6 @@ pp_c_statement (c_pretty_printer *pp, tree stmt)
       break;
 
     case FOR_STMT:
-      if (pp_needs_newline (pp))
-        pp_newline_and_indent (pp, 0);
       pp_c_identifier (pp, "for");
       pp_space (pp);
       pp_c_left_paren (pp);
@@ -2057,41 +2051,14 @@ pp_c_statement (c_pretty_printer *pp, tree stmt)
             return expression(opt) ;  */
     case BREAK_STMT:
     case CONTINUE_STMT:
-      if (pp_needs_newline (pp))
-        pp_newline_and_indent (pp, 0);
       pp_identifier (pp, code == BREAK_STMT ? "break" : "continue");
       pp_c_semicolon (pp);
       pp_needs_newline (pp) = true;
       break;
 
-    case RETURN_STMT:
-      {
-       tree e = RETURN_STMT_EXPR (stmt);
-        if (pp_needs_newline (pp))
-          pp_newline_and_indent (pp, 0);
-       pp_c_identifier (pp, "return");
-        pp_c_whitespace (pp);
-       if (e)
-          {
-            if (TREE_CODE (e) == INIT_EXPR
-                && TREE_CODE (TREE_OPERAND (e, 0)) == RESULT_DECL)
-              e = TREE_OPERAND (e, 1);
-            pp_expression (pp, e);
-          }
-       pp_c_semicolon (pp);
-       pp_needs_newline (pp) = true;
-      }
-      break;
-
-    case DECL_STMT:
-      if (pp_needs_newline (pp))
-        pp_newline_and_indent (pp, 0);
-      pp_declaration (pp, DECL_STMT_DECL (stmt));
-      pp_needs_newline (pp) = true;
-      break;
-
     default:
-      pp_unsupported_tree (pp, stmt);
+      dump_generic_node (pp_base (pp), stmt, pp_indentation (pp), 0, true);
+      break;
     }
 }