Mercurial > hg > octave-nkf
annotate libinterp/parse-tree/pt-binop.h @ 20441:83792dd9bcc1
Use in-place operators in m-files where possible.
* scripts/audio/@audioplayer/set.m, scripts/audio/@audiorecorder/set.m,
scripts/audio/mu2lin.m, scripts/elfun/cosd.m, scripts/general/del2.m,
scripts/general/profexplore.m, scripts/general/quadl.m, scripts/general/rat.m,
scripts/general/rotdim.m, scripts/help/get_first_help_sentence.m,
scripts/help/private/__strip_html_tags__.m, scripts/image/cubehelix.m,
scripts/io/textread.m, scripts/linear-algebra/duplication_matrix.m,
scripts/linear-algebra/housh.m, scripts/linear-algebra/krylov.m,
scripts/linear-algebra/logm.m, scripts/linear-algebra/normest.m,
scripts/linear-algebra/onenormest.m, scripts/optimization/fminsearch.m,
scripts/optimization/lsqnonneg.m, scripts/optimization/qp.m,
scripts/plot/appearance/annotation.m, scripts/plot/appearance/axis.m,
scripts/plot/appearance/legend.m, scripts/plot/appearance/specular.m,
scripts/plot/draw/colorbar.m, scripts/plot/draw/hist.m,
scripts/plot/draw/plotmatrix.m, scripts/plot/draw/private/__stem__.m,
scripts/plot/util/__actual_axis_position__.m,
scripts/plot/util/__gnuplot_drawnow__.m, scripts/plot/util/findobj.m,
scripts/plot/util/print.m, scripts/plot/util/private/__go_draw_axes__.m,
scripts/plot/util/private/__print_parse_opts__.m, scripts/plot/util/rotate.m,
scripts/polynomial/pchip.m, scripts/polynomial/polyaffine.m,
scripts/polynomial/polyder.m, scripts/polynomial/private/__splinefit__.m,
scripts/polynomial/residue.m, scripts/signal/arch_fit.m,
scripts/signal/arch_rnd.m, scripts/signal/bartlett.m,
scripts/signal/blackman.m, scripts/signal/freqz.m, scripts/signal/hamming.m,
scripts/signal/hanning.m, scripts/signal/spectral_adf.m,
scripts/signal/spectral_xdf.m, scripts/signal/stft.m,
scripts/sparse/bicgstab.m, scripts/sparse/cgs.m,
scripts/sparse/private/__sprand_impl__.m, scripts/sparse/qmr.m,
scripts/sparse/sprandsym.m, scripts/sparse/svds.m, scripts/specfun/legendre.m,
scripts/special-matrix/gallery.m, scripts/statistics/base/gls.m,
scripts/statistics/models/logistic_regression.m,
scripts/statistics/tests/kruskal_wallis_test.m,
scripts/statistics/tests/manova.m, scripts/statistics/tests/wilcoxon_test.m,
scripts/time/datevec.m:
Use in-place operators in m-files where possible.
author | Rik <rik@octave.org> |
---|---|
date | Tue, 26 May 2015 21:07:42 -0700 |
parents | 4197fc428c7d |
children |
rev | line source |
---|---|
2980 | 1 /* |
2 | |
19898
4197fc428c7d
maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents:
19520
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 | |
17822
ebb3ef964372
maint: Use common #define syntax "octave_filename_h" in h_files.
Rik <rik@octave.org>
parents:
17787
diff
changeset
|
23 #if !defined (octave_pt_binop_h) |
ebb3ef964372
maint: Use common #define syntax "octave_filename_h" in h_files.
Rik <rik@octave.org>
parents:
17787
diff
changeset
|
24 #define octave_pt_binop_h 1 |
2980 | 25 |
26 #include <string> | |
27 | |
28 class tree_walker; | |
29 | |
30 class octave_value; | |
31 class octave_value_list; | |
32 class octave_lvalue; | |
33 | |
34 #include "ov.h" | |
35 #include "pt-exp.h" | |
7336 | 36 #include "symtab.h" |
2980 | 37 |
38 // Binary expressions. | |
39 | |
40 class | |
41 tree_binary_expression : public tree_expression | |
42 { | |
43 public: | |
44 | |
45 tree_binary_expression (int l = -1, int c = -1, | |
10313 | 46 octave_value::binary_op t |
47 = octave_value::unknown_binary_op) | |
11091
5677f3f7b5fa
Matlab compatible short-circuit behavior for & and | operators
John W. Eaton <jwe@octave.org>
parents:
10313
diff
changeset
|
48 : tree_expression (l, c), op_lhs (0), op_rhs (0), etype (t), |
18126
d76f790b4eec
enable do_braindead_shortcircuit_evaluation by default and deprecate
John W. Eaton <jwe@octave.org>
parents:
17822
diff
changeset
|
49 eligible_for_braindead_shortcircuit (false), |
d76f790b4eec
enable do_braindead_shortcircuit_evaluation by default and deprecate
John W. Eaton <jwe@octave.org>
parents:
17822
diff
changeset
|
50 braindead_shortcircuit_warning_issued (false) { } |
2980 | 51 |
52 tree_binary_expression (tree_expression *a, tree_expression *b, | |
10313 | 53 int l = -1, int c = -1, |
54 octave_value::binary_op t | |
55 = octave_value::unknown_binary_op) | |
11091
5677f3f7b5fa
Matlab compatible short-circuit behavior for & and | operators
John W. Eaton <jwe@octave.org>
parents:
10313
diff
changeset
|
56 : tree_expression (l, c), op_lhs (a), op_rhs (b), etype (t), |
18126
d76f790b4eec
enable do_braindead_shortcircuit_evaluation by default and deprecate
John W. Eaton <jwe@octave.org>
parents:
17822
diff
changeset
|
57 eligible_for_braindead_shortcircuit (false), |
d76f790b4eec
enable do_braindead_shortcircuit_evaluation by default and deprecate
John W. Eaton <jwe@octave.org>
parents:
17822
diff
changeset
|
58 braindead_shortcircuit_warning_issued (false) { } |
2980 | 59 |
60 ~tree_binary_expression (void) | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
61 { |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
62 delete op_lhs; |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
63 delete op_rhs; |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
64 } |
2980 | 65 |
18126
d76f790b4eec
enable do_braindead_shortcircuit_evaluation by default and deprecate
John W. Eaton <jwe@octave.org>
parents:
17822
diff
changeset
|
66 void mark_braindead_shortcircuit (void) |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
67 { |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
68 if (etype == octave_value::op_el_and || etype == octave_value::op_el_or) |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
69 { |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
70 eligible_for_braindead_shortcircuit = true; |
11091
5677f3f7b5fa
Matlab compatible short-circuit behavior for & and | operators
John W. Eaton <jwe@octave.org>
parents:
10313
diff
changeset
|
71 |
18126
d76f790b4eec
enable do_braindead_shortcircuit_evaluation by default and deprecate
John W. Eaton <jwe@octave.org>
parents:
17822
diff
changeset
|
72 op_lhs->mark_braindead_shortcircuit (); |
d76f790b4eec
enable do_braindead_shortcircuit_evaluation by default and deprecate
John W. Eaton <jwe@octave.org>
parents:
17822
diff
changeset
|
73 op_rhs->mark_braindead_shortcircuit (); |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
74 } |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
75 } |
11091
5677f3f7b5fa
Matlab compatible short-circuit behavior for & and | operators
John W. Eaton <jwe@octave.org>
parents:
10313
diff
changeset
|
76 |
4267 | 77 bool has_magic_end (void) const |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
78 { |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
79 return ((op_lhs && op_lhs->has_magic_end ()) |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
80 || (op_rhs && op_rhs->has_magic_end ())); |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
81 } |
4267 | 82 |
4023 | 83 bool is_binary_expression (void) const { return true; } |
84 | |
3933 | 85 bool rvalue_ok (void) const { return true; } |
2980 | 86 |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8011
diff
changeset
|
87 octave_value rvalue1 (int nargout = 1); |
2980 | 88 |
3010 | 89 octave_value_list rvalue (int nargout); |
2980 | 90 |
3523 | 91 std::string oper (void) const; |
2980 | 92 |
4023 | 93 octave_value::binary_op op_type (void) const { return etype; } |
94 | |
2980 | 95 tree_expression *lhs (void) { return op_lhs; } |
96 tree_expression *rhs (void) { return op_rhs; } | |
97 | |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
98 tree_expression *dup (symbol_table::scope_id scope, |
10313 | 99 symbol_table::context_id context) const; |
5861 | 100 |
2980 | 101 void accept (tree_walker& tw); |
102 | |
19520
91cd85a75705
Reduce profiling overhead using inlining and templates.
Julien Bect <julien.bect@supelec.fr>
parents:
18126
diff
changeset
|
103 std::string profiler_name (void) const { return "binary " + oper (); } |
91cd85a75705
Reduce profiling overhead using inlining and templates.
Julien Bect <julien.bect@supelec.fr>
parents:
18126
diff
changeset
|
104 |
91cd85a75705
Reduce profiling overhead using inlining and templates.
Julien Bect <julien.bect@supelec.fr>
parents:
18126
diff
changeset
|
105 |
2980 | 106 protected: |
107 | |
108 // The operands for the expression. | |
109 tree_expression *op_lhs; | |
110 tree_expression *op_rhs; | |
111 | |
112 private: | |
113 | |
114 // The type of the expression. | |
115 octave_value::binary_op etype; | |
2988 | 116 |
11091
5677f3f7b5fa
Matlab compatible short-circuit behavior for & and | operators
John W. Eaton <jwe@octave.org>
parents:
10313
diff
changeset
|
117 // TRUE if this is an | or & expression in the condition of an IF |
5677f3f7b5fa
Matlab compatible short-circuit behavior for & and | operators
John W. Eaton <jwe@octave.org>
parents:
10313
diff
changeset
|
118 // or WHILE statement. |
5677f3f7b5fa
Matlab compatible short-circuit behavior for & and | operators
John W. Eaton <jwe@octave.org>
parents:
10313
diff
changeset
|
119 bool eligible_for_braindead_shortcircuit; |
5677f3f7b5fa
Matlab compatible short-circuit behavior for & and | operators
John W. Eaton <jwe@octave.org>
parents:
10313
diff
changeset
|
120 |
18126
d76f790b4eec
enable do_braindead_shortcircuit_evaluation by default and deprecate
John W. Eaton <jwe@octave.org>
parents:
17822
diff
changeset
|
121 // TRUE if we have already issued a warning about short circuiting |
d76f790b4eec
enable do_braindead_shortcircuit_evaluation by default and deprecate
John W. Eaton <jwe@octave.org>
parents:
17822
diff
changeset
|
122 // for this operator. |
d76f790b4eec
enable do_braindead_shortcircuit_evaluation by default and deprecate
John W. Eaton <jwe@octave.org>
parents:
17822
diff
changeset
|
123 bool braindead_shortcircuit_warning_issued; |
d76f790b4eec
enable do_braindead_shortcircuit_evaluation by default and deprecate
John W. Eaton <jwe@octave.org>
parents:
17822
diff
changeset
|
124 |
d76f790b4eec
enable do_braindead_shortcircuit_evaluation by default and deprecate
John W. Eaton <jwe@octave.org>
parents:
17822
diff
changeset
|
125 void matlab_style_short_circuit_warning (const char *op); |
d76f790b4eec
enable do_braindead_shortcircuit_evaluation by default and deprecate
John W. Eaton <jwe@octave.org>
parents:
17822
diff
changeset
|
126 |
2988 | 127 // No copying! |
128 | |
129 tree_binary_expression (const tree_binary_expression&); | |
130 | |
131 tree_binary_expression& operator = (const tree_binary_expression&); | |
2980 | 132 }; |
133 | |
134 // Boolean expressions. | |
135 | |
136 class | |
137 tree_boolean_expression : public tree_binary_expression | |
138 { | |
139 public: | |
140 | |
141 enum type | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
142 { |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
143 unknown, |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
144 bool_and, |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
145 bool_or |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
146 }; |
2980 | 147 |
148 tree_boolean_expression (int l = -1, int c = -1, type t = unknown) | |
149 : tree_binary_expression (l, c), etype (t) { } | |
150 | |
151 tree_boolean_expression (tree_expression *a, tree_expression *b, | |
10313 | 152 int l = -1, int c = -1, type t = unknown) |
2980 | 153 : tree_binary_expression (a, b, l, c), etype (t) { } |
154 | |
155 ~tree_boolean_expression (void) { } | |
156 | |
4023 | 157 bool is_boolean_expression (void) const { return true; } |
158 | |
3933 | 159 bool rvalue_ok (void) const { return true; } |
2980 | 160 |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8011
diff
changeset
|
161 octave_value rvalue1 (int nargout = 1); |
2980 | 162 |
163 octave_value_list rvalue (int nargout); | |
164 | |
3523 | 165 std::string oper (void) const; |
2980 | 166 |
4023 | 167 type op_type (void) const { return etype; } |
168 | |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
169 tree_expression *dup (symbol_table::scope_id scope, |
10313 | 170 symbol_table::context_id context) const; |
5861 | 171 |
2980 | 172 private: |
173 | |
174 // The type of the expression. | |
175 type etype; | |
2988 | 176 |
177 // No copying! | |
178 | |
179 tree_boolean_expression (const tree_boolean_expression&); | |
180 | |
181 tree_boolean_expression& operator = (const tree_boolean_expression&); | |
2980 | 182 }; |
183 | |
184 #endif |