Mercurial > hg > octave-nkf
annotate src/ov-usr-fcn.h @ 7968:0d607e8dbbfa
eliminate curr_parent_function; fix subfunction lookup
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Wed, 23 Jul 2008 17:16:50 -0400 |
parents | 8447a5024650 |
children | 3100283874d7 |
rev | line source |
---|---|
2974 | 1 /* |
2 | |
7017 | 3 Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, |
4 2005, 2006, 2007 John W. Eaton | |
2974 | 5 |
6 This file is part of Octave. | |
7 | |
8 Octave is free software; you can redistribute it and/or modify it | |
9 under the terms of the GNU General Public License as published by the | |
7016 | 10 Free Software Foundation; either version 3 of the License, or (at your |
11 option) any later version. | |
2974 | 12 |
13 Octave is distributed in the hope that it will be useful, but WITHOUT | |
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
16 for more details. | |
17 | |
18 You should have received a copy of the GNU General Public License | |
7016 | 19 along with Octave; see the file COPYING. If not, see |
20 <http://www.gnu.org/licenses/>. | |
2974 | 21 |
22 */ | |
23 | |
24 #if !defined (octave_user_function_h) | |
25 #define octave_user_function_h 1 | |
26 | |
27 #include <ctime> | |
28 | |
29 #include <string> | |
4214 | 30 #include <stack> |
2974 | 31 |
3665 | 32 #include "comment-list.h" |
2974 | 33 #include "oct-obj.h" |
34 #include "ov-fcn.h" | |
35 #include "ov-typeinfo.h" | |
7336 | 36 #include "symtab.h" |
2974 | 37 |
38 class string_vector; | |
39 | |
40 class octave_value; | |
41 class tree_parameter_list; | |
42 class tree_statement_list; | |
43 class tree_va_return_list; | |
44 class tree_walker; | |
45 | |
7719
87eda1f8faaa
octave_user_code: new base class for octave_user_script and octave_user_function
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
46 class |
87eda1f8faaa
octave_user_code: new base class for octave_user_script and octave_user_function
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
47 octave_user_code : public octave_function |
87eda1f8faaa
octave_user_code: new base class for octave_user_script and octave_user_function
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
48 { |
87eda1f8faaa
octave_user_code: new base class for octave_user_script and octave_user_function
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
49 public: |
87eda1f8faaa
octave_user_code: new base class for octave_user_script and octave_user_function
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
50 octave_user_code (void) |
87eda1f8faaa
octave_user_code: new base class for octave_user_script and octave_user_function
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
51 : octave_function () { } |
87eda1f8faaa
octave_user_code: new base class for octave_user_script and octave_user_function
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
52 |
87eda1f8faaa
octave_user_code: new base class for octave_user_script and octave_user_function
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
53 ~octave_user_code (void) { } |
87eda1f8faaa
octave_user_code: new base class for octave_user_script and octave_user_function
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
54 |
87eda1f8faaa
octave_user_code: new base class for octave_user_script and octave_user_function
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
55 bool is_user_code (void) const { return true; } |
87eda1f8faaa
octave_user_code: new base class for octave_user_script and octave_user_function
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
56 |
87eda1f8faaa
octave_user_code: new base class for octave_user_script and octave_user_function
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
57 virtual tree_statement_list *body (void) = 0; |
87eda1f8faaa
octave_user_code: new base class for octave_user_script and octave_user_function
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
58 |
87eda1f8faaa
octave_user_code: new base class for octave_user_script and octave_user_function
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
59 protected: |
87eda1f8faaa
octave_user_code: new base class for octave_user_script and octave_user_function
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
60 |
87eda1f8faaa
octave_user_code: new base class for octave_user_script and octave_user_function
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
61 octave_user_code (const std::string& nm, |
87eda1f8faaa
octave_user_code: new base class for octave_user_script and octave_user_function
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
62 const std::string& ds = std::string ()) |
87eda1f8faaa
octave_user_code: new base class for octave_user_script and octave_user_function
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
63 : octave_function (nm, ds) { } |
87eda1f8faaa
octave_user_code: new base class for octave_user_script and octave_user_function
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
64 |
87eda1f8faaa
octave_user_code: new base class for octave_user_script and octave_user_function
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
65 private: |
87eda1f8faaa
octave_user_code: new base class for octave_user_script and octave_user_function
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
66 |
87eda1f8faaa
octave_user_code: new base class for octave_user_script and octave_user_function
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
67 // No copying! |
87eda1f8faaa
octave_user_code: new base class for octave_user_script and octave_user_function
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
68 |
87eda1f8faaa
octave_user_code: new base class for octave_user_script and octave_user_function
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
69 octave_user_code (const octave_user_code& f); |
87eda1f8faaa
octave_user_code: new base class for octave_user_script and octave_user_function
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
70 |
87eda1f8faaa
octave_user_code: new base class for octave_user_script and octave_user_function
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
71 octave_user_code& operator = (const octave_user_code& f); |
87eda1f8faaa
octave_user_code: new base class for octave_user_script and octave_user_function
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
72 }; |
87eda1f8faaa
octave_user_code: new base class for octave_user_script and octave_user_function
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
73 |
5744 | 74 // Scripts. |
75 | |
76 class | |
7719
87eda1f8faaa
octave_user_code: new base class for octave_user_script and octave_user_function
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
77 octave_user_script : public octave_user_code |
5744 | 78 { |
79 public: | |
80 | |
7731
2d2a969c731c
fix max_recursion_limit exceeded at startup with Intel C++
Jaroslav Hajek <highegg@gmail.com>
parents:
7719
diff
changeset
|
81 octave_user_script (void); |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7651
diff
changeset
|
82 |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7651
diff
changeset
|
83 octave_user_script (const std::string& fnm, const std::string& nm, |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7651
diff
changeset
|
84 tree_statement_list *cmds, |
7731
2d2a969c731c
fix max_recursion_limit exceeded at startup with Intel C++
Jaroslav Hajek <highegg@gmail.com>
parents:
7719
diff
changeset
|
85 const std::string& ds = std::string ()); |
5744 | 86 |
87 octave_user_script (const std::string& fnm, const std::string& nm, | |
7731
2d2a969c731c
fix max_recursion_limit exceeded at startup with Intel C++
Jaroslav Hajek <highegg@gmail.com>
parents:
7719
diff
changeset
|
88 const std::string& ds = std::string ()); |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7651
diff
changeset
|
89 |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7651
diff
changeset
|
90 ~octave_user_script (void); |
5744 | 91 |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7651
diff
changeset
|
92 octave_function *function_value (bool = false) { return this; } |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7651
diff
changeset
|
93 |
7761
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
94 const octave_function *function_value (bool = false) const { return this; } |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
95 |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7651
diff
changeset
|
96 octave_user_script *user_script_value (bool = false) { return this; } |
5744 | 97 |
7719
87eda1f8faaa
octave_user_code: new base class for octave_user_script and octave_user_function
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
98 octave_user_code *user_code_value (bool = false) { return this; } |
87eda1f8faaa
octave_user_code: new base class for octave_user_script and octave_user_function
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
99 |
5744 | 100 // Scripts and user functions are both considered "scripts" because |
101 // they are written in Octave's scripting language. | |
102 | |
103 bool is_user_script (void) const { return true; } | |
104 | |
105 void stash_fcn_file_name (const std::string& nm) { file_name = nm; } | |
106 | |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7651
diff
changeset
|
107 void mark_fcn_file_up_to_date (const octave_time& t) { t_checked = t; } |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7651
diff
changeset
|
108 |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7651
diff
changeset
|
109 void stash_fcn_file_time (const octave_time& t) |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7651
diff
changeset
|
110 { |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7651
diff
changeset
|
111 t_parsed = t; |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7651
diff
changeset
|
112 mark_fcn_file_up_to_date (t); |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7651
diff
changeset
|
113 } |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7651
diff
changeset
|
114 |
5744 | 115 std::string fcn_file_name (void) const { return file_name; } |
116 | |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7651
diff
changeset
|
117 octave_time time_parsed (void) const { return t_parsed; } |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7651
diff
changeset
|
118 |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7651
diff
changeset
|
119 octave_time time_checked (void) const { return t_checked; } |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7651
diff
changeset
|
120 |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7651
diff
changeset
|
121 octave_value subsref (const std::string& type, |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7651
diff
changeset
|
122 const std::list<octave_value_list>& idx) |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7651
diff
changeset
|
123 { |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7651
diff
changeset
|
124 octave_value_list tmp = subsref (type, idx, 1); |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7651
diff
changeset
|
125 return tmp.length () > 0 ? tmp(0) : octave_value (); |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7651
diff
changeset
|
126 } |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7651
diff
changeset
|
127 |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7651
diff
changeset
|
128 octave_value_list subsref (const std::string& type, |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7651
diff
changeset
|
129 const std::list<octave_value_list>& idx, |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7651
diff
changeset
|
130 int nargout); |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7651
diff
changeset
|
131 |
7336 | 132 octave_value_list |
133 do_multi_index_op (int nargout, const octave_value_list& args); | |
134 | |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7651
diff
changeset
|
135 tree_statement_list *body (void) { return cmd_list; } |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7651
diff
changeset
|
136 |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7651
diff
changeset
|
137 void traceback_error (void) const; |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7651
diff
changeset
|
138 |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7651
diff
changeset
|
139 void accept (tree_walker& tw); |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7651
diff
changeset
|
140 |
5744 | 141 private: |
142 | |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7651
diff
changeset
|
143 // The list of commands that make up the body of this function. |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7651
diff
changeset
|
144 tree_statement_list *cmd_list; |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7651
diff
changeset
|
145 |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7651
diff
changeset
|
146 // The name of the file we parsed. |
5744 | 147 std::string file_name; |
148 | |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7651
diff
changeset
|
149 // The time the file was parsed. |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7651
diff
changeset
|
150 octave_time t_parsed; |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7651
diff
changeset
|
151 |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7651
diff
changeset
|
152 // The time the file was last checked to see if it needs to be |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7651
diff
changeset
|
153 // parsed again. |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7651
diff
changeset
|
154 octave_time t_checked; |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7651
diff
changeset
|
155 |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7651
diff
changeset
|
156 // Used to keep track of recursion depth. |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7651
diff
changeset
|
157 int call_depth; |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7651
diff
changeset
|
158 |
5744 | 159 // No copying! |
160 | |
161 octave_user_script (const octave_user_script& f); | |
162 | |
163 octave_user_script& operator = (const octave_user_script& f); | |
164 | |
165 DECLARE_OCTAVE_ALLOCATOR | |
166 | |
167 DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA | |
168 }; | |
169 | |
170 // User-defined functions. | |
2974 | 171 |
172 class | |
7719
87eda1f8faaa
octave_user_code: new base class for octave_user_script and octave_user_function
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
173 octave_user_function : public octave_user_code |
2974 | 174 { |
175 public: | |
176 | |
7336 | 177 octave_user_function (symbol_table::scope_id sid = -1, |
178 tree_parameter_list *pl = 0, | |
2974 | 179 tree_parameter_list *rl = 0, |
7336 | 180 tree_statement_list *cl = 0); |
2974 | 181 |
182 ~octave_user_function (void); | |
183 | |
4654 | 184 octave_function *function_value (bool = false) { return this; } |
2974 | 185 |
7761
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
186 const octave_function *function_value (bool = false) const { return this; } |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
187 |
4700 | 188 octave_user_function *user_function_value (bool = false) { return this; } |
189 | |
7719
87eda1f8faaa
octave_user_code: new base class for octave_user_script and octave_user_function
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
190 octave_user_code *user_code_value (bool = false) { return this; } |
87eda1f8faaa
octave_user_code: new base class for octave_user_script and octave_user_function
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
191 |
2974 | 192 octave_user_function *define_param_list (tree_parameter_list *t); |
193 | |
194 octave_user_function *define_ret_list (tree_parameter_list *t); | |
195 | |
4343 | 196 void stash_fcn_file_name (const std::string& nm); |
2974 | 197 |
6323 | 198 void stash_parent_fcn_name (const std::string& p) { parent_name = p; } |
199 | |
7968
0d607e8dbbfa
eliminate curr_parent_function; fix subfunction lookup
John W. Eaton <jwe@octave.org>
parents:
7876
diff
changeset
|
200 void stash_parent_fcn_scope (symbol_table::scope_id ps) { parent_scope = ps; } |
0d607e8dbbfa
eliminate curr_parent_function; fix subfunction lookup
John W. Eaton <jwe@octave.org>
parents:
7876
diff
changeset
|
201 |
3665 | 202 void stash_leading_comment (octave_comment_list *lc) { lead_comm = lc; } |
203 | |
204 void stash_trailing_comment (octave_comment_list *tc) { trail_comm = tc; } | |
205 | |
3325 | 206 void mark_fcn_file_up_to_date (const octave_time& t) { t_checked = t; } |
3165 | 207 |
3255 | 208 void stash_fcn_file_time (const octave_time& t) |
3165 | 209 { |
210 t_parsed = t; | |
211 mark_fcn_file_up_to_date (t); | |
212 } | |
2974 | 213 |
4346 | 214 std::string fcn_file_name (void) const { return file_name; } |
2974 | 215 |
6323 | 216 std::string parent_fcn_name (void) const { return parent_name; } |
217 | |
7968
0d607e8dbbfa
eliminate curr_parent_function; fix subfunction lookup
John W. Eaton <jwe@octave.org>
parents:
7876
diff
changeset
|
218 symbol_table::scope_id parent_fcn_scope (void) const { return parent_scope; } |
0d607e8dbbfa
eliminate curr_parent_function; fix subfunction lookup
John W. Eaton <jwe@octave.org>
parents:
7876
diff
changeset
|
219 |
7336 | 220 symbol_table::scope_id scope (void) { return local_scope; } |
221 | |
4346 | 222 octave_time time_parsed (void) const { return t_parsed; } |
2974 | 223 |
4346 | 224 octave_time time_checked (void) const { return t_checked; } |
3165 | 225 |
2974 | 226 void mark_as_system_fcn_file (void); |
227 | |
4346 | 228 bool is_system_fcn_file (void) const { return system_fcn_file; } |
2974 | 229 |
4748 | 230 bool is_user_function (void) const { return true; } |
231 | |
7876
8447a5024650
clear subfunctions when clearing parent function
John W. Eaton <jwe@octave.org>
parents:
7761
diff
changeset
|
232 void erase_subfunctions (void) |
8447a5024650
clear subfunctions when clearing parent function
John W. Eaton <jwe@octave.org>
parents:
7761
diff
changeset
|
233 { |
8447a5024650
clear subfunctions when clearing parent function
John W. Eaton <jwe@octave.org>
parents:
7761
diff
changeset
|
234 symbol_table::erase_subfunctions_in_scope (local_scope); |
8447a5024650
clear subfunctions when clearing parent function
John W. Eaton <jwe@octave.org>
parents:
7761
diff
changeset
|
235 } |
8447a5024650
clear subfunctions when clearing parent function
John W. Eaton <jwe@octave.org>
parents:
7761
diff
changeset
|
236 |
2974 | 237 bool takes_varargs (void) const; |
238 | |
5848 | 239 bool takes_var_return (void) const; |
2974 | 240 |
7761
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
241 void lock_subfunctions (void); |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
242 |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
243 void unlock_subfunctions (void); |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
244 |
2974 | 245 octave_value_list octave_all_va_args (void); |
246 | |
4748 | 247 void stash_function_name (const std::string& s) { my_name = s; } |
2974 | 248 |
4238 | 249 void mark_as_nested_function (void) { nested_function = true; } |
250 | |
251 bool is_nested_function (void) const { return nested_function; } | |
252 | |
6149 | 253 void mark_as_inline_function (void) { inline_function = true; } |
254 | |
255 bool is_inline_function (void) const { return inline_function; } | |
256 | |
7336 | 257 void mark_as_class_constructor (void) { class_constructor = true; } |
258 | |
259 bool is_class_constructor (void) const { return class_constructor; } | |
260 | |
261 void mark_as_class_method (void) { class_method = true; } | |
262 | |
263 bool is_class_method (void) const { return class_method; } | |
264 | |
265 void stash_dispatch_class (const std::string& nm) { xdispatch_class = nm; } | |
266 | |
267 std::string dispatch_class (void) const { return xdispatch_class; } | |
268 | |
3875 | 269 void save_args_passed (const octave_value_list& args) |
270 { | |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7731
diff
changeset
|
271 if (call_depth > 0) |
3875 | 272 saved_args.push (args_passed); |
273 | |
274 args_passed = args; | |
275 } | |
276 | |
277 void restore_args_passed (void) | |
278 { | |
3933 | 279 if (saved_args.empty ()) |
280 args_passed = octave_value_list (); | |
281 else | |
4214 | 282 { |
283 args_passed = saved_args.top (); | |
284 saved_args.pop (); | |
285 } | |
3875 | 286 } |
3239 | 287 |
7651
443a8f5a50fd
require both subsref variants to be defined in octave_value subclasses
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
288 octave_value subsref (const std::string& type, |
443a8f5a50fd
require both subsref variants to be defined in octave_value subclasses
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
289 const std::list<octave_value_list>& idx) |
4271 | 290 { |
7651
443a8f5a50fd
require both subsref variants to be defined in octave_value subclasses
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
291 octave_value_list tmp = subsref (type, idx, 1); |
443a8f5a50fd
require both subsref variants to be defined in octave_value subclasses
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
292 return tmp.length () > 0 ? tmp(0) : octave_value (); |
4271 | 293 } |
294 | |
4247 | 295 octave_value_list subsref (const std::string& type, |
4219 | 296 const std::list<octave_value_list>& idx, |
3933 | 297 int nargout); |
298 | |
3544 | 299 octave_value_list |
300 do_multi_index_op (int nargout, const octave_value_list& args); | |
2974 | 301 |
4346 | 302 void traceback_error (void) const; |
2974 | 303 |
304 tree_parameter_list *parameter_list (void) { return param_list; } | |
305 | |
306 tree_parameter_list *return_list (void) { return ret_list; } | |
307 | |
308 tree_statement_list *body (void) { return cmd_list; } | |
309 | |
3665 | 310 octave_comment_list *leading_comment (void) { return lead_comm; } |
311 | |
312 octave_comment_list *trailing_comment (void) { return trail_comm; } | |
313 | |
2974 | 314 void accept (tree_walker& tw); |
315 | |
7336 | 316 #if 0 |
3933 | 317 void print_symtab_info (std::ostream& os) const; |
7336 | 318 #endif |
3933 | 319 |
2974 | 320 private: |
321 | |
322 // List of arguments for this function. These are local variables. | |
323 tree_parameter_list *param_list; | |
324 | |
325 // List of parameters we return. These are also local variables in | |
326 // this function. | |
327 tree_parameter_list *ret_list; | |
328 | |
329 // The list of commands that make up the body of this function. | |
330 tree_statement_list *cmd_list; | |
331 | |
3665 | 332 // The comments preceding the FUNCTION token. |
333 octave_comment_list *lead_comm; | |
334 | |
335 // The comments preceding the ENDFUNCTION token. | |
336 octave_comment_list *trail_comm; | |
337 | |
6323 | 338 // The name of the file we parsed. |
3523 | 339 std::string file_name; |
2974 | 340 |
6323 | 341 // The name of the parent function, if any. |
342 std::string parent_name; | |
343 | |
2974 | 344 // The time the file was parsed. |
3255 | 345 octave_time t_parsed; |
2974 | 346 |
3165 | 347 // The time the file was last checked to see if it needs to be |
348 // parsed again. | |
3255 | 349 octave_time t_checked; |
3165 | 350 |
2974 | 351 // True if this function came from a file that is considered to be a |
352 // system function. This affects whether we check the time stamp | |
353 // on the file to see if it has changed. | |
354 bool system_fcn_file; | |
355 | |
356 // Used to keep track of recursion depth. | |
357 int call_depth; | |
358 | |
359 // The number of arguments that have names. | |
360 int num_named_args; | |
361 | |
4238 | 362 // TRUE means this is a nested function. |
363 bool nested_function; | |
364 | |
6149 | 365 // TRUE means this is an inline function. |
366 bool inline_function; | |
367 | |
7336 | 368 // TRUE means this function is the constructor for class object. |
369 bool class_constructor; | |
370 | |
371 // TRUE means this function is a method for a class. | |
372 bool class_method; | |
373 | |
374 // If this object is a class method or constructor, this is the name | |
375 // of the class to which the method belongs. | |
376 std::string xdispatch_class; | |
377 | |
2974 | 378 // The values that were passed as arguments. |
379 octave_value_list args_passed; | |
380 | |
3875 | 381 // A place to store the passed args for recursive calls. |
4214 | 382 std::stack<octave_value_list> saved_args; |
3875 | 383 |
2974 | 384 // The number of arguments passed in. |
385 int num_args_passed; | |
386 | |
7968
0d607e8dbbfa
eliminate curr_parent_function; fix subfunction lookup
John W. Eaton <jwe@octave.org>
parents:
7876
diff
changeset
|
387 // The scope of the parent function, if any. |
0d607e8dbbfa
eliminate curr_parent_function; fix subfunction lookup
John W. Eaton <jwe@octave.org>
parents:
7876
diff
changeset
|
388 symbol_table::scope_id parent_scope; |
0d607e8dbbfa
eliminate curr_parent_function; fix subfunction lookup
John W. Eaton <jwe@octave.org>
parents:
7876
diff
changeset
|
389 |
7336 | 390 symbol_table::scope_id local_scope; |
2974 | 391 |
7336 | 392 #if 0 |
2974 | 393 // The symbol record for argn in the local symbol table. |
7336 | 394 octave_value& argn_varref; |
2974 | 395 |
396 // The symbol record for nargin in the local symbol table. | |
7336 | 397 octave_value& nargin_varref; |
2974 | 398 |
399 // The symbol record for nargout in the local symbol table. | |
7336 | 400 octave_value& nargout_varref; |
2974 | 401 |
3974 | 402 // The symbol record for varargin in the local symbol table. |
7336 | 403 octave_value& varargin_varref; |
404 #endif | |
3974 | 405 |
2974 | 406 void print_code_function_header (void); |
407 | |
408 void print_code_function_trailer (void); | |
409 | |
410 void bind_automatic_vars (const string_vector& arg_names, int nargin, | |
3974 | 411 int nargout, const octave_value_list& va_args); |
3219 | 412 |
4645 | 413 // No copying! |
414 | |
415 octave_user_function (const octave_user_function& fn); | |
416 | |
417 octave_user_function& operator = (const octave_user_function& fn); | |
418 | |
4612 | 419 DECLARE_OCTAVE_ALLOCATOR |
3219 | 420 |
4612 | 421 DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA |
2974 | 422 }; |
423 | |
424 #endif | |
425 | |
426 /* | |
427 ;;; Local Variables: *** | |
428 ;;; mode: C++ *** | |
429 ;;; End: *** | |
430 */ |