[colobot] 02/145: Add syntax and type checking for class member vars

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 accfc9357372fd87a71723ebdc3d0210cce2a92c
Author: melex750 <melex750 at users.noreply.github.com>
Date:   Sun Mar 20 07:50:42 2016 -0400

    Add syntax and type checking for class member vars
---
 src/CBot/CBotClass.cpp | 44 ++++++++++++++++++++++++++++++--------------
 1 file changed, 30 insertions(+), 14 deletions(-)

diff --git a/src/CBot/CBotClass.cpp b/src/CBot/CBotClass.cpp
index d5007d8..5f76145 100644
--- a/src/CBot/CBotClass.cpp
+++ b/src/CBot/CBotClass.cpp
@@ -19,6 +19,7 @@
 
 #include "CBot/CBotClass.h"
 
+#include "CBot/CBotInstr/CBotInstrUtils.h"
 #include "CBot/CBotInstr/CBotNew.h"
 #include "CBot/CBotInstr/CBotLeftExprVar.h"
 #include "CBot/CBotInstr/CBotTwoOpExpr.h"
@@ -561,29 +562,27 @@ bool CBotClass::CompileDefItem(CBotToken* &p, CBotCStack* pStack, bool bSecond)
             while ( IsOfType( p, ID_OPBRK ) )   // a table?
             {
                 CBotInstr* i = nullptr;
-
+                pStack->SetStartError( p->GetStart() );
                 if ( p->GetType() != ID_CLBRK )
+                {
                     i = CBotExpression::Compile( p, pStack );           // expression for the value
+                    if (i == nullptr || pStack->GetType() >= CBotTypBoolean) // must be a number
+                    {
+                        pStack->SetError(CBotErrBadIndex, p->GetStart());
+                        return false;
+                    }
+                }
                 else
                     i = new CBotEmpty();                            // special if not a formula
 
                 type = CBotTypResult(CBotTypArrayPointer, type);
 
-                if (!pStack->IsOk() || !IsOfType( p, ID_CLBRK ) )
-                {
-                    pStack->SetError(CBotErrCloseIndex, p->GetStart());
-                    return false;
-                }
-
-/*              CBotVar* pv = pStack->GetVar();
-                if ( pv->GetType()>= CBotTypBoolean )
-                {
-                    pStack->SetError(CBotErrBadType1, p->GetStart());
-                    return false;
-                }*/
-
                 if (limites == nullptr) limites = i;
                 else limites->AddNext3(i);
+
+                if (IsOfType(p, ID_CLBRK)) continue;
+                pStack->SetError(CBotErrCloseIndex, p->GetStart());
+                return false;
             }
 
             if ( p->GetType() == ID_OPENPAR )
@@ -681,6 +680,12 @@ bool CBotClass::CompileDefItem(CBotToken* &p, CBotCStack* pStack, bool bSecond)
             CBotInstr* i = nullptr;
             if ( IsOfType(p, ID_ASS ) )
             {
+                pStack->SetStartError(p->GetStart());
+                if ( IsOfTypeList(p, TokenTypVar, ID_NEW, ID_SEP, 0) ) // no var, new, or ';'
+                {
+                    pStack->SetError(CBotErrBadLeft, p->GetPrev());
+                    return false;
+                }
                 if ( type.Eq(CBotTypArrayPointer) )
                 {
                     i = CBotListArray::Compile(p, pStack, type.GetTypElem());
@@ -689,6 +694,17 @@ bool CBotClass::CompileDefItem(CBotToken* &p, CBotCStack* pStack, bool bSecond)
                 {
                     // 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)) )
+                          
+                    {
+                        pStack->SetError(CBotErrBadType1, p->GetPrev());
+                        return false;
+                    }
                 }
                 if ( !pStack->IsOk() ) return false;
             }

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