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); }
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; } }
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; } }
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: /* 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)); if (TREE_CODE (t) == POINTER_TYPE) pp_c_star (pp); else pp_c_ampersand (pp); pp_c_type_qualifier_list (pp, t); break; /* APPLE LOCAL begin blocks */ case BLOCK_POINTER_TYPE: pp_c_caret (pp); pp_c_type_qualifier_list (pp, t); break; /* APPLE LOCAL end blocks */ /* ??? This node is now in GENERIC and so shouldn't be here. But we'll fix that later. */ case DECL_EXPR: pp_declaration (pp, DECL_EXPR_DECL (t)); pp_needs_newline (pp) = true; break; default: pp_unsupported_tree (pp, t); } }
void pp_c_constant (c_pretty_printer *pp, tree e) { const enum tree_code code = TREE_CODE (e); switch (code) { 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_direct_abstract_declarator (c_pretty_printer *pp, tree t) { switch (TREE_CODE (t)) { case POINTER_TYPE: /* APPLE LOCAL blocks */ case BLOCK_POINTER_TYPE: pp_abstract_declarator (pp, t); break; case FUNCTION_TYPE: pp_c_parameter_type_list (pp, t); pp_direct_abstract_declarator (pp, TREE_TYPE (t)); break; case ARRAY_TYPE: pp_c_left_bracket (pp); if (TYPE_DOMAIN (t) && TYPE_MAX_VALUE (TYPE_DOMAIN (t))) { tree maxval = TYPE_MAX_VALUE (TYPE_DOMAIN (t)); tree type = TREE_TYPE (maxval); if (host_integerp (maxval, 0)) pp_wide_integer (pp, tree_low_cst (maxval, 0) + 1); else pp_expression (pp, fold (build2 (PLUS_EXPR, type, maxval, build_int_cst (type, 1)))); } pp_c_right_bracket (pp); pp_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_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_space_for_pointer_operator (pp, TREE_TYPE (t)); pp_c_tree_decl_identifier (pp, t); break; case ARRAY_TYPE: case POINTER_TYPE: /* APPLE LOCAL blocks */ case BLOCK_POINTER_TYPE: pp_abstract_declarator (pp, TREE_TYPE (t)); break; case FUNCTION_TYPE: 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_decl_identifier (pp, t); if (pp_c_base (pp)->flags & pp_c_flag_abstract) pp_abstract_declarator (pp, TREE_TYPE (t)); else { pp_parameter_list (pp, t); pp_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; } }
/* 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)) switch (DECL_USE_TEMPLATE (t)) { case 1: pp_cxx_template_declaration (pp, t); break; case 2: pp_cxx_explicit_specialization (pp, t); break; case 3: pp_cxx_explicit_instantiation (pp, t); break; default: break; } 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; case NAMESPACE_DECL: if (DECL_NAMESPACE_ALIAS (t)) pp_cxx_namespace_alias_definition (pp, t); else pp_cxx_original_namespace_definition (pp, t); break; default: pp_unsupported_tree (pp, t); break; } }
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)) { if (TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE) pp_cxx_left_paren (pp); pp_cxx_nested_name_specifier (pp, TYPE_PTRMEM_CLASS_TYPE (t)); pp_star (pp); pp_cxx_cv_qualifier_seq (pp, t); break; } /* else fall through. */ default: pp_unsupported_tree (pp, t); break; } }
static void pp_c_compound_literal (c_pretty_printer *pp, tree e) { tree type = TREE_TYPE (e); pp_c_type_cast (pp, type); switch (TREE_CODE (type)) { case RECORD_TYPE: case UNION_TYPE: case ARRAY_TYPE: case VECTOR_TYPE: case COMPLEX_TYPE: pp_c_brace_enclosed_initializer_list (pp, e); break; default: pp_unsupported_tree (pp, e); break; } }
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_cxx_colon_colon (pp); pp_cxx_identifier (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); } }
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: pp_c_tree_decl_identifier (pp, t); break; case IDENTIFIER_NODE: pp_c_tree_identifier (pp, t); break; default: pp_unsupported_tree (pp, t); break; } }
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_cxx_colon_colon (pp); pp_cxx_identifier (pp, "new"); if (TREE_OPERAND (t, 0)) { pp_cxx_call_argument_list (pp, TREE_OPERAND (t, 0)); 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_cxx_expression (pp, t); pp_right_paren (pp); } break; default: pp_unsupported_tree (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); }
void pp_c_type_specifier (c_pretty_printer *pp, tree t) { const enum tree_code code = TREE_CODE (t); switch (code) { case ERROR_MARK: pp_c_identifier (pp, "<type-error>"); break; case IDENTIFIER_NODE: pp_c_tree_decl_identifier (pp, t); break; case VOID_TYPE: case BOOLEAN_TYPE: case INTEGER_TYPE: case REAL_TYPE: if (TYPE_NAME (t)) { t = TYPE_NAME (t); pp_c_type_specifier (pp, t); } else { int prec = TYPE_PRECISION (t); t = c_common_type_for_mode (TYPE_MODE (t), TYPE_UNSIGNED (t)); if (TYPE_NAME (t)) { pp_c_type_specifier (pp, t); if (TYPE_PRECISION (t) != prec) { pp_string (pp, ":"); pp_decimal_int (pp, prec); } } else { switch (code) { case INTEGER_TYPE: pp_string (pp, (TYPE_UNSIGNED (t) ? "<unnamed-unsigned:" : "<unnamed-signed:")); break; case REAL_TYPE: pp_string (pp, "<unnamed-float:"); break; default: gcc_unreachable (); } pp_decimal_int (pp, prec); pp_string (pp, ">"); } } break; case TYPE_DECL: if (DECL_NAME (t)) pp_id_expression (pp, t); else pp_c_identifier (pp, "<typedef-error>"); break; case UNION_TYPE: case RECORD_TYPE: case ENUMERAL_TYPE: if (code == UNION_TYPE) pp_c_identifier (pp, "union"); else if (code == RECORD_TYPE) pp_c_identifier (pp, "struct"); else if (code == ENUMERAL_TYPE) pp_c_identifier (pp, "enum"); else pp_c_identifier (pp, "<tag-error>"); if (TYPE_NAME (t)) pp_id_expression (pp, TYPE_NAME (t)); else pp_c_identifier (pp, "<anonymous>"); break; default: pp_unsupported_tree (pp, t); break; } }
static void pp_c_initializer_list (c_pretty_printer *pp, tree e) { tree type = TREE_TYPE (e); const enum tree_code code = TREE_CODE (type); switch (code) { case RECORD_TYPE: case UNION_TYPE: case 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 (pp); pp_c_primary_expression (pp, TREE_PURPOSE (init)); } else { pp_c_left_bracket (pp); if (TREE_PURPOSE (init)) pp_c_constant (pp, TREE_PURPOSE (init)); pp_c_right_bracket (pp); } pp_c_whitespace (pp); pp_equal (pp); pp_c_whitespace (pp); pp_initializer (pp, TREE_VALUE (init)); if (TREE_CHAIN (init)) pp_separate_with (pp, ','); } } return; case VECTOR_TYPE: if (TREE_CODE (e) == VECTOR_CST) pp_c_expression_list (pp, TREE_VECTOR_CST_ELTS (e)); else if (TREE_CODE (e) == CONSTRUCTOR) pp_c_constructor_elts (pp, CONSTRUCTOR_ELTS (e)); else break; return; case COMPLEX_TYPE: if (TREE_CODE (e) == CONSTRUCTOR) pp_c_constructor_elts (pp, CONSTRUCTOR_ELTS (e)); else if (TREE_CODE (e) == COMPLEX_CST || TREE_CODE (e) == COMPLEX_EXPR) { const bool cst = TREE_CODE (e) == COMPLEX_CST; pp_expression (pp, cst ? TREE_REALPART (e) : TREE_OPERAND (e, 0)); pp_separate_with (pp, ','); pp_expression (pp, cst ? TREE_IMAGPART (e) : TREE_OPERAND (e, 1)); } else break; return; default: break; } pp_unsupported_tree (pp, type); }
static void pp_cxx_unqualified_id (cxx_pretty_printer *pp, tree t) { 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 TYPE_DECL: case FUNCTION_DECL: case NAMESPACE_DECL: case FIELD_DECL: case LABEL_DECL: case USING_DECL: case TEMPLATE_DECL: t = DECL_NAME (t); case IDENTIFIER_NODE: if (t == NULL) pp_cxx_identifier (pp, "<unnamed>"); else if (IDENTIFIER_TYPENAME_P (t)) pp_cxx_conversion_function_id (pp, t); else { if (is_destructor_name (t)) { pp_complement (pp); /* FIXME: Why is this necessary? */ if (TREE_TYPE (t)) t = constructor_name (TREE_TYPE (t)); } pp_cxx_tree_identifier (pp, t); } break; case TEMPLATE_ID_EXPR: pp_cxx_template_id (pp, t); break; case BASELINK: pp_cxx_unqualified_id (pp, BASELINK_FUNCTIONS (t)); break; case RECORD_TYPE: case UNION_TYPE: case ENUMERAL_TYPE: pp_cxx_unqualified_id (pp, TYPE_NAME (t)); break; case TEMPLATE_TYPE_PARM: case TEMPLATE_TEMPLATE_PARM: if (TYPE_IDENTIFIER (t)) pp_cxx_unqualified_id (pp, TYPE_IDENTIFIER (t)); else pp_cxx_canonical_template_parameter (pp, t); break; case TEMPLATE_PARM_INDEX: pp_cxx_unqualified_id (pp, TEMPLATE_PARM_DECL (t)); break; default: pp_unsupported_tree (pp, t); break; } }