GNU Octave  3.8.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-2013 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-alloc.h"
32 #include "oct-obj.h"
33 #include "ov-base.h"
34 #include "ov-typeinfo.h"
35 #include "symtab.h"
36 
37 class tree_walker;
38 
39 // Functions.
40 
41 class
44 {
45 public:
46 
48  : relative (false), locked (false), private_function (false),
49  xdispatch_class (), my_name (), my_dir_name (), 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 is_class_method (const std::string& = std::string ()) const
89  { return false; }
90 
91  virtual bool takes_varargs (void) const { return false; }
92 
93  virtual bool takes_var_return (void) const { return false; }
94 
95  void stash_dispatch_class (const std::string& nm) { xdispatch_class = nm; }
96 
97  std::string dispatch_class (void) const { return xdispatch_class; }
98 
99  virtual void
100  mark_as_private_function (const std::string& cname = std::string ())
101  {
102  private_function = true;
103  xdispatch_class = cname;
104  }
105 
106  bool is_private_function (void) const { return private_function; }
107 
108  bool is_private_function_of_class (const std::string& nm) const
109  { return private_function && xdispatch_class == nm; }
110 
111  virtual bool
112  is_anonymous_function_of_class (const std::string& = std::string ()) const
113  { return false; }
114 
115  std::string dir_name (void) const { return my_dir_name; }
116 
117  void stash_dir_name (const std::string& dir) { my_dir_name = dir; }
118 
119  void lock (void)
120  {
121  this->lock_subfunctions ();
122  locked = true;
123  }
124 
125  void unlock (void)
126  {
127  this->unlock_subfunctions ();
128  locked = false;
129  }
130 
131  bool islocked (void) const { return locked; }
132 
133  virtual void lock_subfunctions (void) { }
134 
135  virtual void unlock_subfunctions (void) { }
136 
137  virtual void maybe_relocate_end (void) { }
138 
139  // Not valid until after the function is completley parsed.
140  virtual bool has_subfunctions (void) const { return false; }
141 
142  virtual void stash_subfunction_names (const std::list<std::string>&) { }
143 
144  virtual std::list<std::string> subfunction_names (void) const
145  {
146  return std::list<std::string> ();
147  }
148 
149  void mark_relative (void) { relative = true; }
150 
151  bool is_relative (void) const { return relative; }
152 
153  std::string name (void) const { return my_name; }
154 
155  void document (const std::string& ds) { doc = ds; }
156 
157  std::string doc_string (void) const { return doc; }
158 
159  virtual void unload (void) { }
160 
161  virtual void accept (tree_walker&) { }
162 
163 protected:
164 
165  octave_function (const std::string& nm,
166  const std::string& ds = std::string ())
167  : relative (false), locked (false), private_function (false),
168  xdispatch_class (), my_name (nm), my_dir_name (), doc (ds) { }
169 
170  // TRUE if this function was found from a relative path element.
171  bool relative;
172 
173  // TRUE if this function is tagged so that it can't be cleared.
174  bool locked;
175 
176  // TRUE means this is a private function.
178 
179  // If this object is a class method or constructor, or a private
180  // function inside a class directory, this is the name of the class
181  // to which the method belongs.
182  std::string xdispatch_class;
183 
184  // The name of this function.
185  std::string my_name;
186 
187  // The name of the directory in the path where we found this
188  // function. May be relative.
189  std::string my_dir_name;
190 
191  // The help text for this function.
192  std::string doc;
193 
194 private:
195 
196  // No copying!
197 
199 
201 
203 };
204 
205 #endif