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