overload exec visitor from external modules 87/19487/6
Cedric Delamarre [Mon, 18 Sep 2017 13:57:06 +0000 (15:57 +0200)]
Change-Id: I6e9f16cc33f84e6ef9ece80e860f6e6579b8912d

13 files changed:
scilab/CHANGES.md
scilab/modules/ast/includes/analysis/AnalysisVisitor.hxx
scilab/modules/ast/includes/analysis/data/LoopAnalyzer.hxx
scilab/modules/ast/includes/analysis/gvn/InferenceConstraint.hxx
scilab/modules/ast/includes/ast/execvisitor.hxx
scilab/modules/ast/includes/ast/runvisitor.hxx
scilab/modules/ast/includes/exps/opexp.hxx
scilab/modules/ast/includes/types/types.hxx
scilab/modules/ast/includes/types/user.hxx
scilab/modules/ast/src/cpp/analysis/VisitTypeExps.cpp
scilab/modules/ast/src/cpp/ast/prettyprintvisitor.cpp
scilab/modules/ast/src/cpp/ast/run_CallExp.hpp
scilab/modules/functions/sci_gateway/cpp/sci_testAnalysis.cpp

index 77848e8..3a2094d 100644 (file)
@@ -28,6 +28,7 @@ In summary, the main new features are:
   - Support for bigger data sets, thanks to dynamic memory usage. No need for `stacksize` anymore.
   - Better performance for some objects (cells and structs).
   - Clearer, less ambiguous, language syntax.
+  - Executor reuse for specialization and custom engines.
   - Xcos also uses the new re-written Scilab engine.
 * New code productivity features: full-featured debugger, profiler / coverage tool, and "lint"-like commands.
 * Newsfeed, providing a continuous feed of news, tips, and general communication from the community and from Scilab Enterprises.
index 954b5bb..0a6b98f 100644 (file)
@@ -445,7 +445,6 @@ private:
     void visit(ast::ArrayListExp & e)
     {
         logger.log(L"ArrayListExp", e.getLocation());
-        const ast::exps_t & exps = e.getExps();
         for (const auto exp : e.getExps())
         {
             exp->accept(*this);
index 536163f..1b82d67 100644 (file)
@@ -207,55 +207,55 @@ private:
         }
     }
 
-    void visit(ast::SimpleVar & e)
+    void visit(ast::SimpleVar & /*e*/)
     {
     }
 
-    void visit(ast::DollarVar & e)
+    void visit(ast::DollarVar & /*e*/)
     {
     }
 
-    void visit(ast::ColonVar & e)
+    void visit(ast::ColonVar & /*e*/)
     {
     }
 
-    void visit(ast::ArrayListVar & e)
+    void visit(ast::ArrayListVar & /*e*/)
     {
     }
 
-    void visit(ast::DoubleExp & e)
+    void visit(ast::DoubleExp & /*e*/)
     {
     }
 
-    void visit(ast::BoolExp & e)
+    void visit(ast::BoolExp & /*e*/)
     {
     }
 
-    void visit(ast::StringExp & e)
+    void visit(ast::StringExp & /*e*/)
     {
     }
 
-    void visit(ast::CommentExp & e)
+    void visit(ast::CommentExp & /*e*/)
     {
     }
 
-    void visit(ast::NilExp & e)
+    void visit(ast::NilExp & /*e*/)
     {
     }
 
-    void visit(ast::CallExp & e)
+    void visit(ast::CallExp & /*e*/)
     {
     }
 
-    void visit(ast::CellCallExp & e)
+    void visit(ast::CellCallExp & /*e*/)
     {
     }
 
-    void visit(ast::OpExp & e)
+    void visit(ast::OpExp & /*e*/)
     {
     }
 
-    void visit(ast::LogicalOpExp & e)
+    void visit(ast::LogicalOpExp & /*e*/)
     {
     }
 
@@ -326,11 +326,11 @@ private:
         pushAssigned();
     }
 
-    void visit(ast::BreakExp & e)
+    void visit(ast::BreakExp & /*e*/)
     {
     }
 
-    void visit(ast::ContinueExp & e)
+    void visit(ast::ContinueExp & /*e*/)
     {
     }
 
@@ -358,31 +358,31 @@ private:
         e.getBody()->accept(*this);
     }
 
-    void visit(ast::ReturnExp & e)
+    void visit(ast::ReturnExp & /*e*/)
     {
     }
 
-    void visit(ast::FieldExp & e)
+    void visit(ast::FieldExp & /*e*/)
     {
     }
 
-    void visit(ast::NotExp & e)
+    void visit(ast::NotExp & /*e*/)
     {
     }
 
-    void visit(ast::TransposeExp & e)
+    void visit(ast::TransposeExp & /*e*/)
     {
     }
 
-    void visit(ast::MatrixExp & e)
+    void visit(ast::MatrixExp & /*e*/)
     {
     }
 
-    void visit(ast::MatrixLineExp & e)
+    void visit(ast::MatrixLineExp & /*e*/)
     {
     }
 
-    void visit(ast::CellExp & e)
+    void visit(ast::CellExp & /*e*/)
     {
     }
 
@@ -407,11 +407,11 @@ private:
         }
     }
 
-    void visit(ast::ArrayListExp & e)
+    void visit(ast::ArrayListExp & /*e*/)
     {
     }
 
-    void visit(ast::AssignListExp & e)
+    void visit(ast::AssignListExp & /*e*/)
     {
     }
 
@@ -420,23 +420,23 @@ private:
         emplaceAssigned(e.getSymbol());
     }
 
-    void visit(ast::FunctionDec & e)
+    void visit(ast::FunctionDec & /*e*/)
     {
     }
 
-    void visit(ast::ListExp & e)
+    void visit(ast::ListExp & /*e*/)
     {
     }
 
-    void visit(ast::OptimizedExp & e)
+    void visit(ast::OptimizedExp & /*e*/)
     {
     }
 
-    void visit(ast::MemfillExp & e)
+    void visit(ast::MemfillExp & /*e*/)
     {
     }
 
-    void visit(ast::DAXPYExp & e)
+    void visit(ast::DAXPYExp & /*e*/)
     {
     }
 
index 18f7a96..7c58ac7 100644 (file)
@@ -39,7 +39,7 @@ struct InferenceConstraint
 
     virtual Result check(GVN & gvn, const std::vector<GVN::Value *> & values) const = 0;
     virtual MPolyConstraintSet getMPConstraints(const std::vector<GVN::Value *> & values) const = 0;
-    virtual void applyConstraints(const std::vector<GVN::Value *> & values) const { }
+    virtual void applyConstraints(const std::vector<GVN::Value *> & /*values*/) const { }
 
     inline static std::vector<const MultivariatePolynomial *> getArgs(const std::vector<GVN::Value *> & values)
     {
index 257b5be..6282e74 100644 (file)
@@ -27,6 +27,8 @@ class EXTERN_AST ExecVisitor : public RunVisitorT<ExecVisitor>
         return new ExecVisitor();
     }
 
+protected:
+
     void visit(const SeqExp  &e)
     {
         visitprivate(e);
index 1ea732f..7d89860 100644 (file)
@@ -96,6 +96,8 @@ public:
     }
 
 public:
+    void getInputs(const CallExp& e, exps_t& args, types::typed_list& inTmp, std::vector<std::wstring>& vectOptName, std::vector<int>& vectNbResult);
+
     int getExpectedSize(void)
     {
         return _expected_result;
index f82f147..ed425c5 100644 (file)
@@ -71,7 +71,9 @@ public:
         /** \brief "||" */     logicalShortCutOr,
 
         // Unary minus
-        /** \brief "-" */ unaryMinus
+        /** \brief "-" */ unaryMinus,
+
+        /** unknow operator*/ unknown
     };
 
     /** \name Ctor & dtor.
@@ -249,6 +251,8 @@ public:
                 return L"||";
             case unaryMinus:
                 return L"-";
+            case unknown:
+                return L"unknown";
         }
     }
 
index d321dba..2220c61 100644 (file)
@@ -64,27 +64,27 @@ public :
     bool                        isScalar();
 
     /*commun functions*/
-    inline int                  getCols()
+    virtual int                  getCols()
     {
         return m_iCols;
     }
 
-    inline int                  getRows()
+    virtual int                  getRows()
     {
         return m_iRows;
     }
 
-    inline int                  getSize()
+    virtual int                  getSize()
     {
         return m_iSize;
     }
 
-    inline int                  getDims()
+    virtual int                  getDims()
     {
         return m_iDims;
     }
 
-    inline int*                 getDimsArray()
+    virtual int*                 getDimsArray()
     {
         return m_piDims;
     }
index 403619f..e1c0185 100644 (file)
@@ -62,7 +62,7 @@ public :
     /*** User can overload these methods                            ***/
     /*** all methods not overloaded will call scilab overload       ***/
 
-    virtual bool operator==(const InternalType& it) override
+    virtual bool operator==(const InternalType& /*it*/) override
     {
         return false;
     }
index 5c14391..b51e25b 100644 (file)
@@ -26,16 +26,16 @@ void AnalysisVisitor::visit(ast::DoubleExp & e)
         e.accept(cv.getExec());
         cv.getExec().setResult(nullptr);
     }
-    types::Double * pDbl = static_cast<types::Double *>(e.getConstant());
-    if (pDbl->isComplex())
+    types::GenericType* pGT = e.getConstant()->getAs<types::GenericType>();
+    if (pGT->isComplex())
     {
-        Result & res = e.getDecorator().setResult(TIType(dm.getGVN(), TIType::COMPLEX, pDbl->getRows(), pDbl->getCols()));
+        Result & res = e.getDecorator().setResult(TIType(dm.getGVN(), TIType::COMPLEX, pGT->getRows(), pGT->getCols()));
         res.getConstant() = e.getConstant();
         setResult(res);
     }
     else
     {
-        Result & res = e.getDecorator().setResult(TIType(dm.getGVN(), TIType::DOUBLE, pDbl->getRows(), pDbl->getCols()));
+        Result & res = e.getDecorator().setResult(TIType(dm.getGVN(), TIType::DOUBLE, pGT->getRows(), pGT->getCols()));
         res.getConstant() = e.getConstant();
         setResult(res);
     }
@@ -49,8 +49,9 @@ void AnalysisVisitor::visit(ast::BoolExp & e)
         e.accept(cv.getExec());
         cv.getExec().setResult(nullptr);
     }
-    types::Bool * pBool = static_cast<types::Bool *>(e.getConstant());
-    Result & res = e.getDecorator().setResult(TIType(dm.getGVN(), TIType::BOOLEAN, pBool->getRows(), pBool->getCols()));
+
+    types::GenericType* pGT = e.getConstant()->getAs<types::GenericType>();
+    Result & res = e.getDecorator().setResult(TIType(dm.getGVN(), TIType::BOOLEAN, pGT->getRows(), pGT->getCols()));
     res.getConstant() = e.getConstant();
     setResult(res);
 }
@@ -63,8 +64,8 @@ void AnalysisVisitor::visit(ast::StringExp & e)
         e.accept(cv.getExec());
         cv.getExec().setResult(nullptr);
     }
-    types::String * pStr = static_cast<types::String *>(e.getConstant());
-    Result & res = e.getDecorator().setResult(TIType(dm.getGVN(), TIType::STRING, pStr->getRows(), pStr->getCols()));
+    types::GenericType* pGT = e.getConstant()->getAs<types::GenericType>();
+    Result & res = e.getDecorator().setResult(TIType(dm.getGVN(), TIType::STRING, pGT->getRows(), pGT->getCols()));
     res.getConstant() = e.getConstant();
     setResult(res);
 }
index 775b4c6..1930eae 100644 (file)
@@ -324,10 +324,14 @@ void PrettyPrintVisitor::visit(const DoubleExp & e)
                    << static_cast<types::Double *>(pIL->getStep())->get(0) << L":"
                    << static_cast<types::Double *>(pIL->getEnd())->get(0);
         }
-        else
+        else if (pIT->isDouble())
         {
             printInternalType<types::Double>(stream, pIT);
         }
+        else
+        {
+            stream << pIT->getTypeStr();
+        }
     }
     else
     {
index bbf3854..db76707 100644 (file)
@@ -30,96 +30,7 @@ void RunVisitorT<T>::visitprivate(const CallExp &e)
 
     //get function arguments
     exps_t args = e.getArgs();
-    try
-    {
-        for (auto& arg : args)
-        {
-            int iSize = getExpectedSize();
-            if (arg->isAssignExp())
-            {
-                AssignExp* pAssign = static_cast<AssignExp*>(arg);
-                //optional parameter
-                Exp* pL = &pAssign->getLeftExp();
-                if (!pL->isSimpleVar())
-                {
-                    std::wostringstream os;
-                    os << _W("left side of optional parameter must be a variable") << std::endl;
-                    CoverageInstance::stopChrono((void*)&e);
-                    throw ast::InternalError(os.str(), 999, e.getLocation());
-                }
-
-                SimpleVar* pVar = pL->getAs<SimpleVar>();
-                Exp* pR = &pAssign->getRightExp();
-                // optional parameter have only one output argument
-                setExpectedSize(1);
-                try
-                {
-                    pR->accept(*this);
-                }
-                catch (ScilabException &)
-                {
-                    CoverageInstance::stopChrono((void*)&e);
-                    throw;
-                }
-                setExpectedSize(iSize);
-                types::InternalType* pITR = getResult();
-                // IncreaseRef to protect opt argument of scope_end delete
-                // It will be deleted by clear_opt
-                pITR->IncreaseRef();
-
-                vectOptName.push_back(pVar->getSymbol().getName());
-                inTmp.push_back(pITR);
-                vectNbResult.push_back(1);
-
-                clearResult();
-                continue;
-            }
-
-            setExpectedSize(-1);
-            try
-            {
-                arg->accept(*this);
-            }
-            catch (ScilabException &)
-            {
-                CoverageInstance::stopChrono((void*)&e);
-                throw;
-            }
-            setExpectedSize(iSize);
-
-            if (getResult() == NULL)
-            {
-                //special case for empty extraction of list ( list()(:) )
-                vectNbResult.push_back(0);
-                continue;
-            }
-
-            if (isSingleResult())
-            {
-                inTmp.push_back(getResult());
-                getResult()->IncreaseRef();
-            }
-            else
-            {
-                for (int i = 0; i < getResultSize(); i++)
-                {
-                    types::InternalType * pITArg = getResult(i);
-                    pITArg->IncreaseRef();
-                    inTmp.push_back(pITArg);
-                }
-            }
-
-            vectNbResult.push_back(getResultSize());
-            clearResult();
-        }
-    }
-    catch (const InternalError& ie)
-    {
-        clearResult();
-        cleanIn(inTmp, outTmp);
-        CoverageInstance::stopChrono((void*)&e);
-        throw ie;
-    }
+    getInputs(e, args, inTmp, vectOptName, vectNbResult);
 
     // reset expected size for recursive call
     // ie [a, b] = l(1)(1), where l is a list containing a function with two output argument
@@ -436,6 +347,7 @@ void RunVisitorT<T>::visitprivate(const CellCallExp &e)
                 CoverageInstance::stopChrono((void*)&e);
                 throw ast::InternalError(_W("[error] Cell contents reference from a non-cell array object.\n"), 999, e.getFirstLocation());
             }
+
             //Create list of indexes
             ast::exps_t exps = e.getArgs();
             types::typed_list *pArgs = GetArgumentList(exps);
@@ -495,4 +407,98 @@ void RunVisitorT<T>::visitprivate(const CellCallExp &e)
     CoverageInstance::stopChrono((void*)&e);
 }
 
+void RunVisitor::getInputs(const CallExp& e, exps_t& args, types::typed_list& inTmp, std::vector<std::wstring>& vectOptName, std::vector<int>& vectNbResult)
+{
+    try
+    {
+        for (auto& arg : args)
+        {
+            int iSize = getExpectedSize();
+            if (arg->isAssignExp())
+            {
+                AssignExp* pAssign = static_cast<AssignExp*>(arg);
+                //optional parameter
+                Exp* pL = &pAssign->getLeftExp();
+                if (!pL->isSimpleVar())
+                {
+                    std::wostringstream os;
+                    os << _W("left side of optional parameter must be a variable") << std::endl;
+                    CoverageInstance::stopChrono((void*)&e);
+                    throw ast::InternalError(os.str(), 999, e.getLocation());
+                }
+
+                SimpleVar* pVar = pL->getAs<SimpleVar>();
+                Exp* pR = &pAssign->getRightExp();
+                // optional parameter have only one output argument
+                setExpectedSize(1);
+                try
+                {
+                    pR->accept(*this);
+                }
+                catch (ScilabException &)
+                {
+                    CoverageInstance::stopChrono((void*)&e);
+                    throw;
+                }
+                setExpectedSize(iSize);
+                types::InternalType* pITR = getResult();
+                // IncreaseRef to protect opt argument of scope_end delete
+                // It will be deleted by clear_opt
+                pITR->IncreaseRef();
+
+                vectOptName.push_back(pVar->getSymbol().getName());
+                inTmp.push_back(pITR);
+                vectNbResult.push_back(1);
+
+                clearResult();
+                continue;
+            }
+
+            setExpectedSize(-1);
+            try
+            {
+                arg->accept(*this);
+            }
+            catch (ScilabException &)
+            {
+                CoverageInstance::stopChrono((void*)&e);
+                throw;
+            }
+            setExpectedSize(iSize);
+
+            if (getResult() == NULL)
+            {
+                //special case for empty extraction of list ( list()(:) )
+                vectNbResult.push_back(0);
+                continue;
+            }
+
+            if (isSingleResult())
+            {
+                inTmp.push_back(getResult());
+                getResult()->IncreaseRef();
+            }
+            else
+            {
+                for (int i = 0; i < getResultSize(); i++)
+                {
+                    types::InternalType * pITArg = getResult(i);
+                    pITArg->IncreaseRef();
+                    inTmp.push_back(pITArg);
+                }
+            }
+
+            vectNbResult.push_back(getResultSize());
+            clearResult();
+        }
+    }
+    catch (const InternalError& ie)
+    {
+        clearResult();
+        types::typed_list outTmp;
+        cleanIn(inTmp, outTmp);
+        CoverageInstance::stopChrono((void*)&e);
+        throw ie;
+    }
+}
 } /* namespace ast */
index 6a0152b..adfc129 100644 (file)
@@ -35,7 +35,7 @@ extern "C"
 }
 
 /*--------------------------------------------------------------------------*/
-types::Function::ReturnValue sci_testAnalysis(types::typed_list &in, int _iRetCount, types::typed_list &out)
+types::Function::ReturnValue sci_testAnalysis(types::typed_list &in, int /*_iRetCount*/, types::typed_list &out)
 {
     if (in.size() == 0)
     {