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-id.h
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 #if !defined (octave_pt_id_h)
24 #define octave_pt_id_h 1
25 
26 #include <iosfwd>
27 #include <string>
28 
29 class octave_value;
30 class octave_value_list;
31 class octave_function;
32 
33 class tree_walker;
34 
35 #include "pt-bp.h"
36 #include "pt-exp.h"
37 #include "symtab.h"
38 
39 // Symbols from the symbol table.
40 
41 class
43 {
44  friend class tree_index_expression;
45 
46 public:
47 
48  tree_identifier (int l = -1, int c = -1)
49  : tree_expression (l, c) { }
50 
52  int l = -1, int c = -1,
54  : tree_expression (l, c), sym (s, sc) { }
55 
56  ~tree_identifier (void) { }
57 
58  bool has_magic_end (void) const { return (name () == "end"); }
59 
60  bool is_identifier (void) const { return true; }
61 
62  // The name doesn't change with scope, so use sym instead of
63  // accessing it through sym so that this function may remain const.
64  std::string name (void) const { return sym.name (); }
65 
66  bool is_defined (void) { return sym->is_defined (); }
67 
68  virtual bool is_variable (void) { return sym->is_variable (); }
69 
70  virtual bool is_black_hole (void) { return false; }
71 
72  // Try to find a definition for an identifier. Here's how:
73  //
74  // * If the identifier is already defined and is a function defined
75  // in an function file that has been modified since the last time
76  // we parsed it, parse it again.
77  //
78  // * If the identifier is not defined, try to find a builtin
79  // variable or an already compiled function with the same name.
80  //
81  // * If the identifier is still undefined, try looking for an
82  // function file to parse.
83  //
84  // * On systems that support dynamic linking, we prefer .oct files,
85  // then .mex files, then .m files.
86 
88  do_lookup (const octave_value_list& args = octave_value_list ())
89  {
90  return sym->find (args);
91  }
92 
93  void mark_global (void) { sym->mark_global (); }
94 
95  void mark_as_static (void) { sym->init_persistent (); }
96 
97  void mark_as_formal_parameter (void) { sym->mark_formal (); }
98 
99  // We really need to know whether this symbol referst to a variable
100  // or a function, but we may not know that yet.
101 
102  bool lvalue_ok (void) const { return true; }
103 
104  octave_value rvalue1 (int nargout = 1);
105 
106  octave_value_list rvalue (int nargout)
107  {
108  return rvalue (nargout, 0);
109  }
110 
111  octave_value_list rvalue (int nargout,
112  const std::list<octave_lvalue> *lvalue_list);
113 
114  octave_lvalue lvalue (void);
115 
116  void eval_undefined_error (void);
117 
118  void static_workspace_error (void)
119  {
120  ::error ("can not add variable \"%s\" to a static workspace",
121  name ().c_str ());
122  }
123 
126 
127  void accept (tree_walker& tw);
128 
129  symbol_table::symbol_reference symbol (void) const
130  {
131  return sym;
132  }
133 private:
134 
135  // The symbol record that this identifier references.
137 
138  // No copying!
139 
141 
143 };
144 
146 {
147 public:
148 
149  tree_black_hole (int l = -1, int c = -1)
150  : tree_identifier (l, c) { }
151 
152  std::string name (void) const { return "~"; }
153 
154  bool is_variable (void) { return false; }
155 
156  bool is_black_hole (void) { return true; }
157 
158  tree_black_hole *dup (void) const
159  { return new tree_black_hole; }
160 
162  {
163  return octave_lvalue (); // black hole lvalue
164  }
165 };
166 
167 #endif