void CBotVar::SetVal(CBotVar* var) { switch (var->GetType()) { case CBotTypBoolean: SetValInt(var->GetValInt()); break; case CBotTypInt: SetValInt(var->GetValInt(), (static_cast<CBotVarInt*>(var))->m_defnum); break; case CBotTypFloat: SetValFloat(var->GetValFloat()); break; case CBotTypString: SetValString(var->GetValString()); break; case CBotTypPointer: case CBotTypNullPointer: case CBotTypArrayPointer: SetPointer(var->GetPointer()); break; case CBotTypClass: { delete (static_cast<CBotVarClass*>(this))->m_pVar; (static_cast<CBotVarClass*>(this))->m_pVar = NULL; Copy(var, false); } break; default: ASM_TRAP(); } m_binit = var->m_binit; // copie l'état nan s'il y a }
CBotVarClass::CBotVarClass( const CBotToken* name, const CBotTypResult& type) { /* // int nIdent = 0; InitCBotVarClass( name, type ) //, nIdent ); } CBotVarClass::CBotVarClass( const CBotToken* name, CBotTypResult& type) //, int &nIdent ) { InitCBotVarClass( name, type ); //, nIdent ); } void CBotVarClass::InitCBotVarClass( const CBotToken* name, CBotTypResult& type ) //, int &nIdent ) {*/ if ( !type.Eq(CBotTypClass) && !type.Eq(CBotTypIntrinsic) && // by convenience there accepts these types !type.Eq(CBotTypPointer) && !type.Eq(CBotTypArrayPointer) && !type.Eq(CBotTypArrayBody)) ASM_TRAP(); m_token = new CBotToken(name); m_next = NULL; m_pMyThis = NULL; m_pUserPtr = OBJECTCREATED;//NULL; m_InitExpr = NULL; 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 ); // officel type for this object m_pClass = NULL; m_pParent = NULL; m_binit = false; m_bStatic = false; m_mPrivate = 0; m_bConstructor = false; m_CptUse = 0; m_ItemIdent = type.Eq(CBotTypIntrinsic) ? 0 : CBotVar::NextUniqNum(); // se place tout seul dans la liste // TODO stands alone in the list (stands only in a list) if (m_ExClass) m_ExClass->m_ExPrev = this; m_ExNext = m_ExClass; m_ExPrev = NULL; m_ExClass = this; CBotClass* pClass = type.GetClass(); CBotClass* pClass2 = pClass->GetParent(); if ( pClass2 != NULL ) { // also creates an instance of the parent class m_pParent = new CBotVarClass(name, CBotTypResult(type.GetType(),pClass2) ); //, nIdent); } SetClass( pClass ); //, nIdent ); }
bool CBotVar::Save1State(FILE* pf) { // this routine "virtual" must never be called, // there must be a routine for each of the subclasses (CBotVarInt, CBotVarFloat, etc) // ( see the type in m_type ) ASM_TRAP(); return false; }
CBotVar* CBotVar::Create(const CBotToken* name, CBotTypResult type) { switch (type.GetType()) { case CBotTypShort: case CBotTypInt: return new CBotVarInt(name); case CBotTypFloat: return new CBotVarFloat(name); case CBotTypBoolean: return new CBotVarBoolean(name); case CBotTypString: return new CBotVarString(name); case CBotTypPointer: case CBotTypNullPointer: return new CBotVarPointer(name, type); case CBotTypIntrinsic: return new CBotVarClass(name, type); case CBotTypClass: // creates a new instance of a class // and returns the POINTER on this instance { CBotVarClass* instance = new CBotVarClass(name, type); CBotVarPointer* pointer = new CBotVarPointer(name, type); pointer->SetPointer( instance ); return pointer; } case CBotTypArrayPointer: return new CBotVarArray(name, type); case CBotTypArrayBody: { CBotVarClass* instance = new CBotVarClass(name, type); CBotVarArray* array = new CBotVarArray(name, type); array->SetPointer( instance ); CBotVar* pv = array; while (type.Eq(CBotTypArrayBody)) { type = type.GetTypElem(); pv = (static_cast<CBotVarArray*>(pv))->GetItem(0, true); // creates at least the element [0] } return array; } } ASM_TRAP(); return NULL; }
bool CBotDefParam::Execute(CBotVar** ppVars, CBotStack* &pj) { int i = 0; CBotDefParam* p = this; while ( p != NULL ) { // creates a local variable on the stack CBotVar* newvar = CBotVar::Create(p->m_token.GetString(), p->m_type); // serves to make the transformation of types: if ( ppVars != NULL && ppVars[i] != NULL ) { switch (p->m_type.GetType()) { case CBotTypInt: newvar->SetValInt(ppVars[i]->GetValInt()); break; case CBotTypFloat: newvar->SetValFloat(ppVars[i]->GetValFloat()); break; case CBotTypString: newvar->SetValString(ppVars[i]->GetValString()); break; case CBotTypBoolean: newvar->SetValInt(ppVars[i]->GetValInt()); break; case CBotTypIntrinsic: (static_cast<CBotVarClass*>(newvar))->Copy(ppVars[i], false); break; case CBotTypPointer: case CBotTypArrayPointer: { newvar->SetPointer(ppVars[i]->GetPointer()); } break; default: ASM_TRAP(); } } newvar->SetUniqNum(p->m_nIdent); pj->AddVar(newvar); // add a variable p = p->m_next; i++; } return true; }
void CBotCStack::AddVar(CBotVar* pVar) { CBotCStack* p = this; // returns to the father element while (p != NULL && p->m_bBlock == 0) p = p->m_prev; if ( p == NULL ) return; CBotVar** pp = &p->m_listVar; while ( *pp != NULL ) pp = &(*pp)->m_next; *pp = pVar; // added after #ifdef _DEBUG if ( pVar->GetUniqNum() == 0 ) ASM_TRAP(); #endif }
CBotVarClass::~CBotVarClass( ) { if ( m_CptUse != 0 ) ASM_TRAP(); if ( m_pParent ) delete m_pParent; m_pParent = NULL; // frees the indirect object if necessary // if ( m_Indirect != NULL ) // m_Indirect->DecrementUse(); // removes the class list if ( m_ExPrev ) m_ExPrev->m_ExNext = m_ExNext; else m_ExClass = m_ExNext; if ( m_ExNext ) m_ExNext->m_ExPrev = m_ExPrev; m_ExPrev = NULL; m_ExNext = NULL; delete m_pVar; }
CBotStack::~CBotStack() { ASM_TRAP(); // use Delete () instead }
void CBotVar::SetClass(CBotClass* pClass) { ASM_TRAP(); }
void CBotVar::SetValString(const char* p) { ASM_TRAP(); }
void CBotVar::Dec() { ASM_TRAP(); }
void CBotVar::Not() { ASM_TRAP(); }
int CBotVar::GetValInt() { ASM_TRAP(); return 0; }
CBotVarClass* CBotVar::GetPointer() { ASM_TRAP(); return NULL; }
void CBotVar::SetPointer(CBotVar* pVarClass) { ASM_TRAP(); }
void CBotVar::SL(CBotVar* left, CBotVar* right) { ASM_TRAP(); }
void CBotVar::Neg() { ASM_TRAP(); }
float CBotVar::GetValFloat() { ASM_TRAP(); return 0; }
void CBotVar::Inc() { ASM_TRAP(); }
void CBotVar::SetValInt(int c, const char* s) { ASM_TRAP(); }
void CBotVar::Copy(CBotVar* pSrc, bool bName) { ASM_TRAP(); }
void CBotVar::SetValFloat(float c) { ASM_TRAP(); }
CBotString CBotVar::GetValString() { ASM_TRAP(); return CBotString(); }
void CBotVar::Power(CBotVar* left, CBotVar* right) { ASM_TRAP(); }
CBotClass* CBotVar::GetClass() { ASM_TRAP(); return NULL; }
int CBotVar::Div(CBotVar* left, CBotVar* right) { ASM_TRAP(); return 0; }
CBotStack::CBotStack(CBotStack* ppapa) { // constructor must exist or the destructor is never called! ASM_TRAP(); }
int CBotVar::Modulo(CBotVar* left, CBotVar* right) { ASM_TRAP(); return 0; }
bool CBotVar::RestoreState(FILE* pf, CBotVar* &pVar) { unsigned short w, wi, prv, st; float ww; CBotString name, s; delete pVar; pVar = NULL; CBotVar* pNew = NULL; CBotVar* pPrev = NULL; while ( true ) // retrieves a list { if (!ReadWord(pf, w)) return false; // private or type? if ( w == 0 ) return true; CBotString defnum; if ( w == 200 ) { if (!ReadString(pf, defnum)) return false; // number with identifier if (!ReadWord(pf, w)) return false; // type } prv = 100; st = 0; if ( w >= 100 ) { prv = w; if (!ReadWord(pf, st)) return false; // static if (!ReadWord(pf, w)) return false; // type } if ( w == CBotTypClass ) w = CBotTypIntrinsic; // necessarily intrinsic if (!ReadWord(pf, wi)) return false; // init ? if (!ReadString(pf, name)) return false; // variable name CBotToken token(name, CBotString()); switch (w) { case CBotTypInt: case CBotTypBoolean: pNew = CBotVar::Create(&token, w); // creates a variable if (!ReadWord(pf, w)) return false; pNew->SetValInt(static_cast<short>(w), defnum); break; case CBotTypFloat: pNew = CBotVar::Create(&token, w); // creates a variable if (!ReadFloat(pf, ww)) return false; pNew->SetValFloat(ww); break; case CBotTypString: pNew = CBotVar::Create(&token, w); // creates a variable if (!ReadString(pf, s)) return false; pNew->SetValString(s); break; // returns an intrinsic object or element of an array case CBotTypIntrinsic: case CBotTypArrayBody: { CBotTypResult r; long id; if (!ReadType(pf, r)) return false; // complete type if (!ReadLong(pf, id) ) return false; // if (!ReadString(pf, s)) return false; { CBotVar* p = NULL; if ( id ) p = CBotVarClass::Find(id) ; pNew = new CBotVarClass(&token, r); // directly creates an instance // attention cptuse = 0 if ( !RestoreState(pf, (static_cast<CBotVarClass*>(pNew))->m_pVar)) return false; pNew->SetIdent(id); if ( p != NULL ) { delete pNew; pNew = p; // resume known element } } } break; case CBotTypPointer: case CBotTypNullPointer: if (!ReadString(pf, s)) return false; { pNew = CBotVar::Create(&token, CBotTypResult(w, s));// creates a variable // CBotVarClass* p = NULL; long id; ReadLong(pf, id); // if ( id ) p = CBotVarClass::Find(id); // found the instance (made by RestoreInstance) // returns a copy of the original instance CBotVar* pInstance = NULL; if ( !CBotVar::RestoreState( pf, pInstance ) ) return false; (static_cast<CBotVarPointer*>(pNew))->SetPointer( pInstance ); // and point over // if ( p != NULL ) (static_cast<CBotVarPointer*>(pNew))->SetPointer( p ); // rather this one } break; case CBotTypArrayPointer: { CBotTypResult r; if (!ReadType(pf, r)) return false; pNew = CBotVar::Create(&token, r); // creates a variable // returns a copy of the original instance CBotVar* pInstance = NULL; if ( !CBotVar::RestoreState( pf, pInstance ) ) return false; (static_cast<CBotVarPointer*>(pNew))->SetPointer( pInstance ); // and point over } break; default: ASM_TRAP(); } if ( pPrev != NULL ) pPrev->m_next = pNew; if ( pVar == NULL ) pVar = pNew; pNew->m_binit = wi; // pNew->SetInit(wi); pNew->SetStatic(st); pNew->SetPrivate(prv-100); pPrev = pNew; } return true; }
bool CBotVar::Ne(CBotVar* left, CBotVar* right) { ASM_TRAP(); return false; }