Remove remaining "this != nullptr" checks in CBOT, closes #828

dev-buzzingcars
krzys-h 2016-11-11 18:02:39 +01:00
parent 3bac0aabd9
commit 8764d28e9e
6 changed files with 76 additions and 75 deletions

View File

@ -133,7 +133,6 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
message(STATUS "Detected GCC version 4.7+") message(STATUS "Detected GCC version 4.7+")
set(NORMAL_CXX_FLAGS "-std=gnu++11 -Wall -Wold-style-cast -pedantic-errors") set(NORMAL_CXX_FLAGS "-std=gnu++11 -Wall -Wold-style-cast -pedantic-errors")
set(NORMAL_CXX_FLAGS "${NORMAL_CXX_FLAGS} -fno-delete-null-pointer-checks") # Temporary hack, see #828
set(RELEASE_CXX_FLAGS "-O2") set(RELEASE_CXX_FLAGS "-O2")
set(DEBUG_CXX_FLAGS "-g -O0") set(DEBUG_CXX_FLAGS "-g -O0")
set(TEST_CXX_FLAGS "-pthread") set(TEST_CXX_FLAGS "-pthread")

View File

@ -350,7 +350,7 @@ CBotTypResult CBotCStack::CompileCall(CBotToken* &p, CBotVar** ppVars, long& nId
val = m_prog->GetExternalCalls()->CompileCall(p, nullptr, ppVars, this); val = m_prog->GetExternalCalls()->CompileCall(p, nullptr, ppVars, this);
if (val.GetType() < 0) if (val.GetType() < 0)
{ {
val = m_prog->GetFunctions()->CompileCall(p->GetString(), ppVars, nIdent); val = CBotFunction::CompileCall(m_prog->GetFunctions(), p->GetString(), ppVars, nIdent);
if ( val.GetType() < 0 ) if ( val.GetType() < 0 )
{ {
// pVar = nullptr; // the error is not on a particular parameter // pVar = nullptr; // the error is not on a particular parameter

View File

@ -331,7 +331,7 @@ CBotTypResult CBotClass::CompileMethode(const std::string& name,
// find the methods declared by user // find the methods declared by user
r = m_pMethod->CompileCall(name, ppParams, nIdent); r = CBotFunction::CompileCall(m_pMethod, name, ppParams, nIdent);
if ( r.Eq(CBotErrUndefCall) && m_parent != nullptr ) if ( r.Eq(CBotErrUndefCall) && m_parent != nullptr )
return m_parent->CompileMethode(name, pThis, ppParams, pStack, nIdent); return m_parent->CompileMethode(name, pThis, ppParams, pStack, nIdent);
return r; return r;
@ -349,7 +349,7 @@ bool CBotClass::ExecuteMethode(long& nIdent,
int ret = m_pCalls->DoCall(name, pThis, ppParams, pResult, pStack, pToken); int ret = m_pCalls->DoCall(name, pThis, ppParams, pResult, pStack, pToken);
if (ret>=0) return ret; if (ret>=0) return ret;
ret = m_pMethod->DoCall(nIdent, name, pThis, ppParams, pStack, pToken, this); ret = CBotFunction::DoCall(m_pMethod, nIdent, name, pThis, ppParams, pStack, pToken, this);
if (ret >= 0) return ret; if (ret >= 0) return ret;
if (m_parent != nullptr) if (m_parent != nullptr)
@ -369,7 +369,7 @@ void CBotClass::RestoreMethode(long& nIdent,
CBotClass* pClass = this; CBotClass* pClass = this;
while (pClass != nullptr) while (pClass != nullptr)
{ {
bool ok = pClass->m_pMethod->RestoreCall(nIdent, name, pThis, ppParams, pStack, pClass); bool ok = CBotFunction::RestoreCall(pClass->m_pMethod, nIdent, name, pThis, ppParams, pStack, pClass);
if (ok) return; if (ok) return;
pClass = pClass->m_parent; pClass = pClass->m_parent;
} }

View File

@ -421,26 +421,27 @@ void CBotFunction::AddNext(CBotFunction* p)
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
CBotTypResult CBotFunction::CompileCall(const std::string& name, CBotVar** ppVars, long& nIdent) CBotTypResult CBotFunction::CompileCall(CBotFunction* localFunctionList, const std::string &name, CBotVar** ppVars, long &nIdent)
{ {
nIdent = 0; CBotTypResult type;
CBotTypResult type; if (!FindLocalOrPublic(localFunctionList, nIdent, name, ppVars, type))
{
// CBotFunction* pt = FindLocalOrPublic(nIdent, name, ppVars, type); // Reset the identifier to "not found" value
FindLocalOrPublic(nIdent, name, ppVars, type); nIdent = 0;
}
return type; return type;
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
CBotFunction* CBotFunction::FindLocalOrPublic(long& nIdent, const std::string& name, CBotVar** ppVars, CBotFunction* CBotFunction::FindLocalOrPublic(CBotFunction* localFunctionList, long &nIdent, const std::string &name,
CBotTypResult& TypeOrError, bool bPublic) CBotVar** ppVars, CBotTypResult &TypeOrError, bool bPublic)
{ {
TypeOrError.SetType(CBotErrUndefCall); // no routine of the name TypeOrError.SetType(CBotErrUndefCall); // no routine of the name
CBotFunction* pt; CBotFunction* pt;
if ( nIdent ) if ( nIdent )
{ {
if ( this != nullptr ) for ( pt = this ; pt != nullptr ; pt = pt->m_next ) if ( localFunctionList != nullptr ) for ( pt = localFunctionList ; pt != nullptr ; pt = pt->m_next )
{ {
if ( pt->m_nFuncIdent == nIdent ) if ( pt->m_nFuncIdent == nIdent )
{ {
@ -464,9 +465,9 @@ CBotFunction* CBotFunction::FindLocalOrPublic(long& nIdent, const std::string& n
std::map<CBotFunction*, int> funcMap; std::map<CBotFunction*, int> funcMap;
if ( this != nullptr ) if ( localFunctionList != nullptr )
{ {
for ( pt = this ; pt != nullptr ; pt = pt->m_next ) for ( pt = localFunctionList ; pt != nullptr ; pt = pt->m_next )
{ {
if ( pt->m_token.GetString() == name ) if ( pt->m_token.GetString() == name )
{ {
@ -610,12 +611,13 @@ CBotFunction* CBotFunction::FindLocalOrPublic(long& nIdent, const std::string& n
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
int CBotFunction::DoCall(long& nIdent, const std::string& name, CBotVar** ppVars, CBotStack* pStack, CBotToken* pToken) int CBotFunction::DoCall(CBotProgram* program, CBotFunction* localFunctionList, long &nIdent, const std::string &name,
CBotVar** ppVars, CBotStack* pStack, CBotToken* pToken)
{ {
CBotTypResult type; CBotTypResult type;
CBotFunction* pt = nullptr; CBotFunction* pt = nullptr;
pt = FindLocalOrPublic(nIdent, name, ppVars, type); pt = FindLocalOrPublic(localFunctionList, nIdent, name, ppVars, type);
if ( pt != nullptr ) if ( pt != nullptr )
{ {
@ -634,7 +636,7 @@ int CBotFunction::DoCall(long& nIdent, const std::string& name, CBotVar** ppVars
{ {
if ( !pt->m_MasterClass.empty() ) if ( !pt->m_MasterClass.empty() )
{ {
CBotVar* pInstance = m_pProg->m_thisVar; CBotVar* pInstance = program->m_thisVar;
// make "this" known // make "this" known
CBotVar* pThis ; CBotVar* pThis ;
if ( pInstance == nullptr ) if ( pInstance == nullptr )
@ -670,7 +672,7 @@ int CBotFunction::DoCall(long& nIdent, const std::string& name, CBotVar** ppVars
if ( !pStk3->GetRetVar( // puts the result on the stack if ( !pStk3->GetRetVar( // puts the result on the stack
pt->m_block->Execute(pStk3) )) // GetRetVar said if it is interrupted pt->m_block->Execute(pStk3) )) // GetRetVar said if it is interrupted
{ {
if ( !pStk3->IsOk() && pt->m_pProg != m_pProg ) if ( !pStk3->IsOk() && pt->m_pProg != program )
{ {
pStk3->SetPosError(pToken); // indicates the error on the procedure call pStk3->SetPosError(pToken); // indicates the error on the procedure call
} }
@ -683,7 +685,8 @@ int CBotFunction::DoCall(long& nIdent, const std::string& name, CBotVar** ppVars
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
void CBotFunction::RestoreCall(long& nIdent, const std::string& name, CBotVar** ppVars, CBotStack* pStack) void CBotFunction::RestoreCall(CBotFunction* localFunctionList,
long &nIdent, const std::string &name, CBotVar** ppVars, CBotStack* pStack)
{ {
CBotTypResult type; CBotTypResult type;
CBotFunction* pt = nullptr; CBotFunction* pt = nullptr;
@ -692,7 +695,7 @@ void CBotFunction::RestoreCall(long& nIdent, const std::string& name, CBotVar**
// search function to return the ok identifier // search function to return the ok identifier
pt = FindLocalOrPublic(nIdent, name, ppVars, type); pt = FindLocalOrPublic(localFunctionList, nIdent, name, ppVars, type);
if ( pt != nullptr ) if ( pt != nullptr )
{ {
@ -740,13 +743,13 @@ void CBotFunction::RestoreCall(long& nIdent, const std::string& name, CBotVar**
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
int CBotFunction::DoCall(long& nIdent, const std::string& name, CBotVar* pThis, CBotVar** ppVars, CBotStack* pStack, int CBotFunction::DoCall(CBotFunction* localFunctionList, long &nIdent, const std::string &name, CBotVar* pThis,
CBotToken* pToken, CBotClass* pClass) CBotVar** ppVars, CBotStack* pStack, CBotToken* pToken, CBotClass* pClass)
{ {
CBotTypResult type; CBotTypResult type;
CBotProgram* pProgCurrent = pStack->GetProgram(); CBotProgram* pProgCurrent = pStack->GetProgram();
CBotFunction* pt = FindLocalOrPublic(nIdent, name, ppVars, type, false); CBotFunction* pt = FindLocalOrPublic(localFunctionList, nIdent, name, ppVars, type, false);
if ( pt != nullptr ) if ( pt != nullptr )
{ {
@ -822,11 +825,11 @@ int CBotFunction::DoCall(long& nIdent, const std::string& name, CBotVar* pThis,
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
bool CBotFunction::RestoreCall(long& nIdent, const std::string& name, CBotVar* pThis, CBotVar** ppVars, bool CBotFunction::RestoreCall(CBotFunction* localFunctionList, long &nIdent, const std::string &name, CBotVar* pThis,
CBotStack* pStack, CBotClass* pClass) CBotVar** ppVars, CBotStack* pStack, CBotClass* pClass)
{ {
CBotTypResult type; CBotTypResult type;
CBotFunction* pt = FindLocalOrPublic(nIdent, name, ppVars, type); CBotFunction* pt = FindLocalOrPublic(localFunctionList, nIdent, name, ppVars, type);
if ( pt != nullptr ) if ( pt != nullptr )
{ {

View File

@ -98,33 +98,43 @@ public:
void AddNext(CBotFunction* p); void AddNext(CBotFunction* p);
/*! /*!
* \brief CompileCall * \brief Compile a function call
* \param name *
* \param ppVars * See FindLocalOrPublic for more detailed explanation
* \param nIdent *
* \return * \param localFunctionList Linked list of local functions to search in, can be null
* \param name Name of the function
* \param ppVars List of function arguments
* \param nIdent[in, out] Unique identifier of the function
* \return Type returned by the function or error code
* \see FindLocalOrPublic
*/ */
CBotTypResult CompileCall(const std::string& name, static CBotTypResult CompileCall(CBotFunction* localFunctionList,
CBotVar** ppVars, const std::string &name, CBotVar** ppVars, long &nIdent);
long& nIdent);
/*! /*!
* \brief FindLocalOrPublic Is a function according to its unique identifier * \brief Finds a local or public function
* if the identifier is not found, looking by name and parameters. *
* \param nIdent * <p>Finds a local or (if bPublic is true) public function to call
* \param name *
* \param ppVars * <p>First, it looks for a function according to its unique identifier.<br>
* \param TypeOrError * If the identifier is not found, looks by name and parameters.
* \param bPublic *
* \return * \param localFunctionList Linked list of local functions to search in, can be null
* \param nIdent[in, out] Unique identifier of the function
* \param name Name of the function
* \param ppVars List of function arguments
* \param TypeOrError Type returned by the function or error code
* \param bPublic Whether to look in public functions or not
* \return Pointer to found CBotFunction instance, or nullptr in case of no match or ambiguity (see TypeOrError for error code)
*/ */
CBotFunction* FindLocalOrPublic(long& nIdent, const std::string& name, static CBotFunction* FindLocalOrPublic(CBotFunction* localFunctionList, long &nIdent, const std::string &name,
CBotVar** ppVars, CBotVar** ppVars, CBotTypResult &TypeOrError, bool bPublic = true);
CBotTypResult& TypeOrError,
bool bPublic = true);
/*! /*!
* \brief DoCall Fait un appel à une fonction. * \brief DoCall Fait un appel à une fonction.
* \param program
* \param localFunctionList
* \param nIdent * \param nIdent
* \param name * \param name
* \param ppVars * \param ppVars
@ -133,27 +143,24 @@ public:
* \return * \return
*/ */
int DoCall(long& nIdent, static int DoCall(CBotProgram* program, CBotFunction* localFunctionList, long &nIdent, const std::string &name,
const std::string& name, CBotVar** ppVars, CBotStack* pStack, CBotToken* pToken);
CBotVar** ppVars,
CBotStack* pStack,
CBotToken* pToken);
/*! /*!
* \brief RestoreCall * \brief RestoreCall
* \param localFunctionList
* \param nIdent * \param nIdent
* \param name * \param name
* \param ppVars * \param ppVars
* \param pStack * \param pStack
*/ */
void RestoreCall(long& nIdent, static void RestoreCall(CBotFunction* localFunctionList,
const std::string& name, long &nIdent, const std::string &name, CBotVar** ppVars, CBotStack* pStack);
CBotVar** ppVars,
CBotStack* pStack);
/*! /*!
* \brief DoCall Makes call of a method note: this is already on the stack, * \brief DoCall Makes call of a method
* the pointer pThis is just to simplify. * note: this is already on the stack, the pointer pThis is just to simplify.
* \param localFunctionList
* \param nIdent * \param nIdent
* \param name * \param name
* \param pThis * \param pThis
@ -163,16 +170,12 @@ public:
* \param pClass * \param pClass
* \return * \return
*/ */
int DoCall(long& nIdent, static int DoCall(CBotFunction* localFunctionList, long &nIdent, const std::string &name, CBotVar* pThis,
const std::string& name, CBotVar** ppVars, CBotStack* pStack, CBotToken* pToken, CBotClass* pClass);
CBotVar* pThis,
CBotVar** ppVars,
CBotStack* pStack,
CBotToken* pToken,
CBotClass* pClass);
/*! /*!
* \brief RestoreCall * \brief RestoreCall
* \param localFunctionList
* \param nIdent * \param nIdent
* \param name * \param name
* \param pThis * \param pThis
@ -181,12 +184,8 @@ public:
* \param pClass * \param pClass
* \return Returns true if the method call was restored. * \return Returns true if the method call was restored.
*/ */
bool RestoreCall(long& nIdent, static bool RestoreCall(CBotFunction* localFunctionList, long &nIdent, const std::string &name, CBotVar* pThis,
const std::string& name, CBotVar** ppVars, CBotStack* pStack, CBotClass* pClass);
CBotVar* pThis,
CBotVar** ppVars,
CBotStack* pStack,
CBotClass* pClass);
/*! /*!
* \brief CheckParam See if the "signature" of parameters is identical. * \brief CheckParam See if the "signature" of parameters is identical.

View File

@ -568,7 +568,7 @@ bool CBotStack::ExecuteCall(long& nIdent, CBotToken* token, CBotVar** ppVar, con
res = m_prog->GetExternalCalls()->DoCall(nullptr, nullptr, ppVar, this, rettype); res = m_prog->GetExternalCalls()->DoCall(nullptr, nullptr, ppVar, this, rettype);
if (res >= 0) return res; if (res >= 0) return res;
res = m_prog->GetFunctions()->DoCall(nIdent, "", ppVar, this, token ); res = CBotFunction::DoCall(m_prog, m_prog->GetFunctions(), nIdent, "", ppVar, this, token);
if (res >= 0) return res; if (res >= 0) return res;
// if not found (recompile?) seeks by name // if not found (recompile?) seeks by name
@ -577,7 +577,7 @@ bool CBotStack::ExecuteCall(long& nIdent, CBotToken* token, CBotVar** ppVar, con
res = m_prog->GetExternalCalls()->DoCall(token, nullptr, ppVar, this, rettype); res = m_prog->GetExternalCalls()->DoCall(token, nullptr, ppVar, this, rettype);
if (res >= 0) return res; if (res >= 0) return res;
res = m_prog->GetFunctions()->DoCall(nIdent, token->GetString(), ppVar, this, token ); res = CBotFunction::DoCall(m_prog, m_prog->GetFunctions(), nIdent, token->GetString(), ppVar, this, token);
if (res >= 0) return res; if (res >= 0) return res;
SetError(CBotErrUndefFunc, token); SetError(CBotErrUndefFunc, token);
@ -592,7 +592,7 @@ void CBotStack::RestoreCall(long& nIdent, CBotToken* token, CBotVar** ppVar)
if (m_prog->GetExternalCalls()->RestoreCall(token, nullptr, ppVar, this)) if (m_prog->GetExternalCalls()->RestoreCall(token, nullptr, ppVar, this))
return; return;
m_prog->GetFunctions()->RestoreCall(nIdent, token->GetString(), ppVar, this); CBotFunction::RestoreCall(m_prog->GetFunctions(), nIdent, token->GetString(), ppVar, this);
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////