GNU Octave 10.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 
Loading...
Searching...
No Matches
pt-id.h
Go to the documentation of this file.
1////////////////////////////////////////////////////////////////////////
2//
3// Copyright (C) 1996-2025 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
34class octave_value;
36class octave_function;
37
38#include "comment-list.h"
39#include "oct-lvalue.h"
40#include "pt-bp.h"
41#include "pt-exp.h"
42#include "pt-walk.h"
43#include "symscope.h"
44#include "token.h"
45
47
48class tree_evaluator;
49
50// Symbols from the symbol table.
51
53{
55
56public:
57
58 tree_identifier (const token& tok) : m_token (tok) { }
59
60 tree_identifier (symbol_scope& scope, const token& tok)
61 : m_sym (scope ? scope.insert (tok.text ()) : symbol_record (tok.text ())),
62 m_token (tok)
63 { }
64
65 OCTAVE_DISABLE_COPY_MOVE (tree_identifier)
66
67 ~tree_identifier () = default;
68
69 bool is_identifier () const { return true; }
70
71 std::string name () const { return m_sym.name (); }
72
74
75 filepos beg_pos () const { return m_token.beg_pos (); }
76 filepos end_pos () const { return m_token.end_pos (); }
77
78 virtual bool is_black_hole () const { return false; }
79
81
82 // We really need to know whether this symbol refers to a variable
83 // or a function, but we may not know that yet.
84
85 bool lvalue_ok () const { return true; }
86
88
90
92 {
93 error (R"(can not add variable "%s" to a static workspace)",
94 name ().c_str ());
95 }
96
97 tree_identifier * dup (symbol_scope& scope) const;
98
99 octave_value evaluate (tree_evaluator& tw, int nargout = 1)
100 {
101 octave_value_list retval = evaluate_n (tw, nargout);
102
103 return retval.length () > 0 ? retval(0) : octave_value ();
104 }
105
106 octave_value_list evaluate_n (tree_evaluator& tw, int nargout = 1);
107
109 {
110 tw.visit_identifier (*this);
111 }
112
113 symbol_record symbol () const { return m_sym; }
114
115 tree_identifier * mark_get_set (const token& get_set_tok, const token& dot_tok)
116 {
117 m_get_set_tok = get_set_tok;
118 m_dot_tok = dot_tok;
119
120 return this;
121 }
122
123protected:
124
126 : m_sym (sym), m_token (tok)
127 { }
128
129 // The symbol record that this identifier references.
131
132 // These will be defined for get.ID or set.ID function names.
135
136 // The IDENT token from the lexer.
138};
139
141{
142public:
143
147
148 OCTAVE_DISABLE_COPY_MOVE (tree_black_hole)
149
150 ~tree_black_hole () = default;
151
152 std::string name () const { return "~"; }
153
154 bool is_black_hole () const { return true; }
155
157 {
158 return new tree_black_hole (m_token);
159 }
160
162};
163
164OCTAVE_END_NAMESPACE(octave)
165
166#endif
octave_idx_type length() const
Definition ovl.h:111
void mark_formal()
Definition symrec.h:228
std::string name() const
Definition symrec.h:218
Definition token.h:42
filepos end_pos() const
Definition token.h:129
comment_list leading_comments() const
Definition token.h:134
filepos beg_pos() const
Definition token.h:128
~tree_black_hole()=default
tree_black_hole * dup(symbol_scope &) const
Definition pt-id.h:156
octave_lvalue lvalue(tree_evaluator &tw)
Definition pt-id.cc:155
std::string name() const
Definition pt-id.h:152
bool is_black_hole() const
Definition pt-id.h:154
tree_black_hole(const token &token)
Definition pt-id.h:144
token m_token
Definition pt-id.h:137
void mark_as_formal_parameter()
Definition pt-id.h:80
tree_identifier(const token &tok)
Definition pt-id.h:58
filepos beg_pos() const
Definition pt-id.h:75
tree_identifier * mark_get_set(const token &get_set_tok, const token &dot_tok)
Definition pt-id.h:115
virtual bool is_black_hole() const
Definition pt-id.h:78
symbol_record symbol() const
Definition pt-id.h:113
std::string name() const
Definition pt-id.h:71
octave_lvalue lvalue(tree_evaluator &tw)
Definition pt-id.cc:68
tree_identifier(symbol_record &sym, const token &tok)
Definition pt-id.h:125
bool lvalue_ok() const
Definition pt-id.h:85
filepos end_pos() const
Definition pt-id.h:76
octave_value_list evaluate_n(tree_evaluator &tw, int nargout=1)
Definition pt-id.cc:92
comment_list leading_comments() const
Definition pt-id.h:73
tree_identifier(symbol_scope &scope, const token &tok)
Definition pt-id.h:60
~tree_identifier()=default
tree_identifier * dup(symbol_scope &scope) const
Definition pt-id.cc:77
bool is_identifier() const
Definition pt-id.h:69
void static_workspace_error()
Definition pt-id.h:91
token m_get_set_tok
Definition pt-id.h:133
void accept(tree_walker &tw)
Definition pt-id.h:108
symbol_record m_sym
Definition pt-id.h:130
octave_value evaluate(tree_evaluator &tw, int nargout=1)
Definition pt-id.h:99
token m_dot_tok
Definition pt-id.h:134
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:1003