Mercurial > hg > octave-nkf
annotate libinterp/parse-tree/pt-unop.cc @ 20830:b65888ec820e draft default tip gccjit
dmalcom gcc jit import
author | Stefan Mahr <dac922@gmx.de> |
---|---|
date | Fri, 27 Feb 2015 16:59:36 +0100 |
parents | f90c8372b7ba |
children |
rev | line source |
---|---|
2980 | 1 /* |
2 | |
19898
4197fc428c7d
maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents:
19792
diff
changeset
|
3 Copyright (C) 1996-2015 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) | |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
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 (op) | |
66 { | |
3539 | 67 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
|
68 { |
10614
d1194069e58c
optimize code handling ++,--
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
69 octave_lvalue ref = op->lvalue (); |
3962 | 70 |
20762
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
19898
diff
changeset
|
71 BEGIN_PROFILER_BLOCK (tree_prefix_expression) |
19792
be7ac98fab43
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
19520
diff
changeset
|
72 |
20762
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
19898
diff
changeset
|
73 ref.do_unary_op (etype); |
3203 | 74 |
20762
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
19898
diff
changeset
|
75 retval = ref.value (); |
12960
43d78e103984
Use macro to start profiler blocks.
Daniel Kraft <d@domob.eu>
parents:
12920
diff
changeset
|
76 |
20762
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
19898
diff
changeset
|
77 END_PROFILER_BLOCK |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
78 } |
3203 | 79 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
80 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
81 octave_value val = op->rvalue1 (); |
2980 | 82 |
20762
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
19898
diff
changeset
|
83 if (val.is_defined ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
84 { |
20762
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
19898
diff
changeset
|
85 BEGIN_PROFILER_BLOCK (tree_prefix_expression) |
12920
5d18231eee00
Extend profiling support to operators.
Daniel Kraft <d@domob.eu>
parents:
11586
diff
changeset
|
86 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
87 // 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
|
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 |
12960
43d78e103984
Use macro to start profiler blocks.
Daniel Kraft <d@domob.eu>
parents:
12920
diff
changeset
|
94 END_PROFILER_BLOCK |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
95 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
96 } |
2980 | 97 } |
98 | |
99 return retval; | |
100 } | |
101 | |
5861 | 102 tree_expression * |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
103 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
|
104 symbol_table::context_id context) const |
5861 | 105 { |
106 tree_prefix_expression *new_pe | |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
107 = 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
|
108 line (), column (), etype); |
5861 | 109 |
110 new_pe->copy_base (*this); | |
111 | |
112 return new_pe; | |
113 } | |
114 | |
2980 | 115 void |
116 tree_prefix_expression::accept (tree_walker& tw) | |
117 { | |
118 tw.visit_prefix_expression (*this); | |
119 } | |
120 | |
121 // Postfix expressions. | |
122 | |
123 octave_value_list | |
124 tree_postfix_expression::rvalue (int nargout) | |
125 { | |
126 octave_value_list retval; | |
127 | |
128 if (nargout > 1) | |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
129 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
|
130 oper () . c_str ()); |
2980 | 131 else |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8011
diff
changeset
|
132 retval = rvalue1 (nargout); |
2980 | 133 |
134 return retval; | |
135 } | |
136 | |
137 octave_value | |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8011
diff
changeset
|
138 tree_postfix_expression::rvalue1 (int) |
2980 | 139 { |
140 octave_value retval; | |
141 | |
142 if (op) | |
143 { | |
3539 | 144 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
|
145 { |
10614
d1194069e58c
optimize code handling ++,--
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
146 octave_lvalue ref = op->lvalue (); |
3962 | 147 |
20762
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
19898
diff
changeset
|
148 retval = ref.value (); |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
19898
diff
changeset
|
149 |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
19898
diff
changeset
|
150 BEGIN_PROFILER_BLOCK (tree_postfix_expression) |
3203 | 151 |
20762
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
19898
diff
changeset
|
152 ref.do_unary_op (etype); |
19520
91cd85a75705
Reduce profiling overhead using inlining and templates.
Julien Bect <julien.bect@supelec.fr>
parents:
17744
diff
changeset
|
153 |
20762
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
19898
diff
changeset
|
154 END_PROFILER_BLOCK |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
155 } |
3203 | 156 else |
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 octave_value val = op->rvalue1 (); |
2980 | 159 |
20762
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
19898
diff
changeset
|
160 if (val.is_defined ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
161 { |
19520
91cd85a75705
Reduce profiling overhead using inlining and templates.
Julien Bect <julien.bect@supelec.fr>
parents:
17744
diff
changeset
|
162 BEGIN_PROFILER_BLOCK (tree_postfix_expression) |
12920
5d18231eee00
Extend profiling support to operators.
Daniel Kraft <d@domob.eu>
parents:
11586
diff
changeset
|
163 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
164 retval = ::do_unary_op (etype, val); |
2980 | 165 |
12960
43d78e103984
Use macro to start profiler blocks.
Daniel Kraft <d@domob.eu>
parents:
12920
diff
changeset
|
166 END_PROFILER_BLOCK |
10315
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 } |
2980 | 169 } |
170 | |
171 return retval; | |
172 } | |
173 | |
5861 | 174 tree_expression * |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
175 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
|
176 symbol_table::context_id context) const |
5861 | 177 { |
178 tree_postfix_expression *new_pe | |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
179 = 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
|
180 line (), column (), etype); |
5861 | 181 |
182 new_pe->copy_base (*this); | |
183 | |
184 return new_pe; | |
185 } | |
186 | |
2980 | 187 void |
188 tree_postfix_expression::accept (tree_walker& tw) | |
189 { | |
190 tw.visit_postfix_expression (*this); | |
191 } |