1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302
|
////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 1996-2021 The Octave Project Developers
//
// See the file COPYRIGHT.md in the top-level directory of this
// distribution or <https://octave.org/copyright/>.
//
// This file is part of Octave.
//
// Octave is free software: you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Octave is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Octave; see the file COPYING. If not, see
// <https://www.gnu.org/licenses/>.
//
////////////////////////////////////////////////////////////////////////
#if defined (HAVE_CONFIG_H)
# include "config.h"
#endif
#include <typeinfo>
#include "quit.h"
#include "bp-table.h"
#include "comment-list.h"
#include "event-manager.h"
#include "input.h"
#include "oct-lvalue.h"
#include "ov.h"
#include "pager.h"
#include "pt-bp.h"
#include "pt-cmd.h"
#include "pt-eval.h"
#include "pt-id.h"
#include "pt-idx.h"
#include "pt-jump.h"
#include "pt-pr-code.h"
#include "pt-stmt.h"
#include "utils.h"
#include "variables.h"
namespace octave
{
// A list of commands to be executed.
tree_statement::~tree_statement (void)
{
delete m_command;
delete m_expression;
delete m_comment_list;
}
void
tree_statement::set_print_flag (bool print_flag)
{
if (m_expression)
m_expression->set_print_flag (print_flag);
}
bool
tree_statement::print_result (void)
{
return m_expression && m_expression->print_result ();
}
void
tree_statement::set_breakpoint (const std::string& condition)
{
if (m_command)
m_command->set_breakpoint (condition);
else if (m_expression)
m_expression->set_breakpoint (condition);
}
void
tree_statement::delete_breakpoint (void)
{
if (m_command)
m_command->delete_breakpoint ();
else if (m_expression)
m_expression->delete_breakpoint ();
}
bool
tree_statement::is_breakpoint (void) const
{
return m_command ? m_command->is_breakpoint ()
: (m_expression ? m_expression->is_breakpoint () : false);
}
bool
tree_statement::is_active_breakpoint (tree_evaluator& tw) const
{
return m_command ? m_command->is_active_breakpoint (tw)
: (m_expression ? m_expression->is_active_breakpoint (tw) : false);
}
std::string
tree_statement::bp_cond () const
{
return (m_command
? m_command->bp_cond ()
: (m_expression ? m_expression->bp_cond () : "0"));
}
int
tree_statement::line (void) const
{
return (m_command
? m_command->line ()
: (m_expression ? m_expression->line () : -1));
}
int
tree_statement::column (void) const
{
return (m_command
? m_command->column ()
: (m_expression ? m_expression->column () : -1));
}
void
tree_statement::set_location (int l, int c)
{
if (m_command)
m_command->set_location (l, c);
else if (m_expression)
m_expression->set_location (l, c);
}
void
tree_statement::echo_code (const std::string& prefix)
{
tree_print_code tpc (octave_stdout, prefix);
accept (tpc);
}
bool
tree_statement::is_end_of_fcn_or_script (void) const
{
bool retval = false;
if (m_command)
{
tree_no_op_command *no_op_cmd
= dynamic_cast<tree_no_op_command *> (m_command);
if (no_op_cmd)
retval = no_op_cmd->is_end_of_fcn_or_script ();
}
return retval;
}
bool
tree_statement::is_end_of_file (void) const
{
bool retval = false;
if (m_command)
{
tree_no_op_command *no_op_cmd
= dynamic_cast<tree_no_op_command *> (m_command);
if (no_op_cmd)
retval = no_op_cmd->is_end_of_file ();
}
return retval;
}
// Create a "breakpoint" tree-walker, and get it to "walk" this
// statement list
// (FIXME: What does that do???)
int
tree_statement_list::set_breakpoint (int line, const std::string& condition)
{
tree_breakpoint tbp (line, tree_breakpoint::set, condition);
accept (tbp);
return tbp.get_line ();
}
void
tree_statement_list::delete_breakpoint (int line)
{
if (line < 0)
{
octave_value_list bp_lst = list_breakpoints ();
int len = bp_lst.length ();
for (int i = 0; i < len; i++)
{
tree_breakpoint tbp (i, tree_breakpoint::clear);
accept (tbp);
}
}
else
{
tree_breakpoint tbp (line, tree_breakpoint::clear);
accept (tbp);
}
}
octave_value_list
tree_statement_list::list_breakpoints (void)
{
tree_breakpoint tbp (0, tree_breakpoint::list);
accept (tbp);
return tbp.get_list ();
}
// Get list of pairs (breakpoint line, breakpoint condition)
std::list<bp_type>
tree_statement_list::breakpoints_and_conds (void)
{
tree_breakpoint tbp (0, tree_breakpoint::list);
accept (tbp);
std::list<bp_type> retval;
octave_value_list lines = tbp.get_list ();
octave_value_list conds = tbp.get_cond_list ();
for (int i = 0; i < lines.length (); i++)
{
retval.push_back (bp_type (lines(i).double_value (),
conds(i).string_value ()));
}
return retval;
}
// Add breakpoints to file at multiple lines (the second arguments
// of line), to stop only if condition is true.
// Updates GUI via event_manager::update_breakpoint.
// FIXME: COME BACK TO ME.
bp_table::intmap
tree_statement_list::add_breakpoint (event_manager& evmgr,
const std::string& file,
const bp_table::intmap& line,
const std::string& condition)
{
bp_table::intmap retval;
octave_idx_type len = line.size ();
for (int i = 0; i < len; i++)
{
bp_table::const_intmap_iterator p = line.find (i);
if (p != line.end ())
{
int lineno = p->second;
retval[i] = set_breakpoint (lineno, condition);
if (retval[i] != 0 && ! file.empty ())
evmgr.update_breakpoint (true, file, retval[i], condition);
}
}
return retval;
}
bp_table::intmap
tree_statement_list::remove_all_breakpoints (event_manager& evmgr,
const std::string& file)
{
bp_table::intmap retval;
octave_value_list bkpts = list_breakpoints ();
for (int i = 0; i < bkpts.length (); i++)
{
int lineno = static_cast<int> (bkpts(i).int_value ());
delete_breakpoint (lineno);
retval[i] = lineno;
if (! file.empty ())
evmgr.update_breakpoint (false, file, lineno);
}
return retval;
}
}
|