Bug 14386 fixed bis (remove CommentExp for empty else) 19/20619/2
Antoine ELIAS [Wed, 14 Nov 2018 20:54:32 +0000 (21:54 +0100)]
Change-Id: Ibec1f6ab9a031a2e05eb248d770fdb62eee0a998

scilab/modules/ast/includes/ast/deserializervisitor.hxx
scilab/modules/ast/includes/exps/ifexp.hxx
scilab/modules/ast/src/cpp/analysis/VisitIfExp.cpp
scilab/modules/ast/src/cpp/ast/prettyprintvisitor.cpp
scilab/modules/ast/src/cpp/ast/runvisitor.cpp
scilab/modules/ast/src/cpp/ast/treevisitor.cpp
scilab/modules/ast/tests/nonreg_tests/bug_14386.tst
scilab/modules/coverage/src/cpp/CodePrinterVisitor.cpp
scilab/modules/coverage/src/cpp/InstrumentVisitor.cpp

index f87e457..990679d 100644 (file)
@@ -309,7 +309,7 @@ private :
                 Exp* test = get_exp();
                 Exp* _then = get_exp();
                 IfExp* ifexp;
-                if ( hasElse )
+                if (hasElse)
                 {
                     Exp* _else = get_exp();
                     ifexp = new IfExp(loc, *test, *_then->getAs<SeqExp>(), *_else->getAs<SeqExp>());
index 1d7bc55..54c9a26 100644 (file)
@@ -59,8 +59,6 @@ public:
 
         _exps.push_back(&test);
         _exps.push_back(t.getAs<Exp>());
-        _exps.push_back(new ast::CommentExp(location, new std::wstring(L"No else\n")));
-        _exps[2]->setParent(this);
     }
 
     virtual ~IfExp()
@@ -69,9 +67,18 @@ public:
 
     virtual IfExp* clone()
     {
-        IfExp* cloned = new IfExp(getLocation(), *getTest().clone(), *getThen().clone()->getAs<SeqExp>(), *getElse().clone()->getAs<SeqExp>());
-        cloned->setVerbose(isVerbose());
-        return cloned;
+        if (hasElse())
+        {
+            IfExp* cloned = new IfExp(getLocation(), *getTest().clone(), *getThen().clone()->getAs<SeqExp>(), *getElse().clone()->getAs<SeqExp>());
+            cloned->setVerbose(isVerbose());
+            return cloned;
+        }
+        else
+        {
+            IfExp* cloned = new IfExp(getLocation(), *getTest().clone(), *getThen().clone()->getAs<SeqExp>());
+            cloned->setVerbose(isVerbose());
+            return cloned;
+        }
     }
 
     // \brief Visitors entry point.
index ee1ee64..9b8424d 100644 (file)
@@ -38,6 +38,7 @@ void AnalysisVisitor::visit(ast::IfExp & e)
             test.accept(cv.getExec());
             pIT = ce.getConstant();
         }
+
         if (pIT)
         {
             const bool result = pIT->isTrue();
@@ -46,7 +47,7 @@ void AnalysisVisitor::visit(ast::IfExp & e)
                 shortcutExp = &e.getThen();
                 e.getExps()[1] = nullptr;
             }
-            else
+            else if (e.hasElse())
             {
                 shortcutExp = &e.getElse();
                 e.getExps()[2] = nullptr;
@@ -137,16 +138,16 @@ void AnalysisVisitor::visit(ast::IfExp & e)
             TIType & ty = res.getType();
             if ((ty.ismatrix() && ty.isscalar()) || (getCM().check(ConstraintManager::STRICT_POSITIVE, ty.rows.getValue()) || getCM().check(ConstraintManager::STRICT_POSITIVE, ty.cols.getValue())))
             {
-                if (isEq)
-                {
-                    shortcutExp = &e.getElse();
-                    e.getExps()[2] = nullptr;
-                }
-                else
+                if (isEq == false)
                 {
                     shortcutExp = &e.getThen();
                     e.getExps()[1] = nullptr;
                 }
+                else if (e.hasElse())
+                {
+                    shortcutExp = &e.getElse();
+                    e.getExps()[2] = nullptr;
+                }
             }
         }
     }
index 1930eae..0c3f89d 100644 (file)
@@ -493,7 +493,7 @@ void PrettyPrintVisitor::visit(const IfExp & e)
     e.getThen().accept(*this);
     if (e.hasElse())
     {
-        e.getElse ().accept(*this);
+        e.getElse().accept(*this);
     }
     END_NODE();
 }
index eb2f775..78ec8fc 100644 (file)
@@ -513,15 +513,7 @@ void RunVisitorT<T>::visitprivate(const IfExp  &e)
         }
         else if (e.hasElse())
         {
-            const ast::Exp & _else = e.getElse();
-            if (_else.isCommentExp())
-            {
-                CoverageInstance::invoke(_else);
-            }
-            else
-            {
-                e.getElse().accept(*this);
-            }
+            e.getElse().accept(*this);
         }
     }
     catch (ScilabException &)
@@ -531,30 +523,39 @@ void RunVisitorT<T>::visitprivate(const IfExp  &e)
     }
 
     if (e.isBreakable()
-            && ((&e.getElse())->isBreak()
-                || (&e.getThen())->isBreak()))
+        && ((e.hasElse() && (&e.getElse())->isContinue())
+        || (&e.getThen())->isBreak()))
     {
         const_cast<IfExp*>(&e)->setBreak();
-        const_cast<Exp*>(&e.getElse())->resetBreak();
         const_cast<Exp*>(&e.getThen())->resetBreak();
+        if (e.hasElse())
+        {
+            const_cast<Exp*>(&e.getElse())->resetBreak();
+        }
     }
 
     if (e.isContinuable()
-            && ((&e.getElse())->isContinue()
-                || (&e.getThen())->isContinue()))
+        && ((e.hasElse() && (&e.getElse())->isContinue())
+        || (&e.getThen())->isContinue()))
     {
         const_cast<IfExp*>(&e)->setContinue();
-        const_cast<Exp*>(&e.getElse())->resetContinue();
         const_cast<Exp*>(&e.getThen())->resetContinue();
+        if (e.hasElse())
+        {
+            const_cast<Exp*>(&e.getElse())->resetContinue();
+        }
     }
 
     if (e.isReturnable()
-            && ((&e.getElse())->isReturn()
-                || (&e.getThen())->isReturn()))
+        && ((e.hasElse() && (&e.getElse())->isReturn())
+        || (&e.getThen())->isReturn()))
     {
         const_cast<IfExp*>(&e)->setReturn();
-        const_cast<Exp*>(&e.getElse())->resetReturn();
         const_cast<Exp*>(&e.getThen())->resetReturn();
+        if (e.hasElse())
+        {
+            const_cast<Exp*>(&e.getElse())->resetReturn();
+        }
     }
 
     CoverageInstance::stopChrono((void*)&e);
index fc41ae1..189e5d6 100644 (file)
@@ -401,7 +401,7 @@ void TreeVisitor::visit(const LogicalOpExp &e)
 void TreeVisitor::visit(const IfExp  &e)
 {
     types::TList* tl = new types::TList();
-    bool hasElse = e.hasElse() && e.getElse().isCommentExp() == false;
+    bool hasElse = e.hasElse();
     //header
     types::String* s = new types::String(1, 5);
     s->set(0, L"ifthenelse");
index 45a4fd6..8ebc46d 100644 (file)
 
 
 function test()
-    if 2>1
+    if 2 > 1 then
         disp("Bug 14386 fixed")
     end
 endfunction
-[i,o,t] = string(test); t
+[i,o,t] = string(test);
 assert_checkequal(t($-1), "end");
-
index 090df67..676c914 100644 (file)
@@ -468,7 +468,7 @@ void CodePrinterVisitor::visit(const ast::IfExp & e)
     printer.decIndent();
     printer.handleNewLine();
 
-    if (e.hasElse() && !e.getElse().isCommentExp())
+    if (e.hasElse())
     {
         printer.handleStructureKwds(SCI_ELSE);
         printer.incIndent();
index f08618d..9232295 100644 (file)
@@ -48,14 +48,7 @@ void InstrumentVisitor::visit(ast::IfExp & e)
     if (e.hasElse())
     {
         ++branchesCount;
-        if (e.getElse().isCommentExp())
-        {
-            cover.add(macro, &e.getElse());
-        }
-        else
-        {
-            e.getElse().accept(*this);
-        }
+        e.getElse().accept(*this);
     }
 }