forked from APrioriInvestments/typed_python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClassType.hpp
More file actions
153 lines (111 loc) · 4.13 KB
/
Copy pathClassType.hpp
File metadata and controls
153 lines (111 loc) · 4.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#pragma once
#include "Type.hpp"
class Instance;
class Class : public Type {
class layout {
public:
std::atomic<int64_t> refcount;
unsigned char data[];
};
public:
Class(HeldClass* inClass) :
Type(catClass),
m_heldClass(inClass)
{
m_size = sizeof(layout*);
m_is_default_constructible = inClass->is_default_constructible();
m_name = m_heldClass->name();
forwardTypesMayHaveChanged();
}
bool isBinaryCompatibleWithConcrete(Type* other);
template<class visitor_type>
void _visitContainedTypes(const visitor_type& visitor) {
}
template<class visitor_type>
void _visitReferencedTypes(const visitor_type& visitor) {
Type* t = m_heldClass;
visitor(t);
assert(t == m_heldClass);
}
void _forwardTypesMayHaveChanged();
static Class* Make(
std::string inName,
const std::vector<std::tuple<std::string, Type*, Instance> >& members,
const std::map<std::string, Function*>& memberFunctions,
const std::map<std::string, Function*>& staticFunctions,
const std::map<std::string, Function*>& propertyFunctions,
const std::map<std::string, PyObject*>& classMembers
)
{
return new Class(HeldClass::Make(inName, members, memberFunctions, staticFunctions, propertyFunctions, classMembers));
}
Class* renamed(std::string newName) {
return new Class(m_heldClass->renamed(newName));
}
instance_ptr eltPtr(instance_ptr self, int64_t ix) const;
void setAttribute(instance_ptr self, int64_t ix, instance_ptr elt) const;
bool checkInitializationFlag(instance_ptr self, int64_t ix) const;
bool cmp(instance_ptr left, instance_ptr right, int pyComparisonOp);
template<class buf_t>
void deserialize(instance_ptr self, buf_t& buffer) {
*(layout**)self = (layout*)malloc(
sizeof(layout) + m_heldClass->bytecount()
);
layout& record = **(layout**)self;
record.refcount = 1;
m_heldClass->deserialize(record.data, buffer);
}
template<class buf_t>
void serialize(instance_ptr self, buf_t& buffer) {
layout& l = **(layout**)self;
m_heldClass->serialize(l.data, buffer);
}
void repr(instance_ptr self, ReprAccumulator& stream);
int32_t hash32(instance_ptr left);
template<class sub_constructor>
void constructor(instance_ptr self, const sub_constructor& initializer) const {
*(layout**)self = (layout*)malloc(sizeof(layout) + m_heldClass->bytecount());
layout& l = **(layout**)self;
l.refcount = 1;
try {
m_heldClass->constructor(l.data, initializer);
} catch (...) {
free(*(layout**)self);
}
}
void emptyConstructor(instance_ptr self);
void constructor(instance_ptr self);
void destroy(instance_ptr self);
int64_t refcount(instance_ptr self);
void copy_constructor(instance_ptr self, instance_ptr other);
void assign(instance_ptr self, instance_ptr other);
Type* getMemberType(int index) const {
return m_heldClass->getMemberType(index);
}
const std::string& getMemberName(int index) const {
return m_heldClass->getMemberName(index);
}
const std::vector<std::tuple<std::string, Type*, Instance> >& getMembers() const {
return m_heldClass->getMembers();
}
const std::map<std::string, Function*>& getMemberFunctions() const {
return m_heldClass->getMemberFunctions();
}
const std::map<std::string, Function*>& getStaticFunctions() const {
return m_heldClass->getStaticFunctions();
}
const std::map<std::string, PyObject*>& getClassMembers() const {
return m_heldClass->getClassMembers();
}
const std::map<std::string, Function*>& getPropertyFunctions() const {
return m_heldClass->getPropertyFunctions();
}
int memberNamed(const char* c) const {
return m_heldClass->memberNamed(c);
}
HeldClass* getHeldClass() const {
return m_heldClass;
}
private:
HeldClass* m_heldClass;
};