Game Develop Core: EventsCodeGenerator.h Source File

| Game Develop Core Core library for developing platforms and tools compatible with Game Develop.

- Main Page
- Modules
- Classes

- File List
- File Members

All Classes Files Functions Variables Typedefs Enumerations Macros Groups Pages
EventsCodeGenerator.h
1 #ifndef GDCORE_EVENTSCODEGENERATOR_H
2 #define GDCORE_EVENTSCODEGENERATOR_H
3
4 #include "GDCore/Events/Event.h"
5 #include <string>
6 #include <vector>
7 #include <set>
8 #include <utility>
9 namespace gd { class Project; }
10 namespace gd { class Layout; }
11 namespace gd { class ExternalEvents; }
12 namespace gd { class ParameterMetadata; }
13 namespace gd { class ObjectMetadata; }
14 namespace gd { class AutomatismMetadata; }
15 namespace gd { class InstructionMetadata; }
16 namespace gd { class EventsCodeGenerationContext; }
17 namespace gd { class ExpressionCodeGenerationInformation; }
18 namespace gd { class InstructionMetadata;}
19 namespace gd { class Platform;}
20
21 namespace gd
22 {
23
30 class GD_CORE_API EventsCodeGenerator
31 {
32 friend class CallbacksForGeneratingExpressionCode;
33 public:
34 static void DeleteUselessEvents(std::vector < gd::BaseEventSPtr > & events);
35
39 EventsCodeGenerator(gd::Project & project_, const gd::Layout & layout, const gd::Platform & platform_);
40 virtual ~EventsCodeGenerator() {};
41
47 void PreprocessEventList( std::vector < gd::BaseEventSPtr > & listEvent );
48
56 std::string GenerateEventsListCode(std::vector < gd::BaseEventSPtr > & events, const EventsCodeGenerationContext & context);
57
69 virtual std::string GenerateConditionsListCode(std::vector < gd::Instruction > & conditions, EventsCodeGenerationContext & context);
70
82 virtual std::string GenerateActionsListCode(std::vector < gd::Instruction > & actions, EventsCodeGenerationContext & context);
83
96 std::vector<std::string> GenerateParametersCodes(std::vector < gd::Expression > parameters,
97 const std::vector < gd::ParameterMetadata > & parametersInfo,
98 EventsCodeGenerationContext & context,
99 std::vector < std::pair<std::string, std::string> > * supplementaryParametersTypes = 0);
100
111 std::string GenerateConditionCode(gd::Instruction & condition, std::string returnBoolean, EventsCodeGenerationContext & context);
112
122 std::string GenerateActionCode(gd::Instruction & action, EventsCodeGenerationContext & context);
123
131 virtual std::string GenerateObjectsDeclarationCode(EventsCodeGenerationContext & context);
132
146 virtual std::string ConvertToString(std::string plainString);
147
162 virtual std::string ConvertToStringExplicit(std::string plainString);
163
170 void AddIncludeFile(std::string file) { if ( !file.empty() ) includeFiles.insert(file); };
171
176 void AddIncludeFiles(std::vector<std::string> files) { for(unsigned int i = 0;i<files.size();++i) AddIncludeFile(files[i]); };
177
181 void AddGlobalDeclaration(std::string declaration) { customGlobalDeclaration.insert(declaration); };
182
186 void AddCustomCodeOutsideMain(std::string code) { customCodeOutsideMain += code; };
187
191 void AddCustomCodeInMain(std::string code) { customCodeInMain += code; };
192
195 const std::set<std::string> & GetIncludeFiles() const { return includeFiles; }
196
199 const std::string & GetCustomCodeOutsideMain() const { return customCodeOutsideMain; }
200
203 const std::string & GetCustomCodeInMain() const { return customCodeInMain; }
204
207 const std::set<std::string> & GetCustomGlobalDeclaration() const { return customGlobalDeclaration; }
208
212 bool GenerateCodeForRuntime() { return compilationForRuntime; }
213
217 void SetGenerateCodeForRuntime(bool compilationForRuntime_) { compilationForRuntime = compilationForRuntime_; }
218
222 void ReportError();
223
227 bool ErrorOccurred() const { return errorOccurred; };
228
232 gd::Project & GetProject() const { return project; }
233
237 const gd::Layout & GetLayout() const { return scene; }
238
242 const gd::Platform & GetPlatform() const { return platform; }
243
253 std::vector<std::string> ExpandObjectsName(const std::string & objectName, const EventsCodeGenerationContext & context) const;
254
258 size_t GetMaxCustomConditionsDepth() const { return maxCustomConditionsDepth; }
259
263 size_t GetMaxConditionsListsSize() const { return maxConditionsListsSize; }
264
270 virtual std::string GenerateBooleanFullName(const std::string & boolName, const gd::EventsCodeGenerationContext & context ) { return boolName; }
271
277 virtual std::string GenerateBooleanInitializationToFalse(const std::string & boolName,
278 const gd::EventsCodeGenerationContext & context) { return "bool "+boolName+" = false;\n";}
279
285 virtual std::string GetObjectListName(const std::string & name, const gd::EventsCodeGenerationContext & context);
286
287 protected:
288
325 virtual std::string GenerateParameterCodes(const std::string & parameter, const gd::ParameterMetadata & metadata,
326 gd::EventsCodeGenerationContext & context,
327 const std::string & previousParameter,
328 std::vector < std::pair<std::string, std::string> > * supplementaryParametersTypes);
329
340 virtual std::string GenerateObjectFunctionCall(std::string objectListName,
341 const ObjectMetadata & objMetadata,
342 const gd::ExpressionCodeGenerationInformation & codeInfo,
343 std::string parametersStr,
344 std::string defaultOutput,
345 gd::EventsCodeGenerationContext & context);
346
358 virtual std::string GenerateObjectAutomatismFunctionCall(std::string objectListName,
359 std::string automatismName,
360 const gd::AutomatismMetadata & autoInfo,
361 const gd::ExpressionCodeGenerationInformation & codeInfo,
362 std::string parametersStr,
363 std::string defaultOutput,
364 gd::EventsCodeGenerationContext & context);
365
371 virtual std::string GenerateScopeBegin(gd::EventsCodeGenerationContext & context, const std::string & extraVariable = "") { return "{\n"; };
372
378 virtual std::string GenerateScopeEnd(gd::EventsCodeGenerationContext & context, const std::string & extraVariable = "") { return "}\n"; };
379
385 virtual std::string GenerateNegatedPredicat(const std::string & predicat) const { return "!("+predicat+")"; };
386
392 virtual std::string GenerateReferenceToUpperScopeBoolean(const std::string & referenceName,
393 const std::string & referencedBoolean,
394 gd::EventsCodeGenerationContext & context) { return "bool & "+referenceName+" = "+referencedBoolean+";\n";}
395
396 virtual std::string GenerateFreeCondition(const std::vector<std::string> & arguments,
397 const gd::InstructionMetadata & instrInfos,
398 const std::string & returnBoolean,
399 bool conditionInverted,
400 gd::EventsCodeGenerationContext & context);
401
402 virtual std::string GenerateObjectCondition(const std::string & objectName,
403 const gd::ObjectMetadata & objInfo,
404 const std::vector<std::string> & arguments,
405 const gd::InstructionMetadata & instrInfos,
406 const std::string & returnBoolean,
407 bool conditionInverted,
408 gd::EventsCodeGenerationContext & context);
409
410 virtual std::string GenerateAutomatismCondition(const std::string & objectName,
411 const std::string & automatismName,
412 const gd::AutomatismMetadata & autoInfo,
413 const std::vector<std::string> & arguments,
414 const gd::InstructionMetadata & instrInfos,
415 const std::string & returnBoolean,
416 bool conditionInverted,
417 gd::EventsCodeGenerationContext & context);
418
419 virtual std::string GenerateFreeAction(const std::vector<std::string> & arguments,
420 const gd::InstructionMetadata & instrInfos,
421 gd::EventsCodeGenerationContext & context);
422
423 virtual std::string GenerateObjectAction(const std::string & objectName,
424 const gd::ObjectMetadata & objInfo,
425 const std::vector<std::string> & arguments,
426 const gd::InstructionMetadata & instrInfos,
427 gd::EventsCodeGenerationContext & context);
428
429 virtual std::string GenerateAutomatismAction(const std::string & objectName,
430 const std::string & automatismName,
431 const gd::AutomatismMetadata & autoInfo,
432 const std::vector<std::string> & arguments,
433 const gd::InstructionMetadata & instrInfos,
434 gd::EventsCodeGenerationContext & context);
435
436
437 std::string GenerateRelationalOperatorCall(const gd::InstructionMetadata & instrInfos, const std::vector<std::string> & arguments, const std::string & callStartString, unsigned int startFromArgument = 0);
438 std::string GenerateOperatorCall(const gd::InstructionMetadata & instrInfos, const std::vector<std::string> & arguments, const std::string & callStartString, const std::string & getterStartString, unsigned int startFromArgument = 0);
439 std::string GenerateCompoundOperatorCall(const gd::InstructionMetadata & instrInfos, const std::vector<std::string> & arguments, const std::string & callStartString, unsigned int startFromArgument = 0);
440
444 std::string GenerateTrue() const { return "true"; };
445
449 std::string GenerateFalse() const { return "false"; };
450
451 gd::Project & project;
452 const gd::Layout & scene;
453 const gd::Platform & platform;
454
455 bool errorOccurred;
456 bool compilationForRuntime;
457
458 std::set<std::string> includeFiles;
459 std::string customCodeOutsideMain;
460 std::string customCodeInMain;
461 std::set<std::string> customGlobalDeclaration;
462 size_t maxCustomConditionsDepth;
463 size_t maxConditionsListsSize;
464 };
465
466 }
467
468 #endif // GDCORE_EVENTSCODEGENERATOR_H