use reduce version of function from analysis during macro execution 71/19371/2
Antoine ELIAS [Mon, 14 Aug 2017 10:33:50 +0000 (12:33 +0200)]
Change-Id: I0c89dbe24f906b899698742ac76ea2800c46ff6a

scilab/modules/ast/Makefile.am
scilab/modules/ast/Makefile.in
scilab/modules/ast/ast.vcxproj
scilab/modules/ast/ast.vcxproj.filters
scilab/modules/ast/includes/ast/FBlockListener.hxx [new file with mode: 0644]
scilab/modules/ast/includes/types/callable.hxx
scilab/modules/ast/src/cpp/ast/FBlockListener.cpp [new file with mode: 0644]
scilab/modules/ast/src/cpp/types/callable.cpp
scilab/modules/ast/src/cpp/types/macro.cpp
scilab/modules/core/src/cpp/tasks.cpp

index 8cb0d49..a4c9765 100644 (file)
@@ -37,6 +37,7 @@ src/cpp/ast/visitor_common.cpp \
 src/cpp/ast/consoledebugger.cpp \
 src/cpp/ast/debuggervisitor.cpp \
 src/cpp/ast/debugmanager.cpp \
+src/cpp/ast/FBlockListener.cpp \
 src/cpp/ast/prettyprintvisitor.cpp \
 src/cpp/operations/interface_addition.cpp \
 src/cpp/operations/operations.cpp \
index 671569e..be3b3eb 100644 (file)
@@ -201,6 +201,7 @@ am__libsciast_la_SOURCES_DIST = src/c/operations/doublecomplex.c \
        src/cpp/ast/treevisitor.cpp src/cpp/ast/visitor_common.cpp \
        src/cpp/ast/consoledebugger.cpp \
        src/cpp/ast/debuggervisitor.cpp src/cpp/ast/debugmanager.cpp \
+       src/cpp/ast/FBlockListener.cpp \
        src/cpp/ast/prettyprintvisitor.cpp \
        src/cpp/operations/interface_addition.cpp \
        src/cpp/operations/operations.cpp \
@@ -402,6 +403,7 @@ am_libsciast_la_OBJECTS =  \
        src/cpp/ast/libsciast_la-consoledebugger.lo \
        src/cpp/ast/libsciast_la-debuggervisitor.lo \
        src/cpp/ast/libsciast_la-debugmanager.lo \
+       src/cpp/ast/libsciast_la-FBlockListener.lo \
        src/cpp/ast/libsciast_la-prettyprintvisitor.lo \
        src/cpp/operations/libsciast_la-interface_addition.lo \
        src/cpp/operations/libsciast_la-operations.lo \
@@ -1019,6 +1021,7 @@ libsciast_la_SOURCES = src/c/operations/doublecomplex.c \
        src/cpp/ast/treevisitor.cpp src/cpp/ast/visitor_common.cpp \
        src/cpp/ast/consoledebugger.cpp \
        src/cpp/ast/debuggervisitor.cpp src/cpp/ast/debugmanager.cpp \
+       src/cpp/ast/FBlockListener.cpp \
        src/cpp/ast/prettyprintvisitor.cpp \
        src/cpp/operations/interface_addition.cpp \
        src/cpp/operations/operations.cpp \
@@ -1660,6 +1663,9 @@ src/cpp/ast/libsciast_la-debuggervisitor.lo:  \
        src/cpp/ast/$(DEPDIR)/$(am__dirstamp)
 src/cpp/ast/libsciast_la-debugmanager.lo: src/cpp/ast/$(am__dirstamp) \
        src/cpp/ast/$(DEPDIR)/$(am__dirstamp)
+src/cpp/ast/libsciast_la-FBlockListener.lo:  \
+       src/cpp/ast/$(am__dirstamp) \
+       src/cpp/ast/$(DEPDIR)/$(am__dirstamp)
 src/cpp/ast/libsciast_la-prettyprintvisitor.lo:  \
        src/cpp/ast/$(am__dirstamp) \
        src/cpp/ast/$(DEPDIR)/$(am__dirstamp)
