Mercurial > hg > octave-nkf
annotate src/ov-fcn.h @ 14923:168cb10bb9c5
If, ifelse, and else statements JIT compile now
author | Max Brister <max@2bass.com> |
---|---|
date | Mon, 28 May 2012 23:19:41 -0500 |
parents | 72c96de7a403 |
children | 74c7265c057a |
rev | line source |
---|---|
2974 | 1 /* |
2 | |
14138
72c96de7a403
maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents:
13241
diff
changeset
|
3 Copyright (C) 1996-2012 John W. Eaton |
2974 | 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 | |
7016 | 9 Free Software Foundation; either version 3 of the License, or (at your |
10 option) any later version. | |
2974 | 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 | |
7016 | 18 along with Octave; see the file COPYING. If not, see |
19 <http://www.gnu.org/licenses/>. | |
2974 | 20 |
21 */ | |
22 | |
23 #if !defined (octave_function_h) | |
24 #define octave_function_h 1 | |
25 | |
26 #include <string> | |
27 | |
3258 | 28 #include "oct-time.h" |
3325 | 29 #include "str-vec.h" |
3258 | 30 |
2974 | 31 #include "oct-alloc.h" |
4748 | 32 #include "oct-obj.h" |
2974 | 33 #include "ov-base.h" |
34 #include "ov-typeinfo.h" | |
7336 | 35 #include "symtab.h" |
2974 | 36 |
2976 | 37 class tree_walker; |
38 | |
2974 | 39 // Functions. |
40 | |
41 class | |
6109 | 42 OCTINTERP_API |
2974 | 43 octave_function : public octave_base_value |
44 { | |
45 public: | |
46 | |
8785
70f5a0375afd
oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents:
7968
diff
changeset
|
47 octave_function (void) |
70f5a0375afd
oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents:
7968
diff
changeset
|
48 : relative (false), locked (false), private_function (false), |
70f5a0375afd
oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents:
7968
diff
changeset
|
49 xdispatch_class (), my_name (), my_dir_name (), doc () { } |
2974 | 50 |
51 ~octave_function (void) { } | |
52 | |
5759 | 53 octave_base_value *clone (void) const; |
54 octave_base_value *empty_clone (void) const; | |
2974 | 55 |
56 bool is_defined (void) const { return true; } | |
57 | |
58 bool is_function (void) const { return true; } | |
59 | |
3544 | 60 virtual bool is_system_fcn_file (void) const { return false; } |
2974 | 61 |
3523 | 62 virtual std::string fcn_file_name (void) const { return std::string (); } |
13141
e81ddf9cacd5
maint: untabify and remove trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
12783
diff
changeset
|
63 |
12783
ad9263d965dc
First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
11586
diff
changeset
|
64 // The name to show in the profiler (also used as map-key). |
ad9263d965dc
First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
11586
diff
changeset
|
65 virtual std::string profiler_name (void) const { return name (); } |
2974 | 66 |
6323 | 67 virtual std::string parent_fcn_name (void) const { return std::string (); } |
68 | |
7968
0d607e8dbbfa
eliminate curr_parent_function; fix subfunction lookup
John W. Eaton <jwe@octave.org>
parents:
7761
diff
changeset
|
69 virtual symbol_table::scope_id parent_fcn_scope (void) const { return -1; } |
0d607e8dbbfa
eliminate curr_parent_function; fix subfunction lookup
John W. Eaton <jwe@octave.org>
parents:
7761
diff
changeset
|
70 |
3255 | 71 virtual void mark_fcn_file_up_to_date (const octave_time&) { } |
3166 | 72 |
7336 | 73 virtual symbol_table::scope_id scope (void) { return -1; } |
74 | |
3255 | 75 virtual octave_time time_parsed (void) const |
76 { return octave_time (static_cast<time_t> (0)); } | |
2974 | 77 |
3255 | 78 virtual octave_time time_checked (void) const |
79 { return octave_time (static_cast<time_t> (0)); } | |
3166 | 80 |
11461
2b8531a6a3c9
Change mentions of "nested function" to the less misleading "subfunction"
David Grundberg <individ@acc.umu.se>
parents:
11445
diff
changeset
|
81 virtual bool is_subfunction (void) const { return false; } |
4343 | 82 |
11220
883b9308353c
allow class function to be called from methods as well as constructors
John W. Eaton <jwe@octave.org>
parents:
10313
diff
changeset
|
83 virtual bool is_class_constructor (const std::string& = std::string ()) const |
883b9308353c
allow class function to be called from methods as well as constructors
John W. Eaton <jwe@octave.org>
parents:
10313
diff
changeset
|
84 { return false; } |
5744 | 85 |
11220
883b9308353c
allow class function to be called from methods as well as constructors
John W. Eaton <jwe@octave.org>
parents:
10313
diff
changeset
|
86 virtual bool is_class_method (const std::string& = std::string ()) const |
883b9308353c
allow class function to be called from methods as well as constructors
John W. Eaton <jwe@octave.org>
parents:
10313
diff
changeset
|
87 { return false; } |
7336 | 88 |
4748 | 89 virtual bool takes_varargs (void) const { return false; } |
90 | |
91 virtual bool takes_var_return (void) const { return false; } | |
92 | |
8785
70f5a0375afd
oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents:
7968
diff
changeset
|
93 void stash_dispatch_class (const std::string& nm) { xdispatch_class = nm; } |
70f5a0375afd
oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents:
7968
diff
changeset
|
94 |
70f5a0375afd
oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents:
7968
diff
changeset
|
95 std::string dispatch_class (void) const { return xdispatch_class; } |
70f5a0375afd
oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents:
7968
diff
changeset
|
96 |
11445
40f311a69417
fix OO field access in subfunctions of private functions
John W. Eaton <jwe@octave.org>
parents:
11220
diff
changeset
|
97 virtual void |
40f311a69417
fix OO field access in subfunctions of private functions
John W. Eaton <jwe@octave.org>
parents:
11220
diff
changeset
|
98 mark_as_private_function (const std::string& cname = std::string ()) |
8785
70f5a0375afd
oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents:
7968
diff
changeset
|
99 { |
70f5a0375afd
oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents:
7968
diff
changeset
|
100 private_function = true; |
70f5a0375afd
oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents:
7968
diff
changeset
|
101 xdispatch_class = cname; |
70f5a0375afd
oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents:
7968
diff
changeset
|
102 } |
70f5a0375afd
oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents:
7968
diff
changeset
|
103 |
70f5a0375afd
oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents:
7968
diff
changeset
|
104 bool is_private_function (void) const { return private_function; } |
70f5a0375afd
oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents:
7968
diff
changeset
|
105 |
13241
2a8dcb5b3a00
improve default indexing for objects
John W. Eaton <jwe@octave.org>
parents:
13141
diff
changeset
|
106 bool is_private_function_of_class (const std::string& nm) const |
8785
70f5a0375afd
oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents:
7968
diff
changeset
|
107 { return private_function && xdispatch_class == nm; } |
70f5a0375afd
oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents:
7968
diff
changeset
|
108 |
13241
2a8dcb5b3a00
improve default indexing for objects
John W. Eaton <jwe@octave.org>
parents:
13141
diff
changeset
|
109 virtual bool |
2a8dcb5b3a00
improve default indexing for objects
John W. Eaton <jwe@octave.org>
parents:
13141
diff
changeset
|
110 is_anonymous_function_of_class (const std::string& = std::string ()) const |
2a8dcb5b3a00
improve default indexing for objects
John W. Eaton <jwe@octave.org>
parents:
13141
diff
changeset
|
111 { return false; } |
2a8dcb5b3a00
improve default indexing for objects
John W. Eaton <jwe@octave.org>
parents:
13141
diff
changeset
|
112 |
7336 | 113 std::string dir_name (void) const { return my_dir_name; } |
114 | |
115 void stash_dir_name (const std::string& dir) { my_dir_name = dir; } | |
116 | |
7761
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
117 void lock (void) |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
118 { |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
119 this->lock_subfunctions (); |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
120 locked = true; |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
121 } |
7336 | 122 |
7761
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
123 void unlock (void) |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
124 { |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
125 this->unlock_subfunctions (); |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
126 locked = false; |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
127 } |
7336 | 128 |
7489
8e4592e49fa7
don't clear locked functions
John W. Eaton <jwe@octave.org>
parents:
7438
diff
changeset
|
129 bool islocked (void) const { return locked; } |
7336 | 130 |
7761
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
131 virtual void lock_subfunctions (void) { } |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
132 |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
133 virtual void unlock_subfunctions (void) { } |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7489
diff
changeset
|
134 |
6323 | 135 void mark_relative (void) { relative = true; } |
136 | |
137 bool is_relative (void) const { return relative; } | |
138 | |
3523 | 139 std::string name (void) const { return my_name; } |
2974 | 140 |
5823 | 141 void document (const std::string& ds) { doc = ds; } |
142 | |
3523 | 143 std::string doc_string (void) const { return doc; } |
2974 | 144 |
3325 | 145 virtual void unload (void) { } |
146 | |
2976 | 147 virtual void accept (tree_walker&) { } |
148 | |
2974 | 149 protected: |
150 | |
5864 | 151 octave_function (const std::string& nm, |
10313 | 152 const std::string& ds = std::string ()) |
10101
b51848e95e4b
cleanups to avoid valgrind warnings
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
153 : relative (false), locked (false), private_function (false), |
b51848e95e4b
cleanups to avoid valgrind warnings
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
154 xdispatch_class (), my_name (nm), my_dir_name (), doc (ds) { } |
6323 | 155 |
156 // TRUE if this function was found from a relative path element. | |
157 bool relative; | |
2974 | 158 |
7336 | 159 // TRUE if this function is tagged so that it can't be cleared. |
160 bool locked; | |
161 | |
8785
70f5a0375afd
oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents:
7968
diff
changeset
|
162 // TRUE means this is a private function. |
70f5a0375afd
oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents:
7968
diff
changeset
|
163 bool private_function; |
70f5a0375afd
oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents:
7968
diff
changeset
|
164 |
70f5a0375afd
oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents:
7968
diff
changeset
|
165 // If this object is a class method or constructor, or a private |
70f5a0375afd
oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents:
7968
diff
changeset
|
166 // function inside a class directory, this is the name of the class |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
167 // to which the method belongs. |
8785
70f5a0375afd
oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents:
7968
diff
changeset
|
168 std::string xdispatch_class; |
70f5a0375afd
oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents:
7968
diff
changeset
|
169 |
2974 | 170 // The name of this function. |
3523 | 171 std::string my_name; |
2974 | 172 |
7336 | 173 // The name of the directory in the path where we found this |
174 // function. May be relative. | |
175 std::string my_dir_name; | |
176 | |
2974 | 177 // The help text for this function. |
3523 | 178 std::string doc; |
2974 | 179 |
3325 | 180 private: |
181 | |
4645 | 182 // No copying! |
183 | |
184 octave_function (const octave_function& f); | |
185 | |
186 octave_function& operator = (const octave_function& f); | |
187 | |
3219 | 188 DECLARE_OCTAVE_ALLOCATOR |
2974 | 189 }; |
190 | |
191 #endif |