GNU Octave  6.2.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
symrec.h
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (C) 1993-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_symrec_h)
27 #define octave_symrec_h 1
28 
29 #include "octave-config.h"
30 
31 #include <deque>
32 #include <list>
33 #include <memory>
34 #include <string>
35 
37 
38 #include "ov.h"
39 #include "ovl.h"
40 
41 namespace octave
42 {
43  class symbol_scope_rep;
44 
46  {
47  public:
48 
49  typedef size_t context_id;
50 
51  // generic variable
52  static const unsigned int local = 1;
53 
54  // formal parameter
55  static const unsigned int formal = 2;
56 
57  // this symbol may NOT become a variable.
58  // (symbol added to a static workspace)
59  static const unsigned int added_static = 4;
60 
61  private:
62 
64  {
65  public:
66 
67  symbol_record_rep (const std::string& nm, unsigned int sc)
69  m_name (nm)
70  { }
71 
73 
75 
76  ~symbol_record_rep (void) = default;
77 
78  // FIXME: use special storage class instead?
79  bool is_valid (void) const { return ! m_name.empty (); }
80 
81  void set_frame_offset (size_t offset) { m_frame_offset = offset; }
82 
83  size_t frame_offset (void) const { return m_frame_offset; }
84 
85  void set_data_offset (size_t offset) { m_data_offset = offset; }
86 
87  size_t data_offset (void) const { return m_data_offset; }
88 
89  bool is_local (void) const
90  {
91  return m_storage_class & local;
92  }
93 
94  bool is_formal (void) const
95  {
96  return m_storage_class & formal;
97  }
98 
99  bool is_added_static (void) const
100  {
101  return m_storage_class & added_static;
102  }
103 
104  void mark_local (void)
105  {
106  m_storage_class |= local;
107  }
108 
109  void mark_formal (void)
110  {
112  }
113 
114  void mark_added_static (void)
115  {
117  }
118 
119  void unmark_local (void)
120  {
121  m_storage_class &= ~local;
122  }
123 
124  void unmark_formal (void)
125  {
127  }
128 
130  {
132  }
133 
134  unsigned int storage_class (void) const { return m_storage_class; }
135 
136  std::shared_ptr<symbol_record_rep> dup (void) const;
137 
138  octave_value dump (void) const;
139 
140  std::string name (void) const { return m_name; }
141 
142  void rename (const std::string& new_name) { m_name = new_name; }
143 
144  private:
145 
148 
149  unsigned int m_storage_class;
150 
151  std::string m_name;
152  };
153 
154  public:
155 
156  symbol_record (const std::string& nm = "", unsigned int sc = local)
157  : m_rep (new symbol_record_rep (nm, sc))
158  { }
159 
160  symbol_record (const std::string& nm, const octave_value&,
161  unsigned int sc = local)
162  : m_rep (new symbol_record_rep (nm, sc))
163  { }
164 
165  symbol_record (const symbol_record&) = default;
166 
168 
169  ~symbol_record (void) = default;
170 
171  bool is_valid (void) const { return m_rep->is_valid (); }
172 
173  explicit operator bool () const { return is_valid (); }
174 
175  void set_frame_offset (size_t offset) { m_rep->set_frame_offset (offset); }
176 
177  size_t frame_offset (void) const { return m_rep->frame_offset (); }
178 
179  void set_data_offset (size_t offset) { m_rep->set_data_offset (offset); }
180 
181  size_t data_offset (void) const { return m_rep->data_offset (); }
182 
183  symbol_record dup (void) const { return symbol_record (m_rep->dup ()); }
184 
185  std::string name (void) const { return m_rep->name (); }
186 
187  void rename (const std::string& new_name) { m_rep->rename (new_name); }
188 
189  bool is_local (void) const { return m_rep->is_local (); }
190  bool is_formal (void) const { return m_rep->is_formal (); }
191  bool is_added_static (void) const { return m_rep->is_added_static (); }
192 
193  void mark_local (void) { m_rep->mark_local (); }
194  void mark_formal (void) { m_rep->mark_formal (); }
195  void mark_added_static (void) { m_rep->mark_added_static (); }
196 
197  void unmark_local (void) { m_rep->unmark_local (); }
198  void unmark_formal (void) { m_rep->unmark_formal (); }
199  void unmark_added_static (void) { m_rep->unmark_added_static (); }
200 
201  unsigned int storage_class (void) const { return m_rep->storage_class (); }
202 
203  octave_value dump (void) const { return m_rep->dump (); }
204 
205  private:
206 
207  std::shared_ptr<symbol_record_rep> m_rep;
208 
209  // NEW_REP must be dynamically allocated or nullptr.
210  symbol_record (const std::shared_ptr<symbol_record_rep>& new_rep)
211  : m_rep (new_rep)
212  { }
213  };
214 }
215 
216 #endif
void rename(const std::string &new_name)
Definition: symrec.h:142
unsigned int storage_class(void) const
Definition: symrec.h:134
symbol_record_rep(const std::string &nm, unsigned int sc)
Definition: symrec.h:67
symbol_record_rep & operator=(const symbol_record_rep &)=default
void set_frame_offset(size_t offset)
Definition: symrec.h:81
octave_value dump(void) const
Definition: symrec.cc:51
void set_data_offset(size_t offset)
Definition: symrec.h:85
symbol_record_rep(const symbol_record_rep &)=default
std::shared_ptr< symbol_record_rep > dup(void) const
Definition: symrec.cc:45
std::string name(void) const
Definition: symrec.h:140
symbol_record(const std::string &nm="", unsigned int sc=local)
Definition: symrec.h:156
void set_data_offset(size_t offset)
Definition: symrec.h:179
std::shared_ptr< symbol_record_rep > m_rep
Definition: symrec.h:207
void unmark_local(void)
Definition: symrec.h:197
symbol_record(const symbol_record &)=default
symbol_record dup(void) const
Definition: symrec.h:183
static const unsigned int formal
Definition: symrec.h:55
void mark_formal(void)
Definition: symrec.h:194
symbol_record & operator=(const symbol_record &)=default
void mark_added_static(void)
Definition: symrec.h:195
symbol_record(const std::string &nm, const octave_value &, unsigned int sc=local)
Definition: symrec.h:160
symbol_record(const std::shared_ptr< symbol_record_rep > &new_rep)
Definition: symrec.h:210
void unmark_formal(void)
Definition: symrec.h:198
bool is_local(void) const
Definition: symrec.h:189
void set_frame_offset(size_t offset)
Definition: symrec.h:175
size_t frame_offset(void) const
Definition: symrec.h:177
unsigned int storage_class(void) const
Definition: symrec.h:201
bool is_formal(void) const
Definition: symrec.h:190
size_t data_offset(void) const
Definition: symrec.h:181
octave_value dump(void) const
Definition: symrec.h:203
static const unsigned int added_static
Definition: symrec.h:59
void rename(const std::string &new_name)
Definition: symrec.h:187
bool is_added_static(void) const
Definition: symrec.h:191
void unmark_added_static(void)
Definition: symrec.h:199
~symbol_record(void)=default
void mark_local(void)
Definition: symrec.h:193
std::string name(void) const
Definition: symrec.h:185
bool is_valid(void) const
Definition: symrec.h:171