6 #ifndef GDCORE_EVENTSCODEGENERATOR_H
7 #define GDCORE_EVENTSCODEGENERATOR_H
13 #include "GDCore/Events/Event.h"
14 #include "GDCore/Events/Instruction.h"
15 #include "GDCore/Project/ProjectScopedContainers.h"
16 #include "GDCore/String.h"
22 class ObjectsContainer;
23 class ObjectsContainersList;
25 class ParameterMetadata;
27 class BehaviorMetadata;
28 class InstructionMetadata;
29 class EventsCodeGenerationContext;
30 class ExpressionCodeGenerationInformation;
31 class InstructionMetadata;
128 std::vector<gd::String> GenerateParametersCodes(
129 const std::vector<gd::Expression>& parameters,
130 const std::vector<gd::ParameterMetadata>& parametersInfo,
132 std::vector<std::pair<gd::String, gd::String> >*
133 supplementaryParametersTypes = 0);
162 const gd::String& optionalAsyncCallbackName =
"");
167 const std::set<gd::String> requiredObjects_)
168 : functionName(functionName_),
169 argumentsList(argumentsList_),
170 requiredObjects(requiredObjects_){};
215 virtual gd::String GenerateObjectsDeclarationCode(
262 if (!file.
empty()) includeFiles.insert(file);
270 for (std::size_t i = 0; i < files.size(); ++i) AddIncludeFile(files[i]);
277 customGlobalDeclarations.insert(declaration);
284 customCodeOutsideMain += code;
294 return customCodeOutsideMain;
300 return customGlobalDeclarations;
313 compilationForRuntime = compilationForRuntime_;
332 return projectScopedContainers.GetObjectsContainersList();
336 return projectScopedContainers;
367 return maxCustomConditionsDepth;
407 return "bool " + boolName +
" = false;\n";
451 enum VariableScope { LAYOUT_VARIABLE = 0, PROJECT_VARIABLE, OBJECT_VARIABLE };
465 size_t GenerateSingleUsageUniqueIdFor(
const gd::Instruction* instruction);
474 size_t GenerateSingleUsageUniqueIdForEventsList();
476 virtual gd::String GenerateRelationalOperation(
482 virtual const gd::String GenerateRelationalOperatorCodes(
526 std::vector<std::pair<gd::String, gd::String> >*
527 supplementaryParametersTypes);
534 const VariableScope& scope,
537 if (scope == LAYOUT_VARIABLE) {
538 return "getLayoutVariable(" + variableName +
")";
540 }
else if (scope == PROJECT_VARIABLE) {
541 return "getProjectVariable(" + variableName +
")";
544 return "getVariableForObject(" + objectName +
", " + variableName +
")";
551 return ".getChild(" + ConvertToStringExplicit(childName) +
")";
555 return type ==
"number|string" ?
".getAsNumberOrString()"
556 : type ==
"string" ?
".getAsString()"
566 return ".getChild(" + expressionCode +
")";
585 return "fakeObjectListOf_" + objectName;
617 virtual gd::String GenerateObjectFunctionCall(
638 virtual gd::String GenerateObjectBehaviorFunctionCall(
680 return "!(" + predicate +
")";
684 const std::vector<gd::String>& arguments,
687 bool conditionInverted,
693 const std::vector<gd::String>& arguments,
696 bool conditionInverted,
703 const std::vector<gd::String>& arguments,
706 bool conditionInverted,
711 const std::vector<gd::String>& arguments,
714 const gd::String& optionalAsyncCallbackName =
"");
720 const std::vector<gd::String>& arguments,
723 const gd::String& optionalAsyncCallbackName =
"");
730 const std::vector<gd::String>& arguments,
733 const gd::String& optionalAsyncCallbackName =
"");
737 const std::vector<gd::String>& arguments,
739 std::size_t startFromArgument = 0);
742 const std::vector<gd::String>& arguments,
745 std::size_t startFromArgument = 0);
748 const std::vector<gd::String>& arguments,
750 std::size_t startFromArgument = 0);
752 const std::vector<gd::String>& arguments,
754 std::size_t startFromArgument = 0);
774 const std::vector<gd::String>& arguments,
size_t startFrom = 0);
779 virtual gd::String GenerateGetBehaviorNameCode(
Used to manage the context when generating code for events.
Definition: EventsCodeGenerationContext.h:27
Internal class used to generate code from events.
Definition: EventsCodeGenerator.h:40
virtual gd::String GenerateNegatedPredicate(const gd::String &predicate) const
Must negate a predicate.
Definition: EventsCodeGenerator.h:678
size_t GetMaxConditionsListsSize() const
Get the maximum size of a list of conditions.
Definition: EventsCodeGenerator.h:373
const gd::Project * project
The project being used.
Definition: EventsCodeGenerator.h:788
void AddIncludeFiles(std::vector< gd::String > files)
Declare a list of include files to be added.
Definition: EventsCodeGenerator.h:269
virtual gd::String GetCodeNamespace()
Get the namespace to be used to store code generated objects/values/functions.
Definition: EventsCodeGenerator.h:449
const gd::Platform & GetPlatform() const
Get the platform the code is being generated for.
Definition: EventsCodeGenerator.h:360
virtual gd::String GenerateUpperScopeBooleanFullName(const gd::String &boolName, const gd::EventsCodeGenerationContext &context)
Generate the full name for accessing to a boolean variable used for conditions.
Definition: EventsCodeGenerator.h:393
void AddGlobalDeclaration(gd::String declaration)
Add a declaration which will be inserted after includes.
Definition: EventsCodeGenerator.h:276
virtual gd::String GenerateVariableBracketAccessor(gd::String expressionCode)
Generate the code to get the child of a variable, using generated the expression.
Definition: EventsCodeGenerator.h:564
const std::set< gd::String > & GetIncludeFiles() const
Get the set containing the include files.
Definition: EventsCodeGenerator.h:289
void SetGenerateCodeForRuntime(bool compilationForRuntime_)
Set if the code generated is meant to be used for runtime only and not in the IDE.
Definition: EventsCodeGenerator.h:312
size_t maxCustomConditionsDepth
Definition: EventsCodeGenerator.h:804
virtual gd::String GenerateScopeBegin(gd::EventsCodeGenerationContext &context, const gd::String &extraVariable="")
Called when a new scope must be entered.
Definition: EventsCodeGenerator.h:654
bool compilationForRuntime
Definition: EventsCodeGenerator.h:792
const gd::Platform & platform
The platform being used.
Definition: EventsCodeGenerator.h:782
virtual gd::String GenerateProfilerSectionBegin(const gd::String §ion)
Generate the code to notify the profiler of the beginning of a section.
Definition: EventsCodeGenerator.h:423
const gd::Layout * scene
The scene being generated.
Definition: EventsCodeGenerator.h:789
virtual gd::String GenerateBadVariable()
Generate the code to reference a variable which is in an empty/null state.
Definition: EventsCodeGenerator.h:573
virtual gd::String GenerateBooleanInitializationToFalse(const gd::String &boolName, const gd::EventsCodeGenerationContext &context)
Must create a boolean. Its value must be false.
Definition: EventsCodeGenerator.h:404
bool GenerateCodeForRuntime()
Return true if code generation is made for runtime only.
Definition: EventsCodeGenerator.h:306
virtual gd::String GenerateBadObject()
Generate the code to reference an object which is in an empty/null state.
Definition: EventsCodeGenerator.h:603
bool hasProjectAndLayout
Definition: EventsCodeGenerator.h:786
gd::String GenerateTrue() const
Return the "true" keyword in the target language.
Definition: EventsCodeGenerator.h:759
size_t GetMaxCustomConditionsDepth() const
Get the maximum depth of custom conditions reached during code generation.
Definition: EventsCodeGenerator.h:366
gd::String GenerateFalse() const
Return the "false" keyword in the target language.
Definition: EventsCodeGenerator.h:764
gd::String customCodeOutsideMain
Definition: EventsCodeGenerator.h:799
size_t maxConditionsListsSize
The maximum size of a list of conditions.
Definition: EventsCodeGenerator.h:806
size_t eventsListNextUniqueId
Definition: EventsCodeGenerator.h:810
std::set< gd::String > customGlobalDeclarations
Definition: EventsCodeGenerator.h:802
const std::set< gd::String > & GetCustomGlobalDeclaration() const
Get the custom declaration to be inserted after includes.
Definition: EventsCodeGenerator.h:299
virtual gd::String GenerateObject(const gd::String &objectName, const gd::String &type, gd::EventsCodeGenerationContext &context)
Generate the code to reference an object.
Definition: EventsCodeGenerator.h:582
bool HasProjectAndLayout() const
Return true if the code generation is done for a given project and layout. If not,...
Definition: EventsCodeGenerator.h:343
virtual gd::String GenerateBooleanFullName(const gd::String &boolName, const gd::EventsCodeGenerationContext &context)
Generate the full name for accessing to a boolean variable used for conditions.
Definition: EventsCodeGenerator.h:381
virtual gd::String GenerateProfilerSectionEnd(const gd::String §ion)
Generate the code to notify the profiler of the end of a section.
Definition: EventsCodeGenerator.h:430
const gd::String & GetCustomCodeOutsideMain() const
Get the custom code to be inserted outside main.
Definition: EventsCodeGenerator.h:293
const gd::Project & GetProject() const
Get the project the code is being generated for.
Definition: EventsCodeGenerator.h:349
void AddCustomCodeOutsideMain(gd::String code)
Add some code before events outside the main function.
Definition: EventsCodeGenerator.h:283
std::set< gd::String > includeFiles
Definition: EventsCodeGenerator.h:796
virtual gd::String GenerateGetVariable(const gd::String &variableName, const VariableScope &scope, gd::EventsCodeGenerationContext &context, const gd::String &objectName)
Generate the code to get a variable.
Definition: EventsCodeGenerator.h:532
void AddIncludeFile(gd::String file)
Declare an include file to be added.
Definition: EventsCodeGenerator.h:261
virtual gd::String GenerateVariableAccessor(gd::String childName)
Generate the code to get the child of a variable.
Definition: EventsCodeGenerator.h:550
bool errorOccurred
Must be set to true if an error occurred.
Definition: EventsCodeGenerator.h:791
virtual gd::String GetCodeNamespaceAccessor()
Get the namespace to be used to store code generated objects/values/functions, with the extra "dot" a...
Definition: EventsCodeGenerator.h:441
bool ErrorOccurred() const
Return true if an error has occurred during code generation (in this case, generated code is not usab...
Definition: EventsCodeGenerator.h:329
std::set< size_t > instructionUniqueIds
The unique ids generated for instructions.
Definition: EventsCodeGenerator.h:809
const gd::Layout & GetLayout() const
Get the layout the code is being generated for.
Definition: EventsCodeGenerator.h:355
virtual gd::String GenerateScopeEnd(gd::EventsCodeGenerationContext &context, const gd::String &extraVariable="")
Called when a new must be ended.
Definition: EventsCodeGenerator.h:667
A list of events.
Definition: EventsList.h:33
Generate code for a parsed expression.
Definition: ExpressionCodeGenerator.h:35
Class representing an expression used as a parameter of a gd::Instruction. This class is nothing more...
Definition: Expression.h:30
An instruction is a member of an event: It can be a condition or an action.
Definition: Instruction.h:30
Definition: InstructionsList.h:25
Represent a layout ( also called a scene ) of a project.
Definition: Layout.h:39
Used to describe a property shown in a property grid.
Definition: NamedPropertyDescriptor.h:21
A list of objects containers, useful for accessing objects in a scoped way, along with methods to acc...
Definition: ObjectsContainersList.h:29
Base class representing a project (game), including all resources, scenes, objects,...
Definition: Project.h:50
Holds references to variables, objects, properties and other containers.
Definition: ProjectScopedContainers.h:30
A container of properties, used for custom behaviors, custom objects, extensions.....
Definition: PropertiesContainer.h:17
String represents an UTF8 encoded string.
Definition: String.h:31
bool empty() const
Returns true if the string is empty.
Definition: String.h:155
Definition: CommonTools.h:24
Definition: EventsCodeGenerator.h:164
const std::set< gd::String > requiredObjects
Definition: EventsCodeGenerator.h:183
const gd::String argumentsList
Definition: EventsCodeGenerator.h:178
const gd::String functionName
Definition: EventsCodeGenerator.h:170