GNU Octave  4.2.1
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
pt-unop.cc
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 1996-2017 John W. Eaton
4 
5 This file is part of Octave.
6 
7 Octave is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by the
9 Free Software Foundation; either version 3 of the License, or (at your
10 option) any later version.
11 
12 Octave is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 for more details.
16 
17 You should have received a copy of the GNU General Public License
18 along with Octave; see the file COPYING. If not, see
19 <http://www.gnu.org/licenses/>.
20 
21 */
22 
23 #if defined (HAVE_CONFIG_H)
24 # include "config.h"
25 #endif
26 
27 #include "error.h"
28 #include "ovl.h"
29 #include "oct-lvalue.h"
30 #include "ov.h"
31 #include "profiler.h"
32 #include "pt-bp.h"
33 #include "pt-unop.h"
34 #include "pt-walk.h"
35 
36 // Unary expressions.
37 
40 {
42 }
43 
44 // Prefix expressions.
45 
48 {
50 
51  if (nargout > 1)
52  error ("prefix operator '%s': invalid number of output arguments",
53  oper ().c_str ());
54 
55  retval = rvalue1 (nargout);
56 
57  return retval;
58 }
59 
62 {
64 
65  if (op)
66  {
68  {
69  octave_lvalue ref = op->lvalue ();
70 
72 
73  ref.do_unary_op (etype);
74 
75  retval = ref.value ();
76 
78  }
79  else
80  {
81  octave_value val = op->rvalue1 ();
82 
83  if (val.is_defined ())
84  {
86 
87  // Attempt to do the operation in-place if it is unshared
88  // (a temporary expression).
89  if (val.get_count () == 1)
90  retval = val.do_non_const_unary_op (etype);
91  else
92  retval = ::do_unary_op (etype, val);
93 
95  }
96  }
97  }
98 
99  return retval;
100 }
101 
105 {
106  tree_prefix_expression *new_pe
107  = new tree_prefix_expression (op ? op->dup (scope, context) : 0,
108  line (), column (), etype);
109 
110  new_pe->copy_base (*this);
111 
112  return new_pe;
113 }
114 
115 void
117 {
118  tw.visit_prefix_expression (*this);
119 }
120 
121 // Postfix expressions.
122 
125 {
127 
128  if (nargout > 1)
129  error ("postfix operator '%s': invalid number of output arguments",
130  oper ().c_str ());
131 
132  retval = rvalue1 (nargout);
133 
134  return retval;
135 }
136 
139 {
141 
142  if (op)
143  {
145  {
146  octave_lvalue ref = op->lvalue ();
147 
148  retval = ref.value ();
149 
151 
152  ref.do_unary_op (etype);
153 
155  }
156  else
157  {
158  octave_value val = op->rvalue1 ();
159 
160  if (val.is_defined ())
161  {
163 
164  retval = ::do_unary_op (etype, val);
165 
167  }
168  }
169  }
170 
171  return retval;
172 }
173 
177 {
179  = new tree_postfix_expression (op ? op->dup (scope, context) : 0,
180  line (), column (), etype);
181 
182  new_pe->copy_base (*this);
183 
184  return new_pe;
185 }
186 
187 void
189 {
190  tw.visit_postfix_expression (*this);
191 }
void accept(tree_walker &tw)
Definition: pt-unop.cc:116
identity matrix If supplied two scalar respectively For allows like xample val
Definition: data.cc:5068
octave_value do_unary_op(octave_value::unary_op op, const octave_value &v)
Definition: ov.cc:2645
bool is_defined(void) const
Definition: ov.h:536
virtual void visit_postfix_expression(tree_postfix_expression &)=0
virtual tree_expression * dup(symbol_table::scope_id, symbol_table::context_id context) const =0
void error(const char *fmt,...)
Definition: error.cc:570
octave_value rvalue1(int nargout=1)
Definition: pt-unop.cc:61
tree_postfix_expression(int l=-1, int c=-1)
Definition: pt-unop.h:131
void do_unary_op(octave_value::unary_op op)
Definition: oct-lvalue.cc:71
virtual void copy_base(const tree_expression &e)
Definition: pt-exp.h:131
#define END_PROFILER_BLOCK
Definition: profiler.h:215
void accept(tree_walker &tw)
Definition: pt-unop.cc:188
octave_value & do_non_const_unary_op(unary_op op)
Definition: ov.cc:2704
tree_prefix_expression(int l=-1, int c=-1)
Definition: pt-unop.h:92
octave_value::unary_op etype
Definition: pt-unop.h:74
tree_expression * op
Definition: pt-unop.h:71
octave_value_list rvalue(int nargout)
Definition: pt-unop.cc:47
octave_value value(void) const
Definition: oct-lvalue.cc:83
tree_expression * dup(symbol_table::scope_id scope, symbol_table::context_id context) const
Definition: pt-unop.cc:175
OCTAVE_EXPORT octave_value_list return the number of command line arguments passed to Octave If called with the optional argument the function xample nargout(@histc)
Definition: ov-usr-fcn.cc:935
octave_value rvalue1(int nargout=1)
Definition: pt-unop.cc:138
static llvm::LLVMContext & context
Definition: jit-typeinfo.cc:76
std::string oper(void) const
Definition: pt-unop.cc:39
octave_value retval
Definition: data.cc:6294
virtual int line(void) const
Definition: pt.h:49
virtual octave_value rvalue1(int nargout=1)
Definition: pt-exp.cc:54
tree_expression * dup(symbol_table::scope_id scope, symbol_table::context_id context) const
Definition: pt-unop.cc:103
octave_value_list rvalue(int nargout)
Definition: pt-unop.cc:124
virtual octave_lvalue lvalue(void)
Definition: pt-exp.cc:72
octave_idx_type get_count(void) const
Definition: ov.h:372
static std::string unary_op_as_string(unary_op)
Definition: ov.cc:119
virtual void visit_prefix_expression(tree_prefix_expression &)=0
virtual int column(void) const
Definition: pt.h:51
If this string is the system will ring the terminal sometimes it is useful to be able to print the original representation of the string
Definition: utils.cc:854
#define BEGIN_PROFILER_BLOCK(classname)
Definition: profiler.h:211