GNU Octave  9.1.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-2024 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 
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  OCTAVE_DISABLE_COPY_MOVE (tree_identifier)
64 
65  ~tree_identifier () = default;
66 
67  bool is_identifier () const { return true; }
68 
69  std::string name () const { return m_sym.name (); }
70 
71  virtual bool is_black_hole () const { return false; }
72 
74 
75  // We really need to know whether this symbol refers to a variable
76  // or a function, but we may not know that yet.
77 
78  bool lvalue_ok () const { return true; }
79 
81 
82  void eval_undefined_error ();
83 
85  {
86  error (R"(can not add variable "%s" to a static workspace)",
87  name ().c_str ());
88  }
89 
90  tree_identifier * dup (symbol_scope& scope) const;
91 
92  octave_value evaluate (tree_evaluator& tw, int nargout = 1)
93  {
94  octave_value_list retval = evaluate_n (tw, nargout);
95 
96  return retval.length () > 0 ? retval(0) : octave_value ();
97  }
98 
99  octave_value_list evaluate_n (tree_evaluator& tw, int nargout = 1);
100 
101  void accept (tree_walker& tw)
102  {
103  tw.visit_identifier (*this);
104  }
105 
106  symbol_record symbol () const { return m_sym; }
107 
108 protected:
109 
110  // The symbol record that this identifier references.
112 };
113 
115 {
116 public:
117 
118  tree_black_hole (int l = -1, int c = -1)
119  : tree_identifier (l, c) { }
120 
121  OCTAVE_DISABLE_COPY_MOVE (tree_black_hole)
122 
123  ~tree_black_hole () = default;
124 
125  std::string name () const { return "~"; }
126 
127  bool is_black_hole () const { return true; }
128 
130  {
131  return new tree_black_hole;
132  }
133 
135 };
136 
137 OCTAVE_END_NAMESPACE(octave)
138 
139 #endif
octave_idx_type length() const
Definition: ovl.h:113
void mark_formal()
Definition: symrec.h:217
std::string name() const
Definition: symrec.h:207
~tree_black_hole()=default
octave_lvalue lvalue(tree_evaluator &tw)
Definition: pt-id.cc:156
tree_black_hole(int l=-1, int c=-1)
Definition: pt-id.h:118
std::string name() const
Definition: pt-id.h:125
bool is_black_hole() const
Definition: pt-id.h:127
tree_black_hole * dup(symbol_scope &) const
Definition: pt-id.h:129
void mark_as_formal_parameter()
Definition: pt-id.h:73
tree_identifier(int l=-1, int c=-1)
Definition: pt-id.h:56
virtual bool is_black_hole() const
Definition: pt-id.h:71
symbol_record symbol() const
Definition: pt-id.h:106
std::string name() const
Definition: pt-id.h:69
octave_lvalue lvalue(tree_evaluator &tw)
Definition: pt-id.cc:68
bool lvalue_ok() const
Definition: pt-id.h:78
octave_value_list evaluate_n(tree_evaluator &tw, int nargout=1)
Definition: pt-id.cc:93
~tree_identifier()=default
tree_identifier * dup(symbol_scope &scope) const
Definition: pt-id.cc:77
bool is_identifier() const
Definition: pt-id.h:67
void static_workspace_error()
Definition: pt-id.h:84
void accept(tree_walker &tw)
Definition: pt-id.h:101
symbol_record m_sym
Definition: pt-id.h:111
octave_value evaluate(tree_evaluator &tw, int nargout=1)
Definition: pt-id.h:92
tree_identifier(const symbol_record &s, int l=-1, int c=-1)
Definition: pt-id.h:59
void eval_undefined_error()
Definition: pt-id.cc:44
virtual void visit_identifier(tree_identifier &)
Definition: pt-walk.cc:316
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
void() error(const char *fmt,...)
Definition: error.cc:988
return octave_value(v1.char_array_value() . concat(v2.char_array_value(), ra_idx),((a1.is_sq_string()||a2.is_sq_string()) ? '\'' :'"'))