nany
atom.hxx
1 #pragma once
2 #include "atom.h"
3 
4 
5 namespace ny {
6 
7 
8 inline uint32_t Atom::Instances::size() const {
9  return static_cast<uint32_t>(m_instances.size());
10 }
11 
12 
15 }
16 
17 inline const Atom* Atom::parentScope() const {
19 }
20 
21 
22 inline AnyString Atom::name() const {
23  return m_name;
24 }
25 
26 
27 inline bool Atom::canCaptureVariabes() const {
28  return flags.has(Flags::captureVariables)
30 }
31 
32 
33 inline CLID Atom::clid() const {
34  return CLID::AtomMapID(atomid);
35 }
36 
37 
38 inline bool Atom::isNamespace() const {
39  return type == Type::namespacedef;
40 }
41 
42 
43 inline bool Atom::isClass() const {
44  return type == Type::classdef;
45 }
46 
47 
48 inline bool Atom::isAnonymousClass() const {
49  return type == Type::classdef and m_name.empty();
50 }
51 
52 
53 inline bool Atom::callable() const {
54  return isFunction() or (isClass() and hasMember("^()"));
55 }
56 
57 
58 inline bool Atom::isCtor() const {
59  return category(Category::ctor);
60 }
61 
62 
63 inline bool Atom::isDtor() const {
64  return category(Category::dtor);
65 }
66 
67 
68 inline bool Atom::isCloneCtor() const {
69  return category(Category::clone);
70 }
71 
72 
73 inline bool Atom::isUnit() const {
74  return type == Type::unit;
75 }
76 
77 
78 inline bool Atom::isTypeAlias() const {
79  return type == Type::typealias;
80 }
81 
82 
83 inline bool Atom::isFunction() const {
84  return type == Type::funcdef;
85 }
86 
87 
88 inline bool Atom::isOperator() const {
90 }
91 
92 
93 inline bool Atom::isSpecial() const {
95 }
96 
97 
98 inline bool Atom::isView() const {
99  return category(Category::view);
100 }
101 
102 
103 inline bool Atom::isFunctor() const {
104  return category(Category::functor);
105 }
106 
107 
108 inline bool Atom::isCapturedVariable() const {
110 }
111 
112 
113 inline bool Atom::isMemberVarDefaultInit() const {
115 }
116 
117 
118 inline bool Atom::isMemberVariable() const {
120 }
121 
122 
123 inline bool Atom::isClassMember() const {
125 }
126 
127 
128 inline bool Atom::isPropertyGet() const {
129  return category(Category::propget);
130 }
131 
132 
133 inline bool Atom::isPropertySet() const {
134  return category(Category::propset);
135 }
136 
137 
138 inline bool Atom::isPropertySetCustom() const {
140 }
141 
142 
143 inline bool Atom::isProperty() const {
145 }
146 
147 
148 inline bool Atom::isUnittest() const {
150 }
151 
152 
153 inline bool Atom::isPublicOrPublished() const {
154  return (visibility == nyv_public) or (visibility == nyv_published);
155 }
156 
157 
158 inline bool Atom::hasReturnType() const {
159  return not returnType.clid.isVoid();
160 }
161 
162 
163 inline bool Atom::hasGenericParameters() const {
164  return not tmplparams.empty();
165 }
166 
167 
168 inline bool Atom::isContextual() const {
169  return hasGenericParameters() // generic classes
170  or m_name.empty() // anonymous classes
171  or (parent and parent->isFunction()); // anything inside a func which may depend from parameters
172 }
173 
174 
175 template<class C>
176 inline void Atom::eachChild(const C& callback) {
177  for (auto& pair : m_children) {
178  if (not callback(*pair.second))
179  return;
180  }
181 }
182 
183 template<class C>
184 inline void Atom::eachChild(const C& callback) const {
185  for (auto& pair : m_children) {
186  if (not callback(*pair.second))
187  return;
188  }
189 }
190 
191 
192 inline bool Atom::hasMember(const AnyString& name) const {
193  return (m_children.count(name) != 0);
194 }
195 
196 
197 template<class C>
198 inline void Atom::eachChild(const AnyString& needle, const C& callback) {
199  assert(not needle.empty());
200  auto range = m_children.equal_range(needle);
201  for (auto it = range.first; it != range.second; ++it) {
202  if (not callback(*(it->second)))
203  return;
204  }
205 }
206 
207 
208 template<class C>
209 inline void Atom::eachChild(const AnyString& needle, const C& callback) const {
210  assert(not needle.empty());
211  auto range = m_children.equal_range(needle);
212  for (auto it = range.first; it != range.second; ++it) {
213  if (not callback(*(it->second)))
214  return;
215  }
216 }
217 
218 
219 inline void Atom::Parameters::swap(Parameters& rhs) {
220  std::swap(pData, rhs.pData);
221  std::swap(shortcircuitValue, rhs.shortcircuitValue);
222 }
223 
224 
225 template<class T>
226 inline void Atom::Parameters::each(const T& callback) const {
227  if (!!pData) {
228  uint32_t count = pData->count;
229  auto& params = pData->params;
230  for (uint32_t i = 0; i != count; ++i) {
231  auto& pair = params[i];
232  callback(i, pair.first, pair.second);
233  }
234  }
235 }
236 
237 
238 inline uint Atom::Parameters::size() const {
239  return (!!pData) ? pData.get()->count : 0;
240 }
241 
242 
243 inline bool Atom::Parameters::empty() const {
244  return !pData;
245 }
246 
247 
248 inline const AnyString& Atom::Parameters::name(uint index) const {
249  assert(!!pData and index < pData->count);
250  return pData->params[index].first;
251 }
252 
253 
254 inline const Vardef& Atom::Parameters::vardef(uint index) const {
255  assert(!!pData and index < pData->count);
256  return pData->params[index].second;
257 }
258 
259 
260 inline const std::pair<AnyString, Vardef>& Atom::Parameters::operator [] (uint index) const {
261  assert(!!pData and index < pData->count);
262  return pData->params[index];
263 }
264 
265 
266 inline uint64_t Atom::runtimeSizeof() const {
267  return classinfo.nextFieldIndex * sizeof(uint64_t);
268 }
269 
270 
271 inline uint32_t Atom::childrenCount() const {
272  return (uint32_t) m_children.size();
273 }
274 
275 
276 inline bool Atom::hasChildren() const {
277  return not m_children.empty();
278 }
279 
280 
282  return Ref(*this, index);
283 }
284 
285 
287  return (m_index < m_ref.m_instances.size())
288  ? m_ref.m_instances[m_index].ircode.get() : nullptr;
289 }
290 
291 
293  assert(m_index < m_ref.m_instances.size());
294  return *(m_ref.m_instances[m_index].ircode.get());
295 }
296 
297 
298 inline AnyString Atom::Instances::Ref::symbolname() const {
299  return (m_index < m_ref.m_instances.size())
300  ? AnyString{m_ref.m_instances[m_index].symbol} :
301  AnyString{};
302 }
303 
304 
305 inline uint32_t Atom::Instances::Ref::id() const {
306  return m_index;
307 }
308 
309 
310 inline void Atom::Instances::Ref::update(YString&& symbol, const Classdef& rettype) {
311  m_ref.update(m_index, std::move(symbol), rettype);
312 }
313 
314 
315 inline uint32_t Atom::Instances::Ref::invalidate(const Signature& signature) {
316  m_ref.invalidate(m_index, signature);
317  return (uint32_t) - 1;
318 }
319 
320 
321 } // namespace ny
bool isPropertySetCustom() const
Get if the atom is a property setter (custom operator)
Definition: atom.hxx:138
bool isCapturedVariable() const
Get if the atom is a captured variable.
Definition: atom.hxx:108
Yuni::Flags< Flags > flags
Atom flags.
Definition: atom.h:422
Vardef returnType
The return type.
Definition: atom.h:477
bool hasMember(const AnyString &name) const
Get if this atom has a child member.
Definition: atom.hxx:192
uint32_t childrenCount() const
Get the number of children.
Definition: atom.hxx:271
bool isAnonymousClass() const
Get if the atom is an anonymous class.
Definition: atom.hxx:48
uint32_t size() const
Number of instances.
Definition: atom.hxx:8
bool isPropertySet() const
Get if the atom is a property setter.
Definition: atom.hxx:133
Yuni::Flags< Category > category
Atom Category.
Definition: atom.h:424
bool empty() const
Get if empty.
Definition: atom.hxx:243
bool hasGenericParameters() const
Get if the atom has generic type parameters.
Definition: atom.hxx:163
Definition: clid.h:11
const Vardef & vardef(uint index) const
Var def.
Definition: atom.hxx:254
static CLID AtomMapID(uint32_t atomid)
Create a CLID for an atom id.
Definition: clid.hxx:9
bool isCtor() const
Get if the atom is a constructor.
Definition: atom.hxx:58
bool isVoid() const
Get if the clid is valid (aka != 0)
Definition: clid.hxx:21
Definition: signature.h:15
const AnyString & name(uint index) const
Parameter name.
Definition: atom.hxx:248
bool isMemberVarDefaultInit() const
Is a constructor.
Definition: atom.hxx:113
Class definition.
Definition: classdef.h:24
bool hasChildren() const
Get if this atom owns children (sub-classes, methods...)
Definition: atom.hxx:276
bool isCloneCtor() const
Get if the atom is a clone constructor.
Definition: atom.hxx:68
Definition: atom.h:363
Definition: ast.cpp:6
bool isUnittest() const
Get if the atom is an unittest.
Definition: atom.hxx:148
CLID clid() const
Get the clid for this atom.
Definition: atom.hxx:33
bool hasReturnType() const
Get if the atom has a return type.
Definition: atom.hxx:158
Definition: vardef.h:11
bool isFunctor() const
Get if the atom is a functor (operator ())
Definition: atom.hxx:103
When the atom is copy constructor.
const Type type
Flag to determine whether this entry is a blueprint or a namespace.
Definition: atom.h:459
bool isPublicOrPublished() const
Get if the atom is publicly accessible.
Definition: atom.hxx:153
Variable definition.
void update(YString &&symbol, const Classdef &rettype)
Update atom instance.
Definition: atom.hxx:310
ir::Sequence & ircode()
Get the attached IR sequence.
Definition: atom.hxx:292
bool isPropertyGet() const
Get if the atom is a property getter.
Definition: atom.hxx:128
Atom * parentScope()
Get the parent atom (if any)
Definition: atom.hxx:13
uint32_t atomid
Atom unique ID (32-bits only, used for classification)
Definition: atom.h:420
bool isClass() const
Get if the atom is a class.
Definition: atom.hxx:43
AnyString symbolname() const
Get the symbol name of the instantiation (with fully qualified types)
Definition: atom.hxx:298
bool isUnit() const
Get if the atom is an unit.
Definition: atom.hxx:73
void eachChild(const C &callback)
Iterate through all children.
Definition: atom.hxx:176
void each(const T &callback) const
Iterate through all parameters.
Definition: atom.hxx:226
Parameters tmplparams
Template parameters.
Definition: atom.h:481
Atom * scopeForNameResolution
A different scope for name resolution, if not null (for plugs/outlets)
Definition: atom.h:487
When the atom has a class as parent.
bool isContextual() const
Get if the atom is contextual.
Definition: atom.hxx:168
uint32_t id() const
Instance ID.
Definition: atom.hxx:305
property set, custom operator, for future uses
When the atom is a constructor.
uint32_t invalidate(const Signature &)
Mark the instantiation (and its signature) as invalid (always returns -1)
Definition: atom.hxx:315
When the atom is the destructor.
define a part of a namespace
uint size() const
Get the total number of parameters.
Definition: atom.hxx:238
nyvisibility_t visibility
Visibility.
Definition: atom.h:461
Definition of a single class or function.
Definition: atom.h:37
Definition: atom.h:113
bool isDtor() const
Get if the atom is a destructor.
Definition: atom.hxx:63
class definition
bool isProperty() const
Get if the atom is a property (get or set)
Definition: atom.hxx:143
struct ny::Atom::@2 classinfo
Various information for classdef only.
bool isFunction() const
Get if the atom is a function.
Definition: atom.hxx:83
Not a normal func/class.
bool isView() const
Get if the atom is a view.
Definition: atom.hxx:98
bool shortcircuitValue
Shortcircuit value (if applicable)
Definition: atom.h:138
bool isSpecial() const
Get if the atom is a special atom (operator, view...)
Definition: atom.hxx:93
AnyString name() const
Atom name.
Definition: atom.hxx:22
Atom * parent
Parent node.
Definition: atom.h:463
Allow this atom (and the sub-functions) to capture variables.
ir::Sequence * ircodeIfExists()
Get the attached IR sequence, if any.
Definition: atom.hxx:286
Unit (source file)
bool isNamespace() const
Get if the atom is a namespace.
Definition: atom.hxx:38
bool isClassMember() const
Get if the atom is a class member (function or variable)
Definition: atom.hxx:123
uint64_t runtimeSizeof() const
Size at runtime (sizeof)
Definition: atom.hxx:266
Is the atom a view.
bool isTypeAlias() const
Is a type alias.
Definition: atom.hxx:78
bool callable() const
Get if the atom is callable (can be called like a function)
Definition: atom.hxx:53
bool canCaptureVariabes() const
Get if the atom can capture out-of-scope variables.
Definition: atom.hxx:27
Default variable initialization.
function definition
bool isMemberVariable() const
Get if the atom is a member variable.
Definition: atom.hxx:118
Definition: sequence.h:22
Ref operator[](uint32_t index)
Retrieve information about the Nth instantiation of this atom.
Definition: atom.hxx:281
CLID clid
Attached type (class id)
Definition: vardef.h:34
bool isOperator() const
Get if the atom is an operator.
Definition: atom.hxx:88