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