Mercurial > hg > octave-nkf
annotate src/pt-fcn-handle.cc @ 7948:af10baa63915 ss-3-1-50
3.1.50 snapshot
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Fri, 18 Jul 2008 17:42:48 -0400 |
parents | 71f068b22fcc |
children | 2fd4a5ef6b59 |
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) | |
115 uf->stash_parent_fcn_name (curr_fcn->name ()); | |
116 | |
6149 | 117 uf->mark_as_inline_function (); |
118 | |
6505 | 119 octave_value ov_fcn (uf); |
5861 | 120 |
6505 | 121 octave_value fh (new octave_fcn_handle (ov_fcn, "@<anonymous>")); |
5861 | 122 |
123 return fh; | |
124 } | |
125 | |
126 octave_value_list | |
127 tree_anon_fcn_handle::rvalue (int nargout) | |
128 { | |
129 octave_value_list retval; | |
130 | |
131 if (nargout > 1) | |
132 error ("invalid number of output arguments for anonymous function handle expression"); | |
133 else | |
134 retval = rvalue (); | |
135 | |
136 return retval; | |
137 } | |
138 | |
139 tree_expression * | |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
140 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
|
141 symbol_table::context_id parent_context) |
5861 | 142 { |
7336 | 143 tree_parameter_list *param_list = parameter_list (); |
144 tree_parameter_list *ret_list = return_list (); | |
145 tree_statement_list *cmd_list = body (); | |
146 symbol_table::scope_id this_scope = scope (); | |
6505 | 147 |
7336 | 148 symbol_table::scope_id new_scope = symbol_table::dup_scope (this_scope); |
6061 | 149 |
7336 | 150 if (new_scope > 0) |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
151 symbol_table::inherit (new_scope, parent_scope, parent_context); |
6061 | 152 |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
153 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
|
154 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
|
155 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
|
156 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
|
157 new_scope, line (), column ()); |
5861 | 158 |
159 new_afh->copy_base (*this); | |
160 | |
161 return new_afh; | |
162 } | |
163 | |
164 void | |
165 tree_anon_fcn_handle::accept (tree_walker& tw) | |
166 { | |
167 tw.visit_anon_fcn_handle (*this); | |
168 } | |
169 | |
170 | |
171 | |
4343 | 172 /* |
173 ;;; Local Variables: *** | |
174 ;;; mode: C++ *** | |
175 ;;; End: *** | |
176 */ |