[colobot] 44/62: Fix 'this' for object:: functions
Didier Raboud
odyx at moszumanska.debian.org
Fri Nov 10 11:53:58 UTC 2017
This is an automated email from the git hooks/post-receive script.
odyx pushed a commit to branch debian/master
in repository colobot.
commit a9e0874abcfd9f070c6f1288eff0c031d7a31010
Author: melex750 <melex750 at users.noreply.github.com>
Date: Tue Oct 24 04:46:07 2017 -0400
Fix 'this' for object:: functions
Fixes #672
Fixes #1026
---
src/CBot/CBotInstr/CBotExprVar.cpp | 4 ++++
src/CBot/CBotInstr/CBotFunction.cpp | 10 ++++++----
src/CBot/CBotInstr/CBotLeftExpr.cpp | 2 ++
3 files changed, 12 insertions(+), 4 deletions(-)
diff --git a/src/CBot/CBotInstr/CBotExprVar.cpp b/src/CBot/CBotInstr/CBotExprVar.cpp
index ed77d8a..ed20c6f 100644
--- a/src/CBot/CBotInstr/CBotExprVar.cpp
+++ b/src/CBot/CBotInstr/CBotExprVar.cpp
@@ -76,6 +76,8 @@ CBotInstr* CBotExprVar::Compile(CBotToken*& p, CBotCStack* pStack, bool bCheckRe
// This is an element of the current class
// ads the equivalent of this. before
CBotToken token("this");
+ // invisible 'this.' highlights member token on error
+ token.SetPos(p->GetStart(), p->GetEnd());
inst->SetToken(&token);
(static_cast<CBotExprVar*>(inst))->m_nIdent = -2; // identificator for this
@@ -196,6 +198,8 @@ CBotInstr* CBotExprVar::CompileMethode(CBotToken* &p, CBotCStack* pStack)
// this is an element of the current class
// adds the equivalent of this. before
+ // invisible 'this.' highlights member token on error
+ pthis.SetPos(pp->GetStart(), pp->GetEnd());
inst->SetToken(&pthis);
(static_cast<CBotExprVar*>(inst))->m_nIdent = -2; // ident for this
diff --git a/src/CBot/CBotInstr/CBotFunction.cpp b/src/CBot/CBotInstr/CBotFunction.cpp
index c24f986..13b9005 100644
--- a/src/CBot/CBotInstr/CBotFunction.cpp
+++ b/src/CBot/CBotInstr/CBotFunction.cpp
@@ -464,6 +464,7 @@ void CBotFunction::RestoreState(CBotVar** ppVars, CBotStack* &pj, CBotVar* pInst
{
CBotVar* pThis = pile->FindVar("this");
pThis->SetInit(CBotVar::InitType::IS_POINTER);
+ pThis->SetPointer(pInstance);
pThis->SetUniqNum(-2);
}
@@ -672,6 +673,7 @@ int CBotFunction::DoCall(CBotProgram* program, const std::list<CBotFunction*>& l
{
CBotTypResult type;
CBotFunction* pt = nullptr;
+ CBotProgram* baseProg = pStack->GetProgram(true);
pt = FindLocalOrPublic(localFunctionList, nIdent, name, ppVars, type);
@@ -695,7 +697,7 @@ int CBotFunction::DoCall(CBotProgram* program, const std::list<CBotFunction*>& l
if (pStk3b->GetState() == 0 && !pt->m_MasterClass.empty())
{
- CBotVar* pInstance = program->m_thisVar;
+ CBotVar* pInstance = (baseProg != nullptr) ? baseProg->m_thisVar : nullptr;
// make "this" known
CBotVar* pThis ;
if ( pInstance == nullptr )
@@ -762,8 +764,7 @@ void CBotFunction::RestoreCall(const std::list<CBotFunction*>& localFunctionList
CBotFunction* pt = nullptr;
CBotStack* pStk1;
CBotStack* pStk3;
-
- // search function to return the ok identifier
+ CBotProgram* baseProg = pStack->GetProgram(true);
pt = FindLocalOrPublic(localFunctionList, nIdent, name, ppVars, type);
@@ -792,10 +793,11 @@ void CBotFunction::RestoreCall(const std::list<CBotFunction*>& localFunctionList
{
if ( !pt->m_MasterClass.empty() )
{
-// CBotVar* pInstance = m_pProg->m_thisVar;
+ CBotVar* pInstance = (baseProg != nullptr) ? baseProg->m_thisVar : nullptr;
// make "this" known
CBotVar* pThis = pStk1->FindVar("this");
pThis->SetInit(CBotVar::InitType::IS_POINTER);
+ pThis->SetPointer(pInstance);
pThis->SetUniqNum(-2);
}
}
diff --git a/src/CBot/CBotInstr/CBotLeftExpr.cpp b/src/CBot/CBotInstr/CBotLeftExpr.cpp
index 4c4400a..3c701eb 100644
--- a/src/CBot/CBotInstr/CBotLeftExpr.cpp
+++ b/src/CBot/CBotInstr/CBotLeftExpr.cpp
@@ -72,6 +72,8 @@ CBotLeftExpr* CBotLeftExpr::Compile(CBotToken* &p, CBotCStack* pStack)
// this is an element of the current class
// adds the equivalent of this. before
CBotToken pthis("this");
+ // invisible 'this.' highlights member token on error
+ pthis.SetPos(p->GetStart(), p->GetEnd());
inst->SetToken(&pthis);
inst->m_nIdent = -2; // indent for this
--
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