Mercurial > hg > octave-avbm
annotate src/symtab.cc @ 7767:71f068b22fcc
scope and context fixes for function handles
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Wed, 07 May 2008 13:45:30 -0400 |
parents | 5adeea5de26c |
children | 5640a70cbab1 |
rev | line source |
---|---|
1 | 1 /* |
2 | |
7017 | 3 Copyright (C) 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, |
4 2002, 2003, 2004, 2005, 2006, 2007 John W. Eaton | |
7336 | 5 |
1 | 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. | |
1 | 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/>. | |
1 | 21 |
22 */ | |
23 | |
240 | 24 #ifdef HAVE_CONFIG_H |
1192 | 25 #include <config.h> |
1 | 26 #endif |
27 | |
7336 | 28 #include "oct-env.h" |
29 #include "oct-time.h" | |
30 #include "file-ops.h" | |
31 #include "file-stat.h" | |
1755 | 32 |
3308 | 33 #include "defun.h" |
7336 | 34 #include "dirfns.h" |
35 #include "input.h" | |
36 #include "load-path.h" | |
1755 | 37 #include "symtab.h" |
7336 | 38 #include "ov-fcn.h" |
39 #include "pager.h" | |
40 #include "parse.h" | |
41 #include "pt-arg-list.h" | |
42 #include "toplev.h" | |
43 #include "unwind-prot.h" | |
1 | 44 #include "utils.h" |
7336 | 45 |
46 symbol_table *symbol_table::instance = 0; | |
1 | 47 |
7761
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
48 symbol_table::scope_id_cache *symbol_table::scope_id_cache::instance = 0; |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
49 |
7336 | 50 std::map<symbol_table::scope_id, symbol_table*> symbol_table::all_instances; |
4913 | 51 |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7745
diff
changeset
|
52 std::map<std::string, octave_value> symbol_table::global_table; |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7745
diff
changeset
|
53 |
7336 | 54 std::map<std::string, symbol_table::fcn_info> symbol_table::fcn_table; |
4913 | 55 |
7336 | 56 const symbol_table::scope_id symbol_table::xglobal_scope = 0; |
57 const symbol_table::scope_id symbol_table::xtop_scope = 1; | |
4238 | 58 |
7336 | 59 symbol_table::scope_id symbol_table::xcurrent_scope = 1; |
60 symbol_table::scope_id symbol_table::xcurrent_caller_scope = -1; | |
3308 | 61 |
7336 | 62 symbol_table::scope_id symbol_table::xparent_scope = -1; |
63 | |
64 std::deque<symbol_table::scope_id> symbol_table::scope_stack; | |
4238 | 65 |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7745
diff
changeset
|
66 symbol_table::context_id symbol_table::xcurrent_context = 0; |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7745
diff
changeset
|
67 |
7336 | 68 // Should Octave always check to see if function files have changed |
69 // since they were last compiled? | |
70 static int Vignore_function_time_stamp = 1; | |
3355 | 71 |
7761
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
72 void |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
73 symbol_table::symbol_record::symbol_record_rep::dump |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
74 (std::ostream& os, const std::string& prefix) const |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
75 { |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7761
diff
changeset
|
76 octave_value val = varval (xcurrent_context); |
7761
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
77 |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
78 os << prefix << name; |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
79 |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
80 if (val.is_defined ()) |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
81 { |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
82 os << " [" |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
83 << (is_local () ? "l" : "") |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
84 << (is_automatic () ? "a" : "") |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
85 << (is_formal () ? "f" : "") |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
86 << (is_hidden () ? "h" : "") |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
87 << (is_inherited () ? "i" : "") |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
88 << (is_global () ? "g" : "") |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
89 << (is_persistent () ? "p" : "") |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
90 << "] "; |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
91 val.dump (os); |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
92 } |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
93 |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
94 os << "\n"; |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
95 } |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
96 |
7336 | 97 octave_value |
98 symbol_table::symbol_record::find (tree_argument_list *args, | |
99 const string_vector& arg_names, | |
100 octave_value_list& evaluated_args, | |
101 bool& args_evaluated) const | |
102 { | |
103 octave_value retval; | |
3355 | 104 |
7336 | 105 if (is_global ()) |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7745
diff
changeset
|
106 return symbol_table::global_varref (name ()); |
7336 | 107 else |
108 { | |
109 octave_value val = varval (); | |
110 | |
111 if (val.is_defined ()) | |
112 return val; | |
113 } | |
114 | |
115 return symbol_table::find_function (name (), args, arg_names, | |
116 evaluated_args, args_evaluated); | |
3355 | 117 } |
118 | |
7336 | 119 // Check the load path to see if file that defined this is still |
120 // visible. If the file is no longer visible, then erase the | |
121 // definition and move on. If the file is visible, then we also | |
122 // need to check to see whether the file has changed since the the | |
123 // function was loaded/parsed. However, this check should only | |
124 // happen once per prompt (for files found from relative path | |
125 // elements, we also check if the working directory has changed | |
126 // since the last time the function was loaded/parsed). | |
127 // | |
128 // FIXME -- perhaps this should be done for all loaded functions when | |
129 // the prompt is printed or the directory has changed, and then we | |
130 // would not check for it when finding symbol definitions. | |
3355 | 131 |
7336 | 132 static inline bool |
7745
0ff0fc033f28
better handling of functions found by relative lookup
John W. Eaton <jwe@octave.org>
parents:
7437
diff
changeset
|
133 load_out_of_date_fcn (const std::string& ff, const std::string& dir_name, |
0ff0fc033f28
better handling of functions found by relative lookup
John W. Eaton <jwe@octave.org>
parents:
7437
diff
changeset
|
134 octave_value& function) |
0ff0fc033f28
better handling of functions found by relative lookup
John W. Eaton <jwe@octave.org>
parents:
7437
diff
changeset
|
135 { |
0ff0fc033f28
better handling of functions found by relative lookup
John W. Eaton <jwe@octave.org>
parents:
7437
diff
changeset
|
136 bool retval = false; |
0ff0fc033f28
better handling of functions found by relative lookup
John W. Eaton <jwe@octave.org>
parents:
7437
diff
changeset
|
137 |
0ff0fc033f28
better handling of functions found by relative lookup
John W. Eaton <jwe@octave.org>
parents:
7437
diff
changeset
|
138 octave_function *fcn = load_fcn_from_file (ff, dir_name); |
0ff0fc033f28
better handling of functions found by relative lookup
John W. Eaton <jwe@octave.org>
parents:
7437
diff
changeset
|
139 |
0ff0fc033f28
better handling of functions found by relative lookup
John W. Eaton <jwe@octave.org>
parents:
7437
diff
changeset
|
140 if (fcn) |
0ff0fc033f28
better handling of functions found by relative lookup
John W. Eaton <jwe@octave.org>
parents:
7437
diff
changeset
|
141 { |
0ff0fc033f28
better handling of functions found by relative lookup
John W. Eaton <jwe@octave.org>
parents:
7437
diff
changeset
|
142 retval = true; |
0ff0fc033f28
better handling of functions found by relative lookup
John W. Eaton <jwe@octave.org>
parents:
7437
diff
changeset
|
143 |
0ff0fc033f28
better handling of functions found by relative lookup
John W. Eaton <jwe@octave.org>
parents:
7437
diff
changeset
|
144 function = octave_value (fcn); |
0ff0fc033f28
better handling of functions found by relative lookup
John W. Eaton <jwe@octave.org>
parents:
7437
diff
changeset
|
145 } |
0ff0fc033f28
better handling of functions found by relative lookup
John W. Eaton <jwe@octave.org>
parents:
7437
diff
changeset
|
146 else |
0ff0fc033f28
better handling of functions found by relative lookup
John W. Eaton <jwe@octave.org>
parents:
7437
diff
changeset
|
147 function = octave_value (); |
0ff0fc033f28
better handling of functions found by relative lookup
John W. Eaton <jwe@octave.org>
parents:
7437
diff
changeset
|
148 |
0ff0fc033f28
better handling of functions found by relative lookup
John W. Eaton <jwe@octave.org>
parents:
7437
diff
changeset
|
149 return retval; |
0ff0fc033f28
better handling of functions found by relative lookup
John W. Eaton <jwe@octave.org>
parents:
7437
diff
changeset
|
150 } |
0ff0fc033f28
better handling of functions found by relative lookup
John W. Eaton <jwe@octave.org>
parents:
7437
diff
changeset
|
151 |
0ff0fc033f28
better handling of functions found by relative lookup
John W. Eaton <jwe@octave.org>
parents:
7437
diff
changeset
|
152 static inline bool |
7336 | 153 out_of_date_check_internal (octave_value& function) |
1 | 154 { |
3013 | 155 bool retval = false; |
2949 | 156 |
7336 | 157 octave_function *fcn = function.function_value (true); |
5861 | 158 |
7336 | 159 if (fcn) |
220 | 160 { |
7336 | 161 // FIXME -- we need to handle nested functions properly here. |
4914 | 162 |
7336 | 163 if (! fcn->is_nested_function ()) |
164 { | |
165 std::string ff = fcn->fcn_file_name (); | |
4914 | 166 |
7336 | 167 if (! ff.empty ()) |
168 { | |
169 octave_time tc = fcn->time_checked (); | |
4913 | 170 |
7336 | 171 bool relative = fcn->is_relative (); |
3013 | 172 |
7336 | 173 if (tc < Vlast_prompt_time |
174 || (relative && tc < Vlast_chdir_time)) | |
4913 | 175 { |
7336 | 176 std::string nm = fcn->name (); |
4914 | 177 |
7336 | 178 int nm_len = nm.length (); |
4913 | 179 |
7336 | 180 std::string file; |
181 std::string dir_name; | |
4913 | 182 |
7336 | 183 if (octave_env::absolute_pathname (nm) |
184 && ((nm_len > 4 && (nm.substr (nm_len-4) == ".oct" | |
185 || nm.substr (nm_len-4) == ".mex")) | |
186 || (nm_len > 2 && nm.substr (nm_len-4) == ".m"))) | |
187 file = nm; | |
188 else | |
7745
0ff0fc033f28
better handling of functions found by relative lookup
John W. Eaton <jwe@octave.org>
parents:
7437
diff
changeset
|
189 { |
0ff0fc033f28
better handling of functions found by relative lookup
John W. Eaton <jwe@octave.org>
parents:
7437
diff
changeset
|
190 // FIXME -- this lookup is not right since it doesn't |
0ff0fc033f28
better handling of functions found by relative lookup
John W. Eaton <jwe@octave.org>
parents:
7437
diff
changeset
|
191 // account for dispatch type. |
0ff0fc033f28
better handling of functions found by relative lookup
John W. Eaton <jwe@octave.org>
parents:
7437
diff
changeset
|
192 |
0ff0fc033f28
better handling of functions found by relative lookup
John W. Eaton <jwe@octave.org>
parents:
7437
diff
changeset
|
193 // We don't want to make this an absolute name, |
0ff0fc033f28
better handling of functions found by relative lookup
John W. Eaton <jwe@octave.org>
parents:
7437
diff
changeset
|
194 // because load_fcn_file looks at the name to |
0ff0fc033f28
better handling of functions found by relative lookup
John W. Eaton <jwe@octave.org>
parents:
7437
diff
changeset
|
195 // decide whether it came from a relative lookup. |
0ff0fc033f28
better handling of functions found by relative lookup
John W. Eaton <jwe@octave.org>
parents:
7437
diff
changeset
|
196 |
0ff0fc033f28
better handling of functions found by relative lookup
John W. Eaton <jwe@octave.org>
parents:
7437
diff
changeset
|
197 file = load_path::find_fcn (nm, dir_name); |
0ff0fc033f28
better handling of functions found by relative lookup
John W. Eaton <jwe@octave.org>
parents:
7437
diff
changeset
|
198 } |
4913 | 199 |
7336 | 200 if (file.empty ()) |
201 { | |
202 // Can't see this function from current | |
203 // directory, so we should clear it. | |
195 | 204 |
7336 | 205 function = octave_value (); |
206 } | |
207 else if (same_file (file, ff)) | |
208 { | |
7745
0ff0fc033f28
better handling of functions found by relative lookup
John W. Eaton <jwe@octave.org>
parents:
7437
diff
changeset
|
209 // Same file. If it is out of date, then reload it. |
0ff0fc033f28
better handling of functions found by relative lookup
John W. Eaton <jwe@octave.org>
parents:
7437
diff
changeset
|
210 |
0ff0fc033f28
better handling of functions found by relative lookup
John W. Eaton <jwe@octave.org>
parents:
7437
diff
changeset
|
211 octave_time ottp = fcn->time_parsed (); |
0ff0fc033f28
better handling of functions found by relative lookup
John W. Eaton <jwe@octave.org>
parents:
7437
diff
changeset
|
212 time_t tp = ottp.unix_time (); |
0ff0fc033f28
better handling of functions found by relative lookup
John W. Eaton <jwe@octave.org>
parents:
7437
diff
changeset
|
213 |
7336 | 214 fcn->mark_fcn_file_up_to_date (octave_time ()); |
1 | 215 |
7336 | 216 if (! (Vignore_function_time_stamp == 2 |
217 || (Vignore_function_time_stamp | |
218 && fcn->is_system_fcn_file ()))) | |
219 { | |
220 file_stat fs (ff); | |
572 | 221 |
7336 | 222 if (fs) |
223 { | |
224 if (fs.is_newer (tp)) | |
7745
0ff0fc033f28
better handling of functions found by relative lookup
John W. Eaton <jwe@octave.org>
parents:
7437
diff
changeset
|
225 retval = load_out_of_date_fcn (ff, dir_name, |
0ff0fc033f28
better handling of functions found by relative lookup
John W. Eaton <jwe@octave.org>
parents:
7437
diff
changeset
|
226 function); |
7336 | 227 } |
228 else | |
229 function = octave_value (); | |
6829 | 230 } |
231 } | |
7745
0ff0fc033f28
better handling of functions found by relative lookup
John W. Eaton <jwe@octave.org>
parents:
7437
diff
changeset
|
232 else |
0ff0fc033f28
better handling of functions found by relative lookup
John W. Eaton <jwe@octave.org>
parents:
7437
diff
changeset
|
233 { |
0ff0fc033f28
better handling of functions found by relative lookup
John W. Eaton <jwe@octave.org>
parents:
7437
diff
changeset
|
234 // Not the same file, so load the new file in |
0ff0fc033f28
better handling of functions found by relative lookup
John W. Eaton <jwe@octave.org>
parents:
7437
diff
changeset
|
235 // place of the old. |
0ff0fc033f28
better handling of functions found by relative lookup
John W. Eaton <jwe@octave.org>
parents:
7437
diff
changeset
|
236 |
0ff0fc033f28
better handling of functions found by relative lookup
John W. Eaton <jwe@octave.org>
parents:
7437
diff
changeset
|
237 retval = load_out_of_date_fcn (file, dir_name, function); |
0ff0fc033f28
better handling of functions found by relative lookup
John W. Eaton <jwe@octave.org>
parents:
7437
diff
changeset
|
238 } |
6829 | 239 } |
240 } | |
4009 | 241 } |
242 } | |
243 | |
244 return retval; | |
245 } | |
246 | |
247 bool | |
7336 | 248 out_of_date_check (octave_value& function) |
4009 | 249 { |
7336 | 250 return out_of_date_check_internal (function); |
251 } | |
4009 | 252 |
7336 | 253 octave_value |
254 symbol_table::fcn_info::fcn_info_rep::load_private_function | |
255 (const std::string& dir_name) | |
256 { | |
257 octave_value retval; | |
258 | |
259 std::string file_name = load_path::find_private_fcn (dir_name, name); | |
260 | |
261 if (! file_name.empty ()) | |
4009 | 262 { |
7336 | 263 octave_function *fcn = load_fcn_from_file (file_name); |
4009 | 264 |
7336 | 265 if (fcn) |
4009 | 266 { |
7336 | 267 retval = octave_value (fcn); |
4009 | 268 |
7336 | 269 private_functions[dir_name] = retval; |
4009 | 270 } |
271 } | |
272 | |
273 return retval; | |
274 } | |
275 | |
7336 | 276 octave_value |
277 symbol_table::fcn_info::fcn_info_rep::load_class_constructor (void) | |
4009 | 278 { |
7336 | 279 octave_value retval; |
280 | |
281 std::string dir_name; | |
4009 | 282 |
7336 | 283 std::string file_name = load_path::find_method (name, name, dir_name); |
284 | |
285 if (! file_name.empty ()) | |
4009 | 286 { |
7336 | 287 octave_function *fcn = load_fcn_from_file (file_name, dir_name, name); |
4009 | 288 |
7336 | 289 if (fcn) |
4009 | 290 { |
7336 | 291 retval = octave_value (fcn); |
292 | |
293 class_constructors[name] = retval; | |
294 } | |
295 } | |
296 | |
297 return retval; | |
298 } | |
299 | |
300 octave_value | |
301 symbol_table::fcn_info::fcn_info_rep::load_class_method | |
302 (const std::string& dispatch_type) | |
303 { | |
304 octave_value retval; | |
4009 | 305 |
7336 | 306 std::string dir_name; |
307 | |
308 std::string file_name = load_path::find_method (dispatch_type, name, dir_name); | |
4009 | 309 |
7336 | 310 if (! file_name.empty ()) |
311 { | |
312 octave_function *fcn = load_fcn_from_file (file_name, dir_name, | |
313 dispatch_type); | |
4009 | 314 |
7336 | 315 if (fcn) |
316 { | |
317 retval = octave_value (fcn); | |
318 | |
319 class_methods[dispatch_type] = retval; | |
4009 | 320 } |
321 } | |
322 | |
323 return retval; | |
324 } | |
325 | |
7336 | 326 void |
327 symbol_table::fcn_info::fcn_info_rep::print_dispatch (std::ostream& os) const | |
1 | 328 { |
7336 | 329 if (dispatch_map.empty ()) |
330 os << "dispatch: " << name << " is not overloaded" << std::endl; | |
331 else | |
332 { | |
333 os << "Overloaded function " << name << ":\n\n"; | |
334 | |
7761
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
335 for (dispatch_map_const_iterator p = dispatch_map.begin (); |
7336 | 336 p != dispatch_map.end (); p++) |
337 os << " " << name << " (" << p->first << ", ...) -> " | |
338 << p->second << " (" << p->first << ", ...)\n"; | |
3013 | 339 |
7336 | 340 os << std::endl; |
341 } | |
342 } | |
343 | |
344 std::string | |
345 symbol_table::fcn_info::fcn_info_rep::help_for_dispatch (void) const | |
346 { | |
347 std::string retval; | |
348 | |
349 if (! dispatch_map.empty ()) | |
1 | 350 { |
7336 | 351 retval = "Overloaded function:\n\n"; |
352 | |
7761
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
353 for (dispatch_map_const_iterator p = dispatch_map.begin (); |
7336 | 354 p != dispatch_map.end (); p++) |
355 retval += " " + p->second + " (" + p->first + ", ...)\n\n"; | |
356 } | |
357 | |
358 return retval; | |
359 } | |
360 | |
361 // Find the definition of NAME according to the following precedence | |
362 // list: | |
363 // | |
364 // variable | |
365 // subfunction | |
366 // private function | |
367 // class constructor | |
368 // class method | |
369 // legacy dispatch | |
370 // command-line function | |
371 // autoload function | |
372 // function on the path | |
373 // built-in function | |
3013 | 374 |
7336 | 375 // Notes: |
376 // | |
377 // FIXME -- we need to evaluate the argument list to determine the | |
378 // dispatch type. The method used here works (pass in the args, pass | |
379 // out the evaluated args and a flag saying whether the evaluation was | |
380 // needed), but it seems a bit inelegant. We do need to save the | |
381 // evaluated args in some way to avoid evaluating them multiple times. | |
382 // Maybe evaluated args could be attached to the tree_argument_list | |
383 // object? Then the argument list could be evaluated outside of this | |
384 // function and we could elimnate the arg_names, evaluated_args, and | |
385 // args_evaluated arguments. We would still want to avoid computing | |
386 // the dispatch type unless it is needed, so the args should be passed | |
387 // rather than the dispatch type. But the arguments will need to be | |
388 // evaluated no matter what, so evaluating them beforehand should be | |
389 // OK. If the evaluated arguments are attached to args, then we would | |
390 // need to determine the appropriate place(s) to clear them (for | |
391 // example, before returning from tree_index_expression::rvalue). | |
392 | |
393 octave_value | |
394 symbol_table::fcn_info::fcn_info_rep::find | |
395 (tree_argument_list *args, const string_vector& arg_names, | |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7745
diff
changeset
|
396 octave_value_list& evaluated_args, bool& args_evaluated) |
7336 | 397 { |
398 static bool deja_vu = false; | |
399 | |
400 // Subfunction. I think it only makes sense to check for | |
401 // subfunctions if we are currently executing a function defined | |
402 // from a .m file. | |
403 | |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7745
diff
changeset
|
404 scope_val_iterator r = subfunctions.find (xcurrent_scope); |
7336 | 405 |
406 if (r != subfunctions.end ()) | |
407 { | |
408 // FIXME -- out-of-date check here. | |
409 | |
410 return r->second; | |
411 } | |
412 else if (curr_parent_function) | |
413 { | |
414 scope_id pscope = curr_parent_function->scope (); | |
415 | |
416 r = subfunctions.find (pscope); | |
417 | |
418 if (r != subfunctions.end ()) | |
1 | 419 { |
7336 | 420 // FIXME -- out-of-date check here. |
421 | |
422 return r->second; | |
1 | 423 } |
424 } | |
3013 | 425 |
7336 | 426 // Private function. |
1 | 427 |
7336 | 428 octave_function *curr_fcn = octave_call_stack::current (); |
1 | 429 |
7336 | 430 if (curr_fcn) |
431 { | |
432 std::string dir_name = curr_fcn->dir_name (); | |
1 | 433 |
7336 | 434 if (! dir_name.empty ()) |
435 { | |
436 str_val_iterator q = private_functions.find (dir_name); | |
4913 | 437 |
7336 | 438 if (q == private_functions.end ()) |
439 { | |
440 octave_value val = load_private_function (dir_name); | |
4913 | 441 |
7336 | 442 if (val.is_defined ()) |
443 return val; | |
444 } | |
445 else | |
4913 | 446 { |
7336 | 447 octave_value& fval = q->second; |
4913 | 448 |
7336 | 449 if (fval.is_defined ()) |
450 out_of_date_check_internal (fval); | |
4913 | 451 |
7336 | 452 if (fval.is_defined ()) |
453 return fval; | |
454 else | |
455 { | |
456 octave_value val = load_private_function (dir_name); | |
4913 | 457 |
7336 | 458 if (val.is_defined ()) |
459 return val; | |
4913 | 460 } |
461 } | |
462 } | |
463 } | |
464 | |
7336 | 465 // Class constructors. The class name and function name are the same. |
4913 | 466 |
7336 | 467 str_val_iterator q = class_constructors.find (name); |
4913 | 468 |
7336 | 469 if (q == class_constructors.end ()) |
470 { | |
471 octave_value val = load_class_constructor (); | |
3013 | 472 |
7336 | 473 if (val.is_defined ()) |
474 return val; | |
475 } | |
476 else | |
1 | 477 { |
7336 | 478 octave_value& fval = q->second; |
3013 | 479 |
7336 | 480 if (fval.is_defined ()) |
481 out_of_date_check_internal (fval); | |
867 | 482 |
7336 | 483 if (fval.is_defined ()) |
484 return fval; | |
485 else | |
486 { | |
487 octave_value val = load_class_constructor (); | |
867 | 488 |
7336 | 489 if (val.is_defined ()) |
490 return val; | |
1 | 491 } |
492 } | |
1755 | 493 |
7336 | 494 // Class methods. |
1 | 495 |
7336 | 496 if (args_evaluated || (args && args->length () > 0)) |
497 { | |
498 if (! args_evaluated) | |
499 evaluated_args = args->convert_to_const_vector (); | |
3013 | 500 |
7336 | 501 if (! error_state) |
502 { | |
503 int n = evaluated_args.length (); | |
504 | |
505 if (n > 0 && ! args_evaluated) | |
506 evaluated_args.stash_name_tags (arg_names); | |
507 | |
508 args_evaluated = true; | |
509 | |
510 // FIXME -- need to handle precedence. | |
3013 | 511 |
7336 | 512 std::string dispatch_type = evaluated_args(0).class_name (); |
3013 | 513 |
7336 | 514 for (int i = 1; i < n; i++) |
515 { | |
516 octave_value arg = evaluated_args(i); | |
3013 | 517 |
7336 | 518 if (arg.is_object ()) |
519 { | |
520 dispatch_type = arg.class_name (); | |
521 break; | |
522 } | |
523 } | |
3013 | 524 |
7336 | 525 octave_value fcn = find_method (dispatch_type); |
526 | |
527 if (fcn.is_defined ()) | |
528 return fcn; | |
529 } | |
530 else | |
531 return octave_value (); | |
3013 | 532 } |
533 | |
7336 | 534 // Legacy dispatch. We just check args_evaluated here because the |
535 // actual evaluation will have happened already when searching for | |
536 // class methods. | |
537 | |
538 if (args_evaluated && ! dispatch_map.empty ()) | |
539 { | |
540 std::string dispatch_type = evaluated_args(0).type_name (); | |
541 | |
542 std::string fname; | |
543 | |
544 dispatch_map_iterator p = dispatch_map.find (dispatch_type); | |
545 | |
546 if (p == dispatch_map.end ()) | |
547 p = dispatch_map.find ("any"); | |
3013 | 548 |
7336 | 549 if (p != dispatch_map.end ()) |
550 { | |
551 fname = p->second; | |
552 | |
553 octave_value fcn | |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7745
diff
changeset
|
554 = symbol_table::find_function (fname, evaluated_args); |
7336 | 555 |
556 if (fcn.is_defined ()) | |
557 return fcn; | |
558 } | |
559 } | |
560 | |
561 // Command-line function. | |
562 | |
563 if (cmdline_function.is_defined ()) | |
564 return cmdline_function; | |
565 | |
566 // Autoload? | |
3013 | 567 |
7336 | 568 octave_value fcn = find_autoload (); |
569 | |
570 if (fcn.is_defined ()) | |
571 return fcn; | |
572 | |
573 // Function on the path. | |
574 | |
575 fcn = find_user_function (); | |
576 | |
577 if (fcn.is_defined ()) | |
578 return fcn; | |
579 | |
580 // Built-in function. | |
581 | |
582 if (built_in_function.is_defined ()) | |
583 return built_in_function; | |
3013 | 584 |
7336 | 585 // At this point, we failed to find anything. It is possible that |
586 // the user created a file on the fly since the last prompt or | |
587 // chdir, so try updating the load path and searching again. | |
588 | |
589 octave_value retval; | |
3145 | 590 |
7336 | 591 if (! deja_vu) |
592 { | |
593 load_path::update (); | |
594 | |
595 deja_vu = true; | |
596 | |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7745
diff
changeset
|
597 retval = find (args, arg_names, evaluated_args, args_evaluated); |
7336 | 598 } |
599 | |
600 deja_vu = false; | |
601 | |
602 return retval; | |
3013 | 603 } |
1 | 604 |
7336 | 605 octave_value |
606 symbol_table::fcn_info::fcn_info_rep::find_method (const std::string& dispatch_type) | |
4913 | 607 { |
7336 | 608 octave_value retval; |
4913 | 609 |
7336 | 610 str_val_iterator q = class_methods.find (dispatch_type); |
4913 | 611 |
7336 | 612 if (q == class_methods.end ()) |
613 { | |
614 octave_value val = load_class_method (dispatch_type); | |
4913 | 615 |
7336 | 616 if (val.is_defined ()) |
617 return val; | |
618 } | |
619 else | |
620 { | |
621 octave_value& fval = q->second; | |
4913 | 622 |
7336 | 623 if (fval.is_defined ()) |
624 out_of_date_check_internal (fval); | |
625 | |
626 if (fval.is_defined ()) | |
627 return fval; | |
4913 | 628 else |
629 { | |
7336 | 630 octave_value val = load_class_method (dispatch_type); |
631 | |
632 if (val.is_defined ()) | |
633 return val; | |
4913 | 634 } |
635 } | |
636 | |
7336 | 637 return retval; |
4913 | 638 } |
639 | |
7336 | 640 octave_value |
641 symbol_table::fcn_info::fcn_info_rep::find_autoload (void) | |
4913 | 642 { |
7336 | 643 octave_value retval; |
4913 | 644 |
7336 | 645 // Autoloaded function. |
4913 | 646 |
7336 | 647 if (autoload_function.is_defined ()) |
648 out_of_date_check_internal (autoload_function); | |
4913 | 649 |
7336 | 650 if (! autoload_function.is_defined ()) |
651 { | |
652 std::string file_name = lookup_autoload (name); | |
4913 | 653 |
7336 | 654 if (! file_name.empty ()) |
655 { | |
656 size_t pos = file_name.find_last_of (file_ops::dir_sep_chars); | |
4913 | 657 |
7336 | 658 std::string dir_name = file_name.substr (0, pos); |
4913 | 659 |
7336 | 660 octave_function *fcn = load_fcn_from_file (file_name, dir_name, |
661 "", name, true); | |
4913 | 662 |
7336 | 663 if (fcn) |
664 autoload_function = octave_value (fcn); | |
665 } | |
4913 | 666 } |
667 | |
7336 | 668 return autoload_function; |
669 } | |
4914 | 670 |
7336 | 671 octave_value |
672 symbol_table::fcn_info::fcn_info_rep::find_user_function (void) | |
673 { | |
674 // Function on the path. | |
4913 | 675 |
7336 | 676 if (function_on_path.is_defined ()) |
677 out_of_date_check_internal (function_on_path); | |
4913 | 678 |
7336 | 679 if (! function_on_path.is_defined ()) |
680 { | |
681 std::string dir_name; | |
4913 | 682 |
7336 | 683 std::string file_name = load_path::find_fcn (name, dir_name); |
4913 | 684 |
7336 | 685 if (! file_name.empty ()) |
686 { | |
687 octave_function *fcn = load_fcn_from_file (file_name, dir_name); | |
4913 | 688 |
7336 | 689 if (fcn) |
690 function_on_path = octave_value (fcn); | |
4913 | 691 } |
692 } | |
693 | |
7336 | 694 return function_on_path; |
695 } | |
696 | |
7761
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
697 static std::string |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
698 fcn_file_name (const octave_value& fcn) |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
699 { |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
700 const octave_function *f = fcn.function_value (); |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
701 |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
702 return f ? f->fcn_file_name () : std::string (); |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
703 } |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
704 |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
705 void |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
706 symbol_table::fcn_info::fcn_info_rep::dump |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
707 (std::ostream& os, const std::string& prefix) const |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
708 { |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
709 os << prefix << name |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
710 << " [" |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
711 << (cmdline_function.is_defined () ? "c" : "") |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
712 << (built_in_function.is_defined () ? "b" : "") |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
713 << "]\n"; |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
714 |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
715 std::string tprefix = prefix + " "; |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
716 |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
717 if (autoload_function.is_defined ()) |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
718 os << tprefix << "autoload: " |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
719 << fcn_file_name (autoload_function) << "\n"; |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
720 |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
721 if (function_on_path.is_defined ()) |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
722 os << tprefix << "function from path: " |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
723 << fcn_file_name (function_on_path) << "\n"; |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
724 |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
725 if (! subfunctions.empty ()) |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
726 { |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
727 for (scope_val_const_iterator p = subfunctions.begin (); |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
728 p != subfunctions.end (); p++) |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
729 os << tprefix << "subfunction: " << fcn_file_name (p->second) |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
730 << " [" << p->first << "]\n"; |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
731 } |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
732 |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
733 if (! private_functions.empty ()) |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
734 { |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
735 for (str_val_const_iterator p = private_functions.begin (); |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
736 p != private_functions.end (); p++) |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
737 os << tprefix << "private: " << fcn_file_name (p->second) |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
738 << " [" << p->first << "]\n"; |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
739 } |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
740 |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
741 if (! class_constructors.empty ()) |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
742 { |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
743 for (str_val_const_iterator p = class_constructors.begin (); |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
744 p != class_constructors.end (); p++) |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
745 os << tprefix << "constructor: " << fcn_file_name (p->second) |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
746 << " [" << p->first << "]\n"; |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
747 } |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
748 |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
749 if (! class_methods.empty ()) |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
750 { |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
751 for (str_val_const_iterator p = class_methods.begin (); |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
752 p != class_methods.end (); p++) |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
753 os << tprefix << "method: " << fcn_file_name (p->second) |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
754 << " [" << p->first << "]\n"; |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
755 } |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
756 |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
757 if (! dispatch_map.empty ()) |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
758 { |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
759 for (dispatch_map_const_iterator p = dispatch_map.begin (); |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
760 p != dispatch_map.end (); p++) |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
761 os << tprefix << "dispatch: " << fcn_file_name (p->second) |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
762 << " [" << p->first << "]\n"; |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
763 } |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
764 } |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
765 |
7336 | 766 octave_value |
767 symbol_table::fcn_info::find (tree_argument_list *args, | |
768 const string_vector& arg_names, | |
769 octave_value_list& evaluated_args, | |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7745
diff
changeset
|
770 bool& args_evaluated) |
7336 | 771 { |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7745
diff
changeset
|
772 return rep->find (args, arg_names, evaluated_args, args_evaluated); |
7336 | 773 } |
774 | |
775 octave_value | |
776 symbol_table::find (const std::string& name, tree_argument_list *args, | |
777 const string_vector& arg_names, | |
778 octave_value_list& evaluated_args, bool& args_evaluated, | |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7745
diff
changeset
|
779 bool skip_variables) |
7336 | 780 { |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7745
diff
changeset
|
781 symbol_table *inst = get_instance (xcurrent_scope); |
7336 | 782 |
783 return inst | |
784 ? inst->do_find (name, args, arg_names, evaluated_args, | |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7745
diff
changeset
|
785 args_evaluated, skip_variables) |
7336 | 786 : octave_value (); |
787 } | |
788 | |
789 octave_value | |
790 symbol_table::find_function (const std::string& name, tree_argument_list *args, | |
791 const string_vector& arg_names, | |
792 octave_value_list& evaluated_args, | |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7745
diff
changeset
|
793 bool& args_evaluated) |
7336 | 794 { |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7745
diff
changeset
|
795 return find (name, args, arg_names, evaluated_args, args_evaluated, true); |
4913 | 796 } |
797 | |
7761
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
798 void |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
799 symbol_table::dump (std::ostream& os, scope_id scope) |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
800 { |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
801 if (scope == xglobal_scope) |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
802 dump_global (os); |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
803 else |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
804 { |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
805 symbol_table *inst = get_instance (scope, false); |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
806 |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
807 if (inst) |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
808 { |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
809 os << "*** dumping symbol table scope " << scope |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
810 << " (" << inst->table_name << ")\n\n"; |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
811 |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
812 std::map<std::string, octave_value> sfuns |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
813 = symbol_table::subfunctions_defined_in_scope (scope); |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
814 |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
815 if (! sfuns.empty ()) |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
816 { |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
817 os << " subfunctions defined in this scope:\n"; |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
818 |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
819 for (std::map<std::string, octave_value>::const_iterator p = sfuns.begin (); |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
820 p != sfuns.end (); p++) |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
821 os << " " << p->first << "\n"; |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
822 |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
823 os << "\n"; |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
824 } |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
825 |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
826 |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
827 inst->do_dump (os); |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
828 } |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
829 } |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
830 } |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
831 |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
832 void |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
833 symbol_table::dump_global (std::ostream& os) |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
834 { |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
835 if (! global_table.empty ()) |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
836 { |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
837 os << "*** dumping global symbol table\n\n"; |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
838 |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
839 for (global_table_const_iterator p = global_table.begin (); |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
840 p != global_table.end (); p++) |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
841 { |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
842 std::string nm = p->first; |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
843 octave_value val = p->second; |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
844 |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
845 os << " " << nm << " "; |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
846 val.dump (os); |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
847 os << "\n"; |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
848 } |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
849 } |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
850 } |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
851 |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
852 void |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
853 symbol_table::dump_functions (std::ostream& os) |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
854 { |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
855 if (! fcn_table.empty ()) |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
856 { |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
857 os << "*** dumping globally visible functions from symbol table\n" |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
858 << " (c=commandline, b=built-in)\n\n"; |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
859 |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
860 for (fcn_table_const_iterator p = fcn_table.begin (); |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
861 p != fcn_table.end (); p++) |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
862 p->second.dump (os, " "); |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
863 |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
864 os << "\n"; |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
865 } |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
866 } |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
867 |
7336 | 868 octave_value |
869 symbol_table::do_find (const std::string& name, tree_argument_list *args, | |
870 const string_vector& arg_names, | |
871 octave_value_list& evaluated_args, | |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7745
diff
changeset
|
872 bool& args_evaluated, bool skip_variables) |
3013 | 873 { |
7336 | 874 octave_value retval; |
4913 | 875 |
7336 | 876 // Variable. |
4913 | 877 |
7336 | 878 if (! skip_variables) |
3013 | 879 { |
7336 | 880 table_iterator p = table.find (name); |
3013 | 881 |
7336 | 882 if (p != table.end ()) |
883 { | |
7761
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
884 symbol_record sr = p->second; |
3013 | 885 |
7336 | 886 // FIXME -- should we be using something other than varref here? |
5005 | 887 |
7336 | 888 if (sr.is_global ()) |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7745
diff
changeset
|
889 return symbol_table::global_varref (name); |
7336 | 890 else |
891 { | |
892 octave_value& val = sr.varref (); | |
4913 | 893 |
7336 | 894 if (val.is_defined ()) |
895 return val; | |
896 } | |
897 } | |
898 } | |
4913 | 899 |
7336 | 900 fcn_table_iterator p = fcn_table.find (name); |
4913 | 901 |
7336 | 902 if (p != fcn_table.end ()) |
903 { | |
904 evaluated_args = octave_value_list (); | |
905 args_evaluated = false; | |
3013 | 906 |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7745
diff
changeset
|
907 return p->second.find (args, arg_names, evaluated_args, args_evaluated); |
3013 | 908 } |
909 else | |
910 { | |
7336 | 911 fcn_info finfo (name); |
912 | |
913 octave_value fcn = finfo.find (args, arg_names, evaluated_args, | |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7745
diff
changeset
|
914 args_evaluated); |
3013 | 915 |
7336 | 916 if (fcn.is_defined ()) |
917 fcn_table[name] = finfo; | |
3013 | 918 |
7336 | 919 return fcn; |
3013 | 920 } |
921 | |
7336 | 922 return retval; |
605 | 923 } |
924 | |
7761
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
925 void |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
926 symbol_table::do_dump (std::ostream& os) |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
927 { |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
928 if (! persistent_table.empty ()) |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
929 { |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
930 os << " persistent variables in this scope:\n\n"; |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
931 |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
932 for (persistent_table_const_iterator p = persistent_table.begin (); |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
933 p != persistent_table.end (); p++) |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
934 { |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
935 std::string nm = p->first; |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
936 octave_value val = p->second; |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
937 |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
938 os << " " << nm << " "; |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
939 val.dump (os); |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
940 os << "\n"; |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
941 } |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
942 |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
943 os << "\n"; |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
944 } |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
945 |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
946 if (! table.empty ()) |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
947 { |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
948 os << " other symbols in this scope (l=local; a=auto; f=formal\n" |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
949 << " h=hidden; i=inherited; g=global; p=persistent)\n\n"; |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
950 |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
951 for (table_const_iterator p = table.begin (); p != table.end (); p++) |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
952 p->second.dump (os, " "); |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
953 |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
954 os << "\n"; |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
955 } |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
956 } |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
957 |
7336 | 958 DEFUN (ignore_function_time_stamp, args, nargout, |
959 "-*- texinfo -*-\n\ | |
960 @deftypefn {Built-in Function} {@var{val} =} ignore_function_time_stamp ()\n\ | |
961 @deftypefnx {Built-in Function} {@var{old_val} =} ignore_function_time_stamp (@var{new_val})\n\ | |
962 Query or set the internal variable that controls whether Octave checks\n\ | |
963 the time stamp on files each time it looks up functions defined in\n\ | |
964 function files. If the internal variable is set to @code{\"system\"},\n\ | |
965 Octave will not automatically recompile function files in subdirectories of\n\ | |
966 @file{@var{octave-home}/lib/@var{version}} if they have changed since\n\ | |
967 they were last compiled, but will recompile other function files in the\n\ | |
968 search path if they change. If set to @code{\"all\"}, Octave will not\n\ | |
969 recompile any function files unless their definitions are removed with\n\ | |
970 @code{clear}. If set to \"none\", Octave will always check time stamps\n\ | |
971 on files to determine whether functions defined in function files\n\ | |
972 need to recompiled.\n\ | |
973 @end deftypefn") | |
220 | 974 { |
7336 | 975 octave_value retval; |
220 | 976 |
7336 | 977 if (nargout > 0) |
5861 | 978 { |
7336 | 979 switch (Vignore_function_time_stamp) |
5861 | 980 { |
7336 | 981 case 1: |
982 retval = "system"; | |
983 break; | |
5861 | 984 |
7336 | 985 case 2: |
986 retval = "all"; | |
987 break; | |
5861 | 988 |
7336 | 989 default: |
990 retval = "none"; | |
991 break; | |
5861 | 992 } |
993 } | |
994 | |
7336 | 995 int nargin = args.length (); |
5861 | 996 |
7336 | 997 if (nargin == 1) |
3013 | 998 { |
7336 | 999 std::string sval = args(0).string_value (); |
1 | 1000 |
7336 | 1001 if (! error_state) |
1002 { | |
1003 if (sval == "all") | |
1004 Vignore_function_time_stamp = 2; | |
1005 else if (sval == "system") | |
1006 Vignore_function_time_stamp = 1; | |
1007 else if (sval == "none") | |
1008 Vignore_function_time_stamp = 0; | |
1009 else | |
1010 error ("ignore_function_time_stamp: expecting argument to be \"all\", \"system\", or \"none\""); | |
1011 } | |
1012 else | |
1013 error ("ignore_function_time_stamp: expecting argument to be character string"); | |
1014 } | |
1015 else if (nargin > 1) | |
1016 print_usage (); | |
4238 | 1017 |
7336 | 1018 return retval; |
3308 | 1019 } |
1020 | |
7761
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
1021 DEFUN (__current_scope__, , , |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
1022 "-*- texinfo -*-\n\ |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
1023 @deftypefn {Built-in Function} {[@var{scope}, @var{context}]} __dump_symtab_info__ ()\n\ |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
1024 Undocumented internal function.\n\ |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
1025 @end deftypefn") |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
1026 { |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
1027 octave_value_list retval; |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
1028 |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
1029 retval(1) = symbol_table::current_context (); |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
1030 retval(0) = symbol_table::current_scope (); |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
1031 |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
1032 return retval; |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
1033 } |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
1034 |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
1035 DEFUN (__dump_symtab_info__, args, , |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
1036 "-*- texinfo -*-\n\ |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
1037 @deftypefn {Built-in Function} {} __dump_symtab_info__ ()\n\ |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
1038 @deftypefnx {Built-in Function} {} __dump_symtab_info__ (@var{scope})\n\ |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
1039 @deftypefnx {Built-in Function} {} __dump_symtab_info__ (\"scopes\")\n\ |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
1040 @deftypefnx {Built-in Function} {} __dump_symtab_info__ (\"functions\")\n\ |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
1041 Undocumented internal function.\n\ |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
1042 @end deftypefn") |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
1043 { |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
1044 octave_value retval; |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
1045 |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
1046 int nargin = args.length (); |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
1047 |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
1048 if (nargin == 0) |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
1049 { |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
1050 symbol_table::dump_functions (octave_stdout); |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
1051 |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
1052 symbol_table::dump_global (octave_stdout); |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
1053 |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
1054 std::list<symbol_table::scope_id> lst = symbol_table::scopes (); |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
1055 |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
1056 for (std::list<symbol_table::scope_id>::const_iterator p = lst.begin (); |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
1057 p != lst.end (); p++) |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
1058 symbol_table::dump (octave_stdout, *p); |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
1059 } |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
1060 else if (nargin == 1) |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
1061 { |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
1062 octave_value arg = args(0); |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
1063 |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
1064 if (arg.is_string ()) |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
1065 { |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
1066 std::string s_arg = arg.string_value (); |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
1067 |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
1068 if (s_arg == "scopes") |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
1069 { |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
1070 std::list<symbol_table::scope_id> lst = symbol_table::scopes (); |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
1071 |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
1072 RowVector v (lst.size ()); |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
1073 |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
1074 octave_idx_type k = 0; |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
1075 |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
1076 for (std::list<symbol_table::scope_id>::const_iterator p = lst.begin (); |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
1077 p != lst.end (); p++) |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
1078 v.xelem (k++) = *p; |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
1079 |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
1080 retval = v; |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
1081 } |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
1082 else if (s_arg == "functions") |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
1083 { |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
1084 symbol_table::dump_functions (octave_stdout); |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
1085 } |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
1086 else |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
1087 error ("__dump_symtab_info__: expecting \"functions\" or \"scopes\""); |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
1088 } |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
1089 else |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
1090 { |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
1091 int s = arg.int_value (); |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
1092 |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
1093 if (! error_state) |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
1094 symbol_table::dump (octave_stdout, s); |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
1095 else |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
1096 error ("__dump_symtab_info__: expecting string or scope id"); |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
1097 } |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
1098 } |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
1099 else |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
1100 print_usage (); |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
1101 |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
1102 return retval; |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
1103 } |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
1104 |
7437 | 1105 #if 0 |
1106 | |
1107 // FIXME -- should we have functions like this in Octave? | |
1108 | |
1109 DEFUN (set_variable, args, , "set_variable (NAME, VALUE)") | |
1110 { | |
1111 octave_value retval; | |
1112 | |
1113 if (args.length () == 2) | |
1114 { | |
1115 std::string name = args(0).string_value (); | |
1116 | |
1117 if (! error_state) | |
1118 symbol_table::varref (name) = args(1); | |
1119 else | |
1120 error ("set_variable: expecting variable name as first argument"); | |
1121 } | |
1122 else | |
1123 print_usage (); | |
1124 | |
1125 return retval; | |
1126 } | |
1127 | |
1128 DEFUN (variable_value, args, , "VALUE = variable_value (NAME)") | |
1129 { | |
1130 octave_value retval; | |
1131 | |
1132 if (args.length () == 1) | |
1133 { | |
1134 std::string name = args(0).string_value (); | |
1135 | |
1136 if (! error_state) | |
1137 { | |
1138 retval = symbol_table::varval (name); | |
1139 | |
1140 if (retval.is_undefined ()) | |
1141 error ("variable_value: `%s' is not a variable in the current scope", | |
1142 name.c_str ()); | |
1143 } | |
1144 else | |
1145 error ("variable_value: expecting variable name as first argument"); | |
1146 } | |
1147 else | |
1148 print_usage (); | |
1149 | |
1150 return retval; | |
1151 } | |
1152 #endif | |
1153 | |
1 | 1154 /* |
1155 ;;; Local Variables: *** | |
1156 ;;; mode: C++ *** | |
1157 ;;; End: *** | |
1158 */ |