2 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 * Copyright (C) 2015 - Scilab Enterprises - Antoine ELIAS
5 * Copyright (C) 2012 - 2016 - Scilab Enterprises
7 * This file is hereby licensed under the terms of the GNU GPL v2.0,
8 * pursuant to article 5.3.4 of the CeCILL v.2.1.
9 * This file was originally licensed under the terms of the CeCILL v2.1,
10 * and continues to be available under such terms.
11 * For more information, see the COPYING file which you should have received
12 * along with this program.
17 //file included in runvisitor.cpp
21 void RunVisitorT<T>::visitprivate(const SeqExp &e)
23 CoverageInstance::invokeAndStartChrono((void*)&e);
25 ast::exps_t exps = e.getExps();
26 ast::exps_t::const_iterator it = exps.begin();
27 ast::exps_t::const_iterator itEnd = exps.end();
30 /*stuff of printf input during execution*/
32 int iCurrentLine = -1; //no data in str
34 std::ifstream* file = nullptr;
35 if (e.getExecFrom() == SeqExp::EXEC)
37 //open input file to print exp from it
38 int iFileID = ConfigVariable::getExecutedFileID();
41 const wchar_t* filename = getfile_filename(iFileID);
44 char* cfilename = wide_string_to_UTF8(filename);
45 file = new std::ifstream(cfilename);
51 for (; it != itEnd; ++it)
53 if (ConfigVariable::isExecutionBreak())
55 ConfigVariable::resetExecutionBreak();
56 if (ConfigVariable::isPrintInteractive())
58 ClearTemporaryPrompt();
61 StorePrioritaryCommand("pause");
62 ThreadManagement::WaitForRunMeSignal();
65 // interrupt me to execute a prioritary command
66 while (StaticRunner_isInterruptibleCommand() == 1 && StaticRunner_isRunnerAvailable() == 1)
68 StaticRunner_launch();
69 StaticRunner_setInterruptibleCommand(1);
72 //printf input expression line following mode configuration
73 if (file && ConfigVariable::isPrintInput())
75 Location loc = (*it)->getLocation();
76 if (iCurrentLine + 1 < loc.first_line)
79 std::string stPrompt = GetCurrentPrompt();
80 if (ConfigVariable::isPrintInteractive())
82 stPrompt = SCIPROMPT_PAUSE;
85 ast::exps_t::const_iterator k = it;
86 int iLastLine = loc.last_line;
87 int iCurrentCol = 0; //no data in str
90 str = printExp(*file, *k, stPrompt, &iCurrentLine, &iCurrentCol, str);
91 iLastLine = (*k)->getLocation().last_line;
93 } while (k != exps.end() && (*k)->getLocation().first_line == iLastLine);
97 if ((*it)->isCommentExp())
104 //reset default values
106 int iExpectedSize = getExpectedSize();
108 (*it)->accept(*this);
109 setExpectedSize(iExpectedSize);
110 types::InternalType * pIT = getResult();
112 // In case of exec file, set the file name in the Macro to store where it is defined.
113 int iFileID = ConfigVariable::getExecutedFileID();
114 if (iFileID && (*it)->isFunctionDec())
116 types::InternalType* pITMacro = symbol::Context::getInstance()->get((*it)->getAs<FunctionDec>()->getSymbol());
119 types::Macro* pMacro = pITMacro->getAs<types::Macro>();
120 const wchar_t* filename = getfile_filename(iFileID);
121 // scilab.quit is not open with mopen
122 // in this case filename is NULL because FileManager have not been filled.
125 pMacro->setFileName(filename);
132 bool bImplicitCall = false;
133 if (pIT->isCallable()) //to manage call without ()
135 types::Callable *pCall = pIT->getAs<types::Callable>();
136 types::typed_list out;
137 types::typed_list in;
138 types::optional_list opt;
142 //in this case of calling, we can return at most one value
143 int iSaveExpectedSize = getExpectedSize();
146 pCall->invoke(in, opt, getExpectedSize(), out, **it);
147 setExpectedSize(iSaveExpectedSize);
158 bImplicitCall = true;
160 catch (const InternalError& ie)
162 if (ConfigVariable::getLastErrorFunction() == L"")
164 ConfigVariable::setLastErrorFunction(pCall->getName());
165 ConfigVariable::setLastErrorLine(e.getLocation().first_line);
167 CoverageInstance::stopChrono((void*)&e);
171 else if (pIT->isImplicitList())
173 //expand implicit when possible
174 types::ImplicitList* pIL = pIT->getAs<types::ImplicitList>();
175 if (pIL->isComputable())
177 types::InternalType* p = pIL->extractFullMatrix();
185 //don't output Simplevar and empty result
186 if (getResult() != NULL && (!(*it)->isSimpleVar() || bImplicitCall))
188 //symbol::Context::getInstance()->put(symbol::Symbol(L"ans"), *execMe.getResult());
189 types::InternalType* pITAns = getResult();
190 symbol::Context::getInstance()->put(m_pAns, pITAns);
191 if ((*it)->isVerbose() && ConfigVariable::isPrintOutput())
193 //TODO manage multiple returns
194 scilabWriteW(L" ans =\n");
195 if (ConfigVariable::isPrintCompact() == false)
199 std::wostringstream ostrName;
201 VariableToString(pITAns, ostrName.str().c_str());
208 if (ConfigVariable::isPrintInteractive())
210 Location loc = (*it)->getLocation();
211 if (lastLine < loc.first_line)
214 SetTemporaryPrompt(SCIPROMPT_PAUSE);
216 // The console thread must not parse the next console input.
217 ConfigVariable::setScilabCommand(0);
219 // Get the console input filled by the console thread.
220 char* pcConsoleReadStr = ConfigVariable::getConsoleReadStr();
221 ThreadManagement::SendConsoleExecDoneSignal();
222 while (pcConsoleReadStr == NULL)
224 pcConsoleReadStr = ConfigVariable::getConsoleReadStr();
225 ThreadManagement::SendConsoleExecDoneSignal();
228 // reset flag to default value
229 ConfigVariable::setScilabCommand(1);
231 if (pcConsoleReadStr && pcConsoleReadStr[0] == 'p' && pcConsoleReadStr[1] == '\0')
234 ConfigVariable::setExecutionBreak();
238 lastLine = loc.last_line;
241 if ((&e)->isBreakable() && (*it)->isBreak())
243 const_cast<SeqExp *>(&e)->setBreak();
248 if ((&e)->isContinuable() && (*it)->isContinue())
250 const_cast<SeqExp *>(&e)->setContinue();
251 (*it)->resetContinue();
255 if ((&e)->isReturnable() && (*it)->isReturn())
257 const_cast<SeqExp *>(&e)->setReturn();
258 (*it)->resetReturn();
262 catch (const InternalError& ie)
264 ConfigVariable::fillWhereError(ie.GetErrorLocation().first_line);
265 CoverageInstance::stopChrono((void*)&e);
274 catch (const InternalAbort& ia)
283 // If something other than NULL is given to setResult, then that would imply
284 // to make a cleanup in visit(ForExp) for example (e.getBody().accept(*this);)
293 CoverageInstance::stopChrono((void*)&e);
297 } /* namespace ast */