Made CBot errors an enum
parent
5db1254dd8
commit
73f8bd5490
|
@ -36,7 +36,7 @@
|
|||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
CBotProgram* CBotCStack::m_prog = nullptr; // init the static variable
|
||||
int CBotCStack::m_error = 0;
|
||||
CBotError CBotCStack::m_error = CBotNoErr;
|
||||
int CBotCStack::m_end = 0;
|
||||
CBotTypResult CBotCStack::m_retTyp = CBotTypResult(0);
|
||||
|
||||
|
@ -48,7 +48,7 @@ CBotCStack::CBotCStack(CBotCStack* ppapa)
|
|||
|
||||
if (ppapa == nullptr)
|
||||
{
|
||||
m_error = 0;
|
||||
m_error = CBotNoErr;
|
||||
m_start = 0;
|
||||
m_end = 0;
|
||||
m_bBlock = true;
|
||||
|
@ -124,7 +124,7 @@ CBotFunction* CBotCStack::ReturnFunc(CBotFunction* inst, CBotCStack* pfils)
|
|||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
int CBotCStack::GetError(int& start, int& end)
|
||||
CBotError CBotCStack::GetError(int& start, int& end)
|
||||
{
|
||||
start = m_start;
|
||||
end = m_end;
|
||||
|
@ -132,7 +132,7 @@ int CBotCStack::GetError(int& start, int& end)
|
|||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
int CBotCStack::GetError()
|
||||
CBotError CBotCStack::GetError()
|
||||
{
|
||||
return m_error;
|
||||
}
|
||||
|
@ -225,7 +225,7 @@ void CBotCStack::SetStartError( int pos )
|
|||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
void CBotCStack::SetError(int n, int pos)
|
||||
void CBotCStack::SetError(CBotError n, int pos)
|
||||
{
|
||||
if ( n!= 0 && m_error != 0) return; // does not change existing error
|
||||
m_error = n;
|
||||
|
@ -233,7 +233,7 @@ void CBotCStack::SetError(int n, int pos)
|
|||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
void CBotCStack::SetError(int n, CBotToken* p)
|
||||
void CBotCStack::SetError(CBotError n, CBotToken* p)
|
||||
{
|
||||
if (m_error) return; // does not change existing error
|
||||
m_error = n;
|
||||
|
@ -242,7 +242,7 @@ void CBotCStack::SetError(int n, CBotToken* p)
|
|||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
void CBotCStack::ResetError(int n, int start, int end)
|
||||
void CBotCStack::ResetError(CBotError n, int start, int end)
|
||||
{
|
||||
m_error = n;
|
||||
m_start = start;
|
||||
|
@ -362,7 +362,7 @@ CBotTypResult CBotCStack::CompileCall(CBotToken* &p, CBotVar** ppVars, long& nId
|
|||
if ( val.GetType() < 0 )
|
||||
{
|
||||
// pVar = nullptr; // the error is not on a particular parameter
|
||||
SetError( -val.GetType(), p );
|
||||
SetError( static_cast<CBotError>(-val.GetType()), p );
|
||||
val.SetType(-val.GetType());
|
||||
return val;
|
||||
}
|
||||
|
|
|
@ -57,7 +57,7 @@ public:
|
|||
* \brief GetError
|
||||
* \return
|
||||
*/
|
||||
int GetError();
|
||||
CBotError GetError();
|
||||
|
||||
/*!
|
||||
* \brief GetError Gives error number
|
||||
|
@ -65,7 +65,7 @@ public:
|
|||
* \param end
|
||||
* \return
|
||||
*/
|
||||
int GetError(int& start, int& end);
|
||||
CBotError GetError(int& start, int& end);
|
||||
|
||||
/*!
|
||||
* \brief SetType Set the type of instruction on the stack.
|
||||
|
@ -183,14 +183,14 @@ public:
|
|||
* \param n
|
||||
* \param pos
|
||||
*/
|
||||
void SetError(int n, int pos);
|
||||
void SetError(CBotError n, int pos);
|
||||
|
||||
/*!
|
||||
* \brief SetError
|
||||
* \param n
|
||||
* \param p
|
||||
*/
|
||||
void SetError(int n, CBotToken* p);
|
||||
void SetError(CBotError n, CBotToken* p);
|
||||
|
||||
/*!
|
||||
* \brief ResetError
|
||||
|
@ -198,7 +198,7 @@ public:
|
|||
* \param start
|
||||
* \param end
|
||||
*/
|
||||
void ResetError(int n, int start, int end);
|
||||
void ResetError(CBotError n, int start, int end);
|
||||
|
||||
/*!
|
||||
* \brief SetRetType
|
||||
|
@ -252,7 +252,7 @@ private:
|
|||
CBotCStack* m_next;
|
||||
CBotCStack* m_prev;
|
||||
|
||||
static int m_error;
|
||||
static CBotError m_error;
|
||||
static int m_end;
|
||||
int m_start;
|
||||
|
||||
|
|
|
@ -118,7 +118,7 @@ CBotTypResult CBotCall::CompileCall(CBotToken* &p, CBotVar** ppVar, CBotCStack*
|
|||
|
||||
if ( ret > 20 )
|
||||
{
|
||||
if (pVar2) pStack->SetError(ret, p /*pVar2->GetToken()*/ );
|
||||
if (pVar2) pStack->SetError(static_cast<CBotError>(ret), p /*pVar2->GetToken()*/ );
|
||||
}
|
||||
delete pVar;
|
||||
nIdent = pt->m_nFuncIdent;
|
||||
|
|
|
@ -70,7 +70,7 @@ CBotTypResult CBotCallMethode::CompileCall(const std::string& name,
|
|||
int ret = r.GetType();
|
||||
if ( ret > 20 )
|
||||
{
|
||||
if (pVar2) pStack->SetError(ret, pVar2->GetToken());
|
||||
if (pVar2) pStack->SetError(static_cast<CBotError>(ret), pVar2->GetToken());
|
||||
}
|
||||
delete pVar;
|
||||
nIdent = pt->m_nFuncIdent;
|
||||
|
|
|
@ -47,80 +47,3 @@
|
|||
#define OBJECTDELETED (reinterpret_cast<void*>(-1))
|
||||
// value set before initialization
|
||||
#define OBJECTCREATED (reinterpret_cast<void*>(-2))
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// Error Handling of compilation and execution
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// TODO: Why are all of those duplicated? This needs to be unified across the source code ~krzys_h
|
||||
|
||||
// Compile errors
|
||||
#define CBotErrOpenPar 5000 // missing the opening parenthesis
|
||||
#define CBotErrClosePar 5001 // missing the closing parenthesis
|
||||
#define CBotErrNotBoolean 5002 // expression must be a boolean
|
||||
#define CBotErrUndefVar 5003 // undeclared variable
|
||||
#define CBotErrBadLeft 5004 // assignment impossible ( 5 = ... )
|
||||
#define CBotErrNoTerminator 5005 // semicolon expected
|
||||
#define CBotErrCaseOut 5006 // case outside a switch
|
||||
#define CBotErrNoEnd 5007 // instructions after final closing brace
|
||||
#define CBotErrCloseBlock 5008 // missing " } "
|
||||
#define CBotErrElseWhitoutIf 5009 // else without matching if
|
||||
#define CBotErrOpenBlock 5010 // missing " { "
|
||||
#define CBotErrBadType1 5011 // wrong type for the assignment
|
||||
#define CBotErrRedefVar 5012 // redefinition of the variable
|
||||
#define CBotErrBadType2 5013 // Two operands are incompatible
|
||||
#define CBotErrUndefCall 5014 // routine undefined
|
||||
#define CBotErrNoDoubleDots 5015 // " : " expected
|
||||
#define CBotErrNoWhile 5016 // "while" expected (in do..while)
|
||||
#define CBotErrBreakOutside 5017 // break outside of a loop
|
||||
#define CBotErrUndefLabel 5019 // label udnefined
|
||||
#define CBotErrLabel 5018 // label ne peut se mettre ici (label can not get here)
|
||||
#define CBotErrNoCase 5020 // missing " case "
|
||||
#define CBotErrBadNum 5021 // expected number
|
||||
#define CBotErrVoid 5022 // " void " not possible here
|
||||
#define CBotErrNoType 5023 // type declaration expected
|
||||
#define CBotErrNoVar 5024 // variable name expected
|
||||
#define CBotErrNoFunc 5025 // expected function name
|
||||
#define CBotErrOverParam 5026 // too many parameters
|
||||
#define CBotErrRedefFunc 5027 // this function already exists
|
||||
#define CBotErrLowParam 5028 // not enough parameters
|
||||
#define CBotErrBadParam 5029 // wrong types of parameters
|
||||
#define CBotErrNbParam 5030 // wrong number of parameters
|
||||
#define CBotErrUndefItem 5031 // element does not exist in the class
|
||||
#define CBotErrUndefClass 5032 // variable is not a class
|
||||
#define CBotErrNoConstruct 5033 // no appropriate constructor
|
||||
#define CBotErrRedefClass 5034 // class already exists
|
||||
#define CBotErrCloseIndex 5035 // " ] " expected
|
||||
#define CBotErrReserved 5036 // reserved word (for a DefineNum)
|
||||
#define CBotErrBadNew 5037 // wrong setting for new
|
||||
#define CBotErrOpenIndex 5038 // " [ " expected
|
||||
#define CBotErrBadString 5039 // expected string
|
||||
#define CBotErrBadIndex 5040 // wrong index type "[ false ]"
|
||||
#define CBotErrPrivate 5041 // protected item
|
||||
#define CBotErrNoPublic 5042 // missing word "public"
|
||||
|
||||
// Runtime errors
|
||||
#define CBotErrZeroDiv 6000 // division by zero
|
||||
#define CBotErrNotInit 6001 // uninitialized variable
|
||||
#define CBotErrBadThrow 6002 // throw a negative value
|
||||
#define CBotErrNoRetVal 6003 // function did not return results
|
||||
#define CBotErrNoRun 6004 // Run() without active function
|
||||
#define CBotErrUndefFunc 6005 // calling a function that no longer exists
|
||||
#define CBotErrNotClass 6006 // this class does not exist
|
||||
#define CBotErrNull 6007 // null pointer
|
||||
#define CBotErrNan 6008 // calculation with a NAN
|
||||
#define CBotErrOutArray 6009 // index out of array
|
||||
#define CBotErrStackOver 6010 // stack overflow
|
||||
#define CBotErrDeletedPtr 6011 // pointer to an object destroyed
|
||||
#define CBotErrFileOpen 6012 // cannot open the file
|
||||
#define CBotErrNotOpen 6013 // channel not open
|
||||
#define CBotErrRead 6014 // error while reading
|
||||
#define CBotErrWrite 6015 // writing error
|
||||
|
||||
// Max errors
|
||||
#define TX_MAX 6016
|
||||
|
||||
// other values may be returned
|
||||
// for example exceptions returned by external routines
|
||||
// and " throw " with any number.
|
||||
|
|
|
@ -153,3 +153,84 @@ enum EID
|
|||
TX_UNDEF = 4000,
|
||||
TX_NAN
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// Error Handling of compilation and execution
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// NOTE: These CANNOT overlap with CBotType
|
||||
|
||||
enum CBotError
|
||||
{
|
||||
CBotNoErr = 0,
|
||||
|
||||
// Compile errors
|
||||
CBotErrOpenPar = 5000, //!< missing the opening parenthesis
|
||||
CBotErrClosePar = 5001, //!< missing the closing parenthesis
|
||||
CBotErrNotBoolean = 5002, //!< expression must be a boolean
|
||||
CBotErrUndefVar = 5003, //!< undeclared variable
|
||||
CBotErrBadLeft = 5004, //!< assignment impossible ( 5 = ... )
|
||||
CBotErrNoTerminator = 5005, //!< semicolon expected
|
||||
CBotErrCaseOut = 5006, //!< case outside a switch
|
||||
CBotErrNoEnd = 5007, //!< instructions after final closing brace
|
||||
CBotErrCloseBlock = 5008, //!< missing " } "
|
||||
CBotErrElseWhitoutIf = 5009, //!< else without matching if
|
||||
CBotErrOpenBlock = 5010, //!< missing " { "
|
||||
CBotErrBadType1 = 5011, //!< wrong type for the assignment
|
||||
CBotErrRedefVar = 5012, //!< redefinition of the variable
|
||||
CBotErrBadType2 = 5013, //!< Two operands are incompatible
|
||||
CBotErrUndefCall = 5014, //!< routine undefined
|
||||
CBotErrNoDoubleDots = 5015, //!< " : " expected
|
||||
CBotErrNoWhile = 5016, //!< "while" expected (in do..while)
|
||||
CBotErrBreakOutside = 5017, //!< break outside of a loop
|
||||
CBotErrUndefLabel = 5019, //!< label udnefined
|
||||
CBotErrLabel = 5018, //!< label ne peut se mettre ici (label can not get here)
|
||||
CBotErrNoCase = 5020, //!< missing " case "
|
||||
CBotErrBadNum = 5021, //!< expected number
|
||||
CBotErrVoid = 5022, //!< " void " not possible here
|
||||
CBotErrNoType = 5023, //!< type declaration expected
|
||||
CBotErrNoVar = 5024, //!< variable name expected
|
||||
CBotErrNoFunc = 5025, //!< expected function name
|
||||
CBotErrOverParam = 5026, //!< too many parameters
|
||||
CBotErrRedefFunc = 5027, //!< this function already exists
|
||||
CBotErrLowParam = 5028, //!< not enough parameters
|
||||
CBotErrBadParam = 5029, //!< wrong types of parameters
|
||||
CBotErrNbParam = 5030, //!< wrong number of parameters
|
||||
CBotErrUndefItem = 5031, //!< element does not exist in the class
|
||||
CBotErrUndefClass = 5032, //!< variable is not a class
|
||||
CBotErrNoConstruct = 5033, //!< no appropriate constructor
|
||||
CBotErrRedefClass = 5034, //!< class already exists
|
||||
CBotErrCloseIndex = 5035, //!< " ] " expected
|
||||
CBotErrReserved = 5036, //!< reserved word (for a DefineNum)
|
||||
CBotErrBadNew = 5037, //!< wrong setting for new
|
||||
CBotErrOpenIndex = 5038, //!< " [ " expected
|
||||
CBotErrBadString = 5039, //!< expected string
|
||||
CBotErrBadIndex = 5040, //!< wrong index type "[ false ]"
|
||||
CBotErrPrivate = 5041, //!< protected item
|
||||
CBotErrNoPublic = 5042, //!< missing word "public"
|
||||
|
||||
// Runtime errors
|
||||
CBotErrZeroDiv = 6000, //!< division by zero
|
||||
CBotErrNotInit = 6001, //!< uninitialized variable
|
||||
CBotErrBadThrow = 6002, //!< throw a negative value
|
||||
CBotErrNoRetVal = 6003, //!< function did not return results
|
||||
CBotErrNoRun = 6004, //!< Run() without active function
|
||||
CBotErrUndefFunc = 6005, //!< calling a function that no longer exists
|
||||
CBotErrNotClass = 6006, //!< this class does not exist
|
||||
CBotErrNull = 6007, //!< null pointer
|
||||
CBotErrNan = 6008, //!< calculation with a NAN
|
||||
CBotErrOutArray = 6009, //!< index out of array
|
||||
CBotErrStackOver = 6010, //!< stack overflow
|
||||
CBotErrDeletedPtr = 6011, //!< pointer to an object destroyed
|
||||
CBotErrFileOpen = 6012, //!< cannot open the file
|
||||
CBotErrNotOpen = 6013, //!< channel not open
|
||||
CBotErrRead = 6014, //!< error while reading
|
||||
CBotErrWrite = 6015, //!< writing error
|
||||
|
||||
// Max errors
|
||||
TX_MAX,
|
||||
|
||||
// other values may be returned
|
||||
// for example exceptions returned by external routines
|
||||
// and " throw " with any number.
|
||||
};
|
||||
|
|
|
@ -155,7 +155,7 @@ CBotInstr* CBotClassInst::Compile(CBotToken* &p, CBotCStack* pStack, CBotClass*
|
|||
|
||||
if (typ>20)
|
||||
{
|
||||
pStk->SetError(typ, vartoken->GetEnd());
|
||||
pStk->SetError(static_cast<CBotError>(typ), vartoken->GetEnd());
|
||||
goto error;
|
||||
}
|
||||
|
||||
|
|
|
@ -213,7 +213,7 @@ CBotInstr* CBotExprVar::CompileMethode(CBotToken* &p, CBotCStack* pStack)
|
|||
p = pp; // previous instruction
|
||||
return pStack->Return(inst, pStk);
|
||||
}
|
||||
pStk->SetError(0,0); // the error is not adressed here
|
||||
pStk->SetError(CBotNoErr, 0); // the error is not adressed here
|
||||
}
|
||||
}
|
||||
delete inst;
|
||||
|
|
|
@ -142,10 +142,11 @@ CBotInstr* CBotExpression::Compile(CBotToken* &p, CBotCStack* pStack)
|
|||
}
|
||||
|
||||
delete inst;
|
||||
int start, end, error = pStack->GetError(start, end);
|
||||
int start, end;
|
||||
CBotError error = pStack->GetError(start, end);
|
||||
|
||||
p = pp; // returns to the top
|
||||
pStack->SetError(0,0); // forget the error
|
||||
pStack->SetError(CBotNoErr,0); // forget the error
|
||||
|
||||
CBotInstr* i = CBotTwoOpExpr::Compile(p, pStack); // tries without assignment
|
||||
if (i != nullptr && error == CBotErrPrivate && p->GetType() == ID_ASS)
|
||||
|
|
|
@ -111,7 +111,7 @@ CBotInstr* CBotInstrCall::Compile(CBotToken* &p, CBotCStack* pStack)
|
|||
if ( inst->m_typRes.GetType() >= 20 )
|
||||
{
|
||||
// if (pVar2!=nullptr) pp = pVar2->RetToken();
|
||||
pStack->SetError( inst->m_typRes.GetType(), pp );
|
||||
pStack->SetError( static_cast<CBotError>(inst->m_typRes.GetType()), pp );
|
||||
delete pStack->TokenStack();
|
||||
delete inst;
|
||||
return nullptr;
|
||||
|
|
|
@ -77,7 +77,7 @@ CBotInstr* CBotInstrMethode::Compile(CBotToken* &p, CBotCStack* pStack, CBotVar*
|
|||
|
||||
if (inst->m_typRes.GetType() > 20)
|
||||
{
|
||||
pStack->SetError(inst->m_typRes.GetType(), pp);
|
||||
pStack->SetError(static_cast<CBotError>(inst->m_typRes.GetType()), pp);
|
||||
delete inst;
|
||||
return nullptr;
|
||||
}
|
||||
|
@ -97,7 +97,7 @@ CBotInstr* CBotInstrMethode::Compile(CBotToken* &p, CBotCStack* pStack, CBotVar*
|
|||
return nullptr;
|
||||
}
|
||||
}
|
||||
pStack->SetError(1234, p);
|
||||
pStack->SetError(static_cast<CBotError>(1234), p); // TODO: seriously? ~krzys_h
|
||||
delete inst;
|
||||
return nullptr;
|
||||
}
|
||||
|
|
|
@ -92,7 +92,7 @@ CBotInstr* CBotNew::Compile(CBotToken* &p, CBotCStack* pStack)
|
|||
|
||||
if (typ>20)
|
||||
{
|
||||
pStk->SetError(typ, inst->m_vartoken.GetEnd());
|
||||
pStk->SetError(static_cast<CBotError>(typ), inst->m_vartoken.GetEnd());
|
||||
goto error;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue