GDevelop Core
Core library for developing platforms and tools compatible with GDevelop.
Classes | Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | Friends | List of all members
gd::EventsCodeGenerator Class Reference

Internal class used to generate code from events. More...

#include <EventsCodeGenerator.h>

Classes

struct  CallbackDescriptor
 

Public Types

enum  VariableScope { LAYOUT_VARIABLE = 0 , PROJECT_VARIABLE , OBJECT_VARIABLE , ANY_VARIABLE }
 

Public Member Functions

 EventsCodeGenerator (const gd::Project &project_, const gd::Layout &layout, const gd::Platform &platform_)
 Construct a code generator for the specified platform/project/layout.
 
 EventsCodeGenerator (const gd::Platform &platform, const gd::ProjectScopedContainers &projectScopedContainers_)
 Construct a code generator for the specified objects/groups and platform.
 
void PreprocessEventList (gd::EventsList &listEvent)
 Preprocess an events list (replacing for example links with the linked events). More...
 
virtual gd::String GenerateEventsListCode (gd::EventsList &events, EventsCodeGenerationContext &context)
 Generate code for executing an event list. More...
 
virtual gd::String GenerateConditionsListCode (gd::InstructionsList &conditions, EventsCodeGenerationContext &context)
 Generate code for executing a condition list. More...
 
virtual gd::String GenerateActionsListCode (gd::InstructionsList &actions, EventsCodeGenerationContext &context)
 Generate code for executing an action list. More...
 
std::vector< gd::StringGenerateParametersCodes (const std::vector< gd::Expression > &parameters, const ParameterMetadataContainer &parametersInfo, EventsCodeGenerationContext &context, std::vector< std::pair< gd::String, gd::String > > *supplementaryParametersTypes=0)
 Generate the code for a parameter of an action/condition/expression. More...
 
gd::String GenerateConditionCode (gd::Instruction &condition, gd::String returnBoolean, EventsCodeGenerationContext &context)
 Generate code for a single condition. More...
 
gd::String GenerateActionCode (gd::Instruction &action, EventsCodeGenerationContext &context, const gd::String &optionalAsyncCallbackName="")
 Generate code for a single action. More...
 
virtual const CallbackDescriptor GenerateCallback (const gd::String &callbackFunctionName, gd::EventsCodeGenerationContext &parentContext, gd::InstructionsList &actions, gd::EventsList *subEvents=nullptr)
 Generates actions and events as a callback. More...
 
const gd::String GenerateEventsParameters (const gd::EventsCodeGenerationContext &context)
 Generates the parameters list of an event's generated function.
 
virtual gd::String GenerateObjectsDeclarationCode (EventsCodeGenerationContext &context)
 Generate code for declaring objects lists. More...
 
void AddIncludeFile (gd::String file)
 Declare an include file to be added. More...
 
void AddIncludeFiles (std::vector< gd::String > files)
 Declare a list of include files to be added. More...
 
void AddGlobalDeclaration (gd::String declaration)
 Add a declaration which will be inserted after includes.
 
void AddCustomCodeOutsideMain (gd::String code)
 Add some code before events outside the main function.
 
const std::set< gd::String > & GetIncludeFiles () const
 Get the set containing the include files.
 
const gd::StringGetCustomCodeOutsideMain () const
 Get the custom code to be inserted outside main.
 
const std::set< gd::String > & GetCustomGlobalDeclaration () const
 Get the custom declaration to be inserted after includes.
 
bool GenerateCodeForRuntime ()
 Return true if code generation is made for runtime only.
 
void SetGenerateCodeForRuntime (bool compilationForRuntime_)
 Set if the code generated is meant to be used for runtime only and not in the IDE.
 
void ReportError ()
 Report that an error occurred during code generation ( Event code won't be generated )
 
bool ErrorOccurred () const
 Return true if an error has occurred during code generation (in this case, generated code is not usable). More...
 
const gd::ObjectsContainersListGetObjectsContainersList () const
 
const gd::ProjectScopedContainersGetProjectScopedContainers () const
 
gd::ProjectScopedContainersGetProjectScopedContainers ()
 Give access to the project scoped containers as code generation might push and pop variable containers (for local variables). This could be passed as a parameter recursively in code generation, but this requires heavy refactoring. Instead, we use this single instance.
 
bool HasProjectAndLayout () const
 Return true if the code generation is done for a given project and layout. If not, this means that the code is generated for a function.
 
const gd::ProjectGetProject () const
 Get the project the code is being generated for. More...
 
const gd::LayoutGetLayout () const
 Get the layout the code is being generated for. More...
 
const gd::PlatformGetPlatform () const
 Get the platform the code is being generated for.
 
size_t GetMaxCustomConditionsDepth () const
 Get the maximum depth of custom conditions reached during code generation.
 
size_t GetMaxConditionsListsSize () const
 Get the maximum size of a list of conditions.
 
void SetDiagnosticReport (gd::DiagnosticReport *diagnosticReport_)
 
gd::DiagnosticReportGetDiagnosticReport ()
 
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. More...
 
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. More...
 
virtual gd::String GenerateBooleanInitializationToFalse (const gd::String &boolName, const gd::EventsCodeGenerationContext &context)
 Must create a boolean. Its value must be false. More...
 
virtual gd::String GetObjectListName (const gd::String &name, const gd::EventsCodeGenerationContext &context)
 Get the full name for accessing to a list of objects. More...
 
virtual gd::String GenerateProfilerSectionBegin (const gd::String &section)
 Generate the code to notify the profiler of the beginning of a section.
 
virtual gd::String GenerateProfilerSectionEnd (const gd::String &section)
 Generate the code to notify the profiler of the end of a section.
 
virtual gd::String GetCodeNamespaceAccessor ()
 Get the namespace to be used to store code generated objects/values/functions, with the extra "dot" at the end to be used to access to a property/member. More...
 
virtual gd::String GetCodeNamespace ()
 Get the namespace to be used to store code generated objects/values/functions. More...
 
size_t GenerateSingleUsageUniqueIdFor (const gd::Instruction *instruction)
 
size_t GenerateSingleUsageUniqueIdForEventsList ()
 
virtual gd::String GenerateRelationalOperation (const gd::String &relationalOperator, const gd::String &lhs, const gd::String &rhs)
 Generate a relational operation. More...
 
virtual gd::String GenerateLocalVariablesStackAccessor ()
 Generate the code to access the local variables stack.
 
gd::String GenerateAnyOrSceneVariableGetter (const gd::Expression &variableExpression, EventsCodeGenerationContext &context)
 Generate an any variable getter that fallbacks on scene variable for compatibility reason.
 

Static Public Member Functions

static void DeleteUselessEvents (gd::EventsList &events)
 Remove non executable events from the event list.
 
static gd::String ConvertToString (gd::String plainString)
 Must convert a plain string ( with line feed, quotes ) to a string that can be inserted into code. More...
 
static gd::String ConvertToStringExplicit (gd::String plainString)
 Convert a plain string (with line feed, quotes) to a string that can be inserted into code. The string construction must be explicit: for example, quotes must be added if the target language need quotes. More...
 

Protected Member Functions

virtual const gd::String GenerateRelationalOperatorCodes (const gd::String &operatorString)
 
virtual gd::String GenerateParameterCodes (const gd::Expression &parameter, const gd::ParameterMetadata &metadata, gd::EventsCodeGenerationContext &context, const gd::String &lastObjectName, std::vector< std::pair< gd::String, gd::String > > *supplementaryParametersTypes)
 Generate the code for a single parameter. More...
 
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.
 
virtual gd::String GenerateVariableAccessor (gd::String childName)
 Generate the code to get the child of a variable.
 
virtual gd::String GenerateVariableValueAs (const gd::String &type)
 
virtual gd::String GenerateVariableBracketAccessor (gd::String expressionCode)
 Generate the code to get the child of a variable, using generated the expression.
 
virtual gd::String GenerateBadVariable ()
 Generate the code to reference a variable which is in an empty/null state.
 
virtual gd::String GenerateObject (const gd::String &objectName, const gd::String &type, gd::EventsCodeGenerationContext &context)
 Generate the code to reference an object. More...
 
virtual gd::String GeneratePropertyGetter (const gd::PropertiesContainer &propertiesContainer, const gd::NamedPropertyDescriptor &property, const gd::String &type, gd::EventsCodeGenerationContext &context)
 
virtual gd::String GenerateParameterGetter (const gd::ParameterMetadata &parameter, const gd::String &type, gd::EventsCodeGenerationContext &context)
 
virtual gd::String GenerateBadObject ()
 Generate the code to reference an object which is in an empty/null state.
 
virtual gd::String GenerateObjectFunctionCall (gd::String objectListName, const ObjectMetadata &objMetadata, const gd::ExpressionCodeGenerationInformation &codeInfo, gd::String parametersStr, gd::String defaultOutput, gd::EventsCodeGenerationContext &context)
 Call a function of the current object. More...
 
virtual gd::String GenerateObjectBehaviorFunctionCall (gd::String objectListName, gd::String behaviorName, const gd::BehaviorMetadata &autoInfo, const gd::ExpressionCodeGenerationInformation &codeInfo, gd::String parametersStr, gd::String defaultOutput, gd::EventsCodeGenerationContext &context)
 Call a function of a behavior of the current object. More...
 
virtual gd::String GenerateScopeBegin (gd::EventsCodeGenerationContext &context, const gd::String &extraVariable="")
 Called when a new scope must be entered. More...
 
virtual gd::String GenerateScopeEnd (gd::EventsCodeGenerationContext &context, const gd::String &extraVariable="")
 Called when a new must be ended. More...
 
virtual gd::String GenerateNegatedPredicate (const gd::String &predicate) const
 Must negate a predicate. More...
 
virtual gd::String GenerateFreeCondition (const std::vector< gd::String > &arguments, const gd::InstructionMetadata &instrInfos, const gd::String &returnBoolean, bool conditionInverted, gd::EventsCodeGenerationContext &context)
 
virtual gd::String GenerateObjectCondition (const gd::String &objectName, const gd::ObjectMetadata &objInfo, const std::vector< gd::String > &arguments, const gd::InstructionMetadata &instrInfos, const gd::String &returnBoolean, bool conditionInverted, gd::EventsCodeGenerationContext &context)
 
virtual gd::String GenerateBehaviorCondition (const gd::String &objectName, const gd::String &behaviorName, const gd::BehaviorMetadata &autoInfo, const std::vector< gd::String > &arguments, const gd::InstructionMetadata &instrInfos, const gd::String &returnBoolean, bool conditionInverted, gd::EventsCodeGenerationContext &context)
 
virtual gd::String GenerateFreeAction (const gd::String &functionCallName, const std::vector< gd::String > &arguments, const gd::InstructionMetadata &instrInfos, gd::EventsCodeGenerationContext &context, const gd::String &optionalAsyncCallbackName="")
 
virtual gd::String GenerateObjectAction (const gd::String &objectName, const gd::ObjectMetadata &objInfo, const gd::String &functionCallName, const std::vector< gd::String > &arguments, const gd::InstructionMetadata &instrInfos, gd::EventsCodeGenerationContext &context, const gd::String &optionalAsyncCallbackName="")
 
virtual gd::String GenerateBehaviorAction (const gd::String &objectName, const gd::String &behaviorName, const gd::BehaviorMetadata &autoInfo, const gd::String &functionCallName, const std::vector< gd::String > &arguments, const gd::InstructionMetadata &instrInfos, gd::EventsCodeGenerationContext &context, const gd::String &optionalAsyncCallbackName="")
 
gd::String GenerateRelationalOperatorCall (const gd::InstructionMetadata &instrInfos, const std::vector< gd::String > &arguments, const gd::String &callStartString, std::size_t startFromArgument=0)
 
gd::String GenerateOperatorCall (const gd::InstructionMetadata &instrInfos, const std::vector< gd::String > &arguments, const gd::String &callStartString, const gd::String &getterStartString, std::size_t startFromArgument=0)
 
gd::String GenerateCompoundOperatorCall (const gd::InstructionMetadata &instrInfos, const std::vector< gd::String > &arguments, const gd::String &callStartString, std::size_t startFromArgument=0)
 
gd::String GenerateMutatorCall (const gd::InstructionMetadata &instrInfos, const std::vector< gd::String > &arguments, const gd::String &callStartString, std::size_t startFromArgument=0)
 
gd::String GenerateTrue () const
 Return the "true" keyword in the target language.
 
gd::String GenerateFalse () const
 Return the "false" keyword in the target language.
 
virtual gd::String GenerateArgumentsList (const std::vector< gd::String > &arguments, size_t startFrom=0)
 Generate the list of comma-separated arguments to be used to call a function. More...
 
virtual gd::String GenerateGetBehaviorNameCode (const gd::String &behaviorName)
 
void CheckBehaviorParameters (const gd::Instruction &instruction, const gd::InstructionMetadata &instrInfos)
 

Protected Attributes

const gd::Platformplatform
 The platform being used.
 
gd::ProjectScopedContainers projectScopedContainers
 
bool hasProjectAndLayout
 
const gd::Projectproject
 The project being used.
 
const gd::Layoutscene
 The scene being generated.
 
bool errorOccurred
 Must be set to true if an error occurred.
 
bool compilationForRuntime
 
std::set< gd::StringincludeFiles
 
gd::String customCodeOutsideMain
 
std::set< gd::StringcustomGlobalDeclarations
 
size_t maxCustomConditionsDepth
 
size_t maxConditionsListsSize
 The maximum size of a list of conditions.
 
std::set< size_t > instructionUniqueIds
 The unique ids generated for instructions.
 
size_t eventsListNextUniqueId
 
gd::DiagnosticReportdiagnosticReport
 

Friends

class ExpressionCodeGenerator
 

Detailed Description

Internal class used to generate code from events.

Member Function Documentation

◆ AddIncludeFile()

void gd::EventsCodeGenerator::AddIncludeFile ( gd::String  file)
inline

Declare an include file to be added.

Note
The way includes files are used may vary depending on the platform:
  • On GD C++ Platform, the includes files are added in the #include directives of the generated code.
  • On GD JS Platform, the includes files are added in the list of JS files in the index file.

◆ AddIncludeFiles()

void gd::EventsCodeGenerator::AddIncludeFiles ( std::vector< gd::String files)
inline

Declare a list of include files to be added.

See also
gd::EventsCodeGenerator::AddIncludeFile

◆ ConvertToString()

gd::String gd::EventsCodeGenerator::ConvertToString ( gd::String  plainString)
static

Must convert a plain string ( with line feed, quotes ) to a string that can be inserted into code.

Note
It is the caller responsibility to add proper code need to create a full string.

Usage example :

code += "gd::String(\""+codeGenerator.ConvertToString(name)+"\")";
/
Parameters
plainStringThe string to convert
Returns
plainString which can be included into the generated code.

◆ ConvertToStringExplicit()

gd::String gd::EventsCodeGenerator::ConvertToStringExplicit ( gd::String  plainString)
static

Convert a plain string (with line feed, quotes) to a string that can be inserted into code. The string construction must be explicit: for example, quotes must be added if the target language need quotes.

Usage example :

code += codeGenerator.ConvertToStringExplicit(name);
Note
The default implementation simply call ConvertToString and add quotes
Parameters
plainStringThe string to convert
Returns
plainString which can be included into the generated code.

◆ ErrorOccurred()

bool gd::EventsCodeGenerator::ErrorOccurred ( ) const
inline

Return true if an error has occurred during code generation (in this case, generated code is not usable).

Todo:
TODO: This is actually not used and should be moved to a more complete error reporting.

◆ GenerateActionCode()

gd::String gd::EventsCodeGenerator::GenerateActionCode ( gd::Instruction action,
EventsCodeGenerationContext context,
const gd::String optionalAsyncCallbackName = "" 
)

Generate code for a single action.

The generation is really done in GenerateFreeAction/GenerateObjectAction or GenerateBehaviorAction.

Parameters
conditioninstruction to be done.
contextContext used for generation
Returns
Code

Generate code for an action.

◆ GenerateActionsListCode()

gd::String gd::EventsCodeGenerator::GenerateActionsListCode ( gd::InstructionsList actions,
EventsCodeGenerationContext context 
)
virtual

Generate code for executing an action list.

The default implementation just calls repeatedly GenerateActionCode.

Parameters
gameGame used
sceneScene used
actionsstd::vector of actions
contextContext used for generation
Returns
Code

Generate actions code.

◆ GenerateArgumentsList()

gd::String gd::EventsCodeGenerator::GenerateArgumentsList ( const std::vector< gd::String > &  arguments,
size_t  startFrom = 0 
)
protectedvirtual

Generate the list of comma-separated arguments to be used to call a function.

Parameters
argumentsThe code already generated for the arguments
startFromIndex of the first argument, the previous will be ignored.

◆ GenerateBooleanFullName()

virtual gd::String gd::EventsCodeGenerator::GenerateBooleanFullName ( const gd::String boolName,
const gd::EventsCodeGenerationContext context 
)
inlinevirtual

Generate the full name for accessing to a boolean variable used for conditions.

Default implementation just returns the boolean name passed as argument.

◆ GenerateBooleanInitializationToFalse()

virtual gd::String gd::EventsCodeGenerator::GenerateBooleanInitializationToFalse ( const gd::String boolName,
const gd::EventsCodeGenerationContext context 
)
inlinevirtual

Must create a boolean. Its value must be false.

The default implementation generates C-style code.

◆ GenerateCallback()

const EventsCodeGenerator::CallbackDescriptor gd::EventsCodeGenerator::GenerateCallback ( const gd::String callbackFunctionName,
gd::EventsCodeGenerationContext parentContext,
gd::InstructionsList actions,
gd::EventsList subEvents = nullptr 
)
virtual

Generates actions and events as a callback.

This is used by asynchronous functions to run the code out of the normal events flow.

Returns
A set with all objects required by the callback code. The caller must take care of backing them up in a LongLivedObjectsList, and to pass it to the callback function as the last argument.

◆ GenerateCompoundOperatorCall()

gd::String gd::EventsCodeGenerator::GenerateCompoundOperatorCall ( const gd::InstructionMetadata instrInfos,
const std::vector< gd::String > &  arguments,
const gd::String callStartString,
std::size_t  startFromArgument = 0 
)
protected

Generate call using a compound assignment operators ( =,+=,-=,*=,/= ). Operator position is deduced from parameters type. Expression is assumed to be placed just before the operator.

Parameters
Informationabout the instruction
Arguments,intheir C++ form.
Stringto be placed at the start of the call ( the function to be called typically ). Example : MyObject->Set
Argumentswill be generated starting from this number. For example, set this to 1 to skip the first argument.

◆ GenerateConditionCode()

gd::String gd::EventsCodeGenerator::GenerateConditionCode ( gd::Instruction condition,
gd::String  returnBoolean,
EventsCodeGenerationContext context 
)

Generate code for a single condition.

The generation is really done in GenerateFreeCondition/GenerateObjectCondition or GenerateBehaviorCondition.

Parameters
conditioninstruction to be done.
returnBooleanThe name of the boolean that must contains the condition result.
contextContext used for generation
Returns
Code

◆ GenerateConditionsListCode()

gd::String gd::EventsCodeGenerator::GenerateConditionsListCode ( gd::InstructionsList conditions,
EventsCodeGenerationContext context 
)
virtual

Generate code for executing a condition list.

The default implementation create the condition calls using C-style ifs and booleans.

Parameters
gameGame used
sceneScene used
conditionsstd::vector of conditions
contextContext used for generation
Returns
Code. Boolean containing conditions result are name conditionXIsTrue, with X = the number of the condition, starting from 0.

Generate code for a list of conditions. Bools containing conditions results are named conditionXIsTrue.

◆ GenerateEventsListCode()

gd::String gd::EventsCodeGenerator::GenerateEventsListCode ( gd::EventsList events,
EventsCodeGenerationContext parentContext 
)
virtual

Generate code for executing an event list.

Parameters
eventsstd::vector of events
contextContext used for generation
Returns
Code

Generate events list code.

◆ GenerateGetBehaviorNameCode()

gd::String gd::EventsCodeGenerator::GenerateGetBehaviorNameCode ( const gd::String behaviorName)
protectedvirtual

Generate the getter to get the name of the specified behavior.

◆ GenerateNegatedPredicate()

virtual gd::String gd::EventsCodeGenerator::GenerateNegatedPredicate ( const gd::String predicate) const
inlineprotectedvirtual

Must negate a predicate.

The default implementation generates C-style code : It wraps the predicate inside parenthesis and add a !.

◆ GenerateObject()

virtual gd::String gd::EventsCodeGenerator::GenerateObject ( const gd::String objectName,
const gd::String type,
gd::EventsCodeGenerationContext context 
)
inlineprotectedvirtual

Generate the code to reference an object.

Parameters
objectNamethe name of the object.
typewhat is the expected type (object, objectPtr...) in which the object must be generated.
contextThe context for code generation

◆ GenerateObjectBehaviorFunctionCall()

gd::String gd::EventsCodeGenerator::GenerateObjectBehaviorFunctionCall ( gd::String  objectListName,
gd::String  behaviorName,
const gd::BehaviorMetadata autoInfo,
const gd::ExpressionCodeGenerationInformation codeInfo,
gd::String  parametersStr,
gd::String  defaultOutput,
gd::EventsCodeGenerationContext context 
)
protectedvirtual

Call a function of a behavior of the current object.

Note
The current object is the object being manipulated by a condition or an action.
Parameters
objectListNameThe full name of the object list being used
behaviorNameThe full name of the behavior to be used
objMetadataMetadata about the behavior being used.
functionCallNameThe function to be called on this object.
parametersStrThe parameters of the function
contextThe context : May be used to get information about the current scope.

◆ GenerateObjectFunctionCall()

gd::String gd::EventsCodeGenerator::GenerateObjectFunctionCall ( gd::String  objectListName,
const ObjectMetadata objMetadata,
const gd::ExpressionCodeGenerationInformation codeInfo,
gd::String  parametersStr,
gd::String  defaultOutput,
gd::EventsCodeGenerationContext context 
)
protectedvirtual

Call a function of the current object.

Note
The current object is the object being manipulated by a condition or an action.
Parameters
objectListNameThe full name of the object list being used
objMetadataMetadata about the object being used.
functionCallNameThe function to be called on this object.
parametersStrThe parameters of the function
contextThe context : May be used to get information about the current scope.

◆ GenerateObjectsDeclarationCode()

gd::String gd::EventsCodeGenerator::GenerateObjectsDeclarationCode ( EventsCodeGenerationContext context)
virtual

Generate code for declaring objects lists.

This method is used for each event.

Parameters
contextThe context to be used.

◆ GenerateOperatorCall()

gd::String gd::EventsCodeGenerator::GenerateOperatorCall ( const gd::InstructionMetadata instrInfos,
const std::vector< gd::String > &  arguments,
const gd::String callStartString,
const gd::String getterStartString,
std::size_t  startFromArgument = 0 
)
protected

Generate call using an operator ( =,+,-,*,/ ). Operator position is deduced from parameters type. Expression is assumed to be placed just before the operator.

Parameters
Informationabout the instruction
Arguments,intheir C++ form.
Stringto be placed at the start of the call ( the function to be called typically ). Example : MyObject->Set
Stringto be placed at the start of the call of the getter ( the "getter" function to be called typically ). Example : MyObject->Get
Argumentswill be generated starting from this number. For example, set this to 1 to skip the first argument.

◆ GenerateParameterCodes()

gd::String gd::EventsCodeGenerator::GenerateParameterCodes ( const gd::Expression parameter,
const gd::ParameterMetadata metadata,
gd::EventsCodeGenerationContext context,
const gd::String lastObjectName,
std::vector< std::pair< gd::String, gd::String > > *  supplementaryParametersTypes 
)
protectedvirtual

Generate the code for a single parameter.

Standard supported parameters type, and how they are used in code:

  • object : Object name -> string
  • expression : Mathematical expression -> number (double)
  • string : Text expression -> string
  • layer, color, file, stringWithSelector : Same as string
  • relationalOperator : Used to make a comparison between the function return value and value of the parameter preceding the relationOperator parameter -> string
  • operator : Used to update a value using a setter and a getter -> string
  • key, mouse, objectvar, scenevar, globalvar, password, musicfile, soundfile -> string
  • trueorfalse, yesorno -> boolean ( See GenerateTrue/GenerateFalse ).



"Code only" parameters types:

  • inlineCode: supplementary information associated with the parameter is directly pasted in the code without change.



Other standard parameters type that should be implemented by platforms:

  • currentScene: Reference to the current runtime scene.
  • objectList : a map containing lists of objects which are specified by the object name in another parameter.
  • objectListOrEmptyIfJustDeclared : Same as objectList but do not pick object if they are not already picked.
  • objectPtr: Return a reference to the object specified by the object name in another parameter. Example:
    .AddParameter("object", _("Object"))
    .AddParameter("objectPtr", _("Target object"))

◆ GenerateParametersCodes()

vector< gd::String > gd::EventsCodeGenerator::GenerateParametersCodes ( const std::vector< gd::Expression > &  parameters,
const ParameterMetadataContainer parametersInfo,
EventsCodeGenerationContext context,
std::vector< std::pair< gd::String, gd::String > > *  supplementaryParametersTypes = 0 
)

Generate the code for a parameter of an action/condition/expression.

This method uses GenerateParameterCodes to generate the parameters code.

Parameters
sceneScene used
parametersstd::vector of actual parameters.
parametersInfostd::vector of information about parameters
contextContext used for generation
supplementaryParametersTypesOptional std::vector of new parameters types ( std::vector of pair<gd::String,gd::String>("type", "valueToBeInserted") )

◆ GenerateRelationalOperation()

gd::String gd::EventsCodeGenerator::GenerateRelationalOperation ( const gd::String relationalOperator,
const gd::String lhs,
const gd::String rhs 
)
virtual

Generate a relational operation.

Parameters
relationalOperatorthe operator
lhsthe left hand operand
rhsthe right hand operand
Returns
gd::String

◆ GenerateRelationalOperatorCall()

gd::String gd::EventsCodeGenerator::GenerateRelationalOperatorCall ( const gd::InstructionMetadata instrInfos,
const std::vector< gd::String > &  arguments,
const gd::String callStartString,
std::size_t  startFromArgument = 0 
)
protected

Generate call using a relational operator. Relational operator position is deduced from parameters type. Rhs hand side expression is assumed to be placed just before the relational operator.

Parameters
Informationabout the instruction
Arguments,intheir C++ form.
Stringto be placed at the start of the call ( the function to be called typically ). Example : MyObject->Get
Argumentswill be generated starting from this number. For example, set this to 1 to skip the first argument.

◆ GenerateScopeBegin()

virtual gd::String gd::EventsCodeGenerator::GenerateScopeBegin ( gd::EventsCodeGenerationContext context,
const gd::String extraVariable = "" 
)
inlineprotectedvirtual

Called when a new scope must be entered.

Parameters
contextThe context : Internal events of the scope have been generated, but GenerateObjectsDeclarationCode was not called.
extraVariableAn optional supplementary variable that should be inherited from the parent scope.

◆ GenerateScopeEnd()

virtual gd::String gd::EventsCodeGenerator::GenerateScopeEnd ( gd::EventsCodeGenerationContext context,
const gd::String extraVariable = "" 
)
inlineprotectedvirtual

Called when a new must be ended.

Parameters
contextThe context : Internal events of the scope have been generated, but GenerateObjectsDeclarationCode was not called.
extraVariableAn optional supplementary variable that should be inherited from the parent scope.

◆ GenerateSingleUsageUniqueIdFor()

size_t gd::EventsCodeGenerator::GenerateSingleUsageUniqueIdFor ( const gd::Instruction instruction)

Generate a single unique number for the specified instruction.

This is useful for instructions that need to identify themselves in the generated code like the "Trigger Once" conditions. The id is stable across code generations if the instructions are the same objects in memory.

Note that if this function is called multiple times with the same instruction, the unique number returned will be different. This is because a single instruction might appear at multiple places in events due to the usage of links.

◆ GenerateSingleUsageUniqueIdForEventsList()

size_t gd::EventsCodeGenerator::GenerateSingleUsageUniqueIdForEventsList ( )

Generate a single unique number for an events list.

This is useful to create unique function names for events list, that are stable across code generation given the exact same list of events. They are not stable if events are moved/reorganized.

◆ GenerateUpperScopeBooleanFullName()

virtual gd::String gd::EventsCodeGenerator::GenerateUpperScopeBooleanFullName ( const gd::String boolName,
const gd::EventsCodeGenerationContext context 
)
inlinevirtual

Generate the full name for accessing to a boolean variable used for conditions.

Default implementation just returns the boolean name passed as argument.

◆ GetCodeNamespace()

virtual gd::String gd::EventsCodeGenerator::GetCodeNamespace ( )
inlinevirtual

Get the namespace to be used to store code generated objects/values/functions.

Example: "gdjs.something"

◆ GetCodeNamespaceAccessor()

virtual gd::String gd::EventsCodeGenerator::GetCodeNamespaceAccessor ( )
inlinevirtual

Get the namespace to be used to store code generated objects/values/functions, with the extra "dot" at the end to be used to access to a property/member.

Example: "gdjs.something."

◆ GetLayout()

const gd::Layout& gd::EventsCodeGenerator::GetLayout ( ) const
inline

Get the layout the code is being generated for.

Warning
This is only valid if HasProjectAndLayout() is true.

◆ GetObjectListName()

gd::String gd::EventsCodeGenerator::GetObjectListName ( const gd::String name,
const gd::EventsCodeGenerationContext context 
)
virtual

Get the full name for accessing to a list of objects.

Default implementation simply returns the name mangled using gd::EventsCodeNameMangler.

◆ GetProject()

const gd::Project& gd::EventsCodeGenerator::GetProject ( ) const
inline

Get the project the code is being generated for.

Warning
This is only valid if HasProjectAndLayout() is true.

◆ PreprocessEventList()

void gd::EventsCodeGenerator::PreprocessEventList ( gd::EventsList listEvent)

Preprocess an events list (replacing for example links with the linked events).

This should be called before any code generation.

Call preprocessing method of each event

Member Data Documentation

◆ compilationForRuntime

bool gd::EventsCodeGenerator::compilationForRuntime
protected

Is set to true if the code generation is made for runtime only.

◆ customCodeOutsideMain

gd::String gd::EventsCodeGenerator::customCodeOutsideMain
protected

Custom code inserted before events ( and not in events function )

◆ customGlobalDeclarations

std::set<gd::String> gd::EventsCodeGenerator::customGlobalDeclarations
protected

Custom global C++ declarations inserted after includes

◆ eventsListNextUniqueId

size_t gd::EventsCodeGenerator::eventsListNextUniqueId
protected

The next identifier to use for an events list function name.

◆ hasProjectAndLayout

bool gd::EventsCodeGenerator::hasProjectAndLayout
protected

true only if project and layout are valid references. If false, they should not be used.

◆ includeFiles

std::set<gd::String> gd::EventsCodeGenerator::includeFiles
protected

List of headers files used by instructions. A (shared) pointer is used so as context created from another one can share the same list.

◆ maxCustomConditionsDepth

size_t gd::EventsCodeGenerator::maxCustomConditionsDepth
protected

The maximum depth value for all the custom conditions created.


The documentation for this class was generated from the following files: