Analysis: fix bugs found with Coverity
[scilab.git] / scilab / modules / ast / src / cpp / analysis / OperGVNValues.cpp
index dfd3d94..700438b 100644 (file)
 
 namespace analysis
 {
-    bool AnalysisVisitor::operGVNValues(ast::OpExp & oe)
-    {
-        Result & resL = oe.getLeft().getDecorator().getResult();
-        Result & resR = oe.getRight().getDecorator().getResult();
-        const ConstantValue & valL = resL.getConstant();
-        const ConstantValue & valR = resR.getConstant();
-        GVN::Value * gvnL = nullptr;
-        GVN::Value * gvnR = nullptr;
-       bool LisInt = false;
-       bool RisInt = false;
+bool AnalysisVisitor::operGVNValues(ast::OpExp & oe)
+{
+    Result & resL = oe.getLeft().getDecorator().getResult();
+    Result & resR = oe.getRight().getDecorator().getResult();
+    const ConstantValue & valL = resL.getConstant();
+    const ConstantValue & valR = resR.getConstant();
+    GVN::Value * gvnL = nullptr;
+    GVN::Value * gvnR = nullptr;
+    bool LisInt = false;
+    bool RisInt = false;
 
-        if (valL.getKind() == ConstantValue::GVNVAL)
-        {
-            gvnL = valL.getGVNValue();
-        }
-        else
+    if (valL.getKind() == ConstantValue::GVNVAL)
+    {
+        gvnL = valL.getGVNValue();
+    }
+    else
+    {
+        double val;
+        if (valL.getDblValue(val) && tools::isAnInt(val))
         {
-            double val;
-            if (valL.getDblValue(val) && tools::isAnInt(val))
-            {
-                gvnL = getGVN().getValue(val);
-               LisInt = true;
-            }
+            gvnL = getGVN().getValue(val);
+            LisInt = true;
         }
+    }
 
-        if (valR.getKind() == ConstantValue::GVNVAL)
-        {
-            gvnR = valR.getGVNValue();
-        }
-        else
+    if (valR.getKind() == ConstantValue::GVNVAL)
+    {
+        gvnR = valR.getGVNValue();
+    }
+    else
+    {
+        double val;
+        if (valR.getDblValue(val) && tools::isAnInt(val))
         {
-            double val;
-            if (valR.getDblValue(val) && tools::isAnInt(val))
-            {
-                gvnR = getGVN().getValue(val);
-               RisInt = true;
-            }
+            gvnR = getGVN().getValue(val);
+            RisInt = true;
         }
+    }
 
-        if (gvnL && gvnR)
-        {
-            TIType typ(getGVN(), TIType::DOUBLE, 1, 1);
+    if (gvnL && gvnR)
+    {
+        TIType typ(getGVN(), TIType::DOUBLE, 1, 1);
 
-            switch (oe.getOper())
-            {
+        switch (oe.getOper())
+        {
             case ast::OpExp::plus:
             {
-               if (LisInt)
-               {
-                   resL.getConstant() = gvnL;
-               }
-               if (RisInt)
-               {
-                   resR.getConstant() = gvnR;
-               }
+                if (LisInt)
+                {
+                    resL.getConstant() = gvnL;
+                }
+                if (RisInt)
+                {
+                    resR.getConstant() = gvnR;
+                }
                 Result & res = oe.getDecorator().setResult(typ);
                 res.getConstant() = getGVN().getValue(OpValue::PLUS, *gvnL, *gvnR);
-               oe.getDecorator().safe = true;
+                oe.getDecorator().safe = true;
                 setResult(res);
                 return true;
             }
             case ast::OpExp::minus:
             {
-               if (LisInt)
-               {
-                   resL.getConstant() = gvnL;
-               }
-               if (RisInt)
-               {
-                   resR.getConstant() = gvnR;
-               }
+                if (LisInt)
+                {
+                    resL.getConstant() = gvnL;
+                }
+                if (RisInt)
+                {
+                    resR.getConstant() = gvnR;
+                }
                 Result & res = oe.getDecorator().setResult(typ);
                 res.getConstant() = getGVN().getValue(OpValue::MINUS, *gvnL, *gvnR);
-               oe.getDecorator().safe = true;
-               setResult(res);
+                oe.getDecorator().safe = true;
+                setResult(res);
                 return true;
                 break;
             }
             case ast::OpExp::times:
             {
                 if (LisInt)
-               {
-                   resL.getConstant() = gvnL;
-               }
-               if (RisInt)
-               {
-                   resR.getConstant() = gvnR;
-               }
+                {
+                    resL.getConstant() = gvnL;
+                }
+                if (RisInt)
+                {
+                    resR.getConstant() = gvnR;
+                }
                 Result & res = oe.getDecorator().setResult(typ);
                 res.getConstant() = getGVN().getValue(OpValue::TIMES, *gvnL, *gvnR);
                 oe.getDecorator().safe = true;
-               setResult(res);
+                setResult(res);
                 return true;
             }
             case ast::OpExp::dottimes:
             {
                 if (LisInt)
-               {
-                   resL.getConstant() = gvnL;
-               }
-               if (RisInt)
-               {
-                   resR.getConstant() = gvnR;
-               }
+                {
+                    resL.getConstant() = gvnL;
+                }
+                if (RisInt)
+                {
+                    resR.getConstant() = gvnR;
+                }
                 Result & res = oe.getDecorator().setResult(typ);
                 res.getConstant() = getGVN().getValue(OpValue::DOTTIMES, *gvnL, *gvnR);
                 oe.getDecorator().safe = true;
-               setResult(res);
+                setResult(res);
                 return true;
             }
             case ast::OpExp::power:
@@ -130,23 +130,23 @@ namespace analysis
                 Result & res = oe.getDecorator().setResult(typ);
                 res.getConstant() = getGVN().getValue(OpValue::POWER, *gvnL, *gvnR);
                 oe.getDecorator().safe = true;
-               setResult(res);
+                setResult(res);
                 return true;
             }
             case ast::OpExp::dotpower:
             {
                 if (LisInt)
-               {
-                   resL.getConstant() = gvnL;
-               }
-               if (RisInt)
-               {
-                   resR.getConstant() = gvnR;
-               }
+                {
+                    resL.getConstant() = gvnL;
+                }
+                if (RisInt)
+                {
+                    resR.getConstant() = gvnR;
+                }
                 Result & res = oe.getDecorator().setResult(typ);
                 res.getConstant() = getGVN().getValue(OpValue::DOTPOWER, *gvnL, *gvnR);
                 oe.getDecorator().safe = true;
-               setResult(res);
+                setResult(res);
                 return true;
             }
             case ast::OpExp::rdivide:
@@ -154,42 +154,43 @@ namespace analysis
                 if (gvnL->poly->isDivisibleBy(*gvnR->poly))
                 {
                     if (LisInt)
-                   {
-                       resL.getConstant() = gvnL;
-                   }
-                   if (RisInt)
-                   {
-                       resR.getConstant() = gvnR;
-                   }
-                   Result & res = oe.getDecorator().setResult(typ);
+                    {
+                        resL.getConstant() = gvnL;
+                    }
+                    if (RisInt)
+                    {
+                        resR.getConstant() = gvnR;
+                    }
+                    Result & res = oe.getDecorator().setResult(typ);
                     res.getConstant() = getGVN().getValue(OpValue::RDIV, *gvnL, *gvnR);
                     oe.getDecorator().safe = true;
-                   setResult(res);
+                    setResult(res);
                     return true;
                 }
+                break;
             }
             case ast::OpExp::dotrdivide:
             {
                 if (gvnL->poly->isDivisibleBy(*gvnR->poly))
                 {
                     if (LisInt)
-                   {
-                       resL.getConstant() = gvnL;
-                   }
-                   if (RisInt)
-                   {
-                       resR.getConstant() = gvnR;
-                   }
-                   Result & res = oe.getDecorator().setResult(typ);
+                    {
+                        resL.getConstant() = gvnL;
+                    }
+                    if (RisInt)
+                    {
+                        resR.getConstant() = gvnR;
+                    }
+                    Result & res = oe.getDecorator().setResult(typ);
                     res.getConstant() = getGVN().getValue(OpValue::DOTRDIV, *gvnL, *gvnR);
                     oe.getDecorator().safe = true;
-                   setResult(res);
+                    setResult(res);
                     return true;
                 }
             }
-            }
         }
-
-        return false;
     }
+
+    return false;
+}
 }