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