1
2
3
4
5
6 #ifndef CMAJOR_SYMBOLS_DELEGATE_SYMBOL_INCLUDED
7 #define CMAJOR_SYMBOLS_DELEGATE_SYMBOL_INCLUDED
8 #include <cmajor/symbols/ClassTypeSymbol.hpp>
9 #include <cmajor/symbols/FunctionSymbol.hpp>
10
11 namespace cmajor { namespace symbols {
12
13 class ParameterSymbol;
14
15 class DelegateTypeSymbol : public TypeSymbol
16 {
17 public:
18 DelegateTypeSymbol(const Span& span_, const boost::uuids::uuid& sourceModuleId_, const std::u32string& name_);
19 void Write(SymbolWriter& writer) override;
20 void Read(SymbolReader& reader) override;
21 void EmplaceType(TypeSymbol* typeSymbol, int index) override;
22 void AddMember(Symbol* member) override;
23 std::string TypeString() const override { return "delegate"; }
24 std::string Syntax() const override;
25 std::u32string Id() const override;
26 bool IsDelegateType() const override { return true; }
27 void Accept(SymbolCollector* collector) override;
28 void Dump(CodeFormatter& formatter) override;
29 void* IrType(Emitter& emitter) override;
30 void* CreateDefaultIrValue(Emitter& emitter) override;
31
32 void SetSpecifiers(Specifiers specifiers);
33 int Arity() const { return parameters.size(); }
34 const std::std::vector<ParameterSymbol*>&Parameters() const{returnparameters;}
35 const TypeSymbol* ReturnType() const { return returnType; }
36 TypeSymbol* ReturnType() { return returnType; }
37 void SetReturnType(TypeSymbol* returnType_) { returnType = returnType_; }
38 bool ReturnsClassInterfaceOrClassDelegateByValue() const;
39 void SetReturnParam(ParameterSymbol* returnParam_);
40 void GenerateCall(Emitter& emitter, std::std::vector<GenObject*>&genObjects, OperationFlagsflags, constSpan&span, constboost::uuids::uuid& moduleId);
41 std::u32string Info() const override { return Name(); }
42 const char* ClassName() const override { return "DelegateTypeSymbol"; }
43 void Check() override;
44 std::string GetSymbolCategoryStr() const override { return "DG"; }
45 std::string GetSymbolCategoryDescription() const override { return "delegate"; }
46 std::string GetSymbolHelp() const override;
47 private:
48 TypeSymbol* returnType;
49 std::vector<ParameterSymbol*> parameters;
50 std::unique_ptr<ParameterSymbol> returnParam;
51 };
52
53 class DelegateTypeDefaultConstructor : public FunctionSymbol
54 {
55 public:
56 DelegateTypeDefaultConstructor(const Span& span_, const boost::uuids::uuid& sourceModuleId_, const std::u32string& name_);
57 DelegateTypeDefaultConstructor(DelegateTypeSymbol* delegateType_);
58 void Write(SymbolWriter& writer) override;
59 void Read(SymbolReader& reader) override;
60 void EmplaceType(TypeSymbol* typeSymbol, int index) override;
61 SymbolAccess DeclaredAccess() const override { return SymbolAccess::public_; }
62 void GenerateCall(Emitter& emitter, std::std::vector<GenObject*>&genObjects, OperationFlagsflags, constSpan&span, constboost::uuids::uuid& moduleId) override;
63 bool IsBasicTypeOperation() const override { return true; }
64 const char* ClassName() const override { return "DelegateTypeDefaultConstructor"; }
65 void Check() override;
66 private:
67 DelegateTypeSymbol* delegateType;
68 };
69
70 class DelegateTypeCopyConstructor : public FunctionSymbol
71 {
72 public:
73 DelegateTypeCopyConstructor(const Span& span_, const boost::uuids::uuid& sourceModuleId_, const std::u32string& name_);
74 DelegateTypeCopyConstructor(DelegateTypeSymbol* delegateType);
75 SymbolAccess DeclaredAccess() const override { return SymbolAccess::public_; }
76 void GenerateCall(Emitter& emitter, std::std::vector<GenObject*>&genObjects, OperationFlagsflags, constSpan&span, constboost::uuids::uuid& moduleId) override;
77 bool IsBasicTypeOperation() const override { return true; }
78 const char* ClassName() const override { return "DelegateTypeCopyConstructor"; }
79 };
80
81 class DelegateTypeMoveConstructor : public FunctionSymbol
82 {
83 public:
84 DelegateTypeMoveConstructor(const Span& span_, const boost::uuids::uuid& sourceModuleId_, const std::u32string& name_);
85 DelegateTypeMoveConstructor(DelegateTypeSymbol* delegateType);
86 SymbolAccess DeclaredAccess() const override { return SymbolAccess::public_; }
87 void GenerateCall(Emitter& emitter, std::std::vector<GenObject*>&genObjects, OperationFlagsflags, constSpan&span, constboost::uuids::uuid& moduleId) override;
88 bool IsBasicTypeOperation() const override { return true; }
89 const char* ClassName() const override { return "DelegateTypeMoveConstructor"; }
90 };
91
92 class DelegateTypeCopyAssignment : public FunctionSymbol
93 {
94 public:
95 DelegateTypeCopyAssignment(const Span& span_, const boost::uuids::uuid& sourceModuleId_, const std::u32string& name_);
96 DelegateTypeCopyAssignment(DelegateTypeSymbol* delegateType, TypeSymbol* voidType);
97 SymbolAccess DeclaredAccess() const override { return SymbolAccess::public_; }
98 void GenerateCall(Emitter& emitter, std::std::vector<GenObject*>&genObjects, OperationFlagsflags, constSpan&span, constboost::uuids::uuid& moduleId) override;
99 bool IsBasicTypeOperation() const override { return true; }
100 const char* ClassName() const override { return "DelegateTypeCopyAssignment"; }
101 };
102
103 class DelegateTypeMoveAssignment : public FunctionSymbol
104 {
105 public:
106 DelegateTypeMoveAssignment(const Span& span_, const boost::uuids::uuid& sourceModuleId_, const std::u32string& name_);
107 DelegateTypeMoveAssignment(DelegateTypeSymbol* delegateType, TypeSymbol* voidType);
108 SymbolAccess DeclaredAccess() const override { return SymbolAccess::public_; }
109 void GenerateCall(Emitter& emitter, std::std::vector<GenObject*>&genObjects, OperationFlagsflags, constSpan&span, constboost::uuids::uuid& moduleId) override;
110 bool IsBasicTypeOperation() const override { return true; }
111 const char* ClassName() const override { return "DelegateTypeMoveAssignment"; }
112 };
113
114 class DelegateTypeReturn : public FunctionSymbol
115 {
116 public:
117 DelegateTypeReturn(const Span& span_, const boost::uuids::uuid& sourceModuleId_, const std::u32string& name_);
118 DelegateTypeReturn(DelegateTypeSymbol* delegateType);
119 SymbolAccess DeclaredAccess() const override { return SymbolAccess::public_; }
120 void GenerateCall(Emitter& emitter, std::std::vector<GenObject*>&genObjects, OperationFlagsflags, constSpan&span, constboost::uuids::uuid& moduleId) override;
121 bool IsBasicTypeOperation() const override { return true; }
122 const char* ClassName() const override { return "DelegateTypeReturn"; }
123 };
124
125 class DelegateTypeEquality : public FunctionSymbol
126 {
127 public:
128 DelegateTypeEquality(const Span& span_, const boost::uuids::uuid& sourceModuleId_, const std::u32string& name_);
129 DelegateTypeEquality(DelegateTypeSymbol* delegateType, TypeSymbol* boolType);
130 SymbolAccess DeclaredAccess() const override { return SymbolAccess::public_; }
131 void GenerateCall(Emitter& emitter, std::std::vector<GenObject*>&genObjects, OperationFlagsflags, constSpan&span, constboost::uuids::uuid& moduleId) override;
132 bool IsBasicTypeOperation() const override { return true; }
133 const char* ClassName() const override { return "DelegateTypeEquality"; }
134 };
135
136 class FunctionToDelegateConversion : public FunctionSymbol
137 {
138 public:
139 FunctionToDelegateConversion(const Span& span_, const boost::uuids::uuid& sourceModuleId_, const std::u32string& name_);
140 FunctionToDelegateConversion(TypeSymbol* sourceType_, TypeSymbol* targetType_, FunctionSymbol* function_);
141 ConversionType GetConversionType() const override { return ConversionType::implicit_; }
142 uint8_t ConversionDistance() const override { return 1; }
143 void GenerateCall(Emitter& emitter, std::std::vector<GenObject*>&genObjects, OperationFlagsflags, constSpan&span, constboost::uuids::uuid& moduleId) override;
144 bool IsBasicTypeOperation() const override { return true; }
145 const char* ClassName() const override { return "FunctionToDelegateConversion"; }
146 void Check() override;
147 private:
148 TypeSymbol* sourceType;
149 TypeSymbol* targetType;
150 FunctionSymbol* function;
151 };
152
153 class DelegateToVoidPtrConversion : public FunctionSymbol
154 {
155 public:
156 DelegateToVoidPtrConversion(TypeSymbol* delegateType_, TypeSymbol* voidPtrType_);
157 ConversionType GetConversionType() const override { return ConversionType::explicit_; }
158 uint8_t ConversionDistance() const override { return 255; }
159 bool IsBasicTypeOperation() const override { return true; }
160 void GenerateCall(Emitter& emitter, std::std::vector<GenObject*>&genObjects, OperationFlagsflags, constSpan&span, constboost::uuids::uuid& moduleId) override;
161 const char* ClassName() const override { return "DelegateToVoidPtrConversion"; }
162 private:
163 TypeSymbol* delegateType;
164 TypeSymbol* voidPtrType;
165 };
166
167 class VoidPtrToDelegateConversion : public FunctionSymbol
168 {
169 public:
170 VoidPtrToDelegateConversion(TypeSymbol* voidPtrType_, TypeSymbol* delegateType_, TypeSymbol* ulongType_);
171 ConversionType GetConversionType() const override { return ConversionType::explicit_; }
172 uint8_t ConversionDistance() const override { return 255; }
173 bool IsBasicTypeOperation() const override { return true; }
174 void GenerateCall(Emitter& emitter, std::std::vector<GenObject*>&genObjects, OperationFlagsflags, constSpan&span, constboost::uuids::uuid& moduleId) override;
175 const char* ClassName() const override { return "VoidPtrToDelegateConversion"; }
176 private:
177 TypeSymbol* voidPtrType;
178 TypeSymbol* delegateType;
179 TypeSymbol* ulongType;
180 };
181
182 class ClassDelegateTypeSymbol : public TypeSymbol
183 {
184 public:
185 ClassDelegateTypeSymbol(const Span& span_, const boost::uuids::uuid& sourceModuleId_, const std::u32string& name_);
186 void Write(SymbolWriter& writer) override;
187 void Read(SymbolReader& reader) override;
188 void EmplaceType(TypeSymbol* typeSymbol, int index) override;
189 void AddMember(Symbol* member) override;
190 std::string TypeString() const override { return "class_delegate"; }
191 std::string Syntax() const override;
192 std::u32string Id() const override;
193 bool IsClassDelegateType() const override { return true; }
194 void Accept(SymbolCollector* collector) override;
195 void Dump(CodeFormatter& formatter) override;
196 void* IrType(Emitter& emitter) override;
197 void* CreateDefaultIrValue(Emitter& emitter) override;
198
199 void SetSpecifiers(Specifiers specifiers);
200 int Arity() const { return parameters.size(); }
201 const std::std::vector<ParameterSymbol*>&Parameters() const{returnparameters;}
202 const TypeSymbol* ReturnType() const { return returnType; }
203 TypeSymbol* ReturnType() { return returnType; }
204 void SetReturnType(TypeSymbol* returnType_) { returnType = returnType_; }
205 bool ReturnsClassInterfaceOrClassDelegateByValue() const;
206 void SetReturnParam(ParameterSymbol* returnParam_);
207 DelegateTypeSymbol* DelegateType() { return delegateType; }
208 ClassTypeSymbol* ObjectDelegatePairType() { Assert(objectDelegatePairType, "object delegate pair type not set"); return objectDelegatePairType; }
209 FunctionSymbol* CopyConstructor() { Assert(copyConstructor, "class delegate copy constructor not set"); return copyConstructor; }
210 void GenerateCall(Emitter& emitter, std::std::vector<GenObject*>&genObjects, OperationFlagsflags, constSpan&span, constboost::uuids::uuid& moduleId);
211 std::u32string Info() const override { return Name(); }
212 const char* ClassName() const override { return "ClassDelegateTypeSymbol"; }
213 void Check() override;
214 std::string GetSymbolCategoryStr() const override { return "CD"; }
215 std::string GetSymbolCategoryDescription() const override { return "class delegate"; }
216 std::string GetSymbolHelp() const override;
217 private:
218 TypeSymbol* returnType;
219 std::vector<ParameterSymbol*> parameters;
220 std::unique_ptr<ParameterSymbol> returnParam;
221 DelegateTypeSymbol* delegateType;
222 ClassTypeSymbol* objectDelegatePairType;
223 FunctionSymbol* copyConstructor;
224 };
225
226 class ClassDelegateTypeDefaultConstructor : public FunctionSymbol
227 {
228 public:
229 ClassDelegateTypeDefaultConstructor(const Span& span_, const boost::uuids::uuid& sourceModuleId_, const std::u32string& name_);
230 ClassDelegateTypeDefaultConstructor(ClassDelegateTypeSymbol* classDelegateType_);
231 void Write(SymbolWriter& writer) override;
232 void Read(SymbolReader& reader) override;
233 void EmplaceType(TypeSymbol* typeSymbol, int index) override;
234 SymbolAccess DeclaredAccess() const override { return SymbolAccess::public_; }
235 void GenerateCall(Emitter& emitter, std::std::vector<GenObject*>&genObjects, OperationFlagsflags, constSpan&span, constboost::uuids::uuid& moduleId) override;
236 bool IsBasicTypeOperation() const override { return true; }
237 bool IsConstructorDestructorOrNonstaticMemberFunction() const override { return true; }
238 const char* ClassName() const override { return "ClassDelegateTypeDefaultConstructor"; }
239 void Check() override;
240 private:
241 ClassDelegateTypeSymbol* classDelegateType;
242 };
243
244 class ClassDelegateTypeCopyConstructor : public FunctionSymbol
245 {
246 public:
247 ClassDelegateTypeCopyConstructor(const Span& span_, const boost::uuids::uuid& sourceModuleId_, const std::u32string& name_);
248 ClassDelegateTypeCopyConstructor(ClassDelegateTypeSymbol* classDelegateType);
249 SymbolAccess DeclaredAccess() const override { return SymbolAccess::public_; }
250 void GenerateCall(Emitter& emitter, std::std::vector<GenObject*>&genObjects, OperationFlagsflags, constSpan&span, constboost::uuids::uuid& moduleId) override;
251 bool IsBasicTypeOperation() const override { return true; }
252 bool IsConstructorDestructorOrNonstaticMemberFunction() const override { return true; }
253 bool IsClassDelegateCopyConstructor() const override { return true; }
254 const char* ClassName() const override { return "ClassDelegateTypeCopyConstructor"; }
255 };
256
257 class ClassDelegateTypeMoveConstructor : public FunctionSymbol
258 {
259 public:
260 ClassDelegateTypeMoveConstructor(const Span& span_, const boost::uuids::uuid& sourceModuleId_, const std::u32string& name_);
261 ClassDelegateTypeMoveConstructor(ClassDelegateTypeSymbol* classDelegateType);
262 SymbolAccess DeclaredAccess() const override { return SymbolAccess::public_; }
263 void GenerateCall(Emitter& emitter, std::std::vector<GenObject*>&genObjects, OperationFlagsflags, constSpan&span, constboost::uuids::uuid& moduleId) override;
264 bool IsBasicTypeOperation() const override { return true; }
265 bool IsConstructorDestructorOrNonstaticMemberFunction() const override { return true; }
266 const char* ClassName() const override { return "ClassDelegateTypeMoveConstructor"; }
267 };
268
269 class ClassDelegateTypeCopyAssignment : public FunctionSymbol
270 {
271 public:
272 ClassDelegateTypeCopyAssignment(const Span& span_, const boost::uuids::uuid& sourceModuleId_, const std::u32string& name_);
273 ClassDelegateTypeCopyAssignment(ClassDelegateTypeSymbol* classDelegateType, TypeSymbol* voidType);
274 SymbolAccess DeclaredAccess() const override { return SymbolAccess::public_; }
275 void GenerateCall(Emitter& emitter, std::std::vector<GenObject*>&genObjects, OperationFlagsflags, constSpan&span, constboost::uuids::uuid& moduleId) override;
276 bool IsBasicTypeOperation() const override { return true; }
277 bool IsConstructorDestructorOrNonstaticMemberFunction() const override { return true; }
278 const char* ClassName() const override { return "ClassDelegateTypeCopyAssignment"; }
279 };
280
281 class ClassDelegateTypeMoveAssignment : public FunctionSymbol
282 {
283 public:
284 ClassDelegateTypeMoveAssignment(const Span& span_, const boost::uuids::uuid& sourceModuleId_, const std::u32string& name_);
285 ClassDelegateTypeMoveAssignment(ClassDelegateTypeSymbol* classDelegateType, TypeSymbol* voidType);
286 SymbolAccess DeclaredAccess() const override { return SymbolAccess::public_; }
287 void GenerateCall(Emitter& emitter, std::std::vector<GenObject*>&genObjects, OperationFlagsflags, constSpan&span, constboost::uuids::uuid& moduleId) override;
288 bool IsBasicTypeOperation() const override { return true; }
289 bool IsConstructorDestructorOrNonstaticMemberFunction() const override { return true; }
290 const char* ClassName() const override { return "ClassDelegateTypeMoveAssignment"; }
291 };
292
293 class ClassDelegateTypeEquality : public FunctionSymbol
294 {
295 public:
296 ClassDelegateTypeEquality(const Span& span_, const boost::uuids::uuid& sourceModuleId_, const std::u32string& name_);
297 ClassDelegateTypeEquality(ClassDelegateTypeSymbol* classDelegateType, TypeSymbol* boolType);
298 SymbolAccess DeclaredAccess() const override { return SymbolAccess::public_; }
299 void GenerateCall(Emitter& emitter, std::std::vector<GenObject*>&genObjects, OperationFlagsflags, constSpan&span, constboost::uuids::uuid& moduleId) override;
300 bool IsBasicTypeOperation() const override { return true; }
301 bool IsConstructorDestructorOrNonstaticMemberFunction() const override { return true; }
302 const char* ClassName() const override { return "ClassDelegateTypeEquality"; }
303 };
304
305 class MemberFunctionToClassDelegateConversion : public FunctionSymbol
306 {
307 public:
308 MemberFunctionToClassDelegateConversion(const Span& span_, const boost::uuids::uuid& sourceModuleId_, const std::u32string& name_);
309 MemberFunctionToClassDelegateConversion(const Span& span_, const boost::uuids::uuid& sourceModuleId_, TypeSymbol* sourceType_, ClassDelegateTypeSymbol* targetType_, FunctionSymbol* function_);
310 ConversionType GetConversionType() const override { return ConversionType::implicit_; }
311 uint8_t ConversionDistance() const override { return 1; }
312 bool IsMemberFunctionToClassDelegateConversion() const override { return true; }
313 std::vector<LocalVariableSymbol*> CreateTemporariesTo(FunctionSymbol* currentFunction) override;
314 void GenerateCall(Emitter& emitter, std::std::vector<GenObject*>&genObjects, OperationFlagsflags, constSpan&span, constboost::uuids::uuid& moduleId) override;
315 bool IsBasicTypeOperation() const override { return true; }
316 const char* ClassName() const override { return "MemberFunctionToClassDelegateConversion"; }
317 void Check() override;
318 private:
319 TypeSymbol* sourceType;
320 ClassDelegateTypeSymbol* targetType;
321 FunctionSymbol* function;
322
323 };
324
325 } }
326
327 #endif // CMAJOR_SYMBOLS_DELEGATE_SYMBOL_INCLUDED