GNU Octave  6.2.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-2021 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 
41 class tree_argument_list;
43 
44 #include "fcn-info.h"
45 #include "ov.h"
46 #include "ovl.h"
47 #include "symscope.h"
48 
49 namespace octave
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.
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  OCTAVE_DEPRECATED (6, "use 'interpreter::at_top_level' instead")
193  bool at_top_level (void);
194 
195  OCTAVE_DEPRECATED (6, "use 'interpreter::varval' instead")
196  octave_value varval (const std::string& name) const;
197 
198  OCTAVE_DEPRECATED (6, "use 'interpreter::global_varval' instead")
199  octave_value global_varval (const std::string& name) const;
200 
201  OCTAVE_DEPRECATED (6, "use 'interpreter::top_level_varval' instead")
202  octave_value top_level_varval (const std::string& name) const;
203 
204  OCTAVE_DEPRECATED (6, "use 'interpreter::global_variable_names' instead")
205  std::list<std::string> global_variable_names (void);
206 
207  OCTAVE_DEPRECATED (6, "use 'interpreter::top_level_variable_names' instead")
208  std::list<std::string> top_level_variable_names (void);
209 
210  OCTAVE_DEPRECATED (6, "use 'interpreter::variable_names' instead")
211  std::list<std::string> variable_names (void);
212 
213  OCTAVE_DEPRECATED (6, "use 'interpreter::assign' instead")
214  void assign (const std::string& name,
215  const octave_value& value = octave_value ());
216 
217  // Note, FORCE_ADD no longer has any meaning.
218  OCTAVE_DEPRECATED (6, "use 'interpreter::assign' instead")
219  void assign (const std::string& name, const octave_value& value,
220  bool /*force_add*/);
221 
222  OCTAVE_DEPRECATED (6, "use 'interpreter::clear_all' instead")
223  void clear_all (bool force = false);
224 
225  OCTAVE_DEPRECATED (6, "use 'interpreter::clear_global' instead")
226  void clear_global (const std::string& name);
227 
228  OCTAVE_DEPRECATED (6, "use 'interpreter::clear_global_pattern' instead")
229  void clear_global_pattern (const std::string& pattern);
230 
231  OCTAVE_DEPRECATED (6, "use 'interpreter::clear_symbol' instead")
232  void clear_symbol (const std::string& name);
233 
234  OCTAVE_DEPRECATED (6, "use 'interpreter::clear_symbol_pattern' instead")
235  void clear_symbol_pattern (const std::string& pattern);
236 
237  OCTAVE_DEPRECATED (6, "use 'interpreter::global_assign' instead")
238  void global_assign (const std::string& name,
239  const octave_value& value = octave_value ());
240 
241  OCTAVE_DEPRECATED (6, "use 'interpreter::top_level_assign' instead")
242  void top_level_assign (const std::string& name,
243  const octave_value& value = octave_value ());
244 
245  private:
246 
247  interpreter& m_interpreter;
248 
249  typedef std::map<std::string, octave_value>::const_iterator
251  typedef std::map<std::string, octave_value>::iterator
253 
254  typedef std::map<std::string, fcn_info>::const_iterator
256  typedef std::map<std::string, fcn_info>::iterator
258 
259  // Map from function names to function info (private
260  // functions, class constructors, class methods, etc.)
261  // Note that subfunctions are defined in the scope that contains
262  // them.
263  std::map<std::string, fcn_info> m_fcn_table;
264 
265  // Map from class names to set of classes that have lower
266  // precedence.
267  std::map<std::string, std::set<std::string>> m_class_precedence_table;
268 
269  typedef std::map<std::string, std::set<std::string>>::const_iterator
271  typedef std::map<std::string, std::set<std::string>>::iterator
273 
274  // Map from class names to parent class names.
275  std::map<std::string, std::list<std::string>> m_parent_map;
276 
277  typedef std::map<std::string, std::list<std::string>>::const_iterator
279  typedef std::map<std::string, std::list<std::string>>::iterator
281 
282  octave_value dump_fcn_table_map (void) const;
283 
284  // This function is generated automatically by mk-builtins.pl.
285  void install_builtins (void);
286  };
287 }
288 
289 #endif
std::map< std::string, std::list< std::string > >::const_iterator const_parent_map_iterator
Definition: symtab.h:278
~symbol_table(void)=default
symbol_table(const symbol_table &)=delete
std::map< std::string, fcn_info >::const_iterator fcn_table_const_iterator
Definition: symtab.h:255
std::map< std::string, std::set< std::string > >::const_iterator class_precedence_table_const_iterator
Definition: symtab.h:270
std::map< std::string, std::list< std::string > >::iterator parent_map_iterator
Definition: symtab.h:280
octave::fcn_info fcn_info
Definition: symtab.h:59
octave::symbol_scope scope
Definition: symtab.h:58
std::map< std::string, octave_value >::iterator global_symbols_iterator
Definition: symtab.h:252
std::map< std::string, octave_value >::const_iterator global_symbols_const_iterator
Definition: symtab.h:250
std::map< std::string, std::set< std::string > >::iterator class_precedence_table_iterator
Definition: symtab.h:272
std::map< std::string, fcn_info >::iterator fcn_table_iterator
Definition: symtab.h:257
QString name
octave_value_list ovl(const OV_Args &... args)
Construct an octave_value_list with less typing.
Definition: ovl.h:211