GNU Octave  9.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
pt-unop.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_unop_h)
27 #define octave_pt_unop_h 1
28 
29 #include "octave-config.h"
30 
31 #include <string>
32 
33 class octave_value;
34 class octave_value_list;
35 
36 #include "ov.h"
37 #include "pt-exp.h"
38 #include "pt-walk.h"
39 
41 
42 class symbol_scope;
43 
44 // Unary expressions.
45 
47 {
48 protected:
49 
50  tree_unary_expression (int l = -1, int c = -1,
53  : tree_expression (l, c), m_op (nullptr), m_etype (t) { }
54 
55  tree_unary_expression (tree_expression *e, int l = -1, int c = -1,
58  : tree_expression (l, c), m_op (e), m_etype (t) { }
59 
60 public:
61 
62  OCTAVE_DISABLE_COPY_MOVE (tree_unary_expression)
63 
65 
66  bool is_unary_expression () const { return true; }
67 
68  tree_expression * operand () { return m_op; }
69 
70  std::string oper () const;
71 
72  octave_value::unary_op op_type () const { return m_etype; }
73 
74 protected:
75 
76  // The operand for the expression.
78 
79  // The type of the expression.
81 };
82 
83 // Prefix expressions.
84 
86 {
87 public:
88 
89  tree_prefix_expression (int l = -1, int c = -1)
90  : tree_unary_expression (l, c, octave_value::unknown_unary_op) { }
91 
92  tree_prefix_expression (tree_expression *e, int l = -1, int c = -1,
95  : tree_unary_expression (e, l, c, t) { }
96 
97  OCTAVE_DISABLE_COPY_MOVE (tree_prefix_expression)
98 
100 
101  bool rvalue_ok () const { return true; }
102 
103  tree_expression * dup (symbol_scope& scope) const;
104 
105  octave_value evaluate (tree_evaluator&, int nargout = 1);
106 
108  {
109  return ovl (evaluate (tw, nargout));
110  }
111 
112  void accept (tree_walker& tw)
113  {
114  tw.visit_prefix_expression (*this);
115  }
116 
117  std::string profiler_name () const { return "prefix " + oper (); }
118 };
119 
120 // Postfix expressions.
121 
123 {
124 public:
125 
126  tree_postfix_expression (int l = -1, int c = -1)
127  : tree_unary_expression (l, c, octave_value::unknown_unary_op) { }
128 
129  tree_postfix_expression (tree_expression *e, int l = -1, int c = -1,
132  : tree_unary_expression (e, l, c, t) { }
133 
134  OCTAVE_DISABLE_COPY_MOVE (tree_postfix_expression)
135 
137 
138  bool rvalue_ok () const { return true; }
139 
140  tree_expression * dup (symbol_scope& scope) const;
141 
142  octave_value evaluate (tree_evaluator&, int nargout = 1);
143 
145  {
146  return ovl (evaluate (tw, nargout));
147  }
148 
149  void accept (tree_walker& tw)
150  {
151  tw.visit_postfix_expression (*this);
152  }
153 
154  std::string profiler_name () const { return "postfix " + oper (); }
155 };
156 
157 OCTAVE_END_NAMESPACE(octave)
158 
159 #endif
unary_op
Definition: ov.h:79
@ unknown_unary_op
Definition: ov.h:88
octave_value evaluate(tree_evaluator &, int nargout=1)
Definition: pt-unop.cc:122
bool rvalue_ok() const
Definition: pt-unop.h:138
tree_expression * dup(symbol_scope &scope) const
Definition: pt-unop.cc:110
tree_postfix_expression(tree_expression *e, int l=-1, int c=-1, octave_value::unary_op t=octave_value::unknown_unary_op)
Definition: pt-unop.h:129
~tree_postfix_expression()=default
tree_postfix_expression(int l=-1, int c=-1)
Definition: pt-unop.h:126
void accept(tree_walker &tw)
Definition: pt-unop.h:149
std::string profiler_name() const
Definition: pt-unop.h:154
octave_value_list evaluate_n(tree_evaluator &tw, int nargout=1)
Definition: pt-unop.h:144
bool rvalue_ok() const
Definition: pt-unop.h:101
std::string profiler_name() const
Definition: pt-unop.h:117
tree_expression * dup(symbol_scope &scope) const
Definition: pt-unop.cc:48
octave_value evaluate(tree_evaluator &, int nargout=1)
Definition: pt-unop.cc:60
void accept(tree_walker &tw)
Definition: pt-unop.h:112
octave_value_list evaluate_n(tree_evaluator &tw, int nargout=1)
Definition: pt-unop.h:107
tree_prefix_expression(int l=-1, int c=-1)
Definition: pt-unop.h:89
tree_prefix_expression(tree_expression *e, int l=-1, int c=-1, octave_value::unary_op t=octave_value::unknown_unary_op)
Definition: pt-unop.h:92
~tree_prefix_expression()=default
octave_value::unary_op m_etype
Definition: pt-unop.h:80
tree_unary_expression(tree_expression *e, int l=-1, int c=-1, octave_value::unary_op t=octave_value::unknown_unary_op)
Definition: pt-unop.h:55
tree_expression * operand()
Definition: pt-unop.h:68
tree_expression * m_op
Definition: pt-unop.h:77
octave_value::unary_op op_type() const
Definition: pt-unop.h:72
bool is_unary_expression() const
Definition: pt-unop.h:66
tree_unary_expression(int l=-1, int c=-1, octave_value::unary_op t=octave_value::unknown_unary_op)
Definition: pt-unop.h:50
std::string oper() const
Definition: pt-unop.cc:40
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_value_list ovl(const OV_Args &... args)
Construct an octave_value_list with less typing.
Definition: ovl.h:219