2 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 * Copyright (C) 2009-2009 - DIGITEO - Bruno JOFRET
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 "context.hxx"
16 #include "visitor.hxx"
17 #include "printvisitor.hxx"
18 #include "execvisitor.hxx"
19 #include "timedvisitor.hxx"
20 #include "debugvisitor.hxx"
21 #include "stepvisitor.hxx"
22 #include "AnalysisVisitor.hxx"
23 #include "visitor_common.hxx"
25 #include "scilabWrite.hxx"
28 #define SCILAB_START L"/etc/scilab.start"
29 #define SCILAB_QUIT L"/etc/scilab.quit"
38 ** Parse the given file and create the AST.
40 void parseFileTask(Parser *parser, bool timed, const wchar_t* file_name, const wchar_t* prog_name)
43 std::cerr << "*** Processing " << file_name << " file..." << std::endl;
51 parser->parseFile(file_name, prog_name);
55 _timer.check(L"Parsing");
62 ** Parse the given command and create the AST.
64 void parseCommandTask(Parser *parser, bool timed, wchar_t *command)
67 std::cerr << "*** Processing [" << command << "]..." << std::endl;
75 parser->parse(command);
77 if (timed && parser->getControlStatus() == Parser::AllControlClosed)
79 _timer.check(L"Parsing");
86 ** Display the AST in human readable format.
88 void dumpAstTask(ast::Exp *tree, bool timed)
95 ast::DebugVisitor debugMe;
98 tree->accept(debugMe);
103 _timer.check(L"AST Dump");
110 ** Pretty print the Stored AST.
112 void printAstTask(ast::Exp *tree, bool timed)
121 ast::PrintVisitor printMe = *new ast::PrintVisitor(std::wcout);
122 tree->accept(printMe);
127 _timer.check(L"Pretty Print");
135 ** Execute the stored AST.
137 void execAstTask(ast::Exp* tree, bool serialize, bool timed, bool ASTtimed, bool execVerbose)
144 ast::Exp* newTree = NULL;
149 newTree = callTyper(tree, L"tasks");
153 newTree = callTyper(tree);
163 ast::ExecVisitor *exec;
171 exec = (ast::ExecVisitor*)new ast::TimedVisitor();
176 exec = (ast::ExecVisitor*)new ast::StepVisitor();
179 if (!execVerbose && !ASTtimed)
181 //call analyzer visitor before exec visitor
182 if (ConfigVariable::getAnalyzerOptions() == 1)
184 analysis::AnalysisVisitor analysis;
185 newTree->accept(analysis);
188 exec = new ast::ExecVisitor();
191 Runner::execAndWait(newTree, exec);
192 //DO NOT DELETE tree or newTree, they was deleted by Runner or previously;
196 _timer.check(L"Execute AST");
203 ** Display what is stored in scilab.
205 void dumpStackTask(bool timed)
212 symbol::Context::getInstance()->print(std::wcout);
216 _timer.check(L"Dumping Stack");
221 ** Execute scilab.start
224 void execScilabStartTask(bool _bSerialize)
227 wstring stSCI = ConfigVariable::getSCIPath();
229 stSCI += SCILAB_START;
230 parse.parseFile(stSCI, L"");
232 if (parse.getExitStatus() != Parser::Succeded)
234 scilabWriteW(parse.getErrorMessage());
235 scilabWriteW(L"Failed to parse scilab.start");
239 execAstTask(parse.getTree(), _bSerialize, false, false, false);
243 ** Execute scilab.quit
246 void execScilabQuitTask(bool _bSerialize)
249 wstring stSCI = ConfigVariable::getSCIPath();
251 stSCI += SCILAB_QUIT;
252 parse.parseFile(stSCI, L"");
254 if (parse.getExitStatus() != Parser::Succeded)
256 scilabWriteW(parse.getErrorMessage());
257 scilabWriteW(L"Failed to parse scilab.quit");
261 execAstTask(parse.getTree(), _bSerialize, false, false, false);