Moving CBotTypResult class in its own header and source files.
parent
942d7195e4
commit
3b0561056a
|
@ -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).
|
||||
|
|
|
@ -69,90 +69,6 @@ class CBotCStack; // stack
|
|||
#define OBJECTCREATED (reinterpret_cast<void*>(-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
|
||||
|
|
|
@ -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.
|
||||
*/
|
||||
|
|
|
@ -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;
|
||||
}
|
|
@ -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;
|
||||
};
|
|
@ -23,6 +23,7 @@
|
|||
#include "CBotDll.h"
|
||||
|
||||
#include "CBotString.h"
|
||||
#include "CBotTypResult.h"
|
||||
|
||||
// Local include
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -11,6 +11,7 @@ set(SOURCES
|
|||
CBotDefParam.cpp
|
||||
CBotCallMethode.cpp
|
||||
CBotStringArray.cpp
|
||||
CBotTypResult.cpp
|
||||
CBotInstr/CBotInstr.cpp
|
||||
CBotInstr/CBotWhile.cpp
|
||||
CBotInstr/CBotDo.cpp
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
#pragma once
|
||||
|
||||
#include "CBot/CBotDll.h"
|
||||
#include "CBot/CBotTypResult.h"
|
||||
|
||||
#include "common/error.h"
|
||||
|
||||
|
|
Loading…
Reference in New Issue