GNU Octave 11.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 
Loading...
Searching...
No Matches
pt-binop.h
Go to the documentation of this file.
1////////////////////////////////////////////////////////////////////////
2//
3// Copyright (C) 1996-2026 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
41
42class symbol_scope;
43
44// Binary expressions.
45
46class OCTINTERP_API tree_binary_expression : public tree_expression
47{
48public:
49
51 : m_lhs (nullptr), m_rhs (nullptr), m_etype (t), m_preserve_operands (false)
52 { }
53
55 : m_lhs (a), m_op_tok (op_tok), m_rhs (b), m_etype (t), m_preserve_operands (false)
56 { }
57
58 OCTAVE_DISABLE_COPY_MOVE (tree_binary_expression)
59
61 {
62 if (! m_preserve_operands)
63 {
64 delete m_lhs;
65 delete m_rhs;
66 }
67 }
68
69 void preserve_operands () { m_preserve_operands = true; }
70
71 bool is_binary_expression () const { return true; }
72
73 filepos beg_pos () const { return m_lhs->beg_pos (); }
74 filepos end_pos () const { return m_rhs->end_pos (); }
75
76 comment_list leading_comments () const { return m_lhs->leading_comments (); }
77 comment_list trailing_comments () const { return m_rhs->trailing_comments (); }
78
79 bool rvalue_ok () const { return true; }
80
81 OCTAVE_DEPRECATED (11, "use tree_binary_expression::op_str instead")
82 std::string oper () const { return op_str (); }
83
84 std::string op_str () const;
85
86 octave_value::binary_op op_type () const { return m_etype; }
87
88 tree_expression * lhs () { return m_lhs; }
89
90 token op_token () const { return m_op_tok; }
91
92 tree_expression * rhs () { return m_rhs; }
93
94 void lhs (tree_expression *expr) { m_lhs = expr; }
95 void rhs (tree_expression *expr) { m_rhs = expr; }
96
97 tree_expression * dup (symbol_scope& scope) const;
98
99 octave_value evaluate (tree_evaluator&, int nargout = 1);
100
102 {
103 return ovl (evaluate (tw, nargout));
104 }
105
107 {
108 tw.visit_binary_expression (*this);
109 }
110
111 std::string profiler_name () const { return "binary " + op_str (); }
112
113 void matlab_style_short_circuit_warning (const char *op);
114
115 virtual bool is_braindead () const { return false; }
116
117protected:
118
119 // The operands and operator for the expression.
121
123
125
126private:
127
128 // The type of the expression.
130
131 // If TRUE, don't delete m_lhs and m_rhs in destructor;
132 bool m_preserve_operands;
133};
134
137{
138public:
139
143
144 OCTAVE_DISABLE_CONSTRUCT_COPY_MOVE (tree_braindead_shortcircuit_binary_expression)
145
147
148 tree_expression * dup (symbol_scope& scope) const;
149
150 octave_value evaluate (tree_evaluator&, int nargout = 1);
151
153
154 bool is_braindead () const { return true; }
155};
156
157// Boolean expressions.
158
160{
161public:
162
163 enum type
164 {
167 bool_or
168 };
169
170 tree_boolean_expression (type t = unknown) : m_etype (t) { }
171
173 : tree_binary_expression (a, op_tok, b), m_etype (t)
174 { }
175
176 OCTAVE_DISABLE_COPY_MOVE (tree_boolean_expression)
177
179
180 bool is_boolean_expression () const { return true; }
181
182 bool rvalue_ok () const { return true; }
183
184 OCTAVE_DEPRECATED (11, "use tree_binary_expression::op_str instead")
185 std::string oper () const { return op_str (); }
186
187 std::string op_str () const;
188
189 type op_type () const { return m_etype; }
190
191 tree_expression * dup (symbol_scope& scope) const;
192
193 octave_value evaluate (tree_evaluator&, int nargout = 1);
194
196 {
197 return ovl (evaluate (tw, nargout));
198 }
199
201 {
202 tw.visit_boolean_expression (*this);
203 }
204
205private:
206
207 // The type of the expression.
208 type m_etype;
209};
210
211OCTAVE_END_NAMESPACE(octave)
212
213#endif
binary_op
Definition ov.h:92
@ unknown_binary_op
Definition ov.h:113
Definition token.h:42
token op_token() const
Definition pt-binop.h:90
tree_expression * m_lhs
Definition pt-binop.h:120
tree_binary_expression(octave_value::binary_op t=octave_value::unknown_binary_op)
Definition pt-binop.h:50
octave_value::binary_op op_type() const
Definition pt-binop.h:86
tree_binary_expression(tree_expression *a, const token &op_tok, tree_expression *b, octave_value::binary_op t=octave_value::unknown_binary_op)
Definition pt-binop.h:54
filepos beg_pos() const
Definition pt-binop.h:73
tree_expression * lhs()
Definition pt-binop.h:88
comment_list leading_comments() const
Definition pt-binop.h:76
tree_expression * rhs()
Definition pt-binop.h:92
octave_value_list evaluate_n(tree_evaluator &tw, int nargout=1)
Definition pt-binop.h:101
bool is_binary_expression() const
Definition pt-binop.h:71
filepos end_pos() const
Definition pt-binop.h:74
tree_expression * m_rhs
Definition pt-binop.h:124
void rhs(tree_expression *expr)
Definition pt-binop.h:95
void accept(tree_walker &tw)
Definition pt-binop.h:106
comment_list trailing_comments() const
Definition pt-binop.h:77
virtual bool is_braindead() const
Definition pt-binop.h:115
void lhs(tree_expression *expr)
Definition pt-binop.h:94
bool rvalue_ok() const
Definition pt-binop.h:79
std::string profiler_name() const
Definition pt-binop.h:111
void accept(tree_walker &tw)
Definition pt-binop.h:200
bool rvalue_ok() const
Definition pt-binop.h:182
tree_boolean_expression(type t=unknown)
Definition pt-binop.h:170
octave_value_list evaluate_n(tree_evaluator &tw, int nargout=1)
Definition pt-binop.h:195
~tree_boolean_expression()=default
tree_boolean_expression(tree_expression *a, const token &op_tok, tree_expression *b, type t=unknown)
Definition pt-binop.h:172
type op_type() const
Definition pt-binop.h:189
bool is_boolean_expression() const
Definition pt-binop.h:180
tree_braindead_shortcircuit_binary_expression(tree_expression *a, const token &op_tok, tree_expression *b, octave_value::binary_op t)
Definition pt-binop.h:140
virtual octave_value evaluate(tree_evaluator &tw, int nargout=1)=0
virtual std::string op_str() const
Definition pt-exp.h:112
virtual tree_expression * dup(symbol_scope &scope) const =0
virtual void visit_boolean_expression(tree_boolean_expression &)
Definition pt-walk.cc:156
virtual void visit_binary_expression(tree_binary_expression &)
Definition pt-walk.cc:142
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
OCTAVE_DEPRECATED(11, "") typedef bool(*b_d_Mapper)(double)
octave_value_list ovl(const OV_Args &... args)
Construct an octave_value_list with less typing.
Definition ovl.h:217