GDevelop Core
Core library for developing platforms and tools compatible with GDevelop.
Public Member Functions | Friends | List of all members
gd::EventsCodeGenerationContext Class Reference

Used to manage the context when generating code for events. More...

#include <EventsCodeGenerationContext.h>

Public Member Functions

 EventsCodeGenerationContext (unsigned int *maxDepthLevel_=nullptr)
 
void InheritsFrom (EventsCodeGenerationContext &parent)
 
void InheritsAsAsyncCallbackFrom (EventsCodeGenerationContext &parent)
 
void Reuse (EventsCodeGenerationContext &parent)
 As InheritsFrom, mark the context as being the child of another one, but enabling the child context to use the same object lists. More...
 
void ForbidReuse ()
 Forbid any optimization that would reuse and modify the object list from this context in children context. More...
 
bool CanReuse () const
 Return false if the object lists of the context can not be reused in a child context.
 
size_t GetContextDepth () const
 Returns the depth of the inheritance of the context. More...
 
const EventsCodeGenerationContextGetParentContext () const
 Get the parent context, if any. More...
 
void SetCurrentObject (const gd::String &objectName)
 
void SetNoCurrentObject ()
 
const gd::StringGetCurrentObject () const
 
void ObjectsListNeeded (const gd::String &objectName)
 Call this when an instruction in the event needs an objects list. More...
 
void ObjectsListNeededOrEmptyIfJustDeclared (const gd::String &objectName)
 
void EmptyObjectsListNeeded (const gd::String &objectName)
 
bool ObjectAlreadyDeclaredByParents (const gd::String &objectName) const
 
std::set< gd::StringGetAllObjectsToBeDeclared () const
 
const std::set< gd::String > & GetObjectsListsToBeDeclared () const
 
const std::set< gd::String > & GetObjectsListsToBeEmptyIfJustDeclared () const
 
const std::set< gd::String > & GetObjectsListsToBeDeclaredEmpty () const
 
const std::set< gd::String > & GetObjectsListsAlreadyDeclaredByParents () const
 
unsigned int GetLastDepthObjectListWasNeeded (const gd::String &objectName) const
 Get the depth of the context that was in effect when objectName was needed. More...
 
bool IsSameObjectsList (const gd::String &objectName, const EventsCodeGenerationContext &otherContext) const
 Check if twos context have the same list for an object. More...
 
void EnterCustomCondition ()
 Called when a custom condition code is generated.
 
void LeaveCustomCondition ()
 Called when a custom condition code generation is over.
 
size_t GetCurrentConditionDepth () const
 Get the current condition depth : The depth is increased each time a custom condition code is generated, and decreased when the condition generation is done. More...
 
const std::set< gd::String > & GetAllDeclaredObjectsAcrossChildren ()
 Returns the list of all objects declared in this context and subcontexts. More...
 
bool ShouldUseAsyncObjectsList (const gd::String &objectName) const
 
bool IsInsideAsync () const
 
bool IsAsyncCallback () const
 
bool IsToBeDeclared (const gd::String &objectName)
 Returns true if the given object is already going to be declared in this context (either as a traditional objects list, or an empty one).
 

Friends

class EventsCodeGenerator
 

Detailed Description

Used to manage the context when generating code for events.

The context refers to :

Constructor & Destructor Documentation

◆ EventsCodeGenerationContext()

gd::EventsCodeGenerationContext::EventsCodeGenerationContext ( unsigned int *  maxDepthLevel_ = nullptr)
inline

Default constructor. You may want to call InheritsFrom just after.

Parameters
maxDepthLevelOptional pointer to an unsigned integer that will be updated to contain the maximal scope depth reached.

Member Function Documentation

◆ EmptyObjectsListNeeded()

void gd::EventsCodeGenerationContext::EmptyObjectsListNeeded ( const gd::String objectName)

Call this when an instruction in the event needs an empty object list, even if one is already declared.

An empty objects list will be declared, without filling it with objects from the scene. If there is already an object list with this name, it won't be used to initialize the new list, which will remain empty.

◆ ForbidReuse()

void gd::EventsCodeGenerationContext::ForbidReuse ( )
inline

Forbid any optimization that would reuse and modify the object list from this context in children context.

Used in while/for each/repeat or any event that have a loop and must ensure that the list of objects stay clean.

◆ GetAllDeclaredObjectsAcrossChildren()

const std::set<gd::String>& gd::EventsCodeGenerationContext::GetAllDeclaredObjectsAcrossChildren ( )
inline

Returns the list of all objects declared in this context and subcontexts.

Warning
Only works on an async callback's context.

It is to be used by the Async event code generator to know what objects lists to backup for the async callback and async callbacks after it.

◆ GetAllObjectsToBeDeclared()

std::set< gd::String > gd::EventsCodeGenerationContext::GetAllObjectsToBeDeclared ( ) const

Return all the objects lists which will be declared by the current context (normal, potentially empty or empty).

◆ GetContextDepth()

size_t gd::EventsCodeGenerationContext::GetContextDepth ( ) const
inline

Returns the depth of the inheritance of the context.

A context created from scratch will returns 0, and a context inheriting from a context with depth n will returns n+1.

◆ GetCurrentConditionDepth()

size_t gd::EventsCodeGenerationContext::GetCurrentConditionDepth ( ) const
inline

Get the current condition depth : The depth is increased each time a custom condition code is generated, and decreased when the condition generation is done.

This can be useful to generate sub conditions booleans with a different name than the parent's conditions.

◆ GetCurrentObject()

const gd::String& gd::EventsCodeGenerationContext::GetCurrentObject ( ) const
inline

Get the object being handled by the instruction.

◆ GetLastDepthObjectListWasNeeded()

unsigned int gd::EventsCodeGenerationContext::GetLastDepthObjectListWasNeeded ( const gd::String objectName) const

Get the depth of the context that was in effect when objectName was needed.

If objectName is needed in this context, it will return the depth of this context.

◆ GetObjectsListsAlreadyDeclaredByParents()

const std::set<gd::String>& gd::EventsCodeGenerationContext::GetObjectsListsAlreadyDeclaredByParents ( ) const
inline

Return the objects lists which are already declared and can be used in the current context without declaration.

◆ GetObjectsListsToBeDeclared()

const std::set<gd::String>& gd::EventsCodeGenerationContext::GetObjectsListsToBeDeclared ( ) const
inline

Return the objects lists which will be declared by the current context.

◆ GetObjectsListsToBeDeclaredEmpty()

const std::set<gd::String>& gd::EventsCodeGenerationContext::GetObjectsListsToBeDeclaredEmpty ( ) const
inline

Return the objects lists which will be will be declared empty, without filling them with objects from the scene and without copying any previously declared objects list.

◆ GetObjectsListsToBeEmptyIfJustDeclared()

const std::set<gd::String>& gd::EventsCodeGenerationContext::GetObjectsListsToBeEmptyIfJustDeclared ( ) const
inline

Return the objects lists which will be will be declared, without filling them with objects from the scene.

◆ GetParentContext()

const EventsCodeGenerationContext* gd::EventsCodeGenerationContext::GetParentContext ( ) const
inline

Get the parent context, if any.

Returns
A pointer to the parent context, or NULL if the context has no parent.

◆ InheritsAsAsyncCallbackFrom()

void gd::EventsCodeGenerationContext::InheritsAsAsyncCallbackFrom ( EventsCodeGenerationContext parent)

Call this method to make an EventsCodeGenerationContext as a "child" of another one, but in the context of an async function.

◆ InheritsFrom()

void gd::EventsCodeGenerationContext::InheritsFrom ( EventsCodeGenerationContext parent)

Call this method to make an EventsCodeGenerationContext as a "child" of another one. The child will then for example not declare again objects already declared by its parent.

◆ IsAsyncCallback()

bool gd::EventsCodeGenerationContext::IsAsyncCallback ( ) const
inline

Returns true if the code currently being generated is an asynchronous callback (but not a child of an asynchronous callback).

◆ IsInsideAsync()

bool gd::EventsCodeGenerationContext::IsInsideAsync ( ) const
inline

Returns true if the code currently being generated is inside an asynchronous context (either in an asynchronous callback, or in a children of an asynchronous callback).

◆ IsSameObjectsList()

bool gd::EventsCodeGenerationContext::IsSameObjectsList ( const gd::String objectName,
const EventsCodeGenerationContext otherContext 
) const

Check if twos context have the same list for an object.

This can be the case when a context is reusing the lists of another (see gd::EventsCodeGenerationContext::Reuse).

◆ ObjectAlreadyDeclaredByParents()

bool gd::EventsCodeGenerationContext::ObjectAlreadyDeclaredByParents ( const gd::String objectName) const
inline

Return true if an object list has already been declared by the parent contexts.

◆ ObjectsListNeeded()

void gd::EventsCodeGenerationContext::ObjectsListNeeded ( const gd::String objectName)

Call this when an instruction in the event needs an objects list.

The list will be filled with objects from the scene if it is the first time it is requested, unless there is already an object list with this name (i.e. ObjectAlreadyDeclaredByParents(objectName) returns true).

◆ ObjectsListNeededOrEmptyIfJustDeclared()

void gd::EventsCodeGenerationContext::ObjectsListNeededOrEmptyIfJustDeclared ( const gd::String objectName)

Call this when an instruction in the event needs an empty objects list or the one already declared, if any.

An empty objects list will be declared, without filling it with objects from the scene. If there is already an objects list with this name, no new list will be declared again.

◆ Reuse()

void gd::EventsCodeGenerationContext::Reuse ( EventsCodeGenerationContext parent)

As InheritsFrom, mark the context as being the child of another one, but enabling the child context to use the same object lists.

Used for example for optimizing the last event of a list.

◆ SetCurrentObject()

void gd::EventsCodeGenerationContext::SetCurrentObject ( const gd::String objectName)
inline

Mark the object as being the object being handled by the instruction.

◆ SetNoCurrentObject()

void gd::EventsCodeGenerationContext::SetNoCurrentObject ( )
inline

Set that no particular object is being handled by an instruction.

◆ ShouldUseAsyncObjectsList()

bool gd::EventsCodeGenerationContext::ShouldUseAsyncObjectsList ( const gd::String objectName) const

Returns true if an object list should be gotten from a backed up objects list instead of the parent context. This can happen inside an asynchronous callback or a child context of an asynchronous callback (i.e: the asyncDepth is not 0).


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