Improve performance for loop and insertion 42/16442/3
Antoine ELIAS [Wed, 29 Apr 2015 09:27:30 +0000 (11:27 +0200)]
Change-Id: I963599a21312ef536ca6cebfecde9debd57b04d2

27 files changed:
scilab/modules/ast/includes/analysis/data/DataManager.hxx
scilab/modules/ast/includes/ast/deserializervisitor.hxx
scilab/modules/ast/includes/exps/caseexp.hxx
scilab/modules/ast/includes/exps/controlexp.hxx
scilab/modules/ast/includes/exps/exp.hxx
scilab/modules/ast/includes/exps/forexp.hxx
scilab/modules/ast/includes/exps/functiondec.hxx
scilab/modules/ast/includes/exps/ifexp.hxx
scilab/modules/ast/includes/exps/selectexp.hxx
scilab/modules/ast/includes/exps/seqexp.hxx
scilab/modules/ast/includes/exps/trycatchexp.hxx
scilab/modules/ast/includes/exps/whileexp.hxx
scilab/modules/ast/includes/symbol/context.hxx
scilab/modules/ast/includes/symbol/variables.hxx
scilab/modules/ast/includes/types/double.hxx
scilab/modules/ast/includes/types/types.hxx
scilab/modules/ast/includes/types/types_tools.hxx
scilab/modules/ast/src/cpp/ast/run_AssignExp.hpp
scilab/modules/ast/src/cpp/ast/runvisitor.cpp
scilab/modules/ast/src/cpp/symbol/context.cpp
scilab/modules/ast/src/cpp/types/arrayof.cpp
scilab/modules/ast/src/cpp/types/implicitlist.cpp
scilab/modules/ast/src/cpp/types/macro.cpp
scilab/modules/ast/src/cpp/types/types_tools.cpp
scilab/modules/ast/tests/unit_tests/controlexp.dia.ref [new file with mode: 0644]
scilab/modules/ast/tests/unit_tests/controlexp.tst [new file with mode: 0644]
scilab/modules/core/macros/isRelease.sci

index 687e3b1..127ce36 100644 (file)
@@ -22,6 +22,7 @@
 
 #include "allexp.hxx"
 #include "allvar.hxx"
+#include "alldec.hxx"
 #include "tools.hxx"
 #include "Block.hxx"
 #include "FunctionBlock.hxx"
index c348efe..d557606 100644 (file)
@@ -306,7 +306,7 @@ private :
                 if ( hasElse )
                 {
                     Exp* _else = get_exp();
-                    ifexp = new IfExp(loc, *test, *_then, *_else);
+                    ifexp = new IfExp(loc, *test, *_then->getAs<SeqExp>(), *_else->getAs<SeqExp>());
                 }
                 else
                 {
@@ -330,7 +330,7 @@ private :
             {
                 Exp* test = get_exp();
                 Exp* body = get_exp();
-                exp = new WhileExp(loc, *test, *body);
+                exp = new WhileExp(loc, *test, *body->getAs<SeqExp>());
                 break;
             }
             case 17:
@@ -338,7 +338,7 @@ private :
                 Location vardec_location = get_location();
                 VarDec* vardec = get_VarDec(vardec_location);
                 Exp* body = get_exp();
-                exp = new ForExp(loc, *vardec, *body);
+                exp = new ForExp(loc, *vardec, *body->getAs<SeqExp>());
                 break;
             }
             case 18:
@@ -456,7 +456,7 @@ private :
                 exps_t* returns_list = get_vars();
                 ArrayListVar *args = new ArrayListVar(args_loc, *args_list);
                 ArrayListVar *returns = new ArrayListVar(returns_loc, *returns_list);
-                exp = new FunctionDec(loc, *name, *args, *returns, *body);
+                exp = new FunctionDec(loc, *name, *args, *returns, *body->getAs<SeqExp>());
                 delete name;
                 break;
             }
index a5503e5..e98998c 100644 (file)
@@ -23,13 +23,13 @@ class CaseExp : public ControlExp
 public :
     CaseExp(const Location& location,
             Exp& test,
-            Exp& body) :
+            SeqExp& body) :
         ControlExp (location)
     {
         test.setParent(this);
         body.setParent(this);
         _exps.push_back(&test);
-        _exps.push_back(&body);
+        _exps.push_back(body.getAs<Exp>());
     }
 
     ~CaseExp()
@@ -38,7 +38,7 @@ public :
 
     virtual CaseExp* clone()
     {
-        CaseExp* cloned = new CaseExp(getLocation(), *getTest()->clone(), *getBody()->clone());
+        CaseExp* cloned = new CaseExp(getLocation(), *getTest()->clone(), *getBody()->clone()->getAs<SeqExp>());
         cloned->setVerbose(isVerbose());
         return cloned;
     }
index c47ad7b..f0484bc 100644 (file)
@@ -14,6 +14,7 @@
 #define AST_CONTROLEXP_HXX
 
 #include "exp.hxx"
+#include "seqexp.hxx"
 
 namespace ast
 {
@@ -31,6 +32,37 @@ public:
     virtual ~ControlExp ()
     {
     }
+
+    //forward continuable information to children
+    virtual inline void setContinuable(void)
+    {
+        Exp::setContinuable();
+        for (auto exp : _exps)
+        {
+            exp->setContinuable();
+        }
+    }
+
+    //forward returnable information to children
+    virtual inline void setReturnable(void)
+    {
+        Exp::setReturnable();
+        for (auto exp : _exps)
+        {
+            exp->setReturnable();
+        }
+    }
+
+    //forward breakable information to children
+    virtual inline void setBreakable(void)
+    {
+        Exp::setBreakable();
+        for (auto exp : _exps)
+        {
+            exp->setBreakable();
+        }
+    }
+
 };
 } // namespace ast
 #endif /* !AST_CONTROLEXP_HXX */
index 62df94f..21d34d6 100644 (file)
@@ -117,6 +117,7 @@ public:
         return _verbose;
     }
 
+    //manage break instruction
     inline void setBreak(void)
     {
         _bBreak = true;
@@ -132,7 +133,7 @@ public:
         return _bBreak;
     }
 
-    inline void setBreakable(void)
+    virtual inline void setBreakable(void)
     {
         _bBreakable = true;
     }
@@ -147,6 +148,7 @@ public:
         return _bBreakable;
     }
 
+    //manage return instruction
     inline void setReturn(void)
     {
         _bReturn = true;
@@ -162,7 +164,7 @@ public:
         return _bReturn;
     }
 
-    inline void setReturnable(void)
+    virtual inline void setReturnable(void)
     {
         _bReturnable = true;
     }
@@ -177,6 +179,7 @@ public:
         return _bReturnable;
     }
 
+    //manage continue instruction
     inline void setContinue(void)
     {
         _bContinue = true;
@@ -192,7 +195,7 @@ public:
         return _bContinue;
     }
 
-    inline void setContinuable(void)
+    virtual inline void setContinuable(void)
     {
         _bContinuable = true;
     }
index 17caaf7..5cefea4 100644 (file)
@@ -42,13 +42,16 @@ public:
     ** \li "print("WipeOut")" is the body
     */
     ForExp (const Location& location,
-            Exp& vardec, Exp& body)
+            Exp& vardec, SeqExp& body)
         : ControlExp (location)
     {
         vardec.setParent(this);
         body.setParent(this);
         _exps.push_back(&vardec);
-        _exps.push_back(&body);
+        _exps.push_back(body.getAs<Exp>());
+
+        body.setBreakable();
+        body.setContinuable();
     }
 
     /** \brief Destroy a For Expression node.
@@ -61,7 +64,7 @@ public:
 
     virtual ForExp* clone()
     {
-        ForExp* cloned = new ForExp(getLocation(), *getVardec().clone(), *getBody().clone());
+        ForExp* cloned = new ForExp(getLocation(), *getVardec().clone(), *getBody().clone()->getAs<SeqExp>());
         cloned->setVerbose(isVerbose());
         return cloned;
     }
index 1f81f2d..6f87cbf 100644 (file)
 
 #include <list>
 
+#include "context.hxx"
 #include "dec.hxx"
-#include "symbol.hxx"
-#include "exp.hxx"
 #include "arraylistvar.hxx"
+#include "seqexp.hxx"
 
 using namespace std;
 
@@ -50,7 +50,7 @@ public:
                  symbol::Symbol name,
                  Exp& args,
                  Exp& returns,
-                 Exp& body)
+                 SeqExp& body)
         : Dec (location),
           _name (name),
           _stack(NULL)
@@ -60,7 +60,9 @@ public:
         body.setParent(this);
         _exps.push_back(&args);
         _exps.push_back(&returns);
-        _exps.push_back(&body);
+        _exps.push_back(body.getAs<Exp>());
+
+        body.setReturnable();
     }
 
     virtual ~FunctionDec ()
@@ -72,7 +74,7 @@ public:
 
     virtual FunctionDec* clone()
     {
-        FunctionDec* cloned = new FunctionDec(getLocation(), getSymbol(), *getArgs().clone(), *getReturns().clone(), *getBody().clone());
+        FunctionDec* cloned = new FunctionDec(getLocation(), getSymbol(), *getArgs().clone(), *getReturns().clone(), *getBody().clone()->getAs<SeqExp>());
         cloned->setVerbose(isVerbose());
         return cloned;
     }
index a135bd6..32833ed 100644 (file)
@@ -34,7 +34,7 @@ public:
     ** \param else instruction if test is false
     */
     IfExp(const Location& location,
-          Exp& test, Exp& t, Exp& e)
+          Exp& test, SeqExp& t, SeqExp& e)
         : ControlExp (location),
           _hasElse (true)
     {
@@ -42,8 +42,13 @@ public:
         t.setParent(this);
         e.setParent(this);
         _exps.push_back(&test);
-        _exps.push_back(&t);
-        _exps.push_back(&e);
+        _exps.push_back(t.getAs<Exp>());
+        _exps.push_back(e.getAs<Exp>());
+
+        t.setContinuable();
+        t.setBreakable();
+        e.setContinuable();
+        e.setBreakable();
     }
 
     IfExp(const Location& location,
@@ -55,9 +60,12 @@ public:
         t.setParent(this);
 
         _exps.push_back(&test);
-        _exps.push_back(&t);
+        _exps.push_back(t.getAs<Exp>());
         _exps.push_back(new ast::CommentExp(location, new std::wstring(L"No else !!")));
         _exps[2]->setParent(this);
+
+        t.setContinuable();
+        t.setBreakable();
     }
 
     virtual ~IfExp()
@@ -66,7 +74,7 @@ public:
 
     virtual IfExp* clone()
     {
-        IfExp* cloned = new IfExp(getLocation(), *getTest().clone(), *getThen().clone(), *getElse().clone());
+        IfExp* cloned = new IfExp(getLocation(), *getTest().clone(), *getThen().clone()->getAs<SeqExp>(), *getElse().clone()->getAs<SeqExp>());
         cloned->setVerbose(isVerbose());
         return cloned;
     }
index eda68f5..3b618d9 100644 (file)
@@ -38,10 +38,10 @@ public :
         select.setParent(this);
         _exps.push_back(&select);
 
-        for (exps_t::const_iterator it = cases.begin(), itEnd = cases.end(); it != itEnd ; ++it)
+        for (auto it : cases)
         {
-            (*it)->setParent(this);
-            _exps.push_back(*it);
+            it->setParent(this);
+            _exps.push_back(it);
         }
 
         delete &cases;
@@ -113,12 +113,12 @@ public :
 
     inline exps_t getCases() const
     {
-       return ast::exps_t(std::next(_exps.begin()), _hasDefault ? std::prev(_exps.end()) : _exps.end());
+        return ast::exps_t(std::next(_exps.begin()), _hasDefault ? std::prev(_exps.end()) : _exps.end());
     }
 
     inline exps_t getCases()
     {
-       return ast::exps_t(std::next(_exps.begin()), _hasDefault ? std::prev(_exps.end()) : _exps.end());
+        return ast::exps_t(std::next(_exps.begin()), _hasDefault ? std::prev(_exps.end()) : _exps.end());
     }
 
     Exp* getDefaultCase() const
index 2cc0d69..441bc8e 100644 (file)
@@ -19,7 +19,6 @@
 #define __AST_SEQEXP_HXX__
 
 #include "exp.hxx"
-#include "functiondec.hxx"
 
 namespace ast
 {
@@ -40,10 +39,10 @@ public:
             exps_t& body)
         : Exp (location)
     {
-        for (exps_t::const_iterator it = body.begin(), itEnd = body.end(); it != itEnd ; ++it)
+        for (auto it : body)
         {
-            (*it)->setParent(this);
-            _exps.push_back(*it);
+            it->setParent(this);
+            _exps.push_back(it);
         }
 
         delete &body;
@@ -56,9 +55,9 @@ public:
     virtual SeqExp* clone()
     {
         exps_t* exp = new exps_t;
-        for (exps_t::const_iterator it = _exps.begin(), itEnd = _exps.end(); it != itEnd; ++it)
+        for (auto it : _exps)
         {
-            exp->push_back((*it)->clone());
+            exp->push_back(it->clone());
         }
 
         SeqExp* cloned = new SeqExp(getLocation(), *exp);
@@ -101,6 +100,36 @@ public:
     {
         return true;
     }
+
+    //forward continuable information to children
+    virtual inline void setContinuable(void)
+    {
+        Exp::setContinuable();
+        for (auto exp : _exps)
+        {
+            exp->setContinuable();
+        }
+    }
+
+    //forward returnable information to children
+    virtual inline void setReturnable(void)
+    {
+        Exp::setReturnable();
+        for (auto exp : _exps)
+        {
+            exp->setReturnable();
+        }
+    }
+
+    //forward breakable information to children
+    virtual inline void setBreakable(void)
+    {
+        Exp::setBreakable();
+        for (auto exp : _exps)
+        {
+            exp->setBreakable();
+        }
+    }
 };
 
 } // namespace ast
index ec001aa..f54bc44 100644 (file)
@@ -37,14 +37,14 @@ public:
     ** \param body EXP LIST intruction
     */
     TryCatchExp (const Location& location,
-                 Exp& tryme,
-                 Exp& catchme)
+                 SeqExp& tryme,
+                 SeqExp& catchme)
         : ControlExp (location)
     {
         tryme.setParent(this);
         catchme.setParent(this);
-        _exps.push_back(&tryme);
-        _exps.push_back(&catchme);
+        _exps.push_back(tryme.getAs<Exp>());
+        _exps.push_back(catchme.getAs<Exp>());
     }
 
     virtual ~TryCatchExp ()
