GNU Octave  4.0.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
pt-eval.cc
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 2009-2015 John W. Eaton
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 3 of the License, or (at your
10 option) any 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, see
19 <http://www.gnu.org/licenses/>.
20 
21 */
22 
23 #ifdef HAVE_CONFIG_H
24 #include <config.h>
25 #endif
26 
27 #include <cctype>
28 
29 #include <iostream>
30 
31 #include <fstream>
32 #include <typeinfo>
33 
34 #include "debug.h"
35 #include "defun.h"
36 #include "error.h"
37 #include "gripes.h"
38 #include "input.h"
39 #include "ov-fcn-handle.h"
40 #include "ov-usr-fcn.h"
41 #include "variables.h"
42 #include "pt-all.h"
43 #include "pt-eval.h"
44 #include "symtab.h"
45 #include "unwind-prot.h"
46 
47 //FIXME: This should be part of tree_evaluator
48 #include "pt-jit.h"
49 
51 
53 
55 
57 
58 bool tree_evaluator::debug_mode = false;
59 
61 
64 
66 
67 // Maximum nesting level for functions, scripts, or sourced files called
68 // recursively.
70 
71 // If TRUE, turn off printing of results in functions (as if a
72 // semicolon has been appended to each statement).
73 static bool Vsilent_functions = false;
74 
75 // Normal evaluator.
76 
77 void
79 {
81 }
82 
83 void
85 {
87 }
88 
89 void
91 {
93 }
94 
95 void
97 {
98  if (! error_state)
99  {
100  if (debug_mode)
101  do_breakpoint (cmd.is_breakpoint ());
102 
103  if (statement_context == function || statement_context == script
104  || in_loop_command)
106  }
107 }
108 
109 void
111 {
112  panic_impossible ();
113 }
114 
115 void
117 {
118  if (! error_state)
119  {
120  if (debug_mode)
121  do_breakpoint (cmd.is_breakpoint ());
122 
123  if (statement_context == function || statement_context == script
124  || in_loop_command)
126  }
127 }
128 
129 void
131 {
133 
134  dbstep_flag = 0;
135 }
136 
137 bool
139 {
140  return ! (Vsilent_functions && (statement_context == function
141  || statement_context == script));
142 }
143 
144 static inline void
146 {
147  tree_identifier *id = elt.ident ();
148 
149  if (id)
150  {
151  id->mark_global ();
152 
153  if (! error_state)
154  {
155  octave_lvalue ult = id->lvalue ();
156 
157  if (ult.is_undefined ())
158  {
159  tree_expression *expr = elt.expression ();
160 
161  octave_value init_val;
162 
163  if (expr)
164  init_val = expr->rvalue1 ();
165  else
166  init_val = Matrix ();
167 
168  ult.assign (octave_value::op_asn_eq, init_val);
169  }
170  }
171  }
172 }
173 
174 static inline void
176 {
177  tree_identifier *id = elt.ident ();
178 
179  if (id)
180  {
181  id->mark_as_static ();
182 
183  octave_lvalue ult = id->lvalue ();
184 
185  if (ult.is_undefined ())
186  {
187  tree_expression *expr = elt.expression ();
188 
189  octave_value init_val;
190 
191  if (expr)
192  init_val = expr->rvalue1 ();
193  else
194  init_val = Matrix ();
195 
196  ult.assign (octave_value::op_asn_eq, init_val);
197  }
198  }
199 }
200 
201 void
202 tree_evaluator::do_decl_init_list (decl_elt_init_fcn fcn,
203  tree_decl_init_list *init_list)
204 {
205  if (init_list)
206  {
207  for (tree_decl_init_list::iterator p = init_list->begin ();
208  p != init_list->end (); p++)
209  {
210  tree_decl_elt *elt = *p;
211 
212  fcn (*elt);
213 
214  if (error_state)
215  break;
216  }
217  }
218 }
219 
220 void
222 {
223  if (debug_mode)
224  do_breakpoint (cmd.is_breakpoint ());
225 
227 }
228 
229 void
231 {
232  if (debug_mode)
233  do_breakpoint (cmd.is_breakpoint ());
234 
236 }
237 
238 void
240 {
241  panic_impossible ();
242 }
243 
244 #if 0
245 bool
246 tree_decl_elt::eval (void)
247 {
248  bool retval = false;
249 
250  if (id && expr)
251  {
252  octave_lvalue ult = id->lvalue ();
253 
254  octave_value init_val = expr->rvalue1 ();
255 
256  if (! error_state)
257  {
258  ult.assign (octave_value::op_asn_eq, init_val);
259 
260  retval = true;
261  }
262  }
263 
264  return retval;
265 }
266 #endif
267 
268 void
270 {
271  panic_impossible ();
272 }
273 
274 // Decide if it's time to quit a for or while loop.
275 static inline bool
277 {
278  octave_quit ();
279 
280  // Maybe handle 'continue N' someday...
281 
284 
285  bool quit = (error_state
289 
292 
293  return quit;
294 }
295 
296 void
298 {
299  if (error_state)
300  return;
301 
302  if (debug_mode)
303  do_breakpoint (cmd.is_breakpoint ());
304 
305  // FIXME: need to handle PARFOR loops here using cmd.in_parallel ()
306  // and cmd.maxproc_expr ();
307 
308  unwind_protect frame;
309 
311 
312  in_loop_command = true;
313 
314  tree_expression *expr = cmd.control_expr ();
315 
316  octave_value rhs = expr->rvalue1 ();
317 
318 #if HAVE_LLVM
319  if (tree_jit::execute (cmd, rhs))
320  return;
321 #endif
322 
323  if (error_state || rhs.is_undefined ())
324  return;
325 
326  {
327  tree_expression *lhs = cmd.left_hand_side ();
328 
329  octave_lvalue ult = lhs->lvalue ();
330 
331  if (error_state)
332  return;
333 
334  tree_statement_list *loop_body = cmd.body ();
335 
336  if (rhs.is_range ())
337  {
338  Range rng = rhs.range_value ();
339 
340  octave_idx_type steps = rng.nelem ();
341 
342  for (octave_idx_type i = 0; i < steps; i++)
343  {
344  octave_value val (rng.elem (i));
345 
346  ult.assign (octave_value::op_asn_eq, val);
347 
348  if (! error_state && loop_body)
349  loop_body->accept (*this);
350 
351  if (quit_loop_now ())
352  break;
353  }
354  }
355  else if (rhs.is_scalar_type ())
356  {
357  ult.assign (octave_value::op_asn_eq, rhs);
358 
359  if (! error_state && loop_body)
360  loop_body->accept (*this);
361 
362  // Maybe decrement break and continue states.
363  quit_loop_now ();
364  }
365  else if (rhs.is_matrix_type () || rhs.is_cell () || rhs.is_string ()
366  || rhs.is_map ())
367  {
368  // A matrix or cell is reshaped to 2 dimensions and iterated by
369  // columns.
370 
371  dim_vector dv = rhs.dims ().redim (2);
372 
373  octave_idx_type nrows = dv(0);
374  octave_idx_type steps = dv(1);
375 
376  if (steps > 0)
377  {
378  octave_value arg = rhs;
379  if (rhs.ndims () > 2)
380  arg = arg.reshape (dv);
381 
382  // for row vectors, use single index to speed things up.
383  octave_value_list idx;
384  octave_idx_type iidx;
385  if (nrows == 1)
386  {
387  idx.resize (1);
388  iidx = 0;
389  }
390  else
391  {
392  idx.resize (2);
394  iidx = 1;
395  }
396 
397  for (octave_idx_type i = 1; i <= steps; i++)
398  {
399  // do_index_op expects one-based indices.
400  idx(iidx) = i;
401  octave_value val = arg.do_index_op (idx);
402 
403  ult.assign (octave_value::op_asn_eq, val);
404 
405  if (! error_state && loop_body)
406  loop_body->accept (*this);
407 
408  if (quit_loop_now ())
409  break;
410  }
411  }
412  }
413  else
414  {
415  ::error ("invalid type in for loop expression near line %d, column %d",
416  cmd.line (), cmd.column ());
417  }
418  }
419 }
420 
421 void
423 {
424  if (error_state)
425  return;
426 
427  if (debug_mode)
428  do_breakpoint (cmd.is_breakpoint ());
429 
430  unwind_protect frame;
431 
433 
434  in_loop_command = true;
435 
436  tree_expression *expr = cmd.control_expr ();
437 
438  octave_value rhs = expr->rvalue1 ();
439 
440  if (error_state || rhs.is_undefined ())
441  return;
442 
443  if (rhs.is_map ())
444  {
445  // Cycle through structure elements. First element of id_list
446  // is set to value and the second is set to the name of the
447  // structure element.
448 
449  tree_argument_list *lhs = cmd.left_hand_side ();
450 
452 
453  tree_expression *elt = *p++;
454 
455  octave_lvalue val_ref = elt->lvalue ();
456 
457  elt = *p;
458 
459  octave_lvalue key_ref = elt->lvalue ();
460 
461  const octave_map tmp_val = rhs.map_value ();
462 
463  tree_statement_list *loop_body = cmd.body ();
464 
465  string_vector keys = tmp_val.keys ();
466 
467  octave_idx_type nel = keys.numel ();
468 
469  for (octave_idx_type i = 0; i < nel; i++)
470  {
471  std::string key = keys[i];
472 
473  const Cell val_lst = tmp_val.contents (key);
474 
475  octave_idx_type n = val_lst.numel ();
476 
477  octave_value val = (n == 1) ? val_lst(0) : octave_value (val_lst);
478 
479  val_ref.assign (octave_value::op_asn_eq, val);
480  key_ref.assign (octave_value::op_asn_eq, key);
481 
482  if (! error_state && loop_body)
483  loop_body->accept (*this);
484 
485  if (quit_loop_now ())
486  break;
487  }
488  }
489  else
490  error ("in statement 'for [X, Y] = VAL', VAL must be a structure");
491 }
492 
493 void
495 {
496  panic_impossible ();
497 }
498 
499 void
501 {
502  panic_impossible ();
503 }
504 
505 void
507 {
508  panic_impossible ();
509 }
510 
511 void
513 {
514  panic_impossible ();
515 }
516 
517 void
519 {
520  octave_value fcn = cmd.function ();
521 
522  octave_function *f = fcn.function_value ();
523 
524  if (f)
525  {
526  std::string nm = f->name ();
527 
529 
530  // Make sure that any variable with the same name as the new
531  // function is cleared.
532 
534  }
535 }
536 
537 void
539 {
540  panic_impossible ();
541 }
542 
543 void
545 {
546  panic_impossible ();
547 }
548 
549 void
551 {
552  tree_if_command_list *lst = cmd.cmd_list ();
553 
554  if (lst)
555  lst->accept (*this);
556 }
557 
558 void
560 {
561  for (tree_if_command_list::iterator p = lst.begin (); p != lst.end (); p++)
562  {
563  tree_if_clause *tic = *p;
564 
565  tree_expression *expr = tic->condition ();
566 
567  if (statement_context == function || statement_context == script)
568  octave_call_stack::set_location (tic->line (), tic->column ());
569 
570  if (debug_mode && ! tic->is_else_clause ())
571  do_breakpoint (tic->is_breakpoint ());
572 
573  if (tic->is_else_clause () || expr->is_logically_true ("if"))
574  {
575  if (! error_state)
576  {
577  tree_statement_list *stmt_lst = tic->commands ();
578 
579  if (stmt_lst)
580  stmt_lst->accept (*this);
581  }
582 
583  break;
584  }
585  }
586 }
587 
588 void
590 {
591  panic_impossible ();
592 }
593 
594 void
596 {
597  panic_impossible ();
598 }
599 
600 void
602 {
603  panic_impossible ();
604 }
605 
606 void
608 {
609  panic_impossible ();
610 }
611 
612 void
614 {
615  if (debug_mode && cmd.is_end_of_fcn_or_script ())
616  do_breakpoint (cmd.is_breakpoint (), true);
617 }
618 
619 void
621 {
622  panic_impossible ();
623 }
624 
625 void
627 {
628  panic_impossible ();
629 }
630 
631 void
633 {
634  panic_impossible ();
635 }
636 
637 void
639 {
640  panic_impossible ();
641 }
642 
643 void
645 {
646  panic_impossible ();
647 }
648 
649 void
651 {
652  panic_impossible ();
653 }
654 
655 void
657 {
658  if (! error_state)
659  {
660  if (debug_mode)
661  do_breakpoint (cmd.is_breakpoint ());
662 
663  // Act like dbcont.
664 
665  if (Vdebugging
667  {
668  Vdebugging = false;
669 
671  }
672  else if (statement_context == function || statement_context == script
673  || in_loop_command)
675  }
676 }
677 
678 void
680 {
681  panic_impossible ();
682 }
683 
684 void
686 {
687  panic_impossible ();
688 }
689 
690 void
692 {
693  tree_command *cmd = stmt.command ();
694  tree_expression *expr = stmt.expression ();
695 
696  if (cmd || expr)
697  {
698  if (statement_context == function || statement_context == script)
699  {
700  // Skip commands issued at a debug> prompt to avoid disturbing
701  // the state of the program we are debugging.
702 
703  if (! Vdebugging)
704  octave_call_stack::set_location (stmt.line (), stmt.column ());
705 
706  if ((statement_context == script
710  || (statement_context == function
712  stmt.echo_code ();
713  }
714 
715  try
716  {
717  if (cmd)
718  cmd->accept (*this);
719  else
720  {
721  if (debug_mode)
722  do_breakpoint (expr->is_breakpoint ());
723 
724  // FIXME: maybe all of this should be packaged in
725  // one virtual function that returns a flag saying whether
726  // or not the expression will take care of binding ans and
727  // printing the result.
728 
729  // FIXME: it seems that we should just have to
730  // call expr->rvalue1 () and that should take care of
731  // everything, binding ans as necessary?
732 
733  bool do_bind_ans = false;
734 
735  if (expr->is_identifier ())
736  {
737  tree_identifier *id = dynamic_cast<tree_identifier *> (expr);
738 
739  do_bind_ans = (! id->is_variable ());
740  }
741  else
742  do_bind_ans = (! expr->is_assignment_expression ());
743 
744  octave_value tmp_result = expr->rvalue1 (0);
745 
746  if (do_bind_ans && ! (error_state || tmp_result.is_undefined ()))
747  bind_ans (tmp_result, expr->print_result ()
749 
750  // if (tmp_result.is_defined ())
751  // result_values(0) = tmp_result;
752  }
753  }
754  catch (octave_execution_exception)
755  {
757  }
758  catch (std::bad_alloc)
759  {
760  // FIXME: We want to use error_with_id here so that we set
761  // the error state, give users control over this error
762  // message, and so that we set the error_state appropriately
763  // so we'll get stack trace info when appropriate. But
764  // error_with_id will require some memory allocations. Is
765  // there anything we can do to make those more likely to
766  // succeed?
767 
768  error_with_id ("Octave:bad-alloc",
769  "out of memory or dimension too large for Octave's index type");
770  }
771  }
772 }
773 
774 void
776 {
777  static octave_value_list empty_list;
778 
779  if (error_state)
780  return;
781 
783 
784  if (p != lst.end ())
785  {
786  while (true)
787  {
788  tree_statement *elt = *p++;
789 
790  if (elt)
791  {
792  octave_quit ();
793 
794  elt->accept (*this);
795 
796  if (error_state)
797  break;
798 
801  break;
802 
804  break;
805 
806  if (p == lst.end ())
807  break;
808  else
809  {
810  // Clear previous values before next statement is
811  // evaluated so that we aren't holding an extra
812  // reference to a value that may be used next. For
813  // example, in code like this:
814  //
815  // X = rand (N); # refcount for X should be 1
816  // # after this statement
817  //
818  // X(idx) = val; # no extra copy of X should be
819  // # needed, but we will be faked
820  // # out if retval is not cleared
821  // # between statements here
822 
823  // result_values = empty_list;
824  }
825  }
826  else
827  error ("invalid statement found in statement list!");
828  }
829  }
830 }
831 
832 void
834 {
835  panic_impossible ();
836 }
837 
838 void
840 {
841  panic_impossible ();
842 }
843 
844 void
846 {
847  if (debug_mode)
848  do_breakpoint (cmd.is_breakpoint ());
849 
850  tree_expression *expr = cmd.switch_value ();
851 
852  if (expr)
853  {
854  octave_value val = expr->rvalue1 ();
855 
856  tree_switch_case_list *lst = cmd.case_list ();
857 
858  if (! error_state && lst)
859  {
860  for (tree_switch_case_list::iterator p = lst->begin ();
861  p != lst->end (); p++)
862  {
863  tree_switch_case *t = *p;
864 
865  if (t->is_default_case () || t->label_matches (val))
866  {
867  if (error_state)
868  break;
869 
870  tree_statement_list *stmt_lst = t->commands ();
871 
872  if (stmt_lst)
873  stmt_lst->accept (*this);
874 
875  break;
876  }
877  }
878  }
879  }
880  else
881  ::error ("missing value in switch command near line %d, column %d",
882  cmd.line (), cmd.column ());
883 }
884 
885 void
887 {
888  unwind_protect frame;
889 
893 
895  Vdebug_on_error = false;
896  Vdebug_on_warning = false;
897 
898  tree_statement_list *catch_code = cmd.cleanup ();
899 
900  // The catch code is *not* added to unwind_protect stack; it doesn't need
901  // to be run on interrupts.
902 
903  tree_statement_list *try_code = cmd.body ();
904 
905  if (try_code)
906  {
907  try_code->accept (*this);
908  }
909 
910  if (error_state)
911  {
912  error_state = 0;
913 
914  if (catch_code)
915  {
916  // Set up for letting the user print any messages from errors that
917  // occurred in the body of the try_catch statement.
918 
920 
921  tree_identifier *expr_id = cmd.identifier ();
922  octave_lvalue ult;
923 
924  if (expr_id)
925  {
926 
927  octave_scalar_map err;
928 
929  ult = expr_id->lvalue ();
930 
931  if (error_state)
932  return;
933 
934  err.assign ("message", last_error_message ());
935  err.assign ("identifier", last_error_id ());
936  err.assign ("stack", last_error_stack ());
937 
938  if (! error_state)
939  ult.assign (octave_value::op_asn_eq, err);
940 
941  }
942 
943  if (catch_code)
944  catch_code->accept (*this);
945  }
946  }
947 }
948 
949 void
951 {
952  unwind_protect frame;
953 
956 
957  // We want to run the cleanup code without error_state being set,
958  // but we need to restore its value, so that any errors encountered
959  // in the first part of the unwind_protect are not completely
960  // ignored.
961 
962  frame.protect_var (error_state);
963  error_state = 0;
964 
965  // We want to preserve the last location info for possible
966  // backtracking.
971 
972  // Similarly, if we have seen a return or break statement, allow all
973  // the cleanup code to run before returning or handling the break.
974  // We don't have to worry about continue statements because they can
975  // only occur in loops.
976 
979 
982 
983  if (list)
984  list->accept (*this);
985 
986  // The unwind_protects are popped off the stack in the reverse of
987  // the order they are pushed on.
988 
989  // FIXME: these statements say that if we see a break or
990  // return statement in the cleanup block, that we want to use the
991  // new value of the breaking or returning flag instead of restoring
992  // the previous value. Is that the right thing to do? I think so.
993  // Consider the case of
994  //
995  // function foo ()
996  // unwind_protect
997  // stderr << "1: this should always be executed\n";
998  // break;
999  // stderr << "1: this should never be executed\n";
1000  // unwind_protect_cleanup
1001  // stderr << "2: this should always be executed\n";
1002  // return;
1003  // stderr << "2: this should never be executed\n";
1004  // end_unwind_protect
1005  // endfunction
1006  //
1007  // If we reset the value of the breaking flag, both the returning
1008  // flag and the breaking flag will be set, and we shouldn't have
1009  // both. So, use the most recent one. If there is no return or
1010  // break in the cleanup block, the values should be reset to
1011  // whatever they were when the cleanup block was entered.
1012 
1014  {
1015  frame.discard (2);
1016  }
1017  else
1018  {
1019  frame.run (2);
1020  }
1021 
1022  // We don't want to ignore errors that occur in the cleanup code, so
1023  // if an error is encountered there, leave error_state alone.
1024  // Otherwise, set it back to what it was before.
1025 
1026  if (error_state)
1027  frame.discard (2);
1028  else
1029  frame.run (2);
1030 
1031  frame.run ();
1032 }
1033 
1034 void
1036 {
1037  tree_statement_list *cleanup_code = cmd.cleanup ();
1038 
1039  tree_statement_list *unwind_protect_code = cmd.body ();
1040 
1041  if (unwind_protect_code)
1042  {
1043  try
1044  {
1045  unwind_protect_code->accept (*this);
1046  }
1047  catch (...)
1048  {
1049  // Run the cleanup code on exceptions, so that it is run even in case
1050  // of interrupt or out-of-memory.
1051  do_unwind_protect_cleanup_code (cleanup_code);
1052  // FIXME: should error_state be checked here?
1053  // We want to rethrow the exception, even if error_state is set, so
1054  // that interrupts continue.
1055  throw;
1056  }
1057 
1058  do_unwind_protect_cleanup_code (cleanup_code);
1059  }
1060 }
1061 
1062 void
1064 {
1065  if (error_state)
1066  return;
1067 
1068 #if HAVE_LLVM
1069  if (tree_jit::execute (cmd))
1070  return;
1071 #endif
1072 
1073  unwind_protect frame;
1074 
1075  frame.protect_var (in_loop_command);
1076 
1077  in_loop_command = true;
1078 
1079  tree_expression *expr = cmd.condition ();
1080 
1081  if (! expr)
1082  panic_impossible ();
1083 
1084  for (;;)
1085  {
1086  if (debug_mode)
1087  do_breakpoint (cmd.is_breakpoint ());
1088 
1089  if (expr->is_logically_true ("while"))
1090  {
1091  tree_statement_list *loop_body = cmd.body ();
1092 
1093  if (loop_body)
1094  {
1095  loop_body->accept (*this);
1096 
1097  if (error_state)
1098  return;
1099  }
1100 
1101  if (quit_loop_now ())
1102  break;
1103  }
1104  else
1105  break;
1106  }
1107 }
1108 
1109 void
1111 {
1112  if (error_state)
1113  return;
1114 
1115 #if HAVE_LLVM
1116  if (tree_jit::execute (cmd))
1117  return;
1118 #endif
1119 
1120  unwind_protect frame;
1121 
1122  frame.protect_var (in_loop_command);
1123 
1124  in_loop_command = true;
1125 
1126  tree_expression *expr = cmd.condition ();
1127 
1128  if (! expr)
1129  panic_impossible ();
1130 
1131  for (;;)
1132  {
1133  tree_statement_list *loop_body = cmd.body ();
1134 
1135  if (loop_body)
1136  {
1137  loop_body->accept (*this);
1138 
1139  if (error_state)
1140  return;
1141  }
1142 
1143  if (quit_loop_now ())
1144  break;
1145 
1146  if (debug_mode)
1147  do_breakpoint (cmd.is_breakpoint ());
1148 
1149  if (expr->is_logically_true ("do-until"))
1150  break;
1151  }
1152 }
1153 
1154 void
1156 {
1158 }
1159 
1160 void
1161 tree_evaluator::do_breakpoint (bool is_breakpoint,
1162  bool is_end_of_fcn_or_script) const
1163 {
1164  bool break_on_this_statement = false;
1165 
1167  {
1168  break_on_this_statement = true;
1169 
1171 
1173  }
1174  else if (is_breakpoint)
1175  {
1176  break_on_this_statement = true;
1177 
1178  dbstep_flag = 0;
1179 
1181  }
1182  else if (dbstep_flag > 0)
1183  {
1185  {
1186  if (dbstep_flag == 1 || is_end_of_fcn_or_script)
1187  {
1188  // We get here if we are doing a "dbstep" or a "dbstep N" and the
1189  // count has reached 1 so that we must stop and return to debug
1190  // prompt. Alternatively, "dbstep N" has been used but the end
1191  // of the frame has been reached so we stop at the last line and
1192  // return to prompt.
1193 
1194  break_on_this_statement = true;
1195 
1196  dbstep_flag = 0;
1197  }
1198  else
1199  {
1200  // Executing "dbstep N". Decrease N by one and continue.
1201 
1202  dbstep_flag--;
1203  }
1204 
1205  }
1206  else if (dbstep_flag == 1
1208  {
1209  // We stepped out from the end of a function.
1210 
1212 
1213  break_on_this_statement = true;
1214 
1215  dbstep_flag = 0;
1216  }
1217  }
1218  else if (dbstep_flag == -1)
1219  {
1220  // We get here if we are doing a "dbstep in".
1221 
1222  break_on_this_statement = true;
1223 
1224  dbstep_flag = 0;
1225 
1227  }
1228  else if (dbstep_flag == -2)
1229  {
1230  // We get here if we are doing a "dbstep out". Check for end of
1231  // function and whether the current frame is the same as the
1232  // cached value because we want to step out from the frame where
1233  // "dbstep out" was evaluated, not from any functions called from
1234  // that frame.
1235 
1236  if (is_end_of_fcn_or_script
1238  dbstep_flag = -1;
1239  }
1240 
1241  if (break_on_this_statement)
1242  do_keyboard ();
1243 
1244 }
1245 
1246 // ARGS is currently unused, but since the do_keyboard function in
1247 // input.cc accepts an argument list, we preserve it here so that the
1248 // interface won't have to change if we decide to use it in the future.
1249 
1252 {
1253  return ::do_keyboard (args);
1254 }
1255 
1256 DEFUN (max_recursion_depth, args, nargout,
1257  "-*- texinfo -*-\n\
1258 @deftypefn {Built-in Function} {@var{val} =} max_recursion_depth ()\n\
1259 @deftypefnx {Built-in Function} {@var{old_val} =} max_recursion_depth (@var{new_val})\n\
1260 @deftypefnx {Built-in Function} {} max_recursion_depth (@var{new_val}, \"local\")\n\
1261 Query or set the internal limit on the number of times a function may\n\
1262 be called recursively.\n\
1263 \n\
1264 If the limit is exceeded, an error message is printed and control returns to\n\
1265 the top level.\n\
1266 \n\
1267 When called from inside a function with the @qcode{\"local\"} option, the\n\
1268 variable is changed locally for the function and any subroutines it calls.\n\
1269 The original variable value is restored when exiting the function.\n\
1270 @end deftypefn")
1271 {
1272  return SET_INTERNAL_VARIABLE (max_recursion_depth);
1273 }
1274 
1275 /*
1276 %!test
1277 %! orig_val = max_recursion_depth ();
1278 %! old_val = max_recursion_depth (2*orig_val);
1279 %! assert (orig_val, old_val);
1280 %! assert (max_recursion_depth (), 2*orig_val);
1281 %! max_recursion_depth (orig_val);
1282 %! assert (max_recursion_depth (), orig_val);
1283 
1284 %!error (max_recursion_depth (1, 2))
1285 */
1286 
1287 DEFUN (silent_functions, args, nargout,
1288  "-*- texinfo -*-\n\
1289 @deftypefn {Built-in Function} {@var{val} =} silent_functions ()\n\
1290 @deftypefnx {Built-in Function} {@var{old_val} =} silent_functions (@var{new_val})\n\
1291 @deftypefnx {Built-in Function} {} silent_functions (@var{new_val}, \"local\")\n\
1292 Query or set the internal variable that controls whether internal\n\
1293 output from a function is suppressed.\n\
1294 \n\
1295 If this option is disabled, Octave will display the results produced by\n\
1296 evaluating expressions within a function body that are not terminated with\n\
1297 a semicolon.\n\
1298 \n\
1299 When called from inside a function with the @qcode{\"local\"} option, the\n\
1300 variable is changed locally for the function and any subroutines it calls.\n\
1301 The original variable value is restored when exiting the function.\n\
1302 @end deftypefn")
1303 {
1304  return SET_INTERNAL_VARIABLE (silent_functions);
1305 }
1306 
1307 /*
1308 %!test
1309 %! orig_val = silent_functions ();
1310 %! old_val = silent_functions (! orig_val);
1311 %! assert (orig_val, old_val);
1312 %! assert (silent_functions (), ! orig_val);
1313 %! silent_functions (orig_val);
1314 %! assert (silent_functions (), orig_val);
1315 
1316 %!error (silent_functions (1, 2))
1317 */
octave_lvalue lvalue(void)
Definition: pt-id.cc:130
bool Vdebug_on_error
Definition: error.cc:58
string_vector keys(void) const
Definition: oct-map.h:339
void visit_colon_expression(tree_colon_expression &)
Definition: pt-eval.cc:110
tree_identifier * identifier(void)
Definition: pt-except.h:57
void visit_simple_for_command(tree_simple_for_command &)
Definition: pt-eval.cc:297
const Cell & contents(const_iterator p) const
Definition: oct-map.h:314
bool is_range(void) const
Definition: ov.h:571
void discard(size_t num)
Definition: Cell.h:35
void mark_global(void)
Definition: pt-id.h:94
void visit_cell(tree_cell &)
Definition: pt-eval.cc:601
void visit_funcall(tree_funcall &)
Definition: pt-eval.cc:632
bool Vdebug_on_warning
Definition: error.cc:62
void visit_parameter_list(tree_parameter_list &)
Definition: pt-eval.cc:638
static bool debug_mode
Definition: pt-eval.h:152
tree_statement_list * cleanup(void)
Definition: pt-except.h:125
int ndims(void) const
Definition: ov.h:479
octave_value reshape(const dim_vector &dv) const
Definition: ov.h:498
static bool statement_printing_enabled(void)
Definition: pt-eval.cc:138
bool label_matches(const octave_value &val)
Definition: pt-select.cc:122
static tree_evaluator std_evaluator
Definition: pt-eval.cc:50
void do_decl_init_list(decl_elt_init_fcn fcn, tree_decl_init_list *init_list)
Definition: pt-eval.cc:202
tree_expression * switch_value(void)
Definition: pt-select.h:268
void visit_switch_case_list(tree_switch_case_list &)
Definition: pt-eval.cc:839
void visit_decl_init_list(tree_decl_init_list &)
Definition: pt-eval.cc:269
tree_expression * control_expr(void)
Definition: pt-loop.h:291
octave_idx_type numel(void) const
Number of elements in the array.
Definition: Array.h:275
static bool all_scripts(void)
Definition: toplev.h:227
static int continuing
Definition: pt-jump.h:76
void visit_simple_assignment(tree_simple_assignment &)
Definition: pt-eval.cc:685
void visit_multi_assignment(tree_multi_assignment &)
Definition: pt-eval.cc:607
void accept(tree_walker &tw)
Definition: pt-stmt.cc:289
octave_idx_type nelem(void) const
Definition: Range.h:64
static bool have_breakpoints(void)
Definition: debug.h:102
octave_map map_value(void) const
Definition: ov.cc:1585
void visit_break_command(tree_break_command &)
Definition: pt-eval.cc:96
bool is_scalar_type(void) const
Definition: ov.h:657
void visit_postfix_expression(tree_postfix_expression &)
Definition: pt-eval.cc:644
bool is_default_case(void)
Definition: pt-select.h:185
static bool execute(tree_simple_for_command &cmd, const octave_value &bounds)
Definition: pt-jit.cc:2027
tree_command * command(void)
Definition: pt-stmt.h:81
void run(size_t num)
Definition: Range.h:31
void protect_var(T &var)
bool is_end_of_fcn_or_script(void) const
Definition: pt-cmd.h:77
#define DEFUN(name, args_name, nargout_name, doc)
Definition: defun.h:44
void echo_code(void)
Definition: pt-stmt.cc:119
void error(const char *fmt,...)
Definition: error.cc:476
std::string name(void) const
Definition: ov-fcn.h:161
#define SET_INTERNAL_VARIABLE(NM)
Definition: variables.h:120
tree_switch_case_list * case_list(void)
Definition: pt-select.h:270
static stmt_list_type statement_context
Definition: pt-eval.h:165
void visit_statement(tree_statement &)
Definition: pt-eval.cc:691
bool is_cell(void) const
Definition: ov.h:529
void gripe_library_execution_error(void)
Definition: gripes.cc:208
tree_statement_list * commands(void)
Definition: pt-select.h:61
virtual octave_value do_keyboard(const octave_value_list &args=octave_value_list()) const
Definition: pt-eval.cc:1251
void bind_ans(const octave_value &val, bool print)
Definition: variables.cc:1980
void do_unwind_protect_cleanup_code(tree_statement_list *list)
Definition: pt-eval.cc:950
static void set_location(int l, int c)
Definition: toplev.h:249
tree_expression * expr
Definition: pt-decl.h:102
void visit_function_def(tree_function_def &)
Definition: pt-eval.cc:518
static bool quiet_breakpoint_flag
Definition: pt-eval.h:154
tree_argument_list * left_hand_side(void)
Definition: pt-loop.h:289
void visit_octave_user_function_trailer(octave_user_function &)
Definition: pt-eval.cc:512
void visit_argument_list(tree_argument_list &)
Definition: pt-eval.cc:84
tree_identifier * ident(void)
Definition: pt-decl.h:85
void visit_no_op_command(tree_no_op_command &)
Definition: pt-eval.cc:613
tree_decl_init_list * initializer_list(void)
Definition: pt-decl.h:160
tree_statement_list * body(void)
Definition: pt-loop.h:293
tree_if_command_list * cmd_list(void)
Definition: pt-select.h:135
tree_statement_list * body(void)
Definition: pt-loop.h:212
void visit_constant(tree_constant &)
Definition: pt-eval.cc:620
static int breaking
Definition: pt-jump.h:48
std::list< tree_decl_elt * >::iterator iterator
Definition: base-list.h:36
static int current_line(void)
Definition: toplev.h:152
static int dbstep_flag
Definition: pt-eval.h:147
void visit_while_command(tree_while_command &)
Definition: pt-eval.cc:1063
iterator end(void)
Definition: base-list.h:81
int buffer_error_messages
Definition: error.cc:115
void mark_as_static(void)
Definition: pt-id.h:96
bool print_result(void) const
Definition: pt-exp.h:97
static void do_global_init(tree_decl_elt &elt)
Definition: pt-eval.cc:145
void visit_if_clause(tree_if_clause &)
Definition: pt-eval.cc:544
tree_expression * condition(void)
Definition: pt-select.h:59
F77_RET_T const double const double * f
void add_fcn(void(*fcn)(void))
static size_t current_frame(void)
Definition: toplev.h:181
void visit_global_command(tree_global_command &)
Definition: pt-eval.cc:221
tree_expression * control_expr(void)
Definition: pt-loop.h:208
void visit_decl_elt(tree_decl_elt &)
Definition: pt-eval.cc:239
void error_with_id(const char *id, const char *fmt,...)
Definition: error.cc:506
void accept(tree_walker &tw)
Definition: pt-stmt.cc:176
octave_map last_error_stack(void)
Definition: error.cc:2143
Range range_value(void) const
Definition: ov.h:903
bool is_matrix_type(void) const
Definition: ov.h:660
bool is_string(void) const
Definition: ov.h:562
int error_state
Definition: error.cc:101
void visit_fcn_handle(tree_fcn_handle &)
Definition: pt-eval.cc:626
void visit_if_command(tree_if_command &)
Definition: pt-eval.cc:550
octave_value function(void)
Definition: pt-cmd.h:116
double elem(octave_idx_type i) const
Definition: Range.cc:105
tree_statement_list * body(void)
Definition: pt-except.h:123
static void install_cmdline_function(const std::string &name, const octave_value &fcn)
Definition: symtab.h:1551
#define panic_impossible()
Definition: error.h:33
void visit_do_until_command(tree_do_until_command &)
Definition: pt-eval.cc:1110
tree_expression * left_hand_side(void)
Definition: pt-loop.h:206
sig_atomic_t octave_interrupt_state
Definition: cquit.c:80
static void reset_debug_state(void)
Definition: pt-eval.cc:130
static void assign(const std::string &name, const octave_value &value=octave_value(), scope_id scope=xcurrent_scope, context_id context=xdefault_context, bool force_add=false)
Definition: symtab.h:1335
dim_vector redim(int n) const
Definition: dim-vector.cc:266
tree_statement_list * body(void)
Definition: pt-except.h:59
void visit_return_command(tree_return_command &)
Definition: pt-eval.cc:656
static bool quit_loop_now(void)
Definition: pt-eval.cc:276
bool is_breakpoint(void) const
Definition: pt.h:63
Definition: dMatrix.h:35
tree_statement_list * commands(void)
Definition: pt-select.h:191
void visit_octave_user_function(octave_user_function &)
Definition: pt-eval.cc:500
static void set_column(int c)
Definition: toplev.h:261
tree_statement_list * cleanup(void)
Definition: pt-except.h:61
void visit_octave_user_function_header(octave_user_function &)
Definition: pt-eval.cc:506
tree_evaluator * current_evaluator
Definition: pt-eval.cc:52
dim_vector dims(void) const
Definition: ov.h:470
virtual int line(void) const
Definition: pt.h:45
iterator begin(void)
Definition: base-list.h:78
double arg(double x)
Definition: lo-mappers.h:37
octave_function * function_value(bool silent=false) const
Definition: ov.cc:1597
int line(void) const
Definition: pt-stmt.cc:98
bool is_map(void) const
Definition: ov.h:574
bool is_end_of_fcn_or_script(void) const
Definition: pt-stmt.cc:127
virtual octave_value rvalue1(int nargout=1)
Definition: pt-exp.cc:58
int Vecho_executing_commands
Definition: input.cc:94
static int returning
Definition: pt-jump.h:104
void assign(octave_value::assign_op, const octave_value &)
Definition: oct-lvalue.cc:33
void visit_binary_expression(tree_binary_expression &)
Definition: pt-eval.cc:90
static size_t current_frame
Definition: pt-eval.h:150
bool is_else_clause(void)
Definition: pt-select.h:57
static bool Vsilent_functions
Definition: pt-eval.cc:73
static void do_static_init(tree_decl_elt &elt)
Definition: pt-eval.cc:175
int Vmax_recursion_depth
Definition: pt-eval.cc:69
void visit_continue_command(tree_continue_command &)
Definition: pt-eval.cc:116
void assign(const std::string &k, const octave_value &val)
Definition: oct-map.h:225
bool is_breakpoint(void) const
Definition: pt-stmt.cc:92
tree_expression * expression(void)
Definition: pt-stmt.h:83
static int current_column(void)
Definition: toplev.h:158
tree_expression * expression(void)
Definition: pt-decl.h:89
virtual octave_lvalue lvalue(void)
Definition: pt-exp.cc:78
void accept(tree_walker &tw)
Definition: pt-select.cc:81
bool octave_debug_on_interrupt_state
Definition: pt-bp.cc:33
void visit_unwind_protect_command(tree_unwind_protect_command &)
Definition: pt-eval.cc:1035
bool is_undefined(void) const
Definition: ov.h:523
void visit_statement_list(tree_statement_list &)
Definition: pt-eval.cc:775
void resize(octave_idx_type n, const octave_value &rfv=octave_value())
Definition: oct-obj.h:93
virtual bool is_assignment_expression(void) const
Definition: pt-exp.h:63
void visit_index_expression(tree_index_expression &)
Definition: pt-eval.cc:589
std::string last_error_id(void)
Definition: error.cc:2137
static void set_line(int l)
Definition: toplev.h:255
void visit_persistent_command(tree_persistent_command &)
Definition: pt-eval.cc:230
int column(void) const
Definition: pt-stmt.cc:104
static bool in_loop_command
Definition: pt-eval.h:168
void visit_if_command_list(tree_if_command_list &)
Definition: pt-eval.cc:559
bool is_undefined(void) const
Definition: oct-lvalue.h:71
tree_statement_list * body(void)
Definition: pt-loop.h:82
void visit_identifier(tree_identifier &)
Definition: pt-eval.cc:538
void do_breakpoint(tree_statement &stmt) const
Definition: pt-eval.cc:1155
virtual bool is_logically_true(const char *)
Definition: pt-exp.cc:39
void visit_prefix_expression(tree_prefix_expression &)
Definition: pt-eval.cc:650
bool eval(void)
Definition: pt-decl.cc:49
void visit_switch_case(tree_switch_case &)
Definition: pt-eval.cc:833
bool Vdebugging
Definition: input.cc:117
octave_value do_keyboard(const octave_value_list &args)
Definition: input.cc:859
virtual int column(void) const
Definition: pt.h:47
void visit_return_list(tree_return_list &)
Definition: pt-eval.cc:679
void visit_anon_fcn_handle(tree_anon_fcn_handle &)
Definition: pt-eval.cc:78
void visit_complex_for_command(tree_complex_for_command &)
Definition: pt-eval.cc:422
virtual void accept(tree_walker &tw)=0
void visit_matrix(tree_matrix &)
Definition: pt-eval.cc:595
virtual bool is_identifier(void) const
Definition: pt-exp.h:59
void visit_try_catch_command(tree_try_catch_command &)
Definition: pt-eval.cc:886
return octave_value(v1.char_array_value().concat(v2.char_array_value(), ra_idx),((a1.is_sq_string()||a2.is_sq_string())? '\'': '"'))
void visit_switch_command(tree_switch_command &)
Definition: pt-eval.cc:845
std::string last_error_message(void)
Definition: error.cc:2131
tree_expression * condition(void)
Definition: pt-loop.h:80
void visit_octave_user_script(octave_user_script &)
Definition: pt-eval.cc:494
octave_value do_index_op(const octave_value_list &idx, bool resize_ok=false)
Definition: ov.h:438