pt-const.cc

Go to the documentation of this file.
00001 /*
00002 
00003 Copyright (C) 1993-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 <iostream>
00028 
00029 #include "error.h"
00030 #include "oct-obj.h"
00031 #include "pager.h"
00032 #include "pt-const.h"
00033 #include "pt-walk.h"
00034 
00035 // We are likely to have a lot of tree_constant objects to allocate,
00036 // so make the grow_size large.
00037 DEFINE_OCTAVE_ALLOCATOR2 (tree_constant, 1024);
00038 
00039 void
00040 tree_constant::print (std::ostream& os, bool pr_as_read_syntax, bool pr_orig_text)
00041 {
00042   if (pr_orig_text && ! orig_text.empty ())
00043     os << orig_text;
00044   else
00045     val.print (os, pr_as_read_syntax);
00046 }
00047 
00048 void
00049 tree_constant::print_raw (std::ostream& os, bool pr_as_read_syntax,
00050                           bool pr_orig_text)
00051 {
00052   if (pr_orig_text && ! orig_text.empty ())
00053     os << orig_text;
00054   else
00055     val.print_raw (os, pr_as_read_syntax);
00056 }
00057 
00058 octave_value_list
00059 tree_constant::rvalue (int nargout)
00060 {
00061   octave_value_list retval;
00062 
00063   if (nargout > 1)
00064     error ("invalid number of output arguments for constant expression");
00065   else
00066     retval = rvalue1 (nargout);
00067 
00068   return retval;
00069 }
00070 
00071 tree_expression *
00072 tree_constant::dup (symbol_table::scope_id,
00073                     symbol_table::context_id) const
00074 {
00075   tree_constant *new_tc
00076     = new tree_constant (val, orig_text, line (), column ());
00077 
00078   new_tc->copy_base (*this);
00079 
00080   return new_tc;
00081 }
00082 
00083 void
00084 tree_constant::accept (tree_walker& tw)
00085 {
00086   tw.visit_constant (*this);
00087 }
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines