[colobot] 205/377: CBotVar::GetTypeMode enum
Didier Raboud
odyx at moszumanska.debian.org
Wed Mar 30 13:34:16 UTC 2016
This is an automated email from the git hooks/post-receive script.
odyx pushed a commit to branch debian/master
in repository colobot.
commit 40b7d986aaace22a3e342f62766b75f6879da461
Author: krzys-h <krzys_h at interia.pl>
Date: Fri Dec 25 19:16:54 2015 +0100
CBotVar::GetTypeMode enum
---
src/CBot/CBotCStack.cpp | 8 ++++----
src/CBot/CBotCStack.h | 5 +++--
src/CBot/CBotInstr/CBotClassInst.cpp | 4 ++--
src/CBot/CBotInstr/CBotExprVar.cpp | 2 +-
src/CBot/CBotInstr/CBotExpression.cpp | 2 +-
src/CBot/CBotInstr/CBotFieldExpr.cpp | 4 ++--
src/CBot/CBotInstr/CBotFunction.cpp | 4 ++--
src/CBot/CBotInstr/CBotIndexExpr.cpp | 4 ++--
src/CBot/CBotInstr/CBotLeftExpr.cpp | 2 +-
src/CBot/CBotInstr/CBotReturn.cpp | 2 +-
src/CBot/CBotStack.cpp | 13 +++----------
src/CBot/CBotStack.h | 14 ++++----------
src/CBot/CBotVar/CBotVar.cpp | 14 +++++++-------
src/CBot/CBotVar/CBotVar.h | 27 ++++++++++++++-------------
14 files changed, 47 insertions(+), 58 deletions(-)
diff --git a/src/CBot/CBotCStack.cpp b/src/CBot/CBotCStack.cpp
index 98bee9f..d05f445 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 02c78f3..7e66878 100644
--- a/src/CBot/CBotCStack.h
+++ b/src/CBot/CBotCStack.h
@@ -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.
diff --git a/src/CBot/CBotInstr/CBotClassInst.cpp b/src/CBot/CBotInstr/CBotClassInst.cpp
index f598db9..a7a903a 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 bca8171..da53488 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 afc8607..0f95625 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 8bd5919..cc7decf 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 8be758f..6a5a914 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 62d37f7..483b1a0 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<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();
diff --git a/src/CBot/CBotInstr/CBotLeftExpr.cpp b/src/CBot/CBotInstr/CBotLeftExpr.cpp
index 01b43cc..e191518 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 c3915e4..30f7d49 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 93ab3fd..0e56def 100644
--- a/src/CBot/CBotStack.cpp
+++ b/src/CBot/CBotStack.cpp
@@ -319,27 +319,20 @@ 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)
{
CBotStack* p = this;
@@ -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 4e1566e..10873c9 100644
--- a/src/CBot/CBotStack.h
+++ b/src/CBot/CBotStack.h
@@ -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.
diff --git a/src/CBot/CBotVar/CBotVar.cpp b/src/CBot/CBotVar/CBotVar.cpp
index 1dd19e1..460a0f2 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<CBotType>(m_type.GetType());
}
diff --git a/src/CBot/CBotVar/CBotVar.h b/src/CBot/CBotVar/CBotVar.h
index aee738d..ec177e0 100644
--- a/src/CBot/CBotVar/CBotVar.h
+++ b/src/CBot/CBotVar/CBotVar.h
@@ -178,26 +178,27 @@ public:
CBotToken* GetToken();
/**
+ * \brief Mode for GetType() and GetTypResult()
+ */
+ 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
- * \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
*/
- CBotType GetType(int mode = 0);
+ 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
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-games/colobot.git
More information about the Pkg-games-commits
mailing list