pt-const.h

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 #if !defined (octave_tree_const_h)
00024 #define octave_tree_const_h 1
00025 
00026 #include <iosfwd>
00027 #include <string>
00028 
00029 #include "oct-alloc.h"
00030 
00031 class octave_value_list;
00032 class tree_walker;
00033 
00034 #include "ov.h"
00035 #include "pt-bp.h"
00036 #include "pt-exp.h"
00037 #include "symtab.h"
00038 
00039 class
00040 tree_constant : public tree_expression
00041 {
00042 public:
00043 
00044   tree_constant (int l = -1, int c = -1)
00045     : tree_expression (l, c), val (), orig_text () { }
00046 
00047   tree_constant (const octave_value& v, int l = -1, int c = -1)
00048     : tree_expression (l, c), val (v), orig_text () { }
00049 
00050   tree_constant (const octave_value& v, const std::string& ot,
00051                  int l = -1, int c = -1)
00052     : tree_expression (l, c), val (v), orig_text (ot) { }
00053 
00054   ~tree_constant (void) { }
00055 
00056   bool has_magic_end (void) const { return false; }
00057 
00058   // Type.  It would be nice to eliminate the need for this.
00059 
00060   bool is_constant (void) const { return true; }
00061 
00062   void maybe_mutate (void) { val.maybe_mutate (); }
00063 
00064   void print (std::ostream& os, bool pr_as_read_syntax = false,
00065               bool pr_orig_txt = true);
00066 
00067   void print_raw (std::ostream& os, bool pr_as_read_syntax = false,
00068                   bool pr_orig_txt = true);
00069 
00070   bool rvalue_ok (void) const { return true; }
00071 
00072   octave_value rvalue1 (int = 1) { return val; }
00073 
00074   octave_value_list rvalue (int nargout);
00075 
00076   tree_expression *dup (symbol_table::scope_id scope,
00077                         symbol_table::context_id context) const;
00078 
00079   void accept (tree_walker& tw);
00080 
00081   // Store the original text corresponding to this constant for later
00082   // pretty printing.
00083 
00084   void stash_original_text (const std::string& s) { orig_text = s; }
00085 
00086   std::string original_text (void) const { return orig_text; }
00087 
00088 private:
00089 
00090   // The actual value that this constant refers to.
00091   octave_value val;
00092 
00093   // The original text form of this constant.
00094   std::string orig_text;
00095 
00096   // No copying!
00097 
00098   tree_constant (const tree_constant&);
00099 
00100   tree_constant& operator = (const tree_constant&);
00101 
00102   DECLARE_OCTAVE_ALLOCATOR
00103 };
00104 
00105 #endif
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines