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-const.h
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 1993-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 #if !defined (octave_pt_const_h)
24 #define octave_pt_const_h 1
25 
26 #include <iosfwd>
27 #include <string>
28 
29 #include "oct-alloc.h"
30 
31 class octave_value_list;
32 class tree_walker;
33 
34 #include "ov.h"
35 #include "pt-bp.h"
36 #include "pt-exp.h"
37 #include "symtab.h"
38 
39 class
41 {
42 public:
43 
44  tree_constant (int l = -1, int c = -1)
45  : tree_expression (l, c), val (), orig_text () { }
46 
47  tree_constant (const octave_value& v, int l = -1, int c = -1)
48  : tree_expression (l, c), val (v), orig_text () { }
49 
50  tree_constant (const octave_value& v, const std::string& ot,
51  int l = -1, int c = -1)
52  : tree_expression (l, c), val (v), orig_text (ot) { }
53 
54  ~tree_constant (void) { }
55 
56  bool has_magic_end (void) const { return false; }
57 
58  // Type. It would be nice to eliminate the need for this.
59 
60  bool is_constant (void) const { return true; }
61 
62  void maybe_mutate (void) { val.maybe_mutate (); }
63 
64  void print (std::ostream& os, bool pr_as_read_syntax = false,
65  bool pr_orig_txt = true);
66 
67  void print_raw (std::ostream& os, bool pr_as_read_syntax = false,
68  bool pr_orig_txt = true);
69 
70  bool rvalue_ok (void) const { return true; }
71 
72  octave_value rvalue1 (int = 1) { return val; }
73 
74  octave_value_list rvalue (int nargout);
75 
78 
79  void accept (tree_walker& tw);
80 
81  // Store the original text corresponding to this constant for later
82  // pretty printing.
83 
84  void stash_original_text (const std::string& s) { orig_text = s; }
85 
86  std::string original_text (void) const { return orig_text; }
87 
88 private:
89 
90  // The actual value that this constant refers to.
92 
93  // The original text form of this constant.
94  std::string orig_text;
95 
96  // No copying!
97 
99 
101 
103 };
104 
105 #endif