2123
|
1 /* |
|
2 |
2847
|
3 Copyright (C) 1996, 1997 John W. Eaton |
2123
|
4 |
|
5 This file is part of Octave. |
|
6 |
|
7 Octave is free software; you can redistribute it and/or modify it |
|
8 under the terms of the GNU General Public License as published by the |
|
9 Free Software Foundation; either version 2, or (at your option) any |
|
10 later version. |
|
11 |
|
12 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
15 for more details. |
|
16 |
|
17 You should have received a copy of the GNU General Public License |
|
18 along with Octave; see the file COPYING. If not, write to the Free |
|
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
20 |
|
21 */ |
|
22 |
|
23 #if !defined (octave_tree_print_code_h) |
|
24 #define octave_tree_print_code_h 1 |
|
25 |
4192
|
26 #if defined (__GNUG__) && defined (USE_PRAGMA_INTERFACE_IMPLEMENTATION) |
2123
|
27 #pragma interface |
|
28 #endif |
|
29 |
4676
|
30 #include <stack> |
2530
|
31 #include <string> |
|
32 |
3665
|
33 #include "comment-list.h" |
2123
|
34 #include "pt-walk.h" |
|
35 |
2961
|
36 class tree_expression; |
|
37 |
2123
|
38 // How to print the code that the parse trees represent. |
|
39 |
|
40 class |
|
41 tree_print_code : public tree_walker |
|
42 { |
|
43 public: |
|
44 |
3708
|
45 tree_print_code (std::ostream& os_arg, |
|
46 const std::string& pfx = std::string (), |
2530
|
47 bool pr_orig_txt = true) |
4676
|
48 : os (os_arg), prefix (pfx), nesting (), |
|
49 print_original_text (pr_orig_txt), |
4980
|
50 curr_print_indent_level (0), beginning_of_line (true), |
|
51 printing_newlines (true) |
4676
|
52 { |
|
53 // For "none". |
|
54 nesting.push ('n'); |
|
55 } |
2123
|
56 |
|
57 ~tree_print_code (void) { } |
|
58 |
|
59 void visit_argument_list (tree_argument_list&); |
|
60 |
|
61 void visit_binary_expression (tree_binary_expression&); |
|
62 |
4207
|
63 void visit_break_command (tree_break_command&); |
2123
|
64 |
|
65 void visit_colon_expression (tree_colon_expression&); |
|
66 |
4207
|
67 void visit_continue_command (tree_continue_command&); |
2123
|
68 |
2846
|
69 void visit_decl_command (tree_decl_command&); |
|
70 |
|
71 void visit_decl_elt (tree_decl_elt&); |
|
72 |
|
73 void visit_decl_init_list (tree_decl_init_list&); |
|
74 |
2969
|
75 void visit_simple_for_command (tree_simple_for_command&); |
|
76 |
|
77 void visit_complex_for_command (tree_complex_for_command&); |
2123
|
78 |
2891
|
79 void visit_octave_user_function (octave_user_function&); |
2123
|
80 |
2891
|
81 void visit_octave_user_function_header (octave_user_function&); |
2123
|
82 |
2891
|
83 void visit_octave_user_function_trailer (octave_user_function&); |
2123
|
84 |
|
85 void visit_identifier (tree_identifier&); |
|
86 |
|
87 void visit_if_clause (tree_if_clause&); |
|
88 |
|
89 void visit_if_command (tree_if_command&); |
|
90 |
|
91 void visit_if_command_list (tree_if_command_list&); |
|
92 |
|
93 void visit_index_expression (tree_index_expression&); |
|
94 |
|
95 void visit_matrix (tree_matrix&); |
|
96 |
3351
|
97 void visit_cell (tree_cell&); |
|
98 |
2969
|
99 void visit_multi_assignment (tree_multi_assignment&); |
2123
|
100 |
2620
|
101 void visit_no_op_command (tree_no_op_command&); |
|
102 |
2372
|
103 void visit_constant (tree_constant&); |
2123
|
104 |
4342
|
105 void visit_fcn_handle (tree_fcn_handle&); |
|
106 |
2123
|
107 void visit_parameter_list (tree_parameter_list&); |
|
108 |
|
109 void visit_postfix_expression (tree_postfix_expression&); |
|
110 |
|
111 void visit_prefix_expression (tree_prefix_expression&); |
|
112 |
4207
|
113 void visit_return_command (tree_return_command&); |
2123
|
114 |
|
115 void visit_return_list (tree_return_list&); |
|
116 |
2969
|
117 void visit_simple_assignment (tree_simple_assignment&); |
2123
|
118 |
|
119 void visit_statement (tree_statement&); |
|
120 |
|
121 void visit_statement_list (tree_statement_list&); |
|
122 |
2846
|
123 void visit_switch_case (tree_switch_case&); |
|
124 |
|
125 void visit_switch_case_list (tree_switch_case_list&); |
|
126 |
|
127 void visit_switch_command (tree_switch_command&); |
|
128 |
2123
|
129 void visit_try_catch_command (tree_try_catch_command&); |
|
130 |
|
131 void visit_unwind_protect_command (tree_unwind_protect_command&); |
|
132 |
|
133 void visit_while_command (tree_while_command&); |
|
134 |
3484
|
135 void visit_do_until_command (tree_do_until_command&); |
|
136 |
4980
|
137 void suspend_newline (void) { printing_newlines = false; } |
|
138 |
|
139 void resume_newline (void) { printing_newlines = true; } |
|
140 |
2123
|
141 private: |
|
142 |
3523
|
143 std::ostream& os; |
2123
|
144 |
3523
|
145 std::string prefix; |
2530
|
146 |
4676
|
147 std::stack<char> nesting; |
|
148 |
2530
|
149 bool print_original_text; |
|
150 |
3708
|
151 // Current indentation. |
|
152 int curr_print_indent_level; |
|
153 |
|
154 // TRUE means we are at the beginning of a line. |
|
155 bool beginning_of_line; |
2123
|
156 |
4980
|
157 // TRUE means we are printing newlines and indenting. |
|
158 bool printing_newlines; |
|
159 |
3933
|
160 void reset_indent_level (void) { curr_print_indent_level = 0; } |
2123
|
161 |
3933
|
162 void increment_indent_level (void) { curr_print_indent_level += 2; } |
2123
|
163 |
3933
|
164 void decrement_indent_level (void) { curr_print_indent_level -= 2; } |
2123
|
165 |
4980
|
166 void newline (const char *alt_txt = ", "); |
2123
|
167 |
|
168 void indent (void); |
|
169 |
|
170 void reset (void); |
|
171 |
2961
|
172 void print_parens (const tree_expression& expr, const char *txt); |
|
173 |
3665
|
174 void print_comment_list (octave_comment_list *comment_list); |
|
175 |
|
176 void print_comment_elt (const octave_comment_elt& comment_elt); |
|
177 |
|
178 void print_indented_comment (octave_comment_list *comment_list); |
|
179 |
2123
|
180 // Must create with an output stream! |
|
181 |
|
182 tree_print_code (void); |
|
183 |
|
184 // No copying! |
|
185 |
|
186 tree_print_code (const tree_print_code&); |
|
187 |
|
188 tree_print_code& operator = (const tree_print_code&); |
|
189 }; |
|
190 |
|
191 #endif |
|
192 |
|
193 /* |
|
194 ;;; Local Variables: *** |
|
195 ;;; mode: C++ *** |
|
196 ;;; End: *** |
|
197 */ |