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 |
3010
|
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 |
2372
|
549 tree_print_code::visit_constant (tree_constant& val) |
2123
|
550 { |
|
551 indent (); |
|
552 |
2961
|
553 print_parens (val, "("); |
2123
|
554 |
2942
|
555 val.print_raw (os, true, print_original_text); |
2123
|
556 |
2961
|
557 print_parens (val, ")"); |
2123
|
558 } |
|
559 |
|
560 void |
|
561 tree_print_code::visit_parameter_list (tree_parameter_list& lst) |
|
562 { |
|
563 Pix p = lst.first (); |
|
564 |
|
565 while (p) |
|
566 { |
|
567 tree_identifier *elt = lst (p); |
|
568 |
|
569 lst.next (p); |
|
570 |
|
571 if (elt) |
|
572 { |
|
573 elt->accept (*this); |
|
574 |
|
575 if (p) |
|
576 os << ", "; |
|
577 } |
|
578 } |
|
579 } |
|
580 |
|
581 void |
|
582 tree_print_code::visit_plot_command (tree_plot_command& cmd) |
|
583 { |
|
584 indent (); |
|
585 |
|
586 int ndim = cmd.num_dimensions (); |
|
587 |
|
588 switch (ndim) |
|
589 { |
|
590 case 1: |
|
591 os << "replot"; |
|
592 break; |
|
593 |
|
594 case 2: |
|
595 os << "gplot"; |
|
596 break; |
|
597 |
|
598 case 3: |
|
599 os << "gsplot"; |
|
600 break; |
|
601 |
|
602 default: |
|
603 os << "<unkown plot command>"; |
|
604 break; |
|
605 } |
|
606 |
|
607 plot_limits *range = cmd.limits (); |
|
608 |
|
609 if (range) |
|
610 range->accept (*this); |
|
611 |
|
612 subplot_list *plot_list = cmd.subplots (); |
|
613 |
|
614 if (plot_list) |
|
615 plot_list->accept (*this); |
|
616 } |
|
617 |
|
618 void |
|
619 tree_print_code::visit_plot_limits (plot_limits& cmd) |
|
620 { |
|
621 plot_range *x_range = cmd.x_limits (); |
|
622 |
|
623 if (x_range) |
|
624 x_range->accept (*this); |
|
625 |
|
626 plot_range *y_range = cmd.y_limits (); |
|
627 |
|
628 if (y_range) |
|
629 y_range->accept (*this); |
|
630 |
|
631 plot_range *z_range = cmd.z_limits (); |
|
632 |
|
633 if (z_range) |
|
634 z_range->accept (*this); |
|
635 } |
|
636 |
|
637 void |
|
638 tree_print_code::visit_plot_range (plot_range& cmd) |
|
639 { |
|
640 os << " ["; |
|
641 |
|
642 tree_expression *lower = cmd.lower_bound (); |
|
643 |
|
644 if (lower) |
|
645 lower->accept (*this); |
|
646 |
|
647 os << ":"; |
|
648 |
|
649 tree_expression *upper = cmd.upper_bound (); |
|
650 |
|
651 if (upper) |
|
652 upper->accept (*this); |
|
653 |
|
654 os << "]"; |
|
655 } |
|
656 |
|
657 void |
|
658 tree_print_code::visit_postfix_expression (tree_postfix_expression& expr) |
|
659 { |
|
660 indent (); |
|
661 |
2961
|
662 print_parens (expr, "("); |
2123
|
663 |
2960
|
664 tree_expression *e = expr.operand (); |
2123
|
665 |
2960
|
666 if (e) |
|
667 e->accept (*this); |
2123
|
668 |
|
669 os << expr.oper (); |
|
670 |
2961
|
671 print_parens (expr, ")"); |
2123
|
672 } |
|
673 |
|
674 void |
|
675 tree_print_code::visit_prefix_expression (tree_prefix_expression& expr) |
|
676 { |
|
677 indent (); |
|
678 |
2961
|
679 print_parens (expr, "("); |
2123
|
680 |
|
681 os << expr.oper (); |
|
682 |
2960
|
683 tree_expression *e = expr.operand (); |
2123
|
684 |
2960
|
685 if (e) |
|
686 e->accept (*this); |
2123
|
687 |
2961
|
688 print_parens (expr, ")"); |
2123
|
689 } |
|
690 |
|
691 void |
|
692 tree_print_code::visit_return_command (tree_return_command&) |
|
693 { |
|
694 indent (); |
|
695 |
|
696 os << "return"; |
|
697 } |
|
698 |
|
699 void |
|
700 tree_print_code::visit_return_list (tree_return_list& lst) |
|
701 { |
|
702 Pix p = lst.first (); |
|
703 |
|
704 while (p) |
|
705 { |
|
706 tree_index_expression *elt = lst (p); |
|
707 |
|
708 lst.next (p); |
|
709 |
|
710 if (elt) |
|
711 { |
|
712 elt->accept (*this); |
|
713 |
|
714 if (p) |
|
715 os << ", "; |
|
716 } |
|
717 } |
|
718 } |
|
719 |
|
720 void |
2969
|
721 tree_print_code::visit_simple_assignment (tree_simple_assignment& expr) |
2123
|
722 { |
|
723 indent (); |
|
724 |
2961
|
725 print_parens (expr, "("); |
2123
|
726 |
2969
|
727 tree_expression *lhs = expr.left_hand_side (); |
2123
|
728 |
2969
|
729 if (lhs) |
|
730 lhs->accept (*this); |
2123
|
731 |
2969
|
732 os << " " << expr.oper () << " "; |
2123
|
733 |
|
734 tree_expression *rhs = expr.right_hand_side (); |
|
735 |
|
736 if (rhs) |
|
737 rhs->accept (*this); |
|
738 |
2961
|
739 print_parens (expr, ")"); |
2123
|
740 } |
|
741 |
|
742 void |
|
743 tree_print_code::visit_statement (tree_statement& stmt) |
|
744 { |
|
745 tree_command *cmd = stmt.command (); |
|
746 |
|
747 if (cmd) |
|
748 { |
|
749 cmd->accept (*this); |
|
750 |
|
751 if (! stmt.print_result ()) |
|
752 os << ";"; |
|
753 |
|
754 newline (); |
|
755 } |
|
756 else |
|
757 { |
|
758 tree_expression *expr = stmt.expression (); |
|
759 |
|
760 if (expr) |
|
761 { |
|
762 expr->accept (*this); |
|
763 |
|
764 if (! stmt.print_result ()) |
|
765 os << ";"; |
|
766 |
|
767 newline (); |
|
768 } |
|
769 } |
|
770 } |
|
771 |
|
772 void |
|
773 tree_print_code::visit_statement_list (tree_statement_list& lst) |
|
774 { |
|
775 for (Pix p = lst.first (); p != 0; lst.next (p)) |
|
776 { |
|
777 tree_statement *elt = lst (p); |
|
778 |
|
779 if (elt) |
|
780 elt->accept (*this); |
|
781 } |
|
782 } |
|
783 |
|
784 void |
|
785 tree_print_code::visit_subplot (subplot& cmd) |
|
786 { |
|
787 tree_expression *sp_plot_data = cmd.plot_data (); |
|
788 |
|
789 if (sp_plot_data) |
|
790 { |
|
791 os << " "; |
|
792 |
|
793 sp_plot_data->accept (*this); |
|
794 } |
|
795 |
3165
|
796 subplot_axes *sp_axes_clause = cmd.axes_clause (); |
|
797 |
|
798 if (sp_axes_clause) |
|
799 sp_axes_clause->accept (*this); |
|
800 |
2123
|
801 subplot_using *sp_using_clause = cmd.using_clause (); |
|
802 |
|
803 if (sp_using_clause) |
|
804 sp_using_clause->accept (*this); |
|
805 |
|
806 tree_expression *sp_title_clause = cmd.title_clause (); |
|
807 |
|
808 if (sp_title_clause) |
|
809 sp_title_clause->accept (*this); |
|
810 |
|
811 subplot_style *sp_style_clause = cmd.style_clause (); |
|
812 |
|
813 if (sp_style_clause) |
|
814 sp_style_clause->accept (*this); |
|
815 } |
|
816 |
|
817 void |
3165
|
818 tree_print_code::visit_subplot_axes (subplot_axes& cmd) |
|
819 { |
|
820 os << " axes " << cmd.axes (); |
|
821 } |
|
822 |
|
823 void |
2123
|
824 tree_print_code::visit_subplot_list (subplot_list& lst) |
|
825 { |
|
826 Pix p = lst.first (); |
|
827 |
|
828 while (p) |
|
829 { |
|
830 subplot *elt = lst (p); |
|
831 |
|
832 lst.next (p); |
|
833 |
|
834 if (elt) |
|
835 { |
|
836 elt->accept (*this); |
|
837 |
|
838 if (p) |
|
839 os << ","; |
|
840 } |
|
841 } |
|
842 } |
|
843 |
|
844 void |
|
845 tree_print_code::visit_subplot_style (subplot_style& cmd) |
|
846 { |
|
847 os << " with " << cmd.style (); |
|
848 |
|
849 tree_expression *sp_linetype = cmd.linetype (); |
|
850 |
|
851 if (sp_linetype) |
|
852 { |
|
853 os << " "; |
|
854 |
|
855 sp_linetype->accept (*this); |
|
856 } |
|
857 |
|
858 tree_expression *sp_pointtype = cmd.pointtype (); |
|
859 |
|
860 if (sp_pointtype) |
|
861 { |
|
862 os << " "; |
|
863 |
|
864 sp_pointtype->accept (*this); |
|
865 } |
|
866 } |
|
867 |
|
868 void |
|
869 tree_print_code::visit_subplot_using (subplot_using& cmd) |
|
870 { |
|
871 os << " using "; |
|
872 |
|
873 int qual_count = cmd.qualifier_count (); |
|
874 |
|
875 if (qual_count > 0) |
|
876 { |
|
877 tree_expression **x = cmd.qualifiers (); |
|
878 |
|
879 for (int i = 0; i < qual_count; i++) |
|
880 { |
|
881 if (i > 0) |
|
882 os << ":"; |
|
883 |
|
884 if (x[i]) |
|
885 x[i]->accept (*this); |
|
886 } |
|
887 } |
|
888 else |
|
889 { |
|
890 tree_expression *scanf_fmt = cmd.scanf_format (); |
|
891 |
|
892 if (scanf_fmt) |
|
893 scanf_fmt->accept (*this); |
|
894 } |
|
895 } |
|
896 |
|
897 void |
2846
|
898 tree_print_code::visit_switch_case (tree_switch_case& cs) |
|
899 { |
|
900 indent (); |
|
901 |
|
902 if (cs.is_default_case ()) |
|
903 os << "otherwise"; |
|
904 else |
|
905 os << "case "; |
|
906 |
|
907 tree_expression *label = cs.case_label (); |
|
908 |
|
909 if (label) |
|
910 label->accept (*this); |
|
911 |
|
912 newline (); |
|
913 |
|
914 increment_indent_level (); |
|
915 |
|
916 tree_statement_list *list = cs.commands (); |
|
917 |
|
918 if (list) |
|
919 { |
|
920 list->accept (*this); |
|
921 |
|
922 decrement_indent_level (); |
|
923 } |
|
924 } |
|
925 |
|
926 void |
|
927 tree_print_code::visit_switch_case_list (tree_switch_case_list& lst) |
|
928 { |
|
929 Pix p = lst.first (); |
|
930 |
|
931 while (p) |
|
932 { |
|
933 tree_switch_case *elt = lst (p); |
|
934 |
|
935 if (elt) |
|
936 elt->accept (*this); |
|
937 |
|
938 lst.next (p); |
|
939 } |
|
940 } |
|
941 |
|
942 void |
|
943 tree_print_code::visit_switch_command (tree_switch_command& cmd) |
|
944 { |
|
945 indent (); |
|
946 |
|
947 os << "switch "; |
|
948 |
|
949 tree_expression *expr = cmd.switch_value (); |
|
950 |
|
951 if (expr) |
|
952 expr->accept (*this); |
|
953 |
|
954 newline (); |
|
955 |
|
956 increment_indent_level (); |
|
957 |
|
958 tree_switch_case_list *list = cmd.case_list (); |
|
959 |
|
960 if (list) |
|
961 list->accept (*this); |
|
962 |
|
963 indent (); |
|
964 |
|
965 os << "endswitch"; |
|
966 } |
|
967 |
|
968 void |
2123
|
969 tree_print_code::visit_try_catch_command (tree_try_catch_command& cmd) |
|
970 { |
|
971 indent (); |
|
972 |
|
973 os << "try_catch"; |
|
974 |
|
975 newline (); |
|
976 |
|
977 tree_statement_list *try_code = cmd.body (); |
|
978 |
|
979 if (try_code) |
|
980 { |
|
981 increment_indent_level (); |
|
982 try_code->accept (*this); |
|
983 decrement_indent_level (); |
|
984 } |
|
985 |
|
986 indent (); |
|
987 |
|
988 os << "catch"; |
|
989 |
|
990 newline (); |
|
991 |
|
992 tree_statement_list *catch_code = cmd.cleanup (); |
|
993 |
|
994 if (catch_code) |
|
995 { |
|
996 increment_indent_level (); |
|
997 catch_code->accept (*this); |
|
998 decrement_indent_level (); |
|
999 } |
|
1000 |
|
1001 indent (); |
|
1002 |
|
1003 os << "end_try_catch"; |
|
1004 } |
|
1005 |
|
1006 void |
|
1007 tree_print_code::visit_unwind_protect_command |
|
1008 (tree_unwind_protect_command& cmd) |
|
1009 { |
|
1010 indent (); |
|
1011 |
|
1012 os << "unwind_protect"; |
|
1013 |
|
1014 newline (); |
|
1015 |
|
1016 tree_statement_list *unwind_protect_code = cmd.body (); |
|
1017 |
|
1018 if (unwind_protect_code) |
|
1019 { |
|
1020 increment_indent_level (); |
|
1021 unwind_protect_code->accept (*this); |
|
1022 decrement_indent_level (); |
|
1023 } |
|
1024 |
|
1025 indent (); |
|
1026 |
|
1027 os << "cleanup_code"; |
|
1028 |
|
1029 newline (); |
|
1030 |
|
1031 tree_statement_list *cleanup_code = cmd.cleanup (); |
|
1032 |
|
1033 if (cleanup_code) |
|
1034 { |
|
1035 increment_indent_level (); |
|
1036 cleanup_code->accept (*this); |
|
1037 decrement_indent_level (); |
|
1038 } |
|
1039 |
|
1040 indent (); |
|
1041 |
|
1042 os << "end_unwind_protect"; |
|
1043 } |
|
1044 |
|
1045 void |
|
1046 tree_print_code::visit_while_command (tree_while_command& cmd) |
|
1047 { |
|
1048 indent (); |
|
1049 |
|
1050 os << "while "; |
|
1051 |
|
1052 tree_expression *expr = cmd.condition (); |
|
1053 |
|
1054 if (expr) |
|
1055 expr->accept (*this); |
|
1056 |
|
1057 newline (); |
|
1058 |
|
1059 tree_statement_list *list = cmd.body (); |
|
1060 |
|
1061 if (list) |
|
1062 { |
|
1063 increment_indent_level (); |
|
1064 list->accept (*this); |
|
1065 decrement_indent_level (); |
|
1066 } |
|
1067 |
|
1068 indent (); |
|
1069 |
|
1070 os << "endwhile"; |
|
1071 } |
|
1072 |
|
1073 // Current indentation. |
|
1074 int tree_print_code::curr_print_indent_level = 0; |
|
1075 |
3018
|
1076 // TRUE means we are at the beginning of a line. |
2123
|
1077 bool tree_print_code::beginning_of_line = true; |
|
1078 |
|
1079 // Each print_code() function should call this before printing |
|
1080 // anything. |
|
1081 // |
|
1082 // This doesn't need to be fast, but isn't there a better way? |
|
1083 |
|
1084 void |
|
1085 tree_print_code::indent (void) |
|
1086 { |
|
1087 assert (curr_print_indent_level >= 0); |
|
1088 |
|
1089 if (beginning_of_line) |
|
1090 { |
2900
|
1091 os << prefix; |
|
1092 |
|
1093 for (int i = 0; i < curr_print_indent_level; i++) |
|
1094 os << " "; |
|
1095 |
2123
|
1096 beginning_of_line = false; |
|
1097 } |
|
1098 } |
|
1099 |
|
1100 // All print_code() functions should use this to print new lines. |
|
1101 |
|
1102 void |
|
1103 tree_print_code::newline (void) |
|
1104 { |
|
1105 os << "\n"; |
|
1106 |
|
1107 beginning_of_line = true; |
|
1108 } |
|
1109 |
|
1110 // For ressetting print_code state. |
|
1111 |
|
1112 void |
|
1113 tree_print_code::reset (void) |
|
1114 { |
|
1115 beginning_of_line = true; |
|
1116 curr_print_indent_level = 0; |
|
1117 } |
|
1118 |
2961
|
1119 void |
|
1120 tree_print_code::print_parens (const tree_expression& expr, const char *txt) |
|
1121 { |
|
1122 int n = expr.paren_count (); |
|
1123 |
|
1124 for (int i = 0; i < n; i++) |
|
1125 os << txt; |
|
1126 } |
|
1127 |
2123
|
1128 /* |
|
1129 ;;; Local Variables: *** |
|
1130 ;;; mode: C++ *** |
|
1131 ;;; End: *** |
|
1132 */ |