GNU Octave 7.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
pt-binop.h
Go to the documentation of this file.
1////////////////////////////////////////////////////////////////////////
2//
3// Copyright (C) 1996-2022 The Octave Project Developers
4//
5// See the file COPYRIGHT.md in the top-level directory of this
6// distribution or <https://octave.org/copyright/>.
7//
8// This file is part of Octave.
9//
10// Octave is free software: you can redistribute it and/or modify it
11// under the terms of the GNU General Public License as published by
12// the Free Software Foundation, either version 3 of the License, or
13// (at your option) any later version.
14//
15// Octave is distributed in the hope that it will be useful, but
16// WITHOUT ANY WARRANTY; without even the implied warranty of
17// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18// GNU General Public License for more details.
19//
20// You should have received a copy of the GNU General Public License
21// along with Octave; see the file COPYING. If not, see
22// <https://www.gnu.org/licenses/>.
23//
24////////////////////////////////////////////////////////////////////////
25
26#if ! defined (octave_pt_binop_h)
27#define octave_pt_binop_h 1
28
29#include "octave-config.h"
30
31#include <string>
32
33class octave_value;
35
36#include "ov.h"
37#include "pt-exp.h"
38#include "pt-walk.h"
39
40namespace octave
41{
42 class symbol_scope;
43
44 // Binary expressions.
45
47 {
48 public:
49
50 tree_binary_expression (int l = -1, int c = -1,
53 : tree_expression (l, c), m_lhs (nullptr), m_rhs (nullptr), m_etype (t),
56
58 int l = -1, int c = -1,
61 : tree_expression (l, c), m_lhs (a), m_rhs (b), m_etype (t),
64
65 // No copying!
66
68
70
72 {
73 delete m_lhs;
74 delete m_rhs;
75 }
76
78 {
80 {
82
85 }
86 }
87
88 bool is_binary_expression (void) const { return true; }
89
90 bool rvalue_ok (void) const { return true; }
91
92 std::string oper (void) const;
93
94 octave_value::binary_op op_type (void) const { return m_etype; }
95
96 tree_expression * lhs (void) { return m_lhs; }
97 tree_expression * rhs (void) { return m_rhs; }
98
100 {
102 }
103
104 tree_expression * dup (symbol_scope& scope) const;
105
106 octave_value evaluate (tree_evaluator&, int nargout = 1);
107
109 {
110 return ovl (evaluate (tw, nargout));
111 }
112
114 {
115 tw.visit_binary_expression (*this);
116 }
117
118 std::string profiler_name (void) const { return "binary " + oper (); }
119
120 void matlab_style_short_circuit_warning (const char *op);
121
122 protected:
123
124 // The operands for the expression.
127
128 private:
129
130 // The type of the expression.
132
133 // TRUE if this is an | or & expression in the condition of an IF
134 // or WHILE statement.
136
137 // TRUE if we have already issued a warning about short circuiting
138 // for this operator.
140 };
141
142 // Boolean expressions.
143
145 {
146 public:
147
148 enum type
149 {
152 bool_or
153 };
154
155 tree_boolean_expression (int l = -1, int c = -1, type t = unknown)
156 : tree_binary_expression (l, c), m_etype (t) { }
157
159 int l = -1, int c = -1, type t = unknown)
160 : tree_binary_expression (a, b, l, c), m_etype (t) { }
161
162 // No copying!
163
165
167
168 ~tree_boolean_expression (void) = default;
169
170 bool is_boolean_expression (void) const { return true; }
171
172 bool rvalue_ok (void) const { return true; }
173
174 std::string oper (void) const;
175
176 type op_type (void) const { return m_etype; }
177
178 tree_expression * dup (symbol_scope& scope) const;
179
180 octave_value evaluate (tree_evaluator&, int nargout = 1);
181
183 {
184 return ovl (evaluate (tw, nargout));
185 }
186
188 {
189 tw.visit_boolean_expression (*this);
190 }
191
192 private:
193
194 // The type of the expression.
196 };
197}
198
199#endif
tree_binary_expression(tree_expression *a, tree_expression *b, int l=-1, int c=-1, octave_value::binary_op t=octave_value::unknown_binary_op)
Definition: pt-binop.h:57
bool is_binary_expression(void) const
Definition: pt-binop.h:88
void matlab_style_short_circuit_warning(const char *op)
Definition: pt-binop.cc:43
octave_value evaluate(tree_evaluator &, int nargout=1)
Definition: pt-binop.cc:72
tree_binary_expression & operator=(const tree_binary_expression &)=delete
tree_expression * m_rhs
Definition: pt-binop.h:126
tree_expression * lhs(void)
Definition: pt-binop.h:96
void mark_braindead_shortcircuit(void)
Definition: pt-binop.h:77
tree_expression * rhs(void)
Definition: pt-binop.h:97
void accept(tree_walker &tw)
Definition: pt-binop.h:113
octave_value::binary_op op_type(void) const
Definition: pt-binop.h:94
tree_binary_expression(const tree_binary_expression &)=delete
tree_expression * m_lhs
Definition: pt-binop.h:125
octave_value_list evaluate_n(tree_evaluator &tw, int nargout=1)
Definition: pt-binop.h:108
bool rvalue_ok(void) const
Definition: pt-binop.h:90
octave_value::binary_op m_etype
Definition: pt-binop.h:131
tree_binary_expression(int l=-1, int c=-1, octave_value::binary_op t=octave_value::unknown_binary_op)
Definition: pt-binop.h:50
std::string profiler_name(void) const
Definition: pt-binop.h:118
tree_expression * dup(symbol_scope &scope) const
Definition: pt-binop.cc:59
std::string oper(void) const
Definition: pt-binop.cc:53
bool is_eligible_for_braindead_shortcircuit(void) const
Definition: pt-binop.h:99
tree_boolean_expression(tree_expression *a, tree_expression *b, int l=-1, int c=-1, type t=unknown)
Definition: pt-binop.h:158
bool is_boolean_expression(void) const
Definition: pt-binop.h:170
~tree_boolean_expression(void)=default
std::string oper(void) const
Definition: pt-binop.cc:151
tree_boolean_expression & operator=(const tree_boolean_expression &)=delete
octave_value_list evaluate_n(tree_evaluator &tw, int nargout=1)
Definition: pt-binop.h:182
type op_type(void) const
Definition: pt-binop.h:176
tree_expression * dup(symbol_scope &scope) const
Definition: pt-binop.cc:173
void accept(tree_walker &tw)
Definition: pt-binop.h:187
tree_boolean_expression(const tree_boolean_expression &)=delete
tree_boolean_expression(int l=-1, int c=-1, type t=unknown)
Definition: pt-binop.h:155
bool rvalue_ok(void) const
Definition: pt-binop.h:172
octave_value evaluate(tree_evaluator &, int nargout=1)
Definition: pt-binop.cc:186
virtual void mark_braindead_shortcircuit(void)
Definition: pt-exp.h:109
virtual void visit_boolean_expression(tree_boolean_expression &)
Definition: pt-walk.cc:147
virtual void visit_binary_expression(tree_binary_expression &)
Definition: pt-walk.cc:134
binary_op
Definition: ov.h:90
@ unknown_binary_op
Definition: ov.h:111
@ op_el_or
Definition: ov.h:108
@ op_el_and
Definition: ov.h:107
octave_value_list ovl(const OV_Args &... args)
Construct an octave_value_list with less typing.
Definition: ovl.h:211