pt-unop.cc

Go to the documentation of this file.
00001 /*
00002 
00003 Copyright (C) 1996-2012 John W. Eaton
00004 
00005 This file is part of Octave.
00006 
00007 Octave is free software; you can redistribute it and/or modify it
00008 under the terms of the GNU General Public License as published by the
00009 Free Software Foundation; either version 3 of the License, or (at your
00010 option) any later version.
00011 
00012 Octave is distributed in the hope that it will be useful, but WITHOUT
00013 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00014 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00015 for more details.
00016 
00017 You should have received a copy of the GNU General Public License
00018 along with Octave; see the file COPYING.  If not, see
00019 <http://www.gnu.org/licenses/>.
00020 
00021 */
00022 
00023 #ifdef HAVE_CONFIG_H
00024 #include <config.h>
00025 #endif
00026 
00027 #include "error.h"
00028 #include "oct-obj.h"
00029 #include "oct-lvalue.h"
00030 #include "ov.h"
00031 #include "profiler.h"
00032 #include "pt-bp.h"
00033 #include "pt-unop.h"
00034 #include "pt-walk.h"
00035 
00036 // Unary expressions.
00037 
00038 std::string
00039 tree_unary_expression::oper (void) const
00040 {
00041   return octave_value::unary_op_as_string (etype);
00042 }
00043 
00044 // Prefix expressions.
00045 
00046 octave_value_list
00047 tree_prefix_expression::rvalue (int nargout)
00048 {
00049   octave_value_list retval;
00050 
00051   if (nargout > 1)
00052     error ("prefix operator '%s': invalid number of output arguments",
00053            oper () . c_str ());
00054   else
00055     retval = rvalue1 (nargout);
00056 
00057   return retval;
00058 }
00059 
00060 octave_value
00061 tree_prefix_expression::rvalue1 (int)
00062 {
00063   octave_value retval;
00064 
00065   if (error_state)
00066     return retval;
00067 
00068   if (op)
00069     {
00070       if (etype == octave_value::op_incr || etype == octave_value::op_decr)
00071         {
00072           octave_lvalue ref = op->lvalue ();
00073 
00074           if (! error_state)
00075             {
00076               BEGIN_PROFILER_BLOCK ("prefix " + oper ())
00077 
00078               ref.do_unary_op (etype);
00079 
00080               if (! error_state)
00081                 retval = ref.value ();
00082 
00083               END_PROFILER_BLOCK
00084             }
00085         }
00086       else
00087         {
00088           octave_value val = op->rvalue1 ();
00089 
00090           if (! error_state && val.is_defined ())
00091             {
00092               BEGIN_PROFILER_BLOCK ("prefix " + oper ())
00093 
00094               // Attempt to do the operation in-place if it is unshared
00095               // (a temporary expression).
00096               if (val.get_count () == 1)
00097                 retval = val.do_non_const_unary_op (etype);
00098               else
00099                 retval = ::do_unary_op (etype, val);
00100 
00101               if (error_state)
00102                 retval = octave_value ();
00103 
00104               END_PROFILER_BLOCK
00105             }
00106         }
00107     }
00108 
00109   return retval;
00110 }
00111 
00112 tree_expression *
00113 tree_prefix_expression::dup (symbol_table::scope_id scope,
00114                              symbol_table::context_id context) const
00115 {
00116   tree_prefix_expression *new_pe
00117     = new tree_prefix_expression (op ? op->dup (scope, context) : 0,
00118                                   line (), column (), etype);
00119 
00120   new_pe->copy_base (*this);
00121 
00122   return new_pe;
00123 }
00124 
00125 void
00126 tree_prefix_expression::accept (tree_walker& tw)
00127 {
00128   tw.visit_prefix_expression (*this);
00129 }
00130 
00131 // Postfix expressions.
00132 
00133 octave_value_list
00134 tree_postfix_expression::rvalue (int nargout)
00135 {
00136   octave_value_list retval;
00137 
00138   if (nargout > 1)
00139     error ("postfix operator '%s': invalid number of output arguments",
00140            oper () . c_str ());
00141   else
00142     retval = rvalue1 (nargout);
00143 
00144   return retval;
00145 }
00146 
00147 octave_value
00148 tree_postfix_expression::rvalue1 (int)
00149 {
00150   octave_value retval;
00151 
00152   if (error_state)
00153     return retval;
00154 
00155   if (op)
00156     {
00157       if (etype == octave_value::op_incr || etype == octave_value::op_decr)
00158         {
00159           octave_lvalue ref = op->lvalue ();
00160 
00161           if (! error_state)
00162             {
00163               retval = ref.value ();
00164 
00165               BEGIN_PROFILER_BLOCK ("postfix " + oper ())
00166               ref.do_unary_op (etype);
00167               END_PROFILER_BLOCK
00168             }
00169         }
00170       else
00171         {
00172           octave_value val = op->rvalue1 ();
00173 
00174           if (! error_state && val.is_defined ())
00175             {
00176               BEGIN_PROFILER_BLOCK ("postfix " + oper ())
00177 
00178               retval = ::do_unary_op (etype, val);
00179 
00180               if (error_state)
00181                 retval = octave_value ();
00182 
00183               END_PROFILER_BLOCK
00184             }
00185         }
00186     }
00187 
00188   return retval;
00189 }
00190 
00191 tree_expression *
00192 tree_postfix_expression::dup (symbol_table::scope_id scope,
00193                               symbol_table::context_id context) const
00194 {
00195   tree_postfix_expression *new_pe
00196     = new tree_postfix_expression (op ? op->dup (scope, context) : 0,
00197                                    line (), column (), etype);
00198 
00199   new_pe->copy_base (*this);
00200 
00201   return new_pe;
00202 }
00203 
00204 void
00205 tree_postfix_expression::accept (tree_walker& tw)
00206 {
00207   tw.visit_postfix_expression (*this);
00208 }
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines