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 |
|
26 #if defined (__GNUG__) |
|
27 #pragma interface |
|
28 #endif |
|
29 |
2530
|
30 #include <string> |
|
31 |
2123
|
32 #include "pt-walk.h" |
|
33 |
2961
|
34 class tree_expression; |
|
35 |
2123
|
36 // How to print the code that the parse trees represent. |
|
37 |
|
38 class |
|
39 tree_print_code : public tree_walker |
|
40 { |
|
41 public: |
|
42 |
2530
|
43 tree_print_code (ostream& os_arg, const string& pfx = string (), |
|
44 bool pr_orig_txt = true) |
|
45 : os (os_arg), prefix (pfx), print_original_text (pr_orig_txt) { } |
2123
|
46 |
|
47 ~tree_print_code (void) { } |
|
48 |
|
49 void visit_argument_list (tree_argument_list&); |
|
50 |
|
51 void visit_binary_expression (tree_binary_expression&); |
|
52 |
|
53 void visit_break_command (tree_break_command&); |
|
54 |
|
55 void visit_colon_expression (tree_colon_expression&); |
|
56 |
|
57 void visit_continue_command (tree_continue_command&); |
|
58 |
2846
|
59 void visit_decl_command (tree_decl_command&); |
|
60 |
|
61 void visit_decl_elt (tree_decl_elt&); |
|
62 |
|
63 void visit_decl_init_list (tree_decl_init_list&); |
|
64 |
2969
|
65 void visit_simple_for_command (tree_simple_for_command&); |
|
66 |
|
67 void visit_complex_for_command (tree_complex_for_command&); |
2123
|
68 |
2891
|
69 void visit_octave_user_function (octave_user_function&); |
2123
|
70 |
2891
|
71 void visit_octave_user_function_header (octave_user_function&); |
2123
|
72 |
2891
|
73 void visit_octave_user_function_trailer (octave_user_function&); |
2123
|
74 |
|
75 void visit_identifier (tree_identifier&); |
|
76 |
|
77 void visit_if_clause (tree_if_clause&); |
|
78 |
|
79 void visit_if_command (tree_if_command&); |
|
80 |
|
81 void visit_if_command_list (tree_if_command_list&); |
|
82 |
|
83 void visit_index_expression (tree_index_expression&); |
|
84 |
|
85 void visit_indirect_ref (tree_indirect_ref&); |
|
86 |
|
87 void visit_matrix (tree_matrix&); |
|
88 |
2969
|
89 void visit_multi_assignment (tree_multi_assignment&); |
2123
|
90 |
2620
|
91 void visit_no_op_command (tree_no_op_command&); |
|
92 |
2372
|
93 void visit_constant (tree_constant&); |
2123
|
94 |
|
95 void visit_parameter_list (tree_parameter_list&); |
|
96 |
|
97 void visit_plot_command (tree_plot_command&); |
|
98 |
|
99 void visit_plot_limits (plot_limits&); |
|
100 |
|
101 void visit_plot_range (plot_range&); |
|
102 |
|
103 void visit_postfix_expression (tree_postfix_expression&); |
|
104 |
|
105 void visit_prefix_expression (tree_prefix_expression&); |
|
106 |
|
107 void visit_return_command (tree_return_command&); |
|
108 |
|
109 void visit_return_list (tree_return_list&); |
|
110 |
2969
|
111 void visit_simple_assignment (tree_simple_assignment&); |
2123
|
112 |
|
113 void visit_statement (tree_statement&); |
|
114 |
|
115 void visit_statement_list (tree_statement_list&); |
|
116 |
|
117 void visit_subplot (subplot&); |
|
118 |
|
119 void visit_subplot_list (subplot_list&); |
|
120 |
|
121 void visit_subplot_style (subplot_style&); |
|
122 |
|
123 void visit_subplot_using (subplot_using&); |
|
124 |
2846
|
125 void visit_switch_case (tree_switch_case&); |
|
126 |
|
127 void visit_switch_case_list (tree_switch_case_list&); |
|
128 |
|
129 void visit_switch_command (tree_switch_command&); |
|
130 |
2123
|
131 void visit_try_catch_command (tree_try_catch_command&); |
|
132 |
|
133 void visit_unwind_protect_command (tree_unwind_protect_command&); |
|
134 |
|
135 void visit_while_command (tree_while_command&); |
|
136 |
|
137 private: |
|
138 |
|
139 ostream& os; |
|
140 |
2530
|
141 string prefix; |
|
142 |
|
143 bool print_original_text; |
|
144 |
2123
|
145 static int curr_print_indent_level; |
|
146 static bool beginning_of_line; |
|
147 |
|
148 void reset_indent_level (void) |
|
149 { curr_print_indent_level = 0; } |
|
150 |
|
151 void increment_indent_level (void) |
|
152 { curr_print_indent_level += 2; } |
|
153 |
|
154 void decrement_indent_level (void) |
|
155 { curr_print_indent_level -= 2; } |
|
156 |
|
157 void newline (void); |
|
158 |
|
159 void indent (void); |
|
160 |
|
161 void reset (void); |
|
162 |
2961
|
163 void print_parens (const tree_expression& expr, const char *txt); |
|
164 |
2123
|
165 // Must create with an output stream! |
|
166 |
|
167 tree_print_code (void); |
|
168 |
|
169 // No copying! |
|
170 |
|
171 tree_print_code (const tree_print_code&); |
|
172 |
|
173 tree_print_code& operator = (const tree_print_code&); |
|
174 }; |
|
175 |
|
176 #endif |
|
177 |
|
178 /* |
|
179 ;;; Local Variables: *** |
|
180 ;;; mode: C++ *** |
|
181 ;;; End: *** |
|
182 */ |