Colobot
Public Member Functions | Static Public Member Functions | Protected Member Functions | Friends | List of all members
CBot::CBotFunction Class Reference

A function declaration in the code. More...

#include <src/CBot/CBotInstr/CBotFunction.h>

Inheritance diagram for CBot::CBotFunction:
Inheritance graph
[legend]

Public Member Functions

bool Execute (CBotVar **ppVars, CBotStack *&pj, CBotVar *pInstance=nullptr)
 Execute. More...
 
void RestoreState (CBotVar **ppVars, CBotStack *&pj, CBotVar *pInstance=nullptr)
 RestoreState. More...
 
bool CheckParam (CBotDefParam *pParam)
 CheckParam See if the "signature" of parameters is identical. More...
 
const std::string & GetName ()
 GetName. More...
 
std::string GetParams ()
 GetParams. More...
 
bool IsPublic ()
 IsPublic. More...
 
bool IsExtern ()
 IsExtern. More...
 
bool GetPosition (int &start, int &stop, CBotGet modestart, CBotGet modestop)
 GetPosition. More...
 
bool HasReturn () override
 Check if the function has a return statment that will execute. More...
 
- Public Member Functions inherited from CBot::CBotInstr
 CBotInstr ()
 Constructor. More...
 
virtual ~CBotInstr ()
 Destructor. More...
 
virtual bool Execute (CBotStack *&pj)
 Execute. More...
 
virtual bool Execute (CBotStack *&pj, CBotVar *pVar)
 Execute. More...
 
virtual void RestoreState (CBotStack *&pj, bool bMain)
 RestoreState. More...
 
virtual bool ExecuteVar (CBotVar *&pVar, CBotCStack *&pile)
 ExecuteVar. More...
 
virtual bool ExecuteVar (CBotVar *&pVar, CBotStack *&pile, CBotToken *prevToken, bool bStep, bool bExtend)
 ExecuteVar. More...
 
virtual void RestoreStateVar (CBotStack *&pile, bool bMain)
 RestoreStateVar. More...
 
virtual bool CompCase (CBotStack *&pj, int val)
 CompCase This routine is defined only for the subclass CBotCase this allows to make the call on all instructions CompCase to see if it's a case to the desired value.. More...
 
void SetToken (CBotToken *p)
 SetToken Set the token corresponding to the instruction. More...
 
int GetTokenType ()
 GetTokenType Return the type of the token assicated with the instruction. More...
 
CBotTokenGetToken ()
 GetToken Return associated token. More...
 
void AddNext (CBotInstr *n)
 AddNext Adds the statement following the other. More...
 
CBotInstrGetNext ()
 GetNext Returns next statement. More...
 
void AddNext3 (CBotInstr *n)
 AddNext3. More...
 
CBotInstrGetNext3 ()
 GetNext3. More...
 
void AddNext3b (CBotInstr *n)
 AddNext3b. More...
 
CBotInstrGetNext3b ()
 GetNext3b. More...
 

Static Public Member Functions

static CBotFunctionCompile (CBotToken *&p, CBotCStack *pStack, CBotFunction *pFunc, bool bLocal=true)
 Compile Compiles a new function. More...
 
static CBotFunctionCompile1 (CBotToken *&p, CBotCStack *pStack, CBotClass *pClass)
 Pre-compile a new function. More...
 
static CBotTypResult CompileCall (const std::list< CBotFunction *> &localFunctionList, const std::string &name, CBotVar **ppVars, long &nIdent)
 Compile a function call. More...
 
static CBotFunctionFindLocalOrPublic (const std::list< CBotFunction *> &localFunctionList, long &nIdent, const std::string &name, CBotVar **ppVars, CBotTypResult &TypeOrError, bool bPublic=true)
 Finds a local or public function. More...
 
static int DoCall (CBotProgram *program, const std::list< CBotFunction *> &localFunctionList, long &nIdent, const std::string &name, CBotVar **ppVars, CBotStack *pStack, CBotToken *pToken)
 DoCall Fait un appel à une fonction. More...
 
static void RestoreCall (const std::list< CBotFunction *> &localFunctionList, long &nIdent, const std::string &name, CBotVar **ppVars, CBotStack *pStack)
 RestoreCall. More...
 
static int DoCall (const std::list< CBotFunction *> &localFunctionList, long &nIdent, const std::string &name, CBotVar *pThis, CBotVar **ppVars, CBotStack *pStack, CBotToken *pToken, CBotClass *pClass)
 DoCall Makes call of a method note: this is already on the stack, the pointer pThis is just to simplify. More...
 
static bool RestoreCall (const std::list< CBotFunction *> &localFunctionList, long &nIdent, const std::string &name, CBotVar *pThis, CBotVar **ppVars, CBotStack *pStack, CBotClass *pClass)
 RestoreCall. More...
 
static void AddPublic (CBotFunction *pfunc)
 AddPublic. More...
 
- Static Public Member Functions inherited from CBot::CBotInstr
static CBotInstrCompile (CBotToken *&p, CBotCStack *pStack)
 Compile an instruction. More...
 
static CBotInstrCompileArray (CBotToken *&p, CBotCStack *pStack, CBotTypResult type, bool first=true)
 CompileArray. More...
 
static void IncLvl (std::string &label)
 IncLvl Adds a level with a label. More...
 
static void IncLvl ()
 IncLvl Adds a level (switch statement). More...
 
static void DecLvl ()
 DecLvl Free a level. More...
 
static bool ChkLvl (const std::string &label, int type)
 ChkLvl Control validity of break and continue. More...
 

Protected Member Functions

virtual const std::string GetDebugName () override
 Returns the name of this class. More...
 
virtual std::string GetDebugData () override
 Returns additional data associated with this instruction for debugging purposes. More...
 
virtual std::map< std::string, CBotInstr * > GetDebugLinks () override
 

Friends

class CBotDebug
 
class CBotProgram
 
class CBotClass
 
class CBotCStack
 

Additional Inherited Members

- Protected Attributes inherited from CBot::CBotInstr
CBotToken m_token
 Keeps the token. More...
 
CBotInstrm_next
 Linked command. More...
 
CBotInstrm_next2b
 Second list definition chain. More...
 
CBotInstrm_next3
 Third list for indices and fields. More...
 
CBotInstrm_next3b
 Necessary for reporting tables. More...
 
- Static Protected Attributes inherited from CBot::CBotInstr
static int m_LoopLvl = 0
 Counter of nested loops, to determine the break and continue valid. More...
 

Detailed Description

A function declaration in the code.

Examples:

void test() { ... }
void test(int a, float b) { ... }
int test(int a, float b, string c) { ... }
public bool test(int a, float b, string c, SomeClass d) { ... }
extern void test() { ... }
void classname::test() { ... }

Member Function Documentation

◆ Compile()

CBotFunction * CBot::CBotFunction::Compile ( CBotToken *&  p,
CBotCStack pStack,
CBotFunction pFunc,
bool  bLocal = true 
)
static

Compile Compiles a new function.

Parameters
p
pStack
pFunc
bLocalallows of the declaration of parameters on the same level as the elements belonging to the class for methods.
Returns

◆ Compile1()

CBotFunction * CBot::CBotFunction::Compile1 ( CBotToken *&  p,
CBotCStack pStack,
CBotClass pClass 
)
static

Pre-compile a new function.

Parameters
p[in,out]Pointer to first token of the function, will be updated to point to first token after the function definition
pStackCompile stack
pClassIf this is a class method, pointer to class this function is part of, otherwise nullptr

This function is used to find the beginning and end of function definition.

If any errors in the code are detected, this function will set the error on compile stack and return nullptr.

Returns
Precompiled function, or nullptr in case of error

◆ Execute()

bool CBot::CBotFunction::Execute ( CBotVar **  ppVars,
CBotStack *&  pj,
CBotVar pInstance = nullptr 
)

Execute.

Parameters
ppVars
pj
pInstance
Returns

◆ RestoreState()

void CBot::CBotFunction::RestoreState ( CBotVar **  ppVars,
CBotStack *&  pj,
CBotVar pInstance = nullptr 
)

RestoreState.

Parameters
ppVars
pj
pInstance

◆ CompileCall()

CBotTypResult CBot::CBotFunction::CompileCall ( const std::list< CBotFunction *> &  localFunctionList,
const std::string &  name,
CBotVar **  ppVars,
long &  nIdent 
)
static

Compile a function call.

See FindLocalOrPublic for more detailed explanation

Parameters
localFunctionListLinked list of local functions to search in, can be null
nameName of the function
ppVarsList of function arguments
nIdent[in,out]Unique identifier of the function
Returns
Type returned by the function or error code
See also
FindLocalOrPublic

◆ FindLocalOrPublic()

