00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #if !defined (octave_tree_print_code_h)
00025 #define octave_tree_print_code_h 1
00026
00027 #include <stack>
00028 #include <string>
00029
00030 #include "comment-list.h"
00031 #include "pt-walk.h"
00032
00033 class tree_decl_command;
00034 class tree_expression;
00035
00036
00037
00038 class
00039 tree_print_code : public tree_walker
00040 {
00041 public:
00042
00043 tree_print_code (std::ostream& os_arg,
00044 const std::string& pfx = std::string (),
00045 bool pr_orig_txt = true)
00046 : os (os_arg), prefix (pfx), nesting (),
00047 print_original_text (pr_orig_txt),
00048 curr_print_indent_level (0), beginning_of_line (true),
00049 printing_newlines (true)
00050 {
00051
00052 nesting.push ('n');
00053 }
00054
00055 ~tree_print_code (void) { }
00056
00057 void visit_anon_fcn_handle (tree_anon_fcn_handle&);
00058
00059 void visit_argument_list (tree_argument_list&);
00060
00061 void visit_binary_expression (tree_binary_expression&);
00062
00063 void visit_break_command (tree_break_command&);
00064
00065 void visit_colon_expression (tree_colon_expression&);
00066
00067 void visit_continue_command (tree_continue_command&);
00068
00069 void visit_global_command (tree_global_command&);
00070
00071 void visit_static_command (tree_static_command&);
00072
00073 void visit_decl_elt (tree_decl_elt&);
00074
00075 void visit_decl_init_list (tree_decl_init_list&);
00076
00077 void visit_simple_for_command (tree_simple_for_command&);
00078
00079 void visit_complex_for_command (tree_complex_for_command&);
00080
00081 void visit_octave_user_script (octave_user_script&);
00082
00083 void visit_octave_user_function (octave_user_function&);
00084
00085 void visit_octave_user_function_header (octave_user_function&);
00086
00087 void visit_octave_user_function_trailer (octave_user_function&);
00088
00089 void visit_function_def (tree_function_def&);
00090
00091 void visit_identifier (tree_identifier&);
00092
00093 void visit_if_clause (tree_if_clause&);
00094
00095 void visit_if_command (tree_if_command&);
00096
00097 void visit_if_command_list (tree_if_command_list&);
00098
00099 void visit_index_expression (tree_index_expression&);
00100
00101 void visit_matrix (tree_matrix&);
00102
00103 void visit_cell (tree_cell&);
00104
00105 void visit_multi_assignment (tree_multi_assignment&);
00106
00107 void visit_no_op_command (tree_no_op_command&);
00108
00109 void visit_constant (tree_constant&);
00110
00111 void visit_fcn_handle (tree_fcn_handle&);
00112
00113 void visit_parameter_list (tree_parameter_list&);
00114
00115 void visit_postfix_expression (tree_postfix_expression&);
00116
00117 void visit_prefix_expression (tree_prefix_expression&);
00118
00119 void visit_return_command (tree_return_command&);
00120
00121 void visit_return_list (tree_return_list&);
00122
00123 void visit_simple_assignment (tree_simple_assignment&);
00124
00125 void visit_statement (tree_statement&);
00126
00127 void visit_statement_list (tree_statement_list&);
00128
00129 void visit_switch_case (tree_switch_case&);
00130
00131 void visit_switch_case_list (tree_switch_case_list&);
00132
00133 void visit_switch_command (tree_switch_command&);
00134
00135 void visit_try_catch_command (tree_try_catch_command&);
00136
00137 void visit_unwind_protect_command (tree_unwind_protect_command&);
00138
00139 void visit_while_command (tree_while_command&);
00140
00141 void visit_do_until_command (tree_do_until_command&);
00142
00143 void suspend_newline (void) { printing_newlines = false; }
00144
00145 void resume_newline (void) { printing_newlines = true; }
00146
00147 private:
00148
00149 std::ostream& os;
00150
00151 std::string prefix;
00152
00153 std::stack<char> nesting;
00154
00155 bool print_original_text;
00156
00157
00158 int curr_print_indent_level;
00159
00160
00161 bool beginning_of_line;
00162
00163
00164 bool printing_newlines;
00165
00166 void do_decl_command (tree_decl_command& cmd);
00167
00168 void reset_indent_level (void) { curr_print_indent_level = 0; }
00169
00170 void increment_indent_level (void) { curr_print_indent_level += 2; }
00171
00172 void decrement_indent_level (void) { curr_print_indent_level -= 2; }
00173
00174 void newline (const char *alt_txt = ", ");
00175
00176 void indent (void);
00177
00178 void reset (void);
00179
00180 void print_parens (const tree_expression& expr, const char *txt);
00181
00182 void print_comment_list (octave_comment_list *comment_list);
00183
00184 void print_comment_elt (const octave_comment_elt& comment_elt);
00185
00186 void print_indented_comment (octave_comment_list *comment_list);
00187
00188
00189
00190 tree_print_code (void);
00191
00192
00193
00194 tree_print_code (const tree_print_code&);
00195
00196 tree_print_code& operator = (const tree_print_code&);
00197 };
00198
00199 #endif
00200
00201
00202
00203
00204
00205