@@ -53,7 +53,7 @@ public:
 
     virtual TryCatchExp* clone()
     {
-        TryCatchExp* cloned = new TryCatchExp(getLocation(), *getTry().clone(), *getCatch().clone());
+        TryCatchExp* cloned = new TryCatchExp(getLocation(), *getTry().clone()->getAs<SeqExp>(), *getCatch().clone()->getAs<SeqExp>());
         cloned->setVerbose(isVerbose());
         return cloned;
     }
index c534519..4a75885 100644 (file)
@@ -40,13 +40,17 @@ public:
     ** \li "print("WipeOut")" body of the loop
     */
     WhileExp (const Location& location,
-              Exp& test, Exp& body)
+              Exp& test, SeqExp& body)
         : ControlExp (location)
     {
         test.setParent(this);
         body.setParent(this);
         _exps.push_back(&test);
-        _exps.push_back(&body);
+        _exps.push_back(body.getAs<Exp>());
+
+        //set capabilities flags @init instead of each calls.
+        body.setBreakable();
+        body.setContinuable();
     }
 
     /** \brief Destroy a While Expression node.
@@ -59,7 +63,7 @@ public:
 
     virtual WhileExp* clone()
     {
-        WhileExp* cloned = new WhileExp(getLocation(), *getTest().clone(), *getBody().clone());
+        WhileExp* cloned = new WhileExp(getLocation(), *getTest().clone(), *getBody().clone()->getAs<SeqExp>());
         cloned->setVerbose(isVerbose());
         return cloned;
     }
index 9f72cf6..7d873ee 100644 (file)
@@ -1,19 +1,19 @@
 /*
- *  Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
- *  Copyright (C) 2007-2008 - INRIA - Bruno JOFRET
- *
- *  This file must be used under the terms of the CeCILL.
- *  This source file is licensed as described in the file COPYING, which
- *  you should have received as part of this distribution.  The terms
- *  are also available at
- *  http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
- *
- */
+*  Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+*  Copyright (C) 2007-2008 - INRIA - Bruno JOFRET
+*
+*  This file must be used under the terms of the CeCILL.
+*  This source file is licensed as described in the file COPYING, which
+*  you should have received as part of this distribution.  The terms
+*  are also available at
+*  http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+*
+*/
 
 /**
- ** \file symbol/context.hh
- ** \brief Define class Context.
- */
+** \file symbol/context.hh
+** \brief Define class Context.
+*/
 
 #ifndef __CONTEXT_HXX__
 #define __CONTEXT_HXX__
