CBotVar::GetTypeMode enum
parent
d041a16a50
commit
40b7d986aa
|
@ -138,7 +138,7 @@ CBotError CBotCStack::GetError()
|
|||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
CBotTypResult CBotCStack::GetTypResult(int mode)
|
||||
CBotTypResult CBotCStack::GetTypResult(CBotVar::GetTypeMode mode)
|
||||
{
|
||||
if (m_var == nullptr)
|
||||
return CBotTypResult(99);
|
||||
|
@ -146,7 +146,7 @@ CBotTypResult CBotCStack::GetTypResult(int mode)
|
|||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
int CBotCStack::GetType(int mode)
|
||||
int CBotCStack::GetType(CBotVar::GetTypeMode mode)
|
||||
{
|
||||
if (m_var == nullptr)
|
||||
return 99;
|
||||
|
@ -158,7 +158,7 @@ CBotClass* CBotCStack::GetClass()
|
|||
{
|
||||
if ( m_var == nullptr )
|
||||
return nullptr;
|
||||
if ( m_var->GetType(1) != CBotTypPointer ) return nullptr;
|
||||
if ( m_var->GetType(CBotVar::GetTypeMode::CLASS_AS_POINTER) != CBotTypPointer ) return nullptr;
|
||||
|
||||
return m_var->GetClass();
|
||||
}
|
||||
|
@ -298,7 +298,7 @@ void CBotCStack::SetCopyVar( CBotVar* var )
|
|||
if (m_var) delete m_var; // replacement of a variable
|
||||
|
||||
if ( var == nullptr ) return;
|
||||
m_var = CBotVar::Create("", var->GetTypResult(2));
|
||||
m_var = CBotVar::Create("", var->GetTypResult(CBotVar::GetTypeMode::CLASS_AS_INTRINSIC));
|
||||
m_var->Copy( var );
|
||||
}
|
||||
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
#pragma once
|
||||
|
||||
// Modules inlcude
|
||||
#include <CBot/CBotVar/CBotVar.h>
|
||||
#include "CBot/CBotProgram.h"
|
||||
|
||||
// Local include
|
||||
|
@ -79,14 +80,14 @@ public:
|
|||
* \param mode
|
||||
* \return
|
||||
*/
|
||||
CBotTypResult GetTypResult(int mode = 0);
|
||||
CBotTypResult GetTypResult(CBotVar::GetTypeMode mode = CBotVar::GetTypeMode::NORMAL);
|
||||
|
||||
/*!
|
||||
* \brief GetType Gives the type of value on the stack.
|
||||
* \param mode
|
||||
* \return
|
||||
*/
|
||||
int GetType(int mode = 0);
|
||||
int GetType(CBotVar::GetTypeMode mode = CBotVar::GetTypeMode::NORMAL);
|
||||
|
||||
/*!
|
||||
* \brief GetClass Gives the class of the value on the stack.
|
||||
|
|
|
@ -174,8 +174,8 @@ CBotInstr* CBotClassInst::Compile(CBotToken* &p, CBotCStack* pStack, CBotClass*
|
|||
goto error;
|
||||
}
|
||||
CBotClass* result = pStk->GetClass();
|
||||
if ( !pStk->GetTypResult(1).Eq(CBotTypNullPointer) &&
|
||||
( !pStk->GetTypResult(1).Eq(CBotTypPointer) ||
|
||||
if ( !pStk->GetTypResult(CBotVar::GetTypeMode::CLASS_AS_POINTER).Eq(CBotTypNullPointer) &&
|
||||
( !pStk->GetTypResult(CBotVar::GetTypeMode::CLASS_AS_POINTER).Eq(CBotTypPointer) ||
|
||||
( result != nullptr && !pClass->IsChildOf(result) ))) // type compatible ?
|
||||
{
|
||||
pStk->SetError(CBotErrBadType1, p->GetStart());
|
||||
|
|
|
@ -115,7 +115,7 @@ CBotInstr* CBotExprVar::Compile(CBotToken*& p, CBotCStack* pStack, CBotVar::Prot
|
|||
continue;
|
||||
}
|
||||
}
|
||||
if (var->GetType(1) == CBotTypPointer) // for classes
|
||||
if (var->GetType(CBotVar::GetTypeMode::CLASS_AS_POINTER) == CBotTypPointer) // for classes
|
||||
{
|
||||
if (IsOfType(p, ID_DOT))
|
||||
{
|
||||
|
|
|
@ -196,7 +196,7 @@ bool CBotExpression::Execute(CBotStack* &pj)
|
|||
pile2->SetError(CBotErrNan, m_leftop->GetToken());
|
||||
return pj->Return(pile2);
|
||||
}
|
||||
result = CBotVar::Create("", pVar->GetTypResult(2));
|
||||
result = CBotVar::Create("", pVar->GetTypResult(CBotVar::GetTypeMode::CLASS_AS_INTRINSIC));
|
||||
}
|
||||
|
||||
switch (m_token.GetType())
|
||||
|
|
|
@ -52,7 +52,7 @@ void CBotFieldExpr::SetUniqNum(int num)
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
bool CBotFieldExpr::ExecuteVar(CBotVar* &pVar, CBotCStack* &pile)
|
||||
{
|
||||
if (pVar->GetType(1) != CBotTypPointer)
|
||||
if (pVar->GetType(CBotVar::GetTypeMode::CLASS_AS_POINTER) != CBotTypPointer)
|
||||
assert(0);
|
||||
|
||||
pVar = pVar->GetItemRef(m_nIdent);
|
||||
|
@ -76,7 +76,7 @@ bool CBotFieldExpr::ExecuteVar(CBotVar* &pVar, CBotStack* &pile, CBotToken* prev
|
|||
if (pile == EOX) return true;
|
||||
|
||||
|
||||
if (pVar->GetType(1) != CBotTypPointer)
|
||||
if (pVar->GetType(CBotVar::GetTypeMode::CLASS_AS_POINTER) != CBotTypPointer)
|
||||
assert(0);
|
||||
|
||||
CBotVarClass* pItem = pVar->GetPointer();
|
||||
|
|
|
@ -489,7 +489,7 @@ CBotFunction* CBotFunction::FindLocalOrPublic(long& nIdent, const std::string& n
|
|||
if ( pFunc == nullptr ) TypeOrError = CBotErrBadParam;
|
||||
break;
|
||||
}
|
||||
int d = pv->GetType() - pw->GetType(2);
|
||||
int d = pv->GetType() - pw->GetType(CBotVar::GetTypeMode::CLASS_AS_INTRINSIC);
|
||||
alpha += d>0 ? d : -10*d; // quality loss, 10 times more expensive!
|
||||
|
||||
pv = pv->GetNext();
|
||||
|
@ -544,7 +544,7 @@ CBotFunction* CBotFunction::FindLocalOrPublic(long& nIdent, const std::string& n
|
|||
if ( pFunc == nullptr ) TypeOrError = CBotErrBadParam;
|
||||
break;
|
||||
}
|
||||
int d = pv->GetType() - pw->GetType(2);
|
||||
int d = pv->GetType() - pw->GetType(CBotVar::GetTypeMode::CLASS_AS_INTRINSIC);
|
||||
alpha += d>0 ? d : -10*d; // quality loss, 10 times more expensive!
|
||||
|
||||
pv = pv->GetNext();
|
||||
|
|
|
@ -46,7 +46,7 @@ CBotIndexExpr::~CBotIndexExpr()
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
bool CBotIndexExpr::ExecuteVar(CBotVar* &pVar, CBotCStack* &pile)
|
||||
{
|
||||
if (pVar->GetType(1) != CBotTypArrayPointer)
|
||||
if (pVar->GetType(CBotVar::GetTypeMode::CLASS_AS_POINTER) != CBotTypArrayPointer)
|
||||
assert(0);
|
||||
|
||||
pVar = (static_cast<CBotVarArray*>(pVar))->GetItem(0, false); // at compile time makes the element [0]
|
||||
|
@ -64,7 +64,7 @@ bool CBotIndexExpr::ExecuteVar(CBotVar* &pVar, CBotStack* &pile, CBotToken* prev
|
|||
{
|
||||
CBotStack* pj = pile;
|
||||
|
||||
if (pVar->GetType(1) != CBotTypArrayPointer)
|
||||
if (pVar->GetType(CBotVar::GetTypeMode::CLASS_AS_POINTER) != CBotTypArrayPointer)
|
||||
assert(0);
|
||||
|
||||
pile = pile->AddStack();
|
||||
|
|
|
@ -116,7 +116,7 @@ CBotLeftExpr* CBotLeftExpr::Compile(CBotToken* &p, CBotCStack* pStack)
|
|||
}
|
||||
}
|
||||
|
||||
if (var->GetType(1) == CBotTypPointer) // for classes
|
||||
if (var->GetType(CBotVar::GetTypeMode::CLASS_AS_POINTER) == CBotTypPointer) // for classes
|
||||
{
|
||||
if (IsOfType(p, ID_DOT))
|
||||
{
|
||||
|
|
|
@ -67,7 +67,7 @@ CBotInstr* CBotReturn::Compile(CBotToken* &p, CBotCStack* pStack)
|
|||
inst->m_Instr = CBotExpression::Compile(p, pStack);
|
||||
if ( pStack->IsOk() )
|
||||
{
|
||||
CBotTypResult retType = pStack->GetTypResult(2);
|
||||
CBotTypResult retType = pStack->GetTypResult(CBotVar::GetTypeMode::CLASS_AS_INTRINSIC);
|
||||
if (TypeCompatible(retType, type, ID_ASS))
|
||||
{
|
||||
if ( IsOfType( p, ID_SEP ) )
|
||||
|
|
|
@ -319,26 +319,19 @@ CBotError CBotStack::GetError(int& start, int& end)
|
|||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
int CBotStack::GetType(int mode)
|
||||
int CBotStack::GetType(CBotVar::GetTypeMode mode)
|
||||
{
|
||||
if (m_var == nullptr) return -1;
|
||||
return m_var->GetType(mode);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
CBotTypResult CBotStack::GetTypResult(int mode)
|
||||
CBotTypResult CBotStack::GetTypResult(CBotVar::GetTypeMode mode)
|
||||
{
|
||||
if (m_var == nullptr) return -1;
|
||||
return m_var->GetTypResult(mode);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
void CBotStack::SetType(CBotTypResult& type)
|
||||
{
|
||||
if (m_var == nullptr) return;
|
||||
m_var->SetType( type );
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
CBotVar* CBotStack::FindVar(CBotToken*& pToken, bool bUpdate)
|
||||
{
|
||||
|
@ -520,7 +513,7 @@ void CBotStack::SetCopyVar( CBotVar* var )
|
|||
{
|
||||
if (m_var) delete m_var; // replacement of a variable
|
||||
|
||||
m_var = CBotVar::Create("", var->GetTypResult(2));
|
||||
m_var = CBotVar::Create("", var->GetTypResult(CBotVar::GetTypeMode::CLASS_AS_INTRINSIC));
|
||||
m_var->Copy( var );
|
||||
}
|
||||
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
|
||||
#include <cstdio>
|
||||
#include <string>
|
||||
#include <CBot/CBotVar/CBotVar.h>
|
||||
|
||||
class CBotInstr;
|
||||
class CBotExternalCall;
|
||||
|
@ -75,30 +76,23 @@ public:
|
|||
CBotError GetError();
|
||||
|
||||
/**
|
||||
* \brief Reset Reset error at and set user
|
||||
* \param [in] pUser User of stack
|
||||
* \brief Reset the stack - resets the error and timer
|
||||
*/
|
||||
void Reset();
|
||||
|
||||
/**
|
||||
* \brief SetType Determines the type.
|
||||
* \param type Type of instruction on the stack.
|
||||
*/
|
||||
void SetType(CBotTypResult& type);
|
||||
|
||||
/**
|
||||
* \brief GetType Get the type of value on the stack.
|
||||
* \param [in] mode Used when getting class type (1 gives pointer, 2 gives intrinsic).
|
||||
* \return Type number.
|
||||
*/
|
||||
int GetType(int mode = 0);
|
||||
int GetType(CBotVar::GetTypeMode mode = CBotVar::GetTypeMode::NORMAL);
|
||||
|
||||
/**
|
||||
* \brief Getes the type of complete value on the stack.
|
||||
* \param [in] mode Used when getting class type (1 gives pointer, 2 gives intrinsic).
|
||||
* \return Type of an element.
|
||||
*/
|
||||
CBotTypResult GetTypResult(int mode = 0);
|
||||
CBotTypResult GetTypResult(CBotVar::GetTypeMode mode = CBotVar::GetTypeMode::NORMAL);
|
||||
|
||||
/**
|
||||
* \brief Adds a local variable.
|
||||
|
|
|
@ -198,7 +198,7 @@ CBotVar* CBotVar::Create(const CBotToken& name, CBotTypResult type)
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
CBotVar* CBotVar::Create( CBotVar* pVar )
|
||||
{
|
||||
CBotVar* p = Create(pVar->m_token->GetString(), pVar->GetTypResult(2));
|
||||
CBotVar* p = Create(pVar->m_token->GetString(), pVar->GetTypResult(CBotVar::GetTypeMode::CLASS_AS_INTRINSIC));
|
||||
return p;
|
||||
}
|
||||
|
||||
|
@ -305,24 +305,24 @@ void CBotVar::Destroy(CBotVar* var)
|
|||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
CBotTypResult CBotVar::GetTypResult(int mode)
|
||||
CBotTypResult CBotVar::GetTypResult(GetTypeMode mode)
|
||||
{
|
||||
CBotTypResult r = m_type;
|
||||
|
||||
if ( mode == 1 && m_type.Eq(CBotTypClass) )
|
||||
if ( mode == GetTypeMode::CLASS_AS_POINTER && m_type.Eq(CBotTypClass) )
|
||||
r.SetType(CBotTypPointer);
|
||||
if ( mode == 2 && m_type.Eq(CBotTypClass) )
|
||||
if ( mode == GetTypeMode::CLASS_AS_INTRINSIC && m_type.Eq(CBotTypClass) )
|
||||
r.SetType(CBotTypIntrinsic);
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
CBotType CBotVar::GetType(int mode)
|
||||
CBotType CBotVar::GetType(GetTypeMode mode)
|
||||
{
|
||||
if ( mode == 1 && m_type.Eq(CBotTypClass) )
|
||||
if ( mode == GetTypeMode::CLASS_AS_POINTER && m_type.Eq(CBotTypClass) )
|
||||
return CBotTypPointer;
|
||||
if ( mode == 2 && m_type.Eq(CBotTypClass) )
|
||||
if ( mode == GetTypeMode::CLASS_AS_INTRINSIC && m_type.Eq(CBotTypClass) )
|
||||
return CBotTypIntrinsic;
|
||||
return static_cast<CBotType>(m_type.GetType());
|
||||
}
|
||||
|
|
|
@ -178,26 +178,27 @@ public:
|
|||
CBotToken* GetToken();
|
||||
|
||||
/**
|
||||
* \brief GetType Returns the base type of the variable (::CBotType)
|
||||
* \param mode
|
||||
* \parblock
|
||||
* * mode = 0 Return type normally
|
||||
* * mode = 1 Treat classes as pointers
|
||||
* * mode = 2 Treat classes as intrinsic
|
||||
* \endparblock
|
||||
* \brief Mode for GetType() and GetTypResult()
|
||||
*/
|
||||
CBotType GetType(int mode = 0);
|
||||
enum class GetTypeMode
|
||||
{
|
||||
NORMAL = 0,
|
||||
CLASS_AS_POINTER = 1,
|
||||
CLASS_AS_INTRINSIC = 2,
|
||||
};
|
||||
|
||||
/**
|
||||
* \brief GetType Returns the base type of the variable (::CBotType)
|
||||
* \param mode Mode, see GetTypeMode enum
|
||||
*/
|
||||
CBotType GetType(GetTypeMode mode = GetTypeMode::NORMAL);
|
||||
|
||||
/**
|
||||
* \brief Returns the complete type of the variable (CBotTypResult)
|
||||
* \param mode
|
||||
* \parblock
|
||||
* * mode = 0 Return type normally
|
||||
* * mode = 1 Treat classes as pointers
|
||||
* * mode = 2 Treat classes as intrinsic
|
||||
* \endparblock
|
||||
* \param mode Mode, see GetTypeMode enum
|
||||
*/
|
||||
CBotTypResult GetTypResult(int mode = 0);
|
||||
CBotTypResult GetTypResult(GetTypeMode mode = GetTypeMode::NORMAL);
|
||||
|
||||
/**
|
||||
* \brief Change type of this variable
|
||||
|
|
Loading…
Reference in New Issue