GNU Octave
9.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
pt-unop.cc
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 (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
?
m_op
->
dup
(scope) :
nullptr
,
52
line
(),
column
(),
m_etype
);
53
54
new_pe->
copy_base
(*
this
);
55
56
return
new_pe;
57
}
58
59
octave_value
60
tree_prefix_expression::evaluate
(
tree_evaluator
& tw,
int
)
61
{
62
octave_value
val;
63
64
if
(
m_op
)
65
{
66
if
(
m_etype
==
octave_value::op_incr
67
||
m_etype
==
octave_value::op_decr
)
68
{
69
octave_lvalue
op_ref =
m_op
->
lvalue
(tw);
70
71
profiler::enter<tree_prefix_expression>
72
block (tw.
get_profiler
(), *
this
);
73
74
op_ref.
unary_op
(
m_etype
);
75
76
val = op_ref.
value
();
77
}
78
else
79
{
80
// Evaluate with unknown number of output arguments
81
octave_value
op_val =
m_op
->
evaluate
(tw, -1);
82
83
if
(op_val.
is_defined
())
84
{
85
profiler::enter<tree_prefix_expression>
86
block (tw.
get_profiler
(), *
this
);
87
88
// Attempt to do the operation in-place if it is unshared
89
// (a temporary expression).
90
if
(op_val.
get_count
() == 1)
91
val = op_val.
non_const_unary_op
(
m_etype
);
92
else
93
{
94
interpreter
& interp = tw.
get_interpreter
();
95
96
type_info
& ti = interp.
get_type_info
();
97
98
val =
unary_op
(ti,
m_etype
, op_val);
99
}
100
}
101
}
102
}
103
104
return
val;
105
}
106
107
// Postfix expressions.
108
109
tree_expression
*
110
tree_postfix_expression::dup
(
symbol_scope
& scope)
const
111
{
112
tree_postfix_expression
*new_pe
113
=
new
tree_postfix_expression
(
m_op
?
m_op
->
dup
(scope) :
nullptr
,
114
line
(),
column
(),
m_etype
);
115
116
new_pe->
copy_base
(*
this
);
117
118
return
new_pe;
119
}
120
121
octave_value
122
tree_postfix_expression::evaluate
(
tree_evaluator
& tw,
int
)
123
{
124
octave_value
val;
125
126
if
(
m_op
)
127
{
128
if
(
m_etype
==
octave_value::op_incr
129
||
m_etype
==
octave_value::op_decr
)
130
{
131
octave_lvalue
ref =
m_op
->
lvalue
(tw);
132
133
val = ref.
value
();
134
135
profiler::enter<tree_postfix_expression>
136
block (tw.
get_profiler
(), *
this
);
137
138
ref.
unary_op
(
m_etype
);
139
}
140
else
141
{
142
// Evaluate with unknown number of output arguments
143
octave_value
op_val =
m_op
->
evaluate
(tw, -1);
144
145
if
(op_val.
is_defined
())
146
{
147
profiler::enter<tree_postfix_expression>
148
block (tw.
get_profiler
(), *
this
);
149
150
interpreter
& interp = tw.
get_interpreter
();
151
152
type_info
& ti = interp.
get_type_info
();
153
154
val =
unary_op
(ti,
m_etype
, op_val);
155
}
156
}
157
}
158
159
return
val;
160
}
161
162
OCTAVE_END_NAMESPACE(
octave
)
interpreter
Definition:
interpreter.h:113
interpreter::get_type_info
type_info & get_type_info()
Definition:
interpreter.h:293
line
Definition:
graphics.h:7297
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::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
octave_value::non_const_unary_op
octave_value & non_const_unary_op(unary_op op)
profiler::enter
Definition:
profiler.h:50
symbol_scope
Definition:
symscope.h:371
tree_evaluator
Definition:
pt-eval.h:68
tree_evaluator::get_interpreter
interpreter & get_interpreter()
Definition:
pt-eval.h:420
tree_evaluator::get_profiler
profiler & get_profiler()
Definition:
pt-eval.h:424
tree_expression
Definition:
pt-exp.h:47
tree_expression::evaluate
virtual octave_value evaluate(tree_evaluator &tw, int nargout=1)=0
tree_expression::dup
virtual tree_expression * dup(symbol_scope &scope) const =0
tree_expression::copy_base
virtual void copy_base(const tree_expression &e)
Definition:
pt-exp.h:128
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:122
tree_postfix_expression::dup
tree_expression * dup(symbol_scope &scope) const
Definition:
pt-unop.cc:110
tree_postfix_expression::tree_postfix_expression
tree_postfix_expression(int l=-1, int c=-1)
Definition:
pt-unop.h:126
tree_prefix_expression
Definition:
pt-unop.h:86
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:60
tree_prefix_expression::tree_prefix_expression
tree_prefix_expression(int l=-1, int c=-1)
Definition:
pt-unop.h:89
tree_unary_expression::m_etype
octave_value::unary_op m_etype
Definition:
pt-unop.h:80
tree_unary_expression::m_op
tree_expression * m_op
Definition:
pt-unop.h:77
tree_unary_expression::oper
std::string oper() const
Definition:
pt-unop.cc:40
tree::column
virtual int column() const
Definition:
pt.h:58
type_info
Definition:
ov-typeinfo.h:45
OCTAVE_BEGIN_NAMESPACE
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
interpreter.h
octave
Definition:
file-ops.cc:60
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 Sun Mar 17 2024 22:36:48 for GNU Octave by
1.9.1