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