GNU Octave 11.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 
Loading...
Searching...
No Matches
pt-unop.h
Go to the documentation of this file.
1////////////////////////////////////////////////////////////////////////
2//
3// Copyright (C) 1996-2026 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_unop_h)
27#define octave_pt_unop_h 1
28
29#include "octave-config.h"
30
31#include <string>
32
33class octave_value;
35
36#include "ov.h"
37#include "pt-exp.h"
38#include "pt-walk.h"
39#include "token.h"
40
42
43class symbol_scope;
44
45// Unary expressions.
46
47class OCTINTERP_API tree_unary_expression : public tree_expression
48{
49protected:
50
53
55 : m_op_tok (op_tok), m_op (e), m_etype (t)
56 { }
57
58public:
59
60 OCTAVE_DISABLE_COPY_MOVE (tree_unary_expression)
61
62 ~tree_unary_expression () { delete m_op; }
63
64 bool is_unary_expression () const { return true; }
65
66 tree_expression * operand () { return m_op; }
67
68 token op_token () const { return m_op_tok; }
69
70 OCTAVE_DEPRECATED (11, "use tree_unary_op::op_str instead")
71 std::string oper () const { return op_str (); }
72
73 std::string op_str () const;
74
75 octave_value::unary_op op_type () const { return m_etype; }
76
77protected:
78
79 // The operator token.
81
82 // The operand for the expression.
84
85 // The type of the expression.
87};
88
89// Prefix expressions.
90
92{
93public:
94
98
99 OCTAVE_DISABLE_COPY_MOVE (tree_prefix_expression)
100
102
103 filepos beg_pos () const { return m_op_tok.beg_pos (); }
104 filepos end_pos () const { return m_op->end_pos (); }
105
106 comment_list leading_comments () const { return m_op_tok.leading_comments (); }
107 comment_list trailing_comments () const { return m_op->trailing_comments (); }
108
109 bool rvalue_ok () const { return true; }
110
111 tree_expression * dup (symbol_scope& scope) const;
112
113 octave_value evaluate (tree_evaluator&, int nargout = 1);
114
116 {
117 return ovl (evaluate (tw, nargout));
118 }
119
121 {
122 tw.visit_prefix_expression (*this);
123 }
124
125 std::string profiler_name () const { return "prefix " + op_str (); }
126};
127
128// Postfix expressions.
129
131{
132public:
133
137
138 OCTAVE_DISABLE_COPY_MOVE (tree_postfix_expression)
139
141
142 filepos beg_pos () const { return m_op->beg_pos (); }
143 filepos end_pos () const { return m_op_tok.end_pos (); }
144
145 comment_list leading_comments () const { return m_op->leading_comments (); }
146 comment_list trailing_comments () const { return m_op_tok.trailing_comments (); }
147
148 bool rvalue_ok () const { return true; }
149
150 tree_expression * dup (symbol_scope& scope) const;
151
152 octave_value evaluate (tree_evaluator&, int nargout = 1);
153
155 {
156 return ovl (evaluate (tw, nargout));
157 }
158
160 {
161 tw.visit_postfix_expression (*this);
162 }
163
164 std::string profiler_name () const { return "postfix " + op_str (); }
165};
166
167OCTAVE_END_NAMESPACE(octave)
168
169#endif
@ unknown_unary_op
Definition ov.h:88
Definition token.h:42
virtual octave_value evaluate(tree_evaluator &tw, int nargout=1)=0
virtual std::string op_str() const
Definition pt-exp.h:112
virtual tree_expression * dup(symbol_scope &scope) const =0
bool rvalue_ok() const
Definition pt-unop.h:148
comment_list leading_comments() const
Definition pt-unop.h:145
filepos end_pos() const
Definition pt-unop.h:143
~tree_postfix_expression()=default
filepos beg_pos() const
Definition pt-unop.h:142
comment_list trailing_comments() const
Definition pt-unop.h:146
void accept(tree_walker &tw)
Definition pt-unop.h:159
tree_postfix_expression(tree_expression *e, const token &op_tok, octave_value::unary_op t=octave_value::unknown_unary_op)
Definition pt-unop.h:134
std::string profiler_name() const
Definition pt-unop.h:164
octave_value_list evaluate_n(tree_evaluator &tw, int nargout=1)
Definition pt-unop.h:154
comment_list leading_comments() const
Definition pt-unop.h:106
bool rvalue_ok() const
Definition pt-unop.h:109
std::string profiler_name() const
Definition pt-unop.h:125
filepos beg_pos() const
Definition pt-unop.h:103
void accept(tree_walker &tw)
Definition pt-unop.h:120
octave_value_list evaluate_n(tree_evaluator &tw, int nargout=1)
Definition pt-unop.h:115
tree_prefix_expression(const token &op_tok, tree_expression *e, octave_value::unary_op t=octave_value::unknown_unary_op)
Definition pt-unop.h:95
filepos end_pos() const
Definition pt-unop.h:104
~tree_prefix_expression()=default
comment_list trailing_comments() const
Definition pt-unop.h:107
tree_expression * operand()
Definition pt-unop.h:66
octave_value::unary_op m_etype
Definition pt-unop.h:86
tree_expression * m_op
Definition pt-unop.h:83
octave_value::unary_op op_type() const
Definition pt-unop.h:75
bool is_unary_expression() const
Definition pt-unop.h:64
token op_token() const
Definition pt-unop.h:68
tree_unary_expression(octave_value::unary_op t=octave_value::unknown_unary_op)
Definition pt-unop.h:51
tree_unary_expression(const token &op_tok, tree_expression *e, octave_value::unary_op t=octave_value::unknown_unary_op)
Definition pt-unop.h:54
virtual void visit_postfix_expression(tree_postfix_expression &)
Definition pt-walk.cc:529
virtual void visit_prefix_expression(tree_prefix_expression &)
Definition pt-walk.cc:538
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
OCTAVE_DEPRECATED(11, "") typedef bool(*b_d_Mapper)(double)
octave_value_list ovl(const OV_Args &... args)
Construct an octave_value_list with less typing.
Definition ovl.h:217