GNU Octave  8.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-2023 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 
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.
58  typedef octave::symbol_scope scope;
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 private:
189 
191 
192  typedef std::map<std::string, octave_value>::const_iterator
194  typedef std::map<std::string, octave_value>::iterator
196 
197  typedef std::map<std::string, fcn_info>::const_iterator
199  typedef std::map<std::string, fcn_info>::iterator
201 
202  // Map from function names to function info (private
203  // functions, class constructors, class methods, etc.)
204  // Note that subfunctions are defined in the scope that contains
205  // them.
206  std::map<std::string, fcn_info> m_fcn_table;
207 
208  // Map from class names to set of classes that have lower
209  // precedence.
210  std::map<std::string, std::set<std::string>> m_class_precedence_table;
211 
212  typedef std::map<std::string, std::set<std::string>>::const_iterator
214  typedef std::map<std::string, std::set<std::string>>::iterator
216 
217  // Map from class names to parent class names.
218  std::map<std::string, std::list<std::string>> m_parent_map;
219 
220  typedef std::map<std::string, std::list<std::string>>::const_iterator
222  typedef std::map<std::string, std::list<std::string>>::iterator
224 
225  octave_value dump_fcn_table_map (void) const;
226 
227  // This function is generated automatically by mk-builtins.pl.
228  void install_builtins (void);
229 };
230 
232 
233 #endif
OCTAVE_END_NAMESPACE(octave)
octave::fcn_info fcn_info
Definition: symtab.h:59
std::map< std::string, std::list< std::string > > m_parent_map
Definition: symtab.h:218
std::map< std::string, std::set< std::string > >::iterator class_precedence_table_iterator
Definition: symtab.h:215
std::map< std::string, std::list< std::string > >::const_iterator const_parent_map_iterator
Definition: symtab.h:221
interpreter & m_interpreter
Definition: symtab.h:190
octave::symbol_scope scope
Definition: symtab.h:58
std::map< std::string, std::list< std::string > >::iterator parent_map_iterator
Definition: symtab.h:223
~symbol_table(void)=default
std::map< std::string, fcn_info >::iterator fcn_table_iterator
Definition: symtab.h:200
symbol_table(const symbol_table &)=delete
std::map< std::string, fcn_info > m_fcn_table
Definition: symtab.h:206
std::map< std::string, octave_value >::iterator global_symbols_iterator
Definition: symtab.h:195
std::map< std::string, octave_value >::const_iterator global_symbols_const_iterator
Definition: symtab.h:193
std::map< std::string, std::set< std::string > >::const_iterator class_precedence_table_const_iterator
Definition: symtab.h:213
void install_builtins(void)
std::map< std::string, std::set< std::string > > m_class_precedence_table
Definition: symtab.h:210
std::map< std::string, fcn_info >::const_iterator fcn_table_const_iterator
Definition: symtab.h:198
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
octave_value_list ovl(const OV_Args &... args)
Construct an octave_value_list with less typing.
Definition: ovl.h:211