GNU Octave  6.2.0
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-2021 The Octave Project Developers
4 //
5 // See the file COPYRIGHT.md in the top-level directory of this
6 // distribution or <https://octave.org/copyright/>.
7 //
8 // This file is part of Octave.
9 //
10 // Octave is free software: you can redistribute it and/or modify it
11 // under the terms of the GNU General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // Octave is distributed in the hope that it will be useful, but
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU General Public License for more details.
19 //
20 // You should have received a copy of the GNU General Public License
21 // along with Octave; see the file COPYING. If not, see
22 // <https://www.gnu.org/licenses/>.
23 //
24 ////////////////////////////////////////////////////////////////////////
25 
26 #if ! defined (octave_pt_id_h)
27 #define octave_pt_id_h 1
28 
29 #include "octave-config.h"
30 
31 #include <iosfwd>
32 #include <string>
33 
34 class octave_value;
35 class octave_value_list;
36 class octave_function;
37 
38 #include "oct-lvalue.h"
39 #include "pt-bp.h"
40 #include "pt-exp.h"
41 #include "pt-walk.h"
42 #include "symscope.h"
43 
44 namespace octave
45 {
46  class tree_evaluator;
47 
48  // Symbols from the symbol table.
49 
51  {
52  friend class tree_index_expression;
53 
54  public:
55 
56  tree_identifier (int l = -1, int c = -1)
57  : tree_expression (l, c), m_sym () { }
58 
60  int l = -1, int c = -1)
61  : tree_expression (l, c), m_sym (s) { }
62 
63  // No copying!
64 
65  tree_identifier (const tree_identifier&) = delete;
66 
68 
69  ~tree_identifier (void) = default;
70 
71  bool is_identifier (void) const { return true; }
72 
73  std::string name (void) const { return m_sym.name (); }
74 
75  virtual bool is_black_hole (void) const { return false; }
76 
78 
79  // We really need to know whether this symbol refers to a variable
80  // or a function, but we may not know that yet.
81 
82  bool lvalue_ok (void) const { return true; }
83 
85 
86  void eval_undefined_error (void);
87 
89  {
90  error (R"(can not add variable "%s" to a static workspace)",
91  name ().c_str ());
92  }
93 
94  tree_identifier * dup (symbol_scope& scope) const;
95 
96  octave_value evaluate (tree_evaluator& tw, int nargout = 1)
97  {
98  octave_value_list retval = evaluate_n (tw, nargout);
99 
100  return retval.length () > 0 ? retval(0) : octave_value ();
101  }
102 
103  octave_value_list evaluate_n (tree_evaluator& tw, int nargout = 1);
104 
105  void accept (tree_walker& tw)
106  {
107  tw.visit_identifier (*this);
108  }
109 
110  symbol_record symbol (void) const { return m_sym; }
111 
112  protected:
113 
114  // The symbol record that this identifier references.
116  };
117 
119  {
120  public:
121 
122  tree_black_hole (int l = -1, int c = -1)
123  : tree_identifier (l, c) { }
124 
125  std::string name (void) const { return "~"; }
126 
127  bool is_black_hole (void) const { return true; }
128 
130  {
131  return new tree_black_hole;
132  }
133 
135  };
136 }
137 
138 #endif
void mark_formal(void)
Definition: symrec.h:194
std::string name(void) const
Definition: symrec.h:185
octave_lvalue lvalue(tree_evaluator &tw)
Definition: pt-id.cc:154
std::string name(void) const
Definition: pt-id.h:125
tree_black_hole * dup(symbol_scope &) const
Definition: pt-id.h:129
bool is_black_hole(void) const
Definition: pt-id.h:127
tree_black_hole(int l=-1, int c=-1)
Definition: pt-id.h:122
tree_identifier(int l=-1, int c=-1)
Definition: pt-id.h:56
tree_identifier * dup(symbol_scope &scope) const
Definition: pt-id.cc:78
octave_value evaluate(tree_evaluator &tw, int nargout=1)
Definition: pt-id.h:96
octave_value_list evaluate_n(tree_evaluator &tw, int nargout=1)
Definition: pt-id.cc:94
symbol_record m_sym
Definition: pt-id.h:115
tree_identifier(const symbol_record &s, int l=-1, int c=-1)
Definition: pt-id.h:59
void eval_undefined_error(void)
Definition: pt-id.cc:45
~tree_identifier(void)=default
octave_lvalue lvalue(tree_evaluator &tw)
Definition: pt-id.cc:69
bool is_identifier(void) const
Definition: pt-id.h:71
bool lvalue_ok(void) const
Definition: pt-id.h:82
std::string name(void) const
Definition: pt-id.h:73
void accept(tree_walker &tw)
Definition: pt-id.h:105
tree_identifier & operator=(const tree_identifier &)=delete
void mark_as_formal_parameter(void)
Definition: pt-id.h:77
symbol_record symbol(void) const
Definition: pt-id.h:110
void static_workspace_error(void)
Definition: pt-id.h:88
tree_identifier(const tree_identifier &)=delete
virtual bool is_black_hole(void) const
Definition: pt-id.h:75
virtual void visit_identifier(tree_identifier &)
Definition: pt-walk.cc:203
void error(const char *fmt,...)
Definition: error.cc:968
return octave_value(v1.char_array_value() . concat(v2.char_array_value(), ra_idx),((a1.is_sq_string()||a2.is_sq_string()) ? '\'' :'"'))
octave_value::octave_value(const Array< char > &chm, char type) return retval
Definition: ov.cc:811