Mercurial > octave-nkf
annotate src/pt-fcn-handle.cc @ 8874:bd1b1fe9c6e9 ss-3-1-53
bump version info for snapshot
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Wed, 25 Feb 2009 18:35:47 -0500 |
parents | 73c4516fae10 |
children | ab87d08d9a1b |
rev | line source |
---|---|
4343 | 1 /* |
2 | |
7017 | 3 Copyright (C) 2003, 2004, 2005, 2006, 2007 John W. Eaton |
4343 | 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. | |
4343 | 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/>. | |
4343 | 20 |
21 */ | |
22 | |
23 #ifdef HAVE_CONFIG_H | |
24 #include <config.h> | |
25 #endif | |
26 | |
27 #include <iostream> | |
28 | |
29 #include "error.h" | |
30 #include "oct-obj.h" | |
31 #include "ov-fcn-handle.h" | |
32 #include "pt-fcn-handle.h" | |
33 #include "pager.h" | |
34 #include "pt-walk.h" | |
5861 | 35 #include "variables.h" |
4343 | 36 |
37 void | |
38 tree_fcn_handle::print (std::ostream& os, bool pr_as_read_syntax, | |
39 bool pr_orig_text) | |
40 { | |
41 print_raw (os, pr_as_read_syntax, pr_orig_text); | |
42 } | |
43 | |
44 void | |
45 tree_fcn_handle::print_raw (std::ostream& os, bool pr_as_read_syntax, | |
46 bool pr_orig_text) | |
47 { | |
48 os << ((pr_as_read_syntax || pr_orig_text) ? "@" : "") << nm; | |
49 } | |
50 | |
51 octave_value | |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8045
diff
changeset
|
52 tree_fcn_handle::rvalue1 (int) |
4343 | 53 { |
54 return make_fcn_handle (nm); | |
55 } | |
56 | |
57 octave_value_list | |
58 tree_fcn_handle::rvalue (int nargout) | |
59 { | |
60 octave_value_list retval; | |
61 | |
62 if (nargout > 1) | |
63 error ("invalid number of output arguments for function handle expression"); | |
64 else | |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8045
diff
changeset
|
65 retval = rvalue1 (nargout); |
4343 | 66 |
67 return retval; | |
68 } | |
69 | |
5861 | 70 tree_expression * |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
71 tree_fcn_handle::dup (symbol_table::scope_id, |
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
72 symbol_table::context_id) |
5861 | 73 { |
74 tree_fcn_handle *new_fh = new tree_fcn_handle (nm, line (), column ()); | |
75 | |
76 new_fh->copy_base (*this); | |
77 | |
78 return new_fh; | |
79 } | |
80 | |
4343 | 81 void |
82 tree_fcn_handle::accept (tree_walker& tw) | |
83 { | |
84 tw.visit_fcn_handle (*this); | |
85 } | |
86 | |
5861 | 87 octave_value |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8045
diff
changeset
|
88 tree_anon_fcn_handle::rvalue1 (int) |
5861 | 89 { |
7336 | 90 tree_parameter_list *param_list = parameter_list (); |
91 tree_parameter_list *ret_list = return_list (); | |
92 tree_statement_list *cmd_list = body (); | |
93 symbol_table::scope_id this_scope = scope (); | |
5861 | 94 |
7336 | 95 symbol_table::scope_id new_scope = symbol_table::dup_scope (this_scope); |
5861 | 96 |
7336 | 97 if (new_scope > 0) |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
98 symbol_table::inherit (new_scope, symbol_table::current_scope (), |
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
99 symbol_table::current_context ()); |
5861 | 100 |
101 octave_user_function *uf | |
7336 | 102 = new octave_user_function (new_scope, |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
103 param_list ? param_list->dup (new_scope, 0) : 0, |
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
104 ret_list ? ret_list->dup (new_scope, 0) : 0, |
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
105 cmd_list ? cmd_list->dup (new_scope, 0) : 0); |
5861 | 106 |
6656 | 107 octave_function *curr_fcn = octave_call_stack::current (); |
108 | |
109 if (curr_fcn) | |
8032
2fd4a5ef6b59
stash parent function scope for inline functions and anonymous function handles.
John W. Eaton <jwe@octave.org>
parents:
7767
diff
changeset
|
110 { |
2fd4a5ef6b59
stash parent function scope for inline functions and anonymous function handles.
John W. Eaton <jwe@octave.org>
parents:
7767
diff
changeset
|
111 uf->stash_parent_fcn_name (curr_fcn->name ()); |
8045
24701aa75ecb
scope fixes for anonymous and inline functions that appear inside subfunctions
John W. Eaton <jwe@octave.org>
parents:
8032
diff
changeset
|
112 |
24701aa75ecb
scope fixes for anonymous and inline functions that appear inside subfunctions
John W. Eaton <jwe@octave.org>
parents:
8032
diff
changeset
|
113 symbol_table::scope_id parent_scope = curr_fcn->parent_fcn_scope (); |
24701aa75ecb
scope fixes for anonymous and inline functions that appear inside subfunctions
John W. Eaton <jwe@octave.org>
parents:
8032
diff
changeset
|
114 |
24701aa75ecb
scope fixes for anonymous and inline functions that appear inside subfunctions
John W. Eaton <jwe@octave.org>
parents:
8032
diff
changeset
|
115 if (parent_scope < 0) |
24701aa75ecb
scope fixes for anonymous and inline functions that appear inside subfunctions
John W. Eaton <jwe@octave.org>
parents:
8032
diff
changeset
|
116 parent_scope = curr_fcn->scope (); |
24701aa75ecb
scope fixes for anonymous and inline functions that appear inside subfunctions
John W. Eaton <jwe@octave.org>
parents:
8032
diff
changeset
|
117 |
24701aa75ecb
scope fixes for anonymous and inline functions that appear inside subfunctions
John W. Eaton <jwe@octave.org>
parents:
8032
diff
changeset
|
118 uf->stash_parent_fcn_scope (parent_scope); |
8032
2fd4a5ef6b59
stash parent function scope for inline functions and anonymous function handles.
John W. Eaton <jwe@octave.org>
parents:
7767
diff
changeset
|
119 } |
6656 | 120 |
6149 | 121 uf->mark_as_inline_function (); |
122 | |
6505 | 123 octave_value ov_fcn (uf); |
5861 | 124 |
6505 | 125 octave_value fh (new octave_fcn_handle (ov_fcn, "@<anonymous>")); |
5861 | 126 |
127 return fh; | |
128 } | |
129 | |
130 octave_value_list | |
131 tree_anon_fcn_handle::rvalue (int nargout) | |
132 { | |
133 octave_value_list retval; | |
134 | |
135 if (nargout > 1) | |
136 error ("invalid number of output arguments for anonymous function handle expression"); | |
137 else | |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8045
diff
changeset
|
138 retval = rvalue1 (nargout); |
5861 | 139 |
140 return retval; | |
141 } | |
142 | |
143 tree_expression * | |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
144 tree_anon_fcn_handle::dup (symbol_table::scope_id parent_scope, |
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
145 symbol_table::context_id parent_context) |
5861 | 146 { |
7336 | 147 tree_parameter_list *param_list = parameter_list (); |
148 tree_parameter_list *ret_list = return_list (); | |
149 tree_statement_list *cmd_list = body (); | |
150 symbol_table::scope_id this_scope = scope (); | |
6505 | 151 |
7336 | 152 symbol_table::scope_id new_scope = symbol_table::dup_scope (this_scope); |
6061 | 153 |
7336 | 154 if (new_scope > 0) |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
155 symbol_table::inherit (new_scope, parent_scope, parent_context); |
6061 | 156 |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
157 tree_anon_fcn_handle *new_afh = new |
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
158 tree_anon_fcn_handle (param_list ? param_list->dup (new_scope, 0) : 0, |
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
159 ret_list ? ret_list->dup (new_scope, 0) : 0, |
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
160 cmd_list ? cmd_list->dup (new_scope, 0) : 0, |
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
161 new_scope, line (), column ()); |
5861 | 162 |
163 new_afh->copy_base (*this); | |
164 | |
165 return new_afh; | |
166 } | |
167 | |
168 void | |
169 tree_anon_fcn_handle::accept (tree_walker& tw) | |
170 { | |
171 tw.visit_anon_fcn_handle (*this); | |
172 } | |
173 | |
174 | |
175 | |
4343 | 176 /* |
177 ;;; Local Variables: *** | |
178 ;;; mode: C++ *** | |
179 ;;; End: *** | |
180 */ |