GNU Octave 10.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 
Loading...
Searching...
No Matches
pt.cc
Go to the documentation of this file.
1////////////////////////////////////////////////////////////////////////
2//
3// Copyright (C) 1996-2025 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 "comment-list.h"
34#include "filepos.h"
35#include "interpreter.h"
36#include "ov-fcn.h"
37#include "pt.h"
38#include "pt-eval.h"
39#include "pt-pr-code.h"
40#include "unwind-prot.h"
41
43
44int
45tree::line () const
46{
47 return beg_pos().line ();
48}
49
50int
52{
53 return beg_pos().column ();
54}
55
58{
59 return comment_list ();
60}
61
62// Hide the details of the string buffer so that we are less likely to
63// create a memory leak.
64
65std::string
67{
68 std::ostringstream buf;
69
70 tree_print_code tpc (buf);
71
72 accept (tpc);
73
74 std::string retval = buf.str ();
75
76 return retval;
77}
78
79// Is the current breakpoint condition met?
80
81bool
83{
84 bool retval;
85 if (m_bp_cond == nullptr)
86 retval = false;
87 else if (m_bp_cond->empty ()) // empty condition always met
88 retval = true;
89 else
90 {
91 int parse_status = 0;
92
93 unwind_protect frame;
94
95 octave::interpreter_try (frame);
96
97 retval = true; // default to stopping if any error
98 try
99 {
101 = tw.eval_string (*m_bp_cond, 1, parse_status, 1);
102
103 if (parse_status == 0)
104 {
105 if (! val(0).is_scalar_type ())
106 warning ("Breakpoint condition must be a scalar, not size %s",
107 val(0).dims ().str ('x').c_str ());
108 else
109 retval = val(0).bool_value ();
110 }
111 else
112 warning ("Error parsing breakpoint condition");
113 }
114 catch (const execution_exception& ee)
115 {
116 interpreter& interp = tw.get_interpreter ();
117
118 interp.recover_from_exception ();
119
120 std::string tmp = ee.message ();
121
122 warning ("Error evaluating breakpoint condition:\n %s",
123 tmp.c_str ());
124 }
125 }
126
127 return retval;
128}
129
130OCTAVE_END_NAMESPACE(octave)
void line(int l)
Definition filepos.h:49
void column(int c)
Definition filepos.h:50
void recover_from_exception()
octave_value_list eval_string(const std::string &eval_str, bool silent, int &parse_status, int nargout)
Definition pt-eval.cc:1028
interpreter & get_interpreter()
Definition pt-eval.h:422
virtual int line() const
Definition pt.cc:45
virtual filepos beg_pos() const =0
bool meets_bp_condition(tree_evaluator &tw) const
Definition pt.cc:82
virtual comment_list leading_comments() const
Definition pt.cc:57
std::string str_print_code()
Definition pt.cc:66
virtual int column() const
Definition pt.cc:51
virtual void accept(tree_walker &tw)=0
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
void warning(const char *fmt,...)
Definition error.cc:1078