[colobot] 03/145: Fix syntax+type checking, base types+CBotDefArray
Didier Raboud
odyx at moszumanska.debian.org
Mon Jul 11 12:56:11 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 707ef976261b4221330f93113d6886b97381c533
Author: melex750 <melex750 at users.noreply.github.com>
Date: Sun Mar 20 07:54:41 2016 -0400
Fix syntax+type checking, base types+CBotDefArray
---
src/CBot/CBotInstr/CBotDefArray.cpp | 41 +++++++++++++++++++++++------------
src/CBot/CBotInstr/CBotDefBoolean.cpp | 13 ++++++-----
src/CBot/CBotInstr/CBotDefClass.cpp | 15 +++++++------
src/CBot/CBotInstr/CBotDefFloat.cpp | 13 ++++++-----
src/CBot/CBotInstr/CBotDefInt.cpp | 25 ++++++++-------------
src/CBot/CBotInstr/CBotDefString.cpp | 10 +++++++--
6 files changed, 66 insertions(+), 51 deletions(-)
diff --git a/src/CBot/CBotInstr/CBotDefArray.cpp b/src/CBot/CBotInstr/CBotDefArray.cpp
index 2cb05aa..c70c8f9 100644
--- a/src/CBot/CBotInstr/CBotDefArray.cpp
+++ b/src/CBot/CBotInstr/CBotDefArray.cpp
@@ -72,19 +72,26 @@ CBotInstr* CBotDefArray::Compile(CBotToken* &p, CBotCStack* pStack, CBotTypResul
CBotInstr* i;
while (IsOfType(p, ID_OPBRK))
{
+ pStk->SetStartError(p->GetStart());
if (p->GetType() != ID_CLBRK)
- i = CBotExpression::Compile(p, pStk); // expression for the value
+ {
+ i = CBotExpression::Compile(p, pStk); // expression for the value
+ if (i == nullptr || pStk->GetType() >= CBotTypBoolean) // must be a number
+ {
+ pStk->SetError(CBotErrBadIndex, p->GetStart());
+ goto error;
+ }
+ }
else
i = new CBotEmpty(); // if no special formula
inst->AddNext3b(i); // construct a list
type = CBotTypResult(CBotTypArrayPointer, type);
- if (!pStk->IsOk() || !IsOfType(p, ID_CLBRK ))
- {
- pStk->SetError(CBotErrCloseIndex, p->GetStart());
- goto error;
- }
+ if (IsOfType(p, ID_CLBRK)) continue;
+
+ pStk->SetError(CBotErrCloseIndex, p->GetStart());
+ goto error;
}
CBotVar* var = CBotVar::Create(*vartoken, type); // create an instance
@@ -96,17 +103,23 @@ CBotInstr* CBotDefArray::Compile(CBotToken* &p, CBotCStack* pStack, CBotTypResul
if (IsOfType(p, ID_ASS)) // with an assignment
{
- if ((inst->m_listass = CBotTwoOpExpr::Compile(p, pStk)) != nullptr)
+ pStk->SetStartError(p->GetStart());
+ if ( IsOfType(p, ID_SEP) )
{
- if (!pStk->GetTypResult().Compare(type)) // compatible type ?
- {
- pStk->SetError(CBotErrBadType1, p->GetStart());
- goto error;
- }
+ pStk->SetError(CBotErrBadLeft, p->GetPrev());
+ goto error;
}
- else
+ if ( nullptr == (inst->m_listass = CBotListArray::Compile(p, pStk, type.GetTypElem())) )
{
- inst->m_listass = CBotListArray::Compile(p, pStk, type.GetTypElem());
+ if (pStk->IsOk())
+ {
+ inst->m_listass = CBotTwoOpExpr::Compile(p, pStk);
+ if (inst->m_listass == nullptr || !pStk->GetTypResult().Compare(type)) // compatible type ?
+ {
+ pStk->SetError(CBotErrBadType1, p->GetStart());
+ goto error;
+ }
+ }
}
}
diff --git a/src/CBot/CBotInstr/CBotDefBoolean.cpp b/src/CBot/CBotInstr/CBotDefBoolean.cpp
index bcac072..63b9d34 100644
--- a/src/CBot/CBotInstr/CBotDefBoolean.cpp
+++ b/src/CBot/CBotInstr/CBotDefBoolean.cpp
@@ -82,16 +82,17 @@ CBotInstr* CBotDefBoolean::Compile(CBotToken* &p, CBotCStack* pStack, bool cont,
inst = static_cast<CBotDefBoolean*>(CBotDefArray::Compile(p, pStk, CBotTypBoolean));
- if (!pStk->IsOk() )
- {
- pStk->SetError(CBotErrCloseIndex, p->GetStart());
- goto error;
- }
goto suite; // no assignment, variable already created
}
if (IsOfType(p, ID_ASS))
{
+ pStk->SetStartError(p->GetStart());
+ if ( IsOfType(p, ID_SEP) )
+ {
+ pStk->SetError(CBotErrBadLeft, p->GetPrev());
+ goto error;
+ }
if (nullptr == ( inst->m_expr = CBotTwoOpExpr::Compile( p, pStk )))
{
goto error;
@@ -109,7 +110,7 @@ CBotInstr* CBotDefBoolean::Compile(CBotToken* &p, CBotCStack* pStack, bool cont,
(static_cast<CBotLeftExprVar*>(inst->m_var))->m_nIdent = CBotVar::NextUniqNum());
pStack->AddVar(var);
suite:
- if (IsOfType(p, ID_COMMA))
+ if (pStk->IsOk() && IsOfType(p, ID_COMMA))
{
if (nullptr != ( inst->m_next2b = CBotDefBoolean::Compile(p, pStk, true, noskip)))
{
diff --git a/src/CBot/CBotInstr/CBotDefClass.cpp b/src/CBot/CBotInstr/CBotDefClass.cpp
index 39ac6af..72ec71e 100644
--- a/src/CBot/CBotInstr/CBotDefClass.cpp
+++ b/src/CBot/CBotInstr/CBotDefClass.cpp
@@ -101,11 +101,6 @@ CBotInstr* CBotDefClass::Compile(CBotToken* &p, CBotCStack* pStack, CBotClass* p
inst = static_cast<CBotDefClass*>(CBotDefArray::Compile(p, pStk, type ));
- if (!pStk->IsOk() )
- {
- pStk->SetError(CBotErrCloseIndex, p->GetStart());
- goto error;
- }
goto suite; // no assignment, variable already created
}
@@ -159,6 +154,12 @@ CBotInstr* CBotDefClass::Compile(CBotToken* &p, CBotCStack* pStack, CBotClass* p
if (IsOfType(p, ID_ASS)) // with a assignment?
{
+ pStk->SetStartError(p->GetStart());
+ if ( IsOfType(p, ID_SEP) )
+ {
+ pStk->SetError(CBotErrBadLeft, p->GetPrev());
+ goto error;
+ }
if (inst->m_hasParams)
{
pStk->SetError(CBotErrNoTerminator, p->GetStart());
@@ -200,7 +201,7 @@ CBotInstr* CBotDefClass::Compile(CBotToken* &p, CBotCStack* pStack, CBotClass* p
var->SetInit(CBotVar::InitType::IS_POINTER); // marks the pointer as init
}
suite:
- if (IsOfType(p, ID_COMMA)) // several chained definitions
+ if (pStk->IsOk() && IsOfType(p, ID_COMMA)) // several chained definitions
{
if ( nullptr != ( inst->m_next = CBotDefClass::Compile(p, pStk, pClass) )) // compiles the following
{
@@ -208,7 +209,7 @@ suite:
}
}
- if (IsOfType(p, ID_SEP)) // complete instruction
+ if (!pStk->IsOk() || IsOfType(p, ID_SEP)) // complete instruction
{
return pStack->Return(inst, pStk);
}
diff --git a/src/CBot/CBotInstr/CBotDefFloat.cpp b/src/CBot/CBotInstr/CBotDefFloat.cpp
index 9a99662..33398fa 100644
--- a/src/CBot/CBotInstr/CBotDefFloat.cpp
+++ b/src/CBot/CBotInstr/CBotDefFloat.cpp
@@ -81,16 +81,17 @@ CBotInstr* CBotDefFloat::Compile(CBotToken* &p, CBotCStack* pStack, bool cont, b
p = vartoken;
inst = static_cast<CBotDefFloat*>(CBotDefArray::Compile(p, pStk, CBotTypFloat));
- if (!pStk->IsOk() )
- {
- pStk->SetError(CBotErrCloseIndex, p->GetStart());
- goto error;
- }
goto suite; // no assignment, variable already created
}
if (IsOfType(p, ID_ASS))
{
+ pStk->SetStartError(p->GetStart());
+ if ( IsOfType(p, ID_SEP) )
+ {
+ pStk->SetError(CBotErrBadLeft, p->GetPrev());
+ goto error;
+ }
if (nullptr == ( inst->m_expr = CBotTwoOpExpr::Compile( p, pStk )))
{
goto error;
@@ -108,7 +109,7 @@ CBotInstr* CBotDefFloat::Compile(CBotToken* &p, CBotCStack* pStack, bool cont, b
(static_cast<CBotLeftExprVar*>(inst->m_var))->m_nIdent = CBotVar::NextUniqNum());
pStack->AddVar(var);
suite:
- if (IsOfType(p, ID_COMMA))
+ if (pStk->IsOk() && IsOfType(p, ID_COMMA))
{
if (nullptr != ( inst->m_next2b = CBotDefFloat::Compile(p, pStk, true, noskip)))
{
diff --git a/src/CBot/CBotInstr/CBotDefInt.cpp b/src/CBot/CBotInstr/CBotDefInt.cpp
index 360eb22..9f7dcb6 100644
--- a/src/CBot/CBotInstr/CBotDefInt.cpp
+++ b/src/CBot/CBotInstr/CBotDefInt.cpp
@@ -84,25 +84,18 @@ CBotInstr* CBotDefInt::Compile(CBotToken* &p, CBotCStack* pStack, bool cont, boo
CBotInstr* inst2 = CBotDefArray::Compile(p, pStk, CBotTypInt);
- if (!pStk->IsOk() )
- {
- pStk->SetError(CBotErrCloseIndex, p->GetStart());
- goto error;
- }
-
- if (IsOfType(p, ID_COMMA)) // several definition chained
- {
- if (nullptr != ( inst2->m_next2b = CBotDefInt::Compile(p, pStk, true, noskip))) // compile the next one
- {
- return pStack->Return(inst2, pStk);
- }
- }
inst = static_cast<CBotDefInt*>(inst2);
goto suite; // no assignment, variable already created
}
if (IsOfType(p, ID_ASS)) // with an assignment?
{
+ pStk->SetStartError(p->GetStart());
+ if ( IsOfType(p, ID_SEP) )
+ {
+ pStk->SetError(CBotErrBadLeft, p->GetPrev());
+ goto error;
+ }
if (nullptr == ( inst->m_expr = CBotTwoOpExpr::Compile( p, pStk )))
{
goto error;
@@ -121,15 +114,15 @@ CBotInstr* CBotDefInt::Compile(CBotToken* &p, CBotCStack* pStack, bool cont, boo
(static_cast<CBotLeftExprVar*>(inst->m_var))->m_nIdent = CBotVar::NextUniqNum());
pStack->AddVar(var); // place it on the stack
}
-
- if (IsOfType(p, ID_COMMA)) // chained several definitions
+suite:
+ if (pStk->IsOk() && IsOfType(p, ID_COMMA)) // chained several definitions
{
if (nullptr != ( inst->m_next2b = CBotDefInt::Compile(p, pStk, true, noskip))) // compile next one
{
return pStack->Return(inst, pStk);
}
}
-suite:
+
if (noskip || IsOfType(p, ID_SEP)) // instruction is completed
{
return pStack->Return(inst, pStk);
diff --git a/src/CBot/CBotInstr/CBotDefString.cpp b/src/CBot/CBotInstr/CBotDefString.cpp
index c878a84..b224a1c 100644
--- a/src/CBot/CBotInstr/CBotDefString.cpp
+++ b/src/CBot/CBotInstr/CBotDefString.cpp
@@ -75,15 +75,21 @@ CBotInstr* CBotDefString::Compile(CBotToken* &p, CBotCStack* pStack, bool cont,
if (IsOfType(p, ID_ASS))
{
+ pStk->SetStartError(p->GetStart());
+ if ( IsOfType(p, ID_SEP) )
+ {
+ pStk->SetError(CBotErrBadLeft, p->GetPrev());
+ goto error;
+ }
if (nullptr == ( inst->m_expr = CBotTwoOpExpr::Compile( p, pStk )))
{
goto error;
}
-/* if (!pStk->GetTypResult().Eq(CBotTypString)) // type compatible ?
+ if (!pStk->GetTypResult().Eq(CBotTypString)) // type compatible ?
{
pStk->SetError(CBotErrBadType1, p->GetStart());
goto error;
- }*/
+ }
}
CBotVar* var = CBotVar::Create(*vartoken, CBotTypString);
--
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