2015-11-15 17:31:57 +00:00
|
|
|
/*
|
|
|
|
* 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
|
|
|
|
|
2015-11-23 20:59:56 +00:00
|
|
|
#include "CBot/CBotInstr/CBotInstr.h"
|
2015-11-16 21:00:01 +00:00
|
|
|
|
2015-12-24 14:07:40 +00:00
|
|
|
#include <set>
|
2015-11-15 17:31:57 +00:00
|
|
|
|
2015-12-26 13:19:24 +00:00
|
|
|
namespace CBot
|
|
|
|
{
|
2015-11-15 17:31:57 +00:00
|
|
|
|
2015-12-30 18:13:32 +00:00
|
|
|
/**
|
|
|
|
* \brief A function declaration in the code
|
|
|
|
*
|
|
|
|
* Examples:
|
|
|
|
* \code
|
|
|
|
* void test() { ... }
|
|
|
|
* void test(int a, float b) { ... }
|
|
|
|
* int test(int a, float b, string c) { ... }
|
|
|
|
* public bool test(int a, float b, string c, SomeClass d) { ... }
|
|
|
|
* extern void test() { ... }
|
|
|
|
* void classname::test() { ... }
|
|
|
|
* \endcode
|
2015-11-15 17:31:57 +00:00
|
|
|
*/
|
|
|
|
class CBotFunction : public CBotInstr
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CBotFunction();
|
|
|
|
~CBotFunction();
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief Compile Compiles a new function
|
|
|
|
* \param p
|
|
|
|
* \param pStack
|
|
|
|
* \param pFunc
|
|
|
|
* \param bLocal allows of the declaration of parameters on the same level
|
|
|
|
* as the elements belonging to the class for methods.
|
|
|
|
* \return
|
|
|
|
*/
|
|
|
|
static CBotFunction* Compile(CBotToken* &p,
|
|
|
|
CBotCStack* pStack,
|
|
|
|
CBotFunction* pFunc,
|
|
|
|
bool bLocal = true);
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief Compile1 Pre-compile a new function.
|
|
|
|
* \param p
|
|
|
|
* \param pStack
|
|
|
|
* \param pClass
|
|
|
|
* \return
|
|
|
|
*/
|
|
|
|
static CBotFunction* Compile1(CBotToken* &p,
|
|
|
|
CBotCStack* pStack,
|
|
|
|
CBotClass* pClass);
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief Execute
|
|
|
|
* \param ppVars
|
|
|
|
* \param pj
|
|
|
|
* \param pInstance
|
|
|
|
* \return
|
|
|
|
*/
|
|
|
|
bool Execute(CBotVar** ppVars,
|
|
|
|
CBotStack* &pj,
|
|
|
|
CBotVar* pInstance = nullptr);
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief RestoreState
|
|
|
|
* \param ppVars
|
|
|
|
* \param pj
|
|
|
|
* \param pInstance
|
|
|
|
*/
|
|
|
|
void RestoreState(CBotVar** ppVars,
|
|
|
|
CBotStack* &pj,
|
|
|
|
CBotVar* pInstance = nullptr);
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief AddNext
|
|
|
|
* \param p
|
|
|
|
*/
|
|
|
|
void AddNext(CBotFunction* p);
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief CompileCall
|
|
|
|
* \param name
|
|
|
|
* \param ppVars
|
|
|
|
* \param nIdent
|
|
|
|
* \return
|
|
|
|
*/
|
2015-12-20 15:19:10 +00:00
|
|
|
CBotTypResult CompileCall(const std::string& name,
|
2015-11-15 17:31:57 +00:00
|
|
|
CBotVar** ppVars,
|
|
|
|
long& nIdent);
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief FindLocalOrPublic Is a function according to its unique identifier
|
|
|
|
* if the identifier is not found, looking by name and parameters.
|
|
|
|
* \param nIdent
|
|
|
|
* \param name
|
|
|
|
* \param ppVars
|
|
|
|
* \param TypeOrError
|
|
|
|
* \param bPublic
|
|
|
|
* \return
|
|
|
|
*/
|
2015-12-20 15:19:10 +00:00
|
|
|
CBotFunction* FindLocalOrPublic(long& nIdent, const std::string& name,
|
2015-11-15 17:31:57 +00:00
|
|
|
CBotVar** ppVars,
|
|
|
|
CBotTypResult& TypeOrError,
|
|
|
|
bool bPublic = true);
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief DoCall Fait un appel à une fonction.
|
|
|
|
* \param nIdent
|
|
|
|
* \param name
|
|
|
|
* \param ppVars
|
|
|
|
* \param pStack
|
|
|
|
* \param pToken
|
|
|
|
* \return
|
|
|
|
*/
|
|
|
|
|
|
|
|
int DoCall(long& nIdent,
|
2015-12-20 15:19:10 +00:00
|
|
|
const std::string& name,
|
2015-11-15 17:31:57 +00:00
|
|
|
CBotVar** ppVars,
|
|
|
|
CBotStack* pStack,
|
|
|
|
CBotToken* pToken);
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief RestoreCall
|
|
|
|
* \param nIdent
|
|
|
|
* \param name
|
|
|
|
* \param ppVars
|
|
|
|
* \param pStack
|
|
|
|
*/
|
|
|
|
void RestoreCall(long& nIdent,
|
2015-12-20 15:19:10 +00:00
|
|
|
const std::string& name,
|
2015-11-15 17:31:57 +00:00
|
|
|
CBotVar** ppVars,
|
|
|
|
CBotStack* pStack);
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief DoCall Makes call of a method note: this is already on the stack,
|
|
|
|
* the pointer pThis is just to simplify.
|
|
|
|
* \param nIdent
|
|
|
|
* \param name
|
|
|
|
* \param pThis
|
|
|
|
* \param ppVars
|
|
|
|
* \param pStack
|
|
|
|
* \param pToken
|
|
|
|
* \param pClass
|
|
|
|
* \return
|
|
|
|
*/
|
|
|
|
int DoCall(long& nIdent,
|
2015-12-20 15:19:10 +00:00
|
|
|
const std::string& name,
|
2015-11-15 17:31:57 +00:00
|
|
|
CBotVar* pThis,
|
|
|
|
CBotVar** ppVars,
|
|
|
|
CBotStack* pStack,
|
|
|
|
CBotToken* pToken,
|
|
|
|
CBotClass* pClass);
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief RestoreCall
|
|
|
|
* \param nIdent
|
|
|
|
* \param name
|
|
|
|
* \param pThis
|
|
|
|
* \param ppVars
|
|
|
|
* \param pStack
|
|
|
|
* \param pClass
|
|
|
|
*/
|
|
|
|
void RestoreCall(long& nIdent,
|
2015-12-20 15:19:10 +00:00
|
|
|
const std::string& name,
|
2015-11-15 17:31:57 +00:00
|
|
|
CBotVar* pThis,
|
|
|
|
CBotVar** ppVars,
|
|
|
|
CBotStack* pStack,
|
|
|
|
CBotClass* pClass);
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief CheckParam See if the "signature" of parameters is identical.
|
|
|
|
* \param pParam
|
|
|
|
* \return
|
|
|
|
*/
|
|
|
|
bool CheckParam(CBotDefParam* pParam);
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief AddPublic
|
|
|
|
* \param pfunc
|
|
|
|
*/
|
|
|
|
static void AddPublic(CBotFunction* pfunc);
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief GetName
|
|
|
|
* \return
|
|
|
|
*/
|
2015-12-20 15:19:10 +00:00
|
|
|
std::string GetName();
|
2015-11-15 17:31:57 +00:00
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief GetParams
|
|
|
|
* \return
|
|
|
|
*/
|
2015-12-20 15:19:10 +00:00
|
|
|
std::string GetParams();
|
2015-11-15 17:31:57 +00:00
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief IsPublic
|
|
|
|
* \return
|
|
|
|
*/
|
|
|
|
bool IsPublic();
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief IsExtern
|
|
|
|
* \return
|
|
|
|
*/
|
|
|
|
bool IsExtern();
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief Next
|
|
|
|
* \return
|
|
|
|
*/
|
|
|
|
CBotFunction* Next();
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief GetPosition
|
|
|
|
* \param start
|
|
|
|
* \param stop
|
|
|
|
* \param modestart
|
|
|
|
* \param modestop
|
|
|
|
* \return
|
|
|
|
*/
|
|
|
|
bool GetPosition(int& start, int& stop,
|
|
|
|
CBotGet modestart,
|
|
|
|
CBotGet modestop);
|
|
|
|
|
2015-12-27 15:51:57 +00:00
|
|
|
protected:
|
|
|
|
virtual const std::string GetDebugName() { return "CBotFunction"; }
|
|
|
|
virtual std::string GetDebugData();
|
|
|
|
virtual std::map<std::string, CBotInstr*> GetDebugLinks();
|
|
|
|
|
2015-11-15 17:31:57 +00:00
|
|
|
private:
|
2015-12-27 15:51:57 +00:00
|
|
|
friend class CBotDebug;
|
2015-11-15 17:31:57 +00:00
|
|
|
long m_nFuncIdent;
|
|
|
|
//! Synchronized method.
|
|
|
|
bool m_bSynchro;
|
|
|
|
|
|
|
|
//! Parameter list.
|
2015-12-27 15:51:57 +00:00
|
|
|
CBotDefParam* m_param;
|
2015-11-15 17:31:57 +00:00
|
|
|
//! The instruction block.
|
2015-12-27 15:51:57 +00:00
|
|
|
CBotInstr* m_block;
|
2015-11-15 17:31:57 +00:00
|
|
|
CBotFunction* m_next;
|
|
|
|
//! If returns CBotTypClass.
|
|
|
|
CBotToken m_retToken;
|
|
|
|
//! Complete type of the result.
|
|
|
|
CBotTypResult m_retTyp;
|
|
|
|
//! Public function.
|
|
|
|
bool m_bPublic;
|
|
|
|
//! Extern function.
|
|
|
|
bool m_bExtern;
|
2015-12-25 14:13:52 +00:00
|
|
|
//! Name of the class we are part of
|
2015-12-20 15:19:10 +00:00
|
|
|
std::string m_MasterClass;
|
2015-12-25 14:13:52 +00:00
|
|
|
//! Token of the class we are part of
|
|
|
|
CBotToken m_classToken;
|
2015-11-15 17:31:57 +00:00
|
|
|
CBotProgram* m_pProg;
|
|
|
|
//! For the position of the word "extern".
|
|
|
|
CBotToken m_extern;
|
|
|
|
CBotToken m_openpar;
|
|
|
|
CBotToken m_closepar;
|
|
|
|
CBotToken m_openblk;
|
|
|
|
CBotToken m_closeblk;
|
|
|
|
|
2015-12-24 14:07:40 +00:00
|
|
|
//! List of public functions
|
|
|
|
static std::set<CBotFunction*> m_publicFunctions;
|
2015-11-15 17:31:57 +00:00
|
|
|
|
|
|
|
friend class CBotProgram;
|
|
|
|
friend class CBotClass;
|
|
|
|
friend class CBotCStack;
|
|
|
|
|
|
|
|
};
|
2015-12-26 13:19:24 +00:00
|
|
|
|
|
|
|
} // namespace CBot
|