Mercurial > octave
annotate src/pt-decl.h @ 8523:ad3afaaa19c1
implement non-copying contiguous range indexing
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Thu, 15 Jan 2009 07:22:24 +0100 |
parents | 283989f2da9b |
children | 73c4516fae10 |
rev | line source |
---|---|
2982 | 1 /* |
2 | |
7017 | 3 Copyright (C) 1996, 1997, 2000, 2002, 2004, 2005, 2006, 2007 |
4 John W. Eaton | |
2982 | 5 |
6 This file is part of Octave. | |
7 | |
8 Octave is free software; you can redistribute it and/or modify it | |
9 under the terms of the GNU General Public License as published by the | |
7016 | 10 Free Software Foundation; either version 3 of the License, or (at your |
11 option) any later version. | |
2982 | 12 |
13 Octave is distributed in the hope that it will be useful, but WITHOUT | |
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
16 for more details. | |
17 | |
18 You should have received a copy of the GNU General Public License | |
7016 | 19 along with Octave; see the file COPYING. If not, see |
20 <http://www.gnu.org/licenses/>. | |
2982 | 21 |
22 */ | |
23 | |
24 #if !defined (octave_tree_decl_h) | |
25 #define octave_tree_decl_h 1 | |
26 | |
27 class tree_expression; | |
28 class tree_identifier; | |
29 | |
30 class tree_walker; | |
31 | |
32 #include <string> | |
33 | |
4219 | 34 #include "base-list.h" |
6215 | 35 #include "oct-lvalue.h" |
2982 | 36 #include "pt-cmd.h" |
6215 | 37 #include "pt-id.h" |
7336 | 38 #include "symtab.h" |
2982 | 39 |
40 // List of expressions that make up a declaration statement. | |
41 | |
42 class | |
43 tree_decl_elt | |
44 { | |
45 public: | |
46 | |
2989 | 47 typedef void (*eval_fcn) (tree_decl_elt &); |
2982 | 48 |
49 tree_decl_elt (tree_identifier *i = 0, tree_expression *e = 0) | |
50 : id (i), expr (e) { } | |
51 | |
52 ~tree_decl_elt (void); | |
53 | |
6215 | 54 bool eval (void); |
55 | |
56 bool is_defined (void) { return id ? id->is_defined () : false; } | |
57 | |
7336 | 58 bool is_variable (void) { return id ? id->is_variable () : false; } |
59 | |
6215 | 60 void mark_as_formal_parameter (void) |
61 { | |
62 if (id) | |
63 id->mark_as_formal_parameter (); | |
64 } | |
65 | |
66 bool lvalue_ok (void) { return id ? id->lvalue_ok () : false; } | |
67 | |
8150
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7767
diff
changeset
|
68 // Do not allow functions return null values |
8523
ad3afaaa19c1
implement non-copying contiguous range indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
69 octave_value rvalue (void) { return id ? id->rvalue ().storable_value () : octave_value (); } |
6215 | 70 |
71 octave_value_list rvalue (int nargout) | |
72 { | |
73 return id ? id->rvalue (nargout) : octave_value_list (); | |
74 } | |
75 | |
76 octave_lvalue lvalue (void) { return id ? id->lvalue () : octave_lvalue (); } | |
2982 | 77 |
78 tree_identifier *ident (void) { return id; } | |
79 | |
80 tree_expression *expression (void) { return expr; } | |
81 | |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
82 tree_decl_elt *dup (symbol_table::scope_id scope, |
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
83 symbol_table::context_id context); |
5861 | 84 |
2982 | 85 void accept (tree_walker& tw); |
86 | |
87 private: | |
88 | |
89 // An identifier to tag with the declared property. | |
90 tree_identifier *id; | |
91 | |
92 // An initializer expression (may be zero); | |
93 tree_expression *expr; | |
2988 | 94 |
95 // No copying! | |
96 | |
97 tree_decl_elt (const tree_decl_elt&); | |
98 | |
99 tree_decl_elt& operator = (const tree_decl_elt&); | |
2982 | 100 }; |
101 | |
102 class | |
4219 | 103 tree_decl_init_list : public octave_base_list<tree_decl_elt *> |
2982 | 104 { |
105 public: | |
106 | |
4219 | 107 tree_decl_init_list (void) { } |
2982 | 108 |
4219 | 109 tree_decl_init_list (tree_decl_elt *t) { append (t); } |
2982 | 110 |
111 ~tree_decl_init_list (void) | |
112 { | |
4219 | 113 while (! empty ()) |
2982 | 114 { |
4219 | 115 iterator p = begin (); |
116 delete *p; | |
117 erase (p); | |
2982 | 118 } |
119 } | |
120 | |
2989 | 121 void eval (tree_decl_elt::eval_fcn); |
2982 | 122 |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
123 tree_decl_init_list *dup (symbol_table::scope_id scope, |
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
124 symbol_table::context_id context); |
5861 | 125 |
2982 | 126 void accept (tree_walker& tw); |
2988 | 127 |
128 private: | |
129 | |
130 // No copying! | |
131 | |
132 tree_decl_init_list (const tree_decl_init_list&); | |
133 | |
134 tree_decl_init_list& operator = (const tree_decl_init_list&); | |
2982 | 135 }; |
136 | |
137 // Base class for declaration commands -- global, static, etc. | |
138 | |
139 class | |
140 tree_decl_command : public tree_command | |
141 { | |
142 public: | |
143 | |
3523 | 144 tree_decl_command (const std::string& n, int l = -1, int c = -1) |
7336 | 145 : tree_command (l, c), cmd_name (n), init_list (0) { } |
2982 | 146 |
3523 | 147 tree_decl_command (const std::string& n, tree_decl_init_list *t, |
2982 | 148 int l = -1, int c = -1) |
7336 | 149 : tree_command (l, c), cmd_name (n), init_list (t) { } |
2982 | 150 |
151 ~tree_decl_command (void); | |
152 | |
153 tree_decl_init_list *initializer_list (void) { return init_list; } | |
154 | |
155 void accept (tree_walker& tw); | |
156 | |
3523 | 157 std::string name (void) { return cmd_name; } |
2982 | 158 |
159 protected: | |
160 | |
161 // The name of this command -- global, static, etc. | |
3523 | 162 std::string cmd_name; |
2982 | 163 |
164 // The list of variables or initializers in this declaration command. | |
165 tree_decl_init_list *init_list; | |
2988 | 166 |
167 private: | |
168 | |
169 // No copying! | |
170 | |
171 tree_decl_command (const tree_decl_command&); | |
172 | |
173 tree_decl_command& operator = (const tree_decl_command&); | |
2982 | 174 }; |
175 | |
176 // Global. | |
177 | |
178 class | |
179 tree_global_command : public tree_decl_command | |
180 { | |
181 public: | |
182 | |
183 tree_global_command (int l = -1, int c = -1) | |
184 : tree_decl_command ("global", l, c) { } | |
185 | |
186 tree_global_command (tree_decl_init_list *t, int l = -1, int c = -1) | |
187 : tree_decl_command ("global", t, l, c) { } | |
188 | |
189 ~tree_global_command (void) { } | |
190 | |
191 void eval (void); | |
2988 | 192 |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
193 tree_command *dup (symbol_table::scope_id scope, |
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
194 symbol_table::context_id context); |
5861 | 195 |
2988 | 196 private: |
197 | |
2989 | 198 static void do_init (tree_decl_elt& elt); |
199 | |
2988 | 200 // No copying! |
201 | |
202 tree_global_command (const tree_global_command&); | |
203 | |
204 tree_global_command& operator = (const tree_global_command&); | |
2982 | 205 }; |
206 | |
207 // Static. | |
208 | |
209 class | |
210 tree_static_command : public tree_decl_command | |
211 { | |
212 public: | |
213 | |
214 tree_static_command (int l = -1, int c = -1) | |
215 : tree_decl_command ("static", l, c) { } | |
216 | |
217 tree_static_command (tree_decl_init_list *t, int l = -1, int c = -1) | |
218 : tree_decl_command ("static", t, l, c) { } | |
219 | |
220 ~tree_static_command (void) { } | |
221 | |
222 void eval (void); | |
2988 | 223 |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
224 tree_command *dup (symbol_table::scope_id scope, |
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
225 symbol_table::context_id context); |
5861 | 226 |
2988 | 227 private: |
228 | |
2989 | 229 static void do_init (tree_decl_elt& elt); |
230 | |
2988 | 231 // No copying! |
232 | |
233 tree_static_command (const tree_static_command&); | |
234 | |
235 tree_static_command& operator = (const tree_static_command&); | |
2982 | 236 }; |
237 | |
238 #endif | |
239 | |
240 /* | |
241 ;;; Local Variables: *** | |
242 ;;; mode: C++ *** | |
243 ;;; End: *** | |
244 */ |