Mercurial > hg > octave-nkf
annotate src/symtab.h @ 12307:3dc4cfc5a3c1 release-3-4-x
Use pattern-style rules to make .texi files rather than older suffix-style rules.
author | Rik <octave@nomad.inbox5.com> |
---|---|
date | Sun, 30 Jan 2011 22:44:52 -0800 |
parents | 3229572cbe23 |
children | d6151d774283 |
rev | line source |
---|---|
8 | 1 /* |
2 | |
11523 | 3 Copyright (C) 1993-2011 John W. Eaton |
10521
4d1fc073fbb7
add some missing copyright stmts
Jaroslav Hajek <highegg@gmail.com>
parents:
10321
diff
changeset
|
4 Copyright (C) 2009 VZLU Prague |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11584
diff
changeset
|
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" |
7779
791231dac333
Add regexp matching to Fwho and Fclear
David Bateman <dbateman@free.fr>
parents:
7767
diff
changeset
|
34 #include "regex-match.h" |
2846 | 35 |
7336 | 36 class tree_argument_list; |
9639
8d79f36ebdde
store scope->function pointer
Jaroslav Hajek <highegg@gmail.com>
parents:
9581
diff
changeset
|
37 class octave_user_function; |
3013 | 38 |
7336 | 39 #include "oct-obj.h" |
40 #include "ov.h" | |
1412 | 41 |
8 | 42 class |
6109 | 43 OCTINTERP_API |
8 | 44 symbol_table |
45 { | |
46 public: | |
47 | |
7336 | 48 typedef int scope_id; |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
49 typedef size_t context_id; |
7336 | 50 |
51 class | |
7761
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
52 scope_id_cache |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
53 { |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
54 protected: |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
55 |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
56 typedef std::set<scope_id>::iterator set_iterator; |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
57 typedef std::set<scope_id>::const_iterator set_const_iterator; |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
58 |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
59 // We start with 2 because we allocate 0 for the global symbols |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
60 // and 1 for the top-level workspace. |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
61 |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
62 scope_id_cache (void) : next_available (2), in_use (), free_list () { } |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
63 |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
64 public: |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
65 |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
66 ~scope_id_cache (void) { } |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
67 |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
68 static scope_id alloc (void) |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
69 { |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
70 return instance_ok () ? instance->do_alloc () : -1; |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
71 } |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
72 |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
73 static void free (scope_id scope) |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
74 { |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
75 if (instance_ok ()) |
10313 | 76 return instance->do_free (scope); |
7761
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
77 } |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
78 |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
79 static std::list<scope_id> scopes (void) |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
80 { |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
81 return instance_ok () ? instance->do_scopes () : std::list<scope_id> (); |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
82 } |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
83 |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
84 static bool instance_ok (void) |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
85 { |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
86 bool retval = true; |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
87 |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
88 if (! instance) |
10313 | 89 instance = new scope_id_cache (); |
7761
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
90 |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
91 if (! instance) |
10313 | 92 { |
93 ::error ("unable to create scope_id_cache object!"); | |
94 | |
95 retval = false; | |
96 } | |
7761
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
97 |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
98 return retval; |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
99 } |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
100 |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
101 private: |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
102 |
12122
f4689107dd8c
Explicitly disallow copying in some classes.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
11586
diff
changeset
|
103 // No copying! |
f4689107dd8c
Explicitly disallow copying in some classes.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
11586
diff
changeset
|
104 |
f4689107dd8c
Explicitly disallow copying in some classes.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
11586
diff
changeset
|
105 scope_id_cache (const scope_id_cache&); |
f4689107dd8c
Explicitly disallow copying in some classes.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
11586
diff
changeset
|
106 |
f4689107dd8c
Explicitly disallow copying in some classes.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
11586
diff
changeset
|
107 scope_id_cache& operator = (const scope_id_cache&); |
f4689107dd8c
Explicitly disallow copying in some classes.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
11586
diff
changeset
|
108 |
7761
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
109 static scope_id_cache *instance; |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
110 |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
111 // The next available scope not in the free list. |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
112 scope_id next_available; |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
113 |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
114 // The set of scope IDs that are currently allocated. |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
115 std::set<scope_id> in_use; |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
116 |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
117 // The set of scope IDs that are currently available. |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
118 std::set<scope_id> free_list; |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
119 |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
120 scope_id do_alloc (void) |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
121 { |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
122 scope_id retval; |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
123 |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
124 set_iterator p = free_list.begin (); |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
125 |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
126 if (p != free_list.end ()) |
10313 | 127 { |
128 retval = *p; | |
129 free_list.erase (p); | |
130 } | |
7761
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
131 else |
10313 | 132 retval = next_available++; |
7761
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
133 |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
134 in_use.insert (retval); |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
135 |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
136 return retval; |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
137 } |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
138 |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
139 void do_free (scope_id scope) |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
140 { |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
141 set_iterator p = in_use.find (scope); |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
142 |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
143 if (p != in_use.end ()) |
10313 | 144 { |
145 in_use.erase (p); | |
146 free_list.insert (scope); | |
147 } | |
7761
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
148 else |
10313 | 149 error ("free_scope: scope %d not found!", scope); |
7761
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
150 } |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
151 |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
152 std::list<scope_id> do_scopes (void) const |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
153 { |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
154 std::list<scope_id> retval; |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
155 |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
156 for (set_const_iterator p = in_use.begin (); p != in_use.end (); p++) |
10313 | 157 retval.push_back (*p); |
7761
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
158 |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
159 retval.sort (); |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
160 |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
161 return retval; |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
162 } |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
163 }; |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
164 |
9413
5cd879a0d8c4
speed-up function call by caching its name lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
9409
diff
changeset
|
165 class fcn_info; |
5cd879a0d8c4
speed-up function call by caching its name lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
9409
diff
changeset
|
166 |
7761
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
167 class |
7336 | 168 symbol_record |
169 { | |
170 public: | |
171 | |
172 // generic variable | |
173 static const unsigned int local = 1; | |
174 | |
175 // varargin, argn, .nargin., .nargout. | |
176 // (FIXME -- is this really used now?) | |
177 static const unsigned int automatic = 2; | |
178 | |
179 // formal parameter | |
180 static const unsigned int formal = 4; | |
181 | |
182 // not listed or cleared (.nargin., .nargout.) | |
183 static const unsigned int hidden = 8; | |
184 | |
185 // inherited from parent scope; not cleared at function exit | |
186 static const unsigned int inherited = 16; | |
187 | |
188 // global (redirects to global scope) | |
189 static const unsigned int global = 32; | |
190 | |
191 // not cleared at function exit | |
192 static const unsigned int persistent = 64; | |
193 | |
8881
8ed42c679af5
after defining a script or function, clear local variables created for parsing
John W. Eaton <jwe@octave.org>
parents:
8819
diff
changeset
|
194 // temporary variables forced into symbol table for parsing |
8ed42c679af5
after defining a script or function, clear local variables created for parsing
John W. Eaton <jwe@octave.org>
parents:
8819
diff
changeset
|
195 static const unsigned int forced = 128; |
8ed42c679af5
after defining a script or function, clear local variables created for parsing
John W. Eaton <jwe@octave.org>
parents:
8819
diff
changeset
|
196 |
7336 | 197 private: |
198 | |
199 class | |
200 symbol_record_rep | |
4009 | 201 { |
7336 | 202 public: |
203 | |
204 symbol_record_rep (const std::string& nm, const octave_value& v, | |
10313 | 205 unsigned int sc) |
206 : name (nm), value_stack (), storage_class (sc), finfo (), count (1) | |
7336 | 207 { |
10313 | 208 value_stack.push_back (v); |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
209 } |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
210 |
8881
8ed42c679af5
after defining a script or function, clear local variables created for parsing
John W. Eaton <jwe@octave.org>
parents:
8819
diff
changeset
|
211 void force_variable (context_id context) |
8ed42c679af5
after defining a script or function, clear local variables created for parsing
John W. Eaton <jwe@octave.org>
parents:
8819
diff
changeset
|
212 { |
10313 | 213 octave_value& val = varref (context); |
214 | |
215 if (! val.is_defined ()) | |
216 mark_forced (); | |
8881
8ed42c679af5
after defining a script or function, clear local variables created for parsing
John W. Eaton <jwe@octave.org>
parents:
8819
diff
changeset
|
217 } |
8ed42c679af5
after defining a script or function, clear local variables created for parsing
John W. Eaton <jwe@octave.org>
parents:
8819
diff
changeset
|
218 |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7761
diff
changeset
|
219 octave_value& varref (context_id context) |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
220 { |
10313 | 221 if (is_global ()) |
222 return symbol_table::global_varref (name); | |
223 else if (is_persistent ()) | |
224 return symbol_table::persistent_varref (name); | |
225 else | |
226 { | |
227 context_id n = value_stack.size (); | |
228 while (n++ <= context) | |
229 value_stack.push_back (octave_value ()); | |
230 | |
231 return value_stack[context]; | |
232 } | |
7336 | 233 } |
234 | |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7761
diff
changeset
|
235 octave_value varval (context_id context) const |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
236 { |
10313 | 237 if (is_global ()) |
238 return symbol_table::global_varval (name); | |
239 else if (is_persistent ()) | |
240 return symbol_table::persistent_varval (name); | |
241 else | |
242 { | |
243 if (context < value_stack.size ()) | |
244 return value_stack[context]; | |
245 else | |
246 return octave_value (); | |
247 } | |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
248 } |
7336 | 249 |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
250 void push_context (void) |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
251 { |
10313 | 252 if (! (is_persistent () || is_global ())) |
253 value_stack.push_back (octave_value ()); | |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
254 } |
7336 | 255 |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
256 // 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
|
257 // 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
|
258 // functions like |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
259 // |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
260 // function foo (n) |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
261 // if (n > 0) |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
262 // foo (n-1); |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
263 // else |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
264 // eval ("x = 1"); |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
265 // endif |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
266 // endfunction |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
267 // |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
268 // Here, X should only exist in the final stack frame. |
7336 | 269 |
7374 | 270 size_t pop_context (void) |
271 { | |
10313 | 272 size_t retval = 1; |
273 | |
274 if (! (is_persistent () || is_global ())) | |
275 { | |
276 value_stack.pop_back (); | |
277 retval = value_stack.size (); | |
278 } | |
279 | |
280 return retval; | |
7374 | 281 } |
7336 | 282 |
283 void clear (void) | |
284 { | |
10313 | 285 if (! (is_hidden () || is_inherited ())) |
286 { | |
287 if (is_global ()) | |
288 unmark_global (); | |
289 | |
290 if (is_persistent ()) | |
291 { | |
292 symbol_table::persistent_varref (name) | |
293 = varval (xcurrent_context); | |
294 | |
295 unmark_persistent (); | |
296 } | |
297 | |
298 varref (xcurrent_context) = octave_value (); | |
299 } | |
7336 | 300 } |
301 | |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7761
diff
changeset
|
302 bool is_defined (context_id context) const |
7336 | 303 { |
10313 | 304 return varval (context).is_defined (); |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7761
diff
changeset
|
305 } |
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7761
diff
changeset
|
306 |
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7761
diff
changeset
|
307 bool is_variable (context_id context) const |
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7761
diff
changeset
|
308 { |
10313 | 309 return (! is_local () || is_defined (context) || is_forced ()); |
7336 | 310 } |
311 | |
312 bool is_local (void) const { return storage_class & local; } | |
313 bool is_automatic (void) const { return storage_class & automatic; } | |
314 bool is_formal (void) const { return storage_class & formal; } | |
315 bool is_hidden (void) const { return storage_class & hidden; } | |
316 bool is_inherited (void) const { return storage_class & inherited; } | |
317 bool is_global (void) const { return storage_class & global; } | |
318 bool is_persistent (void) const { return storage_class & persistent; } | |
8881
8ed42c679af5
after defining a script or function, clear local variables created for parsing
John W. Eaton <jwe@octave.org>
parents:
8819
diff
changeset
|
319 bool is_forced (void) const { return storage_class & forced; } |
7336 | 320 |
321 void mark_local (void) { storage_class |= local; } | |
322 void mark_automatic (void) { storage_class |= automatic; } | |
323 void mark_formal (void) { storage_class |= formal; } | |
324 void mark_hidden (void) { storage_class |= hidden; } | |
325 void mark_inherited (void) { storage_class |= inherited; } | |
326 void mark_global (void) | |
327 { | |
10313 | 328 if (is_persistent ()) |
329 error ("can't make persistent variable %s global", name.c_str ()); | |
330 else | |
331 storage_class |= global; | |
7336 | 332 } |
333 void mark_persistent (void) | |
334 { | |
10313 | 335 if (is_global ()) |
336 error ("can't make global variable %s persistent", name.c_str ()); | |
337 else | |
338 storage_class |= persistent; | |
7336 | 339 } |
8881
8ed42c679af5
after defining a script or function, clear local variables created for parsing
John W. Eaton <jwe@octave.org>
parents:
8819
diff
changeset
|
340 void mark_forced (void) { storage_class |= forced; } |
7336 | 341 |
342 void unmark_local (void) { storage_class &= ~local; } | |
343 void unmark_automatic (void) { storage_class &= ~automatic; } | |
344 void unmark_formal (void) { storage_class &= ~formal; } | |
345 void unmark_hidden (void) { storage_class &= ~hidden; } | |
346 void unmark_inherited (void) { storage_class &= ~inherited; } | |
347 void unmark_global (void) { storage_class &= ~global; } | |
348 void unmark_persistent (void) { storage_class &= ~persistent; } | |
8881
8ed42c679af5
after defining a script or function, clear local variables created for parsing
John W. Eaton <jwe@octave.org>
parents:
8819
diff
changeset
|
349 void unmark_forced (void) { storage_class &= ~forced; } |
7336 | 350 |
351 void init_persistent (void) | |
352 { | |
10313 | 353 if (! is_defined (xcurrent_context)) |
354 { | |
355 mark_persistent (); | |
356 | |
357 varref (xcurrent_context) = symbol_table::persistent_varval (name); | |
358 } | |
359 // FIXME -- this causes trouble with recursive calls. | |
360 // else | |
361 // error ("unable to declare existing variable persistent"); | |
7336 | 362 } |
363 | |
364 void erase_persistent (void) | |
365 { | |
10313 | 366 unmark_persistent (); |
367 symbol_table::erase_persistent (name); | |
7336 | 368 } |
369 | |
8906
ab87d08d9a1b
improve symbol inheritance for anonymous functions
John W. Eaton <jwe@octave.org>
parents:
8884
diff
changeset
|
370 symbol_record_rep *dup (void) const |
7336 | 371 { |
10313 | 372 return new symbol_record_rep (name, varval (xcurrent_context), |
373 storage_class); | |
7336 | 374 } |
375 | |
7761
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
376 void dump (std::ostream& os, const std::string& prefix) const; |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
377 |
7336 | 378 std::string name; |
379 | |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
380 std::deque<octave_value> value_stack; |
7336 | 381 |
382 unsigned int storage_class; | |
383 | |
9413
5cd879a0d8c4
speed-up function call by caching its name lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
9409
diff
changeset
|
384 fcn_info *finfo; |
5cd879a0d8c4
speed-up function call by caching its name lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
9409
diff
changeset
|
385 |
7336 | 386 size_t count; |
387 | |
388 private: | |
389 | |
390 // No copying! | |
391 | |
392 symbol_record_rep (const symbol_record_rep& ov); | |
393 | |
394 symbol_record_rep& operator = (const symbol_record_rep&); | |
395 }; | |
396 | |
397 public: | |
398 | |
399 symbol_record (const std::string& nm = std::string (), | |
10313 | 400 const octave_value& v = octave_value (), |
401 unsigned int sc = local) | |
7336 | 402 : rep (new symbol_record_rep (nm, v, sc)) { } |
403 | |
404 symbol_record (const symbol_record& sr) | |
405 : rep (sr.rep) | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11584
diff
changeset
|
406 { |
7336 | 407 rep->count++; |
408 } | |
409 | |
410 symbol_record& operator = (const symbol_record& sr) | |
411 { | |
412 if (this != &sr) | |
10313 | 413 { |
414 if (--rep->count == 0) | |
415 delete rep; | |
416 | |
417 rep = sr.rep; | |
418 rep->count++; | |
419 } | |
7336 | 420 |
421 return *this; | |
422 } | |
423 | |
424 ~symbol_record (void) | |
425 { | |
426 if (--rep->count == 0) | |
10313 | 427 delete rep; |
7336 | 428 } |
429 | |
430 symbol_record dup (void) const { return symbol_record (rep->dup ()); } | |
431 | |
432 std::string name (void) const { return rep->name; } | |
433 | |
9445
c5f03874ea2a
simplify symbol_table::find and associated functions
Jaroslav Hajek <highegg@gmail.com>
parents:
9444
diff
changeset
|
434 octave_value find (const octave_value_list& args = octave_value_list ()) const; |
7336 | 435 |
8881
8ed42c679af5
after defining a script or function, clear local variables created for parsing
John W. Eaton <jwe@octave.org>
parents:
8819
diff
changeset
|
436 void force_variable (context_id context = xcurrent_context) |
8ed42c679af5
after defining a script or function, clear local variables created for parsing
John W. Eaton <jwe@octave.org>
parents:
8819
diff
changeset
|
437 { |
8ed42c679af5
after defining a script or function, clear local variables created for parsing
John W. Eaton <jwe@octave.org>
parents:
8819
diff
changeset
|
438 rep->force_variable (context); |
8ed42c679af5
after defining a script or function, clear local variables created for parsing
John W. Eaton <jwe@octave.org>
parents:
8819
diff
changeset
|
439 } |
8ed42c679af5
after defining a script or function, clear local variables created for parsing
John W. Eaton <jwe@octave.org>
parents:
8819
diff
changeset
|
440 |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7761
diff
changeset
|
441 octave_value& varref (context_id context = xcurrent_context) |
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7761
diff
changeset
|
442 { |
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7761
diff
changeset
|
443 return rep->varref (context); |
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7761
diff
changeset
|
444 } |
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7761
diff
changeset
|
445 |
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7761
diff
changeset
|
446 octave_value varval (context_id context = xcurrent_context) const |
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7761
diff
changeset
|
447 { |
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7761
diff
changeset
|
448 return rep->varval (context); |
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7761
diff
changeset
|
449 } |
7336 | 450 |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
451 void push_context (void) { rep->push_context (); } |
7336 | 452 |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
453 size_t pop_context (void) { return rep->pop_context (); } |
7336 | 454 |
455 void clear (void) { rep->clear (); } | |
456 | |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7761
diff
changeset
|
457 bool is_defined (context_id context = xcurrent_context) const |
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7761
diff
changeset
|
458 { |
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7761
diff
changeset
|
459 return rep->is_defined (context); |
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7761
diff
changeset
|
460 } |
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7761
diff
changeset
|
461 |
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7761
diff
changeset
|
462 bool is_variable (context_id context = xcurrent_context) const |
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7761
diff
changeset
|
463 { |
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7761
diff
changeset
|
464 return rep->is_variable (context); |
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7761
diff
changeset
|
465 } |
7336 | 466 |
467 bool is_local (void) const { return rep->is_local (); } | |
468 bool is_automatic (void) const { return rep->is_automatic (); } | |
469 bool is_formal (void) const { return rep->is_formal (); } | |
470 bool is_global (void) const { return rep->is_global (); } | |
471 bool is_hidden (void) const { return rep->is_hidden (); } | |
472 bool is_inherited (void) const { return rep->is_inherited (); } | |
473 bool is_persistent (void) const { return rep->is_persistent (); } | |
8881
8ed42c679af5
after defining a script or function, clear local variables created for parsing
John W. Eaton <jwe@octave.org>
parents:
8819
diff
changeset
|
474 bool is_forced (void) const { return rep->is_forced (); } |
7336 | 475 |
476 void mark_local (void) { rep->mark_local (); } | |
477 void mark_automatic (void) { rep->mark_automatic (); } | |
478 void mark_formal (void) { rep->mark_formal (); } | |
479 void mark_hidden (void) { rep->mark_hidden (); } | |
480 void mark_inherited (void) { rep->mark_inherited (); } | |
481 void mark_global (void) { rep->mark_global (); } | |
482 void mark_persistent (void) { rep->mark_persistent (); } | |
8881
8ed42c679af5
after defining a script or function, clear local variables created for parsing
John W. Eaton <jwe@octave.org>
parents:
8819
diff
changeset
|
483 void mark_forced (void) { rep->mark_forced (); } |
7336 | 484 |
485 void unmark_local (void) { rep->unmark_local (); } | |
486 void unmark_automatic (void) { rep->unmark_automatic (); } | |
487 void unmark_formal (void) { rep->unmark_formal (); } | |
488 void unmark_hidden (void) { rep->unmark_hidden (); } | |
489 void unmark_inherited (void) { rep->unmark_inherited (); } | |
490 void unmark_global (void) { rep->unmark_global (); } | |
491 void unmark_persistent (void) { rep->unmark_persistent (); } | |
8881
8ed42c679af5
after defining a script or function, clear local variables created for parsing
John W. Eaton <jwe@octave.org>
parents:
8819
diff
changeset
|
492 void unmark_forced (void) { rep->unmark_forced (); } |
7336 | 493 |
494 void init_persistent (void) { rep->init_persistent (); } | |
495 | |
496 void erase_persistent (void) { rep->erase_persistent (); } | |
497 | |
498 unsigned int xstorage_class (void) const { return rep->storage_class; } | |
499 | |
7761
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
500 void |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
501 dump (std::ostream& os, const std::string& prefix = std::string ()) const |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
502 { |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
503 rep->dump (os, prefix); |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
504 } |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
505 |
7336 | 506 private: |
507 | |
508 symbol_record_rep *rep; | |
509 | |
510 symbol_record (symbol_record_rep *new_rep) : rep (new_rep) { } | |
511 }; | |
512 | |
513 class | |
514 fcn_info | |
515 { | |
516 public: | |
517 | |
518 typedef std::map<std::string, std::string> dispatch_map_type; | |
519 | |
7761
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
520 typedef std::map<scope_id, octave_value>::const_iterator scope_val_const_iterator; |
7336 | 521 typedef std::map<scope_id, octave_value>::iterator scope_val_iterator; |
4238 | 522 |
7761
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
523 typedef std::map<std::string, octave_value>::const_iterator str_val_const_iterator; |
7336 | 524 typedef std::map<std::string, octave_value>::iterator str_val_iterator; |
525 | |
7761
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
526 typedef dispatch_map_type::const_iterator dispatch_map_const_iterator; |
7336 | 527 typedef dispatch_map_type::iterator dispatch_map_iterator; |
528 | |
529 private: | |
530 | |
531 class | |
532 fcn_info_rep | |
533 { | |
534 public: | |
535 | |
536 fcn_info_rep (const std::string& nm) | |
10313 | 537 : name (nm), subfunctions (), private_functions (), |
11584
cda4aa780d58
Another round of initialising members in the constructor initialisation list
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
11557
diff
changeset
|
538 class_constructors (), class_methods (), dispatch_map (), |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11584
diff
changeset
|
539 cmdline_function (), autoload_function (), function_on_path (), |
11584
cda4aa780d58
Another round of initialising members in the constructor initialisation list
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
11557
diff
changeset
|
540 built_in_function (), count (1) { } |
7336 | 541 |
542 octave_value load_private_function (const std::string& dir_name); | |
543 | |
544 octave_value load_class_constructor (void); | |
545 | |
546 octave_value load_class_method (const std::string& dispatch_type); | |
547 | |
9463
d34baf412786
support non-local function lookups in str2func
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
548 octave_value find (const octave_value_list& args, bool local_funcs); |
7336 | 549 |
9444
0c785ad961fa
improve behavior of builtin
John W. Eaton <jwe@octave.org>
parents:
9443
diff
changeset
|
550 octave_value builtin_find (void); |
0c785ad961fa
improve behavior of builtin
John W. Eaton <jwe@octave.org>
parents:
9443
diff
changeset
|
551 |
7336 | 552 octave_value find_method (const std::string& dispatch_type); |
553 | |
554 octave_value find_autoload (void); | |
555 | |
556 octave_value find_user_function (void); | |
557 | |
558 bool is_user_function_defined (void) const | |
559 { | |
10313 | 560 return function_on_path.is_defined (); |
7336 | 561 } |
562 | |
9463
d34baf412786
support non-local function lookups in str2func
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
563 octave_value find_function (const octave_value_list& args, bool local_funcs) |
7336 | 564 { |
10313 | 565 return find (args, local_funcs); |
7336 | 566 } |
567 | |
7761
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
568 void lock_subfunction (scope_id scope) |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
569 { |
10313 | 570 scope_val_iterator p = subfunctions.find (scope); |
571 | |
572 if (p != subfunctions.end ()) | |
573 p->second.lock (); | |
7761
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
574 } |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
575 |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
576 void unlock_subfunction (scope_id scope) |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
577 { |
10313 | 578 scope_val_iterator p = subfunctions.find (scope); |
579 | |
580 if (p != subfunctions.end ()) | |
581 p->second.unlock (); | |
7761
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
582 } |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
583 |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
584 std::pair<std::string, octave_value> |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
585 subfunction_defined_in_scope (scope_id scope) const |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
586 { |
10313 | 587 scope_val_const_iterator p = subfunctions.find (scope); |
588 | |
589 return p == subfunctions.end () | |
590 ? std::pair<std::string, octave_value> () | |
591 : std::pair<std::string, octave_value> (name, p->second); | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11584
diff
changeset
|
592 } |
7761
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
593 |
7876
8447a5024650
clear subfunctions when clearing parent function
John W. Eaton <jwe@octave.org>
parents:
7779
diff
changeset
|
594 void erase_subfunction (scope_id scope) |
8447a5024650
clear subfunctions when clearing parent function
John W. Eaton <jwe@octave.org>
parents:
7779
diff
changeset
|
595 { |
10313 | 596 scope_val_iterator p = subfunctions.find (scope); |
597 | |
598 if (p != subfunctions.end ()) | |
599 subfunctions.erase (p); | |
7876
8447a5024650
clear subfunctions when clearing parent function
John W. Eaton <jwe@octave.org>
parents:
7779
diff
changeset
|
600 } |
8447a5024650
clear subfunctions when clearing parent function
John W. Eaton <jwe@octave.org>
parents:
7779
diff
changeset
|
601 |
11445
40f311a69417
fix OO field access in subfunctions of private functions
John W. Eaton <jwe@octave.org>
parents:
11238
diff
changeset
|
602 void mark_subfunction_in_scope_as_private (scope_id scope, |
40f311a69417
fix OO field access in subfunctions of private functions
John W. Eaton <jwe@octave.org>
parents:
11238
diff
changeset
|
603 const std::string& class_name); |
40f311a69417
fix OO field access in subfunctions of private functions
John W. Eaton <jwe@octave.org>
parents:
11238
diff
changeset
|
604 |
7336 | 605 void install_cmdline_function (const octave_value& f) |
606 { | |
10313 | 607 cmdline_function = f; |
7336 | 608 } |
609 | |
610 void install_subfunction (const octave_value& f, scope_id scope) | |
611 { | |
10313 | 612 subfunctions[scope] = f; |
7336 | 613 } |
614 | |
615 void install_user_function (const octave_value& f) | |
616 { | |
10313 | 617 function_on_path = f; |
7336 | 618 } |
619 | |
620 void install_built_in_function (const octave_value& f) | |
621 { | |
10313 | 622 built_in_function = f; |
7336 | 623 } |
624 | |
7489
8e4592e49fa7
don't clear locked functions
John W. Eaton <jwe@octave.org>
parents:
7374
diff
changeset
|
625 template <class T> |
8e4592e49fa7
don't clear locked functions
John W. Eaton <jwe@octave.org>
parents:
7374
diff
changeset
|
626 void |
8e4592e49fa7
don't clear locked functions
John W. Eaton <jwe@octave.org>
parents:
7374
diff
changeset
|
627 clear_unlocked (std::map<T, octave_value>& map) |
7336 | 628 { |
10313 | 629 typename std::map<T, octave_value>::iterator p = map.begin (); |
630 | |
631 while (p != map.end ()) | |
632 { | |
633 if (p->second.islocked ()) | |
634 p++; | |
635 else | |
636 map.erase (p++); | |
637 } | |
7489
8e4592e49fa7
don't clear locked functions
John W. Eaton <jwe@octave.org>
parents:
7374
diff
changeset
|
638 } |
8e4592e49fa7
don't clear locked functions
John W. Eaton <jwe@octave.org>
parents:
7374
diff
changeset
|
639 |
8e4592e49fa7
don't clear locked functions
John W. Eaton <jwe@octave.org>
parents:
7374
diff
changeset
|
640 void clear_cmdline_function (void) |
8e4592e49fa7
don't clear locked functions
John W. Eaton <jwe@octave.org>
parents:
7374
diff
changeset
|
641 { |
10313 | 642 if (! cmdline_function.islocked ()) |
643 cmdline_function = octave_value (); | |
7489
8e4592e49fa7
don't clear locked functions
John W. Eaton <jwe@octave.org>
parents:
7374
diff
changeset
|
644 } |
8e4592e49fa7
don't clear locked functions
John W. Eaton <jwe@octave.org>
parents:
7374
diff
changeset
|
645 |
8e4592e49fa7
don't clear locked functions
John W. Eaton <jwe@octave.org>
parents:
7374
diff
changeset
|
646 void clear_autoload_function (void) |
8e4592e49fa7
don't clear locked functions
John W. Eaton <jwe@octave.org>
parents:
7374
diff
changeset
|
647 { |
10313 | 648 if (! autoload_function.islocked ()) |
649 autoload_function = octave_value (); | |
7336 | 650 } |
651 | |
652 // FIXME -- should this also clear the cmdline and other "user | |
653 // defined" functions? | |
654 void clear_user_function (void) | |
655 { | |
10313 | 656 if (! function_on_path.islocked ()) |
657 { | |
658 function_on_path.erase_subfunctions (); | |
659 | |
660 function_on_path = octave_value (); | |
661 } | |
7336 | 662 } |
663 | |
664 void clear_mex_function (void) | |
665 { | |
10313 | 666 if (function_on_path.is_mex_function ()) |
667 clear_user_function (); | |
7489
8e4592e49fa7
don't clear locked functions
John W. Eaton <jwe@octave.org>
parents:
7374
diff
changeset
|
668 } |
8e4592e49fa7
don't clear locked functions
John W. Eaton <jwe@octave.org>
parents:
7374
diff
changeset
|
669 |
8e4592e49fa7
don't clear locked functions
John W. Eaton <jwe@octave.org>
parents:
7374
diff
changeset
|
670 void clear (void) |
8e4592e49fa7
don't clear locked functions
John W. Eaton <jwe@octave.org>
parents:
7374
diff
changeset
|
671 { |
10313 | 672 clear_unlocked (subfunctions); |
673 clear_unlocked (private_functions); | |
674 clear_unlocked (class_constructors); | |
675 clear_unlocked (class_methods); | |
676 clear_cmdline_function (); | |
677 clear_autoload_function (); | |
678 clear_user_function (); | |
7336 | 679 } |
680 | |
681 void add_dispatch (const std::string& type, const std::string& fname) | |
682 { | |
10313 | 683 dispatch_map[type] = fname; |
7336 | 684 } |
685 | |
686 void clear_dispatch (const std::string& type) | |
687 { | |
10313 | 688 dispatch_map_iterator p = dispatch_map.find (type); |
689 | |
690 if (p != dispatch_map.end ()) | |
691 dispatch_map.erase (p); | |
7336 | 692 } |
693 | |
694 void print_dispatch (std::ostream& os) const; | |
695 | |
696 std::string help_for_dispatch (void) const; | |
697 | |
698 dispatch_map_type get_dispatch (void) const { return dispatch_map; } | |
699 | |
7761
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
700 void dump (std::ostream& os, const std::string& prefix) const; |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
701 |
7336 | 702 std::string name; |
703 | |
704 // Scope id to function object. | |
705 std::map<scope_id, octave_value> subfunctions; | |
706 | |
707 // Directory name to function object. | |
708 std::map<std::string, octave_value> private_functions; | |
709 | |
710 // Class name to function object. | |
711 std::map<std::string, octave_value> class_constructors; | |
712 | |
713 // Dispatch type to function object. | |
714 std::map<std::string, octave_value> class_methods; | |
715 | |
716 // Legacy dispatch map (dispatch type name to function name). | |
717 dispatch_map_type dispatch_map; | |
718 | |
719 octave_value cmdline_function; | |
720 | |
721 octave_value autoload_function; | |
722 | |
723 octave_value function_on_path; | |
724 | |
725 octave_value built_in_function; | |
726 | |
727 size_t count; | |
728 | |
729 private: | |
730 | |
9463
d34baf412786
support non-local function lookups in str2func
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
731 octave_value xfind (const octave_value_list& args, bool local_funcs); |
8691
7838271ee25c
symtab.cc (symbol_table::fcn_info::fcn_info_rep::find): avoid recursive call
John W. Eaton <jwe@octave.org>
parents:
8282
diff
changeset
|
732 |
9444
0c785ad961fa
improve behavior of builtin
John W. Eaton <jwe@octave.org>
parents:
9443
diff
changeset
|
733 octave_value x_builtin_find (void); |
0c785ad961fa
improve behavior of builtin
John W. Eaton <jwe@octave.org>
parents:
9443
diff
changeset
|
734 |
7336 | 735 // No copying! |
736 | |
737 fcn_info_rep (const fcn_info_rep&); | |
738 | |
739 fcn_info_rep& operator = (const fcn_info_rep&); | |
740 }; | |
741 | |
742 public: | |
743 | |
744 fcn_info (const std::string& nm = std::string ()) | |
745 : rep (new fcn_info_rep (nm)) { } | |
746 | |
8906
ab87d08d9a1b
improve symbol inheritance for anonymous functions
John W. Eaton <jwe@octave.org>
parents:
8884
diff
changeset
|
747 fcn_info (const fcn_info& fi) : rep (fi.rep) |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11584
diff
changeset
|
748 { |
7336 | 749 rep->count++; |
750 } | |
751 | |
8906
ab87d08d9a1b
improve symbol inheritance for anonymous functions
John W. Eaton <jwe@octave.org>
parents:
8884
diff
changeset
|
752 fcn_info& operator = (const fcn_info& fi) |
7336 | 753 { |
8906
ab87d08d9a1b
improve symbol inheritance for anonymous functions
John W. Eaton <jwe@octave.org>
parents:
8884
diff
changeset
|
754 if (this != &fi) |
10313 | 755 { |
756 if (--rep->count == 0) | |
757 delete rep; | |
758 | |
759 rep = fi.rep; | |
760 rep->count++; | |
761 } | |
7336 | 762 |
763 return *this; | |
764 } | |
765 | |
766 ~fcn_info (void) | |
767 { | |
768 if (--rep->count == 0) | |
10313 | 769 delete rep; |
7336 | 770 } |
771 | |
9463
d34baf412786
support non-local function lookups in str2func
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
772 octave_value find (const octave_value_list& args = octave_value_list (), |
d34baf412786
support non-local function lookups in str2func
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
773 bool local_funcs = true) |
d34baf412786
support non-local function lookups in str2func
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
774 { |
d34baf412786
support non-local function lookups in str2func
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
775 return rep->find (args, local_funcs); |
d34baf412786
support non-local function lookups in str2func
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
776 } |
7336 | 777 |
9444
0c785ad961fa
improve behavior of builtin
John W. Eaton <jwe@octave.org>
parents:
9443
diff
changeset
|
778 octave_value builtin_find (void) |
0c785ad961fa
improve behavior of builtin
John W. Eaton <jwe@octave.org>
parents:
9443
diff
changeset
|
779 { |
0c785ad961fa
improve behavior of builtin
John W. Eaton <jwe@octave.org>
parents:
9443
diff
changeset
|
780 return rep->builtin_find (); |
0c785ad961fa
improve behavior of builtin
John W. Eaton <jwe@octave.org>
parents:
9443
diff
changeset
|
781 } |
0c785ad961fa
improve behavior of builtin
John W. Eaton <jwe@octave.org>
parents:
9443
diff
changeset
|
782 |
7336 | 783 octave_value find_method (const std::string& dispatch_type) const |
784 { | |
785 return rep->find_method (dispatch_type); | |
786 } | |
787 | |
788 octave_value find_built_in_function (void) const | |
789 { | |
790 return rep->built_in_function; | |
791 } | |
792 | |
793 octave_value find_autoload (void) | |
794 { | |
795 return rep->find_autoload (); | |
796 } | |
797 | |
798 octave_value find_user_function (void) | |
799 { | |
800 return rep->find_user_function (); | |
801 } | |
802 | |
803 bool is_user_function_defined (void) const | |
804 { | |
805 return rep->is_user_function_defined (); | |
806 } | |
807 | |
9463
d34baf412786
support non-local function lookups in str2func
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
808 octave_value find_function (const octave_value_list& args = octave_value_list (), |
d34baf412786
support non-local function lookups in str2func
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
809 bool local_funcs = true) |
7336 | 810 { |
9463
d34baf412786
support non-local function lookups in str2func
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
811 return rep->find_function (args, local_funcs); |
7336 | 812 } |
813 | |
7761
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
814 void lock_subfunction (scope_id scope) |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
815 { |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
816 rep->lock_subfunction (scope); |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
817 } |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
818 |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
819 void unlock_subfunction (scope_id scope) |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
820 { |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
821 rep->unlock_subfunction (scope); |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
822 } |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
823 |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
824 std::pair<std::string, octave_value> |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
825 subfunction_defined_in_scope (scope_id scope = xcurrent_scope) const |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
826 { |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
827 return rep->subfunction_defined_in_scope (scope); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11584
diff
changeset
|
828 } |
7761
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
829 |
7876
8447a5024650
clear subfunctions when clearing parent function
John W. Eaton <jwe@octave.org>
parents:
7779
diff
changeset
|
830 void erase_subfunction (scope_id scope) |
8447a5024650
clear subfunctions when clearing parent function
John W. Eaton <jwe@octave.org>
parents:
7779
diff
changeset
|
831 { |
8447a5024650
clear subfunctions when clearing parent function
John W. Eaton <jwe@octave.org>
parents:
7779
diff
changeset
|
832 rep->erase_subfunction (scope); |
8447a5024650
clear subfunctions when clearing parent function
John W. Eaton <jwe@octave.org>
parents:
7779
diff
changeset
|
833 } |
8447a5024650
clear subfunctions when clearing parent function
John W. Eaton <jwe@octave.org>
parents:
7779
diff
changeset
|
834 |
11445
40f311a69417
fix OO field access in subfunctions of private functions
John W. Eaton <jwe@octave.org>
parents:
11238
diff
changeset
|
835 void mark_subfunction_in_scope_as_private (scope_id scope, |
40f311a69417
fix OO field access in subfunctions of private functions
John W. Eaton <jwe@octave.org>
parents:
11238
diff
changeset
|
836 const std::string& class_name) |
40f311a69417
fix OO field access in subfunctions of private functions
John W. Eaton <jwe@octave.org>
parents:
11238
diff
changeset
|
837 { |
40f311a69417
fix OO field access in subfunctions of private functions
John W. Eaton <jwe@octave.org>
parents:
11238
diff
changeset
|
838 rep->mark_subfunction_in_scope_as_private (scope, class_name); |
40f311a69417
fix OO field access in subfunctions of private functions
John W. Eaton <jwe@octave.org>
parents:
11238
diff
changeset
|
839 } |
40f311a69417
fix OO field access in subfunctions of private functions
John W. Eaton <jwe@octave.org>
parents:
11238
diff
changeset
|
840 |
7336 | 841 void install_cmdline_function (const octave_value& f) |
842 { | |
843 rep->install_cmdline_function (f); | |
844 } | |
845 | |
846 void install_subfunction (const octave_value& f, scope_id scope) | |
847 { | |
848 rep->install_subfunction (f, scope); | |
849 } | |
850 | |
851 void install_user_function (const octave_value& f) | |
852 { | |
853 rep->install_user_function (f); | |
854 } | |
855 | |
856 void install_built_in_function (const octave_value& f) | |
857 { | |
858 rep->install_built_in_function (f); | |
859 } | |
860 | |
861 void clear (void) { rep->clear (); } | |
8881
8ed42c679af5
after defining a script or function, clear local variables created for parsing
John W. Eaton <jwe@octave.org>
parents:
8819
diff
changeset
|
862 |
7336 | 863 void clear_user_function (void) { rep->clear_user_function (); } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11584
diff
changeset
|
864 |
9958
80432f0ee895
improve octave_shlib for safer shared libs treatment
Jaroslav Hajek <highegg@gmail.com>
parents:
9639
diff
changeset
|
865 void clear_autoload_function (void) { rep->clear_autoload_function (); } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11584
diff
changeset
|
866 |
7336 | 867 void clear_mex_function (void) { rep->clear_mex_function (); } |
7972
5bf4e2c13ed8
make superiorto and inferiorto work
John W. Eaton <jwe@octave.org>
parents:
7901
diff
changeset
|
868 |
7336 | 869 void add_dispatch (const std::string& type, const std::string& fname) |
870 { | |
871 rep->add_dispatch (type, fname); | |
872 } | |
873 | |
874 void clear_dispatch (const std::string& type) | |
875 { | |
876 rep->clear_dispatch (type); | |
877 } | |
878 | |
879 void print_dispatch (std::ostream& os) const | |
880 { | |
881 rep->print_dispatch (os); | |
882 } | |
883 | |
884 std::string help_for_dispatch (void) const { return rep->help_for_dispatch (); } | |
885 | |
886 dispatch_map_type get_dispatch (void) const | |
887 { | |
888 return rep->get_dispatch (); | |
4009 | 889 } |
3011 | 890 |
7761
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
891 void |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
892 dump (std::ostream& os, const std::string& prefix = std::string ()) const |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
893 { |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
894 rep->dump (os, prefix); |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
895 } |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
896 |
7336 | 897 private: |
898 | |
899 fcn_info_rep *rep; | |
900 }; | |
901 | |
902 static scope_id global_scope (void) { return xglobal_scope; } | |
903 static scope_id top_scope (void) { return xtop_scope; } | |
904 | |
905 static scope_id current_scope (void) { return xcurrent_scope; } | |
906 | |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
907 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
|
908 |
7761
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
909 static scope_id alloc_scope (void) { return scope_id_cache::alloc (); } |
7336 | 910 |
911 static void set_scope (scope_id scope) | |
912 { | |
913 if (scope == xglobal_scope) | |
914 error ("can't set scope to global"); | |
915 else if (scope != xcurrent_scope) | |
916 { | |
10313 | 917 all_instances_iterator p = all_instances.find (scope); |
918 | |
919 if (p == all_instances.end ()) | |
920 { | |
921 symbol_table *inst = new symbol_table (); | |
922 | |
923 if (inst) | |
924 all_instances[scope] = instance = inst; | |
925 } | |
926 else | |
927 instance = p->second; | |
928 | |
929 xcurrent_scope = scope; | |
930 xcurrent_context = 0; | |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
931 } |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
932 } |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
933 |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
934 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
|
935 { |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
936 if (scope == xglobal_scope) |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
937 error ("can't set scope to global"); |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
938 else |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
939 { |
10313 | 940 if (scope != xcurrent_scope) |
941 { | |
942 all_instances_iterator p = all_instances.find (scope); | |
943 | |
944 if (p == all_instances.end ()) | |
945 error ("scope not found!"); | |
946 else | |
947 { | |
948 instance = p->second; | |
949 | |
950 xcurrent_scope = scope; | |
9355
5e4da3b3747e
fix context restoration in error state
Jaroslav Hajek <highegg@gmail.com>
parents:
9315
diff
changeset
|
951 |
5e4da3b3747e
fix context restoration in error state
Jaroslav Hajek <highegg@gmail.com>
parents:
9315
diff
changeset
|
952 xcurrent_context = context; |
10313 | 953 } |
954 } | |
9355
5e4da3b3747e
fix context restoration in error state
Jaroslav Hajek <highegg@gmail.com>
parents:
9315
diff
changeset
|
955 else |
5e4da3b3747e
fix context restoration in error state
Jaroslav Hajek <highegg@gmail.com>
parents:
9315
diff
changeset
|
956 xcurrent_context = context; |
7336 | 957 } |
958 } | |
959 | |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
960 static void erase_scope (scope_id scope) |
7336 | 961 { |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
962 assert (scope != xglobal_scope); |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
963 |
7336 | 964 all_instances_iterator p = all_instances.find (scope); |
965 | |
966 if (p != all_instances.end ()) | |
7761
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
967 { |
10313 | 968 delete p->second; |
969 | |
970 all_instances.erase (p); | |
971 | |
972 free_scope (scope); | |
7761
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
973 } |
7336 | 974 } |
975 | |
7876
8447a5024650
clear subfunctions when clearing parent function
John W. Eaton <jwe@octave.org>
parents:
7779
diff
changeset
|
976 static void erase_subfunctions_in_scope (scope_id scope) |
8447a5024650
clear subfunctions when clearing parent function
John W. Eaton <jwe@octave.org>
parents:
7779
diff
changeset
|
977 { |
8447a5024650
clear subfunctions when clearing parent function
John W. Eaton <jwe@octave.org>
parents:
7779
diff
changeset
|
978 for (fcn_table_iterator q = fcn_table.begin (); |
10313 | 979 q != fcn_table.end (); q++) |
7876
8447a5024650
clear subfunctions when clearing parent function
John W. Eaton <jwe@octave.org>
parents:
7779
diff
changeset
|
980 q->second.erase_subfunction (scope); |
8447a5024650
clear subfunctions when clearing parent function
John W. Eaton <jwe@octave.org>
parents:
7779
diff
changeset
|
981 } |
8447a5024650
clear subfunctions when clearing parent function
John W. Eaton <jwe@octave.org>
parents:
7779
diff
changeset
|
982 |
11445
40f311a69417
fix OO field access in subfunctions of private functions
John W. Eaton <jwe@octave.org>
parents:
11238
diff
changeset
|
983 static void |
40f311a69417
fix OO field access in subfunctions of private functions
John W. Eaton <jwe@octave.org>
parents:
11238
diff
changeset
|
984 mark_subfunctions_in_scope_as_private (scope_id scope, |
40f311a69417
fix OO field access in subfunctions of private functions
John W. Eaton <jwe@octave.org>
parents:
11238
diff
changeset
|
985 const std::string& class_name) |
40f311a69417
fix OO field access in subfunctions of private functions
John W. Eaton <jwe@octave.org>
parents:
11238
diff
changeset
|
986 { |
40f311a69417
fix OO field access in subfunctions of private functions
John W. Eaton <jwe@octave.org>
parents:
11238
diff
changeset
|
987 for (fcn_table_iterator q = fcn_table.begin (); |
40f311a69417
fix OO field access in subfunctions of private functions
John W. Eaton <jwe@octave.org>
parents:
11238
diff
changeset
|
988 q != fcn_table.end (); q++) |
40f311a69417
fix OO field access in subfunctions of private functions
John W. Eaton <jwe@octave.org>
parents:
11238
diff
changeset
|
989 q->second.mark_subfunction_in_scope_as_private (scope, class_name); |
40f311a69417
fix OO field access in subfunctions of private functions
John W. Eaton <jwe@octave.org>
parents:
11238
diff
changeset
|
990 } |
40f311a69417
fix OO field access in subfunctions of private functions
John W. Eaton <jwe@octave.org>
parents:
11238
diff
changeset
|
991 |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
992 static scope_id dup_scope (scope_id scope) |
7336 | 993 { |
994 scope_id retval = -1; | |
995 | |
996 symbol_table *inst = get_instance (scope); | |
997 | |
998 if (inst) | |
999 { | |
10313 | 1000 scope_id new_scope = alloc_scope (); |
1001 | |
1002 symbol_table *new_symbol_table = new symbol_table (); | |
1003 | |
1004 if (new_symbol_table) | |
1005 { | |
1006 all_instances[new_scope] = new_symbol_table; | |
1007 | |
1008 inst->do_dup_scope (*new_symbol_table); | |
1009 | |
1010 retval = new_scope; | |
1011 } | |
7336 | 1012 } |
1013 | |
1014 return retval; | |
1015 } | |
1016 | |
7761
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
1017 static std::list<scope_id> scopes (void) |
7336 | 1018 { |
7761
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
1019 return scope_id_cache::scopes (); |
7336 | 1020 } |
1021 | |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1022 static symbol_record |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1023 find_symbol (const std::string& name, scope_id scope = xcurrent_scope) |
7336 | 1024 { |
1025 symbol_table *inst = get_instance (scope); | |
1026 | |
1027 return inst ? inst->do_find_symbol (name) : symbol_record (); | |
1028 } | |
4009 | 1029 |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7761
diff
changeset
|
1030 static void |
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7761
diff
changeset
|
1031 inherit (scope_id scope, scope_id donor_scope, context_id donor_context) |
7336 | 1032 { |
1033 symbol_table *inst = get_instance (scope); | |
1034 | |
1035 if (inst) | |
8051
36a485f7f335
symtab.h (symbol_table::do_inherit): copy alll symbols from donor scope
John W. Eaton <jwe@octave.org>
parents:
7972
diff
changeset
|
1036 { |
10313 | 1037 symbol_table *donor_symbol_table = get_instance (donor_scope); |
1038 | |
1039 if (donor_symbol_table) | |
1040 inst->do_inherit (*donor_symbol_table, donor_context); | |
8051
36a485f7f335
symtab.h (symbol_table::do_inherit): copy alll symbols from donor scope
John W. Eaton <jwe@octave.org>
parents:
7972
diff
changeset
|
1041 } |
7336 | 1042 } |
1043 | |
1044 static bool at_top_level (void) { return xcurrent_scope == xtop_scope; } | |
1045 | |
1046 // Find a value corresponding to the given name in the table. | |
1047 static octave_value | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11584
diff
changeset
|
1048 find (const std::string& name, |
9445
c5f03874ea2a
simplify symbol_table::find and associated functions
Jaroslav Hajek <highegg@gmail.com>
parents:
9444
diff
changeset
|
1049 const octave_value_list& args = octave_value_list (), |
10313 | 1050 bool skip_variables = false, |
9463
d34baf412786
support non-local function lookups in str2func
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
1051 bool local_funcs = true); |
7336 | 1052 |
9444
0c785ad961fa
improve behavior of builtin
John W. Eaton <jwe@octave.org>
parents:
9443
diff
changeset
|
1053 static octave_value builtin_find (const std::string& name); |
0c785ad961fa
improve behavior of builtin
John W. Eaton <jwe@octave.org>
parents:
9443
diff
changeset
|
1054 |
7336 | 1055 // 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
|
1056 static symbol_record& insert (const std::string& name) |
7336 | 1057 { |
1058 static symbol_record foobar; | |
1059 | |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1060 symbol_table *inst = get_instance (xcurrent_scope); |
4009 | 1061 |
7336 | 1062 return inst ? inst->do_insert (name) : foobar; |
1063 } | |
1064 | |
8881
8ed42c679af5
after defining a script or function, clear local variables created for parsing
John W. Eaton <jwe@octave.org>
parents:
8819
diff
changeset
|
1065 static void force_variable (const std::string& name, |
10313 | 1066 scope_id scope = xcurrent_scope, |
1067 context_id context = xcurrent_context) | |
8881
8ed42c679af5
after defining a script or function, clear local variables created for parsing
John W. Eaton <jwe@octave.org>
parents:
8819
diff
changeset
|
1068 { |
8ed42c679af5
after defining a script or function, clear local variables created for parsing
John W. Eaton <jwe@octave.org>
parents:
8819
diff
changeset
|
1069 symbol_table *inst = get_instance (scope); |
8ed42c679af5
after defining a script or function, clear local variables created for parsing
John W. Eaton <jwe@octave.org>
parents:
8819
diff
changeset
|
1070 |
8ed42c679af5
after defining a script or function, clear local variables created for parsing
John W. Eaton <jwe@octave.org>
parents:
8819
diff
changeset
|
1071 if (inst) |
8ed42c679af5
after defining a script or function, clear local variables created for parsing
John W. Eaton <jwe@octave.org>
parents:
8819
diff
changeset
|
1072 inst->do_force_variable (name, context); |
8ed42c679af5
after defining a script or function, clear local variables created for parsing
John W. Eaton <jwe@octave.org>
parents:
8819
diff
changeset
|
1073 } |
8ed42c679af5
after defining a script or function, clear local variables created for parsing
John W. Eaton <jwe@octave.org>
parents:
8819
diff
changeset
|
1074 |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1075 static octave_value& varref (const std::string& name, |
10313 | 1076 scope_id scope = xcurrent_scope, |
1077 context_id context = xcurrent_context) | |
7336 | 1078 { |
1079 static octave_value foobar; | |
1080 | |
1081 symbol_table *inst = get_instance (scope); | |
1082 | |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7761
diff
changeset
|
1083 return inst ? inst->do_varref (name, context) : foobar; |
7336 | 1084 } |
1085 | |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1086 static octave_value varval (const std::string& name, |
10313 | 1087 scope_id scope = xcurrent_scope, |
1088 context_id context = xcurrent_context) | |
7336 | 1089 { |
1090 symbol_table *inst = get_instance (scope); | |
1091 | |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7761
diff
changeset
|
1092 return inst ? inst->do_varval (name, context) : octave_value (); |
7336 | 1093 } |
1094 | |
1095 static octave_value& | |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1096 global_varref (const std::string& name) |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1097 { |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1098 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
|
1099 |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1100 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
|
1101 } |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1102 |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1103 static octave_value |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1104 global_varval (const std::string& name) |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1105 { |
7761
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
1106 global_table_const_iterator p = global_table.find (name); |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1107 |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1108 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
|
1109 } |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1110 |
10071
e42b1bbd1052
variables.cc (get_top_level_value, set_top_level_value): new functions
John W. Eaton <jwe@octave.org>
parents:
9981
diff
changeset
|
1111 static octave_value& |
e42b1bbd1052
variables.cc (get_top_level_value, set_top_level_value): new functions
John W. Eaton <jwe@octave.org>
parents:
9981
diff
changeset
|
1112 top_level_varref (const std::string& name) |
e42b1bbd1052
variables.cc (get_top_level_value, set_top_level_value): new functions
John W. Eaton <jwe@octave.org>
parents:
9981
diff
changeset
|
1113 { |
e42b1bbd1052
variables.cc (get_top_level_value, set_top_level_value): new functions
John W. Eaton <jwe@octave.org>
parents:
9981
diff
changeset
|
1114 return varref (name, top_scope (), 0); |
e42b1bbd1052
variables.cc (get_top_level_value, set_top_level_value): new functions
John W. Eaton <jwe@octave.org>
parents:
9981
diff
changeset
|
1115 } |
e42b1bbd1052
variables.cc (get_top_level_value, set_top_level_value): new functions
John W. Eaton <jwe@octave.org>
parents:
9981
diff
changeset
|
1116 |
e42b1bbd1052
variables.cc (get_top_level_value, set_top_level_value): new functions
John W. Eaton <jwe@octave.org>
parents:
9981
diff
changeset
|
1117 static octave_value |
e42b1bbd1052
variables.cc (get_top_level_value, set_top_level_value): new functions
John W. Eaton <jwe@octave.org>
parents:
9981
diff
changeset
|
1118 top_level_varval (const std::string& name) |
e42b1bbd1052
variables.cc (get_top_level_value, set_top_level_value): new functions
John W. Eaton <jwe@octave.org>
parents:
9981
diff
changeset
|
1119 { |
e42b1bbd1052
variables.cc (get_top_level_value, set_top_level_value): new functions
John W. Eaton <jwe@octave.org>
parents:
9981
diff
changeset
|
1120 return varval (name, top_scope (), 0); |
e42b1bbd1052
variables.cc (get_top_level_value, set_top_level_value): new functions
John W. Eaton <jwe@octave.org>
parents:
9981
diff
changeset
|
1121 } |
e42b1bbd1052
variables.cc (get_top_level_value, set_top_level_value): new functions
John W. Eaton <jwe@octave.org>
parents:
9981
diff
changeset
|
1122 |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1123 static octave_value& persistent_varref (const std::string& name) |
7336 | 1124 { |
1125 static octave_value foobar; | |
1126 | |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1127 symbol_table *inst = get_instance (xcurrent_scope); |
7336 | 1128 |
1129 return inst ? inst->do_persistent_varref (name) : foobar; | |
1130 } | |
1131 | |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1132 static octave_value persistent_varval (const std::string& name) |
7336 | 1133 { |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1134 symbol_table *inst = get_instance (xcurrent_scope); |
7336 | 1135 |
1136 return inst ? inst->do_persistent_varval (name) : octave_value (); | |
1137 } | |
1138 | |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1139 static void erase_persistent (const std::string& name) |
7336 | 1140 { |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1141 symbol_table *inst = get_instance (xcurrent_scope); |
7336 | 1142 |
1143 if (inst) | |
1144 inst->do_erase_persistent (name); | |
1145 } | |
8 | 1146 |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1147 static bool is_variable (const std::string& name) |
7336 | 1148 { |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1149 symbol_table *inst = get_instance (xcurrent_scope); |
7336 | 1150 |
1151 return inst ? inst->do_is_variable (name) : false; | |
1152 } | |
1153 | |
1154 static bool | |
1155 is_built_in_function_name (const std::string& name) | |
1156 { | |
1157 octave_value val = find_built_in_function (name); | |
1158 | |
1159 return val.is_defined (); | |
1160 } | |
1161 | |
1162 static octave_value | |
1163 find_method (const std::string& name, const std::string& dispatch_type) | |
1164 { | |
7761
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
1165 fcn_table_const_iterator p = fcn_table.find (name); |
8 | 1166 |
7336 | 1167 if (p != fcn_table.end ()) |
1168 return p->second.find_method (dispatch_type); | |
1169 else | |
1170 { | |
10313 | 1171 fcn_info finfo (name); |
1172 | |
1173 octave_value fcn = finfo.find_method (dispatch_type); | |
1174 | |
1175 if (fcn.is_defined ()) | |
1176 fcn_table[name] = finfo; | |
1177 | |
1178 return fcn; | |
7336 | 1179 } |
1180 } | |
1181 | |
1182 static octave_value | |
1183 find_built_in_function (const std::string& name) | |
1184 { | |
7761
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
1185 fcn_table_const_iterator p = fcn_table.find (name); |
7336 | 1186 |
1187 return (p != fcn_table.end ()) | |
1188 ? p->second.find_built_in_function () : octave_value (); | |
1189 } | |
1190 | |
1191 static octave_value | |
1192 find_autoload (const std::string& name) | |
1193 { | |
1194 fcn_table_iterator p = fcn_table.find (name); | |
4913 | 1195 |
7336 | 1196 return (p != fcn_table.end ()) |
1197 ? p->second.find_autoload () : octave_value (); | |
1198 } | |
1199 | |
1200 static octave_value | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11584
diff
changeset
|
1201 find_function (const std::string& name, |
9463
d34baf412786
support non-local function lookups in str2func
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
1202 const octave_value_list& args = octave_value_list (), |
d34baf412786
support non-local function lookups in str2func
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
1203 bool local_funcs = true); |
7336 | 1204 |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1205 static octave_value find_user_function (const std::string& name) |
7336 | 1206 { |
1207 fcn_table_iterator p = fcn_table.find (name); | |
1208 | |
1209 return (p != fcn_table.end ()) | |
1210 ? p->second.find_user_function () : octave_value (); | |
1211 } | |
1212 | |
1213 static void install_cmdline_function (const std::string& name, | |
10313 | 1214 const octave_value& fcn) |
7336 | 1215 { |
1216 fcn_table_iterator p = fcn_table.find (name); | |
1217 | |
1218 if (p != fcn_table.end ()) | |
1219 { | |
10313 | 1220 fcn_info& finfo = p->second; |
1221 | |
1222 finfo.install_cmdline_function (fcn); | |
7336 | 1223 } |
1224 else | |
1225 { | |
10313 | 1226 fcn_info finfo (name); |
1227 | |
1228 finfo.install_cmdline_function (fcn); | |
1229 | |
1230 fcn_table[name] = finfo; | |
7336 | 1231 } |
1232 } | |
1233 | |
1234 static void install_subfunction (const std::string& name, | |
10313 | 1235 const octave_value& fcn, |
1236 scope_id scope) | |
7336 | 1237 { |
1238 fcn_table_iterator p = fcn_table.find (name); | |
1239 | |
1240 if (p != fcn_table.end ()) | |
1241 { | |
10313 | 1242 fcn_info& finfo = p->second; |
1243 | |
1244 finfo.install_subfunction (fcn, scope); | |
7336 | 1245 } |
1246 else | |
1247 { | |
10313 | 1248 fcn_info finfo (name); |
1249 | |
1250 finfo.install_subfunction (fcn, scope); | |
1251 | |
1252 fcn_table[name] = finfo; | |
7336 | 1253 } |
1254 } | |
1255 | |
1256 static void install_user_function (const std::string& name, | |
10313 | 1257 const octave_value& fcn) |
7336 | 1258 { |
1259 fcn_table_iterator p = fcn_table.find (name); | |
1260 | |
1261 if (p != fcn_table.end ()) | |
1262 { | |
10313 | 1263 fcn_info& finfo = p->second; |
1264 | |
1265 finfo.install_user_function (fcn); | |
7336 | 1266 } |
1267 else | |
1268 { | |
10313 | 1269 fcn_info finfo (name); |
1270 | |
1271 finfo.install_user_function (fcn); | |
1272 | |
1273 fcn_table[name] = finfo; | |
7336 | 1274 } |
1275 } | |
605 | 1276 |
7336 | 1277 static void install_built_in_function (const std::string& name, |
10313 | 1278 const octave_value& fcn) |
7336 | 1279 { |
1280 fcn_table_iterator p = fcn_table.find (name); | |
1281 | |
1282 if (p != fcn_table.end ()) | |
1283 { | |
10313 | 1284 fcn_info& finfo = p->second; |
1285 | |
1286 finfo.install_built_in_function (fcn); | |
7336 | 1287 } |
1288 else | |
1289 { | |
10313 | 1290 fcn_info finfo (name); |
1291 | |
1292 finfo.install_built_in_function (fcn); | |
1293 | |
1294 fcn_table[name] = finfo; | |
7336 | 1295 } |
1296 } | |
1297 | |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1298 static void clear (const std::string& name) |
7336 | 1299 { |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1300 clear_variable (name); |
7336 | 1301 } |
1302 | |
1303 static void clear_all (void) | |
1304 { | |
1305 clear_variables (); | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11584
diff
changeset
|
1306 |
10559
0ecbb17d130a
Clear global variables when 'clear -all' called
Rik <code@nomad.inbox5.com>
parents:
10521
diff
changeset
|
1307 clear_global_pattern ("*"); |
7336 | 1308 |
1309 clear_functions (); | |
1310 } | |
1311 | |
9396
17af7cce7d1b
yet more unwind_protect improvements
Jaroslav Hajek <highegg@gmail.com>
parents:
9355
diff
changeset
|
1312 static void clear_variables (scope_id scope) |
7336 | 1313 { |
8282
47a3d2f829e4
clear local symbol table after parsing function
John W. Eaton <jwe@octave.org>
parents:
8123
diff
changeset
|
1314 symbol_table *inst = get_instance (scope); |
7336 | 1315 |
1316 if (inst) | |
1317 inst->do_clear_variables (); | |
1318 } | |
1319 | |
9396
17af7cce7d1b
yet more unwind_protect improvements
Jaroslav Hajek <highegg@gmail.com>
parents:
9355
diff
changeset
|
1320 // This is split for unwind_protect. |
17af7cce7d1b
yet more unwind_protect improvements
Jaroslav Hajek <highegg@gmail.com>
parents:
9355
diff
changeset
|
1321 static void clear_variables (void) |
17af7cce7d1b
yet more unwind_protect improvements
Jaroslav Hajek <highegg@gmail.com>
parents:
9355
diff
changeset
|
1322 { |
17af7cce7d1b
yet more unwind_protect improvements
Jaroslav Hajek <highegg@gmail.com>
parents:
9355
diff
changeset
|
1323 clear_variables (xcurrent_scope); |
17af7cce7d1b
yet more unwind_protect improvements
Jaroslav Hajek <highegg@gmail.com>
parents:
9355
diff
changeset
|
1324 } |
17af7cce7d1b
yet more unwind_protect improvements
Jaroslav Hajek <highegg@gmail.com>
parents:
9355
diff
changeset
|
1325 |
9240
f27a8c07f0b2
clear -classes and support.
Robert T. Short <octave@phaselockedsystems.com>
parents:
9144
diff
changeset
|
1326 static void clear_objects (scope_id scope = xcurrent_scope) |
f27a8c07f0b2
clear -classes and support.
Robert T. Short <octave@phaselockedsystems.com>
parents:
9144
diff
changeset
|
1327 { |
f27a8c07f0b2
clear -classes and support.
Robert T. Short <octave@phaselockedsystems.com>
parents:
9144
diff
changeset
|
1328 symbol_table *inst = get_instance (scope); |
f27a8c07f0b2
clear -classes and support.
Robert T. Short <octave@phaselockedsystems.com>
parents:
9144
diff
changeset
|
1329 |
f27a8c07f0b2
clear -classes and support.
Robert T. Short <octave@phaselockedsystems.com>
parents:
9144
diff
changeset
|
1330 if (inst) |
f27a8c07f0b2
clear -classes and support.
Robert T. Short <octave@phaselockedsystems.com>
parents:
9144
diff
changeset
|
1331 inst->do_clear_objects (); |
f27a8c07f0b2
clear -classes and support.
Robert T. Short <octave@phaselockedsystems.com>
parents:
9144
diff
changeset
|
1332 } |
f27a8c07f0b2
clear -classes and support.
Robert T. Short <octave@phaselockedsystems.com>
parents:
9144
diff
changeset
|
1333 |
9009
da58ec8f62e8
tag bug don't define forced variables
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
1334 static void unmark_forced_variables (scope_id scope = xcurrent_scope) |
8881
8ed42c679af5
after defining a script or function, clear local variables created for parsing
John W. Eaton <jwe@octave.org>
parents:
8819
diff
changeset
|
1335 { |
8ed42c679af5
after defining a script or function, clear local variables created for parsing
John W. Eaton <jwe@octave.org>
parents:
8819
diff
changeset
|
1336 symbol_table *inst = get_instance (scope); |
8ed42c679af5
after defining a script or function, clear local variables created for parsing
John W. Eaton <jwe@octave.org>
parents:
8819
diff
changeset
|
1337 |
8ed42c679af5
after defining a script or function, clear local variables created for parsing
John W. Eaton <jwe@octave.org>
parents:
8819
diff
changeset
|
1338 if (inst) |
9009
da58ec8f62e8
tag bug don't define forced variables
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
1339 inst->do_unmark_forced_variables (); |
8881
8ed42c679af5
after defining a script or function, clear local variables created for parsing
John W. Eaton <jwe@octave.org>
parents:
8819
diff
changeset
|
1340 } |
8ed42c679af5
after defining a script or function, clear local variables created for parsing
John W. Eaton <jwe@octave.org>
parents:
8819
diff
changeset
|
1341 |
7336 | 1342 static void clear_functions (void) |
1343 { | |
1344 for (fcn_table_iterator p = fcn_table.begin (); p != fcn_table.end (); p++) | |
1345 p->second.clear (); | |
1346 } | |
1347 | |
1348 static void clear_function (const std::string& name) | |
1349 { | |
1350 clear_user_function (name); | |
1351 } | |
1352 | |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1353 static void clear_global (const std::string& name) |
7336 | 1354 { |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1355 symbol_table *inst = get_instance (xcurrent_scope); |
7336 | 1356 |
1357 if (inst) | |
1358 inst->do_clear_global (name); | |
1359 } | |
1360 | |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1361 static void clear_variable (const std::string& name) |
7336 | 1362 { |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1363 symbol_table *inst = get_instance (xcurrent_scope); |
7336 | 1364 |
1365 if (inst) | |
1366 inst->do_clear_variable (name); | |
1367 } | |
1368 | |
1369 static void clear_symbol (const std::string& name) | |
1370 { | |
1371 // FIXME -- are we supposed to do both here? | |
1372 | |
1373 clear_variable (name); | |
1374 clear_function (name); | |
1375 } | |
1376 | |
1377 static void clear_function_pattern (const std::string& pat) | |
1378 { | |
1379 glob_match pattern (pat); | |
1380 | |
1381 for (fcn_table_iterator p = fcn_table.begin (); p != fcn_table.end (); p++) | |
1382 { | |
10313 | 1383 if (pattern.match (p->first)) |
1384 p->second.clear_user_function (); | |
7336 | 1385 } |
1386 } | |
1387 | |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1388 static void clear_global_pattern (const std::string& pat) |
7336 | 1389 { |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1390 symbol_table *inst = get_instance (xcurrent_scope); |
4009 | 1391 |
7336 | 1392 if (inst) |
1393 inst->do_clear_global_pattern (pat); | |
1394 } | |
1395 | |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1396 static void clear_variable_pattern (const std::string& pat) |
7336 | 1397 { |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1398 symbol_table *inst = get_instance (xcurrent_scope); |
7336 | 1399 |
1400 if (inst) | |
1401 inst->do_clear_variable_pattern (pat); | |
1402 } | |
1403 | |
7779
791231dac333
Add regexp matching to Fwho and Fclear
David Bateman <dbateman@free.fr>
parents:
7767
diff
changeset
|
1404 static void clear_variable_regexp (const std::string& pat) |
791231dac333
Add regexp matching to Fwho and Fclear
David Bateman <dbateman@free.fr>
parents:
7767
diff
changeset
|
1405 { |
791231dac333
Add regexp matching to Fwho and Fclear
David Bateman <dbateman@free.fr>
parents:
7767
diff
changeset
|
1406 symbol_table *inst = get_instance (xcurrent_scope); |
791231dac333
Add regexp matching to Fwho and Fclear
David Bateman <dbateman@free.fr>
parents:
7767
diff
changeset
|
1407 |
791231dac333
Add regexp matching to Fwho and Fclear
David Bateman <dbateman@free.fr>
parents:
7767
diff
changeset
|
1408 if (inst) |
791231dac333
Add regexp matching to Fwho and Fclear
David Bateman <dbateman@free.fr>
parents:
7767
diff
changeset
|
1409 inst->do_clear_variable_regexp (pat); |
791231dac333
Add regexp matching to Fwho and Fclear
David Bateman <dbateman@free.fr>
parents:
7767
diff
changeset
|
1410 } |
791231dac333
Add regexp matching to Fwho and Fclear
David Bateman <dbateman@free.fr>
parents:
7767
diff
changeset
|
1411 |
7336 | 1412 static void clear_symbol_pattern (const std::string& pat) |
1413 { | |
1414 // FIXME -- are we supposed to do both here? | |
1415 | |
1416 clear_variable_pattern (pat); | |
1417 clear_function_pattern (pat); | |
1418 } | |
1419 | |
1420 static void clear_user_function (const std::string& name) | |
1421 { | |
1422 fcn_table_iterator p = fcn_table.find (name); | |
1423 | |
1424 if (p != fcn_table.end ()) | |
1425 { | |
10313 | 1426 fcn_info& finfo = p->second; |
1427 | |
1428 finfo.clear_user_function (); | |
7336 | 1429 } |
1430 // FIXME -- is this necessary, or even useful? | |
1431 // else | |
1432 // error ("clear: no such function `%s'", name.c_str ()); | |
1433 } | |
1434 | |
9958
80432f0ee895
improve octave_shlib for safer shared libs treatment
Jaroslav Hajek <highegg@gmail.com>
parents:
9639
diff
changeset
|
1435 // This clears oct and mex files, incl. autoloads. |
80432f0ee895
improve octave_shlib for safer shared libs treatment
Jaroslav Hajek <highegg@gmail.com>
parents:
9639
diff
changeset
|
1436 static void clear_dld_function (const std::string& name) |
80432f0ee895
improve octave_shlib for safer shared libs treatment
Jaroslav Hajek <highegg@gmail.com>
parents:
9639
diff
changeset
|
1437 { |
80432f0ee895
improve octave_shlib for safer shared libs treatment
Jaroslav Hajek <highegg@gmail.com>
parents:
9639
diff
changeset
|
1438 fcn_table_iterator p = fcn_table.find (name); |
80432f0ee895
improve octave_shlib for safer shared libs treatment
Jaroslav Hajek <highegg@gmail.com>
parents:
9639
diff
changeset
|
1439 |
80432f0ee895
improve octave_shlib for safer shared libs treatment
Jaroslav Hajek <highegg@gmail.com>
parents:
9639
diff
changeset
|
1440 if (p != fcn_table.end ()) |
80432f0ee895
improve octave_shlib for safer shared libs treatment
Jaroslav Hajek <highegg@gmail.com>
parents:
9639
diff
changeset
|
1441 { |
10313 | 1442 fcn_info& finfo = p->second; |
1443 | |
1444 finfo.clear_autoload_function (); | |
1445 finfo.clear_user_function (); | |
9958
80432f0ee895
improve octave_shlib for safer shared libs treatment
Jaroslav Hajek <highegg@gmail.com>
parents:
9639
diff
changeset
|
1446 } |
80432f0ee895
improve octave_shlib for safer shared libs treatment
Jaroslav Hajek <highegg@gmail.com>
parents:
9639
diff
changeset
|
1447 } |
80432f0ee895
improve octave_shlib for safer shared libs treatment
Jaroslav Hajek <highegg@gmail.com>
parents:
9639
diff
changeset
|
1448 |
7336 | 1449 static void clear_mex_functions (void) |
1450 { | |
1451 for (fcn_table_iterator p = fcn_table.begin (); p != fcn_table.end (); p++) | |
1452 { | |
10313 | 1453 fcn_info& finfo = p->second; |
1454 | |
1455 finfo.clear_mex_function (); | |
7336 | 1456 } |
1457 } | |
1458 | |
7972
5bf4e2c13ed8
make superiorto and inferiorto work
John W. Eaton <jwe@octave.org>
parents:
7901
diff
changeset
|
1459 static bool set_class_relationship (const std::string& sup_class, |
10313 | 1460 const std::string& inf_class); |
7972
5bf4e2c13ed8
make superiorto and inferiorto work
John W. Eaton <jwe@octave.org>
parents:
7901
diff
changeset
|
1461 |
5bf4e2c13ed8
make superiorto and inferiorto work
John W. Eaton <jwe@octave.org>
parents:
7901
diff
changeset
|
1462 static bool is_superiorto (const std::string& a, const std::string& b); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11584
diff
changeset
|
1463 |
7336 | 1464 static void alias_built_in_function (const std::string& alias, |
10313 | 1465 const std::string& name) |
7336 | 1466 { |
1467 octave_value fcn = find_built_in_function (name); | |
1468 | |
1469 if (fcn.is_defined ()) | |
1470 { | |
10313 | 1471 fcn_info finfo (alias); |
1472 | |
1473 finfo.install_built_in_function (fcn); | |
1474 | |
1475 fcn_table[alias] = finfo; | |
7336 | 1476 } |
1477 else | |
1478 panic ("alias: `%s' is undefined", name.c_str ()); | |
1479 } | |
1480 | |
1481 static void add_dispatch (const std::string& name, const std::string& type, | |
10313 | 1482 const std::string& fname) |
7336 | 1483 { |
1484 fcn_table_iterator p = fcn_table.find (name); | |
1485 | |
1486 if (p != fcn_table.end ()) | |
1487 { | |
10313 | 1488 fcn_info& finfo = p->second; |
1489 | |
1490 finfo.add_dispatch (type, fname); | |
7336 | 1491 } |
1492 else | |
1493 { | |
10313 | 1494 fcn_info finfo (name); |
1495 | |
1496 finfo.add_dispatch (type, fname); | |
1497 | |
1498 fcn_table[name] = finfo; | |
7336 | 1499 } |
1500 } | |
1501 | |
1502 static void clear_dispatch (const std::string& name, const std::string& type) | |
1503 { | |
1504 fcn_table_iterator p = fcn_table.find (name); | |
1505 | |
1506 if (p != fcn_table.end ()) | |
1507 { | |
10313 | 1508 fcn_info& finfo = p->second; |
1509 | |
1510 finfo.clear_dispatch (type); | |
7336 | 1511 } |
1512 } | |
1513 | |
1514 static void print_dispatch (std::ostream& os, const std::string& name) | |
1515 { | |
1516 fcn_table_iterator p = fcn_table.find (name); | |
4009 | 1517 |
7336 | 1518 if (p != fcn_table.end ()) |
1519 { | |
10313 | 1520 fcn_info& finfo = p->second; |
1521 | |
1522 finfo.print_dispatch (os); | |
7336 | 1523 } |
1524 } | |
1525 | |
1526 static fcn_info::dispatch_map_type get_dispatch (const std::string& name) | |
1527 { | |
1528 fcn_info::dispatch_map_type retval; | |
1529 | |
1530 fcn_table_iterator p = fcn_table.find (name); | |
1531 | |
1532 if (p != fcn_table.end ()) | |
1533 { | |
10313 | 1534 fcn_info& finfo = p->second; |
1535 | |
1536 retval = finfo.get_dispatch (); | |
7336 | 1537 } |
1538 | |
1539 return retval; | |
1540 } | |
1541 | |
1542 static std::string help_for_dispatch (const std::string& name) | |
1543 { | |
1544 std::string retval; | |
1545 | |
1546 fcn_table_iterator p = fcn_table.find (name); | |
1547 | |
1548 if (p != fcn_table.end ()) | |
1549 { | |
10313 | 1550 fcn_info& finfo = p->second; |
1551 | |
1552 retval = finfo.help_for_dispatch (); | |
7336 | 1553 } |
1554 | |
1555 return retval; | |
1556 } | |
1557 | |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1558 static void push_context (void) |
7336 | 1559 { |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1560 if (xcurrent_scope == xglobal_scope || xcurrent_scope == xtop_scope) |
7336 | 1561 error ("invalid call to xymtab::push_context"); |
1562 else | |
1563 { | |
10313 | 1564 symbol_table *inst = get_instance (xcurrent_scope); |
1565 | |
1566 if (inst) | |
1567 inst->do_push_context (); | |
7336 | 1568 } |
1569 } | |
1570 | |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1571 static void pop_context (void) |
7336 | 1572 { |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1573 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
|
1574 error ("invalid call to xymtab::pop_context"); |
7336 | 1575 else |
1576 { | |
10313 | 1577 symbol_table *inst = get_instance (xcurrent_scope); |
1578 | |
1579 if (inst) | |
1580 inst->do_pop_context (); | |
7336 | 1581 } |
1582 } | |
1583 | |
1584 // For unwind_protect. | |
1585 static void pop_context (void *) { pop_context (); } | |
1586 | |
11557
e9d72a3caa46
mark automatic variables as automatic
John W. Eaton <jwe@octave.org>
parents:
11548
diff
changeset
|
1587 static void mark_automatic (const std::string& name) |
e9d72a3caa46
mark automatic variables as automatic
John W. Eaton <jwe@octave.org>
parents:
11548
diff
changeset
|
1588 { |
e9d72a3caa46
mark automatic variables as automatic
John W. Eaton <jwe@octave.org>
parents:
11548
diff
changeset
|
1589 symbol_table *inst = get_instance (xcurrent_scope); |
e9d72a3caa46
mark automatic variables as automatic
John W. Eaton <jwe@octave.org>
parents:
11548
diff
changeset
|
1590 |
e9d72a3caa46
mark automatic variables as automatic
John W. Eaton <jwe@octave.org>
parents:
11548
diff
changeset
|
1591 if (inst) |
e9d72a3caa46
mark automatic variables as automatic
John W. Eaton <jwe@octave.org>
parents:
11548
diff
changeset
|
1592 inst->do_mark_automatic (name); |
e9d72a3caa46
mark automatic variables as automatic
John W. Eaton <jwe@octave.org>
parents:
11548
diff
changeset
|
1593 } |
e9d72a3caa46
mark automatic variables as automatic
John W. Eaton <jwe@octave.org>
parents:
11548
diff
changeset
|
1594 |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1595 static void mark_hidden (const std::string& name) |
7336 | 1596 { |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1597 symbol_table *inst = get_instance (xcurrent_scope); |
7336 | 1598 |
1599 if (inst) | |
1600 inst->do_mark_hidden (name); | |
1601 } | |
1602 | |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1603 static void mark_global (const std::string& name) |
7336 | 1604 { |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1605 symbol_table *inst = get_instance (xcurrent_scope); |
7336 | 1606 |
1607 if (inst) | |
1608 inst->do_mark_global (name); | |
1609 } | |
1610 | |
1611 static std::list<symbol_record> | |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7761
diff
changeset
|
1612 all_variables (scope_id scope = xcurrent_scope, |
10313 | 1613 context_id context = xcurrent_context, |
1614 bool defined_only = true) | |
7336 | 1615 { |
1616 symbol_table *inst = get_instance (scope); | |
1617 | |
1618 return inst | |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7761
diff
changeset
|
1619 ? inst->do_all_variables (context, defined_only) : std::list<symbol_record> (); |
7336 | 1620 } |
3011 | 1621 |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1622 static std::list<symbol_record> glob (const std::string& pattern) |
7336 | 1623 { |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1624 symbol_table *inst = get_instance (xcurrent_scope); |
7336 | 1625 |
1626 return inst ? inst->do_glob (pattern) : std::list<symbol_record> (); | |
1627 } | |
1628 | |
7779
791231dac333
Add regexp matching to Fwho and Fclear
David Bateman <dbateman@free.fr>
parents:
7767
diff
changeset
|
1629 static std::list<symbol_record> regexp (const std::string& pattern) |
791231dac333
Add regexp matching to Fwho and Fclear
David Bateman <dbateman@free.fr>
parents:
7767
diff
changeset
|
1630 { |
791231dac333
Add regexp matching to Fwho and Fclear
David Bateman <dbateman@free.fr>
parents:
7767
diff
changeset
|
1631 symbol_table *inst = get_instance (xcurrent_scope); |
791231dac333
Add regexp matching to Fwho and Fclear
David Bateman <dbateman@free.fr>
parents:
7767
diff
changeset
|
1632 |
791231dac333
Add regexp matching to Fwho and Fclear
David Bateman <dbateman@free.fr>
parents:
7767
diff
changeset
|
1633 return inst ? inst->do_regexp (pattern) : std::list<symbol_record> (); |
791231dac333
Add regexp matching to Fwho and Fclear
David Bateman <dbateman@free.fr>
parents:
7767
diff
changeset
|
1634 } |
791231dac333
Add regexp matching to Fwho and Fclear
David Bateman <dbateman@free.fr>
parents:
7767
diff
changeset
|
1635 |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1636 static std::list<symbol_record> glob_variables (const std::string& pattern) |
7336 | 1637 { |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1638 symbol_table *inst = get_instance (xcurrent_scope); |
7336 | 1639 |
1640 return inst ? inst->do_glob (pattern, true) : std::list<symbol_record> (); | |
1641 } | |
1642 | |
7779
791231dac333
Add regexp matching to Fwho and Fclear
David Bateman <dbateman@free.fr>
parents:
7767
diff
changeset
|
1643 static std::list<symbol_record> regexp_variables (const std::string& pattern) |
791231dac333
Add regexp matching to Fwho and Fclear
David Bateman <dbateman@free.fr>
parents:
7767
diff
changeset
|
1644 { |
791231dac333
Add regexp matching to Fwho and Fclear
David Bateman <dbateman@free.fr>
parents:
7767
diff
changeset
|
1645 symbol_table *inst = get_instance (xcurrent_scope); |
791231dac333
Add regexp matching to Fwho and Fclear
David Bateman <dbateman@free.fr>
parents:
7767
diff
changeset
|
1646 |
791231dac333
Add regexp matching to Fwho and Fclear
David Bateman <dbateman@free.fr>
parents:
7767
diff
changeset
|
1647 return inst ? inst->do_regexp (pattern, true) : std::list<symbol_record> (); |
791231dac333
Add regexp matching to Fwho and Fclear
David Bateman <dbateman@free.fr>
parents:
7767
diff
changeset
|
1648 } |
791231dac333
Add regexp matching to Fwho and Fclear
David Bateman <dbateman@free.fr>
parents:
7767
diff
changeset
|
1649 |
7336 | 1650 static std::list<symbol_record> |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1651 glob_global_variables (const std::string& pattern) |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1652 { |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1653 std::list<symbol_record> retval; |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1654 |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1655 glob_match pat (pattern); |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1656 |
7761
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
1657 for (global_table_const_iterator p = global_table.begin (); |
10313 | 1658 p != global_table.end (); p++) |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1659 { |
10313 | 1660 // We generate a list of symbol_record objects so that |
1661 // the results from glob_variables and glob_global_variables | |
1662 // may be handled the same way. | |
1663 | |
1664 if (pat.match (p->first)) | |
1665 retval.push_back (symbol_record (p->first, p->second, | |
1666 symbol_record::global)); | |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1667 } |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1668 |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1669 return retval; |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1670 } |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1671 |
7779
791231dac333
Add regexp matching to Fwho and Fclear
David Bateman <dbateman@free.fr>
parents:
7767
diff
changeset
|
1672 static std::list<symbol_record> |
791231dac333
Add regexp matching to Fwho and Fclear
David Bateman <dbateman@free.fr>
parents:
7767
diff
changeset
|
1673 regexp_global_variables (const std::string& pattern) |
791231dac333
Add regexp matching to Fwho and Fclear
David Bateman <dbateman@free.fr>
parents:
7767
diff
changeset
|
1674 { |
791231dac333
Add regexp matching to Fwho and Fclear
David Bateman <dbateman@free.fr>
parents:
7767
diff
changeset
|
1675 std::list<symbol_record> retval; |
791231dac333
Add regexp matching to Fwho and Fclear
David Bateman <dbateman@free.fr>
parents:
7767
diff
changeset
|
1676 |
791231dac333
Add regexp matching to Fwho and Fclear
David Bateman <dbateman@free.fr>
parents:
7767
diff
changeset
|
1677 regex_match pat (pattern); |
791231dac333
Add regexp matching to Fwho and Fclear
David Bateman <dbateman@free.fr>
parents:
7767
diff
changeset
|
1678 |
791231dac333
Add regexp matching to Fwho and Fclear
David Bateman <dbateman@free.fr>
parents:
7767
diff
changeset
|
1679 for (global_table_const_iterator p = global_table.begin (); |
10313 | 1680 p != global_table.end (); p++) |
7779
791231dac333
Add regexp matching to Fwho and Fclear
David Bateman <dbateman@free.fr>
parents:
7767
diff
changeset
|
1681 { |
10313 | 1682 // We generate a list of symbol_record objects so that |
1683 // the results from regexp_variables and regexp_global_variables | |
1684 // may be handled the same way. | |
1685 | |
1686 if (pat.match (p->first)) | |
1687 retval.push_back (symbol_record (p->first, p->second, | |
1688 symbol_record::global)); | |
7779
791231dac333
Add regexp matching to Fwho and Fclear
David Bateman <dbateman@free.fr>
parents:
7767
diff
changeset
|
1689 } |
791231dac333
Add regexp matching to Fwho and Fclear
David Bateman <dbateman@free.fr>
parents:
7767
diff
changeset
|
1690 |
791231dac333
Add regexp matching to Fwho and Fclear
David Bateman <dbateman@free.fr>
parents:
7767
diff
changeset
|
1691 return retval; |
791231dac333
Add regexp matching to Fwho and Fclear
David Bateman <dbateman@free.fr>
parents:
7767
diff
changeset
|
1692 } |
791231dac333
Add regexp matching to Fwho and Fclear
David Bateman <dbateman@free.fr>
parents:
7767
diff
changeset
|
1693 |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1694 static std::list<symbol_record> glob_variables (const string_vector& patterns) |
7336 | 1695 { |
1696 std::list<symbol_record> retval; | |
1697 | |
1698 size_t len = patterns.length (); | |
8 | 1699 |
7336 | 1700 for (size_t i = 0; i < len; i++) |
1701 { | |
10313 | 1702 std::list<symbol_record> tmp = glob_variables (patterns[i]); |
1703 | |
1704 retval.insert (retval.begin (), tmp.begin (), tmp.end ()); | |
7336 | 1705 } |
1706 | |
1707 return retval; | |
1708 } | |
1709 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11584
diff
changeset
|
1710 static std::list<symbol_record> regexp_variables |
7779
791231dac333
Add regexp matching to Fwho and Fclear
David Bateman <dbateman@free.fr>
parents:
7767
diff
changeset
|
1711 (const string_vector& patterns) |
791231dac333
Add regexp matching to Fwho and Fclear
David Bateman <dbateman@free.fr>
parents:
7767
diff
changeset
|
1712 { |
791231dac333
Add regexp matching to Fwho and Fclear
David Bateman <dbateman@free.fr>
parents:
7767
diff
changeset
|
1713 std::list<symbol_record> retval; |
791231dac333
Add regexp matching to Fwho and Fclear
David Bateman <dbateman@free.fr>
parents:
7767
diff
changeset
|
1714 |
791231dac333
Add regexp matching to Fwho and Fclear
David Bateman <dbateman@free.fr>
parents:
7767
diff
changeset
|
1715 size_t len = patterns.length (); |
791231dac333
Add regexp matching to Fwho and Fclear
David Bateman <dbateman@free.fr>
parents:
7767
diff
changeset
|
1716 |
791231dac333
Add regexp matching to Fwho and Fclear
David Bateman <dbateman@free.fr>
parents:
7767
diff
changeset
|
1717 for (size_t i = 0; i < len; i++) |
791231dac333
Add regexp matching to Fwho and Fclear
David Bateman <dbateman@free.fr>
parents:
7767
diff
changeset
|
1718 { |
10313 | 1719 std::list<symbol_record> tmp = regexp_variables (patterns[i]); |
1720 | |
1721 retval.insert (retval.begin (), tmp.begin (), tmp.end ()); | |
7779
791231dac333
Add regexp matching to Fwho and Fclear
David Bateman <dbateman@free.fr>
parents:
7767
diff
changeset
|
1722 } |
791231dac333
Add regexp matching to Fwho and Fclear
David Bateman <dbateman@free.fr>
parents:
7767
diff
changeset
|
1723 |
791231dac333
Add regexp matching to Fwho and Fclear
David Bateman <dbateman@free.fr>
parents:
7767
diff
changeset
|
1724 return retval; |
791231dac333
Add regexp matching to Fwho and Fclear
David Bateman <dbateman@free.fr>
parents:
7767
diff
changeset
|
1725 } |
791231dac333
Add regexp matching to Fwho and Fclear
David Bateman <dbateman@free.fr>
parents:
7767
diff
changeset
|
1726 |
7336 | 1727 static std::list<std::string> user_function_names (void) |
1728 { | |
1729 std::list<std::string> retval; | |
1730 | |
1731 for (fcn_table_iterator p = fcn_table.begin (); | |
10313 | 1732 p != fcn_table.end (); p++) |
7336 | 1733 { |
10313 | 1734 if (p->second.is_user_function_defined ()) |
1735 retval.push_back (p->first); | |
7336 | 1736 } |
1737 | |
1738 if (! retval.empty ()) | |
1739 retval.sort (); | |
1740 | |
1741 return retval; | |
1742 } | |
3011 | 1743 |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1744 static std::list<std::string> global_variable_names (void) |
7336 | 1745 { |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1746 std::list<std::string> retval; |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1747 |
7761
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
1748 for (global_table_const_iterator p = global_table.begin (); |
10313 | 1749 p != global_table.end (); p++) |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1750 retval.push_back (p->first); |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1751 |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1752 retval.sort (); |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1753 |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1754 return retval; |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1755 } |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1756 |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1757 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
|
1758 { |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1759 symbol_table *inst = get_instance (xtop_scope); |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1760 |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1761 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
|
1762 } |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1763 |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1764 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
|
1765 { |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1766 symbol_table *inst = get_instance (xcurrent_scope); |
7336 | 1767 |
1768 return inst ? inst->do_variable_names () : std::list<std::string> (); | |
1769 } | |
1770 | |
1771 static std::list<std::string> built_in_function_names (void) | |
1772 { | |
1773 std::list<std::string> retval; | |
1774 | |
7761
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
1775 for (fcn_table_const_iterator p = fcn_table.begin (); |
10313 | 1776 p != fcn_table.end (); p++) |
7336 | 1777 { |
10313 | 1778 octave_value fcn = p->second.find_built_in_function (); |
1779 | |
1780 if (fcn.is_defined ()) | |
1781 retval.push_back (p->first); | |
7336 | 1782 } |
1783 | |
1784 if (! retval.empty ()) | |
1785 retval.sort (); | |
220 | 1786 |
7336 | 1787 return retval; |
1788 } | |
1789 | |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1790 static bool is_local_variable (const std::string& name) |
7336 | 1791 { |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1792 if (xcurrent_scope == xglobal_scope) |
7336 | 1793 return false; |
1794 else | |
1795 { | |
10313 | 1796 symbol_table *inst = get_instance (xcurrent_scope); |
1797 | |
1798 return inst ? inst->do_is_local_variable (name) : false; | |
7336 | 1799 } |
1800 } | |
5861 | 1801 |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1802 static bool is_global (const std::string& name) |
7336 | 1803 { |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1804 if (xcurrent_scope == xglobal_scope) |
7336 | 1805 return true; |
1806 else | |
1807 { | |
10313 | 1808 symbol_table *inst = get_instance (xcurrent_scope); |
1809 | |
1810 return inst ? inst->do_is_global (name) : false; | |
7336 | 1811 } |
1812 } | |
3011 | 1813 |
7761
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
1814 static void dump (std::ostream& os, scope_id scope = xcurrent_scope); |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
1815 |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
1816 static void dump_global (std::ostream& os); |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
1817 |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
1818 static void dump_functions (std::ostream& os); |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
1819 |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
1820 static void cache_name (scope_id scope, const std::string& name) |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
1821 { |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
1822 symbol_table *inst = get_instance (scope, false); |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
1823 |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
1824 if (inst) |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
1825 inst->do_cache_name (name); |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
1826 } |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
1827 |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
1828 static void lock_subfunctions (scope_id scope = xcurrent_scope) |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
1829 { |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
1830 for (fcn_table_iterator p = fcn_table.begin (); |
10313 | 1831 p != fcn_table.end (); p++) |
7761
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
1832 p->second.lock_subfunction (scope); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11584
diff
changeset
|
1833 } |
7761
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
1834 |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
1835 static void unlock_subfunctions (scope_id scope = xcurrent_scope) |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
1836 { |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
1837 for (fcn_table_iterator p = fcn_table.begin (); |
10313 | 1838 p != fcn_table.end (); p++) |
7761
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
1839 p->second.unlock_subfunction (scope); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11584
diff
changeset
|
1840 } |
7761
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
1841 |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
1842 static void free_scope (scope_id scope) |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
1843 { |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
1844 if (scope == xglobal_scope || scope == xtop_scope) |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
1845 error ("can't free global or top-level scopes!"); |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
1846 else |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
1847 symbol_table::scope_id_cache::free (scope); |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
1848 } |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
1849 |
8819
96d87674b818
also stash directory name for subfunctions
John W. Eaton <jwe@octave.org>
parents:
8691
diff
changeset
|
1850 static void stash_dir_name_for_subfunctions (scope_id scope, |
10313 | 1851 const std::string& dir_name); |
8819
96d87674b818
also stash directory name for subfunctions
John W. Eaton <jwe@octave.org>
parents:
8691
diff
changeset
|
1852 |
9581
3d0d2bda3a0f
fix previous change, avoid duplicate loads of methods in descendant classes
Jaroslav Hajek <highegg@gmail.com>
parents:
9509
diff
changeset
|
1853 static void add_to_parent_map (const std::string& classname, |
10313 | 1854 const std::list<std::string>& parent_list) |
9581
3d0d2bda3a0f
fix previous change, avoid duplicate loads of methods in descendant classes
Jaroslav Hajek <highegg@gmail.com>
parents:
9509
diff
changeset
|
1855 { |
3d0d2bda3a0f
fix previous change, avoid duplicate loads of methods in descendant classes
Jaroslav Hajek <highegg@gmail.com>
parents:
9509
diff
changeset
|
1856 parent_map[classname] = parent_list; |
3d0d2bda3a0f
fix previous change, avoid duplicate loads of methods in descendant classes
Jaroslav Hajek <highegg@gmail.com>
parents:
9509
diff
changeset
|
1857 } |
3d0d2bda3a0f
fix previous change, avoid duplicate loads of methods in descendant classes
Jaroslav Hajek <highegg@gmail.com>
parents:
9509
diff
changeset
|
1858 |
11238
1783b360976f
also consider parent classes when checking if class methods are out of date
John W. Eaton <jwe@octave.org>
parents:
10633
diff
changeset
|
1859 static std::list<std::string> |
1783b360976f
also consider parent classes when checking if class methods are out of date
John W. Eaton <jwe@octave.org>
parents:
10633
diff
changeset
|
1860 parent_classes (const std::string& dispatch_type) |
1783b360976f
also consider parent classes when checking if class methods are out of date
John W. Eaton <jwe@octave.org>
parents:
10633
diff
changeset
|
1861 { |
1783b360976f
also consider parent classes when checking if class methods are out of date
John W. Eaton <jwe@octave.org>
parents:
10633
diff
changeset
|
1862 std::list<std::string> retval; |
1783b360976f
also consider parent classes when checking if class methods are out of date
John W. Eaton <jwe@octave.org>
parents:
10633
diff
changeset
|
1863 |
1783b360976f
also consider parent classes when checking if class methods are out of date
John W. Eaton <jwe@octave.org>
parents:
10633
diff
changeset
|
1864 const_parent_map_iterator it = parent_map.find (dispatch_type); |
1783b360976f
also consider parent classes when checking if class methods are out of date
John W. Eaton <jwe@octave.org>
parents:
10633
diff
changeset
|
1865 |
1783b360976f
also consider parent classes when checking if class methods are out of date
John W. Eaton <jwe@octave.org>
parents:
10633
diff
changeset
|
1866 if (it != parent_map.end ()) |
1783b360976f
also consider parent classes when checking if class methods are out of date
John W. Eaton <jwe@octave.org>
parents:
10633
diff
changeset
|
1867 retval = it->second; |
1783b360976f
also consider parent classes when checking if class methods are out of date
John W. Eaton <jwe@octave.org>
parents:
10633
diff
changeset
|
1868 |
12130
3229572cbe23
symbol_table::parent_classes: also add parents of parents to the list
John W. Eaton <jwe@octave.org>
parents:
12122
diff
changeset
|
1869 for (std::list<std::string>::const_iterator lit = retval.begin (); |
3229572cbe23
symbol_table::parent_classes: also add parents of parents to the list
John W. Eaton <jwe@octave.org>
parents:
12122
diff
changeset
|
1870 lit != retval.end (); lit++) |
3229572cbe23
symbol_table::parent_classes: also add parents of parents to the list
John W. Eaton <jwe@octave.org>
parents:
12122
diff
changeset
|
1871 { |
3229572cbe23
symbol_table::parent_classes: also add parents of parents to the list
John W. Eaton <jwe@octave.org>
parents:
12122
diff
changeset
|
1872 // Search for parents of parents and append them to the list. |
3229572cbe23
symbol_table::parent_classes: also add parents of parents to the list
John W. Eaton <jwe@octave.org>
parents:
12122
diff
changeset
|
1873 |
3229572cbe23
symbol_table::parent_classes: also add parents of parents to the list
John W. Eaton <jwe@octave.org>
parents:
12122
diff
changeset
|
1874 // FIXME -- should we worry about a circular inheritance graph? |
3229572cbe23
symbol_table::parent_classes: also add parents of parents to the list
John W. Eaton <jwe@octave.org>
parents:
12122
diff
changeset
|
1875 |
3229572cbe23
symbol_table::parent_classes: also add parents of parents to the list
John W. Eaton <jwe@octave.org>
parents:
12122
diff
changeset
|
1876 std::list<std::string> parents = parent_classes (*lit); |
3229572cbe23
symbol_table::parent_classes: also add parents of parents to the list
John W. Eaton <jwe@octave.org>
parents:
12122
diff
changeset
|
1877 |
3229572cbe23
symbol_table::parent_classes: also add parents of parents to the list
John W. Eaton <jwe@octave.org>
parents:
12122
diff
changeset
|
1878 if (! parents.empty ()) |
3229572cbe23
symbol_table::parent_classes: also add parents of parents to the list
John W. Eaton <jwe@octave.org>
parents:
12122
diff
changeset
|
1879 retval.insert (retval.end (), parents.begin (), parents.end ()); |
3229572cbe23
symbol_table::parent_classes: also add parents of parents to the list
John W. Eaton <jwe@octave.org>
parents:
12122
diff
changeset
|
1880 } |
3229572cbe23
symbol_table::parent_classes: also add parents of parents to the list
John W. Eaton <jwe@octave.org>
parents:
12122
diff
changeset
|
1881 |
11238
1783b360976f
also consider parent classes when checking if class methods are out of date
John W. Eaton <jwe@octave.org>
parents:
10633
diff
changeset
|
1882 return retval; |
1783b360976f
also consider parent classes when checking if class methods are out of date
John W. Eaton <jwe@octave.org>
parents:
10633
diff
changeset
|
1883 } |
1783b360976f
also consider parent classes when checking if class methods are out of date
John W. Eaton <jwe@octave.org>
parents:
10633
diff
changeset
|
1884 |
9639
8d79f36ebdde
store scope->function pointer
Jaroslav Hajek <highegg@gmail.com>
parents:
9581
diff
changeset
|
1885 static octave_user_function *get_curr_fcn (scope_id scope = xcurrent_scope) |
8d79f36ebdde
store scope->function pointer
Jaroslav Hajek <highegg@gmail.com>
parents:
9581
diff
changeset
|
1886 { |
8d79f36ebdde
store scope->function pointer
Jaroslav Hajek <highegg@gmail.com>
parents:
9581
diff
changeset
|
1887 symbol_table *inst = get_instance (scope); |
8d79f36ebdde
store scope->function pointer
Jaroslav Hajek <highegg@gmail.com>
parents:
9581
diff
changeset
|
1888 return inst->curr_fcn; |
8d79f36ebdde
store scope->function pointer
Jaroslav Hajek <highegg@gmail.com>
parents:
9581
diff
changeset
|
1889 } |
8d79f36ebdde
store scope->function pointer
Jaroslav Hajek <highegg@gmail.com>
parents:
9581
diff
changeset
|
1890 |
8d79f36ebdde
store scope->function pointer
Jaroslav Hajek <highegg@gmail.com>
parents:
9581
diff
changeset
|
1891 static void set_curr_fcn (octave_user_function *curr_fcn, |
8d79f36ebdde
store scope->function pointer
Jaroslav Hajek <highegg@gmail.com>
parents:
9581
diff
changeset
|
1892 scope_id scope = xcurrent_scope) |
8d79f36ebdde
store scope->function pointer
Jaroslav Hajek <highegg@gmail.com>
parents:
9581
diff
changeset
|
1893 { |
8d79f36ebdde
store scope->function pointer
Jaroslav Hajek <highegg@gmail.com>
parents:
9581
diff
changeset
|
1894 assert (scope != xtop_scope && scope != xglobal_scope); |
8d79f36ebdde
store scope->function pointer
Jaroslav Hajek <highegg@gmail.com>
parents:
9581
diff
changeset
|
1895 symbol_table *inst = get_instance (scope); |
8d79f36ebdde
store scope->function pointer
Jaroslav Hajek <highegg@gmail.com>
parents:
9581
diff
changeset
|
1896 // FIXME: normally, functions should not usurp each other's scope. |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11584
diff
changeset
|
1897 // If for any incredible reason this is needed, call |
9639
8d79f36ebdde
store scope->function pointer
Jaroslav Hajek <highegg@gmail.com>
parents:
9581
diff
changeset
|
1898 // set_user_function (0, scope) first. |
8d79f36ebdde
store scope->function pointer
Jaroslav Hajek <highegg@gmail.com>
parents:
9581
diff
changeset
|
1899 assert (inst->curr_fcn == 0 || curr_fcn == 0); |
8d79f36ebdde
store scope->function pointer
Jaroslav Hajek <highegg@gmail.com>
parents:
9581
diff
changeset
|
1900 inst->curr_fcn = curr_fcn; |
8d79f36ebdde
store scope->function pointer
Jaroslav Hajek <highegg@gmail.com>
parents:
9581
diff
changeset
|
1901 } |
8d79f36ebdde
store scope->function pointer
Jaroslav Hajek <highegg@gmail.com>
parents:
9581
diff
changeset
|
1902 |
9981
692ab4eaf965
clean up top-level variables when exiting Octave
Jaroslav Hajek <highegg@gmail.com>
parents:
9958
diff
changeset
|
1903 static void cleanup (void); |
692ab4eaf965
clean up top-level variables when exiting Octave
Jaroslav Hajek <highegg@gmail.com>
parents:
9958
diff
changeset
|
1904 |
8 | 1905 private: |
1906 | |
12122
f4689107dd8c
Explicitly disallow copying in some classes.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
11586
diff
changeset
|
1907 // No copying! |
f4689107dd8c
Explicitly disallow copying in some classes.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
11586
diff
changeset
|
1908 |
f4689107dd8c
Explicitly disallow copying in some classes.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
11586
diff
changeset
|
1909 symbol_table (const symbol_table&); |
f4689107dd8c
Explicitly disallow copying in some classes.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
11586
diff
changeset
|
1910 |
f4689107dd8c
Explicitly disallow copying in some classes.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
11586
diff
changeset
|
1911 symbol_table& operator = (const symbol_table&); |
f4689107dd8c
Explicitly disallow copying in some classes.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
11586
diff
changeset
|
1912 |
7761
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
1913 typedef std::map<std::string, symbol_record>::const_iterator table_const_iterator; |
7336 | 1914 typedef std::map<std::string, symbol_record>::iterator table_iterator; |
1915 | |
7761
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
1916 typedef std::map<std::string, octave_value>::const_iterator global_table_const_iterator; |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1917 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
|
1918 |
7761
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
1919 typedef std::map<std::string, octave_value>::const_iterator persistent_table_const_iterator; |
7336 | 1920 typedef std::map<std::string, octave_value>::iterator persistent_table_iterator; |
1921 | |
1922 typedef std::map<scope_id, symbol_table*>::const_iterator all_instances_const_iterator; | |
1923 typedef std::map<scope_id, symbol_table*>::iterator all_instances_iterator; | |
1924 | |
7761
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
1925 typedef std::map<std::string, fcn_info>::const_iterator fcn_table_const_iterator; |
7336 | 1926 typedef std::map<std::string, fcn_info>::iterator fcn_table_iterator; |
1927 | |
7761
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
1928 // Name for this table (usually the file name of the function |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
1929 // corresponding to the scope); |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
1930 std::string table_name; |
7336 | 1931 |
1932 // Map from symbol names to symbol info. | |
1933 std::map<std::string, symbol_record> table; | |
1934 | |
9639
8d79f36ebdde
store scope->function pointer
Jaroslav Hajek <highegg@gmail.com>
parents:
9581
diff
changeset
|
1935 // The associated user code (may be null). |
8d79f36ebdde
store scope->function pointer
Jaroslav Hajek <highegg@gmail.com>
parents:
9581
diff
changeset
|
1936 octave_user_function *curr_fcn; |
8d79f36ebdde
store scope->function pointer
Jaroslav Hajek <highegg@gmail.com>
parents:
9581
diff
changeset
|
1937 |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1938 // 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
|
1939 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
|
1940 |
7336 | 1941 // Map from names of persistent variables to values. |
1942 std::map<std::string, octave_value> persistent_table; | |
1943 | |
1944 // Pointer to symbol table for current scope (variables only). | |
1945 static symbol_table *instance; | |
3011 | 1946 |
7336 | 1947 // Map from scope id to symbol table instances. |
1948 static std::map<scope_id, symbol_table*> all_instances; | |
1949 | |
1950 // Map from function names to function info (subfunctions, private | |
1951 // functions, class constructors, class methods, etc.) | |
1952 static std::map<std::string, fcn_info> fcn_table; | |
1953 | |
7972
5bf4e2c13ed8
make superiorto and inferiorto work
John W. Eaton <jwe@octave.org>
parents:
7901
diff
changeset
|
1954 // Mape from class names to set of classes that have lower |
5bf4e2c13ed8
make superiorto and inferiorto work
John W. Eaton <jwe@octave.org>
parents:
7901
diff
changeset
|
1955 // precedence. |
5bf4e2c13ed8
make superiorto and inferiorto work
John W. Eaton <jwe@octave.org>
parents:
7901
diff
changeset
|
1956 static std::map<std::string, std::set<std::string> > class_precedence_table; |
5bf4e2c13ed8
make superiorto and inferiorto work
John W. Eaton <jwe@octave.org>
parents:
7901
diff
changeset
|
1957 |
5bf4e2c13ed8
make superiorto and inferiorto work
John W. Eaton <jwe@octave.org>
parents:
7901
diff
changeset
|
1958 typedef std::map<std::string, std::set<std::string> >::const_iterator class_precedence_table_const_iterator; |
5bf4e2c13ed8
make superiorto and inferiorto work
John W. Eaton <jwe@octave.org>
parents:
7901
diff
changeset
|
1959 typedef std::map<std::string, std::set<std::string> >::iterator class_precedence_table_iterator; |
5bf4e2c13ed8
make superiorto and inferiorto work
John W. Eaton <jwe@octave.org>
parents:
7901
diff
changeset
|
1960 |
9581
3d0d2bda3a0f
fix previous change, avoid duplicate loads of methods in descendant classes
Jaroslav Hajek <highegg@gmail.com>
parents:
9509
diff
changeset
|
1961 // Map from class names to parent class names. |
3d0d2bda3a0f
fix previous change, avoid duplicate loads of methods in descendant classes
Jaroslav Hajek <highegg@gmail.com>
parents:
9509
diff
changeset
|
1962 static std::map<std::string, std::list<std::string> > parent_map; |
3d0d2bda3a0f
fix previous change, avoid duplicate loads of methods in descendant classes
Jaroslav Hajek <highegg@gmail.com>
parents:
9509
diff
changeset
|
1963 |
3d0d2bda3a0f
fix previous change, avoid duplicate loads of methods in descendant classes
Jaroslav Hajek <highegg@gmail.com>
parents:
9509
diff
changeset
|
1964 typedef std::map<std::string, std::list<std::string> >::const_iterator const_parent_map_iterator; |
3d0d2bda3a0f
fix previous change, avoid duplicate loads of methods in descendant classes
Jaroslav Hajek <highegg@gmail.com>
parents:
9509
diff
changeset
|
1965 typedef std::map<std::string, std::list<std::string> >::iterator parent_map_iterator; |
3d0d2bda3a0f
fix previous change, avoid duplicate loads of methods in descendant classes
Jaroslav Hajek <highegg@gmail.com>
parents:
9509
diff
changeset
|
1966 |
7336 | 1967 static const scope_id xglobal_scope; |
1968 static const scope_id xtop_scope; | |
1969 | |
1970 static scope_id xcurrent_scope; | |
1971 | |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1972 static context_id xcurrent_context; |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1973 |
7761
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
1974 symbol_table (void) |
11584
cda4aa780d58
Another round of initialising members in the constructor initialisation list
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
11557
diff
changeset
|
1975 : table_name (), table (), curr_fcn (0), persistent_table () { } |
7336 | 1976 |
1977 ~symbol_table (void) { } | |
3011 | 1978 |
7761
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
1979 static symbol_table *get_instance (scope_id scope, bool create = true) |
7336 | 1980 { |
1981 symbol_table *retval = 0; | |
1982 | |
7761
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
1983 bool ok = true; |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
1984 |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
1985 if (scope != xglobal_scope) |
7336 | 1986 { |
10313 | 1987 if (scope == xcurrent_scope) |
1988 { | |
1989 if (! instance && create) | |
1990 { | |
1991 symbol_table *inst = new symbol_table (); | |
1992 | |
1993 if (inst) | |
1994 { | |
1995 all_instances[scope] = instance = inst; | |
1996 | |
1997 if (scope == xtop_scope) | |
1998 instance->do_cache_name ("top-level"); | |
1999 } | |
2000 } | |
2001 | |
2002 if (! instance) | |
2003 ok = false; | |
2004 | |
2005 retval = instance; | |
2006 } | |
2007 else | |
2008 { | |
2009 all_instances_iterator p = all_instances.find (scope); | |
2010 | |
2011 if (p == all_instances.end ()) | |
2012 { | |
2013 if (create) | |
2014 { | |
2015 retval = new symbol_table (); | |
2016 | |
2017 if (retval) | |
2018 all_instances[scope] = retval; | |
2019 else | |
2020 ok = false; | |
2021 } | |
2022 else | |
2023 ok = false; | |
2024 } | |
2025 else | |
2026 retval = p->second; | |
2027 } | |
7336 | 2028 } |
2029 | |
7761
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
2030 if (! ok) |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
2031 error ("unable to %s symbol_table object for scope %d!", |
10313 | 2032 create ? "create" : "find", scope); |
7761
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
2033 |
7336 | 2034 return retval; |
2035 } | |
2036 | |
2037 void insert_symbol_record (const symbol_record& sr) | |
2038 { | |
2039 table[sr.name ()] = sr; | |
2040 } | |
4238 | 2041 |
4913 | 2042 void |
7336 | 2043 do_dup_scope (symbol_table& new_symbol_table) const |
2044 { | |
7761
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
2045 for (table_const_iterator p = table.begin (); p != table.end (); p++) |
7336 | 2046 new_symbol_table.insert_symbol_record (p->second.dup ()); |
2047 } | |
2048 | |
2049 symbol_record do_find_symbol (const std::string& name) | |
2050 { | |
2051 table_iterator p = table.find (name); | |
2052 | |
2053 if (p == table.end ()) | |
2054 return do_insert (name); | |
2055 else | |
2056 return p->second; | |
2057 } | |
2058 | |
8906
ab87d08d9a1b
improve symbol inheritance for anonymous functions
John W. Eaton <jwe@octave.org>
parents:
8884
diff
changeset
|
2059 void do_inherit (symbol_table& donor_table, context_id donor_context) |
7336 | 2060 { |
8906
ab87d08d9a1b
improve symbol inheritance for anonymous functions
John W. Eaton <jwe@octave.org>
parents:
8884
diff
changeset
|
2061 for (table_iterator p = table.begin (); p != table.end (); p++) |
7336 | 2062 { |
10313 | 2063 symbol_record& sr = p->second; |
2064 | |
2065 if (! (sr.is_automatic () || sr.is_formal ())) | |
2066 { | |
2067 std::string nm = sr.name (); | |
2068 | |
2069 if (nm != "__retval__") | |
2070 { | |
2071 octave_value val = donor_table.do_varval (nm, donor_context); | |
2072 | |
2073 if (val.is_defined ()) | |
2074 { | |
2075 sr.varref (0) = val; | |
2076 | |
2077 sr.mark_inherited (); | |
2078 } | |
2079 } | |
2080 } | |
7336 | 2081 } |
2082 } | |
2083 | |
9413
5cd879a0d8c4
speed-up function call by caching its name lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
9409
diff
changeset
|
2084 static fcn_info *get_fcn_info (const std::string& name) |
5cd879a0d8c4
speed-up function call by caching its name lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
9409
diff
changeset
|
2085 { |
5cd879a0d8c4
speed-up function call by caching its name lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
9409
diff
changeset
|
2086 fcn_table_iterator p = fcn_table.find (name); |
5cd879a0d8c4
speed-up function call by caching its name lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
9409
diff
changeset
|
2087 return p != fcn_table.end () ? &p->second : 0; |
5cd879a0d8c4
speed-up function call by caching its name lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
9409
diff
changeset
|
2088 } |
5cd879a0d8c4
speed-up function call by caching its name lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
9409
diff
changeset
|
2089 |
7336 | 2090 octave_value |
9445
c5f03874ea2a
simplify symbol_table::find and associated functions
Jaroslav Hajek <highegg@gmail.com>
parents:
9444
diff
changeset
|
2091 do_find (const std::string& name, const octave_value_list& args, |
9463
d34baf412786
support non-local function lookups in str2func
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
2092 bool skip_variables, bool local_funcs); |
7336 | 2093 |
9444
0c785ad961fa
improve behavior of builtin
John W. Eaton <jwe@octave.org>
parents:
9443
diff
changeset
|
2094 octave_value do_builtin_find (const std::string& name); |
0c785ad961fa
improve behavior of builtin
John W. Eaton <jwe@octave.org>
parents:
9443
diff
changeset
|
2095 |
7336 | 2096 symbol_record& do_insert (const std::string& name) |
2097 { | |
2098 table_iterator p = table.find (name); | |
2099 | |
2100 return p == table.end () | |
2101 ? (table[name] = symbol_record (name)) : p->second; | |
2102 } | |
2103 | |
8881
8ed42c679af5
after defining a script or function, clear local variables created for parsing
John W. Eaton <jwe@octave.org>
parents:
8819
diff
changeset
|
2104 void do_force_variable (const std::string& name, context_id context) |
8ed42c679af5
after defining a script or function, clear local variables created for parsing
John W. Eaton <jwe@octave.org>
parents:
8819
diff
changeset
|
2105 { |
8ed42c679af5
after defining a script or function, clear local variables created for parsing
John W. Eaton <jwe@octave.org>
parents:
8819
diff
changeset
|
2106 table_iterator p = table.find (name); |
8ed42c679af5
after defining a script or function, clear local variables created for parsing
John W. Eaton <jwe@octave.org>
parents:
8819
diff
changeset
|
2107 |
8ed42c679af5
after defining a script or function, clear local variables created for parsing
John W. Eaton <jwe@octave.org>
parents:
8819
diff
changeset
|
2108 if (p == table.end ()) |
8ed42c679af5
after defining a script or function, clear local variables created for parsing
John W. Eaton <jwe@octave.org>
parents:
8819
diff
changeset
|
2109 { |
10313 | 2110 symbol_record& sr = do_insert (name); |
2111 | |
2112 sr.force_variable (context); | |
8881
8ed42c679af5
after defining a script or function, clear local variables created for parsing
John W. Eaton <jwe@octave.org>
parents:
8819
diff
changeset
|
2113 } |
8884 | 2114 else |
2115 p->second.force_variable (context); | |
8881
8ed42c679af5
after defining a script or function, clear local variables created for parsing
John W. Eaton <jwe@octave.org>
parents:
8819
diff
changeset
|
2116 } |
8ed42c679af5
after defining a script or function, clear local variables created for parsing
John W. Eaton <jwe@octave.org>
parents:
8819
diff
changeset
|
2117 |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7761
diff
changeset
|
2118 octave_value& do_varref (const std::string& name, context_id context) |
7336 | 2119 { |
2120 table_iterator p = table.find (name); | |
2121 | |
2122 if (p == table.end ()) | |
2123 { | |
10313 | 2124 symbol_record& sr = do_insert (name); |
2125 | |
2126 return sr.varref (context); | |
7336 | 2127 } |
2128 else | |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7761
diff
changeset
|
2129 return p->second.varref (context); |
7336 | 2130 } |
4913 | 2131 |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7761
diff
changeset
|
2132 octave_value do_varval (const std::string& name, context_id context) const |
7336 | 2133 { |
7761
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
2134 table_const_iterator p = table.find (name); |
7336 | 2135 |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7761
diff
changeset
|
2136 return (p != table.end ()) ? p->second.varval (context) : octave_value (); |
7336 | 2137 } |
2138 | |
2139 octave_value& do_persistent_varref (const std::string& name) | |
2140 { | |
2141 persistent_table_iterator p = persistent_table.find (name); | |
2142 | |
2143 return (p == persistent_table.end ()) | |
2144 ? persistent_table[name] : p->second; | |
2145 } | |
2146 | |
2147 octave_value do_persistent_varval (const std::string& name) | |
2148 { | |
7761
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
2149 persistent_table_const_iterator p = persistent_table.find (name); |
7336 | 2150 |
2151 return (p != persistent_table.end ()) ? p->second : octave_value (); | |
2152 } | |
2153 | |
2154 void do_erase_persistent (const std::string& name) | |
2155 { | |
2156 persistent_table_iterator p = persistent_table.find (name); | |
2157 | |
2158 if (p != persistent_table.end ()) | |
2159 persistent_table.erase (p); | |
2160 } | |
2161 | |
2162 bool do_is_variable (const std::string& name) const | |
2163 { | |
2164 bool retval = false; | |
2165 | |
7761
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
2166 table_const_iterator p = table.find (name); |
7336 | 2167 |
2168 if (p != table.end ()) | |
2169 { | |
10313 | 2170 const symbol_record& sr = p->second; |
2171 | |
2172 retval = sr.is_variable (); | |
7336 | 2173 } |
2174 | |
2175 return retval; | |
2176 } | |
2177 | |
2178 void do_push_context (void) | |
2179 { | |
2180 for (table_iterator p = table.begin (); p != table.end (); p++) | |
2181 p->second.push_context (); | |
2182 } | |
2183 | |
2184 void do_pop_context (void) | |
2185 { | |
7374 | 2186 for (table_iterator p = table.begin (); p != table.end (); ) |
2187 { | |
10313 | 2188 if (p->second.pop_context () == 0) |
2189 table.erase (p++); | |
2190 else | |
2191 p++; | |
7374 | 2192 } |
7336 | 2193 } |
2194 | |
2195 void do_clear_variables (void) | |
2196 { | |
2197 for (table_iterator p = table.begin (); p != table.end (); p++) | |
2198 p->second.clear (); | |
2199 } | |
2200 | |
9240
f27a8c07f0b2
clear -classes and support.
Robert T. Short <octave@phaselockedsystems.com>
parents:
9144
diff
changeset
|
2201 void do_clear_objects (void) |
f27a8c07f0b2
clear -classes and support.
Robert T. Short <octave@phaselockedsystems.com>
parents:
9144
diff
changeset
|
2202 { |
f27a8c07f0b2
clear -classes and support.
Robert T. Short <octave@phaselockedsystems.com>
parents:
9144
diff
changeset
|
2203 for (table_iterator p = table.begin (); p != table.end (); p++) |
f27a8c07f0b2
clear -classes and support.
Robert T. Short <octave@phaselockedsystems.com>
parents:
9144
diff
changeset
|
2204 { |
10313 | 2205 symbol_record& sr = p->second; |
2206 octave_value& val = sr.varref (); | |
2207 if (val.is_object()) | |
2208 p->second.clear (); | |
9240
f27a8c07f0b2
clear -classes and support.
Robert T. Short <octave@phaselockedsystems.com>
parents:
9144
diff
changeset
|
2209 } |
f27a8c07f0b2
clear -classes and support.
Robert T. Short <octave@phaselockedsystems.com>
parents:
9144
diff
changeset
|
2210 } |
f27a8c07f0b2
clear -classes and support.
Robert T. Short <octave@phaselockedsystems.com>
parents:
9144
diff
changeset
|
2211 |
f27a8c07f0b2
clear -classes and support.
Robert T. Short <octave@phaselockedsystems.com>
parents:
9144
diff
changeset
|
2212 void do_unmark_forced_variables (void) |
8881
8ed42c679af5
after defining a script or function, clear local variables created for parsing
John W. Eaton <jwe@octave.org>
parents:
8819
diff
changeset
|
2213 { |
8ed42c679af5
after defining a script or function, clear local variables created for parsing
John W. Eaton <jwe@octave.org>
parents:
8819
diff
changeset
|
2214 for (table_iterator p = table.begin (); p != table.end (); p++) |
9009
da58ec8f62e8
tag bug don't define forced variables
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
2215 p->second.unmark_forced (); |
8881
8ed42c679af5
after defining a script or function, clear local variables created for parsing
John W. Eaton <jwe@octave.org>
parents:
8819
diff
changeset
|
2216 } |
8ed42c679af5
after defining a script or function, clear local variables created for parsing
John W. Eaton <jwe@octave.org>
parents:
8819
diff
changeset
|
2217 |
7336 | 2218 void do_clear_global (const std::string& name) |
2219 { | |
2220 table_iterator p = table.find (name); | |
4913 | 2221 |
7336 | 2222 if (p != table.end ()) |
2223 { | |
10313 | 2224 symbol_record& sr = p->second; |
2225 | |
2226 if (sr.is_global ()) | |
9315
73e36b147e45
properly clear global variables
Jaroslav Hajek <highegg@gmail.com>
parents:
9260
diff
changeset
|
2227 sr.unmark_global (); |
7336 | 2228 } |
9315
73e36b147e45
properly clear global variables
Jaroslav Hajek <highegg@gmail.com>
parents:
9260
diff
changeset
|
2229 |
73e36b147e45
properly clear global variables
Jaroslav Hajek <highegg@gmail.com>
parents:
9260
diff
changeset
|
2230 global_table_iterator q = global_table.find (name); |
73e36b147e45
properly clear global variables
Jaroslav Hajek <highegg@gmail.com>
parents:
9260
diff
changeset
|
2231 |
73e36b147e45
properly clear global variables
Jaroslav Hajek <highegg@gmail.com>
parents:
9260
diff
changeset
|
2232 if (q != global_table.end ()) |
73e36b147e45
properly clear global variables
Jaroslav Hajek <highegg@gmail.com>
parents:
9260
diff
changeset
|
2233 global_table.erase (q); |
73e36b147e45
properly clear global variables
Jaroslav Hajek <highegg@gmail.com>
parents:
9260
diff
changeset
|
2234 |
7336 | 2235 } |
2236 | |
2237 void do_clear_variable (const std::string& name) | |
2238 { | |
2239 table_iterator p = table.find (name); | |
2240 | |
2241 if (p != table.end ()) | |
2242 p->second.clear (); | |
2243 } | |
2244 | |
2245 void do_clear_global_pattern (const std::string& pat) | |
2246 { | |
2247 glob_match pattern (pat); | |
2248 | |
2249 for (table_iterator p = table.begin (); p != table.end (); p++) | |
2250 { | |
10313 | 2251 symbol_record& sr = p->second; |
2252 | |
2253 if (sr.is_global () && pattern.match (sr.name ())) | |
9315
73e36b147e45
properly clear global variables
Jaroslav Hajek <highegg@gmail.com>
parents:
9260
diff
changeset
|
2254 sr.unmark_global (); |
7336 | 2255 } |
9315
73e36b147e45
properly clear global variables
Jaroslav Hajek <highegg@gmail.com>
parents:
9260
diff
changeset
|
2256 |
11548
50a7935f2512
Don't invalidate iterators when calling std::map::erase, found by cppcheck
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
11523
diff
changeset
|
2257 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11584
diff
changeset
|
2258 for (global_table_iterator q = global_table.begin (); |
11548
50a7935f2512
Don't invalidate iterators when calling std::map::erase, found by cppcheck
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
11523
diff
changeset
|
2259 q != global_table.end ();) |
9315
73e36b147e45
properly clear global variables
Jaroslav Hajek <highegg@gmail.com>
parents:
9260
diff
changeset
|
2260 { |
10313 | 2261 if (pattern.match (q->first)) |
11548
50a7935f2512
Don't invalidate iterators when calling std::map::erase, found by cppcheck
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
11523
diff
changeset
|
2262 global_table.erase (q++); //Gotta be careful to not |
50a7935f2512
Don't invalidate iterators when calling std::map::erase, found by cppcheck
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
11523
diff
changeset
|
2263 //invalidate iterators |
50a7935f2512
Don't invalidate iterators when calling std::map::erase, found by cppcheck
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
11523
diff
changeset
|
2264 else |
50a7935f2512
Don't invalidate iterators when calling std::map::erase, found by cppcheck
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
11523
diff
changeset
|
2265 q++; |
9315
73e36b147e45
properly clear global variables
Jaroslav Hajek <highegg@gmail.com>
parents:
9260
diff
changeset
|
2266 } |
73e36b147e45
properly clear global variables
Jaroslav Hajek <highegg@gmail.com>
parents:
9260
diff
changeset
|
2267 |
73e36b147e45
properly clear global variables
Jaroslav Hajek <highegg@gmail.com>
parents:
9260
diff
changeset
|
2268 |
7336 | 2269 } |
2270 | |
2271 void do_clear_variable_pattern (const std::string& pat) | |
2272 { | |
2273 glob_match pattern (pat); | |
2274 | |
2275 for (table_iterator p = table.begin (); p != table.end (); p++) | |
2276 { | |
10313 | 2277 symbol_record& sr = p->second; |
2278 | |
2279 if (sr.is_defined () || sr.is_global ()) | |
2280 { | |
2281 if (pattern.match (sr.name ())) | |
2282 sr.clear (); | |
2283 } | |
7336 | 2284 } |
2285 } | |
2286 | |
7779
791231dac333
Add regexp matching to Fwho and Fclear
David Bateman <dbateman@free.fr>
parents:
7767
diff
changeset
|
2287 void do_clear_variable_regexp (const std::string& pat) |
791231dac333
Add regexp matching to Fwho and Fclear
David Bateman <dbateman@free.fr>
parents:
7767
diff
changeset
|
2288 { |
791231dac333
Add regexp matching to Fwho and Fclear
David Bateman <dbateman@free.fr>
parents:
7767
diff
changeset
|
2289 regex_match pattern (pat); |
791231dac333
Add regexp matching to Fwho and Fclear
David Bateman <dbateman@free.fr>
parents:
7767
diff
changeset
|
2290 |
791231dac333
Add regexp matching to Fwho and Fclear
David Bateman <dbateman@free.fr>
parents:
7767
diff
changeset
|
2291 for (table_iterator p = table.begin (); p != table.end (); p++) |
791231dac333
Add regexp matching to Fwho and Fclear
David Bateman <dbateman@free.fr>
parents:
7767
diff
changeset
|
2292 { |
10313 | 2293 symbol_record& sr = p->second; |
2294 | |
2295 if (sr.is_defined () || sr.is_global ()) | |
2296 { | |
2297 if (pattern.match (sr.name ())) | |
2298 sr.clear (); | |
2299 } | |
7779
791231dac333
Add regexp matching to Fwho and Fclear
David Bateman <dbateman@free.fr>
parents:
7767
diff
changeset
|
2300 } |
791231dac333
Add regexp matching to Fwho and Fclear
David Bateman <dbateman@free.fr>
parents:
7767
diff
changeset
|
2301 } |
791231dac333
Add regexp matching to Fwho and Fclear
David Bateman <dbateman@free.fr>
parents:
7767
diff
changeset
|
2302 |
11557
e9d72a3caa46
mark automatic variables as automatic
John W. Eaton <jwe@octave.org>
parents:
11548
diff
changeset
|
2303 void do_mark_automatic (const std::string& name) |
e9d72a3caa46
mark automatic variables as automatic
John W. Eaton <jwe@octave.org>
parents:
11548
diff
changeset
|
2304 { |
e9d72a3caa46
mark automatic variables as automatic
John W. Eaton <jwe@octave.org>
parents:
11548
diff
changeset
|
2305 do_insert (name).mark_automatic (); |
e9d72a3caa46
mark automatic variables as automatic
John W. Eaton <jwe@octave.org>
parents:
11548
diff
changeset
|
2306 } |
e9d72a3caa46
mark automatic variables as automatic
John W. Eaton <jwe@octave.org>
parents:
11548
diff
changeset
|
2307 |
7336 | 2308 void do_mark_hidden (const std::string& name) |
2309 { | |
10633
d022061c288d
symbol_table minor improvements
Jaroslav Hajek <highegg@gmail.com>
parents:
10559
diff
changeset
|
2310 do_insert (name).mark_hidden (); |
7336 | 2311 } |
2312 | |
2313 void do_mark_global (const std::string& name) | |
2314 { | |
10633
d022061c288d
symbol_table minor improvements
Jaroslav Hajek <highegg@gmail.com>
parents:
10559
diff
changeset
|
2315 do_insert (name).mark_global (); |
7336 | 2316 } |
2317 | |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7761
diff
changeset
|
2318 std::list<symbol_record> |
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7761
diff
changeset
|
2319 do_all_variables (context_id context, bool defined_only) const |
7336 | 2320 { |
2321 std::list<symbol_record> retval; | |
2322 | |
7761
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
2323 for (table_const_iterator p = table.begin (); p != table.end (); p++) |
7336 | 2324 { |
10313 | 2325 const symbol_record& sr = p->second; |
2326 | |
2327 if (defined_only && ! sr.is_defined (context)) | |
2328 continue; | |
2329 | |
2330 retval.push_back (sr); | |
7336 | 2331 } |
2332 | |
2333 return retval; | |
2334 } | |
2335 | |
2336 std::list<symbol_record> do_glob (const std::string& pattern, | |
10313 | 2337 bool vars_only = false) const |
7336 | 2338 { |
2339 std::list<symbol_record> retval; | |
2340 | |
2341 glob_match pat (pattern); | |
2342 | |
7761
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
2343 for (table_const_iterator p = table.begin (); p != table.end (); p++) |
7336 | 2344 { |
10313 | 2345 if (pat.match (p->first)) |
2346 { | |
2347 const symbol_record& sr = p->second; | |
2348 | |
2349 if (vars_only && ! sr.is_variable ()) | |
2350 continue; | |
2351 | |
2352 retval.push_back (sr); | |
2353 } | |
7336 | 2354 } |
2355 | |
2356 return retval; | |
2357 } | |
2358 | |
7779
791231dac333
Add regexp matching to Fwho and Fclear
David Bateman <dbateman@free.fr>
parents:
7767
diff
changeset
|
2359 std::list<symbol_record> do_regexp (const std::string& pattern, |
10313 | 2360 bool vars_only = false) const |
7779
791231dac333
Add regexp matching to Fwho and Fclear
David Bateman <dbateman@free.fr>
parents:
7767
diff
changeset
|
2361 { |
791231dac333
Add regexp matching to Fwho and Fclear
David Bateman <dbateman@free.fr>
parents:
7767
diff
changeset
|
2362 std::list<symbol_record> retval; |
791231dac333
Add regexp matching to Fwho and Fclear
David Bateman <dbateman@free.fr>
parents:
7767
diff
changeset
|
2363 |
791231dac333
Add regexp matching to Fwho and Fclear
David Bateman <dbateman@free.fr>
parents:
7767
diff
changeset
|
2364 regex_match pat (pattern); |
791231dac333
Add regexp matching to Fwho and Fclear
David Bateman <dbateman@free.fr>
parents:
7767
diff
changeset
|
2365 |
791231dac333
Add regexp matching to Fwho and Fclear
David Bateman <dbateman@free.fr>
parents:
7767
diff
changeset
|
2366 for (table_const_iterator p = table.begin (); p != table.end (); p++) |
791231dac333
Add regexp matching to Fwho and Fclear
David Bateman <dbateman@free.fr>
parents:
7767
diff
changeset
|
2367 { |
10313 | 2368 if (pat.match (p->first)) |
2369 { | |
2370 const symbol_record& sr = p->second; | |
2371 | |
2372 if (vars_only && ! sr.is_variable ()) | |
2373 continue; | |
2374 | |
2375 retval.push_back (sr); | |
2376 } | |
7779
791231dac333
Add regexp matching to Fwho and Fclear
David Bateman <dbateman@free.fr>
parents:
7767
diff
changeset
|
2377 } |
791231dac333
Add regexp matching to Fwho and Fclear
David Bateman <dbateman@free.fr>
parents:
7767
diff
changeset
|
2378 |
791231dac333
Add regexp matching to Fwho and Fclear
David Bateman <dbateman@free.fr>
parents:
7767
diff
changeset
|
2379 return retval; |
791231dac333
Add regexp matching to Fwho and Fclear
David Bateman <dbateman@free.fr>
parents:
7767
diff
changeset
|
2380 } |
791231dac333
Add regexp matching to Fwho and Fclear
David Bateman <dbateman@free.fr>
parents:
7767
diff
changeset
|
2381 |
7336 | 2382 std::list<std::string> do_variable_names (void) |
2383 { | |
2384 std::list<std::string> retval; | |
2385 | |
7761
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
2386 for (table_const_iterator p = table.begin (); p != table.end (); p++) |
9260
9c2349a51218
properly unmark forced variables
John W. Eaton <jwe@octave.org>
parents:
9240
diff
changeset
|
2387 { |
10313 | 2388 if (p->second.is_variable ()) |
2389 retval.push_back (p->first); | |
9260
9c2349a51218
properly unmark forced variables
John W. Eaton <jwe@octave.org>
parents:
9240
diff
changeset
|
2390 } |
7336 | 2391 |
2392 retval.sort (); | |
2393 | |
2394 return retval; | |
2395 } | |
2396 | |
7761
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
2397 static std::map<std::string, octave_value> |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
2398 subfunctions_defined_in_scope (scope_id scope = xcurrent_scope) |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
2399 { |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
2400 std::map<std::string, octave_value> retval; |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
2401 |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
2402 for (fcn_table_const_iterator p = fcn_table.begin (); |
10313 | 2403 p != fcn_table.end (); p++) |
7761
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
2404 { |
10313 | 2405 std::pair<std::string, octave_value> tmp |
2406 = p->second.subfunction_defined_in_scope (scope); | |
2407 | |
2408 std::string nm = tmp.first; | |
2409 | |
2410 if (! nm.empty ()) | |
2411 retval[nm] = tmp.second; | |
7761
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
2412 } |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
2413 |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
2414 return retval; |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
2415 } |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
2416 |
7336 | 2417 bool do_is_local_variable (const std::string& name) const |
2418 { | |
7761
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
2419 table_const_iterator p = table.find (name); |
7336 | 2420 |
2421 return (p != table.end () | |
10313 | 2422 && ! p->second.is_global () |
2423 && p->second.is_defined ()); | |
7336 | 2424 } |
2425 | |
2426 bool do_is_global (const std::string& name) const | |
2427 { | |
7761
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
2428 table_const_iterator p = table.find (name); |
7336 | 2429 |
2430 return p != table.end () && p->second.is_global (); | |
2431 } | |
7761
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
2432 |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
2433 void do_dump (std::ostream& os); |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
2434 |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7753
diff
changeset
|
2435 void do_cache_name (const std::string& name) { table_name = name; } |
3011 | 2436 }; |
2790 | 2437 |
9450
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9446
diff
changeset
|
2438 extern bool out_of_date_check (octave_value& function, |
9509
c5330ef7aecd
fix handles to private functions, simplify out-of-date checks in symtab
Jaroslav Hajek <highegg@gmail.com>
parents:
9474
diff
changeset
|
2439 const std::string& dispatch_type = std::string (), |
c5330ef7aecd
fix handles to private functions, simplify out-of-date checks in symtab
Jaroslav Hajek <highegg@gmail.com>
parents:
9474
diff
changeset
|
2440 bool check_relative = true); |
9450
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9446
diff
changeset
|
2441 |
10087
090173f2db40
improve overload dispatching of built-in classes
Jaroslav Hajek <highegg@gmail.com>
parents:
10071
diff
changeset
|
2442 extern OCTINTERP_API std::string |
090173f2db40
improve overload dispatching of built-in classes
Jaroslav Hajek <highegg@gmail.com>
parents:
10071
diff
changeset
|
2443 get_dispatch_type (const octave_value_list& args); |
090173f2db40
improve overload dispatching of built-in classes
Jaroslav Hajek <highegg@gmail.com>
parents:
10071
diff
changeset
|
2444 extern OCTINTERP_API std::string |
10321
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10313
diff
changeset
|
2445 get_dispatch_type (const octave_value_list& args, builtin_type_t& builtin_type); |
8123
eb2beef9a9ff
clear breakpoints is function found to be out of date
David Bateman <dbateman@free.fr>
parents:
8051
diff
changeset
|
2446 |
8 | 2447 #endif |