Colobot
Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | Static Protected Attributes | Friends | List of all members
CBot::CBotInstr Class Referenceabstract

Class for one CBot instruction. More...

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

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

Public Member Functions

 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...
 
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...
 
virtual bool HasReturn ()
 Check a list of instructions for a return statement. More...
 

Static Public Member Functions

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

Protected Attributes

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

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

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:

dot_inline_dotgraph_1.png
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]pToken to start at, updated to point at the next token
    pStackCompilation 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() [2/2]

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

Execute.

Parameters
pj
pVar
Returns

Reimplemented in CBot::CBotListArray.

◆ RestoreState()

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

◆ ExecuteVar() [1/2]

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

ExecuteVar.

Parameters
pVar
pile
Returns

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

◆ 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::CBotInstrMethode, CBot::CBotIndexExpr, and CBot::CBotFieldExpr.

◆ RestoreStateVar()

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

RestoreStateVar.

Parameters
pile
bMain

Reimplemented in CBot::CBotInstrMethode, CBot::CBotIndexExpr, CBot::CBotFieldExpr, CBot::CBotExprVar, 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::CBotReturn, CBot::CBotListInstr, CBot::CBotIf, and CBot::CBotFunction.

◆ GetDebugName()

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

◆ GetDebugData()

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

◆ GetDebugLinks()

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

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
staticprotected

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


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