diff options
Diffstat (limited to 'src/CBot')
-rw-r--r-- | src/CBot/.gitignore | 1 | ||||
-rw-r--r-- | src/CBot/CBot.cpp | 65 | ||||
-rw-r--r-- | src/CBot/CBot.h | 76 | ||||
-rw-r--r-- | src/CBot/CBotAddExpr.cpp | 3 | ||||
-rw-r--r-- | src/CBot/CBotClass.cpp | 40 | ||||
-rw-r--r-- | src/CBot/CBotCompExpr.cpp | 2 | ||||
-rw-r--r-- | src/CBot/CBotDll.h | 46 | ||||
-rw-r--r-- | src/CBot/CBotFunction.cpp | 43 | ||||
-rw-r--r-- | src/CBot/CBotIf.cpp | 4 | ||||
-rw-r--r-- | src/CBot/CBotProgram.cpp | 48 | ||||
-rw-r--r-- | src/CBot/CBotStack.cpp | 56 | ||||
-rw-r--r-- | src/CBot/CBotString.cpp | 11 | ||||
-rw-r--r-- | src/CBot/CBotToken.cpp | 8 | ||||
-rw-r--r-- | src/CBot/CBotToken.h | 1 | ||||
-rw-r--r-- | src/CBot/CBotTwoOpExpr.cpp | 15 | ||||
-rw-r--r-- | src/CBot/CBotVar.cpp | 35 | ||||
-rw-r--r-- | src/CBot/CBotWhile.cpp | 207 | ||||
-rw-r--r-- | src/CBot/CMakeLists.txt | 3 | ||||
-rw-r--r-- | src/CBot/ClassFILE.cpp | 6 | ||||
-rw-r--r-- | src/CBot/StringFunctions.cpp | 7 | ||||
-rw-r--r-- | src/CBot/idees.txt | 1 | ||||
-rw-r--r-- | src/CBot/resource.h | 2 |
22 files changed, 254 insertions, 426 deletions
diff --git a/src/CBot/.gitignore b/src/CBot/.gitignore new file mode 100644 index 0000000..4c80252 --- /dev/null +++ b/src/CBot/.gitignore @@ -0,0 +1 @@ +libCBot.so diff --git a/src/CBot/CBot.cpp b/src/CBot/CBot.cpp index ed6831d..513b803 100644 --- a/src/CBot/CBot.cpp +++ b/src/CBot/CBot.cpp @@ -186,7 +186,7 @@ CBotInstr* CBotInstr::Compile(CBotToken* &p, CBotCStack* pStack) { type = pp->GetType(); // these instructions accept only lable - if (!IsOfTypeList(pp, ID_WHILE, ID_FOR, ID_DO, ID_REPEAT, 0)) + if (!IsOfTypeList(pp, ID_WHILE, ID_FOR, ID_DO, 0)) { pStack->SetError(TX_LABEL, pp->GetStart()); return NULL; @@ -205,9 +205,6 @@ CBotInstr* CBotInstr::Compile(CBotToken* &p, CBotCStack* pStack) case ID_DO: return CBotDo::Compile(p, pStack); - case ID_REPEAT: - return CBotRepeat::Compile(p, pStack); - case ID_BREAK: case ID_CONTINUE: return CBotBreak::Compile(p, pStack); @@ -513,7 +510,7 @@ CBotInstr* CBotLeftExprVar::Compile(CBotToken* &p, CBotCStack* pStack) return inst; } -// creates a variable and assigns the result to the stack +// creates a variable and assigns the result to the stack bool CBotLeftExprVar::Execute(CBotStack* &pj) { CBotVar* var1; @@ -1076,7 +1073,7 @@ bool CBotInt::Execute(CBotStack* &pj) if (pile->IfStep()) return false; - if ( m_next2b && + if ( m_next2b && !m_next2b->Execute(pile)) return false; // other(s) definition(s) return pj->Return(pile); // forward below @@ -1561,8 +1558,8 @@ CBotInstr* CBotExpression::Compile(CBotToken* &p, CBotCStack* pStack) int OpType = p->GetType(); if ( pStack->IsOk() && - IsOfTypeList(p, ID_ASS, ID_ASSADD, ID_ASSSUB, ID_ASSMUL, ID_ASSDIV, ID_ASSMODULO, - ID_ASSAND, ID_ASSXOR, ID_ASSOR, + IsOfTypeList(p, ID_ASS, ID_ASSADD, ID_ASSSUB, ID_ASSMUL, ID_ASSDIV, ID_ASSMODULO, + ID_ASSAND, ID_ASSXOR, ID_ASSOR, ID_ASSSL , ID_ASSSR, ID_ASSASR, 0 )) { if (inst->m_leftop == NULL) @@ -1658,7 +1655,7 @@ bool CBotExpression::Execute(CBotStack* &pj) CBotStack* pile = pj->AddStack(this); // CBotToken* pToken = m_leftop->GetToken(); - + CBotVar* pVar = NULL; CBotStack* pile1 = pile; @@ -1714,13 +1711,13 @@ bool CBotExpression::Execute(CBotStack* &pj) pile2->SetVar(result); break; case ID_ASSDIV: - if (IsInit && + if (IsInit && result->Div(pile1->GetVar(), pile2->GetVar())) pile2->SetError(TX_DIVZERO, &m_token); pile2->SetVar(result); break; case ID_ASSMODULO: - if (IsInit && + if (IsInit && result->Modulo(pile1->GetVar(), pile2->GetVar())) pile2->SetError(TX_DIVZERO, &m_token); pile2->SetVar(result); @@ -1779,7 +1776,7 @@ void CBotExpression::RestoreState(CBotStack* &pj, bool bMain) if ( pile1->GetState()==0) { - m_leftop->RestoreStateVar(pile, true); + m_leftop->RestoreStateVar(pile, true); return; } @@ -1972,7 +1969,7 @@ CBotInstr* CBotParExpr::Compile(CBotToken* &p, CBotCStack* pStack) } // is it a number or DefineNum? - if (p->GetType() == TokenTypNum || + if (p->GetType() == TokenTypNum || p->GetType() == TokenTypDef ) { CBotInstr* inst = CBotExprNum::Compile(p, pStk); @@ -2069,7 +2066,7 @@ bool CBotPostIncExpr::Execute(CBotStack* &pj) pile1->SetState(1); pile1->SetCopyVar(var1); // places the result (before incrementation); - CBotStack* pile3 = pile2->AddStack(this); + CBotStack* pile3 = pile2->AddStack(this); if (pile3->IfStep()) return false; if (var1->GetInit() == IS_NAN) @@ -2324,7 +2321,7 @@ bool CBotIndexExpr::ExecuteVar(CBotVar* &pVar, CBotStack* &pile, CBotToken* prev pVar->Maj(pile->GetPUser(), true); - if ( m_next3 != NULL && + if ( m_next3 != NULL && !m_next3->ExecuteVar(pVar, pile, prevToken, bStep, bExtend) ) return false; // does not release the stack @@ -2343,7 +2340,7 @@ void CBotIndexExpr::RestoreStateVar(CBotStack* &pile, bool bMain) return; } - if (m_next3) + if (m_next3) m_next3->RestoreStateVar(pile, bMain); } @@ -2431,7 +2428,7 @@ bool CBotFieldExpr::ExecuteVar(CBotVar* &pVar, CBotStack* &pile, CBotToken* prev // request the update of the element, if applicable pVar->Maj(pile->GetPUser(), true); - if ( m_next3 != NULL && + if ( m_next3 != NULL && !m_next3->ExecuteVar(pVar, pile, &m_token, bStep, bExtend) ) return false; // does not release the stack @@ -2445,7 +2442,7 @@ void CBotFieldExpr::RestoreStateVar(CBotStack* &pj, bool bMain) pj = pj->RestoreStack(this); if (pj == NULL) return; - if (m_next3 != NULL) + if (m_next3 != NULL) m_next3->RestoreStateVar(pj, bMain); } @@ -2659,7 +2656,7 @@ bool CBotLeftExpr::ExecuteVar(CBotVar* &pVar, CBotStack* &pile, CBotToken* prevT if (bStep && m_next3 == NULL && pile->IfStep()) return false; - if ( m_next3 != NULL && + if ( m_next3 != NULL && !m_next3->ExecuteVar(pVar, pile, &m_token, bStep, true) ) return false; return true; @@ -2670,7 +2667,7 @@ void CBotLeftExpr::RestoreStateVar(CBotStack* &pile, bool bMain) pile = pile->RestoreStack(this); if (pile == NULL) return; - if (m_next3 != NULL) + if (m_next3 != NULL) m_next3->RestoreStateVar(pile, bMain); } @@ -3098,7 +3095,7 @@ CBotInstr* CBotExprVar::Compile(CBotToken* &p, CBotCStack* pStack, int privat) { if (var->GetType() == CBotTypArrayPointer) { - if (IsOfType( p, ID_OPBRK )) // check if there is an aindex + if (IsOfType( p, ID_OPBRK )) // check if there is an aindex { CBotIndexExpr* i = new CBotIndexExpr(); i->m_expr = CBotExpression::Compile(p, pStk); // compile the formula @@ -3415,7 +3412,7 @@ CBotInstr* CBotInstrMethode::Compile(CBotToken* &p, CBotCStack* pStack, CBotVar* { CBotClass* pClass = var->GetClass(); // pointer to the class inst->m_ClassName = pClass->GetName(); // name of the class - CBotTypResult r = pClass->CompileMethode(inst->m_NomMethod, var, ppVars, + CBotTypResult r = pClass->CompileMethode(inst->m_NomMethod, var, ppVars, pStack, inst->m_MethodeIdent); delete pStack->TokenStack(); // release parameters on the stack inst->m_typRes = r; @@ -3507,8 +3504,8 @@ bool CBotInstrMethode::ExecuteVar(CBotVar* &pVar, CBotStack* &pj, CBotToken* pre } CBotVar* pRes = pResult; - if ( !pClass->ExecuteMethode(m_MethodeIdent, m_NomMethod, - pThis, ppVars, + if ( !pClass->ExecuteMethode(m_MethodeIdent, m_NomMethod, + pThis, ppVars, pResult, pile2, GetToken())) return false; if (pRes != pResult) delete pRes; @@ -3558,7 +3555,7 @@ void CBotInstrMethode::RestoreStateVar(CBotStack* &pile, bool bMain) // CBotVar* pRes = pResult; - pClass->RestoreMethode(m_MethodeIdent, m_NomMethod, + pClass->RestoreMethode(m_MethodeIdent, m_NomMethod, pThis, ppVars, pile2); } @@ -3612,8 +3609,8 @@ bool CBotInstrMethode::Execute(CBotStack* &pj) } CBotVar* pRes = pResult; - if ( !pClass->ExecuteMethode(m_MethodeIdent, m_NomMethod, - pThis, ppVars, + if ( !pClass->ExecuteMethode(m_MethodeIdent, m_NomMethod, + pThis, ppVars, pResult, pile2, GetToken())) return false; // interupted // set the new value of this in place of the old variable @@ -3628,7 +3625,7 @@ bool CBotInstrMethode::Execute(CBotStack* &pj) /////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////// -// compile an instruction "new" +// compile an instruction "new" CBotNew::CBotNew() { @@ -3773,8 +3770,8 @@ bool CBotNew::Execute(CBotStack* &pj) // create a variable for the result CBotVar* pResult = NULL; // constructos still void - if ( !pClass->ExecuteMethode(m_nMethodeIdent, pClass->GetName(), - pThis, ppVars, + if ( !pClass->ExecuteMethode(m_nMethodeIdent, pClass->GetName(), + pThis, ppVars, pResult, pile2, GetToken())) return false; // interrupt pThis->ConstructorSet(); // indicates that the constructor has been called @@ -3860,13 +3857,13 @@ bool TypeCompatible(CBotTypResult& type1, CBotTypResult& type2, int op) if (max >= CBotTypBoolean) { - if ( (op == ID_EQ || op == ID_NE) && + if ( (op == ID_EQ || op == ID_NE) && (t1 == CBotTypPointer && t2 == CBotTypNullPointer)) return true; - if ( (op == ID_EQ || op == ID_NE || op == ID_ASS) && + if ( (op == ID_EQ || op == ID_NE || op == ID_ASS) && (t2 == CBotTypPointer && t1 == CBotTypNullPointer)) return true; - if ( (op == ID_EQ || op == ID_NE) && + if ( (op == ID_EQ || op == ID_NE) && (t1 == CBotTypArrayPointer && t2 == CBotTypNullPointer)) return true; - if ( (op == ID_EQ || op == ID_NE || op == ID_ASS) && + if ( (op == ID_EQ || op == ID_NE || op == ID_ASS) && (t2 == CBotTypArrayPointer && t1 == CBotTypNullPointer)) return true; if (t2 != t1) return false; if (t1 == CBotTypArrayPointer) return type1.Compare(type2); diff --git a/src/CBot/CBot.h b/src/CBot/CBot.h index 8886308..8313252 100644 --- a/src/CBot/CBot.h +++ b/src/CBot/CBot.h @@ -57,7 +57,6 @@ class CBotExprVar; // a variable name as class CBotWhile; // while (...) {...}; class CBotIf; // if (...) {...} else {...} class CBotDefParam; // paramerer list of a function -class CBotRepeat; // repeat (nb) {...} @@ -70,7 +69,7 @@ class CBotRepeat; // repeat (nb) {...} // to use for routine CBotProgram :: Execute (CBotStack) -/**\class CBotStack +/**\class CBotStack * \brief Management of the execution stack. * \brief Actually the only thing it can do is to create an instance of a stack * \brief to use for routine CBotProgram :: Execute(CBotStack)*/ @@ -211,14 +210,14 @@ public: // in case of eventual break bool IfContinue(int state, const char* name); // or "continue" - + bool IsOk(); bool SetState(int n, int lim = -10); // select a state int GetState(); // in what state am I? bool IncState(int lim = -10); // passes to the next state bool IfStep(); // do step by step - bool Execute(); + bool Execute(); void SetVar( CBotVar* var ); void SetCopyVar( CBotVar* var ); @@ -260,7 +259,7 @@ private: CBotStack* m_prev; friend class CBotInstArray; -#ifdef _DEBUG +#ifdef _DEBUG int m_index; #endif int m_state; @@ -361,7 +360,7 @@ public: CBotCStack* TokenStack(CBotToken* pToken = NULL, bool bBlock = false); CBotInstr* Return(CBotInstr* p, CBotCStack* pParent); // transmits the result upper CBotFunction* ReturnFunc(CBotFunction* p, CBotCStack* pParent); // transmits the result upper - + void SetVar( CBotVar* var ); void SetCopyVar( CBotVar* var ); CBotVar* GetVar(); @@ -481,7 +480,7 @@ class CBotWhile : public CBotInstr private: CBotInstr* m_Condition; // condition CBotInstr* m_Block; // instructions - CBotString m_label; // a label if there is + CBotString m_label; // a label if there is public: CBotWhile(); @@ -492,38 +491,12 @@ public: void RestoreState(CBotStack* &pj, bool bMain); }; -class CBotRepeat : public CBotInstr -{ -private: - /// Number of iterations - CBotInstr* m_NbIter; - - /// Instructions - CBotInstr* m_Block; - - /// Label - CBotString m_label; // a label if there is - -public: - CBotRepeat(); - ~CBotRepeat(); - - /// Static method used for compilation - static CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack); - - /// Execute - bool Execute(CBotStack* &pj); - - /// Restore state - void RestoreState(CBotStack* &pj, bool bMain); -}; - class CBotDo : public CBotInstr { private: CBotInstr* m_Block; // instruction CBotInstr* m_Condition; // conditions - CBotString m_label; // a label if there is + CBotString m_label; // a label if there is public: CBotDo(); @@ -541,7 +514,7 @@ private: CBotInstr* m_Test; // test condition CBotInstr* m_Incr; // instruction for increment CBotInstr* m_Block; // instructions - CBotString m_label; // a label if there is + CBotString m_label; // a label if there is public: CBotFor(); @@ -555,7 +528,7 @@ public: class CBotBreak : public CBotInstr { private: - CBotString m_label; // a label if there is + CBotString m_label; // a label if there is public: CBotBreak(); @@ -569,7 +542,7 @@ public: class CBotReturn : public CBotInstr { private: - CBotInstr* m_Instr; // paramter of return + CBotInstr* m_Instr; // paramter of return public: CBotReturn(); @@ -584,7 +557,7 @@ public: class CBotSwitch : public CBotInstr { private: - CBotInstr* m_Value; // value to seek + CBotInstr* m_Value; // value to seek CBotInstr* m_Block; // instructions public: @@ -731,7 +704,7 @@ public: }; -// definition of a assignment list for a table +// definition of a assignment list for a table // int [ ] a [ ] = ( ( 1, 2, 3 ) , ( 3, 2, 1 ) ) ; class CBotListArray : public CBotInstr @@ -1442,12 +1415,12 @@ public: void IncrementUse(); // a reference to incrementation void DecrementUse(); // a reference to decrementation - CBotVarClass* + CBotVarClass* GetPointer(); void SetItemList(CBotVar* pVar); void SetIdent(long n); - + static CBotVarClass* Find(long id); @@ -1516,7 +1489,7 @@ public: void SetPointer(CBotVar* p); CBotVarClass* GetPointer(); - + void Copy(CBotVar* pSrc, bool bName=true); CBotVar* GetItem(int n, bool bGrow=false); // makes an element according to its numeric index // enlarged the table if necessary if bExtend @@ -1571,14 +1544,14 @@ private: CBotCall* m_next; public: - CBotCall(const char* name, - bool rExec (CBotVar* pVar, CBotVar* pResult, int& Exception, void* pUser), + CBotCall(const char* name, + bool rExec (CBotVar* pVar, CBotVar* pResult, int& Exception, void* pUser), CBotTypResult rCompile (CBotVar* &pVar, void* pUser)); ~CBotCall(); static - bool AddFunction(const char* name, - bool rExec (CBotVar* pVar, CBotVar* pResult, int& Exception, void* pUser), + bool AddFunction(const char* name, + bool rExec (CBotVar* pVar, CBotVar* pResult, int& Exception, void* pUser), CBotTypResult rCompile (CBotVar* &pVar, void* pUser)); static @@ -1599,7 +1572,7 @@ public: CBotString GetName(); CBotCall* Next(); - + static void SetPUser(void* pUser); static void Free(); }; @@ -1618,13 +1591,13 @@ private: long m_nFuncIdent; public: - CBotCallMethode(const char* name, - bool rExec (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception), + CBotCallMethode(const char* name, + bool rExec (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception), CBotTypResult rCompile (CBotVar* pThis, CBotVar* &pVar)); ~CBotCallMethode(); CBotTypResult - CompileCall(const char* name, CBotVar* pThis, + CompileCall(const char* name, CBotVar* pThis, CBotVar** ppVars, CBotCStack* pStack, long& nIdent); @@ -1633,7 +1606,7 @@ public: CBotString GetName(); CBotCallMethode* Next(); void AddNext(CBotCallMethode* p); - + }; // a list of parameters @@ -1730,4 +1703,3 @@ public: bool GetPosition(int& start, int& stop, CBotGet modestart, CBotGet modestop); }; - diff --git a/src/CBot/CBotAddExpr.cpp b/src/CBot/CBotAddExpr.cpp index 231f008..ec007ae 100644 --- a/src/CBot/CBotAddExpr.cpp +++ b/src/CBot/CBotAddExpr.cpp @@ -84,7 +84,7 @@ CBotInstr* CBotAddExpr::Compile(CBotToken* &p, CBotStack* pStack) return pStack->Return(NULL, pStk); } - // if we are not dealing with an operation + or - + // if we are not dealing with an operation + or - // goes to that requested, the operand (left) found // place the object "addition" return pStack->Return(left, pStk); @@ -141,4 +141,3 @@ bool CBotAddExpr::Execute(CBotStack* &pStack) return pStack->Return(pStk1); // transmits the result } - diff --git a/src/CBot/CBotClass.cpp b/src/CBot/CBotClass.cpp index a1c3fd4..12765ba 100644 --- a/src/CBot/CBotClass.cpp +++ b/src/CBot/CBotClass.cpp @@ -54,7 +54,7 @@ CBotClass::CBotClass(const char* name, CBotClass* pPapa, bool bIntrinsic) CBotClass::~CBotClass() { - // removes the list of class + // removes the list of class if ( m_ExPrev ) m_ExPrev->m_ExNext = m_ExNext; else m_ExClass = m_ExNext; @@ -106,7 +106,7 @@ bool CBotClass::Lock(CBotProgram* p) m_ProgInLock[0] = p; return true; } - if ( p == m_ProgInLock[0] ) + if ( p == m_ProgInLock[0] ) { m_cptOne++; m_cptLock--; // has already been counted @@ -156,14 +156,14 @@ void CBotClass::FreeLock(CBotProgram* p) while ( pClass != NULL ) { - if ( p == pClass->m_ProgInLock[0] ) + if ( p == pClass->m_ProgInLock[0] ) { pClass->m_cptLock -= pClass->m_cptOne; pClass->m_cptOne = 0; } for ( int j = 1; j < 5 ; j++ ) - if ( p == pClass->m_ProgInLock[j] ) + if ( p == pClass->m_ProgInLock[j] ) pClass->m_cptLock--; pClass = pClass->m_ExNext; @@ -291,8 +291,8 @@ CBotClass* CBotClass::Find(const char* name) return NULL; } -bool CBotClass::AddFunction(const char* name, - bool rExec (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception), +bool CBotClass::AddFunction(const char* name, + bool rExec (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception), CBotTypResult rCompile (CBotVar* pThis, CBotVar* &pVar)) { // stores pointers to the two functions @@ -313,7 +313,7 @@ bool CBotClass::AddFunction(const char* name, } p = new CBotCallMethode(name, rExec, rCompile); - + if (m_pCalls == NULL) m_pCalls = p; else m_pCalls->AddNext(p); // added to the list @@ -329,8 +329,8 @@ bool CBotClass::AddUpdateFunc( void rMaj ( CBotVar* pThis, void* pUser ) ) // compiles a method associated with an instance of class // the method can be declared by the user or AddFunction -CBotTypResult CBotClass::CompileMethode(const char* name, - CBotVar* pThis, CBotVar** ppParams, +CBotTypResult CBotClass::CompileMethode(const char* name, + CBotVar* pThis, CBotVar** ppParams, CBotCStack* pStack, long& nIdent) { nIdent = 0; // forget the previous one if necessary @@ -350,8 +350,8 @@ CBotTypResult CBotClass::CompileMethode(const char* name, // executes a method -bool CBotClass::ExecuteMethode(long& nIdent, const char* name, - CBotVar* pThis, CBotVar** ppParams, +bool CBotClass::ExecuteMethode(long& nIdent, const char* name, + CBotVar* pThis, CBotVar** ppParams, CBotVar* &pResult, CBotStack* &pStack, CBotToken* pToken) { @@ -437,7 +437,7 @@ bool CBotClass::RestoreStaticState(FILE* pf) if (!ReadString( pf, VarName )) return false; if ( pClass != NULL ) pVar = pClass->GetItem(VarName); - if (!CBotVar::RestoreState(pf, pv)) return false; // the temp variable + if (!CBotVar::RestoreState(pf, pv)) return false; // the temp variable if ( pVar != NULL ) pVar->Copy(pv); delete pv; @@ -514,7 +514,7 @@ CBotInstr* CBotClassInst::Compile(CBotToken* &p, CBotCStack* pStack, CBotClass* delete inst; // is not type CBotInt p = vartoken; // returns to the variable name - // compiles declaration an array + // compiles declaration an array inst = static_cast<CBotClassInst*>(CBotInstArray::Compile( p, pStk, type )); @@ -595,7 +595,7 @@ CBotInstr* CBotClassInst::Compile(CBotToken* &p, CBotCStack* pStack, CBotClass* goto error; } // if ( !bIntrinsic ) var->SetPointer(pStk->GetVar()->GetPointer()); - if ( !bIntrinsic ) + if ( !bIntrinsic ) { // does not use the result on the stack, to impose the class CBotVar* pvar = CBotVar::Create("", pClass); @@ -608,7 +608,7 @@ CBotInstr* CBotClassInst::Compile(CBotToken* &p, CBotCStack* pStack, CBotClass* { // creates the object on the "job" (\TODO "tas") // with a pointer to the object - if ( !bIntrinsic ) + if ( !bIntrinsic ) { CBotVar* pvar = CBotVar::Create("", pClass); var->SetPointer( pvar ); // variable already declared instance pointer @@ -617,14 +617,14 @@ CBotInstr* CBotClassInst::Compile(CBotToken* &p, CBotCStack* pStack, CBotClass* var->SetInit(2); // marks the pointer as init } suite: - if (IsOfType(p, ID_COMMA)) // several chained definitions + if (IsOfType(p, ID_COMMA)) // several chained definitions { if ( NULL != ( inst->m_next = CBotClassInst::Compile(p, pStk, pClass) )) // compiles the following { return pStack->Return(inst, pStk); } } - + if (IsOfType(p, ID_SEP)) // complete instruction { return pStack->Return(inst, pStk); @@ -684,7 +684,7 @@ bool CBotClassInst::Execute(CBotStack* &pj) { // evaluates the expression for the assignment if (!m_expr->Execute(pile)) return false; - + if ( bIntrincic ) { CBotVar* pv = pile->GetVar(); @@ -750,8 +750,8 @@ bool CBotClassInst::Execute(CBotStack* &pj) // creates a variable for the result CBotVar* pResult = NULL; // constructor still void - if ( !pClass->ExecuteMethode(m_nMethodeIdent, pClass->GetName(), - pThis, ppVars, + if ( !pClass->ExecuteMethode(m_nMethodeIdent, pClass->GetName(), + pThis, ppVars, pResult, pile2, GetToken())) return false; // interrupt pThis->SetInit(true); diff --git a/src/CBot/CBotCompExpr.cpp b/src/CBot/CBotCompExpr.cpp index 2daf53f..c9a977c 100644 --- a/src/CBot/CBotCompExpr.cpp +++ b/src/CBot/CBotCompExpr.cpp @@ -83,7 +83,7 @@ CBotInstr* CBotCompExpr::Compile(CBotToken* &p, CBotCStack* pStack) } -// perform the operation +// perform the operation bool CBotCompExpr::Execute(CBotStack* &pStack) { diff --git a/src/CBot/CBotDll.h b/src/CBot/CBotDll.h index b401528..8858559 100644 --- a/src/CBot/CBotDll.h +++ b/src/CBot/CBotDll.h @@ -93,22 +93,22 @@ public: CBotTypResult(int type); // for simple types (CBotTypInt à CBotTypString) - + CBotTypResult(int type, const char* name); // for pointer types and intrinsic classes - + CBotTypResult(int type, CBotClass* pClass); // for the instance of a class - + CBotTypResult(int type, CBotTypResult elem); // for arrays of variables - + CBotTypResult(const CBotTypResult& typ); // for assignments - + CBotTypResult(); // for default - + ~CBotTypResult(); int GetType(int mode = 0) const; @@ -147,7 +147,7 @@ private: CBotClass* m_pClass; // for the derivatives of class int m_limite; // limits of tables friend class CBotVarClass; - friend class CBotVarPointer; + friend class CBotVarPointer; }; /* @@ -246,7 +246,7 @@ private: //////////////////////////////////////////////////////////////////////// -// +// // as part of MFC CString not used here. // // ( all functions are not implemented yet ) @@ -451,12 +451,12 @@ public: static void SetTimer(int n); - // defines the number of steps (parts of instructions) to done + // defines the number of steps (parts of instructions) to done // in Run() before rendering hand "false" \TODO avant de rendre la main "false" static - bool AddFunction(const char* name, - bool rExec (CBotVar* pVar, CBotVar* pResult, int& Exception, void* pUser), + bool AddFunction(const char* name, + bool rExec (CBotVar* pVar, CBotVar* pResult, int& Exception, void* pUser), CBotTypResult rCompile (CBotVar* &pVar, void* pUser)); // call this to add externally (**) // a new function used by the program CBoT @@ -472,8 +472,8 @@ public: // restores the state of execution from file // the compiled program must obviously be the same - bool GetPosition(const char* name, int& start, int& stop, - CBotGet modestart = GetPosExtern, + bool GetPosition(const char* name, int& start, int& stop, + CBotGet modestart = GetPosExtern, CBotGet modestop = GetPosBloc); // gives the position of a routine in the original text // the user can select the item to find from the beginning to the end @@ -513,7 +513,7 @@ int cMean(CBotVar* &pVar, CBotString& ClassName) while ( pVar != NULL ) { - if ( pVar->GetType() > CBotTypDouble ) return 6002; // this is not a number + if ( pVar->GetType() > CBotTypDouble ) return 6002; // this is not a number pVar = pVar -> GetNext(); } @@ -623,7 +623,7 @@ virtual ~CBotVar( ); // destructor void SetName(const char* name); // changes the name of the variable int GetType(int mode = 0); // returns the base type (int) of the variable - // TODO check it + // TODO check it //////////////////////////////////////////////////////////////////////////////////////// CBotTypResult GetTypResult(int mode = 0); // returns the complete type of the variable @@ -654,7 +654,7 @@ virtual ~CBotVar( ); // destructor CBotVar* GetItemRef(int nIdent); // idem à partir du n° ref // TODO ditto from ref no. virtual - CBotVar* GetItem(int row, bool bGrow = false); + CBotVar* GetItem(int row, bool bGrow = false); virtual CBotVar* GetItemList(); // lists the elements @@ -802,8 +802,8 @@ public: ~CBotClass( ); // destructor - bool AddFunction(const char* name, - bool rExec (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception), + bool AddFunction(const char* name, + bool rExec (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception), CBotTypResult rCompile (CBotVar* pThis, CBotVar* &pVar)); // this call allows to add as external (**) // new method used by the objects of this class @@ -841,7 +841,7 @@ public: CBotVar* GetItem(const char* name); // one of the variables according to its name CBotVar* GetItemRef(int nIdent); - CBotTypResult CompileMethode(const char* name, CBotVar* pThis, CBotVar** ppParams, + CBotTypResult CompileMethode(const char* name, CBotVar* pThis, CBotVar** ppParams, CBotCStack* pStack, long& nIdent); bool ExecuteMethode(long& nIdent, const char* name, CBotVar* pThis, CBotVar** ppParams, CBotVar* &pResult, CBotStack* &pStack, CBotToken* pToken); @@ -854,7 +854,7 @@ public: CBotClass* Compile1(CBotToken* &p, CBotCStack* pStack); bool CompileDefItem(CBotToken* &p, CBotCStack* pStack, bool bSecond); - + bool IsIntrinsic(); void Purge(); static @@ -917,7 +917,7 @@ private: int m_start; // position in the original text (program) int m_end; // the same for the end of the token - + /** * \brief Check whether given parameter is a keyword */ @@ -979,11 +979,11 @@ public: CBotToken* GetPrev(); /** - * \brief transforms the entire program + * \brief transforms the entire program */ static CBotToken* CompileTokens(const char* p, int& error); - + /** * \brief releases the list */ diff --git a/src/CBot/CBotFunction.cpp b/src/CBot/CBotFunction.cpp index 28db24e..862554e 100644 --- a/src/CBot/CBotFunction.cpp +++ b/src/CBot/CBotFunction.cpp @@ -28,7 +28,7 @@ CBotFunction::CBotFunction() m_Param = NULL; // empty parameter list m_Block = NULL; // the instruction block m_next = NULL; // functions can be chained - m_bPublic = false; // function not public + m_bPublic = false; // function not public m_bExtern = false; // function not extern m_nextpublic = NULL; m_prevpublic = NULL; @@ -159,9 +159,9 @@ CBotTypResult TypeParam(CBotToken* &p, CBotCStack* pile) if ( pClass != NULL) { p = p->GetNext(); - return ArrayType(p, pile, - pClass->IsIntrinsic() ? - CBotTypResult( CBotTypIntrinsic, pClass ) : + return ArrayType(p, pile, + pClass->IsIntrinsic() ? + CBotTypResult( CBotTypIntrinsic, pClass ) : CBotTypResult( CBotTypPointer, pClass ) ); } } @@ -261,7 +261,7 @@ CBotFunction* CBotFunction::Compile(CBotToken* &p, CBotCStack* pStack, CBotFunct } } - // and compiles the following instruction block + // and compiles the following instruction block func->m_openblk = p; func->m_Block = CBotBlock::Compile(p, pStk, false); func->m_closeblk = p->GetPrev(); @@ -288,7 +288,7 @@ CBotFunction* CBotFunction::Compile1(CBotToken* &p, CBotCStack* pStack, CBotClas { CBotFunction* func = new CBotFunction(); func->m_nFuncIdent = CBotVar::NextUniqNum(); - + CBotCStack* pStk = pStack->TokenStack(p, true); while (true) @@ -334,7 +334,7 @@ CBotFunction* CBotFunction::Compile1(CBotToken* &p, CBotCStack* pStack, CBotClas func->m_Param = CBotDefParam::Compile( p, pStk ); if (pStk->IsOk()) { - // looks if the function exists elsewhere + // looks if the function exists elsewhere if (( pClass != NULL || !pStack->CheckCall(pp, func->m_Param)) && ( pClass == NULL || !pClass->CheckCall(pp, func->m_Param)) ) { @@ -350,7 +350,7 @@ CBotFunction* CBotFunction::Compile1(CBotToken* &p, CBotCStack* pStack, CBotClas if (type == ID_CLBLK) level--; } while (level > 0 && p != NULL); - + return pStack->ReturnFunc(func, pStk); } pStk->SetError(TX_OPENBLK, p); @@ -528,7 +528,7 @@ CBotFunction* CBotFunction::FindLocalOrPublic(long& nIdent, const char* name, CB pv = pv->GetNext(); pw = ppVars[i++]; } - if ( pw != NULL ) + if ( pw != NULL ) { if ( pFunc != NULL ) continue; if ( TypeOrError.Eq(TX_LOWPARAM) ) TypeOrError.SetType(TX_NUMPARAM); @@ -583,7 +583,7 @@ CBotFunction* CBotFunction::FindLocalOrPublic(long& nIdent, const char* name, CB pv = pv->GetNext(); pw = ppVars[i++]; } - if ( pw != NULL ) + if ( pw != NULL ) { if ( pFunc != NULL ) continue; if ( TypeOrError.Eq(TX_LOWPARAM) ) TypeOrError.SetType(TX_NUMPARAM); @@ -630,7 +630,7 @@ int CBotFunction::DoCall(long& nIdent, const char* name, CBotVar** ppVars, CBotS { CBotTypResult type; CBotFunction* pt = NULL; - + pt = FindLocalOrPublic(nIdent, name, ppVars, type); if ( pt != NULL ) @@ -754,7 +754,7 @@ void CBotFunction::RestoreCall(long& nIdent, const char* name, CBotVar** ppVars, -// makes call of a method +// makes call of a method // note: this is already on the stack, the pointer pThis is just to simplify int CBotFunction::DoCall(long& nIdent, const char* name, CBotVar* pThis, CBotVar** ppVars, CBotStack* pStack, CBotToken* pToken, CBotClass* pClass) @@ -951,7 +951,7 @@ CBotDefParam* CBotDefParam::Compile(CBotToken* &p, CBotCStack* pStack) if (IsOfType(p, ID_OPENPAR)) { CBotDefParam* list = NULL; - + while (!IsOfType(p, ID_CLOSEPAR)) { CBotDefParam* param = new CBotDefParam(); @@ -1090,7 +1090,7 @@ CBotDefParam* CBotDefParam::GetNext() CBotString CBotDefParam::GetParamString() { CBotString param; - + param = m_typename; param += ' '; @@ -1136,7 +1136,7 @@ CBotInstr* CBotReturn::Compile(CBotToken* &p, CBotCStack* pStack) if ( pStack->IsOk() ) { CBotTypResult retType = pStack->GetTypResult(2); - if (TypeCompatible(retType, type, ID_ASS)) + if (TypeCompatible(retType, type, ID_ASS)) { if ( IsOfType( p, ID_SEP ) ) return inst; @@ -1202,7 +1202,7 @@ CBotInstr* CBotInstrCall::Compile(CBotToken* &p, CBotCStack* pStack) int i = 0; - CBotToken* pp = p; + CBotToken* pp = p; p = p->GetNext(); pStack->SetStartError(p->GetStart()); @@ -1367,7 +1367,7 @@ CBotClass* CBotClass::Compile1(CBotToken* &p, CBotCStack* pStack) pStack->SetError(TX_NOPUBLIC, p); return NULL; } - + if ( !IsOfType(p, ID_CLASS) ) return NULL; CBotString name = p->GetString(); @@ -1443,7 +1443,7 @@ bool CBotClass::CompileDefItem(CBotToken* &p, CBotCStack* pStack, bool bSecond) return false; } - while (pStack->IsOk()) + while (pStack->IsOk()) { CBotToken* pp = p; IsOfType(p, ID_NOT); // skips ~ eventual (destructor) @@ -1484,7 +1484,7 @@ bool CBotClass::CompileDefItem(CBotToken* &p, CBotCStack* pStack, bool bSecond) if ( !bSecond ) { p = pBase; - CBotFunction* f = + CBotFunction* f = CBotFunction::Compile1(p, pStack, this); if ( f == NULL ) return false; @@ -1497,7 +1497,7 @@ bool CBotClass::CompileDefItem(CBotToken* &p, CBotCStack* pStack, bool bSecond) // return a method precompiled in pass 1 CBotFunction* pf = m_pMethod; CBotFunction* prev = NULL; - while ( pf != NULL ) + while ( pf != NULL ) { if (pf->GetName() == pp->GetString()) break; prev = pf; @@ -1541,7 +1541,7 @@ bool CBotClass::CompileDefItem(CBotToken* &p, CBotCStack* pStack, bool bSecond) // compiles a method p = pBase; - CBotFunction* f = + CBotFunction* f = CBotFunction::Compile(p, pile, NULL/*, false*/); if ( f != NULL ) @@ -1646,3 +1646,4 @@ CBotClass* CBotClass::Compile(CBotToken* &p, CBotCStack* pStack) pStack->SetError(TX_ENDOF, p); return NULL; } + diff --git a/src/CBot/CBotIf.cpp b/src/CBot/CBotIf.cpp index a5d2693..bc58af1 100644 --- a/src/CBot/CBotIf.cpp +++ b/src/CBot/CBotIf.cpp @@ -109,7 +109,7 @@ bool CBotIf :: Execute(CBotStack* &pj) // passes into the second state if (!pile->SetState(1)) return false; // ready for further } - + // second state, evaluates the associated instructions // the result of the condition is on the stack @@ -143,7 +143,7 @@ void CBotIf :: RestoreState(CBotStack* &pj, bool bMain) m_Condition->RestoreState(pile, bMain); // interrupted here! return; } - + // second state, evaluates the associated instructions // the result of the condition is on the stack diff --git a/src/CBot/CBotProgram.cpp b/src/CBot/CBotProgram.cpp index f4987a7..1944f92 100644 --- a/src/CBot/CBotProgram.cpp +++ b/src/CBot/CBotProgram.cpp @@ -97,7 +97,7 @@ bool CBotProgram::Compile( const char* program, CBotStringArray& ListFonctions, { if ( IsOfType(p, ID_SEP) ) continue; // semicolons lurking - if ( p->GetType() == ID_CLASS || + if ( p->GetType() == ID_CLASS || ( p->GetType() == ID_PUBLIC && p->GetNext()->GetType() == ID_CLASS )) { CBotClass* nxt = CBotClass::Compile1(p, pStack); @@ -113,7 +113,7 @@ bool CBotProgram::Compile( const char* program, CBotStringArray& ListFonctions, } if ( !pStack->IsOk() ) { - m_ErrorCode = pStack->GetError(m_ErrorStart, m_ErrorEnd); + m_ErrorCode = pStack->GetError(m_ErrorStart, m_ErrorEnd); delete m_Prog; m_Prog = NULL; delete pBaseToken; @@ -129,7 +129,7 @@ bool CBotProgram::Compile( const char* program, CBotStringArray& ListFonctions, { if ( IsOfType(p, ID_SEP) ) continue; // semicolons lurking - if ( p->GetType() == ID_CLASS || + if ( p->GetType() == ID_CLASS || ( p->GetType() == ID_PUBLIC && p->GetNext()->GetType() == ID_CLASS )) { m_bCompileClass = true; @@ -150,7 +150,7 @@ bool CBotProgram::Compile( const char* program, CBotStringArray& ListFonctions, if ( !pStack->IsOk() ) { - m_ErrorCode = pStack->GetError(m_ErrorStart, m_ErrorEnd); + m_ErrorCode = pStack->GetError(m_ErrorStart, m_ErrorEnd); delete m_Prog; m_Prog = NULL; } @@ -228,7 +228,7 @@ bool CBotProgram::Run(void* pUser, int timer) #if STACKRUN // resumes execution on the top of the stack ok = m_pStack->Execute(); - if ( ok ) + if ( ok ) { #ifdef _DEBUG CBotVar* ppVar[3]; @@ -354,8 +354,8 @@ CBotFunction* CBotProgram::GetFunctions() return m_Prog; } -bool CBotProgram::AddFunction(const char* name, - bool rExec (CBotVar* pVar, CBotVar* pResult, int& Exception, void* pUser), +bool CBotProgram::AddFunction(const char* name, + bool rExec (CBotVar* pVar, CBotVar* pResult, int& Exception, void* pUser), CBotTypResult rCompile (CBotVar* &pVar, void* pUser)) { // stores pointers to the two functions @@ -369,7 +369,7 @@ bool WriteWord(FILE* pf, unsigned short w) lg = fwrite(&w, sizeof( unsigned short ), 1, pf ); - return (lg == 1); + return (lg == 1); } bool ReadWord(FILE* pf, unsigned short& w) @@ -387,7 +387,7 @@ bool WriteFloat(FILE* pf, float w) lg = fwrite(&w, sizeof( float ), 1, pf ); - return (lg == 1); + return (lg == 1); } bool ReadFloat(FILE* pf, float& w) @@ -405,7 +405,7 @@ bool WriteLong(FILE* pf, long w) lg = fwrite(&w, sizeof( long ), 1, pf ); - return (lg == 1); + return (lg == 1); } bool ReadLong(FILE* pf, long& w) @@ -425,7 +425,7 @@ bool WriteString(FILE* pf, CBotString s) if (!WriteWord(pf, lg1)) return false; lg2 = fwrite(s, 1, lg1, pf ); - return (lg1 == lg2); + return (lg1 == lg2); } bool ReadString(FILE* pf, CBotString& s) @@ -510,7 +510,7 @@ bool CBotProgram::SaveState(FILE* pf) if (!WriteString( pf, m_pRun->GetName() )) return false; if (!m_pStack->SaveState(pf)) return false; } - else + else { if (!WriteWord( pf, 0)) return false; } @@ -560,9 +560,9 @@ int CBotProgram::GetVersion() ////////////////////////////////////////////////////////////////////////////////////////////////////// CBotCall* CBotCall::m_ListCalls = NULL; - -CBotCall::CBotCall(const char* name, - bool rExec (CBotVar* pVar, CBotVar* pResult, int& Exception, void* pUser), + +CBotCall::CBotCall(const char* name, + bool rExec (CBotVar* pVar, CBotVar* pResult, int& Exception, void* pUser), CBotTypResult rCompile (CBotVar* &pVar, void* pUser)) { m_name = name; @@ -583,8 +583,8 @@ void CBotCall::Free() delete CBotCall::m_ListCalls; } -bool CBotCall::AddFunction(const char* name, - bool rExec (CBotVar* pVar, CBotVar* pResult, int& Exception, void* pUser), +bool CBotCall::AddFunction(const char* name, + bool rExec (CBotVar* pVar, CBotVar* pResult, int& Exception, void* pUser), CBotTypResult rCompile (CBotVar* &pVar, void* pUser)) { CBotCall* p = m_ListCalls; @@ -608,7 +608,7 @@ bool CBotCall::AddFunction(const char* name, } pp = new CBotCall(name, rExec, rCompile); - + if (p) p->m_next = pp; else m_ListCalls = pp; @@ -658,7 +658,7 @@ CBotTypResult CBotCall::CompileCall(CBotToken* &p, CBotVar** ppVar, CBotCStack* CBotVar* pVar2 = pVar; CBotTypResult r = pt->m_rComp(pVar2, m_pUser); int ret = r.GetType(); - + // if a class is returned, it is actually a pointer if ( ret == CBotTypClass ) r.SetType( ret = CBotTypPointer ); @@ -859,8 +859,8 @@ bool CBotCall::Run(CBotStack* pStack) /////////////////////////////////////////////////////////////////////////////////////// -CBotCallMethode::CBotCallMethode(const char* name, - bool rExec (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception), +CBotCallMethode::CBotCallMethode(const char* name, + bool rExec (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception), CBotTypResult rCompile (CBotVar* pThis, CBotVar* &pVar)) { m_name = name; @@ -879,7 +879,7 @@ CBotCallMethode::~CBotCallMethode() // is acceptable by a call procedure name // and given parameters -CBotTypResult CBotCallMethode::CompileCall(const char* name, CBotVar* pThis, +CBotTypResult CBotCallMethode::CompileCall(const char* name, CBotVar* pThis, CBotVar** ppVar, CBotCStack* pStack, long& nIdent) { @@ -1008,7 +1008,7 @@ bool rSizeOf( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser ) while ( pVar != NULL ) { - i++; + i++; pVar = pVar->GetNext(); } @@ -1107,7 +1107,7 @@ void CBotProgram::Init() void CBotProgram::Free() { - CBotToken::Free() ; + CBotToken::Free() ; CBotCall ::Free() ; CBotClass::Free() ; } diff --git a/src/CBot/CBotStack.cpp b/src/CBot/CBotStack.cpp index 67f2000..086442d 100644 --- a/src/CBot/CBotStack.cpp +++ b/src/CBot/CBotStack.cpp @@ -63,7 +63,7 @@ CBotStack* CBotStack::FirstStack() pp->m_bOver = true; pp ++; } -#ifdef _DEBUG +#ifdef _DEBUG int n = 1; pp = p; for ( i = 0 ; i< MAXSTACK+10 ; i++ ) @@ -120,7 +120,7 @@ void CBotStack::Delete() m_index = n; #endif - if ( p == NULL ) + if ( p == NULL ) free( this ); } @@ -128,7 +128,7 @@ void CBotStack::Delete() // routine improved CBotStack* CBotStack::AddStack(CBotInstr* instr, bool bBlock) { - if (m_next != NULL) + if (m_next != NULL) { return m_next; // included in an existing stack } @@ -160,7 +160,7 @@ CBotStack* CBotStack::AddStack(CBotInstr* instr, bool bBlock) CBotStack* CBotStack::AddStackEOX(CBotCall* instr, bool bBlock) { - if (m_next != NULL) + if (m_next != NULL) { if ( m_next == EOX ) { @@ -177,7 +177,7 @@ CBotStack* CBotStack::AddStackEOX(CBotCall* instr, bool bBlock) CBotStack* CBotStack::AddStack2(bool bBlock) { - if (m_next2 != NULL) + if (m_next2 != NULL) { m_next2->m_prog = m_prog; // special avoids RestoreStack2 return m_next2; // included in an existing stack @@ -251,8 +251,8 @@ CBotStack::CBotStack(CBotStack* ppapa) if (ppapa == NULL) m_timer = m_initimer; // sets the timer at the beginning m_listVar = NULL; - m_bDontDelete = false; - + m_bDontDelete = false; + m_var = NULL; m_prog = NULL; m_instr = NULL; @@ -275,7 +275,7 @@ CBotStack::~CBotStack() // \TODO routine has/to optimize CBotStack* CBotStack::AddStack(CBotInstr* instr, bool bBlock) { - if (m_next != NULL) + if (m_next != NULL) { return m_next; // included in an existing stack } @@ -290,7 +290,7 @@ CBotStack* CBotStack::AddStack(CBotInstr* instr, bool bBlock) CBotStack* CBotStack::AddStackEOX(CBotCall* instr, bool bBlock) { - if (m_next != NULL) + if (m_next != NULL) { if ( m_next == EOX ) { @@ -311,7 +311,7 @@ CBotStack* CBotStack::AddStackEOX(CBotCall* instr, bool bBlock) CBotStack* CBotStack::AddStack2(bool bBlock) { - if (m_next2 != NULL) + if (m_next2 != NULL) { m_next2->m_prog = m_prog; // special avoids RestoreStack2 return m_next2; // included in an existing stack @@ -362,7 +362,7 @@ void CBotStack::Reset(void* pUser) CBotStack* CBotStack::RestoreStack(CBotInstr* instr) { - if (m_next != NULL) + if (m_next != NULL) { m_next->m_instr = instr; // reset (if recovery after ) m_next->m_prog = m_prog; @@ -480,7 +480,7 @@ CBotVar* CBotStack::FindVar(CBotToken* &pToken, bool bUpdate, bool bModif) { if (pp->GetName() == name) { - if ( bUpdate ) + if ( bUpdate ) pp->Maj(m_pUser, false); return pp; @@ -521,7 +521,7 @@ CBotVar* CBotStack::FindVar(long ident, bool bUpdate, bool bModif) { if (pp->GetUniqNum() == ident) { - if ( bUpdate ) + if ( bUpdate ) pp->Maj(m_pUser, false); return pp; @@ -552,7 +552,7 @@ CBotVar* CBotStack::CopyVar(CBotToken& Token, bool bUpdate) return pCopy; } - + bool CBotStack::SetState(int n, int limite) { m_state = n; @@ -609,7 +609,7 @@ bool CBotStack::Execute() while (p != NULL) { if ( p->m_next2 != NULL ) break; - if ( p->m_call != NULL ) + if ( p->m_call != NULL ) { instr = p->m_call; pile = p->m_prev ; @@ -684,7 +684,7 @@ void CBotStack::AddVar(CBotVar* pVar) while (p != NULL && p->m_bBlock == 0) p = p->m_prev; if ( p == NULL ) return; - + /// p->m_bDontDelete = bDontDelete; CBotVar** pp = &p->m_listVar; @@ -787,7 +787,7 @@ void CBotStack::GetRunPos(const char* &FunctionName, int &start, int &end) { if ( p->m_instr != NULL ) instr = p->m_instr; if ( p->m_bFunc == 1 ) funct = p->m_instr; - if ( p->m_next->m_prog != prog ) break ; + if ( p->m_next->m_prog != prog ) break ; if (p->m_next2 && p->m_next2->m_state != 0) p = p->m_next2 ; else p = p->m_next; @@ -818,7 +818,7 @@ CBotVar* CBotStack::GetStackVars(const char* &FunctionName, int level) while (p->m_next != NULL) { - if ( p->m_next->m_prog != prog ) break ; + if ( p->m_next->m_prog != prog ) break ; if (p->m_next2 && p->m_next2->m_state != 0) p = p->m_next2 ; else p = p->m_next; @@ -848,7 +848,7 @@ CBotVar* CBotStack::GetStackVars(const char* &FunctionName, int level) CBotToken* t = pp->m_instr->GetToken(); FunctionName = t->GetString(); - + return p->m_listVar; } @@ -872,8 +872,8 @@ bool CBotStack::SaveState(FILE* pf) if (!WriteWord(pf, m_state)) return false; // in what state? if (!WriteWord(pf, 0)) return false; // by compatibility m_bDontDelete if (!WriteWord(pf, m_step)) return false; // in what state? - - + + if (!SaveVar(pf, m_var)) return false; // current result if (!SaveVar(pf, m_listVar)) return false; // local variables @@ -921,7 +921,7 @@ bool CBotStack::RestoreState(FILE* pf, CBotStack* &pStack) bool CBotVar::Save0State(FILE* pf) -{ +{ if (!WriteWord(pf, 100+m_mPrivate))return false; // private variable? if (!WriteWord(pf, m_bStatic))return false; // static variable? if (!WriteWord(pf, m_type.GetType()))return false; // saves the type (always non-zero) @@ -930,11 +930,11 @@ bool CBotVar::Save0State(FILE* pf) } bool CBotVarInt::Save0State(FILE* pf) -{ +{ if ( !m_defnum.IsEmpty() ) { if(!WriteWord(pf, 200 )) return false; // special marker - if(!WriteString(pf, m_defnum)) return false; // name of the value + if(!WriteString(pf, m_defnum)) return false; // name of the value } return CBotVar::Save0State(pf); @@ -1051,7 +1051,7 @@ bool CBotVar::RestoreState(FILE* pf, CBotVar* &pVar) if ( p != NULL ) { delete pNew; - pNew = p; // resume known element + pNew = p; // resume known element } } } @@ -1167,7 +1167,7 @@ CBotCStack* CBotCStack::TokenStack(CBotToken* pToken, bool bBlock) CBotInstr* CBotCStack::Return(CBotInstr* inst, CBotCStack* pfils) -{ +{ if ( pfils == this ) return inst; if (m_var != NULL) delete m_var; // value replaced? @@ -1185,7 +1185,7 @@ CBotInstr* CBotCStack::Return(CBotInstr* inst, CBotCStack* pfils) } CBotFunction* CBotCStack::ReturnFunc(CBotFunction* inst, CBotCStack* pfils) -{ +{ if (m_var != NULL) delete m_var; // value replaced? m_var = pfils->m_var; // result transmitted pfils->m_var = NULL; // not to destroy the variable @@ -1292,7 +1292,7 @@ bool CBotCStack::IsOk() return (m_error == 0); } - + void CBotCStack::SetStartError( int pos ) { if ( m_error != 0) return; // does not change existing error diff --git a/src/CBot/CBotString.cpp b/src/CBot/CBotString.cpp index b1b5fc4..2929977 100644 --- a/src/CBot/CBotString.cpp +++ b/src/CBot/CBotString.cpp @@ -54,7 +54,6 @@ const std::map<EID,const char *> CBotString::s_keywordString = {ID_STATIC, "static"}, {ID_PROTECTED, "protected"}, {ID_PRIVATE, "private"}, - {ID_REPEAT, "repeat"}, {ID_DEBUGDD, "STARTDEBUGDD"}, {ID_INT, "int"}, {ID_FLOAT, "float"}, @@ -162,7 +161,7 @@ CBotString::CBotString(const CBotString& srcString) int CBotString::GetLength() { if (m_ptr == NULL) return 0; - return strlen( m_ptr ); + return strlen( m_ptr ); } @@ -337,7 +336,7 @@ const CBotString& CBotString::operator=(const CBotString& stringSrc) delete[] m_ptr; m_ptr = nullptr; - m_lg = stringSrc.m_lg; + m_lg = stringSrc.m_lg; if (m_lg > 0) { @@ -374,7 +373,7 @@ const CBotString& CBotString::operator=(const char ch) { delete[] m_ptr; - m_lg = 1; + m_lg = 1; m_ptr = new char[2]; m_ptr[0] = ch; @@ -390,7 +389,7 @@ const CBotString& CBotString::operator=(const char* pString) if (pString != nullptr) { - m_lg = strlen(pString); + m_lg = strlen(pString); if (m_lg != 0) { @@ -521,7 +520,7 @@ int CBotString::Compare(const char * lpsz) const char* p = m_ptr; if (lpsz == NULL) lpsz = emptyString; if (m_ptr == NULL) p = emptyString; - return strcmp(p, lpsz); // wcscmp + return strcmp(p, lpsz); // wcscmp } const char * CBotString::MapIdToString(EID id) diff --git a/src/CBot/CBotToken.cpp b/src/CBot/CBotToken.cpp index f03ca91..48033a3 100644 --- a/src/CBot/CBotToken.cpp +++ b/src/CBot/CBotToken.cpp @@ -248,17 +248,15 @@ CBotToken* CBotToken::NextToken(char* &program, int& error, bool first) { while (c != 0 && !CharInList(c, nch)) { - mot += c; - c = *(program++); // next character if ( c == '\\' ) { c = *(program++); // next character if ( c == 'n' ) c = '\n'; if ( c == 'r' ) c = '\r'; if ( c == 't' ) c = '\t'; - mot += c; - c = *(program++); // next character } + mot += c; + c = *(program++); } if ( c == '\"' ) { @@ -474,7 +472,7 @@ void CBotToken::LoadKeyWords() { CBotString s; int i, n = 0; - + i = TokenKeyWord; //start with keywords of the language while (s.LoadString(i)) { diff --git a/src/CBot/CBotToken.h b/src/CBot/CBotToken.h index 6f11bb2..a423375 100644 --- a/src/CBot/CBotToken.h +++ b/src/CBot/CBotToken.h @@ -36,3 +36,4 @@ extern bool IsOfType(CBotToken* &p, int type1, int type2 = -1); extern bool IsOfTypeList(CBotToken* &p, int type1, ...); + diff --git a/src/CBot/CBotTwoOpExpr.cpp b/src/CBot/CBotTwoOpExpr.cpp index dfaed9f..6a0d636 100644 --- a/src/CBot/CBotTwoOpExpr.cpp +++ b/src/CBot/CBotTwoOpExpr.cpp @@ -63,10 +63,10 @@ CBotLogicExpr::~CBotLogicExpr() // acceptable type, operand // zero ends level \TODO précéance -static int ListOp[] = +static int ListOp[] = { BOOLEEN, ID_LOGIC, 0, - BOOLEEN, ID_TXT_OR, + BOOLEEN, ID_TXT_OR, BOOLEEN, ID_LOG_OR, 0, BOOLEEN, ID_TXT_AND, BOOLEEN, ID_LOG_AND, 0, @@ -76,7 +76,7 @@ static int ListOp[] = BOOLEEN|ENTIER|FLOTANT |CHAINE |POINTER - |INSTANCE,ID_EQ, + |INSTANCE,ID_EQ, BOOLEEN|ENTIER|FLOTANT |CHAINE |POINTER @@ -90,8 +90,8 @@ static int ListOp[] = ENTIER, ID_ASR, 0, ENTIER|FLOTANT|CHAINE, ID_ADD, ENTIER|FLOTANT, ID_SUB, 0, - ENTIER|FLOTANT, ID_MUL, - ENTIER|FLOTANT, ID_DIV, + ENTIER|FLOTANT, ID_MUL, + ENTIER|FLOTANT, ID_DIV, ENTIER|FLOTANT, ID_MODULO, 0, ENTIER|FLOTANT, ID_POWER, 0, 0, @@ -194,7 +194,7 @@ CBotInstr* CBotTwoOpExpr::Compile(CBotToken* &p, CBotCStack* pStack, int* pOpera if ( NULL != (inst->m_rightop = CBotTwoOpExpr::Compile( p, pStk, pOp )) ) // expression (...) right { - // there is an second operand acceptable + // there is an second operand acceptable type2 = pStk->GetTypResult(); // what kind of results? @@ -327,7 +327,7 @@ bool CBotTwoOpExpr::Execute(CBotStack* &pStack) } - // requires a little more stack to avoid touching the result + // requires a little more stack to avoid touching the result // of which is left on the stack, precisely CBotStack* pStk2 = pStk1->AddStack(); // adds an item to the stack @@ -566,3 +566,4 @@ void t(bool t) t ? 0 : "test"; } #endif + diff --git a/src/CBot/CBotVar.cpp b/src/CBot/CBotVar.cpp index 7b0ce7b..ad3708d 100644 --- a/src/CBot/CBotVar.cpp +++ b/src/CBot/CBotVar.cpp @@ -134,8 +134,8 @@ void CBotVarClass::InitCBotVarClass( const CBotToken* name, CBotTypResult& type m_LimExpr = NULL; m_pVar = NULL; m_type = type; - if ( type.Eq(CBotTypArrayPointer) ) m_type.SetType( CBotTypArrayBody ); - else if ( !type.Eq(CBotTypArrayBody) ) m_type.SetType( CBotTypClass ); + if ( type.Eq(CBotTypArrayPointer) ) m_type.SetType( CBotTypArrayBody ); + else if ( !type.Eq(CBotTypArrayBody) ) m_type.SetType( CBotTypClass ); // officel type for this object m_pClass = NULL; @@ -394,7 +394,7 @@ CBotVar* CBotVar::Create( const char* n, CBotTypResult type) CBotVarClass* instance = new CBotVarClass(&name, type); CBotVarArray* array = new CBotVarArray(&name, type); array->SetPointer( instance ); - + CBotVar* pv = array; while (type.Eq(CBotTypArrayBody)) { @@ -414,14 +414,14 @@ CBotVar* CBotVar::Create( const char* name, int type, CBotClass* pClass) { CBotToken token( name, "" ); CBotVar* pVar = Create( &token, type ); - + if ( type == CBotTypPointer && pClass == NULL ) // pointer "null" ? return pVar; if ( type == CBotTypClass || type == CBotTypPointer || type == CBotTypIntrinsic ) { - if (pClass == NULL) + if (pClass == NULL) { delete pVar; return NULL; @@ -443,9 +443,9 @@ CBotTypResult CBotVar::GetTypResult(int mode) { CBotTypResult r = m_type; - if ( mode == 1 && m_type.Eq(CBotTypClass) ) + if ( mode == 1 && m_type.Eq(CBotTypClass) ) r.SetType(CBotTypPointer); - if ( mode == 2 && m_type.Eq(CBotTypClass) ) + if ( mode == 2 && m_type.Eq(CBotTypClass) ) r.SetType(CBotTypIntrinsic); return r; @@ -453,9 +453,9 @@ CBotTypResult CBotVar::GetTypResult(int mode) int CBotVar::GetType(int mode) { - if ( mode == 1 && m_type.Eq(CBotTypClass) ) + if ( mode == 1 && m_type.Eq(CBotTypClass) ) return CBotTypPointer; - if ( mode == 2 && m_type.Eq(CBotTypClass) ) + if ( mode == 2 && m_type.Eq(CBotTypClass) ) return CBotTypIntrinsic; return m_type.GetType(); } @@ -620,7 +620,7 @@ void CBotVar::SetVal(CBotVar* var) ASM_TRAP(); } - m_binit = var->m_binit; // copie l'état nan s'il y a + m_binit = var->m_binit; // copie l'état nan s'il y a } void CBotVar::SetStatic(bool bStatic) @@ -1293,7 +1293,7 @@ void CBotVarBoolean::XOr(CBotVar* left, CBotVar* right) void CBotVarBoolean::Not() { - m_val = m_val ? false : true ; + m_val = m_val ? false : true ; } bool CBotVarBoolean::Eq(CBotVar* left, CBotVar* right) @@ -1468,7 +1468,7 @@ void CBotVarClass::SetClass(CBotClass* pClass)//, int &nIdent) CBotInstr* p = pv->m_LimExpr; // the different formulas if ( p != NULL ) { - CBotStack* pile = CBotStack::FirstStack(); // an independent stack + CBotStack* pile = CBotStack::FirstStack(); // an independent stack int n = 0; int max[100]; @@ -1524,7 +1524,7 @@ CBotClass* CBotVarClass::GetClass() void CBotVarClass::Maj(void* pUser, bool bContinu) { -/* if (!bContinu && m_pMyThis != NULL) +/* if (!bContinu && m_pMyThis != NULL) m_pMyThis->Maj(pUser, true);*/ // an update routine exist? @@ -1671,7 +1671,7 @@ void CBotVarClass::IncrementUse() void CBotVarClass::DecrementUse() { m_CptUse--; - if ( m_CptUse == 0 ) + if ( m_CptUse == 0 ) { // if there is one, call the destructor // but only if a constructor had been called. @@ -2025,7 +2025,7 @@ bool CBotVarPointer::Save1State(FILE* pf) if (!WriteLong(pf, GetIdent())) return false; // the unique reference - // also saves the proceedings copies + // also saves the proceedings copies return SaveVar(pf, GetPointer()); } @@ -2082,7 +2082,7 @@ bool CBotVarPointer::Ne(CBotVar* left, CBotVar* right) /////////////////////////////////////////////////////// -// management of results types +// management of results types CBotTypResult::CBotTypResult(int type) @@ -2164,7 +2164,7 @@ int CBotTypResult::GetType(int mode) const if ( m_pClass == NULL ) ASM_TRAP(); - + if ( m_type == CBotTypArrayPointer ) if ( m_pNext == NULL ) ASM_TRAP(); #endif @@ -2245,4 +2245,3 @@ CBotTypResult& return *this; } - diff --git a/src/CBot/CBotWhile.cpp b/src/CBot/CBotWhile.cpp index dfd69bf..73bcab9 100644 --- a/src/CBot/CBotWhile.cpp +++ b/src/CBot/CBotWhile.cpp @@ -112,16 +112,16 @@ bool CBotWhile :: Execute(CBotStack* &pj) // the condition is true, pass in the second mode if (!pile->SetState(1)) return false; // ready for further - + case 1: // evaluates the associated statement block - if ( m_Block != NULL && + if ( m_Block != NULL && !m_Block->Execute(pile) ) { if (pile->IfContinue(0, m_label)) continue; // if continued, will return to test return pj->BreakReturn(pile, m_label); // sends the results and releases the stack } - + // terminates if there is an error if ( !pile->IsOk() ) { @@ -130,7 +130,7 @@ bool CBotWhile :: Execute(CBotStack* &pj) // returns to the test again if (!pile->SetState(0, 0)) return false; - continue; + continue; } } @@ -140,163 +140,20 @@ void CBotWhile :: RestoreState(CBotStack* &pj, bool bMain) CBotStack* pile = pj->RestoreStack(this); // adds an item to the stack if ( pile == NULL ) return; - switch( pile->GetState() ) + switch( pile->GetState() ) { // there are two possible states (depending on recovery) case 0: // evaluates the condition - m_Condition->RestoreState(pile, bMain); + m_Condition->RestoreState(pile, bMain); return; - + case 1: // evaluates the associated statement block if ( m_Block != NULL ) m_Block->RestoreState(pile, bMain); return; - } -} - - -/////////////////////////////////////////////////////////////////////////// - -/////////////////////////////////////////////////////////////////////////// -// compiles instruction "repeat" - -CBotRepeat::CBotRepeat() -{ - m_NbIter = - m_Block = NULL; // NULL so that delete is not possible further - name = "CBotRepeat"; // debug -} - -CBotRepeat::~CBotRepeat() -{ - delete m_NbIter; // frees the condition - delete m_Block; // frees the instruction block -} - -CBotInstr* CBotRepeat::Compile(CBotToken* &p, CBotCStack* pStack) -{ - CBotRepeat* inst = new CBotRepeat(); // creates the object - CBotToken* pp = p; // preserves at the ^ token (starting position) - - if ( IsOfType( p, TokenTypVar ) && - IsOfType( p, ID_DOTS ) ) - { - inst->m_label = pp->GetString(); // register the name of label - } - - inst->SetToken(p); - if (!IsOfType(p, ID_REPEAT)) return NULL; // should never happen - - CBotCStack* pStk = pStack->TokenStack(pp); // un petit bout de pile svp - - if ( IsOfType(p, ID_OPENPAR ) ) - { - CBotToken* ppp = p; // preserves the ^ token (starting position) - if ( NULL != (inst->m_NbIter = CBotExpression::Compile( p, pStk )) ) - { - if ( pStk->GetType() < CBotTypLong ) - { - if ( IsOfType(p, ID_CLOSEPAR ) ) - { - - IncLvl(inst->m_label); - inst->m_Block = CBotBlock::CompileBlkOrInst( p, pStk, true ); - DecLvl(); - - if ( pStk->IsOk() ) - { - // the statement block is ok (it may be empty! - - return pStack->Return(inst, pStk); // return an object to the application - } - } - pStack->SetError(TX_CLOSEPAR, p->GetStart()); - } - pStk->SetStartError(ppp->GetStart()); - pStk->SetError( TX_BADTYPE, p->GetStart() ); - } - pStack->SetError(TX_ENDOF, p); - } - pStack->SetError(TX_OPENPAR, p->GetStart()); // missing parenthesis - - delete inst; // error, frees up - return pStack->Return(NULL, pStk); // no object, the error is on the stack -} - -// execution of intruction "repeat" - -bool CBotRepeat :: Execute(CBotStack* &pj) -{ - CBotStack* pile = pj->AddStack(this); // adds an item to the stack - // or find in case of recovery -// if ( pile == EOX ) return true; - - if ( pile->IfStep() ) return false; - - while( true ) switch( pile->GetState() ) // executes the loop - { // there are two possible states (depending on recovery) - case 0: - // evaluates the number of iterations - if ( !m_NbIter->Execute(pile) ) return false; // interrupted here ? - - // the result of the condition is on the stack - - // terminates if an error or if the condition is false - int n; - if ( !pile->IsOk() || ( n = pile->GetVal() ) < 1 ) - { - return pj->Return(pile); // sends the results and releases the stack - } - - // puts the number of iterations +1 to the "state" - - if (!pile->SetState(n+1)) return false; // ready for further - continue; // continue as a result - - case 1: - // normal end of the loop - return pj->Return(pile); // sends the results and releases the stack - - default: - // evaluates the associated statement block - if ( m_Block != NULL && - !m_Block->Execute(pile) ) - { - if (pile->IfContinue(pile->GetState()-1, m_label)) continue; // if continued, will return to test - return pj->BreakReturn(pile, m_label); // sends the results and releases the stack - } - - // terminates if there is an error - if ( !pile->IsOk() ) - { - return pj->Return(pile); // sends the results and releases the stack - } - - // returns to the test again - if (!pile->SetState(pile->GetState()-1, 0)) return false; - continue; } } -void CBotRepeat :: RestoreState(CBotStack* &pj, bool bMain) -{ - if ( !bMain ) return; - CBotStack* pile = pj->RestoreStack(this); // adds an item to the stack - if ( pile == NULL ) return; - - switch( pile->GetState() ) - { // there are two possible states (depending on recovery) - case 0: - // evaluates the condition - m_NbIter->RestoreState(pile, bMain); - return; - - case 1: - // evaluates the associated statement block - if ( m_Block != NULL ) m_Block->RestoreState(pile, bMain); - return; - } -} /////////////////////////////////////////////////////////////////////////// @@ -374,13 +231,13 @@ bool CBotDo :: Execute(CBotStack* &pj) { // there are two possible states (depending on recovery) case 0: // evaluates the associated statement block - if ( m_Block != NULL && + if ( m_Block != NULL && !m_Block->Execute(pile) ) { if (pile->IfContinue(1, m_label)) continue; // if continued, will return to test return pj->BreakReturn(pile, m_label); // sends the results and releases the stack } - + // terminates if there is an error if ( !pile->IsOk() ) { @@ -388,7 +245,7 @@ bool CBotDo :: Execute(CBotStack* &pj) } if (!pile->SetState(1)) return false; // ready for further - + case 1: // evaluates the condition if ( !m_Condition->Execute(pile) ) return false; // interrupted here ? @@ -403,7 +260,7 @@ bool CBotDo :: Execute(CBotStack* &pj) // returns to instruction block to start if (!pile->SetState(0, 0)) return false; - continue; + continue; } } @@ -420,7 +277,7 @@ void CBotDo :: RestoreState(CBotStack* &pj, bool bMain) // restores the assosiated statement's block if ( m_Block != NULL ) m_Block->RestoreState(pile, bMain); return; - + case 1: // restores the condition m_Condition->RestoreState(pile, bMain); @@ -445,9 +302,9 @@ CBotFor::CBotFor() CBotFor::~CBotFor() { - delete m_Init; - delete m_Test; - delete m_Incr; + delete m_Init; + delete m_Test; + delete m_Incr; delete m_Block; // frees the instruction block } @@ -529,7 +386,7 @@ bool CBotFor :: Execute(CBotStack* &pj) if ( m_Init != NULL && !m_Init->Execute(pile) ) return false; // interrupted here ? if (!pile->SetState(1)) return false; // ready for further - + case 1: // evaluates the condition if ( m_Test != NULL ) // no strings attached? -> True! @@ -547,10 +404,10 @@ bool CBotFor :: Execute(CBotStack* &pj) // la condition est vrai, passe à la suite if (!pile->SetState(2)) return false; // ready for further - + case 2: // evaluates the associated statement block - if ( m_Block != NULL && + if ( m_Block != NULL && !m_Block->Execute(pile) ) { if (pile->IfContinue(3, m_label)) continue; // if continued, going on to incrementation @@ -572,7 +429,7 @@ bool CBotFor :: Execute(CBotStack* &pj) // returns to the test again if (!pile->SetState(1, 0)) return false; // returns to the test - continue; + continue; } } @@ -589,7 +446,7 @@ void CBotFor :: RestoreState(CBotStack* &pj, bool bMain) // initialize if ( m_Init != NULL ) m_Init->RestoreState(pile, true); // interrupted here ! return; - + case 1: if ( m_Init != NULL ) m_Init->RestoreState(pile, false); // variables definitions @@ -686,7 +543,7 @@ void CBotListExpression::RestoreState(CBotStack* &pj, bool bMain) { CBotStack* pile = pj; int state = 0x7000; - + if ( bMain ) { pile = pj->RestoreStack(); @@ -758,7 +615,7 @@ CBotInstr* CBotSwitch::Compile(CBotToken* &p, CBotCStack* pStack) CBotInstr* i = CBotCase::Compile( p, pStk2 ); if (i == NULL) { - delete inst; + delete inst; return pStack->Return(NULL, pStk2); } delete pStk2; @@ -766,7 +623,7 @@ CBotInstr* CBotSwitch::Compile(CBotToken* &p, CBotCStack* pStack) else inst->m_Block->AddNext(i); continue; } - + if ( inst->m_Block == NULL ) { pStk->SetError(TX_NOCASE, p->GetStart()); @@ -790,7 +647,7 @@ CBotInstr* CBotSwitch::Compile(CBotToken* &p, CBotCStack* pStack) } } DecLvl(); - + if ( inst->m_Block == NULL ) { pStk->SetError(TX_NOCASE, p->GetStart()); @@ -817,7 +674,7 @@ CBotInstr* CBotSwitch::Compile(CBotToken* &p, CBotCStack* pStack) bool CBotSwitch :: Execute(CBotStack* &pj) { - CBotStack* pile1 = pj->AddStack(this); // adds an item to the stack + CBotStack* pile1 = pj->AddStack(this); // adds an item to the stack // if ( pile1 == EOX ) return true; CBotInstr* p = m_Block; // first expression @@ -866,7 +723,7 @@ void CBotSwitch :: RestoreState(CBotStack* &pj, bool bMain) { if ( !bMain ) return; - CBotStack* pile1 = pj->RestoreStack(this); // adds an item to the stack + CBotStack* pile1 = pj->RestoreStack(this); // adds an item to the stack if ( pile1 == NULL ) return; CBotInstr* p = m_Block; // first expression @@ -1055,7 +912,7 @@ CBotTry::~CBotTry() delete m_ListCatch; // frees the list delete m_Block; // frees the instruction block delete m_FinalInst; -} +} CBotInstr* CBotTry::Compile(CBotToken* &p, CBotCStack* pStack) { @@ -1069,7 +926,7 @@ CBotInstr* CBotTry::Compile(CBotToken* &p, CBotCStack* pStack) inst->m_Block = CBotBlock::CompileBlkOrInst( p, pStk ); CBotCatch** pn = &inst->m_ListCatch; - + while (pStk->IsOk() && p->GetType() == ID_CATCH) { CBotCatch* i = CBotCatch::Compile(p, pStk); @@ -1154,7 +1011,7 @@ bool CBotTry :: Execute(CBotStack* &pj) if ( !pc->Execute(pile2) ) return false; // performs the operation if ( m_FinalInst == NULL ) return pj->Return(pile2); // ends the try - + pile1->SetState(-2); // passes final break; } @@ -1162,13 +1019,13 @@ bool CBotTry :: Execute(CBotStack* &pj) } pc = pc->m_next; } - if ( m_FinalInst != NULL && + if ( m_FinalInst != NULL && pile1->GetState() > 0 && val != 0 ) pile1->SetState(-1);// if stop then made the final if (pile1->GetState() <= -1) { // pile0->SetState(1); - + if (!m_FinalInst->Execute(pile2) && pile2->IsOk()) return false; if (!pile2->IsOk()) return pj->Return(pile2); // keep this exception pile2->SetError(pile1->GetState()==-1 ? val : 0); // gives the initial error @@ -1319,7 +1176,7 @@ bool CBotCatch :: TestCatch(CBotStack* &pile, int val) var->SetValInt( pile->GetVal() == val ); pile->SetVar(var); // calls on the stack } - + return true; } diff --git a/src/CBot/CMakeLists.txt b/src/CBot/CMakeLists.txt index fecd18e..8bb8a5c 100644 --- a/src/CBot/CMakeLists.txt +++ b/src/CBot/CMakeLists.txt @@ -12,7 +12,7 @@ CBotVar.cpp CBotWhile.cpp ) -if(${CBOT_STATIC}) +if(CBOT_STATIC) add_library(CBot STATIC ${SOURCES}) else() add_library(CBot SHARED ${SOURCES}) @@ -21,3 +21,4 @@ else() ARCHIVE DESTINATION ${COLOBOT_INSTALL_LIB_DIR} RUNTIME DESTINATION ${COLOBOT_INSTALL_BIN_DIR}) endif() + diff --git a/src/CBot/ClassFILE.cpp b/src/CBot/ClassFILE.cpp index b0f7977..6906bd4 100644 --- a/src/CBot/ClassFILE.cpp +++ b/src/CBot/ClassFILE.cpp @@ -58,7 +58,7 @@ void PrepareFilename(CBotString &filename) //DD! // gets the filename as a parameter // execution -bool rfconstruct (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception) +bool rfconstruct (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception) { CBotString mode; @@ -239,7 +239,7 @@ CBotTypResult cfopen (CBotVar* pThis, CBotVar* &pVar) return CBotTypResult(CBotTypBoolean); //DR } - + // FILE :: close method // execution @@ -291,7 +291,7 @@ bool rfwrite (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception) if ( pVar->GetInit() != IS_DEF) { Exception = CBotErrNotOpen; return false; } FILE* pFile= (FILE*)pVar->GetValInt(); - + int res = fputs(param+CBotString("\n"), pFile); // on error throws an exception diff --git a/src/CBot/StringFunctions.cpp b/src/CBot/StringFunctions.cpp index d24c942..abdcc18 100644 --- a/src/CBot/StringFunctions.cpp +++ b/src/CBot/StringFunctions.cpp @@ -184,10 +184,10 @@ bool rStrMid( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser ) if ( pVar->GetNext() != NULL ) { pVar = pVar->GetNext(); - + // which must be a number if ( pVar->GetType() > CBotTypDouble ) { ex = TX_BADNUM ; return true; } - + // retrieves this number int l = pVar->GetValInt(); @@ -231,7 +231,7 @@ CBotTypResult cStrStrIntInt( CBotVar* &pVar, void* pUser ) // third parameter optional if ( pVar->GetNext() != NULL ) { - + pVar = pVar->GetNext(); // which must be a number if ( pVar->GetType() > CBotTypDouble ) @@ -434,3 +434,4 @@ void InitStringFunctions() CBotProgram::AddFunction("strupper", rStrUpper, cStrStr ); CBotProgram::AddFunction("strlower", rStrLower, cStrStr ); } + diff --git a/src/CBot/idees.txt b/src/CBot/idees.txt index 3966ee1..3f335da 100644 --- a/src/CBot/idees.txt +++ b/src/CBot/idees.txt @@ -39,3 +39,4 @@ the object being created with CBotVar :: Create (name, pClasse) not destroy the object when there imédiatement pointers
but marked as virtually destroyed
+ diff --git a/src/CBot/resource.h b/src/CBot/resource.h index ed14240..9c7e82e 100644 --- a/src/CBot/resource.h +++ b/src/CBot/resource.h @@ -47,7 +47,6 @@ enum EID ID_STATIC, ID_PROTECTED, ID_PRIVATE, - ID_REPEAT, ID_DEBUGDD, ID_INT, ID_FLOAT, @@ -177,3 +176,4 @@ enum EID #define TX_ERRWRITE 6015 #define TX_MAX 6016 + |