CBotFunction * CBot::CBotFunction::FindLocalOrPublic ( const std::list< CBotFunction *> &  localFunctionList,
long &  nIdent,
const std::string &  name,
CBotVar **  ppVars,
CBotTypResult TypeOrError,
bool  bPublic = true 
)
static

Finds a local or public function.

Finds a local or (if bPublic is true) public function to call

First, it looks for a function according to its unique identifier.
If the identifier is not found, looks by name and parameters.

Parameters
localFunctionListLinked list of local functions to search in, can be null
nIdent[in,out]Unique identifier of the function
nameName of the function
ppVarsList of function arguments
TypeOrErrorType returned by the function or error code
bPublicWhether to look in public functions or not
Returns
Pointer to found CBotFunction instance, or nullptr in case of no match or ambiguity (see TypeOrError for error code)

◆ DoCall() [1/2]

int CBot::CBotFunction::DoCall ( CBotProgram program,
const std::list< CBotFunction *> &  localFunctionList,
long &  nIdent,
const std::string &  name,
CBotVar **  ppVars,
CBotStack pStack,
CBotToken pToken 
)
static

DoCall Fait un appel à une fonction.

Parameters
program
localFunctionList
nIdent
name
ppVars
pStack
pToken
Returns

◆ RestoreCall() [1/2]

void CBot::CBotFunction::RestoreCall ( const std::list< CBotFunction *> &  localFunctionList,
long &  nIdent,
const std::string &  name,
CBotVar **  ppVars,
CBotStack pStack 
)
static

RestoreCall.

Parameters
localFunctionList
nIdent
name
ppVars
pStack

◆ DoCall() [2/2]

int CBot::CBotFunction::DoCall ( const std::list< CBotFunction *> &  localFunctionList,
long &  nIdent,
const std::string &  name,
CBotVar pThis,
CBotVar **  ppVars,
CBotStack pStack,
CBotToken pToken,
CBotClass pClass 
)
static

DoCall Makes call of a method note: this is already on the stack, the pointer pThis is just to simplify.

Parameters
localFunctionList
nIdent
name
pThis
ppVars
pStack
pToken
pClass
Returns

◆ RestoreCall() [2/2]

bool CBot::CBotFunction::RestoreCall ( const std::list< CBotFunction *> &  localFunctionList,
long &  nIdent,
const std::string &  name,
CBotVar pThis,
CBotVar **  ppVars,
CBotStack pStack,
CBotClass pClass 
)
static

RestoreCall.

Parameters
localFunctionList
nIdent
name
pThis
ppVars
pStack
pClass
Returns
Returns true if the method call was restored.

◆ CheckParam()

bool CBot::CBotFunction::CheckParam ( CBotDefParam pParam)

CheckParam See if the "signature" of parameters is identical.

Parameters
pParam
Returns

◆ AddPublic()

void CBot::CBotFunction::AddPublic ( CBotFunction pfunc)
static

AddPublic.

Parameters
pfunc

◆ GetName()

const std::string & CBot::CBotFunction::GetName ( )

GetName.

Returns

◆ GetParams()

std::string CBot::CBotFunction::GetParams ( )

GetParams.

Returns

◆ IsPublic()

bool CBot::CBotFunction::IsPublic ( )

IsPublic.

Returns

◆ IsExtern()

bool CBot::CBotFunction::IsExtern ( )

IsExtern.

Returns

◆ GetPosition()

bool CBot::CBotFunction::GetPosition ( int &  start,
int &  stop,
CBotGet  modestart,
CBotGet  modestop 
)

GetPosition.

Parameters
start
stop
modestart
modestop
Returns

◆ HasReturn()

bool CBot::CBotFunction::HasReturn ( )
overridevirtual

Check if the function has a return statment that will execute.

Returns
true if a return statment was found.

Reimplemented from CBot::CBotInstr.

◆ GetDebugName()

virtual const std::string CBot::CBotFunction::GetDebugName ( )
inlineoverrideprotectedvirtual

Returns the name of this class.

See also
CBotDebug

Implements CBot::CBotInstr.

◆ GetDebugData()

std::string CBot::CBotFunction::GetDebugData ( )
overrideprotectedvirtual

Returns additional data associated with this instruction for debugging purposes.

See also
CBotDebug

Reimplemented from CBot::CBotInstr.

◆ GetDebugLinks()

std::map< std::string, CBotInstr * > CBot::CBotFunction::GetDebugLinks ( )
overrideprotectedvirtual

Returns a map of all instructions connected with this one

See also
CBotDebug

Reimplemented from CBot::CBotInstr.


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