Better CBot class destructor parsing (#257)
The previous one broke the NOT (~) operation parsing
This reverts commit 7c8a31c074
.
dev-time-step
parent
45a433525f
commit
c9e0249008
|
@ -616,8 +616,11 @@ bool CBotClass::CompileDefItem(CBotToken* &p, CBotCStack* pStack, bool bSecond)
|
||||||
|
|
||||||
while (pStack->IsOk())
|
while (pStack->IsOk())
|
||||||
{
|
{
|
||||||
CBotToken* pp = p;
|
std::string pp = p->GetString();
|
||||||
IsOfType(p, ID_NOT); // skips ~ eventual (destructor)
|
if ( IsOfType(p, ID_NOT) )
|
||||||
|
{
|
||||||
|
pp = std::string("~") + p->GetString();
|
||||||
|
}
|
||||||
|
|
||||||
if (IsOfType(p, TokenTypVar))
|
if (IsOfType(p, TokenTypVar))
|
||||||
{
|
{
|
||||||
|
@ -670,12 +673,12 @@ bool CBotClass::CompileDefItem(CBotToken* &p, CBotCStack* pStack, bool bSecond)
|
||||||
CBotFunction* prev = nullptr;
|
CBotFunction* prev = nullptr;
|
||||||
while ( pf != nullptr )
|
while ( pf != nullptr )
|
||||||
{
|
{
|
||||||
if (pf->GetName() == pp->GetString()) break;
|
if (pf->GetName() == pp) break;
|
||||||
prev = pf;
|
prev = pf;
|
||||||
pf = pf->Next();
|
pf = pf->Next();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool bConstructor = (pp->GetString() == GetName());
|
bool bConstructor = (pp == GetName());
|
||||||
CBotCStack* pile = pStack->TokenStack(nullptr, true);
|
CBotCStack* pile = pStack->TokenStack(nullptr, true);
|
||||||
|
|
||||||
// make "this" known
|
// make "this" known
|
||||||
|
@ -760,7 +763,7 @@ bool CBotClass::CompileDefItem(CBotToken* &p, CBotCStack* pStack, bool bSecond)
|
||||||
|
|
||||||
if ( !bSecond )
|
if ( !bSecond )
|
||||||
{
|
{
|
||||||
CBotVar* pv = CBotVar::Create(pp->GetString(), type);
|
CBotVar* pv = CBotVar::Create(pp, type);
|
||||||
pv -> SetStatic( bStatic );
|
pv -> SetStatic( bStatic );
|
||||||
pv -> SetPrivate( mProtect );
|
pv -> SetPrivate( mProtect );
|
||||||
|
|
||||||
|
|
|
@ -57,7 +57,7 @@ class CBotCStack;
|
||||||
* classObject->AddItem("category", CBotTypResult(CBotTypInt), CBotVar::ProtectionType::ReadOnly);
|
* classObject->AddItem("category", CBotTypResult(CBotTypInt), CBotVar::ProtectionType::ReadOnly);
|
||||||
* classObject->AddItem("position", CBotTypResult(CBotTypClass, classPoint), 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()!)
|
* 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:
|
* // This class can be used in CBot like so:
|
||||||
* // object item = radar(Me);
|
* // object item = radar(Me);
|
||||||
* // goto(item.position);
|
* // goto(item.position);
|
||||||
|
|
|
@ -285,6 +285,13 @@ CBotFunction* CBotFunction::Compile1(CBotToken* &p, CBotCStack* pStack, CBotClas
|
||||||
{
|
{
|
||||||
CBotToken* pp = p;
|
CBotToken* pp = p;
|
||||||
func->m_token = *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à ?
|
// un nom de fonction est-il là ?
|
||||||
if (IsOfType(p, TokenTypVar))
|
if (IsOfType(p, TokenTypVar))
|
||||||
{
|
{
|
||||||
|
|
|
@ -232,17 +232,6 @@ CBotToken* CBotToken::NextToken(char* &program, int& error, bool first)
|
||||||
mot = c; // built the word
|
mot = c; // built the word
|
||||||
c = *(program++); // next character
|
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
|
// special case for strings
|
||||||
if ( mot[0] == '\"' )
|
if ( mot[0] == '\"' )
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue