diff --git a/src/CBot/CBotCStack.cpp b/src/CBot/CBotCStack.cpp index 98bee9f0..d05f4450 100644 --- a/src/CBot/CBotCStack.cpp +++ b/src/CBot/CBotCStack.cpp @@ -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 ); } diff --git a/src/CBot/CBotCStack.h b/src/CBot/CBotCStack.h index 02c78f3b..7e66878a 100644 --- a/src/CBot/CBotCStack.h +++ b/src/CBot/CBotCStack.h @@ -20,6 +20,7 @@ #pragma once // Modules inlcude +#include #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. diff --git a/src/CBot/CBotInstr/CBotClassInst.cpp b/src/CBot/CBotInstr/CBotClassInst.cpp index f598db9d..a7a903af 100644 --- a/src/CBot/CBotInstr/CBotClassInst.cpp +++ b/src/CBot/CBotInstr/CBotClassInst.cpp @@ -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()); diff --git a/src/CBot/CBotInstr/CBotExprVar.cpp b/src/CBot/CBotInstr/CBotExprVar.cpp index bca8171d..da534886 100644 --- a/src/CBot/CBotInstr/CBotExprVar.cpp +++ b/src/CBot/CBotInstr/CBotExprVar.cpp @@ -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)) { diff --git a/src/CBot/CBotInstr/CBotExpression.cpp b/src/CBot/CBotInstr/CBotExpression.cpp index afc86076..0f95625e 100644 --- a/src/CBot/CBotInstr/CBotExpression.cpp +++ b/src/CBot/CBotInstr/CBotExpression.cpp @@ -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()) diff --git a/src/CBot/CBotInstr/CBotFieldExpr.cpp b/src/CBot/CBotInstr/CBotFieldExpr.cpp index 8bd5919e..cc7decfd 100644 --- a/src/CBot/CBotInstr/CBotFieldExpr.cpp +++ b/src/CBot/CBotInstr/CBotFieldExpr.cpp @@ -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(); diff --git a/src/CBot/CBotInstr/CBotFunction.cpp b/src/CBot/CBotInstr/CBotFunction.cpp index 8be758f0..6a5a9140 100644 --- a/src/CBot/CBotInstr/CBotFunction.cpp +++ b/src/CBot/CBotInstr/CBotFunction.cpp @@ -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(); diff --git a/src/CBot/CBotInstr/CBotIndexExpr.cpp b/src/CBot/CBotInstr/CBotIndexExpr.cpp index 62d37f72..483b1a0e 100644 --- a/src/CBot/CBotInstr/CBotIndexExpr.cpp +++ b/src/CBot/CBotInstr/CBotIndexExpr.cpp @@ -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(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(); diff --git a/src/CBot/CBotInstr/CBotLeftExpr.cpp b/src/CBot/CBotInstr/CBotLeftExpr.cpp index 01b43ccf..e1915180 100644 --- a/src/CBot/CBotInstr/CBotLeftExpr.cpp +++ b/src/CBot/CBotInstr/CBotLeftExpr.cpp @@ -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)) { diff --git a/src/CBot/CBotInstr/CBotReturn.cpp b/src/CBot/CBotInstr/CBotReturn.cpp index c3915e48..30f7d492 100644 --- a/src/CBot/CBotInstr/CBotReturn.cpp +++ b/src/CBot/CBotInstr/CBotReturn.cpp @@ -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 ) ) diff --git a/src/CBot/CBotStack.cpp b/src/CBot/CBotStack.cpp index 93ab3fdd..0e56defd 100644 --- a/src/CBot/CBotStack.cpp +++ b/src/CBot/CBotStack.cpp @@ -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 ); } diff --git a/src/CBot/CBotStack.h b/src/CBot/CBotStack.h index 4e1566eb..10873c94 100644 --- a/src/CBot/CBotStack.h +++ b/src/CBot/CBotStack.h @@ -25,6 +25,7 @@ #include #include +#include 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. diff --git a/src/CBot/CBotVar/CBotVar.cpp b/src/CBot/CBotVar/CBotVar.cpp index 1dd19e16..460a0f28 100644 --- a/src/CBot/CBotVar/CBotVar.cpp +++ b/src/CBot/CBotVar/CBotVar.cpp @@ -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(m_type.GetType()); } diff --git a/src/CBot/CBotVar/CBotVar.h b/src/CBot/CBotVar/CBotVar.h index aee738d9..ec177e0d 100644 --- a/src/CBot/CBotVar/CBotVar.h +++ b/src/CBot/CBotVar/CBotVar.h @@ -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