GNU Octave 7.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-2022 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
35class octave_function;
36
37namespace octave
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 // No copying!
53
54 tree (const tree&) = delete;
55
56 tree& operator = (const tree&) = delete;
57
58 virtual ~tree (void) = default;
59
60 virtual int line (void) const { return m_line_num; }
61
62 virtual int column (void) const { return m_column_num; }
63
64 void line (int l) { m_line_num = l; }
65
66 void column (int c) { m_column_num = c; }
67
68 void set_location (int l, int c)
69 {
70 m_line_num = l;
71 m_column_num = c;
72 }
73
74 virtual void set_breakpoint (const std::string& condition)
75 {
76 if (m_bp_cond)
77 *m_bp_cond = condition;
78 else
79 m_bp_cond = new std::string (condition);
80 }
81
82 virtual void delete_breakpoint (void)
83 {
84 if (m_bp_cond)
85 {
86 delete m_bp_cond;
87
88 m_bp_cond = nullptr;
89 }
90 }
91
92 bool meets_bp_condition (tree_evaluator& tw) const;
93
94 bool is_breakpoint (void) const
95 {
96 return m_bp_cond;
97 }
98
100 {
101 return m_bp_cond && meets_bp_condition (tw);
102 }
103
104 // breakpoint condition, or "0" (i.e., "false") if no breakpoint.
105 // To distinguish "0" from a disabled breakpoint, test "is_breakpoint" too.
106 const std::string bp_cond (void) const
107 {
108 return m_bp_cond ? *m_bp_cond : "0";
109 }
110
111 std::string str_print_code (void);
112
113 virtual void accept (tree_walker& tw) = 0;
114
115 private:
116
117 // The input line and column where we found the text that was
118 // eventually converted to this tree node.
121
122 // NULL if no breakpoint, or a breakpoint condition if there is one.
123 std::string *m_bp_cond;
124 };
125}
126
127#endif
void column(int c)
Definition: pt.h:66
void line(int l)
Definition: pt.h:64
virtual ~tree(void)=default
virtual int column(void) const
Definition: pt.h:62
int m_line_num
Definition: pt.h:119
std::string * m_bp_cond
Definition: pt.h:123
std::string str_print_code(void)
Definition: pt.cc:46
int m_column_num
Definition: pt.h:120
tree & operator=(const tree &)=delete
void set_location(int l, int c)
Definition: pt.h:68
virtual void delete_breakpoint(void)
Definition: pt.h:82
bool is_active_breakpoint(tree_evaluator &tw) const
Definition: pt.h:99
const std::string bp_cond(void) const
Definition: pt.h:106
tree(const tree &)=delete
bool meets_bp_condition(tree_evaluator &tw) const
Definition: pt.cc:62
virtual void accept(tree_walker &tw)=0
virtual int line(void) const
Definition: pt.h:60
tree(int l=-1, int c=-1)
Definition: pt.h:48
virtual void set_breakpoint(const std::string &condition)
Definition: pt.h:74
bool is_breakpoint(void) const
Definition: pt.h:94