[colobot] 06/145: Fix class.arrays using size of one before comma

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 8b7410f803c89f5261071f28e75e7e15382b2521
Author: melex750 <melex750 at users.noreply.github.com>
Date:   Mon Mar 21 06:11:55 2016 -0400

    Fix class.arrays using size of one before comma
---
 src/CBot/CBotClass.cpp                | 34 +++++++++++++++++++++-------------
 src/CBot/CBotInstr/CBotDefBoolean.cpp |  2 +-
 src/CBot/CBotInstr/CBotDefClass.cpp   | 13 +++++++------
 src/CBot/CBotInstr/CBotDefFloat.cpp   |  2 +-
 src/CBot/CBotInstr/CBotDefInt.cpp     |  2 +-
 src/CBot/CBotInstr/CBotDefString.cpp  |  2 +-
 src/CBot/CBotInstr/CBotListArray.cpp  | 15 ++++++++-------
 src/CBot/CBotInstr/CBotListArray.h    |  1 -
 8 files changed, 40 insertions(+), 31 deletions(-)

diff --git a/src/CBot/CBotClass.cpp b/src/CBot/CBotClass.cpp
index aca2d2b..e701db8 100644
--- a/src/CBot/CBotClass.cpp
+++ b/src/CBot/CBotClass.cpp
@@ -550,6 +550,7 @@ bool CBotClass::CompileDefItem(CBotToken* &p, CBotCStack* pStack, bool bSecond)
 
     while (pStack->IsOk())
     {
+        CBotTypResult  type2 = CBotTypResult(type);                     // reset type after comma
         std::string pp = p->GetString();
         if ( IsOfType(p, ID_NOT) )
         {
@@ -575,7 +576,7 @@ bool CBotClass::CompileDefItem(CBotToken* &p, CBotCStack* pStack, bool bSecond)
                 else
                     i = new CBotEmpty();                            // special if not a formula
 
-                type = CBotTypResult(CBotTypArrayPointer, type);
+                type2 = CBotTypResult(CBotTypArrayPointer, type2);
 
                 if (limites == nullptr) limites = i;
                 else limites->AddNext3(i);
@@ -671,7 +672,7 @@ bool CBotClass::CompileDefItem(CBotToken* &p, CBotCStack* pStack, bool bSecond)
             }
 
             // definition of an element
-            if (type.Eq(0))
+            if (type2.Eq(0))
             {
                 pStack->SetError(CBotErrNoTerminator, p);
                 return false;
@@ -683,26 +684,33 @@ bool CBotClass::CompileDefItem(CBotToken* &p, CBotCStack* pStack, bool bSecond)
                 pStack->SetStartError(p->GetStart());
                 if ( IsOfType(p, ID_SEP) )
                 {
-                    pStack->SetError(CBotErrNoExpression, p->GetPrev());
+                    pStack->SetError(CBotErrNoExpression, p->GetStart());
                     return false;
                 }
-                if ( type.Eq(CBotTypArrayPointer) )
+                if ( type2.Eq(CBotTypArrayPointer) )
                 {
-                    i = CBotListArray::Compile(p, pStack, type.GetTypElem());
+                    if ( nullptr == (i = CBotListArray::Compile(p, pStack, type2.GetTypElem())) )
+                    {
+                        if (pStack->IsOk())
+                        {
+                            i = CBotTwoOpExpr::Compile(p, pStack);
+                            if (i == nullptr || !pStack->GetTypResult().Compare(type2))
+                            {
+                                pStack->SetError(CBotErrBadType1, p->GetStart());
+                                return false;
+                            }
+                        }
+                    }
                 }
                 else
                 {
                     // it has an assignmet to calculate
                     i = CBotTwoOpExpr::Compile(p, pStack);
 
-                    CBotTypResult retType = pStack->GetTypResult(CBotVar::GetTypeMode::CLASS_AS_INTRINSIC);
-
-                    if ( (type.Eq(CBotTypString) && !retType.Eq(CBotTypString)) ||
-                         (!(type.Eq(CBotTypPointer) && retType.Eq(CBotTypNullPointer)) &&
-                          !TypeCompatible( type, retType, ID_ASS)) )
-                          
+                    if ( !(type.Eq(CBotTypPointer) && pStack->GetTypResult().Eq(CBotTypNullPointer)) &&
+                         !TypesCompatibles( type, pStack->GetTypResult()) )
                     {
-                        pStack->SetError(CBotErrBadType1, p->GetPrev());
+                        pStack->SetError(CBotErrBadType1, p->GetStart());
                         return false;
                     }
                 }
@@ -712,7 +720,7 @@ bool CBotClass::CompileDefItem(CBotToken* &p, CBotCStack* pStack, bool bSecond)
 
             if ( !bSecond )
             {
-                CBotVar*    pv = CBotVar::Create(pp, type);
+                CBotVar*    pv = CBotVar::Create(pp, type2);
                 pv -> SetStatic( bStatic );
                 pv -> SetPrivate( mProtect );
 
diff --git a/src/CBot/CBotInstr/CBotDefBoolean.cpp b/src/CBot/CBotInstr/CBotDefBoolean.cpp
index d64a186..e89bdc8 100644
--- a/src/CBot/CBotInstr/CBotDefBoolean.cpp
+++ b/src/CBot/CBotInstr/CBotDefBoolean.cpp
@@ -90,7 +90,7 @@ CBotInstr* CBotDefBoolean::Compile(CBotToken* &p, CBotCStack* pStack, bool cont,
             pStk->SetStartError(p->GetStart());
             if ( IsOfType(p, ID_SEP) )
             {
-                pStk->SetError(CBotErrNoExpression, p->GetPrev());
+                pStk->SetError(CBotErrNoExpression, p->GetStart());
                 goto error;
             }
             if (nullptr == ( inst->m_expr = CBotTwoOpExpr::Compile( p, pStk )))
diff --git a/src/CBot/CBotInstr/CBotDefClass.cpp b/src/CBot/CBotInstr/CBotDefClass.cpp
index ab4ea99..f7ea77a 100644
--- a/src/CBot/CBotInstr/CBotDefClass.cpp
+++ b/src/CBot/CBotInstr/CBotDefClass.cpp
@@ -155,14 +155,15 @@ 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) )
+            if (inst->m_hasParams)
             {
-                pStk->SetError(CBotErrNoExpression, p->GetPrev());
+                pStk->SetError(CBotErrNoTerminator, p->GetStart());
                 goto error;
             }
-            if (inst->m_hasParams)
+
+            if ( IsOfType(p, ID_SEP) )
             {
-                pStk->SetError(CBotErrNoTerminator, p->GetStart());
+                pStk->SetError(CBotErrNoExpression, p->GetStart());
                 goto error;
             }
 
@@ -201,7 +202,7 @@ CBotInstr* CBotDefClass::Compile(CBotToken* &p, CBotCStack* pStack, CBotClass* p
             var->SetInit(CBotVar::InitType::IS_POINTER);                            // marks the pointer as init
         }
 suite:
-        if (pStk->IsOk() && 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
             {
@@ -209,7 +210,7 @@ suite:
             }
         }
 
-        if (!pStk->IsOk() || 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 5348a52..1746658 100644
--- a/src/CBot/CBotInstr/CBotDefFloat.cpp
+++ b/src/CBot/CBotInstr/CBotDefFloat.cpp
@@ -89,7 +89,7 @@ CBotInstr* CBotDefFloat::Compile(CBotToken* &p, CBotCStack* pStack, bool cont, b
             pStk->SetStartError(p->GetStart());
             if ( IsOfType(p, ID_SEP) )
             {
-                pStk->SetError(CBotErrNoExpression, p->GetPrev());
+                pStk->SetError(CBotErrNoExpression, p->GetStart());
                 goto error;
             }
             if (nullptr == ( inst->m_expr = CBotTwoOpExpr::Compile( p, pStk )))
diff --git a/src/CBot/CBotInstr/CBotDefInt.cpp b/src/CBot/CBotInstr/CBotDefInt.cpp
index babd3fd..4e946e9 100644
--- a/src/CBot/CBotInstr/CBotDefInt.cpp
+++ b/src/CBot/CBotInstr/CBotDefInt.cpp
@@ -93,7 +93,7 @@ CBotInstr* CBotDefInt::Compile(CBotToken* &p, CBotCStack* pStack, bool cont, boo
             pStk->SetStartError(p->GetStart());
             if ( IsOfType(p, ID_SEP) )
             {
-                pStk->SetError(CBotErrNoExpression, p->GetPrev());
+                pStk->SetError(CBotErrNoExpression, p->GetStart());
                 goto error;
             }
             if (nullptr == ( inst->m_expr = CBotTwoOpExpr::Compile( p, pStk )))
diff --git a/src/CBot/CBotInstr/CBotDefString.cpp b/src/CBot/CBotInstr/CBotDefString.cpp
index cb4502d..9bf2eeb 100644
--- a/src/CBot/CBotInstr/CBotDefString.cpp
+++ b/src/CBot/CBotInstr/CBotDefString.cpp
@@ -93,7 +93,7 @@ CBotInstr* CBotDefString::Compile(CBotToken* &p, CBotCStack* pStack, bool cont,
             pStk->SetStartError(p->GetStart());
             if ( IsOfType(p, ID_SEP) )
             {
-                pStk->SetError(CBotErrNoExpression, p->GetPrev());
+                pStk->SetError(CBotErrNoExpression, p->GetStart());
                 goto error;
             }
             if (nullptr == ( inst->m_expr = CBotTwoOpExpr::Compile( p, pStk )))
diff --git a/src/CBot/CBotInstr/CBotListArray.cpp b/src/CBot/CBotInstr/CBotListArray.cpp
index bc6ac28..559bb9d 100644
--- a/src/CBot/CBotInstr/CBotListArray.cpp
+++ b/src/CBot/CBotInstr/CBotListArray.cpp
@@ -61,15 +61,13 @@ CBotInstr* CBotListArray::Compile(CBotToken* &p, CBotCStack* pStack, CBotTypResu
 
     CBotListArray*    inst = new CBotListArray();
 
-    pStk->SetStartError(p->GetStart());
-
     if (IsOfType( p, ID_OPBLK ))
     {
         // each element takes the one after the other
         if (type.Eq( CBotTypArrayPointer ))
         {
             pStk->SetStartError(p->GetStart());
-            if ( nullptr == (inst->m_expr = CBotListArray::Compile(p, pStk, type.GetTypElem())) )
+            if (nullptr == ( inst->m_expr = CBotListArray::Compile( p, pStk, type.GetTypElem() ) ))
             {
                 if (pStk->IsOk())
                 {
@@ -81,11 +79,13 @@ CBotInstr* CBotListArray::Compile(CBotToken* &p, CBotCStack* pStack, CBotTypResu
                     }
                 }
             }
+
             while (IsOfType( p, ID_COMMA ))                                     // other elements?
             {
                 pStk->SetStartError(p->GetStart());
+
                 CBotInstr* i = nullptr;
-                if ( nullptr == (i = CBotListArray::Compile(p, pStk, type.GetTypElem())) )
+                if (nullptr == ( i = CBotListArray::Compile(p, pStk, type.GetTypElem() ) ))
                 {
                     if (pStk->IsOk())
                     {
@@ -97,7 +97,9 @@ CBotInstr* CBotListArray::Compile(CBotToken* &p, CBotCStack* pStack, CBotTypResu
                         }
                     }
                 }
+
                 inst->m_expr->AddNext3(i);
+
                 if ( p->GetType() == ID_COMMA ) continue;
                 if ( p->GetType() == ID_CLBLK ) break;
 
@@ -108,7 +110,6 @@ CBotInstr* CBotListArray::Compile(CBotToken* &p, CBotCStack* pStack, CBotTypResu
         else
         {
             pStk->SetStartError(p->GetStart());
-
             if (nullptr == ( inst->m_expr = CBotTwoOpExpr::Compile( p, pStk )))
             {
                 goto error;
@@ -116,7 +117,7 @@ CBotInstr* CBotListArray::Compile(CBotToken* &p, CBotCStack* pStack, CBotTypResu
             CBotVar* pv = pStk->GetVar();                                       // result of the expression
 
             if (pv == nullptr || (!TypesCompatibles( type, pv->GetTypResult()) &&
-                !(type.Eq(CBotTypPointer) && pv->GetTypResult().Eq(CBotTypNullPointer))) ) // compatible type?
+                !(type.Eq(CBotTypPointer) && pv->GetTypResult().Eq(CBotTypNullPointer)) ))
             {
                 pStk->SetError(CBotErrBadType1, p->GetStart());
                 goto error;
@@ -135,7 +136,7 @@ CBotInstr* CBotListArray::Compile(CBotToken* &p, CBotCStack* pStack, CBotTypResu
                 CBotVar* pv = pStk->GetVar();                                   // result of the expression
 
                 if (pv == nullptr || (!TypesCompatibles( type, pv->GetTypResult()) &&
-                    !(type.Eq(CBotTypPointer) && pv->GetTypResult().Eq(CBotTypNullPointer))) ) // compatible type?
+                    !(type.Eq(CBotTypPointer) && pv->GetTypResult().Eq(CBotTypNullPointer)) ))
                 {
                     pStk->SetError(CBotErrBadType1, p->GetStart());
                     goto error;
diff --git a/src/CBot/CBotInstr/CBotListArray.h b/src/CBot/CBotInstr/CBotListArray.h
index 329e587..c5f800b 100644
--- a/src/CBot/CBotInstr/CBotListArray.h
+++ b/src/CBot/CBotInstr/CBotListArray.h
@@ -38,7 +38,6 @@ public:
      * \param p
      * \param pStack
      * \param type
-     * \param classItem
      * \return
      */
     static CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack, CBotTypResult type);

-- 
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