Mercurial > hg > octave-nkf
annotate src/pt-unop.cc @ 11523:fd0a3ac60b0e
update copyright notices
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Fri, 14 Jan 2011 05:47:45 -0500 |
parents | d1194069e58c |
children | 12df7854fa7c |
rev | line source |
---|---|
2980 | 1 /* |
2 | |
11523 | 3 Copyright (C) 1996-2011 John W. Eaton |
2980 | 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 | |
7016 | 9 Free Software Foundation; either version 3 of the License, or (at your |
10 option) any later version. | |
2980 | 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 | |
7016 | 18 along with Octave; see the file COPYING. If not, see |
19 <http://www.gnu.org/licenses/>. | |
2980 | 20 |
21 */ | |
22 | |
23 #ifdef HAVE_CONFIG_H | |
24 #include <config.h> | |
25 #endif | |
26 | |
27 #include "error.h" | |
28 #include "oct-obj.h" | |
29 #include "oct-lvalue.h" | |
30 #include "ov.h" | |
3770 | 31 #include "pt-bp.h" |
2980 | 32 #include "pt-unop.h" |
33 #include "pt-walk.h" | |
34 | |
3203 | 35 // Unary expressions. |
36 | |
3536 | 37 std::string |
3203 | 38 tree_unary_expression::oper (void) const |
39 { | |
40 return octave_value::unary_op_as_string (etype); | |
41 } | |
42 | |
2980 | 43 // Prefix expressions. |
44 | |
45 octave_value_list | |
46 tree_prefix_expression::rvalue (int nargout) | |
47 { | |
48 octave_value_list retval; | |
49 | |
50 if (nargout > 1) | |
51 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
|
52 oper () . c_str ()); |
2980 | 53 else |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8011
diff
changeset
|
54 retval = rvalue1 (nargout); |
2980 | 55 |
56 return retval; | |
57 } | |
58 | |
59 octave_value | |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8011
diff
changeset
|
60 tree_prefix_expression::rvalue1 (int) |
2980 | 61 { |
62 octave_value retval; | |
63 | |
64 if (error_state) | |
65 return retval; | |
66 | |
67 if (op) | |
68 { | |
3539 | 69 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
|
70 { |
10614
d1194069e58c
optimize code handling ++,--
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
71 octave_lvalue ref = op->lvalue (); |
3962 | 72 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
73 if (! error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
74 { |
10614
d1194069e58c
optimize code handling ++,--
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
75 ref.do_unary_op (etype); |
3203 | 76 |
10614
d1194069e58c
optimize code handling ++,--
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
77 if (! error_state) |
d1194069e58c
optimize code handling ++,--
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
78 retval = ref.value (); |
10315
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 } |
3203 | 81 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
82 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
83 octave_value val = op->rvalue1 (); |
2980 | 84 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
85 if (! error_state && val.is_defined ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
86 { |
9887
e3bd1569a68c
in-place operation of unary ops on temporary expressions
Jaroslav Hajek <highegg@gmail.com>
parents:
9716
diff
changeset
|
87 // 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
|
88 // (a temporary expression). |
e3bd1569a68c
in-place operation of unary ops on temporary expressions
Jaroslav Hajek <highegg@gmail.com>
parents:
9716
diff
changeset
|
89 if (val.get_count () == 1) |
e3bd1569a68c
in-place operation of unary ops on temporary expressions
Jaroslav Hajek <highegg@gmail.com>
parents:
9716
diff
changeset
|
90 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
|
91 else |
e3bd1569a68c
in-place operation of unary ops on temporary expressions
Jaroslav Hajek <highegg@gmail.com>
parents:
9716
diff
changeset
|
92 retval = ::do_unary_op (etype, val); |
2980 | 93 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
94 if (error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
95 retval = octave_value (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
96 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
97 } |
2980 | 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, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
105 symbol_table::context_id context) const |
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, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
109 line (), column (), etype); |
5861 | 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", | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
131 oper () . c_str ()); |
2980 | 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) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
149 { |
10614
d1194069e58c
optimize code handling ++,--
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
150 octave_lvalue ref = op->lvalue (); |
3962 | 151 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
152 if (! error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
153 { |
10614
d1194069e58c
optimize code handling ++,--
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
154 retval = ref.value (); |
3203 | 155 |
10614
d1194069e58c
optimize code handling ++,--
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
156 ref.do_unary_op (etype); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
157 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
158 } |
3203 | 159 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
160 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
161 octave_value val = op->rvalue1 (); |
2980 | 162 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
163 if (! error_state && val.is_defined ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
164 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
165 retval = ::do_unary_op (etype, val); |
2980 | 166 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
167 if (error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
168 retval = octave_value (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
169 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
170 } |
2980 | 171 } |
172 | |
173 return retval; | |
174 } | |
175 | |
5861 | 176 tree_expression * |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
177 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
|
178 symbol_table::context_id context) const |
5861 | 179 { |
180 tree_postfix_expression *new_pe | |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
181 = 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
|
182 line (), column (), etype); |
5861 | 183 |
184 new_pe->copy_base (*this); | |
185 | |
186 return new_pe; | |
187 } | |
188 | |
2980 | 189 void |
190 tree_postfix_expression::accept (tree_walker& tw) | |
191 { | |
192 tw.visit_postfix_expression (*this); | |
193 } |