Mercurial > hg > octave-lyh
annotate src/pt-fcn-handle.cc @ 8523:ad3afaaa19c1
implement non-copying contiguous range indexing
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Thu, 15 Jan 2009 07:22:24 +0100 |
parents | 24701aa75ecb |
children | 73c4516fae10 |
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 | |
52 tree_fcn_handle::rvalue (void) | |
53 { | |
54 MAYBE_DO_BREAKPOINT; | |
55 | |
56 return make_fcn_handle (nm); | |
57 } | |
58 | |
59 | |
60 octave_value_list | |
61 tree_fcn_handle::rvalue (int nargout) | |
62 { | |
63 octave_value_list retval; | |
64 | |
65 if (nargout > 1) | |
66 error ("invalid number of output arguments for function handle expression"); | |
67 else | |
68 retval = rvalue (); | |
69 | |
70 return retval; | |
71 } | |
72 | |
5861 | 73 tree_expression * |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
74 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
|
75 symbol_table::context_id) |
5861 | 76 { |
77 tree_fcn_handle *new_fh = new tree_fcn_handle (nm, line (), column ()); | |
78 | |
79 new_fh->copy_base (*this); | |
80 | |
81 return new_fh; | |
82 } | |
83 | |
4343 | 84 void |
85 tree_fcn_handle::accept (tree_walker& tw) | |
86 { | |
87 tw.visit_fcn_handle (*this); | |
88 } | |
89 | |
5861 | 90 octave_value |
91 tree_anon_fcn_handle::rvalue (void) | |
92 { | |
93 MAYBE_DO_BREAKPOINT; | |
94 | |
7336 | 95 tree_parameter_list *param_list = parameter_list (); |
96 tree_parameter_list *ret_list = return_list (); | |
97 tree_statement_list *cmd_list = body (); | |
98 symbol_table::scope_id this_scope = scope (); | |
5861 | 99 |
7336 | 100 symbol_table::scope_id new_scope = symbol_table::dup_scope (this_scope); |
5861 | 101 |
7336 | 102 if (new_scope > 0) |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
103 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
|
104 symbol_table::current_context ()); |
5861 | 105 |
106 octave_user_function *uf | |
7336 | 107 = 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
|
108 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
|
109 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
|
110 cmd_list ? cmd_list->dup (new_scope, 0) : 0); |
5861 | 111 |
6656 | 112 octave_function *curr_fcn = octave_call_stack::current (); |
113 | |
114 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
|
115 { |
2fd4a5ef6b59
stash parent function scope for inline functions and anonymous function handles.
John W. Eaton <jwe@octave.org>
parents:
7767
diff
changeset
|
116 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
|
117 |
24701aa75ecb
scope fixes for anonymous and inline functions that appear inside subfunctions
John W. Eaton <jwe@octave.org>
parents:
8032
diff
changeset
|
118 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
|
119 |
24701aa75ecb
scope fixes for anonymous and inline functions that appear inside subfunctions
John W. Eaton <jwe@octave.org>
parents:
8032
diff
changeset
|
120 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
|
121 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
|
122 |
24701aa75ecb
scope fixes for anonymous and inline functions that appear inside subfunctions
John W. Eaton <jwe@octave.org>
parents:
8032
diff
changeset
|
123 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
|
124 } |
6656 | 125 |
6149 | 126 uf->mark_as_inline_function (); |
127 | |
6505 | 128 octave_value ov_fcn (uf); |
5861 | 129 |
6505 | 130 octave_value fh (new octave_fcn_handle (ov_fcn, "@<anonymous>")); |
5861 | 131 |
132 return fh; | |
133 } | |
134 | |
135 octave_value_list | |
136 tree_anon_fcn_handle::rvalue (int nargout) | |
137 { | |
138 octave_value_list retval; | |
139 | |
140 if (nargout > 1) | |
141 error ("invalid number of output arguments for anonymous function handle expression"); | |
142 else | |
143 retval = rvalue (); | |
144 | |
145 return retval; | |
146 } | |
147 | |
148 tree_expression * | |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
149 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
|
150 symbol_table::context_id parent_context) |
5861 | 151 { |
7336 | 152 tree_parameter_list *param_list = parameter_list (); |
153 tree_parameter_list *ret_list = return_list (); | |
154 tree_statement_list *cmd_list = body (); | |
155 symbol_table::scope_id this_scope = scope (); | |
6505 | 156 |
7336 | 157 symbol_table::scope_id new_scope = symbol_table::dup_scope (this_scope); |
6061 | 158 |
7336 | 159 if (new_scope > 0) |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
160 symbol_table::inherit (new_scope, parent_scope, parent_context); |
6061 | 161 |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
162 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
|
163 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
|
164 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
|
165 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
|
166 new_scope, line (), column ()); |
5861 | 167 |
168 new_afh->copy_base (*this); | |
169 | |
170 return new_afh; | |
171 } | |
172 | |
173 void | |
174 tree_anon_fcn_handle::accept (tree_walker& tw) | |
175 { | |
176 tw.visit_anon_fcn_handle (*this); | |
177 } | |
178 | |
179 | |
180 | |
4343 | 181 /* |
182 ;;; Local Variables: *** | |
183 ;;; mode: C++ *** | |
184 ;;; End: *** | |
185 */ |