GNU Octave 11.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 
Loading...
Searching...
No Matches
pt-assign.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_assign_h)
27#define octave_pt_assign_h 1
28
29#include "octave-config.h"
30
31#include <iosfwd>
32#include <string>
33
34class octave_value;
36
37#include "comment-list.h"
38#include "ov.h"
39#include "pt-arg-list.h"
40#include "pt-exp.h"
41#include "pt-walk.h"
42#include "token.h"
43
45
46class symbol_scope;
47class octave_lvalue;
49
50// Simple assignment expressions.
51
52class OCTINTERP_API tree_simple_assignment : public tree_expression
53{
54public:
55
57
58 OCTAVE_DISABLE_COPY_MOVE (tree_simple_assignment)
59
61
62 filepos beg_pos () const { return m_lhs->beg_pos (); }
63 filepos end_pos () const { return m_rhs->end_pos (); }
64
65 comment_list leading_comments () const { return m_lhs->leading_comments (); }
66 comment_list trailing_comments () const { return m_rhs->trailing_comments (); }
67
68 bool rvalue_ok () const { return true; }
69
70 bool is_assignment_expression () const { return true; }
71
72 OCTAVE_DEPRECATED (11, "use tree_simple_assignment::op_str instead")
73 std::string oper () const { return op_str (); }
74
75 std::string op_str () const;
76
77 tree_expression * left_hand_side () { return m_lhs; }
78
79 tree_expression * right_hand_side () { return m_rhs; }
80
81 tree_expression * dup (symbol_scope& scope) const;
82
83 octave_value evaluate (tree_evaluator& tw, int nargout = 1);
84
86 {
87 return ovl (evaluate (tw, nargout));
88 }
89
91 {
92 tw.visit_simple_assignment (*this);
93 }
94
95 octave_value::assign_op op_type () const { return m_etype; }
96
97private:
98
99 void do_assign (octave_lvalue& ult, const octave_value_list& args,
100 const octave_value& rhs_val);
101
102 void do_assign (octave_lvalue& ult, const octave_value& rhs_val);
103
104 // The left hand side of the assignment.
105 tree_expression *m_lhs;
106
107 // The right hand side of the assignment.
108 tree_expression *m_rhs;
109
110 // True if we should not delete the lhs.
111 bool m_preserve;
112
113 // True if this is an assignment to the automatic variable ans.
114 bool m_ans_assign;
115
116 // The type of the expression.
118};
119
120// Multi-valued assignment expressions.
121
122class OCTINTERP_API tree_multi_assignment : public tree_expression
123{
124public:
125
126 tree_multi_assignment (bool plhs = false)
127 : m_lhs (nullptr), m_rhs (nullptr), m_preserve (plhs)
128 { }
129
130 tree_multi_assignment (tree_argument_list *lst, tree_expression *r, bool plhs = false);
131
132 OCTAVE_DISABLE_COPY_MOVE (tree_multi_assignment)
133
135
136 bool is_assignment_expression () const { return true; }
137
138 filepos beg_pos () const { return m_lhs->beg_pos (); }
139 filepos end_pos () const { return m_rhs->end_pos (); }
140
141 comment_list leading_comments () const { return m_lhs->leading_comments (); }
142 comment_list trailing_comments () const { return m_rhs->trailing_comments (); }
143
144 bool rvalue_ok () const { return true; }
145
146 OCTAVE_DEPRECATED (11, "use tree_multi_assignment::op_str instead")
147 std::string oper () const { return op_str (); }
148
149 std::string op_str () const;
150
151 tree_argument_list * left_hand_side () { return m_lhs; }
152
153 tree_expression * right_hand_side () { return m_rhs; }
154
155 tree_expression * dup (symbol_scope& scope) const;
156
157 octave_value evaluate (tree_evaluator& tw, int nargout = 1)
158 {
159 octave_value_list retval = evaluate_n (tw, nargout);
160
161 return retval.length () > 0 ? retval(0) : octave_value ();
162 }
163
164 octave_value_list evaluate_n (tree_evaluator& tw, int nargout = 1);
165
167 {
168 tw.visit_multi_assignment (*this);
169 }
170
175
176private:
177
178 // The left hand side of the assignment.
179 tree_argument_list *m_lhs;
180
181 // The right hand side of the assignment.
182 tree_expression *m_rhs;
183
184 // True if we should not delete the lhs.
185 bool m_preserve;
186};
187
188OCTAVE_END_NAMESPACE(octave)
189
190#endif
octave_idx_type length() const
Definition ovl.h:111
@ op_asn_eq
Definition ov.h:135
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 octave_value_list evaluate_n(tree_evaluator &tw, int nargout=1)=0
bool rvalue_ok() const
Definition pt-assign.h:144
comment_list leading_comments() const
Definition pt-assign.h:141
void accept(tree_walker &tw)
Definition pt-assign.h:166
comment_list trailing_comments() const
Definition pt-assign.h:142
bool is_assignment_expression() const
Definition pt-assign.h:136
octave_value evaluate(tree_evaluator &tw, int nargout=1)
Definition pt-assign.h:157
octave_value::assign_op op_type() const
Definition pt-assign.h:171
filepos end_pos() const
Definition pt-assign.h:139
tree_expression * right_hand_side()
Definition pt-assign.h:153
tree_multi_assignment(bool plhs=false)
Definition pt-assign.h:126
filepos beg_pos() const
Definition pt-assign.h:138
tree_argument_list * left_hand_side()
Definition pt-assign.h:151
comment_list trailing_comments() const
Definition pt-assign.h:66
tree_expression * right_hand_side()
Definition pt-assign.h:79
bool is_assignment_expression() const
Definition pt-assign.h:70
void accept(tree_walker &tw)
Definition pt-assign.h:90
octave_value_list evaluate_n(tree_evaluator &tw, int nargout=1)
Definition pt-assign.h:85
comment_list leading_comments() const
Definition pt-assign.h:65
bool rvalue_ok() const
Definition pt-assign.h:68
filepos beg_pos() const
Definition pt-assign.h:62
octave_value::assign_op op_type() const
Definition pt-assign.h:95
filepos end_pos() const
Definition pt-assign.h:63
tree_expression * left_hand_side()
Definition pt-assign.h:77
virtual void visit_multi_assignment(tree_multi_assignment &)
Definition pt-walk.cc:483
virtual void visit_simple_assignment(tree_simple_assignment &)
Definition pt-walk.cc:553
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