GNU Octave  4.0.0
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-2015 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 #ifdef HAVE_CONFIG_H
24 #include <config.h>
25 #endif
26 
27 #include "error.h"
28 #include "oct-obj.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 
38 std::string
40 {
42 }
43 
44 // Prefix expressions.
45 
48 {
49  octave_value_list retval;
50 
51  if (nargout > 1)
52  error ("prefix operator '%s': invalid number of output arguments",
53  oper () . c_str ());
54  else
55  retval = rvalue1 (nargout);
56 
57  return retval;
58 }
59 
62 {
63  octave_value retval;
64 
65  if (error_state)
66  return retval;
67 
68  if (op)
69  {
71  {
72  octave_lvalue ref = op->lvalue ();
73 
74  if (! error_state)
75  {
77 
78  ref.do_unary_op (etype);
79 
80  if (! error_state)
81  retval = ref.value ();
82 
84  }
85  }
86  else
87  {
88  octave_value val = op->rvalue1 ();
89 
90  if (! error_state && val.is_defined ())
91  {
93 
94  // Attempt to do the operation in-place if it is unshared
95  // (a temporary expression).
96  if (val.get_count () == 1)
97  retval = val.do_non_const_unary_op (etype);
98  else
99  retval = ::do_unary_op (etype, val);
100 
101  if (error_state)
102  retval = octave_value ();
103 
105  }
106  }
107  }
108 
109  return retval;
110 }
111 
115 {
116  tree_prefix_expression *new_pe
117  = new tree_prefix_expression (op ? op->dup (scope, context) : 0,
118  line (), column (), etype);
119 
120  new_pe->copy_base (*this);
121 
122  return new_pe;
123 }
124 
125 void
127 {
128  tw.visit_prefix_expression (*this);
129 }
130 
131 // Postfix expressions.
132 
135 {
136  octave_value_list retval;
137 
138  if (nargout > 1)
139  error ("postfix operator '%s': invalid number of output arguments",
140  oper () . c_str ());
141  else
142  retval = rvalue1 (nargout);
143 
144  return retval;
145 }
146 
149 {
150  octave_value retval;
151 
152  if (error_state)
153  return retval;
154 
155  if (op)
156  {
158  {
159  octave_lvalue ref = op->lvalue ();
160 
161  if (! error_state)
162  {
163  retval = ref.value ();
164 
166 
167  ref.do_unary_op (etype);
168 
170  }
171  }
172  else
173  {
174  octave_value val = op->rvalue1 ();
175 
176  if (! error_state && val.is_defined ())
177  {
179 
180  retval = ::do_unary_op (etype, val);
181 
182  if (error_state)
183  retval = octave_value ();
184 
186  }
187  }
188  }
189 
190  return retval;
191 }
192 
196 {
198  = new tree_postfix_expression (op ? op->dup (scope, context) : 0,
199  line (), column (), etype);
200 
201  new_pe->copy_base (*this);
202 
203  return new_pe;
204 }
205 
206 void
208 {
209  tw.visit_postfix_expression (*this);
210 }
void accept(tree_walker &tw)
Definition: pt-unop.cc:126
octave_value do_unary_op(octave_value::unary_op op, const octave_value &v)
Definition: ov.cc:2511
bool is_defined(void) const
Definition: ov.h:520
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:476
octave_value rvalue1(int nargout=1)
Definition: pt-unop.cc:61
tree_postfix_expression(int l=-1, int c=-1)
Definition: pt-unop.h:130
void do_unary_op(octave_value::unary_op op)
Definition: oct-lvalue.cc:58
virtual void copy_base(const tree_expression &e)
Definition: pt-exp.h:129
#define END_PROFILER_BLOCK
Definition: profiler.h:213
void accept(tree_walker &tw)
Definition: pt-unop.cc:207
octave_value & do_non_const_unary_op(unary_op op)
Definition: ov.cc:2593
tree_prefix_expression(int l=-1, int c=-1)
Definition: pt-unop.h:90
octave_value::unary_op etype
Definition: pt-unop.h:72
tree_expression * op
Definition: pt-unop.h:69
octave_value_list rvalue(int nargout)
Definition: pt-unop.cc:47
octave_value value(void) const
Definition: oct-lvalue.cc:70
tree_expression * dup(symbol_table::scope_id scope, symbol_table::context_id context) const
Definition: pt-unop.cc:194
octave_value rvalue1(int nargout=1)
Definition: pt-unop.cc:148
static llvm::LLVMContext & context
Definition: jit-typeinfo.cc:76
int error_state
Definition: error.cc:101
std::string oper(void) const
Definition: pt-unop.cc:39
virtual int line(void) const
Definition: pt.h:45
virtual octave_value rvalue1(int nargout=1)
Definition: pt-exp.cc:58
tree_expression * dup(symbol_table::scope_id scope, symbol_table::context_id context) const
Definition: pt-unop.cc:113
octave_value_list rvalue(int nargout)
Definition: pt-unop.cc:134
virtual octave_lvalue lvalue(void)
Definition: pt-exp.cc:78
octave_idx_type get_count(void) const
Definition: ov.h:371
static std::string unary_op_as_string(unary_op)
Definition: ov.cc:114
virtual void visit_prefix_expression(tree_prefix_expression &)=0
virtual int column(void) const
Definition: pt.h:47
#define BEGIN_PROFILER_BLOCK(classname)
Definition: profiler.h:209
return octave_value(v1.char_array_value().concat(v2.char_array_value(), ra_idx),((a1.is_sq_string()||a2.is_sq_string())? '\'': '"'))