Mercurial > hg > octave-lyh
annotate src/pt-binop.cc @ 8011:3100283874d7
improve backtrace error messages
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Tue, 05 Aug 2008 23:09:32 -0400 |
parents | 71f068b22fcc |
children | 73c4516fae10 |
rev | line source |
---|---|
2980 | 1 /* |
2 | |
7017 | 3 Copyright (C) 1996, 1997, 2000, 2001, 2002, 2004, 2005, 2006, 2007 |
4 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 "ov.h" | |
31 #include "pt-binop.h" | |
3770 | 32 #include "pt-bp.h" |
2980 | 33 #include "pt-walk.h" |
34 | |
35 // Binary expressions. | |
36 | |
37 octave_value_list | |
38 tree_binary_expression::rvalue (int nargout) | |
39 { | |
40 octave_value_list retval; | |
41 | |
42 if (nargout > 1) | |
43 error ("binary operator `%s': invalid number of output arguments", | |
44 oper () . c_str ()); | |
45 else | |
46 retval = rvalue (); | |
47 | |
48 return retval; | |
49 } | |
50 | |
51 octave_value | |
52 tree_binary_expression::rvalue (void) | |
53 { | |
54 octave_value retval; | |
55 | |
3770 | 56 MAYBE_DO_BREAKPOINT; |
57 | |
2980 | 58 if (error_state) |
59 return retval; | |
60 | |
61 if (op_lhs) | |
62 { | |
63 octave_value a = op_lhs->rvalue (); | |
64 | |
8011
3100283874d7
improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents:
7767
diff
changeset
|
65 if (! error_state && a.is_defined () && op_rhs) |
2980 | 66 { |
67 octave_value b = op_rhs->rvalue (); | |
68 | |
8011
3100283874d7
improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents:
7767
diff
changeset
|
69 if (! error_state && b.is_defined ()) |
2980 | 70 { |
71 retval = ::do_binary_op (etype, a, b); | |
72 | |
73 if (error_state) | |
8011
3100283874d7
improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents:
7767
diff
changeset
|
74 retval = octave_value (); |
2980 | 75 } |
76 } | |
77 } | |
78 | |
79 return retval; | |
80 } | |
81 | |
3536 | 82 std::string |
2980 | 83 tree_binary_expression::oper (void) const |
84 { | |
85 return octave_value::binary_op_as_string (etype); | |
86 } | |
87 | |
5861 | 88 tree_expression * |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
89 tree_binary_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
|
90 symbol_table::context_id context) |
5861 | 91 { |
92 tree_binary_expression *new_be | |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
93 = new tree_binary_expression (op_lhs ? op_lhs->dup (scope, context) : 0, |
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
94 op_rhs ? op_rhs->dup (scope, context) : 0, |
5861 | 95 line (), column (), etype); |
96 | |
97 new_be->copy_base (*this); | |
98 | |
99 return new_be; | |
100 } | |
101 | |
2980 | 102 void |
103 tree_binary_expression::accept (tree_walker& tw) | |
104 { | |
105 tw.visit_binary_expression (*this); | |
106 } | |
107 | |
108 // Boolean expressions. | |
109 | |
110 octave_value_list | |
111 tree_boolean_expression::rvalue (int nargout) | |
112 { | |
113 octave_value_list retval; | |
114 | |
3770 | 115 MAYBE_DO_BREAKPOINT; |
116 | |
2980 | 117 if (nargout > 1) |
118 error ("binary operator `%s': invalid number of output arguments", | |
119 oper () . c_str ()); | |
120 else | |
121 retval = rvalue (); | |
122 | |
123 return retval; | |
124 } | |
125 | |
126 octave_value | |
127 tree_boolean_expression::rvalue (void) | |
128 { | |
129 octave_value retval; | |
130 | |
131 if (error_state) | |
132 return retval; | |
133 | |
134 bool result = false; | |
135 | |
136 if (op_lhs) | |
137 { | |
138 octave_value a = op_lhs->rvalue (); | |
139 | |
8011
3100283874d7
improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents:
7767
diff
changeset
|
140 if (! error_state) |
2980 | 141 { |
142 bool a_true = a.is_true (); | |
143 | |
8011
3100283874d7
improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents:
7767
diff
changeset
|
144 if (! error_state) |
2980 | 145 { |
146 if (a_true) | |
147 { | |
148 if (etype == bool_or) | |
149 { | |
150 result = true; | |
151 goto done; | |
152 } | |
153 } | |
154 else | |
155 { | |
156 if (etype == bool_and) | |
157 goto done; | |
158 } | |
159 | |
160 if (op_rhs) | |
161 { | |
162 octave_value b = op_rhs->rvalue (); | |
163 | |
8011
3100283874d7
improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents:
7767
diff
changeset
|
164 if (! error_state) |
3100283874d7
improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents:
7767
diff
changeset
|
165 result = b.is_true (); |
2980 | 166 } |
167 | |
168 done: | |
169 | |
170 if (! error_state) | |
3798 | 171 retval = octave_value (result); |
2980 | 172 } |
173 } | |
174 } | |
175 | |
176 return retval; | |
177 } | |
178 | |
3536 | 179 std::string |
2980 | 180 tree_boolean_expression::oper (void) const |
181 { | |
3523 | 182 std::string retval = "<unknown>"; |
2980 | 183 |
184 switch (etype) | |
185 { | |
186 case bool_and: | |
187 retval = "&&"; | |
188 break; | |
189 | |
190 case bool_or: | |
191 retval = "||"; | |
192 break; | |
193 | |
194 default: | |
195 break; | |
196 } | |
197 | |
198 return retval; | |
199 } | |
200 | |
5861 | 201 tree_expression * |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
202 tree_boolean_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
|
203 symbol_table::context_id context) |
5861 | 204 { |
205 tree_boolean_expression *new_be | |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
206 = new tree_boolean_expression (op_lhs ? op_lhs->dup (scope, context) : 0, |
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
207 op_rhs ? op_rhs->dup (scope, context) : 0, |
5861 | 208 line (), column (), etype); |
209 | |
210 new_be->copy_base (*this); | |
211 | |
212 return new_be; | |
213 } | |
214 | |
2980 | 215 /* |
216 ;;; Local Variables: *** | |
217 ;;; mode: C++ *** | |
218 ;;; End: *** | |
219 */ |