OSDN Git Service

gcc:
[pf3gnuchains/gcc-fork.git] / gcc / cp / cxx-pretty-print.c
index 04a8314..c5f1ac0 100644 (file)
@@ -1,6 +1,6 @@
 /* Implementation of subroutines for the GNU C++ pretty-printer.
    Copyright (C) 2003, 2004, 2005, 2007, 2008,
-   2009, 2010 Free Software Foundation, Inc.
+   2009, 2010, 2011 Free Software Foundation, Inc.
    Contributed by Gabriel Dos Reis <gdr@integrable-solutions.net>
 
 This file is part of GCC.
@@ -27,7 +27,6 @@ along with GCC; see the file COPYING3.  If not see
 #include "cp-tree.h"
 #include "cxx-pretty-print.h"
 #include "tree-pretty-print.h"
-#include "toplev.h"
 
 /* Translate if being used for diagnostics, but not for dump files or
    __PRETTY_FUNCTION.  */
@@ -260,7 +259,7 @@ pp_cxx_template_keyword_if_needed (cxx_pretty_printer *pp, tree scope, tree t)
 static void
 pp_cxx_nested_name_specifier (cxx_pretty_printer *pp, tree t)
 {
-  if (t != NULL && t != pp->enclosing_scope)
+  if (!SCOPE_FILE_SCOPE_P (t) && t != pp->enclosing_scope)
     {
       tree scope = TYPE_P (t) ? TYPE_CONTEXT (t) : DECL_CONTEXT (t);
       pp_cxx_nested_name_specifier (pp, scope);
@@ -395,8 +394,11 @@ pp_cxx_id_expression (cxx_pretty_printer *pp, tree t)
      __is_convertible_to ( type-id , type-id )     
      __is_empty ( type-id )
      __is_enum ( type-id )
+     __is_literal_type ( type-id )
      __is_pod ( type-id )
      __is_polymorphic ( type-id )
+     __is_std_layout ( type-id )
+     __is_trivial ( type-id )
      __is_union ( type-id )  */
 
 static void
@@ -791,6 +793,22 @@ pp_cxx_unary_expression (cxx_pretty_printer *pp, tree t)
        pp_unary_expression (pp, TREE_OPERAND (t, 0));
       break;
 
+    case AT_ENCODE_EXPR:
+      pp_cxx_ws_string (pp, "@encode");
+      pp_cxx_whitespace (pp);
+      pp_cxx_left_paren (pp);
+      pp_cxx_type_id (pp, TREE_OPERAND (t, 0));
+      pp_cxx_right_paren (pp);
+      break;      
+
+    case NOEXCEPT_EXPR:
+      pp_cxx_ws_string (pp, "noexcept");
+      pp_cxx_whitespace (pp);
+      pp_cxx_left_paren (pp);
+      pp_cxx_expression (pp, TREE_OPERAND (t, 0));
+      pp_cxx_right_paren (pp);
+      break;
+
     case UNARY_PLUS_EXPR:
       pp_plus (pp);
       pp_cxx_cast_expression (pp, TREE_OPERAND (t, 0));
@@ -1061,6 +1079,7 @@ pp_cxx_expression (cxx_pretty_printer *pp, tree t)
 
     case SIZEOF_EXPR:
     case ALIGNOF_EXPR:
+    case NOEXCEPT_EXPR:
       pp_cxx_unary_expression (pp, t);
       break;
 
@@ -1307,6 +1326,8 @@ pp_cxx_ptr_operator (cxx_pretty_printer *pp, tree t)
       if (TREE_CODE (TREE_TYPE (t)) == POINTER_TYPE
          || TYPE_PTR_TO_MEMBER_P (TREE_TYPE (t)))
        pp_cxx_ptr_operator (pp, TREE_TYPE (t));
+      pp_c_attributes_display (pp_c_base (pp),
+                              TYPE_ATTRIBUTES (TREE_TYPE (t)));
       if (TREE_CODE (t) == POINTER_TYPE)
        {
          pp_star (pp);
@@ -1345,7 +1366,7 @@ pp_cxx_ptr_operator (cxx_pretty_printer *pp, tree t)
 static inline tree
 pp_cxx_implicit_parameter_type (tree mf)
 {
-  return TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (mf))));
+  return class_of_this_parm (TREE_TYPE (mf));
 }
 
 /*
@@ -1418,8 +1439,20 @@ pp_cxx_exception_specification (cxx_pretty_printer *pp, tree t)
   tree ex_spec = TYPE_RAISES_EXCEPTIONS (t);
   bool need_comma = false;
 
-  if (!TYPE_NOTHROW_P (t) && ex_spec == NULL)
+  if (ex_spec == NULL)
     return;
+  if (TREE_PURPOSE (ex_spec))
+    {
+      pp_cxx_ws_string (pp, "noexcept");
+      pp_cxx_whitespace (pp);
+      pp_cxx_left_paren (pp);
+      if (DEFERRED_NOEXCEPT_SPEC_P (ex_spec))
+       pp_cxx_ws_string (pp, "<uninstantiated>");
+      else
+       pp_cxx_expression (pp, TREE_PURPOSE (ex_spec));
+      pp_cxx_right_paren (pp);
+      return;
+    }
   pp_cxx_ws_string (pp, "throw");
   pp_cxx_left_paren (pp);
   for (; ex_spec && TREE_VALUE (ex_spec); ex_spec = TREE_CHAIN (ex_spec))
@@ -1625,8 +1658,7 @@ pp_cxx_direct_abstract_declarator (cxx_pretty_printer *pp, tree t)
       if (TREE_CODE (t) == METHOD_TYPE)
        {
          pp_base (pp)->padding = pp_before;
-         pp_cxx_cv_qualifier_seq
-           (pp, TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (t))));
+         pp_cxx_cv_qualifier_seq (pp, class_of_this_parm (t));
        }
       pp_cxx_exception_specification (pp, t);
       break;
@@ -1667,6 +1699,7 @@ pp_cxx_type_id (cxx_pretty_printer *pp, tree t)
     case TEMPLATE_PARM_INDEX:
     case TEMPLATE_DECL:
     case TYPEOF_TYPE:
+    case UNDERLYING_TYPE:
     case DECLTYPE_TYPE:
     case TEMPLATE_ID_EXPR:
       pp_cxx_type_specifier_seq (pp, t);
@@ -1903,6 +1936,23 @@ pp_cxx_statement (cxx_pretty_printer *pp, tree t)
       pp_needs_newline (pp) = true;
       break;
 
+    case RANGE_FOR_STMT:
+      pp_cxx_ws_string (pp, "for");
+      pp_space (pp);
+      pp_cxx_left_paren (pp);
+      pp_cxx_statement (pp, RANGE_FOR_DECL (t));
+      pp_space (pp);
+      pp_needs_newline (pp) = false;
+      pp_colon (pp);
+      pp_space (pp);
+      pp_cxx_statement (pp, RANGE_FOR_EXPR (t));
+      pp_cxx_right_paren (pp);
+      pp_newline_and_indent (pp, 3);
+      pp_cxx_statement (pp, FOR_BODY (t));
+      pp_indentation (pp) -= 3;
+      pp_needs_newline (pp) = true;
+      break;
+
       /* jump-statement:
            goto identifier;
            continue ;
@@ -2089,7 +2139,6 @@ pp_cxx_template_declaration (cxx_pretty_printer *pp, tree t)
 {
   tree tmpl = most_general_template (t);
   tree level;
-  int i = 0;
 
   pp_maybe_newline_and_indent (pp, 0);
   for (level = DECL_TEMPLATE_PARMS (tmpl); level; level = TREE_CHAIN (level))
@@ -2099,7 +2148,6 @@ pp_cxx_template_declaration (cxx_pretty_printer *pp, tree t)
       pp_cxx_template_parameter_list (pp, TREE_VALUE (level));
       pp_cxx_end_template_argument_list (pp);
       pp_newline_and_indent (pp, 3);
-      i += 3;
     }
   if (TREE_CODE (t) == FUNCTION_DECL && DECL_SAVED_TREE (t))
     pp_cxx_function_definition (pp, t);
@@ -2326,6 +2374,9 @@ pp_cxx_trait_expression (cxx_pretty_printer *pp, tree t)
     case CPTK_IS_UNION:
       pp_cxx_ws_string (pp, "__is_union");
       break;
+    case CPTK_IS_LITERAL_TYPE:
+      pp_cxx_ws_string (pp, "__is_literal_type");
+      break;
 
     default:
       gcc_unreachable ();