GNU Octave 10.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-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_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
53{
54public:
55
57
58 OCTAVE_DISABLE_COPY_MOVE (tree_simple_assignment)
59
61
62 comment_list leading_comments () const { return m_lhs->leading_comments (); }
63
64 filepos beg_pos () const { return m_lhs->beg_pos (); }
65 filepos end_pos () const { return m_rhs->end_pos (); }
66
67 bool rvalue_ok () const { return true; }
68
69 bool is_assignment_expression () const { return true; }
70
71 std::string oper () const;
72
73 tree_expression * left_hand_side () { return m_lhs; }
74
75 tree_expression * right_hand_side () { return m_rhs; }
76
77 tree_expression * dup (symbol_scope& scope) const;
78
79 octave_value evaluate (tree_evaluator& tw, int nargout = 1);
80
82 {
83 return ovl (evaluate (tw, nargout));
84 }
85
87 {
88 tw.visit_simple_assignment (*this);
89 }
90
91 octave_value::assign_op op_type () const { return m_etype; }
92
93private:
94
95 void do_assign (octave_lvalue& ult, const octave_value_list& args,
96 const octave_value& rhs_val);
97
98 void do_assign (octave_lvalue& ult, const octave_value& rhs_val);
99
100 // The left hand side of the assignment.
101 tree_expression *m_lhs;
102
103 // The right hand side of the assignment.
104 tree_expression *m_rhs;
105
106 // True if we should not delete the lhs.
107 bool m_preserve;
108
109 // True if this is an assignment to the automatic variable ans.
110 bool m_ans_assign;
111
112 // The type of the expression.
114};
115
116// Multi-valued assignment expressions.
117
119{
120public:
121
122 tree_multi_assignment (bool plhs = false)
123 : m_lhs (nullptr), m_rhs (nullptr), m_preserve (plhs)
124 { }
125
126 tree_multi_assignment (tree_argument_list *lst, tree_expression *r, bool plhs = false);
127
128 OCTAVE_DISABLE_COPY_MOVE (tree_multi_assignment)
129
131
132 bool is_assignment_expression () const { return true; }
133
134 filepos beg_pos () const { return m_lhs->beg_pos (); }
135 filepos end_pos () const { return m_rhs->end_pos (); }
136
137 bool rvalue_ok () const { return true; }
138
139 std::string oper () const;
140
141 tree_argument_list * left_hand_side () { return m_lhs; }
142
143 tree_expression * right_hand_side () { return m_rhs; }
144
145 tree_expression * dup (symbol_scope& scope) const;
146
147 octave_value evaluate (tree_evaluator& tw, int nargout = 1)
148 {
149 octave_value_list retval = evaluate_n (tw, nargout);
150
151 return retval.length () > 0 ? retval(0) : octave_value ();
152 }
153
154 octave_value_list evaluate_n (tree_evaluator& tw, int nargout = 1);
155
157 {
158 tw.visit_multi_assignment (*this);
159 }
160
165
166private:
167
168 // The left hand side of the assignment.
169 tree_argument_list *m_lhs;
170
171 // The right hand side of the assignment.
172 tree_expression *m_rhs;
173
174 // True if we should not delete the lhs.
175 bool m_preserve;
176};
177
178OCTAVE_END_NAMESPACE(octave)
179
180#endif
octave_idx_type length() const
Definition ovl.h:111
@ op_asn_eq
Definition ov.h:135
filepos beg_pos() const
Definition pt-arg-list.h:72
bool rvalue_ok() const
Definition pt-assign.h:137
void accept(tree_walker &tw)
Definition pt-assign.h:156
std::string oper() const
Definition pt-assign.cc:165
bool is_assignment_expression() const
Definition pt-assign.h:132
octave_value evaluate(tree_evaluator &tw, int nargout=1)
Definition pt-assign.h:147
octave_value::assign_op op_type() const
Definition pt-assign.h:161
filepos end_pos() const
Definition pt-assign.h:135
tree_expression * right_hand_side()
Definition pt-assign.h:143
tree_expression * dup(symbol_scope &scope) const
Definition pt-assign.cc:171
tree_multi_assignment(bool plhs=false)
Definition pt-assign.h:122
octave_value_list evaluate_n(tree_evaluator &tw, int nargout=1)
Definition pt-assign.cc:179
filepos beg_pos() const
Definition pt-assign.h:134
tree_argument_list * left_hand_side()
Definition pt-assign.h:141
std::string oper() const
Definition pt-assign.cc:56
tree_expression * right_hand_side()
Definition pt-assign.h:75
bool is_assignment_expression() const
Definition pt-assign.h:69
void accept(tree_walker &tw)
Definition pt-assign.h:86
octave_value evaluate(tree_evaluator &tw, int nargout=1)
Definition pt-assign.cc:75
octave_value_list evaluate_n(tree_evaluator &tw, int nargout=1)
Definition pt-assign.h:81
comment_list leading_comments() const
Definition pt-assign.h:62
tree_expression * dup(symbol_scope &scope) const
Definition pt-assign.cc:62
bool rvalue_ok() const
Definition pt-assign.h:67
filepos beg_pos() const
Definition pt-assign.h:64
octave_value::assign_op op_type() const
Definition pt-assign.h:91
filepos end_pos() const
Definition pt-assign.h:65
tree_expression * left_hand_side()
Definition pt-assign.h:73
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
virtual filepos end_pos() const =0
virtual filepos beg_pos() const =0
virtual comment_list leading_comments() const
Definition pt.cc:57
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