@@ -2495,6 +2501,7 @@ distclean-compile:
 @AMDEP_TRUE@@am__include@ @am__quote@src/cpp/analysis/$(DEPDIR)/libsciast_la-check_uint64.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@src/cpp/analysis/$(DEPDIR)/libsciast_la-check_uint8.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@src/cpp/analysis/$(DEPDIR)/libsciast_la-check_zeros.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@src/cpp/ast/$(DEPDIR)/libsciast_la-FBlockListener.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@src/cpp/ast/$(DEPDIR)/libsciast_la-consoledebugger.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@src/cpp/ast/$(DEPDIR)/libsciast_la-debuggervisitor.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@src/cpp/ast/$(DEPDIR)/libsciast_la-debugmanager.Plo@am__quote@
@@ -2771,6 +2778,13 @@ src/cpp/ast/libsciast_la-debugmanager.lo: src/cpp/ast/debugmanager.cpp
 @AMDEP_TRUE@@am__fastdepCXX_FALSE@     DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
 @am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libsciast_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o src/cpp/ast/libsciast_la-debugmanager.lo `test -f 'src/cpp/ast/debugmanager.cpp' || echo '$(srcdir)/'`src/cpp/ast/debugmanager.cpp
 
+src/cpp/ast/libsciast_la-FBlockListener.lo: src/cpp/ast/FBlockListener.cpp
+@am__fastdepCXX_TRUE@  $(AM_V_CXX)$(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libsciast_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT src/cpp/ast/libsciast_la-FBlockListener.lo -MD -MP -MF src/cpp/ast/$(DEPDIR)/libsciast_la-FBlockListener.Tpo -c -o src/cpp/ast/libsciast_la-FBlockListener.lo `test -f 'src/cpp/ast/FBlockListener.cpp' || echo '$(srcdir)/'`src/cpp/ast/FBlockListener.cpp
+@am__fastdepCXX_TRUE@  $(AM_V_at)$(am__mv) src/cpp/ast/$(DEPDIR)/libsciast_la-FBlockListener.Tpo src/cpp/ast/$(DEPDIR)/libsciast_la-FBlockListener.Plo
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@     $(AM_V_CXX)source='src/cpp/ast/FBlockListener.cpp' object='src/cpp/ast/libsciast_la-FBlockListener.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@     DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libsciast_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o src/cpp/ast/libsciast_la-FBlockListener.lo `test -f 'src/cpp/ast/FBlockListener.cpp' || echo '$(srcdir)/'`src/cpp/ast/FBlockListener.cpp
+
 src/cpp/ast/libsciast_la-prettyprintvisitor.lo: src/cpp/ast/prettyprintvisitor.cpp
 @am__fastdepCXX_TRUE@  $(AM_V_CXX)$(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libsciast_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT src/cpp/ast/libsciast_la-prettyprintvisitor.lo -MD -MP -MF src/cpp/ast/$(DEPDIR)/libsciast_la-prettyprintvisitor.Tpo -c -o src/cpp/ast/libsciast_la-prettyprintvisitor.lo `test -f 'src/cpp/ast/prettyprintvisitor.cpp' || echo '$(srcdir)/'`src/cpp/ast/prettyprintvisitor.cpp
 @am__fastdepCXX_TRUE@  $(AM_V_at)$(am__mv) src/cpp/ast/$(DEPDIR)/libsciast_la-prettyprintvisitor.Tpo src/cpp/ast/$(DEPDIR)/libsciast_la-prettyprintvisitor.Plo
index f1b8184..da9c11c 100644 (file)
@@ -1,4 +1,4 @@
-<?xml version="1.0" encoding="utf-8"?>
+<?xml version="1.0" encoding="utf-8"?>
 <Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
   <ItemGroup Label="ProjectConfigurations">
     <ProjectConfiguration Include="Debug|Win32">
@@ -344,6 +344,7 @@ lib /DEF:"$(ProjectDir)functions_manager_import.def" /SUBSYSTEM:WINDOWS /MACHINE
     <ClInclude Include="includes\ast\dynlib_ast.h" />
     <ClInclude Include="includes\ast\execvisitor.hxx" />
     <ClInclude Include="includes\ast\expHistory.hxx" />
+    <ClInclude Include="includes\ast\FBlockListener.hxx" />
     <ClInclude Include="includes\ast\prettyprintvisitor.hxx" />
     <ClInclude Include="includes\ast\treevisitor.hxx" />
     <ClInclude Include="includes\ast\macrovarvisitor.hxx" />
@@ -660,6 +661,7 @@ lib /DEF:"$(ProjectDir)functions_manager_import.def" /SUBSYSTEM:WINDOWS /MACHINE
     <ClCompile Include="src\cpp\ast\debuggervisitor.cpp" />
     <ClCompile Include="src\cpp\ast\debugmanager.cpp" />
     <ClCompile Include="src\cpp\ast\expHistory.cpp" />
+    <ClCompile Include="src\cpp\ast\FBlockListener.cpp" />
     <ClCompile Include="src\cpp\ast\prettyprintvisitor.cpp" />
     <ClCompile Include="src\cpp\ast\treevisitor.cpp" />
     <ClCompile Include="src\cpp\ast\macrovarvisitor.cpp" />
index 3a7d11e..af27295 100644 (file)
     <ClInclude Include="src\cpp\ast\run_SeqExp.hpp">
       <Filter>Header Files\ast</Filter>
     </ClInclude>
+    <ClInclude Include="includes\ast\FBlockListener.hxx">
+      <Filter>Header Files\ast</Filter>
+    </ClInclude>
   </ItemGroup>
   <ItemGroup>
     <ClCompile Include="src\cpp\ast\expHistory.cpp">
     <ClCompile Include="src\cpp\analysis\VisitWhileExp.cpp">
       <Filter>Source Files\analysis</Filter>
     </ClCompile>
+    <ClCompile Include="src\cpp\ast\FBlockListener.cpp">
+      <Filter>Source Files\ast</Filter>
+    </ClCompile>
   </ItemGroup>
 </Project>
\ No newline at end of file
diff --git a/scilab/modules/ast/includes/ast/FBlockListener.hxx b/scilab/modules/ast/includes/ast/FBlockListener.hxx
new file mode 100644 (file)
index 0000000..3edb69e
--- /dev/null
@@ -0,0 +1,34 @@
+/*
+*  Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+*  Copyright (C) 2017 - ESI - Antoine ELIAS
+*
+* Copyright (C) 2012 - 2016 - Scilab Enterprises
+*
+* This file is hereby licensed under the terms of the GNU GPL v2.0,
+* pursuant to article 5.3.4 of the CeCILL v.2.1.
+* This file was originally licensed under the terms of the CeCILL v2.1,
+* and continues to be available under such terms.
+* For more information, see the COPYING file which you should have received
+* along with this program.
+*
+*/
+
+#ifndef __FBLOCK_LISTENER_HXX__
+#define __FBLOCK_LISTENER_HXX__
+
+#include "dynlib_ast.h"
+#include "FBlockEmittedListener.hxx"
+
+class EXTERN_AST FBlockListener : public analysis::FBlockEmittedListener
+{
+
+    static std::unordered_map<uint64_t, ast::Exp*> functions;
+public:
+    FBlockListener();
+    virtual void action(analysis::FunctionBlock & fblock);
+    static ast::Exp* getExp(uint64_t functionId);
+};
+
+#endif // __FBLOCK_LISTENER_HXX__
+
+
index 1a1e6e9..8f4b1bf 100644 (file)
@@ -17,6 +17,7 @@
 #ifndef __CALLABLE_HXX__
 #define __CALLABLE_HXX__
 
+#include <stdint.h>
 #include <string>
 #include "internal.hxx"
 
@@ -39,11 +40,8 @@ public :
         Error
     };
 
-    Callable(): InternalType()
-    {
-        m_iFirstLine = 0;
-        m_iLastLine = 0;
-    }
+    Callable() : InternalType(), m_iFirstLine(0), m_iLastLine(0), m_functionId(-1) {}
+
     virtual             ~Callable() {}
 
     bool                isCallable()
@@ -138,6 +136,7 @@ protected :
     std::wstring            m_wstModule;
     int                     m_iFirstLine;
     int                     m_iLastLine;
+    uint64_t                m_functionId;
 };
 }
 
