static void pp_cxx_parameter_declaration_clause (cxx_pretty_printer *pp, tree t) { tree args = TYPE_P (t) ? NULL : FUNCTION_FIRST_USER_PARM (t); tree types = TYPE_P (t) ? TYPE_ARG_TYPES (t) : FUNCTION_FIRST_USER_PARMTYPE (t); const bool abstract = args == NULL || pp_c_base (pp)->flags & pp_c_flag_abstract; bool first = true; /* Skip artificial parameter for nonstatic member functions. */ if (TREE_CODE (t) == METHOD_TYPE) types = TREE_CHAIN (types); pp_cxx_left_paren (pp); for (; args; args = TREE_CHAIN (args), types = TREE_CHAIN (types)) { if (!first) pp_cxx_separate_with (pp, ','); first = false; pp_cxx_parameter_declaration (pp, abstract ? TREE_VALUE (types) : args); if (!abstract && pp_c_base (pp)->flags & pp_cxx_flag_default_argument) { pp_cxx_whitespace (pp); pp_equal (pp); pp_cxx_whitespace (pp); pp_cxx_assignment_expression (pp, TREE_PURPOSE (types)); } } pp_cxx_right_paren (pp); }
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); }
static void pp_cxx_ctor_initializer (cxx_pretty_printer *pp, tree t) { t = TREE_OPERAND (t, 0); pp_cxx_whitespace (pp); pp_colon (pp); pp_cxx_whitespace (pp); for (; t; t = TREE_CHAIN (t)) { pp_cxx_primary_expression (pp, TREE_PURPOSE (t)); pp_cxx_call_argument_list (pp, TREE_VALUE (t)); if (TREE_CHAIN (t)) pp_cxx_separate_with (pp, ','); } }
static inline void pp_cxx_nonconsecutive_character (cxx_pretty_printer *pp, int c) { const char *p = pp_last_position_in_text (pp); if (p != NULL && *p == c) pp_cxx_whitespace (pp); pp_character (pp, c); pp_base (pp)->padding = pp_none; }
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_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; } }