GNU Octave  8.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
ov-fcn.h
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (C) 1996-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_ov_fcn_h)
27 #define octave_ov_fcn_h 1
28 
29 #include "octave-config.h"
30 
31 #include <string>
32 
33 #include "oct-time.h"
34 #include "str-vec.h"
35 
36 #include "ovl.h"
37 #include "ov-base.h"
38 #include "ov-typeinfo.h"
39 #include "symscope.h"
40 
42 
43 class stack_frame;
44 class tree_evaluator;
45 class tree_walker;
46 
48 
49 // Functions.
50 
51 class
52 OCTINTERP_API
54 {
55 public:
56 
58  : m_relative (false), m_locked (false), m_private (false),
59  m_dispatch_class (), m_package_name (), m_name (), m_dir_name (),
60  m_doc () { }
61 
62  // No copying!
63 
64  octave_function (const octave_function& f) = delete;
65 
67 
68  ~octave_function (void) = default;
69 
70  octave_base_value * clone (void) const;
71  octave_base_value * empty_clone (void) const;
72 
73  bool is_defined (void) const { return true; }
74 
75  bool is_function (void) const { return true; }
76 
77  virtual bool is_system_fcn_file (void) const { return false; }
78 
79  virtual std::string fcn_file_name (void) const { return ""; }
80 
81  virtual std::string src_file_name (void) const { return ""; }
82 
83  // The name to show in the profiler (also used as map-key).
84  virtual std::string profiler_name (void) const { return name (); }
85 
86  virtual std::string parent_fcn_name (void) const { return ""; }
87 
88  virtual octave::symbol_scope parent_fcn_scope (void) const
89  { return octave::symbol_scope (); }
90 
91  virtual std::list<std::string> parent_fcn_names (void) const
92  { return std::list<std::string> (); }
93 
94  virtual void mark_fcn_file_up_to_date (const octave::sys::time&) { }
95 
96  virtual octave::symbol_scope scope (void) { return octave::symbol_scope (); }
97 
98  virtual octave::sys::time time_parsed (void) const
99  { return octave::sys::time (static_cast<OCTAVE_TIME_T> (0)); }
100 
101  virtual octave::sys::time time_checked (void) const
102  { return octave::sys::time (static_cast<OCTAVE_TIME_T> (0)); }
103 
104  virtual int call_depth (void) const { return 0; }
105 
106  virtual bool is_nested_function (void) const { return false; }
107 
108  virtual bool is_parent_function (void) const { return false; }
109 
110  virtual bool is_subfunction (void) const { return false; }
111 
112  bool is_class_constructor (const std::string& cname = "") const
113  {
114  return (is_classdef_constructor (cname) || is_legacy_constructor (cname));
115  }
116 
117  bool is_class_method (const std::string& cname = "") const
118  {
119  return (is_classdef_method (cname) || is_legacy_method (cname));
120  }
121 
122  virtual bool
123  is_legacy_constructor (const std::string& = "") const
124  { return false; }
125 
126  virtual bool
127  is_classdef_constructor (const std::string& = "") const
128  { return false; }
129 
130  virtual bool is_legacy_method (const std::string& = "") const
131  { return false; }
132 
133  virtual bool is_classdef_method (const std::string& = "") const
134  { return false; }
135 
136  virtual bool takes_varargs (void) const { return false; }
137 
138  virtual bool takes_var_return (void) const { return false; }
139 
140  // The next two functions are for dispatching to built-in
141  // functions given built-in classes.
142 
143  virtual void push_dispatch_class (const std::string&) { }
144 
145  virtual bool handles_dispatch_class (const std::string&) const
146  { return false; }
147 
148  void stash_dispatch_class (const std::string& nm) { m_dispatch_class = nm; }
149 
150  std::string dispatch_class (void) const { return m_dispatch_class; }
151 
152  void stash_package_name (const std::string& pack) { m_package_name = pack; }
153 
154  std::string package_name (void) const { return m_package_name; }
155 
156  virtual void
157  mark_as_private_function (const std::string& cname = "")
158  {
159  m_private = true;
160  m_dispatch_class = cname;
161  }
162 
163  bool is_private_function (void) const { return m_private; }
164 
165  bool is_private_function_of_class (const std::string& nm) const
166  { return m_private && m_dispatch_class == nm; }
167 
168  virtual bool
169  is_anonymous_function_of_class (const std::string& = "") const
170  { return false; }
171 
172  std::string dir_name (void) const { return m_dir_name; }
173 
174  void stash_dir_name (const std::string& dir) { m_dir_name = dir; }
175 
176  void lock (void)
177  {
178  this->lock_subfunctions ();
179  m_locked = true;
180  }
181 
182  void unlock (void)
183  {
184  this->unlock_subfunctions ();
185  m_locked = false;
186  }
187 
188  bool islocked (void) const { return m_locked; }
189 
190  virtual void lock_subfunctions (void) { }
191 
192  virtual void unlock_subfunctions (void) { }
193 
194  virtual void maybe_relocate_end (void) { }
195 
196  // Not valid until after the function is completely parsed.
197  virtual bool has_subfunctions (void) const { return false; }
198 
199  virtual void stash_subfunction_names (const std::list<std::string>&) { }
200 
201  virtual std::list<std::string> subfunction_names (void) const
202  { return std::list<std::string> (); }
203 
204  void mark_relative (void) { m_relative = true; }
205 
206  bool is_relative (void) const { return m_relative; }
207 
208  std::string name (void) const { return m_name; }
209 
210  std::string canonical_name (void) const
211  {
212  if (m_package_name.empty ())
213  return m_name;
214  else
215  return m_package_name + '.' + m_name;
216  }
217 
218  void document (const std::string& ds) { m_doc = ds; }
219 
220  virtual std::string
221  doc_string (const std::string& /*meth_name*/ = "") const { return m_doc; }
222 
223  virtual void unload (void) { }
224 
225  virtual void accept (octave::tree_walker&) { }
226 
227  virtual bool accepts_postfix_index (char type) const
228  { return (type == '('); }
229 
230  // Push new stack frame (if necessary) and execute function.
231  virtual octave_value_list
232  call (octave::tree_evaluator& tw, int nargout = 0,
233  const octave_value_list& args = octave_value_list ());
234 
235  // Execute function without pushing new stack frame (assumes that has
236  // already been done).
237  virtual octave_value_list
238  execute (octave::tree_evaluator& tw, int nargout = 0,
239  const octave_value_list& args = octave_value_list ()) = 0;
240 
241 protected:
242 
243  octave_function (const std::string& nm,
244  const std::string& ds = "")
245  : m_relative (false), m_locked (false), m_private (false),
246  m_dispatch_class (), m_name (nm), m_dir_name (), m_doc (ds) { }
247 
248  // TRUE if this function was found from a m_relative path element.
250 
251  // TRUE if this function is tagged so that it can't be cleared.
252  bool m_locked;
253 
254  // TRUE means this is a private function.
255  bool m_private;
256 
257  // If this object is a class method or constructor, or a private
258  // function inside a class directory, this is the name of the class
259  // to which the method belongs.
260  std::string m_dispatch_class;
261 
262  // If this function is part of a package, this is the full name
263  // of the package to which the function belongs.
264  std::string m_package_name;
265 
266  // The name of this function.
267  std::string m_name;
268 
269  // The name of the directory in the path where we found this
270  // function. May be m_relative.
271  std::string m_dir_name;
272 
273  // The help text for this function.
274  std::string m_doc;
275 };
276 
277 #endif
OCTAVE_END_NAMESPACE(octave)
virtual bool handles_dispatch_class(const std::string &) const
Definition: ov-fcn.h:145
bool m_private
Definition: ov-fcn.h:255
std::string dispatch_class(void) const
Definition: ov-fcn.h:150
virtual int call_depth(void) const
Definition: ov-fcn.h:104
virtual bool is_anonymous_function_of_class(const std::string &="") const
Definition: ov-fcn.h:169
virtual std::string fcn_file_name(void) const
Definition: ov-fcn.h:79
virtual std::string profiler_name(void) const
Definition: ov-fcn.h:84
bool is_private_function(void) const
Definition: ov-fcn.h:163
octave_function(const std::string &nm, const std::string &ds="")
Definition: ov-fcn.h:243
~octave_function(void)=default
virtual octave::symbol_scope scope(void)
Definition: ov-fcn.h:96
virtual bool is_legacy_constructor(const std::string &="") const
Definition: ov-fcn.h:123
virtual octave::sys::time time_parsed(void) const
Definition: ov-fcn.h:98
virtual octave_value_list execute(octave::tree_evaluator &tw, int nargout=0, const octave_value_list &args=octave_value_list())=0
octave_function(const octave_function &f)=delete
bool is_relative(void) const
Definition: ov-fcn.h:206
std::string dir_name(void) const
Definition: ov-fcn.h:172
std::string package_name(void) const
Definition: ov-fcn.h:154
bool m_locked
Definition: ov-fcn.h:252
virtual void unload(void)
Definition: ov-fcn.h:223
bool is_class_method(const std::string &cname="") const
Definition: ov-fcn.h:117
virtual bool is_parent_function(void) const
Definition: ov-fcn.h:108
bool is_class_constructor(const std::string &cname="") const
Definition: ov-fcn.h:112
virtual std::string doc_string(const std::string &="") const
Definition: ov-fcn.h:221
bool is_function(void) const
Definition: ov-fcn.h:75
virtual std::list< std::string > subfunction_names(void) const
Definition: ov-fcn.h:201
virtual void lock_subfunctions(void)
Definition: ov-fcn.h:190
virtual bool has_subfunctions(void) const
Definition: ov-fcn.h:197
virtual std::string src_file_name(void) const
Definition: ov-fcn.h:81
virtual void maybe_relocate_end(void)
Definition: ov-fcn.h:194
void mark_relative(void)
Definition: ov-fcn.h:204
std::string m_dir_name
Definition: ov-fcn.h:271
virtual void unlock_subfunctions(void)
Definition: ov-fcn.h:192
virtual void push_dispatch_class(const std::string &)
Definition: ov-fcn.h:143
virtual bool is_subfunction(void) const
Definition: ov-fcn.h:110
virtual bool is_classdef_constructor(const std::string &="") const
Definition: ov-fcn.h:127
std::string canonical_name(void) const
Definition: ov-fcn.h:210
virtual bool takes_varargs(void) const
Definition: ov-fcn.h:136
void unlock(void)
Definition: ov-fcn.h:182
virtual std::list< std::string > parent_fcn_names(void) const
Definition: ov-fcn.h:91
virtual bool accepts_postfix_index(char type) const
Definition: ov-fcn.h:227
bool islocked(void) const
Definition: ov-fcn.h:188
void document(const std::string &ds)
Definition: ov-fcn.h:218
std::string m_dispatch_class
Definition: ov-fcn.h:260
virtual std::string parent_fcn_name(void) const
Definition: ov-fcn.h:86
void stash_dir_name(const std::string &dir)
Definition: ov-fcn.h:174
virtual bool is_legacy_method(const std::string &="") const
Definition: ov-fcn.h:130
virtual bool is_classdef_method(const std::string &="") const
Definition: ov-fcn.h:133
bool m_relative
Definition: ov-fcn.h:249
virtual octave::sys::time time_checked(void) const
Definition: ov-fcn.h:101
void lock(void)
Definition: ov-fcn.h:176
std::string m_name
Definition: ov-fcn.h:267
virtual octave::symbol_scope parent_fcn_scope(void) const
Definition: ov-fcn.h:88
virtual bool takes_var_return(void) const
Definition: ov-fcn.h:138
std::string m_package_name
Definition: ov-fcn.h:264
virtual void mark_fcn_file_up_to_date(const octave::sys::time &)
Definition: ov-fcn.h:94
void stash_dispatch_class(const std::string &nm)
Definition: ov-fcn.h:148
bool is_private_function_of_class(const std::string &nm) const
Definition: ov-fcn.h:165
std::string m_doc
Definition: ov-fcn.h:274
virtual void mark_as_private_function(const std::string &cname="")
Definition: ov-fcn.h:157
std::string name(void) const
Definition: ov-fcn.h:208
virtual bool is_nested_function(void) const
Definition: ov-fcn.h:106
octave_function(void)
Definition: ov-fcn.h:57
virtual bool is_system_fcn_file(void) const
Definition: ov-fcn.h:77
void stash_package_name(const std::string &pack)
Definition: ov-fcn.h:152
virtual void accept(octave::tree_walker &)
Definition: ov-fcn.h:225
bool is_defined(void) const
Definition: ov-fcn.h:73
virtual void stash_subfunction_names(const std::list< std::string > &)
Definition: ov-fcn.h:199
tree_walker & operator=(const tree_walker &)=delete
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
F77_RET_T const F77_DBLE const F77_DBLE * f