use reduce version of function from analysis during macro execution
[scilab.git] / scilab / modules / ast / src / cpp / types / callable.cpp
1 /*
2  *  Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3  *  Copyright (C) 2014 - Scilab Enterprises - Calixte DENIZET
4  *
5  * Copyright (C) 2012 - 2016 - Scilab Enterprises
6  *
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.
13  *
14  */
15
16 #include <sstream>
17 #include <vector>
18 #include "callable.hxx"
19 #include "configvariable.hxx"
20 #include "exp.hxx"
21 #include "scilabexception.hxx"
22 #include "FBlockListener.hxx"
23
24 namespace types
25 {
26
27 bool Callable::invoke(typed_list & in, optional_list & opt, int _iRetCount, typed_list & out, const ast::Exp & e)
28 {
29     //check recursion before try catch, to make difference with  errors
30     if (ConfigVariable::increaseRecursion())
31     {
32         //reset previous error before call function
33         ConfigVariable::resetError();
34         //update verbose";" flag
35         ConfigVariable::setVerbose(e.isVerbose());
36         // add line and function name in where
37         int iFirstLine = e.getLocation().first_line;
38         ConfigVariable::where_begin(iFirstLine + 1 - ConfigVariable::getMacroFirstLines(), iFirstLine, this);
39         Callable::ReturnValue Ret;
40
41         try
42         {
43             if (ConfigVariable::getAnalyzerOptions() == 1)
44             {
45                 m_functionId = e.getDecorator().res.getFunctionId();
46             }
47
48             Ret = call(in, opt, _iRetCount, out);
49             ConfigVariable::where_end();
50             ConfigVariable::decreaseRecursion();
51         }
52         catch (ast::InternalError & ie)
53         {
54             ConfigVariable::where_end();
55             ConfigVariable::setLastErrorFunction(getName());
56             ConfigVariable::decreaseRecursion();
57             throw ie;
58         }
59         catch (ast::InternalAbort & ia)
60         {
61             ConfigVariable::where_end();
62             ConfigVariable::setLastErrorFunction(getName());
63             ConfigVariable::decreaseRecursion();
64             throw ia;
65         }
66
67         if (Ret == Callable::Error)
68         {
69             ConfigVariable::setLastErrorFunction(getName());
70             ConfigVariable::setLastErrorLine(e.getLocation().first_line);
71             throw ast::InternalError(ConfigVariable::getLastErrorMessage(), ConfigVariable::getLastErrorNumber(), e.getLocation());
72         }
73     }
74     else
75     {
76         throw ast::RecursionException();
77     }
78     return true;
79 }
80 }