Mercurial > hg > octave-nkf
comparison src/pt-pr-code.cc @ 2969:1b47dd00a831
[project @ 1997-05-15 17:57:48 by jwe]
author | jwe |
---|---|
date | Thu, 15 May 1997 17:58:30 +0000 |
parents | 8a77d52c9d02 |
children | 20f5cec4f11c |
comparison
equal
deleted
inserted
replaced
2968:e330cb788508 | 2969:1b47dd00a831 |
---|---|
29 #endif | 29 #endif |
30 | 30 |
31 #include <iostream.h> | 31 #include <iostream.h> |
32 | 32 |
33 #include "error.h" | 33 #include "error.h" |
34 #include "oct-usr-fcn.h" | 34 #include "ov-usr-fcn.h" |
35 #include "pr-output.h" | 35 #include "pr-output.h" |
36 #include "pt-cmd.h" | 36 #include "pt-cmd.h" |
37 #include "pt-const.h" | 37 #include "pt-const.h" |
38 #include "pt-exp.h" | 38 #include "pt-exp.h" |
39 #include "pt-id.h" | 39 #include "pt-id.h" |
40 #include "pt-indir.h" | 40 #include "pt-indir.h" |
41 #include "pt-mat.h" | 41 #include "pt-mat.h" |
42 #include "pt-misc.h" | 42 #include "pt-misc.h" |
43 #include "pt-mvr.h" | |
44 #include "pt-plot.h" | 43 #include "pt-plot.h" |
45 #include "pt-pr-code.h" | 44 #include "pt-pr-code.h" |
46 | 45 |
47 void | 46 void |
48 tree_print_code::visit_argument_list (tree_argument_list& lst) | 47 tree_print_code::visit_argument_list (tree_argument_list& lst) |
155 tree_identifier *id = cmd.ident (); | 154 tree_identifier *id = cmd.ident (); |
156 | 155 |
157 if (id) | 156 if (id) |
158 id->accept (*this); | 157 id->accept (*this); |
159 | 158 |
160 tree_simple_assignment_expression *ass_expr = cmd.assign_expr (); | 159 tree_expression *expr = cmd.expression (); |
161 | 160 |
162 if (ass_expr) | 161 if (expr) |
163 ass_expr->accept (*this); | 162 { |
163 os << " = "; | |
164 | |
165 expr->accept (*this); | |
166 } | |
164 } | 167 } |
165 | 168 |
166 void | 169 void |
167 tree_print_code::visit_decl_init_list (tree_decl_init_list& lst) | 170 tree_print_code::visit_decl_init_list (tree_decl_init_list& lst) |
168 { | 171 { |
183 } | 186 } |
184 } | 187 } |
185 } | 188 } |
186 | 189 |
187 void | 190 void |
188 tree_print_code::visit_for_command (tree_for_command& cmd) | 191 tree_print_code::visit_simple_for_command (tree_simple_for_command& cmd) |
189 { | 192 { |
190 indent (); | 193 indent (); |
191 | 194 |
192 os << "for "; | 195 os << "for "; |
193 | 196 |
194 tree_index_expression *id = cmd.ident (); | 197 tree_expression *lhs = cmd.left_hand_side (); |
195 | 198 |
196 if (id) | 199 if (lhs) |
197 id->accept (*this); | 200 lhs->accept (*this); |
198 | 201 |
199 os << " = "; | 202 os << " = "; |
203 | |
204 tree_expression *expr = cmd.control_expr (); | |
205 | |
206 if (expr) | |
207 expr->accept (*this); | |
208 | |
209 newline (); | |
210 | |
211 tree_statement_list *list = cmd.body (); | |
212 | |
213 if (list) | |
214 { | |
215 increment_indent_level (); | |
216 list->accept (*this); | |
217 decrement_indent_level (); | |
218 } | |
219 | |
220 indent (); | |
221 | |
222 os << "endfor"; | |
223 } | |
224 | |
225 void | |
226 tree_print_code::visit_complex_for_command (tree_complex_for_command& cmd) | |
227 { | |
228 indent (); | |
229 | |
230 os << "for ["; | |
231 | |
232 tree_argument_list *lhs = cmd.left_hand_side (); | |
233 | |
234 if (lhs) | |
235 lhs->accept (*this); | |
236 | |
237 os << "] = "; | |
200 | 238 |
201 tree_expression *expr = cmd.control_expr (); | 239 tree_expression *expr = cmd.control_expr (); |
202 | 240 |
203 if (expr) | 241 if (expr) |
204 expr->accept (*this); | 242 expr->accept (*this); |
408 { | 446 { |
409 indent (); | 447 indent (); |
410 | 448 |
411 print_parens (expr, "("); | 449 print_parens (expr, "("); |
412 | 450 |
413 tree_indirect_ref *id = expr.ident (); | 451 tree_expression *e= expr.expression (); |
414 | 452 |
415 if (id) | 453 if (e) |
416 id->accept (*this); | 454 e->accept (*this); |
417 | 455 |
418 tree_argument_list *list = expr.arg_list (); | 456 tree_argument_list *list = expr.arg_list (); |
419 | 457 |
420 if (list) | 458 if (list) |
421 { | 459 { |
432 { | 470 { |
433 indent (); | 471 indent (); |
434 | 472 |
435 print_parens (expr, "("); | 473 print_parens (expr, "("); |
436 | 474 |
437 // The name of the indirect ref includes the sub-elements. | 475 tree_expression *e = expr.expression (); |
438 | 476 |
439 string nm = expr.name (); | 477 if (e) |
440 os << (nm.empty () ? string ("(empty)") : nm); | 478 e->accept (*this); |
479 | |
480 os << "." << expr.elt_name (); | |
441 | 481 |
442 print_parens (expr, ")"); | 482 print_parens (expr, ")"); |
443 } | 483 } |
444 | 484 |
445 void | 485 void |
453 | 493 |
454 Pix p = lst.first (); | 494 Pix p = lst.first (); |
455 | 495 |
456 while (p) | 496 while (p) |
457 { | 497 { |
458 tree_matrix_row *elt = lst (p); | 498 tree_argument_list *elt = lst (p); |
459 | 499 |
460 lst.next (p); | 500 lst.next (p); |
461 | 501 |
462 if (elt) | 502 if (elt) |
463 { | 503 { |
472 | 512 |
473 print_parens (lst, ")"); | 513 print_parens (lst, ")"); |
474 } | 514 } |
475 | 515 |
476 void | 516 void |
477 tree_print_code::visit_matrix_row (tree_matrix_row& lst) | 517 tree_print_code::visit_multi_assignment (tree_multi_assignment& expr) |
518 { | |
519 indent (); | |
520 | |
521 print_parens (expr, "("); | |
522 | |
523 tree_argument_list *lhs = expr.left_hand_side (); | |
524 | |
525 if (lhs) | |
526 { | |
527 int len = lhs->length (); | |
528 | |
529 if (len > 1) | |
530 os << "["; | |
531 | |
532 lhs->accept (*this); | |
533 | |
534 if (len > 1) | |
535 os << "]"; | |
536 } | |
537 | |
538 os << " = "; | |
539 | |
540 tree_expression *rhs = expr.right_hand_side (); | |
541 | |
542 if (rhs) | |
543 rhs->accept (*this); | |
544 | |
545 print_parens (expr, ")"); | |
546 } | |
547 | |
548 void | |
549 tree_print_code::visit_no_op_command (tree_no_op_command& cmd) | |
550 { | |
551 indent (); | |
552 | |
553 os << cmd.original_command (); | |
554 } | |
555 | |
556 void | |
557 tree_print_code::visit_oct_obj (tree_oct_obj&) | |
558 { | |
559 ::error ("visit_oct_obj: internal error"); | |
560 } | |
561 | |
562 void | |
563 tree_print_code::visit_constant (tree_constant& val) | |
564 { | |
565 indent (); | |
566 | |
567 print_parens (val, "("); | |
568 | |
569 val.print_raw (os, true, print_original_text); | |
570 | |
571 print_parens (val, ")"); | |
572 } | |
573 | |
574 void | |
575 tree_print_code::visit_parameter_list (tree_parameter_list& lst) | |
478 { | 576 { |
479 Pix p = lst.first (); | 577 Pix p = lst.first (); |
480 | 578 |
481 while (p) | 579 while (p) |
482 { | 580 { |
483 tree_expression *elt = lst (p); | 581 tree_identifier *elt = lst (p); |
484 | 582 |
485 lst.next (p); | 583 lst.next (p); |
486 | 584 |
487 if (elt) | 585 if (elt) |
488 { | 586 { |
493 } | 591 } |
494 } | 592 } |
495 } | 593 } |
496 | 594 |
497 void | 595 void |
498 tree_print_code::visit_multi_assignment_expression | 596 tree_print_code::visit_plot_command (tree_plot_command& cmd) |
499 (tree_multi_assignment_expression& expr) | 597 { |
598 indent (); | |
599 | |
600 int ndim = cmd.num_dimensions (); | |
601 | |
602 switch (ndim) | |
603 { | |
604 case 1: | |
605 os << "replot"; | |
606 break; | |
607 | |
608 case 2: | |
609 os << "gplot"; | |
610 break; | |
611 | |
612 case 3: | |
613 os << "gsplot"; | |
614 break; | |
615 | |
616 default: | |
617 os << "<unkown plot command>"; | |
618 break; | |
619 } | |
620 | |
621 plot_limits *range = cmd.limits (); | |
622 | |
623 if (range) | |
624 range->accept (*this); | |
625 | |
626 subplot_list *plot_list = cmd.subplots (); | |
627 | |
628 if (plot_list) | |
629 plot_list->accept (*this); | |
630 } | |
631 | |
632 void | |
633 tree_print_code::visit_plot_limits (plot_limits& cmd) | |
634 { | |
635 plot_range *x_range = cmd.x_limits (); | |
636 | |
637 if (x_range) | |
638 x_range->accept (*this); | |
639 | |
640 plot_range *y_range = cmd.y_limits (); | |
641 | |
642 if (y_range) | |
643 y_range->accept (*this); | |
644 | |
645 plot_range *z_range = cmd.z_limits (); | |
646 | |
647 if (z_range) | |
648 z_range->accept (*this); | |
649 } | |
650 | |
651 void | |
652 tree_print_code::visit_plot_range (plot_range& cmd) | |
653 { | |
654 os << " ["; | |
655 | |
656 tree_expression *lower = cmd.lower_bound (); | |
657 | |
658 if (lower) | |
659 lower->accept (*this); | |
660 | |
661 os << ":"; | |
662 | |
663 tree_expression *upper = cmd.upper_bound (); | |
664 | |
665 if (upper) | |
666 upper->accept (*this); | |
667 | |
668 os << "]"; | |
669 } | |
670 | |
671 void | |
672 tree_print_code::visit_postfix_expression (tree_postfix_expression& expr) | |
500 { | 673 { |
501 indent (); | 674 indent (); |
502 | 675 |
503 print_parens (expr, "("); | 676 print_parens (expr, "("); |
504 | 677 |
505 tree_return_list *lhs = expr.left_hand_side (); | 678 tree_expression *e = expr.operand (); |
506 | 679 |
507 if (lhs) | 680 if (e) |
508 { | 681 e->accept (*this); |
509 int len = lhs->length (); | 682 |
510 | 683 os << expr.oper (); |
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 | 684 |
527 print_parens (expr, ")"); | 685 print_parens (expr, ")"); |
528 } | 686 } |
529 | 687 |
530 void | 688 void |
531 tree_print_code::visit_no_op_command (tree_no_op_command& cmd) | 689 tree_print_code::visit_prefix_expression (tree_prefix_expression& expr) |
532 { | 690 { |
533 indent (); | 691 indent (); |
534 | 692 |
535 os << cmd.original_command (); | 693 print_parens (expr, "("); |
536 } | 694 |
537 | 695 os << expr.oper (); |
538 void | 696 |
539 tree_print_code::visit_oct_obj (tree_oct_obj&) | 697 tree_expression *e = expr.operand (); |
540 { | 698 |
541 ::error ("visit_oct_obj: internal error"); | 699 if (e) |
542 } | 700 e->accept (*this); |
543 | 701 |
544 void | 702 print_parens (expr, ")"); |
545 tree_print_code::visit_constant (tree_constant& val) | 703 } |
546 { | 704 |
547 indent (); | 705 void |
548 | 706 tree_print_code::visit_return_command (tree_return_command&) |
549 print_parens (val, "("); | 707 { |
550 | 708 indent (); |
551 val.print_raw (os, true, print_original_text); | 709 |
552 | 710 os << "return"; |
553 print_parens (val, ")"); | 711 } |
554 } | 712 |
555 | 713 void |
556 void | 714 tree_print_code::visit_return_list (tree_return_list& lst) |
557 tree_print_code::visit_parameter_list (tree_parameter_list& lst) | |
558 { | 715 { |
559 Pix p = lst.first (); | 716 Pix p = lst.first (); |
560 | 717 |
561 while (p) | 718 while (p) |
562 { | 719 { |
563 tree_identifier *elt = lst (p); | 720 tree_index_expression *elt = lst (p); |
564 | 721 |
565 lst.next (p); | 722 lst.next (p); |
566 | 723 |
567 if (elt) | 724 if (elt) |
568 { | 725 { |
573 } | 730 } |
574 } | 731 } |
575 } | 732 } |
576 | 733 |
577 void | 734 void |
578 tree_print_code::visit_plot_command (tree_plot_command& cmd) | 735 tree_print_code::visit_simple_assignment (tree_simple_assignment& expr) |
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 { | 736 { |
656 indent (); | 737 indent (); |
657 | 738 |
658 print_parens (expr, "("); | 739 print_parens (expr, "("); |
659 | 740 |
660 tree_expression *e = expr.operand (); | 741 tree_expression *lhs = expr.left_hand_side (); |
661 | 742 |
662 if (e) | 743 if (lhs) |
663 e->accept (*this); | 744 lhs->accept (*this); |
664 | 745 |
665 os << expr.oper (); | 746 os << " " << expr.oper () << " "; |
666 | |
667 print_parens (expr, ")"); | |
668 } | |
669 | |
670 void | |
671 tree_print_code::visit_prefix_expression (tree_prefix_expression& expr) | |
672 { | |
673 indent (); | |
674 | |
675 print_parens (expr, "("); | |
676 | |
677 os << expr.oper (); | |
678 | |
679 tree_expression *e = expr.operand (); | |
680 | |
681 if (e) | |
682 e->accept (*this); | |
683 | |
684 print_parens (expr, ")"); | |
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 | |
722 print_parens (expr, "("); | |
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 | |
740 os << " " << expr.oper () << " "; | |
741 } | |
742 | 747 |
743 tree_expression *rhs = expr.right_hand_side (); | 748 tree_expression *rhs = expr.right_hand_side (); |
744 | 749 |
745 if (rhs) | 750 if (rhs) |
746 rhs->accept (*this); | 751 rhs->accept (*this); |