2 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 * Copyright (C) 2014 - Scilab Enterprises - Antoine ELIAS
5 * This file must be used under the terms of the CeCILL.
6 * This source file is licensed as described in the file COPYING, which
7 * you should have received as part of this distribution. The terms
8 * are also available at
9 * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
15 #include "runvisitor.hxx"
16 #include "execvisitor.hxx"
17 #include "stepvisitor.hxx"
18 #include "timedvisitor.hxx"
19 #include "shortcutvisitor.hxx"
20 #include "printvisitor.hxx"
21 #include "mutevisitor.hxx"
23 #include "visitor_common.hxx"
25 #include "context.hxx"
26 #include "generic_operations.hxx"
27 #include "types_or.hxx"
28 #include "types_and.hxx"
29 #include "localization.hxx"
31 #include "macrofile.hxx"
37 #include "os_swprintf.h"
43 void RunVisitorT<T>::visitprivate(const CellExp &e)
45 std::list<MatrixLineExp *>::const_iterator row;
46 std::list<Exp *>::const_iterator col;
50 for (row = e.lines_get().begin() ; row != e.lines_get().end() ; ++row )
54 iColMax = static_cast<int>((*row)->columns_get().size());
57 if (iColMax != static_cast<int>((*row)->columns_get().size()))
59 std::wostringstream os;
60 os << _W("inconsistent row/column dimensions\n");
61 //os << ((Location)(*row)->location_get()).location_getString() << std::endl;
62 throw ScilabError(os.str(), 999, (*row)->location_get());
67 types::Cell *pC = new types::Cell(static_cast<int>(e.lines_get().size()), iColMax);
72 //insert items in cell
73 for (i = 0, row = e.lines_get().begin() ; row != e.lines_get().end() ; ++row, ++i)
75 for (j = 0, col = (*row)->columns_get().begin() ; col != (*row)->columns_get().end() ; ++col, ++j)
77 (*col)->accept(*this);
78 InternalType *pIT = result_get();
79 if (pIT->isImplicitList())
81 InternalType * _pIT = pIT->getAs<ImplicitList>()->extractFullMatrix();
98 void RunVisitorT<T>::visitprivate(const FieldExp &e)
104 if (!e.tail_get()->is_simple_var())
106 wchar_t szError[bsiz];
107 os_swprintf(szError, bsiz, _W("/!\\ Unmanaged FieldExp.\n").c_str());
108 throw ScilabError(szError, 999, e.location_get());
113 e.head_get()->accept(*this);
115 catch (const ScilabError& error)
120 if (result_get() == NULL)
122 wchar_t szError[bsiz];
123 os_swprintf(szError, bsiz, _W("Attempt to reference field of non-structure array.\n").c_str());
124 throw ScilabError(szError, 999, e.location_get());
127 // TODO: handle case where getSize() > 1
128 // l=list(struct("toto","coucou"),struct("toto","hello"),1,2);[a,b]=l(1:2).toto
130 if (result_getSize() > 1)
133 wchar_t szError[bsiz];
134 os_swprintf(szError, bsiz, _W("Not yet implemented in Scilab.\n").c_str());
135 throw ScilabError(szError, 999, e.location_get());
138 SimpleVar * psvRightMember = static_cast<SimpleVar *>(const_cast<Exp *>(e.tail_get()));
139 std::wstring wstField = psvRightMember->name_get().name_get();
140 InternalType * pValue = result_get();
141 InternalType * pReturn = NULL;
146 ok = pValue->extract(wstField, pReturn);
148 catch (std::wstring & err)
151 throw ScilabError(err.c_str(), 999, e.tail_get()->location_get());
158 else if (pValue->isFieldExtractionOverloadable())
160 types::typed_list in;
161 types::typed_list out;
163 String* pS = new String(wstField.c_str());
165 //TODO: in the case where overload is a macro there is no need to incref in
166 // because args will be put in context, removed and killed if required.
167 // But if the overload is a function... it is another story...
170 pValue->IncreaseRef();
173 in.push_back(pValue);
175 Callable::ReturnValue Ret = Overload::call(L"%" + pValue->getShortTypeStr() + L"_e", in, 1, out, this);
177 if (Ret != Callable::OK)
179 clean_in_out(in, out);
189 wchar_t szError[bsiz];
190 os_swprintf(szError, bsiz, _W("Attempt to reference field of non-structure array.\n").c_str());
191 throw ScilabError(szError, 999, e.location_get());
196 void RunVisitorT<T>::visitprivate(const IfExp &e)
198 //Create local exec visitor
199 ShortCutVisitor SCTest;
200 bool bTestStatus = false;
203 e.test_get().accept(SCTest);
204 e.test_get().accept(*this);
206 bTestStatus = result_get()->isTrue();
208 if (bTestStatus == true)
211 if (e.is_breakable())
213 const_cast<IfExp*>(&e)->break_reset();
214 const_cast<Exp*>(&e.then_get())->breakable_set();
217 if (e.is_continuable())
219 const_cast<IfExp*>(&e)->continue_reset();
220 const_cast<Exp*>(&e.then_get())->continuable_set();
223 if (e.is_returnable())
225 const_cast<IfExp*>(&e)->return_reset();
226 const_cast<Exp*>(&e.then_get())->returnable_set();
229 e.then_get().accept(*this);
237 if (e.is_breakable())
239 const_cast<Exp*>(&e.else_get())->breakable_set();
242 if (e.is_continuable())
244 const_cast<IfExp*>(&e)->continue_reset();
245 const_cast<Exp*>(&e.else_get())->continuable_set();
248 if (e.is_returnable())
250 const_cast<Exp*>(&e.else_get())->returnable_set();
253 e.else_get().accept(*this);
258 && ( (&e.else_get())->is_break()
259 || (&e.then_get())->is_break() ))
261 const_cast<IfExp*>(&e)->break_set();
262 const_cast<Exp*>(&e.else_get())->break_reset();
263 const_cast<Exp*>(&e.then_get())->break_reset();
266 if (e.is_continuable()
267 && ( (&e.else_get())->is_continue()
268 || (&e.then_get())->is_continue() ))
270 const_cast<IfExp*>(&e)->continue_set();
271 const_cast<Exp*>(&e.else_get())->continue_reset();
272 const_cast<Exp*>(&e.then_get())->continue_reset();
275 if (e.is_returnable()
276 && ( (&e.else_get())->is_return()
277 || (&e.then_get())->is_return() ))
279 const_cast<IfExp*>(&e)->return_set();
280 const_cast<Exp*>(&e.else_get())->return_reset();
281 const_cast<Exp*>(&e.then_get())->return_reset();
286 void RunVisitorT<T>::visitprivate(const WhileExp &e)
288 //allow break and continue operations
289 const_cast<Exp*>(&e.body_get())->breakable_set();
290 const_cast<Exp*>(&e.body_get())->continuable_set();
291 //allow return operation
292 if (e.is_returnable())
294 (&e.body_get())->is_returnable();
298 e.test_get().accept(*this);
299 while (result_get()->isTrue())
301 e.body_get().accept(*this);
302 if (e.body_get().is_break())
304 const_cast<Exp*>(&(e.body_get()))->break_reset();
308 if (e.body_get().is_return())
310 const_cast<WhileExp*>(&e)->return_set();
311 const_cast<Exp*>(&(e.body_get()))->return_reset();
315 if (e.body_get().is_continue())
317 const_cast<WhileExp*>(&e)->continue_set();
318 const_cast<Exp*>(&(e.body_get()))->continue_reset();
319 e.test_get().accept(*this);
323 //clear old result value before evaluate new one
324 if (result_get() != NULL)
326 result_get()->killMe();
329 e.test_get().accept(*this);
332 //clear result of condition or result of body
337 void RunVisitorT<T>::visitprivate(const ForExp &e)
339 e.vardec_get().accept(*this);
340 InternalType* pIT = result_get();
341 //allow break and continue operations
342 const_cast<Exp&>(e.body_get()).breakable_set();
343 const_cast<Exp&>(e.body_get()).continuable_set();
345 //allow return operation
346 if (e.is_returnable())
348 e.body_get().is_returnable();
351 if (result_get()->isImplicitList())
353 ImplicitList* pVar = pIT->getAs<ImplicitList>();
354 for (int i = 0; i < pVar->getSize(); ++i)
356 //TODO : maybe it would be interesting here to reuse the same InternalType (to avoid delete/new)
357 InternalType * pIL = pVar->extractValue(i);
358 symbol::Context::getInstance()->put(e.vardec_get().stack_get(), pIL);
360 e.body_get().accept(*this);
361 if (e.body_get().is_break())
363 const_cast<Exp&>(e.body_get()).break_reset();
367 if (e.body_get().is_continue())
369 const_cast<Exp&>(e.body_get()).continue_reset();
373 if (e.body_get().is_return())
375 const_cast<ForExp&>(e).return_set();
380 else if (result_get()->isList())
382 List* pL = pIT->getAs<List>();
383 const int size = pL->getSize();
384 for (int i = 0; i < size; ++i)
386 InternalType* pNew = pL->get(i);
387 symbol::Context::getInstance()->put(e.vardec_get().stack_get(), pNew);
389 e.body_get().accept(*this);
390 if (e.body_get().is_break())
392 const_cast<Exp*>(&(e.body_get()))->break_reset();
396 if (e.body_get().is_continue())
398 const_cast<Exp*>(&(e.body_get()))->continue_reset();
402 if (e.body_get().is_return())
404 const_cast<ForExp*>(&e)->return_set();
411 //Matrix i = [1,3,2,6] or other type
412 GenericType* pVar = pIT->getAs<GenericType>();
413 if (pVar->getDims() > 2)
418 throw ScilabError(_W("for expression can only manage 1 or 2 dimensions variables\n"), 999, e.vardec_get().location_get());
421 for (int i = 0; i < pVar->getCols(); i++)
423 GenericType* pNew = pVar->getColumnValues(i);
424 symbol::Context::getInstance()->put(e.vardec_get().stack_get(), pNew);
426 e.body_get().accept(*this);
427 if (e.body_get().is_break())
429 const_cast<Exp*>(&(e.body_get()))->break_reset();
433 if (e.body_get().is_continue())
435 const_cast<Exp*>(&(e.body_get()))->continue_reset();
439 if (e.body_get().is_return())
441 const_cast<ForExp*>(&e)->return_set();
454 void RunVisitorT<T>::visitprivate(const ReturnExp &e)
459 if (ConfigVariable::getPauseLevel() != 0)
461 ThreadId* pThreadId = ConfigVariable::getLastPausedThread();
462 if (pThreadId == NULL)
464 //no paused thread, so just go leave
468 //force exit without prompt of current thread ( via Aborted status )
469 ThreadId* pMe = ConfigVariable::getThread(__GetCurrentThreadKey());
470 pMe->setStatus(ThreadId::Aborted);
472 //resume previous execution thread
479 const_cast<ReturnExp*>(&e)->return_set();
486 //in case of CallExp, we can return only one values
487 int iSaveExpectedSize = expected_getSize();
489 e.exp_get().accept(*this);
490 expected_setSize(iSaveExpectedSize);
492 if (result_getSize() == 1)
495 result_get()->IncreaseRef();
499 for (int i = 0 ; i < result_getSize() ; i++)
502 result_get(i)->IncreaseRef();
506 if (result_getSize() == 1)
509 result_get()->DecreaseRef();
513 for (int i = 0 ; i < result_getSize() ; i++)
516 result_get(i)->DecreaseRef();
520 const_cast<ReturnExp*>(&e)->return_set();
525 void RunVisitorT<T>::visitprivate(const SelectExp &e)
527 // FIXME : exec select ... case ... else ... end
528 e.select_get()->accept(*this);
532 InternalType* pIT = result_get();
537 cases_t::iterator it;
538 for (it = e.cases_get()->begin(); it != e.cases_get()->end() ; it++)
540 CaseExp* pCase = *it;
541 pCase->test_get()->accept(*this);
542 InternalType *pITCase = result_get();
546 if (pITCase->isContainer()) //WARNING ONLY FOR CELL
550 else if (*pITCase == *pIT)
552 if (e.is_breakable())
554 const_cast<SelectExp*>(&e)->break_reset();
555 pCase->body_get()->breakable_set();
558 if (e.is_continuable())
560 const_cast<SelectExp*>(&e)->continue_reset();
561 pCase->body_get()->continuable_set();
564 if (e.is_returnable())
566 const_cast<SelectExp*>(&e)->return_reset();
567 pCase->body_get()->returnable_set();
571 pCase->body_get()->accept(*this);
573 if (e.is_breakable() && pCase->body_get()->is_break())
575 const_cast<SelectExp*>(&e)->break_set();
576 pCase->body_get()->break_reset();
579 if (e.is_continuable() && pCase->body_get()->is_continue())
581 const_cast<SelectExp*>(&e)->continue_set();
582 pCase->body_get()->continue_reset();
585 if (e.is_returnable() && pCase->body_get()->is_return())
587 const_cast<SelectExp*>(&e)->return_set();
588 pCase->body_get()->return_reset();
598 if (bCase == false && e.default_case_get() != NULL)
600 if (e.is_breakable())
602 const_cast<SelectExp*>(&e)->break_reset();
603 e.default_case_get()->breakable_set();
606 if (e.is_continuable())
608 const_cast<SelectExp*>(&e)->continue_reset();
609 e.default_case_get()->continuable_set();
612 if (e.is_returnable())
614 const_cast<SelectExp*>(&e)->return_reset();
615 e.default_case_get()->returnable_set();
619 e.default_case_get()->accept(*this);
621 if (e.is_breakable() && e.default_case_get()->is_break())
623 const_cast<SelectExp*>(&e)->break_set();
624 e.default_case_get()->break_reset();
627 if (e.is_continuable() && e.default_case_get()->is_continue())
629 const_cast<SelectExp*>(&e)->continue_set();
630 e.default_case_get()->continue_reset();
633 if (e.is_returnable() && e.default_case_get()->is_return())
635 const_cast<SelectExp*>(&e)->return_set();
636 e.default_case_get()->return_reset();
644 void RunVisitorT<T>::visitprivate(const SeqExp &e)
647 std::list<Exp *>::const_iterator itExp;
649 for (itExp = e.exps_get().begin (); itExp != e.exps_get().end (); ++itExp)
651 if (e.is_breakable())
653 (*itExp)->break_reset();
654 (*itExp)->breakable_set();
657 if (e.is_continuable())
659 (*itExp)->continue_reset();
660 (*itExp)->continuable_set();
663 if (e.is_returnable())
665 (*itExp)->returnable_set();
670 //reset default values
672 expected_setSize(-1);
673 (*itExp)->accept(*this);
674 InternalType * pIT = result_get();
678 bool bImplicitCall = false;
679 if (pIT->isCallable()) //to manage call without ()
681 Callable *pCall = pIT->getAs<Callable>();
688 //in this case of calling, we can return only one values
689 int iSaveExpectedSize = expected_getSize();
691 Function::ReturnValue Ret = pCall->call(in, opt, expected_getSize(), out, this);
692 expected_setSize(iSaveExpectedSize);
694 if (Ret == Callable::OK)
704 bImplicitCall = true;
706 else if (Ret == Callable::Error)
708 if (ConfigVariable::getLastErrorFunction() == L"")
710 ConfigVariable::setLastErrorFunction(pCall->getName());
711 ConfigVariable::setLastErrorLine(e.location_get().first_line);
715 if (pCall->isMacro() || pCall->isMacroFile())
717 wchar_t szError[bsiz];
718 os_swprintf(szError, bsiz, _W("at line % 5d of function %ls called by :\n").c_str(), (*itExp)->location_get().first_line, pCall->getName().c_str());
719 throw ScilabMessage(szError);
723 throw ScilabMessage();
727 catch (ScilabMessage sm)
730 PrintVisitor printMe(os);
731 (*itExp)->accept(printMe);
732 //os << std::endl << std::endl;
733 if (ConfigVariable::getLastErrorFunction() == L"")
735 ConfigVariable::setLastErrorFunction(pCall->getName());
738 if (pCall->isMacro() || pCall->isMacroFile())
740 wchar_t szError[bsiz];
741 os_swprintf(szError, bsiz, _W("at line % 5d of function %ls called by :\n").c_str(), sm.GetErrorLocation().first_line, pCall->getName().c_str());
742 throw ScilabMessage(szError + os.str());
746 sm.SetErrorMessage(sm.GetErrorMessage() + os.str());
752 //don't output Simplevar and empty result
753 if (result_get() != NULL && (!(*itExp)->is_simple_var() || bImplicitCall))
755 //symbol::Context::getInstance()->put(symbol::Symbol(L"ans"), *execMe.result_get());
756 InternalType* pITAns = result_get();
757 symbol::Context::getInstance()->put(m_pAns, pITAns);
758 if ((*itExp)->is_verbose() && ConfigVariable::isPromptShow())
760 //TODO manage multiple returns
761 scilabWriteW(L" ans =\n\n");
762 VariableToString(pITAns, L"ans");
769 if ((&e)->is_breakable() && (*itExp)->is_break())
771 const_cast<SeqExp *>(&e)->break_set();
775 if ((&e)->is_continuable() && (*itExp)->is_continue())
777 const_cast<SeqExp *>(&e)->continue_set();
781 if ((&e)->is_returnable() && (*itExp)->is_return())
783 const_cast<SeqExp *>(&e)->return_set();
784 (*itExp)->return_reset();
788 catch (const ScilabMessage& sm)
790 scilabErrorW(sm.GetErrorMessage().c_str());
792 CallExp* pCall = dynamic_cast<CallExp*>(*itExp);
795 //to print call expression only of it is a macro
796 pCall->name_get().accept(*this);
798 if (result_get() != NULL && (result_get()->isMacro() || result_get()->isMacroFile()))
801 PrintVisitor printMe(os);
802 pCall->accept(printMe);
803 //os << std::endl << std::endl;
804 if (ConfigVariable::getLastErrorFunction() == L"")
806 ConfigVariable::setLastErrorFunction(((InternalType*)result_get())->getAs<Callable>()->getName());
808 throw ScilabMessage(os.str(), 0, (*itExp)->location_get());
812 throw ScilabMessage((*itExp)->location_get());
814 catch (const ScilabError& se)
816 // check on error number because error message can be empty.
817 if (ConfigVariable::getLastErrorNumber() == 0)
819 ConfigVariable::setLastErrorMessage(se.GetErrorMessage());
820 ConfigVariable::setLastErrorNumber(se.GetErrorNumber());
821 ConfigVariable::setLastErrorLine(se.GetErrorLocation().first_line);
822 ConfigVariable::setLastErrorFunction(wstring(L""));
825 CallExp* pCall = dynamic_cast<CallExp*>(*itExp);
828 //to print call expression only of it is a macro
831 pCall->name_get().accept(*this);
832 if (result_get() != NULL && (result_get()->isMacro() || result_get()->isMacroFile()))
835 PrintVisitor printMe(os);
836 pCall->accept(printMe);
837 //os << std::endl << std::endl;
838 ConfigVariable::setLastErrorFunction(((InternalType*)result_get())->getAs<Callable>()->getName());
839 scilabErrorW(se.GetErrorMessage().c_str());
840 throw ScilabMessage(os.str(), 999, (*itExp)->location_get());
843 catch (ScilabError se2)
845 //just to catch exception, do nothing
849 scilabErrorW(se.GetErrorMessage().c_str());
851 throw ScilabMessage((*itExp)->location_get());
854 // If something other than NULL is given to result_set, then that would imply
855 // to make a cleanup in visit(ForExp) for example (e.body_get().accept(*this);)
861 void RunVisitorT<T>::visitprivate(const NotExp &e)
866 e.exp_get().accept(*this);
868 InternalType * pValue = result_get();
869 InternalType * pReturn = NULL;
870 if (pValue->neg(pReturn))
872 if (pValue != pReturn)
881 // neg returned false so the negation is not possible so we call the overload (%foo_5)
882 types::typed_list in;
883 types::typed_list out;
885 pValue->IncreaseRef();
886 in.push_back(pValue);
888 Callable::ReturnValue Ret = Overload::call(L"%" + pValue->getShortTypeStr() + L"_5", in, 1, out, this);
890 if (Ret != Callable::OK)
892 clean_in_out(in, out);
902 void RunVisitorT<T>::visitprivate(const TransposeExp &e)
904 e.exp_get().accept(*this);
906 if (result_getSize() != 1)
909 wchar_t szError[bsiz];
910 os_swprintf(szError, bsiz, _W("%ls: Can not transpose multiple elements.\n").c_str(), L"Transpose");
911 throw ScilabError(szError, 999, e.location_get());
914 InternalType * pValue = result_get();
915 InternalType * pReturn = NULL;
916 const bool bConjug = e.conjugate_get() == TransposeExp::_Conjugate_;
918 if ((bConjug && pValue->adjoint(pReturn)) || (!bConjug && pValue->transpose(pReturn)))
920 if (pValue != pReturn)
931 // transpose returned false so the negation is not possible so we call the overload (%foo_t or %foo_0)
932 types::typed_list in;
933 types::typed_list out;
935 pValue->IncreaseRef();
936 in.push_back(pValue);
938 Callable::ReturnValue Ret;
941 Ret = Overload::call(L"%" + result_get()->getShortTypeStr() + L"_t", in, 1, out, this);
945 Ret = Overload::call(L"%" + result_get()->getShortTypeStr() + L"_0", in, 1, out, this);
948 if (Ret != Callable::OK)
950 clean_in_out(in, out);
960 void RunVisitorT<T>::visitprivate(const FunctionDec & e)
967 // funcprot(0) : do nothing
968 // funcprot(1) && warning(on) : warning
969 //get input parameters list
970 std::list<symbol::Variable*> *pVarList = new std::list<symbol::Variable*>();
971 const ArrayListVar *pListVar = &e.args_get();
972 for (std::list<Var *>::const_iterator i = pListVar->vars_get().begin(), end = pListVar->vars_get().end(); i != end; ++i)
974 pVarList->push_back(static_cast<SimpleVar*>(*i)->stack_get());
977 //get output parameters list
978 std::list<symbol::Variable*> *pRetList = new std::list<symbol::Variable*>();
979 const ArrayListVar *pListRet = &e.returns_get();
980 for (std::list<Var *>::const_iterator i = pListRet->vars_get().begin(), end = pListRet->vars_get().end(); i != end; ++i)
982 pRetList->push_back(static_cast<SimpleVar*>(*i)->stack_get());
985 types::Macro *pMacro = new types::Macro(e.name_get().name_get(), *pVarList, *pRetList,
986 const_cast<SeqExp&>(static_cast<const SeqExp&>(e.body_get())), L"script");
987 pMacro->setFirstLine(e.location_get().first_line);
989 bool bEquals = false;
990 int iFuncProt = ConfigVariable::getFuncprot();
993 types::InternalType* pITFunc = symbol::Context::getInstance()->get(((FunctionDec&)e).stack_get());
994 if (pITFunc && pITFunc->isCallable())
996 if (pITFunc->isMacroFile())
998 types::MacroFile* pMF = pITFunc->getAs<types::MacroFile>();
999 bEquals = *pMF->getMacro() == *pMacro;
1001 else if (pITFunc->isMacro())
1003 types::Macro* pM = pITFunc->getAs<types::Macro>();
1004 bEquals = *pM == *pMacro;
1009 bEquals = true; //avoid msg but keep assignation
1013 if (bEquals == false && iFuncProt == 1 && ConfigVariable::getWarningMode())
1015 wchar_t pwstFuncName[1024];
1016 os_swprintf(pwstFuncName, 1024, L"%-24ls", e.name_get().name_get().c_str());
1017 char* pstFuncName = wide_string_to_UTF8(pwstFuncName);
1019 sciprint(_("Warning : redefining function: %s. Use funcprot(0) to avoid this message"), pstFuncName);
1023 else if (bEquals == false && iFuncProt == 2)
1025 char pstError[1024];
1026 char* pstFuncName = wide_string_to_UTF8(e.name_get().name_get().c_str());
1027 sprintf(pstError, _("It is not possible to redefine the %s primitive this way (see clearfun).\n"), pstFuncName);
1028 wchar_t* pwstError = to_wide_string(pstError);
1029 std::wstring wstError(pwstError);
1032 throw ScilabError(wstError, 999, e.location_get());
1035 symbol::Context::getInstance()->addMacro(pMacro);
1040 void RunVisitorT<T>::visitprivate(const ListExp &e)
1042 e.start_get().accept(*this);
1043 GenericType* pITStart = static_cast<GenericType*>(result_get());
1044 if ((pITStart->getSize() != 1 || (pITStart->isDouble() && pITStart->getAs<Double>()->isComplex())) &&
1045 pITStart->isList() == false) // list case => call overload
1048 wchar_t szError[bsiz];
1049 os_swprintf(szError, bsiz, _W("%ls: Wrong type for argument %d: Real scalar expected.\n").c_str(), L"':'", 1);
1050 throw ScilabError(szError, 999, e.location_get());
1052 InternalType * piStart = pITStart;
1054 e.step_get().accept(*this);
1055 GenericType* pITStep = static_cast<GenericType*>(result_get());
1056 if ((pITStep->getSize() != 1 || (pITStep->isDouble() && pITStep->getAs<Double>()->isComplex())) &&
1057 pITStep->isList() == false) // list case => call overload
1061 wchar_t szError[bsiz];
1062 os_swprintf(szError, bsiz, _W("%ls: Wrong type for argument %d: Real scalar expected.\n").c_str(), L"':'", 2);
1063 throw ScilabError(szError, 999, e.location_get());
1065 InternalType* piStep = pITStep;
1067 e.end_get().accept(*this);
1068 GenericType* pITEnd = static_cast<GenericType*>(result_get());
1069 if ((pITEnd->getSize() != 1 || (pITEnd->isDouble() && pITEnd->getAs<Double>()->isComplex())) &&
1070 pITEnd->isList() == false) // list case => call overload
1075 wchar_t szError[bsiz];
1076 os_swprintf(szError, bsiz, _W("%ls: Wrong type for argument %d: Real scalar expected.\n").c_str(), L"':'", 3);
1077 throw ScilabError(szError, 999, e.location_get());
1079 InternalType* piEnd = pITEnd;
1081 //check compatibility
1082 // double : double : double or poly : poly : poly and mix like double : double : poly
1083 if ((piStart->isPoly() || piStart->isDouble()) &&
1084 (piStep->isPoly() || piStep->isDouble()) &&
1085 (piEnd->isPoly() || piEnd->isDouble()))
1087 // No need to kill piStart, ... because Implicit list ctor will incref them
1088 result_set(new ImplicitList(piStart, piStep, piEnd));
1092 // int : double or int : int
1093 if ( piStart->isInt() &&
1094 (piStep->isDouble() || piStep->isInt()) &&
1097 // check for same int type int8, int 16 ...
1098 if (piStart->getType() == piEnd->getType() &&
1099 (piStart->getType() == piStep->getType() ||
1100 piStep->isDouble()))
1102 // No need to kill piStart, ... because Implicit list ctor will incref them
1103 result_set(new ImplicitList(piStart, piStep, piEnd));
1109 Callable::ReturnValue Ret;
1110 types::typed_list in;
1111 types::typed_list out;
1113 piStart->IncreaseRef();
1114 piStep->IncreaseRef();
1115 piEnd->IncreaseRef();
1117 in.push_back(piStart);
1118 if (e.hasExplicitStep())
1121 //call overload %typeStart_b_typeEnd
1122 in.push_back(piStep);
1123 in.push_back(piEnd);
1124 Ret = Overload::call(L"%" + piStart->getShortTypeStr() + L"_b_" + piStep->getShortTypeStr(), in, 1, out, this, true);
1129 //call overload %typeStart_b_typeStep
1130 in.push_back(piEnd);
1131 Ret = Overload::call(L"%" + piStart->getShortTypeStr() + L"_b_" + piEnd->getShortTypeStr(), in, 1, out, this, true);
1134 if (Ret != Callable::OK)
1136 clean_in_out(in, out);
1137 throw ScilabError();
1144 #include "run_CallExp.cpp"
1145 #include "run_MatrixExp.cpp"
1146 #include "run_OpExp.cpp"
1147 #include "run_AssignExp.cpp"
1150 template EXTERN_AST class ast::RunVisitorT<ast::ExecVisitor>;
1151 template EXTERN_AST class ast::RunVisitorT<ast::StepVisitor>;
1152 template EXTERN_AST class ast::RunVisitorT<ast::TimedVisitor>;