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