nany
classdef-table.h
1 #pragma once
2 #include "libnanyc.h"
3 #include <yuni/core/string.h>
4 #include "classdef.h"
5 #include "details/utils/stringrefs.h"
6 #include "nany/nany.h"
7 #include "atom-map.h"
8 #include <unordered_map>
9 #include <vector>
10 
11 
12 namespace ny {
13 
14 
15 struct ClassdefTableView;
16 struct Atom;
17 
18 
19 struct ClassdefTable final {
21 
22  ClassdefTable();
25  ClassdefTable(const ClassdefTable&) = delete;
27  ClassdefTable(ClassdefTable&&) = default;
29  ~ClassdefTable() = default;
31 
32 
34 
35  bool hasClassdef(const CLID&) const;
37 
41  Classdef& classdef(const CLID&);
45  const Classdef& classdef(const CLID&) const;
49  const Classdef& rawclassdef(const CLID&) const;
50  Classdef& rawclassdef(const CLID&);
51 
53  const Classdef& classdefFollowClassMember(const CLID&) const;
54 
59  Funcdef& addClassdefInterface(const CLID&, const AnyString& name);
63  Funcdef& addClassdefInterface(const Classdef&, const AnyString& name);
64 
69  Funcdef& addClassdefInterfaceSelf(const CLID&, const AnyString& name);
73  Funcdef& addClassdefInterfaceSelf(const Classdef&, const AnyString& name);
74 
84 
89  bool makeHardlink(const CLID& source, const CLID& target);
90 
94  void bulkCreate(std::vector<CLID>& out, uint32_t atomid, uint32_t count);
95 
99  void bulkAppend(uint32_t atomid, uint32_t offset, uint32_t count);
100 
104  void registerAtom(Atom& atom);
106 
107 
109 
110 
114  AnyString keyword(const Atom&) const;
115 
117  Atom* findClassdefAtom(const Classdef&) const;
119  // (do not take layer into consideration)
120  Atom* findRawClassdefAtom(const Classdef&) const;
122 
123 
125 
126  bool hasSubstitute(CLID) const;
129  Classdef& substitute(uint32_t) const;
130 
132  Classdef& addSubstitute(nytype_t kind, Atom* atom, const Qualifiers&) const;
133 
135  uint32_t substituteAtomID() const;
136 
138  void substituteResize(uint32_t count);
139 
141  void mergeSubstitutes();
143 
144 
146 
147  ClassdefTable& operator = (const ClassdefTable&) = delete;
150 
151 public:
156 
157 
158 private:
159  inline bool nameLookupForClassdef(Classdef& classdef);
160  inline bool nameLookupForSelfInterface(Classdef& classdef);
161 
162 private:
165  struct LayerItem final {
166  void swap(LayerItem& rhs);
167 
169  uint32_t atomid = (uint32_t) - 1;
171  // \note On some STL implementation, std::vector.size is rather ineficient (distance(end - begin))
172  uint32_t count = 0;
174  std::vector<bool> flags;
176  std::vector<Classdef> storage;
177  };
178 
180  std::unordered_map<CLID, yuni::Ref<Classdef>> m_classdefs;
182  mutable LayerItem m_layer;
183 
184  friend struct ClassdefTableView;
185 
186 }; // struct ClassdefTable
187 
188 
189 } // namespace ny
190 
191 #include "classdef-table.hxx"
Atom * findRawClassdefAtom(const Classdef &) const
Find the atom of a classdef, via its extends if necessary.
Definition: classdef-table.cpp:186
void bulkCreate(std::vector< CLID > &out, uint32_t atomid, uint32_t count)
Bulk create several class id.
Definition: classdef-table.cpp:146
Definition: clid.h:11
const Classdef & rawclassdef(const CLID &) const
Retrieve a classdef from its ID without using the current layer.
Definition: classdef-table.cpp:69
Class definition.
Definition: classdef.h:24
Function definition.
Definition: funcdef.h:15
AtomMap atoms
Atom map.
Definition: classdef-table.h:155
StringRefs stringrefs
String dictionary.
Definition: classdef-table.h:153
Definition: ast.cpp:6
Funcdef & addClassdefInterfaceSelf(const CLID &, const AnyString &name)
Get or create an interface from its name for a given CLID.
Definition: classdef-table.cpp:137
void bulkAppend(uint32_t atomid, uint32_t offset, uint32_t count)
Bulk append class id.
Definition: classdef-table.cpp:164
Definition: classdef-table.h:19
Atom * findClassdefAtom(const Classdef &) const
Find the atom of a classdef, via its extends if necessary.
Definition: classdef-table.cpp:204
ClassdefTable()
Default constructor.
Definition: classdef-table.cpp:13
void substituteResize(uint32_t count)
Resize the substitutes for the current layer.
Definition: classdef-table.cpp:233
ClassdefTable & operator=(const ClassdefTable &)=delete
No assignment operator.
void mergeSubstitutes()
Make substitutes permanent.
Definition: classdef-table.cpp:255
bool hasSubstitute(CLID) const
Get if the current layer has a substitute for a given CLID.
Definition: classdef-table.cpp:222
Atoms.
Definition: atom-map.h:17
bool hasClassdef(const CLID &) const
Get if a clid is available.
Definition: classdef-table.hxx:16
Definition of a single class or function.
Definition: atom.h:37
const Classdef & classdefFollowClassMember(const CLID &) const
Retrieve the real classdef from its ID (or from the current layer) even if a class member...
Definition: classdef-table.cpp:118
AnyString keyword(const Atom &) const
Get the keyword associated to an atom (class, func, var, cref, namespace...)
Definition: classdef-table.cpp:306
uint32_t substituteAtomID() const
Get the atom id of the current layer.
Definition: classdef-table.hxx:46
bool makeHardlink(const CLID &source, const CLID &target)
Make a target class ID share the same definition than a source class ID.
Definition: classdef-table.cpp:19
Funcdef & addClassdefInterface(const CLID &, const AnyString &name)
Get or create an interface from its name for a given CLID.
Definition: classdef-table.cpp:127
~ClassdefTable()=default
Destructor.
Classdef & substitute(uint32_t) const
Get the substiture for the current atomid in the current layer.
Definition: classdef-table.cpp:268
Definition: qualifiers.h:9
Classdef & addSubstitute(nytype_t kind, Atom *atom, const Qualifiers &) const
Append a new substitute.
Definition: classdef-table.cpp:285
void registerAtom(Atom &atom)
Register an Atom (created from blueprints)
Definition: classdef-table.cpp:177
Definition: classdef-table-view.h:9
Container for minimizing memory use of duplicate strings.
Definition: stringrefs.h:12
Classdef & classdef(const CLID &)
Retrieve or create a classdef from its ID.
Definition: classdef-table.cpp:45