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