4343
|
1 /* |
|
2 |
|
3 Copyright (C) 2003 John W. Eaton |
|
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 |
|
9 Free Software Foundation; either version 2, or (at your option) any |
|
10 later version. |
|
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 |
|
18 along with Octave; see the file COPYING. If not, write to the Free |
5307
|
19 Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|
20 02110-1301, USA. |
4343
|
21 |
|
22 */ |
|
23 |
|
24 #ifdef HAVE_CONFIG_H |
|
25 #include <config.h> |
|
26 #endif |
|
27 |
|
28 #include <iostream> |
|
29 |
|
30 #include "error.h" |
|
31 #include "oct-obj.h" |
|
32 #include "ov-fcn-handle.h" |
|
33 #include "pt-fcn-handle.h" |
|
34 #include "pager.h" |
|
35 #include "pt-walk.h" |
5861
|
36 #include "variables.h" |
4343
|
37 |
|
38 void |
|
39 tree_fcn_handle::print (std::ostream& os, bool pr_as_read_syntax, |
|
40 bool pr_orig_text) |
|
41 { |
|
42 print_raw (os, pr_as_read_syntax, pr_orig_text); |
|
43 } |
|
44 |
|
45 void |
|
46 tree_fcn_handle::print_raw (std::ostream& os, bool pr_as_read_syntax, |
|
47 bool pr_orig_text) |
|
48 { |
|
49 os << ((pr_as_read_syntax || pr_orig_text) ? "@" : "") << nm; |
|
50 } |
|
51 |
|
52 octave_value |
|
53 tree_fcn_handle::rvalue (void) |
|
54 { |
|
55 MAYBE_DO_BREAKPOINT; |
|
56 |
|
57 return make_fcn_handle (nm); |
|
58 } |
|
59 |
|
60 |
|
61 octave_value_list |
|
62 tree_fcn_handle::rvalue (int nargout) |
|
63 { |
|
64 octave_value_list retval; |
|
65 |
|
66 if (nargout > 1) |
|
67 error ("invalid number of output arguments for function handle expression"); |
|
68 else |
|
69 retval = rvalue (); |
|
70 |
|
71 return retval; |
|
72 } |
|
73 |
5861
|
74 tree_expression * |
|
75 tree_fcn_handle::dup (symbol_table *sym_tab) |
|
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 tree_anon_fcn_handle::~tree_anon_fcn_handle (void) |
|
91 { |
|
92 delete param_list; |
|
93 delete cmd_list; |
|
94 delete ret_list; |
|
95 delete sym_tab; |
|
96 } |
|
97 |
|
98 octave_value |
|
99 tree_anon_fcn_handle::rvalue (void) |
|
100 { |
|
101 MAYBE_DO_BREAKPOINT; |
|
102 |
|
103 symbol_table *new_sym_tab = sym_tab ? sym_tab->dup () : 0; |
|
104 |
|
105 if (new_sym_tab) |
|
106 new_sym_tab->inherit (curr_sym_tab); |
|
107 |
|
108 tree_parameter_list *new_param_list |
|
109 = param_list ? param_list->dup (new_sym_tab) : 0; |
|
110 |
|
111 tree_statement_list *new_cmd_list |
|
112 = cmd_list ? cmd_list->dup (new_sym_tab) : 0; |
|
113 |
|
114 tree_parameter_list *new_ret_list |
|
115 = ret_list ? ret_list->dup (new_sym_tab) : 0; |
|
116 |
|
117 octave_user_function *uf |
|
118 = new octave_user_function (new_param_list, new_ret_list, |
|
119 new_cmd_list, new_sym_tab); |
|
120 |
|
121 octave_value fcn (uf); |
|
122 |
|
123 octave_value fh (new octave_fcn_handle (fcn, "@<anonymous>")); |
|
124 |
|
125 return fh; |
|
126 } |
|
127 |
|
128 octave_value_list |
|
129 tree_anon_fcn_handle::rvalue (int nargout) |
|
130 { |
|
131 octave_value_list retval; |
|
132 |
|
133 if (nargout > 1) |
|
134 error ("invalid number of output arguments for anonymous function handle expression"); |
|
135 else |
|
136 retval = rvalue (); |
|
137 |
|
138 return retval; |
|
139 } |
|
140 |
|
141 tree_expression * |
|
142 tree_anon_fcn_handle::dup (symbol_table *st) |
|
143 { |
6061
|
144 symbol_table *new_sym_tab = sym_tab ? sym_tab->dup () : 0; |
|
145 |
|
146 if (new_sym_tab) |
|
147 new_sym_tab->inherit (st); |
|
148 |
5861
|
149 tree_anon_fcn_handle *new_afh |
6061
|
150 = new tree_anon_fcn_handle (param_list ? param_list->dup (new_sym_tab) : 0, |
|
151 ret_list ? ret_list->dup (new_sym_tab) : 0, |
|
152 cmd_list ? cmd_list->dup (new_sym_tab) : 0, |
|
153 new_sym_tab, line (), column ()); |
5861
|
154 |
|
155 new_afh->copy_base (*this); |
|
156 |
|
157 return new_afh; |
|
158 } |
|
159 |
|
160 void |
|
161 tree_anon_fcn_handle::accept (tree_walker& tw) |
|
162 { |
|
163 tw.visit_anon_fcn_handle (*this); |
|
164 } |
|
165 |
|
166 |
|
167 |
4343
|
168 /* |
|
169 ;;; Local Variables: *** |
|
170 ;;; mode: C++ *** |
|
171 ;;; End: *** |
|
172 */ |