GNU Octave  4.4.1
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
pt-decl.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_decl_h)
24 #define octave_pt_decl_h 1
25 
26 #include "octave-config.h"
27 
28 #include <list>
29 #include <string>
30 
31 #include "base-list.h"
32 #include "oct-lvalue.h"
33 #include "pt-cmd.h"
34 #include "pt-id.h"
35 #include "pt-walk.h"
36 #include "symrec.h"
37 
38 namespace octave
39 {
40  class symbol_scope;
41  class tree_evaluator;
42  class tree_expression;
43  class tree_identifier;
44 
45  // List of expressions that make up a declaration statement.
46 
48  {
49  public:
50 
51  enum decl_type
52  {
56  };
57 
58  tree_decl_elt (tree_identifier *i = nullptr, tree_expression *e = nullptr)
59  : type (unknown), m_id (i), m_expr (e) { }
60 
61  // No copying!
62 
63  tree_decl_elt (const tree_decl_elt&) = delete;
64 
65  tree_decl_elt& operator = (const tree_decl_elt&) = delete;
66 
67  ~tree_decl_elt (void);
68 
70  {
71  return m_id ? m_id->is_defined (context) : false;
72  }
73 
75  {
76  return m_id ? m_id->is_variable (context) : false;
77  }
78 
80  {
81  if (m_id)
83  }
84 
85  bool lvalue_ok (void) { return m_id ? m_id->lvalue_ok () : false; }
86 
88  {
89  return m_id ? m_id->lvalue (tw) : octave_lvalue ();
90  }
91 
92  void mark_global (void) { type = global; }
93  bool is_global (void) const { return type == global; }
94 
95  void mark_persistent (void) { type = persistent; }
96  bool is_persistent (void) const { return type == persistent; }
97 
98  tree_identifier * ident (void) { return m_id; }
99 
100  std::string name (void) const { return m_id ? m_id->name () : ""; }
101 
102  tree_expression * expression (void) { return m_expr; }
103 
104  tree_decl_elt * dup (symbol_scope& scope) const;
105 
106  void accept (tree_walker& tw)
107  {
108  tw.visit_decl_elt (*this);
109  }
110 
111  private:
112 
114 
115  // An identifier to tag with the declared property.
117 
118  // An initializer expression (may be zero);
120  };
121 
122  class tree_decl_init_list : public base_list<tree_decl_elt *>
123  {
124  public:
125 
127 
129 
130  // No copying!
131 
132  tree_decl_init_list (const tree_decl_init_list&) = delete;
133 
135 
137  {
138  while (! empty ())
139  {
140  iterator p = begin ();
141  delete *p;
142  erase (p);
143  }
144  }
145 
146  void mark_global (void)
147  {
148  for (tree_decl_elt *elt : *this)
149  elt->mark_global ();
150  }
151 
152  void mark_persistent (void)
153  {
154  for (tree_decl_elt *elt : *this)
155  elt->mark_persistent ();
156  }
157 
158  std::list<std::string> variable_names (void) const
159  {
160  std::list<std::string> retval;
161 
162  for (const tree_decl_elt *elt : *this)
163  {
164  std::string nm = elt->name ();
165 
166  if (! nm.empty ())
167  retval.push_back (nm);
168  }
169 
170  return retval;
171  }
172 
173  void accept (tree_walker& tw)
174  {
175  tw.visit_decl_init_list (*this);
176  }
177  };
178 
179  // Base class for declaration commands -- global, static, etc.
180 
182  {
183  public:
184 
185  tree_decl_command (const std::string& n, int l = -1, int c = -1)
186  : tree_command (l, c), m_cmd_name (n), m_init_list (nullptr) { }
187 
189  int l = -1, int c = -1);
190 
191  // No copying!
192 
193  tree_decl_command (const tree_decl_command&) = delete;
194 
196 
197  ~tree_decl_command (void);
198 
199  void mark_global (void)
200  {
201  if (m_init_list)
203  }
204 
205  void mark_persistent (void)
206  {
207  if (m_init_list)
209  }
210 
212 
213  std::string name (void) const { return m_cmd_name; }
214 
215  void accept (tree_walker& tw)
216  {
217  tw.visit_decl_command (*this);
218  }
219 
220  private:
221 
222  // The name of this command -- global, static, etc.
224 
225  // The list of variables or initializers in this declaration command.
227  };
228 }
229 
230 #if defined (OCTAVE_USE_DEPRECATED_FUNCTIONS)
231 
232 OCTAVE_DEPRECATED (4.4, "use 'octave::tree_decl_elt' instead")
233 typedef octave::tree_decl_elt tree_decl_elt;
234 
235 // tree_decl_init_list is derived from a template.
236 
237 OCTAVE_DEPRECATED (4.4, "use 'octave::tree_decl_command' instead")
238 typedef octave::tree_decl_command tree_decl_command;
239 
240 #endif
241 
242 #endif
virtual bool is_variable(symbol_record::context_id context) const
Definition: pt-id.h:79
bool is_defined(symbol_record::context_id context)
Definition: pt-decl.h:69
tree_decl_init_list & operator=(const tree_decl_init_list &)=delete
octave_lvalue lvalue(tree_evaluator *tw)
Definition: pt-decl.h:87
tree_identifier * m_id
Definition: pt-decl.h:116
bool is_persistent(void) const
Definition: pt-decl.h:96
void mark_persistent(void)
Definition: pt-decl.h:152
void mark_persistent(void)
Definition: pt-decl.h:95
virtual void visit_decl_elt(tree_decl_elt &)=0
bool empty(void) const
Definition: ovl.h:98
octave_lvalue lvalue(tree_evaluator *)
Definition: pt-id.cc:68
tree_decl_init_list * initializer_list(void)
Definition: pt-decl.h:211
std::list< tree_decl_elt * >::iterator iterator
Definition: base-list.h:40
static llvm::LLVMContext & context
Definition: jit-typeinfo.cc:79
iterator erase(iterator pos)
Definition: base-list.h:52
bool is_variable(symbol_record::context_id context)
Definition: pt-decl.h:74
OCTAVE_EXPORT octave_value_list return the number of command line arguments passed to Octave If called with the optional argument the function t
Definition: ov-usr-fcn.cc:997
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
void mark_global(void)
Definition: pt-decl.h:92
tree_decl_elt & operator=(const tree_decl_elt &)=delete
i e
Definition: data.cc:2591
bool is_global(void) const
Definition: pt-decl.h:93
void mark_as_formal_parameter(void)
Definition: pt-decl.h:79
std::string name(void) const
Definition: pt-decl.h:100
void accept(tree_walker &tw)
Definition: pt-decl.h:215
void accept(tree_walker &tw)
Definition: pt-decl.h:173
void mark_persistent(void)
Definition: pt-decl.h:205
OCTAVE_EXPORT octave_value_list isdir nd deftypefn *std::string nm
Definition: utils.cc:975
void mark_as_formal_parameter(void)
Definition: pt-id.h:113
bool lvalue_ok(void)
Definition: pt-decl.h:85
tree_decl_command & operator=(const tree_decl_command &)=delete
octave_value retval
Definition: data.cc:6246
tree_expression * expression(void)
Definition: pt-decl.h:102
virtual void visit_decl_command(tree_decl_command &)=0
void accept(tree_walker &tw)
Definition: pt-decl.h:106
bool lvalue_ok(void) const
Definition: pt-id.h:118
tree_decl_elt * dup(symbol_scope &scope) const
Definition: pt-decl.cc:51
std::list< std::string > variable_names(void) const
Definition: pt-decl.h:158
p
Definition: lu.cc:138
void mark_global(void)
Definition: pt-decl.h:199
std::string name(void) const
Definition: pt-id.h:72
for i
Definition: data.cc:5264
tree_decl_command(const std::string &n, int l=-1, int c=-1)
Definition: pt-decl.h:185
tree_decl_elt(tree_identifier *i=nullptr, tree_expression *e=nullptr)
Definition: pt-decl.h:58
void append(const tree_decl_elt * &s)
Definition: base-list.h:110
std::string name(void) const
Definition: pt-decl.h:213
std::string m_cmd_name
Definition: pt-decl.h:223
tree_identifier * ident(void)
Definition: pt-decl.h:98
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
tree_expression * m_expr
Definition: pt-decl.h:119
tree_decl_init_list * m_init_list
Definition: pt-decl.h:226
tree_decl_init_list(tree_decl_elt *t)
Definition: pt-decl.h:128
bool is_defined(symbol_record::context_id context)
Definition: pt-id.h:74
virtual void visit_decl_init_list(tree_decl_init_list &)=0