Mercurial > hg > octave-lyh
annotate src/pt-pr-code.cc @ 13219:cf5ebc0e47e4
fix warnings for unused but set variables and shadowed variables
* quadcc.cc (Fquadcc): Delete unused variable err_excess.
* find.cc (find_nonzero_elem_idx (const PermMatrix&, int,
octave_idx_type, int)): Delete unused variable end_nc.
* eigs.cc (Feigs): Delete unused variable bmat.
* conv2.cc (Fconvn): Delete unused variable separable.
* colamd.cc (Fetree, Fsymamd): Delete unused variable nnz.
* ccolamd.cc (Fcsymamd): Delete unused variable nnz.
* pt-pr-code.cc (tree_print_code::visit_index_expression):
Delete unused variable expr_has_parens.
* pt-mat.cc (tree_matrix::rvalue1): Delete unused variables
all_complex_p and all_strings_p
(tm_const::init): Eliminate shadowed variables.
* gl-render.cc (opengl_renderer::draw_image): Delete unused
variable ok.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Sun, 25 Sep 2011 16:52:23 -0400 |
parents | 12df7854fa7c |
children | 027a2186cd90 |
rev | line source |
---|---|
2123 | 1 /* |
2 | |
11523 | 3 Copyright (C) 1996-2011 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 | |
7016 | 9 Free Software Foundation; either version 3 of the License, or (at your |
10 option) any later version. | |
2123 | 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 | |
7016 | 18 along with Octave; see the file COPYING. If not, see |
19 <http://www.gnu.org/licenses/>. | |
2123 | 20 |
21 */ | |
22 | |
23 #ifdef HAVE_CONFIG_H | |
24 #include <config.h> | |
25 #endif | |
26 | |
3665 | 27 #include <cctype> |
28 | |
3503 | 29 #include <iostream> |
2123 | 30 |
3665 | 31 #include "comment-list.h" |
2123 | 32 #include "error.h" |
2969 | 33 #include "ov-usr-fcn.h" |
2123 | 34 #include "pr-output.h" |
2988 | 35 #include "pt-all.h" |
2123 | 36 |
37 void | |
5861 | 38 tree_print_code::visit_anon_fcn_handle (tree_anon_fcn_handle& afh) |
39 { | |
40 indent (); | |
41 | |
42 print_parens (afh, "("); | |
43 | |
44 os << "@("; | |
45 | |
46 tree_parameter_list *param_list = afh.parameter_list (); | |
47 | |
48 if (param_list) | |
49 param_list->accept (*this); | |
50 | |
51 os << ") "; | |
52 | |
11223
64e7538db12a
fix printing of newlines for anonymous function handle bodies
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
53 print_fcn_handle_body (afh.body ()); |
5861 | 54 |
55 print_parens (afh, ")"); | |
56 } | |
57 | |
58 void | |
2123 | 59 tree_print_code::visit_argument_list (tree_argument_list& lst) |
60 { | |
4219 | 61 tree_argument_list::iterator p = lst.begin (); |
2123 | 62 |
4219 | 63 while (p != lst.end ()) |
2123 | 64 { |
4219 | 65 tree_expression *elt = *p++; |
2123 | 66 |
67 if (elt) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
68 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
69 elt->accept (*this); |
2123 | 70 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
71 if (p != lst.end ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
72 os << ", "; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
73 } |
2123 | 74 } |
75 } | |
76 | |
77 void | |
78 tree_print_code::visit_binary_expression (tree_binary_expression& expr) | |
79 { | |
80 indent (); | |
81 | |
2961 | 82 print_parens (expr, "("); |
2123 | 83 |
84 tree_expression *op1 = expr.lhs (); | |
85 | |
86 if (op1) | |
87 op1->accept (*this); | |
88 | |
89 os << " " << expr.oper () << " "; | |
90 | |
91 tree_expression *op2 = expr.rhs (); | |
92 | |
93 if (op2) | |
94 op2->accept (*this); | |
95 | |
2961 | 96 print_parens (expr, ")"); |
2123 | 97 } |
98 | |
99 void | |
4207 | 100 tree_print_code::visit_break_command (tree_break_command&) |
2123 | 101 { |
102 indent (); | |
103 | |
104 os << "break"; | |
105 } | |
106 | |
107 void | |
108 tree_print_code::visit_colon_expression (tree_colon_expression& expr) | |
109 { | |
110 indent (); | |
111 | |
2961 | 112 print_parens (expr, "("); |
2123 | 113 |
114 tree_expression *op1 = expr.base (); | |
115 | |
116 if (op1) | |
117 op1->accept (*this); | |
118 | |
119 // Stupid syntax. | |
120 | |
121 tree_expression *op3 = expr.increment (); | |
122 | |
123 if (op3) | |
124 { | |
125 os << ":"; | |
126 op3->accept (*this); | |
127 } | |
128 | |
129 tree_expression *op2 = expr.limit (); | |
130 | |
131 if (op2) | |
132 { | |
133 os << ":"; | |
134 op2->accept (*this); | |
135 } | |
136 | |
2961 | 137 print_parens (expr, ")"); |
2123 | 138 } |
139 | |
140 void | |
4207 | 141 tree_print_code::visit_continue_command (tree_continue_command&) |
2123 | 142 { |
143 indent (); | |
144 | |
145 os << "continue"; | |
146 } | |
147 | |
148 void | |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
149 tree_print_code::do_decl_command (tree_decl_command& cmd) |
2846 | 150 { |
151 indent (); | |
152 | |
153 os << cmd.name () << " "; | |
154 | |
155 tree_decl_init_list *init_list = cmd.initializer_list (); | |
156 | |
157 if (init_list) | |
158 init_list->accept (*this); | |
159 } | |
160 | |
161 void | |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
162 tree_print_code::visit_global_command (tree_global_command& cmd) |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
163 { |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
164 do_decl_command (cmd); |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
165 } |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
166 |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
167 void |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
168 tree_print_code::visit_static_command (tree_static_command& cmd) |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
169 { |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
170 do_decl_command (cmd); |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
171 } |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
172 |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
173 void |
2846 | 174 tree_print_code::visit_decl_elt (tree_decl_elt& cmd) |
175 { | |
176 tree_identifier *id = cmd.ident (); | |
177 | |
178 if (id) | |
179 id->accept (*this); | |
180 | |
2969 | 181 tree_expression *expr = cmd.expression (); |
2846 | 182 |
2969 | 183 if (expr) |
184 { | |
185 os << " = "; | |
186 | |
187 expr->accept (*this); | |
188 } | |
2846 | 189 } |
190 | |
191 void | |
192 tree_print_code::visit_decl_init_list (tree_decl_init_list& lst) | |
193 { | |
4219 | 194 tree_decl_init_list::iterator p = lst.begin (); |
2846 | 195 |
4219 | 196 while (p != lst.end ()) |
2846 | 197 { |
4219 | 198 tree_decl_elt *elt = *p++; |
2846 | 199 |
200 if (elt) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
201 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
202 elt->accept (*this); |
2846 | 203 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
204 if (p != lst.end ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
205 os << ", "; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
206 } |
2846 | 207 } |
208 } | |
209 | |
210 void | |
2969 | 211 tree_print_code::visit_simple_for_command (tree_simple_for_command& cmd) |
2123 | 212 { |
3665 | 213 print_comment_list (cmd.leading_comment ()); |
214 | |
2123 | 215 indent (); |
216 | |
217 os << "for "; | |
218 | |
2969 | 219 tree_expression *lhs = cmd.left_hand_side (); |
2123 | 220 |
2969 | 221 if (lhs) |
222 lhs->accept (*this); | |
2123 | 223 |
224 os << " = "; | |
225 | |
226 tree_expression *expr = cmd.control_expr (); | |
227 | |
228 if (expr) | |
229 expr->accept (*this); | |
230 | |
231 newline (); | |
232 | |
233 tree_statement_list *list = cmd.body (); | |
234 | |
235 if (list) | |
236 { | |
237 increment_indent_level (); | |
3665 | 238 |
2123 | 239 list->accept (*this); |
3665 | 240 |
2123 | 241 decrement_indent_level (); |
242 } | |
243 | |
3665 | 244 print_indented_comment (cmd.trailing_comment ()); |
245 | |
2123 | 246 indent (); |
247 | |
248 os << "endfor"; | |
249 } | |
250 | |
251 void | |
2969 | 252 tree_print_code::visit_complex_for_command (tree_complex_for_command& cmd) |
253 { | |
3665 | 254 print_comment_list (cmd.leading_comment ()); |
255 | |
2969 | 256 indent (); |
257 | |
258 os << "for ["; | |
4676 | 259 nesting.push ('['); |
2969 | 260 |
261 tree_argument_list *lhs = cmd.left_hand_side (); | |
262 | |
263 if (lhs) | |
264 lhs->accept (*this); | |
265 | |
4676 | 266 nesting.pop (); |
2969 | 267 os << "] = "; |
268 | |
269 tree_expression *expr = cmd.control_expr (); | |
270 | |
271 if (expr) | |
272 expr->accept (*this); | |
273 | |
274 newline (); | |
275 | |
276 tree_statement_list *list = cmd.body (); | |
277 | |
278 if (list) | |
279 { | |
280 increment_indent_level (); | |
3665 | 281 |
2969 | 282 list->accept (*this); |
3665 | 283 |
2969 | 284 decrement_indent_level (); |
285 } | |
286 | |
3665 | 287 print_indented_comment (cmd.trailing_comment ()); |
288 | |
2969 | 289 indent (); |
290 | |
291 os << "endfor"; | |
292 } | |
293 | |
294 void | |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
295 tree_print_code::visit_octave_user_script (octave_user_script& fcn) |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
296 { |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
297 reset (); |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
298 |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
299 tree_statement_list *cmd_list = fcn.body (); |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
300 |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
301 if (cmd_list) |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
302 cmd_list->accept (*this); |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
303 } |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
304 |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
305 void |
2891 | 306 tree_print_code::visit_octave_user_function (octave_user_function& fcn) |
2123 | 307 { |
308 reset (); | |
309 | |
2891 | 310 visit_octave_user_function_header (fcn); |
2123 | 311 |
312 tree_statement_list *cmd_list = fcn.body (); | |
313 | |
314 if (cmd_list) | |
315 { | |
316 increment_indent_level (); | |
3665 | 317 |
2123 | 318 cmd_list->accept (*this); |
3665 | 319 |
2123 | 320 decrement_indent_level (); |
321 } | |
322 | |
2891 | 323 visit_octave_user_function_trailer (fcn); |
2123 | 324 } |
325 | |
326 void | |
2891 | 327 tree_print_code::visit_octave_user_function_header (octave_user_function& fcn) |
2123 | 328 { |
3665 | 329 octave_comment_list *leading_comment = fcn.leading_comment (); |
330 | |
331 if (leading_comment) | |
332 { | |
333 print_comment_list (leading_comment); | |
334 newline (); | |
335 } | |
336 | |
2123 | 337 indent (); |
338 | |
339 os << "function "; | |
340 | |
341 tree_parameter_list *ret_list = fcn.return_list (); | |
342 | |
343 if (ret_list) | |
344 { | |
345 bool takes_var_return = fcn.takes_var_return (); | |
346 | |
347 int len = ret_list->length (); | |
348 | |
349 if (len > 1 || takes_var_return) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
350 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
351 os << "["; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
352 nesting.push ('['); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
353 } |
2123 | 354 |
355 ret_list->accept (*this); | |
356 | |
357 if (takes_var_return) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
358 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
359 if (len > 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
360 os << ", "; |
2123 | 361 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
362 os << "varargout"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
363 } |
2123 | 364 |
365 if (len > 1 || takes_var_return) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
366 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
367 nesting.pop (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
368 os << "]"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
369 } |
2123 | 370 |
371 os << " = "; | |
372 } | |
373 | |
4748 | 374 std::string fcn_name = fcn.name (); |
2123 | 375 |
3523 | 376 os << (fcn_name.empty () ? std::string ("(empty)") : fcn_name) << " "; |
2123 | 377 |
378 tree_parameter_list *param_list = fcn.parameter_list (); | |
379 | |
380 if (param_list) | |
381 { | |
382 bool takes_varargs = fcn.takes_varargs (); | |
383 | |
384 int len = param_list->length (); | |
385 | |
386 if (len > 0 || takes_varargs) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
387 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
388 os << "("; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
389 nesting.push ('('); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
390 } |
2123 | 391 |
392 param_list->accept (*this); | |
393 | |
394 if (takes_varargs) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
395 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
396 if (len > 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
397 os << ", "; |
2123 | 398 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
399 os << "varargin"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
400 } |
2123 | 401 |
402 if (len > 0 || takes_varargs) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
403 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
404 nesting.pop (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
405 os << ")"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
406 newline (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
407 } |
2123 | 408 } |
409 else | |
410 { | |
411 os << "()"; | |
412 newline (); | |
413 } | |
414 } | |
415 | |
416 void | |
3665 | 417 tree_print_code::visit_octave_user_function_trailer (octave_user_function& fcn) |
2123 | 418 { |
3665 | 419 print_indented_comment (fcn.trailing_comment ()); |
420 | |
2123 | 421 newline (); |
422 } | |
423 | |
424 void | |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
425 tree_print_code::visit_function_def (tree_function_def& fdef) |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
426 { |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
427 indent (); |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
428 |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
429 octave_value fcn = fdef.function (); |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
430 |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
431 octave_function *f = fcn.function_value (); |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
432 |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
433 if (f) |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
434 f->accept (*this); |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
435 } |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
436 |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
437 void |
2123 | 438 tree_print_code::visit_identifier (tree_identifier& id) |
439 { | |
440 indent (); | |
441 | |
2961 | 442 print_parens (id, "("); |
2123 | 443 |
3523 | 444 std::string nm = id.name (); |
445 os << (nm.empty () ? std::string ("(empty)") : nm); | |
2123 | 446 |
2961 | 447 print_parens (id, ")"); |
2123 | 448 } |
449 | |
450 void | |
451 tree_print_code::visit_if_clause (tree_if_clause& cmd) | |
452 { | |
453 tree_expression *expr = cmd.condition (); | |
454 | |
455 if (expr) | |
456 expr->accept (*this); | |
457 | |
458 newline (); | |
459 | |
460 tree_statement_list *list = cmd.commands (); | |
461 | |
462 if (list) | |
463 { | |
3665 | 464 increment_indent_level (); |
465 | |
2123 | 466 list->accept (*this); |
467 | |
468 decrement_indent_level (); | |
469 } | |
470 } | |
471 | |
472 void | |
473 tree_print_code::visit_if_command (tree_if_command& cmd) | |
474 { | |
3665 | 475 print_comment_list (cmd.leading_comment ()); |
476 | |
2123 | 477 indent (); |
478 | |
479 os << "if "; | |
480 | |
481 tree_if_command_list *list = cmd.cmd_list (); | |
482 | |
483 if (list) | |
484 list->accept (*this); | |
485 | |
3665 | 486 print_indented_comment (cmd.trailing_comment ()); |
487 | |
2123 | 488 indent (); |
489 | |
490 os << "endif"; | |
491 } | |
492 | |
493 void | |
494 tree_print_code::visit_if_command_list (tree_if_command_list& lst) | |
495 { | |
4219 | 496 tree_if_command_list::iterator p = lst.begin (); |
2123 | 497 |
498 bool first_elt = true; | |
499 | |
4219 | 500 while (p != lst.end ()) |
2123 | 501 { |
4219 | 502 tree_if_clause *elt = *p++; |
2123 | 503 |
504 if (elt) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
505 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
506 if (! first_elt) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
507 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
508 print_indented_comment (elt->leading_comment ()); |
3665 | 509 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
510 indent (); |
2123 | 511 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
512 if (elt->is_else_clause ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
513 os << "else"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
514 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
515 os << "elseif "; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
516 } |
2123 | 517 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
518 elt->accept (*this); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
519 } |
2123 | 520 |
521 first_elt = false; | |
522 } | |
523 } | |
524 | |
525 void | |
526 tree_print_code::visit_index_expression (tree_index_expression& expr) | |
527 { | |
528 indent (); | |
529 | |
2961 | 530 print_parens (expr, "("); |
2123 | 531 |
3010 | 532 tree_expression *e = expr.expression (); |
2123 | 533 |
2969 | 534 if (e) |
13219
cf5ebc0e47e4
fix warnings for unused but set variables and shadowed variables
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
535 e->accept (*this); |
2123 | 536 |
4219 | 537 std::list<tree_argument_list *> arg_lists = expr.arg_lists (); |
3933 | 538 std::string type_tags = expr.type_tags (); |
4219 | 539 std::list<string_vector> arg_names = expr.arg_names (); |
2123 | 540 |
3933 | 541 int n = type_tags.length (); |
542 | |
4219 | 543 std::list<tree_argument_list *>::iterator p_arg_lists = arg_lists.begin (); |
544 std::list<string_vector>::iterator p_arg_names = arg_names.begin (); | |
3933 | 545 |
546 for (int i = 0; i < n; i++) | |
2123 | 547 { |
3933 | 548 switch (type_tags[i]) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
549 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
550 case '(': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
551 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
552 char nc = nesting.top (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
553 if ((nc == '[' || nc == '{') && expr.paren_count () == 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
554 os << "("; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
555 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
556 os << " ("; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
557 nesting.push ('('); |
4676 | 558 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
559 tree_argument_list *l = *p_arg_lists; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
560 if (l) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
561 l->accept (*this); |
4676 | 562 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
563 nesting.pop (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
564 os << ")"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
565 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
566 break; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
567 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
568 case '{': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
569 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
570 char nc = nesting.top (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
571 if ((nc == '[' || nc == '{') && expr.paren_count () == 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
572 os << "{"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
573 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
574 os << " {"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
575 // We only care about whitespace inside [] and {} when we |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
576 // are defining matrix and cell objects, not when indexing. |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
577 nesting.push ('('); |
4676 | 578 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
579 tree_argument_list *l = *p_arg_lists; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
580 if (l) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
581 l->accept (*this); |
4676 | 582 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
583 nesting.pop (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
584 os << "}"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
585 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
586 break; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
587 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
588 case '.': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
589 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
590 string_vector nm = *p_arg_names; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
591 assert (nm.length () == 1); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
592 os << "." << nm(0); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
593 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
594 break; |
3933 | 595 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
596 default: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
597 panic_impossible (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
598 } |
3933 | 599 |
4219 | 600 p_arg_lists++; |
601 p_arg_names++; | |
3930 | 602 } |
2123 | 603 |
2961 | 604 print_parens (expr, ")"); |
2123 | 605 } |
606 | |
607 void | |
608 tree_print_code::visit_matrix (tree_matrix& lst) | |
609 { | |
610 indent (); | |
611 | |
2961 | 612 print_parens (lst, "("); |
2123 | 613 |
614 os << "["; | |
4676 | 615 nesting.push ('['); |
2123 | 616 |
4219 | 617 tree_matrix::iterator p = lst.begin (); |
2123 | 618 |
4219 | 619 while (p != lst.end ()) |
2123 | 620 { |
4219 | 621 tree_argument_list *elt = *p++; |
2123 | 622 |
623 if (elt) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
624 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
625 elt->accept (*this); |
2123 | 626 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
627 if (p != lst.end ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
628 os << "; "; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
629 } |
2123 | 630 } |
631 | |
4676 | 632 nesting.pop (); |
2123 | 633 os << "]"; |
634 | |
2961 | 635 print_parens (lst, ")"); |
2123 | 636 } |
637 | |
638 void | |
3351 | 639 tree_print_code::visit_cell (tree_cell& lst) |
640 { | |
641 indent (); | |
642 | |
643 print_parens (lst, "("); | |
644 | |
645 os << "{"; | |
4676 | 646 nesting.push ('{'); |
3351 | 647 |
4219 | 648 tree_cell::iterator p = lst.begin (); |
3351 | 649 |
4219 | 650 while (p != lst.end ()) |
3351 | 651 { |
4219 | 652 tree_argument_list *elt = *p++; |
3351 | 653 |
654 if (elt) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
655 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
656 elt->accept (*this); |
3351 | 657 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
658 if (p != lst.end ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
659 os << "; "; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
660 } |
3351 | 661 } |
662 | |
4676 | 663 nesting.pop (); |
3351 | 664 os << "}"; |
665 | |
666 print_parens (lst, ")"); | |
667 } | |
668 | |
669 void | |
2969 | 670 tree_print_code::visit_multi_assignment (tree_multi_assignment& expr) |
2123 | 671 { |
672 indent (); | |
673 | |
2961 | 674 print_parens (expr, "("); |
2123 | 675 |
2969 | 676 tree_argument_list *lhs = expr.left_hand_side (); |
2123 | 677 |
678 if (lhs) | |
679 { | |
680 int len = lhs->length (); | |
681 | |
682 if (len > 1) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
683 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
684 os << "["; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
685 nesting.push ('['); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
686 } |
2123 | 687 |
688 lhs->accept (*this); | |
689 | |
690 if (len > 1) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
691 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
692 nesting.pop (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
693 os << "]"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
694 } |
2123 | 695 } |
696 | |
3208 | 697 os << " " << expr.oper () << " "; |
2123 | 698 |
2969 | 699 tree_expression *rhs = expr.right_hand_side (); |
2123 | 700 |
701 if (rhs) | |
702 rhs->accept (*this); | |
703 | |
2961 | 704 print_parens (expr, ")"); |
2123 | 705 } |
706 | |
707 void | |
2620 | 708 tree_print_code::visit_no_op_command (tree_no_op_command& cmd) |
709 { | |
710 indent (); | |
711 | |
712 os << cmd.original_command (); | |
713 } | |
714 | |
715 void | |
2372 | 716 tree_print_code::visit_constant (tree_constant& val) |
2123 | 717 { |
718 indent (); | |
719 | |
2961 | 720 print_parens (val, "("); |
2123 | 721 |
2942 | 722 val.print_raw (os, true, print_original_text); |
2123 | 723 |
2961 | 724 print_parens (val, ")"); |
2123 | 725 } |
726 | |
727 void | |
4342 | 728 tree_print_code::visit_fcn_handle (tree_fcn_handle& fh) |
729 { | |
730 indent (); | |
731 | |
732 print_parens (fh, "("); | |
733 | |
734 fh.print_raw (os, true, print_original_text); | |
735 | |
736 print_parens (fh, ")"); | |
737 } | |
738 | |
739 void | |
2123 | 740 tree_print_code::visit_parameter_list (tree_parameter_list& lst) |
741 { | |
4219 | 742 tree_parameter_list::iterator p = lst.begin (); |
2123 | 743 |
4219 | 744 while (p != lst.end ()) |
2123 | 745 { |
6215 | 746 tree_decl_elt *elt = *p++; |
2123 | 747 |
748 if (elt) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
749 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
750 elt->accept (*this); |
2123 | 751 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
752 if (p != lst.end ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
753 os << ", "; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
754 } |
2123 | 755 } |
756 } | |
757 | |
758 void | |
759 tree_print_code::visit_postfix_expression (tree_postfix_expression& expr) | |
760 { | |
761 indent (); | |
762 | |
2961 | 763 print_parens (expr, "("); |
2123 | 764 |
2960 | 765 tree_expression *e = expr.operand (); |
2123 | 766 |
2960 | 767 if (e) |
768 e->accept (*this); | |
2123 | 769 |
770 os << expr.oper (); | |
771 | |
2961 | 772 print_parens (expr, ")"); |
2123 | 773 } |
774 | |
775 void | |
776 tree_print_code::visit_prefix_expression (tree_prefix_expression& expr) | |
777 { | |
778 indent (); | |
779 | |
2961 | 780 print_parens (expr, "("); |
2123 | 781 |
782 os << expr.oper (); | |
783 | |
2960 | 784 tree_expression *e = expr.operand (); |
2123 | 785 |
2960 | 786 if (e) |
787 e->accept (*this); | |
2123 | 788 |
2961 | 789 print_parens (expr, ")"); |
2123 | 790 } |
791 | |
792 void | |
4207 | 793 tree_print_code::visit_return_command (tree_return_command&) |
2123 | 794 { |
795 indent (); | |
796 | |
797 os << "return"; | |
798 } | |
799 | |
800 void | |
801 tree_print_code::visit_return_list (tree_return_list& lst) | |
802 { | |
4219 | 803 tree_return_list::iterator p = lst.begin (); |
2123 | 804 |
4219 | 805 while (p != lst.end ()) |
2123 | 806 { |
4219 | 807 tree_index_expression *elt = *p++; |
2123 | 808 |
809 if (elt) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
810 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
811 elt->accept (*this); |
2123 | 812 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
813 if (p != lst.end ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
814 os << ", "; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
815 } |
2123 | 816 } |
817 } | |
818 | |
819 void | |
2969 | 820 tree_print_code::visit_simple_assignment (tree_simple_assignment& expr) |
2123 | 821 { |
822 indent (); | |
823 | |
2961 | 824 print_parens (expr, "("); |
2123 | 825 |
2969 | 826 tree_expression *lhs = expr.left_hand_side (); |
2123 | 827 |
2969 | 828 if (lhs) |
829 lhs->accept (*this); | |
2123 | 830 |
2969 | 831 os << " " << expr.oper () << " "; |
2123 | 832 |
833 tree_expression *rhs = expr.right_hand_side (); | |
834 | |
835 if (rhs) | |
836 rhs->accept (*this); | |
837 | |
2961 | 838 print_parens (expr, ")"); |
2123 | 839 } |
840 | |
841 void | |
842 tree_print_code::visit_statement (tree_statement& stmt) | |
843 { | |
3665 | 844 print_comment_list (stmt.comment_text ()); |
845 | |
2123 | 846 tree_command *cmd = stmt.command (); |
847 | |
848 if (cmd) | |
849 { | |
850 cmd->accept (*this); | |
851 | |
852 if (! stmt.print_result ()) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
853 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
854 os << ";"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
855 newline (" "); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
856 } |
4980 | 857 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
858 newline (); |
2123 | 859 } |
860 else | |
861 { | |
862 tree_expression *expr = stmt.expression (); | |
863 | |
864 if (expr) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
865 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
866 expr->accept (*this); |
2123 | 867 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
868 if (! stmt.print_result ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
869 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
870 os << ";"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
871 newline (" "); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
872 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
873 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
874 newline (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
875 } |
2123 | 876 } |
877 } | |
878 | |
879 void | |
880 tree_print_code::visit_statement_list (tree_statement_list& lst) | |
881 { | |
4219 | 882 for (tree_statement_list::iterator p = lst.begin (); p != lst.end (); p++) |
2123 | 883 { |
4219 | 884 tree_statement *elt = *p; |
2123 | 885 |
886 if (elt) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
887 elt->accept (*this); |
2123 | 888 } |
889 } | |
890 | |
891 void | |
2846 | 892 tree_print_code::visit_switch_case (tree_switch_case& cs) |
893 { | |
3665 | 894 print_comment_list (cs.leading_comment ()); |
895 | |
2846 | 896 indent (); |
897 | |
898 if (cs.is_default_case ()) | |
899 os << "otherwise"; | |
900 else | |
901 os << "case "; | |
902 | |
903 tree_expression *label = cs.case_label (); | |
904 | |
905 if (label) | |
906 label->accept (*this); | |
907 | |
908 newline (); | |
909 | |
910 tree_statement_list *list = cs.commands (); | |
911 | |
912 if (list) | |
913 { | |
3665 | 914 increment_indent_level (); |
915 | |
2846 | 916 list->accept (*this); |
917 | |
3665 | 918 newline (); |
919 | |
2846 | 920 decrement_indent_level (); |
921 } | |
922 } | |
923 | |
924 void | |
925 tree_print_code::visit_switch_case_list (tree_switch_case_list& lst) | |
926 { | |
4219 | 927 tree_switch_case_list::iterator p = lst.begin (); |
2846 | 928 |
4219 | 929 while (p != lst.end ()) |
2846 | 930 { |
4219 | 931 tree_switch_case *elt = *p++; |
2846 | 932 |
933 if (elt) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
934 elt->accept (*this); |
2846 | 935 } |
936 } | |
937 | |
938 void | |
939 tree_print_code::visit_switch_command (tree_switch_command& cmd) | |
940 { | |
3665 | 941 print_comment_list (cmd.leading_comment ()); |
942 | |
2846 | 943 indent (); |
944 | |
945 os << "switch "; | |
946 | |
947 tree_expression *expr = cmd.switch_value (); | |
948 | |
949 if (expr) | |
950 expr->accept (*this); | |
951 | |
952 newline (); | |
953 | |
954 tree_switch_case_list *list = cmd.case_list (); | |
955 | |
956 if (list) | |
3665 | 957 { |
958 increment_indent_level (); | |
959 | |
960 list->accept (*this); | |
961 | |
962 decrement_indent_level (); | |
963 } | |
964 | |
965 print_indented_comment (cmd.leading_comment ()); | |
2846 | 966 |
967 indent (); | |
968 | |
969 os << "endswitch"; | |
970 } | |
971 | |
972 void | |
2123 | 973 tree_print_code::visit_try_catch_command (tree_try_catch_command& cmd) |
974 { | |
3665 | 975 print_comment_list (cmd.leading_comment ()); |
976 | |
2123 | 977 indent (); |
978 | |
3665 | 979 os << "try"; |
2123 | 980 |
981 newline (); | |
982 | |
983 tree_statement_list *try_code = cmd.body (); | |
984 | |
985 if (try_code) | |
986 { | |
987 increment_indent_level (); | |
3665 | 988 |
2123 | 989 try_code->accept (*this); |
3665 | 990 |
2123 | 991 decrement_indent_level (); |
992 } | |
993 | |
3665 | 994 print_indented_comment (cmd.middle_comment ()); |
995 | |
2123 | 996 indent (); |
997 | |
998 os << "catch"; | |
999 | |
1000 newline (); | |
1001 | |
1002 tree_statement_list *catch_code = cmd.cleanup (); | |
1003 | |
1004 if (catch_code) | |
1005 { | |
1006 increment_indent_level (); | |
3665 | 1007 |
2123 | 1008 catch_code->accept (*this); |
3665 | 1009 |
2123 | 1010 decrement_indent_level (); |
1011 } | |
1012 | |
3665 | 1013 print_indented_comment (cmd.trailing_comment ()); |
1014 | |
2123 | 1015 indent (); |
1016 | |
1017 os << "end_try_catch"; | |
1018 } | |
1019 | |
1020 void | |
1021 tree_print_code::visit_unwind_protect_command | |
1022 (tree_unwind_protect_command& cmd) | |
1023 { | |
3665 | 1024 print_comment_list (cmd.leading_comment ()); |
1025 | |
2123 | 1026 indent (); |
1027 | |
1028 os << "unwind_protect"; | |
1029 | |
1030 newline (); | |
1031 | |
1032 tree_statement_list *unwind_protect_code = cmd.body (); | |
1033 | |
1034 if (unwind_protect_code) | |
1035 { | |
1036 increment_indent_level (); | |
3665 | 1037 |
2123 | 1038 unwind_protect_code->accept (*this); |
3665 | 1039 |
2123 | 1040 decrement_indent_level (); |
1041 } | |
1042 | |
3665 | 1043 print_indented_comment (cmd.middle_comment ()); |
1044 | |
2123 | 1045 indent (); |
1046 | |
3478 | 1047 os << "unwind_protect_cleanup"; |
2123 | 1048 |
1049 newline (); | |
1050 | |
1051 tree_statement_list *cleanup_code = cmd.cleanup (); | |
1052 | |
1053 if (cleanup_code) | |
1054 { | |
1055 increment_indent_level (); | |
3665 | 1056 |
2123 | 1057 cleanup_code->accept (*this); |
3665 | 1058 |
2123 | 1059 decrement_indent_level (); |
1060 } | |
1061 | |
3665 | 1062 print_indented_comment (cmd.trailing_comment ()); |
1063 | |
2123 | 1064 indent (); |
1065 | |
1066 os << "end_unwind_protect"; | |
1067 } | |
1068 | |
1069 void | |
1070 tree_print_code::visit_while_command (tree_while_command& cmd) | |
1071 { | |
3665 | 1072 print_comment_list (cmd.leading_comment ()); |
1073 | |
2123 | 1074 indent (); |
1075 | |
1076 os << "while "; | |
1077 | |
1078 tree_expression *expr = cmd.condition (); | |
1079 | |
1080 if (expr) | |
1081 expr->accept (*this); | |
1082 | |
1083 newline (); | |
1084 | |
1085 tree_statement_list *list = cmd.body (); | |
1086 | |
1087 if (list) | |
1088 { | |
1089 increment_indent_level (); | |
3665 | 1090 |
2123 | 1091 list->accept (*this); |
3665 | 1092 |
2123 | 1093 decrement_indent_level (); |
1094 } | |
1095 | |
3665 | 1096 print_indented_comment (cmd.trailing_comment ()); |
1097 | |
2123 | 1098 indent (); |
1099 | |
1100 os << "endwhile"; | |
1101 } | |
1102 | |
3484 | 1103 void |
1104 tree_print_code::visit_do_until_command (tree_do_until_command& cmd) | |
1105 { | |
3665 | 1106 print_comment_list (cmd.leading_comment ()); |
1107 | |
3484 | 1108 indent (); |
1109 | |
1110 os << "do"; | |
1111 | |
1112 newline (); | |
1113 | |
1114 tree_statement_list *list = cmd.body (); | |
1115 | |
1116 if (list) | |
1117 { | |
1118 increment_indent_level (); | |
3665 | 1119 |
3484 | 1120 list->accept (*this); |
3665 | 1121 |
3484 | 1122 decrement_indent_level (); |
1123 } | |
1124 | |
3665 | 1125 print_indented_comment (cmd.trailing_comment ()); |
1126 | |
3484 | 1127 indent (); |
1128 | |
1129 os << "until"; | |
1130 | |
1131 tree_expression *expr = cmd.condition (); | |
1132 | |
1133 if (expr) | |
1134 expr->accept (*this); | |
1135 | |
1136 newline (); | |
1137 } | |
1138 | |
11223
64e7538db12a
fix printing of newlines for anonymous function handle bodies
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1139 void |
64e7538db12a
fix printing of newlines for anonymous function handle bodies
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1140 tree_print_code::print_fcn_handle_body (tree_statement_list *b) |
64e7538db12a
fix printing of newlines for anonymous function handle bodies
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1141 { |
64e7538db12a
fix printing of newlines for anonymous function handle bodies
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1142 if (b) |
64e7538db12a
fix printing of newlines for anonymous function handle bodies
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1143 { |
64e7538db12a
fix printing of newlines for anonymous function handle bodies
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1144 assert (b->length () == 1); |
64e7538db12a
fix printing of newlines for anonymous function handle bodies
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1145 |
64e7538db12a
fix printing of newlines for anonymous function handle bodies
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1146 tree_statement *s = b->front (); |
64e7538db12a
fix printing of newlines for anonymous function handle bodies
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1147 |
64e7538db12a
fix printing of newlines for anonymous function handle bodies
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1148 if (s) |
64e7538db12a
fix printing of newlines for anonymous function handle bodies
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1149 { |
64e7538db12a
fix printing of newlines for anonymous function handle bodies
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1150 if (s->is_expression ()) |
64e7538db12a
fix printing of newlines for anonymous function handle bodies
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1151 { |
64e7538db12a
fix printing of newlines for anonymous function handle bodies
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1152 tree_expression *e = s->expression (); |
64e7538db12a
fix printing of newlines for anonymous function handle bodies
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1153 |
64e7538db12a
fix printing of newlines for anonymous function handle bodies
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1154 if (e) |
64e7538db12a
fix printing of newlines for anonymous function handle bodies
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1155 { |
64e7538db12a
fix printing of newlines for anonymous function handle bodies
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1156 suppress_newlines++; |
64e7538db12a
fix printing of newlines for anonymous function handle bodies
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1157 e->accept (*this); |
64e7538db12a
fix printing of newlines for anonymous function handle bodies
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1158 suppress_newlines--; |
64e7538db12a
fix printing of newlines for anonymous function handle bodies
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1159 } |
64e7538db12a
fix printing of newlines for anonymous function handle bodies
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1160 } |
64e7538db12a
fix printing of newlines for anonymous function handle bodies
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1161 else |
64e7538db12a
fix printing of newlines for anonymous function handle bodies
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1162 { |
64e7538db12a
fix printing of newlines for anonymous function handle bodies
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1163 tree_command *c = s->command (); |
64e7538db12a
fix printing of newlines for anonymous function handle bodies
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1164 |
64e7538db12a
fix printing of newlines for anonymous function handle bodies
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1165 suppress_newlines++; |
64e7538db12a
fix printing of newlines for anonymous function handle bodies
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1166 c->accept (*this); |
64e7538db12a
fix printing of newlines for anonymous function handle bodies
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1167 suppress_newlines--; |
64e7538db12a
fix printing of newlines for anonymous function handle bodies
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1168 } |
64e7538db12a
fix printing of newlines for anonymous function handle bodies
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1169 } |
64e7538db12a
fix printing of newlines for anonymous function handle bodies
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1170 } |
64e7538db12a
fix printing of newlines for anonymous function handle bodies
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1171 } |
64e7538db12a
fix printing of newlines for anonymous function handle bodies
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1172 |
2123 | 1173 // Each print_code() function should call this before printing |
1174 // anything. | |
1175 // | |
1176 // This doesn't need to be fast, but isn't there a better way? | |
1177 | |
1178 void | |
1179 tree_print_code::indent (void) | |
1180 { | |
1181 assert (curr_print_indent_level >= 0); | |
2900 | 1182 |
11223
64e7538db12a
fix printing of newlines for anonymous function handle bodies
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1183 if (beginning_of_line) |
4980 | 1184 { |
11223
64e7538db12a
fix printing of newlines for anonymous function handle bodies
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1185 os << prefix; |
2900 | 1186 |
11223
64e7538db12a
fix printing of newlines for anonymous function handle bodies
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1187 for (int i = 0; i < curr_print_indent_level; i++) |
64e7538db12a
fix printing of newlines for anonymous function handle bodies
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1188 os << " "; |
4980 | 1189 |
11223
64e7538db12a
fix printing of newlines for anonymous function handle bodies
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1190 beginning_of_line = false; |
2123 | 1191 } |
1192 } | |
1193 | |
1194 // All print_code() functions should use this to print new lines. | |
1195 | |
1196 void | |
4980 | 1197 tree_print_code::newline (const char *alt_txt) |
2123 | 1198 { |
11223
64e7538db12a
fix printing of newlines for anonymous function handle bodies
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1199 if (suppress_newlines) |
64e7538db12a
fix printing of newlines for anonymous function handle bodies
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1200 os << alt_txt; |
64e7538db12a
fix printing of newlines for anonymous function handle bodies
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1201 else |
64e7538db12a
fix printing of newlines for anonymous function handle bodies
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1202 { |
64e7538db12a
fix printing of newlines for anonymous function handle bodies
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1203 os << "\n"; |
2123 | 1204 |
11223
64e7538db12a
fix printing of newlines for anonymous function handle bodies
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1205 beginning_of_line = true; |
64e7538db12a
fix printing of newlines for anonymous function handle bodies
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1206 } |
2123 | 1207 } |
1208 | |
1209 // For ressetting print_code state. | |
1210 | |
1211 void | |
1212 tree_print_code::reset (void) | |
1213 { | |
1214 beginning_of_line = true; | |
1215 curr_print_indent_level = 0; | |
4676 | 1216 while (nesting.top () != 'n') |
1217 nesting.pop (); | |
2123 | 1218 } |
1219 | |
2961 | 1220 void |
1221 tree_print_code::print_parens (const tree_expression& expr, const char *txt) | |
1222 { | |
1223 int n = expr.paren_count (); | |
1224 | |
1225 for (int i = 0; i < n; i++) | |
1226 os << txt; | |
1227 } | |
1228 | |
3665 | 1229 void |
1230 tree_print_code::print_comment_elt (const octave_comment_elt& elt) | |
1231 { | |
1232 bool printed_something = false; | |
1233 | |
1234 bool prev_char_was_newline = false; | |
1235 | |
3769 | 1236 std::string comment = elt.text (); |
3665 | 1237 |
1238 size_t len = comment.length (); | |
1239 | |
1240 size_t i = 0; | |
1241 | |
1242 while (i < len && comment[i++] == '\n') | |
1243 ; /* Skip leading new lines. */ | |
1244 i--; | |
1245 | |
1246 while (i < len) | |
1247 { | |
1248 char c = comment[i++]; | |
1249 | |
1250 if (c == '\n') | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1251 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1252 if (prev_char_was_newline) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1253 os << "##"; |
3665 | 1254 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1255 newline (); |
3665 | 1256 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1257 prev_char_was_newline = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1258 } |
3665 | 1259 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1260 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1261 if (beginning_of_line) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1262 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1263 printed_something = true; |
3665 | 1264 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1265 indent (); |
3665 | 1266 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1267 os << "##"; |
3665 | 1268 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1269 if (! (isspace (c) || c == '!')) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1270 os << " "; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1271 } |
3665 | 1272 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1273 os << static_cast<char> (c); |
3665 | 1274 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1275 prev_char_was_newline = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1276 } |
3665 | 1277 } |
1278 | |
1279 if (printed_something && ! beginning_of_line) | |
1280 newline (); | |
1281 } | |
1282 | |
1283 void | |
1284 tree_print_code::print_comment_list (octave_comment_list *comment_list) | |
1285 { | |
1286 if (comment_list) | |
1287 { | |
4219 | 1288 octave_comment_list::iterator p = comment_list->begin (); |
3665 | 1289 |
4219 | 1290 while (p != comment_list->end ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1291 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1292 octave_comment_elt elt = *p++; |
3665 | 1293 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1294 print_comment_elt (elt); |
3665 | 1295 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1296 if (p != comment_list->end ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1297 newline (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1298 } |
3665 | 1299 } |
1300 } | |
1301 | |
1302 void | |
1303 tree_print_code::print_indented_comment (octave_comment_list *comment_list) | |
1304 { | |
1305 increment_indent_level (); | |
1306 | |
1307 print_comment_list (comment_list); | |
1308 | |
1309 decrement_indent_level (); | |
1310 } |