2015-11-15 22:41:24 +00:00
|
|
|
/*
|
|
|
|
* This file is part of the Colobot: Gold Edition source code
|
2020-07-07 08:19:36 +00:00
|
|
|
* Copyright (C) 2001-2020, Daniel Roux, EPSITEC SA & TerranovaTeam
|
2015-11-15 22:41:24 +00:00
|
|
|
* 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
|
|
|
|
|
2015-12-26 13:19:24 +00:00
|
|
|
#include "CBot/CBotVar/CBotVar.h"
|
2015-11-23 20:59:56 +00:00
|
|
|
#include "CBot/CBotProgram.h"
|
2015-11-15 22:41:24 +00:00
|
|
|
|
2021-06-12 02:47:33 +00:00
|
|
|
#include <list>
|
|
|
|
#include <memory>
|
|
|
|
|
2015-12-26 13:19:24 +00:00
|
|
|
namespace CBot
|
|
|
|
{
|
2015-11-15 22:41:24 +00:00
|
|
|
|
2015-11-22 15:42:51 +00:00
|
|
|
class CBotInstr;
|
|
|
|
class CBotDefParam;
|
2015-12-20 15:19:10 +00:00
|
|
|
class CBotToken;
|
2015-11-15 22:41:24 +00:00
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief The CBotCStack class Management of the stack of compilation.
|
|
|
|
*/
|
|
|
|
class CBotCStack
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief CBotCStack
|
|
|
|
* \param ppapa
|
|
|
|
*/
|
|
|
|
CBotCStack(CBotCStack* ppapa);
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief CBotCStack Destructor.
|
|
|
|
*/
|
|
|
|
~CBotCStack();
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief IsOk
|
|
|
|
* \return
|
|
|
|
*/
|
|
|
|
bool IsOk();
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief GetError
|
|
|
|
* \return
|
|
|
|
*/
|
2015-12-20 18:16:01 +00:00
|
|
|
CBotError GetError();
|
2015-11-15 22:41:24 +00:00
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief GetError Gives error number
|
|
|
|
* \param start
|
|
|
|
* \param end
|
|
|
|
* \return
|
|
|
|
*/
|
2015-12-20 18:16:01 +00:00
|
|
|
CBotError GetError(int& start, int& end);
|
2015-11-15 22:41:24 +00:00
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief SetType Set the type of instruction on the stack.
|
|
|
|
* \param type
|
|
|
|
*/
|
|
|
|
void SetType(CBotTypResult& type);
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief GetTypResult Gives the type of value on the stack. Type of
|
|
|
|
* instruction on the stack.
|
|
|
|
* \param mode
|
|
|
|
* \return
|
|
|
|
*/
|
2015-12-25 18:16:54 +00:00
|
|
|
CBotTypResult GetTypResult(CBotVar::GetTypeMode mode = CBotVar::GetTypeMode::NORMAL);
|
2015-11-15 22:41:24 +00:00
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief GetType Gives the type of value on the stack.
|
|
|
|
* \param mode
|
|
|
|
* \return
|
|
|
|
*/
|
2015-12-25 18:16:54 +00:00
|
|
|
int GetType(CBotVar::GetTypeMode mode = CBotVar::GetTypeMode::NORMAL);
|
2015-11-15 22:41:24 +00:00
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief GetClass Gives the class of the value on the stack.
|
|
|
|
* \return
|
|
|
|
*/
|
|
|
|
CBotClass* GetClass();
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief AddVar Adds a local variable.
|
|
|
|
* \param p
|
|
|
|
*/
|
|
|
|
void AddVar(CBotVar* p);
|
|
|
|
|
2017-11-15 21:21:01 +00:00
|
|
|
/*!
|
|
|
|
* \brief Create 'this' as a local variable.
|
|
|
|
* \param pClass The current class referred to by 'this'
|
|
|
|
*/
|
|
|
|
void CreateVarThis(CBotClass* pClass);
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief Create 'super' as a local variable.
|
|
|
|
* \param pClass The parent class referred to by 'super'
|
|
|
|
*/
|
|
|
|
void CreateVarSuper(CBotClass* pClass);
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief Create member variables of the current class as local variables.
|
|
|
|
* \param pClass The current class.
|
|
|
|
* \param setDefined Whether to mark the variables as initialized.
|
|
|
|
*/
|
|
|
|
void CreateMemberVars(CBotClass* pClass, bool setDefined);
|
|
|
|
|
2015-11-15 22:41:24 +00:00
|
|
|
/*!
|
|
|
|
* \brief FindVar Finds a variable. Seeks a variable on the stack the token
|
|
|
|
* may be a result of TokenTypVar (object of a class) or a pointer in the
|
|
|
|
* source.
|
|
|
|
* \param p
|
|
|
|
* \return
|
|
|
|
*/
|
|
|
|
CBotVar* FindVar(CBotToken* &p);
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief FindVar
|
|
|
|
* \param Token
|
|
|
|
* \return
|
|
|
|
*/
|
|
|
|
CBotVar* FindVar(CBotToken& Token);
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief CheckVarLocal Test whether a variable is already defined locally.
|
|
|
|
* \param pToken
|
|
|
|
* \return
|
|
|
|
*/
|
|
|
|
bool CheckVarLocal(CBotToken* &pToken);
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief CopyVar Finds and makes a copy.
|
|
|
|
* \param Token
|
|
|
|
* \return
|
|
|
|
*/
|
|
|
|
CBotVar* CopyVar(CBotToken& Token);
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief TokenStack Used only at compile.
|
|
|
|
* \param pToken
|
|
|
|
* \param bBlock
|
|
|
|
* \return
|
|
|
|
*/
|
|
|
|
CBotCStack* TokenStack(CBotToken* pToken = nullptr, bool bBlock = false);
|
|
|
|
|
2021-06-12 02:47:33 +00:00
|
|
|
/*!
|
|
|
|
* \brief Deletes all subsequent stack frames created by TokenStack.
|
|
|
|
*/
|
|
|
|
void DeleteNext();
|
|
|
|
|
2015-11-15 22:41:24 +00:00
|
|
|
/*!
|
|
|
|
* \brief Return Transmits the result upper.
|
|
|
|
* \param p
|
|
|
|
* \param pParent
|
|
|
|
* \return
|
|
|
|
*/
|
|
|
|
CBotInstr* Return(CBotInstr* p, CBotCStack* pParent);
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief ReturnFunc Transmits the result upper.
|
|
|
|
* \param p
|
|
|
|
* \param pParent
|
|
|
|
* \return
|
|
|
|
*/
|
|
|
|
CBotFunction* ReturnFunc(CBotFunction* p, CBotCStack* pParent);
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief SetVar
|
|
|
|
* \param var
|
|
|
|
*/
|
|
|
|
void SetVar( CBotVar* var );
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief SetCopyVar Puts on the stack a copy of a variable.
|
|
|
|
* \param var
|
|
|
|
*/
|
|
|
|
void SetCopyVar( CBotVar* var );
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief GetVar
|
|
|
|
* \return
|
|
|
|
*/
|
|
|
|
CBotVar* GetVar();
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief SetStartError
|
|
|
|
* \param pos
|
|
|
|
*/
|
|
|
|
void SetStartError(int pos);
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief SetError
|
|
|
|
* \param n
|
|
|
|
* \param pos
|
|
|
|
*/
|
2015-12-20 18:16:01 +00:00
|
|
|
void SetError(CBotError n, int pos);
|
2015-11-15 22:41:24 +00:00
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief SetError
|
|
|
|
* \param n
|
|
|
|
* \param p
|
|
|
|
*/
|
2015-12-20 18:16:01 +00:00
|
|
|
void SetError(CBotError n, CBotToken* p);
|
2015-11-15 22:41:24 +00:00
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief ResetError
|
|
|
|
* \param n
|
|
|
|
* \param start
|
|
|
|
* \param end
|
|
|
|
*/
|
2015-12-20 18:16:01 +00:00
|
|
|
void ResetError(CBotError n, int start, int end);
|
2015-11-15 22:41:24 +00:00
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief SetRetType
|
|
|
|
* \param type
|
|
|
|
*/
|
|
|
|
void SetRetType(CBotTypResult& type);
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief GetRetType
|
|
|
|
* \return
|
|
|
|
*/
|
|
|
|
CBotTypResult GetRetType();
|
|
|
|
|
|
|
|
/*!
|
2015-12-23 15:46:41 +00:00
|
|
|
* \brief SetProgram
|
2015-11-15 22:41:24 +00:00
|
|
|
* \param p
|
|
|
|
*/
|
2015-12-23 15:46:41 +00:00
|
|
|
void SetProgram(CBotProgram* p);
|
2015-11-15 22:41:24 +00:00
|
|
|
|
|
|
|
/*!
|
2015-12-23 15:46:41 +00:00
|
|
|
* \brief GetProgram
|
2015-11-15 22:41:24 +00:00
|
|
|
* \return
|
|
|
|
*/
|
2015-12-23 15:46:41 +00:00
|
|
|
CBotProgram* GetProgram();
|
2015-11-15 22:41:24 +00:00
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief CompileCall
|
|
|
|
* \param p
|
|
|
|
* \param ppVars
|
|
|
|
* \param nIdent
|
|
|
|
* \return
|
|
|
|
*/
|
|
|
|
CBotTypResult CompileCall(CBotToken* &p, CBotVar** ppVars, long& nIdent);
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief CheckCall Test if a procedure name is already defined somewhere.
|
2017-11-15 21:21:01 +00:00
|
|
|
* \param pToken Token representing the name of a function.
|
|
|
|
* \param pParam List of parameters.
|
|
|
|
* \param className Name of a class when checking for methods.
|
2015-11-15 22:41:24 +00:00
|
|
|
* \return
|
|
|
|
*/
|
2017-11-15 21:21:01 +00:00
|
|
|
bool CheckCall(CBotToken* &pToken, CBotDefParam* pParam, const std::string& className);
|
2015-11-15 22:41:24 +00:00
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief NextToken
|
|
|
|
* \param p
|
|
|
|
* \return
|
|
|
|
*/
|
|
|
|
bool NextToken(CBotToken* &p);
|
|
|
|
|
|
|
|
private:
|
2021-06-12 02:47:33 +00:00
|
|
|
std::unique_ptr<CBotCStack> m_next;
|
2015-11-15 22:41:24 +00:00
|
|
|
CBotCStack* m_prev;
|
|
|
|
|
2021-06-12 02:47:33 +00:00
|
|
|
int m_errStart = 0;
|
|
|
|
|
|
|
|
struct Data;
|
|
|
|
|
|
|
|
CBotCStack::Data* m_data;
|
2015-11-15 22:41:24 +00:00
|
|
|
|
|
|
|
//! Result of the operations.
|
2021-06-12 02:47:33 +00:00
|
|
|
std::unique_ptr<CBotVar> m_var;
|
2015-11-15 22:41:24 +00:00
|
|
|
//! Is part of a block (variables are local to this block).
|
|
|
|
bool m_bBlock;
|
2021-06-12 02:47:33 +00:00
|
|
|
std::list<std::unique_ptr<CBotVar>> m_listVar;
|
2015-11-15 22:41:24 +00:00
|
|
|
};
|
2015-12-26 13:19:24 +00:00
|
|
|
|
|
|
|
} // namespace CBot
|