This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[mainline] PATCH: More on pretty-printing
- From: gdr at integrable-solutions dot net
- To: gcc-patches at gcc dot gnu dot org
- Date: 10 Aug 2003 20:41:34 +0200
- Subject: [mainline] PATCH: More on pretty-printing
- Organization: Integrable Solutions
This adds more to the pretty-printing facilities.
In the C land, the output is not that nifty nifty but it gives
results that are satisfactory. By inserting pp_c_function_definition in
finish_function() I got results for the entire bootstrap process that
were quite good. Outputs that adhere to the GNU C conding style will
be subject of later work. If you don't care about that, you might
want to try it out right now.
A direct benefit is that we might now make C diagnostics more talkative
about entities involved in the error messages.
While looking at the output, I noticed that someone recently broke an
invariant in the tree representations (C front end): Function
parameter-type list ends with void_list_node when they do not contain
an ellipsis. For example, given the declaration
int (*f(int i))(int)
the TYPE_ARGS_TYPE of TREE_TYPE (f) is a TREE_LIST with only one node.
That is wrong. It should contain two nodes:
(1) one for the type of the parameter 'i'
(2) and void_list_node, indicating that f() is not varargs.
However the TYPE_ARGS_TYPE of the return type is correctly
represented, i.e.
(1) a note for 'int'
(2) and void_list_node to properly end the parameter-type-list.
Another source of difficulty is CONVERT_EXPR.
For example, given
int *buff;
int i;
// ...
buff[i];
is transformed by the C front end into something like
*(buff + (int*) (i * 4))
while looks very wierd because it adds two pointers.
That is coming from the fact that the C front end calculates that it
needs a stride of 4 to advance in the raw memory 'buff' (i.e. of type
char*), so it converts the index 'i' to a pointer type and adds the
value to buff. There seems to be no reliable way to get such
expressions back in their sensical forms.
Also, the C front end does not seem to keep typedef-names around. That
is too bad.
I have not covered all nodes in the C front end.
The C++ bits are not functioninig yet.
Bootstrapped and regtested on an i686-pc-linux-gnu.
-- Gaby
2003-08-10 Gabriel Dos Reis <gdr@integrable-solutions.net>
* pretty-print.c (pp_base_indent): Rename from pp_indent.
* c-pretty-print.h (pp_c_pretty_print_flag)s: New datatype.
(struct c_pretty_print_info): Add more fields.
(pp_c_left_paren): Move to c-pretty-print.c.
(pp_c_right_paren): Likewise.
(pp_c_left_brace): Likewise.
(pp_c_right_brace): Likewise.
(pp_c_left_bracket): Likewise.
(pp_c_right_bracket): Likewise.
(pp_c_declarator): Declare.
(pp_c_direct_declarator): Likewise.
(pp_c_specifier_qualifier_list): Likewise.
(pp_c_type_id): Likewise.
* c-pretty-print.c (pp_c_cv_qualifier): Change prootype. Rework..
(pp_c_type_qualifier_list): New.
(pp_c_pointer): Likewise.
(pp_c_parameter_type_list): Likewise.
(pp_c_function_definition): Likewise.
(pp_c_id_expression): Likewise.
(pp_c_simple_type_specifier): Tidy.
(pp_c_unary_expression): Likewise.
(pp_c_expression): Likewise.
(pp_c_pretty_printer_init): Likewise.
(pp_c_specifier_qualifier_list): Rework..
(pp_c_abstract_declarator): Likewise.
(pp_c_postfix_expression): Likewise.
(pp_c_primary_expression): Likewise.
(pp_c_cast_expression): Likewise.
(pp_c_direct_abstract_declarator): Likewise.
(pp_c_storage_class_specifier): Likewise.
(pp_c_function_specifier): Likewise.
(pp_c_declaration_specifiers): Likewise.
(pp_c_direct_declarator): Likewise.
(pp_c_declarator): Likewise.
(pp_c_declaration): Likewise.
(pp_c_statement): Likewise.
(pp_c_integer_constant): Rename from pp_c_integer_literal.
(pp_c_character_constant): Rename from pp_c_character_literal.
(pp_c_bool_constant): Rename from pp_c_bool_literal.
(pp_c_enumeration_constant): Rename from pp_c_enumerator.
(pp_c_floating_constant): Rename from pp_c_real_literal.
(pp_c_constant): Rename from pp_c_literal.
* c-lang.c: Include diagnostic.h and c-pretty-print.h
(LANG_HOOKS_INITIALIZE_DIAGNOSTITCS): Define.
(c_initialize_diagnostics): New.
* Makefile.in (c-lang.o): Update dependency.
cp/
2003-08-10 Gabriel Dos Reis <gdr@integrable-solutions.net>
* error.c (dump_expr): Tidy.
* cxx-pretty-print.c (pp_cxx_nonconsecutive_character): New.
(pp_cxx_begin_template_argument_list): Likewise.
(pp_cxx_end_template_argument_list): Likewise.
(is_destructor_name): Likewise.
(pp_cxx_unqualified_id): Likewise.
(pp_cxx_qualified_id): Likewise.
(pp_cxx_id_expression): Likewise.
(pp_cxx_new_expression): Likewise.
(pp_cxx_delete_expression): Likewise.
(pp_cxx_pm_expression): Likewise.
(pp_cxx_type_specifier): Rework.
(pp_cxx_type_id): Likewise.
(pp_cxx_primary_expression): Likewise.
(pp_cxx_postfix_expression): Likewise.
(pp_cxx_unary_expression): Likewise.
(pp_cxx_multiplicative_expression): Likewise.
(pp_cxx_conditional_expression): Likewise.
(pp_cxx_assignment_expression): Likewise.
(pp_cxx_pretty_printer_init): Tidy.
Index: Makefile.in
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Makefile.in,v
retrieving revision 1.1136
diff -p -r1.1136 Makefile.in
*** Makefile.in 5 Aug 2003 19:23:10 -0000 1.1136
--- Makefile.in 10 Aug 2003 17:06:48 -0000
*************** c-decl.o : c-decl.c $(CONFIG_H) $(SYSTEM
*** 1280,1286 ****
$(LANGHOOKS_DEF_H)
c-typeck.o : c-typeck.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) $(TREE_H) $(C_TREE_H) \
$(TARGET_H) flags.h intl.h output.h $(EXPR_H) $(RTL_H) toplev.h $(TM_P_H)
! c-lang.o : c-lang.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) $(TREE_H) $(C_TREE_H) \
$(GGC_H) langhooks.h $(LANGHOOKS_DEF_H) $(C_COMMON_H) gtype-c.h
c-lex.o : c-lex.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) $(TREE_H) \
$(RTL_H) debug.h $(C_TREE_H) $(C_COMMON_H) real.h c-incpath.h cppdefault.h \
--- 1280,1287 ----
$(LANGHOOKS_DEF_H)
c-typeck.o : c-typeck.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) $(TREE_H) $(C_TREE_H) \
$(TARGET_H) flags.h intl.h output.h $(EXPR_H) $(RTL_H) toplev.h $(TM_P_H)
! c-lang.o : c-lang.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) $(TREE_H) \
! $(C_TREE_H) $(C_PRETTY_PRINT_H) $(DIAGNOSTIC_H) \
$(GGC_H) langhooks.h $(LANGHOOKS_DEF_H) $(C_COMMON_H) gtype-c.h
c-lex.o : c-lex.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) $(TREE_H) \
$(RTL_H) debug.h $(C_TREE_H) $(C_COMMON_H) real.h c-incpath.h cppdefault.h \
Index: c-lang.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-lang.c,v
retrieving revision 1.112
diff -p -r1.112 c-lang.c
*** c-lang.c 4 Aug 2003 20:44:13 -0000 1.112
--- c-lang.c 10 Aug 2003 17:06:48 -0000
*************** Software Foundation, 59 Temple Place - S
*** 30,35 ****
--- 30,39 ----
#include "ggc.h"
#include "langhooks.h"
#include "langhooks-def.h"
+ #include "diagnostic.h"
+ #include "c-pretty-print.h"
+
+ static void c_initialize_diagnostics (diagnostic_context *);
enum c_language_kind c_language = clk_c;
*************** enum c_language_kind c_language = clk_c;
*** 43,48 ****
--- 47,54 ----
#define LANG_HOOKS_FINISH c_common_finish
#undef LANG_HOOKS_INIT_OPTIONS
#define LANG_HOOKS_INIT_OPTIONS c_common_init_options
+ #undef LANG_HOOKS_INITIALIZE_DIAGNOSTITCS
+ #define LANG_HOOKS_INITIALIZE_DIAGNOSTITCS c_initialize_diagnostics
#undef LANG_HOOKS_HANDLE_OPTION
#define LANG_HOOKS_HANDLE_OPTION c_common_handle_option
#undef LANG_HOOKS_MISSING_ARGUMENT
*************** finish_file (void)
*** 217,221 ****
--- 223,241 ----
{
c_objc_common_finish_file ();
}
+
+ static void
+ c_initialize_diagnostics (diagnostic_context *context)
+ {
+ pretty_printer *base = context->printer;
+ c_pretty_printer pp = xmalloc (sizeof *pp);
+ memcpy (pp_base (pp), base, sizeof (pretty_printer));
+ pp_c_pretty_printer_init (pp);
+ context->printer = (pretty_printer *) pp;
+
+ /* It is safe to free this object because it was previously malloc()'d. */
+ free (base);
+ }
+
#include "gtype-c.h"
Index: c-pretty-print.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-pretty-print.c,v
retrieving revision 1.21
diff -p -r1.21 c-pretty-print.c
*** c-pretty-print.c 5 Aug 2003 19:23:10 -0000 1.21
--- c-pretty-print.c 10 Aug 2003 17:06:49 -0000
*************** Software Foundation, 59 Temple Place - S
*** 34,51 ****
much easier o add extensions and nifty pretty-printing effects that
takes expresssion or declaration contexts into account. */
/* literal */
static void pp_c_char (c_pretty_printer, int);
- static void pp_c_character_literal (c_pretty_printer, tree);
- static void pp_c_bool_literal (c_pretty_printer, tree);
- static bool pp_c_enumerator (c_pretty_printer, tree);
-
static void pp_c_primary_expression (c_pretty_printer, tree);
/* postfix-expression */
static void pp_c_initializer_list (c_pretty_printer, tree);
- static void pp_c_unary_expression (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);
--- 34,118 ----
much easier o add extensions and nifty pretty-printing effects that
takes expresssion 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_right_brace(PP) \
+ do { \
+ pp_right_brace (PP); \
+ pp_base (PP)->padding = pp_none; \
+ } while (0)
+
+ #define pp_c_left_bracket(PP) \
+ do { \
+ pp_left_bracket (PP); \
+ pp_base (PP)->padding = pp_none; \
+ } while (0)
+
+ #define pp_c_right_bracket(PP) \
+ do { \
+ pp_right_bracket (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);
/* 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_assignment_expression (
*** 60,73 ****
/* declarations. */
static void pp_c_declaration_specifiers (c_pretty_printer, tree);
static void pp_c_init_declarator (c_pretty_printer, tree);
- static void pp_c_declarator (c_pretty_printer, tree);
- static void pp_c_direct_declarator (c_pretty_printer, tree);
- static void pp_c_abstract_declarator (c_pretty_printer, tree);
- static void pp_c_specifier_qualifier_list (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_type_id (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);
--- 127,136 ----
/* 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);
*************** static void pp_c_function_specifier (c_p
*** 75,95 ****
/* Declarations. */
! /* Print out CV-qualifiers. Take care of possible extensions.
! cv-qualifier:
! const
! volatile
! restrict
! __restrict__ */
! void
! pp_c_cv_qualifier (c_pretty_printer ppi, int cv)
! {
! if (cv & TYPE_QUAL_CONST)
! pp_c_identifier (ppi, "const");
! if (cv & TYPE_QUAL_VOLATILE)
! pp_c_identifier (ppi, "volatile");
! if (cv & TYPE_QUAL_RESTRICT)
! pp_c_identifier (ppi, flag_isoc99 ? "restrict" : "__restrict__");
}
/*
--- 138,197 ----
/* Declarations. */
! static void
! 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_whitespace (pp);
! pp_c_identifier (pp, cv);
! }
!
! /* 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:
! const
! volatile
! restrict
! __restrict__ */
! void
! pp_c_type_qualifier_list (c_pretty_printer pp, tree t)
! {
! int qualifiers;
!
! if (!TYPE_P (t))
! t = TREE_TYPE (t);
!
! qualifiers = TYPE_QUALS (t);
! if (qualifiers & TYPE_QUAL_CONST)
! pp_c_cv_qualifier (pp, "const");
! if (qualifiers & TYPE_QUAL_VOLATILE)
! pp_c_cv_qualifier (pp, "volatile");
! if (qualifiers & TYPE_QUAL_RESTRICT)
! pp_c_cv_qualifier (pp, flag_isoc99 ? "restrict" : "__restrict__");
! }
!
! /* pointer:
! * type-qualifier-list(opt)
! * type-qualifier-list(opt) pointer */
! static void
! 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:
! if (TREE_CODE (TREE_TYPE (t)) == POINTER_TYPE)
! pp_c_pointer (pp, TREE_TYPE (t));
! pp_c_star (pp);
! pp_c_type_qualifier_list (pp, t);
! break;
!
! default:
! pp_unsupported_tree (pp, t);
! }
}
/*
*************** pp_c_cv_qualifier (c_pretty_printer ppi,
*** 115,121 ****
static void
pp_c_simple_type_specifier (c_pretty_printer ppi, tree t)
{
! const enum tree_code code = TREE_CODE (t);
switch (code)
{
case ERROR_MARK:
--- 217,228 ----
static void
pp_c_simple_type_specifier (c_pretty_printer ppi, tree t)
{
! enum tree_code code;
!
! if (DECL_P (t) && TREE_CODE (t) != TYPE_DECL)
! t = TREE_TYPE (t);
!
! code = TREE_CODE (t);
switch (code)
{
case ERROR_MARK:
*************** pp_c_simple_type_specifier (c_pretty_pri
*** 137,143 ****
case CHAR_TYPE:
case INTEGER_TYPE:
case REAL_TYPE:
! pp_c_tree_identifier (ppi, DECL_NAME (t));
break;
case COMPLEX_TYPE:
--- 244,250 ----
case CHAR_TYPE:
case INTEGER_TYPE:
case REAL_TYPE:
! pp_c_simple_type_specifier (ppi, TYPE_NAME (t));
break;
case COMPLEX_TYPE:
*************** pp_c_simple_type_specifier (c_pretty_pri
*** 151,157 ****
case TYPE_DECL:
if (DECL_NAME (t))
! pp_c_tree_identifier (ppi, DECL_NAME (t));
else
pp_c_identifier (ppi, "<typedef-error>");
break;
--- 258,264 ----
case TYPE_DECL:
if (DECL_NAME (t))
! pp_id_expression (ppi, t);
else
pp_c_identifier (ppi, "<typedef-error>");
break;
*************** pp_c_simple_type_specifier (c_pretty_pri
*** 169,206 ****
pp_c_identifier (ppi, "<tag-error>");
if (TYPE_NAME (t))
! pp_c_tree_identifier (ppi, TYPE_NAME (t));
else
pp_c_identifier (ppi, "<anonymous>");
break;
default:
pp_unsupported_tree (ppi, t);
}
}
/* specifier-qualifier-list:
type-specifier specifier-qualifier-list-opt
! cv-qualifier specifier-qualifier-list-opt */
! static inline void
! pp_c_specifier_qualifier_list (c_pretty_printer ppi, tree t)
{
! pp_c_simple_type_specifier (ppi, TYPE_MAIN_VARIANT (TREE_TYPE (t)));
! pp_c_cv_qualifier (ppi, TYPE_QUALS (t));
}
static void
! pp_c_abstract_declarator (c_pretty_printer ppi, tree t)
{
! pp_unsupported_tree (ppi, t);
}
!
static inline void
pp_c_type_id (c_pretty_printer ppi, tree t)
{
pp_c_specifier_qualifier_list (ppi, t);
! pp_c_abstract_declarator (ppi, t);
}
static inline void
--- 276,457 ----
pp_c_identifier (ppi, "<tag-error>");
if (TYPE_NAME (t))
! pp_id_expression (ppi, 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));
+ break;
+
default:
pp_unsupported_tree (ppi, t);
+ break;
}
}
/* specifier-qualifier-list:
type-specifier specifier-qualifier-list-opt
! cv-qualifier specifier-qualifier-list-opt
!
!
! Implementation note: Because of the non-linearities in array or
! function declarations, this routinie prints not just the
! specifier-qualifier-list of such entities or types of such entities,
! 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)
{
! if (TREE_CODE (t) != POINTER_TYPE)
! pp_c_type_qualifier_list (pp, t);
! switch (TREE_CODE (t))
! {
! 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);
! 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);
! }
! break;
!
! case FUNCTION_TYPE:
! case ARRAY_TYPE:
! pp_c_specifier_qualifier_list (pp, TREE_TYPE (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);
! break;
!
! default:
! pp_c_simple_type_specifier (pp, t);
! break;
! }
}
+ /* parameter-type-list:
+ parameter-list
+ parameter-list , ...
+
+ parameter-list:
+ parameter-declaration
+ parameter-list , parameter-declaration
+
+ parameter-declaration:
+ declaration-specifiers declarator
+ declaration-specifiers abstract-declarator(opt) */
static void
! pp_c_parameter_type_list (c_pretty_printer pp, tree t)
{
! pp_c_left_paren (pp);
! if (t == 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))
! {
! if (!first)
! pp_separate_with (pp, ',');
! first = false;
! pp_declaration_specifiers (pp, want_parm_decl ? t : TREE_VALUE (t));
! if (want_parm_decl)
! pp_declarator (pp, t);
! else
! pp_abstract_declarator (pp, TREE_VALUE (t));
! }
! }
! pp_c_right_paren (pp);
}
! /* abstract-declarator:
! pointer
! pointer(opt) direct-abstract-declarator */
static inline void
+ pp_c_abstract_declarator (c_pretty_printer pp, tree t)
+ {
+ if (TREE_CODE (t) == POINTER_TYPE)
+ {
+ if (TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE
+ || TREE_CODE (TREE_TYPE (t)) == FUNCTION_TYPE)
+ pp_c_right_paren (pp);
+ t = TREE_TYPE (t);
+ }
+
+ pp_c_direct_abstract_declarator (pp, t);
+ }
+
+ /* direct-abstract-declarator:
+ ( 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)
+ {
+ switch (TREE_CODE (t))
+ {
+ case POINTER_TYPE:
+ pp_c_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));
+ break;
+
+ case ARRAY_TYPE:
+ pp_c_left_bracket (pp);
+ if (TYPE_DOMAIN (t))
+ pp_c_expression (pp, TYPE_MAX_VALUE (TYPE_DOMAIN (t)));
+ pp_c_right_bracket (pp);
+ pp_c_direct_abstract_declarator (pp, TREE_TYPE (t));
+ break;
+
+ case IDENTIFIER_NODE:
+ case VOID_TYPE:
+ case BOOLEAN_TYPE:
+ case INTEGER_TYPE:
+ case REAL_TYPE:
+ case ENUMERAL_TYPE:
+ case RECORD_TYPE:
+ case UNION_TYPE:
+ case VECTOR_TYPE:
+ case COMPLEX_TYPE:
+ case TYPE_DECL:
+ break;
+
+ default:
+ pp_unsupported_tree (pp, t);
+ break;
+ }
+ }
+
+ void
pp_c_type_id (c_pretty_printer ppi, tree t)
{
pp_c_specifier_qualifier_list (ppi, t);
! pp_abstract_declarator (ppi, t);
}
static inline void
*************** pp_c_storage_class_specifier (c_pretty_p
*** 208,215 ****
{
if (TREE_CODE (t) == TYPE_DECL)
pp_c_identifier (pp, "typedef");
! else if (DECL_REGISTER (t))
! pp_c_identifier (pp, "register");
}
static inline void
--- 459,471 ----
{
if (TREE_CODE (t) == TYPE_DECL)
pp_c_identifier (pp, "typedef");
! else if (DECL_P (t))
! {
! if (DECL_REGISTER (t))
! pp_c_identifier (pp, "register");
! else if (TREE_STATIC (t) && TREE_CODE (t) == VAR_DECL)
! pp_c_identifier (pp, "static");
! }
}
static inline void
*************** pp_c_function_specifier (c_pretty_printe
*** 219,245 ****
pp_c_identifier (pp, "inline");
}
static inline void
pp_c_declaration_specifiers (c_pretty_printer pp, tree t)
{
! pp_c_storage_class_specifier (pp, t);
! pp_c_function_specifier (pp, t);
! pp_type_specifier (pp, TYPE_MAIN_VARIANT (TREE_TYPE (t)));
! pp_c_cv_qualifier (pp, TYPE_QUALS (TREE_TYPE (t)));
}
! static inline void
pp_c_direct_declarator (c_pretty_printer pp, tree t)
{
! pp_unsupported_tree (pp, t);
}
! static inline void
pp_c_declarator (c_pretty_printer pp, tree t)
{
! pp_unsupported_tree (pp, t);
}
static inline void
pp_c_init_declarator (c_pretty_printer pp, tree t)
{
--- 475,582 ----
pp_c_identifier (pp, "inline");
}
+ /* declaration-specifiers:
+ storage-class-specifier declaration-specifiers(opt)
+ 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)
{
! pp_storage_class_specifier (pp, t);
! pp_function_specifier (pp, t);
! pp_c_specifier_qualifier_list (pp, DECL_P (t) ? TREE_TYPE (t) : t);
}
! /* direct-declarator
! identifier
! ( declarator )
! direct-declarator [ type-qualifier-list(opt) assignment-expression(opt) ]
! direct-declarator [ static type-qualifier-list(opt) assignment-expression(opt)]
! direct-declarator [ type-qualifier-list static assignment-exression ]
! direct-declarator [ type-qualifier-list * ]
! direct-declaratpr ( parameter-type-list )
! direct-declarator ( identifier-list(opt) ) */
! void
pp_c_direct_declarator (c_pretty_printer pp, tree t)
{
! switch (TREE_CODE (t))
! {
! case VAR_DECL:
! case PARM_DECL:
! case TYPE_DECL:
! case FIELD_DECL:
! case LABEL_DECL:
! 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));
! break;
!
! case FUNCTION_DECL:
! 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));
! else
! {
! pp_c_parameter_type_list (pp, DECL_ARGUMENTS (t));
! pp_c_abstract_declarator (pp, TREE_TYPE (TREE_TYPE (t)));
! }
! break;
!
! case INTEGER_TYPE:
! case REAL_TYPE:
! case ENUMERAL_TYPE:
! case UNION_TYPE:
! case RECORD_TYPE:
! break;
!
! default:
! pp_unsupported_tree (pp, t);
! break;
! }
}
!
! /* declarator:
! pointer(opt) direct-declarator */
! void
pp_c_declarator (c_pretty_printer pp, tree t)
{
! switch (TREE_CODE (t))
! {
! case INTEGER_TYPE:
! case REAL_TYPE:
! case ENUMERAL_TYPE:
! case UNION_TYPE:
! case RECORD_TYPE:
! break;
!
! case VAR_DECL:
! case PARM_DECL:
! case FIELD_DECL:
! case ARRAY_TYPE:
! case FUNCTION_TYPE:
! case FUNCTION_DECL:
! case TYPE_DECL:
! pp_direct_declarator (pp, t);
! break;
!
!
! default:
! pp_unsupported_tree (pp, t);
! break;
! }
}
+ /* init-declarator:
+ declarator:
+ declarator = initializer */
static inline void
pp_c_init_declarator (c_pretty_printer pp, tree t)
{
*************** pp_c_init_declarator (c_pretty_printer p
*** 253,258 ****
--- 590,598 ----
}
}
+ /* declaration:
+ declaration-specifiers init-declarator-list(opt) ; */
+
void
pp_c_declaration (c_pretty_printer pp, tree t)
{
*************** pp_c_attributes (c_pretty_printer pp, tr
*** 293,298 ****
--- 633,651 ----
pp_c_right_paren (pp);
}
+ /* function-definition:
+ declaration-specifiers declarator compound-statement */
+ void
+ pp_c_function_definition (c_pretty_printer pp, tree t)
+ {
+ pp_declaration_specifiers (pp, t);
+ pp_declarator (pp, t);
+ pp_needs_newline (pp) = true;
+ pp_statement (pp, DECL_SAVED_TREE (t));
+ pp_newline (pp);
+ pp_flush (pp);
+ }
+
/* Expressions. */
*************** pp_c_string_literal (c_pretty_printer pp
*** 354,396 ****
pp_doublequote (ppi);
}
/* Print out a CHARACTER literal. */
static inline void
! pp_c_character_literal (c_pretty_printer ppi, tree c)
{
tree type = TREE_TYPE (c);
! pp_quote (ppi);
if (host_integerp (c, TREE_UNSIGNED (type)))
! pp_c_char (ppi, tree_low_cst (c, TREE_UNSIGNED (type)));
else
! pp_scalar (ppi, "\\x%x", (unsigned) TREE_INT_CST_LOW (c));
! pp_quote (ppi);
}
/* Print out a BOOLEAN literal. */
! void
! pp_c_bool_literal (c_pretty_printer ppi, tree b)
{
! if (b == boolean_false_node || integer_zerop (b))
{
if (c_dialect_cxx ())
! pp_c_identifier (ppi, "false");
else if (flag_isoc99)
! pp_c_identifier (ppi, "_False");
else
! pp_unsupported_tree (ppi, b);
}
else if (b == boolean_true_node)
{
if (c_dialect_cxx ())
! pp_c_identifier (ppi, "true");
else if (flag_isoc99)
! pp_c_identifier (ppi, "_True");
else
! pp_unsupported_tree (ppi, b);
}
else
! pp_unsupported_tree (ppi, b);
}
/* Attempt to print out an ENUMERATOR. Return true on success. Else return
--- 707,773 ----
pp_doublequote (ppi);
}
+ static void
+ pp_c_integer_constant (c_pretty_printer pp, tree i)
+ {
+ if (host_integerp (i, 0))
+ pp_wide_integer (pp, TREE_INT_CST_LOW (i));
+ else
+ {
+ if (tree_int_cst_sgn (i) < 0)
+ {
+ pp_c_char (pp, '-');
+ i = build_int_2 (-TREE_INT_CST_LOW (i),
+ ~TREE_INT_CST_HIGH (i) + !TREE_INT_CST_LOW (i));
+ }
+ sprintf (pp_buffer (pp)->digit_buffer,
+ HOST_WIDE_INT_PRINT_DOUBLE_HEX,
+ TREE_INT_CST_HIGH (i), TREE_INT_CST_LOW (i));
+ pp_string (pp, pp_buffer (pp)->digit_buffer);
+ }
+ }
+
/* Print out a CHARACTER literal. */
static inline void
! pp_c_character_constant (c_pretty_printer pp, tree c)
{
tree type = TREE_TYPE (c);
! if (type == wchar_type_node)
! pp_character (pp, 'L');
! pp_quote (pp);
if (host_integerp (c, TREE_UNSIGNED (type)))
! pp_c_char (pp, tree_low_cst (c, TREE_UNSIGNED (type)));
else
! pp_scalar (pp, "\\x%x", (unsigned) TREE_INT_CST_LOW (c));
! pp_quote (pp);
}
/* Print out a BOOLEAN literal. */
! static void
! pp_c_bool_constant (c_pretty_printer pp, tree b)
{
! if (b == boolean_false_node)
{
if (c_dialect_cxx ())
! pp_c_identifier (pp, "false");
else if (flag_isoc99)
! pp_c_identifier (pp, "_False");
else
! pp_unsupported_tree (pp, b);
}
else if (b == boolean_true_node)
{
if (c_dialect_cxx ())
! pp_c_identifier (pp, "true");
else if (flag_isoc99)
! pp_c_identifier (pp, "_True");
else
! pp_unsupported_tree (pp, b);
}
+ else if (TREE_CODE (b) == INTEGER_CST)
+ pp_c_integer_constant (pp, b);
else
! pp_unsupported_tree (pp, b);
}
/* Attempt to print out an ENUMERATOR. Return true on success. Else return
*************** pp_c_bool_literal (c_pretty_printer ppi,
*** 398,405 ****
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_enumerator (c_pretty_printer ppi, tree e)
{
tree type = TREE_TYPE (e);
tree value;
--- 775,783 ----
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)
{
+ bool value_is_named = true;
tree type = TREE_TYPE (e);
tree value;
*************** pp_c_enumerator (c_pretty_printer ppi, t
*** 410,495 ****
;
if (value != NULL_TREE)
! pp_c_tree_identifier (ppi, TREE_PURPOSE (value));
else
{
/* Value must have been cast. */
pp_c_left_paren (ppi);
pp_type_id (ppi, type);
pp_c_right_paren (ppi);
! return false;
}
! return true;
! }
!
! /* Print out an INTEGER constant value. */
! void
! pp_c_integer_literal (c_pretty_printer ppi, tree i)
! {
! tree type = TREE_TYPE (i);
!
! if (type == boolean_type_node)
! pp_c_bool_literal (ppi, i);
! else if (type == char_type_node)
! pp_c_character_literal (ppi, i);
! else if (TREE_CODE (type) == ENUMERAL_TYPE
! && pp_c_enumerator (ppi, i))
! ;
! else
! {
! if (host_integerp (i, 0))
! pp_wide_integer (ppi, TREE_INT_CST_LOW (i));
! else
! {
! if (tree_int_cst_sgn (i) < 0)
! {
! pp_c_char (ppi, '-');
! i = build_int_2 (-TREE_INT_CST_LOW (i),
! ~TREE_INT_CST_HIGH (i) + !TREE_INT_CST_LOW (i));
! sprintf (pp_buffer (ppi)->digit_buffer,
! HOST_WIDE_INT_PRINT_DOUBLE_HEX,
! TREE_INT_CST_HIGH (i), TREE_INT_CST_LOW (i));
! pp_string (ppi, pp_buffer (ppi)->digit_buffer);
! }
! }
! }
}
/* Print out a REAL value. */
! void
! pp_c_real_literal (c_pretty_printer ppi, tree r)
{
! real_to_decimal (pp_buffer (ppi)->digit_buffer, &TREE_REAL_CST (r),
! sizeof (pp_buffer (ppi)->digit_buffer), 0, 1);
! pp_string (ppi, pp_buffer(ppi)->digit_buffer);
}
!
void
! pp_c_literal (c_pretty_printer ppi, tree e)
{
switch (TREE_CODE (e))
{
case INTEGER_CST:
! pp_c_integer_literal (ppi, e);
break;
case REAL_CST:
! pp_c_real_literal (ppi, e);
break;
case STRING_CST:
! pp_c_string_literal (ppi, e);
break;
default:
! pp_unsupported_tree (ppi, e);
break;
}
}
! /* Pretty-print a C primary-expression. */
static void
pp_c_primary_expression (c_pretty_printer ppi, tree e)
{
--- 788,868 ----
;
if (value != NULL_TREE)
! pp_id_expression (ppi, TREE_PURPOSE (value));
else
{
/* Value must have been cast. */
pp_c_left_paren (ppi);
pp_type_id (ppi, type);
pp_c_right_paren (ppi);
! value_is_named = false;
}
! return value_is_named;
}
/* Print out a REAL value. */
! static inline void
! 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);
! pp_string (pp, pp_buffer(pp)->digit_buffer);
}
! /* constant:
! integer-constant
! floating-constant
! enumeration-constant
! chatracter-constant */
void
! pp_c_constant (c_pretty_printer pp, tree e)
{
switch (TREE_CODE (e))
{
case INTEGER_CST:
! {
! tree type = TREE_TYPE (e);
! if (type == boolean_type_node)
! pp_c_bool_constant (pp, e);
! else if (type == char_type_node)
! pp_c_character_constant (pp, e);
! else if (TREE_CODE (type) == ENUMERAL_TYPE
! && pp_c_enumeration_constant (pp, e))
! ;
! else
! pp_c_integer_constant (pp, e);
! }
break;
case REAL_CST:
! pp_c_floating_constant (pp, e);
break;
case STRING_CST:
! pp_c_string_literal (pp, e);
break;
default:
! pp_unsupported_tree (pp, e);
break;
}
}
! void
! pp_c_identifier (c_pretty_printer pp, const char *id)
! {
! pp_c_maybe_whitespace (pp);
! pp_identifier (pp, id);
! pp_base (pp)->padding = pp_before;
! }
!
! /* Pretty-print a C primary-expression.
! primary-expression:
! identifier
! constant
! string-literal
! ( expression ) */
static void
pp_c_primary_expression (c_pretty_printer ppi, tree e)
{
*************** pp_c_primary_expression (c_pretty_printe
*** 518,524 ****
case INTEGER_CST:
case REAL_CST:
case STRING_CST:
! pp_c_literal (ppi, e);
break;
case TARGET_EXPR:
--- 891,897 ----
case INTEGER_CST:
case REAL_CST:
case STRING_CST:
! pp_c_constant (ppi, e);
break;
case TARGET_EXPR:
*************** pp_c_primary_expression (c_pretty_printe
*** 526,532 ****
pp_c_identifier (ppi, "__builtin_memcpy");
pp_c_left_paren (ppi);
pp_ampersand (ppi);
! pp_c_primary_expression (ppi, TREE_OPERAND (e, 0));
pp_separate_with (ppi, ',');
pp_ampersand (ppi);
pp_initializer (ppi, TREE_OPERAND (e, 1));
--- 899,905 ----
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));
*************** pp_c_primary_expression (c_pretty_printe
*** 544,550 ****
break;
default:
! /* Make sure this call won't cause any infinite loop. */
pp_c_left_paren (ppi);
pp_c_expression (ppi, e);
pp_c_right_paren (ppi);
--- 917,923 ----
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_primary_expression (c_pretty_printe
*** 552,558 ****
}
}
! /* Print out a C initializer -- also support C compound-literals. */
void
pp_c_initializer (c_pretty_printer ppi, tree e)
{
--- 925,936 ----
}
}
! /* Print out a C initializer -- also support C compound-literals.
! initializer:
! assignment-expression:
! { initializer-list }
! { initializer-list , } */
!
void
pp_c_initializer (c_pretty_printer ppi, tree e)
{
*************** pp_c_initializer (c_pretty_printer ppi,
*** 561,569 ****
enum tree_code code = TREE_CODE (TREE_TYPE (e));
if (code == RECORD_TYPE || code == UNION_TYPE || code == ARRAY_TYPE)
{
! pp_left_brace (ppi);
pp_c_initializer_list (ppi, e);
! pp_right_brace (ppi);
}
else
pp_unsupported_tree (ppi, TREE_OPERAND (e, 1));
--- 939,947 ----
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);
}
else
pp_unsupported_tree (ppi, TREE_OPERAND (e, 1));
*************** pp_c_initializer (c_pretty_printer ppi,
*** 572,577 ****
--- 950,969 ----
pp_assignment_expression (ppi, e);
}
+ /* initializer-list:
+ designation(opt) initializer
+ initializer-list , designation(opt) initializer
+
+ designation:
+ designator-list =
+
+ designator-list:
+ designator
+ designator-list designator
+
+ designator:
+ [ constant-expression ]
+ identifier */
static void
pp_c_initializer_list (c_pretty_printer ppi, tree e)
{
*************** pp_c_initializer_list (c_pretty_printer
*** 580,598 ****
if (code == RECORD_TYPE || code == UNION_TYPE || code == ARRAY_TYPE)
{
! tree init = TREE_OPERAND (e, 1);
for (; init != NULL_TREE; init = TREE_CHAIN (init))
{
if (code == RECORD_TYPE || code == UNION_TYPE)
{
! pp_dot (ppi);
pp_c_primary_expression (ppi, TREE_PURPOSE (init));
}
else
{
pp_c_left_bracket (ppi);
if (TREE_PURPOSE (init))
! pp_c_literal (ppi, TREE_PURPOSE (init));
pp_c_right_bracket (ppi);
}
pp_c_whitespace (ppi);
--- 972,990 ----
if (code == RECORD_TYPE || code == UNION_TYPE || code == ARRAY_TYPE)
{
! tree init = TREE_OPERAND (e, 0);
for (; init != NULL_TREE; init = TREE_CHAIN (init))
{
if (code == RECORD_TYPE || code == UNION_TYPE)
{
! pp_c_dot (ppi);
pp_c_primary_expression (ppi, TREE_PURPOSE (init));
}
else
{
pp_c_left_bracket (ppi);
if (TREE_PURPOSE (init))
! pp_c_constant (ppi, TREE_PURPOSE (init));
pp_c_right_bracket (ppi);
}
pp_c_whitespace (ppi);
*************** pp_c_initializer_list (c_pretty_printer
*** 607,612 ****
--- 999,1042 ----
pp_unsupported_tree (ppi, type);
}
+ /* This is a convenient function, used to bridge gap between C and C++
+ grammars.
+
+ id-expression:
+ identifier */
+ void
+ pp_c_id_expression (c_pretty_printer pp, tree t)
+ {
+ switch (TREE_CODE (t))
+ {
+ case VAR_DECL:
+ case PARM_DECL:
+ case CONST_DECL:
+ case TYPE_DECL:
+ case FUNCTION_DECL:
+ case FIELD_DECL:
+ case LABEL_DECL:
+ t = DECL_NAME (t);
+ case IDENTIFIER_NODE:
+ pp_c_tree_identifier (pp, t);
+ break;
+
+ default:
+ pp_unsupported_tree (pp, t);
+ break;
+ }
+ }
+
+ /* postfix-expression:
+ primary-expression
+ postfix-expression [ expression ]
+ postfix-expression ( argument-expression-list(opt) )
+ postfix-expression . identifier
+ postfix-expression -> identifier
+ postfix-expression ++
+ postfix-expression --
+ ( 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_printe
*** 621,627 ****
case ARROW_EXPR:
pp_postfix_expression (ppi, TREE_OPERAND (e, 0));
! pp_arrow (ppi);
break;
case ARRAY_REF:
--- 1051,1057 ----
case ARROW_EXPR:
pp_postfix_expression (ppi, TREE_OPERAND (e, 0));
! pp_c_arrow (ppi);
break;
case ARRAY_REF:
*************** pp_c_postfix_expression (c_pretty_printe
*** 653,664 ****
if (TREE_CODE (object) == INDIRECT_REF)
{
pp_postfix_expression (ppi, TREE_OPERAND (object, 0));
! pp_arrow (ppi);
}
else
{
pp_postfix_expression (ppi, object);
! pp_dot (ppi);
}
pp_c_expression (ppi, TREE_OPERAND (e, 1));
}
--- 1083,1094 ----
if (TREE_CODE (object) == INDIRECT_REF)
{
pp_postfix_expression (ppi, TREE_OPERAND (object, 0));
! pp_c_arrow (ppi);
}
else
{
pp_postfix_expression (ppi, object);
! pp_c_dot (ppi);
}
pp_c_expression (ppi, TREE_OPERAND (e, 1));
}
*************** pp_c_postfix_expression (c_pretty_printe
*** 670,676 ****
pp_c_left_paren (ppi);
pp_type_id (ppi, TREE_TYPE (e));
pp_c_right_paren (ppi);
! pp_left_brace (ppi);
if (code == COMPLEX_CST)
{
--- 1100,1106 ----
pp_c_left_paren (ppi);
pp_type_id (ppi, TREE_TYPE (e));
pp_c_right_paren (ppi);
! pp_c_left_brace (ppi);
if (code == COMPLEX_CST)
{
*************** pp_c_postfix_expression (c_pretty_printe
*** 687,693 ****
pp_c_expression (ppi, TREE_OPERAND (e, 1));
}
! pp_right_brace (ppi);
break;
case COMPOUND_LITERAL_EXPR:
--- 1117,1123 ----
pp_c_expression (ppi, TREE_OPERAND (e, 1));
}
! pp_c_right_brace (ppi);
break;
case COMPOUND_LITERAL_EXPR:
*************** pp_c_postfix_expression (c_pretty_printe
*** 706,711 ****
--- 1136,1149 ----
pp_c_right_paren (ppi);
break;
+ case ADDR_EXPR:
+ if (TREE_CODE (TREE_OPERAND (e, 0)) == FUNCTION_DECL)
+ {
+ pp_c_id_expression (ppi, TREE_OPERAND (e, 0));
+ break;
+ }
+ /* else fall through. */
+
default:
pp_primary_expression (ppi, e);
break;
*************** pp_c_expression_list (c_pretty_printer p
*** 741,747 ****
__alignof__ ( type-id )
__real__ unary-expression
__imag__ unary-expression */
! static void
pp_c_unary_expression (c_pretty_printer ppi, tree e)
{
enum tree_code code = TREE_CODE (e);
--- 1179,1185 ----
__alignof__ ( type-id )
__real__ unary-expression
__imag__ unary-expression */
! void
pp_c_unary_expression (c_pretty_printer ppi, tree e)
{
enum tree_code code = TREE_CODE (e);
*************** pp_c_unary_expression (c_pretty_printer
*** 759,768 ****
case BIT_NOT_EXPR:
case TRUTH_NOT_EXPR:
case CONJ_EXPR:
! if (code == ADDR_EXPR)
pp_ampersand (ppi);
else if (code == INDIRECT_REF)
! pp_star (ppi);
else if (code == NEGATE_EXPR)
pp_minus (ppi);
else if (code == BIT_NOT_EXPR || code == CONJ_EXPR)
--- 1197,1207 ----
case BIT_NOT_EXPR:
case TRUTH_NOT_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);
else if (code == INDIRECT_REF)
! pp_c_star (ppi);
else if (code == NEGATE_EXPR)
pp_minus (ppi);
else if (code == BIT_NOT_EXPR || code == CONJ_EXPR)
*************** pp_c_unary_expression (c_pretty_printer
*** 783,789 ****
pp_c_right_paren (ppi);
}
else
! pp_c_unary_expression (ppi, TREE_OPERAND (e, 0));
break;
case REALPART_EXPR:
--- 1222,1228 ----
pp_c_right_paren (ppi);
}
else
! pp_unary_expression (ppi, TREE_OPERAND (e, 0));
break;
case REALPART_EXPR:
*************** pp_c_unary_expression (c_pretty_printer
*** 802,816 ****
void
pp_c_cast_expression (c_pretty_printer ppi, tree e)
{
! if (TREE_CODE (e) == CONVERT_EXPR || TREE_CODE (e) == FLOAT_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));
}
- else
- pp_unary_expression (ppi, e);
}
static void
--- 1241,1260 ----
void
pp_c_cast_expression (c_pretty_printer ppi, 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));
+ break;
+
+ default:
+ pp_unary_expression (ppi, e);
}
}
static void
*************** pp_c_multiplicative_expression (c_pretty
*** 822,831 ****
case MULT_EXPR:
case TRUNC_DIV_EXPR:
case TRUNC_MOD_EXPR:
! pp_c_multiplicative_expression (ppi, TREE_OPERAND (e, 0));
pp_c_whitespace (ppi);
if (code == MULT_EXPR)
! pp_star (ppi);
else if (code == TRUNC_DIV_EXPR)
pp_slash (ppi);
else
--- 1266,1275 ----
case MULT_EXPR:
case TRUNC_DIV_EXPR:
case TRUNC_MOD_EXPR:
! pp_multiplicative_expression (ppi, TREE_OPERAND (e, 0));
pp_c_whitespace (ppi);
if (code == MULT_EXPR)
! pp_c_star (ppi);
else if (code == TRUNC_DIV_EXPR)
pp_slash (ppi);
else
*************** pp_c_additive_expression (c_pretty_print
*** 855,861 ****
else
pp_minus (ppi);
pp_c_whitespace (ppi);
! pp_multiplicative_expression (ppi, TREE_OPERAND (e, 1));
break;
default:
--- 1299,1305 ----
else
pp_minus (ppi);
pp_c_whitespace (ppi);
! pp_multiplicative_expression (ppi, TREE_OPERAND (e, 1));
break;
default:
*************** pp_c_equality_expression (c_pretty_print
*** 923,929 ****
case EQ_EXPR:
case NE_EXPR:
pp_c_equality_expression (ppi, TREE_OPERAND (e, 0));
! pp_c_maybe_whitespace (ppi);
pp_identifier (ppi, code == EQ_EXPR ? "==" : "!=");
pp_c_whitespace (ppi);
pp_c_relational_expression (ppi, TREE_OPERAND (e, 1));
--- 1367,1373 ----
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_and_expression (c_pretty_printer pp
*** 941,947 ****
if (TREE_CODE (e) == BIT_AND_EXPR)
{
pp_c_and_expression (ppi, TREE_OPERAND (e, 0));
! pp_c_maybe_whitespace (ppi);
pp_ampersand (ppi);
pp_c_whitespace (ppi);
pp_c_equality_expression (ppi, TREE_OPERAND (e, 1));
--- 1385,1391 ----
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_inclusive_or_expression (c_pretty_p
*** 971,977 ****
if (TREE_CODE (e) == BIT_IOR_EXPR)
{
pp_c_exclusive_or_expression (ppi, TREE_OPERAND (e, 0));
! pp_c_maybe_whitespace (ppi);
pp_bar (ppi);
pp_c_whitespace (ppi);
pp_c_exclusive_or_expression (ppi, TREE_OPERAND (e, 1));
--- 1415,1421 ----
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_logical_and_expression (c_pretty_pr
*** 986,992 ****
if (TREE_CODE (e) == TRUTH_ANDIF_EXPR)
{
pp_c_logical_and_expression (ppi, TREE_OPERAND (e, 0));
! pp_c_maybe_whitespace (ppi);
pp_identifier (ppi, "&&");
pp_c_whitespace (ppi);
pp_c_inclusive_or_expression (ppi, TREE_OPERAND (e, 1));
--- 1430,1436 ----
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_or_expression (c_pretty_pri
*** 1001,1007 ****
if (TREE_CODE (e) == TRUTH_ORIF_EXPR)
{
pp_c_logical_or_expression (ppi, TREE_OPERAND (e, 0));
! pp_c_maybe_whitespace (ppi);
pp_identifier (ppi, "||");
pp_c_whitespace (ppi);
pp_c_logical_and_expression (ppi, TREE_OPERAND (e, 1));
--- 1445,1451 ----
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_conditional_expression (c_pretty_pr
*** 1016,1022 ****
if (TREE_CODE (e) == COND_EXPR)
{
pp_c_logical_or_expression (ppi, TREE_OPERAND (e, 0));
! pp_c_maybe_whitespace (ppi);
pp_question (ppi);
pp_c_whitespace (ppi);
pp_c_expression (ppi, TREE_OPERAND (e, 1));
--- 1460,1466 ----
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_expression (c_pretty_printer ppi, t
*** 1053,1063 ****
switch (TREE_CODE (e))
{
case INTEGER_CST:
! pp_c_integer_literal (ppi, e);
break;
case REAL_CST:
! pp_c_real_literal (ppi, e);
break;
case STRING_CST:
--- 1497,1507 ----
switch (TREE_CODE (e))
{
case INTEGER_CST:
! pp_c_integer_constant (ppi, e);
break;
case REAL_CST:
! pp_c_floating_constant (ppi, e);
break;
case STRING_CST:
*************** pp_c_expression (c_pretty_printer ppi, t
*** 1074,1080 ****
case ERROR_MARK:
case TARGET_EXPR:
case STMT_EXPR:
! pp_c_primary_expression (ppi, e);
break;
case POSTINCREMENT_EXPR:
--- 1518,1524 ----
case ERROR_MARK:
case TARGET_EXPR:
case STMT_EXPR:
! pp_primary_expression (ppi, e);
break;
case POSTINCREMENT_EXPR:
*************** pp_c_expression (c_pretty_printer ppi, t
*** 1091,1097 ****
case COMPOUND_LITERAL_EXPR:
case COMPLEX_EXPR:
case VA_ARG_EXPR:
! pp_c_postfix_expression (ppi, e);
break;
case CONJ_EXPR:
--- 1535,1541 ----
case COMPOUND_LITERAL_EXPR:
case COMPLEX_EXPR:
case VA_ARG_EXPR:
! pp_postfix_expression (ppi, e);
break;
case CONJ_EXPR:
*************** pp_c_expression (c_pretty_printer ppi, t
*** 1109,1123 ****
pp_c_unary_expression (ppi, e);
break;
- case CONVERT_EXPR:
case FLOAT_EXPR:
pp_c_cast_expression (ppi, e);
break;
case MULT_EXPR:
case TRUNC_MOD_EXPR:
case TRUNC_DIV_EXPR:
! pp_c_multiplicative_expression (ppi, e);
break;
case LSHIFT_EXPR:
--- 1553,1568 ----
pp_c_unary_expression (ppi, e);
break;
case FLOAT_EXPR:
+ case FIX_TRUNC_EXPR:
+ case CONVERT_EXPR:
pp_c_cast_expression (ppi, e);
break;
case MULT_EXPR:
case TRUNC_MOD_EXPR:
case TRUNC_DIV_EXPR:
! pp_multiplicative_expression (ppi, e);
break;
case LSHIFT_EXPR:
*************** pp_c_expression (c_pretty_printer ppi, t
*** 1152,1168 ****
pp_c_logical_or_expression (ppi, e);
break;
case COND_EXPR:
! pp_c_conditional_expression (ppi, e);
break;
! case MODIFY_EXPR:
! case INIT_EXPR:
! pp_c_assignment_expression (ppi, e);
break;
! case NOP_EXPR:
! pp_c_expression (ppi, TREE_OPERAND (e, 0));
break;
case COMPOUND_EXPR:
--- 1597,1619 ----
pp_c_logical_or_expression (ppi, e);
break;
+ case EQ_EXPR:
+ case NE_EXPR:
+ pp_c_equality_expression (ppi, e);
+ break;
+
case COND_EXPR:
! pp_conditional_expression (ppi, e);
break;
! case PLUS_EXPR:
! case MINUS_EXPR:
! pp_c_additive_expression (ppi, e);
break;
! case MODIFY_EXPR:
! case INIT_EXPR:
! pp_assignment_expression (ppi, e);
break;
case COMPOUND_EXPR:
*************** pp_c_expression (c_pretty_printer ppi, t
*** 1173,1199 ****
pp_c_right_paren (ppi);
break;
!
default:
pp_unsupported_tree (ppi, e);
break;
}
}
/* Statements. */
void
pp_c_statement (c_pretty_printer ppi, tree stmt)
{
! const enum tree_code code = TREE_CODE (stmt);
switch (code)
{
case LABEL_STMT:
case CASE_LABEL:
! pp_newline (ppi);
if (code == LABEL_STMT)
pp_tree_identifier (ppi, DECL_NAME (LABEL_STMT_LABEL (stmt)));
! else if (code == LABEL_STMT)
{
if (CASE_LOW (stmt) == NULL_TREE)
pp_identifier (ppi, "default");
--- 1624,1665 ----
pp_c_right_paren (ppi);
break;
! case NOP_EXPR:
! case NON_LVALUE_EXPR:
! case SAVE_EXPR:
! case UNSAVE_EXPR:
! pp_c_expression (ppi, TREE_OPERAND (e, 0));
! break;
!
default:
pp_unsupported_tree (ppi, e);
break;
}
}
+
/* Statements. */
void
pp_c_statement (c_pretty_printer ppi, tree stmt)
{
! enum tree_code code;
!
! if (stmt == NULL)
! return;
!
! code = TREE_CODE (stmt);
switch (code)
{
case LABEL_STMT:
case CASE_LABEL:
! if (pp_needs_newline (ppi))
! pp_newline_and_indent (ppi, -3);
! else
! pp_indentation (ppi) -= 3;
if (code == LABEL_STMT)
pp_tree_identifier (ppi, DECL_NAME (LABEL_STMT_LABEL (stmt)));
! else if (code == CASE_LABEL)
{
if (CASE_LOW (stmt) == NULL_TREE)
pp_identifier (ppi, "default");
*************** pp_c_statement (c_pretty_printer ppi, tr
*** 1210,1244 ****
}
}
pp_colon (ppi);
! pp_newline_and_indent (ppi, 3);
break;
case COMPOUND_STMT:
! pp_left_brace (ppi);
pp_newline_and_indent (ppi, 3);
for (stmt = COMPOUND_BODY (stmt); stmt; stmt = TREE_CHAIN (stmt))
pp_c_statement (ppi, stmt);
pp_newline_and_indent (ppi, -3);
! pp_right_brace (ppi);
! pp_newline (ppi);
break;
case EXPR_STMT:
case CLEANUP_STMT:
! pp_newline (ppi);
! pp_c_expression (ppi, code == EXPR_STMT
! ? EXPR_STMT_EXPR (stmt)
! : CLEANUP_EXPR (stmt));
! pp_semicolon (ppi);
! pp_newline (ppi);
break;
case IF_STMT:
pp_c_identifier (ppi, "if");
! pp_space (ppi);
pp_c_left_paren (ppi);
pp_c_expression (ppi, IF_COND (stmt));
! pp_right_paren (ppi);
pp_newline_and_indent (ppi, 3);
pp_statement (ppi, THEN_CLAUSE (stmt));
pp_newline_and_indent (ppi, -3);
--- 1676,1720 ----
}
}
pp_colon (ppi);
! pp_indentation (ppi) += 3;
! pp_needs_newline (ppi) = true;
break;
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);
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;
break;
case EXPR_STMT:
case CLEANUP_STMT:
! if (pp_needs_newline (ppi))
! pp_newline_and_indent (ppi, 0);
! {
! tree e = code == EXPR_STMT
! ? EXPR_STMT_EXPR (stmt)
! : CLEANUP_EXPR (stmt);
! if (e)
! pp_c_expression (ppi, e);
! }
! pp_c_semicolon (ppi);
! pp_needs_newline (ppi) = true;
break;
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);
*************** pp_c_statement (c_pretty_printer ppi, tr
*** 1257,1285 ****
break;
case SWITCH_STMT:
! pp_newline (ppi);
pp_c_identifier (ppi, "switch");
pp_space (ppi);
pp_c_left_paren (ppi);
pp_c_expression (ppi, SWITCH_COND (stmt));
! pp_right_paren (ppi);
! pp_newline_and_indent (ppi, 3);
pp_statement (ppi, SWITCH_BODY (stmt));
pp_newline_and_indent (ppi, -3);
break;
case WHILE_STMT:
pp_c_identifier (ppi, "while");
pp_space (ppi);
pp_c_left_paren (ppi);
pp_c_expression (ppi, WHILE_COND (stmt));
! pp_right_paren (ppi);
pp_newline_and_indent (ppi, 3);
pp_statement (ppi, WHILE_BODY (stmt));
! pp_newline_and_indent (ppi, -3);
break;
case DO_STMT:
pp_c_identifier (ppi, "do");
pp_newline_and_indent (ppi, 3);
pp_statement (ppi, DO_BODY (stmt));
--- 1733,1768 ----
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;
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;
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_c_statement (c_pretty_printer ppi, tr
*** 1289,1322 ****
pp_c_left_paren (ppi);
pp_c_expression (ppi, DO_COND (stmt));
pp_c_right_paren (ppi);
! pp_semicolon (ppi);
! pp_newline (ppi);
break;
case FOR_STMT:
pp_c_identifier (ppi, "for");
pp_space (ppi);
pp_c_left_paren (ppi);
! pp_statement (ppi, FOR_INIT_STMT (stmt));
pp_c_whitespace (ppi);
if (FOR_COND (stmt))
pp_c_expression (ppi, FOR_COND (stmt));
! pp_semicolon (ppi);
pp_c_whitespace (ppi);
if (FOR_EXPR (stmt))
pp_c_expression (ppi, FOR_EXPR (stmt));
! pp_right_paren (ppi);
pp_newline_and_indent (ppi, 3);
pp_statement (ppi, FOR_BODY (stmt));
! pp_newline_and_indent (ppi, -3);
break;
case BREAK_STMT:
case CONTINUE_STMT:
! pp_newline (ppi);
pp_identifier (ppi, code == BREAK_STMT ? "break" : "continue");
! pp_semicolon (ppi);
! pp_newline (ppi);
break;
case RETURN_STMT:
--- 1772,1814 ----
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;
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 (FOR_INIT_STMT (stmt))
! pp_statement (ppi, FOR_INIT_STMT (stmt));
! else
! pp_c_semicolon (ppi);
! pp_needs_newline (ppi) = false;
pp_c_whitespace (ppi);
if (FOR_COND (stmt))
pp_c_expression (ppi, FOR_COND (stmt));
! pp_c_semicolon (ppi);
! pp_needs_newline (ppi) = false;
pp_c_whitespace (ppi);
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;
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;
break;
case RETURN_STMT:
*************** pp_c_statement (c_pretty_printer ppi, tr
*** 1325,1360 ****
tree e = code == RETURN_STMT
? RETURN_STMT_EXPR (stmt)
: GOTO_DESTINATION (stmt);
!
! pp_newline (ppi);
pp_c_identifier (ppi, code == RETURN_STMT ? "return" : "goto");
if (e)
pp_c_expression (ppi, e);
! pp_semicolon (ppi);
! pp_newline (ppi);
}
break;
case SCOPE_STMT:
if (!SCOPE_NULLIFIED_P (stmt) && SCOPE_NO_CLEANUPS_P (stmt))
! {
! if (SCOPE_BEGIN_P (stmt))
! {
! pp_left_brace (ppi);
! pp_newline_and_indent (ppi, 3);
! }
! else if (SCOPE_END_P (stmt))
! {
! pp_right_brace (ppi);
! pp_newline_and_indent (ppi, -3);
! }
! }
break;
case DECL_STMT:
pp_declaration (ppi, DECL_STMT_DECL (stmt));
! pp_semicolon (ppi);
! pp_newline (ppi);
break;
case ASM_STMT:
--- 1817,1859 ----
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 (e)
pp_c_expression (ppi, e);
! pp_c_semicolon (ppi);
! pp_needs_newline (ppi) = true;
}
break;
case SCOPE_STMT:
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 (SCOPE_BEGIN_P (stmt))
! {
! pp_left_brace (ppi);
! i = 3;
! }
! else if (SCOPE_END_P (stmt))
! {
! pp_right_brace (ppi);
! i = -3;
! }
! pp_indentation (ppi) += i;
! pp_needs_newline (ppi) = 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;
break;
case ASM_STMT:
*************** pp_c_statement (c_pretty_printer ppi, tr
*** 1383,1389 ****
if (ASM_CLOBBERS (stmt))
pp_c_expression (ppi, ASM_CLOBBERS (stmt));
}
! pp_right_paren (ppi);
pp_newline (ppi);
}
break;
--- 1882,1888 ----
if (ASM_CLOBBERS (stmt))
pp_c_expression (ppi, ASM_CLOBBERS (stmt));
}
! pp_c_right_paren (ppi);
pp_newline (ppi);
}
break;
*************** pp_c_statement (c_pretty_printer ppi, tr
*** 1394,1401 ****
pp_equal (ppi);
pp_c_whitespace (ppi);
pp_c_identifier (ppi, FILE_STMT_FILENAME (stmt));
! pp_semicolon (ppi);
! pp_newline (ppi);
break;
default:
--- 1893,1900 ----
pp_equal (ppi);
pp_c_whitespace (ppi);
pp_c_identifier (ppi, FILE_STMT_FILENAME (stmt));
! pp_c_semicolon (ppi);
! pp_needs_newline (ppi) = true;
break;
default:
*************** pp_c_pretty_printer_init (c_pretty_print
*** 1413,1426 ****
pp->declaration = pp_c_declaration;
pp->declaration_specifiers = pp_c_declaration_specifiers;
- pp->type_specifier = pp_c_simple_type_specifier;
pp->declarator = pp_c_declarator;
pp->direct_declarator = pp_c_direct_declarator;
pp->parameter_declaration = pp_c_parameter_declaration;
pp->type_id = pp_c_type_id;
pp->statement = pp_c_statement;
pp->primary_expression = pp_c_primary_expression;
pp->postfix_expression = pp_c_postfix_expression;
pp->unary_expression = pp_c_unary_expression;
--- 1912,1929 ----
pp->declaration = pp_c_declaration;
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->abstract_declarator = pp_c_abstract_declarator;
pp->parameter_declaration = pp_c_parameter_declaration;
pp->type_id = pp_c_type_id;
+ pp->function_specifier = pp_c_function_specifier;
+ pp->storage_class_specifier = pp_c_storage_class_specifier;
pp->statement = pp_c_statement;
+ pp->id_expression = pp_c_id_expression;
pp->primary_expression = pp_c_primary_expression;
pp->postfix_expression = pp_c_postfix_expression;
pp->unary_expression = pp_c_unary_expression;
Index: c-pretty-print.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-pretty-print.h,v
retrieving revision 1.10
diff -p -r1.10 c-pretty-print.h
*** c-pretty-print.h 5 Aug 2003 19:23:11 -0000 1.10
--- c-pretty-print.h 10 Aug 2003 17:06:49 -0000
*************** Software Foundation, 59 Temple Place - S
*** 27,32 ****
--- 27,39 ----
#include "pretty-print.h"
+ typedef enum
+ {
+ pp_c_flag_abstract = 1 << 1,
+ pp_c_flag_last_bit = 2
+ } pp_c_pretty_print_flags;
+
+
/* The data type used to bundle information necessary for pretty-printing
a C or C++ entity. */
typedef struct c_pretty_print_info *c_pretty_printer;
*************** struct c_pretty_print_info
*** 41,58 ****
Not used yet. */
int *offset_list;
/* These must be overridden by each of the C and C++ front-end to
reflect their understanding of syntactic productions when they differ. */
c_pretty_print_fn declaration;
c_pretty_print_fn declaration_specifiers;
- c_pretty_print_fn type_specifier;
c_pretty_print_fn declarator;
c_pretty_print_fn direct_declarator;
c_pretty_print_fn parameter_declaration;
c_pretty_print_fn type_id;
c_pretty_print_fn statement;
c_pretty_print_fn primary_expression;
c_pretty_print_fn postfix_expression;
c_pretty_print_fn unary_expression;
--- 48,71 ----
Not used yet. */
int *offset_list;
+ pp_flags flags;
+
/* These must be overridden by each of the C and C++ front-end to
reflect their understanding of syntactic productions when they differ. */
c_pretty_print_fn declaration;
c_pretty_print_fn declaration_specifiers;
c_pretty_print_fn declarator;
+ c_pretty_print_fn abstract_declarator;
+ c_pretty_print_fn type_specifier;
c_pretty_print_fn direct_declarator;
c_pretty_print_fn parameter_declaration;
c_pretty_print_fn type_id;
+ c_pretty_print_fn function_specifier;
+ c_pretty_print_fn storage_class_specifier;
c_pretty_print_fn statement;
+ c_pretty_print_fn id_expression;
c_pretty_print_fn primary_expression;
c_pretty_print_fn postfix_expression;
c_pretty_print_fn unary_expression;
*************** struct c_pretty_print_info
*** 65,142 ****
#undef pp_base
#define pp_base(PP) (&pp_c_base (PP)->base)
- #define pp_c_left_paren(PPI) \
- do { \
- pp_left_paren (PPI); \
- pp_c_base (PPI)->base.padding = pp_none; \
- } while (0)
- #define pp_c_right_paren(PPI) \
- do { \
- pp_right_paren (PPI); \
- pp_c_base (PPI)->base.padding = pp_none; \
- } while (0)
- #define pp_c_left_bracket(PPI) \
- do { \
- pp_left_bracket (PPI); \
- pp_c_base (PPI)->base.padding = pp_none; \
- } while (0)
- #define pp_c_right_bracket(PPI) \
- do { \
- pp_right_bracket (PPI); \
- pp_c_base (PPI)->base.padding = pp_none; \
- } while (0)
- #define pp_c_whitespace(PPI) \
- do { \
- pp_space (PPI); \
- pp_c_base (PPI)->base.padding = pp_none; \
- } while (0)
- #define pp_c_maybe_whitespace(PPI) \
- do { \
- if (pp_c_base (PPI)->base.padding != pp_none) \
- pp_c_whitespace (PPI); \
- } while (0)
- #define pp_c_identifier(PPI, ID) \
- do { \
- pp_c_maybe_whitespace (PPI); \
- pp_identifier (PPI, ID); \
- pp_c_base (PPI)->base.padding = pp_before; \
- } while (0)
#define pp_c_tree_identifier(PPI, ID) \
pp_c_identifier (PPI, IDENTIFIER_POINTER (ID))
#define pp_declaration(PPI, T) \
! (*pp_c_base (PPI)->declaration) (pp_c_base (PPI), T)
#define pp_declaration_specifiers(PPI, D) \
! (*pp_c_base (PPI)->declaration_specifiers) (pp_c_base (PPI), D)
#define pp_type_specifier(PPI, D) \
! (*pp_c_base (PPI)->type_specifier) (pp_c_base (PPI), D)
#define pp_declarator(PPI, D) \
! (*pp_c_base (PPI)->declarator) (pp_c_base (PPI), D)
#define pp_direct_declarator(PPI, D) \
! (*pp_c_base (PPI)->direct_declarator) (pp_c_base (PPI), D)
#define pp_parameter_declaration(PPI, T) \
! (*pp_c_base (PPI)->parameter_declaration) (pp_c_base (PPI), T)
#define pp_type_id(PPI, D) \
! (*pp_c_base (PPI)->type_id) (pp_c_base (PPI), D)
#define pp_statement(PPI, S) \
! (*pp_c_base (PPI)->statement) (pp_c_base (PPI), S)
#define pp_primary_expression(PPI, E) \
! (*pp_c_base (PPI)->primary_expression) (pp_c_base (PPI), E)
#define pp_postfix_expression(PPI, E) \
! (*pp_c_base (PPI)->postfix_expression) (pp_c_base (PPI), E)
#define pp_unary_expression(PPI, E) \
! (*pp_c_base (PPI)->unary_expression) (pp_c_base (PPI), E)
#define pp_initializer(PPI, E) \
! (*pp_c_base (PPI)->initializer) (pp_c_base (PPI), E)
#define pp_multiplicative_expression(PPI, E) \
! (*pp_c_base (PPI)->multiplicative_expression) (pp_c_base (PPI), E)
#define pp_conditional_expression(PPI, E) \
! (*pp_c_base (PPI)->conditional_expression) (pp_c_base (PPI), E)
#define pp_assignment_expression(PPI, E) \
! (*pp_c_base (PPI)->assignment_expression) (pp_c_base (PPI), E)
/* Returns the c_pretty_printer base object of PRETTY-PRINTER. This
--- 78,127 ----
#undef pp_base
#define pp_base(PP) (&pp_c_base (PP)->base)
#define pp_c_tree_identifier(PPI, ID) \
pp_c_identifier (PPI, IDENTIFIER_POINTER (ID))
#define pp_declaration(PPI, T) \
! pp_c_base (PPI)->declaration (pp_c_base (PPI), T)
#define pp_declaration_specifiers(PPI, D) \
! pp_c_base (PPI)->declaration_specifiers (pp_c_base (PPI), D)
! #define pp_abstract_declarator(PP, D) \
! pp_c_base (PP)->abstract_declarator (pp_c_base (PP), D)
#define pp_type_specifier(PPI, D) \
! pp_c_base (PPI)->type_specifier (pp_c_base (PPI), D)
#define pp_declarator(PPI, D) \
! pp_c_base (PPI)->declarator (pp_c_base (PPI), D)
#define pp_direct_declarator(PPI, D) \
! pp_c_base (PPI)->direct_declarator (pp_c_base (PPI), D)
#define pp_parameter_declaration(PPI, T) \
! pp_c_base (PPI)->parameter_declaration (pp_c_base (PPI), T)
#define pp_type_id(PPI, D) \
! pp_c_base (PPI)->type_id (pp_c_base (PPI), D)
! #define pp_function_specifier(PP, D) \
! pp_c_base (PP)->function_specifier (pp_c_base (PP), D)
! #define pp_storage_class_specifier(PP, D) \
! pp_c_base (PP)->storage_class_specifier (pp_c_base (PP), D);
#define pp_statement(PPI, S) \
! pp_c_base (PPI)->statement (pp_c_base (PPI), S)
+ #define pp_id_expression(PP, E) \
+ pp_c_base (PP)->id_expression (pp_c_base (PP), E)
#define pp_primary_expression(PPI, E) \
! pp_c_base (PPI)->primary_expression (pp_c_base (PPI), E)
#define pp_postfix_expression(PPI, E) \
! pp_c_base (PPI)->postfix_expression (pp_c_base (PPI), E)
#define pp_unary_expression(PPI, E) \
! pp_c_base (PPI)->unary_expression (pp_c_base (PPI), E)
#define pp_initializer(PPI, E) \
! pp_c_base (PPI)->initializer (pp_c_base (PPI), E)
#define pp_multiplicative_expression(PPI, E) \
! pp_c_base (PPI)->multiplicative_expression (pp_c_base (PPI), E)
#define pp_conditional_expression(PPI, E) \
! pp_c_base (PPI)->conditional_expression (pp_c_base (PPI), E)
#define pp_assignment_expression(PPI, E) \
! pp_c_base (PPI)->assignment_expression (pp_c_base (PPI), E)
/* Returns the c_pretty_printer base object of PRETTY-PRINTER. This
*************** struct c_pretty_print_info
*** 146,167 ****
extern void pp_c_pretty_printer_init (c_pretty_printer);
/* Declarations. */
void pp_c_attributes (c_pretty_printer, tree);
! void pp_c_cv_qualifier (c_pretty_printer, int);
void pp_c_parameter_declaration_clause (c_pretty_printer, tree);
void pp_c_declaration (c_pretty_printer, tree);
/* Statements. */
void pp_c_statement (c_pretty_printer, tree);
/* Expressions. */
void pp_c_expression (c_pretty_printer, tree);
void pp_c_logical_or_expression (c_pretty_printer, tree);
void pp_c_expression_list (c_pretty_printer, tree);
void pp_c_cast_expression (c_pretty_printer, tree);
void pp_c_postfix_expression (c_pretty_printer, tree);
void pp_c_initializer (c_pretty_printer, tree);
! void pp_c_literal (c_pretty_printer, tree);
void pp_c_string_literal (c_pretty_printer, tree);
- void pp_c_real_literal (c_pretty_printer, tree);
- void pp_c_integer_literal (c_pretty_printer, tree);
#endif /* GCC_C_PRETTY_PRINTER */
--- 131,158 ----
extern void pp_c_pretty_printer_init (c_pretty_printer);
/* Declarations. */
+ void pp_c_function_definition (c_pretty_printer, tree);
void pp_c_attributes (c_pretty_printer, tree);
! void pp_c_type_qualifier_list (c_pretty_printer, tree);
void pp_c_parameter_declaration_clause (c_pretty_printer, tree);
void pp_c_declaration (c_pretty_printer, tree);
+ void pp_c_declarator (c_pretty_printer, tree);
+ void pp_c_direct_declarator (c_pretty_printer, tree);
+ void pp_c_specifier_qualifier_list (c_pretty_printer, tree);
+ void pp_c_type_id (c_pretty_printer, tree);
/* Statements. */
void pp_c_statement (c_pretty_printer, tree);
/* Expressions. */
void pp_c_expression (c_pretty_printer, tree);
void pp_c_logical_or_expression (c_pretty_printer, tree);
void pp_c_expression_list (c_pretty_printer, tree);
+ void pp_c_unary_expression (c_pretty_printer, tree);
void pp_c_cast_expression (c_pretty_printer, tree);
void pp_c_postfix_expression (c_pretty_printer, tree);
void pp_c_initializer (c_pretty_printer, tree);
! void pp_c_constant (c_pretty_printer, tree);
! void pp_c_id_expression (c_pretty_printer, tree);
! void pp_c_identifier (c_pretty_printer, const char *);
void pp_c_string_literal (c_pretty_printer, tree);
#endif /* GCC_C_PRETTY_PRINTER */
Index: pretty-print.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/pretty-print.c,v
retrieving revision 2.3
diff -p -r2.3 pretty-print.c
*** pretty-print.c 5 Aug 2003 19:23:12 -0000 2.3
--- pretty-print.c 10 Aug 2003 17:06:49 -0000
*************** pp_clear_state (pretty_printer *pp)
*** 90,108 ****
pp_indentation (pp) = 0;
}
- /* Insert enough spaces into the output area of PRETTY-PRINTER to bring
- the column position to the current indentation level, assuming that a
- newline has just been written to the buffer. */
- static void
- pp_indent (pretty_printer *pp)
- {
- int n = pp_indentation (pp);
- int i;
-
- for (i = 0; i < n; ++i)
- pp_space (pp);
- }
-
/* Flush the formatted text of PRETTY-PRINTER onto the attached stream. */
static inline void
pp_write_text_to_stream (pretty_printer *pp)
--- 90,95 ----
*************** pp_append_r (pretty_printer *pp, const c
*** 164,169 ****
--- 151,169 ----
pp->buffer->line_length += length;
}
+ /* Insert enough spaces into the output area of PRETTY-PRINTER to bring
+ the column position to the current indentation level, assuming that a
+ newline has just been written to the buffer. */
+ void
+ pp_base_indent (pretty_printer *pp)
+ {
+ int n = pp_indentation (pp);
+ int i;
+
+ for (i = 0; i < n; ++i)
+ pp_space (pp);
+ }
+
/* Format a message pointed to by TEXT. The following format specifiers are
recognized as being client independent:
%d, %i: (signed) integer in base ten.
*************** pp_base_emit_prefix (pretty_printer *pp)
*** 399,405 ****
case DIAGNOSTICS_SHOW_PREFIX_ONCE:
if (pp->emitted_prefix)
{
! pp_indent (pp);
break;
}
pp_indentation (pp) += 3;
--- 399,405 ----
case DIAGNOSTICS_SHOW_PREFIX_ONCE:
if (pp->emitted_prefix)
{
! pp_base_indent (pp);
break;
}
pp_indentation (pp) += 3;
Index: pretty-print.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/pretty-print.h,v
retrieving revision 1.8
diff -p -r1.8 pretty-print.h
*** pretty-print.h 5 Aug 2003 19:23:12 -0000 1.8
--- pretty-print.h 10 Aug 2003 17:06:50 -0000
*************** struct pretty_print_info
*** 108,115 ****
/* The prefix for each new line. */
const char *prefix;
-
- pp_flags flags;
/* Where to put whitespace around the entity being formatted. */
pp_padding padding;
--- 108,113 ----
*************** struct pretty_print_info
*** 202,207 ****
--- 200,207 ----
do { \
pp_indentation (PP) += N; \
pp_newline (PP); \
+ pp_base_indent (pp_base (PP)); \
+ pp_needs_newline (PP) = false; \
} while (0)
#define pp_separate_with(PP, C) \
do { \
*************** extern void pp_base_flush (pretty_printe
*** 251,256 ****
--- 251,257 ----
extern void pp_base_format_text (pretty_printer *, text_info *);
extern void pp_base_format_verbatim (pretty_printer *, text_info *);
+ extern void pp_base_indent (pretty_printer *);
extern void pp_base_newline (pretty_printer *);
extern void pp_base_character (pretty_printer *, int);
extern void pp_base_string (pretty_printer *, const char *);
Index: cp/cxx-pretty-print.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/cxx-pretty-print.c,v
retrieving revision 1.1
diff -p -r1.1 cxx-pretty-print.c
*** cp/cxx-pretty-print.c 5 Aug 2003 19:23:14 -0000 1.1
--- cp/cxx-pretty-print.c 10 Aug 2003 17:06:51 -0000
*************** Software Foundation, 59 Temple Place - S
*** 26,32 ****
--- 26,53 ----
#include "real.h"
#include "cxx-pretty-print.h"
#include "cp-tree.h"
+
+ static void pp_cxx_unqualified_id (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_template_argument_list (cxx_pretty_printer *, tree);
+
+ 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_character (pp, c);
+ }
+
+ #define pp_cxx_begin_template_argument_list(PP) \
+ pp_cxx_nonconsecutive_character (PP, '<')
+ #define pp_cxx_end_template_argument_list(PP) \
+ pp_cxx_nonconsecutive_character (PP, '>')
+
/* Declarations. */
void
*************** pp_cxx_declaration_specifiers (cxx_prett
*** 40,62 ****
{
pp_unsupported_tree (pp, t);
}
static void
pp_cxx_type_specifier (cxx_pretty_printer *pp, tree t)
{
! pp_unsupported_tree (pp, t);
}
static void
pp_cxx_declarator (cxx_pretty_printer *pp, tree t)
{
! pp_unsupported_tree (pp, t);
}
static void
pp_cxx_direct_declarator (cxx_pretty_printer *pp, tree t)
{
! pp_unsupported_tree (pp, t);
}
static void
--- 61,115 ----
{
pp_unsupported_tree (pp, t);
}
+ /* type-specifier:
+ simple-type-specifier
+ class-specifier
+ enum-specifier
+ elaborated-type-specifier
+ cv-qualifer */
static void
pp_cxx_type_specifier (cxx_pretty_printer *pp, tree t)
{
! 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);
! }
}
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);
}
static void
*************** pp_cxx_parameter_declaration (cxx_pretty
*** 65,132 ****
pp_unsupported_tree (pp, t);
}
static void
pp_cxx_type_id (cxx_pretty_printer *pp, tree t)
{
! pp_unsupported_tree (pp, t);
! }
! /* Statements. */
! void
! pp_cxx_statement (cxx_pretty_printer *pp, tree t)
! {
! pp_unsupported_tree (pp, t);
}
- /* Expressions. */
-
static void
! pp_cxx_primary_expression (cxx_pretty_printer *pp, tree t)
{
pp_unsupported_tree (pp, t);
}
! static void
! pp_cxx_postfix_expression (cxx_pretty_printer *pp, tree t)
! {
! pp_unsupported_tree (pp, t);
}
- static void
- pp_cxx_unary_expression (cxx_pretty_printer *pp, tree t)
- {
- pp_unsupported_tree (pp, t);
- }
! static void
! pp_cxx_initializer (cxx_pretty_printer *pp, tree t)
! {
! pp_unsupported_tree (pp, t);
! }
! static void
! pp_cxx_multiplicatice_expression (cxx_pretty_printer *pp, tree t)
{
pp_unsupported_tree (pp, t);
}
static void
! pp_cxx_conditional_expression (cxx_pretty_printer *pp, tree t)
{
! pp_unsupported_tree (pp, t);
! }
static void
! pp_cxx_assignment_expression (cxx_pretty_printer *pp, tree t)
{
! pp_unsupported_tree (pp, t);
! }
!
! void
! pp_cxx_expression (cxx_pretty_printer *pp, tree t)
{
! pp_unsupported_tree (pp, t);
}
--- 118,669 ----
pp_unsupported_tree (pp, t);
}
+
+
+ /* 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 (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;
}
static void
! pp_cxx_initializer (cxx_pretty_printer *pp, tree t)
{
pp_unsupported_tree (pp, t);
}
! /* 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)
+ {
+ return name == complete_dtor_identifier
+ || name == base_dtor_identifier
+ || name == deleting_dtor_identifier;
+ }
+
+ /* unqualified-id:
+ identifier
+ operator-function-id
+ conversion-function-id
+ ~ class-name
+ template-id */
+ static void
+ pp_cxx_unqualified_id (cxx_pretty_printer *pp, tree t)
+ {
+ enum tree_code code = TREE_CODE (t);
+ switch (code)
+ {
+ case VAR_DECL:
+ case PARM_DECL:
+ case CONST_DECL:
+ case TYPE_DECL:
+ case FUNCTION_DECL:
+ case NAMESPACE_DECL:
+ case FIELD_DECL:
+ case LABEL_DECL:
+ case USING_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);
+ }
+ else
+ {
+ if (is_destructor_name (t))
+ {
+ pp_complement (pp);
+ t = constructor_name (TREE_TYPE (t));
+ }
+ pp_c_tree_identifier (pp_c_base (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);
+ break;
+
+ default:
+ pp_unsupported_tree (pp, t);
+ }
+ }
+
+ /* qualified-id:
+ nested-name-specifier template(opt) unqualified-id */
+ static void
+ pp_cxx_qualified_id (cxx_pretty_printer *pp, tree t)
+ {
+ switch (TREE_CODE (t))
+ {
+ case PTRMEM_CST:
+ pp_cxx_qualified_id (pp, PTRMEM_CST_CLASS (t));
+ pp_colon_colon (pp);
+ pp_cxx_unqualified_id (pp, PTRMEM_CST_MEMBER (t));
+ break;
+
+ case OFFSET_REF:
+ case SCOPE_REF:
+ pp_cxx_qualified_id (pp, TREE_OPERAND (t, 0));
+ pp_colon_colon (pp);
+ 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
+ {
+ 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);
+ }
+ }
+ break;
+ }
+ }
+
+ /* id-expression:
+ unaqualified-id
+ qualified-id */
+ 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))
+ pp_cxx_qualified_id (pp, t);
+ else
+ pp_cxx_unqualified_id (pp, t);
+ }
+
+ /* primary-expression:
+ literal
+ this
+ :: identifier
+ :: operator-function-id
+ :: qualifier-id
+ ( expression )
+ id-expression */
static void
! pp_cxx_primary_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;
!
! 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);
! }
! break;
! }
! }
!
! /* postfix-expression:
! primary-expression
! postfix-expression [ expression ]
! postfix-expression ( expression-list(opt) )
! simple-type-specifier ( expression-list(opt) )
! typename ::(opt) nested-name-specifier identifier ( expression-list(opt) )
! typename ::(opt) nested-name-specifier template(opt)
! template-id ( expression-list(opt) )
! postfix-expression . template(opt) ::(opt) id-expression
! postfix-expression -> template(opt) ::(opt) id-expression
! postfix-expression . pseudo-destructor-name
! postfix-expression -> pseudo-destructor-name
! postfix-expression ++
! postfix-expression --
! dynamic_cast < type-id > ( expression )
! static_cast < type-id > ( expression )
! reinterpret_cast < type-id > ( expression )
! const_cast < type-id > ( expression )
! typeid ( expression )
! typeif ( type-id ) */
static void
! pp_cxx_postfix_expression (cxx_pretty_printer *pp, tree t)
{
! enum tree_code code = TREE_CODE (t);
!
! switch (code)
! {
! case DYNAMIC_CAST_EXPR:
! case STATIC_CAST_EXPR:
! case REINTERPRET_CAST_EXPR:
! case CONST_CAST_EXPR:
! if (code == DYNAMIC_CAST_EXPR)
! pp_identifier (pp, "dynamic_cast");
! else if (code == STATIC_CAST_EXPR)
! pp_identifier (pp, "static_cast");
! else if (code == REINTERPRET_CAST_EXPR)
! pp_identifier (pp, "reinterpret_cast");
! else
! pp_identifier (pp, "const_cast");
! pp_cxx_begin_template_argument_list (pp);
! 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_right_paren (pp);
! break;
!
! case EMPTY_CLASS_EXPR:
! pp_cxx_type_id (pp, TREE_TYPE (t));
! pp_left_paren (pp);
! pp_right_paren (pp);
! break;
!
! case TYPEID_EXPR:
! t = TREE_OPERAND (t, 0);
! pp_c_identifier (pp_c_base (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_right_paren (pp);
! break;
!
! case PSEUDO_DTOR_EXPR:
! pp_cxx_postfix_expression (pp, TREE_OPERAND (t, 0));
! pp_dot (pp);
! pp_cxx_qualified_id (pp, TREE_OPERAND (t, 1));
! pp_colon_colon (pp);
! pp_complement (pp);
! pp_cxx_unqualified_id (pp, TREE_OPERAND (t, 2));
! break;
!
! default:
! pp_c_postfix_expression (pp_c_base (pp), t);
! break;
! }
! }
!
! /* new-expression:
! ::(opt) new new-placement(opt) new-type-id new-initializer(opt)
! ::(opt) new new-placement(opt) ( type-id ) new-initializer(opt)
!
! new-placement:
! ( expression-list )
!
! new-type-id:
! type-specifier-seq new-declarator(opt)
!
! new-declarator:
! ptr-operator new-declarator(opt)
! direct-new-declarator
!
! direct-new-declarator
! [ expression ]
! direct-new-declarator [ constant-expression ]
!
! new-initializer:
! ( expression-list(opt) ) */
! static void
! pp_cxx_new_expression (cxx_pretty_printer *pp, tree t)
! {
! enum tree_code code = TREE_CODE (t);
! switch (code)
! {
! 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");
! 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_space (pp);
! }
! /* FIXME: array-types are built with one more element. */
! pp_cxx_type_id (pp, TREE_OPERAND (t, 1));
! if (TREE_OPERAND (t, 2))
! {
! pp_left_paren (pp);
! t = TREE_OPERAND (t, 2);
! if (TREE_CODE (t) == TREE_LIST)
! pp_c_expression_list (pp_c_base (pp), t);
! else if (t == void_zero_node)
! ; /* OK, empty initializer list. */
! else
! pp_c_expression (pp_c_base (pp), t);
! pp_right_paren (pp);
! }
! break;
!
! default:
! pp_unsupported_tree (pp, t);
! }
! }
!
! /* delete-expression:
! ::(opt) delete cast-expression
! ::(opt) delete [ ] cast-expression */
! static void
! pp_cxx_delete_expression (cxx_pretty_printer *pp, tree t)
! {
! enum tree_code code = TREE_CODE (t);
! switch (code)
! {
! 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");
! if (code == VEC_DELETE_EXPR)
! {
! pp_left_bracket (pp);
! pp_right_bracket (pp);
! }
! pp_c_cast_expression (pp_c_base (pp), TREE_OPERAND (t, 0));
! break;
!
! default:
! pp_unsupported_tree (pp, t);
! }
! }
!
! /* unary-expression:
! postfix-expression
! ++ cast-expression
! -- cast-expression
! unary-operator cast-expression
! sizeof unary-expression
! sizeof ( type-id )
! new-expression
! delete-expression
!
! unary-operator: one of
! * & + - !
!
! GNU extensions:
! __alignof__ unary-expression
! __alignof__ ( type-id ) */
! static void
! pp_cxx_unary_expression (cxx_pretty_printer *pp, tree t)
{
! enum tree_code code = TREE_CODE (t);
! switch (code)
! {
! 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;
!
! default:
! pp_c_unary_expression (pp_c_base (pp), t);
! break;
! }
! }
!
! /* pm-expression:
! cast-expression
! pm-expression .* cast-expression
! pm-expression ->* cast-expression */
! static void
! pp_cxx_pm_expression (cxx_pretty_printer *pp, tree t)
! {
! switch (TREE_CODE (t))
! {
! /* Handle unfortunate OFFESET_REF overloading here. */
! case OFFSET_REF:
! if (TYPE_P (TREE_OPERAND (t, 0)))
! {
! pp_cxx_qualified_id (pp, t);
! break;
! }
! /* else fall through */
! case MEMBER_REF:
! case DOTSTAR_EXPR:
! pp_cxx_pm_expression (pp, TREE_OPERAND (t, 0));
! pp_dot (pp);
! pp_star(pp);
! pp_c_cast_expression (pp_c_base (pp), TREE_OPERAND (t, 1));
! break;
!
!
! default:
! pp_c_cast_expression (pp_c_base (pp), t);
! break;
! }
! }
!
! /* multiplicative-expression:
! pm-expression
! multiplicative-expression * pm-expression
! multiplicative-expression / pm-expression
! multiplicative-expression % pm-expression */
! static void
! pp_cxx_multiplicative_expression (cxx_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_cxx_multiplicative_expression (pp, TREE_OPERAND (e, 0));
! pp_space (pp);
! if (code == MULT_EXPR)
! pp_star (pp);
! else if (code == TRUNC_DIV_EXPR)
! pp_slash (pp);
! else
! pp_modulo (pp);
! pp_space (pp);
! pp_cxx_pm_expression (pp, TREE_OPERAND (e, 1));
! break;
!
! default:
! pp_cxx_pm_expression (pp, e);
! break;
! }
! }
!
!
! /* conditional-expression:
! logical-or-expression
! logical-or-expression ? expression : assignment-expression */
! static void
! pp_cxx_conditional_expression (cxx_pretty_printer *pp, tree e)
! {
! if (TREE_CODE (e) == COND_EXPR)
! {
! pp_c_logical_or_expression (pp_c_base (pp), TREE_OPERAND (e, 0));
! pp_space (pp);
! pp_question (pp);
! pp_space (pp);
! pp_c_expression (pp_c_base (pp), TREE_OPERAND (e, 1));
! pp_space (pp);
! pp_cxx_assignment_expression (pp, TREE_OPERAND (e, 2));
! }
! else
! pp_c_logical_or_expression (pp_c_base (pp), e);
! }
!
! /* assignment-expression:
! conditional-expression
! logical-or-expression assignment-operator assignment-expression
!
! assignment-expression: one of
! = *= /= %= += -= >>= <<= &= ^= |= */
! static void
! pp_cxx_assignment_expression (cxx_pretty_printer *pp, tree e)
! {
! if (TREE_CODE (e) == MODIFY_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);
}
*************** pp_cxx_pretty_printer_init (cxx_pretty_p
*** 146,156 ****
pp->c_base.parameter_declaration = (pp_fun) pp_cxx_parameter_declaration;
pp->c_base.type_id = (pp_fun) pp_cxx_type_id;
pp->c_base.statement = (pp_fun) pp_cxx_statement;
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_multiplicatice_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;
--- 683,694 ----
pp->c_base.parameter_declaration = (pp_fun) pp_cxx_parameter_declaration;
pp->c_base.type_id = (pp_fun) pp_cxx_type_id;
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;
Index: cp/cxx-pretty-print.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/cxx-pretty-print.h,v
retrieving revision 1.1
diff -p -r1.1 cxx-pretty-print.h
*** cp/cxx-pretty-print.h 5 Aug 2003 19:23:14 -0000 1.1
--- cp/cxx-pretty-print.h 10 Aug 2003 17:06:51 -0000
*************** Software Foundation, 59 Temple Place - S
*** 27,32 ****
--- 27,40 ----
#undef pp_c_base
#define pp_c_base(PP) (&(PP)->c_base)
+ typedef enum
+ {
+ /* Ask for an qualified-id. */
+ pp_cxx_flag_qualified_id = 1 << pp_c_flag_last_bit,
+ pp_cxx_flag_global_scope = 1 << (pp_c_flag_last_bit + 1)
+
+ } cxx_pretty_printer_flags;
+
typedef struct
{
struct c_pretty_print_info c_base;
*************** void pp_cxx_pretty_printer_init (cxx_pre
*** 38,44 ****
void pp_cxx_declaration (cxx_pretty_printer *, tree);
void pp_cxx_statement (cxx_pretty_printer *, tree);
- void pp_cxx_expression (cxx_pretty_printer *, tree);
#endif /* GCC_CXX_PRETTY_PRINT_H */
--- 46,51 ----
Index: cp/error.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/error.c,v
retrieving revision 1.230
diff -p -r1.230 error.c
*** cp/error.c 10 Aug 2003 15:10:34 -0000 1.230
--- cp/error.c 10 Aug 2003 17:06:52 -0000
*************** dump_expr (tree t, int flags)
*** 1331,1368 ****
break;
case INTEGER_CST:
! {
! tree type = TREE_TYPE (t);
! my_friendly_assert (type != 0, 81);
!
! /* If it's an enum, output its tag, rather than its value. */
! if (TREE_CODE (type) == ENUMERAL_TYPE)
! {
! tree values = TYPE_VALUES (type);
!
! for (; values;
! values = TREE_CHAIN (values))
! if (tree_int_cst_equal (TREE_VALUE (values), t))
! break;
!
! if (values)
! pp_tree_identifier (cxx_pp, TREE_PURPOSE (values));
! else
! {
! /* Value must have been cast. */
! pp_left_paren (cxx_pp);
! dump_type (type, flags);
! pp_right_paren (cxx_pp);
! pp_c_integer_literal (pp_c_base (cxx_pp), t);
! }
! }
! else
! pp_c_integer_literal (pp_c_base (cxx_pp), t);
! }
! break;
!
case REAL_CST:
! pp_c_real_literal (pp_c_base (cxx_pp), t);
break;
case PTRMEM_CST:
--- 1331,1339 ----
break;
case INTEGER_CST:
! case STRING_CST:
case REAL_CST:
! pp_c_constant (pp_c_base (cxx_pp), t);
break;
case PTRMEM_CST:
*************** dump_expr (tree t, int flags)
*** 1370,1379 ****
dump_type (PTRMEM_CST_CLASS (t), flags);
pp_colon_colon (cxx_pp);
pp_tree_identifier (cxx_pp, DECL_NAME (PTRMEM_CST_MEMBER (t)));
- break;
-
- case STRING_CST:
- pp_c_string_literal (pp_c_base (cxx_pp), t);
break;
case COMPOUND_EXPR:
--- 1341,1346 ----