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