takes expression or declaration contexts into account. */
-#define pp_c_whitespace(PP) \
- do { \
- pp_space (PP); \
- pp_base (PP)->padding = pp_none; \
- } while (0)
#define pp_c_maybe_whitespace(PP) \
do { \
if (pp_base (PP)->padding == pp_before) \
pp_c_whitespace (PP); \
} while (0)
-#define pp_c_left_paren(PP) \
- do { \
- pp_left_paren (PP); \
- pp_base (PP)->padding = pp_none; \
- } while (0)
-
-#define pp_c_right_paren(PP) \
- do { \
- pp_right_paren (PP); \
- pp_base (PP)->padding = pp_none; \
- } while (0)
-
#define pp_c_left_brace(PP) \
do { \
pp_left_brace (PP); \
pp_base (PP)->padding = pp_none; \
} while (0)
-#define pp_c_arrow(PP) \
- do { \
- pp_arrow (PP); \
- pp_base (PP)->padding = pp_none; \
- } while (0)
-
#define pp_c_star(PP) \
do { \
pp_star (PP); \
pp_base (PP)->padding = pp_none; \
} while (0)
-#define pp_c_dot(PP) \
- do { \
- pp_dot (PP); \
- pp_base (PP)->padding = pp_none; \
- } while (0)
-
-#define pp_c_semicolon(PP) \
- do { \
- pp_semicolon (PP); \
- pp_base (PP)->padding = pp_none; \
- } while (0)
-
/* literal */
-static void pp_c_char (c_pretty_printer, int);
-static void pp_c_primary_expression (c_pretty_printer, tree);
+static void pp_c_char (c_pretty_printer *, int);
/* postfix-expression */
-static void pp_c_initializer_list (c_pretty_printer, tree);
-
-static void pp_c_multiplicative_expression (c_pretty_printer, tree);
-static void pp_c_additive_expression (c_pretty_printer, tree);
-static void pp_c_shift_expression (c_pretty_printer, tree);
-static void pp_c_relational_expression (c_pretty_printer, tree);
-static void pp_c_equality_expression (c_pretty_printer, tree);
-static void pp_c_and_expression (c_pretty_printer, tree);
-static void pp_c_exclusive_or_expression (c_pretty_printer, tree);
-static void pp_c_inclusive_or_expression (c_pretty_printer, tree);
-static void pp_c_logical_and_expression (c_pretty_printer, tree);
-static void pp_c_conditional_expression (c_pretty_printer, tree);
-static void pp_c_assignment_expression (c_pretty_printer, tree);
+static void pp_c_initializer_list (c_pretty_printer *, tree);
+
+static void pp_c_multiplicative_expression (c_pretty_printer *, tree);
+static void pp_c_additive_expression (c_pretty_printer *, tree);
+static void pp_c_shift_expression (c_pretty_printer *, tree);
+static void pp_c_relational_expression (c_pretty_printer *, tree);
+static void pp_c_equality_expression (c_pretty_printer *, tree);
+static void pp_c_and_expression (c_pretty_printer *, tree);
+static void pp_c_exclusive_or_expression (c_pretty_printer *, tree);
+static void pp_c_inclusive_or_expression (c_pretty_printer *, tree);
+static void pp_c_logical_and_expression (c_pretty_printer *, tree);
+static void pp_c_conditional_expression (c_pretty_printer *, tree);
+static void pp_c_assignment_expression (c_pretty_printer *, tree);
/* declarations. */
-static void pp_c_declaration_specifiers (c_pretty_printer, tree);
-static void pp_c_direct_abstract_declarator (c_pretty_printer, tree);
-static void pp_c_init_declarator (c_pretty_printer, tree);
-static void pp_c_simple_type_specifier (c_pretty_printer, tree);
-static void pp_c_parameter_declaration (c_pretty_printer, tree);
-static void pp_c_storage_class_specifier (c_pretty_printer, tree);
-static void pp_c_function_specifier (c_pretty_printer, tree);
-
\f
-/* Declarations. */
+/* Helper functions. */
+
+void
+pp_c_whitespace (c_pretty_printer *pp)
+{
+ pp_space (pp);
+ pp_base (pp)->padding = pp_none;
+}
+
+void
+pp_c_left_paren (c_pretty_printer *pp)
+{
+ pp_left_paren (pp);
+ pp_base (pp)->padding = pp_none;
+}
+
+void
+pp_c_right_paren (c_pretty_printer *pp)
+{
+ pp_right_paren (pp);
+ pp_base (pp)->padding = pp_none;
+}
+
+void
+pp_c_dot (c_pretty_printer *pp)
+{
+ pp_dot (pp);
+ pp_base (pp)->padding = pp_none;
+}
+
+void
+pp_c_ampersand (c_pretty_printer *pp)
+{
+ pp_ampersand (pp);
+ pp_base (pp)->padding = pp_none;
+}
+
+void
+pp_c_arrow (c_pretty_printer *pp)
+{
+ pp_arrow (pp);
+ pp_base (pp)->padding = pp_none;
+}
+
+void
+pp_c_semicolon(c_pretty_printer *pp)
+{
+ pp_semicolon (pp);
+ pp_base (pp)->padding = pp_none;
+}
static void
-pp_c_cv_qualifier (c_pretty_printer pp, const char *cv)
+pp_c_cv_qualifier (c_pretty_printer *pp, const char *cv)
{
const char *p = pp_last_position_in_text (pp);
if (p != NULL && *p == '*')
pp_c_identifier (pp, cv);
}
+/* Pretty-print T using the type-cast notation '( type-name )'. */
+static inline void
+pp_c_type_cast (c_pretty_printer *pp, tree t)
+{
+ pp_c_left_paren (pp);
+ pp_type_id (pp, t);
+ pp_c_right_paren (pp);
+}
+
+void
+pp_c_space_for_pointer_operator (c_pretty_printer *pp, tree t)
+{
+ if (POINTER_TYPE_P (t))
+ {
+ tree pointee = strip_pointer_operator (TREE_TYPE (t));
+ if (TREE_CODE (pointee) != ARRAY_TYPE
+ && TREE_CODE (pointee) != FUNCTION_TYPE)
+ pp_c_whitespace (pp);
+ }
+}
+
+\f
+/* Declarations. */
+
/* C++ cv-qualifiers are called type-qualifiers in C. Print out the
cv-qualifiers of T. If T is a declaration then it is the cv-qualifier
of its type. Take care of possible extensions.
- cv-qualifier:
+
+ type-qualifier-list:
+ type-qualifier
+ type-qualifier-list type-qualifier
+
+ type-qualifier:
const
- volatile
- restrict
- __restrict__ */
+ restrict -- C99
+ __restrict__ -- GNU C
+ volatile */
void
-pp_c_type_qualifier_list (c_pretty_printer pp, tree t)
+pp_c_type_qualifier_list (c_pretty_printer *pp, tree t)
{
int qualifiers;
* type-qualifier-list(opt)
* type-qualifier-list(opt) pointer */
static void
-pp_c_pointer (c_pretty_printer pp, tree t)
+pp_c_pointer (c_pretty_printer *pp, tree t)
{
if (!TYPE_P (t) && TREE_CODE (t) != TYPE_DECL)
t = TREE_TYPE (t);
switch (TREE_CODE (t))
{
case POINTER_TYPE:
+ /* It is easier to handle C++ reference types here. */
+ case REFERENCE_TYPE:
if (TREE_CODE (TREE_TYPE (t)) == POINTER_TYPE)
pp_c_pointer (pp, TREE_TYPE (t));
- pp_c_star (pp);
+ if (TREE_CODE (t) == POINTER_TYPE)
+ pp_c_star (pp);
+ else
+ pp_c_ampersand (pp);
pp_c_type_qualifier_list (pp, t);
break;
}
}
-/*
- simple-type-specifier:
- void
- char
- short
- int
- long
- float
- double
- signed
- unsigned
- _Bool -- C99
- _Complex -- C99
- _Imaginary -- C99
- typedef-name.
+/* type-specifier:
+ void
+ char
+ short
+ int
+ long
+ float
+ double
+ signed
+ unsigned
+ _Bool -- C99
+ _Complex -- C99
+ _Imaginary -- C99
+ struct-or-union-specifier
+ enum-specifier
+ typedef-name.
GNU extensions.
simple-type-specifier:
__complex__
__vector__ */
-static void
-pp_c_simple_type_specifier (c_pretty_printer ppi, tree t)
+void
+pp_c_type_specifier (c_pretty_printer *pp, tree t)
{
- enum tree_code code;
-
- if (DECL_P (t) && TREE_CODE (t) != TYPE_DECL)
- t = TREE_TYPE (t);
-
- code = TREE_CODE (t);
+ const enum tree_code code = TREE_CODE (t);
switch (code)
{
case ERROR_MARK:
- pp_c_identifier (ppi, "<type-error>");
- break;
-
-#if 0
- case UNKNOWN_TYPE:
- pp_c_identifier (ppi, "<unkown-type>");
+ pp_c_identifier (pp, "<type-error>");
break;
-#endif
case IDENTIFIER_NODE:
- pp_c_tree_identifier (ppi, t);
+ pp_c_tree_identifier (pp, t);
break;
case VOID_TYPE:
case CHAR_TYPE:
case INTEGER_TYPE:
case REAL_TYPE:
- pp_c_simple_type_specifier (ppi, TYPE_NAME (t));
- break;
-
- case COMPLEX_TYPE:
- case VECTOR_TYPE:
- pp_c_simple_type_specifier (ppi, TYPE_MAIN_VARIANT (TREE_TYPE (t)));
- if (code == COMPLEX_TYPE)
- pp_c_identifier (ppi, flag_isoc99 ? "_Complex" : "__complex__");
- else if (code == VECTOR_TYPE)
- pp_c_identifier (ppi, "__vector__");
+ pp_c_type_specifier (pp, TYPE_NAME (t));
break;
case TYPE_DECL:
if (DECL_NAME (t))
- pp_id_expression (ppi, t);
+ pp_id_expression (pp, t);
else
- pp_c_identifier (ppi, "<typedef-error>");
+ pp_c_identifier (pp, "<typedef-error>");
break;
case UNION_TYPE:
case RECORD_TYPE:
case ENUMERAL_TYPE:
if (code == UNION_TYPE)
- pp_c_identifier (ppi, "union");
+ pp_c_identifier (pp, "union");
else if (code == RECORD_TYPE)
- pp_c_identifier (ppi, "struct");
+ pp_c_identifier (pp, "struct");
else if (code == ENUMERAL_TYPE)
- pp_c_identifier (ppi, "enum");
+ pp_c_identifier (pp, "enum");
else
- pp_c_identifier (ppi, "<tag-error>");
+ pp_c_identifier (pp, "<tag-error>");
if (TYPE_NAME (t))
- pp_id_expression (ppi, TYPE_NAME (t));
+ pp_id_expression (pp, TYPE_NAME (t));
else
- pp_c_identifier (ppi, "<anonymous>");
- break;
-
- case POINTER_TYPE:
- case ARRAY_TYPE:
- case FUNCTION_TYPE:
- pp_c_simple_type_specifier (ppi, TREE_TYPE (t));
+ pp_c_identifier (pp, "<anonymous>");
break;
default:
- pp_unsupported_tree (ppi, t);
+ pp_unsupported_tree (pp, t);
break;
}
}
/* specifier-qualifier-list:
type-specifier specifier-qualifier-list-opt
- cv-qualifier specifier-qualifier-list-opt
+ type-qualifier specifier-qualifier-list-opt
Implementation note: Because of the non-linearities in array or
but also the 'pointer' production part of their declarators. The
remaining part is done by pp_declarator or pp_c_abstract_declarator. */
void
-pp_c_specifier_qualifier_list (c_pretty_printer pp, tree t)
+pp_c_specifier_qualifier_list (c_pretty_printer *pp, tree t)
{
+ const enum tree_code code = TREE_CODE (t);
+
if (TREE_CODE (t) != POINTER_TYPE)
pp_c_type_qualifier_list (pp, t);
- switch (TREE_CODE (t))
+ switch (code)
{
+ case REFERENCE_TYPE:
case POINTER_TYPE:
{
/* Get the types-specifier of this type. */
- tree pointee = TREE_TYPE (t);
- while (TREE_CODE (pointee) == POINTER_TYPE)
- pointee = TREE_TYPE (pointee);
+ tree pointee = strip_pointer_operator (TREE_TYPE (t));
pp_c_specifier_qualifier_list (pp, pointee);
if (TREE_CODE (pointee) == ARRAY_TYPE
|| TREE_CODE (pointee) == FUNCTION_TYPE)
pp_c_whitespace (pp);
pp_c_left_paren (pp);
}
- pp_c_pointer (pp, t);
- if (TREE_CODE (pointee) != FUNCTION_TYPE
- && TREE_CODE (pointee) != ARRAY_TYPE)
- pp_c_whitespace (pp);
+ pp_ptr_operator (pp, t);
}
break;
case VECTOR_TYPE:
case COMPLEX_TYPE:
pp_c_specifier_qualifier_list (pp, TREE_TYPE (t));
- pp_space (pp);
- pp_c_simple_type_specifier (pp, t);
+ if (code == COMPLEX_TYPE)
+ pp_c_identifier (pp, flag_isoc99 ? "_Complex" : "__complex__");
+ else if (code == VECTOR_TYPE)
+ pp_c_identifier (pp, "__vector__");
break;
default:
- pp_c_simple_type_specifier (pp, t);
+ pp_simple_type_specifier (pp, t);
break;
}
}
parameter-declaration:
declaration-specifiers declarator
declaration-specifiers abstract-declarator(opt) */
-static void
-pp_c_parameter_type_list (c_pretty_printer pp, tree t)
+void
+pp_c_parameter_type_list (c_pretty_printer *pp, tree t)
{
+ bool want_parm_decl = DECL_P (t) && !(pp->flags & pp_c_flag_abstract);
+ tree parms = want_parm_decl ? DECL_ARGUMENTS (t) : TYPE_ARG_TYPES (t);
pp_c_left_paren (pp);
- if (t == void_list_node)
+ if (parms == void_list_node)
pp_c_identifier (pp, "void");
else
{
bool first = true;
- bool want_parm_decl = t && DECL_P (t);
- for ( ; t != NULL && t != void_list_node; t = TREE_CHAIN (t))
+ for ( ; parms && parms != void_list_node; parms = TREE_CHAIN (parms))
{
if (!first)
pp_separate_with (pp, ',');
first = false;
- pp_declaration_specifiers (pp, want_parm_decl ? t : TREE_VALUE (t));
+ pp_declaration_specifiers
+ (pp, want_parm_decl ? parms : TREE_VALUE (parms));
if (want_parm_decl)
- pp_declarator (pp, t);
+ pp_declarator (pp, parms);
else
- pp_abstract_declarator (pp, TREE_VALUE (t));
+ pp_abstract_declarator (pp, TREE_VALUE (parms));
}
}
pp_c_right_paren (pp);
pointer
pointer(opt) direct-abstract-declarator */
static inline void
-pp_c_abstract_declarator (c_pretty_printer pp, tree t)
+pp_c_abstract_declarator (c_pretty_printer *pp, tree t)
{
if (TREE_CODE (t) == POINTER_TYPE)
{
t = TREE_TYPE (t);
}
- pp_c_direct_abstract_declarator (pp, t);
+ pp_direct_abstract_declarator (pp, t);
}
/* direct-abstract-declarator:
direct-abstract-declarator(opt) [ assignment-expression(opt) ]
direct-abstract-declarator(opt) [ * ]
direct-abstract-declarator(opt) ( parameter-type-list(opt) ) */
-static void
-pp_c_direct_abstract_declarator (c_pretty_printer pp, tree t)
+void
+pp_c_direct_abstract_declarator (c_pretty_printer *pp, tree t)
{
switch (TREE_CODE (t))
{
case POINTER_TYPE:
- pp_c_abstract_declarator (pp, t);
+ pp_abstract_declarator (pp, t);
break;
case FUNCTION_TYPE:
- pp_c_parameter_type_list (pp, TYPE_ARG_TYPES (t));
- pp_c_direct_abstract_declarator (pp, TREE_TYPE (t));
+ pp_c_parameter_type_list (pp, t);
+ pp_direct_abstract_declarator (pp, TREE_TYPE (t));
break;
case ARRAY_TYPE:
pp_c_left_bracket (pp);
if (TYPE_DOMAIN (t))
- pp_c_expression (pp, TYPE_MAX_VALUE (TYPE_DOMAIN (t)));
+ pp_expression (pp, TYPE_MAX_VALUE (TYPE_DOMAIN (t)));
pp_c_right_bracket (pp);
- pp_c_direct_abstract_declarator (pp, TREE_TYPE (t));
+ pp_direct_abstract_declarator (pp, TREE_TYPE (t));
break;
case IDENTIFIER_NODE:
}
}
+/* type-name:
+ specifier-qualifier-list abstract-declarator(opt) */
void
-pp_c_type_id (c_pretty_printer ppi, tree t)
+pp_c_type_id (c_pretty_printer *pp, tree t)
{
- pp_c_specifier_qualifier_list (ppi, t);
- pp_abstract_declarator (ppi, t);
+ pp_c_specifier_qualifier_list (pp, t);
+ pp_abstract_declarator (pp, t);
}
-static inline void
-pp_c_storage_class_specifier (c_pretty_printer pp, tree t)
+/* storage-class-specifier:
+ typedef
+ extern
+ static
+ auto
+ register */
+void
+pp_c_storage_class_specifier (c_pretty_printer *pp, tree t)
{
if (TREE_CODE (t) == TYPE_DECL)
pp_c_identifier (pp, "typedef");
}
}
-static inline void
-pp_c_function_specifier (c_pretty_printer pp, tree t)
+/* function-specifier:
+ inline */
+void
+pp_c_function_specifier (c_pretty_printer *pp, tree t)
{
if (TREE_CODE (t) == FUNCTION_DECL && DECL_DECLARED_INLINE_P (t))
pp_c_identifier (pp, "inline");
type-specifier declaration-specifiers(opt)
type-qualifier declaration-specifiers(opt)
function-specifier declaration-specifiers(opt) */
-static inline void
-pp_c_declaration_specifiers (c_pretty_printer pp, tree t)
+void
+pp_c_declaration_specifiers (c_pretty_printer *pp, tree t)
{
pp_storage_class_specifier (pp, t);
pp_function_specifier (pp, t);
direct-declaratpr ( parameter-type-list )
direct-declarator ( identifier-list(opt) ) */
void
-pp_c_direct_declarator (c_pretty_printer pp, tree t)
+pp_c_direct_declarator (c_pretty_printer *pp, tree t)
{
switch (TREE_CODE (t))
{
case TYPE_DECL:
case FIELD_DECL:
case LABEL_DECL:
- pp_c_tree_identifier (pp, DECL_NAME (t));
+ if (DECL_NAME (t))
+ {
+ pp_c_space_for_pointer_operator (pp, TREE_TYPE (t));
+ pp_c_tree_identifier (pp, DECL_NAME (t));
+ }
case ARRAY_TYPE:
case POINTER_TYPE:
pp_abstract_declarator (pp, TREE_TYPE (t));
break;
case FUNCTION_TYPE:
- pp_c_parameter_type_list (pp, TYPE_ARG_TYPES (t));
- pp_c_abstract_declarator (pp, TREE_TYPE (t));
+ pp_parameter_list (pp, t);
+ pp_abstract_declarator (pp, TREE_TYPE (t));
break;
case FUNCTION_DECL:
+ pp_c_space_for_pointer_operator (pp, TREE_TYPE (TREE_TYPE (t)));
pp_c_tree_identifier (pp, DECL_NAME (t));
if (pp_c_base (pp)->flags & pp_c_flag_abstract)
- pp_c_abstract_declarator (pp, TREE_TYPE (t));
+ pp_abstract_declarator (pp, TREE_TYPE (t));
else
{
- pp_c_parameter_type_list (pp, DECL_ARGUMENTS (t));
- pp_c_abstract_declarator (pp, TREE_TYPE (TREE_TYPE (t)));
+ pp_parameter_list (pp, t);
+ pp_abstract_declarator (pp, TREE_TYPE (TREE_TYPE (t)));
}
break;
/* declarator:
pointer(opt) direct-declarator */
void
-pp_c_declarator (c_pretty_printer pp, tree t)
+pp_c_declarator (c_pretty_printer *pp, tree t)
{
switch (TREE_CODE (t))
{
}
}
-/* init-declarator:
- declarator:
- declarator = initializer */
-static inline void
-pp_c_init_declarator (c_pretty_printer pp, tree t)
-{
- pp_declarator (pp, t);
- if (DECL_INITIAL (t))
- {
- pp_space (pp);
- pp_equal (pp);
- pp_space (pp);
- pp_c_initializer (pp, DECL_INITIAL (t));
- }
-}
-
/* declaration:
declaration-specifiers init-declarator-list(opt) ; */
-
void
-pp_c_declaration (c_pretty_printer pp, tree t)
+pp_c_declaration (c_pretty_printer *pp, tree t)
{
pp_declaration_specifiers (pp, t);
pp_c_init_declarator (pp, t);
}
-static void
-pp_c_parameter_declaration (c_pretty_printer pp, tree t)
-{
- pp_unsupported_tree (pp, t);
-}
-
/* Pretty-print ATTRIBUTES using GNU C extension syntax. */
void
-pp_c_attributes (c_pretty_printer pp, tree attributes)
+pp_c_attributes (c_pretty_printer *pp, tree attributes)
{
if (attributes == NULL_TREE)
return;
{
pp_tree_identifier (pp, TREE_PURPOSE (attributes));
if (TREE_VALUE (attributes))
- {
- pp_c_left_paren (pp);
- pp_c_expression_list (pp, TREE_VALUE (attributes));
- pp_c_right_paren (pp);
- }
+ pp_c_call_argument_list (pp, TREE_VALUE (attributes));
if (TREE_CHAIN (attributes))
pp_separate_with (pp, ',');
/* function-definition:
declaration-specifiers declarator compound-statement */
void
-pp_c_function_definition (c_pretty_printer pp, tree t)
+pp_c_function_definition (c_pretty_printer *pp, tree t)
{
pp_declaration_specifiers (pp, t);
pp_declarator (pp, t);
/* Print out a c-char. */
static void
-pp_c_char (c_pretty_printer ppi, int c)
+pp_c_char (c_pretty_printer *pp, int c)
{
switch (c)
{
case TARGET_NEWLINE:
- pp_string (ppi, "\\n");
+ pp_string (pp, "\\n");
break;
case TARGET_TAB:
- pp_string (ppi, "\\t");
+ pp_string (pp, "\\t");
break;
case TARGET_VT:
- pp_string (ppi, "\\v");
+ pp_string (pp, "\\v");
break;
case TARGET_BS:
- pp_string (ppi, "\\b");
+ pp_string (pp, "\\b");
break;
case TARGET_CR:
- pp_string (ppi, "\\r");
+ pp_string (pp, "\\r");
break;
case TARGET_FF:
- pp_string (ppi, "\\f");
+ pp_string (pp, "\\f");
break;
case TARGET_BELL:
- pp_string (ppi, "\\a");
+ pp_string (pp, "\\a");
break;
case '\\':
- pp_string (ppi, "\\\\");
+ pp_string (pp, "\\\\");
break;
case '\'':
- pp_string (ppi, "\\'");
+ pp_string (pp, "\\'");
break;
case '\"':
- pp_string (ppi, "\\\"");
+ pp_string (pp, "\\\"");
break;
default:
if (ISPRINT (c))
- pp_character (ppi, c);
+ pp_character (pp, c);
else
- pp_scalar (ppi, "\\%03o", (unsigned) c);
+ pp_scalar (pp, "\\%03o", (unsigned) c);
break;
}
}
/* Print out a STRING literal. */
void
-pp_c_string_literal (c_pretty_printer ppi, tree s)
+pp_c_string_literal (c_pretty_printer *pp, tree s)
{
const char *p = TREE_STRING_POINTER (s);
int n = TREE_STRING_LENGTH (s) - 1;
int i;
- pp_doublequote (ppi);
+ pp_doublequote (pp);
for (i = 0; i < n; ++i)
- pp_c_char (ppi, p[i]);
- pp_doublequote (ppi);
+ pp_c_char (pp, p[i]);
+ pp_doublequote (pp);
}
static void
-pp_c_integer_constant (c_pretty_printer pp, tree i)
+pp_c_integer_constant (c_pretty_printer *pp, tree i)
{
if (host_integerp (i, 0))
pp_wide_integer (pp, TREE_INT_CST_LOW (i));
/* Print out a CHARACTER literal. */
static inline void
-pp_c_character_constant (c_pretty_printer pp, tree c)
+pp_c_character_constant (c_pretty_printer *pp, tree c)
{
tree type = TREE_TYPE (c);
if (type == wchar_type_node)
/* Print out a BOOLEAN literal. */
static void
-pp_c_bool_constant (c_pretty_printer pp, tree b)
+pp_c_bool_constant (c_pretty_printer *pp, tree b)
{
if (b == boolean_false_node)
{
print out the type-id part of the cast-expression -- the casted value
is then printed by pp_c_integer_literal. */
static bool
-pp_c_enumeration_constant (c_pretty_printer ppi, tree e)
+pp_c_enumeration_constant (c_pretty_printer *pp, tree e)
{
bool value_is_named = true;
tree type = TREE_TYPE (e);
;
if (value != NULL_TREE)
- pp_id_expression (ppi, TREE_PURPOSE (value));
+ pp_id_expression (pp, TREE_PURPOSE (value));
else
{
/* Value must have been cast. */
- pp_c_left_paren (ppi);
- pp_type_id (ppi, type);
- pp_c_right_paren (ppi);
+ pp_c_type_cast (pp, type);
value_is_named = false;
}
/* Print out a REAL value. */
static inline void
-pp_c_floating_constant (c_pretty_printer pp, tree r)
+pp_c_floating_constant (c_pretty_printer *pp, tree r)
{
real_to_decimal (pp_buffer (pp)->digit_buffer, &TREE_REAL_CST (r),
sizeof (pp_buffer (pp)->digit_buffer), 0, 1);
enumeration-constant
chatracter-constant */
void
-pp_c_constant (c_pretty_printer pp, tree e)
+pp_c_constant (c_pretty_printer *pp, tree e)
{
switch (TREE_CODE (e))
{
}
void
-pp_c_identifier (c_pretty_printer pp, const char *id)
+pp_c_identifier (c_pretty_printer *pp, const char *id)
{
pp_c_maybe_whitespace (pp);
pp_identifier (pp, id);
constant
string-literal
( expression ) */
-static void
-pp_c_primary_expression (c_pretty_printer ppi, tree e)
+void
+pp_c_primary_expression (c_pretty_printer *pp, tree e)
{
switch (TREE_CODE (e))
{
e = DECL_NAME (e);
/* Fall through. */
case IDENTIFIER_NODE:
- pp_c_tree_identifier (ppi, e);
+ pp_c_tree_identifier (pp, e);
break;
case ERROR_MARK:
- pp_c_identifier (ppi, "<erroneous-expression>");
+ pp_c_identifier (pp, "<erroneous-expression>");
break;
case RESULT_DECL:
- pp_c_identifier (ppi, "<return-value>");
+ pp_c_identifier (pp, "<return-value>");
break;
case INTEGER_CST:
case REAL_CST:
case STRING_CST:
- pp_c_constant (ppi, e);
+ pp_c_constant (pp, e);
break;
- case TARGET_EXPR:
- pp_c_left_paren (ppi);
- pp_c_identifier (ppi, "__builtin_memcpy");
- pp_c_left_paren (ppi);
- pp_ampersand (ppi);
- pp_primary_expression (ppi, TREE_OPERAND (e, 0));
- pp_separate_with (ppi, ',');
- pp_ampersand (ppi);
- pp_initializer (ppi, TREE_OPERAND (e, 1));
- if (TREE_OPERAND (e, 2))
- {
- pp_separate_with (ppi, ',');
- pp_c_expression (ppi, TREE_OPERAND (e, 2));
- }
- pp_c_right_paren (ppi);
-
case STMT_EXPR:
- pp_c_left_paren (ppi);
- pp_statement (ppi, STMT_EXPR_STMT (e));
- pp_c_right_paren (ppi);
+ pp_c_left_paren (pp);
+ pp_statement (pp, STMT_EXPR_STMT (e));
+ pp_c_right_paren (pp);
break;
default:
/* FIXME: Make sure we won't get into an infinie loop. */
- pp_c_left_paren (ppi);
- pp_c_expression (ppi, e);
- pp_c_right_paren (ppi);
+ pp_c_left_paren (pp);
+ pp_expression (pp, e);
+ pp_c_right_paren (pp);
break;
}
}
{ initializer-list }
{ initializer-list , } */
-void
-pp_c_initializer (c_pretty_printer ppi, tree e)
+static void
+pp_c_initializer (c_pretty_printer *pp, tree e)
{
if (TREE_CODE (e) == CONSTRUCTOR)
{
enum tree_code code = TREE_CODE (TREE_TYPE (e));
if (code == RECORD_TYPE || code == UNION_TYPE || code == ARRAY_TYPE)
{
- pp_c_left_brace (ppi);
- pp_c_initializer_list (ppi, e);
- pp_c_right_brace (ppi);
+ pp_c_left_brace (pp);
+ pp_c_initializer_list (pp, e);
+ pp_c_right_brace (pp);
}
else
- pp_unsupported_tree (ppi, TREE_OPERAND (e, 1));
+ pp_unsupported_tree (pp, TREE_OPERAND (e, 1));
}
else
- pp_assignment_expression (ppi, e);
+ pp_expression (pp, e);
+}
+
+/* init-declarator:
+ declarator:
+ declarator = initializer */
+void
+pp_c_init_declarator (c_pretty_printer *pp, tree t)
+{
+ pp_declarator (pp, t);
+ if (DECL_INITIAL (t))
+ {
+ tree init = DECL_INITIAL (t);
+ /* This C++ bit is handled here because it is easier to do so.
+ In templates, the C++ parser builds a TREE_LIST for a
+ direct-initialization; the TREE_PURPOSE is the variable to
+ initialize and the TREE_VALUE is the initializer. */
+ if (TREE_CODE (init) == TREE_LIST)
+ {
+ pp_c_left_paren (pp);
+ pp_expression (pp, TREE_VALUE (init));
+ pp_right_paren (pp);
+ }
+ else
+ {
+ pp_space (pp);
+ pp_equal (pp);
+ pp_space (pp);
+ pp_c_initializer (pp, init);
+ }
+ }
}
/* initializer-list:
[ constant-expression ]
identifier */
static void
-pp_c_initializer_list (c_pretty_printer ppi, tree e)
+pp_c_initializer_list (c_pretty_printer *pp, tree e)
{
tree type = TREE_TYPE (e);
const enum tree_code code = TREE_CODE (type);
{
if (code == RECORD_TYPE || code == UNION_TYPE)
{
- pp_c_dot (ppi);
- pp_c_primary_expression (ppi, TREE_PURPOSE (init));
+ pp_c_dot (pp);
+ pp_c_primary_expression (pp, TREE_PURPOSE (init));
}
else
{
- pp_c_left_bracket (ppi);
+ pp_c_left_bracket (pp);
if (TREE_PURPOSE (init))
- pp_c_constant (ppi, TREE_PURPOSE (init));
- pp_c_right_bracket (ppi);
+ pp_c_constant (pp, TREE_PURPOSE (init));
+ pp_c_right_bracket (pp);
}
- pp_c_whitespace (ppi);
- pp_equal (ppi);
- pp_c_whitespace (ppi);
- pp_initializer (ppi, TREE_VALUE (init));
+ pp_c_whitespace (pp);
+ pp_equal (pp);
+ pp_c_whitespace (pp);
+ pp_initializer (pp, TREE_VALUE (init));
if (TREE_CHAIN (init))
- pp_separate_with (ppi, ',');
+ pp_separate_with (pp, ',');
}
}
else
- pp_unsupported_tree (ppi, type);
+ pp_unsupported_tree (pp, type);
}
/* This is a convenient function, used to bridge gap between C and C++
id-expression:
identifier */
void
-pp_c_id_expression (c_pretty_printer pp, tree t)
+pp_c_id_expression (c_pretty_printer *pp, tree t)
{
switch (TREE_CODE (t))
{
( type-name ) { initializer-list }
( type-name ) { initializer-list , } */
void
-pp_c_postfix_expression (c_pretty_printer ppi, tree e)
+pp_c_postfix_expression (c_pretty_printer *pp, tree e)
{
enum tree_code code = TREE_CODE (e);
switch (code)
{
case POSTINCREMENT_EXPR:
case POSTDECREMENT_EXPR:
- pp_postfix_expression (ppi, TREE_OPERAND (e, 0));
- pp_identifier (ppi, code == POSTINCREMENT_EXPR ? "++" : "--");
+ pp_postfix_expression (pp, TREE_OPERAND (e, 0));
+ pp_identifier (pp, code == POSTINCREMENT_EXPR ? "++" : "--");
break;
case ARROW_EXPR:
- pp_postfix_expression (ppi, TREE_OPERAND (e, 0));
- pp_c_arrow (ppi);
+ pp_postfix_expression (pp, TREE_OPERAND (e, 0));
+ pp_c_arrow (pp);
break;
case ARRAY_REF:
- pp_postfix_expression (ppi, TREE_OPERAND (e, 0));
- pp_c_left_bracket (ppi);
- pp_c_expression (ppi, TREE_OPERAND (e, 1));
- pp_c_right_bracket (ppi);
+ pp_postfix_expression (pp, TREE_OPERAND (e, 0));
+ pp_c_left_bracket (pp);
+ pp_expression (pp, TREE_OPERAND (e, 1));
+ pp_c_right_bracket (pp);
break;
case CALL_EXPR:
- pp_postfix_expression (ppi, TREE_OPERAND (e, 0));
- pp_c_left_paren (ppi);
- pp_c_expression_list (ppi, TREE_OPERAND (e, 1));
- pp_c_right_paren (ppi);
+ pp_postfix_expression (pp, TREE_OPERAND (e, 0));
+ pp_c_call_argument_list (pp, TREE_OPERAND (e, 1));
break;
case ABS_EXPR:
case FFS_EXPR:
- pp_c_identifier (ppi,
+ pp_c_identifier (pp,
code == ABS_EXPR ? "__builtin_abs" : "__builtin_ffs");
- pp_c_left_paren (ppi);
- pp_c_expression (ppi, TREE_OPERAND (e, 0));
- pp_c_right_paren (ppi);
+ pp_c_left_paren (pp);
+ pp_expression (pp, TREE_OPERAND (e, 0));
+ pp_c_right_paren (pp);
break;
case COMPONENT_REF:
tree object = TREE_OPERAND (e, 0);
if (TREE_CODE (object) == INDIRECT_REF)
{
- pp_postfix_expression (ppi, TREE_OPERAND (object, 0));
- pp_c_arrow (ppi);
+ pp_postfix_expression (pp, TREE_OPERAND (object, 0));
+ pp_c_arrow (pp);
}
else
{
- pp_postfix_expression (ppi, object);
- pp_c_dot (ppi);
+ pp_postfix_expression (pp, object);
+ pp_c_dot (pp);
}
- pp_c_expression (ppi, TREE_OPERAND (e, 1));
+ pp_expression (pp, TREE_OPERAND (e, 1));
}
break;
case COMPLEX_CST:
case VECTOR_CST:
case COMPLEX_EXPR:
- pp_c_left_paren (ppi);
- pp_type_id (ppi, TREE_TYPE (e));
- pp_c_right_paren (ppi);
- pp_c_left_brace (ppi);
+ pp_c_type_cast (pp, TREE_TYPE (e));
+ pp_c_left_brace (pp);
if (code == COMPLEX_CST)
{
- pp_c_expression (ppi, TREE_REALPART (e));
- pp_separate_with (ppi, ',');
- pp_c_expression (ppi, TREE_IMAGPART (e));
+ pp_expression (pp, TREE_REALPART (e));
+ pp_separate_with (pp, ',');
+ pp_expression (pp, TREE_IMAGPART (e));
}
else if (code == VECTOR_CST)
- pp_c_expression_list (ppi, TREE_VECTOR_CST_ELTS (e));
+ pp_c_expression_list (pp, TREE_VECTOR_CST_ELTS (e));
else if (code == COMPLEX_EXPR)
{
- pp_c_expression (ppi, TREE_OPERAND (e, 0));
- pp_separate_with (ppi, ',');
- pp_c_expression (ppi, TREE_OPERAND (e, 1));
+ pp_expression (pp, TREE_OPERAND (e, 0));
+ pp_separate_with (pp, ',');
+ pp_expression (pp, TREE_OPERAND (e, 1));
}
- pp_c_right_brace (ppi);
+ pp_c_right_brace (pp);
break;
case COMPOUND_LITERAL_EXPR:
e = DECL_INITIAL (e);
/* Fall through. */
case CONSTRUCTOR:
- pp_initializer (ppi, e);
+ pp_initializer (pp, e);
break;
case VA_ARG_EXPR:
- pp_c_identifier (ppi, "__builtin_va_arg");
- pp_c_left_paren (ppi);
- pp_assignment_expression (ppi, TREE_OPERAND (e, 0));
- pp_separate_with (ppi, ',');
- pp_type_id (ppi, TREE_TYPE (e));
- pp_c_right_paren (ppi);
+ pp_c_identifier (pp, "__builtin_va_arg");
+ pp_c_left_paren (pp);
+ pp_assignment_expression (pp, TREE_OPERAND (e, 0));
+ pp_separate_with (pp, ',');
+ pp_type_id (pp, TREE_TYPE (e));
+ pp_c_right_paren (pp);
break;
case ADDR_EXPR:
if (TREE_CODE (TREE_OPERAND (e, 0)) == FUNCTION_DECL)
{
- pp_c_id_expression (ppi, TREE_OPERAND (e, 0));
+ pp_c_id_expression (pp, TREE_OPERAND (e, 0));
break;
}
/* else fall through. */
default:
- pp_primary_expression (ppi, e);
+ pp_primary_expression (pp, e);
break;
}
}
/* Print out an expression-list; E is expected to be a TREE_LIST */
void
-pp_c_expression_list (c_pretty_printer ppi, tree e)
+pp_c_expression_list (c_pretty_printer *pp, tree e)
{
for (; e != NULL_TREE; e = TREE_CHAIN (e))
{
- pp_c_assignment_expression (ppi, TREE_VALUE (e));
+ pp_expression (pp, TREE_VALUE (e));
if (TREE_CHAIN (e))
- pp_separate_with (ppi, ',');
+ pp_separate_with (pp, ',');
}
}
+/* Print out an expression-list in parens, as in a function call. */
+void
+pp_c_call_argument_list (c_pretty_printer *pp, tree t)
+{
+ pp_c_left_paren (pp);
+ if (t && TREE_CODE (t) == TREE_LIST)
+ pp_c_expression_list (pp, t);
+ pp_c_right_paren (pp);
+}
+
/* unary-expression:
postfix-expression
++ cast-expression
__real__ unary-expression
__imag__ unary-expression */
void
-pp_c_unary_expression (c_pretty_printer ppi, tree e)
+pp_c_unary_expression (c_pretty_printer *pp, tree e)
{
enum tree_code code = TREE_CODE (e);
switch (code)
{
case PREINCREMENT_EXPR:
case PREDECREMENT_EXPR:
- pp_identifier (ppi, code == PREINCREMENT_EXPR ? "++" : "--");
- pp_c_unary_expression (ppi, TREE_OPERAND (e, 0));
+ pp_identifier (pp, code == PREINCREMENT_EXPR ? "++" : "--");
+ pp_c_unary_expression (pp, TREE_OPERAND (e, 0));
break;
case ADDR_EXPR:
case CONJ_EXPR:
/* String literal are used by address. */
if (code == ADDR_EXPR && TREE_CODE (TREE_OPERAND (e, 0)) != STRING_CST)
- pp_ampersand (ppi);
+ pp_ampersand (pp);
else if (code == INDIRECT_REF)
- pp_c_star (ppi);
+ pp_c_star (pp);
else if (code == NEGATE_EXPR)
- pp_minus (ppi);
+ pp_minus (pp);
else if (code == BIT_NOT_EXPR || code == CONJ_EXPR)
- pp_complement (ppi);
+ pp_complement (pp);
else if (code == TRUTH_NOT_EXPR)
- pp_exclamation (ppi);
- pp_c_cast_expression (ppi, TREE_OPERAND (e, 0));
+ pp_exclamation (pp);
+ pp_c_cast_expression (pp, TREE_OPERAND (e, 0));
break;
case SIZEOF_EXPR:
case ALIGNOF_EXPR:
- pp_c_identifier (ppi, code == SIZEOF_EXPR ? "sizeof" : "__alignof__");
- pp_c_whitespace (ppi);
+ pp_c_identifier (pp, code == SIZEOF_EXPR ? "sizeof" : "__alignof__");
+ pp_c_whitespace (pp);
if (TYPE_P (TREE_OPERAND (e, 0)))
- {
- pp_c_left_paren (ppi);
- pp_type_id (ppi, TREE_OPERAND (e, 0));
- pp_c_right_paren (ppi);
- }
+ pp_c_type_cast (pp, TREE_OPERAND (e, 0));
else
- pp_unary_expression (ppi, TREE_OPERAND (e, 0));
+ pp_unary_expression (pp, TREE_OPERAND (e, 0));
break;
case REALPART_EXPR:
case IMAGPART_EXPR:
- pp_c_identifier (ppi, code == REALPART_EXPR ? "__real__" : "__imag__");
- pp_c_whitespace (ppi);
- pp_unary_expression (ppi, TREE_OPERAND (e, 0));
+ pp_c_identifier (pp, code == REALPART_EXPR ? "__real__" : "__imag__");
+ pp_c_whitespace (pp);
+ pp_unary_expression (pp, TREE_OPERAND (e, 0));
break;
default:
- pp_postfix_expression (ppi, e);
+ pp_postfix_expression (pp, e);
break;
}
}
+/* cast-expression:
+ unary-expression
+ ( type-name ) cast-expression */
void
-pp_c_cast_expression (c_pretty_printer ppi, tree e)
+pp_c_cast_expression (c_pretty_printer *pp, tree e)
{
switch (TREE_CODE (e))
{
case FLOAT_EXPR:
case FIX_TRUNC_EXPR:
case CONVERT_EXPR:
- pp_c_left_paren (ppi);
- pp_type_id (ppi, TREE_TYPE (e));
- pp_c_right_paren (ppi);
- pp_c_cast_expression (ppi, TREE_OPERAND (e, 0));
+ pp_c_type_cast (pp, TREE_TYPE (e));
+ pp_c_cast_expression (pp, TREE_OPERAND (e, 0));
break;
default:
- pp_unary_expression (ppi, e);
+ pp_unary_expression (pp, e);
}
}
+/* multiplicative-expression:
+ cast-expression
+ multiplicative-expression * cast-expression
+ multiplicative-expression / cast-expression
+ multiplicative-expression % cast-expression */
static void
-pp_c_multiplicative_expression (c_pretty_printer ppi, tree e)
+pp_c_multiplicative_expression (c_pretty_printer *pp, tree e)
{
enum tree_code code = TREE_CODE (e);
switch (code)
case MULT_EXPR:
case TRUNC_DIV_EXPR:
case TRUNC_MOD_EXPR:
- pp_multiplicative_expression (ppi, TREE_OPERAND (e, 0));
- pp_c_whitespace (ppi);
+ pp_multiplicative_expression (pp, TREE_OPERAND (e, 0));
+ pp_c_whitespace (pp);
if (code == MULT_EXPR)
- pp_c_star (ppi);
+ pp_c_star (pp);
else if (code == TRUNC_DIV_EXPR)
- pp_slash (ppi);
+ pp_slash (pp);
else
- pp_modulo (ppi);
- pp_c_whitespace (ppi);
- pp_c_cast_expression (ppi, TREE_OPERAND (e, 1));
+ pp_modulo (pp);
+ pp_c_whitespace (pp);
+ pp_c_cast_expression (pp, TREE_OPERAND (e, 1));
break;
default:
- pp_c_cast_expression (ppi, e);
+ pp_c_cast_expression (pp, e);
break;
}
}
+/* additive-expression:
+ multiplicative-expression
+ additive-expression + multiplicative-expression
+ additive-expression - multiplicative-expression */
static inline void
-pp_c_additive_expression (c_pretty_printer ppi, tree e)
+pp_c_additive_expression (c_pretty_printer *pp, tree e)
{
enum tree_code code = TREE_CODE (e);
switch (code)
{
case PLUS_EXPR:
case MINUS_EXPR:
- pp_c_additive_expression (ppi, TREE_OPERAND (e, 0));
- pp_c_whitespace (ppi);
+ pp_c_additive_expression (pp, TREE_OPERAND (e, 0));
+ pp_c_whitespace (pp);
if (code == PLUS_EXPR)
- pp_plus (ppi);
+ pp_plus (pp);
else
- pp_minus (ppi);
- pp_c_whitespace (ppi);
- pp_multiplicative_expression (ppi, TREE_OPERAND (e, 1));
+ pp_minus (pp);
+ pp_c_whitespace (pp);
+ pp_multiplicative_expression (pp, TREE_OPERAND (e, 1));
break;
default:
- pp_multiplicative_expression (ppi, e);
+ pp_multiplicative_expression (pp, e);
break;
}
}
+/* additive-expression:
+ additive-expression
+ shift-expression << additive-expression
+ shift-expression >> additive-expression */
static inline void
-pp_c_shift_expression (c_pretty_printer ppi, tree e)
+pp_c_shift_expression (c_pretty_printer *pp, tree e)
{
enum tree_code code = TREE_CODE (e);
switch (code)
{
case LSHIFT_EXPR:
case RSHIFT_EXPR:
- pp_c_shift_expression (ppi, TREE_OPERAND (e, 0));
- pp_c_whitespace (ppi);
- pp_identifier (ppi, code == LSHIFT_EXPR ? "<<" : ">>");
- pp_c_whitespace (ppi);
- pp_c_additive_expression (ppi, TREE_OPERAND (e, 1));
+ pp_c_shift_expression (pp, TREE_OPERAND (e, 0));
+ pp_c_whitespace (pp);
+ pp_identifier (pp, code == LSHIFT_EXPR ? "<<" : ">>");
+ pp_c_whitespace (pp);
+ pp_c_additive_expression (pp, TREE_OPERAND (e, 1));
break;
default:
- pp_c_additive_expression (ppi, e);
+ pp_c_additive_expression (pp, e);
}
}
+/* relational-expression:
+ shift-expression
+ relational-expression < shift-expression
+ relational-expression > shift-expression
+ relational-expression <= shift-expression
+ relational-expression >= shift-expression */
static void
-pp_c_relational_expression (c_pretty_printer ppi, tree e)
+pp_c_relational_expression (c_pretty_printer *pp, tree e)
{
enum tree_code code = TREE_CODE (e);
switch (code)
case GT_EXPR:
case LE_EXPR:
case GE_EXPR:
- pp_c_relational_expression (ppi, TREE_OPERAND (e, 0));
- pp_c_whitespace (ppi);
+ pp_c_relational_expression (pp, TREE_OPERAND (e, 0));
+ pp_c_whitespace (pp);
if (code == LT_EXPR)
- pp_less (ppi);
+ pp_less (pp);
else if (code == GT_EXPR)
- pp_greater (ppi);
+ pp_greater (pp);
else if (code == LE_EXPR)
- pp_identifier (ppi, "<=");
+ pp_identifier (pp, "<=");
else if (code == GE_EXPR)
- pp_identifier (ppi, ">=");
- pp_c_whitespace (ppi);
- pp_c_shift_expression (ppi, TREE_OPERAND (e, 1));
+ pp_identifier (pp, ">=");
+ pp_c_whitespace (pp);
+ pp_c_shift_expression (pp, TREE_OPERAND (e, 1));
break;
default:
- pp_c_shift_expression (ppi, e);
+ pp_c_shift_expression (pp, e);
break;
}
}
+/* equality-expression:
+ relational-expression
+ equality-expression == relational-expression
+ equality-equality != relational-expression */
static inline void
-pp_c_equality_expression (c_pretty_printer ppi, tree e)
+pp_c_equality_expression (c_pretty_printer *pp, tree e)
{
enum tree_code code = TREE_CODE (e);
switch (code)
{
case EQ_EXPR:
case NE_EXPR:
- pp_c_equality_expression (ppi, TREE_OPERAND (e, 0));
- pp_c_whitespace (ppi);
- pp_identifier (ppi, code == EQ_EXPR ? "==" : "!=");
- pp_c_whitespace (ppi);
- pp_c_relational_expression (ppi, TREE_OPERAND (e, 1));
+ pp_c_equality_expression (pp, TREE_OPERAND (e, 0));
+ pp_c_whitespace (pp);
+ pp_identifier (pp, code == EQ_EXPR ? "==" : "!=");
+ pp_c_whitespace (pp);
+ pp_c_relational_expression (pp, TREE_OPERAND (e, 1));
break;
default:
- pp_c_relational_expression (ppi, e);
+ pp_c_relational_expression (pp, e);
break;
}
}
+/* AND-expression:
+ equality-expression
+ AND-expression & equality-equality */
static inline void
-pp_c_and_expression (c_pretty_printer ppi, tree e)
+pp_c_and_expression (c_pretty_printer *pp, tree e)
{
if (TREE_CODE (e) == BIT_AND_EXPR)
{
- pp_c_and_expression (ppi, TREE_OPERAND (e, 0));
- pp_c_whitespace (ppi);
- pp_ampersand (ppi);
- pp_c_whitespace (ppi);
- pp_c_equality_expression (ppi, TREE_OPERAND (e, 1));
+ pp_c_and_expression (pp, TREE_OPERAND (e, 0));
+ pp_c_whitespace (pp);
+ pp_ampersand (pp);
+ pp_c_whitespace (pp);
+ pp_c_equality_expression (pp, TREE_OPERAND (e, 1));
}
else
- pp_c_equality_expression (ppi, e);
+ pp_c_equality_expression (pp, e);
}
+/* exclusive-OR-expression:
+ AND-expression
+ exclusive-OR-expression ^ AND-expression */
static inline void
-pp_c_exclusive_or_expression (c_pretty_printer ppi, tree e)
+pp_c_exclusive_or_expression (c_pretty_printer *pp, tree e)
{
if (TREE_CODE (e) == BIT_XOR_EXPR)
{
- pp_c_exclusive_or_expression (ppi, TREE_OPERAND (e, 0));
- pp_c_maybe_whitespace (ppi);
- pp_carret (ppi);
- pp_c_whitespace (ppi);
- pp_c_and_expression (ppi, TREE_OPERAND (e, 1));
+ pp_c_exclusive_or_expression (pp, TREE_OPERAND (e, 0));
+ pp_c_maybe_whitespace (pp);
+ pp_carret (pp);
+ pp_c_whitespace (pp);
+ pp_c_and_expression (pp, TREE_OPERAND (e, 1));
}
else
- pp_c_and_expression (ppi, e);
+ pp_c_and_expression (pp, e);
}
+/* inclusive-OR-expression:
+ exclusive-OR-expression
+ inclusive-OR-expression | exclusive-OR-expression */
static inline void
-pp_c_inclusive_or_expression (c_pretty_printer ppi, tree e)
+pp_c_inclusive_or_expression (c_pretty_printer *pp, tree e)
{
if (TREE_CODE (e) == BIT_IOR_EXPR)
{
- pp_c_exclusive_or_expression (ppi, TREE_OPERAND (e, 0));
- pp_c_whitespace (ppi);
- pp_bar (ppi);
- pp_c_whitespace (ppi);
- pp_c_exclusive_or_expression (ppi, TREE_OPERAND (e, 1));
+ pp_c_exclusive_or_expression (pp, TREE_OPERAND (e, 0));
+ pp_c_whitespace (pp);
+ pp_bar (pp);
+ pp_c_whitespace (pp);
+ pp_c_exclusive_or_expression (pp, TREE_OPERAND (e, 1));
}
else
- pp_c_exclusive_or_expression (ppi, e);
+ pp_c_exclusive_or_expression (pp, e);
}
+/* logical-AND-expression:
+ inclusive-OR-expression
+ logical-AND-expression && inclusive-OR-expression */
static inline void
-pp_c_logical_and_expression (c_pretty_printer ppi, tree e)
+pp_c_logical_and_expression (c_pretty_printer *pp, tree e)
{
if (TREE_CODE (e) == TRUTH_ANDIF_EXPR)
{
- pp_c_logical_and_expression (ppi, TREE_OPERAND (e, 0));
- pp_c_whitespace (ppi);
- pp_identifier (ppi, "&&");
- pp_c_whitespace (ppi);
- pp_c_inclusive_or_expression (ppi, TREE_OPERAND (e, 1));
+ pp_c_logical_and_expression (pp, TREE_OPERAND (e, 0));
+ pp_c_whitespace (pp);
+ pp_identifier (pp, "&&");
+ pp_c_whitespace (pp);
+ pp_c_inclusive_or_expression (pp, TREE_OPERAND (e, 1));
}
else
- pp_c_inclusive_or_expression (ppi, e);
+ pp_c_inclusive_or_expression (pp, e);
}
+/* logical-OR-expression:
+ logical-AND-expression
+ logical-OR-expression || logical-AND-expression */
void
-pp_c_logical_or_expression (c_pretty_printer ppi, tree e)
+pp_c_logical_or_expression (c_pretty_printer *pp, tree e)
{
if (TREE_CODE (e) == TRUTH_ORIF_EXPR)
{
- pp_c_logical_or_expression (ppi, TREE_OPERAND (e, 0));
- pp_c_whitespace (ppi);
- pp_identifier (ppi, "||");
- pp_c_whitespace (ppi);
- pp_c_logical_and_expression (ppi, TREE_OPERAND (e, 1));
+ pp_c_logical_or_expression (pp, TREE_OPERAND (e, 0));
+ pp_c_whitespace (pp);
+ pp_identifier (pp, "||");
+ pp_c_whitespace (pp);
+ pp_c_logical_and_expression (pp, TREE_OPERAND (e, 1));
}
else
- pp_c_logical_and_expression (ppi, e);
+ pp_c_logical_and_expression (pp, e);
}
+/* conditional-expression:
+ logical-OR-expression
+ logical-OR-expression ? expression : conditional-expression */
static void
-pp_c_conditional_expression (c_pretty_printer ppi, tree e)
+pp_c_conditional_expression (c_pretty_printer *pp, tree e)
{
if (TREE_CODE (e) == COND_EXPR)
{
- pp_c_logical_or_expression (ppi, TREE_OPERAND (e, 0));
- pp_c_whitespace (ppi);
- pp_question (ppi);
- pp_c_whitespace (ppi);
- pp_c_expression (ppi, TREE_OPERAND (e, 1));
- pp_c_maybe_whitespace (ppi);
- pp_colon (ppi);
- pp_c_whitespace (ppi);
- pp_c_conditional_expression (ppi, TREE_OPERAND (e, 2));
+ pp_c_logical_or_expression (pp, TREE_OPERAND (e, 0));
+ pp_c_whitespace (pp);
+ pp_question (pp);
+ pp_c_whitespace (pp);
+ pp_expression (pp, TREE_OPERAND (e, 1));
+ pp_c_whitespace (pp);
+ pp_colon (pp);
+ pp_c_whitespace (pp);
+ pp_c_conditional_expression (pp, TREE_OPERAND (e, 2));
}
else
- pp_c_logical_or_expression (ppi, e);
+ pp_c_logical_or_expression (pp, e);
}
-/* Pretty-print a C assignment-expression. */
+/* assignment-expression:
+ conditional-expression
+ unary-expression assignment-operator assignment-expression
+
+ assignment-expression: one of
+ = *= /= %= += -= >>= <<= &= ^= |= */
static void
-pp_c_assignment_expression (c_pretty_printer ppi, tree e)
+pp_c_assignment_expression (c_pretty_printer *pp, tree e)
{
if (TREE_CODE (e) == MODIFY_EXPR || TREE_CODE (e) == INIT_EXPR)
{
- pp_c_unary_expression (ppi, TREE_OPERAND (e, 0));
- pp_c_maybe_whitespace (ppi);
- pp_equal (ppi);
- pp_space (ppi);
- pp_c_assignment_expression (ppi, TREE_OPERAND (e, 1));
+ pp_c_unary_expression (pp, TREE_OPERAND (e, 0));
+ pp_c_whitespace (pp);
+ pp_equal (pp);
+ pp_space (pp);
+ pp_c_expression (pp, TREE_OPERAND (e, 1));
}
else
- pp_c_conditional_expression (ppi, e);
+ pp_c_conditional_expression (pp, e);
}
-/* Pretty-print an expression. */
+/* expression:
+ assignment-expression
+ expression , assignment-expression
+
+ Implementation note: instead of going through the usual recursion
+ chain, I take the liberty of dispatching nodes to the appropriate
+ functions. This makes some redundancy, but it worths it. That also
+ prevents a possible infinite recursion between pp_c_primary_expression ()
+ and pp_c_expression (). */
void
-pp_c_expression (c_pretty_printer ppi, tree e)
+pp_c_expression (c_pretty_printer *pp, tree e)
{
switch (TREE_CODE (e))
{
case INTEGER_CST:
- pp_c_integer_constant (ppi, e);
+ pp_c_integer_constant (pp, e);
break;
case REAL_CST:
- pp_c_floating_constant (ppi, e);
+ pp_c_floating_constant (pp, e);
break;
case STRING_CST:
- pp_c_string_literal (ppi, e);
+ pp_c_string_literal (pp, e);
break;
+ case IDENTIFIER_NODE:
case FUNCTION_DECL:
case VAR_DECL:
case CONST_DECL:
case FIELD_DECL:
case LABEL_DECL:
case ERROR_MARK:
- case TARGET_EXPR:
case STMT_EXPR:
- pp_primary_expression (ppi, e);
+ pp_primary_expression (pp, e);
break;
case POSTINCREMENT_EXPR:
case COMPOUND_LITERAL_EXPR:
case COMPLEX_EXPR:
case VA_ARG_EXPR:
- pp_postfix_expression (ppi, e);
+ pp_postfix_expression (pp, e);
break;
case CONJ_EXPR:
case ALIGNOF_EXPR:
case REALPART_EXPR:
case IMAGPART_EXPR:
- pp_c_unary_expression (ppi, e);
+ pp_c_unary_expression (pp, e);
break;
case FLOAT_EXPR:
case FIX_TRUNC_EXPR:
case CONVERT_EXPR:
- pp_c_cast_expression (ppi, e);
+ pp_c_cast_expression (pp, e);
break;
case MULT_EXPR:
case TRUNC_MOD_EXPR:
case TRUNC_DIV_EXPR:
- pp_multiplicative_expression (ppi, e);
+ pp_multiplicative_expression (pp, e);
break;
case LSHIFT_EXPR:
case RSHIFT_EXPR:
- pp_c_shift_expression (ppi, e);
+ pp_c_shift_expression (pp, e);
break;
case LT_EXPR:
case GT_EXPR:
case LE_EXPR:
case GE_EXPR:
- pp_c_relational_expression (ppi, e);
+ pp_c_relational_expression (pp, e);
break;
case BIT_AND_EXPR:
- pp_c_and_expression (ppi, e);
+ pp_c_and_expression (pp, e);
break;
case BIT_XOR_EXPR:
- pp_c_exclusive_or_expression (ppi, e);
+ pp_c_exclusive_or_expression (pp, e);
break;
case BIT_IOR_EXPR:
- pp_c_inclusive_or_expression (ppi, e);
+ pp_c_inclusive_or_expression (pp, e);
break;
case TRUTH_ANDIF_EXPR:
- pp_c_logical_and_expression (ppi, e);
+ pp_c_logical_and_expression (pp, e);
break;
case TRUTH_ORIF_EXPR:
- pp_c_logical_or_expression (ppi, e);
+ pp_c_logical_or_expression (pp, e);
break;
case EQ_EXPR:
case NE_EXPR:
- pp_c_equality_expression (ppi, e);
+ pp_c_equality_expression (pp, e);
break;
case COND_EXPR:
- pp_conditional_expression (ppi, e);
+ pp_conditional_expression (pp, e);
break;
case PLUS_EXPR:
case MINUS_EXPR:
- pp_c_additive_expression (ppi, e);
+ pp_c_additive_expression (pp, e);
break;
case MODIFY_EXPR:
case INIT_EXPR:
- pp_assignment_expression (ppi, e);
+ pp_assignment_expression (pp, e);
break;
case COMPOUND_EXPR:
- pp_c_left_paren (ppi);
- pp_c_expression (ppi, TREE_OPERAND (e, 0));
- pp_separate_with (ppi, ',');
- pp_assignment_expression (ppi, TREE_OPERAND (e, 1));
- pp_c_right_paren (ppi);
+ pp_c_left_paren (pp);
+ pp_expression (pp, TREE_OPERAND (e, 0));
+ pp_separate_with (pp, ',');
+ pp_assignment_expression (pp, TREE_OPERAND (e, 1));
+ pp_c_right_paren (pp);
break;
case NOP_EXPR:
case NON_LVALUE_EXPR:
case SAVE_EXPR:
case UNSAVE_EXPR:
- pp_c_expression (ppi, TREE_OPERAND (e, 0));
+ pp_expression (pp, TREE_OPERAND (e, 0));
+ break;
+
+ case TARGET_EXPR:
+ pp_postfix_expression (pp, TREE_OPERAND (e, 1));
break;
default:
- pp_unsupported_tree (ppi, e);
+ pp_unsupported_tree (pp, e);
break;
}
}
\f
/* Statements. */
+
+/* statement:
+ labeled-statement
+ coumpound-statement
+ expression-statement
+ selection-statement
+ iteration-statement
+ jump-statement */
void
-pp_c_statement (c_pretty_printer ppi, tree stmt)
+pp_c_statement (c_pretty_printer *pp, tree stmt)
{
enum tree_code code;
code = TREE_CODE (stmt);
switch (code)
{
+ /* labeled-statement:
+ identifier : statement
+ case constant-expression : statement
+ default : statement */
case LABEL_STMT:
case CASE_LABEL:
- if (pp_needs_newline (ppi))
- pp_newline_and_indent (ppi, -3);
+ if (pp_needs_newline (pp))
+ pp_newline_and_indent (pp, -3);
else
- pp_indentation (ppi) -= 3;
+ pp_indentation (pp) -= 3;
if (code == LABEL_STMT)
- pp_tree_identifier (ppi, DECL_NAME (LABEL_STMT_LABEL (stmt)));
+ pp_tree_identifier (pp, DECL_NAME (LABEL_STMT_LABEL (stmt)));
else if (code == CASE_LABEL)
{
if (CASE_LOW (stmt) == NULL_TREE)
- pp_identifier (ppi, "default");
+ pp_identifier (pp, "default");
else
{
- pp_c_identifier (ppi, "case");
- pp_c_whitespace (ppi);
- pp_conditional_expression (ppi, CASE_LOW (stmt));
+ pp_c_identifier (pp, "case");
+ pp_c_whitespace (pp);
+ pp_conditional_expression (pp, CASE_LOW (stmt));
if (CASE_HIGH (stmt))
{
- pp_identifier (ppi, "...");
- pp_conditional_expression (ppi, CASE_HIGH (stmt));
+ pp_identifier (pp, "...");
+ pp_conditional_expression (pp, CASE_HIGH (stmt));
}
}
}
- pp_colon (ppi);
- pp_indentation (ppi) += 3;
- pp_needs_newline (ppi) = true;
+ pp_colon (pp);
+ pp_indentation (pp) += 3;
+ pp_needs_newline (pp) = true;
break;
+ /* coumpound-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 (ppi))
- pp_newline_and_indent (ppi, 0);
- pp_c_left_brace (ppi);
- pp_newline_and_indent (ppi, 3);
+ if (pp_needs_newline (pp))
+ pp_newline_and_indent (pp, 0);
+ pp_c_left_brace (pp);
+ pp_newline_and_indent (pp, 3);
for (stmt = COMPOUND_BODY (stmt); stmt; stmt = TREE_CHAIN (stmt))
- pp_c_statement (ppi, stmt);
- pp_newline_and_indent (ppi, -3);
- pp_c_right_brace (ppi);
- pp_needs_newline (ppi) = true;
+ pp_statement (pp, 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 (ppi))
- pp_newline_and_indent (ppi, 0);
+ 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_c_expression (ppi, e);
+ pp_expression (pp, e);
}
- pp_c_semicolon (ppi);
- pp_needs_newline (ppi) = true;
+ 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 (ppi))
- pp_newline_and_indent (ppi, 0);
- pp_c_identifier (ppi, "if");
- pp_c_whitespace (ppi);
- pp_c_left_paren (ppi);
- pp_c_expression (ppi, IF_COND (stmt));
- pp_c_right_paren (ppi);
- pp_newline_and_indent (ppi, 3);
- pp_statement (ppi, THEN_CLAUSE (stmt));
- pp_newline_and_indent (ppi, -3);
+ 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 (ppi, "else");
+ pp_c_identifier (pp, "else");
if (TREE_CODE (else_clause) == IF_STMT)
- pp_c_whitespace (ppi);
+ pp_c_whitespace (pp);
else
- pp_newline_and_indent (ppi, 3);
- pp_statement (ppi, else_clause);
+ pp_newline_and_indent (pp, 3);
+ pp_statement (pp, else_clause);
if (TREE_CODE (else_clause) != IF_STMT)
- pp_newline_and_indent (ppi, -3);
+ pp_newline_and_indent (pp, -3);
}
break;
case SWITCH_STMT:
- if (pp_needs_newline (ppi))
- pp_newline_and_indent (ppi, 0);
- pp_c_identifier (ppi, "switch");
- pp_space (ppi);
- pp_c_left_paren (ppi);
- pp_c_expression (ppi, SWITCH_COND (stmt));
- pp_c_right_paren (ppi);
- pp_indentation (ppi) += 3;
- pp_needs_newline (ppi) = true;
- pp_statement (ppi, SWITCH_BODY (stmt));
- pp_newline_and_indent (ppi, -3);
- break;
-
+ if (pp_needs_newline (pp))
+ pp_newline_and_indent (pp, 0);
+ pp_c_identifier (pp, "switch");
+ pp_space (pp);
+ pp_c_left_paren (pp);
+ pp_expression (pp, SWITCH_COND (stmt));
+ pp_c_right_paren (pp);
+ pp_indentation (pp) += 3;
+ pp_needs_newline (pp) = true;
+ pp_statement (pp, SWITCH_BODY (stmt));
+ pp_newline_and_indent (pp, -3);
+ break;
+
+ /* iteration-statement:
+ while ( expression ) statement
+ do statement while ( expression ) ;
+ for ( expression(opt) ; expression(opt) ; expression(opt) ) statement
+ for ( declaration expression(opt) ; expression(opt) ) statement */
case WHILE_STMT:
- if (pp_needs_newline (ppi))
- pp_newline_and_indent (ppi, 0);
- pp_c_identifier (ppi, "while");
- pp_space (ppi);
- pp_c_left_paren (ppi);
- pp_c_expression (ppi, WHILE_COND (stmt));
- pp_c_right_paren (ppi);
- pp_newline_and_indent (ppi, 3);
- pp_statement (ppi, WHILE_BODY (stmt));
- pp_indentation (ppi) -= 3;
- pp_needs_newline (ppi) = true;
+ if (pp_needs_newline (pp))
+ pp_newline_and_indent (pp, 0);
+ pp_c_identifier (pp, "while");
+ pp_space (pp);
+ pp_c_left_paren (pp);
+ pp_expression (pp, WHILE_COND (stmt));
+ pp_c_right_paren (pp);
+ pp_newline_and_indent (pp, 3);
+ pp_statement (pp, WHILE_BODY (stmt));
+ pp_indentation (pp) -= 3;
+ pp_needs_newline (pp) = true;
break;
case DO_STMT:
- if (pp_needs_newline (ppi))
- pp_newline_and_indent (ppi, 0);
- pp_c_identifier (ppi, "do");
- pp_newline_and_indent (ppi, 3);
- pp_statement (ppi, DO_BODY (stmt));
- pp_newline_and_indent (ppi, -3);
- pp_c_identifier (ppi, "while");
- pp_space (ppi);
- pp_c_left_paren (ppi);
- pp_c_expression (ppi, DO_COND (stmt));
- pp_c_right_paren (ppi);
- pp_c_semicolon (ppi);
- pp_needs_newline (ppi) = true;
+ 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));
+ pp_newline_and_indent (pp, -3);
+ pp_c_identifier (pp, "while");
+ pp_space (pp);
+ pp_c_left_paren (pp);
+ pp_expression (pp, DO_COND (stmt));
+ pp_c_right_paren (pp);
+ pp_c_semicolon (pp);
+ pp_needs_newline (pp) = true;
break;
case FOR_STMT:
- if (pp_needs_newline (ppi))
- pp_newline_and_indent (ppi, 0);
- pp_c_identifier (ppi, "for");
- pp_space (ppi);
- pp_c_left_paren (ppi);
+ if (pp_needs_newline (pp))
+ pp_newline_and_indent (pp, 0);
+ pp_c_identifier (pp, "for");
+ pp_space (pp);
+ pp_c_left_paren (pp);
if (FOR_INIT_STMT (stmt))
- pp_statement (ppi, FOR_INIT_STMT (stmt));
+ pp_statement (pp, FOR_INIT_STMT (stmt));
else
- pp_c_semicolon (ppi);
- pp_needs_newline (ppi) = false;
- pp_c_whitespace (ppi);
+ pp_c_semicolon (pp);
+ pp_needs_newline (pp) = false;
+ pp_c_whitespace (pp);
if (FOR_COND (stmt))
- pp_c_expression (ppi, FOR_COND (stmt));
- pp_c_semicolon (ppi);
- pp_needs_newline (ppi) = false;
- pp_c_whitespace (ppi);
+ pp_expression (pp, FOR_COND (stmt));
+ pp_c_semicolon (pp);
+ pp_needs_newline (pp) = false;
+ pp_c_whitespace (pp);
if (FOR_EXPR (stmt))
- pp_c_expression (ppi, FOR_EXPR (stmt));
- pp_c_right_paren (ppi);
- pp_newline_and_indent (ppi, 3);
- pp_statement (ppi, FOR_BODY (stmt));
- pp_indentation (ppi) -= 3;
- pp_needs_newline (ppi) = true;
- break;
-
+ pp_expression (pp, FOR_EXPR (stmt));
+ pp_c_right_paren (pp);
+ pp_newline_and_indent (pp, 3);
+ pp_statement (pp, FOR_BODY (stmt));
+ pp_indentation (pp) -= 3;
+ pp_needs_newline (pp) = true;
+ break;
+
+ /* jump-statement:
+ goto identifier;
+ continue ;
+ return expression(opt) ; */
case BREAK_STMT:
case CONTINUE_STMT:
- if (pp_needs_newline (ppi))
- pp_newline_and_indent (ppi, 0);
- pp_identifier (ppi, code == BREAK_STMT ? "break" : "continue");
- pp_c_semicolon (ppi);
- pp_needs_newline (ppi) = true;
+ 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 = code == RETURN_STMT
? RETURN_STMT_EXPR (stmt)
: GOTO_DESTINATION (stmt);
- if (pp_needs_newline (ppi))
- pp_newline_and_indent (ppi, 0);
- pp_c_identifier (ppi, code == RETURN_STMT ? "return" : "goto");
+ if (pp_needs_newline (pp))
+ pp_newline_and_indent (pp, 0);
+ pp_c_identifier (pp, code == RETURN_STMT ? "return" : "goto");
+ pp_c_whitespace (pp);
if (e)
- pp_c_expression (ppi, e);
- pp_c_semicolon (ppi);
- pp_needs_newline (ppi) = true;
+ {
+ 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;
if (!SCOPE_NULLIFIED_P (stmt) && SCOPE_NO_CLEANUPS_P (stmt))
{
int i = 0;
- if (pp_needs_newline (ppi))
- pp_newline_and_indent (ppi, 0);
+ if (pp_needs_newline (pp))
+ pp_newline_and_indent (pp, 0);
if (SCOPE_BEGIN_P (stmt))
{
- pp_left_brace (ppi);
+ pp_left_brace (pp);
i = 3;
}
else if (SCOPE_END_P (stmt))
{
- pp_right_brace (ppi);
+ pp_right_brace (pp);
i = -3;
}
- pp_indentation (ppi) += i;
- pp_needs_newline (ppi) = true;
+ pp_indentation (pp) += i;
+ pp_needs_newline (pp) = true;
}
break;
case DECL_STMT:
- if (pp_needs_newline (ppi))
- pp_newline_and_indent (ppi, 0);
- pp_declaration (ppi, DECL_STMT_DECL (stmt));
- pp_c_semicolon (ppi);
- pp_needs_newline (ppi) = true;
+ if (pp_needs_newline (pp))
+ pp_newline_and_indent (pp, 0);
+ pp_declaration (pp, DECL_STMT_DECL (stmt));
+ pp_needs_newline (pp) = true;
break;
case ASM_STMT:
bool has_volatile_p = ASM_VOLATILE_P (stmt);
bool is_extended = has_volatile_p || ASM_INPUTS (stmt)
|| ASM_OUTPUTS (stmt) || ASM_CLOBBERS (stmt);
- pp_c_identifier (ppi, is_extended ? "__asm__" : "asm");
+ pp_c_identifier (pp, is_extended ? "__asm__" : "asm");
if (has_volatile_p)
- pp_c_identifier (ppi, "__volatile__");
- pp_space (ppi);
- pp_c_left_paren (ppi);
- pp_c_string_literal (ppi, ASM_STRING (stmt));
+ pp_c_identifier (pp, "__volatile__");
+ pp_space (pp);
+ pp_c_left_paren (pp);
+ pp_c_string_literal (pp, ASM_STRING (stmt));
if (is_extended)
{
- pp_space (ppi);
- pp_separate_with (ppi, ':');
+ pp_space (pp);
+ pp_separate_with (pp, ':');
if (ASM_OUTPUTS (stmt))
- pp_c_expression (ppi, ASM_OUTPUTS (stmt));
- pp_space (ppi);
- pp_separate_with (ppi, ':');
+ pp_expression (pp, ASM_OUTPUTS (stmt));
+ pp_space (pp);
+ pp_separate_with (pp, ':');
if (ASM_INPUTS (stmt))
- pp_c_expression (ppi, ASM_INPUTS (stmt));
- pp_space (ppi);
- pp_separate_with (ppi, ':');
+ pp_expression (pp, ASM_INPUTS (stmt));
+ pp_space (pp);
+ pp_separate_with (pp, ':');
if (ASM_CLOBBERS (stmt))
- pp_c_expression (ppi, ASM_CLOBBERS (stmt));
+ pp_expression (pp, ASM_CLOBBERS (stmt));
}
- pp_c_right_paren (ppi);
- pp_newline (ppi);
+ pp_c_right_paren (pp);
+ pp_newline (pp);
}
break;
case FILE_STMT:
- pp_c_identifier (ppi, "__FILE__");
- pp_space (ppi);
- pp_equal (ppi);
- pp_c_whitespace (ppi);
- pp_c_identifier (ppi, FILE_STMT_FILENAME (stmt));
- pp_c_semicolon (ppi);
- pp_needs_newline (ppi) = true;
+ pp_c_identifier (pp, "__FILE__");
+ pp_space (pp);
+ pp_equal (pp);
+ pp_c_whitespace (pp);
+ pp_c_identifier (pp, FILE_STMT_FILENAME (stmt));
+ pp_c_semicolon (pp);
+ pp_needs_newline (pp) = true;
break;
default:
- pp_unsupported_tree (ppi, stmt);
+ pp_unsupported_tree (pp, stmt);
}
-
}
\f
/* Initialize the PRETTY-PRINTER for handling C codes. */
void
-pp_c_pretty_printer_init (c_pretty_printer pp)
+pp_c_pretty_printer_init (c_pretty_printer *pp)
{
pp->offset_list = 0;
pp->declaration_specifiers = pp_c_declaration_specifiers;
pp->declarator = pp_c_declarator;
pp->direct_declarator = pp_c_direct_declarator;
- pp->type_specifier = pp_c_simple_type_specifier;
+ pp->type_specifier_seq = pp_c_specifier_qualifier_list;
pp->abstract_declarator = pp_c_abstract_declarator;
- pp->parameter_declaration = pp_c_parameter_declaration;
+ pp->direct_abstract_declarator = pp_c_direct_abstract_declarator;
+ pp->ptr_operator = pp_c_pointer;
+ pp->parameter_list = pp_c_parameter_type_list;
pp->type_id = pp_c_type_id;
+ pp->simple_type_specifier = pp_c_type_specifier;
pp->function_specifier = pp_c_function_specifier;
pp->storage_class_specifier = pp_c_storage_class_specifier;
pp->multiplicative_expression = pp_c_multiplicative_expression;
pp->conditional_expression = pp_c_conditional_expression;
pp->assignment_expression = pp_c_assignment_expression;
+ pp->expression = pp_c_expression;
}
#include "real.h"
#include "cxx-pretty-print.h"
#include "cp-tree.h"
+#include "toplev.h"
static void pp_cxx_unqualified_id (cxx_pretty_printer *, tree);
+static void pp_cxx_nested_name_specifier (cxx_pretty_printer *, tree);
static void pp_cxx_qualified_id (cxx_pretty_printer *, tree);
static void pp_cxx_assignment_expression (cxx_pretty_printer *, tree);
+static void pp_cxx_expression (cxx_pretty_printer *, tree);
static void pp_cxx_template_argument_list (cxx_pretty_printer *, tree);
+static void pp_cxx_type_specifier_seq (cxx_pretty_printer *, tree);
+static void pp_cxx_ptr_operator (cxx_pretty_printer *, tree);
+static void pp_cxx_type_id (cxx_pretty_printer *, tree);
+static void pp_cxx_direct_abstract_declarator (cxx_pretty_printer *, tree);
+static void pp_cxx_declarator (cxx_pretty_printer *, tree);
+static void pp_cxx_abstract_declarator (cxx_pretty_printer *, tree);
+static void pp_cxx_template_parameter (cxx_pretty_printer *, tree);
\f
+#define pp_cxx_whitespace(PP) pp_c_whitespace (pp_c_base (PP))
+#define pp_cxx_left_paren(PP) pp_c_left_paren (pp_c_base (PP))
+#define pp_cxx_right_paren(PP) pp_c_right_paren (pp_c_base (PP))
+#define pp_cxx_dot(PP) pp_c_dot (pp_c_base (PP))
+#define pp_cxx_arrow(PP) pp_c_arrow (pp_c_base (PP))
+#define pp_cxx_semicolon(PP) pp_c_semicolon (pp_c_base (PP))
static inline void
pp_cxx_nonconsecutive_character (cxx_pretty_printer *pp, int c)
const char *p = pp_last_position_in_text (pp);
if (p != NULL && *p == c)
- pp_space (pp);
+ pp_cxx_whitespace (pp);
pp_character (pp, c);
+ pp_base (pp)->padding = pp_none;
}
#define pp_cxx_begin_template_argument_list(PP) \
#define pp_cxx_end_template_argument_list(PP) \
pp_cxx_nonconsecutive_character (PP, '>')
-/* Declarations. */
-
-void
-pp_cxx_declaration (cxx_pretty_printer *pp, tree t)
-{
- pp_unsupported_tree (pp, t);
-}
-
-static void
-pp_cxx_declaration_specifiers (cxx_pretty_printer *pp, tree t)
-{
- pp_unsupported_tree (pp, t);
-}
-/* type-specifier:
- simple-type-specifier
- class-specifier
- enum-specifier
- elaborated-type-specifier
- cv-qualifer */
+#define pp_cxx_identifier(PP, ID) pp_c_identifier (pp_c_base (PP), ID)
+#define pp_cxx_tree_identifier(PP, T) pp_c_tree_identifier (pp_c_base (PP), T)
+
+#define pp_cxx_cv_qualifier_seq(PP, T) \
+ pp_c_type_qualifier_list (pp_c_base (PP), T)
+#define pp_cxx_storage_class_specifier(PP, T) \
+ pp_c_storage_class_specifier (pp_c_base (PP), T)
+#define pp_cxx_expression_list(PP, T) \
+ pp_c_expression_list (pp_c_base (PP), T)
+#define pp_cxx_space_for_pointer_operator(PP, T) \
+ pp_c_space_for_pointer_operator (pp_c_base (PP), T)
+#define pp_cxx_init_declarator(PP, T) \
+ pp_c_init_declarator (pp_c_base (PP), T)
+#define pp_cxx_call_argument_list(PP, T) \
+ pp_c_call_argument_list (pp_c_base (PP), T)
static void
-pp_cxx_type_specifier (cxx_pretty_printer *pp, tree t)
+pp_cxx_colon_colon (cxx_pretty_printer *pp)
{
- pp_c_type_qualifier_list (pp_c_base (pp), t);
-
- switch (TREE_CODE (t))
- {
- case TEMPLATE_DECL:
- case TYPE_DECL:
- if (pp->enclosing_scope != DECL_CONTEXT (t))
- pp_cxx_qualified_id (pp, t);
- else
- pp_cxx_unqualified_id (pp, t);
- break;
-
- case TYPEOF_TYPE:
- pp_c_identifier (pp_c_base (pp), "__typeof__");
- pp_left_paren (pp);
- pp_c_expression (pp_c_base (pp), TYPE_FIELDS (t));
- pp_right_paren (pp);
- break;
-
- default:
- pp_c_specifier_qualifier_list (pp_c_base (pp), t);
- }
+ pp_colon_colon (pp);
+ pp_base (pp)->padding = pp_none;
}
-static void
-pp_cxx_declarator (cxx_pretty_printer *pp, tree t)
-{
- switch (TREE_CODE (t))
- {
- default:
- pp_c_declarator (pp_c_base (pp), t);
- break;
- }
-}
-static void
-pp_cxx_direct_declarator (cxx_pretty_printer *pp, tree t)
-{
- pp_c_direct_declarator (pp_c_base (pp), t);
-}
+/* Expressions. */
-static void
-pp_cxx_parameter_declaration (cxx_pretty_printer *pp, tree t)
+static inline bool
+is_destructor_name (tree name)
{
- pp_unsupported_tree (pp, t);
+ return name == complete_dtor_identifier
+ || name == base_dtor_identifier
+ || name == deleting_dtor_identifier;
}
+/* conversion-function-id:
+ operator conversion-type-id
+ conversion-type-id:
+ type-specifier-seq conversion-declarator(opt)
-/* type-id:
- type-specifier-seq abstract-declarator(opt) */
-static void
-pp_cxx_type_id (cxx_pretty_printer *pp, tree t)
+ conversion-declarator:
+ ptr-operator conversion-declarator(opt) */
+static inline void
+pp_cxx_conversion_function_id (cxx_pretty_printer *pp, tree t)
{
- pp_flags saved_flags = pp_c_base (pp)->flags;
- pp_c_base (pp)->flags |= pp_c_flag_abstract;
-
- switch (TREE_CODE (t))
- {
- case TYPE_DECL:
- case UNION_TYPE:
- case RECORD_TYPE:
- case ENUMERAL_TYPE:
- case TYPENAME_TYPE:
- case BOUND_TEMPLATE_TEMPLATE_PARM:
- case UNBOUND_CLASS_TEMPLATE:
- case TEMPLATE_TEMPLATE_PARM:
- case TEMPLATE_TYPE_PARM:
- case TEMPLATE_PARM_INDEX:
- case TEMPLATE_DECL:
- case TYPEOF_TYPE:
- case TEMPLATE_ID_EXPR:
- /* FIXME: Should be pp_cxx_type_specifier_seq. */
- pp_cxx_type_specifier (pp, t);
- pp_cxx_declarator (pp, t);
- break;
-
- default:
- pp_c_type_id (pp_c_base (pp), t);
- break;
- }
-
- pp_c_base (pp)->flags = saved_flags;
+ pp_cxx_identifier (pp, "operator");
+ pp_cxx_type_specifier_seq (pp, TREE_TYPE (t));
}
-static void
-pp_cxx_initializer (cxx_pretty_printer *pp, tree t)
+static inline void
+pp_cxx_template_id (cxx_pretty_printer *pp, tree t)
{
- pp_unsupported_tree (pp, t);
+ pp_cxx_unqualified_id (pp, TREE_OPERAND (t, 0));
+ pp_cxx_begin_template_argument_list (pp);
+ pp_cxx_template_argument_list (pp, TREE_OPERAND (t, 1));
+ pp_cxx_end_template_argument_list (pp);
}
-/* template-argument-list:
- template-argument
- template-argument-list, template-argument
-
- template-argument:
- assignment-expression
- type-id
- template-name */
static void
-pp_cxx_template_argument_list (cxx_pretty_printer *pp, tree t)
-{
- int i;
- if (t == NULL)
- return;
- for (i = 0; i < TREE_VEC_LENGTH (t); ++i)
- {
- tree arg = TREE_VEC_ELT (t, i);
- if (i != 0)
- pp_separate_with (pp, ',');
- if (TYPE_P (arg) || (TREE_CODE (arg) == TEMPLATE_DECL
- && TYPE_P (DECL_TEMPLATE_RESULT (arg))))
- pp_cxx_type_id (pp, arg);
- else
- pp_c_expression (pp_c_base (pp), arg);
- }
-}
-
-
-/* Statements. */
-
-void
-pp_cxx_statement (cxx_pretty_printer *pp, tree t)
-{
- pp_unsupported_tree (pp, t);
-}
-
-/* Expressions. */
-
-static inline bool
-is_destructor_name (tree name)
+pp_cxx_class_name (cxx_pretty_printer *pp, tree t)
{
- return name == complete_dtor_identifier
- || name == base_dtor_identifier
- || name == deleting_dtor_identifier;
+ pp_cxx_unqualified_id (pp, TYPE_NAME (t));
}
/* unqualified-id:
enum tree_code code = TREE_CODE (t);
switch (code)
{
+ case RESULT_DECL:
+ pp_cxx_identifier (pp, "<return-value>");
+ break;
+
+ case OVERLOAD:
+ t = OVL_CURRENT (t);
case VAR_DECL:
case PARM_DECL:
case CONST_DECL:
case FIELD_DECL:
case LABEL_DECL:
case USING_DECL:
+ case TEMPLATE_DECL:
t = DECL_NAME (t);
case IDENTIFIER_NODE:
- if (IDENTIFIER_TYPENAME_P (t))
- {
- pp_c_identifier (pp_c_base (pp), "operator");
- /* FIXME: should be pp_cxx_type_specifier_seq */
- pp_cxx_type_specifier (pp, TREE_TYPE (t));
- /* FIXME: should be pp_cxx_conversion_declarator. */
- pp_cxx_type_id (pp, TREE_TYPE (t));
- }
- else if (IDENTIFIER_OPNAME_P (t))
- {
- const char *name = operator_name_info[TREE_CODE (t)].name;
- pp_c_identifier (pp_c_base (pp), "operator");
- if (ISALPHA (name[0]))
- pp_space (pp);
- pp_base (pp)->padding = pp_none;
- pp_c_identifier (pp_c_base (pp), name);
- }
+ if (t == NULL)
+ pp_cxx_identifier (pp, "<anonymous>");
+ else if (IDENTIFIER_TYPENAME_P (t))
+ pp_cxx_conversion_function_id (pp, t);
else
{
if (is_destructor_name (t))
{
pp_complement (pp);
- t = constructor_name (TREE_TYPE (t));
+ /* FIXME: Why is this necessary? */
+ if (TREE_TYPE (t))
+ t = constructor_name (TREE_TYPE (t));
}
- pp_c_tree_identifier (pp_c_base (pp), t);
+ pp_cxx_tree_identifier (pp, t);
}
break;
case TEMPLATE_ID_EXPR:
- pp_cxx_unqualified_id (pp, TREE_OPERAND (t, 0));
- pp_less (pp);
- pp_cxx_template_argument_list (pp, TREE_OPERAND (t, 1));
- pp_greater (pp);
+ pp_cxx_template_id (pp, t);
+ break;
+
+ case RECORD_TYPE:
+ case UNION_TYPE:
+ case ENUMERAL_TYPE:
+ pp_cxx_unqualified_id (pp, TYPE_NAME (t));
+ break;
+
+ case TEMPLATE_TYPE_PARM:
+ t = TYPE_FIELDS (t);
+ case TEMPLATE_PARM_INDEX:
+ pp_cxx_unqualified_id (pp, TEMPLATE_PARM_DECL (t));
break;
default:
pp_unsupported_tree (pp, t);
+ break;
+ }
+}
+
+static inline void
+pp_cxx_template_keyword_if_needed (cxx_pretty_printer *pp, tree scope, tree t)
+{
+ if (TREE_CODE (t) == TEMPLATE_ID_EXPR
+ && TYPE_P (scope) && dependent_type_p (scope))
+ pp_cxx_identifier (pp, "template");
+}
+
+/* nested-name-specifier:
+ class-or-namespace-name :: nested-name-specifier(opt)
+ class-or-namespace-name :: template nested-name-specifier */
+static void
+pp_cxx_nested_name_specifier (cxx_pretty_printer *pp, tree t)
+{
+ if (t != NULL && t != pp->enclosing_scope)
+ {
+ tree scope = TYPE_P (t) ? TYPE_CONTEXT (t) : DECL_CONTEXT (t);
+ pp_cxx_nested_name_specifier (pp, scope);
+ pp_cxx_template_keyword_if_needed (pp, scope, t);
+ pp_cxx_unqualified_id (pp, t);
+ pp_cxx_colon_colon (pp);
}
}
switch (TREE_CODE (t))
{
case PTRMEM_CST:
- pp_cxx_qualified_id (pp, PTRMEM_CST_CLASS (t));
- pp_colon_colon (pp);
+ pp_cxx_nested_name_specifier (pp, PTRMEM_CST_CLASS (t));
pp_cxx_unqualified_id (pp, PTRMEM_CST_MEMBER (t));
break;
+ case OVERLOAD:
+ t = OVL_CURRENT (t);
+ case FUNCTION_DECL:
+ if (DECL_FUNCTION_MEMBER_P (t))
+ pp_cxx_nested_name_specifier (pp, DECL_CONTEXT (t));
+ pp_cxx_unqualified_id
+ (pp, DECL_CONSTRUCTOR_P (t) ? DECL_CONTEXT (t) : t);
+ break;
+
case OFFSET_REF:
case SCOPE_REF:
- pp_cxx_qualified_id (pp, TREE_OPERAND (t, 0));
- pp_colon_colon (pp);
+ pp_cxx_nested_name_specifier (pp, TREE_OPERAND (t, 0));
pp_cxx_unqualified_id (pp, TREE_OPERAND (t, 1));
break;
default:
{
- tree scope = DECL_CONTEXT (t);
- if (scope == pp->enclosing_scope)
- pp_cxx_unqualified_id (pp, t);
- else
+ tree scope = TYPE_P (t) ? TYPE_CONTEXT (t) : DECL_CONTEXT (t);
+ if (scope != pp->enclosing_scope)
{
- pp_cxx_qualified_id (pp, scope);
- pp_colon_colon (pp);
- if (TYPE_P (scope) && dependent_type_p (scope)
- && TREE_CODE (t) == TEMPLATE_DECL)
- pp_c_identifier (pp_c_base (pp), "template");
- pp_cxx_unqualified_id (pp, t);
+ pp_cxx_nested_name_specifier (pp, scope);
+ pp_cxx_template_keyword_if_needed (pp, scope, t);
}
+ pp_cxx_unqualified_id (pp, t);
}
break;
}
static inline void
pp_cxx_id_expression (cxx_pretty_printer *pp, tree t)
{
- if (pp_c_base (pp)->flags
- & (pp_cxx_flag_qualified_id | pp_cxx_flag_global_scope))
+ if (TREE_CODE (t) == OVERLOAD)
+ t = OVL_CURRENT (t);
+ if ((TREE_CODE (t) == FUNCTION_DECL && DECL_FUNCTION_MEMBER_P (t))
+ || (pp_c_base (pp)->flags
+ & (pp_cxx_flag_qualified_id | pp_cxx_flag_global_scope)))
pp_cxx_qualified_id (pp, t);
else
pp_cxx_unqualified_id (pp, t);
pp_c_constant (pp_c_base (pp), t);
break;
+ case BASELINK:
+ t = BASELINK_FUNCTIONS (t);
+ case VAR_DECL:
+ case PARM_DECL:
+ case FIELD_DECL:
+ case FUNCTION_DECL:
+ case OVERLOAD:
+ case CONST_DECL:
+ case TEMPLATE_DECL:
+ pp_cxx_id_expression (pp, t);
+ break;
+
+ case RESULT_DECL:
+ case TEMPLATE_TYPE_PARM:
+ case TEMPLATE_PARM_INDEX:
+ pp_cxx_unqualified_id (pp, t);
+ break;
+
default:
- if (pp_c_base (pp)->flags & pp_cxx_flag_qualified_id)
- pp_cxx_qualified_id (pp, t);
- else
- {
- if (pp_c_base (pp)->flags & pp_cxx_flag_global_scope)
- pp_colon_colon (pp);
- pp_cxx_unqualified_id (pp, t);
- }
+ pp_c_primary_expression (pp_c_base (pp), t);
break;
}
}
switch (code)
{
+ case AGGR_INIT_EXPR:
+ case CALL_EXPR:
+ {
+ tree fun = TREE_OPERAND (t, 0);
+ tree args = TREE_OPERAND (t, 1);
+ tree saved_scope = pp->enclosing_scope;
+
+ if (TREE_CODE (fun) == ADDR_EXPR)
+ fun = TREE_OPERAND (fun, 0);
+
+ /* In templates, where there is no way to tell whether a given
+ call uses an actual member function. So the parser builds
+ FUN as a COMPONENT_REF or a plain IDENTIFIER_NODE until
+ instantiation time. */
+ if (TREE_CODE (fun) != FUNCTION_DECL)
+ ;
+ else if (DECL_NONSTATIC_MEMBER_FUNCTION_P (fun))
+ {
+ tree object = code == AGGR_INIT_EXPR && AGGR_INIT_VIA_CTOR_P (t)
+ ? TREE_OPERAND (t, 2)
+ : TREE_VALUE (args);
+
+ while (TREE_CODE (object) == NOP_EXPR)
+ object = TREE_OPERAND (object, 0);
+
+ if (TREE_CODE (object) == ADDR_EXPR)
+ object = TREE_OPERAND (object, 0);
+
+ if (TREE_CODE (TREE_TYPE (object)) != POINTER_TYPE)
+ {
+ pp_cxx_postfix_expression (pp, object);
+ pp_cxx_dot (pp);
+ }
+ else
+ {
+ pp_cxx_postfix_expression (pp, object);
+ pp_cxx_arrow (pp);
+ }
+ args = TREE_CHAIN (args);
+ pp->enclosing_scope = strip_pointer_operator (TREE_TYPE (object));
+ }
+
+ pp_cxx_postfix_expression (pp, fun);
+ pp->enclosing_scope = saved_scope;
+ pp_cxx_call_argument_list (pp, args);
+ }
+ if (code == AGGR_INIT_EXPR && AGGR_INIT_VIA_CTOR_P (t))
+ {
+ pp_separate_with (pp, ',');
+ pp_cxx_postfix_expression (pp, TREE_OPERAND (t, 2));
+ }
+ break;
+
+ case BASELINK:
+ case VAR_DECL:
+ case PARM_DECL:
+ case FIELD_DECL:
+ case FUNCTION_DECL:
+ case OVERLOAD:
+ case CONST_DECL:
+ case TEMPLATE_DECL:
+ case RESULT_DECL:
+ pp_cxx_primary_expression (pp, t);
+ break;
+
case DYNAMIC_CAST_EXPR:
case STATIC_CAST_EXPR:
case REINTERPRET_CAST_EXPR:
pp_cxx_type_id (pp, TREE_TYPE (t));
pp_cxx_end_template_argument_list (pp);
pp_left_paren (pp);
- pp_c_expression (pp_c_base (pp), TREE_OPERAND (t, 0));
+ pp_cxx_expression (pp, TREE_OPERAND (t, 0));
pp_right_paren (pp);
break;
case TYPEID_EXPR:
t = TREE_OPERAND (t, 0);
- pp_c_identifier (pp_c_base (pp), "typeid");
+ pp_cxx_identifier (pp, "typeid");
pp_left_paren (pp);
if (TYPE_P (t))
pp_cxx_type_id (pp, t);
else
- pp_c_expression (pp_c_base (pp), t);
+ pp_cxx_expression (pp, t);
pp_right_paren (pp);
break;
case PSEUDO_DTOR_EXPR:
pp_cxx_postfix_expression (pp, TREE_OPERAND (t, 0));
- pp_dot (pp);
+ pp_cxx_dot (pp);
pp_cxx_qualified_id (pp, TREE_OPERAND (t, 1));
- pp_colon_colon (pp);
+ pp_cxx_colon_colon (pp);
pp_complement (pp);
pp_cxx_unqualified_id (pp, TREE_OPERAND (t, 2));
break;
case NEW_EXPR:
case VEC_NEW_EXPR:
if (NEW_EXPR_USE_GLOBAL (t))
- pp_colon_colon (pp);
- pp_c_identifier (pp_c_base (pp), "new");
+ pp_cxx_colon_colon (pp);
+ pp_cxx_identifier (pp, "new");
if (TREE_OPERAND (t, 0))
{
- pp_left_paren (pp);
- pp_c_expression_list (pp_c_base (pp), TREE_OPERAND (t, 0));
- pp_right_paren (pp);
+ pp_cxx_call_argument_list (pp, TREE_OPERAND (t, 0));
pp_space (pp);
}
/* FIXME: array-types are built with one more element. */
else if (t == void_zero_node)
; /* OK, empty initializer list. */
else
- pp_c_expression (pp_c_base (pp), t);
+ pp_cxx_expression (pp, t);
pp_right_paren (pp);
}
break;
case DELETE_EXPR:
case VEC_DELETE_EXPR:
if (DELETE_EXPR_USE_GLOBAL (t))
- pp_colon_colon (pp);
- pp_c_identifier (pp_c_base (pp), "delete");
+ pp_cxx_colon_colon (pp);
+ pp_cxx_identifier (pp, "delete");
if (code == VEC_DELETE_EXPR)
{
pp_left_bracket (pp);
}
}
+/* cast-expression:
+ unary-expression
+ ( type-id ) cast-expression */
+static void
+pp_cxx_cast_expression (cxx_pretty_printer *pp, tree t)
+{
+ switch (TREE_CODE (t))
+ {
+ case CAST_EXPR:
+ pp_cxx_type_id (pp, TREE_TYPE (t));
+ pp_cxx_call_argument_list (pp, TREE_OPERAND (t, 0));
+ break;
+
+ default:
+ pp_c_cast_expression (pp_c_base (pp), t);
+ break;
+ }
+}
+
/* pm-expression:
cast-expression
pm-expression .* cast-expression
case MEMBER_REF:
case DOTSTAR_EXPR:
pp_cxx_pm_expression (pp, TREE_OPERAND (t, 0));
- pp_dot (pp);
+ pp_cxx_dot (pp);
pp_star(pp);
- pp_c_cast_expression (pp_c_base (pp), TREE_OPERAND (t, 1));
+ pp_cxx_cast_expression (pp, TREE_OPERAND (t, 1));
break;
default:
- pp_c_cast_expression (pp_c_base (pp), t);
+ pp_cxx_cast_expression (pp, t);
break;
}
}
}
}
-
/* conditional-expression:
logical-or-expression
logical-or-expression ? expression : assignment-expression */
pp_space (pp);
pp_question (pp);
pp_space (pp);
- pp_c_expression (pp_c_base (pp), TREE_OPERAND (e, 1));
+ pp_cxx_expression (pp, TREE_OPERAND (e, 1));
pp_space (pp);
pp_cxx_assignment_expression (pp, TREE_OPERAND (e, 2));
}
pp_c_logical_or_expression (pp_c_base (pp), e);
}
+static void
+pp_cxx_assignment_operator (cxx_pretty_printer *pp, tree t)
+{
+ const char *op;
+
+ switch (TREE_CODE (t))
+ {
+ case NOP_EXPR:
+ op = "=";
+ break;
+
+ case PLUS_EXPR:
+ op = "+=";
+ break;
+
+ case MINUS_EXPR:
+ op = "-=";
+ break;
+
+ case TRUNC_DIV_EXPR:
+ op = "/=";
+ break;
+
+ case TRUNC_MOD_EXPR:
+ op = "%=";
+ break;
+
+ default:
+ op = tree_code_name[TREE_CODE (t)];
+ break;
+ }
+
+ pp_cxx_identifier (pp, op);
+}
+
+
/* assignment-expression:
conditional-expression
logical-or-expression assignment-operator assignment-expression
+ throw-expression
+
+ throw-expression:
+ throw assignment-expression(opt)
- assignment-expression: one of
+ assignment-operator: one of
= *= /= %= += -= >>= <<= &= ^= |= */
static void
pp_cxx_assignment_expression (cxx_pretty_printer *pp, tree e)
{
- if (TREE_CODE (e) == MODIFY_EXPR)
+ switch (TREE_CODE (e))
{
+ case MODIFY_EXPR:
+ case INIT_EXPR:
pp_c_logical_or_expression (pp_c_base (pp), TREE_OPERAND (e, 0));
pp_space (pp);
pp_equal (pp);
pp_space (pp);
pp_cxx_assignment_expression (pp, TREE_OPERAND (e, 1));
- }
- else
- pp_cxx_conditional_expression (pp, e);
-}
+ break;
+ case THROW_EXPR:
+ pp_cxx_identifier (pp, "throw");
+ if (TREE_OPERAND (e, 0))
+ pp_cxx_assignment_expression (pp, TREE_OPERAND (e, 0));
+ break;
-\f
-typedef c_pretty_print_fn pp_fun;
+ case MODOP_EXPR:
+ pp_c_logical_or_expression (pp_c_base (pp), TREE_OPERAND (e, 0));
+ pp_cxx_assignment_operator (pp, TREE_OPERAND (e, 1));
+ pp_cxx_assignment_expression (pp, TREE_OPERAND (e, 2));
+ break;
-void
-pp_cxx_pretty_printer_init (cxx_pretty_printer *pp)
-{
- pp_c_pretty_printer_init (pp_c_base (pp));
+ default:
+ pp_cxx_conditional_expression (pp, e);
+ break;
+ }
+}
+
+static void
+pp_cxx_expression (cxx_pretty_printer *pp, tree t)
+{
+ switch (TREE_CODE (t))
+ {
+ case STRING_CST:
+ case INTEGER_CST:
+ case REAL_CST:
+ pp_c_constant (pp_c_base (pp), t);
+ break;
+
+ case RESULT_DECL:
+ pp_cxx_unqualified_id (pp, t);
+ break;
+
+#if 0
+ case OFFSET_REF:
+#endif
+ case SCOPE_REF:
+ case PTRMEM_CST:
+ pp_cxx_qualified_id (pp, t);
+ break;
+
+ case OVERLOAD:
+ t = OVL_CURRENT (t);
+ case VAR_DECL:
+ case PARM_DECL:
+ case FIELD_DECL:
+ case CONST_DECL:
+ case FUNCTION_DECL:
+ case BASELINK:
+ case TEMPLATE_DECL:
+ case TEMPLATE_TYPE_PARM:
+ case TEMPLATE_PARM_INDEX:
+ pp_cxx_primary_expression (pp, t);
+ break;
+
+ case CALL_EXPR:
+ case DYNAMIC_CAST_EXPR:
+ case STATIC_CAST_EXPR:
+ case REINTERPRET_CAST_EXPR:
+ case CONST_CAST_EXPR:
+#if 0
+ case MEMBER_REF:
+#endif
+ case EMPTY_CLASS_EXPR:
+ case TYPEID_EXPR:
+ case PSEUDO_DTOR_EXPR:
+ case AGGR_INIT_EXPR:
+ pp_cxx_postfix_expression (pp, t);
+ break;
+
+ case NEW_EXPR:
+ case VEC_NEW_EXPR:
+ pp_cxx_new_expression (pp, t);
+ break;
+
+ case DELETE_EXPR:
+ case VEC_DELETE_EXPR:
+ pp_cxx_delete_expression (pp, t);
+ break;
+
+ case CAST_EXPR:
+ pp_cxx_cast_expression (pp, t);
+ break;
+
+ case OFFSET_REF:
+ case MEMBER_REF:
+ case DOTSTAR_EXPR:
+ pp_cxx_pm_expression (pp, t);
+ break;
+
+ case MULT_EXPR:
+ case TRUNC_DIV_EXPR:
+ case TRUNC_MOD_EXPR:
+ pp_cxx_multiplicative_expression (pp, t);
+ break;
+
+ case COND_EXPR:
+ pp_cxx_conditional_expression (pp, t);
+ break;
+
+ case MODIFY_EXPR:
+ case INIT_EXPR:
+ case THROW_EXPR:
+ case MODOP_EXPR:
+ pp_cxx_assignment_expression (pp, t);
+ break;
+
+ default:
+ pp_c_expression (pp_c_base (pp), t);
+ break;
+ }
+}
+
+
+/* Declarations. */
+
+/* function-specifier:
+ inline
+ virtual
+ explicit */
+static void
+pp_cxx_function_specifier (cxx_pretty_printer *pp, tree t)
+{
+ switch (TREE_CODE (t))
+ {
+ case FUNCTION_DECL:
+ if (DECL_VIRTUAL_P (t))
+ pp_cxx_identifier (pp, "virtual");
+ else if (DECL_CONSTRUCTOR_P (t) && DECL_NONCONVERTING_P (t))
+ pp_cxx_identifier (pp, "explicit");
+ else
+ pp_c_function_specifier (pp_c_base (pp), t);
+
+ default:
+ break;
+ }
+}
+
+/* decl-specifier-seq:
+ decl-specifier-seq(opt) decl-specifier
+
+ decl-specifier:
+ storage-class-specifier
+ type-specifier
+ function-specifier
+ friend
+ typedef */
+static void
+pp_cxx_decl_specifier_seq (cxx_pretty_printer *pp, tree t)
+{
+ switch (TREE_CODE (t))
+ {
+ case VAR_DECL:
+ case PARM_DECL:
+ case CONST_DECL:
+ case FIELD_DECL:
+ pp_cxx_storage_class_specifier (pp, t);
+ pp_cxx_decl_specifier_seq (pp, TREE_TYPE (t));
+ break;
+
+ case TYPE_DECL:
+ pp_cxx_identifier (pp, "typedef");
+ pp_cxx_decl_specifier_seq (pp, TREE_TYPE (t));
+ break;
+
+ case RECORD_TYPE:
+ if (TYPE_PTRMEMFUNC_P (t))
+ {
+ tree pfm = TYPE_PTRMEMFUNC_FN_TYPE (t);
+ pp_cxx_decl_specifier_seq (pp, TREE_TYPE (TREE_TYPE (pfm)));
+ pp_cxx_whitespace (pp);
+ pp_cxx_ptr_operator (pp, t);
+ }
+ break;
+
+ case FUNCTION_DECL:
+ /* Constructors don't have return types. And conversion functions
+ do not have a type-specifier in their return types. */
+ if (DECL_CONSTRUCTOR_P (t) || DECL_CONV_FN_P (t))
+ pp_cxx_function_specifier (pp, t);
+ else if (DECL_NONSTATIC_MEMBER_FUNCTION_P (t))
+ pp_cxx_decl_specifier_seq (pp, TREE_TYPE (TREE_TYPE (t)));
+ else
+ default:
+ pp_c_declaration_specifiers (pp_c_base (pp), t);
+ break;
+ }
+}
+
+/* simple-type-specifier:
+ ::(opt) nested-name-specifier(opt) type-name
+ ::(opt) nested-name-specifier(opt) template(opt) template-id
+ char
+ wchar_t
+ bool
+ short
+ int
+ long
+ signed
+ unsigned
+ float
+ double
+ void */
+static void
+pp_cxx_simple_type_specifier (cxx_pretty_printer *pp, tree t)
+{
+ switch (TREE_CODE (t))
+ {
+ case RECORD_TYPE:
+ case UNION_TYPE:
+ case ENUMERAL_TYPE:
+ pp_cxx_qualified_id (pp, t);
+ break;
+
+ case TEMPLATE_TYPE_PARM:
+ case TEMPLATE_PARM_INDEX:
+ pp_cxx_unqualified_id (pp, t);
+ break;
+
+ case TYPENAME_TYPE:
+ pp_cxx_identifier (pp, "typename");
+ pp_cxx_nested_name_specifier (pp, TYPE_CONTEXT (t));
+ pp_cxx_unqualified_id (pp, TYPE_NAME (t));
+ break;
+
+ default:
+ pp_c_type_specifier (pp_c_base (pp), t);
+ break;
+ }
+}
+
+/* type-specifier-seq:
+ type-specifier type-specifier-seq(opt)
+
+ type-specifier:
+ simple-type-specifier
+ class-specifier
+ enum-specifier
+ elaborated-type-specifier
+ cv-qualifer */
+
+static void
+pp_cxx_type_specifier_seq (cxx_pretty_printer *pp, tree t)
+{
+ pp_c_type_qualifier_list (pp_c_base (pp), t);
+
+ switch (TREE_CODE (t))
+ {
+ case TEMPLATE_DECL:
+ case TEMPLATE_TYPE_PARM:
+ case TYPE_DECL:
+ case BOUND_TEMPLATE_TEMPLATE_PARM:
+ pp_cxx_simple_type_specifier (pp, t);
+ break;
+
+ case METHOD_TYPE:
+ pp_cxx_type_specifier_seq (pp, TREE_TYPE (t));
+ pp_cxx_space_for_pointer_operator (pp, TREE_TYPE (t));
+ pp_cxx_nested_name_specifier (pp, TYPE_METHOD_BASETYPE (t));
+ break;
+
+ default:
+ if (!(TREE_CODE (t) == FUNCTION_DECL && DECL_CONSTRUCTOR_P (t)))
+ pp_c_specifier_qualifier_list (pp_c_base (pp), t);
+ }
+}
+
+/* ptr-operator:
+ * cv-qualifier-seq(opt)
+ &
+ ::(opt) nested-name-specifier * cv-qualifier-seq(opt) */
+
+static void
+pp_cxx_ptr_operator (cxx_pretty_printer *pp, tree t)
+{
+ if (!TYPE_P (t) && TREE_CODE (t) != TYPE_DECL)
+ t = TREE_TYPE (t);
+ switch (TREE_CODE (t))
+ {
+ case REFERENCE_TYPE:
+ case POINTER_TYPE:
+ if (TREE_CODE (TREE_TYPE (t)) == POINTER_TYPE
+ || TYPE_PTR_TO_MEMBER_P (TREE_TYPE (t)))
+ pp_cxx_ptr_operator (pp, TREE_TYPE (t));
+ if (TREE_CODE (t) == POINTER_TYPE)
+ {
+ pp_star (pp);
+ pp_cxx_cv_qualifier_seq (pp, t);
+ }
+ else
+ pp_ampersand (pp);
+ break;
+
+ case RECORD_TYPE:
+ if (TYPE_PTRMEMFUNC_P (t))
+ {
+ pp_cxx_left_paren (pp);
+ pp_cxx_nested_name_specifier (pp, TYPE_PTRMEMFUNC_OBJECT_TYPE (t));
+ pp_star (pp);
+ break;
+ }
+ case OFFSET_TYPE:
+ if (TYPE_PTR_TO_MEMBER_P (t))
+ {
+ pp_cxx_nested_name_specifier (pp, TYPE_PTRMEM_CLASS_TYPE (t));
+ pp_star (pp);
+ pp_cxx_cv_qualifier_seq (pp, t);
+ break;
+ }
+ /* else fall trhough. */
+
+ default:
+ pp_unsupported_tree (pp, t);
+ break;
+ }
+}
+
+static inline tree
+pp_cxx_implicit_parameter_type (tree mf)
+{
+ return TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (mf))));
+}
+
+/*
+ parameter-declaration:
+ decl-specifier-seq declarator
+ decl-specifier-seq declarator = assignment-expression
+ decl-specifier-seq abstract-declarator(opt)
+ decl-specifier-seq abstract-declarator(opt) assignment-expression */
+static inline void
+pp_cxx_parameter_declaration (cxx_pretty_printer *pp, tree t)
+{
+ pp_cxx_decl_specifier_seq (pp, t);
+ if (TYPE_P (t))
+ pp_cxx_abstract_declarator (pp, t);
+ else
+ pp_cxx_declarator (pp, t);
+}
+
+/* parameter-declaration-clause:
+ parameter-declaration-list(opt) ...(opt)
+ parameter-declaration-list , ...
+
+ parameter-declaration-list:
+ parameter-declaration
+ parameter-declaration-list , parameter-declaration */
+static void
+pp_cxx_parameter_declaration_clause (cxx_pretty_printer *pp, tree t)
+{
+ tree args = TYPE_P (t) ? NULL : FUNCTION_FIRST_USER_PARM (t);
+ tree types = TYPE_P (t) ? TYPE_ARG_TYPES (t) : FUNCTION_FIRST_USER_PARMTYPE (t);
+ const bool abstract = args == NULL
+ || pp_c_base (pp)->flags & pp_c_flag_abstract;
+ bool first = true;
+
+ /* Skip artificial parameter for nonstatic member functions. */
+ if (TREE_CODE (t) == METHOD_TYPE)
+ types = TREE_CHAIN (types);
+
+ pp_cxx_left_paren (pp);
+ for (; args; args = TREE_CHAIN (args), types = TREE_CHAIN (types))
+ {
+ if (!first)
+ pp_separate_with (pp, ',');
+ first = false;
+ pp_cxx_parameter_declaration (pp, abstract ? TREE_VALUE (types) : args);
+ if (!abstract && pp_c_base (pp)->flags & pp_cxx_flag_default_argument)
+ {
+ pp_cxx_whitespace (pp);
+ pp_equal (pp);
+ pp_cxx_whitespace (pp);
+ pp_cxx_assignment_expression (pp, TREE_PURPOSE (types));
+ }
+ }
+ pp_cxx_right_paren (pp);
+}
+
+/* exception-specification:
+ throw ( type-id-list(opt) )
+
+ type-id-list
+ type-id
+ type-id-list , type-id */
+static void
+pp_cxx_exception_specification (cxx_pretty_printer *pp, tree t)
+{
+ tree ex_spec = TYPE_RAISES_EXCEPTIONS (t);
+
+ if (!TYPE_NOTHROW_P (t) && ex_spec == NULL)
+ return;
+ pp_cxx_identifier (pp, "throw");
+ pp_cxx_left_paren (pp);
+ for (; ex_spec && TREE_VALUE (ex_spec); ex_spec = TREE_CHAIN (ex_spec))
+ {
+ pp_cxx_type_id (pp, TREE_VALUE (ex_spec));
+ if (TREE_CHAIN (ex_spec))
+ pp_separate_with (pp, ',');
+ }
+ pp_cxx_right_paren (pp);
+}
+
+/* direct-declarator:
+ declarator-id
+ direct-declarator ( parameter-declaration-clause ) cv-qualifier-seq(opt)
+ exception-specification(opt)
+ direct-declaration [ constant-expression(opt) ]
+ ( declarator ) */
+static void
+pp_cxx_direct_declarator (cxx_pretty_printer *pp, tree t)
+{
+ switch (TREE_CODE (t))
+ {
+ case VAR_DECL:
+ case PARM_DECL:
+ case CONST_DECL:
+ case FIELD_DECL:
+ if (DECL_NAME (t))
+ {
+ pp_cxx_space_for_pointer_operator (pp, TREE_TYPE (t));
+ pp_cxx_id_expression (pp, DECL_NAME (t));
+ }
+ pp_cxx_abstract_declarator (pp, TREE_TYPE (t));
+ break;
+
+ case FUNCTION_DECL:
+ pp_cxx_space_for_pointer_operator (pp, TREE_TYPE (TREE_TYPE (t)));
+ pp_cxx_id_expression (pp, t);
+ pp_cxx_parameter_declaration_clause (pp, t);
+
+ if (DECL_NONSTATIC_MEMBER_FUNCTION_P (t))
+ {
+ pp_base (pp)->padding = pp_before;
+ pp_cxx_cv_qualifier_seq (pp, pp_cxx_implicit_parameter_type (t));
+ }
+
+ pp_cxx_exception_specification (pp, TREE_TYPE (t));
+ break;
+
+ case TYPENAME_TYPE:
+ case TEMPLATE_DECL:
+ case TEMPLATE_TYPE_PARM:
+ case TEMPLATE_PARM_INDEX:
+ break;
+
+ default:
+ pp_c_direct_declarator (pp_c_base (pp), t);
+ break;
+ }
+}
+
+/* declarator:
+ direct-declarator
+ ptr-operator declarator */
+static void
+pp_cxx_declarator (cxx_pretty_printer *pp, tree t)
+{
+ pp_cxx_direct_declarator (pp, t);
+}
+
+/* ctor-initializer:
+ : mem-initializer-list
+
+ mem-initializer-list:
+ mem-initializer
+ mem-initializer , mem-initializer-list
+
+ mem-initializer:
+ mem-initializer-id ( expression-list(opt) )
+
+ mem-initializer-id:
+ ::(opt) nested-name-specifier(opt) class-name
+ identifier */
+static void
+pp_cxx_ctor_initializer (cxx_pretty_printer *pp, tree t)
+{
+ t = TREE_OPERAND (t, 0);
+ pp_cxx_whitespace (pp);
+ pp_colon (pp);
+ pp_cxx_whitespace (pp);
+ for (; t; t = TREE_CHAIN (t))
+ {
+ pp_cxx_primary_expression (pp, TREE_PURPOSE (t));
+ pp_cxx_call_argument_list (pp, TREE_VALUE (t));
+ if (TREE_CHAIN (t))
+ pp_separate_with (pp, ',');
+ }
+}
+
+/* function-definition:
+ decl-specifier-seq(opt) declarator ctor-initializer(opt) function-body
+ decl-specifier-seq(opt) declarator function-try-block */
+
+void
+pp_cxx_function_definition (cxx_pretty_printer *pp, tree t)
+{
+ tree saved_scope = pp->enclosing_scope;
+ pp_cxx_decl_specifier_seq (pp, t);
+ pp_cxx_declarator (pp, t);
+ pp_needs_newline (pp) = true;
+ pp->enclosing_scope = DECL_CONTEXT (t);
+ if (DECL_SAVED_TREE (t))
+ {
+ tree body = DECL_SAVED_TREE (t);
+ if (TREE_CODE (body) == COMPOUND_STMT
+ && TREE_CODE (COMPOUND_BODY (body)) == CTOR_INITIALIZER)
+ {
+ body = COMPOUND_BODY (body);
+ pp_cxx_ctor_initializer (pp, body);
+ body = TREE_CHAIN (body);
+ }
+ pp_cxx_statement (pp, body);
+ }
+ else
+ {
+ pp_cxx_semicolon (pp);
+ pp_needs_newline (pp) = true;
+ }
+ pp_flush (pp);
+ pp->enclosing_scope = saved_scope;
+}
+
+/* abstract-declarator:
+ ptr-operator abstract-declarator(opt)
+ direct-abstract-declarator */
+static void
+pp_cxx_abstract_declarator (cxx_pretty_printer *pp, tree t)
+{
+ if (TYPE_PTRMEM_P (t) || TYPE_PTRMEMFUNC_P (t))
+ pp_cxx_right_paren (pp);
+ else if (POINTER_TYPE_P (t))
+ {
+ if (TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE
+ || TREE_CODE (TREE_TYPE (t)) == FUNCTION_TYPE)
+ pp_cxx_right_paren (pp);
+ t = TREE_TYPE (t);
+ }
+ pp_cxx_direct_abstract_declarator (pp, t);
+}
+
+/* direct-abstract-declarator:
+ direct-abstract-declarator(opt) ( parameter-declaration-clause )
+ cv-quafilier-seq(opt) exception-specification(opt)
+ direct-abstract-declarator(opt) [ constant-expression(opt) ]
+ ( abstract-declarator ) */
+static void
+pp_cxx_direct_abstract_declarator (cxx_pretty_printer *pp, tree t)
+{
+ switch (TREE_CODE (t))
+ {
+ case REFERENCE_TYPE:
+ pp_cxx_abstract_declarator (pp, t);
+ break;
+
+ case RECORD_TYPE:
+ if (TYPE_PTRMEMFUNC_P (t))
+ pp_cxx_direct_abstract_declarator (pp, TYPE_PTRMEMFUNC_FN_TYPE (t));
+ break;
+
+ case METHOD_TYPE:
+ case FUNCTION_TYPE:
+ pp_cxx_parameter_declaration_clause (pp, t);
+ pp_cxx_direct_abstract_declarator (pp, TREE_TYPE (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_exception_specification (pp, t);
+ break;
+
+ case TYPENAME_TYPE:
+ case TEMPLATE_TYPE_PARM:
+ case TEMPLATE_TEMPLATE_PARM:
+ case BOUND_TEMPLATE_TEMPLATE_PARM:
+ case UNBOUND_CLASS_TEMPLATE:
+ break;
+
+ default:
+ pp_c_direct_abstract_declarator (pp_c_base (pp), t);
+ break;
+ }
+}
+
+/* type-id:
+ type-specifier-seq abstract-declarator(opt) */
+static void
+pp_cxx_type_id (cxx_pretty_printer *pp, tree t)
+{
+ pp_flags saved_flags = pp_c_base (pp)->flags;
+ pp_c_base (pp)->flags |= pp_c_flag_abstract;
+
+ switch (TREE_CODE (t))
+ {
+ case TYPE_DECL:
+ case UNION_TYPE:
+ case RECORD_TYPE:
+ case ENUMERAL_TYPE:
+ case TYPENAME_TYPE:
+ case BOUND_TEMPLATE_TEMPLATE_PARM:
+ case UNBOUND_CLASS_TEMPLATE:
+ case TEMPLATE_TEMPLATE_PARM:
+ case TEMPLATE_TYPE_PARM:
+ case TEMPLATE_PARM_INDEX:
+ case TEMPLATE_DECL:
+ case TYPEOF_TYPE:
+ case TEMPLATE_ID_EXPR:
+ /* FIXME: Should be pp_cxx_type_specifier_seq. */
+ pp_cxx_type_specifier_seq (pp, t);
+ pp_cxx_declarator (pp, t);
+ break;
+
+ default:
+ pp_c_type_id (pp_c_base (pp), t);
+ break;
+ }
+
+ pp_c_base (pp)->flags = saved_flags;
+}
+
+/* template-argument-list:
+ template-argument
+ template-argument-list, template-argument
+
+ template-argument:
+ assignment-expression
+ type-id
+ template-name */
+static void
+pp_cxx_template_argument_list (cxx_pretty_printer *pp, tree t)
+{
+ int i;
+ if (t == NULL)
+ return;
+ for (i = 0; i < TREE_VEC_LENGTH (t); ++i)
+ {
+ tree arg = TREE_VEC_ELT (t, i);
+ if (i != 0)
+ pp_separate_with (pp, ',');
+ if (TYPE_P (arg) || (TREE_CODE (arg) == TEMPLATE_DECL
+ && TYPE_P (DECL_TEMPLATE_RESULT (arg))))
+ pp_cxx_type_id (pp, arg);
+ else
+ pp_cxx_expression (pp, arg);
+ }
+}
+
+
+static void
+pp_cxx_exception_declaration (cxx_pretty_printer *pp, tree t)
+{
+ t = DECL_STMT_DECL (t);
+ pp_cxx_type_specifier_seq (pp, t);
+ if (TYPE_P (t))
+ pp_cxx_abstract_declarator (pp, t);
+ else
+ pp_cxx_declarator (pp, t);
+}
+
+/* Statements. */
+
+void
+pp_cxx_statement (cxx_pretty_printer *pp, tree t)
+{
+ switch (TREE_CODE (t))
+ {
+ case USING_STMT:
+ pp_cxx_identifier (pp, "using");
+ pp_cxx_identifier (pp, "namespace");
+ pp_cxx_qualified_id (pp, USING_STMT_NAMESPACE (t));
+ break;
+
+ case USING_DECL:
+ pp_cxx_identifier (pp, "using");
+ pp_cxx_nested_name_specifier (pp, DECL_INITIAL (t));
+ pp_cxx_unqualified_id (pp, DECL_NAME (t));
+ break;
+
+ case EH_SPEC_BLOCK:
+ break;
+
+ /* try-block:
+ try compound-statement handler-seq */
+ case TRY_BLOCK:
+ pp_maybe_newline_and_indent (pp, 0);
+ pp_cxx_identifier (pp, "try");
+ pp_newline_and_indent (pp, 3);
+ pp_cxx_statement (pp, TRY_STMTS (t));
+ pp_newline_and_indent (pp, -3);
+ if (CLEANUP_P (t))
+ ;
+ else
+ pp_cxx_statement (pp, TRY_HANDLERS (t));
+ break;
+
+ /*
+ handler-seq:
+ handler handler-seq(opt)
+
+ handler:
+ catch ( exception-declaration ) compound-statement
+
+ exception-declaration:
+ type-specifier-seq declarator
+ type-specifier-seq abstract-declarator
+ ... */
+ case HANDLER:
+ pp_cxx_identifier (pp, "catch");
+ pp_cxx_left_paren (pp);
+ pp_cxx_exception_declaration (pp, HANDLER_PARMS (t));
+ pp_cxx_right_paren (pp);
+ pp_indentation (pp) += 3;
+ pp_needs_newline (pp) = true;
+ pp_cxx_statement (pp, HANDLER_BODY (t));
+ pp_indentation (pp) -= 3;
+ pp_needs_newline (pp) = true;
+ break;
+
+ default:
+ pp_c_statement (pp_c_base (pp), t);
+ break;
+ }
+}
+
+/* simple-declaration:
+ decl-specifier-seq(opt) init-declarator-list(opt) */
+static void
+pp_cxx_simple_declaration (cxx_pretty_printer *pp, tree t)
+{
+ pp_cxx_decl_specifier_seq (pp, t);
+ pp_cxx_init_declarator (pp, t);
+ pp_cxx_semicolon (pp);
+ pp_needs_newline (pp) = true;
+}
+
+/*
+ template-parameter-list:
+ template-parameter
+ template-parameter-list , template-parameter */
+
+static inline void
+pp_cxx_template_parameter_list (cxx_pretty_printer *pp, tree t)
+{
+ const int n = TREE_VEC_LENGTH (t);
+ int i;
+ for (i = 0; i < n; ++i)
+ {
+ if (i)
+ pp_separate_with (pp, ',');
+ pp_cxx_template_parameter (pp, TREE_VEC_ELT (t, i));
+ }
+}
+
+/* template-parameter:
+ type-parameter
+ parameter-declaration
+
+ type-parameter:
+ class identifier(opt)
+ class identifier(op) = type-id
+ typename identifier(opt)
+ typename identifier(opt) = type-id
+ template < template-parameter-list > class identifier(opt)
+ template < template-parameter-list > class identifier(opt) = template-name
+*/
+static void
+pp_cxx_template_parameter (cxx_pretty_printer *pp, tree t)
+{
+ tree parameter = TREE_VALUE (t);
+ switch (TREE_CODE (parameter))
+ {
+ case TYPE_DECL:
+ pp_cxx_identifier (pp, "class");
+ if (DECL_NAME (parameter))
+ pp_cxx_tree_identifier (pp, DECL_NAME (parameter));
+ /* FIXME: Chech if we should print also default argument. */
+ break;
+
+ case PARM_DECL:
+ pp_cxx_parameter_declaration (pp, parameter);
+ break;
+
+ case TEMPLATE_DECL:
+ break;
+
+ default:
+ pp_unsupported_tree (pp, t);
+ break;
+ }
+}
+
+/*
+ template-declaration:
+ export(opt) template < template-parameter-list > declaration */
+static void
+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))
+ {
+ pp_cxx_identifier (pp, "template");
+ pp_cxx_begin_template_argument_list (pp);
+ 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);
+ else
+ pp_cxx_simple_declaration (pp, t);
+}
+
+static void
+pp_cxx_explicit_specialization (cxx_pretty_printer *pp, tree t)
+{
+ pp_unsupported_tree (pp, t);
+}
+
+static void
+pp_cxx_explicit_instantiation (cxx_pretty_printer *pp, tree t)
+{
+ pp_unsupported_tree (pp, t);
+}
+
+/*
+ declaration:
+ block-declaration
+ function-definition
+ template-declaration
+ explicit-instantiation
+ explicit-specialization
+ linkage-specification
+ namespace-definition
+
+ block-declaration:
+ simple-declaration
+ asm-definition
+ namespace-alias-definition
+ using-declaration
+ using-directive */
+void
+pp_cxx_declaration (cxx_pretty_printer *pp, tree t)
+{
+ if (!DECL_LANG_SPECIFIC (t))
+ pp_cxx_simple_declaration (pp, t);
+ else if (DECL_USE_TEMPLATE (t) > 1)
+ switch (DECL_USE_TEMPLATE (t))
+ {
+ case 2:
+ pp_cxx_explicit_specialization (pp, t);
+ break;
+
+ case 3:
+ pp_cxx_explicit_instantiation (pp, t);
+ break;
+
+ default:
+ break;
+ }
+ else if (DECL_TEMPLATE_INFO (t))
+ pp_cxx_template_declaration (pp, t);
+ else switch (TREE_CODE (t))
+ {
+ case VAR_DECL:
+ case TYPE_DECL:
+ pp_cxx_simple_declaration (pp, t);
+ break;
+
+ case FUNCTION_DECL:
+ if (DECL_SAVED_TREE (t))
+ pp_cxx_function_definition (pp, t);
+ else
+ pp_cxx_simple_declaration (pp, t);
+ break;
+
+ default:
+ pp_unsupported_tree (pp, t);
+ break;
+ }
+}
+
+\f
+typedef c_pretty_print_fn pp_fun;
+
+void
+pp_cxx_pretty_printer_init (cxx_pretty_printer *pp)
+{
+ pp_c_pretty_printer_init (pp_c_base (pp));
+ pp_set_line_maximum_length (pp, 0);
pp->c_base.declaration = (pp_fun) pp_cxx_declaration;
- pp->c_base.declaration_specifiers = (pp_fun) pp_cxx_declaration_specifiers;
- pp->c_base.type_specifier = (pp_fun) pp_cxx_type_specifier;
+ pp->c_base.declaration_specifiers = (pp_fun) pp_cxx_decl_specifier_seq;
+ pp->c_base.function_specifier = (pp_fun) pp_cxx_function_specifier;
+ pp->c_base.type_specifier_seq = (pp_fun) pp_cxx_type_specifier_seq;
pp->c_base.declarator = (pp_fun) pp_cxx_declarator;
pp->c_base.direct_declarator = (pp_fun) pp_cxx_direct_declarator;
- pp->c_base.parameter_declaration = (pp_fun) pp_cxx_parameter_declaration;
+ pp->c_base.parameter_list = (pp_fun) pp_cxx_parameter_declaration_clause;
pp->c_base.type_id = (pp_fun) pp_cxx_type_id;
- pp->c_base.statement = (pp_fun) pp_cxx_statement;
+ pp->c_base.abstract_declarator = (pp_fun) pp_cxx_abstract_declarator;
+ pp->c_base.direct_abstract_declarator =
+ (pp_fun) pp_cxx_direct_abstract_declarator;
+ pp->c_base.simple_type_specifier = (pp_fun)pp_cxx_simple_type_specifier;
+
+ /* pp->c_base.statement = (pp_fun) pp_cxx_statement; */
+
pp->c_base.id_expression = (pp_fun) pp_cxx_id_expression;
pp->c_base.primary_expression = (pp_fun) pp_cxx_primary_expression;
pp->c_base.postfix_expression = (pp_fun) pp_cxx_postfix_expression;
pp->c_base.unary_expression = (pp_fun) pp_cxx_unary_expression;
- pp->c_base.initializer = (pp_fun) pp_cxx_initializer;
pp->c_base.multiplicative_expression = (pp_fun) pp_cxx_multiplicative_expression;
pp->c_base.conditional_expression = (pp_fun) pp_cxx_conditional_expression;
pp->c_base.assignment_expression = (pp_fun) pp_cxx_assignment_expression;
- pp->enclosing_scope = NULL;
+ pp->c_base.expression = (pp_fun) pp_cxx_expression;
+ pp->enclosing_scope = global_namespace;
}