Loading...
Searching...
No Matches
CBot::CBotFunction Class Reference

A function declaration in the code. More...

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

Inheritance diagram for CBot::CBotFunction:
[legend]

## Public Member Functions

bool | Execute (CBotVar **ppVars, CBotStack *&pj, CBotVar *pInstance=nullptr)
| Execute.
void | RestoreState (CBotVar **ppVars, CBotStack *&pj, CBotVar *pInstance=nullptr)
| RestoreState.
bool | CheckParam (CBotDefParam *pParam)
| CheckParam See if the "signature" of parameters is identical.
const std::string & | GetName ()
| GetName.
std::string | GetParams ()
| GetParams.
const std::string & | GetClassName () const
| Get the name of the class for a method.
bool | IsPublic ()
| IsPublic.
bool | IsProtected () const
| Check if a method is protected.
bool | IsPrivate () const
| Check if a method is private.
bool | IsExtern ()
| IsExtern.
bool | GetPosition (int &start, int &stop, CBotGet modestart, CBotGet modestop)
| GetPosition.
bool | HasReturn () override
| Check if the function has a return statment that will execute.
virtual bool | Execute (CBotStack *&pj)
| Execute.
virtual bool | Execute (CBotStack *&pj, CBotVar *pVar)
| Execute.
virtual void | RestoreState (CBotStack *&pj, bool bMain)
| RestoreState.
Public Member Functions inherited from CBot::CBotInstr
| CBotInstr ()
| Constructor.
virtual | ~CBotInstr ()
| Destructor.
virtual bool | ExecuteVar (CBotVar *&pVar, CBotCStack *&pile)
| ExecuteVar.
virtual bool | ExecuteVar (CBotVar *&pVar, CBotStack *&pile, CBotToken *prevToken, bool bStep, bool bExtend)
| ExecuteVar.
virtual void | RestoreStateVar (CBotStack *&pile, bool bMain)
| RestoreStateVar.
void | SetToken (CBotToken *p)
| SetToken Set the token corresponding to the instruction.
int | GetTokenType ()
| GetTokenType Return the type of the token assicated with the instruction.
CBotToken * | GetToken ()
| GetToken Return associated token.
void | AddNext (CBotInstr *n)
| AddNext Adds the statement following the other.
CBotInstr * | GetNext ()
| GetNext Returns next statement.
void | AddNext3 (CBotInstr *n)
| AddNext3.
CBotInstr * | GetNext3 ()
| GetNext3.
void | AddNext3b (CBotInstr *n)
| AddNext3b.
CBotInstr * | GetNext3b ()
| GetNext3b.

## Static Public Member Functions

static CBotFunction * | Compile (CBotToken *&p, CBotCStack *pStack, CBotFunction *pFunc, bool bLocal=true)
| Compile Compiles a new function.
static CBotFunction * | Compile1 (CBotToken *&p, CBotCStack *pStack, CBotClass *pClass)
| Pre-compile a new function.
static CBotTypResult | CompileCall (const std::string &name, CBotVar **ppVars, long &nIdent, CBotProgram *program)
| Compile a function call.
static CBotFunction * | FindLocalOrPublic (const std::list< CBotFunction * > &localFunctionList, long &nIdent, const std::string &name, CBotVar **ppVars, CBotTypResult &TypeOrError, CBotProgram *baseProg)
| Finds a local or public function.
static void | SearchList (const std::list< CBotFunction * > &functionList, const std::string &name, CBotVar **ppVars, CBotTypResult &TypeOrError, std::map< CBotFunction *, int > &funcMap, CBotClass *pClass=nullptr)
| Find all functions that match the name and arguments.
static void | SearchPublic (const std::string &name, CBotVar **ppVars, CBotTypResult &TypeOrError, std::map< CBotFunction *, int > &funcMap, CBotClass *pClass=nullptr)
| Find all public functions that match the name and arguments.
static CBotFunction * | BestFunction (std::map< CBotFunction *, int > &funcMap, long &nIdent, CBotTypResult &TypeOrError)
| Find the function with the lowest signature value. If there is more than one of the same signature value, TypeOrError is set to CBotErrAmbiguousCall.
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.
static void | RestoreCall (const std::list< CBotFunction * > &localFunctionList, long &nIdent, const std::string &name, CBotVar **ppVars, CBotStack *pStack)
| RestoreCall.
static CBotTypResult | CompileMethodCall (const std::string &name, CBotVar **ppVars, long &nIdent, CBotCStack *pStack, CBotClass *pClass)
| Find a method matching the name and arguments.
static CBotFunction * | FindMethod (long &nIdent, const std::string &name, CBotVar **ppVars, CBotTypResult &TypeOrError, CBotClass *pClass, CBotProgram *program)
| Find a method by its unique identifier or by name and parameters.
static int | DoCall (long &nIdent, const std::string &name, CBotVar *pThis, CBotVar **ppVars, CBotStack *pStack, CBotToken *pToken, CBotClass *pClass)
| DoCall Makes call of a method.
static bool | RestoreCall (long &nIdent, const std::string &name, CBotVar *pThis, CBotVar **ppVars, CBotStack *pStack, CBotClass *pClass)
| RestoreCall.
static void | AddPublic (CBotFunction *pfunc)
| AddPublic.
Static Public Member Functions inherited from CBot::CBotInstr
static CBotInstr * | Compile (CBotToken *&p, CBotCStack *pStack)
| Compile an instruction.
static CBotInstr * | CompileArray (CBotToken *&p, CBotCStack *pStack, CBotTypResult type, bool first=true)
| CompileArray.
static void | IncLvl (std::string &label)
| IncLvl Adds a level with a label.
static void | IncLvl ()
| IncLvl Adds a level (switch statement).
static void | DecLvl ()
| DecLvl Free a level.
static bool | ChkLvl (const std::string &label, int type)
| ChkLvl Control validity of break and continue.

