12 #include "GDCore/Events/Event.h"
13 #include "GDCore/Events/Instruction.h"
14 #include "GDCore/Events/CodeGeneration/DiagnosticReport.h"
15 #include "GDCore/Project/ProjectScopedContainers.h"
16 #include "GDCore/String.h"
23 class ObjectsContainer;
24 class ObjectsContainersList;
26 class ParameterMetadata;
28 class BehaviorMetadata;
29 class InstructionMetadata;
30 class EventsCodeGenerationContext;
31 class ExpressionCodeGenerationInformation;
32 class InstructionMetadata;
129 std::vector<gd::String> GenerateParametersCodes(
130 const std::vector<gd::Expression>& parameters,
133 std::vector<std::pair<gd::String, gd::String> >*
134 supplementaryParametersTypes = 0);
163 const gd::String& optionalAsyncCallbackName =
"");
168 const std::set<gd::String> requiredObjects_)
169 : functionName(functionName_),
170 argumentsList(argumentsList_),
171 requiredObjects(requiredObjects_){};
216 virtual gd::String GenerateObjectsDeclarationCode(
263 if (!file.
empty()) includeFiles.insert(file);
271 for (std::size_t i = 0; i < files.size(); ++i) AddIncludeFile(files[i]);
278 customGlobalDeclarations.insert(declaration);
285 customCodeOutsideMain += code;
295 return customCodeOutsideMain;
301 return customGlobalDeclarations;
314 compilationForRuntime = compilationForRuntime_;
333 return projectScopedContainers.GetObjectsContainersList();
337 return projectScopedContainers;
347 return projectScopedContainers;
378 return maxCustomConditionsDepth;
387 diagnosticReport = diagnosticReport_;
391 return diagnosticReport;
426 return "bool " + boolName +
" = false;\n";
470 enum VariableScope { LAYOUT_VARIABLE = 0, PROJECT_VARIABLE, OBJECT_VARIABLE, ANY_VARIABLE };
484 size_t GenerateSingleUsageUniqueIdFor(
const gd::Instruction* instruction);
493 size_t GenerateSingleUsageUniqueIdForEventsList();
495 virtual gd::String GenerateRelationalOperation(
503 virtual gd::String GenerateLocalVariablesStackAccessor();
510 GenerateAnyOrSceneVariableGetter(
const gd::Expression &variableExpression,
511 EventsCodeGenerationContext &context);
514 virtual const gd::String GenerateRelationalOperatorCodes(
558 std::vector<std::pair<gd::String, gd::String> >*
559 supplementaryParametersTypes);
566 const VariableScope& scope,
571 if (scope == LAYOUT_VARIABLE) {
572 return "getLayoutVariable(" + variableName +
")";
574 }
else if (scope == PROJECT_VARIABLE) {
575 return "getProjectVariable(" + variableName +
")";
576 }
else if (scope == ANY_VARIABLE) {
577 return "getAnyVariable(" + variableName +
")";
580 return "getVariableForObject(" + objectName +
", " + variableName +
")";
587 return ".getChild(" + ConvertToStringExplicit(childName) +
")";
591 return type ==
"number|string" ?
".getAsNumberOrString()"
592 : type ==
"string" ?
".getAsString()"
602 return ".getChild(" + expressionCode +
")";
621 return "fakeObjectListOf_" + objectName;
653 virtual gd::String GenerateObjectFunctionCall(
674 virtual gd::String GenerateObjectBehaviorFunctionCall(
716 return "!(" + predicate +
")";
720 const std::vector<gd::String>& arguments,
723 bool conditionInverted,
729 const std::vector<gd::String>& arguments,
732 bool conditionInverted,
739 const std::vector<gd::String>& arguments,
742 bool conditionInverted,
747 const std::vector<gd::String>& arguments,
750 const gd::String& optionalAsyncCallbackName =
"");
756 const std::vector<gd::String>& arguments,
759 const gd::String& optionalAsyncCallbackName =
"");
766 const std::vector<gd::String>& arguments,
769 const gd::String& optionalAsyncCallbackName =
"");
773 const std::vector<gd::String>& arguments,
775 std::size_t startFromArgument = 0);
778 const std::vector<gd::String>& arguments,
781 std::size_t startFromArgument = 0);
784 const std::vector<gd::String>& arguments,
786 std::size_t startFromArgument = 0);
788 const std::vector<gd::String>& arguments,
790 std::size_t startFromArgument = 0);
810 const std::vector<gd::String>& arguments,
size_t startFrom = 0);
815 virtual gd::String GenerateGetBehaviorNameCode(
818 void CheckBehaviorParameters(
Definition: DiagnosticReport.h:57
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:41
virtual gd::String GenerateNegatedPredicate(const gd::String &predicate) const
Must negate a predicate.
Definition: EventsCodeGenerator.h:714
size_t GetMaxConditionsListsSize() const
Get the maximum size of a list of conditions.
Definition: EventsCodeGenerator.h:384
const gd::Project * project
The project being used.
Definition: EventsCodeGenerator.h:828
void AddIncludeFiles(std::vector< gd::String > files)
Declare a list of include files to be added.
Definition: EventsCodeGenerator.h:270
virtual gd::String GetCodeNamespace()
Get the namespace to be used to store code generated objects/values/functions.
Definition: EventsCodeGenerator.h:468
const gd::Platform & GetPlatform() const
Get the platform the code is being generated for.
Definition: EventsCodeGenerator.h:371
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:412
void AddGlobalDeclaration(gd::String declaration)
Add a declaration which will be inserted after includes.
Definition: EventsCodeGenerator.h:277
virtual gd::String GenerateVariableBracketAccessor(gd::String expressionCode)
Generate the code to get the child of a variable, using generated the expression.
Definition: EventsCodeGenerator.h:600
const std::set< gd::String > & GetIncludeFiles() const
Get the set containing the include files.
Definition: EventsCodeGenerator.h:290
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:313
size_t maxCustomConditionsDepth
Definition: EventsCodeGenerator.h:844
virtual gd::String GenerateScopeBegin(gd::EventsCodeGenerationContext &context, const gd::String &extraVariable="")
Called when a new scope must be entered.
Definition: EventsCodeGenerator.h:690
bool compilationForRuntime
Definition: EventsCodeGenerator.h:832
const gd::Platform & platform
The platform being used.
Definition: EventsCodeGenerator.h:822
virtual gd::String GenerateProfilerSectionBegin(const gd::String §ion)
Generate the code to notify the profiler of the beginning of a section.
Definition: EventsCodeGenerator.h:442
const gd::Layout * scene
The scene being generated.
Definition: EventsCodeGenerator.h:829
virtual gd::String GenerateBadVariable()
Generate the code to reference a variable which is in an empty/null state.
Definition: EventsCodeGenerator.h:609
virtual gd::String GenerateBooleanInitializationToFalse(const gd::String &boolName, const gd::EventsCodeGenerationContext &context)
Must create a boolean. Its value must be false.
Definition: EventsCodeGenerator.h:423
bool GenerateCodeForRuntime()
Return true if code generation is made for runtime only.
Definition: EventsCodeGenerator.h:307
virtual gd::String GenerateBadObject()
Generate the code to reference an object which is in an empty/null state.
Definition: EventsCodeGenerator.h:639
bool hasProjectAndLayout
Definition: EventsCodeGenerator.h:826
gd::String GenerateTrue() const
Return the "true" keyword in the target language.
Definition: EventsCodeGenerator.h:795
size_t GetMaxCustomConditionsDepth() const
Get the maximum depth of custom conditions reached during code generation.
Definition: EventsCodeGenerator.h:377
gd::String GenerateFalse() const
Return the "false" keyword in the target language.
Definition: EventsCodeGenerator.h:800
gd::String customCodeOutsideMain
Definition: EventsCodeGenerator.h:839
size_t maxConditionsListsSize
The maximum size of a list of conditions.
Definition: EventsCodeGenerator.h:846
gd::ProjectScopedContainers & GetProjectScopedContainers()
Give access to the project scoped containers as code generation might push and pop variable container...
Definition: EventsCodeGenerator.h:346
size_t eventsListNextUniqueId
Definition: EventsCodeGenerator.h:850
std::set< gd::String > customGlobalDeclarations
Definition: EventsCodeGenerator.h:842
const std::set< gd::String > & GetCustomGlobalDeclaration() const
Get the custom declaration to be inserted after includes.
Definition: EventsCodeGenerator.h:300
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:618
bool HasProjectAndLayout() const
Return true if the code generation is done for a given project and layout. If not,...
Definition: EventsCodeGenerator.h:354
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:400
virtual gd::String GenerateProfilerSectionEnd(const gd::String §ion)
Generate the code to notify the profiler of the end of a section.
Definition: EventsCodeGenerator.h:449
const gd::String & GetCustomCodeOutsideMain() const
Get the custom code to be inserted outside main.
Definition: EventsCodeGenerator.h:294
const gd::Project & GetProject() const
Get the project the code is being generated for.
Definition: EventsCodeGenerator.h:360
void AddCustomCodeOutsideMain(gd::String code)
Add some code before events outside the main function.
Definition: EventsCodeGenerator.h:284
std::set< gd::String > includeFiles
Definition: EventsCodeGenerator.h:836
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:564
void AddIncludeFile(gd::String file)
Declare an include file to be added.
Definition: EventsCodeGenerator.h:262
virtual gd::String GenerateVariableAccessor(gd::String childName)
Generate the code to get the child of a variable.
Definition: EventsCodeGenerator.h:586
bool errorOccurred
Must be set to true if an error occurred.
Definition: EventsCodeGenerator.h:831
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:460
bool ErrorOccurred() const
Return true if an error has occurred during code generation (in this case, generated code is not usab...
Definition: EventsCodeGenerator.h:330
std::set< size_t > instructionUniqueIds
The unique ids generated for instructions.
Definition: EventsCodeGenerator.h:849
const gd::Layout & GetLayout() const
Get the layout the code is being generated for.
Definition: EventsCodeGenerator.h:366
virtual gd::String GenerateScopeEnd(gd::EventsCodeGenerationContext &context, const gd::String &extraVariable="")
Called when a new must be ended.
Definition: EventsCodeGenerator.h:703
A list of events.
Definition: EventsList.h:32
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:40
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:51
Holds references to variables, objects, properties and other containers.
Definition: ProjectScopedContainers.h:34
A container of properties, used for custom behaviors, custom objects, extensions.....
Definition: PropertiesContainer.h:17
String represents an UTF8 encoded string.
Definition: String.h:33
bool empty() const
Returns true if the string is empty.
Definition: String.h:157
Definition: CommonTools.h:24
Definition: EventsCodeGenerator.h:165
const std::set< gd::String > requiredObjects
Definition: EventsCodeGenerator.h:184
const gd::String argumentsList
Definition: EventsCodeGenerator.h:179
const gd::String functionName
Definition: EventsCodeGenerator.h:171