GNU Octave  4.4.1
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
pt-id.h
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 1996-2018 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
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
11 
12 Octave is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License 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 <https://www.gnu.org/licenses/>.
20 
21 */
22 
23 #if ! defined (octave_pt_id_h)
24 #define octave_pt_id_h 1
25 
26 #include "octave-config.h"
27 
28 #include <iosfwd>
29 #include <string>
30 
31 class octave_value;
32 class octave_value_list;
33 class octave_function;
34 
35 #include "oct-lvalue.h"
36 #include "pt-bp.h"
37 #include "pt-exp.h"
38 #include "pt-walk.h"
39 #include "symscope.h"
40 
41 namespace octave
42 {
43  class tree_evaluator;
44 
45  // Symbols from the symbol table.
46 
48  {
49  friend class tree_index_expression;
50 
51  public:
52 
53  tree_identifier (int l = -1, int c = -1)
54  : tree_expression (l, c), m_sym () { }
55 
57  int l = -1, int c = -1)
58  : tree_expression (l, c), m_sym (s) { }
59 
60  // No copying!
61 
62  tree_identifier (const tree_identifier&) = delete;
63 
65 
66  ~tree_identifier (void) = default;
67 
68  bool has_magic_end (void) const { return (name () == "end"); }
69 
70  bool is_identifier (void) const { return true; }
71 
72  std::string name (void) const { return m_sym.name (); }
73 
75  {
76  return m_sym.is_defined (context);
77  }
78 
80  {
81  return m_sym.is_variable (context);
82  }
83 
84  virtual bool is_black_hole (void) { return false; }
85 
86  // Try to find a definition for an identifier. Here's how:
87  //
88  // * If the identifier is already defined and is a function defined
89  // in an function file that has been modified since the last time
90  // we parsed it, parse it again.
91  //
92  // * If the identifier is not defined, try to find a builtin
93  // variable or an already compiled function with the same name.
94  //
95  // * If the identifier is still undefined, try looking for an
96  // function file to parse.
97  //
98  // * On systems that support dynamic linking, we prefer .oct files,
99  // then .mex files, then .m files.
100 
103  const octave_value_list& args = octave_value_list ())
104  {
105  return m_sym.find (context, args);
106  }
107 
108  void link_to_global (const symbol_scope& global_scope,
109  const symbol_record& global_sym);
110 
112 
114 
115  // We really need to know whether this symbol referst to a variable
116  // or a function, but we may not know that yet.
117 
118  bool lvalue_ok (void) const { return true; }
119 
121 
122  void eval_undefined_error (void);
123 
125  {
126  error (R"(can not add variable "%s" to a static workspace)",
127  name ().c_str ());
128  }
129 
130  tree_identifier * dup (symbol_scope& scope) const;
131 
132  void accept (tree_walker& tw)
133  {
134  tw.visit_identifier (*this);
135  }
136 
137  symbol_record symbol (void) const { return m_sym; }
138 
139  private:
140 
141  // The symbol record that this identifier references.
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 (symbol_record::context_id) const { return false; }
155 
156  bool is_black_hole (void) { return true; }
157 
159  {
160  return new tree_black_hole;
161  }
162 
164  {
166  retval.mark_black_hole ();
167  return retval;
168  }
169  };
170 }
171 
172 #if defined (OCTAVE_USE_DEPRECATED_FUNCTIONS)
173 
174 OCTAVE_DEPRECATED (4.4, "use 'octave::tree_identifier' instead")
175 typedef octave::tree_identifier tree_identifier;
176 
177 OCTAVE_DEPRECATED (4.4, "use 'octave::tree_black_hole' instead")
178 typedef octave::tree_black_hole tree_black_hole;
179 
180 #endif
181 
182 #endif
virtual bool is_variable(symbol_record::context_id context) const
Definition: pt-id.h:79
symbol_record symbol(void) const
Definition: pt-id.h:137
symbol_record m_sym
Definition: pt-id.h:142
void eval_undefined_error(void)
Definition: pt-id.cc:51
void link_to_global(const symbol_scope &global_scope, const symbol_record &global_sym)
Definition: pt-id.cc:43
octave_value find(context_id context, const octave_value_list &args=octave_value_list()) const
Definition: symrec.h:581
virtual void visit_identifier(tree_identifier &)=0
bool is_variable(context_id context) const
Definition: symrec.h:645
void error(const char *fmt,...)
Definition: error.cc:578
octave_lvalue lvalue(tree_evaluator *)
Definition: pt-id.cc:68
static llvm::LLVMContext & context
Definition: jit-typeinfo.cc:79
nd example oindent opens the file binary numeric values will be read assuming they are stored in IEEE format with the least significant bit and then converted to the native representation Opening a file that is already open simply opens it again and returns a separate file id It is not an error to open a file several though writing to the same file through several different file ids may produce unexpected results The possible values of text mode reading and writing automatically converts linefeeds to the appropriate line end character for the you may append a you must also open the file in binary mode The parameter conversions are currently only supported for and permissions will be set to and then everything is written in a single operation This is very efficient and improves performance c
Definition: file-io.cc:587
s
Definition: file-io.cc:2729
tree_black_hole * dup(symbol_scope &) const
Definition: pt-id.h:158
tree_black_hole(int l=-1, int c=-1)
Definition: pt-id.h:149
bool is_black_hole(void)
Definition: pt-id.h:156
virtual bool is_black_hole(void)
Definition: pt-id.h:84
std::string name(void) const
Definition: symrec.h:576
void mark_as_formal_parameter(void)
Definition: pt-id.h:113
tree_identifier(int l=-1, int c=-1)
Definition: pt-id.h:53
octave_value retval
Definition: data.cc:6246
octave_value do_lookup(symbol_record::context_id context, const octave_value_list &args=octave_value_list())
Definition: pt-id.h:102
void mark_formal(void)
Definition: symrec.h:662
bool lvalue_ok(void) const
Definition: pt-id.h:118
tree_identifier(const symbol_record &s, int l=-1, int c=-1)
Definition: pt-id.h:56
bool is_identifier(void) const
Definition: pt-id.h:70
~tree_identifier(void)=default
void init_persistent(void)
Definition: symrec.h:679
tree_identifier * dup(symbol_scope &scope) const
Definition: pt-id.cc:79
bool is_defined(context_id context) const
Definition: symrec.h:635
bool is_variable(symbol_record::context_id) const
Definition: pt-id.h:154
void accept(tree_walker &tw)
Definition: pt-id.h:132
void static_workspace_error(void)
Definition: pt-id.h:124
octave_lvalue lvalue(tree_evaluator *)
Definition: pt-id.h:163
std::string name(void) const
Definition: pt-id.h:72
void mark_persistent(void)
Definition: pt-id.h:111
std::string name(void) const
Definition: pt-id.h:152
If this string is the system will ring the terminal sometimes it is useful to be able to print the original representation of the string
Definition: utils.cc:888
bool is_defined(symbol_record::context_id context)
Definition: pt-id.h:74
tree_identifier & operator=(const tree_identifier &)=delete
bool has_magic_end(void) const
Definition: pt-id.h:68