## Protected Member Functions

virtual const std::string | GetDebugName () override
| Returns the name of this class.
virtual std::string | GetDebugData () override
| Returns additional data associated with this instruction for debugging purposes.
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.
CBotInstr * | m_next
| Linked command.
CBotInstr * | m_next2b
| Second list definition chain.
CBotInstr * | m_next3
| Third list for indices and fields.
CBotInstr * | m_next3b
| Necessary for reporting tables.
Static Protected Attributes inherited from CBot::CBotInstr
static int | m_LoopLvl = 0
| Counter of nested loops, to determine the break and continue valid.

## 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 |
  bLocal | allows 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
  pStack | Compile stack
  pClass | If 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() [1/3]

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

Execute.

Parameters

  ppVars |
  pj |
  pInstance |

Returns

## RestoreState() [1/2]

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

RestoreState.

Parameters

  ppVars |
  pj |
  pInstance |

## CompileCall()

CBotTypResult CBot::CBotFunction::CompileCall | ( | const std::string & | name,
|  | CBotVar ** | ppVars,
|  | long & | nIdent,
|  | CBotProgram * | program )

static

Compile a function call.

See FindLocalOrPublic for more detailed explanation

Parameters

  name | Name of the function
  ppVars | List of function arguments
  nIdent[in,out] | Unique identifier of the function
  program | The current program, to search for functions.

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,
|  | CBotProgram * | baseProg )

static

Finds a local or public function.

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

Parameters

  localFunctionList | Linked list of local functions to search in, can be null
  nIdent[in,out] | Unique identifier of the function
  name | Name of the function
  ppVars | List of function arguments
  TypeOrError | Type returned by the function or error code
  baseProg | Initial program, for context of the object/bot

Returns
  Pointer to found CBotFunction instance, or nullptr in case of no match or ambiguity (see TypeOrError for error code)

## SearchList()

void CBot::CBotFunction::SearchList | ( | const std::list< CBotFunction * > & | functionList,
|  | const std::string & | name,
|  | CBotVar ** | ppVars,
|  | CBotTypResult & | TypeOrError,
|  | std::map< CBotFunction *, int > & | funcMap,
|  | CBotClass * | pClass = nullptr )

static

Find all functions that match the name and arguments.

Parameters

  functionList | List of functions to search, can be empty.
  name | Name of the function to find.
  ppVars | Arguments to compare with parameters.
  TypeOrError | Contains a CBotError when no useable function has been found.
  funcMap | Container for suitable functions and their signature values.
  pClass | Pointer to class when searching for methods.

## SearchPublic()

void CBot::CBotFunction::SearchPublic | ( | const std::string & | name,
|  | CBotVar ** | ppVars,
|  | CBotTypResult & | TypeOrError,
|  | std::map< CBotFunction *, int > & | funcMap,
|  | CBotClass * | pClass = nullptr )

static

Find all public functions that match the name and arguments.

Parameters

  name | Name of the function to find.
  ppVars | Arguments to compare with parameters.
  TypeOrError | Contains a CBotError when no useable function has been found.
  funcMap | Container for suitable functions and their signature values.
  pClass | Pointer to class when searching for methods.

