GNU Octave  4.2.1
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-2017 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 "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 class tree_walker;
36 
37 #include "oct-lvalue.h"
38 #include "pt-bp.h"
39 #include "pt-exp.h"
40 #include "symtab.h"
41 
42 // Symbols from the symbol table.
43 
44 class
46 {
47  friend class tree_index_expression;
48 
49 public:
50 
51  tree_identifier (int l = -1, int c = -1)
52  : tree_expression (l, c) { }
53 
55  int l = -1, int c = -1,
57  : tree_expression (l, c), sym (s, sc) { }
58 
59  ~tree_identifier (void) { }
60 
61  bool has_magic_end (void) const { return (name () == "end"); }
62 
63  bool is_identifier (void) const { return true; }
64 
65  // The name doesn't change with scope, so use sym instead of
66  // accessing it through sym so that this function may remain const.
67  std::string name (void) const { return sym.name (); }
68 
69  bool is_defined (void) { return sym->is_defined (); }
70 
71  virtual bool is_variable (void) const { return sym->is_variable (); }
72 
73  virtual bool is_black_hole (void) { return false; }
74 
75  // Try to find a definition for an identifier. Here's how:
76  //
77  // * If the identifier is already defined and is a function defined
78  // in an function file that has been modified since the last time
79  // we parsed it, parse it again.
80  //
81  // * If the identifier is not defined, try to find a builtin
82  // variable or an already compiled function with the same name.
83  //
84  // * If the identifier is still undefined, try looking for an
85  // function file to parse.
86  //
87  // * On systems that support dynamic linking, we prefer .oct files,
88  // then .mex files, then .m files.
89 
92  {
93  return sym->find (args);
94  }
95 
96  void mark_global (void) { sym->mark_global (); }
97 
98  void mark_as_static (void) { sym->init_persistent (); }
99 
100  void mark_as_formal_parameter (void) { sym->mark_formal (); }
101 
102  // We really need to know whether this symbol referst to a variable
103  // or a function, but we may not know that yet.
104 
105  bool lvalue_ok (void) const { return true; }
106 
107  octave_value rvalue1 (int nargout = 1);
108 
110  {
111  return rvalue (nargout, 0);
112  }
113 
115  const std::list<octave_lvalue> *lvalue_list);
116 
117  octave_lvalue lvalue (void);
118 
119  void eval_undefined_error (void);
120 
122  {
123  error ("can not add variable \"%s\" to a static workspace",
124  name ().c_str ());
125  }
126 
129 
130  void accept (tree_walker& tw);
131 
133  {
134  return sym;
135  }
136 private:
137 
138  // The symbol record that this identifier references.
140 
141  // No copying!
142 
144 
146 };
147 
149 {
150 public:
151 
152  tree_black_hole (int l = -1, int c = -1)
153  : tree_identifier (l, c) { }
154 
155  std::string name (void) const { return "~"; }
156 
157  bool is_variable (void) const { return false; }
158 
159  bool is_black_hole (void) { return true; }
160 
163  {
164  return new tree_black_hole;
165  }
166 
168  {
169  return octave_lvalue (); // black hole lvalue
170  }
171 };
172 
173 #endif
void mark_as_formal_parameter(void)
Definition: pt-id.h:100
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:54
octave_value_list rvalue(int nargout)
Definition: pt-idx.cc:267
For example cd octave end example noindent changes the current working directory to an error message is printed and the working directory is not changed sc
Definition: dirfns.cc:120
void mark_global(void)
Definition: pt-id.h:96
octave_lvalue lvalue(void)
Definition: pt-id.h:167
symbol_table::symbol_reference sym
Definition: pt-id.h:139
bool is_variable(void) const
Definition: pt-id.h:157
bool is_identifier(void) const
Definition: pt-id.h:63
symbol_table::symbol_reference symbol(void) const
Definition: pt-id.h:132
bool is_defined(void)
Definition: pt-id.h:69
void error(const char *fmt,...)
Definition: error.cc:570
s
Definition: file-io.cc:2682
virtual bool is_variable(void) const
Definition: pt-id.h:71
std::string name(void) const
Definition: pt-id.h:155
bool lvalue_ok(void) const
Definition: pt-id.h:105
octave_lvalue lvalue(void)
Definition: pt-idx.cc:470
bool is_black_hole(void)
Definition: pt-id.h:159
JNIEnv void * args
Definition: ov-java.cc:67
bool has_magic_end(void) const
Definition: pt-id.h:61
void mark_as_static(void)
Definition: pt-id.h:98
OCTAVE_EXPORT octave_value_list any number nd example oindent prints the prompt xample Pick a any number!nd example oindent and waits for the user to enter a value The string entered by the user is evaluated as an so it may be a literal a variable name
Definition: input.cc:871
octave_value_list rvalue(int nargout)
Definition: pt-id.h:109
OCTAVE_EXPORT octave_value_list return the number of command line arguments passed to Octave If called with the optional argument the function xample nargout(@histc)
Definition: ov-usr-fcn.cc:935
void static_workspace_error(void)
Definition: pt-id.h:121
octave_value rvalue1(int nargout=1)
Definition: pt-idx.cc:457
static llvm::LLVMContext & context
Definition: jit-typeinfo.cc:76
std::string name(void) const
Definition: pt-id.h:67
virtual bool is_black_hole(void)
Definition: pt-id.h:73
tree_identifier(int l=-1, int c=-1)
Definition: pt-id.h:51
the sparsity preserving column transformation such that that defines the pivoting threshold can be given in which case it defines the c
Definition: lu.cc:138
void accept(tree_walker &tw)
Definition: pt-idx.cc:703
octave_value do_lookup(const octave_value_list &args=octave_value_list())
Definition: pt-id.h:91
tree_black_hole(int l=-1, int c=-1)
Definition: pt-id.h:152
tree_index_expression & operator=(const tree_index_expression &)
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:854
~tree_identifier(void)
Definition: pt-id.h:59
static scope_id current_scope(void)
Definition: symtab.h:1163
tree_index_expression * dup(symbol_table::scope_id scope, symbol_table::context_id context) const
Definition: pt-idx.cc:659
tree_black_hole * dup(symbol_table::scope_id, symbol_table::context_id) const
Definition: pt-id.h:161