GNU Octave  3.8.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-2013 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  {
76  BEGIN_PROFILER_BLOCK ("prefix " + oper ())
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  {
92  BEGIN_PROFILER_BLOCK ("prefix " + oper ())
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 
165  BEGIN_PROFILER_BLOCK ("postfix " + oper ())
166  ref.do_unary_op (etype);
168  }
169  }
170  else
171  {
172  octave_value val = op->rvalue1 ();
173 
174  if (! error_state && val.is_defined ())
175  {
176  BEGIN_PROFILER_BLOCK ("postfix " + oper ())
177 
178  retval = ::do_unary_op (etype, val);
179 
180  if (error_state)
181  retval = octave_value ();
182 
184  }
185  }
186  }
187 
188  return retval;
189 }
190 
194 {
196  = new tree_postfix_expression (op ? op->dup (scope, context) : 0,
197  line (), column (), etype);
198 
199  new_pe->copy_base (*this);
200 
201  return new_pe;
202 }
203 
204 void
206 {
207  tw.visit_postfix_expression (*this);
208 }