Mercurial > hg > octave-jordi
annotate src/pt-unop.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 | 35cd375d4bb3 |
rev | line source |
---|---|
2980 | 1 /* |
2 | |
7017 | 3 Copyright (C) 1996, 1997, 1998, 2000, 2001, 2002, 2004, 2005, 2006, |
4 2007 John W. Eaton | |
2980 | 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. | |
2980 | 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/>. | |
2980 | 21 |
22 */ | |
23 | |
24 #ifdef HAVE_CONFIG_H | |
25 #include <config.h> | |
26 #endif | |
27 | |
28 #include "error.h" | |
29 #include "oct-obj.h" | |
30 #include "oct-lvalue.h" | |
31 #include "ov.h" | |
3770 | 32 #include "pt-bp.h" |
2980 | 33 #include "pt-unop.h" |
34 #include "pt-walk.h" | |
35 | |
3203 | 36 // Unary expressions. |
37 | |
3536 | 38 std::string |
3203 | 39 tree_unary_expression::oper (void) const |
40 { | |
41 return octave_value::unary_op_as_string (etype); | |
42 } | |
43 | |
2980 | 44 // Prefix expressions. |
45 | |
46 octave_value_list | |
47 tree_prefix_expression::rvalue (int nargout) | |
48 { | |
49 octave_value_list retval; | |
50 | |
51 if (nargout > 1) | |
52 error ("prefix operator `%s': invalid number of output arguments", | |
53 oper () . c_str ()); | |
54 else | |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8011
diff
changeset
|
55 retval = rvalue1 (nargout); |
2980 | 56 |
57 return retval; | |
58 } | |
59 | |
60 octave_value | |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8011
diff
changeset
|
61 tree_prefix_expression::rvalue1 (int) |
2980 | 62 { |
63 octave_value retval; | |
64 | |
65 if (error_state) | |
66 return retval; | |
67 | |
68 if (op) | |
69 { | |
3539 | 70 if (etype == octave_value::op_incr || etype == octave_value::op_decr) |
3203 | 71 { |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8011
diff
changeset
|
72 op->rvalue1 (); |
3962 | 73 |
74 if (! error_state) | |
75 { | |
76 octave_lvalue ref = op->lvalue (); | |
3203 | 77 |
3962 | 78 if (! error_state && ref.is_defined ()) |
79 { | |
80 ref.do_unary_op (etype); | |
3203 | 81 |
3962 | 82 retval = ref.value (); |
83 } | |
3203 | 84 } |
85 } | |
86 else | |
2980 | 87 { |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8011
diff
changeset
|
88 octave_value val = op->rvalue1 (); |
2980 | 89 |
3962 | 90 if (! error_state && val.is_defined ()) |
2980 | 91 { |
3203 | 92 retval = ::do_unary_op (etype, val); |
2980 | 93 |
3203 | 94 if (error_state) |
8011
3100283874d7
improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents:
7767
diff
changeset
|
95 retval = octave_value (); |
2980 | 96 } |
97 } | |
98 } | |
99 | |
100 return retval; | |
101 } | |
102 | |
5861 | 103 tree_expression * |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
104 tree_prefix_expression::dup (symbol_table::scope_id scope, |
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
105 symbol_table::context_id context) |
5861 | 106 { |
107 tree_prefix_expression *new_pe | |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
108 = new tree_prefix_expression (op ? op->dup (scope, context) : 0, |
5861 | 109 line (), column (), etype); |
110 | |
111 new_pe->copy_base (*this); | |
112 | |
113 return new_pe; | |
114 } | |
115 | |
2980 | 116 void |
117 tree_prefix_expression::accept (tree_walker& tw) | |
118 { | |
119 tw.visit_prefix_expression (*this); | |
120 } | |
121 | |
122 // Postfix expressions. | |
123 | |
124 octave_value_list | |
125 tree_postfix_expression::rvalue (int nargout) | |
126 { | |
127 octave_value_list retval; | |
128 | |
129 if (nargout > 1) | |
130 error ("postfix operator `%s': invalid number of output arguments", | |
131 oper () . c_str ()); | |
132 else | |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8011
diff
changeset
|
133 retval = rvalue1 (nargout); |
2980 | 134 |
135 return retval; | |
136 } | |
137 | |
138 octave_value | |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8011
diff
changeset
|
139 tree_postfix_expression::rvalue1 (int) |
2980 | 140 { |
141 octave_value retval; | |
142 | |
143 if (error_state) | |
144 return retval; | |
145 | |
146 if (op) | |
147 { | |
3539 | 148 if (etype == octave_value::op_incr || etype == octave_value::op_decr) |
3203 | 149 { |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8011
diff
changeset
|
150 op->rvalue1 (); |
3962 | 151 |
152 if (! error_state) | |
153 { | |
154 octave_lvalue ref = op->lvalue (); | |
3203 | 155 |
3962 | 156 if (! error_state && ref.is_defined ()) |
157 { | |
158 retval = ref.value (); | |
3203 | 159 |
3962 | 160 ref.do_unary_op (etype); |
161 } | |
3203 | 162 } |
163 } | |
164 else | |
2980 | 165 { |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8011
diff
changeset
|
166 octave_value val = op->rvalue1 (); |
2980 | 167 |
3962 | 168 if (! error_state && val.is_defined ()) |
2980 | 169 { |
3203 | 170 retval = ::do_unary_op (etype, val); |
2980 | 171 |
3203 | 172 if (error_state) |
8011
3100283874d7
improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents:
7767
diff
changeset
|
173 retval = octave_value (); |
2980 | 174 } |
175 } | |
176 } | |
177 | |
178 return retval; | |
179 } | |
180 | |
5861 | 181 tree_expression * |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
182 tree_postfix_expression::dup (symbol_table::scope_id scope, |
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
183 symbol_table::context_id context) |
5861 | 184 { |
185 tree_postfix_expression *new_pe | |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
186 = new tree_postfix_expression (op ? op->dup (scope, context) : 0, |
5861 | 187 line (), column (), etype); |
188 | |
189 new_pe->copy_base (*this); | |
190 | |
191 return new_pe; | |
192 } | |
193 | |
2980 | 194 void |
195 tree_postfix_expression::accept (tree_walker& tw) | |
196 { | |
197 tw.visit_postfix_expression (*this); | |
198 } | |
199 | |
200 /* | |
201 ;;; Local Variables: *** | |
202 ;;; mode: C++ *** | |
203 ;;; End: *** | |
204 */ |