GNU Octave 7.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
symtab.h
Go to the documentation of this file.
1////////////////////////////////////////////////////////////////////////
2//
3// Copyright (C) 1993-2022 The Octave Project Developers
4//
5// See the file COPYRIGHT.md in the top-level directory of this
6// distribution or <https://octave.org/copyright/>.
7//
8// This file is part of Octave.
9//
10// Octave is free software: you can redistribute it and/or modify it
11// under the terms of the GNU General Public License as published by
12// the Free Software Foundation, either version 3 of the License, or
13// (at your option) any later version.
14//
15// Octave is distributed in the hope that it will be useful, but
16// WITHOUT ANY WARRANTY; without even the implied warranty of
17// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18// GNU General Public License for more details.
19//
20// You should have received a copy of the GNU General Public License
21// along with Octave; see the file COPYING. If not, see
22// <https://www.gnu.org/licenses/>.
23//
24////////////////////////////////////////////////////////////////////////
25
26#if ! defined (octave_symtab_h)
27#define octave_symtab_h 1
28
29#include "octave-config.h"
30
31#include <deque>
32#include <list>
33#include <map>
34#include <set>
35#include <string>
36
37#include "glob-match.h"
38#include "lo-regexp.h"
39#include "oct-refcount.h"
40
41class tree_argument_list;
43
44#include "fcn-info.h"
45#include "ov.h"
46#include "ovl.h"
47#include "symscope.h"
48
49OCTAVE_NAMESPACE_BEGIN
50
51 class interpreter;
52
53 class OCTINTERP_API symbol_table
54 {
55 public:
56
57 // Make symbol_table::scope and symbol_table::fcn_info valid type names.
59 typedef octave::fcn_info fcn_info;
60
61 symbol_table (interpreter& interp);
62
63 // No copying!
64
65 symbol_table (const symbol_table&) = delete;
66
67 symbol_table& operator = (const symbol_table&) = delete;
68
69 ~symbol_table (void) = default;
70
71 symbol_scope current_scope (void) const;
72
73 bool is_built_in_function_name (const std::string& name);
74
75 octave_value find_scoped_function (const std::string& name,
76 const symbol_scope& search_scope);
77
78 octave_value find_private_function (const std::string& dir_name,
79 const std::string& name);
80
81 // FIXME: this function only finds legacy class methods, not
82 // classdef methods.
83 octave_value find_method (const std::string& name,
84 const std::string& dispatch_type);
85
86 octave_value find_built_in_function (const std::string& name);
87
88 octave_value find_autoload (const std::string& name);
89
91 builtin_find (const std::string& name,
92 const symbol_scope& search_scope = symbol_scope ());
93
95 fcn_table_find (const std::string& name,
96 const octave_value_list& args = ovl (),
97 const symbol_scope& search_scope = symbol_scope ());
98
99 // If NAME is of the form @CLASS/FUNCTION, call
100 //
101 // find_method (FUNCTION, CLASS)
102 //
103 // otherwise call
104 //
105 // find_function (NAME, ovl ())
106
108 find_function (const std::string& name,
109 const symbol_scope& search_scope = symbol_scope ());
110
111 // NAME should just be function name; dispatch type determined
112 // from types of ARGS.
113
115 find_function (const std::string& name,
116 const octave_value_list& args,
117 const symbol_scope& search_scope = symbol_scope ());
118
119 octave_value find_user_function (const std::string& name);
120
121 octave_value find_cmdline_function (const std::string& name);
122
123 void install_cmdline_function (const std::string& name,
124 const octave_value& fcn);
125
126 // Install local function FCN named NAME. FILE_NAME is the name of
127 // the file containing the local function.
128
129 void install_local_function (const std::string& name,
130 const octave_value& fcn,
131 const std::string& file_name);
132
133 void install_user_function (const std::string& name,
134 const octave_value& fcn);
135
136 // FIXME: should we ensure that FCN really is a built-in function
137 // object?
138 void install_built_in_function (const std::string& name,
139 const octave_value& fcn);
140
141 // This is written as two separate functions instead of a single
142 // function with default values so that it will work properly with
143 // unwind_protect.
144
145 void clear_functions (bool force = false);
146
147 void clear_function (const std::string& name);
148
149 void clear_function_pattern (const std::string& pat);
150
151 void clear_function_regexp (const std::string& pat);
152
153 void clear_user_function (const std::string& name);
154
155 // This clears oct and mex files, including autoloads.
156 void clear_dld_function (const std::string& name);
157
158 void clear_mex_functions (void);
159
160 bool set_class_relationship (const std::string& sup_class,
161 const std::string& inf_class);
162
163 bool is_superiorto (const std::string& a, const std::string& b);
164
165 void alias_built_in_function (const std::string& alias,
166 const std::string& name);
167
168 void install_built_in_dispatch (const std::string& name,
169 const std::string& klass);
170
171 std::list<std::string> user_function_names (void);
172
173 std::list<std::string> built_in_function_names (void);
174
175 std::list<std::string> cmdline_function_names (void);
176
177 octave_value dump (void) const;
178
179 void add_to_parent_map (const std::string& classname,
180 const std::list<std::string>& parent_list);
181
182 std::list<std::string> parent_classes (const std::string& dispatch_type);
183
184 void cleanup (void);
185
186 fcn_info * get_fcn_info (const std::string& name);
187
188 // The remaining functions are all provided for backward
189 // compatibility. New code should use the functions provided by the
190 // interpreter class.
191
192 private:
193
194 // Remove when corresponding public deprecated function is removed.
195 bool at_top_level_deprecated (void);
196
197 // Remove when corresponding public deprecated function is removed.
198 octave_value varval_deprecated (const std::string& name) const;
199
200 // Remove when corresponding public deprecated function is removed.
201 octave_value global_varval_deprecated (const std::string& name) const;
202
203 // Remove when corresponding public deprecated function is removed.
204 octave_value top_level_varval_deprecated (const std::string& name) const;
205
206 // Remove when corresponding public deprecated function is removed.
207 std::list<std::string> global_variable_names_deprecated (void);
208
209 // Remove when corresponding public deprecated function is removed.
210 std::list<std::string> top_level_variable_names_deprecated (void);
211
212 // Remove when corresponding public deprecated function is removed.
213 std::list<std::string> variable_names_deprecated (void);
214
215 // Remove when corresponding public deprecated function is removed.
216 void assign_deprecated (const std::string& name,
217 const octave_value& value = octave_value ());
218
219 // Remove when corresponding public deprecated function is removed.
220 // Note, FORCE_ADD no longer has any meaning.
221 void assign_deprecated (const std::string& name, const octave_value& value,
222 bool /*force_add*/);
223
224 // Remove when corresponding public deprecated function is removed.
225 void clear_all_deprecated (bool force = false);
226
227 // Remove when corresponding public deprecated function is removed.
228 void clear_global_deprecated (const std::string& name);
229
230 // Remove when corresponding public deprecated function is removed.
231 void clear_global_pattern_deprecated (const std::string& pattern);
232
233 // Remove when corresponding public deprecated function is removed.
234 void clear_symbol_deprecated (const std::string& name);
235
236 // Remove when corresponding public deprecated function is removed.
237 void clear_symbol_pattern_deprecated (const std::string& pattern);
238
239 // Remove when corresponding public deprecated function is removed.
240 void global_assign_deprecated (const std::string& name,
241 const octave_value& value = octave_value ());
242
243 // Remove when corresponding public deprecated function is removed.
244 void top_level_assign_deprecated (const std::string& name,
245 const octave_value& value = octave_value ());
246
247 public:
248
249#if defined (OCTAVE_PROVIDE_DEPRECATED_SYMBOLS)
250 OCTAVE_DEPRECATED (6, "use 'interpreter::at_top_level' instead")
251 bool at_top_level (void)
252 {
253 return at_top_level_deprecated ();
254 }
255
256 OCTAVE_DEPRECATED (6, "use 'interpreter::varval' instead")
257 octave_value varval (const std::string& name) const
258 {
259 return varval_deprecated (name);
260 }
261
262 OCTAVE_DEPRECATED (6, "use 'interpreter::global_varval' instead")
263 octave_value global_varval (const std::string& name) const
264 {
265 return global_varval_deprecated (name);
266 }
267
268 OCTAVE_DEPRECATED (6, "use 'interpreter::top_level_varval' instead")
269 octave_value top_level_varval (const std::string& name) const
270 {
271 return top_level_varval_deprecated (name);
272 }
273
274 OCTAVE_DEPRECATED (6, "use 'interpreter::global_variable_names' instead")
275 std::list<std::string> global_variable_names (void)
276 {
277 return global_variable_names_deprecated ();
278 }
279
280 OCTAVE_DEPRECATED (6, "use 'interpreter::top_level_variable_names' instead")
281 std::list<std::string> top_level_variable_names (void)
282 {
283 return top_level_variable_names_deprecated ();
284 }
285
286 OCTAVE_DEPRECATED (6, "use 'interpreter::variable_names' instead")
287 std::list<std::string> variable_names (void)
288 {
289 return variable_names_deprecated ();
290 }
291
292 OCTAVE_DEPRECATED (6, "use 'interpreter::assign' instead")
293 void assign (const std::string& name,
294 const octave_value& value = octave_value ())
295 {
296 assign_deprecated (name, value);
297 }
298
299 // Note, FORCE_ADD no longer has any meaning.
300 OCTAVE_DEPRECATED (6, "use 'interpreter::assign' instead")
301 void assign (const std::string& name, const octave_value& value,
302 bool /*force_add*/)
303 {
304 assign_deprecated (name, value);
305 }
306
307 OCTAVE_DEPRECATED (6, "use 'interpreter::clear_all' instead")
308 void clear_all (bool force = false)
309 {
310 clear_all_deprecated (force);
311 }
312
313 OCTAVE_DEPRECATED (6, "use 'interpreter::clear_global' instead")
314 void clear_global (const std::string& name)
315 {
316 clear_global_deprecated (name);
317 }
318
319 OCTAVE_DEPRECATED (6, "use 'interpreter::clear_global_pattern' instead")
320 void clear_global_pattern (const std::string& pattern)
321 {
322 clear_global_pattern_deprecated (pattern);
323 }
324
325 OCTAVE_DEPRECATED (6, "use 'interpreter::clear_symbol' instead")
326 void clear_symbol (const std::string& name)
327 {
328 clear_symbol_deprecated (name);
329 }
330
331 OCTAVE_DEPRECATED (6, "use 'interpreter::clear_symbol_pattern' instead")
332 void clear_symbol_pattern (const std::string& pattern)
333 {
334 clear_symbol_pattern_deprecated (pattern);
335 }
336
337 OCTAVE_DEPRECATED (6, "use 'interpreter::global_assign' instead")
338 void global_assign (const std::string& name,
339 const octave_value& value = octave_value ())
340 {
341 global_assign_deprecated (name, value);
342 }
343
344 OCTAVE_DEPRECATED (6, "use 'interpreter::top_level_assign' instead")
345 void top_level_assign (const std::string& name,
346 const octave_value& value = octave_value ())
347 {
348 top_level_assign_deprecated (name, value);
349 }
350#endif
351
352 private:
353
355
356 typedef std::map<std::string, octave_value>::const_iterator
358 typedef std::map<std::string, octave_value>::iterator
360
361 typedef std::map<std::string, fcn_info>::const_iterator
363 typedef std::map<std::string, fcn_info>::iterator
365
366 // Map from function names to function info (private
367 // functions, class constructors, class methods, etc.)
368 // Note that subfunctions are defined in the scope that contains
369 // them.
370 std::map<std::string, fcn_info> m_fcn_table;
371
372 // Map from class names to set of classes that have lower
373 // precedence.
374 std::map<std::string, std::set<std::string>> m_class_precedence_table;
375
376 typedef std::map<std::string, std::set<std::string>>::const_iterator
378 typedef std::map<std::string, std::set<std::string>>::iterator
380
381 // Map from class names to parent class names.
382 std::map<std::string, std::list<std::string>> m_parent_map;
383
384 typedef std::map<std::string, std::list<std::string>>::const_iterator
386 typedef std::map<std::string, std::list<std::string>>::iterator
388
389 octave_value dump_fcn_table_map (void) const;
390
391 // This function is generated automatically by mk-builtins.pl.
392 void install_builtins (void);
393 };
394
395OCTAVE_NAMESPACE_END
396
397#endif
std::map< std::string, std::list< std::string > >::iterator parent_map_iterator
Definition: symtab.h:387
std::map< std::string, octave_value >::iterator global_symbols_iterator
Definition: symtab.h:359
octave::fcn_info fcn_info
Definition: symtab.h:59
std::map< std::string, std::list< std::string > > m_parent_map
Definition: symtab.h:382
std::map< std::string, octave_value >::const_iterator global_symbols_const_iterator
Definition: symtab.h:357
void assign_deprecated(const std::string &name, const octave_value &value, bool)
interpreter & m_interpreter
Definition: symtab.h:354
octave::symbol_scope scope
Definition: symtab.h:58
std::map< std::string, std::set< std::string > >::iterator class_precedence_table_iterator
Definition: symtab.h:379
std::map< std::string, std::set< std::string > >::const_iterator class_precedence_table_const_iterator
Definition: symtab.h:377
~symbol_table(void)=default
symbol_table(const symbol_table &)=delete
std::map< std::string, fcn_info > m_fcn_table
Definition: symtab.h:370
std::map< std::string, fcn_info >::const_iterator fcn_table_const_iterator
Definition: symtab.h:362
std::map< std::string, fcn_info >::iterator fcn_table_iterator
Definition: symtab.h:364
std::map< std::string, std::list< std::string > >::const_iterator const_parent_map_iterator
Definition: symtab.h:385
void install_builtins(void)
std::map< std::string, std::set< std::string > > m_class_precedence_table
Definition: symtab.h:374
QString name
STL namespace.
octave_value_list ovl(const OV_Args &... args)
Construct an octave_value_list with less typing.
Definition: ovl.h:211