GNU Octave  9.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
pt.h
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (C) 1996-2024 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 (octave_pt_h)
27 #define octave_pt_h 1
28 
29 #include "octave-config.h"
30 
31 #include <string>
32 
33 #include <iosfwd>
34 
35 class octave_function;
36 
38 
39 class tree_evaluator;
40 class tree_walker;
41 
42 // Base class for the parse tree.
43 
44 class tree
45 {
46 public:
47 
48  tree (int l = -1, int c = -1)
49  : m_line_num (l), m_column_num (c), m_bp_cond (nullptr)
50  { }
51 
52  OCTAVE_DISABLE_COPY_MOVE (tree)
53 
54  virtual ~tree () = default;
55 
56  virtual int line () const { return m_line_num; }
57 
58  virtual int column () const { return m_column_num; }
59 
60  void line (int l) { m_line_num = l; }
61 
62  void column (int c) { m_column_num = c; }
63 
64  void set_location (int l, int c)
65  {
66  m_line_num = l;
67  m_column_num = c;
68  }
69 
70  virtual void set_breakpoint (const std::string& condition)
71  {
72  if (m_bp_cond)
73  *m_bp_cond = condition;
74  else
75  m_bp_cond = new std::string (condition);
76  }
77 
78  virtual void delete_breakpoint ()
79  {
80  delete m_bp_cond;
81 
82  m_bp_cond = nullptr;
83  }
84 
85  bool meets_bp_condition (tree_evaluator& tw) const;
86 
87  bool is_breakpoint () const
88  {
89  return m_bp_cond;
90  }
91 
93  {
94  return m_bp_cond && meets_bp_condition (tw);
95  }
96 
97  // breakpoint condition, or "0" (i.e., "false") if no breakpoint.
98  // To distinguish "0" from a disabled breakpoint, test "is_breakpoint" too.
99  const std::string bp_cond () const
100  {
101  return m_bp_cond ? *m_bp_cond : "0";
102  }
103 
104  std::string str_print_code ();
105 
106  virtual void accept (tree_walker& tw) = 0;
107 
108 private:
109 
110  // The input line and column where we found the text that was
111  // eventually converted to this tree node.
112  int m_line_num;
113  int m_column_num;
114 
115  // NULL if no breakpoint, or a breakpoint condition if there is one.
116  std::string *m_bp_cond;
117 };
118 
119 OCTAVE_END_NAMESPACE(octave)
120 
121 #endif
Definition: pt.h:45
bool is_breakpoint() const
Definition: pt.h:87
void column(int c)
Definition: pt.h:62
bool meets_bp_condition(tree_evaluator &tw) const
Definition: pt.cc:62
virtual void delete_breakpoint()
Definition: pt.h:78
void line(int l)
Definition: pt.h:60
std::string str_print_code()
Definition: pt.cc:46
const std::string bp_cond() const
Definition: pt.h:99
bool is_active_breakpoint(tree_evaluator &tw) const
Definition: pt.h:92
virtual void accept(tree_walker &tw)=0
virtual int column() const
Definition: pt.h:58
void set_location(int l, int c)
Definition: pt.h:64
virtual void set_breakpoint(const std::string &condition)
Definition: pt.h:70
tree(int l=-1, int c=-1)
Definition: pt.h:48
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn