2015-11-11 16:24:37 +00:00
|
|
|
/*
|
|
|
|
* This file is part of the Colobot: Gold Edition source code
|
2016-02-13 13:11:30 +00:00
|
|
|
* Copyright (C) 2001-2016, Daniel Roux, EPSITEC SA & TerranovaTeam
|
2015-11-11 16:24:37 +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
|
|
|
|
*/
|
|
|
|
|
2015-12-31 13:44:19 +00:00
|
|
|
#include "CBot/CBotInstr/CBotExprLitString.h"
|
2015-11-11 16:24:37 +00:00
|
|
|
|
2015-11-23 20:59:56 +00:00
|
|
|
#include "CBot/CBotStack.h"
|
|
|
|
#include "CBot/CBotCStack.h"
|
2015-11-14 11:56:16 +00:00
|
|
|
|
2015-11-23 20:59:56 +00:00
|
|
|
#include "CBot/CBotVar/CBotVar.h"
|
2015-11-15 22:18:47 +00:00
|
|
|
|
2015-12-26 13:19:24 +00:00
|
|
|
namespace CBot
|
|
|
|
{
|
2015-11-11 16:24:37 +00:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2015-12-31 13:44:19 +00:00
|
|
|
CBotExprLitString::CBotExprLitString()
|
2015-11-11 16:24:37 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2015-12-31 13:44:19 +00:00
|
|
|
CBotExprLitString::~CBotExprLitString()
|
2015-11-11 16:24:37 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2015-12-31 13:44:19 +00:00
|
|
|
CBotInstr* CBotExprLitString::Compile(CBotToken* &p, CBotCStack* pStack)
|
2015-11-11 16:24:37 +00:00
|
|
|
{
|
|
|
|
CBotCStack* pStk = pStack->TokenStack();
|
|
|
|
|
2015-12-31 13:44:19 +00:00
|
|
|
CBotExprLitString* inst = new CBotExprLitString();
|
2015-11-11 16:24:37 +00:00
|
|
|
|
|
|
|
inst->SetToken(p);
|
|
|
|
p = p->GetNext();
|
|
|
|
|
2015-12-23 16:50:10 +00:00
|
|
|
CBotVar* var = CBotVar::Create("", CBotTypString);
|
2015-11-11 16:24:37 +00:00
|
|
|
pStk->SetVar(var);
|
|
|
|
|
|
|
|
return pStack->Return(inst, pStk);
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2015-12-31 13:44:19 +00:00
|
|
|
bool CBotExprLitString::Execute(CBotStack* &pj)
|
2015-11-11 16:24:37 +00:00
|
|
|
{
|
|
|
|
CBotStack* pile = pj->AddStack(this);
|
|
|
|
|
|
|
|
if (pile->IfStep()) return false;
|
|
|
|
|
2015-12-23 16:50:10 +00:00
|
|
|
CBotVar* var = CBotVar::Create("", CBotTypString);
|
2015-11-11 16:24:37 +00:00
|
|
|
|
2015-12-20 15:19:10 +00:00
|
|
|
std::string chaine = m_token.GetString();
|
|
|
|
chaine = chaine.substr(1, chaine.length()-2); // removes the quotes
|
2015-11-11 16:24:37 +00:00
|
|
|
|
|
|
|
var->SetValString(chaine); // value of the number
|
|
|
|
|
|
|
|
pile->SetVar(var); // put on the stack
|
|
|
|
|
|
|
|
return pj->Return(pile);
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2015-12-31 13:44:19 +00:00
|
|
|
void CBotExprLitString::RestoreState(CBotStack* &pj, bool bMain)
|
2015-11-11 16:24:37 +00:00
|
|
|
{
|
|
|
|
if (bMain) pj->RestoreStack(this);
|
|
|
|
}
|
2015-12-26 13:19:24 +00:00
|
|
|
|
2015-12-31 13:44:19 +00:00
|
|
|
std::string CBotExprLitString::GetDebugData()
|
2015-12-27 15:51:57 +00:00
|
|
|
{
|
|
|
|
return m_token.GetString();
|
|
|
|
}
|
|
|
|
|
2015-12-26 13:19:24 +00:00
|
|
|
} // namespace CBot
|