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