GNU Octave  4.0.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ov-fcn.h
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 1996-2015 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 the
9 Free Software Foundation; either version 3 of the License, or (at your
10 option) any later version.
11 
12 Octave is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 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 <http://www.gnu.org/licenses/>.
20 
21 */
22 
23 #if !defined (octave_ov_fcn_h)
24 #define octave_ov_fcn_h 1
25 
26 #include <string>
27 
28 #include "oct-time.h"
29 #include "str-vec.h"
30 
31 #include "oct-obj.h"
32 #include "ov-base.h"
33 #include "ov-typeinfo.h"
34 #include "symtab.h"
35 
36 class tree_walker;
37 
38 // Functions.
39 
40 class
43 {
44 public:
45 
47  : relative (false), locked (false), private_function (false),
48  xdispatch_class (), xpackage_name (), my_name (), my_dir_name (),
49  doc () { }
50 
51  ~octave_function (void) { }
52 
53  octave_base_value *clone (void) const;
54  octave_base_value *empty_clone (void) const;
55 
56  bool is_defined (void) const { return true; }
57 
58  bool is_function (void) const { return true; }
59 
60  virtual bool is_system_fcn_file (void) const { return false; }
61 
62  virtual std::string fcn_file_name (void) const { return std::string (); }
63 
64  virtual std::string src_file_name (void) const { return std::string (); }
65 
66  // The name to show in the profiler (also used as map-key).
67  virtual std::string profiler_name (void) const { return name (); }
68 
69  virtual std::string parent_fcn_name (void) const { return std::string (); }
70 
71  virtual symbol_table::scope_id parent_fcn_scope (void) const { return -1; }
72 
73  virtual void mark_fcn_file_up_to_date (const octave_time&) { }
74 
75  virtual symbol_table::scope_id scope (void) { return -1; }
76 
77  virtual octave_time time_parsed (void) const
78  { return octave_time (static_cast<time_t> (0)); }
79 
80  virtual octave_time time_checked (void) const
81  { return octave_time (static_cast<time_t> (0)); }
82 
83  virtual bool is_subfunction (void) const { return false; }
84 
85  virtual bool is_class_constructor (const std::string& = std::string ()) const
86  { return false; }
87 
88  virtual bool
89  is_classdef_constructor (const std::string& = std::string ()) const
90  { return false; }
91 
92  virtual bool is_class_method (const std::string& = std::string ()) const
93  { return false; }
94 
95  virtual bool takes_varargs (void) const { return false; }
96 
97  virtual bool takes_var_return (void) const { return false; }
98 
99  void stash_dispatch_class (const std::string& nm) { xdispatch_class = nm; }
100 
101  std::string dispatch_class (void) const { return xdispatch_class; }
102 
103  void stash_package_name (const std::string& pack) { xpackage_name = pack; }
104 
105  std::string package_name (void) const { return xpackage_name; }
106 
107  virtual void
108  mark_as_private_function (const std::string& cname = std::string ())
109  {
110  private_function = true;
111  xdispatch_class = cname;
112  }
113 
114  bool is_private_function (void) const { return private_function; }
115 
116  bool is_private_function_of_class (const std::string& nm) const
117  { return private_function && xdispatch_class == nm; }
118 
119  virtual bool
120  is_anonymous_function_of_class (const std::string& = std::string ()) const
121  { return false; }
122 
123  std::string dir_name (void) const { return my_dir_name; }
124 
125  void stash_dir_name (const std::string& dir) { my_dir_name = dir; }
126 
127  void lock (void)
128  {
129  this->lock_subfunctions ();
130  locked = true;
131  }
132 
133  void unlock (void)
134  {
135  this->unlock_subfunctions ();
136  locked = false;
137  }
138 
139  bool islocked (void) const { return locked; }
140 
141  virtual void lock_subfunctions (void) { }
142 
143  virtual void unlock_subfunctions (void) { }
144 
145  virtual void maybe_relocate_end (void) { }
146 
147  // Not valid until after the function is completley parsed.
148  virtual bool has_subfunctions (void) const { return false; }
149 
150  virtual void stash_subfunction_names (const std::list<std::string>&) { }
151 
152  virtual std::list<std::string> subfunction_names (void) const
153  {
154  return std::list<std::string> ();
155  }
156 
157  void mark_relative (void) { relative = true; }
158 
159  bool is_relative (void) const { return relative; }
160 
161  std::string name (void) const { return my_name; }
162 
163  std::string canonical_name (void) const
164  {
165  if (xpackage_name.empty ())
166  return my_name;
167  else
168  return xpackage_name + "." + my_name;
169  }
170 
171  void document (const std::string& ds) { doc = ds; }
172 
173  std::string doc_string (void) const { return doc; }
174 
175  virtual void unload (void) { }
176 
177  virtual void accept (tree_walker&) { }
178 
179  virtual bool is_postfix_index_handled (char type) const
180  { return (type == '(' || type == '{'); }
181 
182 protected:
183 
184  octave_function (const std::string& nm,
185  const std::string& ds = std::string ())
186  : relative (false), locked (false), private_function (false),
187  xdispatch_class (), my_name (nm), my_dir_name (), doc (ds) { }
188 
189  // TRUE if this function was found from a relative path element.
190  bool relative;
191 
192  // TRUE if this function is tagged so that it can't be cleared.
193  bool locked;
194 
195  // TRUE means this is a private function.
197 
198  // If this object is a class method or constructor, or a private
199  // function inside a class directory, this is the name of the class
200  // to which the method belongs.
201  std::string xdispatch_class;
202 
203  // If this function is part of a package, this is the full name
204  // of the package to which the function belongs.
205  std::string xpackage_name;
206 
207  // The name of this function.
208  std::string my_name;
209 
210  // The name of the directory in the path where we found this
211  // function. May be relative.
212  std::string my_dir_name;
213 
214  // The help text for this function.
215  std::string doc;
216 
217 private:
218 
219  // No copying!
220 
222 
224 
225 };
226 
227 #endif
virtual void mark_fcn_file_up_to_date(const octave_time &)
Definition: ov-fcn.h:73
std::string my_name
Definition: ov-fcn.h:208
bool is_relative(void) const
Definition: ov-fcn.h:159
virtual octave_time time_checked(void) const
Definition: ov-fcn.h:80
void document(const std::string &ds)
Definition: ov-fcn.h:171
virtual bool is_postfix_index_handled(char type) const
Definition: ov-fcn.h:179
virtual void stash_subfunction_names(const std::list< std::string > &)
Definition: ov-fcn.h:150
void lock(void)
Definition: ov-fcn.h:127
virtual void unlock_subfunctions(void)
Definition: ov-fcn.h:143
octave_function(const std::string &nm, const std::string &ds=std::string())
Definition: ov-fcn.h:184
virtual void unload(void)
Definition: ov-fcn.h:175
std::string doc
Definition: ov-fcn.h:215
std::string xdispatch_class
Definition: ov-fcn.h:201
std::string doc_string(void) const
Definition: ov-fcn.h:173
void mark_relative(void)
Definition: ov-fcn.h:157
std::string name(void) const
Definition: ov-fcn.h:161
virtual bool is_anonymous_function_of_class(const std::string &=std::string()) const
Definition: ov-fcn.h:120
virtual std::string src_file_name(void) const
Definition: ov-fcn.h:64
void stash_dir_name(const std::string &dir)
Definition: ov-fcn.h:125
virtual bool takes_var_return(void) const
Definition: ov-fcn.h:97
bool relative
Definition: ov-fcn.h:190
bool is_private_function_of_class(const std::string &nm) const
Definition: ov-fcn.h:116
std::string dispatch_class(void) const
Definition: ov-fcn.h:101
virtual symbol_table::scope_id scope(void)
Definition: ov-fcn.h:75
virtual bool is_class_method(const std::string &=std::string()) const
Definition: ov-fcn.h:92
bool is_function(void) const
Definition: ov-fcn.h:58
virtual bool is_classdef_constructor(const std::string &=std::string()) const
Definition: ov-fcn.h:89
bool private_function
Definition: ov-fcn.h:196
F77_RET_T const double const double * f
#define OCTINTERP_API
Definition: mexproto.h:66
virtual bool has_subfunctions(void) const
Definition: ov-fcn.h:148
std::string package_name(void) const
Definition: ov-fcn.h:105
virtual symbol_table::scope_id parent_fcn_scope(void) const
Definition: ov-fcn.h:71
bool is_private_function(void) const
Definition: ov-fcn.h:114
virtual std::list< std::string > subfunction_names(void) const
Definition: ov-fcn.h:152
octave_function(void)
Definition: ov-fcn.h:46
std::string my_dir_name
Definition: ov-fcn.h:212
virtual void maybe_relocate_end(void)
Definition: ov-fcn.h:145
std::string canonical_name(void) const
Definition: ov-fcn.h:163
void unlock(void)
Definition: ov-fcn.h:133
std::string dir_name(void) const
Definition: ov-fcn.h:123
virtual std::string parent_fcn_name(void) const
Definition: ov-fcn.h:69
virtual std::string profiler_name(void) const
Definition: ov-fcn.h:67
virtual void lock_subfunctions(void)
Definition: ov-fcn.h:141
virtual bool is_system_fcn_file(void) const
Definition: ov-fcn.h:60
virtual std::string fcn_file_name(void) const
Definition: ov-fcn.h:62
~octave_function(void)
Definition: ov-fcn.h:51
virtual bool is_subfunction(void) const
Definition: ov-fcn.h:83
void stash_dispatch_class(const std::string &nm)
Definition: ov-fcn.h:99
virtual octave_time time_parsed(void) const
Definition: ov-fcn.h:77
virtual bool is_class_constructor(const std::string &=std::string()) const
Definition: ov-fcn.h:85
virtual void accept(tree_walker &)
Definition: ov-fcn.h:177
std::string xpackage_name
Definition: ov-fcn.h:205
virtual bool takes_varargs(void) const
Definition: ov-fcn.h:95
virtual void mark_as_private_function(const std::string &cname=std::string())
Definition: ov-fcn.h:108
tree_walker & operator=(const tree_walker &)
bool islocked(void) const
Definition: ov-fcn.h:139
void stash_package_name(const std::string &pack)
Definition: ov-fcn.h:103
bool is_defined(void) const
Definition: ov-fcn.h:56