[colobot] 175/377: Better CBot class destructor parsing (#257)
Didier Raboud
odyx at moszumanska.debian.org
Wed Mar 30 13:34:12 UTC 2016
This is an automated email from the git hooks/post-receive script.
odyx pushed a commit to branch debian/master
in repository colobot.
commit c9e0249008bed8c76a43cc616c39e7a8f7ae46b5
Author: krzys-h <krzys_h at interia.pl>
Date: Wed Dec 23 12:47:37 2015 +0100
Better CBot class destructor parsing (#257)
The previous one broke the NOT (~) operation parsing
This reverts commit 7c8a31c074e98bce8efcf97d87ceea95e9f7d55c.
---
src/CBot/CBotClass.cpp | 13 ++++++++-----
src/CBot/CBotClass.h | 2 +-
src/CBot/CBotInstr/CBotFunction.cpp | 7 +++++++
src/CBot/CBotToken.cpp | 11 -----------
4 files changed, 16 insertions(+), 17 deletions(-)
diff --git a/src/CBot/CBotClass.cpp b/src/CBot/CBotClass.cpp
index c2a6e5b..9817a7b 100644
--- a/src/CBot/CBotClass.cpp
+++ b/src/CBot/CBotClass.cpp
@@ -616,8 +616,11 @@ bool CBotClass::CompileDefItem(CBotToken* &p, CBotCStack* pStack, bool bSecond)
while (pStack->IsOk())
{
- CBotToken* pp = p;
- IsOfType(p, ID_NOT); // skips ~ eventual (destructor)
+ std::string pp = p->GetString();
+ if ( IsOfType(p, ID_NOT) )
+ {
+ pp = std::string("~") + p->GetString();
+ }
if (IsOfType(p, TokenTypVar))
{
@@ -670,12 +673,12 @@ bool CBotClass::CompileDefItem(CBotToken* &p, CBotCStack* pStack, bool bSecond)
CBotFunction* prev = nullptr;
while ( pf != nullptr )
{
- if (pf->GetName() == pp->GetString()) break;
+ if (pf->GetName() == pp) break;
prev = pf;
pf = pf->Next();
}
- bool bConstructor = (pp->GetString() == GetName());
+ bool bConstructor = (pp == GetName());
CBotCStack* pile = pStack->TokenStack(nullptr, true);
// make "this" known
@@ -760,7 +763,7 @@ bool CBotClass::CompileDefItem(CBotToken* &p, CBotCStack* pStack, bool bSecond)
if ( !bSecond )
{
- CBotVar* pv = CBotVar::Create(pp->GetString(), type);
+ CBotVar* pv = CBotVar::Create(pp, type);
pv -> SetStatic( bStatic );
pv -> SetPrivate( mProtect );
diff --git a/src/CBot/CBotClass.h b/src/CBot/CBotClass.h
index 5e3410e..c924281 100644
--- a/src/CBot/CBotClass.h
+++ b/src/CBot/CBotClass.h
@@ -57,7 +57,7 @@ class CBotCStack;
* classObject->AddItem("category", CBotTypResult(CBotTypInt), CBotVar::ProtectionType::ReadOnly);
* classObject->AddItem("position", CBotTypResult(CBotTypClass, classPoint), CBotVar::ProtectionType::ReadOnly);
* classObject->AddFunction("func", rFunc, cFunc); // TODO: Document function format for class methods (different from standard CBotProgram::AddFunction()!)
- *
+ *
* // This class can be used in CBot like so:
* // object item = radar(Me);
* // goto(item.position);
diff --git a/src/CBot/CBotInstr/CBotFunction.cpp b/src/CBot/CBotInstr/CBotFunction.cpp
index 9235245..7b4f1f9 100644
--- a/src/CBot/CBotInstr/CBotFunction.cpp
+++ b/src/CBot/CBotInstr/CBotFunction.cpp
@@ -285,6 +285,13 @@ CBotFunction* CBotFunction::Compile1(CBotToken* &p, CBotCStack* pStack, CBotClas
{
CBotToken* pp = p;
func->m_token = *p;
+
+ if ( IsOfType(p, ID_NOT) )
+ {
+ CBotToken d(std::string("~") + p->GetString());
+ func->m_token = d;
+ }
+
// un nom de fonction est-il là ?
if (IsOfType(p, TokenTypVar))
{
diff --git a/src/CBot/CBotToken.cpp b/src/CBot/CBotToken.cpp
index 9951c18..914a54e 100644
--- a/src/CBot/CBotToken.cpp
+++ b/src/CBot/CBotToken.cpp
@@ -232,17 +232,6 @@ CBotToken* CBotToken::NextToken(char* &program, int& error, bool first)
mot = c; // built the word
c = *(program++); // next character
- // special case for destructors
- if ( mot[0] == '~')
- {
- while (c != 0 && !CharInList(c, sep1))
- {
- mot += c;
- c = *(program++);
- }
- stop = true;
- }
-
// special case for strings
if ( mot[0] == '\"' )
{
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-games/colobot.git
More information about the Pkg-games-commits
mailing list