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_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; } }
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; } }