Analysis: workaround for C++11 bug with Intel compiler 83/16783/1
Calixte DENIZET [Fri, 3 Jul 2015 14:39:56 +0000 (16:39 +0200)]
Change-Id: I774c99b845f341d0642097bdc882b5df0969f932

scilab/modules/ast/includes/analysis/AnalysisVisitor.hxx
scilab/modules/ast/src/cpp/analysis/VisitOpExp.cpp

index a822a3f..cc0cd69 100644 (file)
@@ -195,18 +195,18 @@ public:
 
     inline void registerFBlockEmittedListener(FBlockEmittedListener * listener)
     {
-       if (listener)
-       {
-           fblockListeners.push_back(listener);
-       }
+        if (listener)
+        {
+            fblockListeners.push_back(listener);
+        }
     }
 
     inline void emitFunctionBlock(FunctionBlock & fblock)
     {
-       for (auto listener : fblockListeners)
-       {
-           listener->action(fblock);
-       }
+        for (auto listener : fblockListeners)
+        {
+            listener->action(fblock);
+        }
     }
 
     inline Info & getSymInfo(const symbol::Symbol & sym)
@@ -233,39 +233,118 @@ private:
         }
     }
 
+    /*
+       Workaround for a C++11 bug with Intel compiler
+       https://software.intel.com/fr-fr/forums/topic/514793
+    */
+    inline static TIType _check_plus(GVN & gvn, const TIType & Ltype, const TIType & Rtype)
+    {
+        return check_____add____(gvn, Ltype, Rtype);
+    }
+
+    inline static TIType _check_minus(GVN & gvn, const TIType & Ltype, const TIType & Rtype)
+    {
+        return check_____sub____(gvn, Ltype, Rtype);
+    }
+
+    inline static TIType _check_dottimes(GVN & gvn, const TIType & Ltype, const TIType & Rtype)
+    {
+        return check_____dottimes____(gvn, Ltype, Rtype);
+    }
+
+    inline static TIType _check_dotrdiv(GVN & gvn, const TIType & Ltype, const TIType & Rtype)
+    {
+        return check_____dotrdiv____(gvn, Ltype, Rtype);
+    }
+
+    inline static TIType _check_dotpower(GVN & gvn, const TIType & Ltype, const TIType & Rtype)
+    {
+        return check_____dotpower____(gvn, Ltype, Rtype);
+    }
+
+    inline static TIType _check_eq(GVN & gvn, const TIType & Ltype, const TIType & Rtype)
+    {
+        return check_____eq____(gvn, Ltype, Rtype);
+    }
+
+    inline static TIType _check_neq(GVN & gvn, const TIType & Ltype, const TIType & Rtype)
+    {
+        return check_____neq____(gvn, Ltype, Rtype);
+    }
+
+    inline static TIType _check_lt(GVN & gvn, const TIType & Ltype, const TIType & Rtype)
+    {
+        return check_____lt____(gvn, Ltype, Rtype);
+    }
+
+    inline static TIType _check_le(GVN & gvn, const TIType & Ltype, const TIType & Rtype)
+    {
+        return check_____le____(gvn, Ltype, Rtype);
+    }
+
+    inline static TIType _check_gt(GVN & gvn, const TIType & Ltype, const TIType & Rtype)
+    {
+        return check_____gt____(gvn, Ltype, Rtype);
+    }
+
+    inline static TIType _check_ge(GVN & gvn, const TIType & Ltype, const TIType & Rtype)
+    {
+        return check_____ge____(gvn, Ltype, Rtype);
+    }
+
+    inline static TIType _check_and(GVN & gvn, const TIType & Ltype, const TIType & Rtype)
+    {
+        return check_____and____(gvn, Ltype, Rtype);
+    }
+
+    inline static TIType _check_or(GVN & gvn, const TIType & Ltype, const TIType & Rtype)
+    {
+        return check_____or____(gvn, Ltype, Rtype);
+    }
+
+    inline static TIType _check_andand(GVN & gvn, const TIType & Ltype, const TIType & Rtype)
+    {
+        return check_____and____(gvn, Ltype, Rtype);
+    }
+
+    inline static TIType _check_oror(GVN & gvn, const TIType & Ltype, const TIType & Rtype)
+    {
+        return check_____or____(gvn, Ltype, Rtype);
+    }
+
     template<TIType (F)(GVN &, const TIType &, const TIType &)>
-       inline TIType checkEWBinOp(TIType & LT, TIType & RT, const Result & LR, const Result & RR, bool & safe, int & tempId)
-    {
-       TIType resT = F(getGVN(), LT, RT);
-       if (resT.hasInvalidDims())
-       {
-           const bool ret = getCM().check(ConstraintManager::SAMEDIMS, LT.rows.getValue(), LT.cols.getValue(), RT.rows.getValue(), RT.cols.getValue());
-           
-           if (ret)
-           {
-               resT = F(getGVN(), LT, RT);
-               safe = true;
-           }
-           else
-           {
-               resT = resT.asUnknownMatrix();
-           }
-       }
-       else
-       {
-           safe = true;
-       }
-       
-       tempId = getTmpIdForEWOp(resT, LR, RR);
-       
-       if (resT.isscalar())
-       {
-       }
-
-       return resT;
-    }
-
-    
+    inline TIType checkEWBinOp(TIType & LT, TIType & RT, const Result & LR, const Result & RR, bool & safe, int & tempId)
+    {
+        TIType resT = F(getGVN(), LT, RT);
+        if (resT.hasInvalidDims())
+        {
+            const bool ret = getCM().check(ConstraintManager::SAMEDIMS, LT.rows.getValue(), LT.cols.getValue(), RT.rows.getValue(), RT.cols.getValue());
+
+            if (ret)
+            {
+                resT = F(getGVN(), LT, RT);
+                safe = true;
+            }
+            else
+            {
+                resT = resT.asUnknownMatrix();
+            }
+        }
+        else
+        {
+            safe = true;
+        }
+
+        tempId = getTmpIdForEWOp(resT, LR, RR);
+
+        if (resT.isscalar())
+        {
+        }
+
+        return resT;
+    }
+
+
     bool operGVNValues(ast::OpExp & oe);
     bool operSymbolicRange(ast::OpExp & oe);
 
@@ -274,7 +353,7 @@ private:
     int getTmpIdForEWOp(const TIType & resT, const Result & LR, const Result & RR);
     void visitArguments(const std::wstring & name, const unsigned int lhs, const TIType & calltype, ast::CallExp & e, const ast::exps_t & args);
 
-    
+
 
     void visit(ast::SelectExp & e);
     void visit(ast::ListExp & e);
@@ -306,7 +385,7 @@ private:
         Result & res = e.getDecorator().setResult(info.type);
         res.setConstant(info.getConstant());
         res.setRange(info.getRange());
-       res.setMaxIndex(info.getMaxIndex());
+        res.setMaxIndex(info.getMaxIndex());
         setResult(res);
     }
 
@@ -379,10 +458,10 @@ private:
             const symbol::Symbol & sym = var.getSymbol();
             const std::wstring & name = sym.getName();
             Info & info = getSymInfo(sym); // that put the sym in the current block !
-           Result & res = e.getName().getDecorator().setResult(info.type);
-           res.setConstant(info.getConstant());
-           res.setRange(info.getRange());
-           res.setMaxIndex(info.getMaxIndex());
+            Result & res = e.getName().getDecorator().setResult(info.type);
+            res.setConstant(info.getConstant());
+            res.setRange(info.getRange());
+            res.setMaxIndex(info.getMaxIndex());
 
             logger.log(L"CallExp", e.getLocation(), name);
 
@@ -526,10 +605,10 @@ private:
                 exp->accept(*this);
             }
         }
-       if (!e.getParent())
-       {
-           //e.accept(dv);
-       }
+        if (!e.getParent())
+        {
+            //e.accept(dv);
+        }
     }
 
     void visit(ast::ArrayListExp & e)
@@ -556,11 +635,11 @@ private:
         if (e.getInit().isListExp())
         {
             ast::ListExp & le = static_cast<ast::ListExp &>(e.getInit());
-           e.setListInfo(ForList64());
-           le.accept(*this);
-           Result & res = getResult();
-           Info & info = dm.define(sym, res.getType(), res.isAnInt(), &e);
-           info.setRange(res.getRange());
+            e.setListInfo(ForList64());
+            le.accept(*this);
+            Result & res = getResult();
+            Info & info = dm.define(sym, res.getType(), res.isAnInt(), &e);
+            info.setRange(res.getRange());
         }
     }
 
index aefc9c9..c6b1109 100644 (file)
 namespace analysis
 {
 
-    
 
-    void AnalysisVisitor::visit(ast::OpExp & e)
+
+void AnalysisVisitor::visit(ast::OpExp & e)
+{
+    logger.log(L"OpExp", e.getLocation());
+    TIType resT(getGVN());
+    int tempId = -1;
+    bool safe;
+
+    e.getLeft().accept(*this);
+    Result LR = getResult();
+    e.getRight().accept(*this);
+    Result & RR = getResult();
+    if (LR.getType().isknown() && RR.getType().isknown())
     {
-        logger.log(L"OpExp", e.getLocation());
-        TIType resT(getGVN());
-        int tempId = -1;
-       bool safe;
+        TIType & LT = LR.getType();
+        TIType & RT = RR.getType();
 
-        e.getLeft().accept(*this);
-        Result LR = getResult();
-        e.getRight().accept(*this);
-        Result & RR = getResult();
-        if (LR.getType().isknown() && RR.getType().isknown())
+        if (!operSymbolicRange(e) && !operGVNValues(e))
         {
-            TIType & LT = LR.getType();
-            TIType & RT = RR.getType();
-
-            if (!operSymbolicRange(e) && !operGVNValues(e))
+            switch (e.getOper())
             {
-                switch (e.getOper())
-                {
                 case ast::OpExp::plus :
                 {
-                   resT = checkEWBinOp<check_____add____>(LT, RT, LR, RR, safe, tempId);
+                    resT = checkEWBinOp<_check_plus>(LT, RT, LR, RR, safe, tempId);
                     break;
                 }
                 case ast::OpExp::minus:
                 {
-                   resT = checkEWBinOp<check_____sub____>(LT, RT, LR, RR, safe, tempId);
+                    resT = checkEWBinOp<_check_minus>(LT, RT, LR, RR, safe, tempId);
                     break;
                 }
                 case ast::OpExp::times:
@@ -58,22 +58,22 @@ namespace analysis
                         if (ret)
                         {
                             resT = check_____times____(getGVN(), LT, RT);
-                           safe = true;
+                            safe = true;
                         }
                         else
                         {
                             resT = resT.asUnknownMatrix();
                         }
                     }
-                   else
-                   {
-                       safe = true;
-                   }
+                    else
+                    {
+                        safe = true;
+                    }
+
+                    tempId = dm.getTmpId(resT, false);
+                    dm.releaseTmp(LR.getTempId());
+                    dm.releaseTmp(RR.getTempId());
 
-                   tempId = dm.getTmpId(resT, false);
-                   dm.releaseTmp(LR.getTempId());
-                   dm.releaseTmp(RR.getTempId());
-                   
                     break;
                 }
                 case ast::OpExp::rdivide:
@@ -85,21 +85,21 @@ namespace analysis
                         if (ret)
                         {
                             resT = check_____rdivide____(getGVN(), LT, RT);
-                           safe = true;
+                            safe = true;
                         }
                         else
                         {
                             resT = resT.asUnknownMatrix();
                         }
                     }
-                   else
-                   {
-                       safe = true;
-                   }
-                   
-                   tempId = dm.getTmpId(resT, false);
-                   dm.releaseTmp(LR.getTempId());
-                   dm.releaseTmp(RR.getTempId());
+                    else
+                    {
+                        safe = true;
+                    }
+
+                    tempId = dm.getTmpId(resT, false);
+                    dm.releaseTmp(LR.getTempId());
+                    dm.releaseTmp(RR.getTempId());
                     break;
                 }
                 case ast::OpExp::ldivide:
@@ -111,21 +111,21 @@ namespace analysis
                         if (ret)
                         {
                             resT = check_____ldivide____(getGVN(), LT, RT);
-                           safe = true;
+                            safe = true;
                         }
                         else
                         {
                             resT = resT.asUnknownMatrix();
                         }
                     }
-                   else
-                   {
-                       safe = true;
-                   }
-                   
-                   tempId = dm.getTmpId(resT, false);
-                   dm.releaseTmp(LR.getTempId());
-                   dm.releaseTmp(RR.getTempId());
+                    else
+                    {
+                        safe = true;
+                    }
+
+                    tempId = dm.getTmpId(resT, false);
+                    dm.releaseTmp(LR.getTempId());
+                    dm.releaseTmp(RR.getTempId());
                     break;
                 }
                 case ast::OpExp::power:
@@ -137,158 +137,158 @@ namespace analysis
                         if (ret)
                         {
                             resT = check_____power____(getGVN(), LT, RT);
-                           safe = true;
+                            safe = true;
                         }
                         else
                         {
                             resT = resT.asUnknownMatrix();
                         }
                     }
-                   else
-                   {
-                       safe = true;
-                   }
-                   
-                   tempId = dm.getTmpId(resT, false);
-                   dm.releaseTmp(LR.getTempId());
-                   dm.releaseTmp(RR.getTempId());
+                    else
+                    {
+                        safe = true;
+                    }
+
+                    tempId = dm.getTmpId(resT, false);
+                    dm.releaseTmp(LR.getTempId());
+                    dm.releaseTmp(RR.getTempId());
                     break;
                 }
                 case ast::OpExp::dottimes :
                 {
-                   resT = checkEWBinOp<check_____dottimes____>(LT, RT, LR, RR, safe, tempId);
+                    resT = checkEWBinOp<_check_dottimes>(LT, RT, LR, RR, safe, tempId);
                     break;
                 }
                 case ast::OpExp::dotrdivide:
                 {
-                   resT = checkEWBinOp<check_____dotrdiv____>(LT, RT, LR, RR, safe, tempId);
-                   break;
+                    resT = checkEWBinOp<_check_dotrdiv>(LT, RT, LR, RR, safe, tempId);
+                    break;
                 }
                 case ast::OpExp::dotpower:
                 {
-                   resT = checkEWBinOp<check_____dotpower____>(LT, RT, LR, RR, safe, tempId);
+                    resT = checkEWBinOp<_check_dotpower>(LT, RT, LR, RR, safe, tempId);
                     break;
                 }
                 case ast::OpExp::unaryMinus :
                 {
                     resT = check_____unaryminus____(getGVN(), RT);
-                   if (!resT.hasInvalidDims())
-                   {
-                       safe = true;
-                   }
-                   tempId = RR.getTempId();
+                    if (!resT.hasInvalidDims())
+                    {
+                        safe = true;
+                    }
+                    tempId = RR.getTempId();
                     break;
                 }
                 case ast::OpExp::krontimes :
                 {
                     resT = check_____krontimes____(getGVN(), LT, RT);
-                   if (!resT.hasInvalidDims())
-                   {
-                       safe = true;
-                   }
-                   tempId = dm.getTmpId(resT, false);
-                   dm.releaseTmp(LR.getTempId());
-                   dm.releaseTmp(RR.getTempId());
+                    if (!resT.hasInvalidDims())
+                    {
+                        safe = true;
+                    }
+                    tempId = dm.getTmpId(resT, false);
+                    dm.releaseTmp(LR.getTempId());
+                    dm.releaseTmp(RR.getTempId());
                     break;
                 }
                 case ast::OpExp::eq:
                 {
-                   resT = checkEWBinOp<check_____eq____>(LT, RT, LR, RR, safe, tempId);
+                    resT = checkEWBinOp<_check_eq>(LT, RT, LR, RR, safe, tempId);
                     break;
                 }
                 case ast::OpExp::ne:
                 {
-                   resT = checkEWBinOp<check_____neq____>(LT, RT, LR, RR, safe, tempId);
+                    resT = checkEWBinOp<_check_neq>(LT, RT, LR, RR, safe, tempId);
                     break;
                 }
                 case ast::OpExp::lt:
                 {
-                   resT = checkEWBinOp<check_____lt____>(LT, RT, LR, RR, safe, tempId);
+                    resT = checkEWBinOp<_check_lt>(LT, RT, LR, RR, safe, tempId);
                     break;
                 }
                 case ast::OpExp::le:
                 {
-                   resT = checkEWBinOp<check_____le____>(LT, RT, LR, RR, safe, tempId);
+                    resT = checkEWBinOp<_check_le>(LT, RT, LR, RR, safe, tempId);
                     break;
                 }
                 case ast::OpExp::gt:
                 {
-                   resT = checkEWBinOp<check_____gt____>(LT, RT, LR, RR, safe, tempId);
+                    resT = checkEWBinOp<_check_gt>(LT, RT, LR, RR, safe, tempId);
                     break;
                 }
                 case ast::OpExp::ge:
                 {
-                   resT = checkEWBinOp<check_____ge____>(LT, RT, LR, RR, safe, tempId);
+                    resT = checkEWBinOp<_check_ge>(LT, RT, LR, RR, safe, tempId);
                     break;
                 }
                 case ast::OpExp::logicalAnd:
                 {
-                   resT = checkEWBinOp<check_____and____>(LT, RT, LR, RR, safe, tempId);
+                    resT = checkEWBinOp<_check_and>(LT, RT, LR, RR, safe, tempId);
                     break;
                 }
                 case ast::OpExp::logicalOr:
                 {
-                   resT = checkEWBinOp<check_____or____>(LT, RT, LR, RR, safe, tempId);
+                    resT = checkEWBinOp<_check_or>(LT, RT, LR, RR, safe, tempId);
                     break;
                 }
                 case ast::OpExp::logicalShortCutAnd:
                 {
-                   resT = checkEWBinOp<check_____andand____>(LT, RT, LR, RR, safe, tempId);
+                    resT = checkEWBinOp<_check_andand>(LT, RT, LR, RR, safe, tempId);
                     break;
                 }
                 case ast::OpExp::logicalShortCutOr:
                 {
-                   resT = checkEWBinOp<check_____oror____>(LT, RT, LR, RR, safe, tempId);
+                    resT = checkEWBinOp<_check_oror>(LT, RT, LR, RR, safe, tempId);
                     break;
                 }
-                }
             }
-            else
-            {
-                // SymbolicRange or GVNValue ops.
-                return;
-            }
-        }
-
-       e.getDecorator().safe = safe;
-        e.getDecorator().res = Result(resT, tempId);
-        setResult(e.getDecorator().res);
-
-       OperAnalyzer opAn;
-       opAn.analyze(*this, e);
-    }
-
-    void AnalysisVisitor::visit(ast::NotExp & e)
-    {
-        logger.log(L"NotExp", e.getLocation());
-        e.getExp().accept(*this);
-        Result & LR = getResult();
-        TIType & LT = LR.getType();
-       const int tempId = LR.getTempId();
-        if (LT.isknown())
-        {
-            TIType resT = check_____not____(getGVN(), LT);
-            e.getDecorator().res = Result(resT, tempId);
-           e.getDecorator().safe = true;
         }
         else
         {
-            e.getDecorator().res = Result(TIType(getGVN()), tempId);
+            // SymbolicRange or GVNValue ops.
+            return;
         }
-        setResult(e.getDecorator().res);
     }
 
-    void AnalysisVisitor::visit(ast::TransposeExp & e)
+    e.getDecorator().safe = safe;
+    e.getDecorator().res = Result(resT, tempId);
+    setResult(e.getDecorator().res);
+
+    OperAnalyzer opAn;
+    opAn.analyze(*this, e);
+}
+
+void AnalysisVisitor::visit(ast::NotExp & e)
+{
+    logger.log(L"NotExp", e.getLocation());
+    e.getExp().accept(*this);
+    Result & LR = getResult();
+    TIType & LT = LR.getType();
+    const int tempId = LR.getTempId();
+    if (LT.isknown())
+    {
+        TIType resT = check_____not____(getGVN(), LT);
+        e.getDecorator().res = Result(resT, tempId);
+        e.getDecorator().safe = true;
+    }
+    else
     {
-        logger.log(L"TransposeExp", e.getLocation());
-        e.getExp().accept(*this);
-        Result & res = getResult();
-        const TIType & type = res.getType();
-       TIType resType(dm.getGVN(), type.type, type.cols, type.rows);
-       e.getDecorator().res = Result(resType, dm.getTmpId(resType, false));
-       e.getDecorator().safe = true;
-       dm.releaseTmp(res.getTempId());
-       
-        setResult(e.getDecorator().res);
+        e.getDecorator().res = Result(TIType(getGVN()), tempId);
     }
+    setResult(e.getDecorator().res);
+}
+
+void AnalysisVisitor::visit(ast::TransposeExp & e)
+{
+    logger.log(L"TransposeExp", e.getLocation());
+    e.getExp().accept(*this);
+    Result & res = getResult();
+    const TIType & type = res.getType();
+    TIType resType(dm.getGVN(), type.type, type.cols, type.rows);
+    e.getDecorator().res = Result(resType, dm.getTmpId(resType, false));
+    e.getDecorator().safe = true;
+    dm.releaseTmp(res.getTempId());
+
+    setResult(e.getDecorator().res);
+}
 }