GNU Octave  6.2.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-2021 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 
42 namespace octave
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  // No copying!
67 
68  tree_statement (const tree_statement&) = delete;
69 
71 
72  ~tree_statement (void);
73 
74  void set_print_flag (bool print_flag);
75 
76  bool print_result (void);
77 
78  bool is_command (void) const { return m_command != nullptr; }
79 
80  bool is_expression (void) const { return m_expression != nullptr; }
81 
82  void set_breakpoint (const std::string& condition);
83 
84  void delete_breakpoint (void);
85 
86  bool is_breakpoint (void) const;
87 
88  bool is_active_breakpoint (tree_evaluator& tw) const;
89 
90  std::string bp_cond () const;
91 
92  int line (void) const;
93  int column (void) const;
94 
95  void set_location (int l, int c);
96 
97  void echo_code (const std::string& prefix);
98 
99  tree_command * command (void) { return m_command; }
100 
102 
104 
105  bool is_null_statement (void) const
106  {
107  return ! (m_command || m_expression || m_comment_list);
108  }
109 
110  bool is_end_of_fcn_or_script (void) const;
111 
112  bool is_end_of_file (void) const;
113 
114  // Allow modification of this statement. Note that there is no
115  // checking. If you use these, are you sure you know what you are
116  // doing?
117 
118  void set_command (tree_command *c) { m_command = c; }
119 
121 
122  void accept (tree_walker& tw)
123  {
124  tw.visit_statement (*this);
125  }
126 
127  private:
128 
129  // Only one of cmd or expr can be valid at once.
130 
131  // Command to execute.
133 
134  // Expression to evaluate.
136 
137  // Comment associated with this statement.
139  };
140 
141  // A list of statements to evaluate.
142 
143  class tree_statement_list : public base_list<tree_statement *>
144  {
145  public:
146 
148  : m_function_body (false), m_anon_function_body (false),
149  m_script_body (false) { }
150 
152  : m_function_body (false), m_anon_function_body (false),
153  m_script_body (false) { append (s); }
154 
155  // No copying!
156 
158 
160 
162  {
163  while (! empty ())
164  {
165  auto p = begin ();
166  delete *p;
167  erase (p);
168  }
169  }
170 
171  void mark_as_function_body (void) { m_function_body = true; }
172 
174 
175  void mark_as_script_body (void) { m_script_body = true; }
176 
177  bool is_function_body (void) const { return m_function_body; }
178 
179  bool is_anon_function_body (void) const { return m_anon_function_body; }
180 
181  bool is_script_body (void) const { return m_script_body; }
182 
183  int set_breakpoint (int line, const std::string& condition);
184 
185  void delete_breakpoint (int line);
186 
188 
189  std::list<bp_type> breakpoints_and_conds (void);
190 
192  const std::string& file,
193  const bp_table::intmap& line,
194  const std::string& condition);
195 
197  const std::string& file);
198 
199  void accept (tree_walker& tw)
200  {
201  tw.visit_statement_list (*this);
202  }
203 
204  private:
205 
206  // Does this list of statements make up the body of a function?
208 
209  // Does this list of statements make up the body of a function?
211 
212  // Does this list of statements make up the body of a script?
214  };
215 }
216 
217 #endif
void append(const tree_statement * &s)
Definition: base-list.h:92
iterator erase(iterator pos)
Definition: base-list.h:55
std::map< int, int > intmap
Definition: bp-table.h:65
Provides threadsafe access to octave.
void accept(tree_walker &tw)
Definition: pt-stmt.h:199
int set_breakpoint(int line, const std::string &condition)
Definition: pt-stmt.cc:188
void delete_breakpoint(int line)
Definition: pt-stmt.cc:197
void mark_as_anon_function_body(void)
Definition: pt-stmt.h:173
void mark_as_script_body(void)
Definition: pt-stmt.h:175
octave_value_list list_breakpoints(void)
Definition: pt-stmt.cc:219
tree_statement_list & operator=(const tree_statement_list &)=delete
bool is_function_body(void) const
Definition: pt-stmt.h:177
tree_statement_list(tree_statement *s)
Definition: pt-stmt.h:151
tree_statement_list(const tree_statement_list &)=delete
bp_table::intmap remove_all_breakpoints(event_manager &evmgr, const std::string &file)
Definition: pt-stmt.cc:281
void mark_as_function_body(void)
Definition: pt-stmt.h:171
std::list< bp_type > breakpoints_and_conds(void)
Definition: pt-stmt.cc:229
bp_table::intmap add_breakpoint(event_manager &evmgr, const std::string &file, const bp_table::intmap &line, const std::string &condition)
Definition: pt-stmt.cc:253
bool is_script_body(void) const
Definition: pt-stmt.h:181
bool is_anon_function_body(void) const
Definition: pt-stmt.h:179
bool is_end_of_fcn_or_script(void) const
Definition: pt-stmt.cc:150
bool is_active_breakpoint(tree_evaluator &tw) const
Definition: pt-stmt.cc:102
int column(void) const
Definition: pt-stmt.cc:125
bool is_command(void) const
Definition: pt-stmt.h:78
int line(void) const
Definition: pt-stmt.cc:117
bool is_expression(void) const
Definition: pt-stmt.h:80
tree_expression * expression(void)
Definition: pt-stmt.h:101
comment_list * comment_text(void)
Definition: pt-stmt.h:103
comment_list * m_comment_list
Definition: pt-stmt.h:138
bool is_end_of_file(void) const
Definition: pt-stmt.cc:167
tree_expression * m_expression
Definition: pt-stmt.h:135
void set_expression(tree_expression *e)
Definition: pt-stmt.h:120
tree_statement(tree_command *c, comment_list *cl)
Definition: pt-stmt.h:60
void accept(tree_walker &tw)
Definition: pt-stmt.h:122
bool print_result(void)
Definition: pt-stmt.cc:71
void set_print_flag(bool print_flag)
Definition: pt-stmt.cc:64
void delete_breakpoint(void)
Definition: pt-stmt.cc:86
tree_statement(tree_expression *e, comment_list *cl)
Definition: pt-stmt.h:63
void echo_code(const std::string &prefix)
Definition: pt-stmt.cc:142
tree_command * m_command
Definition: pt-stmt.h:132
void set_location(int l, int c)
Definition: pt-stmt.cc:133
bool is_breakpoint(void) const
Definition: pt-stmt.cc:95
bool is_null_statement(void) const
Definition: pt-stmt.h:105
void set_command(tree_command *c)
Definition: pt-stmt.h:118
tree_statement(const tree_statement &)=delete
void set_breakpoint(const std::string &condition)
Definition: pt-stmt.cc:77
tree_statement & operator=(const tree_statement &)=delete
std::string bp_cond() const
Definition: pt-stmt.cc:109
tree_command * command(void)
Definition: pt-stmt.h:99
virtual void visit_statement_list(tree_statement_list &)
Definition: pt-walk.cc:450
virtual void visit_statement(tree_statement &)
Definition: pt-walk.cc:435