* Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
* Copyright (C) 2014 - Scilab Enterprises - 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
+ * Copyright (C) 2012 - 2016 - Scilab Enterprises
+ *
+ * This file is hereby licensed under the terms of the GNU GPL v2.0,
+ * pursuant to article 5.3.4 of the CeCILL v.2.1.
+ * This file was originally licensed under the terms of the CeCILL v2.1,
+ * and continues to be available under such terms.
+ * For more information, see the COPYING file which you should have received
+ * along with this program.
*
*/
//for Visual Leak Detector in debug compilation mode
+//#define DEBUG_VLD
#if defined(DEBUG_VLD) && defined(_DEBUG)
#include <vld.h>
#endif
#include <string>
-#include "runvisitor.hxx"
#include "execvisitor.hxx"
#include "stepvisitor.hxx"
#include "timedvisitor.hxx"
#include "shortcutvisitor.hxx"
#include "printvisitor.hxx"
-#include "mutevisitor.hxx"
//#include "AnalysisVisitor.hxx"
+#include "debuggervisitor.hxx"
+#include "debugmanager.hxx"
#include "visitor_common.hxx"
#include "macrofile.hxx"
#include "macro.hxx"
+#include "cell.hxx"
+#include "listinsert.hxx"
#include "filemanager_interface.h"
#include "runner.hxx"
#include "threadmanagement.hxx"
+#include "coverage_instance.hxx"
+
extern "C"
{
#include "sciprint.h"
#include "os_string.h"
#include "elem_common.h"
+#include "storeCommand.h"
+#include "prompt.h"
+#include "scilabRead.h"
}
namespace ast
{
template <class T>
-void RunVisitorT<T>::visitprivate(const CellExp &e)
+void RunVisitorT<T>::visitprivate(const StringExp & e)
+{
+ CoverageInstance::invokeAndStartChrono((void*)&e);
+ if (e.getConstant() == nullptr)
+ {
+ types::String *psz = new types::String(e.getValue().c_str());
+ (const_cast<StringExp *>(&e))->setConstant(psz);
+ }
+ setResult(e.getConstant());
+ CoverageInstance::stopChrono((void*)&e);
+}
+
+template <class T>
+void RunVisitorT<T>::visitprivate(const DoubleExp & e)
+{
+ CoverageInstance::invokeAndStartChrono((void*)&e);
+ if (e.getConstant() == nullptr)
+ {
+ types::Double *pdbl = new types::Double(e.getValue());
+ (const_cast<DoubleExp *>(&e))->setConstant(pdbl);
+ }
+ setResult(e.getConstant());
+ CoverageInstance::stopChrono((void*)&e);
+}
+
+template <class T>
+void RunVisitorT<T>::visitprivate(const BoolExp & e)
+{
+ CoverageInstance::invokeAndStartChrono((void*)&e);
+ if (e.getConstant() == nullptr)
+ {
+ types::Bool *pB = new types::Bool(e.getValue());
+ (const_cast<BoolExp *>(&e))->setConstant(pB);
+ }
+ setResult(e.getConstant());
+ CoverageInstance::stopChrono((void*)&e);
+}
+
+template <class T>
+void RunVisitorT<T>::visitprivate(const NilExp & e)
+{
+ CoverageInstance::invokeAndStartChrono((void*)&e);
+ setResult(new types::Void());
+ CoverageInstance::stopChrono((void*)&e);
+}
+
+template <class T>
+void RunVisitorT<T>::visitprivate(const SimpleVar & e)
+{
+ CoverageInstance::invokeAndStartChrono((void*)&e);
+ symbol::Context* ctx = symbol::Context::getInstance();
+ symbol::Variable* var = ((SimpleVar&)e).getStack();
+ types::InternalType *pI = ctx->get(var);
+ setResult(pI);
+ if (pI != nullptr)
+ {
+ if (e.isVerbose() && pI->isCallable() == false && ConfigVariable::isPrintOutput())
+ {
+ std::wostringstream ostr;
+ ostr << L" " << e.getSymbol().getName() << L" = ";
+#ifndef NDEBUG
+ ostr << L"(" << pI->getRef() << L")";
+#endif
+ ostr << std::endl;
+ if (ConfigVariable::isPrintCompact() == false)
+ {
+ ostr << std::endl;
+ }
+ scilabWriteW(ostr.str().c_str());
+ std::wostringstream ostrName;
+ ostrName << e.getSymbol().getName();
+ VariableToString(pI, ostrName.str().c_str());
+ }
+
+ //check if var is recalled in current scope like
+ //function f()
+ // a; //<=> a=a;
+ // a(2) = 18;
+ //endfunction
+ if (e.getParent()->isSeqExp())
+ {
+ if (ctx->getScopeLevel() > 1 && var->empty() == false && var->top()->m_iLevel != ctx->getScopeLevel())
+ {
+ //put var in current scope
+ ctx->put(var, pI);
+ }
+ }
+ }
+ else
+ {
+ char pstError[bsiz];
+ wchar_t* pwstError;
+
+ char* strErr = wide_string_to_UTF8(e.getSymbol().getName().c_str());
+
+ os_sprintf(pstError, _("Undefined variable: %s\n"), strErr);
+ pwstError = to_wide_string(pstError);
+ FREE(strErr);
+ std::wstring wstError(pwstError);
+ FREE(pwstError);
+ CoverageInstance::stopChrono((void*)&e);
+ throw InternalError(wstError, 999, e.getLocation());
+ //Err, SimpleVar doesn't exist in Scilab scopes.
+ }
+ CoverageInstance::stopChrono((void*)&e);
+}
+
+template <class T>
+void RunVisitorT<T>::visitprivate(const ColonVar & e)
+{
+ CoverageInstance::invokeAndStartChrono((void*)&e);
+ types::Colon *pC = new types::Colon();
+ setResult(pC);
+ CoverageInstance::stopChrono((void*)&e);
+}
+
+template <class T>
+void RunVisitorT<T>::visitprivate(const DollarVar & e)
{
+ CoverageInstance::invokeAndStartChrono((void*)&e);
+ setResult(types::Polynom::Dollar());
+ CoverageInstance::stopChrono((void*)&e);
+}
+
+template <class T>
+void RunVisitorT<T>::visitprivate(const BreakExp & e)
+{
+ CoverageInstance::invokeAndStartChrono((void*)&e);
+ const_cast<BreakExp*>(&e)->setBreak();
+ CoverageInstance::stopChrono((void*)&e);
+}
+
+template <class T>
+void RunVisitorT<T>::visitprivate(const ContinueExp &e)
+{
+ CoverageInstance::invokeAndStartChrono((void*)&e);
+ const_cast<ContinueExp*>(&e)->setContinue();
+ CoverageInstance::stopChrono((void*)&e);
+}
+
+template <class T>
+void RunVisitorT<T>::visitprivate(const ArrayListExp & e)
+{
+ CoverageInstance::invokeAndStartChrono((void*)&e);
+ exps_t::const_iterator it;
+ int iNbExpSize = this->getExpectedSize();
+ this->setExpectedSize(1);
+
+ types::typed_list lstIT;
+ for (it = e.getExps().begin(); it != e.getExps().end(); it++)
+ {
+ (*it)->accept(*this);
+ for (int j = 0; j < getResultSize(); j++)
+ {
+ lstIT.push_back(getResult(j));
+ }
+ }
+
+ setResult(lstIT);
+
+ this->setExpectedSize(iNbExpSize);
+ CoverageInstance::stopChrono((void*)&e);
+}
+
+template <class T>
+void RunVisitorT<T>::visitprivate(const VarDec & e)
+{
+ CoverageInstance::invokeAndStartChrono((void*)&e);
+ try
+ {
+ /*getting what to assign*/
+ e.getInit().accept(*this);
+ getResult()->IncreaseRef();
+ }
+ catch (const InternalError& error)
+ {
+ CoverageInstance::stopChrono((void*)&e);
+ throw error;
+ }
+ CoverageInstance::stopChrono((void*)&e);
+}
+
+template <class T>
+void RunVisitorT<T>::visitprivate(const CellExp & e)
+{
+ CoverageInstance::invokeAndStartChrono((void*)&e);
+
exps_t::const_iterator row;
exps_t::const_iterator col;
int iColMax = 0;
exps_t lines = e.getLines();
//check dimmension
- for (row = lines.begin() ; row != lines.end() ; ++row )
+ for (row = lines.begin(); row != lines.end(); ++row)
{
exps_t cols = (*row)->getAs<MatrixLineExp>()->getColumns();
if (iColMax == 0)
std::wostringstream os;
os << _W("inconsistent row/column dimensions\n");
//os << ((Location)(*row)->getLocation()).getLocationString() << std::endl;
- throw ScilabError(os.str(), 999, (*row)->getLocation());
+ CoverageInstance::stopChrono((void*)&e);
+ throw InternalError(os.str(), 999, (*row)->getLocation());
}
}
int j = 0;
//insert items in cell
- for (i = 0, row = lines.begin() ; row != lines.end() ; ++row, ++i)
+ for (i = 0, row = lines.begin(); row != lines.end(); ++row, ++i)
{
exps_t cols = (*row)->getAs<MatrixLineExp>()->getColumns();
- for (j = 0, col = cols.begin() ; col != cols.end() ; ++col, ++j)
+ for (j = 0, col = cols.begin(); col != cols.end(); ++col, ++j)
{
- (*col)->accept(*this);
- InternalType *pIT = getResult();
+ try
+ {
+ (*col)->accept(*this);
+ }
+ catch (ScilabException &)
+ {
+ CoverageInstance::stopChrono((void*)&e);
+ throw;
+ }
+ types::InternalType *pIT = getResult();
if (pIT->isImplicitList())
{
- InternalType * _pIT = pIT->getAs<ImplicitList>()->extractFullMatrix();
+ types::InternalType * _pIT = pIT->getAs<types::ImplicitList>()->extractFullMatrix();
pC->set(i, j, _pIT);
_pIT->killMe();
}
//return new cell
setResult(pC);
+
+ CoverageInstance::stopChrono((void*)&e);
}
template <class T>
{
/*
a.b
- */
+ */
+
+ CoverageInstance::invokeAndStartChrono((void*)&e);
if (!e.getTail()->isSimpleVar())
{
wchar_t szError[bsiz];
os_swprintf(szError, bsiz, _W("/!\\ Unmanaged FieldExp.\n").c_str());
- throw ScilabError(szError, 999, e.getLocation());
+ CoverageInstance::stopChrono((void*)&e);
+ throw InternalError(szError, 999, e.getLocation());
}
try
{
e.getHead()->accept(*this);
}
- catch (const ScilabError& error)
+ catch (const InternalError& error)
{
+ CoverageInstance::stopChrono((void*)&e);
throw error;
}
{
wchar_t szError[bsiz];
os_swprintf(szError, bsiz, _W("Attempt to reference field of non-structure array.\n").c_str());
- throw ScilabError(szError, 999, e.getLocation());
+ CoverageInstance::stopChrono((void*)&e);
+ throw InternalError(szError, 999, e.getLocation());
}
// TODO: handle case where getSize() > 1
clearResult();
wchar_t szError[bsiz];
os_swprintf(szError, bsiz, _W("Not yet implemented in Scilab.\n").c_str());
- throw ScilabError(szError, 999, e.getLocation());
+ CoverageInstance::stopChrono((void*)&e);
+ throw InternalError(szError, 999, e.getLocation());
}
SimpleVar * psvRightMember = static_cast<SimpleVar *>(const_cast<Exp *>(e.getTail()));
std::wstring wstField = psvRightMember->getSymbol().getName();
- InternalType * pValue = getResult();
- InternalType * pReturn = NULL;
+ types::InternalType * pValue = getResult();
+ types::InternalType * pReturn = NULL;
bool ok = false;
try
{
if (pValue->isGenericType() || pValue->isUserType())
{
- ok = pValue->getAs<GenericType>()->extract(wstField, pReturn);
+ ok = pValue->getAs<types::GenericType>()->extract(wstField, pReturn);
}
}
catch (std::wstring & err)
{
- pValue->killMe();
- throw ScilabError(err.c_str(), 999, e.getTail()->getLocation());
+ CoverageInstance::stopChrono((void*)&e);
+ throw InternalError(err.c_str(), 999, e.getTail()->getLocation());
}
if (ok)
{
std::wostringstream os;
os << _W("Invalid index.\n");
- throw ScilabError(os.str(), 999, e.getLocation());
+ CoverageInstance::stopChrono((void*)&e);
+ throw InternalError(os.str(), 999, e.getLocation());
}
setResult(pReturn);
types::typed_list in;
types::typed_list out;
- String* pS = new String(wstField.c_str());
+ types::String* pS = new types::String(wstField.c_str());
//TODO: in the case where overload is a macro there is no need to incref in
// because args will be put in context, removed and killed if required.
in.push_back(pS);
in.push_back(pValue);
- Callable::ReturnValue Ret = Callable::Error;
+ types::Callable::ReturnValue Ret = types::Callable::Error;
std::wstring stType = pValue->getShortTypeStr();
try
{
- Ret = Overload::call(L"%" + stType + L"_e", in, 1, out, this);
+ Ret = Overload::call(L"%" + stType + L"_e", in, 1, out, true);
}
- catch (ast::ScilabError & se)
+ catch (const InternalError& ie)
{
try
{
//tlist/mlist name are truncated to 8 first character
if (stType.size() > 8)
{
- Ret = Overload::call(L"%" + stType.substr(0, 8) + L"_e", in, 1, out, this);
+ Ret = Overload::call(L"%" + stType.substr(0, 8) + L"_e", in, 1, out, true);
}
else
{
- throw se;
+ CoverageInstance::stopChrono((void*)&e);
+ throw ie;
}
}
- catch (ast::ScilabError & se)
+ catch (const InternalError& ie)
{
// TList or Mlist
if (pValue->isList())
{
- Ret = Overload::call(L"%l_e", in, 1, out, this);
+ Ret = Overload::call(L"%l_e", in, 1, out, true);
}
else
{
- throw se;
+ CoverageInstance::stopChrono((void*)&e);
+ throw ie;
}
}
}
- if (Ret != Callable::OK)
+ if (Ret != types::Callable::OK)
{
cleanInOut(in, out);
setResult(NULL);
- throw ScilabError(ConfigVariable::getLastErrorMessage(), ConfigVariable::getLastErrorNumber(), e.getLocation());
+ CoverageInstance::stopChrono((void*)&e);
+ throw InternalError(ConfigVariable::getLastErrorMessage(), ConfigVariable::getLastErrorNumber(), e.getLocation());
}
setResult(out);
pValue->killMe();
wchar_t szError[bsiz];
os_swprintf(szError, bsiz, _W("Attempt to reference field of non-structure array.\n").c_str());
- throw ScilabError(szError, 999, e.getLocation());
+ CoverageInstance::stopChrono((void*)&e);
+ throw InternalError(szError, 999, e.getLocation());
}
+
+ CoverageInstance::stopChrono((void*)&e);
}
template <class T>
void RunVisitorT<T>::visitprivate(const IfExp &e)
{
+ CoverageInstance::invokeAndStartChrono((void*)&e);
+
//Create local exec visitor
ShortCutVisitor SCTest;
bool bTestStatus = false;
//condition
- e.getTest().accept(SCTest);
- e.getTest().accept(*this);
+ try
+ {
+ e.getTest().accept(SCTest);
+ e.getTest().accept(*this);
+ }
+ catch (ScilabException &)
+ {
+ CoverageInstance::stopChrono((void*)&e);
+ throw;
+ }
bTestStatus = getResult()->isTrue();
clearResult();
- if (bTestStatus == true)
+ try
{
- e.getThen().accept(*this);
+ if (bTestStatus == true)
+ {
+ e.getThen().accept(*this);
+ }
+ else if (e.hasElse())
+ {
+ e.getElse().accept(*this);
+ }
}
- else if (e.hasElse())
+ catch (ScilabException &)
{
- e.getElse().accept(*this);
+ CoverageInstance::stopChrono((void*)&e);
+ throw;
}
- if (e.isBreakable()
- && ( (&e.getElse())->isBreak()
- || (&e.getThen())->isBreak() ))
+ bool elseIsBreak = e.hasElse() && (&e.getElse())->isBreak();
+ if (e.isBreakable() && (elseIsBreak || (&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() ))
+ bool elseIsContinue = e.hasElse() && (&e.getElse())->isContinue();
+ if (e.isContinuable() && (elseIsContinue || (&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() ))
+ bool elseIsReturn = e.hasElse() && (&e.getElse())->isReturn();
+ if (e.isReturnable() && (elseIsReturn || (&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);
}
template <class T>
void RunVisitorT<T>::visitprivate(const WhileExp &e)
{
+ CoverageInstance::invokeAndStartChrono((void*)&e);
//Create local exec visitor
ShortCutVisitor SCTest;
- //manage & and | like && and ||
- e.getTest().accept(SCTest);
- //condition
- e.getTest().accept(*this);
+ try
+ {
+ //manage & and | like && and ||
+ e.getTest().accept(SCTest);
+ //condition
+ e.getTest().accept(*this);
+ }
+ catch (ScilabException &)
+ {
+ CoverageInstance::stopChrono((void*)&e);
+ throw;
+ }
- InternalType* pIT = getResult();
+ types::InternalType* pIT = getResult();
while (pIT->isTrue())
{
pIT->killMe();
- e.getBody().accept(*this);
+ setResult(NULL);
+
+ try
+ {
+ e.getBody().accept(*this);
+ }
+ catch (ScilabException &)
+ {
+ CoverageInstance::stopChrono((void*)&e);
+ throw;
+ }
//clear old result value before evaluate new one
if (getResult() != NULL)
const_cast<Exp*>(&(e.getBody()))->resetContinue();
}
- e.getTest().accept(*this);
+ try
+ {
+ e.getTest().accept(*this);
+ }
+ catch (ScilabException &)
+ {
+ CoverageInstance::stopChrono((void*)&e);
+ throw;
+ }
pIT = getResult();
}
//pIT->killMe();
//clear result of condition or result of body
clearResult();
+ CoverageInstance::stopChrono((void*)&e);
}
template <class T>
void RunVisitorT<T>::visitprivate(const ForExp &e)
{
+ CoverageInstance::invokeAndStartChrono((void*)&e);
symbol::Context* ctx = symbol::Context::getInstance();
//vardec visit increase its result reference
- e.getVardec().accept(*this);
- InternalType* pIT = getResult();
+ try
+ {
+ e.getVardec().accept(*this);
+ }
+ catch (ScilabException &)
+ {
+ CoverageInstance::stopChrono((void*)&e);
+ throw;
+ }
+ types::InternalType* pIT = getResult();
if (pIT->isImplicitList())
{
//get IL
- ImplicitList* pVar = pIT->getAs<ImplicitList>();
+ types::ImplicitList* pVar = pIT->getAs<types::ImplicitList>();
//get IL initial Type
- InternalType * pIL = pVar->getInitalType();
+ types::InternalType * pIL = pVar->getInitalType();
//std::cout << "for IL: " << pIL << std::endl;
//std::cout << " for IV: " << pIT << std::endl;
//get index stack
{
std::wostringstream os;
os << _W("Redefining permanent variable.\n");
- throw ast::ScilabError(os.str(), 999, e.getVardec().getLocation());
+ CoverageInstance::stopChrono((void*)&e);
+ throw ast::InternalError(os.str(), 999, e.getVardec().getLocation());
}
ctx->put(var, pIL);
{
std::wostringstream os;
os << _W("Redefining permanent variable.\n");
- throw ast::ScilabError(os.str(), 999, e.getVardec().getLocation());
+ CoverageInstance::stopChrono((void*)&e);
+ throw ast::InternalError(os.str(), 999, e.getVardec().getLocation());
}
ctx->put(var, pIL);
{
e.getBody().accept(*this);
}
- catch (ScilabMessage& sm)
+ catch (const InternalError& ie)
{
//unlock loop index and implicit list
pIL->DecreaseRef();
pIT->killMe();
setResult(NULL);
- throw sm;
+ CoverageInstance::stopChrono((void*)&e);
+ throw ie;
}
if (e.getBody().isBreak())
}
else if (pIT->isList())
{
- List* pL = pIT->getAs<List>();
+ types::List* pL = pIT->getAs<types::List>();
const int size = pL->getSize();
symbol::Variable* var = e.getVardec().getAs<VarDec>()->getStack();
for (int i = 0; i < size; ++i)
{
- InternalType* pNew = pL->get(i);
+ types::InternalType* pNew = pL->get(i);
if (ctx->isprotected(var))
{
std::wostringstream os;
os << _W("Redefining permanent variable.\n");
- throw ast::ScilabError(os.str(), 999, e.getVardec().getLocation());
+ CoverageInstance::stopChrono((void*)&e);
+ throw ast::InternalError(os.str(), 999, e.getVardec().getLocation());
}
ctx->put(var, pNew);
{
e.getBody().accept(*this);
}
- catch (ScilabMessage& sm)
+ catch (const InternalError& ie)
{
//implicit list
pIT->DecreaseRef();
pIT->killMe();
setResult(NULL);
- throw sm;
+ CoverageInstance::stopChrono((void*)&e);
+ throw ie;
}
if (e.getBody().isBreak())
else if (pIT->isGenericType())
{
//Matrix i = [1,3,2,6] or other type
- GenericType* pVar = pIT->getAs<GenericType>();
+ types::GenericType* pVar = pIT->getAs<types::GenericType>();
if (pVar->getDims() > 2)
{
pIT->DecreaseRef();
pIT->killMe();
- throw ScilabError(_W("for expression can only manage 1 or 2 dimensions variables\n"), 999, e.getVardec().getLocation());
+ CoverageInstance::stopChrono((void*)&e);
+ throw InternalError(_W("for expression can only manage 1 or 2 dimensions variables\n"), 999, e.getVardec().getLocation());
}
symbol::Variable* var = e.getVardec().getAs<VarDec>()->getStack();
for (int i = 0; i < pVar->getCols(); i++)
{
- GenericType* pNew = pVar->getColumnValues(i);
+ types::GenericType* pNew = pVar->getColumnValues(i);
if (pNew == NULL)
{
pIT->DecreaseRef();
pIT->killMe();
- throw ScilabError(_W("for expression : Wrong type for loop iterator.\n"), 999, e.getVardec().getLocation());
+ CoverageInstance::stopChrono((void*)&e);
+ throw InternalError(_W("for expression : Wrong type for loop iterator.\n"), 999, e.getVardec().getLocation());
}
if (ctx->isprotected(var))
{
std::wostringstream os;
os << _W("Redefining permanent variable.\n");
- throw ast::ScilabError(os.str(), 999, e.getVardec().getLocation());
+ CoverageInstance::stopChrono((void*)&e);
+ throw InternalError(os.str(), 999, e.getVardec().getLocation());
}
ctx->put(var, pNew);
{
e.getBody().accept(*this);
}
- catch (ScilabMessage& sm)
+ catch (const InternalError& ie)
{
//implicit list
pIT->DecreaseRef();
pIT->killMe();
setResult(NULL);
- throw sm;
+ CoverageInstance::stopChrono((void*)&e);
+ throw ie;
}
if (e.getBody().isBreak())
{
pIT->DecreaseRef();
pIT->killMe();
- throw ScilabError(_W("for expression : Wrong type for loop iterator.\n"), 999, e.getVardec().getLocation());
+ CoverageInstance::stopChrono((void*)&e);
+ throw InternalError(_W("for expression : Wrong type for loop iterator.\n"), 999, e.getVardec().getLocation());
}
pIT->DecreaseRef();
pIT->killMe();
setResult(NULL);
+ CoverageInstance::stopChrono((void*)&e);
}
template <class T>
void RunVisitorT<T>::visitprivate(const ReturnExp &e)
{
+ CoverageInstance::invokeAndStartChrono((void*)&e);
if (e.isGlobal())
{
if (ConfigVariable::getPauseLevel() != 0 && symbol::Context::getInstance()->getScopeLevel() == ConfigVariable::getActivePauseLevel())
{
//return or resume
- ThreadId* pThreadId = ConfigVariable::getLastPausedThread();
- if (pThreadId == NULL)
- {
- //no paused thread, so just go leave
- return;
- }
-
- //force exit without prompt of current thread ( via Aborted status )
- ThreadId* pMe = ConfigVariable::getThread(__GetCurrentThreadKey());
- pMe->setStatus(ThreadId::Aborted);
-
- //resume previous execution thread
- pThreadId->resume();
-
+ ConfigVariable::DecreasePauseLevel();
+ ConfigVariable::macroFirstLine_end();
+ CoverageInstance::stopChrono((void*)&e);
return;
}
else
{
//return(x)
- //in case of CallExp, we can return only one values
+ if (e.getParent() == nullptr || e.getParent()->isAssignExp() == false)
+ {
+ CoverageInstance::stopChrono((void*)&e);
+ throw InternalError(_W("With input arguments, return / resume expects output arguments.\n"), 999, e.getLocation());
+ }
+ //in case of CallExp, we can return only one value
int iSaveExpectedSize = getExpectedSize();
setExpectedSize(1);
- e.getExp().accept(*this);
+ try
+ {
+ e.getExp().accept(*this);
+ }
+ catch (ScilabException &)
+ {
+ CoverageInstance::stopChrono((void*)&e);
+ throw;
+ }
setExpectedSize(iSaveExpectedSize);
const_cast<ReturnExp*>(&e)->setReturn();
}
+
+ CoverageInstance::stopChrono((void*)&e);
}
template <class T>
void RunVisitorT<T>::visitprivate(const IntSelectExp &e)
{
+ CoverageInstance::invokeAndStartChrono((void*)&e);
bool found = false;
//e.getSelect()->accept(*this);
//InternalType* pIT = getResult();
// //the good one
// body->accept(*this);
// }
- // catch (ScilabMessage& sm)
+ // catch (const InternalError& ie)
// {
// pIT->killMe();
- // throw sm;
+ // throw ie;
// }
// if (e.isBreakable() && body->isBreak())
if (!found)
{
- e.getOriginal()->accept(*this);
+ try
+ {
+ e.getOriginal()->accept(*this);
+ }
+ catch (ScilabException &)
+ {
+ CoverageInstance::stopChrono((void*)&e);
+ throw;
+ }
}
+ CoverageInstance::stopChrono((void*)&e);
}
template <class T>
void RunVisitorT<T>::visitprivate(const StringSelectExp &e)
{
- e.getSelect()->accept(*this);
- InternalType* pIT = getResult();
+ CoverageInstance::invokeAndStartChrono((void*)&e);
+ try
+ {
+ e.getSelect()->accept(*this);
+ }
+ catch (ScilabException &)
+ {
+ CoverageInstance::stopChrono((void*)&e);
+ throw;
+ }
+ types::InternalType* pIT = getResult();
setResult(nullptr);
bool found = false;
if (pIT && pIT->isString())
{
- String * pStr = static_cast<String *>(pIT);
+ types::String * pStr = static_cast<types::String *>(pIT);
if (pStr->getSize() == 1)
{
if (wchar_t * s = pStr->get(0))
//the good one
body->accept(*this);
}
- catch (ScilabMessage& sm)
+ catch (const InternalError& ie)
{
pIT->killMe();
- throw sm;
+ CoverageInstance::stopChrono((void*)&e);
+ throw ie;
}
if (e.isBreakable() && body->isBreak())
if (!found)
{
- e.getOriginal()->accept(*this);
+ try
+ {
+ e.getOriginal()->accept(*this);
+ }
+ catch (ScilabException &)
+ {
+ CoverageInstance::stopChrono((void*)&e);
+ throw;
+ }
}
+ CoverageInstance::stopChrono((void*)&e);
}
template <class T>
void RunVisitorT<T>::visitprivate(const SelectExp &e)
{
// FIXME : exec select ... case ... else ... end
- e.getSelect()->accept(*this);
+ CoverageInstance::invokeAndStartChrono((void*)&e);
+ try
+ {
+ e.getSelect()->accept(*this);
+ }
+ catch (ScilabException &)
+ {
+ CoverageInstance::stopChrono((void*)&e);
+ throw;
+ }
+
bool bCase = false;
- InternalType* pIT = getResult();
+ types::InternalType* pIT = getResult();
setResult(NULL);
if (pIT)
{
+ // protect pIT to avoid double free when
+ // the variable in select is override in the case
+ pIT->IncreaseRef();
+
//find good case
exps_t cases = e.getCases();
for (auto exp : cases)
{
- CaseExp* pCase = exp->getAs<CaseExp>();
- pCase->getTest()->accept(*this);
- InternalType *pITCase = getResult();
+ CaseExp * pCase = exp->getAs<CaseExp>();
+ try
+ {
+ pCase->getTest()->accept(*this);
+ }
+ catch (ScilabException &)
+ {
+ CoverageInstance::stopChrono((void*)&e);
+ throw;
+ }
+ types::InternalType *pITCase = getResult();
setResult(NULL);
if (pITCase)
{
//the good one
pCase->getBody()->accept(*this);
}
- catch (ScilabMessage& sm)
+ catch (const InternalError& ie)
{
+ pIT->DecreaseRef();
pIT->killMe();
- throw sm;
+ CoverageInstance::stopChrono((void*)&e);
+ throw ie;
}
if (e.isBreakable() && pCase->getBody()->isBreak())
//default case
e.getDefaultCase()->accept(*this);
}
- catch (ScilabMessage& sm)
+ catch (const InternalError& ie)
{
- pIT->killMe();
- throw sm;
+ if (pIT)
+ {
+ pIT->DecreaseRef();
+ pIT->killMe();
+ }
+ CoverageInstance::stopChrono((void*)&e);
+ throw ie;
}
if (e.isBreakable() && e.getDefaultCase()->isBreak())
clearResult();
- pIT->killMe();
-}
-
-template <class T>
-void RunVisitorT<T>::visitprivate(const SeqExp &e)
-{
- types::ThreadId* pThreadMe = ConfigVariable::getThread(__GetCurrentThreadKey());
-
- for (auto exp : e.getExps())
+ if (pIT)
{
- if (exp->isCommentExp())
- {
- continue;
- }
-
- if (pThreadMe && pThreadMe->getInterrupt())
- {
- ThreadManagement::SendAstPendingSignal();
- pThreadMe->suspend();
- }
-
- try
- {
- //reset default values
- setResult(NULL);
- int iExpectedSize = getExpectedSize();
- setExpectedSize(-1);
- exp->accept(*this);
- setExpectedSize(iExpectedSize);
- InternalType * pIT = getResult();
-
- // In case of exec file, set the file name in the Macro to store where it is defined.
- int iFileID = ConfigVariable::getExecutedFileID();
- if (iFileID && exp->isFunctionDec())
- {
- InternalType* pITMacro = symbol::Context::getInstance()->get(exp->getAs<FunctionDec>()->getSymbol());
- if (pITMacro)
- {
- types::Macro* pMacro = pITMacro->getAs<types::Macro>();
- const wchar_t* filename = getfile_filename(iFileID);
- // scilab.quit is not open with mopen
- // in this case filename is NULL because FileManager have not been filled.
- if (filename)
- {
- pMacro->setFileName(filename);
- }
- }
- }
-
- if (pIT != NULL)
- {
- bool bImplicitCall = false;
- if (pIT->isCallable()) //to manage call without ()
- {
- Callable *pCall = pIT->getAs<Callable>();
- typed_list out;
- typed_list in;
- optional_list opt;
-
- try
- {
- //in this case of calling, we can return only one values
- int iSaveExpectedSize = getExpectedSize();
- setExpectedSize(1);
-
- pCall->invoke(in, opt, getExpectedSize(), out, *this, e);
- setExpectedSize(iSaveExpectedSize);
-
- if (out.size() == 0)
- {
- setResult(NULL);
- }
- else
- {
- setResult(out[0]);
- }
-
- bImplicitCall = true;
- }
- catch (ScilabMessage& sm)
- {
- if (ConfigVariable::getLastErrorFunction() == L"")
- {
- ConfigVariable::setLastErrorFunction(pCall->getName());
- }
-
- throw sm;
- }
- catch (ast::ScilabError & se)
- {
- if (ConfigVariable::getLastErrorFunction() == L"")
- {
- ConfigVariable::setLastErrorFunction(pCall->getName());
- ConfigVariable::setLastErrorLine(e.getLocation().first_line);
- }
-
- throw se;
- }
- }
-
- //don't output Simplevar and empty result
- 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 (exp->isVerbose() && ConfigVariable::isPromptShow())
- {
- //TODO manage multiple returns
- scilabWriteW(L" ans =\n\n");
- std::wostringstream ostrName;
- ostrName << L"ans";
- VariableToString(pITAns, ostrName.str().c_str());
- }
- }
-
- pIT->killMe();
- }
-
- if ((&e)->isBreakable() && exp->isBreak())
- {
- const_cast<SeqExp *>(&e)->setBreak();
- exp->resetBreak();
- break;
- }
-
- if ((&e)->isContinuable() && exp->isContinue())
- {
- const_cast<SeqExp *>(&e)->setContinue();
- exp->resetContinue();
- break;
- }
-
- if ((&e)->isReturnable() && exp->isReturn())
- {
- const_cast<SeqExp *>(&e)->setReturn();
- exp->resetReturn();
- break;
- }
- }
- catch (ScilabMessage& sm)
- {
- ConfigVariable::fillWhereError(sm.GetErrorLocation().first_line);
- throw sm;
- }
- catch (const ScilabError& se)
- {
- // check on error number because error message can be empty.
- if (ConfigVariable::getLastErrorNumber() == 0)
- {
- ConfigVariable::setLastErrorMessage(se.GetErrorMessage());
- ConfigVariable::setLastErrorNumber(se.GetErrorNumber());
- ConfigVariable::setLastErrorLine(se.GetErrorLocation().first_line);
- ConfigVariable::setLastErrorFunction(wstring(L""));
- }
-
- ConfigVariable::fillWhereError(se.GetErrorLocation().first_line);
- throw ScilabMessage(se.GetErrorMessage(), se.GetErrorNumber(), se.GetErrorLocation());
- }
-
- // If something other than NULL is given to setResult, then that would imply
- // to make a cleanup in visit(ForExp) for example (e.getBody().accept(*this);)
- setResult(NULL);
+ pIT->DecreaseRef();
+ pIT->killMe();
}
+ CoverageInstance::stopChrono((void*)&e);
}
template <class T>
void RunVisitorT<T>::visitprivate(const NotExp &e)
{
+ CoverageInstance::invokeAndStartChrono((void*)&e);
/*
@ or ~ !
- */
- e.getExp().accept(*this);
+ */
+ try
+ {
+ e.getExp().accept(*this);
+ }
+ catch (ScilabException &)
+ {
+ CoverageInstance::stopChrono((void*)&e);
+ throw;
+ }
- InternalType * pValue = getResult();
- InternalType * pReturn = NULL;
+ types::InternalType * pValue = getResult();
+ types::InternalType * pReturn = NULL;
if (pValue->neg(pReturn))
{
if (pValue != pReturn)
pValue->IncreaseRef();
in.push_back(pValue);
- Callable::ReturnValue Ret = Overload::call(L"%" + pValue->getShortTypeStr() + L"_5", in, 1, out, this);
+ types::Callable::ReturnValue Ret = Overload::call(L"%" + pValue->getShortTypeStr() + L"_5", in, 1, out, true);
- if (Ret != Callable::OK)
+ if (Ret != types::Callable::OK)
{
cleanInOut(in, out);
- throw ScilabError(ConfigVariable::getLastErrorMessage(), ConfigVariable::getLastErrorNumber(), e.getLocation());
+ CoverageInstance::stopChrono((void*)&e);
+ throw InternalError(ConfigVariable::getLastErrorMessage(), ConfigVariable::getLastErrorNumber(), e.getLocation());
}
setResult(out);
cleanIn(in, out);
}
+ CoverageInstance::stopChrono((void*)&e);
}
template <class T>
void RunVisitorT<T>::visitprivate(const TransposeExp &e)
{
- e.getExp().accept(*this);
+ CoverageInstance::invokeAndStartChrono((void*)&e);
+ try
+ {
+ e.getExp().accept(*this);
+ }
+ catch (ScilabException &)
+ {
+ CoverageInstance::stopChrono((void*)&e);
+ throw;
+ }
if (getResultSize() != 1)
{
clearResult();
wchar_t szError[bsiz];
os_swprintf(szError, bsiz, _W("%ls: Can not transpose multiple elements.\n").c_str(), L"Transpose");
- throw ScilabError(szError, 999, e.getLocation());
+ CoverageInstance::stopChrono((void*)&e);
+ throw InternalError(szError, 999, e.getLocation());
}
- InternalType * pValue = getResult();
- InternalType * pReturn = NULL;
+ types::InternalType * pValue = getResult();
+ types::InternalType * pReturn = NULL;
const bool bConjug = e.getConjugate() == TransposeExp::_Conjugate_;
if ((bConjug && pValue->adjoint(pReturn)) || (!bConjug && pValue->transpose(pReturn)))
}
setResult(pReturn);
+ CoverageInstance::stopChrono((void*)&e);
return;
}
pValue->IncreaseRef();
in.push_back(pValue);
- Callable::ReturnValue Ret;
+ types::Callable::ReturnValue Ret;
if (bConjug)
{
- Ret = Overload::call(L"%" + getResult()->getShortTypeStr() + L"_t", in, 1, out, this);
+ Ret = Overload::call(L"%" + getResult()->getShortTypeStr() + L"_t", in, 1, out, true);
}
else
{
- Ret = Overload::call(L"%" + getResult()->getShortTypeStr() + L"_0", in, 1, out, this);
+ Ret = Overload::call(L"%" + getResult()->getShortTypeStr() + L"_0", in, 1, out, true);
}
- if (Ret != Callable::OK)
+ if (Ret != types::Callable::OK)
{
cleanInOut(in, out);
- throw ScilabError(ConfigVariable::getLastErrorMessage(), ConfigVariable::getLastErrorNumber(), e.getLocation());
+ CoverageInstance::stopChrono((void*)&e);
+ throw InternalError(ConfigVariable::getLastErrorMessage(), ConfigVariable::getLastErrorNumber(), e.getLocation());
}
setResult(out);
cleanIn(in, out);
}
+
+ CoverageInstance::stopChrono((void*)&e);
}
template <class T>
void RunVisitorT<T>::visitprivate(const FunctionDec & e)
{
+ CoverageInstance::invokeAndStartChrono((void*)&e);
symbol::Context* ctx = symbol::Context::getInstance();
/*
function foo
endfunction
- */
+ */
// funcprot(0) : do nothing
// funcprot(1) && warning(on) : warning
types::Macro *pMacro = new types::Macro(e.getSymbol().getName(), *pVarList, *pRetList,
const_cast<SeqExp&>(static_cast<const SeqExp&>(e.getBody())), L"script");
pMacro->setLines(e.getLocation().first_line, e.getLocation().last_line);
-
- bool bEquals = false;
- int iFuncProt = ConfigVariable::getFuncprot();
- if (iFuncProt != 0)
+ if (e.getMacro())
{
- types::InternalType* pITFunc = ctx->get(((FunctionDec&)e).getStack());
- if (pITFunc && pITFunc->isCallable())
- {
- if (pITFunc->isMacroFile())
- {
- types::MacroFile* pMF = pITFunc->getAs<types::MacroFile>();
- bEquals = *pMF->getMacro() == *pMacro;
- }
- else if (pITFunc->isMacro())
- {
- types::Macro* pM = pITFunc->getAs<types::Macro>();
- bEquals = *pM == *pMacro;
- }
- }
- else
- {
- bEquals = true; //avoid msg but keep assignation
- }
+ pMacro->setFileName(e.getMacro()->getFileName());
}
- if (bEquals == false && iFuncProt == 1 && ConfigVariable::getWarningMode())
+ if (ctx->isprotected(symbol::Symbol(pMacro->getName())))
{
- wchar_t pwstFuncName[1024];
- os_swprintf(pwstFuncName, 1024, L"%-24ls", e.getSymbol().getName().c_str());
- char* pstFuncName = wide_string_to_UTF8(pwstFuncName);
-
-
- sciprint(_("Warning : redefining function: %s. Use funcprot(0) to avoid this message"), pstFuncName);
- sciprint("\n");
- FREE(pstFuncName);
+ delete pMacro;
+ std::wostringstream os;
+ os << _W("Redefining permanent variable.\n");
+ CoverageInstance::stopChrono((void*)&e);
+ throw InternalError(os.str(), 999, e.getLocation());
}
- else if (bEquals == false && iFuncProt == 2)
+
+ if (ctx->addMacro(pMacro) == false)
{
char pstError[1024];
char* pstFuncName = wide_string_to_UTF8(e.getSymbol().getName().c_str());
std::wstring wstError(pwstError);
FREE(pstFuncName);
FREE(pwstError);
- delete pMacro;
- throw ScilabError(wstError, 999, e.getLocation());
+ pMacro->killMe();
+ CoverageInstance::stopChrono((void*)&e);
+ throw InternalError(wstError, 999, e.getLocation());
}
-
- if (ctx->isprotected(symbol::Symbol(pMacro->getName())))
- {
- delete pMacro;
- std::wostringstream os;
- os << _W("Redefining permanent variable.\n");
- throw ScilabError(os.str(), 999, e.getLocation());
- }
-
- ctx->addMacro(pMacro);
-
+ CoverageInstance::stopChrono((void*)&e);
}
template <class T>
void RunVisitorT<T>::visitprivate(const ListExp &e)
{
- e.getStart().accept(*this);
- GenericType* pITStart = static_cast<GenericType*>(getResult());
- if ((pITStart->getSize() != 1 || (pITStart->isDouble() && pITStart->getAs<Double>()->isComplex())) &&
- pITStart->isList() == false) // list case => call overload
+ CoverageInstance::invokeAndStartChrono((void*)&e);
+ try
{
- pITStart->killMe();
+ e.getStart().accept(*this);
+ }
+ catch (ScilabException &)
+ {
+ CoverageInstance::stopChrono((void*)&e);
+ throw;
+ }
+
+ types::InternalType* pITStart = getResult();
+ types::GenericType* pStart = static_cast<types::GenericType*>(pITStart);
+ if (pITStart == NULL ||
+ ((pITStart->isGenericType() == false || pStart->getSize() != 1 || (pStart->isDouble() && pStart->getAs<types::Double>()->isComplex())) &&
+ pStart->isList() == false)) // list case => call overload
+ {
+ setResult(NULL);
wchar_t szError[bsiz];
- os_swprintf(szError, bsiz, _W("%ls: Wrong type for argument %d: Real scalar expected.\n").c_str(), L"':'", 1);
- throw ScilabError(szError, 999, e.getLocation());
+ if (pITStart && pITStart->isImplicitList())
+ {
+ os_swprintf(szError, bsiz, _W("%ls: Too many %ls or wrong type for argument %d: Real scalar expected.\n").c_str(), L"':'", L"':'", 1);
+ }
+ else
+ {
+ os_swprintf(szError, bsiz, _W("%ls: Wrong type for argument %d: Real scalar expected.\n").c_str(), L"':'", 1);
+ }
+
+ if (pITStart)
+ {
+ pITStart->killMe();
+ }
+
+ CoverageInstance::stopChrono((void*)&e);
+ throw InternalError(szError, 999, e.getLocation());
+ }
+
+ try
+ {
+ e.getStep().accept(*this);
+ }
+ catch (ScilabException &)
+ {
+ CoverageInstance::stopChrono((void*)&e);
+ throw;
}
- InternalType * piStart = pITStart;
- e.getStep().accept(*this);
- GenericType* pITStep = static_cast<GenericType*>(getResult());
- if ((pITStep->getSize() != 1 || (pITStep->isDouble() && pITStep->getAs<Double>()->isComplex())) &&
- pITStep->isList() == false) // list case => call overload
+ types::InternalType* pITStep = getResult();
+ types::GenericType* pStep = static_cast<types::GenericType*>(pITStep);
+ setResult(NULL);
+ if (pITStep == NULL ||
+ ((pITStep->isGenericType() == false || pStep->getSize() != 1 || (pStep->isDouble() && pStep->getAs<types::Double>()->isComplex())) &&
+ pStep->isList() == false)) // list case => call overload
{
pITStart->killMe();
- pITStep->killMe();
+ if (pITStep)
+ {
+ pITStep->killMe();
+ }
+
+ setResult(NULL);
wchar_t szError[bsiz];
os_swprintf(szError, bsiz, _W("%ls: Wrong type for argument %d: Real scalar expected.\n").c_str(), L"':'", 2);
- throw ScilabError(szError, 999, e.getLocation());
+ CoverageInstance::stopChrono((void*)&e);
+ throw InternalError(szError, 999, e.getLocation());
}
- InternalType* piStep = pITStep;
- e.getEnd().accept(*this);
- GenericType* pITEnd = static_cast<GenericType*>(getResult());
- if ((pITEnd->getSize() != 1 || (pITEnd->isDouble() && pITEnd->getAs<Double>()->isComplex())) &&
- pITEnd->isList() == false) // list case => call overload
+ try
+ {
+ e.getEnd().accept(*this);
+ }
+ catch (ScilabException &)
+ {
+ CoverageInstance::stopChrono((void*)&e);
+ throw;
+ }
+
+ types::InternalType* pITEnd = getResult();
+ types::GenericType* pEnd = static_cast<types::GenericType*>(pITEnd);
+ setResult(NULL);
+ if (pITEnd == NULL ||
+ ((pITEnd->isGenericType() == false || pEnd->getSize() != 1 || (pEnd->isDouble() && pEnd->getAs<types::Double>()->isComplex())) &&
+ pEnd->isList() == false)) // list case => call overload
{
pITStart->killMe();
pITStep->killMe();
- pITEnd->killMe();
+ if (pITEnd)
+ {
+ pITEnd->killMe();
+ }
+
+ setResult(NULL);
wchar_t szError[bsiz];
- os_swprintf(szError, bsiz, _W("%ls: Wrong type for argument %d: Real scalar expected.\n").c_str(), L"':'", 3);
- throw ScilabError(szError, 999, e.getLocation());
+ os_swprintf(szError, bsiz, _W("%ls: Wrong type for argument %d: Real scalar expected.\n").c_str(), L"':'", 2 + e.hasExplicitStep());
+ CoverageInstance::stopChrono((void*)&e);
+ throw InternalError(szError, 999, e.getLocation());
}
- InternalType* piEnd = pITEnd;
////check if implicitlist is 1:$ to replace by ':'
//if (piStart->isDouble() && piStep->isDouble() && piEnd->isPoly())
//check compatibility
// double : double : double or poly : poly : poly and mix like double : double : poly
- if ((piStart->isPoly() || piStart->isDouble()) &&
- (piStep->isPoly() || piStep->isDouble()) &&
- (piEnd->isPoly() || piEnd->isDouble()))
+ if ((pStart->isPoly() || pStart->isDouble()) &&
+ (pStep->isPoly() || pStep->isDouble()) &&
+ (pEnd->isPoly() || pEnd->isDouble()))
{
// No need to kill piStart, ... because Implicit list ctor will incref them
- setResult(new ImplicitList(piStart, piStep, piEnd));
+ setResult(new types::ImplicitList(pStart, pStep, pEnd));
+ CoverageInstance::stopChrono((void*)&e);
return;
}
// int : double or int : int
- if ( piStart->isInt() &&
- (piStep->isDouble() || piStep->isInt()) &&
- piEnd->isInt())
+ if (pStart->isInt() &&
+ (pStep->isDouble() || pStep->isInt()) &&
+ pEnd->isInt())
{
// check for same int type int8, int 16 ...
- if (piStart->getType() == piEnd->getType() &&
- (piStart->getType() == piStep->getType() ||
- piStep->isDouble()))
+ if (pStart->getType() == pEnd->getType() &&
+ (pStart->getType() == pStep->getType() ||
+ pStep->isDouble()))
{
// No need to kill piStart, ... because Implicit list ctor will incref them
- setResult(new ImplicitList(piStart, piStep, piEnd));
+ setResult(new types::ImplicitList(pStart, pStep, pEnd));
+ CoverageInstance::stopChrono((void*)&e);
return;
}
}
// Call Overload
- Callable::ReturnValue Ret;
+ types::Callable::ReturnValue Ret;
types::typed_list in;
types::typed_list out;
- piStart->IncreaseRef();
- in.push_back(piStart);
+ pStart->IncreaseRef();
+ in.push_back(pStart);
try
{
{
// 1:2:4
//call overload %typeStart_b_typeStep
- piStep->IncreaseRef();
- in.push_back(piStep);
- piEnd->IncreaseRef();
- in.push_back(piEnd);
- Ret = Overload::call(L"%" + piStart->getShortTypeStr() + L"_b_" + piStep->getShortTypeStr(), in, 1, out, this, true);
+ pStep->IncreaseRef();
+ in.push_back(pStep);
+ pEnd->IncreaseRef();
+ in.push_back(pEnd);
+ Ret = Overload::call(L"%" + pStart->getShortTypeStr() + L"_b_" + pStep->getShortTypeStr(), in, 1, out, true);
}
else
{
// 1:2
//call overload %typeStart_b_typeEnd
- piStep->killMe();
- piEnd->IncreaseRef();
- in.push_back(piEnd);
- Ret = Overload::call(L"%" + piStart->getShortTypeStr() + L"_b_" + piEnd->getShortTypeStr(), in, 1, out, this, true);
+ pStep->killMe();
+ pEnd->IncreaseRef();
+ in.push_back(pEnd);
+ Ret = Overload::call(L"%" + pStart->getShortTypeStr() + L"_b_" + pEnd->getShortTypeStr(), in, 1, out, true);
}
}
- catch (ScilabError& error)
+ catch (const InternalError& error)
{
+ setResult(NULL);
cleanInOut(in, out);
+ CoverageInstance::stopChrono((void*)&e);
throw error;
}
- catch (ast::ScilabMessage msg)
- {
- cleanInOut(in, out);
- throw msg;
- }
- if (Ret != Callable::OK)
+ if (Ret != types::Callable::OK)
{
+ setResult(NULL);
cleanInOut(in, out);
- throw ScilabError(ConfigVariable::getLastErrorMessage(), ConfigVariable::getLastErrorNumber(), e.getLocation());
+ CoverageInstance::stopChrono((void*)&e);
+ throw InternalError(ConfigVariable::getLastErrorMessage(), ConfigVariable::getLastErrorNumber(), e.getLocation());
}
setResult(out);
cleanIn(in, out);
+ CoverageInstance::stopChrono((void*)&e);
}
template <class T>
template <class T>
void RunVisitorT<T>::visitprivate(const MemfillExp &e)
{
- e.getOriginal()->accept(*this);
+ CoverageInstance::invokeAndStartChrono((void*)&e);
+ try
+ {
+ e.getOriginal()->accept(*this);
+ }
+ catch (ScilabException &)
+ {
+ CoverageInstance::stopChrono((void*)&e);
+ throw;
+ }
}
template <class T>
void RunVisitorT<T>::visitprivate(const DAXPYExp &e)
{
- InternalType* pIT = NULL;
- Double* ad = NULL;
+ CoverageInstance::invokeAndStartChrono((void*)&e);
+ types::InternalType* pIT = NULL;
+ types::Double* ad = NULL;
int ar = 0;
int ac = 0;
- Double* xd = NULL;
+ types::Double* xd = NULL;
int xr = 0;
int xc = 0;
- Double* yd = NULL;
+ types::Double* yd = NULL;
int yr = 0;
int yc = 0;
//y must be double
const Exp &ye = e.getY();
- ye.accept(*this);
+ try
+ {
+ ye.accept(*this);
+ }
+ catch (ScilabException &)
+ {
+ CoverageInstance::stopChrono((void*)&e);
+ throw;
+ }
+
pIT = getResult();
if (pIT->isDouble())
{
- yd = pIT->getAs<Double>();
+ yd = pIT->getAs<types::Double>();
if (yd->getDims() == 2 && yd->isComplex() == false)
{
yr = yd->getRows();
else
{
yd->killMe();
- e.getOriginal()->accept(*this);
+ try
+ {
+ e.getOriginal()->accept(*this);
+ }
+ catch (ScilabException &)
+ {
+ CoverageInstance::stopChrono((void*)&e);
+ throw;
+ }
+ CoverageInstance::stopChrono((void*)&e);
return;
}
}
else
{
pIT->killMe();
- e.getOriginal()->accept(*this);
+ try
+ {
+ e.getOriginal()->accept(*this);
+ }
+ catch (ScilabException &)
+ {
+ CoverageInstance::stopChrono((void*)&e);
+ throw;
+ }
+ CoverageInstance::stopChrono((void*)&e);
return;
}
//x
const Exp &xe = e.getX();
- xe.accept(*this);
+ try
+ {
+ xe.accept(*this);
+ }
+ catch (ScilabException &)
+ {
+ CoverageInstance::stopChrono((void*)&e);
+ throw;
+ }
pIT = getResult();
if (pIT->isDouble())
{
- xd = pIT->getAs<Double>();
+ xd = pIT->getAs<types::Double>();
if (xd->isScalar() && xd->isComplex() == false)
{
// x become a
{
yd->killMe();
xd->killMe();
- e.getOriginal()->accept(*this);
+ try
+ {
+ e.getOriginal()->accept(*this);
+ }
+ catch (ScilabException &)
+ {
+ CoverageInstance::stopChrono((void*)&e);
+ throw;
+ }
+ CoverageInstance::stopChrono((void*)&e);
return;
}
}
{
pIT->killMe();
yd->killMe();
- e.getOriginal()->accept(*this);
+ try
+ {
+ e.getOriginal()->accept(*this);
+ }
+ catch (ScilabException &)
+ {
+ CoverageInstance::stopChrono((void*)&e);
+ throw;
+ }
+ CoverageInstance::stopChrono((void*)&e);
return;
}
const Exp &ae = e.getA();
- ae.accept(*this);
+ try
+ {
+ ae.accept(*this);
+ }
+ catch (ScilabException &)
+ {
+ CoverageInstance::stopChrono((void*)&e);
+ throw;
+ }
pIT = getResult();
if (pIT->isDouble())
{
if (ad)
{
- xd = pIT->getAs<Double>();
+ xd = pIT->getAs<types::Double>();
//X is scalar it become A
//now use A as X
if (xd->getDims() == 2 && xd->isComplex() == false)
yd->killMe();
xd->killMe();
ad->killMe();
- e.getOriginal()->accept(*this);
+ try
+ {
+ e.getOriginal()->accept(*this);
+ }
+ catch (ScilabException &)
+ {
+ CoverageInstance::stopChrono((void*)&e);
+ throw;
+ }
+ CoverageInstance::stopChrono((void*)&e);
return;
}
}
else
{
//a is a and it must be scalar
- ad = pIT->getAs<Double>();
+ ad = pIT->getAs<types::Double>();
if (/*ad->isScalar() && */ad->isComplex() == false)
{
ar = ad->getRows(); //1;
yd->killMe();
xd->killMe();
ad->killMe();
- e.getOriginal()->accept(*this);
+ try
+ {
+ e.getOriginal()->accept(*this);
+ }
+ catch (ScilabException &)
+ {
+ CoverageInstance::stopChrono((void*)&e);
+ throw;
+ }
+ throw;
return;
}
}
pIT->killMe();
yd->killMe();
xd->killMe();
- e.getOriginal()->accept(*this);
- return;
- }
-
- if (ad && xd && yd)
- {
- if ( ac == 1 &&
- ar == 1 &&
- xr == yr &&
- xc == yc)
+ try
{
- //go !
- int one = 1;
- int size = xc * xr;
- //Double* od = (Double*)yd->clone();
- C2F(daxpy)(&size, ad->get(), xd->get(), &one, yd->get(), &one);
- //setResult(od);
- //yd->killMe();
- xd->killMe();
- ad->killMe();
- return;
+ e.getOriginal()->accept(*this);
}
- else if (ac == xr && ar == yr && xc == yc)
+ catch (ScilabException &)
{
- char n = 'n';
- double one = 1;
- C2F(dgemm)(&n, &n, &ar, &xc, &ac, &one, ad->get(), &ar, xd->get(), &ac, &one, yd->get(), &ar);
- xd->killMe();
- ad->killMe();
- return;
+ CoverageInstance::stopChrono((void*)&e);
+ throw;
}
+ CoverageInstance::stopChrono((void*)&e);
+ return;
}
- if (yd)
+ // If we get here we are certain that ad, xd & yd have been set
+ if (ac == 1 &&
+ ar == 1 &&
+ xr == yr &&
+ xc == yc)
{
- yd->killMe();
+ //go !
+ int one = 1;
+ int size = xc * xr;
+ //Double* od = (Double*)yd->clone();
+ C2F(daxpy)(&size, ad->get(), xd->get(), &one, yd->get(), &one);
+ //setResult(od);
+ //yd->killMe();
+ xd->killMe();
+ ad->killMe();
+ CoverageInstance::stopChrono((void*)&e);
+ return;
}
-
- if (xd)
+ else if (ac == xr && ar == yr && xc == yc)
{
+ char n = 'n';
+ double one = 1;
+ C2F(dgemm)(&n, &n, &ar, &xc, &ac, &one, ad->get(), &ar, xd->get(), &ac, &one, yd->get(), &ar);
xd->killMe();
+ ad->killMe();
+ CoverageInstance::stopChrono((void*)&e);
+ return;
}
- if (ad)
+ yd->killMe();
+ xd->killMe();
+ ad->killMe();
+
+ try
{
- ad->killMe();
+ e.getOriginal()->accept(*this);
+ }
+ catch (ScilabException &)
+ {
+ CoverageInstance::stopChrono((void*)&e);
+ throw;
}
+ CoverageInstance::stopChrono((void*)&e);
- e.getOriginal()->accept(*this);
return;
}
+template <class T>
+void RunVisitorT<T>::visitprivate(const TryCatchExp &e)
+{
+ CoverageInstance::invokeAndStartChrono((void*)&e);
+ //save current prompt mode
+ bool oldVal = ConfigVariable::isSilentError();
+ int oldMode = ConfigVariable::getPromptMode();
+ //set mode silent for errors
+ ConfigVariable::setSilentError(true);
+
+ symbol::Context* pCtx = symbol::Context::getInstance();
+ try
+ {
+ int scope = pCtx->getScopeLevel();
+ int level = ConfigVariable::getRecursionLevel();
+ try
+ {
+ const_cast<Exp*>(&e.getTry())->setReturnable();
+ e.getTry().accept(*this);
+ //restore previous prompt mode
+ ConfigVariable::setSilentError(oldVal);
+
+ if (e.getTry().isReturn())
+ {
+ const_cast<Exp*>(&e.getTry())->resetReturn();
+ const_cast<TryCatchExp*>(&e)->setReturn();
+ }
+ }
+ catch (const RecursionException& /* re */)
+ {
+ ConfigVariable::setPromptMode(oldMode);
+
+ //close opened scope during try
+ while (pCtx->getScopeLevel() > scope)
+ {
+ pCtx->scope_end();
+ }
+
+ //decrease recursion to init value and close where
+ while (ConfigVariable::getRecursionLevel() > level)
+ {
+ ConfigVariable::where_end();
+ ConfigVariable::decreaseRecursion();
+ }
+
+ //print msg about recursion limit and trigger an error
+ wchar_t sz[1024];
+ os_swprintf(sz, 1024, _W("Recursion limit reached (%d).\n").data(), ConfigVariable::getRecursionLimit());
+ CoverageInstance::stopChrono((void*)&e);
+ throw ast::InternalError(sz);
+ }
+
+ }
+ catch (const InternalError& /* ie */)
+ {
+ //restore previous prompt mode
+ ConfigVariable::setSilentError(oldVal);
+ //to lock lasterror
+ ConfigVariable::setLastErrorCall();
+ // reset call stack filled when error occurred
+ ConfigVariable::resetWhereError();
+ try
+ {
+ const_cast<Exp*>(&e.getCatch())->setReturnable();
+ e.getCatch().accept(*this);
+ if (e.getCatch().isReturn())
+ {
+ const_cast<Exp*>(&e.getCatch())->resetReturn();
+ const_cast<TryCatchExp*>(&e)->setReturn();
+ }
+ }
+ catch (ScilabException &)
+ {
+ CoverageInstance::stopChrono((void*)&e);
+ throw;
+ }
+ }
+ CoverageInstance::stopChrono((void*)&e);
+}
+
+
} /* namespace ast */
+#include "run_SeqExp.hpp"
#include "run_CallExp.hpp"
#include "run_MatrixExp.hpp"
#include "run_OpExp.hpp"
template EXTERN_AST class ast::RunVisitorT<ast::ExecVisitor>;
template EXTERN_AST class ast::RunVisitorT<ast::StepVisitor>;
template EXTERN_AST class ast::RunVisitorT<ast::TimedVisitor>;
+template EXTERN_AST class ast::RunVisitorT<ast::DebuggerVisitor>;