GNU Octave  4.4.1
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-2018 John W. Eaton
4 
5 This file is part of Octave.
6 
7 Octave is free software: you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
11 
12 Octave is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16 
17 You should have received a copy of the GNU General Public License
18 along with Octave; see the file COPYING. If not, see
19 <https://www.gnu.org/licenses/>.
20 
21 */
22 
23 #if ! defined (octave_pt_stmt_h)
24 #define octave_pt_stmt_h 1
25 
26 #include "octave-config.h"
27 
28 class octave_value_list;
29 
30 #include <deque>
31 
32 #include "base-list.h"
33 #include "bp-table.h"
34 #include "pt.h"
35 #include "pt-walk.h"
36 
37 namespace octave
38 {
39  class comment_list;
40  class tree_command;
41  class tree_expression;
42 
43  // A statement is either a command to execute or an expression to
44  // evaluate.
45 
46  class tree_statement : public tree
47  {
48  public:
49 
51  : m_command (nullptr), m_expression (nullptr),
52  m_comment_list (nullptr) { }
53 
55  : m_command (c), m_expression (nullptr), m_comment_list (cl) { }
56 
58  : m_command (nullptr), m_expression (e), m_comment_list (cl) { }
59 
60  // No copying!
61 
62  tree_statement (const tree_statement&) = delete;
63 
64  tree_statement& operator = (const tree_statement&) = delete;
65 
66  ~tree_statement (void);
67 
68  void set_print_flag (bool print_flag);
69 
70  bool print_result (void);
71 
72  bool is_command (void) const { return m_command != nullptr; }
73 
74  bool is_expression (void) const { return m_expression != nullptr; }
75 
76  void set_breakpoint (const std::string& condition);
77 
78  void delete_breakpoint (void);
79 
80  bool is_breakpoint (bool check_valid = false) const;
81  std::string bp_cond () const;
82 
83  int line (void) const;
84  int column (void) const;
85 
86  void set_location (int l, int c);
87 
88  void echo_code (const std::string& prefix);
89 
90  tree_command * command (void) { return m_command; }
91 
93 
95 
96  bool is_null_statement (void) const
97  {
98  return ! (m_command || m_expression || m_comment_list);
99  }
100 
101  bool is_end_of_fcn_or_script (void) const;
102 
103  bool is_end_of_file (void) const;
104 
105  // Allow modification of this statement. Note that there is no
106  // checking. If you use these, are you sure you knwo what you are
107  // doing?
108 
110 
112 
113  void accept (tree_walker& tw)
114  {
115  tw.visit_statement (*this);
116  }
117 
118  private:
119 
120  // Only one of cmd or expr can be valid at once.
121 
122  // Command to execute.
124 
125  // Expression to evaluate.
127 
128  // Comment associated with this statement.
130  };
131 
132  // A list of statements to evaluate.
133 
134  class tree_statement_list : public base_list<tree_statement *>
135  {
136  public:
137 
140  m_script_body (false) { }
141 
144  m_script_body (false) { append (s); }
145 
146  // No copying!
147 
148  tree_statement_list (const tree_statement_list&) = delete;
149 
151 
153  {
154  while (! empty ())
155  {
156  iterator p = begin ();
157  delete *p;
158  erase (p);
159  }
160  }
161 
162  void mark_as_function_body (void) { m_function_body = true; }
163 
165 
166  void mark_as_script_body (void) { m_script_body = true; }
167 
168  bool is_function_body (void) const { return m_function_body; }
169 
170  bool is_anon_function_body (void) const { return m_anon_function_body; }
171 
172  bool is_script_body (void) const { return m_script_body; }
173 
174  int set_breakpoint (int line, const std::string& condition);
175 
176  void delete_breakpoint (int line);
177 
179 
180  std::list<bp_type> breakpoints_and_conds (void);
181 
183  const bp_table::intmap& line,
184  const std::string& condition);
185 
187 
188  void accept (tree_walker& tw)
189  {
190  tw.visit_statement_list (*this);
191  }
192 
193  private:
194 
195  // Does this list of statements make up the body of a function?
197 
198  // Does this list of statements make up the body of a function?
200 
201  // Does this list of statements make up the body of a script?
203  };
204 }
205 
206 #if defined (OCTAVE_USE_DEPRECATED_FUNCTIONS)
207 
208 OCTAVE_DEPRECATED (4.4, "use 'octave::tree_statement' instead")
209 typedef octave::tree_statement tree_statement;
210 
211 OCTAVE_DEPRECATED (4.4, "use 'octave::tree_statement_list' instead")
212 typedef octave::tree_statement_list tree_statement_list;
213 
214 #endif
215 
216 #endif
virtual void visit_statement(tree_statement &)=0
void set_location(int l, int c)
Definition: pt-stmt.cc:123
void delete_breakpoint(void)
Definition: pt-stmt.cc:83
std::string bp_cond() const
Definition: pt-stmt.cc:99
For example cd octave end example noindent changes the current working directory to file
Definition: dirfns.cc:124
int line(void) const
Definition: pt-stmt.cc:107
void mark_as_script_body(void)
Definition: pt-stmt.h:166
bool is_end_of_fcn_or_script(void) const
Definition: pt-stmt.cc:140
bp_table::intmap remove_all_breakpoints(const std::string &file)
Definition: pt-stmt.cc:270
bool is_end_of_file(void) const
Definition: pt-stmt.cc:157
void echo_code(const std::string &prefix)
Definition: pt-stmt.cc:132
void set_expression(tree_expression *e)
Definition: pt-stmt.h:111
tree_command * m_command
Definition: pt-stmt.h:123
void delete_breakpoint(int line)
Definition: pt-stmt.cc:187
tree_expression * m_expression
Definition: pt-stmt.h:126
bool is_breakpoint(bool check_valid=false) const
Definition: pt-stmt.cc:92
std::list< tree_statement * >::iterator iterator
Definition: base-list.h:40
octave_value_list list_breakpoints(void)
Definition: pt-stmt.cc:209
void mark_as_anon_function_body(void)
Definition: pt-stmt.h:164
iterator erase(iterator pos)
Definition: base-list.h:52
nd example oindent opens the file binary numeric values will be read assuming they are stored in IEEE format with the least significant bit and then converted to the native representation Opening a file that is already open simply opens it again and returns a separate file id It is not an error to open a file several though writing to the same file through several different file ids may produce unexpected results The possible values of text mode reading and writing automatically converts linefeeds to the appropriate line end character for the you may append a you must also open the file in binary mode The parameter conversions are currently only supported for and permissions will be set to and then everything is written in a single operation This is very efficient and improves performance c
Definition: file-io.cc:587
tree_statement(tree_expression *e, comment_list *cl)
Definition: pt-stmt.h:57
s
Definition: file-io.cc:2729
i e
Definition: data.cc:2591
int set_breakpoint(int line, const std::string &condition)
Definition: pt-stmt.cc:178
bool print_result(void)
Definition: pt-stmt.cc:68
std::list< bp_type > breakpoints_and_conds(void)
Definition: pt-stmt.cc:219
tree_statement_list & operator=(const tree_statement_list &)=delete
virtual void visit_statement_list(tree_statement_list &)=0
tree_statement(tree_command *c, comment_list *cl)
Definition: pt-stmt.h:54
comment_list * comment_text(void)
Definition: pt-stmt.h:94
void set_breakpoint(const std::string &condition)
Definition: pt-stmt.cc:74
comment_list * m_comment_list
Definition: pt-stmt.h:129
void accept(tree_walker &tw)
Definition: pt-stmt.h:188
bool is_anon_function_body(void) const
Definition: pt-stmt.h:170
is false
Definition: cellfun.cc:400
bool is_null_statement(void) const
Definition: pt-stmt.h:96
std::map< int, int > intmap
Definition: bp-table.h:60
void mark_as_function_body(void)
Definition: pt-stmt.h:162
tree_command * command(void)
Definition: pt-stmt.h:90
void set_command(tree_command *c)
Definition: pt-stmt.h:109
bool is_command(void) const
Definition: pt-stmt.h:72
p
Definition: lu.cc:138
bp_table::intmap add_breakpoint(const std::string &file, const bp_table::intmap &line, const std::string &condition)
Definition: pt-stmt.cc:243
tree_statement & operator=(const tree_statement &)=delete
int column(void) const
Definition: pt-stmt.cc:115
void set_print_flag(bool print_flag)
Definition: pt-stmt.cc:61
void append(const tree_statement * &s)
Definition: base-list.h:110
tree_statement_list(tree_statement *s)
Definition: pt-stmt.h:142
bool is_expression(void) const
Definition: pt-stmt.h:74
void accept(tree_walker &tw)
Definition: pt-stmt.h:113
If this string is the system will ring the terminal sometimes it is useful to be able to print the original representation of the string
Definition: utils.cc:888
bool is_function_body(void) const
Definition: pt-stmt.h:168
bool is_script_body(void) const
Definition: pt-stmt.h:172
tree_expression * expression(void)
Definition: pt-stmt.h:92