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