diff --git a/scilab/modules/ast/src/cpp/ast/FBlockListener.cpp b/scilab/modules/ast/src/cpp/ast/FBlockListener.cpp
new file mode 100644 (file)
index 0000000..95129ba
--- /dev/null
@@ -0,0 +1,41 @@
+/*
+*  Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+*  Copyright (C) 2017 - ESI - Antoine ELIAS
+*
+* Copyright (C) 2012 - 2016 - Scilab Enterprises
+*
+* This file is hereby licensed under the terms of the GNU GPL v2.0,
+* pursuant to article 5.3.4 of the CeCILL v.2.1.
+* This file was originally licensed under the terms of the CeCILL v2.1,
+* and continues to be available under such terms.
+* For more information, see the COPYING file which you should have received
+* along with this program.
+*
+*/
+
+#include "FBlockListener.hxx"
+
+std::unordered_map<uint64_t, ast::Exp*> FBlockListener::functions;
+
+FBlockListener::FBlockListener()
+{
+}
+
+void FBlockListener::action(analysis::FunctionBlock & fblock)
+{
+    std::wcerr << L"Add function \"" << fblock.getName() << L"\" as " << fblock.getFunctionId() << std::endl;
+    functions[fblock.getFunctionId()] = fblock.getExp()->clone();
+}
+
+ast::Exp* FBlockListener::getExp(uint64_t functionId)
+{
+    auto it = functions.find(functionId);
+    if (it != functions.end())
+    {
+        return it->second;
+    }
+    else
+    {
+        return nullptr;
+    }
+}
\ No newline at end of file
index 3ad2a8f..c6affb6 100644 (file)
@@ -19,6 +19,7 @@
 #include "configvariable.hxx"
 #include "exp.hxx"
 #include "scilabexception.hxx"
