GNU Octave  4.2.1
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
pt-decl.h
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 1996-2017 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 the
9 Free Software Foundation; either version 3 of the License, or (at your
10 option) any later version.
11 
12 Octave is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 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 <http://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 class tree_expression;
29 class tree_identifier;
30 
31 class tree_walker;
32 
33 #include <string>
34 
35 #include "base-list.h"
36 #include "oct-lvalue.h"
37 #include "pt-cmd.h"
38 #include "pt-id.h"
39 #include "symtab.h"
40 
41 // List of expressions that make up a declaration statement.
42 
43 class
45 {
46 public:
47 
49  : id (i), expr (e) { }
50 
51  ~tree_decl_elt (void);
52 
53  bool eval (void);
54 
55  bool is_defined (void) { return id ? id->is_defined () : false; }
56 
57  bool is_variable (void) { return id ? id->is_variable () : false; }
58 
60  {
61  if (id)
62  id->mark_as_formal_parameter ();
63  }
64 
65  bool lvalue_ok (void) { return id ? id->lvalue_ok () : false; }
66 
67  // Do not allow functions to return null values.
69  {
70  return id ? id->rvalue1 (nargout).storable_value () : octave_value ();
71  }
72 
74  {
76 
77  if (nargout > 1)
78  error ("invalid number of output arguments in declaration list");
79 
80  retval = rvalue1 (nargout);
81 
82  return retval;
83  }
84 
85  octave_lvalue lvalue (void) { return id ? id->lvalue () : octave_lvalue (); }
86 
87  tree_identifier *ident (void) { return id; }
88 
89  std::string name (void) { return id ? id->name () : ""; }
90 
91  tree_expression *expression (void) { return expr; }
92 
95 
96  void accept (tree_walker& tw);
97 
98 private:
99 
100  // An identifier to tag with the declared property.
102 
103  // An initializer expression (may be zero);
105 
106  // No copying!
107 
108  tree_decl_elt (const tree_decl_elt&);
109 
111 };
112 
113 class
115 {
116 public:
117 
119 
121 
123  {
124  while (! empty ())
125  {
126  iterator p = begin ();
127  delete *p;
128  erase (p);
129  }
130  }
131 
134 
135  void accept (tree_walker& tw);
136 
137 private:
138 
139  // No copying!
140 
142 
144 };
145 
146 // Base class for declaration commands -- global, static, etc.
147 
148 class
150 {
151 public:
152 
153  tree_decl_command (const std::string& n, int l = -1, int c = -1)
154  : tree_command (l, c), cmd_name (n), init_list (0) { }
155 
157  int l = -1, int c = -1)
158  : tree_command (l, c), cmd_name (n), init_list (t) { }
159 
160  ~tree_decl_command (void);
161 
162  tree_decl_init_list *initializer_list (void) { return init_list; }
163 
164  std::string name (void) { return cmd_name; }
165 
166 protected:
167 
168  // The name of this command -- global, static, etc.
170 
171  // The list of variables or initializers in this declaration command.
173 
174 private:
175 
176  // No copying!
177 
179 
181 };
182 
183 // Global.
184 
185 class
187 {
188 public:
189 
190  tree_global_command (int l = -1, int c = -1)
191  : tree_decl_command ("global", l, c) { }
192 
193  tree_global_command (tree_decl_init_list *t, int l = -1, int c = -1)
194  : tree_decl_command ("global", t, l, c) { }
195 
197 
200 
201  void accept (tree_walker& tw);
202 
203 private:
204 
205  static void do_init (tree_decl_elt& elt);
206 
207  // No copying!
208 
210 
212 };
213 
214 // Persistent.
215 
216 class
218 {
219 public:
220 
221  tree_persistent_command (int l = -1, int c = -1)
222  : tree_decl_command ("persistent", l, c) { }
223 
225  : tree_decl_command ("persistent", t, l, c) { }
226 
228 
231 
232  void accept (tree_walker& tw);
233 
234 private:
235 
236  static void do_init (tree_decl_elt& elt);
237 
238  // No copying!
239 
241 
243 };
244 
245 #endif
uint32_t id
Definition: graphics.cc:11587
bool is_variable(void)
Definition: pt-decl.h:57
tree_global_command(tree_decl_init_list *t, int l=-1, int c=-1)
Definition: pt-decl.h:193
tree_decl_command(const std::string &n, tree_decl_init_list *t, int l=-1, int c=-1)
Definition: pt-decl.h:156
tree_decl_init_list(void)
Definition: pt-decl.h:118
tree_identifier * id
Definition: pt-decl.h:101
std::string name(void)
Definition: pt-decl.h:89
~tree_global_command(void)
Definition: pt-decl.h:196
tree_persistent_command(tree_decl_init_list *t, int l=-1, int c=-1)
Definition: pt-decl.h:224
tree_decl_init_list(tree_decl_elt *t)
Definition: pt-decl.h:120
void error(const char *fmt,...)
Definition: error.cc:570
std::list< tree_decl_elt * >::iterator iterator
Definition: base-list.h:40
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:935
octave_value rvalue1(int nargout=1)
Definition: pt-decl.h:68
tree_expression * expr
Definition: pt-decl.h:104
bool lvalue_ok(void)
Definition: pt-decl.h:65
i e
Definition: data.cc:2724
tree_identifier * ident(void)
Definition: pt-decl.h:87
tree_decl_init_list * initializer_list(void)
Definition: pt-decl.h:162
~tree_decl_init_list(void)
Definition: pt-decl.h:122
tree_decl_command(const std::string &n, int l=-1, int c=-1)
Definition: pt-decl.h:153
create a structure array and initialize its values The dimensions of each cell array of values must match Singleton cells and non cell values are repeated so that they fill the entire array If the cells are empty
Definition: ov-struct.cc:1688
OCTAVE_EXPORT octave_value_list return the number of command line arguments passed to Octave If called with the optional argument the function xample nargout(@histc)
Definition: ov-usr-fcn.cc:935
static llvm::LLVMContext & context
Definition: jit-typeinfo.cc:76
std::string cmd_name
Definition: pt-decl.h:169
tree_persistent_command(int l=-1, int c=-1)
Definition: pt-decl.h:221
tree_global_command(int l=-1, int c=-1)
Definition: pt-decl.h:190
octave_value retval
Definition: data.cc:6294
bool append
Definition: load-save.cc:1582
bool is_defined(void)
Definition: pt-decl.h:55
the sparsity preserving column transformation such that that defines the pivoting threshold can be given in which case it defines the c
Definition: lu.cc:138
tree_decl_init_list * init_list
Definition: pt-decl.h:172
octave_lvalue lvalue(void)
Definition: pt-decl.h:85
void mark_as_formal_parameter(void)
Definition: pt-decl.h:59
=val(i)}if ode{val(i)}occurs in table i
Definition: lookup.cc:239
p
Definition: lu.cc:138
std::string name(void)
Definition: pt-decl.h:164
tree_expression * expression(void)
Definition: pt-decl.h:91
tree_decl_elt(tree_identifier *i=0, tree_expression *e=0)
Definition: pt-decl.h:48
~tree_persistent_command(void)
Definition: pt-decl.h:227
octave_value storable_value(void) const
Definition: ov.cc:2166
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:854
tree_walker & operator=(const tree_walker &)
octave_value_list rvalue(int nargout)
Definition: pt-decl.h:73
return octave_value(v1.char_array_value().concat(v2.char_array_value(), ra_idx),((a1.is_sq_string()||a2.is_sq_string())? '\'': '"'))