GNU Octave  9.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
pt-assign.h
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (C) 1996-2024 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 
34 class octave_value;
35 class octave_value_list;
36 
37 #include "ov.h"
38 #include "pt-exp.h"
39 #include "pt-walk.h"
40 
42 
43 class symbol_scope;
44 class octave_lvalue;
45 class tree_argument_list;
46 
47 // Simple assignment expressions.
48 
50 {
51 public:
52 
53  tree_simple_assignment (bool plhs = false, int l = -1, int c = -1,
55  : tree_expression (l, c), m_lhs (nullptr), m_rhs (nullptr),
56  m_preserve (plhs), m_ans_assign (), m_etype (t)
57  { }
58 
60  bool plhs = false, int l = -1, int c = -1,
62 
63  OCTAVE_DISABLE_COPY_MOVE (tree_simple_assignment)
64 
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 
86  void accept (tree_walker& tw)
87  {
88  tw.visit_simple_assignment (*this);
89  }
90 
91  octave_value::assign_op op_type () const { return m_etype; }
92 
93 private:
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.
113  octave_value::assign_op m_etype;
114 };
115 
116 // Multi-valued assignment expressions.
117 
119 {
120 public:
121 
122  tree_multi_assignment (bool plhs = false, int l = -1, int c = -1)
123  : tree_expression (l, c), m_lhs (nullptr), m_rhs (nullptr),
124  m_preserve (plhs)
125  { }
126 
128  bool plhs = false, int l = -1, int c = -1);
129 
130  OCTAVE_DISABLE_COPY_MOVE (tree_multi_assignment)
131 
133 
134  bool is_assignment_expression () const { return true; }
135 
136  bool rvalue_ok () const { return true; }
137 
138  std::string oper () const;
139 
140  tree_argument_list * left_hand_side () { return m_lhs; }
141 
142  tree_expression * right_hand_side () { return m_rhs; }
143 
144  tree_expression * dup (symbol_scope& scope) const;
145 
146  octave_value evaluate (tree_evaluator& tw, int nargout = 1)
147  {
148  octave_value_list retval = evaluate_n (tw, nargout);
149 
150  return retval.length () > 0 ? retval(0) : octave_value ();
151  }
152 
153  octave_value_list evaluate_n (tree_evaluator& tw, int nargout = 1);
154 
155  void accept (tree_walker& tw)
156  {
157  tw.visit_multi_assignment (*this);
158  }
159 
161  {
163  }
164 
165 private:
166 
167  // The left hand side of the assignment.
168  tree_argument_list *m_lhs;
169 
170  // The right hand side of the assignment.
171  tree_expression *m_rhs;
172 
173  // True if we should not delete the lhs.
174  bool m_preserve;
175 };
176 
177 OCTAVE_END_NAMESPACE(octave)
178 
179 #endif
octave_idx_type length() const
Definition: ovl.h:113
assign_op
Definition: ov.h:134
@ op_asn_eq
Definition: ov.h:135
bool rvalue_ok() const
Definition: pt-assign.h:136
tree_multi_assignment(bool plhs=false, int l=-1, int c=-1)
Definition: pt-assign.h:122
tree_argument_list * left_hand_side()
Definition: pt-assign.h:140
void accept(tree_walker &tw)
Definition: pt-assign.h:155
std::string oper() const
Definition: pt-assign.cc:171
bool is_assignment_expression() const
Definition: pt-assign.h:134
octave_value evaluate(tree_evaluator &tw, int nargout=1)
Definition: pt-assign.h:146
octave_value::assign_op op_type() const
Definition: pt-assign.h:160
tree_expression * dup(symbol_scope &scope) const
Definition: pt-assign.cc:177
octave_value_list evaluate_n(tree_evaluator &tw, int nargout=1)
Definition: pt-assign.cc:184
tree_expression * right_hand_side()
Definition: pt-assign.h:142
std::string oper() const
Definition: pt-assign.cc:60
tree_simple_assignment(bool plhs=false, int l=-1, int c=-1, octave_value::assign_op t=octave_value::op_asn_eq)
Definition: pt-assign.h:53
bool is_assignment_expression() const
Definition: pt-assign.h:69
tree_expression * left_hand_side()
Definition: pt-assign.h:73
void accept(tree_walker &tw)
Definition: pt-assign.h:86
octave_value evaluate(tree_evaluator &tw, int nargout=1)
Definition: pt-assign.cc:79
octave_value_list evaluate_n(tree_evaluator &tw, int nargout=1)
Definition: pt-assign.h:81
tree_expression * dup(symbol_scope &scope) const
Definition: pt-assign.cc:66
bool rvalue_ok() const
Definition: pt-assign.h:67
octave_value::assign_op op_type() const
Definition: pt-assign.h:91
tree_expression * right_hand_side()
Definition: pt-assign.h:75
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
T * r
Definition: mx-inlines.cc:781
return octave_value(v1.char_array_value() . concat(v2.char_array_value(), ra_idx),((a1.is_sq_string()||a2.is_sq_string()) ? '\'' :'"'))
octave_value_list ovl(const OV_Args &... args)
Construct an octave_value_list with less typing.
Definition: ovl.h:219