2 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 * Copyright (C) 2009-2009 - DIGITEO - Bruno JOFRET
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.
16 //#include "AnalysisVisitor.hxx"
19 #include "context.hxx"
20 #include "visitor.hxx"
21 #include "printvisitor.hxx"
22 #include "execvisitor.hxx"
23 #include "timedvisitor.hxx"
24 #include "prettyprintvisitor.hxx"
25 #include "debuggervisitor.hxx"
26 #include "stepvisitor.hxx"
27 #include "visitor_common.hxx"
28 #include "threadmanagement.hxx"
30 #include "scilabWrite.hxx"
33 #define SCILAB_START L"/etc/scilab.start"
34 #define SCILAB_QUIT L"/etc/scilab.quit"
43 ** Parse the given file and create the AST.
45 void parseFileTask(Parser *parser, bool timed, const wchar_t* file_name, const wchar_t* prog_name)
48 std::cerr << "*** Processing " << file_name << " file..." << std::endl;
56 parser->parseFile(file_name, prog_name);
60 _timer.check(L"Parsing");
67 ** Parse the given command and create the AST.
69 void parseCommandTask(Parser *parser, bool timed, char *command)
72 std::cerr << "*** Processing [" << command << "]..." << std::endl;
80 parser->parse(command);
82 if (timed && parser->getControlStatus() == Parser::AllControlClosed)
84 _timer.check(L"Parsing");
91 ** Display the AST in human readable format.
93 void dumpAstTask(ast::Exp *tree, bool timed)
100 ast::PrettyPrintVisitor debugMe;
103 tree->accept(debugMe);
108 _timer.check(L"AST Dump");
115 ** Pretty print the Stored AST.
117 void printAstTask(ast::Exp *tree, bool timed)
126 ast::PrintVisitor printMe (std::wcout);
127 tree->accept(printMe);
132 _timer.check(L"Pretty Print");
140 ** Execute the stored AST.
142 void execAstTask(ast::Exp* tree, bool serialize, bool timed, bool ASTtimed, bool execVerbose,
143 bool isInterruptibleThread, bool isPrioritaryThread, command_origin_t iCommandOrigin)
150 ast::Exp* newTree = NULL;
155 newTree = callTyper(tree, L"tasks");
159 newTree = callTyper(tree);
169 ast::RunVisitor *exec;
177 exec = new ast::TimedVisitor();
179 else if (execVerbose)
181 exec = new ast::StepVisitor();
185 //call analyzer visitor before exec visitor
186 if (ConfigVariable::getAnalyzerOptions() == 1)
188 //analysis::AnalysisVisitor analysis;
189 //newTree->accept(analysis);
192 exec = (ast::RunVisitor*)ConfigVariable::getDefaultVisitor();
195 StaticRunner::execAndWait(newTree, exec, isInterruptibleThread, isPrioritaryThread, iCommandOrigin);
196 //DO NOT DELETE tree or newTree, they was deleted by Runner or previously;
200 _timer.check(L"Execute AST");
207 ** Display what is stored in scilab.
209 void dumpStackTask(bool timed)
216 symbol::Context::getInstance()->print(std::wcout);
220 _timer.check(L"Dumping Stack");
225 ** Execute scilab.start
228 int execScilabStartTask(bool _bSerialize)
231 std::wstring stSCI = ConfigVariable::getSCIPath();
232 stSCI += SCILAB_START;
234 ThreadManagement::LockParser();
237 parse.parseFile(stSCI, L"");
239 catch (const ast::InternalError& ie)
241 scilabWrite(ie.what());
242 ThreadManagement::UnlockParser();
246 if (parse.getExitStatus() != Parser::Succeded)
248 scilabWriteW(parse.getErrorMessage());
249 scilabWriteW(L"Failed to parse scilab.start");
250 ThreadManagement::UnlockParser();
253 ThreadManagement::UnlockParser();
255 ast::Exp* newTree = parse.getTree();
258 newTree = callTyper(parse.getTree());
261 return StaticRunner::exec(newTree, new ast::ExecVisitor()) ? 0 : 1;
265 ** Execute scilab.quit
268 int execScilabQuitTask(bool _bSerialize)
271 std::wstring stSCI = ConfigVariable::getSCIPath();
272 stSCI += SCILAB_QUIT;
274 ThreadManagement::LockParser();
277 parse.parseFile(stSCI, L"");
279 catch (const ast::InternalError& ie)
281 scilabWrite(ie.what());
282 ThreadManagement::UnlockParser();
286 if (parse.getExitStatus() != Parser::Succeded)
288 scilabWriteW(parse.getErrorMessage());
289 scilabWriteW(L"Failed to parse scilab.quit");
290 ThreadManagement::UnlockParser();
293 ThreadManagement::UnlockParser();
295 ast::Exp* newTree = parse.getTree();
298 newTree = callTyper(parse.getTree());
301 return StaticRunner::exec(newTree, new ast::ExecVisitor()) ? 0 : 1;
305 ast::Exp* parseCommand(std::wstring _command)
307 if (_command.empty())
313 parse.parse((wchar_t*)_command.c_str());
314 if (parse.getExitStatus() != Parser::Succeded)
319 return parse.getTree();