static inline void pp_cxx_template_keyword_if_needed (cxx_pretty_printer *pp, tree scope, tree t) { if (TREE_CODE (t) == TEMPLATE_ID_EXPR && TYPE_P (scope) && dependent_type_p (scope)) pp_cxx_identifier (pp, "template"); }
static void pp_cxx_assignment_operator (cxx_pretty_printer *pp, tree t) { const char *op; switch (TREE_CODE (t)) { case NOP_EXPR: op = "="; break; case PLUS_EXPR: op = "+="; break; case MINUS_EXPR: op = "-="; break; case TRUNC_DIV_EXPR: op = "/="; break; case TRUNC_MOD_EXPR: op = "%="; break; default: op = tree_code_name[TREE_CODE (t)]; break; } pp_cxx_identifier (pp, op); }
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_cxx_simple_type_specifier (cxx_pretty_printer *pp, tree t) { switch (TREE_CODE (t)) { case RECORD_TYPE: case UNION_TYPE: case ENUMERAL_TYPE: pp_cxx_qualified_id (pp, t); break; case TEMPLATE_TYPE_PARM: case TEMPLATE_TEMPLATE_PARM: case TEMPLATE_PARM_INDEX: pp_cxx_unqualified_id (pp, t); break; case TYPENAME_TYPE: pp_cxx_identifier (pp, "typename"); pp_cxx_nested_name_specifier (pp, TYPE_CONTEXT (t)); pp_cxx_unqualified_id (pp, TYPE_NAME (t)); break; default: pp_c_type_specifier (pp_c_base (pp), t); break; } }
static void pp_cxx_assignment_expression (cxx_pretty_printer *pp, tree e) { switch (TREE_CODE (e)) { case MODIFY_EXPR: case INIT_EXPR: pp_c_logical_or_expression (pp_c_base (pp), TREE_OPERAND (e, 0)); pp_space (pp); pp_equal (pp); pp_space (pp); pp_cxx_assignment_expression (pp, TREE_OPERAND (e, 1)); break; case THROW_EXPR: pp_cxx_identifier (pp, "throw"); if (TREE_OPERAND (e, 0)) pp_cxx_assignment_expression (pp, TREE_OPERAND (e, 0)); break; case MODOP_EXPR: pp_c_logical_or_expression (pp_c_base (pp), TREE_OPERAND (e, 0)); pp_cxx_assignment_operator (pp, TREE_OPERAND (e, 1)); pp_cxx_assignment_expression (pp, TREE_OPERAND (e, 2)); break; default: pp_cxx_conditional_expression (pp, e); break; } }
static void pp_cxx_function_specifier (cxx_pretty_printer *pp, tree t) { switch (TREE_CODE (t)) { case FUNCTION_DECL: if (DECL_VIRTUAL_P (t)) pp_cxx_identifier (pp, "virtual"); else if (DECL_CONSTRUCTOR_P (t) && DECL_NONCONVERTING_P (t)) pp_cxx_identifier (pp, "explicit"); else pp_c_function_specifier (pp_c_base (pp), t); default: break; } }
static void pp_cxx_namespace_alias_definition (cxx_pretty_printer *pp, tree t) { pp_cxx_identifier (pp, "namespace"); pp_cxx_unqualified_id (pp, t); pp_cxx_whitespace (pp); pp_equal (pp); pp_cxx_whitespace (pp); pp_cxx_qualified_id (pp, DECL_NAMESPACE_ALIAS (t)); pp_cxx_semicolon (pp); }
static void pp_cxx_original_namespace_definition (cxx_pretty_printer *pp, tree t) { pp_cxx_identifier (pp, "namespace"); if (DECL_NAME (t)) pp_cxx_unqualified_id (pp, t); pp_cxx_whitespace (pp); pp_cxx_left_brace (pp); /* We do not print the namespace-body. */ pp_cxx_whitespace (pp); pp_cxx_right_brace (pp); }
void pp_cxx_canonical_template_parameter (cxx_pretty_printer *pp, tree parm) { const enum tree_code code = TREE_CODE (parm); /* Brings type template parameters to the canonical forms. */ if (code == TEMPLATE_TYPE_PARM || code == TEMPLATE_TEMPLATE_PARM || code == BOUND_TEMPLATE_TEMPLATE_PARM) parm = TEMPLATE_TYPE_PARM_INDEX (parm); pp_cxx_begin_template_argument_list (pp); pp_cxx_identifier (pp, "template-parameter-"); pp_wide_integer (pp, TEMPLATE_PARM_LEVEL (parm)); pp_minus (pp); pp_wide_integer (pp, TEMPLATE_PARM_IDX (parm) + 1); pp_cxx_end_template_argument_list (pp); }
static void pp_cxx_exception_specification (cxx_pretty_printer *pp, tree t) { tree ex_spec = TYPE_RAISES_EXCEPTIONS (t); if (!TYPE_NOTHROW_P (t) && ex_spec == NULL) return; pp_cxx_identifier (pp, "throw"); pp_cxx_left_paren (pp); for (; ex_spec && TREE_VALUE (ex_spec); ex_spec = TREE_CHAIN (ex_spec)) { pp_cxx_type_id (pp, TREE_VALUE (ex_spec)); if (TREE_CHAIN (ex_spec)) pp_cxx_separate_with (pp, ','); } pp_cxx_right_paren (pp); }
static void pp_cxx_decl_specifier_seq (cxx_pretty_printer *pp, tree t) { switch (TREE_CODE (t)) { case VAR_DECL: case PARM_DECL: case CONST_DECL: case FIELD_DECL: pp_cxx_storage_class_specifier (pp, t); pp_cxx_decl_specifier_seq (pp, TREE_TYPE (t)); break; case TYPE_DECL: pp_cxx_identifier (pp, "typedef"); pp_cxx_decl_specifier_seq (pp, TREE_TYPE (t)); break; case RECORD_TYPE: if (TYPE_PTRMEMFUNC_P (t)) { tree pfm = TYPE_PTRMEMFUNC_FN_TYPE (t); pp_cxx_decl_specifier_seq (pp, TREE_TYPE (TREE_TYPE (pfm))); pp_cxx_whitespace (pp); pp_cxx_ptr_operator (pp, t); } break; case FUNCTION_DECL: /* Constructors don't have return types. And conversion functions do not have a type-specifier in their return types. */ if (DECL_CONSTRUCTOR_P (t) || DECL_CONV_FN_P (t)) pp_cxx_function_specifier (pp, t); else if (DECL_NONSTATIC_MEMBER_FUNCTION_P (t)) pp_cxx_decl_specifier_seq (pp, TREE_TYPE (TREE_TYPE (t))); else default: pp_c_declaration_specifiers (pp_c_base (pp), t); break; } }
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; case SIZEOF_EXPR: case ALIGNOF_EXPR: pp_cxx_identifier (pp, code == SIZEOF_EXPR ? "sizeof" : "__alignof__"); pp_cxx_whitespace (pp); if (TYPE_P (TREE_OPERAND (t, 0))) { pp_cxx_left_paren (pp); pp_cxx_type_id (pp, TREE_OPERAND (t, 0)); pp_cxx_right_paren (pp); } else pp_unary_expression (pp, TREE_OPERAND (t, 0)); break; case UNARY_PLUS_EXPR: pp_plus (pp); pp_cxx_cast_expression (pp, TREE_OPERAND (t, 0)); break; default: pp_c_unary_expression (pp_c_base (pp), t); break; } }
static void pp_cxx_template_declaration (cxx_pretty_printer *pp, tree t) { tree tmpl = most_general_template (t); tree level; int i = 0; pp_maybe_newline_and_indent (pp, 0); for (level = DECL_TEMPLATE_PARMS (tmpl); level; level = TREE_CHAIN (level)) { pp_cxx_identifier (pp, "template"); pp_cxx_begin_template_argument_list (pp); pp_cxx_template_parameter_list (pp, TREE_VALUE (level)); pp_cxx_end_template_argument_list (pp); pp_newline_and_indent (pp, 3); i += 3; } if (TREE_CODE (t) == FUNCTION_DECL && DECL_SAVED_TREE (t)) pp_cxx_function_definition (pp, t); else pp_cxx_simple_declaration (pp, t); }
static void pp_cxx_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); } }
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); } }
void pp_cxx_statement (cxx_pretty_printer *pp, tree t) { switch (TREE_CODE (t)) { case USING_STMT: pp_cxx_identifier (pp, "using"); pp_cxx_identifier (pp, "namespace"); pp_cxx_qualified_id (pp, USING_STMT_NAMESPACE (t)); break; case USING_DECL: pp_cxx_identifier (pp, "using"); pp_cxx_nested_name_specifier (pp, DECL_INITIAL (t)); pp_cxx_unqualified_id (pp, DECL_NAME (t)); break; case EH_SPEC_BLOCK: break; /* try-block: try compound-statement handler-seq */ case TRY_BLOCK: pp_maybe_newline_and_indent (pp, 0); pp_cxx_identifier (pp, "try"); pp_newline_and_indent (pp, 3); pp_cxx_statement (pp, TRY_STMTS (t)); pp_newline_and_indent (pp, -3); if (CLEANUP_P (t)) ; else pp_cxx_statement (pp, TRY_HANDLERS (t)); break; /* handler-seq: handler handler-seq(opt) handler: catch ( exception-declaration ) compound-statement exception-declaration: type-specifier-seq declarator type-specifier-seq abstract-declarator ... */ case HANDLER: pp_cxx_identifier (pp, "catch"); pp_cxx_left_paren (pp); pp_cxx_exception_declaration (pp, HANDLER_PARMS (t)); pp_cxx_right_paren (pp); pp_indentation (pp) += 3; pp_needs_newline (pp) = true; pp_cxx_statement (pp, HANDLER_BODY (t)); pp_indentation (pp) -= 3; pp_needs_newline (pp) = true; break; default: pp_c_statement (pp_c_base (pp), t); break; } }
static inline void pp_cxx_conversion_function_id (cxx_pretty_printer *pp, tree t) { pp_cxx_identifier (pp, "operator"); pp_cxx_type_specifier_seq (pp, TREE_TYPE (t)); }
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; } }
static void pp_cxx_statement (cxx_pretty_printer *pp, tree t) { switch (TREE_CODE (t)) { case CTOR_INITIALIZER: pp_cxx_ctor_initializer (pp, t); break; case USING_STMT: pp_cxx_identifier (pp, "using"); pp_cxx_identifier (pp, "namespace"); if (DECL_CONTEXT (t)) pp_cxx_nested_name_specifier (pp, DECL_CONTEXT (t)); pp_cxx_qualified_id (pp, USING_STMT_NAMESPACE (t)); break; case USING_DECL: pp_cxx_identifier (pp, "using"); pp_cxx_nested_name_specifier (pp, USING_DECL_SCOPE (t)); pp_cxx_unqualified_id (pp, DECL_NAME (t)); break; case EH_SPEC_BLOCK: break; /* try-block: try compound-statement handler-seq */ case TRY_BLOCK: pp_maybe_newline_and_indent (pp, 0); pp_cxx_identifier (pp, "try"); pp_newline_and_indent (pp, 3); pp_cxx_statement (pp, TRY_STMTS (t)); pp_newline_and_indent (pp, -3); if (CLEANUP_P (t)) ; else pp_cxx_statement (pp, TRY_HANDLERS (t)); break; /* handler-seq: handler handler-seq(opt) handler: catch ( exception-declaration ) compound-statement exception-declaration: type-specifier-seq declarator type-specifier-seq abstract-declarator ... */ case HANDLER: pp_cxx_identifier (pp, "catch"); pp_cxx_left_paren (pp); pp_cxx_exception_declaration (pp, HANDLER_PARMS (t)); pp_cxx_right_paren (pp); pp_indentation (pp) += 3; pp_needs_newline (pp) = true; pp_cxx_statement (pp, HANDLER_BODY (t)); pp_indentation (pp) -= 3; pp_needs_newline (pp) = true; break; /* selection-statement: if ( expression ) statement if ( expression ) statement else statement */ case IF_STMT: pp_cxx_identifier (pp, "if"); pp_cxx_whitespace (pp); pp_cxx_left_paren (pp); pp_cxx_expression (pp, IF_COND (t)); pp_cxx_right_paren (pp); pp_newline_and_indent (pp, 2); pp_cxx_statement (pp, THEN_CLAUSE (t)); pp_newline_and_indent (pp, -2); if (ELSE_CLAUSE (t)) { tree else_clause = ELSE_CLAUSE (t); pp_cxx_identifier (pp, "else"); if (TREE_CODE (else_clause) == IF_STMT) pp_cxx_whitespace (pp); else pp_newline_and_indent (pp, 2); pp_cxx_statement (pp, else_clause); if (TREE_CODE (else_clause) != IF_STMT) pp_newline_and_indent (pp, -2); } break; case SWITCH_STMT: pp_cxx_identifier (pp, "switch"); pp_space (pp); pp_cxx_left_paren (pp); pp_cxx_expression (pp, SWITCH_STMT_COND (t)); pp_cxx_right_paren (pp); pp_indentation (pp) += 3; pp_needs_newline (pp) = true; pp_cxx_statement (pp, SWITCH_STMT_BODY (t)); pp_newline_and_indent (pp, -3); break; /* iteration-statement: while ( expression ) statement do statement while ( expression ) ; for ( expression(opt) ; expression(opt) ; expression(opt) ) statement for ( declaration expression(opt) ; expression(opt) ) statement */ case WHILE_STMT: pp_cxx_identifier (pp, "while"); pp_space (pp); pp_cxx_left_paren (pp); pp_cxx_expression (pp, WHILE_COND (t)); pp_cxx_right_paren (pp); pp_newline_and_indent (pp, 3); pp_cxx_statement (pp, WHILE_BODY (t)); pp_indentation (pp) -= 3; pp_needs_newline (pp) = true; break; case DO_STMT: pp_cxx_identifier (pp, "do"); pp_newline_and_indent (pp, 3); pp_cxx_statement (pp, DO_BODY (t)); pp_newline_and_indent (pp, -3); pp_cxx_identifier (pp, "while"); pp_space (pp); pp_cxx_left_paren (pp); pp_cxx_expression (pp, DO_COND (t)); pp_cxx_right_paren (pp); pp_cxx_semicolon (pp); pp_needs_newline (pp) = true; break; case FOR_STMT: pp_cxx_identifier (pp, "for"); pp_space (pp); pp_cxx_left_paren (pp); if (FOR_INIT_STMT (t)) pp_cxx_statement (pp, FOR_INIT_STMT (t)); else pp_cxx_semicolon (pp); pp_needs_newline (pp) = false; pp_cxx_whitespace (pp); if (FOR_COND (t)) pp_cxx_expression (pp, FOR_COND (t)); pp_cxx_semicolon (pp); pp_needs_newline (pp) = false; pp_cxx_whitespace (pp); if (FOR_EXPR (t)) pp_cxx_expression (pp, FOR_EXPR (t)); pp_cxx_right_paren (pp); pp_newline_and_indent (pp, 3); pp_cxx_statement (pp, FOR_BODY (t)); pp_indentation (pp) -= 3; pp_needs_newline (pp) = true; break; /* jump-statement: goto identifier; continue ; return expression(opt) ; */ case BREAK_STMT: case CONTINUE_STMT: pp_identifier (pp, TREE_CODE (t) == BREAK_STMT ? "break" : "continue"); pp_cxx_semicolon (pp); pp_needs_newline (pp) = true; break; /* expression-statement: expression(opt) ; */ case EXPR_STMT: pp_cxx_expression (pp, EXPR_STMT_EXPR (t)); pp_cxx_semicolon (pp); pp_needs_newline (pp) = true; break; case CLEANUP_STMT: pp_cxx_identifier (pp, "try"); pp_newline_and_indent (pp, 2); pp_cxx_statement (pp, CLEANUP_BODY (t)); pp_newline_and_indent (pp, -2); pp_cxx_identifier (pp, CLEANUP_EH_ONLY (t) ? "catch" : "finally"); pp_newline_and_indent (pp, 2); pp_cxx_statement (pp, CLEANUP_EXPR (t)); pp_newline_and_indent (pp, -2); break; default: pp_c_statement (pp_c_base (pp), t); break; } }
static void pp_cxx_postfix_expression (cxx_pretty_printer *pp, tree t) { enum tree_code code = TREE_CODE (t); switch (code) { case AGGR_INIT_EXPR: case CALL_EXPR: { tree fun = TREE_OPERAND (t, 0); tree args = TREE_OPERAND (t, 1); tree saved_scope = pp->enclosing_scope; if (TREE_CODE (fun) == ADDR_EXPR) fun = TREE_OPERAND (fun, 0); /* In templates, where there is no way to tell whether a given call uses an actual member function. So the parser builds FUN as a COMPONENT_REF or a plain IDENTIFIER_NODE until instantiation time. */ if (TREE_CODE (fun) != FUNCTION_DECL) ; else if (DECL_NONSTATIC_MEMBER_FUNCTION_P (fun)) { tree object = code == AGGR_INIT_EXPR && AGGR_INIT_VIA_CTOR_P (t) ? TREE_OPERAND (t, 2) : TREE_VALUE (args); while (TREE_CODE (object) == NOP_EXPR) object = TREE_OPERAND (object, 0); if (TREE_CODE (object) == ADDR_EXPR) object = TREE_OPERAND (object, 0); if (TREE_CODE (TREE_TYPE (object)) != POINTER_TYPE) { pp_cxx_postfix_expression (pp, object); pp_cxx_dot (pp); } else { pp_cxx_postfix_expression (pp, object); pp_cxx_arrow (pp); } args = TREE_CHAIN (args); pp->enclosing_scope = strip_pointer_operator (TREE_TYPE (object)); } pp_cxx_postfix_expression (pp, fun); pp->enclosing_scope = saved_scope; pp_cxx_call_argument_list (pp, args); } if (code == AGGR_INIT_EXPR && AGGR_INIT_VIA_CTOR_P (t)) { pp_cxx_separate_with (pp, ','); pp_cxx_postfix_expression (pp, TREE_OPERAND (t, 2)); } break; case BASELINK: case VAR_DECL: case PARM_DECL: case FIELD_DECL: case FUNCTION_DECL: case OVERLOAD: case CONST_DECL: case TEMPLATE_DECL: case RESULT_DECL: pp_cxx_primary_expression (pp, t); break; case DYNAMIC_CAST_EXPR: case STATIC_CAST_EXPR: case REINTERPRET_CAST_EXPR: case CONST_CAST_EXPR: if (code == DYNAMIC_CAST_EXPR) pp_cxx_identifier (pp, "dynamic_cast"); else if (code == STATIC_CAST_EXPR) pp_cxx_identifier (pp, "static_cast"); else if (code == REINTERPRET_CAST_EXPR) pp_cxx_identifier (pp, "reinterpret_cast"); else pp_cxx_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_cxx_expression (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_cxx_identifier (pp, "typeid"); pp_left_paren (pp); if (TYPE_P (t)) pp_cxx_type_id (pp, t); else pp_cxx_expression (pp, t); pp_right_paren (pp); break; case PSEUDO_DTOR_EXPR: pp_cxx_postfix_expression (pp, TREE_OPERAND (t, 0)); pp_cxx_dot (pp); pp_cxx_qualified_id (pp, TREE_OPERAND (t, 1)); pp_cxx_colon_colon (pp); pp_complement (pp); pp_cxx_unqualified_id (pp, TREE_OPERAND (t, 2)); break; case ARROW_EXPR: pp_cxx_postfix_expression (pp, TREE_OPERAND (t, 0)); pp_cxx_arrow (pp); break; default: pp_c_postfix_expression (pp_c_base (pp), t); break; } }