## BestFunction()

CBotFunction * CBot::CBotFunction::BestFunction | ( | std::map< CBotFunction *, int > & | funcMap,
|  | long & | nIdent,
|  | CBotTypResult & | TypeOrError )

static

Find the function with the lowest signature value. If there is more than one of the same signature value, TypeOrError is set to CBotErrAmbiguousCall.

Parameters

  | funcMap | List of functions and their signature values, can be empty.
  [out] | nIdent | Unique identifier of the function.
  | TypeOrError | Type returned by the function or error code.

Returns
  Pointer to the function with the lowest signature or nullptr.

## 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 |

## CompileMethodCall()

CBotTypResult CBot::CBotFunction::CompileMethodCall | ( | const std::string & | name,
|  | CBotVar ** | ppVars,
|  | long & | nIdent,
|  | CBotCStack * | pStack,
|  | CBotClass * | pClass )

static

Find a method matching the name and arguments.

Parameters

  | name | Name of the method to find.
  | ppVars | Arguments to compare with parameters.
  [out] | nIdent | Unique identifier of the method.
  | pStack | Current compilation stack frame.
  | pClass | Pointer to the class.

Returns
  The return type for the method or a CBotError.

## FindMethod()

CBotFunction * CBot::CBotFunction::FindMethod | ( | long & | nIdent,
|  | const std::string & | name,
|  | CBotVar ** | ppVars,
|  | CBotTypResult & | TypeOrError,
|  | CBotClass * | pClass,
|  | CBotProgram * | program )

static

Find a method by its unique identifier or by name and parameters.

Parameters

  [in,out] | nIdent | Unique identifier of the method.
  | name | Name of the method to find.
  | ppVars | Arguments to compare with parameters.
  | TypeOrError | The return type for the method or a CBotError.
  | pClass | Pointer to the class.
  | program | The current program, to search for out-of-class methods.

Returns
  Pointer to the method that best matches the given arguments or nullptr.

## DoCall() [2/2]

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

static

DoCall Makes call of a method.

Parameters

  nIdent |
  name |
  pThis |
  ppVars |
  pStack |
  pToken |
  pClass |

Returns

## RestoreCall() [2/2]

bool CBot::CBotFunction::RestoreCall | ( | long & | nIdent,
|  | const std::string & | name,
|  | CBotVar * | pThis,
|  | CBotVar ** | ppVars,
|  | CBotStack * | pStack,
|  | CBotClass * | pClass )

static

RestoreCall.

Parameters

  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

## GetClassName()

const std::string & CBot::CBotFunction::GetClassName | ( |  | ) | const

Get the name of the class for a method.

Returns
  The name of a class or empty string if it's not a method.

## IsPublic()

bool CBot::CBotFunction::IsPublic | ( |  | ) |

IsPublic.

Returns

## IsProtected()

bool CBot::CBotFunction::IsProtected | ( |  | ) | const

Check if a method is protected.

Returns
  true if a method was compiled with "protected" keyword.

## IsPrivate()

bool CBot::CBotFunction::IsPrivate | ( |  | ) | const

Check if a method is private.

Returns
  true if a method was compiled with "private" keyword.

## 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 | ( |  | ) |

override virtual

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 | ( |  | ) |

inline override protected virtual

Returns the name of this class.

See also
  CBotDebug

Implements CBot::CBotInstr.

## GetDebugData()

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

override protected virtual

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 | ( |  | ) |

override protected virtual

Returns a map of all instructions connected with this one

See also
  CBotDebug

Reimplemented from CBot::CBotInstr.

## Execute() [2/3]

bool CBot::CBotInstr::Execute | ( | CBotStack *& | pj | ) |

virtual

Execute.

Parameters

  pj |

Returns

Reimplemented from CBot::CBotInstr.

## Execute() [3/3]

bool CBot::CBotInstr::Execute | ( | CBotStack *& | pj,
|  | CBotVar * | pVar )

virtual

Execute.

Parameters

  pj |
  pVar |

Returns

Reimplemented from CBot::CBotInstr.

## RestoreState() [2/2]

void CBot::CBotInstr::RestoreState | ( | CBotStack *& | pj,
|  | bool | bMain )

virtual

RestoreState.

Parameters

  pj |
  bMain |

Reimplemented from CBot::CBotInstr.

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

- src/CBot/CBotInstr/CBotFunction.h
- src/CBot/CBotInstr/CBotFunction.cpp