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 (__GNUG__) |
|
24 #pragma implementation |
|
25 #endif |
|
26 |
|
27 #ifdef HAVE_CONFIG_H |
|
28 #include <config.h> |
|
29 #endif |
|
30 |
|
31 #include <iostream.h> |
|
32 |
|
33 #include "error.h" |
2969
|
34 #include "ov-usr-fcn.h" |
2123
|
35 #include "pr-output.h" |
2988
|
36 #include "pt-all.h" |
2123
|
37 |
|
38 void |
|
39 tree_print_code::visit_argument_list (tree_argument_list& lst) |
|
40 { |
|
41 Pix p = lst.first (); |
|
42 |
|
43 while (p) |
|
44 { |
|
45 tree_expression *elt = lst (p); |
|
46 |
|
47 lst.next (p); |
|
48 |
|
49 if (elt) |
|
50 { |
|
51 elt->accept (*this); |
|
52 |
|
53 if (p) |
|
54 os << ", "; |
|
55 } |
|
56 } |
|
57 } |
|
58 |
|
59 void |
|
60 tree_print_code::visit_binary_expression (tree_binary_expression& expr) |
|
61 { |
|
62 indent (); |
|
63 |
2961
|
64 print_parens (expr, "("); |
2123
|
65 |
|
66 tree_expression *op1 = expr.lhs (); |
|
67 |
|
68 if (op1) |
|
69 op1->accept (*this); |
|
70 |
|
71 os << " " << expr.oper () << " "; |
|
72 |
|
73 tree_expression *op2 = expr.rhs (); |
|
74 |
|
75 if (op2) |
|
76 op2->accept (*this); |
|
77 |
2961
|
78 print_parens (expr, ")"); |
2123
|
79 } |
|
80 |
|
81 void |
|
82 tree_print_code::visit_break_command (tree_break_command&) |
|
83 { |
|
84 indent (); |
|
85 |
|
86 os << "break"; |
|
87 } |
|
88 |
|
89 void |
|
90 tree_print_code::visit_colon_expression (tree_colon_expression& expr) |
|
91 { |
|
92 indent (); |
|
93 |
2961
|
94 print_parens (expr, "("); |
2123
|
95 |
|
96 tree_expression *op1 = expr.base (); |
|
97 |
|
98 if (op1) |
|
99 op1->accept (*this); |
|
100 |
|
101 // Stupid syntax. |
|
102 |
|
103 tree_expression *op3 = expr.increment (); |
|
104 |
|
105 if (op3) |
|
106 { |
|
107 os << ":"; |
|
108 op3->accept (*this); |
|
109 } |
|
110 |
|
111 tree_expression *op2 = expr.limit (); |
|
112 |
|
113 if (op2) |
|
114 { |
|
115 os << ":"; |
|
116 op2->accept (*this); |
|
117 } |
|
118 |
2961
|
119 print_parens (expr, ")"); |
2123
|
120 } |
|
121 |
|
122 void |
|
123 tree_print_code::visit_continue_command (tree_continue_command&) |
|
124 { |
|
125 indent (); |
|
126 |
|
127 os << "continue"; |
|
128 } |
|
129 |
|
130 void |
2846
|
131 tree_print_code::visit_decl_command (tree_decl_command& cmd) |
|
132 { |
|
133 indent (); |
|
134 |
|
135 os << cmd.name () << " "; |
|
136 |
|
137 tree_decl_init_list *init_list = cmd.initializer_list (); |
|
138 |
|
139 if (init_list) |
|
140 init_list->accept (*this); |
|
141 } |
|
142 |
|
143 void |
|
144 tree_print_code::visit_decl_elt (tree_decl_elt& cmd) |
|
145 { |
|
146 tree_identifier *id = cmd.ident (); |
|
147 |
|
148 if (id) |
|
149 id->accept (*this); |
|
150 |
2969
|
151 tree_expression *expr = cmd.expression (); |
2846
|
152 |
2969
|
153 if (expr) |
|
154 { |
|
155 os << " = "; |
|
156 |
|
157 expr->accept (*this); |
|
158 } |
2846
|
159 } |
|
160 |
|
161 void |
|
162 tree_print_code::visit_decl_init_list (tree_decl_init_list& lst) |
|
163 { |
|
164 Pix p = lst.first (); |
|
165 |
|
166 while (p) |
|
167 { |
|
168 tree_decl_elt *elt = lst (p); |
|
169 |
|
170 lst.next (p); |
|
171 |
|
172 if (elt) |
|
173 { |
|
174 elt->accept (*this); |
|
175 |
|
176 if (p) |
|
177 os << ", "; |
|
178 } |
|
179 } |
|
180 } |
|
181 |
|
182 void |
2969
|
183 tree_print_code::visit_simple_for_command (tree_simple_for_command& cmd) |
2123
|
184 { |
|
185 indent (); |
|
186 |
|
187 os << "for "; |
|
188 |
2969
|
189 tree_expression *lhs = cmd.left_hand_side (); |
2123
|
190 |
2969
|
191 if (lhs) |
|
192 lhs->accept (*this); |
2123
|
193 |
|
194 os << " = "; |
|
195 |
|
196 tree_expression *expr = cmd.control_expr (); |
|
197 |
|
198 if (expr) |
|
199 expr->accept (*this); |
|
200 |
|
201 newline (); |
|
202 |
|
203 tree_statement_list *list = cmd.body (); |
|
204 |
|
205 if (list) |
|
206 { |
|
207 increment_indent_level (); |
|
208 list->accept (*this); |
|
209 decrement_indent_level (); |
|
210 } |
|
211 |
|
212 indent (); |
|
213 |
|
214 os << "endfor"; |
|
215 } |
|
216 |
|
217 void |
2969
|
218 tree_print_code::visit_complex_for_command (tree_complex_for_command& cmd) |
|
219 { |
|
220 indent (); |
|
221 |
|
222 os << "for ["; |
|
223 |
|
224 tree_argument_list *lhs = cmd.left_hand_side (); |
|
225 |
|
226 if (lhs) |
|
227 lhs->accept (*this); |
|
228 |
|
229 os << "] = "; |
|
230 |
|
231 tree_expression *expr = cmd.control_expr (); |
|
232 |
|
233 if (expr) |
|
234 expr->accept (*this); |
|
235 |
|
236 newline (); |
|
237 |
|
238 tree_statement_list *list = cmd.body (); |
|
239 |
|
240 if (list) |
|
241 { |
|
242 increment_indent_level (); |
|
243 list->accept (*this); |
|
244 decrement_indent_level (); |
|
245 } |
|
246 |
|
247 indent (); |
|
248 |
|
249 os << "endfor"; |
|
250 } |
|
251 |
|
252 void |
2891
|
253 tree_print_code::visit_octave_user_function (octave_user_function& fcn) |
2123
|
254 { |
|
255 reset (); |
|
256 |
2891
|
257 visit_octave_user_function_header (fcn); |
2123
|
258 |
|
259 tree_statement_list *cmd_list = fcn.body (); |
|
260 |
|
261 if (cmd_list) |
|
262 { |
|
263 increment_indent_level (); |
|
264 cmd_list->accept (*this); |
|
265 decrement_indent_level (); |
|
266 } |
|
267 |
2891
|
268 visit_octave_user_function_trailer (fcn); |
2123
|
269 } |
|
270 |
|
271 void |
2891
|
272 tree_print_code::visit_octave_user_function_header (octave_user_function& fcn) |
2123
|
273 { |
|
274 indent (); |
|
275 |
|
276 os << "function "; |
|
277 |
|
278 tree_parameter_list *ret_list = fcn.return_list (); |
|
279 |
|
280 if (ret_list) |
|
281 { |
|
282 bool takes_var_return = fcn.takes_var_return (); |
|
283 |
|
284 int len = ret_list->length (); |
|
285 |
|
286 if (len > 1 || takes_var_return) |
|
287 os << "["; |
|
288 |
|
289 ret_list->accept (*this); |
|
290 |
|
291 if (takes_var_return) |
|
292 { |
|
293 if (len > 0) |
|
294 os << ", "; |
|
295 |
|
296 os << "..."; |
|
297 } |
|
298 |
|
299 if (len > 1 || takes_var_return) |
|
300 os << "]"; |
|
301 |
|
302 os << " = "; |
|
303 } |
|
304 |
|
305 string fcn_name = fcn.function_name (); |
|
306 |
|
307 os << (fcn_name.empty () ? string ("(empty)") : fcn_name) << " "; |
|
308 |
|
309 tree_parameter_list *param_list = fcn.parameter_list (); |
|
310 |
|
311 if (param_list) |
|
312 { |
|
313 bool takes_varargs = fcn.takes_varargs (); |
|
314 |
|
315 int len = param_list->length (); |
|
316 |
|
317 if (len > 0 || takes_varargs) |
|
318 os << "("; |
|
319 |
|
320 param_list->accept (*this); |
|
321 |
|
322 if (takes_varargs) |
|
323 { |
|
324 if (len > 0) |
|
325 os << ", "; |
|
326 |
|
327 os << "..."; |
|
328 } |
|
329 |
|
330 if (len > 0 || takes_varargs) |
|
331 { |
|
332 os << ")"; |
|
333 newline (); |
|
334 } |
|
335 } |
|
336 else |
|
337 { |
|
338 os << "()"; |
|
339 newline (); |
|
340 } |
|
341 } |
|
342 |
|
343 void |
2891
|
344 tree_print_code::visit_octave_user_function_trailer (octave_user_function&) |
2123
|
345 { |
|
346 indent (); |
|
347 |
|
348 os << "endfunction"; |
|
349 |
|
350 newline (); |
|
351 } |
|
352 |
|
353 void |
|
354 tree_print_code::visit_identifier (tree_identifier& id) |
|
355 { |
|
356 indent (); |
|
357 |
2961
|
358 print_parens (id, "("); |
2123
|
359 |
|
360 string nm = id.name (); |
|
361 os << (nm.empty () ? string ("(empty)") : nm); |
|
362 |
2961
|
363 print_parens (id, ")"); |
2123
|
364 } |
|
365 |
|
366 void |
|
367 tree_print_code::visit_if_clause (tree_if_clause& cmd) |
|
368 { |
|
369 tree_expression *expr = cmd.condition (); |
|
370 |
|
371 if (expr) |
|
372 expr->accept (*this); |
|
373 |
|
374 newline (); |
|
375 |
|
376 increment_indent_level (); |
|
377 |
|
378 tree_statement_list *list = cmd.commands (); |
|
379 |
|
380 if (list) |
|
381 { |
|
382 list->accept (*this); |
|
383 |
|
384 decrement_indent_level (); |
|
385 } |
|
386 } |
|
387 |
|
388 void |
|
389 tree_print_code::visit_if_command (tree_if_command& cmd) |
|
390 { |
|
391 indent (); |
|
392 |
|
393 os << "if "; |
|
394 |
|
395 tree_if_command_list *list = cmd.cmd_list (); |
|
396 |
|
397 if (list) |
|
398 list->accept (*this); |
|
399 |
|
400 indent (); |
|
401 |
|
402 os << "endif"; |
|
403 } |
|
404 |
|
405 void |
|
406 tree_print_code::visit_if_command_list (tree_if_command_list& lst) |
|
407 { |
|
408 Pix p = lst.first (); |
|
409 |
|
410 bool first_elt = true; |
|
411 |
|
412 while (p) |
|
413 { |
|
414 tree_if_clause *elt = lst (p); |
|
415 |
|
416 if (elt) |
|
417 { |
|
418 if (! first_elt) |
|
419 { |
|
420 indent (); |
|
421 |
|
422 if (elt->is_else_clause ()) |
|
423 os << "else"; |
|
424 else |
|
425 os << "elseif "; |
|
426 } |
|
427 |
|
428 elt->accept (*this); |
|
429 } |
|
430 |
|
431 first_elt = false; |
|
432 lst.next (p); |
|
433 } |
|
434 } |
|
435 |
|
436 void |
|
437 tree_print_code::visit_index_expression (tree_index_expression& expr) |
|
438 { |
|
439 indent (); |
|
440 |
2961
|
441 print_parens (expr, "("); |
2123
|
442 |
2969
|
443 tree_expression *e= expr.expression (); |
2123
|
444 |
2969
|
445 if (e) |
|
446 e->accept (*this); |
2123
|
447 |
|
448 tree_argument_list *list = expr.arg_list (); |
|
449 |
|
450 if (list) |
|
451 { |
|
452 os << " ("; |
|
453 list->accept (*this); |
|
454 os << ")"; |
|
455 } |
|
456 |
2961
|
457 print_parens (expr, ")"); |
2123
|
458 } |
|
459 |
|
460 void |
|
461 tree_print_code::visit_indirect_ref (tree_indirect_ref& expr) |
|
462 { |
|
463 indent (); |
|
464 |
2961
|
465 print_parens (expr, "("); |
2123
|
466 |
2969
|
467 tree_expression *e = expr.expression (); |
2123
|
468 |
2969
|
469 if (e) |
|
470 e->accept (*this); |
|
471 |
|
472 os << "." << expr.elt_name (); |
2123
|
473 |
2961
|
474 print_parens (expr, ")"); |
2123
|
475 } |
|
476 |
|
477 void |
|
478 tree_print_code::visit_matrix (tree_matrix& lst) |
|
479 { |
|
480 indent (); |
|
481 |
2961
|
482 print_parens (lst, "("); |
2123
|
483 |
|
484 os << "["; |
|
485 |
|
486 Pix p = lst.first (); |
|
487 |
|
488 while (p) |
|
489 { |
2969
|
490 tree_argument_list *elt = lst (p); |
2123
|
491 |
|
492 lst.next (p); |
|
493 |
|
494 if (elt) |
|
495 { |
|
496 elt->accept (*this); |
|
497 |
|
498 if (p) |
|
499 os << "; "; |
|
500 } |
|
501 } |
|
502 |
|
503 os << "]"; |
|
504 |
2961
|
505 print_parens (lst, ")"); |
2123
|
506 } |
|
507 |
|
508 void |
2969
|
509 tree_print_code::visit_multi_assignment (tree_multi_assignment& expr) |
2123
|
510 { |
|
511 indent (); |
|
512 |
2961
|
513 print_parens (expr, "("); |
2123
|
514 |
2969
|
515 tree_argument_list *lhs = expr.left_hand_side (); |
2123
|
516 |
|
517 if (lhs) |
|
518 { |
|
519 int len = lhs->length (); |
|
520 |
|
521 if (len > 1) |
|
522 os << "["; |
|
523 |
|
524 lhs->accept (*this); |
|
525 |
|
526 if (len > 1) |
|
527 os << "]"; |
|
528 } |
|
529 |
|
530 os << " = "; |
|
531 |
2969
|
532 tree_expression *rhs = expr.right_hand_side (); |
2123
|
533 |
|
534 if (rhs) |
|
535 rhs->accept (*this); |
|
536 |
2961
|
537 print_parens (expr, ")"); |
2123
|
538 } |
|
539 |
|
540 void |
2620
|
541 tree_print_code::visit_no_op_command (tree_no_op_command& cmd) |
|
542 { |
|
543 indent (); |
|
544 |
|
545 os << cmd.original_command (); |
|
546 } |
|
547 |
|
548 void |
2123
|
549 tree_print_code::visit_oct_obj (tree_oct_obj&) |
|
550 { |
|
551 ::error ("visit_oct_obj: internal error"); |
|
552 } |
|
553 |
|
554 void |
2372
|
555 tree_print_code::visit_constant (tree_constant& val) |
2123
|
556 { |
|
557 indent (); |
|
558 |
2961
|
559 print_parens (val, "("); |
2123
|
560 |
2942
|
561 val.print_raw (os, true, print_original_text); |
2123
|
562 |
2961
|
563 print_parens (val, ")"); |
2123
|
564 } |
|
565 |
|
566 void |
|
567 tree_print_code::visit_parameter_list (tree_parameter_list& lst) |
|
568 { |
|
569 Pix p = lst.first (); |
|
570 |
|
571 while (p) |
|
572 { |
|
573 tree_identifier *elt = lst (p); |
|
574 |
|
575 lst.next (p); |
|
576 |
|
577 if (elt) |
|
578 { |
|
579 elt->accept (*this); |
|
580 |
|
581 if (p) |
|
582 os << ", "; |
|
583 } |
|
584 } |
|
585 } |
|
586 |
|
587 void |
|
588 tree_print_code::visit_plot_command (tree_plot_command& cmd) |
|
589 { |
|
590 indent (); |
|
591 |
|
592 int ndim = cmd.num_dimensions (); |
|
593 |
|
594 switch (ndim) |
|
595 { |
|
596 case 1: |
|
597 os << "replot"; |
|
598 break; |
|
599 |
|
600 case 2: |
|
601 os << "gplot"; |
|
602 break; |
|
603 |
|
604 case 3: |
|
605 os << "gsplot"; |
|
606 break; |
|
607 |
|
608 default: |
|
609 os << "<unkown plot command>"; |
|
610 break; |
|
611 } |
|
612 |
|
613 plot_limits *range = cmd.limits (); |
|
614 |
|
615 if (range) |
|
616 range->accept (*this); |
|
617 |
|
618 subplot_list *plot_list = cmd.subplots (); |
|
619 |
|
620 if (plot_list) |
|
621 plot_list->accept (*this); |
|
622 } |
|
623 |
|
624 void |
|
625 tree_print_code::visit_plot_limits (plot_limits& cmd) |
|
626 { |
|
627 plot_range *x_range = cmd.x_limits (); |
|
628 |
|
629 if (x_range) |
|
630 x_range->accept (*this); |
|
631 |
|
632 plot_range *y_range = cmd.y_limits (); |
|
633 |
|
634 if (y_range) |
|
635 y_range->accept (*this); |
|
636 |
|
637 plot_range *z_range = cmd.z_limits (); |
|
638 |
|
639 if (z_range) |
|
640 z_range->accept (*this); |
|
641 } |
|
642 |
|
643 void |
|
644 tree_print_code::visit_plot_range (plot_range& cmd) |
|
645 { |
|
646 os << " ["; |
|
647 |
|
648 tree_expression *lower = cmd.lower_bound (); |
|
649 |
|
650 if (lower) |
|
651 lower->accept (*this); |
|
652 |
|
653 os << ":"; |
|
654 |
|
655 tree_expression *upper = cmd.upper_bound (); |
|
656 |
|
657 if (upper) |
|
658 upper->accept (*this); |
|
659 |
|
660 os << "]"; |
|
661 } |
|
662 |
|
663 void |
|
664 tree_print_code::visit_postfix_expression (tree_postfix_expression& expr) |
|
665 { |
|
666 indent (); |
|
667 |
2961
|
668 print_parens (expr, "("); |
2123
|
669 |
2960
|
670 tree_expression *e = expr.operand (); |
2123
|
671 |
2960
|
672 if (e) |
|
673 e->accept (*this); |
2123
|
674 |
|
675 os << expr.oper (); |
|
676 |
2961
|
677 print_parens (expr, ")"); |
2123
|
678 } |
|
679 |
|
680 void |
|
681 tree_print_code::visit_prefix_expression (tree_prefix_expression& expr) |
|
682 { |
|
683 indent (); |
|
684 |
2961
|
685 print_parens (expr, "("); |
2123
|
686 |
|
687 os << expr.oper (); |
|
688 |
2960
|
689 tree_expression *e = expr.operand (); |
2123
|
690 |
2960
|
691 if (e) |
|
692 e->accept (*this); |
2123
|
693 |
2961
|
694 print_parens (expr, ")"); |
2123
|
695 } |
|
696 |
|
697 void |
|
698 tree_print_code::visit_return_command (tree_return_command&) |
|
699 { |
|
700 indent (); |
|
701 |
|
702 os << "return"; |
|
703 } |
|
704 |
|
705 void |
|
706 tree_print_code::visit_return_list (tree_return_list& lst) |
|
707 { |
|
708 Pix p = lst.first (); |
|
709 |
|
710 while (p) |
|
711 { |
|
712 tree_index_expression *elt = lst (p); |
|
713 |
|
714 lst.next (p); |
|
715 |
|
716 if (elt) |
|
717 { |
|
718 elt->accept (*this); |
|
719 |
|
720 if (p) |
|
721 os << ", "; |
|
722 } |
|
723 } |
|
724 } |
|
725 |
|
726 void |
2969
|
727 tree_print_code::visit_simple_assignment (tree_simple_assignment& expr) |
2123
|
728 { |
|
729 indent (); |
|
730 |
2961
|
731 print_parens (expr, "("); |
2123
|
732 |
2969
|
733 tree_expression *lhs = expr.left_hand_side (); |
2123
|
734 |
2969
|
735 if (lhs) |
|
736 lhs->accept (*this); |
2123
|
737 |
2969
|
738 os << " " << expr.oper () << " "; |
2123
|
739 |
|
740 tree_expression *rhs = expr.right_hand_side (); |
|
741 |
|
742 if (rhs) |
|
743 rhs->accept (*this); |
|
744 |
2961
|
745 print_parens (expr, ")"); |
2123
|
746 } |
|
747 |
|
748 void |
|
749 tree_print_code::visit_statement (tree_statement& stmt) |
|
750 { |
|
751 tree_command *cmd = stmt.command (); |
|
752 |
|
753 if (cmd) |
|
754 { |
|
755 cmd->accept (*this); |
|
756 |
|
757 if (! stmt.print_result ()) |
|
758 os << ";"; |
|
759 |
|
760 newline (); |
|
761 } |
|
762 else |
|
763 { |
|
764 tree_expression *expr = stmt.expression (); |
|
765 |
|
766 if (expr) |
|
767 { |
|
768 expr->accept (*this); |
|
769 |
|
770 if (! stmt.print_result ()) |
|
771 os << ";"; |
|
772 |
|
773 newline (); |
|
774 } |
|
775 } |
|
776 } |
|
777 |
|
778 void |
|
779 tree_print_code::visit_statement_list (tree_statement_list& lst) |
|
780 { |
|
781 for (Pix p = lst.first (); p != 0; lst.next (p)) |
|
782 { |
|
783 tree_statement *elt = lst (p); |
|
784 |
|
785 if (elt) |
|
786 elt->accept (*this); |
|
787 } |
|
788 } |
|
789 |
|
790 void |
|
791 tree_print_code::visit_subplot (subplot& cmd) |
|
792 { |
|
793 tree_expression *sp_plot_data = cmd.plot_data (); |
|
794 |
|
795 if (sp_plot_data) |
|
796 { |
|
797 os << " "; |
|
798 |
|
799 sp_plot_data->accept (*this); |
|
800 } |
|
801 |
|
802 subplot_using *sp_using_clause = cmd.using_clause (); |
|
803 |
|
804 if (sp_using_clause) |
|
805 sp_using_clause->accept (*this); |
|
806 |
|
807 tree_expression *sp_title_clause = cmd.title_clause (); |
|
808 |
|
809 if (sp_title_clause) |
|
810 sp_title_clause->accept (*this); |
|
811 |
|
812 subplot_style *sp_style_clause = cmd.style_clause (); |
|
813 |
|
814 if (sp_style_clause) |
|
815 sp_style_clause->accept (*this); |
|
816 } |
|
817 |
|
818 void |
|
819 tree_print_code::visit_subplot_list (subplot_list& lst) |
|
820 { |
|
821 Pix p = lst.first (); |
|
822 |
|
823 while (p) |
|
824 { |
|
825 subplot *elt = lst (p); |
|
826 |
|
827 lst.next (p); |
|
828 |
|
829 if (elt) |
|
830 { |
|
831 elt->accept (*this); |
|
832 |
|
833 if (p) |
|
834 os << ","; |
|
835 } |
|
836 } |
|
837 } |
|
838 |
|
839 void |
|
840 tree_print_code::visit_subplot_style (subplot_style& cmd) |
|
841 { |
|
842 os << " with " << cmd.style (); |
|
843 |
|
844 tree_expression *sp_linetype = cmd.linetype (); |
|
845 |
|
846 if (sp_linetype) |
|
847 { |
|
848 os << " "; |
|
849 |
|
850 sp_linetype->accept (*this); |
|
851 } |
|
852 |
|
853 tree_expression *sp_pointtype = cmd.pointtype (); |
|
854 |
|
855 if (sp_pointtype) |
|
856 { |
|
857 os << " "; |
|
858 |
|
859 sp_pointtype->accept (*this); |
|
860 } |
|
861 } |
|
862 |
|
863 void |
|
864 tree_print_code::visit_subplot_using (subplot_using& cmd) |
|
865 { |
|
866 os << " using "; |
|
867 |
|
868 int qual_count = cmd.qualifier_count (); |
|
869 |
|
870 if (qual_count > 0) |
|
871 { |
|
872 tree_expression **x = cmd.qualifiers (); |
|
873 |
|
874 for (int i = 0; i < qual_count; i++) |
|
875 { |
|
876 if (i > 0) |
|
877 os << ":"; |
|
878 |
|
879 if (x[i]) |
|
880 x[i]->accept (*this); |
|
881 } |
|
882 } |
|
883 else |
|
884 { |
|
885 tree_expression *scanf_fmt = cmd.scanf_format (); |
|
886 |
|
887 if (scanf_fmt) |
|
888 scanf_fmt->accept (*this); |
|
889 } |
|
890 } |
|
891 |
|
892 void |
2846
|
893 tree_print_code::visit_switch_case (tree_switch_case& cs) |
|
894 { |
|
895 indent (); |
|
896 |
|
897 if (cs.is_default_case ()) |
|
898 os << "otherwise"; |
|
899 else |
|
900 os << "case "; |
|
901 |
|
902 tree_expression *label = cs.case_label (); |
|
903 |
|
904 if (label) |
|
905 label->accept (*this); |
|
906 |
|
907 newline (); |
|
908 |
|
909 increment_indent_level (); |
|
910 |
|
911 tree_statement_list *list = cs.commands (); |
|
912 |
|
913 if (list) |
|
914 { |
|
915 list->accept (*this); |
|
916 |
|
917 decrement_indent_level (); |
|
918 } |
|
919 } |
|
920 |
|
921 void |
|
922 tree_print_code::visit_switch_case_list (tree_switch_case_list& lst) |
|
923 { |
|
924 Pix p = lst.first (); |
|
925 |
|
926 while (p) |
|
927 { |
|
928 tree_switch_case *elt = lst (p); |
|
929 |
|
930 if (elt) |
|
931 elt->accept (*this); |
|
932 |
|
933 lst.next (p); |
|
934 } |
|
935 } |
|
936 |
|
937 void |
|
938 tree_print_code::visit_switch_command (tree_switch_command& cmd) |
|
939 { |
|
940 indent (); |
|
941 |
|
942 os << "switch "; |
|
943 |
|
944 tree_expression *expr = cmd.switch_value (); |
|
945 |
|
946 if (expr) |
|
947 expr->accept (*this); |
|
948 |
|
949 newline (); |
|
950 |
|
951 increment_indent_level (); |
|
952 |
|
953 tree_switch_case_list *list = cmd.case_list (); |
|
954 |
|
955 if (list) |
|
956 list->accept (*this); |
|
957 |
|
958 indent (); |
|
959 |
|
960 os << "endswitch"; |
|
961 } |
|
962 |
|
963 void |
2123
|
964 tree_print_code::visit_try_catch_command (tree_try_catch_command& cmd) |
|
965 { |
|
966 indent (); |
|
967 |
|
968 os << "try_catch"; |
|
969 |
|
970 newline (); |
|
971 |
|
972 tree_statement_list *try_code = cmd.body (); |
|
973 |
|
974 if (try_code) |
|
975 { |
|
976 increment_indent_level (); |
|
977 try_code->accept (*this); |
|
978 decrement_indent_level (); |
|
979 } |
|
980 |
|
981 indent (); |
|
982 |
|
983 os << "catch"; |
|
984 |
|
985 newline (); |
|
986 |
|
987 tree_statement_list *catch_code = cmd.cleanup (); |
|
988 |
|
989 if (catch_code) |
|
990 { |
|
991 increment_indent_level (); |
|
992 catch_code->accept (*this); |
|
993 decrement_indent_level (); |
|
994 } |
|
995 |
|
996 indent (); |
|
997 |
|
998 os << "end_try_catch"; |
|
999 } |
|
1000 |
|
1001 void |
|
1002 tree_print_code::visit_unwind_protect_command |
|
1003 (tree_unwind_protect_command& cmd) |
|
1004 { |
|
1005 indent (); |
|
1006 |
|
1007 os << "unwind_protect"; |
|
1008 |
|
1009 newline (); |
|
1010 |
|
1011 tree_statement_list *unwind_protect_code = cmd.body (); |
|
1012 |
|
1013 if (unwind_protect_code) |
|
1014 { |
|
1015 increment_indent_level (); |
|
1016 unwind_protect_code->accept (*this); |
|
1017 decrement_indent_level (); |
|
1018 } |
|
1019 |
|
1020 indent (); |
|
1021 |
|
1022 os << "cleanup_code"; |
|
1023 |
|
1024 newline (); |
|
1025 |
|
1026 tree_statement_list *cleanup_code = cmd.cleanup (); |
|
1027 |
|
1028 if (cleanup_code) |
|
1029 { |
|
1030 increment_indent_level (); |
|
1031 cleanup_code->accept (*this); |
|
1032 decrement_indent_level (); |
|
1033 } |
|
1034 |
|
1035 indent (); |
|
1036 |
|
1037 os << "end_unwind_protect"; |
|
1038 } |
|
1039 |
|
1040 void |
|
1041 tree_print_code::visit_while_command (tree_while_command& cmd) |
|
1042 { |
|
1043 indent (); |
|
1044 |
|
1045 os << "while "; |
|
1046 |
|
1047 tree_expression *expr = cmd.condition (); |
|
1048 |
|
1049 if (expr) |
|
1050 expr->accept (*this); |
|
1051 |
|
1052 newline (); |
|
1053 |
|
1054 tree_statement_list *list = cmd.body (); |
|
1055 |
|
1056 if (list) |
|
1057 { |
|
1058 increment_indent_level (); |
|
1059 list->accept (*this); |
|
1060 decrement_indent_level (); |
|
1061 } |
|
1062 |
|
1063 indent (); |
|
1064 |
|
1065 os << "endwhile"; |
|
1066 } |
|
1067 |
|
1068 // Current indentation. |
|
1069 int tree_print_code::curr_print_indent_level = 0; |
|
1070 |
|
1071 // Nonzero means we are at the beginning of a line. |
|
1072 bool tree_print_code::beginning_of_line = true; |
|
1073 |
|
1074 // Each print_code() function should call this before printing |
|
1075 // anything. |
|
1076 // |
|
1077 // This doesn't need to be fast, but isn't there a better way? |
|
1078 |
|
1079 void |
|
1080 tree_print_code::indent (void) |
|
1081 { |
|
1082 assert (curr_print_indent_level >= 0); |
|
1083 |
|
1084 if (beginning_of_line) |
|
1085 { |
2900
|
1086 os << prefix; |
|
1087 |
|
1088 for (int i = 0; i < curr_print_indent_level; i++) |
|
1089 os << " "; |
|
1090 |
2123
|
1091 beginning_of_line = false; |
|
1092 } |
|
1093 } |
|
1094 |
|
1095 // All print_code() functions should use this to print new lines. |
|
1096 |
|
1097 void |
|
1098 tree_print_code::newline (void) |
|
1099 { |
|
1100 os << "\n"; |
|
1101 |
|
1102 beginning_of_line = true; |
|
1103 } |
|
1104 |
|
1105 // For ressetting print_code state. |
|
1106 |
|
1107 void |
|
1108 tree_print_code::reset (void) |
|
1109 { |
|
1110 beginning_of_line = true; |
|
1111 curr_print_indent_level = 0; |
|
1112 } |
|
1113 |
2961
|
1114 void |
|
1115 tree_print_code::print_parens (const tree_expression& expr, const char *txt) |
|
1116 { |
|
1117 int n = expr.paren_count (); |
|
1118 |
|
1119 for (int i = 0; i < n; i++) |
|
1120 os << txt; |
|
1121 } |
|
1122 |
2123
|
1123 /* |
|
1124 ;;; Local Variables: *** |
|
1125 ;;; mode: C++ *** |
|
1126 ;;; End: *** |
|
1127 */ |