GNU Octave 10.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-2025 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
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 token operator_token () const { return m_op_tok; }
70
71 void preserve_operands () { m_preserve_operands = true; }
72
73 bool is_binary_expression () const { return true; }
74
75 filepos beg_pos () const { return m_lhs->beg_pos (); }
76 filepos end_pos () const { return m_rhs->end_pos (); }
77
78 bool rvalue_ok () const { return true; }
79
80 std::string oper () const;
81
82 octave_value::binary_op op_type () const { return m_etype; }
83
84 tree_expression * lhs () { return m_lhs; }
85 tree_expression * rhs () { return m_rhs; }
86
87 void lhs (tree_expression *expr) { m_lhs = expr; }
88 void rhs (tree_expression *expr) { m_rhs = expr; }
89
90 tree_expression * dup (symbol_scope& scope) const;
91
92 octave_value evaluate (tree_evaluator&, int nargout = 1);
93
95 {
96 return ovl (evaluate (tw, nargout));
97 }
98
100 {
101 tw.visit_binary_expression (*this);
102 }
103
104 std::string profiler_name () const { return "binary " + oper (); }
105
106 void matlab_style_short_circuit_warning (const char *op);
107
108 virtual bool is_braindead () const { return false; }
109
110protected:
111
112 // The operands and operator for the expression.
114
116
118
119private:
120
121 // The type of the expression.
123
124 // If TRUE, don't delete m_lhs and m_rhs in destructor;
125 bool m_preserve_operands;
126};
127
130{
131public:
132
136
137 OCTAVE_DISABLE_CONSTRUCT_COPY_MOVE (tree_braindead_shortcircuit_binary_expression)
138
140
141 tree_expression * dup (symbol_scope& scope) const;
142
143 octave_value evaluate (tree_evaluator&, int nargout = 1);
144
146
147 bool is_braindead () const { return true; }
148};
149
150// Boolean expressions.
151
153{
154public:
155
162
163 tree_boolean_expression (type t = unknown) : m_etype (t) { }
164
166 : tree_binary_expression (a, op_tok, b), m_etype (t)
167 { }
168
169 OCTAVE_DISABLE_COPY_MOVE (tree_boolean_expression)
170
172
173 bool is_boolean_expression () const { return true; }
174
175 bool rvalue_ok () const { return true; }
176
177 std::string oper () const;
178
179 type op_type () const { return m_etype; }
180
181 tree_expression * dup (symbol_scope& scope) const;
182
183 octave_value evaluate (tree_evaluator&, int nargout = 1);
184
186 {
187 return ovl (evaluate (tw, nargout));
188 }
189
191 {
192 tw.visit_boolean_expression (*this);
193 }
194
195private:
196
197 // The type of the expression.
198 type m_etype;
199};
200
201OCTAVE_END_NAMESPACE(octave)
202
203#endif
binary_op
Definition ov.h:92
@ unknown_binary_op
Definition ov.h:113
Definition token.h:42
tree_expression * m_lhs
Definition pt-binop.h:113
void matlab_style_short_circuit_warning(const char *op)
Definition pt-binop.cc:43
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:82
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:75
tree_expression * lhs()
Definition pt-binop.h:84
tree_expression * rhs()
Definition pt-binop.h:85
octave_value_list evaluate_n(tree_evaluator &tw, int nargout=1)
Definition pt-binop.h:94
token operator_token() const
Definition pt-binop.h:69
bool is_binary_expression() const
Definition pt-binop.h:73
filepos end_pos() const
Definition pt-binop.h:76
tree_expression * m_rhs
Definition pt-binop.h:117
void rhs(tree_expression *expr)
Definition pt-binop.h:88
tree_expression * dup(symbol_scope &scope) const
Definition pt-binop.cc:57
void accept(tree_walker &tw)
Definition pt-binop.h:99
virtual bool is_braindead() const
Definition pt-binop.h:108
void lhs(tree_expression *expr)
Definition pt-binop.h:87
std::string oper() const
Definition pt-binop.cc:51
bool rvalue_ok() const
Definition pt-binop.h:78
std::string profiler_name() const
Definition pt-binop.h:104
octave_value evaluate(tree_evaluator &, int nargout=1)
Definition pt-binop.cc:71
void accept(tree_walker &tw)
Definition pt-binop.h:190
bool rvalue_ok() const
Definition pt-binop.h:175
tree_boolean_expression(type t=unknown)
Definition pt-binop.h:163
octave_value_list evaluate_n(tree_evaluator &tw, int nargout=1)
Definition pt-binop.h:185
~tree_boolean_expression()=default
tree_boolean_expression(tree_expression *a, const token &op_tok, tree_expression *b, type t=unknown)
Definition pt-binop.h:165
type op_type() const
Definition pt-binop.h:179
tree_expression * dup(symbol_scope &scope) const
Definition pt-binop.cc:194
std::string oper() const
Definition pt-binop.cc:172
octave_value evaluate(tree_evaluator &, int nargout=1)
Definition pt-binop.cc:208
bool is_boolean_expression() const
Definition pt-binop.h:173
tree_expression * dup(symbol_scope &scope) const
Definition pt-binop.cc:107
octave_value evaluate(tree_evaluator &, int nargout=1)
Definition pt-binop.cc:122
tree_braindead_shortcircuit_binary_expression(tree_expression *a, const token &op_tok, tree_expression *b, octave_value::binary_op t)
Definition pt-binop.h:133
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
virtual filepos end_pos() const =0
virtual filepos beg_pos() const =0
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
octave_value_list ovl(const OV_Args &... args)
Construct an octave_value_list with less typing.
Definition ovl.h:217