Mercurial > hg > octave-nkf
annotate src/pt-unop.cc @ 10315:57a59eae83cc
untabify src C++ source files
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Thu, 11 Feb 2010 12:41:46 -0500 |
parents | cd96d29c5efa |
children | d1194069e58c |
rev | line source |
---|---|
2980 | 1 /* |
2 | |
7017 | 3 Copyright (C) 1996, 1997, 1998, 2000, 2001, 2002, 2004, 2005, 2006, |
8920 | 4 2007, 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 "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", | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
53 oper () . c_str ()); |
2980 | 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) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
71 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
72 op->rvalue1 (); |
3962 | 73 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
74 if (! error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
75 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
76 octave_lvalue ref = op->lvalue (); |
3203 | 77 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
78 if (! error_state && ref.is_defined ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
79 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
80 ref.do_unary_op (etype); |
3203 | 81 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
82 retval = ref.value (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
83 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
84 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
85 } |
3203 | 86 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
87 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
88 octave_value val = op->rvalue1 (); |
2980 | 89 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
90 if (! error_state && val.is_defined ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
91 { |
9887
e3bd1569a68c
in-place operation of unary ops on temporary expressions
Jaroslav Hajek <highegg@gmail.com>
parents:
9716
diff
changeset
|
92 // Attempt to do the operation in-place if it is unshared |
e3bd1569a68c
in-place operation of unary ops on temporary expressions
Jaroslav Hajek <highegg@gmail.com>
parents:
9716
diff
changeset
|
93 // (a temporary expression). |
e3bd1569a68c
in-place operation of unary ops on temporary expressions
Jaroslav Hajek <highegg@gmail.com>
parents:
9716
diff
changeset
|
94 if (val.get_count () == 1) |
e3bd1569a68c
in-place operation of unary ops on temporary expressions
Jaroslav Hajek <highegg@gmail.com>
parents:
9716
diff
changeset
|
95 retval = val.do_non_const_unary_op (etype); |
e3bd1569a68c
in-place operation of unary ops on temporary expressions
Jaroslav Hajek <highegg@gmail.com>
parents:
9716
diff
changeset
|
96 else |
e3bd1569a68c
in-place operation of unary ops on temporary expressions
Jaroslav Hajek <highegg@gmail.com>
parents:
9716
diff
changeset
|
97 retval = ::do_unary_op (etype, val); |
2980 | 98 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
99 if (error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
100 retval = octave_value (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
101 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
102 } |
2980 | 103 } |
104 | |
105 return retval; | |
106 } | |
107 | |
5861 | 108 tree_expression * |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
109 tree_prefix_expression::dup (symbol_table::scope_id scope, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
110 symbol_table::context_id context) const |
5861 | 111 { |
112 tree_prefix_expression *new_pe | |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
113 = new tree_prefix_expression (op ? op->dup (scope, context) : 0, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
114 line (), column (), etype); |
5861 | 115 |
116 new_pe->copy_base (*this); | |
117 | |
118 return new_pe; | |
119 } | |
120 | |
2980 | 121 void |
122 tree_prefix_expression::accept (tree_walker& tw) | |
123 { | |
124 tw.visit_prefix_expression (*this); | |
125 } | |
126 | |
127 // Postfix expressions. | |
128 | |
129 octave_value_list | |
130 tree_postfix_expression::rvalue (int nargout) | |
131 { | |
132 octave_value_list retval; | |
133 | |
134 if (nargout > 1) | |
135 error ("postfix operator `%s': invalid number of output arguments", | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
136 oper () . c_str ()); |
2980 | 137 else |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8011
diff
changeset
|
138 retval = rvalue1 (nargout); |
2980 | 139 |
140 return retval; | |
141 } | |
142 | |
143 octave_value | |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8011
diff
changeset
|
144 tree_postfix_expression::rvalue1 (int) |
2980 | 145 { |
146 octave_value retval; | |
147 | |
148 if (error_state) | |
149 return retval; | |
150 | |
151 if (op) | |
152 { | |
3539 | 153 if (etype == octave_value::op_incr || etype == octave_value::op_decr) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
154 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
155 op->rvalue1 (); |
3962 | 156 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
157 if (! error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
158 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
159 octave_lvalue ref = op->lvalue (); |
3203 | 160 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
161 if (! error_state && ref.is_defined ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
162 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
163 retval = ref.value (); |
3203 | 164 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
165 ref.do_unary_op (etype); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
166 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
167 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
168 } |
3203 | 169 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
170 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
171 octave_value val = op->rvalue1 (); |
2980 | 172 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
173 if (! error_state && val.is_defined ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
174 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
175 retval = ::do_unary_op (etype, val); |
2980 | 176 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
177 if (error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
178 retval = octave_value (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
179 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
180 } |
2980 | 181 } |
182 | |
183 return retval; | |
184 } | |
185 | |
5861 | 186 tree_expression * |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
187 tree_postfix_expression::dup (symbol_table::scope_id scope, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
188 symbol_table::context_id context) const |
5861 | 189 { |
190 tree_postfix_expression *new_pe | |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
191 = new tree_postfix_expression (op ? op->dup (scope, context) : 0, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
192 line (), column (), etype); |
5861 | 193 |
194 new_pe->copy_base (*this); | |
195 | |
196 return new_pe; | |
197 } | |
198 | |
2980 | 199 void |
200 tree_postfix_expression::accept (tree_walker& tw) | |
201 { | |
202 tw.visit_postfix_expression (*this); | |
203 } |