comparison src/pt-exp.cc @ 2124:97a566037a75

[project @ 1996-05-12 07:16:36 by jwe]
author jwe
date Sun, 12 May 1996 07:16:36 +0000
parents bfb775fb6fe8
children 6abec42e52f6
comparison
equal deleted inserted replaced
2123:ee55d81f585a 2124:97a566037a75
41 #include "pt-const.h" 41 #include "pt-const.h"
42 #include "pt-exp.h" 42 #include "pt-exp.h"
43 #include "pt-fvc.h" 43 #include "pt-fvc.h"
44 #include "pt-misc.h" 44 #include "pt-misc.h"
45 #include "pt-mvr.h" 45 #include "pt-mvr.h"
46 #include "pt-walk.h"
46 #include "user-prefs.h" 47 #include "user-prefs.h"
47 #include "utils.h" 48 #include "utils.h"
48 49
49 // Nonzero means we're returning from a function. 50 // Nonzero means we're returning from a function.
50 extern int returning; 51 extern int returning;
118 op, line (), column ()); 119 op, line (), column ());
119 } 120 }
120 } 121 }
121 122
122 void 123 void
123 tree_prefix_expression::print_code (ostream& os) 124 tree_prefix_expression::accept (tree_walker& tw)
124 { 125 {
125 print_code_indent (os); 126 tw.visit_prefix_expression (*this);
126
127 if (in_parens)
128 os << "(";
129
130 os << oper ();
131
132 if (id)
133 id->print_code (os);
134
135 if (in_parens)
136 os << ")";
137 } 127 }
138 128
139 // Postfix expressions. 129 // Postfix expressions.
140 130
141 tree_postfix_expression::~tree_postfix_expression (void) 131 tree_postfix_expression::~tree_postfix_expression (void)
197 op, line (), column ()); 187 op, line (), column ());
198 } 188 }
199 } 189 }
200 190
201 void 191 void
202 tree_postfix_expression::print_code (ostream& os) 192 tree_postfix_expression::accept (tree_walker& tw)
203 { 193 {
204 print_code_indent (os); 194 tw.visit_postfix_expression (*this);
205
206 if (in_parens)
207 os << "(";
208
209 if (id)
210 id->print_code (os);
211
212 os << oper ();
213
214 if (in_parens)
215 os << ")";
216 } 195 }
217 196
218 // Unary expressions. 197 // Unary expressions.
219 198
220 octave_value 199 octave_value
297 op, line (), column ()); 276 op, line (), column ());
298 } 277 }
299 } 278 }
300 279
301 void 280 void
302 tree_unary_expression::print_code (ostream& os) 281 tree_unary_expression::accept (tree_walker& tw)
303 { 282 {
304 print_code_indent (os); 283 tw.visit_unary_expression (*this);
305
306 if (in_parens)
307 os << "(";
308
309 switch (etype)
310 {
311 case tree_expression::not:
312 case tree_expression::uminus:
313 os << oper ();
314 if (op)
315 op->print_code (os);
316 break;
317
318 case tree_expression::hermitian:
319 case tree_expression::transpose:
320 if (op)
321 op->print_code (os);
322 os << oper ();
323 break;
324
325 default:
326 os << oper ();
327 if (op)
328 op->print_code (os);
329 break;
330 }
331
332 if (in_parens)
333 os << ")";
334 } 284 }
335 285
336 // Binary expressions. 286 // Binary expressions.
337 287
338 octave_value 288 octave_value
361 case tree_expression::cmp_ge: 311 case tree_expression::cmp_ge:
362 case tree_expression::cmp_gt: 312 case tree_expression::cmp_gt:
363 case tree_expression::cmp_ne: 313 case tree_expression::cmp_ne:
364 case tree_expression::and: 314 case tree_expression::and:
365 case tree_expression::or: 315 case tree_expression::or:
366 if (op1) 316 if (op_lhs)
367 { 317 {
368 octave_value a = op1->eval (false); 318 octave_value a = op_lhs->eval (false);
369 if (error_state) 319 if (error_state)
370 eval_error (); 320 eval_error ();
371 else if (a.is_defined () && op2) 321 else if (a.is_defined () && op_rhs)
372 { 322 {
373 octave_value b = op2->eval (false); 323 octave_value b = op_rhs->eval (false);
374 if (error_state) 324 if (error_state)
375 eval_error (); 325 eval_error ();
376 else if (b.is_defined ()) 326 else if (b.is_defined ())
377 { 327 {
378 retval = do_binary_op (a, b, etype); 328 retval = do_binary_op (a, b, etype);
389 339
390 case tree_expression::and_and: 340 case tree_expression::and_and:
391 case tree_expression::or_or: 341 case tree_expression::or_or:
392 { 342 {
393 bool result = false; 343 bool result = false;
394 if (op1) 344 if (op_lhs)
395 { 345 {
396 octave_value a = op1->eval (false); 346 octave_value a = op_lhs->eval (false);
397 if (error_state) 347 if (error_state)
398 { 348 {
399 eval_error (); 349 eval_error ();
400 break; 350 break;
401 } 351 }
422 result = false; 372 result = false;
423 goto done; 373 goto done;
424 } 374 }
425 } 375 }
426 376
427 if (op2) 377 if (op_rhs)
428 { 378 {
429 octave_value b = op2->eval (false); 379 octave_value b = op_rhs->eval (false);
430 if (error_state) 380 if (error_state)
431 { 381 {
432 eval_error (); 382 eval_error ();
433 break; 383 break;
434 } 384 }
558 op, line (), column ()); 508 op, line (), column ());
559 } 509 }
560 } 510 }
561 511
562 void 512 void
563 tree_binary_expression::print_code (ostream& os) 513 tree_binary_expression::accept (tree_walker& tw)
564 { 514 {
565 print_code_indent (os); 515 tw.visit_binary_expression (*this);
566
567 if (in_parens)
568 os << "(";
569
570 if (op1)
571 op1->print_code (os);
572
573 os << " " << oper () << " ";
574
575 if (op2)
576 op2->print_code (os);
577
578 if (in_parens)
579 os << ")";
580 } 516 }
581 517
582 // Simple assignment expressions. 518 // Simple assignment expressions.
583 519
584 tree_simple_assignment_expression::tree_simple_assignment_expression 520 tree_simple_assignment_expression::tree_simple_assignment_expression
699 l, c); 635 l, c);
700 } 636 }
701 } 637 }
702 638
703 void 639 void
704 tree_simple_assignment_expression::print_code (ostream& os) 640 tree_simple_assignment_expression::accept (tree_walker& tw)
705 { 641 {
706 print_code_indent (os); 642 tw.visit_simple_assignment_expression (*this);
707
708 if (in_parens)
709 os << "(";
710
711 if (! is_ans_assign ())
712 {
713 if (lhs)
714 lhs->print_code (os);
715
716 if (index)
717 {
718 os << " (";
719 index->print_code (os);
720 os << ")";
721 }
722
723 os << " = ";
724 }
725
726 if (rhs)
727 rhs->print_code (os);
728
729 if (in_parens)
730 os << ")";
731 } 643 }
732 644
733 // Colon expressions. 645 // Colon expressions.
734 646
735 bool 647 bool
736 tree_colon_expression::is_range_constant (void) const 648 tree_colon_expression::is_range_constant (void) const
737 { 649 {
738 bool tmp = (op1 && op1->is_constant () 650 bool tmp = (op_base && op_base->is_constant ()
739 && op2 && op2->is_constant ()); 651 && op_limit && op_limit->is_constant ());
740 652
741 return op3 ? (tmp && op3->is_constant ()) : tmp; 653 return op_increment ? (tmp && op_increment->is_constant ()) : tmp;
742 } 654 }
743 655
744 tree_colon_expression * 656 tree_colon_expression *
745 tree_colon_expression::chain (tree_expression *t) 657 tree_colon_expression::chain (tree_expression *t)
746 { 658 {
747 tree_colon_expression *retval = 0; 659 tree_colon_expression *retval = 0;
748 if (! op1 || op3) 660 if (! op_base || op_increment)
749 ::error ("invalid colon expression"); 661 ::error ("invalid colon expression");
750 else 662 else
751 { 663 {
752 op3 = op2; // Stupid syntax. 664 // Stupid syntax:
753 op2 = t; 665 //
666 // base : limit
667 // base : increment : limit
668
669 op_increment = op_limit;
670 op_limit = t;
754 671
755 retval = this; 672 retval = this;
756 } 673 }
757 return retval; 674 return retval;
758 } 675 }
760 octave_value 677 octave_value
761 tree_colon_expression::eval (bool /* print */) 678 tree_colon_expression::eval (bool /* print */)
762 { 679 {
763 octave_value retval; 680 octave_value retval;
764 681
765 if (error_state || ! op1 || ! op2) 682 if (error_state || ! op_base || ! op_limit)
766 return retval; 683 return retval;
767 684
768 octave_value tmp = op1->eval (false); 685 octave_value tmp = op_base->eval (false);
769 686
770 if (tmp.is_undefined ()) 687 if (tmp.is_undefined ())
771 { 688 {
772 eval_error ("invalid null value in colon expression"); 689 eval_error ("invalid null value in colon expression");
773 return retval; 690 return retval;
780 error ("colon expression elements must be scalars"); 697 error ("colon expression elements must be scalars");
781 eval_error ("evaluating colon expression"); 698 eval_error ("evaluating colon expression");
782 return retval; 699 return retval;
783 } 700 }
784 701
785 tmp = op2->eval (false); 702 tmp = op_limit->eval (false);
786 703
787 if (tmp.is_undefined ()) 704 if (tmp.is_undefined ())
788 { 705 {
789 eval_error ("invalid null value in colon expression"); 706 eval_error ("invalid null value in colon expression");
790 return retval; 707 return retval;
798 eval_error ("evaluating colon expression"); 715 eval_error ("evaluating colon expression");
799 return retval; 716 return retval;
800 } 717 }
801 718
802 double inc = 1.0; 719 double inc = 1.0;
803 if (op3) 720
804 { 721 if (op_increment)
805 tmp = op3->eval (false); 722 {
723 tmp = op_increment->eval (false);
806 724
807 if (tmp.is_undefined ()) 725 if (tmp.is_undefined ())
808 { 726 {
809 eval_error ("invalid null value in colon expression"); 727 eval_error ("invalid null value in colon expression");
810 return retval; 728 return retval;
838 if (error_state > 0) 756 if (error_state > 0)
839 ::error ("%s near line %d column %d", s, line (), column ()); 757 ::error ("%s near line %d column %d", s, line (), column ());
840 } 758 }
841 759
842 void 760 void
843 tree_colon_expression::print_code (ostream& os) 761 tree_colon_expression::accept (tree_walker& tw)
844 { 762 {
845 print_code_indent (os); 763 tw.visit_colon_expression (*this);
846 764 }
847 if (in_parens)
848 os << "(";
849
850 if (op1)
851 op1->print_code (os);
852
853 // Stupid syntax.
854
855 if (op3)
856 {
857 os << ":";
858 op3->print_code (os);
859 }
860
861 if (op2)
862 {
863 os << ":";
864 op2->print_code (os);
865 }
866
867 if (in_parens)
868 os << ")";
869 }
870
871 765
872 /* 766 /*
873 ;;; Local Variables: *** 767 ;;; Local Variables: ***
874 ;;; mode: C++ *** 768 ;;; mode: C++ ***
875 ;;; End: *** 769 ;;; End: ***