Mercurial > hg > octave-nkf
annotate src/pt-unop.cc @ 14200:64d9f33313cc stable rc-3-6-0-1
3.6.0-rc1 release candidate
* configure.ac (AC_INIT): Version is now 3.6.0-rc1.
(OCTAVE_RELEASE_DATE): Now 2012-01-12.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Thu, 12 Jan 2012 14:31:50 -0500 |
parents | 72c96de7a403 |
children | d174210ce1ec |
rev | line source |
---|---|
2980 | 1 /* |
2 | |
14138
72c96de7a403
maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents:
13141
diff
changeset
|
3 Copyright (C) 1996-2012 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" | |
12920
5d18231eee00
Extend profiling support to operators.
Daniel Kraft <d@domob.eu>
parents:
11586
diff
changeset
|
31 #include "profiler.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 { |
10614
d1194069e58c
optimize code handling ++,--
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
72 octave_lvalue ref = op->lvalue (); |
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 { |
12960
43d78e103984
Use macro to start profiler blocks.
Daniel Kraft <d@domob.eu>
parents:
12920
diff
changeset
|
76 BEGIN_PROFILER_BLOCK ("prefix " + oper ()) |
13141
e81ddf9cacd5
maint: untabify and remove trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
12960
diff
changeset
|
77 |
10614
d1194069e58c
optimize code handling ++,--
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
78 ref.do_unary_op (etype); |
3203 | 79 |
10614
d1194069e58c
optimize code handling ++,--
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
80 if (! error_state) |
d1194069e58c
optimize code handling ++,--
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
81 retval = ref.value (); |
12960
43d78e103984
Use macro to start profiler blocks.
Daniel Kraft <d@domob.eu>
parents:
12920
diff
changeset
|
82 |
43d78e103984
Use macro to start profiler blocks.
Daniel Kraft <d@domob.eu>
parents:
12920
diff
changeset
|
83 END_PROFILER_BLOCK |
10315
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 { |
12960
43d78e103984
Use macro to start profiler blocks.
Daniel Kraft <d@domob.eu>
parents:
12920
diff
changeset
|
92 BEGIN_PROFILER_BLOCK ("prefix " + oper ()) |
12920
5d18231eee00
Extend profiling support to operators.
Daniel Kraft <d@domob.eu>
parents:
11586
diff
changeset
|
93 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
94 // Attempt to do the operation in-place if it is unshared |
9887
e3bd1569a68c
in-place operation of unary ops on temporary expressions
Jaroslav Hajek <highegg@gmail.com>
parents:
9716
diff
changeset
|
95 // (a temporary expression). |
e3bd1569a68c
in-place operation of unary ops on temporary expressions
Jaroslav Hajek <highegg@gmail.com>
parents:
9716
diff
changeset
|
96 if (val.get_count () == 1) |
e3bd1569a68c
in-place operation of unary ops on temporary expressions
Jaroslav Hajek <highegg@gmail.com>
parents:
9716
diff
changeset
|
97 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
|
98 else |
e3bd1569a68c
in-place operation of unary ops on temporary expressions
Jaroslav Hajek <highegg@gmail.com>
parents:
9716
diff
changeset
|
99 retval = ::do_unary_op (etype, val); |
2980 | 100 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
101 if (error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
102 retval = octave_value (); |
12960
43d78e103984
Use macro to start profiler blocks.
Daniel Kraft <d@domob.eu>
parents:
12920
diff
changeset
|
103 |
43d78e103984
Use macro to start profiler blocks.
Daniel Kraft <d@domob.eu>
parents:
12920
diff
changeset
|
104 END_PROFILER_BLOCK |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
105 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
106 } |
2980 | 107 } |
108 | |
109 return retval; | |
110 } | |
111 | |
5861 | 112 tree_expression * |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
113 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
|
114 symbol_table::context_id context) const |
5861 | 115 { |
116 tree_prefix_expression *new_pe | |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
117 = 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
|
118 line (), column (), etype); |
5861 | 119 |
120 new_pe->copy_base (*this); | |
121 | |
122 return new_pe; | |
123 } | |
124 | |
2980 | 125 void |
126 tree_prefix_expression::accept (tree_walker& tw) | |
127 { | |
128 tw.visit_prefix_expression (*this); | |
129 } | |
130 | |
131 // Postfix expressions. | |
132 | |
133 octave_value_list | |
134 tree_postfix_expression::rvalue (int nargout) | |
135 { | |
136 octave_value_list retval; | |
137 | |
138 if (nargout > 1) | |
139 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
|
140 oper () . c_str ()); |
2980 | 141 else |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8011
diff
changeset
|
142 retval = rvalue1 (nargout); |
2980 | 143 |
144 return retval; | |
145 } | |
146 | |
147 octave_value | |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8011
diff
changeset
|
148 tree_postfix_expression::rvalue1 (int) |
2980 | 149 { |
150 octave_value retval; | |
151 | |
152 if (error_state) | |
153 return retval; | |
154 | |
155 if (op) | |
156 { | |
3539 | 157 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
|
158 { |
10614
d1194069e58c
optimize code handling ++,--
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
159 octave_lvalue ref = op->lvalue (); |
3962 | 160 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
161 if (! error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
162 { |
10614
d1194069e58c
optimize code handling ++,--
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
163 retval = ref.value (); |
3203 | 164 |
12960
43d78e103984
Use macro to start profiler blocks.
Daniel Kraft <d@domob.eu>
parents:
12920
diff
changeset
|
165 BEGIN_PROFILER_BLOCK ("postfix " + oper ()) |
10614
d1194069e58c
optimize code handling ++,--
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
166 ref.do_unary_op (etype); |
12960
43d78e103984
Use macro to start profiler blocks.
Daniel Kraft <d@domob.eu>
parents:
12920
diff
changeset
|
167 END_PROFILER_BLOCK |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
168 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
169 } |
3203 | 170 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
171 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
172 octave_value val = op->rvalue1 (); |
2980 | 173 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
174 if (! error_state && val.is_defined ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
175 { |
12960
43d78e103984
Use macro to start profiler blocks.
Daniel Kraft <d@domob.eu>
parents:
12920
diff
changeset
|
176 BEGIN_PROFILER_BLOCK ("postfix " + oper ()) |
12920
5d18231eee00
Extend profiling support to operators.
Daniel Kraft <d@domob.eu>
parents:
11586
diff
changeset
|
177 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
178 retval = ::do_unary_op (etype, val); |
2980 | 179 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
180 if (error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
181 retval = octave_value (); |
12960
43d78e103984
Use macro to start profiler blocks.
Daniel Kraft <d@domob.eu>
parents:
12920
diff
changeset
|
182 |
43d78e103984
Use macro to start profiler blocks.
Daniel Kraft <d@domob.eu>
parents:
12920
diff
changeset
|
183 END_PROFILER_BLOCK |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
184 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
185 } |
2980 | 186 } |
187 | |
188 return retval; | |
189 } | |
190 | |
5861 | 191 tree_expression * |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
192 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
|
193 symbol_table::context_id context) const |
5861 | 194 { |
195 tree_postfix_expression *new_pe | |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
196 = 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
|
197 line (), column (), etype); |
5861 | 198 |
199 new_pe->copy_base (*this); | |
200 | |
201 return new_pe; | |
202 } | |
203 | |
2980 | 204 void |
205 tree_postfix_expression::accept (tree_walker& tw) | |
206 { | |
207 tw.visit_postfix_expression (*this); | |
208 } |