@@ -34,7 +34,7 @@ namespace symbol
 */
 class EXTERN_AST Context
 {
-public :
+public:
     typedef std::map<Symbol, Variable*> VarList;
     typedef std::stack<VarList*> VarStack;
 
@@ -61,6 +61,7 @@ public :
     /** If key was associated to some Entry_T in the last opened scope, return it.
     ** Otherwise return the empty pointer. */
     types::InternalType* getCurrentLevel(const Symbol& key);
+    types::InternalType* getCurrentLevel(Variable* _var);
 
     /** If key was associated to some Entry_T in the open scopes, return the
     ** most recent insertion DESPITE the current/last one. Otherwise return the empty pointer. */
index 874d71f..f6da1c9 100644 (file)
@@ -36,7 +36,7 @@ struct Variable
 {
     typedef std::stack<ScopedVariable*> StackVar;
 
-    Variable(const Symbol& _name) : name(_name), m_Global(false), m_GlobalValue(NULL) {};
+    Variable(const Symbol& _name) : name(_name), m_Global(false), m_GlobalValue(NULL), last(nullptr) {};
     ~Variable()
     {
         while (!empty())
@@ -58,7 +58,8 @@ struct Variable
 
     void put(ScopedVariable* pSV)
     {
-        stack.push(pSV);
+        last = pSV;
+        stack.push(last);
     }
 
     void put(types::InternalType* _pIT, int _iLevel)
@@ -72,7 +73,8 @@ struct Variable
         if (empty() || top()->m_iLevel < _iLevel)
         {
             //create a new level
-            stack.push(new ScopedVariable(_iLevel, _pIT));
+            last = new ScopedVariable(_iLevel, _pIT);
+            stack.push(last);
             _pIT->IncreaseRef();
         }
         else
@@ -115,12 +117,20 @@ struct Variable
 
     inline ScopedVariable* top() const
     {
-        return stack.top();
+        return last;
     }
 
     inline void pop()
     {
         stack.pop();
+        if (stack.empty())
+        {
+            last = nullptr;
+        }
+        else
+        {
+            last = stack.top();
+        }
     }
 
     inline Symbol getSymbol() const
@@ -157,7 +167,8 @@ struct Variable
     {
         if (empty() || top()->m_iLevel != _iLevel)
         {
-            stack.push(new ScopedVariable(_iLevel, types::Double::Empty()));
+            last = new ScopedVariable(_iLevel, types::Double::Empty());
+            stack.push(last);
         }
 
         top()->m_globalVisible = _bVisible;
@@ -191,6 +202,7 @@ private :
     bool m_Global;
     types::InternalType* m_GlobalValue;
     StackVar stack;
+    ScopedVariable* last;
 };
 
 struct Variables
index c875f14..bf38951 100644 (file)
@@ -260,7 +260,52 @@ public :
 
     virtual ast::Exp*           getExp(const Location& loc);
 
-private :
+    virtual bool set(int _iPos, double _data)
+    {
+        if (_iPos >= m_iSize)
+        {
+            return false;
+        }
+
+        m_pRealData[_iPos] = _data;
+        return true;
+    }
+
+    virtual bool set(int _iRows, int _iCols, double _data)
+    {
+        return set(_iCols * getRows() + _iRows, _data);
+    }
+
+    virtual bool set(double* _pdata)
+    {
+        if (m_pRealData == NULL)
+        {
+            return false;
+        }
+
+        for (int i = 0; i < m_iSize; i++)
+        {
+            m_pRealData[i] = _pdata[i];
+        }
+        return true;
+    }
+
+    virtual bool set(const double* _pdata)
+    {
+        if (m_pRealData == NULL)
+        {
+            return false;
+        }
+
+        for (int i = 0; i < m_iSize; i++)
+        {
+            m_pRealData[i] = _pdata[i];
+        }
+        return true;
+    }
+
+
+private:
     virtual bool                subMatrixToString(std::wostringstream& ostr, int* _piDims, int _iDims);
 
     virtual double              getNullValue();
@@ -269,6 +314,7 @@ private :
     virtual void                deleteAll();
     virtual void                deleteImg();
     virtual double*             allocData(int _iSize);
+    virtual void                deleteData(double /*data*/) { }
 
     bool                        m_bViewAsInteger;
     bool                        m_bViewAsZComplex;
index 9cdf20e..8ea3d08 100644 (file)
@@ -23,6 +23,7 @@ extern "C"
 #include "core_math.h"
 }
 
+#define MAX_DIMS 32
 namespace types
 {
 /*
@@ -36,7 +37,7 @@ protected :
     int                         m_iCols;
     int                         m_iSize;
     int                         m_iSizeMax;
-    int                         m_piDims[50];
+    int                         m_piDims[MAX_DIMS];
     int                         m_iDims;
 
 
index 90cae5e..c5933a7 100644 (file)
@@ -1,14 +1,14 @@
 /*
- *  Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
- *  Copyright (C) 2011 - DIGITEO - Antoine ELIAS
- *
- *  This file must be used under the terms of the CeCILL.
- *  This source file is licensed as described in the file COPYING, which
- *  you should have received as part of this distribution.  The terms
- *  are also available at
- *  http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
- *
- */
+*  Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+*  Copyright (C) 2011 - DIGITEO - Antoine ELIAS
+*
+*  This file must be used under the terms of the CeCILL.
+*  This source file is licensed as described in the file COPYING, which
+*  you should have received as part of this distribution.  The terms
+*  are also available at
+*  http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+*
+*/
 
 #ifndef __TYPES_TOOLS_HXX__
 #define __TYPES_TOOLS_HXX__
@@ -18,6 +18,8 @@
 
 namespace types
 {
+bool getScalarIndex(GenericType* _pRef, typed_list* _pArgsIn, int* index);
+bool getImplicitIndex(GenericType* _pRef, typed_list* _pArgsIn, std::vector<int>& index);
 EXTERN_AST int checkIndexesArguments(InternalType* _pRef, typed_list* _pArgsIn, typed_list* _pArgsOut, int* _piMaxDim, int* _piCountDim);
 EXTERN_AST void cleanIndexesArguments(typed_list* _pArgsOrig, typed_list* _pArgsNew);
 EXTERN_AST void getIndexesWithDims(int _iIndex, int* _piIndexes, int* _piDims, int _iDims);
index ac2107b..78739c3 100644 (file)
 /*
- *  Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
- *  Copyright (C) 2008-2008 - DIGITEO - Antoine ELIAS
- *
- *  This file must be used under the terms of the CeCILL.
- *  This source file is licensed as described in the file COPYING, which
- *  you should have received as part of this distribution.  The terms
- *  are also available at
- *  http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
- *
- */
+*  Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+*  Copyright (C) 2008-2008 - DIGITEO - Antoine ELIAS
+*
+*  This file must be used under the terms of the CeCILL.
+*  This source file is licensed as described in the file COPYING, which
+*  you should have received as part of this distribution.  The terms
+*  are also available at
+*  http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+*
+*/
 
 //file included in runvisitor.cpp
 namespace ast {
 
-template<class T>
-void RunVisitorT<T>::visitprivate(const AssignExp  &e)
-{
-    symbol::Context* ctx = symbol::Context::getInstance();
-    /*Create local exec visitor*/
-    try
+    template<class T>
+    void RunVisitorT<T>::visitprivate(const AssignExp  &e)
     {
-        SimpleVar * pVar = NULL;
-        if (e.getLeftExp().isSimpleVar())
+        symbol::Context* ctx = symbol::Context::getInstance();
+        /*Create local exec visitor*/
+        try
         {
-            pVar = static_cast<SimpleVar*>(&e.getLeftExp());
-        }
+            SimpleVar * pVar = NULL;
+            if (e.getLeftExp().isSimpleVar())
+            {
+                pVar = static_cast<SimpleVar*>(&e.getLeftExp());
+            }
 
-        /*get king of left hand*/
-        if (pVar)
-        {
-            // x = ?
-            /*getting what to assign*/
-            InternalType *pIT = e.getRightVal();
-            if (pIT == NULL)
+            /*get king of left hand*/
+            if (pVar)
             {
-                setExpectedSize(1);
-                e.getRightExp().accept(*this);
+                // x = ?
+                /*getting what to assign*/
+                InternalType *pIT = e.getRightVal();
+                if (pIT == NULL)
+                {
+                    setExpectedSize(1);
+                    e.getRightExp().accept(*this);
 
-                if (getResultSize() != 1)
+                    if (getResultSize() != 1)
+                    {
+                        std::wostringstream os;
+                        os << _W("Can not assign multiple value in a single variable") << std::endl;
+                        //os << ((Location)e.getRightExp().getLocation()).getLocationString() << std::endl;
+                        throw ast::ScilabError(os.str(), 999, e.getRightExp().getLocation());
+                    }
+
+                    pIT = getResult();
+                    //reset result
+                    setResult(NULL);
+                }
+
+                if (pIT->isImplicitList())
                 {
-                    std::wostringstream os;
-                    os << _W("Can not assign multiple value in a single variable") << std::endl;
-                    //os << ((Location)e.getRightExp().getLocation()).getLocationString() << std::endl;
-                    throw ast::ScilabError(os.str(), 999, e.getRightExp().getLocation());
+                    if (pIT->getAs<ImplicitList>()->isComputable())
+                    {
+                        InternalType *pTemp = pIT->getAs<ImplicitList>()->extractFullMatrix();
+                        delete pIT;
+                        pIT = pTemp;
+                    }
                 }
 
-                pIT = getResult();
-                //reset result
-                setResult(NULL);
-            }
+                if (pIT->isAssignable() == false)
+                {
+                    if (pIT->isListDelete())
+                    {
+                        //used to delete a variable in current scope
+                        symbol::Symbol sym = pVar->getSymbol();
+                        if (ctx->isprotected(sym) == false)
+                        {
+                            ctx->remove(sym);
+                        }
+                        else
+                        {
+                            std::wostringstream os;
+                            os << _W("Redefining permanent variable.\n");
+                            throw ast::ScilabError(os.str(), 999, e.getLeftExp().getLocation());
+                        }
+                    }
 
-            if (pIT->isImplicitList())
-            {
-                if (pIT->getAs<ImplicitList>()->isComputable())
+                    setResult(NULL);
+                    return;
+                }
+
+                if (pIT->isList() && pIT->getRef() > 0)
                 {
-                    InternalType *pTemp = pIT->getAs<ImplicitList>()->extractFullMatrix();
-                    delete pIT;
-                    pIT = pTemp;
+                    // Prevent modification of all scilab variable
+                    // which point to this container when it is used
+                    // in setfield scilab function.
+                    // A clone on a container will not clone what it contain.
+                    pIT = pIT->clone();
                 }
-            }
 
-            if (pIT->isAssignable() == false)
-            {
-                if (pIT->isListDelete())
+                if (e.getRightExp().isReturnExp())
                 {
-                    //used to delete a variable in current scope
-                    symbol::Symbol sym = pVar->getSymbol();
-                    if (ctx->isprotected(sym) == false)
+                    //ReturnExp so, put the value in the previous scope
+                    ctx->putInPreviousScope(pVar->getStack(), pIT);
+                    ((AssignExp*)&e)->setReturn();
+                }
+                else
+                {
+                    if (ctx->isprotected(pVar->getStack()) == false)
                     {
-                        ctx->remove(sym);
+                        ctx->put(pVar->getStack(), pIT);
                     }
                     else
                     {
@@ -78,379 +111,384 @@ void RunVisitorT<T>::visitprivate(const AssignExp  &e)
                     }
                 }
 
-                setResult(NULL);
+                if (e.isVerbose() && ConfigVariable::isPromptShow())
+                {
+                    std::wstring wstrName = pVar->getSymbol().getName();
+                    std::wostringstream ostr;
+                    ostr << wstrName << L"  = " << std::endl << std::endl;
+                    scilabWriteW(ostr.str().c_str());
+                    std::wostringstream ostrName;
+                    ostrName << wstrName;
+                    VariableToString(pIT, ostrName.str().c_str());
+                }
                 return;
             }
 
-            if(pIT->isList() && pIT->getRef() > 0)
+            if (e.getLeftExp().isCellCallExp())
             {
-                // Prevent modification of all scilab variable
-                // which point to this container when it is used
-                // in setfield scilab function.
-                // A clone on a container will not clone what it contain.
-                pIT = pIT->clone();
-            }
+                CellCallExp *pCell = static_cast<CellCallExp*>(&e.getLeftExp());
+                InternalType *pOut = NULL;
 
-            if (e.getRightExp().isReturnExp())
-            {
-                //ReturnExp so, put the value in the previous scope
-                ctx->putInPreviousScope(pVar->getStack(), pIT);
-                ((AssignExp*)&e)->setReturn();
-            }
-            else
-            {
-                if (ctx->isprotected(pVar->getStack()) == false)
+                /*getting what to assign*/
+                InternalType* pITR = e.getRightVal();
+                if (pITR == NULL)
                 {
-                    ctx->put(pVar->getStack(), pIT);
+                    e.getRightExp().accept(*this);
+                    pITR = getResult();
+                    //reset result
+                    setResult(NULL);
                 }
-                else
+
+                if (pITR == NULL)
                 {
+                    // if the right hand is NULL.
                     std::wostringstream os;
-                    os << _W("Redefining permanent variable.\n");
+                    os << _W("Unable to extract right part expression.\n");
                     throw ast::ScilabError(os.str(), 999, e.getLeftExp().getLocation());
                 }
-            }
-
-            if (e.isVerbose() && ConfigVariable::isPromptShow())
-            {
-                std::wstring wstrName = pVar->getSymbol().getName();
-                std::wostringstream ostr;
-                ostr << wstrName << L"  = " << std::endl << std::endl;
-                scilabWriteW(ostr.str().c_str());
-                std::wostringstream ostrName;
-                ostrName << wstrName;
-                VariableToString(pIT, ostrName.str().c_str());
-            }
-            return;
-        }
-
-        CellCallExp *pCell = dynamic_cast<CellCallExp*>(&e.getLeftExp());
-        if (pCell)
-        {
-            InternalType *pOut = NULL;
 
-            /*getting what to assign*/
-            InternalType* pITR = e.getRightVal();
-            if (pITR == NULL)
-            {
-                e.getRightExp().accept(*this);
-                pITR = getResult();
-                //reset result
-                setResult(NULL);
-            }
-
-            if (pITR == NULL)
-            {
-                // if the right hand is NULL.
-                std::wostringstream os;
-                os << _W("Unable to extract right part expression.\n");
-                throw ast::ScilabError(os.str(), 999, e.getLeftExp().getLocation());
-            }
+                std::list<ExpHistory*> fields;
+                if (getFieldsFromExp(pCell, fields) == false)
+                {
+                    for (std::list<ExpHistory*>::const_iterator i = fields.begin(), end = fields.end(); i != end; i++)
+                    {
+                        delete *i;
+                    }
+                    std::wostringstream os;
+                    os << _W("Get fields from expression failed.");
+                    throw ast::ScilabError(os.str(), 999, e.getRightExp().getLocation());
+                }
 
-            std::list<ExpHistory*> fields;
-            if (getFieldsFromExp(pCell, fields) == false)
-            {
-                for (std::list<ExpHistory*>::const_iterator i = fields.begin(), end = fields.end(); i != end; i++)
+                try
                 {
-                    delete *i;
+                    pOut = evaluateFields(pCell, fields, pITR);
+                }
+                catch (ast::ScilabError error)
+                {
+                    // catch error when call overload
+                    for (std::list<ExpHistory*>::const_iterator i = fields.begin(), end = fields.end(); i != end; i++)
+                    {
+                        (*i)->setDeleteCurrent(true);
+                        delete *i;
+                    }
+
+                    pITR->killMe();
+                    throw error;
                 }
-                std::wostringstream os;
-                os << _W("Get fields from expression failed.");
-                throw ast::ScilabError(os.str(), 999, e.getRightExp().getLocation());
-            }
 
-            try
-            {
-                pOut = evaluateFields(pCell, fields, pITR);
-            }
-            catch (ast::ScilabError error)
-            {
-                // catch error when call overload
                 for (std::list<ExpHistory*>::const_iterator i = fields.begin(), end = fields.end(); i != end; i++)
                 {
-                    (*i)->setDeleteCurrent(true);
                     delete *i;
                 }
 
                 pITR->killMe();
-                throw error;
-            }
-
-            for (std::list<ExpHistory*>::const_iterator i = fields.begin(), end = fields.end(); i != end; i++)
-            {
-                delete *i;
-            }
 
-            pITR->killMe();
-
-            if (pOut == NULL)
-            {
-                std::wostringstream os;
-                os << _W("Fields evaluation failed.");
-                throw ast::ScilabError(os.str(), 999, e.getRightExp().getLocation());
-            }
-
-            if (pOut != NULL)
-            {
-                if (e.isVerbose() && ConfigVariable::isPromptShow())
+                if (pOut == NULL)
                 {
-                    std::wostringstream ostr;
-                    ostr << *getStructNameFromExp(pCell) << L"  = " << std::endl;
-                    ostr << std::endl;
-                    scilabWriteW(ostr.str().c_str());
-
-                    VariableToString(pOut, ostr.str().c_str());
+                    std::wostringstream os;
+                    os << _W("Fields evaluation failed.");
+                    throw ast::ScilabError(os.str(), 999, e.getRightExp().getLocation());
                 }
-            }
-            else
-            {
-                //manage error
-                std::wostringstream os;
-                os << _W("Invalid Index.\n");
-                throw ast::ScilabError(os.str(), 999, e.getRightExp().getLocation());
-            }
 
-            return;
-        }
+                if (pOut != NULL)
+                {
+                    if (e.isVerbose() && ConfigVariable::isPromptShow())
+                    {
+                        std::wostringstream ostr;
+                        ostr << *getStructNameFromExp(pCell) << L"  = " << std::endl;
+                        ostr << std::endl;
+                        scilabWriteW(ostr.str().c_str());
 
-        CallExp *pCall = dynamic_cast<CallExp*>(&e.getLeftExp());
-        if (pCall)
-        {
-            //x(?) = ?
-            InternalType *pOut = NULL;
+                        VariableToString(pOut, ostr.str().c_str());
+                    }
+                }
+                else
+                {
+                    //manage error
+                    std::wostringstream os;
+                    os << _W("Invalid Index.\n");
+                    throw ast::ScilabError(os.str(), 999, e.getRightExp().getLocation());
+                }
 
-            /*getting what to assign*/
-            InternalType* pITR = e.getRightVal();
-            if (pITR == NULL)
-            {
-                e.getRightExp().accept(*this);
-                pITR = getResult();
-                //reset result
-                setResult(NULL);
+                return;
             }
 
-            if (pITR == NULL)
+            if (e.getLeftExp().isCallExp())
             {
-                // if the right hand is NULL.
-                std::wostringstream os;
-                os << _W("Unable to extract right part expression.\n");
-                throw ast::ScilabError(os.str(), 999, e.getLeftExp().getLocation());
-            }
+                CallExp *pCall = static_cast<CallExp*>(&e.getLeftExp());
+                //x(?) = ?
+                InternalType *pOut = NULL;
 
-            std::list<ExpHistory*> fields;
-            if (getFieldsFromExp(pCall, fields) == false)
-            {
-                for (std::list<ExpHistory*>::const_iterator i = fields.begin(), end = fields.end(); i != end; i++)
+                /*getting what to assign*/
+                InternalType* pITR = e.getRightVal();
+                if (pITR == NULL)
                 {
-                    delete *i;
+                    e.getRightExp().accept(*this);
+                    pITR = getResult();
+                    //reset result
+                    setResult(NULL);
                 }
 
-                std::wostringstream os;
-                os << _W("Instruction left hand side: waiting for a name.");
-                throw ast::ScilabError(os.str(), 999, e.getRightExp().getLocation());
-            }
-
-            // prevent delete after extractFullMatrix
-            // called in evaluateFields when pITR is an ImplicitList
-            pITR->IncreaseRef();
+                if (pITR == NULL)
+                {
+                    // if the right hand is NULL.
+                    std::wostringstream os;
+                    os << _W("Unable to extract right part expression.\n");
+                    throw ast::ScilabError(os.str(), 999, e.getLeftExp().getLocation());
+                }
 
-            try
-            {
-                pOut = evaluateFields(pCall, fields, pITR);
-            }
-            catch (ast::ScilabError error)
-            {
-                // catch error when call overload
-                for (std::list<ExpHistory*>::const_iterator i = fields.begin(), end = fields.end(); i != end; i++)
+                bool alreadyProcessed = false;
+                //a(...) without fields or whatever on arrayof derived types
+                if (pCall->getName().isSimpleVar())
                 {
-                    delete *i;
+                    ast::SimpleVar* var = pCall->getName().getAs<ast::SimpleVar>();
+                    InternalType* pIT = ctx->getCurrentLevel(var->getStack());
+                    if (pIT && pIT->isArrayOf())
+                    {
+                        if (ctx->isprotected(var->getStack()))
+                        {
+                            std::wostringstream os;
+                            os << _W("Redefining permanent variable.\n");
+                            throw ast::ScilabError(os.str(), 999, pCall->getLocation());
+                        }
+
+                        typed_list* currentArgs = GetArgumentList(pCall->getArgs());
+                        pOut = insertionCall(e, currentArgs, pIT, pITR);
+                        if (pOut == NULL)
+                        {
+                            std::wostringstream os;
+                            os << _W("Submatrix incorrectly defined.\n");
+                            throw ast::ScilabError(os.str(), 999, e.getLocation());
+                        }
+                        delete currentArgs;
+
+                        //update variable with new value
+                        if (pOut != pIT)
+                        {
+                            ctx->put(var->getStack(), pOut);
+                        }
+
+                        alreadyProcessed = true;
+                    }
                 }
 
-                pITR->DecreaseRef();
-                pITR->killMe();
+                if (alreadyProcessed == false)
+                {
+                    std::list<ExpHistory*> fields;
+                    if (getFieldsFromExp(pCall, fields) == false)
+                    {
+                        for (std::list<ExpHistory*>::const_iterator i = fields.begin(), end = fields.end(); i != end; i++)
+                        {
+                            delete *i;
+                        }
 
-                throw error;
-            }
+                        std::wostringstream os;
+                        os << _W("Instruction left hand side: waiting for a name.");
+                        throw ast::ScilabError(os.str(), 999, e.getRightExp().getLocation());
+                    }
 
-            for (std::list<ExpHistory*>::const_iterator i = fields.begin(), end = fields.end(); i != end; i++)
-            {
-                delete *i;
-            }
+                    // prevent delete after extractFullMatrix
+                    // called in evaluateFields when pITR is an ImplicitList
+                    pITR->IncreaseRef();
 
-            pITR->DecreaseRef();
-            pITR->killMe();
+                    try
+                    {
+                        pOut = evaluateFields(pCall, fields, pITR);
+                    }
+                    catch (ast::ScilabError error)
+                    {
+                        // catch error when call overload
+                        for (std::list<ExpHistory*>::const_iterator i = fields.begin(), end = fields.end(); i != end; i++)
+                        {
+                            delete *i;
+                        }
 
-            if (pOut == NULL)
-            {
-                std::wostringstream os;
-                os << _W("Fields evaluation failed.");
-                throw ast::ScilabError(os.str(), 999, e.getRightExp().getLocation());
-            }
+                        pITR->DecreaseRef();
+                        pITR->killMe();
 
-            if (e.isVerbose() && ConfigVariable::isPromptShow())
-            {
-                std::wostringstream ostr;
-                ostr << *getStructNameFromExp(&pCall->getName()) << L"  = " << std::endl;
-                ostr << std::endl;
-                scilabWriteW(ostr.str().c_str());
-
-                std::wostringstream ostrName;
-                ostrName << *getStructNameFromExp(&pCall->getName());
-                VariableToString(pOut, ostrName.str().c_str());
-            }
+                        throw error;
+                    }
 
-            clearResult();
-            return;
-        }
+                    for (std::list<ExpHistory*>::const_iterator i = fields.begin(), end = fields.end(); i != end; i++)
+                    {
+                        delete *i;
+                    }
 
-        if (e.getLeftExp().isAssignListExp())
-        {
-            AssignListExp *pList = e.getLeftExp().getAs<AssignListExp>();
-            //[x,y] = ?
-            int iLhsCount = (int)pList->getExps().size();
+                    pITR->DecreaseRef();
+                    pITR->killMe();
 
-            /*getting what to assign*/
-            T exec;
-            exec.setExpectedSize(iLhsCount);
-            e.getRightExp().accept(exec);
+                    if (pOut == NULL)
+                    {
+                        std::wostringstream os;
+                        os << _W("Fields evaluation failed.");
+                        throw ast::ScilabError(os.str(), 999, e.getRightExp().getLocation());
+                    }
+                }
 
-            if (exec.getResultSize() < iLhsCount)
-            {
-                std::wostringstream os;
-                os << _W("Incompatible assignation: trying to assign ") << exec.getResultSize();
-                os << _W(" values in ") << iLhsCount << _W(" variables.") << std::endl;
-                throw ast::ScilabError(os.str(), 999, e.getRightExp().getLocation());
-            }
+                if (e.isVerbose() && ConfigVariable::isPromptShow())
+                {
+                    std::wostringstream ostr;
+                    ostr << *getStructNameFromExp(&pCall->getName()) << L"  = " << std::endl;
+                    ostr << std::endl;
+                    scilabWriteW(ostr.str().c_str());
 
-            exps_t::const_reverse_iterator it;
-            exps_t exps = pList->getExps();
-            types::InternalType** pIT = new types::InternalType*[iLhsCount];
-            int i = 0;
-            for (i = iLhsCount - 1; i >= 0; i--)
-            {
-                //create a new AssignExp and run it
-                pIT[i] = (exec.getResult(i));
-                //protet rhs against removal [a,b] = (b,a);
-                pIT[i]->IncreaseRef();
-            }
+                    std::wostringstream ostrName;
+                    ostrName << *getStructNameFromExp(&pCall->getName());
+                    VariableToString(pOut, ostrName.str().c_str());
+                }
 
-            for (i = iLhsCount - 1, it = exps.rbegin(); it != exps.rend(); it++, i--)
-            {
-                Exp* pExp = e.getRightExp().clone();
-                AssignExp pAssign((*it)->getLocation(), *(*it), *pExp, pIT[i]);
-                pAssign.setLrOwner(false);
-                pAssign.setVerbose(e.isVerbose());
-                pAssign.accept(*this);
-                //clear result to take care of [n,n]
-                exec.setResult(i, NULL);
-                delete pExp;
+                clearResult();
+                return;
             }
 
-            for (i = iLhsCount - 1; i >= 0; i--)
+            if (e.getLeftExp().isAssignListExp())
             {
-                //unprotect rhs
-                pIT[i]->DecreaseRef();
-                pIT[i]->killMe();
-            }
+                AssignListExp *pList = e.getLeftExp().getAs<AssignListExp>();
+                //[x,y] = ?
+                int iLhsCount = (int)pList->getExps().size();
 
-            delete[] pIT;
-            exec.clearResult();
-            return;
-        }
-
-        FieldExp *pField = dynamic_cast<FieldExp*>(&e.getLeftExp());
-        if (pField)
-        {
-            InternalType *pIT = e.getRightVal();
-            if (pIT == NULL)
-            {
-                //a.b = x
-                //a.b can be a struct or a tlist/mlist or a handle
                 /*getting what to assign*/
-                setExpectedSize(1);
-                e.getRightExp().accept(*this);
-                pIT = getResult();
-                setResult(NULL);
+                T exec;
+                exec.setExpectedSize(iLhsCount);
+                e.getRightExp().accept(exec);
+
+                if (exec.getResultSize() < iLhsCount)
+                {
+                    std::wostringstream os;
+                    os << _W("Incompatible assignation: trying to assign ") << exec.getResultSize();
+                    os << _W(" values in ") << iLhsCount << _W(" variables.") << std::endl;
+                    throw ast::ScilabError(os.str(), 999, e.getRightExp().getLocation());
+                }
+
+                exps_t::const_reverse_iterator it;
+                exps_t exps = pList->getExps();
+                types::InternalType** pIT = new types::InternalType*[iLhsCount];
+                int i = 0;
+                for (i = iLhsCount - 1; i >= 0; i--)
+                {
+                    //create a new AssignExp and run it
+                    pIT[i] = (exec.getResult(i));
+                    //protet rhs against removal [a,b] = (b,a);
+                    pIT[i]->IncreaseRef();
+                }
+
+                for (i = iLhsCount - 1, it = exps.rbegin(); it != exps.rend(); it++, i--)
+                {
+                    Exp* pExp = e.getRightExp().clone();
+                    AssignExp pAssign((*it)->getLocation(), *(*it), *pExp, pIT[i]);
+                    pAssign.setLrOwner(false);
+                    pAssign.setVerbose(e.isVerbose());
+                    pAssign.accept(*this);
+                    //clear result to take care of [n,n]
+                    exec.setResult(i, NULL);
+                    delete pExp;
+                }
+
+                for (i = iLhsCount - 1; i >= 0; i--)
+                {
+                    //unprotect rhs
+                    pIT[i]->DecreaseRef();
+                    pIT[i]->killMe();
+                }
+
+                delete[] pIT;
+                exec.clearResult();
+                return;
             }
 
-            if (pIT->isImplicitList())
+            if (e.getLeftExp().isFieldExp())
             {
-                if (pIT->getAs<ImplicitList>()->isComputable())
+                FieldExp *pField = static_cast<FieldExp*>(&e.getLeftExp());
+                InternalType *pIT = e.getRightVal();
+                if (pIT == NULL)
                 {
-                    InternalType *pTemp = pIT->getAs<ImplicitList>()->extractFullMatrix();
-                    delete pIT;
+                    //a.b = x
+                    //a.b can be a struct or a tlist/mlist or a handle
+                    /*getting what to assign*/
+                    setExpectedSize(1);
+                    e.getRightExp().accept(*this);
+                    pIT = getResult();
                     setResult(NULL);
-                    pIT = pTemp;
                 }
-            }
 
-            std::list<ExpHistory*> fields;
-            if (getFieldsFromExp(pField, fields) == false)
-            {
-                for (std::list<ExpHistory*>::const_iterator i = fields.begin(), end = fields.end(); i != end; i++)
+                if (pIT->isImplicitList())
                 {
-                    delete *i;
+                    if (pIT->getAs<ImplicitList>()->isComputable())
+                    {
+                        InternalType *pTemp = pIT->getAs<ImplicitList>()->extractFullMatrix();
+                        delete pIT;
+                        setResult(NULL);
+                        pIT = pTemp;
+                    }
                 }
-                std::wostringstream os;
-                os << _W("Get fields from expression failed.");
-                throw ast::ScilabError(os.str(), 999, e.getRightExp().getLocation());
-            }
 
-            try
-            {
-                if (evaluateFields(pField, fields, pIT) == NULL)
+                std::list<ExpHistory*> fields;
+                if (getFieldsFromExp(pField, fields) == false)
                 {
                     for (std::list<ExpHistory*>::const_iterator i = fields.begin(), end = fields.end(); i != end; i++)
                     {
                         delete *i;
                     }
                     std::wostringstream os;
-                    os << _W("Fields evaluation failed.");
+                    os << _W("Get fields from expression failed.");
                     throw ast::ScilabError(os.str(), 999, e.getRightExp().getLocation());
                 }
-            }
-            catch (ScilabError error)
-            {
+
+                try
+                {
+                    if (evaluateFields(pField, fields, pIT) == NULL)
+                    {
+                        for (std::list<ExpHistory*>::const_iterator i = fields.begin(), end = fields.end(); i != end; i++)
+                        {
+                            delete *i;
+                        }
+                        std::wostringstream os;
+                        os << _W("Fields evaluation failed.");
+                        throw ast::ScilabError(os.str(), 999, e.getRightExp().getLocation());
+                    }
+                }
+                catch (ScilabError error)
+                {
+                    for (auto i : fields)
+                    {
+                        delete i;
+                    }
+
+                    throw error;
+                }
+
                 for (auto i : fields)
                 {
                     delete i;
                 }
 
-                throw error;
-            }
-
-            for (auto i : fields)
-            {
-                delete i;
-            }
+                if (e.isVerbose() && ConfigVariable::isPromptShow())
+                {
+                    const wstring *pstName = getStructNameFromExp(pField);
 
-            if (e.isVerbose() && ConfigVariable::isPromptShow())
-            {
-                const wstring *pstName = getStructNameFromExp(pField);
+                    types::InternalType* pPrint = ctx->get(symbol::Symbol(*pstName));
+                    std::wostringstream ostr;
+                    ostr << *pstName << L"  = " << std::endl << std::endl;
+                    scilabWriteW(ostr.str().c_str());
 
-                types::InternalType* pPrint = ctx->get(symbol::Symbol(*pstName));
-                std::wostringstream ostr;
-                ostr << *pstName << L"  = " << std::endl << std::endl;
-                scilabWriteW(ostr.str().c_str());
+                    std::wostringstream ostrName;
+                    ostrName << *pstName;
+                    VariableToString(pPrint, ostrName.str().c_str());
+                }
 
-                std::wostringstream ostrName;
-                ostrName << *pstName;
-                VariableToString(pPrint, ostrName.str().c_str());
+                clearResult();
+                return;
             }
 
-            clearResult();
-            return;
+            std::wostringstream os;
+            os << _W("unknow script form");
+            //os << ((Location)e.getRightExp().getLocation()).getLocationString() << std::endl;
+            throw ast::ScilabError(os.str(), 999, e.getRightExp().getLocation());
+        }
+        catch (ast::ScilabError error)
+        {
+            throw error;
         }
-
-        std::wostringstream os;
-        os << _W("unknow script form");
-        //os << ((Location)e.getRightExp().getLocation()).getLocationString() << std::endl;
-        throw ast::ScilabError(os.str(), 999, e.getRightExp().getLocation());
-    }
-    catch (ast::ScilabError error)
-    {
-        throw error;
     }
-}
 
 } /* namespace ast */
index b8c4433..707d201 100644 (file)
@@ -277,51 +277,11 @@ void RunVisitorT<T>::visitprivate(const IfExp  &e)
     clearResult();
     if (bTestStatus == true)
     {
-        //condition == true
-        if (e.isBreakable())
-        {
-            const_cast<IfExp*>(&e)->resetBreak();
-            const_cast<Exp*>(&e.getThen())->setBreakable();
-        }
-
-        if (e.isContinuable())
-        {
-            const_cast<IfExp*>(&e)->resetContinue();
-            const_cast<Exp*>(&e.getThen())->setContinuable();
-        }
-
-        if (e.isReturnable())
-        {
-            const_cast<IfExp*>(&e)->resetReturn();
-            const_cast<Exp*>(&e.getThen())->setReturnable();
-        }
-
         e.getThen().accept(*this);
     }
-    else
+    else if (e.hasElse())
     {
-        //condition == false
-
-        if (e.hasElse())
-        {
-            if (e.isBreakable())
-            {
-                const_cast<Exp*>(&e.getElse())->setBreakable();
-            }
-
-            if (e.isContinuable())
-            {
-                const_cast<IfExp*>(&e)->resetContinue();
-                const_cast<Exp*>(&e.getElse())->setContinuable();
-            }
-
-            if (e.isReturnable())
-            {
-                const_cast<Exp*>(&e.getElse())->setReturnable();
-            }
-
-            e.getElse().accept(*this);
-        }
+        e.getElse().accept(*this);
     }
 
     if (e.isBreakable()
@@ -355,15 +315,6 @@ void RunVisitorT<T>::visitprivate(const IfExp  &e)
 template <class T>
 void RunVisitorT<T>::visitprivate(const WhileExp  &e)
 {
-    //allow break and continue operations
-    const_cast<Exp*>(&e.getBody())->setBreakable();
-    const_cast<Exp*>(&e.getBody())->setContinuable();
-    //allow return operation
-    if (e.isReturnable())
-    {
-        const_cast<Exp*>(&(e.getBody()))->setReturnable();
-    }
-
     //condition
     e.getTest().accept(*this);
     InternalType* pIT = getResult();
@@ -371,6 +322,13 @@ void RunVisitorT<T>::visitprivate(const WhileExp  &e)
     {
         pIT->killMe();
         e.getBody().accept(*this);
+
+        //clear old result value before evaluate new one
+        if (getResult() != NULL)
+        {
+            getResult()->killMe();
+        }
+
         if (e.getBody().isBreak())
         {
             const_cast<Exp*>(&(e.getBody()))->resetBreak();
@@ -386,16 +344,7 @@ void RunVisitorT<T>::visitprivate(const WhileExp  &e)
 
         if (e.getBody().isContinue())
         {
-            const_cast<WhileExp*>(&e)->setContinue();
             const_cast<Exp*>(&(e.getBody()))->resetContinue();
-            e.getTest().accept(*this);
-            continue;
-        }
-
-        //clear old result value before evaluate new one
-        if (getResult() != NULL)
-        {
-            getResult()->killMe();
         }
 
         e.getTest().accept(*this);
@@ -414,16 +363,6 @@ void RunVisitorT<T>::visitprivate(const ForExp  &e)
     //vardec visit increase its result reference
     e.getVardec().accept(*this);
     InternalType* pIT = getResult();
-    //allow break and continue operations
-    const_cast<Exp&>(e.getBody()).setBreakable();
-    const_cast<Exp&>(e.getBody()).setContinuable();
-
-    //allow return operation
-    if (e.isReturnable())
-    {
-        const_cast<Exp&>(e.getBody()).resetReturn();
-        const_cast<Exp&>(e.getBody()).setReturnable();
-    }
 
     if (pIT->isImplicitList())
     {
@@ -431,6 +370,8 @@ void RunVisitorT<T>::visitprivate(const ForExp  &e)
         ImplicitList* pVar = pIT->getAs<ImplicitList>();
         //get IL initial Type
         InternalType * pIL = pVar->getInitalType();
+        //std::cout << "for IL: " << pIL << std::endl;
+        //std::cout << "  for IV: " << pIT << std::endl;
         //get index stack
         symbol::Variable* var = e.getVardec().getAs<VarDec>()->getStack();
 
@@ -445,40 +386,39 @@ void RunVisitorT<T>::visitprivate(const ForExp  &e)
         //use ref count to lock var against clear and detect any changes
         pIL->IncreaseRef();
 
-
         int size = pVar->getSize();
         for (int i = 0; i < size; ++i)
         {
             //check if loop index has changed, deleted, copy ...
-            switch (pIL->getRef())
+            if (pIL->getRef() != 2)
             {
-                case 2:
-                    //normal case
-                    break;
-                case 1:
-                    //someone clear me
-                    ctx->put(var, pIL);
-                    break;
-                default:
-                    //someone assign me to another var
-                    //a = i;
-                    //unlock me
-                    pIL->DecreaseRef();
-
-                    //create a new me
-                    pIL = pVar->getInitalType();
-                    //lock loop index
-                    pIL->IncreaseRef();
-                    //update me ( must decrease ref of a )
-                    if (ctx->isprotected(var))
-                    {
-                        std::wostringstream os;
-                        os << _W("Redefining permanent variable.\n");
-                        throw ast::ScilabError(os.str(), 999, e.getVardec().getLocation());
-                    }
+                switch (pIL->getRef())
+                {
+                    case 1:
+                        //someone clear me
+                        ctx->put(var, pIL);
+                        break;
+                    default:
+                        //someone assign me to another var
+                        //a = i;
+                        //unlock me
+                        pIL->DecreaseRef();
+
+                        //create a new me
+                        pIL = pVar->getInitalType();
+                        //lock loop index
+                        pIL->IncreaseRef();
+                        //update me ( must decrease ref of a )
+                        if (ctx->isprotected(var))
+                        {
+                            std::wostringstream os;
+                            os << _W("Redefining permanent variable.\n");
+                            throw ast::ScilabError(os.str(), 999, e.getVardec().getLocation());
+                        }
 
-                    ctx->put(var, pIL);
-                    break;
+                        ctx->put(var, pIL);
+                        break;
+                }
             }
 
             pVar->extractValue(i, pIL);
@@ -719,24 +659,6 @@ void RunVisitorT<T>::visitprivate(const SelectExp &e)
                 }
                 else if (*pITCase == *pIT)
                 {
-                    if (e.isBreakable())
-                    {
-                        const_cast<SelectExp*>(&e)->resetBreak();
-                        pCase->getBody()->setBreakable();
-                    }
-
-                    if (e.isContinuable())
-                    {
-                        const_cast<SelectExp*>(&e)->resetContinue();
-                        pCase->getBody()->setContinuable();
-                    }
-
-                    if (e.isReturnable())
-                    {
-                        const_cast<SelectExp*>(&e)->resetReturn();
-                        pCase->getBody()->setReturnable();
-                    }
-
                     try
                     {
                         //the good one
@@ -778,24 +700,6 @@ void RunVisitorT<T>::visitprivate(const SelectExp &e)
 
     if (bCase == false && e.getDefaultCase() != NULL)
     {
-        if (e.isBreakable())
-        {
-            const_cast<SelectExp*>(&e)->resetBreak();
-            e.getDefaultCase()->setBreakable();
-        }
-
-        if (e.isContinuable())
-        {
-            const_cast<SelectExp*>(&e)->resetContinue();
-            e.getDefaultCase()->setContinuable();
-        }
-
-        if (e.isReturnable())
-        {
-            const_cast<SelectExp*>(&e)->resetReturn();
-            e.getDefaultCase()->setReturnable();
-        }
-
         try
         {
             //default case
@@ -834,35 +738,19 @@ void RunVisitorT<T>::visitprivate(const SelectExp &e)
 template <class T>
 void RunVisitorT<T>::visitprivate(const SeqExp  &e)
 {
-    //T execMe;
-    exps_t::const_iterator itExp;
-    exps_t exps = e.getExps();
-
     types::ThreadId* pThreadMe = ConfigVariable::getThread(__GetCurrentThreadKey());
 
-    for (itExp = exps.begin (); itExp != exps.end (); ++itExp)
+    for (auto exp : e.getExps())
     {
-        if (pThreadMe && pThreadMe->getInterrupt())
-        {
-            ThreadManagement::SendAstPendingSignal();
-            pThreadMe->suspend();
-        }
-
-        if (e.isBreakable())
-        {
-            (*itExp)->resetBreak();
-            (*itExp)->setBreakable();
-        }
-
-        if (e.isContinuable())
+        if (exp->isCommentExp())
         {
-            (*itExp)->resetContinue();
-            (*itExp)->setContinuable();
+            continue;
         }
 
-        if (e.isReturnable())
+        if (pThreadMe && pThreadMe->getInterrupt())
         {
-            (*itExp)->setReturnable();
+            ThreadManagement::SendAstPendingSignal();
+            pThreadMe->suspend();
         }
 
         try
@@ -871,7 +759,7 @@ void RunVisitorT<T>::visitprivate(const SeqExp  &e)
             setResult(NULL);
             int iExpectedSize = getExpectedSize();
             setExpectedSize(-1);
-            (*itExp)->accept(*this);
+            exp->accept(*this);
             setExpectedSize(iExpectedSize);
             InternalType * pIT = getResult();
 
@@ -909,7 +797,7 @@ void RunVisitorT<T>::visitprivate(const SeqExp  &e)
                     {
                         wostringstream os;
                         PrintVisitor printMe(os);
-                        (*itExp)->accept(printMe);
+                        exp->accept(printMe);
                         //os << std::endl << std::endl;
                         if (ConfigVariable::getLastErrorFunction() == L"")
                         {
@@ -940,7 +828,7 @@ void RunVisitorT<T>::visitprivate(const SeqExp  &e)
                         if (pCall->isMacro() || pCall->isMacroFile())
                         {
                             wchar_t szError[bsiz];
-                            os_swprintf(szError, bsiz, _W("at line % 5d of function %ls called by :\n").c_str(), (*itExp)->getLocation().first_line, pCall->getName().c_str());
+                            os_swprintf(szError, bsiz, _W("at line % 5d of function %ls called by :\n").c_str(), exp->getLocation().first_line, pCall->getName().c_str());
                             throw ScilabMessage(szError);
                         }
                         else
@@ -951,12 +839,12 @@ void RunVisitorT<T>::visitprivate(const SeqExp  &e)
                 }
 
                 //don't output Simplevar and empty result
-                if (getResult() != NULL && (!(*itExp)->isSimpleVar() || bImplicitCall))
+                if (getResult() != NULL && (!exp->isSimpleVar() || bImplicitCall))
                 {
                     //symbol::Context::getInstance()->put(symbol::Symbol(L"ans"), *execMe.getResult());
                     InternalType* pITAns = getResult();
                     symbol::Context::getInstance()->put(m_pAns, pITAns);
-                    if ((*itExp)->isVerbose() && ConfigVariable::isPromptShow())
+                    if (exp->isVerbose() && ConfigVariable::isPromptShow())
                     {
                         //TODO manage multiple returns
                         scilabWriteW(L" ans  =\n\n");
@@ -969,22 +857,24 @@ void RunVisitorT<T>::visitprivate(const SeqExp  &e)
                 pIT->killMe();
             }
 
-            if ((&e)->isBreakable() && (*itExp)->isBreak())
+            if ((&e)->isBreakable() && exp->isBreak())
             {
                 const_cast<SeqExp *>(&e)->setBreak();
+                exp->resetBreak();
                 break;
             }
 
-            if ((&e)->isContinuable() && (*itExp)->isContinue())
+            if ((&e)->isContinuable() && exp->isContinue())
             {
                 const_cast<SeqExp *>(&e)->setContinue();
+                exp->resetContinue();
                 break;
             }
 
-            if ((&e)->isReturnable() && (*itExp)->isReturn())
+            if ((&e)->isReturnable() && exp->isReturn())
             {
                 const_cast<SeqExp *>(&e)->setReturn();
-                (*itExp)->resetReturn();
+                exp->resetReturn();
                 break;
             }
         }
@@ -992,7 +882,7 @@ void RunVisitorT<T>::visitprivate(const SeqExp  &e)
         {
             scilabErrorW(sm.GetErrorMessage().c_str());
 
-            CallExp* pCall = dynamic_cast<CallExp*>(*itExp);
+            CallExp* pCall = dynamic_cast<CallExp*>(exp);
             if (pCall != NULL)
             {
                 //to print call expression only of it is a macro
@@ -1008,11 +898,10 @@ void RunVisitorT<T>::visitprivate(const SeqExp  &e)
                     {
                         ConfigVariable::setLastErrorFunction(((InternalType*)getResult())->getAs<Callable>()->getName());
                     }
-                    throw ScilabMessage(os.str(), 0, (*itExp)->getLocation());
+                    throw ScilabMessage(os.str(), 0, exp->getLocation());
                 }
             }
-
-            throw ScilabMessage((*itExp)->getLocation());
+            throw ScilabMessage(exp->getLocation());
         }
         catch (const ScilabError& se)
         {
@@ -1025,7 +914,7 @@ void RunVisitorT<T>::visitprivate(const SeqExp  &e)
                 ConfigVariable::setLastErrorFunction(wstring(L""));
             }
 
-            CallExp* pCall = dynamic_cast<CallExp*>(*itExp);
+            CallExp* pCall = dynamic_cast<CallExp*>(exp);
             if (pCall != NULL)
             {
                 //to print call expression only of it is a macro
@@ -1040,7 +929,7 @@ void RunVisitorT<T>::visitprivate(const SeqExp  &e)
                         //os << std::endl << std::endl;
                         ConfigVariable::setLastErrorFunction(((InternalType*)getResult())->getAs<Callable>()->getName());
                         scilabErrorW(se.GetErrorMessage().c_str());
-                        throw ScilabMessage(os.str(), 999, (*itExp)->getLocation());
+                        throw ScilabMessage(os.str(), 999, exp->getLocation());
                     }
                 }
                 catch (ScilabError& se2)
@@ -1051,7 +940,7 @@ void RunVisitorT<T>::visitprivate(const SeqExp  &e)
 
             scilabErrorW(se.GetErrorMessage().c_str());
             scilabErrorW(L"\n");
-            throw ScilabMessage((*itExp)->getLocation());
+            throw ScilabMessage(exp->getLocation());
         }
 
         // If something other than NULL is given to setResult, then that would imply
@@ -1293,6 +1182,20 @@ void RunVisitorT<T>::visitprivate(const ListExp &e)
     }
     InternalType* piEnd = pITEnd;
 
+    //check if implicitlist is 1:$ to replace by ':'
+    if (piStart->isDouble() && piStep->isDouble() && piEnd->isPoly())
+    {
+        if (piStart->getAs<Double>()->get()[0] == 1 && piStep->getAs<Double>()->get()[0] == 1)
+        {
+            SinglePoly* end = piEnd->getAs<Polynom>()->get()[0];
+            if (end->getRank() == 1 && end->get()[0] == 0 && end->get()[1] == 1)
+            {
+                setResult(new Colon());
+                return;
+            }
+        }
+    }
+
     //check compatibility
     // double : double : double or poly : poly : poly and mix like double : double : poly
     if ((piStart->isPoly() || piStart->isDouble()) &&
index fa1e78b..8d57fbb 100644 (file)
@@ -193,6 +193,11 @@ types::InternalType* Context::getCurrentLevel(const Symbol& _key)
     return variables.get(_key, m_iLevel);
 }
 
+types::InternalType* Context::getCurrentLevel(Variable* _var)
+{
+    return variables.get(_var, m_iLevel);
+}
+
 types::InternalType* Context::getAllButCurrentLevel(const Symbol& _key)
 {
     return variables.getAllButCurrentLevel(_key, m_iLevel);
@@ -399,13 +404,13 @@ void Context::print(std::wostream& ostr, bool sorted) const
     wchar_t wcsGlobalVariable[strSize];
 
     int iMemTotal = 0;
-    int iMemUsed  = 0;
-    int nbMaxVar  = 0;
+    int iMemUsed = 0;
+    int nbMaxVar = 0;
 
 #ifdef _MSC_VER
     MEMORYSTATUSEX statex;
     statex.dwLength = sizeof(statex);
-    GlobalMemoryStatusEx (&statex);
+    GlobalMemoryStatusEx(&statex);
     iMemTotal = (int)(statex.ullTotalPhys / (1024 * 1024));
 #else
     iMemTotal = getmemorysize();
index d2fa898..bd64bc5 100644 (file)
@@ -1,15 +1,16 @@
 /*
- *  Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
- *  Copyright (C) 2010 - DIGITEO - Antoine ELIAS
- *
- *  This file must be used under the terms of the CeCILL.
- *  This source file is licensed as described in the file COPYING, which
- *  you should have received as part of this distribution.  The terms
- *  are also available at
- *  http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
- *
- */
+*  Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+*  Copyright (C) 2010 - DIGITEO - Antoine ELIAS
+*
+*  This file must be used under the terms of the CeCILL.
+*  This source file is licensed as described in the file COPYING, which
+*  you should have received as part of this distribution.  The terms
+*  are also available at
+*  http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+*
+*/
 
+#include "arrayof.hxx"
 #include "double.hxx"
 #include "bool.hxx"
 #include "singlepoly.hxx"
@@ -23,10 +24,10 @@ extern "C"
 namespace types
 {
 /*    template <typename T>
-    ArrayOf<T>* createEmptyDouble()
-    {
-        return Double::Empty();
-    }
+ArrayOf<T>* createEmptyDouble()
+{
+return Double::Empty();
+}
 */
 //n-uplet in french
 int computeTuples(int* _piCountDim, int _iDims, int _iCurrentDim, int* _piIndex)
@@ -78,7 +79,7 @@ InternalType* createDoubleVector(int _iSize)
 {
     int piDims[] = {1, _iSize};
     Double* pOut = new Double(2, piDims);
-    for (int i = 0 ; i < _iSize ; i++)
+    for (int i = 0; i < _iSize; i++)
     {
         pOut->set(i, i + 1);
     }
@@ -87,16 +88,16 @@ InternalType* createDoubleVector(int _iSize)
 
 bool checkArgValidity(typed_list& _Arg)
 {
-    for (int i = 0 ; i < (int)_Arg.size() ; i++)
+    for (int i = 0; i < (int)_Arg.size(); i++)
     {
-        if ( _Arg[i]->isDouble() == false)
+        if (_Arg[i]->isDouble() == false)
         {
             return false;
         }
 
         Double* pDbl = _Arg[i]->getAs<Double>();
         double* pdbl = pDbl->get();
-        for (int j = 0 ; j < pDbl->getSize() ; j++)
+        for (int j = 0; j < pDbl->getSize(); j++)
         {
             if (pdbl[j] <= 0)
             {
@@ -125,17 +126,93 @@ InternalType* ArrayOf<T>::insert(typed_list* _pArgs, InternalType* _pSource)
         return pIT;
     }
 
-    bool bNeedToResize  = false;
-    int iDims           = (int)_pArgs->size();
+    int index;
+    if (getScalarIndex(this, _pArgs, &index))
+    {
+        ArrayOf* pIns = _pSource->getAs<ArrayOf>();
+        int sizeIn = pIns->getSize();
+        //only scalar can be used to ".=" operation
+        if (sizeIn != 1)
+        {
+            return NULL;
+        }
+
+        T* pRealData = pIns->get();
+        T* pImgData = pIns->getImg();
+
+        if (isComplex() == false && pIns->isComplex() == false)
+        {
+            if (set(index, *pRealData) == true)
+            {
+                return this;
+            }
+        }
+
+        //if complex continue
+    }
+
+    std::vector<int> indexes;
+    if (getImplicitIndex(this, _pArgs, indexes))
+    {
+        ArrayOf* pIns = _pSource->getAs<ArrayOf>();
+        int sizeIn = pIns->getSize();
+        int count = static_cast<int>(indexes.size());
+        //only scalar can be used to ".=" operation
+        if (sizeIn != 1 && count != sizeIn)
+        {
+            return NULL;
+        }
+
+        T* pRealData = pIns->get();
+        T* pImgData = pIns->getImg();
+
+        bool status = true;
+        if (isComplex() == false && pIns->isComplex() == false)
+        {
+            if (sizeIn == 1)
+            {
+                for (int i : indexes)
+                {
+                    if (set(i, *pRealData) == false)
+                    {
+                        status = false;
+                        break;
+                    }
+                }
+            }
+            else
+            {
+                for (int i : indexes)
+                {
+                    if (set(i, *pRealData) == false)
+                    {
+                        status = false;
+                        break;
+                    }
+                    ++pRealData;
+                }
+            }
+
+            if (status)
+            {
+                return this;
+            }
+
+            //if status is false, continue to entire process
+        }
+    }
+
+    bool bNeedToResize = false;
+    int iDims = (int)_pArgs->size();
     int iDimsOrigine = m_iDims;
     typed_list pArg;
 
-    int* piMaxDim       = new int[iDims];
-    int* piCountDim     = new int[iDims];
+    int* piMaxDim = new int[iDims];
+    int* piCountDim = new int[iDims];
 
     //on case of resize
-    int* piNewDims      = NULL;
-    int iNewDims        = 0;
+    int* piNewDims = NULL;
+    int iNewDims = 0;
     ArrayOf* pSource = _pSource->getAs<ArrayOf>();
 
     bool bIsColon = false;
@@ -184,7 +261,7 @@ InternalType* ArrayOf<T>::insert(typed_list* _pArgs, InternalType* _pSource)
         }
         else //_iDims == m_iDims
         {
-            for (int i = 0 ; i < m_iDims ; i++)
+            for (int i = 0; i < m_iDims; i++)
             {
                 if (m_piDims[i] < piMaxDim[i])
                 {
@@ -199,7 +276,7 @@ InternalType* ArrayOf<T>::insert(typed_list* _pArgs, InternalType* _pSource)
         {
             iNewDims = iDims;
             piNewDims = new int[iNewDims];
-            for (int i = 0 ; i < m_iDims ; i++)
+            for (int i = 0; i < m_iDims; i++)
             {
                 piNewDims[i] = std::max(piMaxDim[i], m_piDims[i]);
             }
@@ -242,14 +319,14 @@ InternalType* ArrayOf<T>::insert(typed_list* _pArgs, InternalType* _pSource)
         {
             //each index before last index must be in range of his dimension
             //and last given dimension can not be > prod(last dimensions)
-            for (int i = 0 ; i < iDims - 1 ; i++)
+            for (int i = 0; i < iDims - 1; i++)
             {
                 //indexes are always doubles
                 double* pIdx = getDoubleArrayFromDouble(pArg[i]);
                 //InternalType* pVar = pArg[i];
                 //double* pIdx = static_cast<double*>(pVar->getAs<Double>()->get());
                 int iSize = pArg[i]->getAs<ArrayOf>()->getSize();
-                for (int j = 0 ; j < iSize ; j++)
+                for (int j = 0; j < iSize; j++)
                 {
                     if (pIdx[j] > m_piDims[i])
                     {
@@ -268,7 +345,7 @@ InternalType* ArrayOf<T>::insert(typed_list* _pArgs, InternalType* _pSource)
             //InternalType* pVar = pArg[pArg.size() - 1];
             //double* pIdx = static_cast<double*>(pVar->getAs<Double>()->get());
             int iSize = pArg[pArg.size() - 1]->getAs<GenericType>()->getSize();
-            for (int i = 0 ; i < iSize ; i++)
+            for (int i = 0; i < iSize; i++)
             {
                 if (pIdx[i] > iMaxLastDim)
                 {
@@ -298,8 +375,8 @@ InternalType* ArrayOf<T>::insert(typed_list* _pArgs, InternalType* _pSource)
     }
     else
     {
-        piNewDims   = m_piDims;
-        iNewDims    = m_iDims;
+        piNewDims = m_piDims;
+        iNewDims = m_iDims;
     }
 
     //update complexity
@@ -315,16 +392,16 @@ InternalType* ArrayOf<T>::insert(typed_list* _pArgs, InternalType* _pSource)
     memset(piIndex, 0x00, sizeof(int) * argSize);
 
     //convert  current dimension to view dimension
-    for (int i = 0 ; i < iDims ; i++)
+    for (int i = 0; i < iDims; i++)
     {
         piViewDims[i] = getVarMaxDim(i, iDims);
     }
 
-    T* pRealData    = pSource->get();
-    T* pImgData     = pSource->getImg();
-    bool bComplex   = pSource->isComplex();
+    T* pRealData = pSource->get();
+    T* pImgData = pSource->getImg();
+    bool bComplex = pSource->isComplex();
 
-    for (int i = 0 ; i < iSeqCount ; i++)
+    for (int i = 0; i < iSeqCount; i++)
     {
         computeTuples(piCountDim, argSize, argSize - 1, piIndex);
 
@@ -372,7 +449,7 @@ InternalType* ArrayOf<T>::insert(typed_list* _pArgs, InternalType* _pSource)
         }
         else
         {
-            if ( bIsColon)
+            if (bIsColon)
             {
                 int iPas = 1;
                 for (int j = 0; j < iDimsOrigine; j++)
@@ -431,15 +508,15 @@ template <typename T>
 InternalType* ArrayOf<T>::insertNew(typed_list* _pArgs, InternalType* _pSource)
 {
     typed_list pArg;
-    InternalType *pOut  = NULL;
+    InternalType *pOut = NULL;
     ArrayOf* pSource = _pSource->getAs<ArrayOf>();
 
-    int iDims           = (int)_pArgs->size();
-    int* piMaxDim       = new int[iDims];
-    int* piCountDim     = new int[iDims];
-    bool bComplex       = pSource->getImg() != NULL;
-    bool bUndefine      = false;
-    bool bIsImpli       = false;
+    int iDims = (int)_pArgs->size();
+    int* piMaxDim = new int[iDims];
+    int* piCountDim = new int[iDims];
+    bool bComplex = pSource->getImg() != NULL;
+    bool bUndefine = false;
+    bool bIsImpli = false;
 
     //evaluate each argument and replace by appropriate value and compute the count of combinations
     int iSeqCount = checkIndexesArguments(NULL, _pArgs, &pArg, piMaxDim, piCountDim);
@@ -536,7 +613,7 @@ InternalType* ArrayOf<T>::insertNew(typed_list* _pArgs, InternalType* _pSource)
 
     //remove last dimension at size 1
     //remove last dimension if are == 1
-    for (int i = (iDims - 1) ; i >= 2 ; i--)
+    for (int i = (iDims - 1); i >= 2; i--)
     {
         if (piMaxDim[i] == 1)
         {
@@ -585,7 +662,7 @@ InternalType* ArrayOf<T>::insertNew(typed_list* _pArgs, InternalType* _pSource)
     if (bComplex)
     {
         T* pImgData = pArrayOut->getImg();
-        for (int i = 0 ; i < pArrayOut->getSize() ; i++)
+        for (int i = 0; i < pArrayOut->getSize(); i++)
         {
             pArrayOut->deleteData(pRealData[i]);
             pRealData[i] = pSource->getNullValue();
@@ -595,7 +672,7 @@ InternalType* ArrayOf<T>::insertNew(typed_list* _pArgs, InternalType* _pSource)
     }
     else
     {
-        for (int i = 0 ; i < pArrayOut->getSize() ; i++)
+        for (int i = 0; i < pArrayOut->getSize(); i++)
         {
             pArrayOut->deleteData(pRealData[i]);
             pRealData[i] = pSource->getNullValue();
@@ -650,9 +727,9 @@ bool ArrayOf<T>::append(int _iRows, int _iCols, InternalType* _poSource)
 
     if (pGT->isComplex())
     {
-        for (int i = 0 ; i < iRows ; i++)
+        for (int i = 0; i < iRows; i++)
         {
-            for (int j = 0 ; j < iCols ; j++)
+            for (int j = 0; j < iCols; j++)
             {
                 set(_iRows + i, _iCols + j, pGT->get(i, j));
                 setImg(_iRows + i, _iCols + j, pGT->getImg(i, j));
@@ -661,9 +738,9 @@ bool ArrayOf<T>::append(int _iRows, int _iCols, InternalType* _poSource)
     }
     else
     {
-        for (int i = 0 ; i < iRows ; i++)
+        for (int i = 0; i < iRows; i++)
         {
-            for (int j = 0 ; j < iCols ; j++)
+            for (int j = 0; j < iCols; j++)
             {
                 set(_iRows + i, _iCols + j, pGT->get(i, j));
             }
@@ -676,12 +753,12 @@ bool ArrayOf<T>::append(int _iRows, int _iCols, InternalType* _poSource)
 template <typename T>
 InternalType* ArrayOf<T>::remove(typed_list* _pArgs)
 {
-    ArrayOf<T>* pOut    = NULL;
-    int iDims           = (int)_pArgs->size();
+    ArrayOf<T>* pOut = NULL;
+    int iDims = (int)_pArgs->size();
     typed_list pArg;
 
-    int* piMaxDim       = new int[iDims];
-    int* piCountDim     = new int[iDims];
+    int* piMaxDim = new int[iDims];
+    int* piCountDim = new int[iDims];
 
     //evaluate each argument and replace by appropriate value and compute the count of combinations
     int iSeqCount = checkIndexesArguments(this, _pArgs, &pArg, piMaxDim, piCountDim);
@@ -697,21 +774,21 @@ InternalType* ArrayOf<T>::remove(typed_list* _pArgs)
 
     bool* pbFull = new bool[iDims];
     //coord must represent all values on a dimension
-    for (int i = 0 ; i < iDims ; i++)
+    for (int i = 0; i < iDims; i++)
     {
-        pbFull[i]       = false;
+        pbFull[i] = false;
         int iDimToCheck = getVarMaxDim(i, iDims);
-        int iIndexSize  = pArg[i]->getAs<GenericType>()->getSize();
+        int iIndexSize = pArg[i]->getAs<GenericType>()->getSize();
 
         //we can have index more than once
         if (iIndexSize >= iDimToCheck)
         {
             //size is good, now check datas
             double* pIndexes = getDoubleArrayFromDouble(pArg[i]);
-            for (int j = 0 ; j < iDimToCheck ; j++)
+            for (int j = 0; j < iDimToCheck; j++)
             {
                 bool bFind = false;
-                for (int k = 0 ; k < iIndexSize ; k++)
+                for (int k = 0; k < iIndexSize; k++)
                 {
                     if ((int)pIndexes[k] == j + 1)
                     {
@@ -719,16 +796,16 @@ InternalType* ArrayOf<T>::remove(typed_list* _pArgs)
                         break;
                     }
                 }
-                pbFull[i]  = bFind;
+                pbFull[i] = bFind;
             }
         }
     }
 
     //only one dims can be not full/entire
     bool bNotEntire = false;
-    int iNotEntire  = 0;
+    int iNotEntire = 0;
     bool bTooMuchNotEntire = false;
-    for (int i = 0 ; i < iDims ; i++)
+    for (int i = 0; i < iDims; i++)
     {
         if (pbFull[i] == false)
         {
@@ -755,18 +832,18 @@ InternalType* ArrayOf<T>::remove(typed_list* _pArgs)
     delete[] pbFull;
 
     //find index to keep
-    int iNotEntireSize          = pArg[iNotEntire]->getAs<GenericType>()->getSize();
-    double* piNotEntireIndex    = getDoubleArrayFromDouble(pArg[iNotEntire]);
-    int iKeepSize               = getVarMaxDim(iNotEntire, iDims);
-    bool* pbKeep                = new bool[iKeepSize];
+    int iNotEntireSize = pArg[iNotEntire]->getAs<GenericType>()->getSize();
+    double* piNotEntireIndex = getDoubleArrayFromDouble(pArg[iNotEntire]);
+    int iKeepSize = getVarMaxDim(iNotEntire, iDims);
+    bool* pbKeep = new bool[iKeepSize];
 
     //fill pbKeep with true value
-    for (int i = 0 ; i < iKeepSize ; i++)
+    for (int i = 0; i < iKeepSize; i++)
     {
         pbKeep[i] = true;
     }
 
-    for (int i = 0 ; i < iNotEntireSize ; i++)
+    for (int i = 0; i < iNotEntireSize; i++)
     {
         int idx = (int)piNotEntireIndex[i] - 1;
 
@@ -778,7 +855,7 @@ InternalType* ArrayOf<T>::remove(typed_list* _pArgs)
     }
 
     int iNewDimSize = 0;
-    for (int i = 0 ; i < iKeepSize ; i++)
+    for (int i = 0; i < iKeepSize; i++)
     {
         if (pbKeep[i] == true)
         {
@@ -788,7 +865,7 @@ InternalType* ArrayOf<T>::remove(typed_list* _pArgs)
     delete[] pbKeep;
 
     int* piNewDims = new int[iDims];
-    for (int i = 0 ; i < iDims ; i++)
+    for (int i = 0; i < iDims; i++)
     {
         if (i == iNotEntire)
         {
@@ -802,7 +879,7 @@ InternalType* ArrayOf<T>::remove(typed_list* _pArgs)
 
     //remove last dimension if are == 1
     int iOrigDims = iDims;
-    for (int i = (iDims - 1) ; i >= 2 ; i--)
+    for (int i = (iDims - 1); i >= 2; i--)
     {
         if (piNewDims[i] == 1)
         {
@@ -849,18 +926,18 @@ InternalType* ArrayOf<T>::remove(typed_list* _pArgs)
     int iNewPos = 0;
     int* piIndexes = new int[iOrigDims];
     int* piViewDims = new int[iOrigDims];
-    for (int i = 0 ; i < iOrigDims ; i++)
+    for (int i = 0; i < iOrigDims; i++)
     {
         piViewDims[i] = getVarMaxDim(i, iOrigDims);
     }
 
-    for (int i = 0 ; i < getSize() ; i++)
+    for (int i = 0; i < getSize(); i++)
     {
         bool bByPass = false;
         getIndexesWithDims(i, piIndexes, piViewDims, iOrigDims);
 
         //check if piIndexes use removed indexes
-        for (int j = 0 ; j < iNotEntireSize ; j++)
+        for (int j = 0; j < iNotEntireSize; j++)
         {
             if ((piNotEntireIndex[j] - 1) == piIndexes[iNotEntire])
             {
@@ -893,12 +970,12 @@ InternalType* ArrayOf<T>::remove(typed_list* _pArgs)
 template <typename T>
 InternalType* ArrayOf<T>::extract(typed_list* _pArgs)
 {
-    ArrayOf<T>* pOut    = NULL;
-    int iDims           = (int)_pArgs->size();
+    ArrayOf<T>* pOut = NULL;
+    int iDims = (int)_pArgs->size();
     typed_list pArg;
 
-    int* piMaxDim       = new int[iDims];
-    int* piCountDim     = new int[iDims];
+    int* piMaxDim = new int[iDims];
+    int* piCountDim = new int[iDims];
 
     //evaluate each argument and replace by appropriate value and compute the count of combinations
     int iSeqCount = checkIndexesArguments(this, _pArgs, &pArg, piMaxDim, piCountDim);
@@ -922,7 +999,7 @@ InternalType* ArrayOf<T>::extract(typed_list* _pArgs)
 
     if (iDims < m_iDims)
     {
-        for (int i = 0 ; i < iDims ; i++)
+        for (int i = 0; i < iDims; i++)
         {
             int iDimToCheck = 0;
             if (i == (iDims - 1))
@@ -948,7 +1025,7 @@ InternalType* ArrayOf<T>::extract(typed_list* _pArgs)
     {
         if (iDims > m_iDims)
         {
-            for (int i = m_iDims ; i < iDims ; i++)
+            for (int i = m_iDims; i < iDims; i++)
             {
                 if (piMaxDim[i] > 1)
                 {
@@ -962,7 +1039,7 @@ InternalType* ArrayOf<T>::extract(typed_list* _pArgs)
         }
 
         //check MaxDim
-        for (int i = 0 ; i < m_iDims ; i++)
+        for (int i = 0; i < m_iDims; i++)
         {
             if (piMaxDim[i] > m_piDims[i])
             {
@@ -977,7 +1054,7 @@ InternalType* ArrayOf<T>::extract(typed_list* _pArgs)
     }
 
     //remove last dimension if are == 1
-    for (int i = (iDims - 1) ; i >= 2 ; i--)
+    for (int i = (iDims - 1); i >= 2; i--)
     {
         if (piCountDim[i] == 1)
         {
@@ -1030,23 +1107,23 @@ InternalType* ArrayOf<T>::extract(typed_list* _pArgs)
         pOut = createEmpty(iDims, piCountDim, m_pImgData != NULL);
     }
 
-    int* piIndex    = new int[_pArgs->size()];
-    int* piCoord    = new int[_pArgs->size()];
+    int* piIndex = new int[_pArgs->size()];
+    int* piCoord = new int[_pArgs->size()];
     int* piViewDims = new int[iDims];
     memset(piIndex, 0x00, sizeof(int) * _pArgs->size());
 
-    for (int i = 0 ; i < iDims ; i++)
+    for (int i = 0; i < iDims; i++)
     {
         piViewDims[i] = getVarMaxDim(i, iDims);
     }
 
-    for (int i = 0 ; i < iSeqCount ; i++)
+    for (int i = 0; i < iSeqCount; i++)
     {
         //increment last dimension
         computeTuples(piCountDim, (int)_pArgs->size(), (int)_pArgs->size() - 1, piIndex);
 
         //std::cout << "[";
-        for (int j = 0 ; j < (int)_pArgs->size() ; j++)
+        for (int j = 0; j < (int)_pArgs->size(); j++)
         {
             piCoord[j] = getIntValueFromDouble(pArg[j], piIndex[j]) - 1;
             //InternalType* pVar = pArg[i];
@@ -1084,7 +1161,7 @@ InternalType* ArrayOf<T>::extract(typed_list* _pArgs)
         }
 
         //convert flat dimension to 0
-        for (int j = 0 ; j < iDims ; j++)
+        for (int j = 0; j < iDims; j++)
         {
             if (piCountDim[j] == 1)
             {
@@ -1120,7 +1197,7 @@ bool ArrayOf<T>::resize(int* _piDims, int _iDims)
     if (_iDims == m_iDims)
     {
         bool bChange = false;
-        for (int i = 0 ; i < _iDims ; i++)
+        for (int i = 0; i < _iDims; i++)
         {
             if (m_piDims[i] != _piDims[i])
             {
@@ -1150,7 +1227,7 @@ bool ArrayOf<T>::resize(int* _piDims, int _iDims)
             int iOldSizeMax = m_iSizeMax;
             m_iSizeMax = static_cast<int>(iNewSize * 1.1);
             pRealData = allocData(m_iSizeMax);
-            pImgData  = allocData(m_iSizeMax);
+            pImgData = allocData(m_iSizeMax);
 
             //copy values into new one
             int* piIndexes = new int[std::max(m_iDims, _iDims)];
@@ -1166,12 +1243,12 @@ bool ArrayOf<T>::resize(int* _piDims, int _iDims)
                 getIndexes(i, piIndexes);
                 int iNewIdx = getIndexWithDims(piIndexes, _piDims, _iDims);
                 pRealData[iNewIdx] = m_pRealData[i];
-                pImgData[iNewIdx]  = m_pImgData[i];
+                pImgData[iNewIdx] = m_pImgData[i];
                 for (int j = iPreviousNewIdx; j < iNewIdx; ++j)
                 {
                     T pTemp = getNullValue();
                     pRealData[j] = copyValue(pTemp);
-                    pImgData[j]  = copyValue(pTemp);
+                    pImgData[j] = copyValue(pTemp);
                     if (pTemp != pRealData[j])
                     {
                         deleteData(pTemp);
@@ -1201,7 +1278,7 @@ bool ArrayOf<T>::resize(int* _piDims, int _iDims)
             {
                 T pTemp = getNullValue();
                 pRealData[i] = copyValue(pTemp);
-                pImgData[i]  = copyValue(pTemp);
+                pImgData[i] = copyValue(pTemp);
                 if (pTemp != pRealData[i])
                 {
                     deleteData(pTemp);
@@ -1267,13 +1344,13 @@ bool ArrayOf<T>::resize(int* _piDims, int _iDims)
             //copy values into new one
             int* piIndexes = new int[std::max(m_iDims, _iDims)];
             memset(piIndexes, 0x00, sizeof(int) * std::max(m_iDims, _iDims));
-            for (int i = 0 ; i < _iDims ; i++)
+            for (int i = 0; i < _iDims; i++)
             {
                 piIndexes[i] = 0;
             }
 
             int iPreviousNewIdx = 0;
-            for (int i = 0 ; i < m_iSize ; i++)
+            for (int i = 0; i < m_iSize; i++)
             {
                 getIndexes(i, piIndexes);
                 int iNewIdx = getIndexWithDims(piIndexes, _piDims, _iDims);
@@ -1335,7 +1412,7 @@ bool ArrayOf<T>::resize(int* _piDims, int _iDims)
         {
             //check if only the last dims change
             bool bNonLastDimChange = false;
-            for (int i = 0 ; i < (m_iDims - 1) ; i++)
+            for (int i = 0; i < (m_iDims - 1); i++)
             {
                 if (m_piDims[i] != _piDims[i])
                 {
@@ -1350,7 +1427,7 @@ bool ArrayOf<T>::resize(int* _piDims, int _iDims)
                 //copy values into new one
                 int* piIndexes = new int[std::max(m_iDims, _iDims)];
                 memset(piIndexes, 0x00, sizeof(int) * std::max(m_iDims, _iDims));
-                for (int i = m_iSize - 1 ; i >= 0  ; i--)
+                for (int i = m_iSize - 1; i >= 0; i--)
                 {
                     getIndexes(i, piIndexes);
                     int iNewIdx = getIndexWithDims(piIndexes, _piDims, _iDims);
@@ -1369,7 +1446,7 @@ bool ArrayOf<T>::resize(int* _piDims, int _iDims)
     if (_iDims != m_iDims)
     {
         //int* piDims = new int[_iDims];
-        for (int i = 0 ; i < _iDims ; i++)
+        for (int i = 0; i < _iDims; i++)
         {
             m_piDims[i] = _piDims[i];
         }
@@ -1379,7 +1456,7 @@ bool ArrayOf<T>::resize(int* _piDims, int _iDims)
     }
     else
     {
-        for (int i = 0 ; i < m_iDims ; i++)
+        for (int i = 0; i < m_iDims; i++)
         {
             m_piDims[i] = _piDims[i];
         }
index 765d77e..a813a52 100644 (file)
@@ -388,8 +388,8 @@ InternalType::ScilabType ImplicitList::getOutputType()
 
 void ImplicitList::extractValueAsDouble(int _iOccur, Double* d)
 {
-    double dblStart            = m_pDblStart->get(0);
-    double dblStep             = m_pDblStep->get(0);
+    double dblStart = m_pDblStart->get(0);
+    double dblStep = m_pDblStep->get(0);
     d->get()[0] = dblStart + _iOccur * dblStep;
 }
 
index 2357947..3dfaba0 100644 (file)
@@ -50,6 +50,7 @@ Macro::Macro(const std::wstring& _stName, std::list<symbol::Variable*>& _inputAr
     m_pDblArgOut = new Double(1);
     m_pDblArgOut->IncreaseRef(); //never delete
 
+    m_body->setReturnable();
 }
 
 Macro::~Macro()
@@ -306,14 +307,9 @@ Callable::ReturnValue Macro::call(typed_list &in, optional_list &opt, int _iRetC
         //m_body->accept(mute);
 
         ConfigVariable::setPromptMode(-1);
-        m_body->setReturnable();
         m_body->accept(*execFunc);
         //restore previous prompt mode
         ConfigVariable::setPromptMode(oldVal);
-        if (m_body->isReturn())
-        {
-            m_body->setReturnable();
-        }
     }
     catch (ast::ScilabMessage & sm)
     {
index 6fa1454..1bf7d91 100644 (file)
@@ -1,14 +1,14 @@
 /*
- *  Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
- *  Copyright (C) 2011 - DIGITEO - Antoine ELIAS
- *
- *  This file must be used under the terms of the CeCILL.
- *  This source file is licensed as described in the file COPYING, which
- *  you should have received as part of this distribution.  The terms
- *  are also available at
- *  http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
- *
- */
+*  Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+*  Copyright (C) 2011 - DIGITEO - Antoine ELIAS
+*
+*  This file must be used under the terms of the CeCILL.
+*  This source file is licensed as described in the file COPYING, which
+*  you should have received as part of this distribution.  The terms
+*  are also available at
+*  http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+*
+*/
 
 #include "alltypes.hxx"
 #include "types_tools.hxx"
 #include "execvisitor.hxx"
 extern "C"
 {
+#include "elem_common.h"
 #include "os_string.h"
 }
 
 namespace types
 {
+template<typename T>
+void getIndexes(T* val, std::vector<int>& vec)
+{
+    typename T::type* p = val->get();
+    int size = val->getSize();
+    for (int i = 0; i < size; ++i)
+    {
+        vec.push_back(static_cast<int>(p[i]));
+    }
+}
+
+template<typename T>
+double getIndex(T* val)
+{
+    typename T::type* p = val->get();
+    return static_cast<double>(p[0]);
+}
+
+double getIndex(InternalType* val)
+{
+    switch (val->getType())
+    {
+        //scalar
+        case InternalType::ScilabDouble:
+        {
+            return getIndex(val->getAs<Double>());
+        }
+        case InternalType::ScilabInt8:
+        {
+            return getIndex(val->getAs<Int8>());
+        }
+        case InternalType::ScilabInt16:
+        {
+            return getIndex(val->getAs<Int16>());
+        }
+        case InternalType::ScilabInt32:
+        {
+            return getIndex(val->getAs<Int32>());
+        }
+        case InternalType::ScilabInt64:
+        {
+            return getIndex(val->getAs<Int64>());
+        }
+        case InternalType::ScilabUInt8:
+        {
+            return getIndex(val->getAs<UInt8>());
+        }
+        case InternalType::ScilabUInt16:
+        {
+            return getIndex(val->getAs<UInt16>());
+        }
+        case InternalType::ScilabUInt32:
+        {
+            return getIndex(val->getAs<UInt32>());
+        }
+        case InternalType::ScilabUInt64:
+        {
+            return getIndex(val->getAs<UInt64>());
+        }
+    }
+
+    return 0;
+}
+
+//get only scalar index
+bool getScalarIndex(GenericType* _pRef, typed_list* _pArgsIn, int* index)
+{
+    //input size must be equal to ref dims
+    int dimsRef = _pRef->getDims();
+    int dimsIn = static_cast<int>(_pArgsIn->size());
+
+    //same dims and less than internal limit
+    if (dimsIn != 1 && dimsIn != dimsRef || dimsIn > MAX_DIMS)
+    {
+        return false;
+    }
+
+    int* pdims = _pRef->getDimsArray();
+    int ind[MAX_DIMS];
+    for (int i = 0; i < dimsIn; ++i)
+    {
+        InternalType* in = (*_pArgsIn)[i];
+        //input arg type must be scalar double, int8, int16, ...
+        if (in->isGenericType() && in->getAs<GenericType>()->isScalar())
+        {
+            ind[i] = static_cast<int>(getIndex(in)) - 1;
+            if (ind[i] == -1)
+            {
+                return false;
+            }
+        }
+        else
+        {
+            //failed, so use entire process
+            return false;
+        }
+    }
+
+    int idx = ind[0];
+    if (dimsIn > 1 && idx >= pdims[0])
+    {
+        return false;
+    }
+
+    for (int i = 1; i < dimsIn; ++i)
+    {
+        if (ind[i] >= pdims[i])
+        {
+            return false;
+        }
+        idx += ind[i] * pdims[i - 1];
+    }
+
+    *index = idx;
+    return true;
+}
+
+static double evalute(InternalType* pIT, int sizeRef)
+{
+    double real;
+    double img;
+    if (pIT->getId() == InternalType::IdScalarPolynom)
+    {
+        SinglePoly* pSP = pIT->getAs<Polynom>()->get()[0];
+        pSP->evaluate(sizeRef, 0, &real, &img);
+    }
+    else
+    {
+        real = getIndex(pIT);
+    }
+
+    return real;
+}
+//get index from implicit or colon index + scalar
+bool getImplicitIndex(GenericType* _pRef, typed_list* _pArgsIn, std::vector<int>& index)
+{
+    int dimsRef = _pRef->getDims();
+    int dimsIn = static_cast<int>(_pArgsIn->size());
+    bool viewAsVector = dimsIn == 1;
+    //same dims and less than internal limit
+    if (dimsIn != 1 && dimsIn != dimsRef || dimsIn > MAX_DIMS)
+    {
+        return false;
+    }
+
+    int* pdims = _pRef->getDimsArray();
+    //input arg type must be computable ( double, $, :, ... )
+    std::list<std::vector<int>> lstIdx;
+    int finalSize = 1;
+    for (int i = 0; i < dimsIn; ++i)
+    {
+        InternalType* in = (*_pArgsIn)[i];
+        if (in->isGenericType() && in->getAs<GenericType>()->isScalar())
+        {
+            int idx = static_cast<int>(getIndex(in)) - 1;
+            if (idx == -1)
+            {
+                return false;
+            }
+
+            lstIdx.emplace_back(1, idx);
+        }
+        else if (in->isColon())
+        {
+            vector<int> idx(2);
+            idx[0] = -1;
+            idx[1] = viewAsVector ? _pRef->getSize() : pdims[i];
+            lstIdx.push_back(idx);
+            finalSize *= idx[1];
+        }
+        else if (in->isImplicitList())
+        {
+            ImplicitList* pIL = in->getAs<ImplicitList>();
+            int sizeRef = viewAsVector ? _pRef->getSize() : pdims[i];
+            double start = evalute(pIL->getStart(), sizeRef);
+            double step = evalute(pIL->getStep(), sizeRef);
+            double end = evalute(pIL->getEnd(), sizeRef);
+
+            //printf("%.2f : %.2f : %.2f\n", start, step, end);
+
+            int size = (end - start) / step + 1;
+            vector<int> idx(size);
+
+            int* pi = idx.data();
+            pi[0] = start - 1; //0-indexed
+            for (int j = 1; j < size; ++j)
+            {
+                pi[j] = pi[j - 1] + step;
+            }
+
+            lstIdx.push_back(idx);
+            finalSize *= size;
+        }
+        else
+        {
+            return false;
+        }
+    }
+
+    index.resize(finalSize, 0);
+    //printf("finalSize : %d\n", finalSize);
+    //compute tuples
+    int previousSize = 1;
+    int currentDim = 0;
+    int previousDims = 1;
+    while (lstIdx.empty() == false)
+    {
+        std::vector<int>& v = lstIdx.front();
+        int currentSize = v.size();
+        const int* pv = v.data();
+
+        bool colon = false;
+        if (pv[0] == -1 && currentSize == 2)
+        {
+            currentSize = pv[1];
+            int occ = finalSize / (currentSize * previousSize);
+            for (int n = 0; n < occ; ++n)
+            {
+                int idx = currentSize * previousSize * n;
+                for (int m = 0; m < currentSize; ++m)
+                {
+                    if (dimsIn > 1 && m >= pdims[currentDim])
+                    {
+                        return false;
+                    }
+                    int idx2 = idx + previousSize * m;
+                    int idx3 = previousDims * m;
+                    for (int j = 0; j < previousSize; ++j)
+                    {
+                        index[idx2 + j] += idx3;
+                        //printf("\tindex[%d] = %d\n", idx2 + i, previousSize * v[m]);
+                    }
+                }
+            }
+        }
+        else
+        {
+            //printf("currentSize : %d\n", currentSize);
+            //printf("previousSize : %d\n", previousSize);
+            //printf("n : %d\n", finalSize / (currentSize * previousSize));
+            int occ = finalSize / (currentSize * previousSize);
+            for (int n = 0; n < occ; ++n)
+            {
+                int idx = currentSize * previousSize * n;
+                for (int m = 0; m < currentSize; ++m)
+                {
+                    if (dimsIn > 1 && pv[m] >= pdims[currentDim])
+                    {
+                        return false;
+                    }
+                    int idx2 = idx + previousSize * m;
+                    int idx3 = previousDims * pv[m];
+                    for (int j = 0; j < previousSize; ++j)
+                    {
+                        index[idx2 + j] += idx3;
+                        //printf("\tindex[%d] = %d\n", idx2 + i, previousSize * v[m]);
+                    }
+                }
+            }
+        }
+
+        previousSize *= currentSize;
+        previousDims *= pdims[currentDim];
+        ++currentDim;
+        //remove used vector
+        lstIdx.pop_front();
+    }
+
+    return true;
+}
+
 //check argument types and compute, dimensions, count of combinations, max indexes
 int checkIndexesArguments(InternalType* _pRef, typed_list* _pArgsIn, typed_list* _pArgsOut, int* _piMaxDim, int* _piCountDim)
 {
-    int iDims           = static_cast<int>(_pArgsIn->size());
-    int iSeqCount       = 1;
-    bool bUndefine      = false;
+    int iDims = static_cast<int>(_pArgsIn->size());
+    int iSeqCount = 1;
+    bool bUndefine = false;
 
-    for (int i = 0 ; i < iDims ; i++)
+    for (int i = 0; i < iDims; i++)
     {
-        bool bDeleteNeeded  = false;
+        bool bDeleteNeeded = false;
         InternalType* pIT = (*_pArgsIn)[i];
         Double *pCurrentArg = NULL;
 
@@ -84,6 +356,7 @@ int checkIndexesArguments(InternalType* _pRef, typed_list* _pArgsIn, typed_list*
             }
         }
 
+        //previous  if can update pIT to Colon
         if (pIT->isColon() || pIT->isImplicitList())
         {
             //: or a:b:c
@@ -108,7 +381,7 @@ int checkIndexesArguments(InternalType* _pRef, typed_list* _pArgsIn, typed_list*
 #endif
                 if (pIL->getStart()->isPoly())
                 {
-                    Polynom *poPoly    = pIL->getStart()->getAs<types::Polynom>();
+                    Polynom *poPoly = pIL->getStart()->getAs<types::Polynom>();
 #if defined(_SCILAB_DEBUGREF_)
                     pIL->setStart(poPoly->evaluate(pdbl));
 #else
@@ -117,7 +390,7 @@ int checkIndexesArguments(InternalType* _pRef, typed_list* _pArgsIn, typed_list*
                 }
                 if (pIL->getStep()->isPoly())
                 {
-                    Polynom *poPoly    = pIL->getStep()->getAs<types::Polynom>();
+                    Polynom *poPoly = pIL->getStep()->getAs<types::Polynom>();
 #if defined(_SCILAB_DEBUGREF_)
                     pIL->setStep(poPoly->evaluate(pdbl));
 #else
@@ -126,7 +399,7 @@ int checkIndexesArguments(InternalType* _pRef, typed_list* _pArgsIn, typed_list*
                 }
                 if (pIL->getEnd()->isPoly())
                 {
-                    Polynom *poPoly    = pIL->getEnd()->getAs<types::Polynom>();
+                    Polynom *poPoly = pIL->getEnd()->getAs<types::Polynom>();
 #if defined(_SCILAB_DEBUGREF_)
                     pIL->setEnd(poPoly->evaluate(pdbl));
 #else
@@ -199,11 +472,11 @@ int checkIndexesArguments(InternalType* _pRef, typed_list* _pArgsIn, typed_list*
         {
             //$
             Polynom* pMP = pIT->getAs<types::Polynom>();
-            int iMaxDim     = 0;
+            int iMaxDim = 0;
             //if pRef == NULL, use 0 insteadof, to allow a($+1) on new variable
             if (_pRef)
             {
-                iMaxDim     = _pRef->getAs<GenericType>()->getVarMaxDim(i, iDims);
+                iMaxDim = _pRef->getAs<GenericType>()->getVarMaxDim(i, iDims);
             }
 
 #ifdef _SCILAB_DEBUGREF_
@@ -218,13 +491,13 @@ int checkIndexesArguments(InternalType* _pRef, typed_list* _pArgsIn, typed_list*
         else if (pIT->isBool())
         {
             //[T F F T F]
-            Bool *pB    = pIT->getAs<types::Bool>();
-            int *piB    = pB->get();
+            Bool *pB = pIT->getAs<types::Bool>();
+            int *piB = pB->get();
             const int size = pB->getSize();
 
             //find true item count
             int iItemCount = 0;
-            for (int j = 0 ; j < size; j++)
+            for (int j = 0; j < size; j++)
             {
                 if (piB[j])
                 {
@@ -233,11 +506,11 @@ int checkIndexesArguments(InternalType* _pRef, typed_list* _pArgsIn, typed_list*
             }
 
             //allow new Double variable
-            Double* pDbl    = new Double(1, iItemCount);
-            double* pdbl    = pDbl->getReal();
+            Double* pDbl = new Double(1, iItemCount);
+            double* pdbl = pDbl->getReal();
 
             int j = 0;
-            for (int l = 0 ; l < size; l++)
+            for (int l = 0; l < size; l++)
             {
                 if (piB[l])
                 {
@@ -256,7 +529,7 @@ int checkIndexesArguments(InternalType* _pRef, typed_list* _pArgsIn, typed_list*
         {
             const int iCountDim = pCurrentArg->getSize();
             _piMaxDim[i] = 0;
-            for (int j = 0 ; j < iCountDim ; j++)
+            for (int j = 0; j < iCountDim; j++)
             {
                 //checks if size < size(int)
                 if (pCurrentArg->get(j) >= INT_MAX)
@@ -266,7 +539,7 @@ int checkIndexesArguments(InternalType* _pRef, typed_list* _pArgsIn, typed_list*
                     throw ast::ScilabError(szError);
                 }
 
-                const int d = static_cast<int>(pCurrentArg->get(j));
+                int d = static_cast<int>(pCurrentArg->get(j));
                 if (d > _piMaxDim[i])
                 {
                     _piMaxDim[i] = d;
@@ -329,7 +602,7 @@ void cleanIndexesArguments(typed_list* _pArgsOrig, typed_list* _pArgsNew)
 void getIndexesWithDims(int _iIndex, int* _piIndexes, int* _piDims, int _iDims)
 {
     int iMul = 1;
-    for (int i = 0 ; i < _iDims ; i++)
+    for (int i = 0; i < _iDims; i++)
     {
         _piIndexes[i] = (int)(_iIndex / iMul) % _piDims[i];
         iMul *= _piDims[i];
@@ -368,7 +641,7 @@ int getIndexWithDims(int* _piIndexes, int* _piDims, int _iDims)
 {
     int idx = 0;
     int iMult = 1;
-    for (int i = 0 ; i < _iDims ; i++)
+    for (int i = 0; i < _iDims; i++)
     {
         idx += _piIndexes[i] * iMult;
         iMult *= _piDims[i];
diff --git a/scilab/modules/ast/tests/unit_tests/controlexp.dia.ref b/scilab/modules/ast/tests/unit_tests/controlexp.dia.ref
new file mode 100644 (file)
index 0000000..2e89fd5
--- /dev/null
@@ -0,0 +1,72 @@
+// ============================================================================
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2015 - Scilab Enterprises - Antoine ELIAS
+//
+//  This file is distributed under the same license as the Scilab package.
+// ============================================================================
+//
+// <-- JVM NOT MANDATORY -->
+//
+//check break instruction
+//in for expression
+function res = test_for_break()
+    res = 0;
+    for i = 1:10
+        res = i;
+        if res == 5 then
+            break;
+        end
+    end
+endfunction
+exec(test_for_break);
+assert_checktrue(res == 5);
+res = test_for_break();
+assert_checktrue(res == 5);
+//in while expression
+function res = test_while_break()
+    i = 1;
+    res = 0;
+    while i <= 10
+        res = i;
+        if res == 5 then
+            break;
+        end
+        i = i+1;
+    end
+endfunction
+exec(test_while_break);
+assert_checktrue(res == 5);
+res = test_while_break();
+assert_checktrue(res == 5);
+//test continue instruction
+//in for expression
+function res = test_for_continue()
+    res = 0;
+    for i = 1:10
+        if i == 5 then
+            continue;
+        end
+        res = res + i;
+    end
+endfunction
+exec(test_for_continue);
+assert_checktrue(res == sum(1:4) + sum(6:10));
+res = test_for_continue();
+assert_checktrue(res == sum(1:4) + sum(6:10));
+//in while expression
+function res = test_while_continue()
+    i = 1;
+    res = 0;
+    while i <= 10
+        if i == 5 then
+            i = i+1;
+            continue;
+        end
+        res = res + i;
+        i = i+1;
+    end
+endfunction
+exec(test_while_continue);
+assert_checktrue(res == sum(1:4) + sum(6:10));
+res = test_while_continue();
+assert_checktrue(res == sum(1:4) + sum(6:10));
diff --git a/scilab/modules/ast/tests/unit_tests/controlexp.tst b/scilab/modules/ast/tests/unit_tests/controlexp.tst
new file mode 100644 (file)
index 0000000..f83406e
--- /dev/null
@@ -0,0 +1,85 @@
+// ============================================================================
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2015 - Scilab Enterprises - Antoine ELIAS
+//
+//  This file is distributed under the same license as the Scilab package.
+// ============================================================================
+//
+// <-- JVM NOT MANDATORY -->
+//
+
+//check break instruction
+//in for expression
+function res = test_for_break()
+    res = 0;
+    for i = 1:10
+        res = i;
+        if res == 5 then
+            break;
+        end
+    end
+endfunction
+
+exec(test_for_break);
+assert_checktrue(res == 5);
+
+res = test_for_break();
+assert_checktrue(res == 5);
+
+//in while expression
+function res = test_while_break()
+    i = 1;
+    res = 0;
+    while i <= 10
+        res = i;
+        if res == 5 then
+            break;
+        end
+
+        i = i+1;
+    end
+endfunction
+
+exec(test_while_break);
+assert_checktrue(res == 5);
+
+res = test_while_break();
+assert_checktrue(res == 5);
+
+//test continue instruction
+//in for expression
+function res = test_for_continue()
+    res = 0;
+    for i = 1:10
+        if i == 5 then
+            continue;
+        end
+        res = res + i;
+    end
+endfunction
+
+exec(test_for_continue);
+assert_checktrue(res == sum(1:4) + sum(6:10));
+
+res = test_for_continue();
+assert_checktrue(res == sum(1:4) + sum(6:10));
+
+//in while expression
+function res = test_while_continue()
+    i = 1;
+    res = 0;
+    while i <= 10
+        if i == 5 then
+            i = i+1;
+            continue;
+        end
+        res = res + i;
+        i = i+1;
+    end
+endfunction
+
+exec(test_while_continue);
+assert_checktrue(res == sum(1:4) + sum(6:10));
+
+res = test_while_continue();
+assert_checktrue(res == sum(1:4) + sum(6:10));
index dea0711..c3fb7ee 100644 (file)
@@ -6,5 +6,5 @@
 // =============================================================================
 function ret = isRelease()
     [a,b] = getversion();
-    ret = b(5) == "release";
+    ret = b(4) == "release";
 endfunction