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
35
OCTAVE_BEGIN_NAMESPACE
(octave)
36
37
// Unary expressions.
38
39
std::string
40
tree_unary_expression::oper
()
const
41
{
42
return
octave_value::unary_op_as_string
(
m_etype
);
43
}
44
45
// Prefix expressions.
46
47
tree_expression
*
48
tree_prefix_expression::dup
(
symbol_scope
& scope)
const
49
{
50
tree_prefix_expression
*new_pe
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
58
octave_value
59
tree_prefix_expression::evaluate
(
tree_evaluator
& tw,
int
)
60
{
61
octave_value
val;
62
63
if
(
m_op
)
64
{
65
if
(
m_etype
==
octave_value::op_incr
66
||
m_etype
==
octave_value::op_decr
)
67
{
68
octave_lvalue
op_ref =
m_op
->
lvalue
(tw);
69
70
profiler::enter<tree_prefix_expression>
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
{
84
profiler::enter<tree_prefix_expression>
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
108
tree_expression
*
109
tree_postfix_expression::dup
(
symbol_scope
& scope)
const
110
{
111
tree_postfix_expression
*new_pe
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
119
octave_value
120
tree_postfix_expression::evaluate
(
tree_evaluator
& tw,
int
)
121
{
122
octave_value
val;
123
124
if
(
m_op
)
125
{
126
if
(
m_etype
==
octave_value::op_incr
127
||
m_etype
==
octave_value::op_decr
)
128
{
129
octave_lvalue
ref =
m_op
->
lvalue
(tw);
130
131
val = ref.
value
();
132
133
profiler::enter<tree_postfix_expression>
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
{
145
profiler::enter<tree_postfix_expression>
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
160
OCTAVE_END_NAMESPACE(octave)
interpreter
Definition
interpreter.h:113
interpreter::get_type_info
type_info & get_type_info()
Definition
interpreter.h:305
octave_lvalue
Definition
oct-lvalue.h:40
octave_lvalue::value
octave_value value() const
Definition
oct-lvalue.cc:224
octave_lvalue::unary_op
void unary_op(octave_value::unary_op op)
Definition
oct-lvalue.cc:217
octave_value
Definition
ov.h:75
octave_value::op_incr
@ op_incr
Definition
ov.h:85
octave_value::op_decr
@ op_decr
Definition
ov.h:86
octave_value::is_defined
bool is_defined() const
Definition
ov.h:592
octave_value::non_const_unary_op
octave_value & non_const_unary_op(unary_op op)
octave_value::unary_op_as_string
static std::string unary_op_as_string(unary_op)
Definition
ov.cc:128
octave_value::get_count
octave_idx_type get_count() const
Definition
ov.h:421
profiler::enter
Definition
profiler.h:48
symbol_scope
Definition
symscope.h:52
tree_evaluator
Definition
pt-eval.h:68
tree_evaluator::get_interpreter
interpreter & get_interpreter()
Definition
pt-eval.h:422
tree_evaluator::get_profiler
profiler & get_profiler()
Definition
pt-eval.h:426
tree_expression
Definition
pt-exp.h:49
tree_expression::evaluate
virtual octave_value evaluate(tree_evaluator &tw, int nargout=1)=0
tree_expression::copy_base
virtual void copy_base(const tree_expression &e)
Definition
pt-exp.h:137
tree_expression::dup
virtual tree_expression * dup(symbol_scope &scope) const =0
tree_expression::lvalue
virtual octave_lvalue lvalue(tree_evaluator &)
Definition
pt-exp.cc:43
tree_postfix_expression
Definition
pt-unop.h:123
tree_postfix_expression::evaluate
octave_value evaluate(tree_evaluator &, int nargout=1)
Definition
pt-unop.cc:120
tree_postfix_expression::dup
tree_expression * dup(symbol_scope &scope) const
Definition
pt-unop.cc:109
tree_prefix_expression
Definition
pt-unop.h:87
tree_prefix_expression::dup
tree_expression * dup(symbol_scope &scope) const
Definition
pt-unop.cc:48
tree_prefix_expression::evaluate
octave_value evaluate(tree_evaluator &, int nargout=1)
Definition
pt-unop.cc:59
tree_unary_expression::m_etype
octave_value::unary_op m_etype
Definition
pt-unop.h:81
tree_unary_expression::m_op
tree_expression * m_op
Definition
pt-unop.h:78
tree_unary_expression::m_op_tok
token m_op_tok
Definition
pt-unop.h:75
tree_unary_expression::oper
std::string oper() const
Definition
pt-unop.cc:40
type_info
Definition
ov-typeinfo.h:43
OCTAVE_BEGIN_NAMESPACE
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
interpreter.h
ov.h
unary_op
octave_value unary_op(type_info &ti, octave_value::unary_op op, const octave_value &a)
profiler.h
pt-unop.h
libinterp
parse-tree
pt-unop.cc
Generated on Sat Aug 2 2025 06:52:13 for GNU Octave by
1.9.8