Mercurial > octave
annotate libinterp/parse-tree/pt-binop.h @ 22022:278fc29b69ca
maint: Eliminate unnecessary double newline blocks (only whitespace changes).
* Figure.cc, annotation-dialog.cc, dialog.cc, dialog.h, files-dock-widget.cc,
find-files-dialog.cc, find-files-model.cc, file-editor-tab.cc, file-editor.cc,
find-dialog.cc, octave-qscintilla.cc, octave-txt-lexer.cc, main-window.cc,
main-window.h, octave-cmd.cc, octave-cmd.h, octave-dock-widget.cc,
octave-qt-link.cc, parser.h, webinfo.cc, settings-dialog.cc,
shortcut-manager.cc, shortcut-manager.h, welcome-wizard.cc, workspace-model.cc,
__ilu__.cc, __lin_interpn__.cc, besselj.cc, bsxfun.cc, cellfun.cc, conv2.cc,
data.cc, debug.cc, debug.h, dynamic-ld.cc, fft2.cc, file-io.cc,
ft-text-renderer.cc, gl-render.cc, gl2ps-print.cc, graphics.cc, graphics.in.h,
help.cc, jit-typeinfo.cc, jit-typeinfo.h, kron.cc, ls-ascii-helper.cc,
ls-hdf5.cc, ls-hdf5.h, ls-mat5.cc, max.cc, oct-map.cc, oct-map.h,
oct-stream.cc, octave-link.h, pr-output.cc, pt-jit.cc, qz.cc, sparse-xdiv.cc,
sparse-xpow.cc, strfind.cc, strfns.cc, symtab.h, toplev.cc, toplev.h,
typecast.cc, utils.cc, variables.cc, xdiv.h, xpow.cc, xpow.h, zfstream.cc,
__eigs__.cc, __init_fltk__.cc, audioread.cc, ccolamd.cc, chol.cc, qr.cc,
ov-base-diag.cc, ov-base-int.cc, ov-base-sparse.cc, ov-base.cc, ov-base.h,
ov-bool-mat.cc, ov-bool-mat.h, ov-bool-sparse.cc, ov-bool-sparse.h, ov-bool.cc,
ov-bool.h, ov-builtin.h, ov-cell.cc, ov-cell.h, ov-class.cc, ov-class.h,
ov-classdef.cc, ov-complex.cc, ov-complex.h, ov-cs-list.cc, ov-cs-list.h,
ov-cx-diag.cc, ov-cx-diag.h, ov-cx-mat.cc, ov-cx-mat.h, ov-cx-sparse.cc,
ov-cx-sparse.h, ov-dld-fcn.cc, ov-dld-fcn.h, ov-fcn-handle.h, ov-fcn-inline.h,
ov-float.cc, ov-float.h, ov-flt-complex.cc, ov-flt-complex.h,
ov-flt-cx-diag.cc, ov-flt-cx-diag.h, ov-flt-cx-mat.cc, ov-flt-cx-mat.h,
ov-flt-re-diag.cc, ov-flt-re-diag.h, ov-flt-re-mat.cc, ov-int16.cc,
ov-int32.cc, ov-int64.cc, ov-int8.cc, ov-intx.h, ov-lazy-idx.cc, ov-lazy-idx.h,
ov-mex-fcn.h, ov-null-mat.h, ov-perm.cc, ov-perm.h, ov-range.cc, ov-range.h,
ov-re-diag.cc, ov-re-diag.h, ov-re-mat.cc, ov-re-sparse.cc, ov-re-sparse.h,
ov-scalar.cc, ov-scalar.h, ov-str-mat.h, ov-struct.cc, ov-struct.h,
ov-type-conv.h, ov-uint16.cc, ov-uint32.cc, ov-uint64.cc, ov-uint8.cc,
ov-usr-fcn.cc, ov-usr-fcn.h, ov.h, op-cm-m.cc, op-fcm-fm.cc, op-fm-fm.cc,
op-int.h, op-m-m.cc, op-pm-template.cc, pt-binop.h, pt-select.cc, pt-stmt.cc,
pt-unop.h, Array-util.cc, Array.cc, Array.h, CColVector.cc, CMatrix.cc,
CMatrix.h, CSparse.cc, MArray.cc, MSparse.cc, MatrixType.cc, PermMatrix.cc,
Range.cc, Sparse-C.cc, Sparse.cc, dMatrix.cc, dim-vector.h, fCColVector.cc,
fCMatrix.cc, fMatrix.cc, fMatrix.h, idx-vector.cc, idx-vector.h, blaswrap.c,
f77-fcn.h, DASPK.cc, eigs-base.cc, hess.cc, lo-specfun.cc, oct-fftw.cc,
oct-norm.cc, oct-rand.cc, oct-rand.h, qr.cc, qrp.cc, randmtzig.cc,
randpoisson.cc, sparse-lu.cc, sparse-lu.h, sparse-qr.cc, Sparse-op-defs.h,
mx-inlines.cc, oct-env.h, cmd-edit.cc, f2c-main.c, lo-array-errwarn.cc,
lo-array-errwarn.h, lo-array-gripes.cc, lo-array-gripes.h, lo-ieee.h,
lo-regexp.cc, oct-binmap.h, oct-inttypes.cc, oct-inttypes.h, oct-sort.cc,
oct-sort.h, mkoctfile.in.cc:
maint: Eliminate unnecessary double newline blocks (only whitespace changes).
author | Rik <rik@octave.org> |
---|---|
date | Fri, 01 Jul 2016 19:48:35 -0700 |
parents | 1473547f50f5 |
children | bac0d6f07a3e |
rev | line source |
---|---|
2980 | 1 /* |
2 | |
19697
4197fc428c7d
maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents:
19327
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 | |
20791
f7084eae3318
maint: Use Octave coding conventions for #if statements.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
23 #if ! defined (octave_pt_binop_h) |
17822
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 |
21244
1473547f50f5
include octave-config.h in public header files
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
26 #include "octave-config.h" |
1473547f50f5
include octave-config.h in public header files
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
27 |
2980 | 28 #include <string> |
29 | |
30 class tree_walker; | |
31 | |
32 class octave_value; | |
33 class octave_value_list; | |
34 class octave_lvalue; | |
35 | |
36 #include "ov.h" | |
37 #include "pt-exp.h" | |
7336 | 38 #include "symtab.h" |
2980 | 39 |
40 // Binary expressions. | |
41 | |
42 class | |
43 tree_binary_expression : public tree_expression | |
44 { | |
45 public: | |
46 | |
47 tree_binary_expression (int l = -1, int c = -1, | |
10313 | 48 octave_value::binary_op t |
49 = 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
|
50 : tree_expression (l, c), op_lhs (0), op_rhs (0), etype (t), |
18127
d76f790b4eec
enable do_braindead_shortcircuit_evaluation by default and deprecate
John W. Eaton <jwe@octave.org>
parents:
17822
diff
changeset
|
51 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
|
52 braindead_shortcircuit_warning_issued (false) { } |
2980 | 53 |
54 tree_binary_expression (tree_expression *a, tree_expression *b, | |
10313 | 55 int l = -1, int c = -1, |
56 octave_value::binary_op t | |
57 = 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
|
58 : tree_expression (l, c), op_lhs (a), op_rhs (b), etype (t), |
18127
d76f790b4eec
enable do_braindead_shortcircuit_evaluation by default and deprecate
John W. Eaton <jwe@octave.org>
parents:
17822
diff
changeset
|
59 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
|
60 braindead_shortcircuit_warning_issued (false) { } |
2980 | 61 |
62 ~tree_binary_expression (void) | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
63 { |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
64 delete op_lhs; |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
65 delete op_rhs; |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
66 } |
2980 | 67 |
18127
d76f790b4eec
enable do_braindead_shortcircuit_evaluation by default and deprecate
John W. Eaton <jwe@octave.org>
parents:
17822
diff
changeset
|
68 void mark_braindead_shortcircuit (void) |
17787
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 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
|
71 { |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
72 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
|
73 |
18127
d76f790b4eec
enable do_braindead_shortcircuit_evaluation by default and deprecate
John W. Eaton <jwe@octave.org>
parents:
17822
diff
changeset
|
74 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
|
75 op_rhs->mark_braindead_shortcircuit (); |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
76 } |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
77 } |
11091
5677f3f7b5fa
Matlab compatible short-circuit behavior for & and | operators
John W. Eaton <jwe@octave.org>
parents:
10313
diff
changeset
|
78 |
4267 | 79 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
|
80 { |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
81 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
|
82 || (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
|
83 } |
4267 | 84 |
4023 | 85 bool is_binary_expression (void) const { return true; } |
86 | |
3933 | 87 bool rvalue_ok (void) const { return true; } |
2980 | 88 |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8011
diff
changeset
|
89 octave_value rvalue1 (int nargout = 1); |
2980 | 90 |
3010 | 91 octave_value_list rvalue (int nargout); |
2980 | 92 |
3523 | 93 std::string oper (void) const; |
2980 | 94 |
4023 | 95 octave_value::binary_op op_type (void) const { return etype; } |
96 | |
2980 | 97 tree_expression *lhs (void) { return op_lhs; } |
98 tree_expression *rhs (void) { return op_rhs; } | |
99 | |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
100 tree_expression *dup (symbol_table::scope_id scope, |
10313 | 101 symbol_table::context_id context) const; |
5861 | 102 |
2980 | 103 void accept (tree_walker& tw); |
104 | |
19327
91cd85a75705
Reduce profiling overhead using inlining and templates.
Julien Bect <julien.bect@supelec.fr>
parents:
18127
diff
changeset
|
105 std::string profiler_name (void) const { return "binary " + oper (); } |
91cd85a75705
Reduce profiling overhead using inlining and templates.
Julien Bect <julien.bect@supelec.fr>
parents:
18127
diff
changeset
|
106 |
2980 | 107 protected: |
108 | |
109 // The operands for the expression. | |
110 tree_expression *op_lhs; | |
111 tree_expression *op_rhs; | |
112 | |
113 private: | |
114 | |
115 // The type of the expression. | |
116 octave_value::binary_op etype; | |
2988 | 117 |
11091
5677f3f7b5fa
Matlab compatible short-circuit behavior for & and | operators
John W. Eaton <jwe@octave.org>
parents:
10313
diff
changeset
|
118 // 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
|
119 // or WHILE statement. |
5677f3f7b5fa
Matlab compatible short-circuit behavior for & and | operators
John W. Eaton <jwe@octave.org>
parents:
10313
diff
changeset
|
120 bool eligible_for_braindead_shortcircuit; |
5677f3f7b5fa
Matlab compatible short-circuit behavior for & and | operators
John W. Eaton <jwe@octave.org>
parents:
10313
diff
changeset
|
121 |
18127
d76f790b4eec
enable do_braindead_shortcircuit_evaluation by default and deprecate
John W. Eaton <jwe@octave.org>
parents:
17822
diff
changeset
|
122 // 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
|
123 // for this operator. |
d76f790b4eec
enable do_braindead_shortcircuit_evaluation by default and deprecate
John W. Eaton <jwe@octave.org>
parents:
17822
diff
changeset
|
124 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
|
125 |
d76f790b4eec
enable do_braindead_shortcircuit_evaluation by default and deprecate
John W. Eaton <jwe@octave.org>
parents:
17822
diff
changeset
|
126 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
|
127 |
2988 | 128 // No copying! |
129 | |
130 tree_binary_expression (const tree_binary_expression&); | |
131 | |
132 tree_binary_expression& operator = (const tree_binary_expression&); | |
2980 | 133 }; |
134 | |
135 // Boolean expressions. | |
136 | |
137 class | |
138 tree_boolean_expression : public tree_binary_expression | |
139 { | |
140 public: | |
141 | |
142 enum type | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
143 { |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
144 unknown, |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
145 bool_and, |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
146 bool_or |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
147 }; |
2980 | 148 |
149 tree_boolean_expression (int l = -1, int c = -1, type t = unknown) | |
150 : tree_binary_expression (l, c), etype (t) { } | |
151 | |
152 tree_boolean_expression (tree_expression *a, tree_expression *b, | |
10313 | 153 int l = -1, int c = -1, type t = unknown) |
2980 | 154 : tree_binary_expression (a, b, l, c), etype (t) { } |
155 | |
156 ~tree_boolean_expression (void) { } | |
157 | |
4023 | 158 bool is_boolean_expression (void) const { return true; } |
159 | |
3933 | 160 bool rvalue_ok (void) const { return true; } |
2980 | 161 |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8011
diff
changeset
|
162 octave_value rvalue1 (int nargout = 1); |
2980 | 163 |
164 octave_value_list rvalue (int nargout); | |
165 | |
3523 | 166 std::string oper (void) const; |
2980 | 167 |
4023 | 168 type op_type (void) const { return etype; } |
169 | |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
170 tree_expression *dup (symbol_table::scope_id scope, |
10313 | 171 symbol_table::context_id context) const; |
5861 | 172 |
2980 | 173 private: |
174 | |
175 // The type of the expression. | |
176 type etype; | |
2988 | 177 |
178 // No copying! | |
179 | |
180 tree_boolean_expression (const tree_boolean_expression&); | |
181 | |
182 tree_boolean_expression& operator = (const tree_boolean_expression&); | |
2980 | 183 }; |
184 | |
185 #endif |