+#include "FBlockListener.hxx"
 
 namespace types
 {
@@ -39,6 +40,11 @@ bool Callable::invoke(typed_list & in, optional_list & opt, int _iRetCount, type
 
         try
         {
+            if (ConfigVariable::getAnalyzerOptions() == 1)
+            {
+                m_functionId = e.getDecorator().res.getFunctionId();
+            }
+
             Ret = call(in, opt, _iRetCount, out);
             ConfigVariable::where_end();
             ConfigVariable::decreaseRecursion();
index 01e2f81..dcefbba 100644 (file)
@@ -17,6 +17,7 @@
 #include <sstream>
 #include <cstdio>
 
+#include "AnalysisVisitor.hxx"
 #include "macro.hxx"
 #include "list.hxx"
 #include "context.hxx"
@@ -24,6 +25,7 @@
 #include "scilabWrite.hxx"
 #include "configvariable.hxx"
 #include "serializervisitor.hxx"
+#include "FBlockListener.hxx"
 
 extern "C"
 {
@@ -315,7 +317,26 @@ Callable::ReturnValue Macro::call(typed_list &in, optional_list &opt, int _iRetC
     try
     {
         ConfigVariable::setPromptMode(-1);
-        m_body->accept(*exec);
+
+        //use version from analyze
+        if (m_functionId != -1) 
+        {
+            ast::Exp* exp = FBlockListener::getExp(m_functionId);
+            if (exp)
+            {
+                //std::wcerr << "exec new exp" << std::endl;
+                exp->accept(*exec);
+            }
+            else
+            {
+                m_body->accept(*exec);
+            }
+        }
+        else 
+        {
+            m_body->accept(*exec);
+        }
+
         //restore previous prompt mode
         ConfigVariable::setPromptMode(oldVal);
     }
index 5f3cb9d..5d86f33 100644 (file)
@@ -14,6 +14,7 @@
 */
 
 #include "AnalysisVisitor.hxx"
+#include "FBlockListener.hxx"
 #include "tasks.hxx"
 #include "timer.hxx"
 #include "context.hxx"
@@ -185,7 +186,9 @@ void execAstTask(ast::Exp* tree, bool serialize, bool timed, bool ASTtimed, bool
         //call analyzer visitor before exec visitor
         if (ConfigVariable::getAnalyzerOptions() == 1)
         {
+            FBlockListener fb;
             analysis::AnalysisVisitor analysis;
+            analysis.registerFBlockEmittedListener(&fb);
             newTree->accept(analysis);
         }