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