diff --git a/src/CBot/CBotClass.h b/src/CBot/CBotClass.h index fe385461..b776fb5a 100644 --- a/src/CBot/CBotClass.h +++ b/src/CBot/CBotClass.h @@ -22,14 +22,18 @@ // Modules inlcude #include "CBotDll.h" -#include "CBotProgram.h" - #include "CBotDefines.h" +#include "CBotTypResult.h" + +#include "CBotString.h" + // Local include // Global include +class CBotProgram; + /*! * \brief The CBotClass class Class to define new classes in the language CBOT * for example to define the class CPoint (x, y). diff --git a/src/CBot/CBotDll.h b/src/CBot/CBotDll.h index 40e4931d..fd5939d2 100644 --- a/src/CBot/CBotDll.h +++ b/src/CBot/CBotDll.h @@ -69,90 +69,6 @@ class CBotCStack; // stack #define OBJECTCREATED (reinterpret_cast(-2)) -/** \brief CBotTypResult class to define the complete type of a result*/ -class CBotTypResult -{ -public: - /** - * \brief CBotTypResult constructor for simple types (CBotTypInt to CBotTypString) - * \param type type of created result, see CBotType - */ - 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; - // returns type CBotType* as a result - - void SetType(int n); - // modifies a type - - CBotClass* GetClass() const; - // makes the pointer to the class (for CBotTypClass, CBotTypPointer) - - int GetLimite() const; - // returns limit size of table (CBotTypArray) - - void SetLimite(int n); - // set limit to the table - - void SetArray(int* max ); - // set limits for a list of dimensions (arrays of arrays) - - CBotTypResult& GetTypElem() const; - // returns type of array elements (CBotTypArray) - // rend le type des éléments du tableau (CBotTypArray) - - bool Compare(const CBotTypResult& typ) const; - // compares whether the types are compatible - bool Eq(int type) const; - // compare type - - CBotTypResult& operator=(const CBotTypResult& src); - // copy a complete type in another - -private: - int m_type; - CBotTypResult* m_pNext; // for the types of type - CBotClass* m_pClass; // for the derivatives of class - int m_limite; // limits of tables - friend class CBotVarClass; - friend class CBotVarPointer; -}; - -/* -// to define a result as output, using for example - - // to return a simple Float - return CBotTypResult( CBotTypFloat ); - - - // to return a string array - return CBotTypResult( CBotTypArray, CBotTypResult( CBotTypString ) ); - - // to return un array of array of "point" class - CBotTypResult typPoint( CBotTypIntrinsic, "point" ); - CBotTypResult arrPoint( CBotTypArray, typPoint ); - return CBotTypResult( CBotTypArray, arrPoint ); -*/ - //////////////////////////////////////////////////////////////////////// // Error Handling of compilation and execution diff --git a/src/CBot/CBotProgram.h b/src/CBot/CBotProgram.h index bef08a8c..f13a1af8 100644 --- a/src/CBot/CBotProgram.h +++ b/src/CBot/CBotProgram.h @@ -20,13 +20,14 @@ #pragma once // Modules inlcude +#include "CBotTypResult.h" +#include "CBotString.h" #include "CBotStringArray.h" // Local include // Global include - /*! * \brief The CBotProgram class Main class managing CBot program. */ diff --git a/src/CBot/CBotTypResult.cpp b/src/CBot/CBotTypResult.cpp new file mode 100644 index 00000000..0ba8ff55 --- /dev/null +++ b/src/CBot/CBotTypResult.cpp @@ -0,0 +1,208 @@ +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsitec.ch; http://colobot.info; http://github.com/colobot + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see http://gnu.org/licenses + */ + +// Modules inlcude +#include "CBotTypResult.h" + +#include "CBotEnums.h" + +#include "CBotClass.h" + +// Local include + +// Global include + + + +/////////////////////////////////////////////////////// +// management of results types + +//////////////////////////////////////////////////////////////////////////////// +CBotTypResult::CBotTypResult(int type) +{ + m_type = type; + m_pNext = nullptr; + m_pClass = nullptr; + m_limite = -1; +} + +//////////////////////////////////////////////////////////////////////////////// +CBotTypResult::CBotTypResult(int type, const char* name) +{ + m_type = type; + m_pNext = nullptr; + m_pClass = nullptr; + m_limite = -1; + + if ( type == CBotTypPointer || + type == CBotTypClass || + type == CBotTypIntrinsic ) + { + m_pClass = CBotClass::Find(name); + if ( m_pClass && m_pClass->IsIntrinsic() ) m_type = CBotTypIntrinsic; + } +} + +//////////////////////////////////////////////////////////////////////////////// +CBotTypResult::CBotTypResult(int type, CBotClass* pClass) +{ + m_type = type; + m_pNext = nullptr; + m_pClass = pClass; + m_limite = -1; + + if ( m_pClass && m_pClass->IsIntrinsic() ) m_type = CBotTypIntrinsic; +} + +//////////////////////////////////////////////////////////////////////////////// +CBotTypResult::CBotTypResult(int type, CBotTypResult elem) +{ + m_type = type; + m_pNext = nullptr; + m_pClass = nullptr; + m_limite = -1; + + if ( type == CBotTypArrayPointer || + type == CBotTypArrayBody ) + m_pNext = new CBotTypResult( elem ); +} + +//////////////////////////////////////////////////////////////////////////////// +CBotTypResult::CBotTypResult(const CBotTypResult& typ) +{ + m_type = typ.m_type; + m_pClass = typ.m_pClass; + m_pNext = nullptr; + m_limite = typ.m_limite; + + if ( typ.m_pNext ) + m_pNext = new CBotTypResult( *typ.m_pNext ); +} + +//////////////////////////////////////////////////////////////////////////////// +CBotTypResult::CBotTypResult() +{ + m_type = 0; + m_limite = -1; + m_pNext = nullptr; + m_pClass = nullptr; +} + +//////////////////////////////////////////////////////////////////////////////// +CBotTypResult::~CBotTypResult() +{ + delete m_pNext; +} + +//////////////////////////////////////////////////////////////////////////////// +int CBotTypResult::GetType(int mode) const +{ +#ifdef _DEBUG + if ( m_type == CBotTypPointer || + m_type == CBotTypClass || + m_type == CBotTypIntrinsic ) + + if ( m_pClass == nullptr ) assert(0); + + + if ( m_type == CBotTypArrayPointer ) + if ( m_pNext == nullptr ) assert(0); +#endif + if ( mode == 3 && m_type == CBotTypNullPointer ) return CBotTypPointer; + return m_type; +} + +//////////////////////////////////////////////////////////////////////////////// +void CBotTypResult::SetType(int n) +{ + m_type = n; +} + +//////////////////////////////////////////////////////////////////////////////// +CBotClass* CBotTypResult::GetClass() const +{ + return m_pClass; +} + +//////////////////////////////////////////////////////////////////////////////// +CBotTypResult& CBotTypResult::GetTypElem() const +{ + return *m_pNext; +} + +//////////////////////////////////////////////////////////////////////////////// +int CBotTypResult::GetLimite() const +{ + return m_limite; +} + +//////////////////////////////////////////////////////////////////////////////// +void CBotTypResult::SetLimite(int n) +{ + m_limite = n; +} + +//////////////////////////////////////////////////////////////////////////////// +void CBotTypResult::SetArray( int* max ) +{ + m_limite = *max; + if (m_limite < 1) m_limite = -1; + + if ( m_pNext != nullptr ) // last dimension? + { + m_pNext->SetArray( max+1 ); + } +} + +//////////////////////////////////////////////////////////////////////////////// +bool CBotTypResult::Compare(const CBotTypResult& typ) const +{ + if ( m_type != typ.m_type ) return false; + + if ( m_type == CBotTypArrayPointer ) return m_pNext->Compare(*typ.m_pNext); + + if ( m_type == CBotTypPointer || + m_type == CBotTypClass || + m_type == CBotTypIntrinsic ) + { + return m_pClass == typ.m_pClass; + } + + return true; +} + +//////////////////////////////////////////////////////////////////////////////// +bool CBotTypResult::Eq(int type) const +{ + return m_type == type; +} + +//////////////////////////////////////////////////////////////////////////////// +CBotTypResult& CBotTypResult::operator=(const CBotTypResult& src) +{ + m_type = src.m_type; + m_limite = src.m_limite; + m_pClass = src.m_pClass; + m_pNext = nullptr; + if ( src.m_pNext != nullptr ) + { + m_pNext = new CBotTypResult(*src.m_pNext); + } + return *this; +} diff --git a/src/CBot/CBotTypResult.h b/src/CBot/CBotTypResult.h new file mode 100644 index 00000000..97ac52af --- /dev/null +++ b/src/CBot/CBotTypResult.h @@ -0,0 +1,112 @@ +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsitec.ch; http://colobot.info; http://github.com/colobot + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see http://gnu.org/licenses + */ + +#pragma once + +// Modules inlcude + +// Local include + +// Global include + +class CBotClass; + +/* +// to define a result as output, using for example + + // to return a simple Float + return CBotTypResult( CBotTypFloat ); + + + // to return a string array + return CBotTypResult( CBotTypArray, CBotTypResult( CBotTypString ) ); + + // to return un array of array of "point" class + CBotTypResult typPoint( CBotTypIntrinsic, "point" ); + CBotTypResult arrPoint( CBotTypArray, typPoint ); + return CBotTypResult( CBotTypArray, arrPoint ); +*/ + +/** \brief CBotTypResult class to define the complete type of a result*/ +class CBotTypResult +{ +public: + /** + * \brief CBotTypResult constructor for simple types (CBotTypInt to CBotTypString) + * \param type type of created result, see CBotType + */ + 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; + // returns type CBotType* as a result + + void SetType(int n); + // modifies a type + + CBotClass* GetClass() const; + // makes the pointer to the class (for CBotTypClass, CBotTypPointer) + + int GetLimite() const; + // returns limit size of table (CBotTypArray) + + void SetLimite(int n); + // set limit to the table + + void SetArray(int* max ); + // set limits for a list of dimensions (arrays of arrays) + + CBotTypResult& GetTypElem() const; + // returns type of array elements (CBotTypArray) + // rend le type des éléments du tableau (CBotTypArray) + + bool Compare(const CBotTypResult& typ) const; + // compares whether the types are compatible + bool Eq(int type) const; + // compare type + + CBotTypResult& operator=(const CBotTypResult& src); + // copy a complete type in another + +private: + int m_type; + CBotTypResult* m_pNext; // for the types of type + CBotClass* m_pClass; // for the derivatives of class + int m_limite; // limits of tables + friend class CBotVarClass; + friend class CBotVarPointer; +}; diff --git a/src/CBot/CBotUtils.h b/src/CBot/CBotUtils.h index e14b4748..739800eb 100644 --- a/src/CBot/CBotUtils.h +++ b/src/CBot/CBotUtils.h @@ -23,6 +23,7 @@ #include "CBotDll.h" #include "CBotString.h" +#include "CBotTypResult.h" // Local include diff --git a/src/CBot/CBotVar/CBotVar.cpp b/src/CBot/CBotVar/CBotVar.cpp index e2c1fe78..e5ce073e 100644 --- a/src/CBot/CBotVar/CBotVar.cpp +++ b/src/CBot/CBotVar/CBotVar.cpp @@ -759,181 +759,3 @@ CBotClass* CBotVar::GetClass() assert(0); return nullptr; } - -/////////////////////////////////////////////////////// -// management of results types - -//////////////////////////////////////////////////////////////////////////////// -CBotTypResult::CBotTypResult(int type) -{ - m_type = type; - m_pNext = nullptr; - m_pClass = nullptr; - m_limite = -1; -} - -//////////////////////////////////////////////////////////////////////////////// -CBotTypResult::CBotTypResult(int type, const char* name) -{ - m_type = type; - m_pNext = nullptr; - m_pClass = nullptr; - m_limite = -1; - - if ( type == CBotTypPointer || - type == CBotTypClass || - type == CBotTypIntrinsic ) - { - m_pClass = CBotClass::Find(name); - if ( m_pClass && m_pClass->IsIntrinsic() ) m_type = CBotTypIntrinsic; - } -} - -//////////////////////////////////////////////////////////////////////////////// -CBotTypResult::CBotTypResult(int type, CBotClass* pClass) -{ - m_type = type; - m_pNext = nullptr; - m_pClass = pClass; - m_limite = -1; - - if ( m_pClass && m_pClass->IsIntrinsic() ) m_type = CBotTypIntrinsic; -} - -//////////////////////////////////////////////////////////////////////////////// -CBotTypResult::CBotTypResult(int type, CBotTypResult elem) -{ - m_type = type; - m_pNext = nullptr; - m_pClass = nullptr; - m_limite = -1; - - if ( type == CBotTypArrayPointer || - type == CBotTypArrayBody ) - m_pNext = new CBotTypResult( elem ); -} - -//////////////////////////////////////////////////////////////////////////////// -CBotTypResult::CBotTypResult(const CBotTypResult& typ) -{ - m_type = typ.m_type; - m_pClass = typ.m_pClass; - m_pNext = nullptr; - m_limite = typ.m_limite; - - if ( typ.m_pNext ) - m_pNext = new CBotTypResult( *typ.m_pNext ); -} - -//////////////////////////////////////////////////////////////////////////////// -CBotTypResult::CBotTypResult() -{ - m_type = 0; - m_limite = -1; - m_pNext = nullptr; - m_pClass = nullptr; -} - -//////////////////////////////////////////////////////////////////////////////// -CBotTypResult::~CBotTypResult() -{ - delete m_pNext; -} - -//////////////////////////////////////////////////////////////////////////////// -int CBotTypResult::GetType(int mode) const -{ -#ifdef _DEBUG - if ( m_type == CBotTypPointer || - m_type == CBotTypClass || - m_type == CBotTypIntrinsic ) - - if ( m_pClass == nullptr ) assert(0); - - - if ( m_type == CBotTypArrayPointer ) - if ( m_pNext == nullptr ) assert(0); -#endif - if ( mode == 3 && m_type == CBotTypNullPointer ) return CBotTypPointer; - return m_type; -} - -//////////////////////////////////////////////////////////////////////////////// -void CBotTypResult::SetType(int n) -{ - m_type = n; -} - -//////////////////////////////////////////////////////////////////////////////// -CBotClass* CBotTypResult::GetClass() const -{ - return m_pClass; -} - -//////////////////////////////////////////////////////////////////////////////// -CBotTypResult& CBotTypResult::GetTypElem() const -{ - return *m_pNext; -} - -//////////////////////////////////////////////////////////////////////////////// -int CBotTypResult::GetLimite() const -{ - return m_limite; -} - -//////////////////////////////////////////////////////////////////////////////// -void CBotTypResult::SetLimite(int n) -{ - m_limite = n; -} - -//////////////////////////////////////////////////////////////////////////////// -void CBotTypResult::SetArray( int* max ) -{ - m_limite = *max; - if (m_limite < 1) m_limite = -1; - - if ( m_pNext != nullptr ) // last dimension? - { - m_pNext->SetArray( max+1 ); - } -} - -//////////////////////////////////////////////////////////////////////////////// -bool CBotTypResult::Compare(const CBotTypResult& typ) const -{ - if ( m_type != typ.m_type ) return false; - - if ( m_type == CBotTypArrayPointer ) return m_pNext->Compare(*typ.m_pNext); - - if ( m_type == CBotTypPointer || - m_type == CBotTypClass || - m_type == CBotTypIntrinsic ) - { - return m_pClass == typ.m_pClass; - } - - return true; -} - -//////////////////////////////////////////////////////////////////////////////// -bool CBotTypResult::Eq(int type) const -{ - return m_type == type; -} - -//////////////////////////////////////////////////////////////////////////////// -CBotTypResult& CBotTypResult::operator=(const CBotTypResult& src) -{ - m_type = src.m_type; - m_limite = src.m_limite; - m_pClass = src.m_pClass; - m_pNext = nullptr; - if ( src.m_pNext != nullptr ) - { - m_pNext = new CBotTypResult(*src.m_pNext); - } - return *this; -} - diff --git a/src/CBot/CMakeLists.txt b/src/CBot/CMakeLists.txt index 28c73204..d8bda9ff 100644 --- a/src/CBot/CMakeLists.txt +++ b/src/CBot/CMakeLists.txt @@ -11,6 +11,7 @@ set(SOURCES CBotDefParam.cpp CBotCallMethode.cpp CBotStringArray.cpp + CBotTypResult.cpp CBotInstr/CBotInstr.cpp CBotInstr/CBotWhile.cpp CBotInstr/CBotDo.cpp diff --git a/src/script/scriptfunc.h b/src/script/scriptfunc.h index 9428879a..07b21cb9 100644 --- a/src/script/scriptfunc.h +++ b/src/script/scriptfunc.h @@ -25,6 +25,7 @@ #pragma once #include "CBot/CBotDll.h" +#include "CBot/CBotTypResult.h" #include "common/error.h"