Mercurial > hg > octave-nkf
annotate src/symtab.h @ 7752:40c428ea3408
initial implementation of dbup and dbdown
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Sun, 04 May 2008 03:42:19 -0400 |
parents | 8e4592e49fa7 |
children | e76a4a6e3c47 |
rev | line source |
---|---|
8 | 1 /* |
2 | |
7017 | 3 Copyright (C) 1993, 1994, 1995, 1996, 1997, 1999, 2000, 2002, 2003, |
7346 | 4 2004, 2005, 2006, 2007, 2008 John W. Eaton |
7336 | 5 |
8 | 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. | |
8 | 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/>. | |
8 | 21 |
22 */ | |
23 | |
383 | 24 #if !defined (octave_symtab_h) |
25 #define octave_symtab_h 1 | |
8 | 26 |
7336 | 27 #include <deque> |
28 #include <list> | |
29 #include <map> | |
30 #include <set> | |
31 #include <string> | |
2953 | 32 |
7336 | 33 #include "glob-match.h" |
2846 | 34 |
7336 | 35 class tree_argument_list; |
3013 | 36 |
7336 | 37 #include "oct-obj.h" |
38 #include "ov.h" | |
1412 | 39 |
8 | 40 class |
6109 | 41 OCTINTERP_API |
8 | 42 symbol_table |
43 { | |
44 public: | |
45 | |
7336 | 46 typedef int scope_id; |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
47 typedef size_t context_id; |
7336 | 48 |
49 class | |
50 symbol_record | |
51 { | |
52 public: | |
53 | |
54 // generic variable | |
55 static const unsigned int local = 1; | |
56 | |
57 // varargin, argn, .nargin., .nargout. | |
58 // (FIXME -- is this really used now?) | |
59 static const unsigned int automatic = 2; | |
60 | |
61 // formal parameter | |
62 static const unsigned int formal = 4; | |
63 | |
64 // not listed or cleared (.nargin., .nargout.) | |
65 static const unsigned int hidden = 8; | |
66 | |
67 // inherited from parent scope; not cleared at function exit | |
68 static const unsigned int inherited = 16; | |
69 | |
70 // global (redirects to global scope) | |
71 static const unsigned int global = 32; | |
72 | |
73 // not cleared at function exit | |
74 static const unsigned int persistent = 64; | |
75 | |
76 private: | |
77 | |
78 class | |
79 symbol_record_rep | |
4009 | 80 { |
7336 | 81 public: |
82 | |
83 symbol_record_rep (const std::string& nm, const octave_value& v, | |
84 unsigned int sc) | |
85 : name (nm), value_stack (), storage_class (sc), count (1) | |
86 { | |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
87 value_stack.push_back (v); |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
88 } |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
89 |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
90 octave_value& varref (void) |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
91 { |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
92 if (is_global ()) |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
93 return symbol_table::global_varref (name); |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
94 else if (is_persistent ()) |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
95 return symbol_table::persistent_varref (name); |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
96 else |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
97 { |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
98 context_id n = value_stack.size (); |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
99 while (n++ <= symbol_table::xcurrent_context) |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
100 value_stack.push_back (octave_value ()); |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
101 |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
102 return value_stack[symbol_table::xcurrent_context]; |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
103 } |
7336 | 104 } |
105 | |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
106 octave_value varval (void) const |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
107 { |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
108 if (is_global ()) |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
109 return symbol_table::global_varval (name); |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
110 else if (is_persistent ()) |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
111 return symbol_table::persistent_varval (name); |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
112 else |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
113 { |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
114 if (symbol_table::xcurrent_context < value_stack.size ()) |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
115 return value_stack[symbol_table::xcurrent_context]; |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
116 else |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
117 return octave_value (); |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
118 } |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
119 } |
7336 | 120 |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
121 void push_context (void) |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
122 { |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
123 if (! (is_persistent () || is_global ())) |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
124 value_stack.push_back (octave_value ()); |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
125 } |
7336 | 126 |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
127 // If pop_context returns 0, we are out of values and this element |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
128 // of the symbol table should be deleted. This can happen for |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
129 // functions like |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
130 // |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
131 // function foo (n) |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
132 // if (n > 0) |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
133 // foo (n-1); |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
134 // else |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
135 // eval ("x = 1"); |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
136 // endif |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
137 // endfunction |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
138 // |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
139 // Here, X should only exist in the final stack frame. |
7336 | 140 |
7374 | 141 size_t pop_context (void) |
142 { | |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
143 size_t retval = 1; |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
144 |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
145 if (! (is_persistent () || is_global ())) |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
146 { |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
147 value_stack.pop_back (); |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
148 retval = value_stack.size (); |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
149 } |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
150 |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
151 return retval; |
7374 | 152 } |
7336 | 153 |
154 void clear (void) | |
155 { | |
156 if (! (is_hidden () || is_inherited ())) | |
157 { | |
158 if (is_global ()) | |
159 unmark_global (); | |
160 | |
161 if (is_persistent ()) | |
162 { | |
163 symbol_table::persistent_varref (name) = varval (); | |
164 unmark_persistent (); | |
165 } | |
166 | |
167 varref () = octave_value (); | |
168 } | |
169 } | |
170 | |
171 bool is_defined (void) const { return varval ().is_defined (); } | |
172 | |
173 bool is_variable (void) const | |
174 { | |
175 return (storage_class != local || is_defined ()); | |
176 } | |
177 | |
178 bool is_local (void) const { return storage_class & local; } | |
179 bool is_automatic (void) const { return storage_class & automatic; } | |
180 bool is_formal (void) const { return storage_class & formal; } | |
181 bool is_hidden (void) const { return storage_class & hidden; } | |
182 bool is_inherited (void) const { return storage_class & inherited; } | |
183 bool is_global (void) const { return storage_class & global; } | |
184 bool is_persistent (void) const { return storage_class & persistent; } | |
185 | |
186 void mark_local (void) { storage_class |= local; } | |
187 void mark_automatic (void) { storage_class |= automatic; } | |
188 void mark_formal (void) { storage_class |= formal; } | |
189 void mark_hidden (void) { storage_class |= hidden; } | |
190 void mark_inherited (void) { storage_class |= inherited; } | |
191 void mark_global (void) | |
192 { | |
193 if (is_persistent ()) | |
194 error ("can't make persistent variable %s global", name.c_str ()); | |
195 else | |
196 storage_class |= global; | |
197 } | |
198 void mark_persistent (void) | |
199 { | |
200 if (is_global ()) | |
201 error ("can't make global variable %s persistent", name.c_str ()); | |
202 else | |
203 storage_class |= persistent; | |
204 } | |
205 | |
206 void unmark_local (void) { storage_class &= ~local; } | |
207 void unmark_automatic (void) { storage_class &= ~automatic; } | |
208 void unmark_formal (void) { storage_class &= ~formal; } | |
209 void unmark_hidden (void) { storage_class &= ~hidden; } | |
210 void unmark_inherited (void) { storage_class &= ~inherited; } | |
211 void unmark_global (void) { storage_class &= ~global; } | |
212 void unmark_persistent (void) { storage_class &= ~persistent; } | |
213 | |
214 void init_persistent (void) | |
215 { | |
216 if (! is_defined ()) | |
217 { | |
218 mark_persistent (); | |
219 | |
220 varref () = symbol_table::persistent_varval (name); | |
221 } | |
222 // FIXME -- this causes trouble with recursive calls. | |
223 // else | |
224 // error ("unable to declare existing variable persistent"); | |
225 } | |
226 | |
227 void erase_persistent (void) | |
228 { | |
229 unmark_persistent (); | |
230 symbol_table::erase_persistent (name); | |
231 } | |
232 | |
233 symbol_record_rep *dup (void) | |
234 { | |
235 return new symbol_record_rep (name, varval (), storage_class); | |
236 } | |
237 | |
238 std::string name; | |
239 | |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
240 std::deque<octave_value> value_stack; |
7336 | 241 |
242 unsigned int storage_class; | |
243 | |
244 size_t count; | |
245 | |
246 private: | |
247 | |
248 // No copying! | |
249 | |
250 symbol_record_rep (const symbol_record_rep& ov); | |
251 | |
252 symbol_record_rep& operator = (const symbol_record_rep&); | |
253 }; | |
254 | |
255 public: | |
256 | |
257 symbol_record (const std::string& nm = std::string (), | |
258 const octave_value& v = octave_value (), | |
259 unsigned int sc = local) | |
260 : rep (new symbol_record_rep (nm, v, sc)) { } | |
261 | |
262 symbol_record (const symbol_record& sr) | |
263 : rep (sr.rep) | |
264 { | |
265 rep->count++; | |
266 } | |
267 | |
268 symbol_record& operator = (const symbol_record& sr) | |
269 { | |
270 if (this != &sr) | |
271 { | |
272 rep = sr.rep; | |
273 rep->count++; | |
274 } | |
275 | |
276 return *this; | |
277 } | |
278 | |
279 ~symbol_record (void) | |
280 { | |
281 if (--rep->count == 0) | |
282 delete rep; | |
283 } | |
284 | |
285 symbol_record dup (void) const { return symbol_record (rep->dup ()); } | |
286 | |
287 std::string name (void) const { return rep->name; } | |
288 | |
289 octave_value | |
290 find (tree_argument_list *args, const string_vector& arg_names, | |
291 octave_value_list& evaluated_args, bool& args_evaluated) const; | |
292 | |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
293 octave_value& varref (void) { return rep->varref (); } |
7336 | 294 |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
295 octave_value varval (void) const { return rep->varval (); } |
7336 | 296 |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
297 void push_context (void) { rep->push_context (); } |
7336 | 298 |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
299 size_t pop_context (void) { return rep->pop_context (); } |
7336 | 300 |
301 void clear (void) { rep->clear (); } | |
302 | |
303 bool is_defined (void) const { return rep->is_defined (); } | |
304 bool is_variable (void) const { return rep->is_variable (); } | |
305 | |
306 bool is_local (void) const { return rep->is_local (); } | |
307 bool is_automatic (void) const { return rep->is_automatic (); } | |
308 bool is_formal (void) const { return rep->is_formal (); } | |
309 bool is_global (void) const { return rep->is_global (); } | |
310 bool is_hidden (void) const { return rep->is_hidden (); } | |
311 bool is_inherited (void) const { return rep->is_inherited (); } | |
312 bool is_persistent (void) const { return rep->is_persistent (); } | |
313 | |
314 void mark_local (void) { rep->mark_local (); } | |
315 void mark_automatic (void) { rep->mark_automatic (); } | |
316 void mark_formal (void) { rep->mark_formal (); } | |
317 void mark_hidden (void) { rep->mark_hidden (); } | |
318 void mark_inherited (void) { rep->mark_inherited (); } | |
319 void mark_global (void) { rep->mark_global (); } | |
320 void mark_persistent (void) { rep->mark_persistent (); } | |
321 | |
322 void unmark_local (void) { rep->unmark_local (); } | |
323 void unmark_automatic (void) { rep->unmark_automatic (); } | |
324 void unmark_formal (void) { rep->unmark_formal (); } | |
325 void unmark_hidden (void) { rep->unmark_hidden (); } | |
326 void unmark_inherited (void) { rep->unmark_inherited (); } | |
327 void unmark_global (void) { rep->unmark_global (); } | |
328 void unmark_persistent (void) { rep->unmark_persistent (); } | |
329 | |
330 void init_persistent (void) { rep->init_persistent (); } | |
331 | |
332 void erase_persistent (void) { rep->erase_persistent (); } | |
333 | |
334 unsigned int xstorage_class (void) const { return rep->storage_class; } | |
335 | |
336 private: | |
337 | |
338 symbol_record_rep *rep; | |
339 | |
340 symbol_record (symbol_record_rep *new_rep) : rep (new_rep) { } | |
341 }; | |
342 | |
343 class | |
344 fcn_info | |
345 { | |
346 public: | |
347 | |
348 typedef std::map<std::string, std::string> dispatch_map_type; | |
349 | |
350 typedef std::map<scope_id, octave_value>::const_iterator const_scope_val_iterator; | |
351 typedef std::map<scope_id, octave_value>::iterator scope_val_iterator; | |
4238 | 352 |
7336 | 353 typedef std::map<std::string, octave_value>::const_iterator const_str_val_iterator; |
354 typedef std::map<std::string, octave_value>::iterator str_val_iterator; | |
355 | |
356 typedef dispatch_map_type::const_iterator const_dispatch_map_iterator; | |
357 typedef dispatch_map_type::iterator dispatch_map_iterator; | |
358 | |
359 private: | |
360 | |
361 class | |
362 fcn_info_rep | |
363 { | |
364 public: | |
365 | |
366 fcn_info_rep (const std::string& nm) | |
367 : name (nm), subfunctions (), private_functions (), | |
368 class_constructors (), class_methods (), cmdline_function (), | |
369 autoload_function (), function_on_path (), built_in_function (), | |
370 count (1) { } | |
371 | |
372 octave_value load_private_function (const std::string& dir_name); | |
373 | |
374 octave_value load_class_constructor (void); | |
375 | |
376 octave_value load_class_method (const std::string& dispatch_type); | |
377 | |
378 octave_value | |
379 find (tree_argument_list *args, const string_vector& arg_names, | |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
380 octave_value_list& evaluated_args, bool& args_evaluated); |
7336 | 381 |
382 octave_value find_method (const std::string& dispatch_type); | |
383 | |
384 octave_value find_autoload (void); | |
385 | |
386 octave_value find_user_function (void); | |
387 | |
388 bool is_user_function_defined (void) const | |
389 { | |
390 return function_on_path.is_defined (); | |
391 } | |
392 | |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
393 octave_value find_function (void) |
7336 | 394 { |
395 octave_value_list args; | |
396 | |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
397 return find_function (args); |
7336 | 398 } |
399 | |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
400 octave_value find_function (const octave_value_list& args) |
7336 | 401 { |
402 string_vector arg_names; | |
403 octave_value_list evaluated_args = args; | |
404 bool args_evaluated; | |
405 | |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
406 return find (0, arg_names, evaluated_args, args_evaluated); |
7336 | 407 } |
408 | |
409 void install_cmdline_function (const octave_value& f) | |
410 { | |
411 cmdline_function = f; | |
412 } | |
413 | |
414 void install_subfunction (const octave_value& f, scope_id scope) | |
415 { | |
416 subfunctions[scope] = f; | |
417 } | |
418 | |
419 void install_user_function (const octave_value& f) | |
420 { | |
421 function_on_path = f; | |
422 } | |
423 | |
424 void install_built_in_function (const octave_value& f) | |
425 { | |
426 built_in_function = f; | |
427 } | |
428 | |
7489
8e4592e49fa7
don't clear locked functions
John W. Eaton <jwe@octave.org>
parents:
7374
diff
changeset
|
429 template <class T> |
8e4592e49fa7
don't clear locked functions
John W. Eaton <jwe@octave.org>
parents:
7374
diff
changeset
|
430 void |
8e4592e49fa7
don't clear locked functions
John W. Eaton <jwe@octave.org>
parents:
7374
diff
changeset
|
431 clear_unlocked (std::map<T, octave_value>& map) |
7336 | 432 { |
7489
8e4592e49fa7
don't clear locked functions
John W. Eaton <jwe@octave.org>
parents:
7374
diff
changeset
|
433 typename std::map<T, octave_value>::iterator p = map.begin (); |
8e4592e49fa7
don't clear locked functions
John W. Eaton <jwe@octave.org>
parents:
7374
diff
changeset
|
434 |
8e4592e49fa7
don't clear locked functions
John W. Eaton <jwe@octave.org>
parents:
7374
diff
changeset
|
435 while (p != map.end ()) |
8e4592e49fa7
don't clear locked functions
John W. Eaton <jwe@octave.org>
parents:
7374
diff
changeset
|
436 { |
8e4592e49fa7
don't clear locked functions
John W. Eaton <jwe@octave.org>
parents:
7374
diff
changeset
|
437 if (p->second.islocked ()) |
8e4592e49fa7
don't clear locked functions
John W. Eaton <jwe@octave.org>
parents:
7374
diff
changeset
|
438 p++; |
8e4592e49fa7
don't clear locked functions
John W. Eaton <jwe@octave.org>
parents:
7374
diff
changeset
|
439 else |
8e4592e49fa7
don't clear locked functions
John W. Eaton <jwe@octave.org>
parents:
7374
diff
changeset
|
440 map.erase (p++); |
8e4592e49fa7
don't clear locked functions
John W. Eaton <jwe@octave.org>
parents:
7374
diff
changeset
|
441 } |
8e4592e49fa7
don't clear locked functions
John W. Eaton <jwe@octave.org>
parents:
7374
diff
changeset
|
442 } |
8e4592e49fa7
don't clear locked functions
John W. Eaton <jwe@octave.org>
parents:
7374
diff
changeset
|
443 |
8e4592e49fa7
don't clear locked functions
John W. Eaton <jwe@octave.org>
parents:
7374
diff
changeset
|
444 void clear_cmdline_function (void) |
8e4592e49fa7
don't clear locked functions
John W. Eaton <jwe@octave.org>
parents:
7374
diff
changeset
|
445 { |
8e4592e49fa7
don't clear locked functions
John W. Eaton <jwe@octave.org>
parents:
7374
diff
changeset
|
446 if (! cmdline_function.islocked ()) |
8e4592e49fa7
don't clear locked functions
John W. Eaton <jwe@octave.org>
parents:
7374
diff
changeset
|
447 cmdline_function = octave_value (); |
8e4592e49fa7
don't clear locked functions
John W. Eaton <jwe@octave.org>
parents:
7374
diff
changeset
|
448 } |
8e4592e49fa7
don't clear locked functions
John W. Eaton <jwe@octave.org>
parents:
7374
diff
changeset
|
449 |
8e4592e49fa7
don't clear locked functions
John W. Eaton <jwe@octave.org>
parents:
7374
diff
changeset
|
450 void clear_autoload_function (void) |
8e4592e49fa7
don't clear locked functions
John W. Eaton <jwe@octave.org>
parents:
7374
diff
changeset
|
451 { |
8e4592e49fa7
don't clear locked functions
John W. Eaton <jwe@octave.org>
parents:
7374
diff
changeset
|
452 if (! autoload_function.islocked ()) |
8e4592e49fa7
don't clear locked functions
John W. Eaton <jwe@octave.org>
parents:
7374
diff
changeset
|
453 autoload_function = octave_value (); |
7336 | 454 } |
455 | |
456 // FIXME -- should this also clear the cmdline and other "user | |
457 // defined" functions? | |
458 void clear_user_function (void) | |
459 { | |
7489
8e4592e49fa7
don't clear locked functions
John W. Eaton <jwe@octave.org>
parents:
7374
diff
changeset
|
460 if (! function_on_path.islocked ()) |
8e4592e49fa7
don't clear locked functions
John W. Eaton <jwe@octave.org>
parents:
7374
diff
changeset
|
461 function_on_path = octave_value (); |
7336 | 462 } |
463 | |
464 void clear_mex_function (void) | |
465 { | |
466 if (function_on_path.is_mex_function ()) | |
7489
8e4592e49fa7
don't clear locked functions
John W. Eaton <jwe@octave.org>
parents:
7374
diff
changeset
|
467 clear_user_function (); |
8e4592e49fa7
don't clear locked functions
John W. Eaton <jwe@octave.org>
parents:
7374
diff
changeset
|
468 } |
8e4592e49fa7
don't clear locked functions
John W. Eaton <jwe@octave.org>
parents:
7374
diff
changeset
|
469 |
8e4592e49fa7
don't clear locked functions
John W. Eaton <jwe@octave.org>
parents:
7374
diff
changeset
|
470 void clear (void) |
8e4592e49fa7
don't clear locked functions
John W. Eaton <jwe@octave.org>
parents:
7374
diff
changeset
|
471 { |
8e4592e49fa7
don't clear locked functions
John W. Eaton <jwe@octave.org>
parents:
7374
diff
changeset
|
472 clear_unlocked (subfunctions); |
8e4592e49fa7
don't clear locked functions
John W. Eaton <jwe@octave.org>
parents:
7374
diff
changeset
|
473 clear_unlocked (private_functions); |
8e4592e49fa7
don't clear locked functions
John W. Eaton <jwe@octave.org>
parents:
7374
diff
changeset
|
474 clear_unlocked (class_constructors); |
8e4592e49fa7
don't clear locked functions
John W. Eaton <jwe@octave.org>
parents:
7374
diff
changeset
|
475 clear_unlocked (class_methods); |
8e4592e49fa7
don't clear locked functions
John W. Eaton <jwe@octave.org>
parents:
7374
diff
changeset
|
476 clear_cmdline_function (); |
8e4592e49fa7
don't clear locked functions
John W. Eaton <jwe@octave.org>
parents:
7374
diff
changeset
|
477 clear_autoload_function (); |
8e4592e49fa7
don't clear locked functions
John W. Eaton <jwe@octave.org>
parents:
7374
diff
changeset
|
478 clear_user_function (); |
7336 | 479 } |
480 | |
481 void add_dispatch (const std::string& type, const std::string& fname) | |
482 { | |
483 dispatch_map[type] = fname; | |
484 } | |
485 | |
486 void clear_dispatch (const std::string& type) | |
487 { | |
488 dispatch_map_iterator p = dispatch_map.find (type); | |
489 | |
490 if (p != dispatch_map.end ()) | |
491 dispatch_map.erase (p); | |
492 } | |
493 | |
494 void print_dispatch (std::ostream& os) const; | |
495 | |
496 std::string help_for_dispatch (void) const; | |
497 | |
498 dispatch_map_type get_dispatch (void) const { return dispatch_map; } | |
499 | |
500 std::string name; | |
501 | |
502 // Scope id to function object. | |
503 std::map<scope_id, octave_value> subfunctions; | |
504 | |
505 // Directory name to function object. | |
506 std::map<std::string, octave_value> private_functions; | |
507 | |
508 // Class name to function object. | |
509 std::map<std::string, octave_value> class_constructors; | |
510 | |
511 // Dispatch type to function object. | |
512 std::map<std::string, octave_value> class_methods; | |
513 | |
514 // Legacy dispatch map (dispatch type name to function name). | |
515 dispatch_map_type dispatch_map; | |
516 | |
517 octave_value cmdline_function; | |
518 | |
519 octave_value autoload_function; | |
520 | |
521 octave_value function_on_path; | |
522 | |
523 octave_value built_in_function; | |
524 | |
525 size_t count; | |
526 | |
527 private: | |
528 | |
529 // No copying! | |
530 | |
531 fcn_info_rep (const fcn_info_rep&); | |
532 | |
533 fcn_info_rep& operator = (const fcn_info_rep&); | |
534 }; | |
535 | |
536 public: | |
537 | |
538 fcn_info (const std::string& nm = std::string ()) | |
539 : rep (new fcn_info_rep (nm)) { } | |
540 | |
541 fcn_info (const fcn_info& ov) : rep (ov.rep) | |
542 { | |
543 rep->count++; | |
544 } | |
545 | |
546 fcn_info& operator = (const fcn_info& ov) | |
547 { | |
548 if (this != &ov) | |
4238 | 549 { |
7336 | 550 rep = ov.rep; |
551 rep->count++; | |
4238 | 552 } |
7336 | 553 |
554 return *this; | |
555 } | |
556 | |
557 ~fcn_info (void) | |
558 { | |
559 if (--rep->count == 0) | |
560 delete rep; | |
561 } | |
562 | |
563 octave_value | |
564 find (tree_argument_list *args, const string_vector& arg_names, | |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
565 octave_value_list& evaluated_args, bool& args_evaluated); |
7336 | 566 |
567 octave_value find_method (const std::string& dispatch_type) const | |
568 { | |
569 return rep->find_method (dispatch_type); | |
570 } | |
571 | |
572 octave_value find_built_in_function (void) const | |
573 { | |
574 return rep->built_in_function; | |
575 } | |
576 | |
577 octave_value find_autoload (void) | |
578 { | |
579 return rep->find_autoload (); | |
580 } | |
581 | |
582 octave_value find_user_function (void) | |
583 { | |
584 return rep->find_user_function (); | |
585 } | |
586 | |
587 bool is_user_function_defined (void) const | |
588 { | |
589 return rep->is_user_function_defined (); | |
590 } | |
591 | |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
592 octave_value find_function (void) |
7336 | 593 { |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
594 return rep->find_function (); |
7336 | 595 } |
596 | |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
597 octave_value find_function (const octave_value_list& args) |
7336 | 598 { |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
599 return rep->find_function (args); |
7336 | 600 } |
601 | |
602 void install_cmdline_function (const octave_value& f) | |
603 { | |
604 rep->install_cmdline_function (f); | |
605 } | |
606 | |
607 void install_subfunction (const octave_value& f, scope_id scope) | |
608 { | |
609 rep->install_subfunction (f, scope); | |
610 } | |
611 | |
612 void install_user_function (const octave_value& f) | |
613 { | |
614 rep->install_user_function (f); | |
615 } | |
616 | |
617 void install_built_in_function (const octave_value& f) | |
618 { | |
619 rep->install_built_in_function (f); | |
620 } | |
621 | |
622 void clear (void) { rep->clear (); } | |
623 | |
624 void clear_user_function (void) { rep->clear_user_function (); } | |
625 | |
626 void clear_mex_function (void) { rep->clear_mex_function (); } | |
627 | |
628 void add_dispatch (const std::string& type, const std::string& fname) | |
629 { | |
630 rep->add_dispatch (type, fname); | |
631 } | |
632 | |
633 void clear_dispatch (const std::string& type) | |
634 { | |
635 rep->clear_dispatch (type); | |
636 } | |
637 | |
638 void print_dispatch (std::ostream& os) const | |
639 { | |
640 rep->print_dispatch (os); | |
641 } | |
642 | |
643 std::string help_for_dispatch (void) const { return rep->help_for_dispatch (); } | |
644 | |
645 dispatch_map_type get_dispatch (void) const | |
646 { | |
647 return rep->get_dispatch (); | |
4009 | 648 } |
3011 | 649 |
7336 | 650 private: |
651 | |
652 fcn_info_rep *rep; | |
653 }; | |
654 | |
655 static scope_id global_scope (void) { return xglobal_scope; } | |
656 static scope_id top_scope (void) { return xtop_scope; } | |
657 | |
658 static scope_id current_scope (void) { return xcurrent_scope; } | |
659 static scope_id current_caller_scope (void) { return xcurrent_caller_scope; } | |
660 | |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
661 static context_id current_context (void) { return xcurrent_context; } |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
662 |
7336 | 663 // We use parent_scope to handle parsing subfunctions. |
664 static scope_id parent_scope (void) { return xparent_scope; } | |
665 | |
666 static scope_id alloc_scope (void) | |
667 { | |
668 scope_id retval; | |
669 | |
670 scope_ids_free_list_iterator p = scope_ids_free_list.begin (); | |
671 | |
672 if (p != scope_ids_free_list.end ()) | |
673 { | |
674 retval = *p; | |
675 scope_ids_free_list.erase (p); | |
676 } | |
677 else | |
678 retval = next_available_scope++; | |
679 | |
680 scope_ids_in_use.insert (retval); | |
681 | |
682 return retval; | |
683 } | |
684 | |
685 static void set_scope (scope_id scope) | |
686 { | |
687 if (scope == xglobal_scope) | |
688 error ("can't set scope to global"); | |
689 else if (scope != xcurrent_scope) | |
690 { | |
691 all_instances_iterator p = all_instances.find (scope); | |
692 | |
693 if (p == all_instances.end ()) | |
694 { | |
695 instance = new symbol_table (); | |
8 | 696 |
7336 | 697 all_instances[scope] = instance; |
698 } | |
699 else | |
700 instance = p->second; | |
701 | |
702 xcurrent_scope = scope; | |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
703 xcurrent_context = instance->xcurrent_context_this_table; |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
704 } |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
705 } |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
706 |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
707 static void set_scope_and_context (scope_id scope, context_id context) |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
708 { |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
709 if (scope == xglobal_scope) |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
710 error ("can't set scope to global"); |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
711 else |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
712 { |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
713 if (scope != xcurrent_scope) |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
714 { |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
715 all_instances_iterator p = all_instances.find (scope); |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
716 |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
717 if (p == all_instances.end ()) |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
718 error ("scope not found!"); |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
719 else |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
720 { |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
721 instance = p->second; |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
722 |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
723 xcurrent_scope = scope; |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
724 } |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
725 } |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
726 |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
727 if (! error_state) |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
728 xcurrent_context = context; |
7336 | 729 } |
730 } | |
731 | |
732 static void push_scope (scope_id scope) | |
733 { | |
734 if (scope_stack.empty ()) | |
735 scope_stack.push_front (xtop_scope); | |
736 | |
737 xcurrent_caller_scope = xcurrent_scope; | |
738 | |
739 set_scope (scope); | |
740 | |
741 scope_stack.push_front (scope); | |
742 } | |
743 | |
744 static void pop_scope (void) | |
745 { | |
746 scope_stack.pop_front (); | |
8 | 747 |
7336 | 748 set_scope (scope_stack[0]); |
749 | |
7346 | 750 xcurrent_caller_scope = scope_stack.size () > 1 ? scope_stack[1] : -1; |
7336 | 751 } |
752 | |
753 static void pop_scope (void *) { pop_scope (); } | |
754 | |
755 static void reset_scope (void) | |
756 { | |
757 scope_stack.clear (); | |
758 | |
759 scope_stack.push_front (xtop_scope); | |
572 | 760 |
7336 | 761 set_scope (xtop_scope); |
762 | |
763 xcurrent_caller_scope = -1; | |
764 } | |
765 | |
766 static void set_parent_scope (scope_id scope) | |
767 { | |
768 xparent_scope = scope; | |
769 } | |
770 | |
771 static void reset_parent_scope (void) | |
772 { | |
773 set_parent_scope (-1); | |
774 } | |
4009 | 775 |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
776 static void erase_scope (scope_id scope) |
7336 | 777 { |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
778 assert (scope != xglobal_scope); |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
779 |
7336 | 780 all_instances_iterator p = all_instances.find (scope); |
781 | |
782 if (p != all_instances.end ()) | |
783 all_instances.erase (p); | |
784 | |
785 // free_scope (scope); | |
786 } | |
787 | |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
788 static scope_id dup_scope (scope_id scope) |
7336 | 789 { |
790 scope_id retval = -1; | |
791 | |
792 symbol_table *inst = get_instance (scope); | |
793 | |
794 if (inst) | |
795 { | |
796 scope_id new_scope = alloc_scope (); | |
797 | |
798 symbol_table *new_symbol_table = new symbol_table (); | |
799 | |
800 if (new_symbol_table) | |
801 { | |
802 all_instances[new_scope] = new_symbol_table; | |
803 | |
804 inst->do_dup_scope (*new_symbol_table); | |
805 | |
806 retval = new_scope; | |
807 } | |
808 } | |
809 | |
810 return retval; | |
811 } | |
812 | |
813 #if 0 | |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
814 static void print_scope (const std::string& tag) |
7336 | 815 { |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
816 symbol_table *inst = get_instance (xcurrent_scope); |
7336 | 817 |
818 if (inst) | |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
819 inst->do_print_scope (std::cerr); |
7336 | 820 } |
4009 | 821 |
7336 | 822 void do_print_scope (std::ostream& os) const |
823 { | |
824 for (const_table_iterator p = table.begin (); p != table.end (); p++) | |
825 { | |
826 symbol_record sr = p->second; | |
827 | |
828 octave_value val = sr.varval (); | |
829 | |
830 if (val.is_defined ()) | |
831 sr.varval ().print_with_name (os, sr.name ()); | |
832 else | |
833 os << sr.name () << " is not defined" << std::endl; | |
834 } | |
835 } | |
836 #endif | |
837 | |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
838 static symbol_record |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
839 find_symbol (const std::string& name, scope_id scope = xcurrent_scope) |
7336 | 840 { |
841 symbol_table *inst = get_instance (scope); | |
842 | |
843 return inst ? inst->do_find_symbol (name) : symbol_record (); | |
844 } | |
4009 | 845 |
7336 | 846 static void inherit (scope_id scope, scope_id donor_scope) |
847 { | |
848 symbol_table *inst = get_instance (scope); | |
849 | |
850 if (inst) | |
851 inst->do_inherit (donor_scope); | |
852 } | |
853 | |
854 static bool at_top_level (void) { return xcurrent_scope == xtop_scope; } | |
855 | |
856 // Find a value corresponding to the given name in the table. | |
857 static octave_value | |
858 find (const std::string& name, tree_argument_list *args, | |
859 const string_vector& arg_names, | |
860 octave_value_list& evaluated_args, bool& args_evaluated, | |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
861 bool skip_variables = false); |
7336 | 862 |
863 // Insert a new name in the table. | |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
864 static symbol_record& insert (const std::string& name) |
7336 | 865 { |
866 static symbol_record foobar; | |
867 | |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
868 symbol_table *inst = get_instance (xcurrent_scope); |
4009 | 869 |
7336 | 870 return inst ? inst->do_insert (name) : foobar; |
871 } | |
872 | |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
873 static octave_value& varref (const std::string& name, |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
874 scope_id scope = xcurrent_scope) |
7336 | 875 { |
876 static octave_value foobar; | |
877 | |
878 symbol_table *inst = get_instance (scope); | |
879 | |
880 return inst ? inst->do_varref (name) : foobar; | |
881 } | |
882 | |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
883 static octave_value varval (const std::string& name, |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
884 scope_id scope = xcurrent_scope) |
7336 | 885 { |
886 symbol_table *inst = get_instance (scope); | |
887 | |
888 return inst ? inst->do_varval (name) : octave_value (); | |
889 } | |
890 | |
891 static octave_value& | |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
892 global_varref (const std::string& name) |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
893 { |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
894 global_table_iterator p = global_table.find (name); |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
895 |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
896 return (p == global_table.end ()) ? global_table[name] : p->second; |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
897 } |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
898 |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
899 static octave_value |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
900 global_varval (const std::string& name) |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
901 { |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
902 const_global_table_iterator p = global_table.find (name); |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
903 |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
904 return (p != global_table.end ()) ? p->second : octave_value (); |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
905 } |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
906 |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
907 static octave_value& persistent_varref (const std::string& name) |
7336 | 908 { |
909 static octave_value foobar; | |
910 | |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
911 symbol_table *inst = get_instance (xcurrent_scope); |
7336 | 912 |
913 return inst ? inst->do_persistent_varref (name) : foobar; | |
914 } | |
915 | |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
916 static octave_value persistent_varval (const std::string& name) |
7336 | 917 { |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
918 symbol_table *inst = get_instance (xcurrent_scope); |
7336 | 919 |
920 return inst ? inst->do_persistent_varval (name) : octave_value (); | |
921 } | |
922 | |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
923 static void erase_persistent (const std::string& name) |
7336 | 924 { |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
925 symbol_table *inst = get_instance (xcurrent_scope); |
7336 | 926 |
927 if (inst) | |
928 inst->do_erase_persistent (name); | |
929 } | |
8 | 930 |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
931 static bool is_variable (const std::string& name) |
7336 | 932 { |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
933 symbol_table *inst = get_instance (xcurrent_scope); |
7336 | 934 |
935 return inst ? inst->do_is_variable (name) : false; | |
936 } | |
937 | |
938 static bool | |
939 is_built_in_function_name (const std::string& name) | |
940 { | |
941 octave_value val = find_built_in_function (name); | |
942 | |
943 return val.is_defined (); | |
944 } | |
945 | |
946 static octave_value | |
947 find_method (const std::string& name, const std::string& dispatch_type) | |
948 { | |
949 const_fcn_table_iterator p = fcn_table.find (name); | |
8 | 950 |
7336 | 951 if (p != fcn_table.end ()) |
952 return p->second.find_method (dispatch_type); | |
953 else | |
954 { | |
955 fcn_info finfo (name); | |
956 | |
957 octave_value fcn = finfo.find_method (dispatch_type); | |
958 | |
959 if (fcn.is_defined ()) | |
960 fcn_table[name] = finfo; | |
961 | |
962 return fcn; | |
963 } | |
964 } | |
965 | |
966 static octave_value | |
967 find_built_in_function (const std::string& name) | |
968 { | |
969 const_fcn_table_iterator p = fcn_table.find (name); | |
970 | |
971 return (p != fcn_table.end ()) | |
972 ? p->second.find_built_in_function () : octave_value (); | |
973 } | |
974 | |
975 static octave_value | |
976 find_autoload (const std::string& name) | |
977 { | |
978 fcn_table_iterator p = fcn_table.find (name); | |
4913 | 979 |
7336 | 980 return (p != fcn_table.end ()) |
981 ? p->second.find_autoload () : octave_value (); | |
982 } | |
983 | |
984 static octave_value | |
985 find_function (const std::string& name, tree_argument_list *args, | |
986 const string_vector& arg_names, | |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
987 octave_value_list& evaluated_args, bool& args_evaluated); |
7336 | 988 |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
989 static octave_value find_user_function (const std::string& name) |
7336 | 990 { |
991 fcn_table_iterator p = fcn_table.find (name); | |
992 | |
993 return (p != fcn_table.end ()) | |
994 ? p->second.find_user_function () : octave_value (); | |
995 } | |
996 | |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
997 static octave_value find_function (const std::string& name) |
7336 | 998 { |
999 octave_value_list evaluated_args; | |
1000 | |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1001 return find_function (name, evaluated_args); |
7336 | 1002 } |
1003 | |
1004 static octave_value | |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1005 find_function (const std::string& name, const octave_value_list& args) |
7336 | 1006 { |
1007 string_vector arg_names; | |
1008 octave_value_list evaluated_args = args; | |
1009 bool args_evaluated = ! args.empty (); | |
1010 | |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1011 return find_function (name, 0, arg_names, evaluated_args, args_evaluated); |
7336 | 1012 } |
1013 | |
1014 static void install_cmdline_function (const std::string& name, | |
1015 const octave_value& fcn) | |
1016 { | |
1017 fcn_table_iterator p = fcn_table.find (name); | |
1018 | |
1019 if (p != fcn_table.end ()) | |
1020 { | |
1021 fcn_info& finfo = p->second; | |
3013 | 1022 |
7336 | 1023 finfo.install_cmdline_function (fcn); |
1024 } | |
1025 else | |
1026 { | |
1027 fcn_info finfo (name); | |
195 | 1028 |
7336 | 1029 finfo.install_cmdline_function (fcn); |
1030 | |
1031 fcn_table[name] = finfo; | |
1032 } | |
1033 } | |
1034 | |
1035 static void install_subfunction (const std::string& name, | |
1036 const octave_value& fcn, | |
1037 scope_id scope = xparent_scope) | |
1038 { | |
1039 fcn_table_iterator p = fcn_table.find (name); | |
1040 | |
1041 if (p != fcn_table.end ()) | |
1042 { | |
1043 fcn_info& finfo = p->second; | |
1044 | |
1045 finfo.install_subfunction (fcn, scope); | |
1046 } | |
1047 else | |
1048 { | |
1049 fcn_info finfo (name); | |
1050 | |
1051 finfo.install_subfunction (fcn, scope); | |
1052 | |
1053 fcn_table[name] = finfo; | |
1054 } | |
1055 } | |
1056 | |
1057 static void install_user_function (const std::string& name, | |
1058 const octave_value& fcn) | |
1059 { | |
1060 fcn_table_iterator p = fcn_table.find (name); | |
1061 | |
1062 if (p != fcn_table.end ()) | |
1063 { | |
1064 fcn_info& finfo = p->second; | |
1065 | |
1066 finfo.install_user_function (fcn); | |
1067 } | |
1068 else | |
1069 { | |
1070 fcn_info finfo (name); | |
1071 | |
1072 finfo.install_user_function (fcn); | |
1073 | |
1074 fcn_table[name] = finfo; | |
1075 } | |
1076 } | |
605 | 1077 |
7336 | 1078 static void install_built_in_function (const std::string& name, |
1079 const octave_value& fcn) | |
1080 { | |
1081 fcn_table_iterator p = fcn_table.find (name); | |
1082 | |
1083 if (p != fcn_table.end ()) | |
1084 { | |
1085 fcn_info& finfo = p->second; | |
1086 | |
1087 finfo.install_built_in_function (fcn); | |
1088 } | |
1089 else | |
1090 { | |
1091 fcn_info finfo (name); | |
1092 | |
1093 finfo.install_built_in_function (fcn); | |
1094 | |
1095 fcn_table[name] = finfo; | |
1096 } | |
1097 } | |
1098 | |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1099 static void clear (const std::string& name) |
7336 | 1100 { |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1101 clear_variable (name); |
7336 | 1102 } |
1103 | |
1104 static void clear_all (void) | |
1105 { | |
1106 clear_variables (); | |
1107 | |
1108 clear_functions (); | |
1109 } | |
1110 | |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1111 static void clear_variables (void) |
7336 | 1112 { |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1113 symbol_table *inst = get_instance (xcurrent_scope); |
7336 | 1114 |
1115 if (inst) | |
1116 inst->do_clear_variables (); | |
1117 } | |
1118 | |
1119 // For unwind_protect. | |
1120 static void clear_variables (void *) { clear_variables (); } | |
1121 | |
1122 static void clear_functions (void) | |
1123 { | |
1124 for (fcn_table_iterator p = fcn_table.begin (); p != fcn_table.end (); p++) | |
1125 p->second.clear (); | |
1126 } | |
1127 | |
1128 static void clear_function (const std::string& name) | |
1129 { | |
1130 clear_user_function (name); | |
1131 } | |
1132 | |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1133 static void clear_global (const std::string& name) |
7336 | 1134 { |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1135 symbol_table *inst = get_instance (xcurrent_scope); |
7336 | 1136 |
1137 if (inst) | |
1138 inst->do_clear_global (name); | |
1139 } | |
1140 | |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1141 static void clear_variable (const std::string& name) |
7336 | 1142 { |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1143 symbol_table *inst = get_instance (xcurrent_scope); |
7336 | 1144 |
1145 if (inst) | |
1146 inst->do_clear_variable (name); | |
1147 } | |
1148 | |
1149 static void clear_symbol (const std::string& name) | |
1150 { | |
1151 // FIXME -- are we supposed to do both here? | |
1152 | |
1153 clear_variable (name); | |
1154 clear_function (name); | |
1155 } | |
1156 | |
1157 static void clear_function_pattern (const std::string& pat) | |
1158 { | |
1159 glob_match pattern (pat); | |
1160 | |
1161 for (fcn_table_iterator p = fcn_table.begin (); p != fcn_table.end (); p++) | |
1162 { | |
1163 if (pattern.match (p->first)) | |
1164 p->second.clear_user_function (); | |
1165 } | |
1166 } | |
1167 | |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1168 static void clear_global_pattern (const std::string& pat) |
7336 | 1169 { |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1170 symbol_table *inst = get_instance (xcurrent_scope); |
4009 | 1171 |
7336 | 1172 if (inst) |
1173 inst->do_clear_global_pattern (pat); | |
1174 } | |
1175 | |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1176 static void clear_variable_pattern (const std::string& pat) |
7336 | 1177 { |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1178 symbol_table *inst = get_instance (xcurrent_scope); |
7336 | 1179 |
1180 if (inst) | |
1181 inst->do_clear_variable_pattern (pat); | |
1182 } | |
1183 | |
1184 static void clear_symbol_pattern (const std::string& pat) | |
1185 { | |
1186 // FIXME -- are we supposed to do both here? | |
1187 | |
1188 clear_variable_pattern (pat); | |
1189 clear_function_pattern (pat); | |
1190 } | |
1191 | |
1192 static void clear_user_function (const std::string& name) | |
1193 { | |
1194 fcn_table_iterator p = fcn_table.find (name); | |
1195 | |
1196 if (p != fcn_table.end ()) | |
1197 { | |
1198 fcn_info& finfo = p->second; | |
1199 | |
1200 finfo.clear_user_function (); | |
1201 } | |
1202 // FIXME -- is this necessary, or even useful? | |
1203 // else | |
1204 // error ("clear: no such function `%s'", name.c_str ()); | |
1205 } | |
1206 | |
1207 static void clear_mex_functions (void) | |
1208 { | |
1209 for (fcn_table_iterator p = fcn_table.begin (); p != fcn_table.end (); p++) | |
1210 { | |
1211 fcn_info& finfo = p->second; | |
1212 | |
1213 finfo.clear_mex_function (); | |
1214 } | |
1215 } | |
1216 | |
1217 static void alias_built_in_function (const std::string& alias, | |
1218 const std::string& name) | |
1219 { | |
1220 octave_value fcn = find_built_in_function (name); | |
1221 | |
1222 if (fcn.is_defined ()) | |
1223 { | |
1224 fcn_info finfo (alias); | |
1225 | |
1226 finfo.install_built_in_function (fcn); | |
1227 | |
1228 fcn_table[alias] = finfo; | |
1229 } | |
1230 else | |
1231 panic ("alias: `%s' is undefined", name.c_str ()); | |
1232 } | |
1233 | |
1234 static void add_dispatch (const std::string& name, const std::string& type, | |
1235 const std::string& fname) | |
1236 { | |
1237 fcn_table_iterator p = fcn_table.find (name); | |
1238 | |
1239 if (p != fcn_table.end ()) | |
1240 { | |
1241 fcn_info& finfo = p->second; | |
1242 | |
1243 finfo.add_dispatch (type, fname); | |
1244 } | |
1245 else | |
1246 { | |
1247 fcn_info finfo (name); | |
1248 | |
1249 finfo.add_dispatch (type, fname); | |
1250 | |
1251 fcn_table[name] = finfo; | |
1252 } | |
1253 } | |
1254 | |
1255 static void clear_dispatch (const std::string& name, const std::string& type) | |
1256 { | |
1257 fcn_table_iterator p = fcn_table.find (name); | |
1258 | |
1259 if (p != fcn_table.end ()) | |
1260 { | |
1261 fcn_info& finfo = p->second; | |
1262 | |
1263 finfo.clear_dispatch (type); | |
1264 } | |
1265 } | |
1266 | |
1267 static void print_dispatch (std::ostream& os, const std::string& name) | |
1268 { | |
1269 fcn_table_iterator p = fcn_table.find (name); | |
4009 | 1270 |
7336 | 1271 if (p != fcn_table.end ()) |
1272 { | |
1273 fcn_info& finfo = p->second; | |
1274 | |
1275 finfo.print_dispatch (os); | |
1276 } | |
1277 } | |
1278 | |
1279 static fcn_info::dispatch_map_type get_dispatch (const std::string& name) | |
1280 { | |
1281 fcn_info::dispatch_map_type retval; | |
1282 | |
1283 fcn_table_iterator p = fcn_table.find (name); | |
1284 | |
1285 if (p != fcn_table.end ()) | |
1286 { | |
1287 fcn_info& finfo = p->second; | |
1288 | |
1289 retval = finfo.get_dispatch (); | |
1290 } | |
1291 | |
1292 return retval; | |
1293 } | |
1294 | |
1295 static std::string help_for_dispatch (const std::string& name) | |
1296 { | |
1297 std::string retval; | |
1298 | |
1299 fcn_table_iterator p = fcn_table.find (name); | |
1300 | |
1301 if (p != fcn_table.end ()) | |
1302 { | |
1303 fcn_info& finfo = p->second; | |
1304 | |
1305 retval = finfo.help_for_dispatch (); | |
1306 } | |
1307 | |
1308 return retval; | |
1309 } | |
1310 | |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1311 static void push_context (void) |
7336 | 1312 { |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1313 if (xcurrent_scope == xglobal_scope || xcurrent_scope == xtop_scope) |
7336 | 1314 error ("invalid call to xymtab::push_context"); |
1315 else | |
1316 { | |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1317 symbol_table *inst = get_instance (xcurrent_scope); |
7336 | 1318 |
1319 if (inst) | |
1320 inst->do_push_context (); | |
1321 } | |
1322 } | |
1323 | |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1324 static void pop_context (void) |
7336 | 1325 { |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1326 if (xcurrent_scope == xglobal_scope || xcurrent_scope == xtop_scope) |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1327 error ("invalid call to xymtab::pop_context"); |
7336 | 1328 else |
1329 { | |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1330 symbol_table *inst = get_instance (xcurrent_scope); |
7336 | 1331 |
1332 if (inst) | |
1333 inst->do_pop_context (); | |
1334 } | |
1335 } | |
1336 | |
1337 // For unwind_protect. | |
1338 static void pop_context (void *) { pop_context (); } | |
1339 | |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1340 static void mark_hidden (const std::string& name) |
7336 | 1341 { |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1342 symbol_table *inst = get_instance (xcurrent_scope); |
7336 | 1343 |
1344 if (inst) | |
1345 inst->do_mark_hidden (name); | |
1346 } | |
1347 | |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1348 static void mark_global (const std::string& name) |
7336 | 1349 { |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1350 symbol_table *inst = get_instance (xcurrent_scope); |
7336 | 1351 |
1352 if (inst) | |
1353 inst->do_mark_global (name); | |
1354 } | |
1355 | |
1356 static std::list<symbol_record> | |
1357 all_variables (scope_id scope = xcurrent_scope, bool defined_only = true) | |
1358 { | |
1359 symbol_table *inst = get_instance (scope); | |
1360 | |
1361 return inst | |
1362 ? inst->do_all_variables (defined_only) : std::list<symbol_record> (); | |
1363 } | |
3011 | 1364 |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1365 static std::list<symbol_record> glob (const std::string& pattern) |
7336 | 1366 { |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1367 symbol_table *inst = get_instance (xcurrent_scope); |
7336 | 1368 |
1369 return inst ? inst->do_glob (pattern) : std::list<symbol_record> (); | |
1370 } | |
1371 | |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1372 static std::list<symbol_record> glob_variables (const std::string& pattern) |
7336 | 1373 { |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1374 symbol_table *inst = get_instance (xcurrent_scope); |
7336 | 1375 |
1376 return inst ? inst->do_glob (pattern, true) : std::list<symbol_record> (); | |
1377 } | |
1378 | |
1379 static std::list<symbol_record> | |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1380 glob_global_variables (const std::string& pattern) |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1381 { |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1382 std::list<symbol_record> retval; |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1383 |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1384 glob_match pat (pattern); |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1385 |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1386 for (const_global_table_iterator p = global_table.begin (); |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1387 p != global_table.end (); p++) |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1388 { |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1389 // We generate a list of symbol_record objects so that |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1390 // the results from glob_variables and glob_global_variables |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1391 // may be handled the same way. |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1392 |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1393 if (pat.match (p->first)) |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1394 retval.push_back (symbol_record (p->first, p->second, |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1395 symbol_record::global)); |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1396 } |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1397 |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1398 return retval; |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1399 } |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1400 |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1401 static std::list<symbol_record> glob_variables (const string_vector& patterns) |
7336 | 1402 { |
1403 std::list<symbol_record> retval; | |
1404 | |
1405 size_t len = patterns.length (); | |
8 | 1406 |
7336 | 1407 for (size_t i = 0; i < len; i++) |
1408 { | |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1409 std::list<symbol_record> tmp = glob_variables (patterns[i]); |
7336 | 1410 |
1411 retval.insert (retval.begin (), tmp.begin (), tmp.end ()); | |
1412 } | |
1413 | |
1414 return retval; | |
1415 } | |
1416 | |
1417 static std::list<std::string> user_function_names (void) | |
1418 { | |
1419 std::list<std::string> retval; | |
1420 | |
1421 for (fcn_table_iterator p = fcn_table.begin (); | |
1422 p != fcn_table.end (); p++) | |
1423 { | |
1424 if (p->second.is_user_function_defined ()) | |
1425 retval.push_back (p->first); | |
1426 } | |
1427 | |
1428 if (! retval.empty ()) | |
1429 retval.sort (); | |
1430 | |
1431 return retval; | |
1432 } | |
3011 | 1433 |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1434 static std::list<std::string> global_variable_names (void) |
7336 | 1435 { |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1436 std::list<std::string> retval; |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1437 |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1438 for (const_global_table_iterator p = global_table.begin (); |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1439 p != global_table.end (); p++) |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1440 retval.push_back (p->first); |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1441 |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1442 retval.sort (); |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1443 |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1444 return retval; |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1445 } |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1446 |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1447 static std::list<std::string> top_level_variable_names (void) |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1448 { |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1449 symbol_table *inst = get_instance (xtop_scope); |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1450 |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1451 return inst ? inst->do_variable_names () : std::list<std::string> (); |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1452 } |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1453 |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1454 static std::list<std::string> variable_names (void) |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1455 { |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1456 symbol_table *inst = get_instance (xcurrent_scope); |
7336 | 1457 |
1458 return inst ? inst->do_variable_names () : std::list<std::string> (); | |
1459 } | |
1460 | |
1461 static std::list<std::string> built_in_function_names (void) | |
1462 { | |
1463 std::list<std::string> retval; | |
1464 | |
1465 for (const_fcn_table_iterator p = fcn_table.begin (); | |
1466 p != fcn_table.end (); p++) | |
1467 { | |
1468 octave_value fcn = p->second.find_built_in_function (); | |
1469 | |
1470 if (fcn.is_defined ()) | |
1471 retval.push_back (p->first); | |
1472 } | |
1473 | |
1474 if (! retval.empty ()) | |
1475 retval.sort (); | |
220 | 1476 |
7336 | 1477 return retval; |
1478 } | |
1479 | |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1480 static bool is_local_variable (const std::string& name) |
7336 | 1481 { |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1482 if (xcurrent_scope == xglobal_scope) |
7336 | 1483 return false; |
1484 else | |
1485 { | |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1486 symbol_table *inst = get_instance (xcurrent_scope); |
5861 | 1487 |
7336 | 1488 return inst ? inst->do_is_local_variable (name) : false; |
1489 } | |
1490 } | |
5861 | 1491 |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1492 static bool is_global (const std::string& name) |
7336 | 1493 { |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1494 if (xcurrent_scope == xglobal_scope) |
7336 | 1495 return true; |
1496 else | |
1497 { | |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1498 symbol_table *inst = get_instance (xcurrent_scope); |
7336 | 1499 |
1500 return inst ? inst->do_is_global (name) : false; | |
1501 } | |
1502 } | |
3011 | 1503 |
8 | 1504 private: |
1505 | |
7336 | 1506 typedef std::map<std::string, symbol_record>::const_iterator const_table_iterator; |
1507 typedef std::map<std::string, symbol_record>::iterator table_iterator; | |
1508 | |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1509 typedef std::map<std::string, octave_value>::const_iterator const_global_table_iterator; |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1510 typedef std::map<std::string, octave_value>::iterator global_table_iterator; |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1511 |
7336 | 1512 typedef std::map<std::string, octave_value>::const_iterator const_persistent_table_iterator; |
1513 typedef std::map<std::string, octave_value>::iterator persistent_table_iterator; | |
1514 | |
1515 typedef std::map<scope_id, symbol_table*>::const_iterator all_instances_const_iterator; | |
1516 typedef std::map<scope_id, symbol_table*>::iterator all_instances_iterator; | |
1517 | |
1518 typedef std::map<std::string, fcn_info>::const_iterator const_fcn_table_iterator; | |
1519 typedef std::map<std::string, fcn_info>::iterator fcn_table_iterator; | |
1520 | |
1521 typedef std::set<scope_id>::const_iterator scope_ids_free_list_const_iterator; | |
1522 typedef std::set<scope_id>::iterator scope_ids_free_list_iterator; | |
1523 | |
1524 typedef std::set<scope_id>::const_iterator scope_ids_in_use_const_iterator; | |
1525 typedef std::set<scope_id>::iterator scope_ids_in_use_iterator; | |
1526 | |
1527 // Map from symbol names to symbol info. | |
1528 std::map<std::string, symbol_record> table; | |
1529 | |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1530 // Map from names of global variables to values. |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1531 static std::map<std::string, octave_value> global_table; |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1532 |
7336 | 1533 // Map from names of persistent variables to values. |
1534 std::map<std::string, octave_value> persistent_table; | |
1535 | |
1536 // Pointer to symbol table for current scope (variables only). | |
1537 static symbol_table *instance; | |
3011 | 1538 |
7336 | 1539 // Map from scope id to symbol table instances. |
1540 static std::map<scope_id, symbol_table*> all_instances; | |
1541 | |
1542 // Map from function names to function info (subfunctions, private | |
1543 // functions, class constructors, class methods, etc.) | |
1544 static std::map<std::string, fcn_info> fcn_table; | |
1545 | |
1546 static const scope_id xglobal_scope; | |
1547 static const scope_id xtop_scope; | |
1548 | |
1549 static scope_id xcurrent_scope; | |
1550 static scope_id xcurrent_caller_scope; | |
1551 | |
1552 // We use parent_scope to handle parsing subfunctions. | |
1553 static scope_id xparent_scope; | |
1554 | |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1555 // Used to handle recursive calls. |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1556 context_id xcurrent_context_this_table; |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1557 static context_id xcurrent_context; |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1558 |
7336 | 1559 static std::deque<scope_id> scope_stack; |
1560 | |
1561 // The next available scope ID. | |
1562 static scope_id next_available_scope; | |
1563 | |
1564 // The set of scope IDs that are currently allocated. | |
1565 static std::set<scope_id> scope_ids_in_use; | |
1566 | |
1567 // The set of scope IDs that are currently available. | |
1568 static std::set<scope_id> scope_ids_free_list; | |
1569 | |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1570 symbol_table (void) : table (), xcurrent_context_this_table () { } |
7336 | 1571 |
1572 ~symbol_table (void) { } | |
3011 | 1573 |
7336 | 1574 static void free_scope (scope_id scope) |
1575 { | |
1576 if (scope == xglobal_scope || scope == xtop_scope) | |
1577 error ("can't free global or top-level scopes!"); | |
1578 else | |
1579 { | |
1580 scope_ids_in_use_iterator p = scope_ids_in_use.find (scope); | |
1581 | |
1582 if (p != scope_ids_in_use.end ()) | |
1583 { | |
1584 scope_ids_in_use.erase (p); | |
1585 scope_ids_free_list.insert (*p); | |
1586 } | |
1587 else | |
1588 error ("scope id = %ld not found!", scope); | |
1589 } | |
1590 } | |
1591 | |
1592 static symbol_table *get_instance (scope_id scope) | |
1593 { | |
1594 symbol_table *retval = 0; | |
1595 | |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1596 if (scope != xglobal_scope) |
7336 | 1597 { |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1598 if (scope == xcurrent_scope) |
7336 | 1599 { |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1600 if (! instance) |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1601 { |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1602 instance = new symbol_table (); |
7336 | 1603 |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1604 all_instances[scope] = instance; |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1605 } |
7336 | 1606 |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1607 if (! instance) |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1608 error ("unable to create symbol_table object!"); |
7336 | 1609 |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1610 retval = instance; |
7336 | 1611 } |
1612 else | |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1613 { |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1614 all_instances_iterator p = all_instances.find (scope); |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1615 |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1616 if (p == all_instances.end ()) |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1617 { |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1618 retval = new symbol_table (); |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1619 |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1620 all_instances[scope] = retval; |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1621 } |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1622 else |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1623 retval = p->second; |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1624 } |
7336 | 1625 } |
1626 | |
1627 return retval; | |
1628 } | |
1629 | |
1630 void insert_symbol_record (const symbol_record& sr) | |
1631 { | |
1632 table[sr.name ()] = sr; | |
1633 } | |
4238 | 1634 |
4913 | 1635 void |
7336 | 1636 do_dup_scope (symbol_table& new_symbol_table) const |
1637 { | |
1638 for (const_table_iterator p = table.begin (); p != table.end (); p++) | |
1639 new_symbol_table.insert_symbol_record (p->second.dup ()); | |
1640 } | |
1641 | |
1642 symbol_record do_find_symbol (const std::string& name) | |
1643 { | |
1644 table_iterator p = table.find (name); | |
1645 | |
1646 if (p == table.end ()) | |
1647 return do_insert (name); | |
1648 else | |
1649 return p->second; | |
1650 } | |
1651 | |
1652 void do_inherit (scope_id donor_scope) | |
1653 { | |
1654 for (table_iterator p = table.begin (); p != table.end (); p++) | |
1655 { | |
1656 symbol_record& sr = p->second; | |
1657 | |
1658 std::string nm = sr.name (); | |
1659 | |
1660 if (! (sr.is_automatic () || sr.is_formal () || nm == "__retval__")) | |
1661 { | |
1662 octave_value val = symbol_table::varval (nm, donor_scope); | |
1663 | |
1664 if (val.is_defined ()) | |
1665 { | |
1666 sr.varref () = val; | |
1667 | |
1668 sr.mark_inherited (); | |
1669 } | |
1670 } | |
1671 } | |
1672 } | |
1673 | |
1674 octave_value | |
1675 do_find (const std::string& name, tree_argument_list *args, | |
1676 const string_vector& arg_names, | |
1677 octave_value_list& evaluated_args, bool& args_evaluated, | |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1678 bool skip_variables); |
7336 | 1679 |
1680 symbol_record& do_insert (const std::string& name) | |
1681 { | |
1682 table_iterator p = table.find (name); | |
1683 | |
1684 return p == table.end () | |
1685 ? (table[name] = symbol_record (name)) : p->second; | |
1686 } | |
1687 | |
1688 octave_value& do_varref (const std::string& name) | |
1689 { | |
1690 table_iterator p = table.find (name); | |
1691 | |
1692 if (p == table.end ()) | |
1693 { | |
1694 symbol_record& sr = do_insert (name); | |
1695 | |
1696 return sr.varref (); | |
1697 } | |
1698 else | |
1699 return p->second.varref (); | |
1700 } | |
4913 | 1701 |
7336 | 1702 octave_value do_varval (const std::string& name) const |
1703 { | |
1704 const_table_iterator p = table.find (name); | |
1705 | |
1706 return (p != table.end ()) ? p->second.varval () : octave_value (); | |
1707 } | |
1708 | |
1709 octave_value& do_persistent_varref (const std::string& name) | |
1710 { | |
1711 persistent_table_iterator p = persistent_table.find (name); | |
1712 | |
1713 return (p == persistent_table.end ()) | |
1714 ? persistent_table[name] : p->second; | |
1715 } | |
1716 | |
1717 octave_value do_persistent_varval (const std::string& name) | |
1718 { | |
1719 const_persistent_table_iterator p = persistent_table.find (name); | |
1720 | |
1721 return (p != persistent_table.end ()) ? p->second : octave_value (); | |
1722 } | |
1723 | |
1724 void do_erase_persistent (const std::string& name) | |
1725 { | |
1726 persistent_table_iterator p = persistent_table.find (name); | |
1727 | |
1728 if (p != persistent_table.end ()) | |
1729 persistent_table.erase (p); | |
1730 } | |
1731 | |
1732 bool do_is_variable (const std::string& name) const | |
1733 { | |
1734 bool retval = false; | |
1735 | |
1736 const_table_iterator p = table.find (name); | |
1737 | |
1738 if (p != table.end ()) | |
1739 { | |
1740 const symbol_record& sr = p->second; | |
1741 | |
1742 retval = sr.is_variable (); | |
1743 } | |
1744 | |
1745 return retval; | |
1746 } | |
1747 | |
1748 void do_push_context (void) | |
1749 { | |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1750 xcurrent_context = ++xcurrent_context_this_table; |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1751 |
7336 | 1752 for (table_iterator p = table.begin (); p != table.end (); p++) |
1753 p->second.push_context (); | |
1754 } | |
1755 | |
1756 void do_pop_context (void) | |
1757 { | |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1758 xcurrent_context = --xcurrent_context_this_table; |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1759 |
7374 | 1760 for (table_iterator p = table.begin (); p != table.end (); ) |
1761 { | |
1762 if (p->second.pop_context () == 0) | |
1763 table.erase (p++); | |
1764 else | |
1765 p++; | |
1766 } | |
7336 | 1767 } |
1768 | |
1769 void do_clear_variables (void) | |
1770 { | |
1771 for (table_iterator p = table.begin (); p != table.end (); p++) | |
1772 p->second.clear (); | |
1773 } | |
1774 | |
1775 void do_clear_global (const std::string& name) | |
1776 { | |
1777 table_iterator p = table.find (name); | |
4913 | 1778 |
7336 | 1779 if (p != table.end ()) |
1780 { | |
1781 symbol_record& sr = p->second; | |
1782 | |
1783 if (sr.is_global ()) | |
1784 { | |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1785 global_table_iterator q = global_table.find (name); |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1786 |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1787 if (q != global_table.end ()) |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1788 global_table.erase (q); |
7336 | 1789 |
1790 sr.unmark_global (); | |
1791 } | |
1792 } | |
1793 } | |
1794 | |
1795 void do_clear_variable (const std::string& name) | |
1796 { | |
1797 table_iterator p = table.find (name); | |
1798 | |
1799 if (p != table.end ()) | |
1800 p->second.clear (); | |
1801 } | |
1802 | |
1803 void do_clear_global_pattern (const std::string& pat) | |
1804 { | |
1805 glob_match pattern (pat); | |
1806 | |
1807 for (table_iterator p = table.begin (); p != table.end (); p++) | |
1808 { | |
1809 symbol_record& sr = p->second; | |
8 | 1810 |
7336 | 1811 if (sr.is_global ()) |
1812 { | |
1813 if (pattern.match (sr.name ())) | |
1814 { | |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1815 global_table_iterator q = global_table.find (sr.name ()); |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1816 |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1817 if (q != global_table.end ()) |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1818 global_table.erase (q); |
7336 | 1819 |
1820 sr.unmark_global (); | |
1821 } | |
1822 } | |
1823 } | |
1824 } | |
1825 | |
1826 void do_clear_variable_pattern (const std::string& pat) | |
1827 { | |
1828 glob_match pattern (pat); | |
1829 | |
1830 for (table_iterator p = table.begin (); p != table.end (); p++) | |
1831 { | |
1832 symbol_record& sr = p->second; | |
1833 | |
1834 if (sr.is_defined () || sr.is_global ()) | |
1835 { | |
1836 if (pattern.match (sr.name ())) | |
1837 sr.clear (); | |
1838 } | |
1839 } | |
1840 } | |
1841 | |
1842 void do_mark_hidden (const std::string& name) | |
1843 { | |
1844 table_iterator p = table.find (name); | |
1845 | |
1846 if (p != table.end ()) | |
1847 p->second.mark_hidden (); | |
1848 } | |
1849 | |
1850 void do_mark_global (const std::string& name) | |
1851 { | |
1852 table_iterator p = table.find (name); | |
8 | 1853 |
7336 | 1854 if (p != table.end ()) |
1855 p->second.mark_global (); | |
1856 } | |
1857 | |
1858 std::list<symbol_record> do_all_variables (bool defined_only) const | |
1859 { | |
1860 std::list<symbol_record> retval; | |
1861 | |
1862 for (const_table_iterator p = table.begin (); p != table.end (); p++) | |
1863 { | |
1864 const symbol_record& sr = p->second; | |
1865 | |
1866 if (defined_only && ! sr.is_defined ()) | |
1867 continue; | |
1868 | |
1869 retval.push_back (sr); | |
1870 } | |
1871 | |
1872 return retval; | |
1873 } | |
1874 | |
1875 std::list<symbol_record> do_glob (const std::string& pattern, | |
1876 bool vars_only = false) const | |
1877 { | |
1878 std::list<symbol_record> retval; | |
1879 | |
1880 glob_match pat (pattern); | |
1881 | |
1882 for (const_table_iterator p = table.begin (); p != table.end (); p++) | |
1883 { | |
1884 if (pat.match (p->first)) | |
1885 { | |
1886 const symbol_record& sr = p->second; | |
1962 | 1887 |
7336 | 1888 if (vars_only && ! sr.is_variable ()) |
1889 continue; | |
1890 | |
1891 retval.push_back (sr); | |
1892 } | |
1893 } | |
1894 | |
1895 return retval; | |
1896 } | |
1897 | |
1898 std::list<std::string> do_variable_names (void) | |
1899 { | |
1900 std::list<std::string> retval; | |
1901 | |
1902 for (const_table_iterator p = table.begin (); p != table.end (); p++) | |
1903 retval.push_back (p->first); | |
1904 | |
1905 retval.sort (); | |
1906 | |
1907 return retval; | |
1908 } | |
1909 | |
1910 bool do_is_local_variable (const std::string& name) const | |
1911 { | |
1912 const_table_iterator p = table.find (name); | |
1913 | |
1914 return (p != table.end () | |
1915 && ! p->second.is_global () | |
1916 && p->second.is_defined ()); | |
1917 } | |
1918 | |
1919 bool do_is_global (const std::string& name) const | |
1920 { | |
1921 const_table_iterator p = table.find (name); | |
1922 | |
1923 return p != table.end () && p->second.is_global (); | |
1924 } | |
3011 | 1925 }; |
2790 | 1926 |
7336 | 1927 extern bool out_of_date_check (octave_value& function); |
4913 | 1928 |
8 | 1929 #endif |
1930 | |
1931 /* | |
1932 ;;; Local Variables: *** | |
1933 ;;; mode: C++ *** | |
1934 ;;; End: *** | |
1935 */ |