GNU Octave 10.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-2025 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
43class filepos;
44class stack_frame;
45class tree_evaluator;
46class tree_walker;
47
48OCTAVE_END_NAMESPACE(octave)
49
50// Functions.
51
52class OCTINTERP_API octave_function : public octave_base_value
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 OCTAVE_DISABLE_COPY_MOVE (octave_function)
62
63 ~octave_function () = default;
64
65 octave_base_value * clone () const;
66 octave_base_value * empty_clone () const;
67
68 bool is_defined () const { return true; }
69
70 bool is_function () const { return true; }
71
72 virtual bool is_system_fcn_file () const { return false; }
73
74 virtual std::string fcn_file_name () const { return ""; }
75
76 virtual std::string src_file_name () const { return ""; }
77
78 virtual octave::filepos beg_pos () const;
79 virtual octave::filepos end_pos () const;
80
81 // The name to show in the profiler (also used as map-key).
82 virtual std::string profiler_name () const { return name (); }
83
84 virtual std::string parent_fcn_name () const { return ""; }
85
86 virtual octave::symbol_scope parent_fcn_scope () const
87 { return octave::symbol_scope::invalid (); }
88
89 virtual std::list<std::string> parent_fcn_names () const
90 { return std::list<std::string> (); }
91
92 virtual void mark_fcn_file_up_to_date (const octave::sys::time&) { }
93
94 virtual octave::symbol_scope scope () { return octave::symbol_scope::invalid (); }
95
96 virtual octave::sys::time time_parsed () const
97 { return octave::sys::time (static_cast<OCTAVE_TIME_T> (0)); }
98
99 virtual octave::sys::time time_checked () const
100 { return octave::sys::time (static_cast<OCTAVE_TIME_T> (0)); }
101
102 virtual int call_depth () const { return 0; }
103
104 virtual bool is_nested_function () const { return false; }
105
106 virtual bool is_parent_function () const { return false; }
107
108 virtual bool is_subfunction () const { return false; }
109
110 virtual bool is_compiled () 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 () const { return false; }
137
138 virtual bool takes_var_return () 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 () 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 () 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 () 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 () const { return m_dir_name; }
173
174 void stash_dir_name (const std::string& dir) { m_dir_name = dir; }
175
176 void lock ()
177 {
178 this->lock_subfunctions ();
179 m_locked = true;
180 }
181
182 void unlock ()
183 {
184 this->unlock_subfunctions ();
185 m_locked = false;
186 }
187
188 bool islocked () const { return m_locked; }
189
190 virtual void lock_subfunctions () { }
191
192 virtual void unlock_subfunctions () { }
193
194 virtual void maybe_relocate_end () { }
195
196 // Not valid until after the function is completely parsed.
197 virtual bool has_subfunctions () const { return false; }
198
199 virtual void stash_subfunction_names (const std::list<std::string>&) { }
200
201 virtual std::list<std::string> subfunction_names () const
202 { return std::list<std::string> (); }
203
204 void mark_relative () { m_relative = true; }
205
206 bool is_relative () const { return m_relative; }
207
208 std::string name () const { return m_name; }
209
210 std::string canonical_name () 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 () { }
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
241protected:
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.
253
254 // TRUE means this is a private function.
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
virtual bool handles_dispatch_class(const std::string &) const
Definition ov-fcn.h:145
virtual bool is_anonymous_function_of_class(const std::string &="") const
Definition ov-fcn.h:169
virtual octave::symbol_scope scope()
Definition ov-fcn.h:94
virtual void unlock_subfunctions()
Definition ov-fcn.h:192
octave_function(const std::string &nm, const std::string &ds="")
Definition ov-fcn.h:243
virtual bool is_nested_function() const
Definition ov-fcn.h:104
virtual bool is_legacy_constructor(const std::string &="") const
Definition ov-fcn.h:123
virtual bool is_subfunction() const
Definition ov-fcn.h:108
std::string dispatch_class() const
Definition ov-fcn.h:150
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:188
virtual std::string profiler_name() const
Definition ov-fcn.h:82
std::string canonical_name() const
Definition ov-fcn.h:210
virtual std::list< std::string > subfunction_names() const
Definition ov-fcn.h:201
std::string package_name() const
Definition ov-fcn.h:154
virtual octave::symbol_scope parent_fcn_scope() const
Definition ov-fcn.h:86
bool is_class_method(const std::string &cname="") const
Definition ov-fcn.h:117
virtual bool takes_var_return() const
Definition ov-fcn.h:138
virtual bool takes_varargs() const
Definition ov-fcn.h:136
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_private_function() const
Definition ov-fcn.h:163
bool is_defined() const
Definition ov-fcn.h:68
virtual octave::sys::time time_checked() const
Definition ov-fcn.h:99
std::string m_dir_name
Definition ov-fcn.h:271
virtual std::string parent_fcn_name() const
Definition ov-fcn.h:84
void unlock()
Definition ov-fcn.h:182
virtual void push_dispatch_class(const std::string &)
Definition ov-fcn.h:143
virtual bool is_classdef_constructor(const std::string &="") const
Definition ov-fcn.h:127
virtual void maybe_relocate_end()
Definition ov-fcn.h:194
virtual bool accepts_postfix_index(char type) const
Definition ov-fcn.h:227
virtual std::string src_file_name() const
Definition ov-fcn.h:76
~octave_function()=default
void document(const std::string &ds)
Definition ov-fcn.h:218
std::string m_dispatch_class
Definition ov-fcn.h:260
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
virtual void lock_subfunctions()
Definition ov-fcn.h:190
virtual bool is_parent_function() const
Definition ov-fcn.h:106
void lock()
Definition ov-fcn.h:176
virtual int call_depth() const
Definition ov-fcn.h:102
bool m_relative
Definition ov-fcn.h:249
virtual bool has_subfunctions() const
Definition ov-fcn.h:197
std::string m_name
Definition ov-fcn.h:267
virtual std::list< std::string > parent_fcn_names() const
Definition ov-fcn.h:89
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:92
bool is_relative() const
Definition ov-fcn.h:206
virtual octave::sys::time time_parsed() const
Definition ov-fcn.h:96
virtual bool is_compiled() const
Definition ov-fcn.h:110
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
bool is_function() const
Definition ov-fcn.h:70
virtual std::string fcn_file_name() const
Definition ov-fcn.h:74
virtual void mark_as_private_function(const std::string &cname="")
Definition ov-fcn.h:157
virtual void unload()
Definition ov-fcn.h:223
virtual bool is_system_fcn_file() const
Definition ov-fcn.h:72
std::string name() const
Definition ov-fcn.h:208
std::string dir_name() const
Definition ov-fcn.h:172
void stash_package_name(const std::string &pack)
Definition ov-fcn.h:152
virtual void accept(octave::tree_walker &)
Definition ov-fcn.h:225
void mark_relative()
Definition ov-fcn.h:204
virtual void stash_subfunction_names(const std::list< std::string > &)
Definition ov-fcn.h:199
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn