Loading...
Searching...
No Matches
CBot::CBotInstr Class Referenceabstract

Class for one CBot instruction. More...

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

Inheritance diagram for CBot::CBotInstr:
[legend]

## Public Member Functions

| CBotInstr ()
| Constructor.
virtual | ~CBotInstr ()
| Destructor.
virtual bool | Execute (CBotStack *&pj)
| Execute.
virtual bool | Execute (CBotStack *&pj, CBotVar *pVar)
| Execute.
virtual void | RestoreState (CBotStack *&pj, bool bMain)
| RestoreState.
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.
virtual bool | HasReturn ()
| Check a list of instructions for a return statement.

## Static Public Member Functions

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 ()=0
| Returns the name of this class.
virtual std::string | GetDebugData ()
| Returns additional data associated with this instruction for debugging purposes.
virtual std::map< std::string, CBotInstr * > | GetDebugLinks ()

## Protected Attributes

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

static int | m_LoopLvl = 0
| Counter of nested loops, to determine the break and continue valid.

## Friends

class | CBotDebug
class | CBotDefClass
class | CBotDefInt
class | CBotListArray

## Detailed Description

Class for one CBot instruction.

For example, for program:

int x[]; x[1] = 4;
int y[x[1]][10], z;

the following structure is generated:

Todo
  More documentation

## Constructor & Destructor Documentation

## CBotInstr()

CBot::CBotInstr::CBotInstr | ( |  | ) |

Constructor.

## ~CBotInstr()

CBot::CBotInstr::~CBotInstr | ( |  | ) |

virtual

Destructor.

## Member Function Documentation

## Compile()

CBotInstr * CBot::CBotInstr::Compile | ( | CBotToken *& | p,
|  | CBotCStack * | pStack )

static

Compile an instruction.

Supported instructions are:

- while
- do
- try
- throw
- if
- for
- switch
- break
- continue
- return
- int
- float
- boolean
- string
- declaration of an instance of a class
- arithmetic expression (with or without assigment)
  Parameters

    [in,out] | p | Token to start at, updated to point at the next token
    | pStack | Compilation stack

  Returns
    Compiled instruction

## CompileArray()

CBotInstr * CBot::CBotInstr::CompileArray | ( | CBotToken *& | p,
|  | CBotCStack * | pStack,
|  | CBotTypResult | type,
|  | bool | first = true )

static

CompileArray.

Parameters

  p |
  pStack |
  type |
  first |

Returns

## Execute() [1/2]

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

virtual

Execute.

Parameters

  pj |

Returns

Reimplemented in CBot::CBotBreak, CBot::CBotCase, CBot::CBotCatch, CBot::CBotDefArray, CBot::CBotDefBoolean, CBot::CBotDefClass, CBot::CBotDefFloat, CBot::CBotDefInt, CBot::CBotDefString, CBot::CBotDo, CBot::CBotExpression, CBot::CBotExprLitBool, CBot::CBotExprLitChar, CBot::CBotExprLitNan, CBot::CBotExprLitNull, CBot::CBotExprLitNum< T >, CBot::CBotExprLitString, CBot::CBotExprRetVar, CBot::CBotExprUnaire, CBot::CBotExprVar, CBot::CBotFor, CBot::CBotFunction, CBot::CBotIf, CBot::CBotInstrCall, CBot::CBotInstrMethode, CBot::CBotLeftExpr, CBot::CBotLeftExprVar, CBot::CBotListExpression, CBot::CBotListInstr, CBot::CBotLogicExpr, CBot::CBotNew, CBot::CBotPostIncExpr, CBot::CBotPreIncExpr, CBot::CBotRepeat, CBot::CBotReturn, CBot::CBotSwitch, CBot::CBotThrow, CBot::CBotTry, CBot::CBotTwoOpExpr, and CBot::CBotWhile.

## Execute() [2/2]

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

virtual

Execute.

Parameters

  pj |
  pVar |

Returns

Reimplemented in CBot::CBotFunction, CBot::CBotLeftExpr, and CBot::CBotListArray.

## RestoreState()

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

virtual

RestoreState.

Parameters

  pj |
  bMain |

Reimplemented in CBot::CBotBreak, CBot::CBotCase, CBot::CBotCatch, CBot::CBotDefArray, CBot::CBotDefBoolean, CBot::CBotDefClass, CBot::CBotDefFloat, CBot::CBotDefInt, CBot::CBotDefString, CBot::CBotDo, CBot::CBotExpression, CBot::CBotExprLitBool, CBot::CBotExprLitChar, CBot::CBotExprLitNan, CBot::CBotExprLitNull, CBot::CBotExprLitNum< T >, CBot::CBotExprLitString, CBot::CBotExprRetVar, CBot::CBotExprUnaire, CBot::CBotExprVar, CBot::CBotFor, CBot::CBotFunction, CBot::CBotIf, CBot::CBotInstrCall, CBot::CBotLeftExprVar, CBot::CBotListArray, CBot::CBotListExpression, CBot::CBotListInstr, CBot::CBotLogicExpr, CBot::CBotNew, CBot::CBotPostIncExpr, CBot::CBotPreIncExpr, CBot::CBotRepeat, CBot::CBotReturn, CBot::CBotSwitch, CBot::CBotThrow, CBot::CBotTry, CBot::CBotTwoOpExpr, and CBot::CBotWhile.

## ExecuteVar() [1/2]

bool CBot::CBotInstr::ExecuteVar | ( | CBotVar *& | pVar,
|  | CBotCStack *& | pile )

virtual

ExecuteVar.

Parameters

  pVar |
  pile |

Returns

Reimplemented in CBot::CBotExprVar, CBot::CBotFieldExpr, CBot::CBotIndexExpr, and CBot::CBotLeftExpr.

## ExecuteVar() [2/2]

bool CBot::CBotInstr::ExecuteVar | ( | CBotVar *& | pVar,
|  | CBotStack *& | pile,
|  | CBotToken * | prevToken,
|  | bool | bStep,
|  | bool | bExtend )

virtual

ExecuteVar.

Parameters

  pVar |
  pile |
  prevToken |
  bStep |
  bExtend |

Returns

Reimplemented in CBot::CBotExprVar, CBot::CBotFieldExpr, CBot::CBotIndexExpr, CBot::CBotInstrMethode, and CBot::CBotLeftExpr.

## RestoreStateVar()

void CBot::CBotInstr::RestoreStateVar | ( | CBotStack *& | pile,
|  | bool | bMain )

virtual

RestoreStateVar.

Parameters

  pile |
  bMain |

Reimplemented in CBot::CBotExprVar, CBot::CBotFieldExpr, CBot::CBotIndexExpr, CBot::CBotInstrMethode, and CBot::CBotLeftExpr.

## SetToken()

void CBot::CBotInstr::SetToken | ( | CBotToken * | p | ) |

SetToken Set the token corresponding to the instruction.

Parameters

  p |

## GetTokenType()

int CBot::CBotInstr::GetTokenType | ( |  | ) |

GetTokenType Return the type of the token assicated with the instruction.

Returns

## GetToken()

CBotToken * CBot::CBotInstr::GetToken | ( |  | ) |

GetToken Return associated token.

Returns

## AddNext()

void CBot::CBotInstr::AddNext | ( | CBotInstr * | n | ) |

AddNext Adds the statement following the other.

Parameters

  n |

## GetNext()

CBotInstr * CBot::CBotInstr::GetNext | ( |  | ) |

GetNext Returns next statement.

Returns

## AddNext3()

void CBot::CBotInstr::AddNext3 | ( | CBotInstr * | n | ) |

AddNext3.

Parameters

  n |

## GetNext3()

CBotInstr * CBot::CBotInstr::GetNext3 | ( |  | ) |

GetNext3.

Returns

## AddNext3b()

void CBot::CBotInstr::AddNext3b | ( | CBotInstr * | n | ) |

AddNext3b.

Parameters

  n |

## GetNext3b()

CBotInstr * CBot::CBotInstr::GetNext3b | ( |  | ) |

GetNext3b.

Returns

## IncLvl() [1/2]

void CBot::CBotInstr::IncLvl | ( | std::string & | label | ) |

static

IncLvl Adds a level with a label.

Parameters

  label |

## IncLvl() [2/2]

void CBot::CBotInstr::IncLvl | ( |  | ) |

static

IncLvl Adds a level (switch statement).

## DecLvl()

void CBot::CBotInstr::DecLvl | ( |  | ) |

static

DecLvl Free a level.

## ChkLvl()

bool CBot::CBotInstr::ChkLvl | ( | const std::string & | label,
|  | int | type )

static

ChkLvl Control validity of break and continue.

Parameters

  label |
  type |

Returns

## HasReturn()

bool CBot::CBotInstr::HasReturn | ( |  | ) |

virtual

Check a list of instructions for a return statement.

Returns
  true if a return statement was found.

Reimplemented in CBot::CBotFunction, CBot::CBotIf, CBot::CBotListInstr, and CBot::CBotReturn.

## GetDebugName()

virtual const std::string CBot::CBotInstr::GetDebugName | ( |  | ) |

protected pure virtual

Returns the name of this class.

See also
  CBotDebug

Implemented in CBot::CBotBreak, CBot::CBotCase, CBot::CBotCatch, CBot::CBotDefArray, CBot::CBotDefBoolean, CBot::CBotDefClass, CBot::CBotDefFloat, CBot::CBotDefInt, CBot::CBotDefString, CBot::CBotDo, CBot::CBotEmpty, CBot::CBotExpression, CBot::CBotExprLitBool, CBot::CBotExprLitChar, CBot::CBotExprLitNan, CBot::CBotExprLitNull, CBot::CBotExprLitNum< T >, CBot::CBotExprLitString, CBot::CBotExprRetVar, CBot::CBotExprUnaire, CBot::CBotExprVar, CBot::CBotFieldExpr, CBot::CBotFor, CBot::CBotFunction, CBot::CBotIf, CBot::CBotIndexExpr, CBot::CBotInstrCall, CBot::CBotInstrMethode, CBot::CBotLeftExpr, CBot::CBotLeftExprVar, CBot::CBotListArray, CBot::CBotListExpression, CBot::CBotListInstr, CBot::CBotLogicExpr, CBot::CBotNew, CBot::CBotPostIncExpr, CBot::CBotPreIncExpr, CBot::CBotRepeat, CBot::CBotReturn, CBot::CBotSwitch, CBot::CBotThrow, CBot::CBotTry, CBot::CBotTwoOpExpr, and CBot::CBotWhile.

## GetDebugData()

virtual std::string CBot::CBotInstr::GetDebugData | ( |  | ) |

inline protected virtual

Returns additional data associated with this instruction for debugging purposes.

See also
  CBotDebug

Reimplemented in CBot::CBotBreak, CBot::CBotDefArray, CBot::CBotDo, CBot::CBotExprLitChar, CBot::CBotExprLitNan, CBot::CBotExprLitNull, CBot::CBotExprLitNum< T >, CBot::CBotExprLitString, CBot::CBotExprRetVar, CBot::CBotExprVar, CBot::CBotFieldExpr, CBot::CBotFor, CBot::CBotFunction, CBot::CBotInstrCall, CBot::CBotInstrMethode, CBot::CBotLeftExpr, CBot::CBotLeftExprVar, CBot::CBotNew, CBot::CBotRepeat, CBot::CBotTwoOpExpr, and CBot::CBotWhile.

## GetDebugLinks()

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

protected virtual

Returns a map of all instructions connected with this one

See also
  CBotDebug

Reimplemented in CBot::CBotCase, CBot::CBotCatch, CBot::CBotDefArray, CBot::CBotDefBoolean, CBot::CBotDefClass, CBot::CBotDefFloat, CBot::CBotDefInt, CBot::CBotDefString, CBot::CBotDo, CBot::CBotExpression, CBot::CBotExprUnaire, CBot::CBotFor, CBot::CBotFunction, CBot::CBotIf, CBot::CBotIndexExpr, CBot::CBotInstrCall, CBot::CBotInstrMethode, CBot::CBotListArray, CBot::CBotListExpression, CBot::CBotListInstr, CBot::CBotLogicExpr, CBot::CBotNew, CBot::CBotPostIncExpr, CBot::CBotPreIncExpr, CBot::CBotRepeat, CBot::CBotReturn, CBot::CBotSwitch, CBot::CBotThrow, CBot::CBotTry, CBot::CBotTwoOpExpr, and CBot::CBotWhile.

## Member Data Documentation

## m_token

CBotToken CBot::CBotInstr::m_token

protected

Keeps the token.

## m_next

CBotInstr* CBot::CBotInstr::m_next

protected

Linked command.

## m_next2b

CBotInstr* CBot::CBotInstr::m_next2b

protected

Second list definition chain.

## m_next3

CBotInstr* CBot::CBotInstr::m_next3

protected

Third list for indices and fields.

## m_next3b

CBotInstr* CBot::CBotInstr::m_next3b

protected

Necessary for reporting tables.

## m_LoopLvl

int CBot::CBotInstr::m_LoopLvl = 0

static protected

Counter of nested loops, to determine the break and continue valid.

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

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