GNU Octave  6.2.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-2021 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 
40 namespace octave
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  // No copying!
63 
65 
67 
68  ~tree_unary_expression (void) { delete m_op; }
69 
70  bool is_unary_expression (void) const { return true; }
71 
72  tree_expression * operand (void) { return m_op; }
73 
74  std::string oper (void) const;
75 
76  octave_value::unary_op op_type (void) const { return m_etype; }
77 
78  protected:
79 
80  // The operand for the expression.
82 
83  // The type of the expression.
85  };
86 
87  // Prefix expressions.
88 
90  {
91  public:
92 
93  tree_prefix_expression (int l = -1, int c = -1)
94  : tree_unary_expression (l, c, octave_value::unknown_unary_op) { }
95 
96  tree_prefix_expression (tree_expression *e, int l = -1, int c = -1,
99  : tree_unary_expression (e, l, c, t) { }
100 
101  // No copying!
102 
104 
106 
107  ~tree_prefix_expression (void) = default;
108 
109  bool rvalue_ok (void) 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 
120  void accept (tree_walker& tw)
121  {
122  tw.visit_prefix_expression (*this);
123  }
124 
125  std::string profiler_name (void) const { return "prefix " + oper (); }
126  };
127 
128  // Postfix expressions.
129 
131  {
132  public:
133 
134  tree_postfix_expression (int l = -1, int c = -1)
135  : tree_unary_expression (l, c, octave_value::unknown_unary_op) { }
136 
137  tree_postfix_expression (tree_expression *e, int l = -1, int c = -1,
140  : tree_unary_expression (e, l, c, t) { }
141 
142  // No copying!
143 
145 
147 
148  ~tree_postfix_expression (void) = default;
149 
150  bool rvalue_ok (void) const { return true; }
151 
152  tree_expression * dup (symbol_scope& scope) const;
153 
154  octave_value evaluate (tree_evaluator&, int nargout = 1);
155 
157  {
158  return ovl (evaluate (tw, nargout));
159  }
160 
161  void accept (tree_walker& tw)
162  {
163  tw.visit_postfix_expression (*this);
164  }
165 
166  std::string profiler_name (void) const { return "postfix " + oper (); }
167  };
168 }
169 
170 #endif
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:137
bool rvalue_ok(void) const
Definition: pt-unop.h:150
void accept(tree_walker &tw)
Definition: pt-unop.h:161
~tree_postfix_expression(void)=default
tree_postfix_expression & operator=(const tree_postfix_expression &)=delete
octave_value evaluate(tree_evaluator &, int nargout=1)
Definition: pt-unop.cc:121
std::string profiler_name(void) const
Definition: pt-unop.h:166
tree_postfix_expression(const tree_postfix_expression &)=delete
tree_expression * dup(symbol_scope &scope) const
Definition: pt-unop.cc:109
tree_postfix_expression(int l=-1, int c=-1)
Definition: pt-unop.h:134
octave_value_list evaluate_n(tree_evaluator &tw, int nargout=1)
Definition: pt-unop.h:156
octave_value_list evaluate_n(tree_evaluator &tw, int nargout=1)
Definition: pt-unop.h:115
tree_prefix_expression(const tree_prefix_expression &)=delete
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:96
~tree_prefix_expression(void)=default
bool rvalue_ok(void) const
Definition: pt-unop.h:109
std::string profiler_name(void) const
Definition: pt-unop.h:125
tree_prefix_expression & operator=(const tree_prefix_expression &)=delete
tree_expression * dup(symbol_scope &scope) const
Definition: pt-unop.cc:48
void accept(tree_walker &tw)
Definition: pt-unop.h:120
tree_prefix_expression(int l=-1, int c=-1)
Definition: pt-unop.h:93
octave_value evaluate(tree_evaluator &, int nargout=1)
Definition: pt-unop.cc:60
tree_unary_expression & operator=(const tree_unary_expression &)=delete
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
std::string oper(void) const
Definition: pt-unop.cc:40
tree_unary_expression(int l=-1, int c=-1, octave_value::unary_op t=octave_value::unknown_unary_op)
Definition: pt-unop.h:50
tree_unary_expression(const tree_unary_expression &)=delete
tree_expression * m_op
Definition: pt-unop.h:81
octave_value::unary_op m_etype
Definition: pt-unop.h:84
tree_expression * operand(void)
Definition: pt-unop.h:72
bool is_unary_expression(void) const
Definition: pt-unop.h:70
octave_value::unary_op op_type(void) const
Definition: pt-unop.h:76
virtual void visit_prefix_expression(tree_prefix_expression &)
Definition: pt-walk.cc:409
virtual void visit_postfix_expression(tree_postfix_expression &)
Definition: pt-walk.cc:401
unary_op
Definition: ov.h:83
@ unknown_unary_op
Definition: ov.h:92
octave_value_list ovl(const OV_Args &... args)
Construct an octave_value_list with less typing.
Definition: ovl.h:211