GNU Octave  6.2.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
pt.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (C) 1996-2021 The Octave Project Developers
4 //
5 // See the file COPYRIGHT.md in the top-level directory of this
6 // distribution or <https://octave.org/copyright/>.
7 //
8 // This file is part of Octave.
9 //
10 // Octave is free software: you can redistribute it and/or modify it
11 // under the terms of the GNU General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // Octave is distributed in the hope that it will be useful, but
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU General Public License for more details.
19 //
20 // You should have received a copy of the GNU General Public License
21 // along with Octave; see the file COPYING. If not, see
22 // <https://www.gnu.org/licenses/>.
23 //
24 ////////////////////////////////////////////////////////////////////////
25 
26 #if defined (HAVE_CONFIG_H)
27 # include "config.h"
28 #endif
29 
30 #include <sstream>
31 #include <string>
32 
33 #include "interpreter.h"
34 #include "ov-fcn.h"
35 #include "pt.h"
36 #include "pt-eval.h"
37 #include "pt-pr-code.h"
38 #include "unwind-prot.h"
39 
40 namespace octave
41 {
42  // Hide the details of the string buffer so that we are less likely to
43  // create a memory leak.
44 
45  std::string
47  {
48  std::ostringstream buf;
49 
50  tree_print_code tpc (buf);
51 
52  accept (tpc);
53 
54  std::string retval = buf.str ();
55 
56  return retval;
57  }
58 
59  // Is the current breakpoint condition met?
60 
61  bool
63  {
64  bool retval;
65  if (m_bp_cond == nullptr)
66  retval = false;
67  else if (m_bp_cond->empty ()) // empty condition always met
68  retval = true;
69  else
70  {
71  int parse_status = 0;
72 
73  unwind_protect frame;
74 
75  interpreter_try (frame);
76 
77  retval = true; // default to stopping if any error
78  try
79  {
81  = tw.eval_string (*m_bp_cond, 1, parse_status, 1);
82 
83  if (parse_status == 0)
84  {
85  if (! val(0).is_scalar_type ())
86  warning ("Breakpoint condition must be a scalar, not size %s",
87  val(0).dims ().str ('x').c_str ());
88  else
89  retval = val(0).bool_value ();
90  }
91  else
92  warning ("Error parsing breakpoint condition");
93  }
94  catch (const execution_exception& e)
95  {
96  interpreter& interp = tw.get_interpreter ();
97 
98  interp.recover_from_exception ();
99 
100  std::string tmp = e.message ();
101 
102  warning ("Error evaluating breakpoint condition:\n %s",
103  tmp.c_str ());
104  }
105  }
106 
107  return retval;
108  }
109 }
void recover_from_exception(void)
octave_value_list eval_string(const std::string &eval_str, bool silent, int &parse_status, int nargout)
Definition: pt-eval.cc:468
interpreter & get_interpreter(void)
Definition: pt-eval.h:370
std::string * m_bp_cond
Definition: pt.h:123
std::string str_print_code(void)
Definition: pt.cc:46
bool meets_bp_condition(tree_evaluator &tw) const
Definition: pt.cc:62
virtual void accept(tree_walker &tw)=0
void warning(const char *fmt,...)
Definition: error.cc:1050
void interpreter_try(octave::unwind_protect &frame)
Definition: error.cc:2182
octave_value::octave_value(const Array< char > &chm, char type) return retval
Definition: ov.cc:811