GNU Octave  9.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
pt-stmt.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_stmt_h)
27 #define octave_pt_stmt_h 1
28 
29 #include "octave-config.h"
30 
31 class octave_value_list;
32 
33 #include <deque>
34 
35 #include "base-list.h"
36 #include "bp-table.h"
37 #include "pt.h"
38 #include "pt-walk.h"
39 
40 class event_manager;
41 
43 
44 class comment_list;
45 class tree_command;
46 class tree_evaluator;
47 class tree_expression;
48 
49 // A statement is either a command to execute or an expression to
50 // evaluate.
51 
52 class tree_statement : public tree
53 {
54 public:
55 
57  : m_command (nullptr), m_expression (nullptr),
58  m_comment_list (nullptr) { }
59 
61  : m_command (c), m_expression (nullptr), m_comment_list (cl) { }
62 
64  : m_command (nullptr), m_expression (e), m_comment_list (cl) { }
65 
66  OCTAVE_DISABLE_COPY_MOVE (tree_statement)
67 
68  ~tree_statement ();
69 
70  void set_print_flag (bool print_flag);
71 
72  bool print_result ();
73 
74  bool is_command () const { return m_command != nullptr; }
75 
76  bool is_expression () const { return m_expression != nullptr; }
77 
78  void set_breakpoint (const std::string& condition);
79 
80  void delete_breakpoint ();
81 
82  bool is_breakpoint () const;
83 
84  bool is_active_breakpoint (tree_evaluator& tw) const;
85 
86  std::string bp_cond () const;
87 
88  int line () const;
89  int column () const;
90 
91  void set_location (int l, int c);
92 
93  void echo_code (const std::string& prefix);
94 
95  tree_command * command () { return m_command; }
96 
97  tree_expression * expression () { return m_expression; }
98 
99  comment_list * comment_text () { return m_comment_list; }
100 
101  bool is_null_statement () const
102  {
103  return ! (m_command || m_expression || m_comment_list);
104  }
105 
106  bool is_end_of_fcn_or_script () const;
107 
108  bool is_end_of_file () const;
109 
110  // Allow modification of this statement. Note that there is no
111  // checking. If you use these, are you sure you know what you are
112  // doing?
113 
114  void set_command (tree_command *c) { m_command = c; }
115 
116  void set_expression (tree_expression *e) { m_expression = e; }
117 
118  void accept (tree_walker& tw)
119  {
120  tw.visit_statement (*this);
121  }
122 
123 private:
124 
125  // Only one of cmd or expr can be valid at once.
126 
127  // Command to execute.
128  tree_command *m_command;
129 
130  // Expression to evaluate.
131  tree_expression *m_expression;
132 
133  // Comment associated with this statement.
134  comment_list *m_comment_list;
135 };
136 
137 // A list of statements to evaluate.
138 
139 class tree_statement_list : public base_list<tree_statement *>
140 {
141 public:
142 
144  : m_function_body (false), m_anon_function_body (false),
145  m_script_body (false) { }
146 
148  : m_function_body (false), m_anon_function_body (false),
149  m_script_body (false) { append (s); }
150 
151  OCTAVE_DISABLE_COPY_MOVE (tree_statement_list)
152 
154  {
155  while (! empty ())
156  {
157  auto p = begin ();
158  delete *p;
159  erase (p);
160  }
161  }
162 
163  void mark_as_function_body () { m_function_body = true; }
164 
165  void mark_as_anon_function_body () { m_anon_function_body = true; }
166 
167  void mark_as_script_body () { m_script_body = true; }
168 
169  bool is_function_body () const { return m_function_body; }
170 
171  bool is_anon_function_body () const { return m_anon_function_body; }
172 
173  bool is_script_body () const { return m_script_body; }
174 
175  int set_breakpoint (int line, const std::string& condition);
176 
177  void delete_breakpoint (int line);
178 
180 
181  std::list<bp_type> breakpoints_and_conds ();
182 
184  const std::string& file,
185  const bp_table::bp_lines& lines,
186  const std::string& condition);
187 
189  const std::string& file);
190 
191  void accept (tree_walker& tw)
192  {
193  tw.visit_statement_list (*this);
194  }
195 
196 private:
197 
198  // Does this list of statements make up the body of a function?
199  bool m_function_body;
200 
201  // Does this list of statements make up the body of a function?
202  bool m_anon_function_body;
203 
204  // Does this list of statements make up the body of a script?
205  bool m_script_body;
206 };
207 
208 OCTAVE_END_NAMESPACE(octave)
209 
210 #endif
void append(const tree_statement * &s)
Definition: base-list.h:92
iterator erase(iterator pos)
Definition: base-list.h:55
std::set< int > bp_lines
Definition: bp-table.h:70
Provides threadsafe access to octave.
void accept(tree_walker &tw)
Definition: pt-stmt.h:191
bool is_function_body() const
Definition: pt-stmt.h:169
octave_value_list list_breakpoints()
Definition: pt-stmt.cc:221
void mark_as_anon_function_body()
Definition: pt-stmt.h:165
std::list< bp_type > breakpoints_and_conds()
Definition: pt-stmt.cc:231
int set_breakpoint(int line, const std::string &condition)
Definition: pt-stmt.cc:190
bool is_script_body() const
Definition: pt-stmt.h:173
void delete_breakpoint(int line)
Definition: pt-stmt.cc:199
void mark_as_script_body()
Definition: pt-stmt.h:167
bp_table::bp_lines remove_all_breakpoints(event_manager &evmgr, const std::string &file)
Definition: pt-stmt.cc:279
tree_statement_list(tree_statement *s)
Definition: pt-stmt.h:147
bool is_anon_function_body() const
Definition: pt-stmt.h:171
bp_table::bp_lines add_breakpoint(event_manager &evmgr, const std::string &file, const bp_table::bp_lines &lines, const std::string &condition)
Definition: pt-stmt.cc:255
void mark_as_function_body()
Definition: pt-stmt.h:163
tree_statement()
Definition: pt-stmt.h:56
std::string bp_cond() const
Definition: pt-stmt.cc:111
bool is_active_breakpoint(tree_evaluator &tw) const
Definition: pt-stmt.cc:103
void echo_code(const std::string &prefix)
Definition: pt-stmt.cc:144
tree_command * command()
Definition: pt-stmt.h:95
int column() const
Definition: pt-stmt.cc:127
bool is_command() const
Definition: pt-stmt.h:74
void set_print_flag(bool print_flag)
Definition: pt-stmt.cc:64
void set_location(int l, int c)
Definition: pt-stmt.cc:135
comment_list * comment_text()
Definition: pt-stmt.h:99
bool is_end_of_file() const
Definition: pt-stmt.cc:169
bool is_expression() const
Definition: pt-stmt.h:76
void set_expression(tree_expression *e)
Definition: pt-stmt.h:116
bool is_null_statement() const
Definition: pt-stmt.h:101
void delete_breakpoint()
Definition: pt-stmt.cc:86
tree_expression * expression()
Definition: pt-stmt.h:97
void set_breakpoint(const std::string &condition)
Definition: pt-stmt.cc:77
bool print_result()
Definition: pt-stmt.cc:71
bool is_breakpoint() const
Definition: pt-stmt.cc:95
tree_statement(tree_command *c, comment_list *cl)
Definition: pt-stmt.h:60
tree_statement(tree_expression *e, comment_list *cl)
Definition: pt-stmt.h:63
void accept(tree_walker &tw)
Definition: pt-stmt.h:118
int line() const
Definition: pt-stmt.cc:119
void set_command(tree_command *c)
Definition: pt-stmt.h:114
bool is_end_of_fcn_or_script() const
Definition: pt-stmt.cc:152
virtual void visit_statement(tree_statement &)
Definition: pt-walk.cc:567
virtual void visit_statement_list(tree_statement_list &)
Definition: pt-walk.cc:583
Definition: pt.h:45
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn