GNU Octave  9.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-2024 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  OCTAVE_DISABLE_CONSTRUCT_COPY_MOVE (symbol_table)
64 
65  ~symbol_table () = default;
66 
67  symbol_scope current_scope () const;
68 
69  bool is_built_in_function_name (const std::string& name);
70 
71  octave_value find_scoped_function (const std::string& name,
72  const symbol_scope& search_scope);
73 
74  octave_value find_private_function (const std::string& dir_name,
75  const std::string& name);
76 
77  // FIXME: this function only finds legacy class methods, not
78  // classdef methods.
79  octave_value find_method (const std::string& name,
80  const std::string& dispatch_type);
81 
82  octave_value find_built_in_function (const std::string& name);
83 
84  octave_value find_autoload (const std::string& name);
85 
87  builtin_find (const std::string& name,
88  const symbol_scope& search_scope = symbol_scope::invalid ());
89 
91  fcn_table_find (const std::string& name,
92  const octave_value_list& args = ovl (),
93  const symbol_scope& search_scope = symbol_scope::invalid ());
94 
95  // If NAME is of the form @CLASS/FUNCTION, call
96  //
97  // find_method (FUNCTION, CLASS)
98  //
99  // otherwise call
100  //
101  // find_function (NAME, ovl ())
102 
104  find_function (const std::string& name,
105  const symbol_scope& search_scope = symbol_scope::invalid ());
106 
107  // NAME should just be function name; dispatch type determined
108  // from types of ARGS.
109 
111  find_function (const std::string& name,
112  const octave_value_list& args,
113  const symbol_scope& search_scope = symbol_scope::invalid ());
114 
115  octave_value find_user_function (const std::string& name);
116 
117  octave_value find_cmdline_function (const std::string& name);
118 
119  void install_cmdline_function (const std::string& name,
120  const octave_value& fcn);
121 
122  // Install local function FCN named NAME. FILE_NAME is the name of
123  // the file containing the local function.
124 
125  void install_local_function (const std::string& name,
126  const octave_value& fcn,
127  const std::string& file_name);
128 
129  void install_user_function (const std::string& name,
130  const octave_value& fcn);
131 
132  // FIXME: should we ensure that FCN really is a built-in function
133  // object?
134  void install_built_in_function (const std::string& name,
135  const octave_value& fcn);
136 
137  // This is written as two separate functions instead of a single
138  // function with default values so that it will work properly with
139  // unwind_protect.
140 
141  void clear_functions (bool force = false);
142 
143  void clear_function (const std::string& name);
144 
145  void clear_function_pattern (const std::string& pat);
146 
147  void clear_function_regexp (const std::string& pat);
148 
149  void clear_user_function (const std::string& name);
150 
151  // This clears oct and mex files, including autoloads.
152  void clear_dld_function (const std::string& name);
153 
154  void clear_mex_functions ();
155 
156  bool set_class_relationship (const std::string& sup_class,
157  const std::string& inf_class);
158 
159  bool is_superiorto (const std::string& a, const std::string& b);
160 
161  void alias_built_in_function (const std::string& alias,
162  const std::string& name);
163 
164  void install_built_in_dispatch (const std::string& name,
165  const std::string& klass);
166 
167  std::list<std::string> user_function_names ();
168 
169  std::list<std::string> built_in_function_names ();
170 
171  std::list<std::string> cmdline_function_names ();
172 
173  octave_value dump () const;
174 
175  void add_to_parent_map (const std::string& classname,
176  const std::list<std::string>& parent_list);
177 
178  std::list<std::string> parent_classes (const std::string& dispatch_type);
179 
180  void cleanup ();
181 
182  fcn_info * get_fcn_info (const std::string& name);
183 
184 private:
185 
186  interpreter& m_interpreter;
187 
188  typedef std::map<std::string, octave_value>::const_iterator
189  global_symbols_const_iterator;
190  typedef std::map<std::string, octave_value>::iterator
191  global_symbols_iterator;
192 
193  typedef std::map<std::string, fcn_info>::const_iterator
194  fcn_table_const_iterator;
195  typedef std::map<std::string, fcn_info>::iterator
196  fcn_table_iterator;
197 
198  // Map from function names to function info (private
199  // functions, class constructors, class methods, etc.)
200  // Note that subfunctions are defined in the scope that contains
201  // them.
202  std::map<std::string, fcn_info> m_fcn_table;
203 
204  // Map from class names to set of classes that have lower
205  // precedence.
206  std::map<std::string, std::set<std::string>> m_class_precedence_table;
207 
208  typedef std::map<std::string, std::set<std::string>>::const_iterator
209  class_precedence_table_const_iterator;
210  typedef std::map<std::string, std::set<std::string>>::iterator
211  class_precedence_table_iterator;
212 
213  // Map from class names to parent class names.
214  std::map<std::string, std::list<std::string>> m_parent_map;
215 
216  typedef std::map<std::string, std::list<std::string>>::const_iterator
217  const_parent_map_iterator;
218  typedef std::map<std::string, std::list<std::string>>::iterator
219  parent_map_iterator;
220 
221  octave_value dump_fcn_table_map () const;
222 
223  // This function is generated automatically by mk-builtins.pl.
224  void install_builtins ();
225 };
226 
227 OCTAVE_END_NAMESPACE(octave)
228 
229 #endif
static symbol_scope invalid()
Definition: symscope.h:400
octave::fcn_info fcn_info
Definition: symtab.h:59
octave::symbol_scope scope
Definition: symtab.h:58
~symbol_table()=default
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:219