GNU Octave 10.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 
Loading...
Searching...
No Matches
pt-unop.cc
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 (HAVE_CONFIG_H)
27# include "config.h"
28#endif
29
30#include "interpreter.h"
31#include "ov.h"
32#include "profiler.h"
33#include "pt-unop.h"
34
36
37// Unary expressions.
38
39std::string
44
45// Prefix expressions.
46
49{
51 = new tree_prefix_expression (m_op_tok, m_op ? m_op->dup (scope) : nullptr, m_etype);
52
53 new_pe->copy_base (*this);
54
55 return new_pe;
56}
57
60{
61 octave_value val;
62
63 if (m_op)
64 {
67 {
68 octave_lvalue op_ref = m_op->lvalue (tw);
69
71 block (tw.get_profiler (), *this);
72
73 op_ref.unary_op (m_etype);
74
75 val = op_ref.value ();
76 }
77 else
78 {
79 // Evaluate with unknown number of output arguments
80 octave_value op_val = m_op->evaluate (tw, -1);
81
82 if (op_val.is_defined ())
83 {
85 block (tw.get_profiler (), *this);
86
87 // Attempt to do the operation in-place if it is unshared
88 // (a temporary expression).
89 if (op_val.get_count () == 1)
90 val = op_val.non_const_unary_op (m_etype);
91 else
92 {
93 interpreter& interp = tw.get_interpreter ();
94
95 type_info& ti = interp.get_type_info ();
96
97 val = unary_op (ti, m_etype, op_val);
98 }
99 }
100 }
101 }
102
103 return val;
104}
105
106// Postfix expressions.
107
110{
112 = new tree_postfix_expression (m_op ? m_op->dup (scope) : nullptr, m_op_tok, m_etype);
113
114 new_pe->copy_base (*this);
115
116 return new_pe;
117}
118
121{
122 octave_value val;
123
124 if (m_op)
125 {
128 {
129 octave_lvalue ref = m_op->lvalue (tw);
130
131 val = ref.value ();
132
134 block (tw.get_profiler (), *this);
135
136 ref.unary_op (m_etype);
137 }
138 else
139 {
140 // Evaluate with unknown number of output arguments
141 octave_value op_val = m_op->evaluate (tw, -1);
142
143 if (op_val.is_defined ())
144 {
146 block (tw.get_profiler (), *this);
147
148 interpreter& interp = tw.get_interpreter ();
149
150 type_info& ti = interp.get_type_info ();
151
152 val = unary_op (ti, m_etype, op_val);
153 }
154 }
155 }
156
157 return val;
158}
159
160OCTAVE_END_NAMESPACE(octave)
type_info & get_type_info()
octave_value value() const
void unary_op(octave_value::unary_op op)
@ op_incr
Definition ov.h:85
@ op_decr
Definition ov.h:86
bool is_defined() const
Definition ov.h:592
octave_value & non_const_unary_op(unary_op op)
static std::string unary_op_as_string(unary_op)
Definition ov.cc:128
octave_idx_type get_count() const
Definition ov.h:421
interpreter & get_interpreter()
Definition pt-eval.h:422
profiler & get_profiler()
Definition pt-eval.h:426
virtual octave_value evaluate(tree_evaluator &tw, int nargout=1)=0
virtual void copy_base(const tree_expression &e)
Definition pt-exp.h:137
virtual tree_expression * dup(symbol_scope &scope) const =0
virtual octave_lvalue lvalue(tree_evaluator &)
Definition pt-exp.cc:43
octave_value evaluate(tree_evaluator &, int nargout=1)
Definition pt-unop.cc:120
tree_expression * dup(symbol_scope &scope) const
Definition pt-unop.cc:109
tree_expression * dup(symbol_scope &scope) const
Definition pt-unop.cc:48
octave_value evaluate(tree_evaluator &, int nargout=1)
Definition pt-unop.cc:59
octave_value::unary_op m_etype
Definition pt-unop.h:81
tree_expression * m_op
Definition pt-unop.h:78
std::string oper() const
Definition pt-unop.cc:40
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
octave_value unary_op(type_info &ti, octave_value::unary_op op, const octave_value &a)