GNU Octave  4.4.1
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-2018 John W. Eaton
4 
5 This file is part of Octave.
6 
7 Octave is free software: you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
11 
12 Octave is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16 
17 You should have received a copy of the GNU General Public License
18 along with Octave; see the file COPYING. If not, see
19 <https://www.gnu.org/licenses/>.
20 
21 */
22 
23 #if ! defined (octave_ov_fcn_h)
24 #define octave_ov_fcn_h 1
25 
26 #include "octave-config.h"
27 
28 #include <string>
29 
30 #include "oct-time.h"
31 #include "str-vec.h"
32 
33 #include "ovl.h"
34 #include "ov-base.h"
35 #include "ov-typeinfo.h"
36 #include "symscope.h"
37 
38 namespace octave
39 {
40  class tree_evaluator;
41  class tree_walker;
42 }
43 
44 // Functions.
45 
46 class
47 OCTINTERP_API
49 {
50 public:
51 
53  : relative (false), locked (false), private_function (false),
54  xdispatch_class (), xpackage_name (), my_name (), my_dir_name (),
55  doc () { }
56 
57  // No copying!
58 
59  octave_function (const octave_function& f) = delete;
60 
61  octave_function& operator = (const octave_function& f) = delete;
62 
63  ~octave_function (void) = default;
64 
65  octave_base_value * clone (void) const;
66  octave_base_value * empty_clone (void) const;
67 
68  bool is_defined (void) const { return true; }
69 
70  bool is_function (void) const { return true; }
71 
72  virtual bool is_system_fcn_file (void) const { return false; }
73 
74  virtual std::string fcn_file_name (void) const { return ""; }
75 
76  virtual std::string src_file_name (void) const { return ""; }
77 
78  // The name to show in the profiler (also used as map-key).
79  virtual std::string profiler_name (void) const { return name (); }
80 
81  virtual std::string parent_fcn_name (void) const { return ""; }
82 
84  { return octave::symbol_scope (); }
85 
86  virtual void mark_fcn_file_up_to_date (const octave::sys::time&) { }
87 
88  virtual octave::symbol_scope scope (void) { return octave::symbol_scope (); }
89 
90  virtual octave::sys::time time_parsed (void) const
91  { return octave::sys::time (static_cast<time_t> (0)); }
92 
93  virtual octave::sys::time time_checked (void) const
94  { return octave::sys::time (static_cast<time_t> (0)); }
95 
96  virtual bool is_subfunction (void) const { return false; }
97 
98  virtual bool is_class_constructor (const std::string& = "") const
99  { return false; }
100 
101  virtual bool
103  { return false; }
104 
105  virtual bool is_class_method (const std::string& = "") const
106  { return false; }
107 
108  virtual bool takes_varargs (void) const { return false; }
109 
110  virtual bool takes_var_return (void) const { return false; }
111 
112  // The next two functions are for dispatching to built-in
113  // functions given built-in classes.
114 
115  virtual void push_dispatch_class (const std::string&) { }
116 
117  virtual bool handles_dispatch_class (const std::string&) const
118  { return false; }
119 
120  void stash_dispatch_class (const std::string& nm) { xdispatch_class = nm; }
121 
122  std::string dispatch_class (void) const { return xdispatch_class; }
123 
124  void stash_package_name (const std::string& pack) { xpackage_name = pack; }
125 
126  std::string package_name (void) const { return xpackage_name; }
127 
128  virtual void
130  {
131  private_function = true;
132  xdispatch_class = cname;
133  }
134 
135  bool is_private_function (void) const { return private_function; }
136 
138  { return private_function && xdispatch_class == nm; }
139 
140  virtual bool
142  { return false; }
143 
144  std::string dir_name (void) const { return my_dir_name; }
145 
146  void stash_dir_name (const std::string& dir) { my_dir_name = dir; }
147 
148  void lock (void)
149  {
150  this->lock_subfunctions ();
151  locked = true;
152  }
153 
154  void unlock (void)
155  {
156  this->unlock_subfunctions ();
157  locked = false;
158  }
159 
160  bool islocked (void) const { return locked; }
161 
162  virtual void lock_subfunctions (void) { }
163 
164  virtual void unlock_subfunctions (void) { }
165 
166  virtual void maybe_relocate_end (void) { }
167 
168  // Not valid until after the function is completley parsed.
169  virtual bool has_subfunctions (void) const { return false; }
170 
171  virtual void stash_subfunction_names (const std::list<std::string>&) { }
172 
173  virtual std::list<std::string> subfunction_names (void) const
174  {
175  return std::list<std::string> ();
176  }
177 
178  void mark_relative (void) { relative = true; }
179 
180  bool is_relative (void) const { return relative; }
181 
182  std::string name (void) const { return my_name; }
183 
185  {
186  if (xpackage_name.empty ())
187  return my_name;
188  else
189  return xpackage_name + '.' + my_name;
190  }
191 
192  void document (const std::string& ds) { doc = ds; }
193 
194  std::string doc_string (void) const { return doc; }
195 
196  virtual void unload (void) { }
197 
198  virtual void accept (octave::tree_walker&) { }
199 
200  virtual bool accepts_postfix_index (char type) const
201  { return (type == '('); }
202 
203  virtual octave_value_list
204  call (octave::tree_evaluator& tw, int nargout = 0,
205  const octave_value_list& args = octave_value_list ()) = 0;
206 
207 protected:
208 
210  const std::string& ds = "")
211  : relative (false), locked (false), private_function (false),
212  xdispatch_class (), my_name (nm), my_dir_name (), doc (ds) { }
213 
214  // TRUE if this function was found from a relative path element.
215  bool relative;
216 
217  // TRUE if this function is tagged so that it can't be cleared.
218  bool locked;
219 
220  // TRUE means this is a private function.
222 
223  // If this object is a class method or constructor, or a private
224  // function inside a class directory, this is the name of the class
225  // to which the method belongs.
227 
228  // If this function is part of a package, this is the full name
229  // of the package to which the function belongs.
231 
232  // The name of this function.
234 
235  // The name of the directory in the path where we found this
236  // function. May be relative.
238 
239  // The help text for this function.
241 };
242 
243 #endif
virtual std::list< std::string > subfunction_names(void) const
Definition: ov-fcn.h:173
virtual octave::symbol_scope scope(void)
Definition: ov-fcn.h:88
virtual octave::sys::time time_parsed(void) const
Definition: ov-fcn.h:90
std::string my_name
Definition: ov-fcn.h:233
void document(const std::string &ds)
Definition: ov-fcn.h:192
virtual void stash_subfunction_names(const std::list< std::string > &)
Definition: ov-fcn.h:171
void lock(void)
Definition: ov-fcn.h:148
virtual void unlock_subfunctions(void)
Definition: ov-fcn.h:164
virtual void unload(void)
Definition: ov-fcn.h:196
F77_RET_T const F77_REAL const F77_REAL F77_REAL &F77_RET_T const F77_DBLE const F77_DBLE F77_DBLE &F77_RET_T const F77_DBLE F77_DBLE &F77_RET_T const F77_REAL F77_REAL &F77_RET_T const F77_DBLE const F77_DBLE * f
std::string doc
Definition: ov-fcn.h:240
std::string xdispatch_class
Definition: ov-fcn.h:226
bool islocked(void) const
Definition: ov-fcn.h:160
bool is_relative(void) const
Definition: ov-fcn.h:180
void mark_relative(void)
Definition: ov-fcn.h:178
virtual void accept(octave::tree_walker &)
Definition: ov-fcn.h:198
virtual std::string src_file_name(void) const
Definition: ov-fcn.h:76
virtual bool is_classdef_constructor(const std::string &="") const
Definition: ov-fcn.h:102
void stash_dir_name(const std::string &dir)
Definition: ov-fcn.h:146
bool relative
Definition: ov-fcn.h:215
virtual std::string fcn_file_name(void) const
Definition: ov-fcn.h:74
bool is_defined(void) const
Definition: ov-fcn.h:68
bool private_function
Definition: ov-fcn.h:221
nd deftypefn *std::string name
Definition: sysdep.cc:647
OCTAVE_EXPORT octave_value_list isdir nd deftypefn *std::string nm
Definition: utils.cc:975
std::string doc_string(void) const
Definition: ov-fcn.h:194
OCTAVE_EXPORT octave_value_list return the number of command line arguments passed to Octave If called with the optional argument the function xample nargout(@histc)
Definition: ov-usr-fcn.cc:997
std::string dispatch_class(void) const
Definition: ov-fcn.h:122
virtual std::string parent_fcn_name(void) const
Definition: ov-fcn.h:81
virtual bool is_subfunction(void) const
Definition: ov-fcn.h:96
bool is_private_function_of_class(const std::string &nm) const
Definition: ov-fcn.h:137
virtual bool handles_dispatch_class(const std::string &) const
Definition: ov-fcn.h:117
virtual bool is_class_method(const std::string &="") const
Definition: ov-fcn.h:105
bool is_function(void) const
Definition: ov-fcn.h:70
virtual bool takes_varargs(void) const
Definition: ov-fcn.h:108
virtual void mark_as_private_function(const std::string &cname="")
Definition: ov-fcn.h:129
is false
Definition: cellfun.cc:400
virtual bool takes_var_return(void) const
Definition: ov-fcn.h:110
virtual bool accepts_postfix_index(char type) const
Definition: ov-fcn.h:200
octave_function(void)
Definition: ov-fcn.h:52
idx type
Definition: ov.cc:3114
virtual octave::sys::time time_checked(void) const
Definition: ov-fcn.h:93
virtual bool is_anonymous_function_of_class(const std::string &="") const
Definition: ov-fcn.h:141
std::string my_dir_name
Definition: ov-fcn.h:237
std::string dir_name(void) const
Definition: ov-fcn.h:144
virtual void maybe_relocate_end(void)
Definition: ov-fcn.h:166
octave_function(const std::string &nm, const std::string &ds="")
Definition: ov-fcn.h:209
void unlock(void)
Definition: ov-fcn.h:154
std::string canonical_name(void) const
Definition: ov-fcn.h:184
virtual void lock_subfunctions(void)
Definition: ov-fcn.h:162
std::string package_name(void) const
Definition: ov-fcn.h:126
virtual bool is_system_fcn_file(void) const
Definition: ov-fcn.h:72
virtual bool has_subfunctions(void) const
Definition: ov-fcn.h:169
virtual void mark_fcn_file_up_to_date(const octave::sys::time &)
Definition: ov-fcn.h:86
virtual bool is_class_constructor(const std::string &="") const
Definition: ov-fcn.h:98
void stash_dispatch_class(const std::string &nm)
Definition: ov-fcn.h:120
std::string xpackage_name
Definition: ov-fcn.h:230
virtual std::string profiler_name(void) const
Definition: ov-fcn.h:79
virtual octave::symbol_scope parent_fcn_scope(void) const
Definition: ov-fcn.h:83
bool is_private_function(void) const
Definition: ov-fcn.h:135
std::string name(void) const
Definition: ov-fcn.h:182
If this string is the system will ring the terminal sometimes it is useful to be able to print the original representation of the string
Definition: utils.cc:888
virtual void push_dispatch_class(const std::string &)
Definition: ov-fcn.h:115
void stash_package_name(const std::string &pack)
Definition: ov-fcn.h:124