add macrovar function 13/11413/4
Antoine ELIAS [Fri, 26 Apr 2013 12:03:51 +0000 (14:03 +0200)]
Change-Id: Ie492a737ae05a285d954c1e5bb224b2fdaa4f935

14 files changed:
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/macrovarvisitor.hxx [new file with mode: 0644]
scilab/modules/ast/src/cpp/macrovarvisitor.cpp [new file with mode: 0644]
scilab/modules/functions/Makefile.am
scilab/modules/functions/Makefile.in
scilab/modules/functions/includes/functions_gw.hxx
scilab/modules/functions/macros/macrovar.sci [deleted file]
scilab/modules/functions/sci_gateway/cpp/functions_gw.vcxproj
scilab/modules/functions/sci_gateway/cpp/functions_gw.vcxproj.filters
scilab/modules/functions/sci_gateway/cpp/sci_macrovar.cpp [new file with mode: 0644]
scilab/modules/functions/sci_gateway/functions_gateway.xml

index df4378f..f9bc0f2 100644 (file)
@@ -20,7 +20,8 @@ libsciast_la_SOURCES = \
        src/cpp/debugvisitor.cpp \
        src/cpp/mutevisitor.cpp \
        src/cpp/shortcutvisitor.cpp \
-       src/cpp/scilabexception.cpp
+       src/cpp/scilabexception.cpp \
+       src/cpp/macrovarvisitor.cpp
 
 libsciast_la_CPPFLAGS = \
        -Iincludes \
index 5d2e4d1..0b126b1 100644 (file)
@@ -135,7 +135,8 @@ am_libsciast_la_OBJECTS = libsciast_la-libAst.lo \
        libsciast_la-visitor_common.lo libsciast_la-printvisitor.lo \
        libsciast_la-debugvisitor.lo libsciast_la-mutevisitor.lo \
        libsciast_la-shortcutvisitor.lo \
-       libsciast_la-scilabexception.lo
+       libsciast_la-scilabexception.lo \
+       libsciast_la-macrovarvisitor.lo
 libsciast_la_OBJECTS = $(am_libsciast_la_OBJECTS)
 am_testConstExp_OBJECTS = testConstExp-testConstExp.$(OBJEXT)
 testConstExp_OBJECTS = $(am_testConstExp_OBJECTS)
@@ -457,7 +458,8 @@ libsciast_la_SOURCES = \
        src/cpp/debugvisitor.cpp \
        src/cpp/mutevisitor.cpp \
        src/cpp/shortcutvisitor.cpp \
-       src/cpp/scilabexception.cpp
+       src/cpp/scilabexception.cpp \
+       src/cpp/macrovarvisitor.cpp
 
 libsciast_la_CPPFLAGS = \
        -Iincludes \
@@ -671,6 +673,7 @@ distclean-compile:
 
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libsciast_la-debugvisitor.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libsciast_la-libAst.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libsciast_la-macrovarvisitor.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libsciast_la-mutevisitor.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libsciast_la-printvisitor.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libsciast_la-scilabexception.Plo@am__quote@
@@ -750,6 +753,13 @@ libsciast_la-scilabexception.lo: src/cpp/scilabexception.cpp
 @AMDEP_TRUE@@am__fastdepCXX_FALSE@     DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
 @am__fastdepCXX_FALSE@ $(LIBTOOL)  --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libsciast_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o libsciast_la-scilabexception.lo `test -f 'src/cpp/scilabexception.cpp' || echo '$(srcdir)/'`src/cpp/scilabexception.cpp
 
+libsciast_la-macrovarvisitor.lo: src/cpp/macrovarvisitor.cpp
+@am__fastdepCXX_TRUE@  $(LIBTOOL)  --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libsciast_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT libsciast_la-macrovarvisitor.lo -MD -MP -MF $(DEPDIR)/libsciast_la-macrovarvisitor.Tpo -c -o libsciast_la-macrovarvisitor.lo `test -f 'src/cpp/macrovarvisitor.cpp' || echo '$(srcdir)/'`src/cpp/macrovarvisitor.cpp
+@am__fastdepCXX_TRUE@  $(am__mv) $(DEPDIR)/libsciast_la-macrovarvisitor.Tpo $(DEPDIR)/libsciast_la-macrovarvisitor.Plo
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@     source='src/cpp/macrovarvisitor.cpp' object='libsciast_la-macrovarvisitor.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@     DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCXX_FALSE@ $(LIBTOOL)  --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libsciast_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o libsciast_la-macrovarvisitor.lo `test -f 'src/cpp/macrovarvisitor.cpp' || echo '$(srcdir)/'`src/cpp/macrovarvisitor.cpp
+
 testConstExp-testConstExp.o: src/cpp/testConstExp.cpp
 @am__fastdepCXX_TRUE@  $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(testConstExp_CXXFLAGS) $(CXXFLAGS) -MT testConstExp-testConstExp.o -MD -MP -MF $(DEPDIR)/testConstExp-testConstExp.Tpo -c -o testConstExp-testConstExp.o `test -f 'src/cpp/testConstExp.cpp' || echo '$(srcdir)/'`src/cpp/testConstExp.cpp
 @am__fastdepCXX_TRUE@  $(am__mv) $(DEPDIR)/testConstExp-testConstExp.Tpo $(DEPDIR)/testConstExp-testConstExp.Po
index 956c077..929ba30 100644 (file)
   <ItemGroup>
     <ClCompile Include="src\cpp\debugvisitor.cpp" />
     <ClCompile Include="src\cpp\libAst.cpp" />
+    <ClCompile Include="src\cpp\macrovarvisitor.cpp" />
     <ClCompile Include="src\cpp\mutevisitor.cpp" />
     <ClCompile Include="src\cpp\printvisitor.cpp" />
     <ClCompile Include="src\cpp\shortcutvisitor.cpp" />
     <ClInclude Include="includes\functiondec.hxx" />
     <ClInclude Include="includes\ifexp.hxx" />
     <ClInclude Include="includes\intexp.hxx" />
+    <ClInclude Include="includes\macrovarvisitor.hxx" />
     <ClInclude Include="includes\stepvisitor.hxx" />
     <ClInclude Include="src\cpp\libAst.hxx" />
     <ClInclude Include="includes\listexp.hxx" />
index ae88779..9c99692 100644 (file)
@@ -19,6 +19,9 @@
     <ClCompile Include="src\cpp\visitor_common.cpp">
       <Filter>Source Files</Filter>
     </ClCompile>
+    <ClCompile Include="src\cpp\macrovarvisitor.cpp">
+      <Filter>Source Files</Filter>
+    </ClCompile>
   </ItemGroup>
   <ItemGroup>
     <ClInclude Include="includes\all.hxx">
     <ClInclude Include="includes\stepvisitor.hxx">
       <Filter>Header Files</Filter>
     </ClInclude>
+    <ClInclude Include="includes\macrovarvisitor.hxx">
+      <Filter>Header Files</Filter>
+    </ClInclude>
   </ItemGroup>
   <ItemGroup>
     <Library Include="..\..\bin\blasplus.lib" />
diff --git a/scilab/modules/ast/includes/macrovarvisitor.hxx b/scilab/modules/ast/includes/macrovarvisitor.hxx
new file mode 100644 (file)
index 0000000..1d8b128
--- /dev/null
@@ -0,0 +1,71 @@
+/*
+ *  Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ *  Copyright (C) 2013 - Scilab Enterprises - Antoine ELIAS
+ *
+ *  This file must be used under the terms of the CeCILL.
+ *  This source file is licensed as described in the file COPYING, which
+ *  you should have received as part of this distribution.  The terms
+ *  are also available at
+ *  http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+ *
+ */
+
+#ifndef __MACROVARVISITOR_HXX__
+#define __MACROVARVISITOR_HXX__
+
+#include "visitor.hxx"
+#include "allexp.hxx"
+#include "allvar.hxx"
+#include "alldec.hxx"
+#include "dummyvisitor.hxx"
+
+/*
+** This class defines a dummy visitor which only purpose is to
+** followup itself through the AST.
+*/
+
+namespace ast
+{
+class EXTERN_AST MacrovarVisitor : public DummyVisitor
+{
+public:
+    MacrovarVisitor() {}
+    ~MacrovarVisitor() {}
+
+    void visit (const SimpleVar &e);
+    void visit(const CallExp &e);
+    void visit (const VarDec &e);
+    void visit(const AssignExp &e);
+
+    std::list<std::wstring>& getIn();
+    std::list<std::wstring>& getOut();
+    std::list<std::wstring>& getExternal();
+    std::list<std::wstring>& getCalled();
+    std::list<std::wstring>& getLocal();
+    void add(std::list<std::wstring>& lst);
+    void add();
+
+    bool isAlreadyIn(std::list<std::wstring>& lst);
+    bool isAlreadyUsed();
+
+    void addIn(std::wstring st)
+    {
+        m_in.push_back(st);
+    }
+
+    void addOut(std::wstring st)
+    {
+        m_out.push_back(st);
+    }
+
+    std::list<std::wstring> m_in; //inout variables
+    std::list<std::wstring> m_out; //output functions
+    std::list<std::wstring> m_external; //external variables
+    std::list<std::wstring> m_called; //called functions
+    std::list<std::wstring> m_local; // local variables
+
+    std::wstring m_current;
+};
+}
+
+#endif /* !__MACROVARVISITOR_HXX__ */
diff --git a/scilab/modules/ast/src/cpp/macrovarvisitor.cpp b/scilab/modules/ast/src/cpp/macrovarvisitor.cpp
new file mode 100644 (file)
index 0000000..7a377b1
--- /dev/null
@@ -0,0 +1,158 @@
+/*
+ *  Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ *  Copyright (C) 2013 - Scilab Enterprises - Antoine ELIAS
+ *
+ *  This file must be used under the terms of the CeCILL.
+ *  This source file is licensed as described in the file COPYING, which
+ *  you should have received as part of this distribution.  The terms
+ *  are also available at
+ *  http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+ *
+ */
+
+#include "macrovarvisitor.hxx"
+#include "context.hxx"
+
+using namespace std;
+using namespace ast;
+using namespace symbol;
+namespace ast
+{
+void MacrovarVisitor::visit (const SimpleVar &e)
+{
+    m_current = e.name_get().name_get();
+}
+
+void MacrovarVisitor::visit(const CallExp &e)
+{
+    e.name_get().accept (*this);
+    add();
+
+    std::list<Exp *>::const_iterator i;
+    for (i = e.args_get().begin (); i != e.args_get().end (); ++i)
+    {
+        (*i)->accept (*this);
+        add();
+    }
+}
+
+void MacrovarVisitor::visit(const AssignExp &e)
+{
+    e.left_exp_get().accept (*this);
+    add();
+    e.right_exp_get().accept (*this);
+    add();
+}
+
+void MacrovarVisitor::visit (const VarDec  &e)
+{
+    e.init_get().accept(*this);
+    add(m_local);
+}
+
+std::list<std::wstring>& MacrovarVisitor::getIn()
+{
+    return m_in;
+}
+
+std::list<std::wstring>& MacrovarVisitor::getOut()
+{
+    return m_out;
+}
+
+std::list<std::wstring>& MacrovarVisitor::getExternal()
+{
+    return m_external;
+}
+
+std::list<std::wstring>& MacrovarVisitor::getCalled()
+{
+    return m_called;
+}
+
+std::list<std::wstring>& MacrovarVisitor::getLocal()
+{
+    return m_local;
+}
+
+void MacrovarVisitor::add(std::list<std::wstring>& lst)
+{
+    if (m_current == L"")
+    {
+        return;
+    }
+
+    if (isAlreadyUsed() == false)
+    {
+        lst.push_back(m_current);
+    }
+
+    m_current = L"";
+}
+
+void MacrovarVisitor::add()
+{
+    InternalType* pVar = Context::getInstance()->get(Symbol(m_current));
+
+    if (pVar)
+    {
+        if (pVar->isCallable())
+        {
+            //symbol already exists and callable
+            add(m_called);
+            return;
+        }
+
+        //symbol already exists and not callable.
+        //it is a external var
+        add(m_external);
+        return;
+    }
+
+    add(m_local);
+}
+
+bool MacrovarVisitor::isAlreadyIn(std::list<std::wstring>& lst)
+{
+    std::list<std::wstring>::iterator it;
+    for (it = lst.begin(); it != lst.end() ; it++)
+    {
+        if (*it == m_current)
+        {
+            return true;
+        }
+    }
+
+    return false;
+}
+
+bool MacrovarVisitor::isAlreadyUsed()
+{
+    if (isAlreadyIn(m_in))
+    {
+        return true;
+    }
+
+    if (isAlreadyIn(m_out))
+    {
+        return true;
+    }
+
+    if (isAlreadyIn(m_external))
+    {
+        return true;
+    }
+
+    if (isAlreadyIn(m_called))
+    {
+        return true;
+    }
+
+    if (isAlreadyIn(m_local))
+    {
+        return true;
+    }
+
+    return false;
+}
+}
\ No newline at end of file
index 86b19b3..aad7fca 100644 (file)
@@ -25,7 +25,8 @@ sci_gateway/cpp/sci_whereis.cpp \
 sci_gateway/cpp/sci_execstr.cpp \
 sci_gateway/cpp/sci_getCurrentThreadId.cpp \
 sci_gateway/cpp/sci_mode.cpp \
-sci_gateway/cpp/sci_getThreads.cpp
+sci_gateway/cpp/sci_getThreads.cpp \
+sci_gateway/cpp/sci_macrovar.cpp
 
 GATEWAY_FORTRAN_SOURCES = \
 sci_gateway/fortran/intlib.f \
index 9b3306c..4b29c75 100644 (file)
@@ -155,7 +155,8 @@ am__objects_5 = libscifunctions_la-sci_exec.lo \
        libscifunctions_la-sci_execstr.lo \
        libscifunctions_la-sci_getCurrentThreadId.lo \
        libscifunctions_la-sci_mode.lo \
-       libscifunctions_la-sci_getThreads.lo
+       libscifunctions_la-sci_getThreads.lo \
+       libscifunctions_la-sci_macrovar.lo
 am_libscifunctions_la_OBJECTS = $(am__objects_3) $(am__objects_4) \
        $(am__objects_5)
 libscifunctions_la_OBJECTS = $(am_libscifunctions_la_OBJECTS)
@@ -488,7 +489,8 @@ sci_gateway/cpp/sci_whereis.cpp \
 sci_gateway/cpp/sci_execstr.cpp \
 sci_gateway/cpp/sci_getCurrentThreadId.cpp \
 sci_gateway/cpp/sci_mode.cpp \
-sci_gateway/cpp/sci_getThreads.cpp
+sci_gateway/cpp/sci_getThreads.cpp \
+sci_gateway/cpp/sci_macrovar.cpp
 
 GATEWAY_FORTRAN_SOURCES = \
 sci_gateway/fortran/intlib.f \
@@ -719,6 +721,7 @@ distclean-compile:
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libscifunctions_la-sci_lib.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libscifunctions_la-sci_librarieslist.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libscifunctions_la-sci_libraryinfo.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libscifunctions_la-sci_macrovar.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libscifunctions_la-sci_mode.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libscifunctions_la-sci_whereis.Plo@am__quote@
 
@@ -883,6 +886,13 @@ libscifunctions_la-sci_getThreads.lo: sci_gateway/cpp/sci_getThreads.cpp
 @AMDEP_TRUE@@am__fastdepCXX_FALSE@     DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
 @am__fastdepCXX_FALSE@ $(LIBTOOL)  --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libscifunctions_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o libscifunctions_la-sci_getThreads.lo `test -f 'sci_gateway/cpp/sci_getThreads.cpp' || echo '$(srcdir)/'`sci_gateway/cpp/sci_getThreads.cpp
 
+libscifunctions_la-sci_macrovar.lo: sci_gateway/cpp/sci_macrovar.cpp
+@am__fastdepCXX_TRUE@  $(LIBTOOL)  --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libscifunctions_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT libscifunctions_la-sci_macrovar.lo -MD -MP -MF $(DEPDIR)/libscifunctions_la-sci_macrovar.Tpo -c -o libscifunctions_la-sci_macrovar.lo `test -f 'sci_gateway/cpp/sci_macrovar.cpp' || echo '$(srcdir)/'`sci_gateway/cpp/sci_macrovar.cpp
+@am__fastdepCXX_TRUE@  $(am__mv) $(DEPDIR)/libscifunctions_la-sci_macrovar.Tpo $(DEPDIR)/libscifunctions_la-sci_macrovar.Plo
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@     source='sci_gateway/cpp/sci_macrovar.cpp' object='libscifunctions_la-sci_macrovar.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@     DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCXX_FALSE@ $(LIBTOOL)  --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libscifunctions_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o libscifunctions_la-sci_macrovar.lo `test -f 'sci_gateway/cpp/sci_macrovar.cpp' || echo '$(srcdir)/'`sci_gateway/cpp/sci_macrovar.cpp
+
 .f.o:
        $(F77COMPILE) -c -o $@ $<
 
index d93aff4..3c21baf 100644 (file)
@@ -24,6 +24,7 @@ CPP_GATEWAY_PROTOTYPE_EXPORT(sci_whereis, FUNCTIONS_GW_IMPEXP);
 CPP_GATEWAY_PROTOTYPE_EXPORT(sci_getCurrentThreadId, FUNCTIONS_GW_IMPEXP);
 CPP_GATEWAY_PROTOTYPE_EXPORT(sci_mode, FUNCTIONS_GW_IMPEXP);
 CPP_GATEWAY_PROTOTYPE_EXPORT(sci_getThreads, FUNCTIONS_GW_IMPEXP);
+CPP_GATEWAY_PROTOTYPE_EXPORT(sci_macrovar, FUNCTIONS_GW_IMPEXP);
 
 #endif /* __FUNCTIONS_GW_HXX__ */
 
diff --git a/scilab/modules/functions/macros/macrovar.sci b/scilab/modules/functions/macros/macrovar.sci
deleted file mode 100644 (file)
index 7da202a..0000000
+++ /dev/null
@@ -1,89 +0,0 @@
-// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
-// Copyright (C) 1992-2008 - INRIA - Serge STEER <serge.steer@inria.fr>
-//
-// This file must be used under the terms of the CeCILL.
-// This source file is licensed as described in the file COPYING, which
-// you should have received as part of this distribution.  The terms
-// are also available at
-// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
-
-function vars=macrovar(macro)
-// Returns in a list the set of varibles used by a macro
-//    mac  : macro
-//    vars : list(in,out,globals,called,locals)
-//           in : input variables
-//           out: output variables
-//           globals: global variables
-//           called : macros called
-//           locals : local variables
-//!
-if type(macro)==11 then comp(macro),end
-if type(macro)<>13 then 
-  error(msprintf(gettext("%s: Wrong type for input argument #%d: Scilab function expected.\n"),"macrovar",1)),
-end
-lst=macr2lst(macro);
-out=lst(2)',if prod(size(out))==0 then out =[],end
-in=lst(3)'
-vars=[]
-getted=[]
-[vars,getted]=listvars(lst)
-ng=prod(size(getted))
-globals=[],called=[]
-for k=1:ng
-  if (find(getted(k)==vars)==[])&(find(getted(k)==in)==[]) then 
-    clear w //to avoid redefinition warning (bug 1774)
-    ierr=execstr('w='+getted(k),'errcatch')
-    if ierr==0 then //the variable exists
-      if or(type(w)==[13 130 11]) then
-        called=[called;getted(k)]
-      else
-        globals=[globals;getted(k)]
-      end
-    else
-      globals=[globals;getted(k)]
-      lasterror(%t)  // clear the error (bug 2393)
-    end
-  end
-end
-locals=[]
-nl=prod(size(vars))
-for k=1:nl
-  if (find(vars(k)==in)==[])&(find(vars(k)==out)==[]) then 
-    locals=[locals;vars(k)]
-  end
-end
-vars=list(in,out,globals,called,locals)
-
-endfunction
-
-function [vars,getted]=listvars(lst)
-for lstk=lst
-  if type(lstk)==15 then
-    [vars,getted]=listvars(lstk)
-  else
-    if lstk(1)=='1'|lstk(1)=='for' then 
-      // case 1 retained for 2.7 and earlier versions
-       vars=[vars;addvar(lstk(2))],
-    elseif lstk(1)=='29' then 
-      nlhs=(size(lstk,'*')-2)/2
-      for k=0:nlhs-1
-       vars=[vars;addvar(lstk(3+2*k))],
-      end
-    elseif or(lstk(1)==['2','20']) then 
-       getted=[getted;addget(lstk(2))],
-    end
-  end
-end
-
-endfunction
-function vnam=addvar(vnam)
-if find(vnam==vars)<>[] then 
-  vnam=[]
-end
-
-endfunction
-function vnam=addget(vnam)
-if find(vnam==getted)<>[] then 
-  vnam=[]
-end
-endfunction
index 726fe99..a5f31c0 100644 (file)
     <ClCompile Include="sci_functionlist.cpp" />
     <ClCompile Include="sci_getCurrentThreadId.cpp" />
     <ClCompile Include="sci_getThreads.cpp" />
+    <ClCompile Include="sci_macrovar.cpp" />
     <ClCompile Include="sci_mode.cpp" />
     <ClCompile Include="sci_whereis.cpp" />
   </ItemGroup>
index d8a3242..588b87a 100644 (file)
@@ -36,6 +36,9 @@
     <ClCompile Include="sci_whereis.cpp">
       <Filter>Source Files</Filter>
     </ClCompile>
+    <ClCompile Include="sci_macrovar.cpp">
+      <Filter>Source Files</Filter>
+    </ClCompile>
   </ItemGroup>
   <ItemGroup>
     <ClInclude Include="..\..\includes\dynlib_functions_gw.h">
diff --git a/scilab/modules/functions/sci_gateway/cpp/sci_macrovar.cpp b/scilab/modules/functions/sci_gateway/cpp/sci_macrovar.cpp
new file mode 100644 (file)
index 0000000..578a30a
--- /dev/null
@@ -0,0 +1,136 @@
+/*
+* Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+* Copyright (C) 2013 - Scilab Enterprises - Antoine ELIAS
+*
+* This file must be used under the terms of the CeCILL.
+* This source file is licensed as described in the file COPYING, which
+* you should have received as part of this distribution.  The terms
+* are also available at
+* http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+*
+*/
+
+#include <string.h>
+#include "parser.hxx"
+#include "funcmanager.hxx"
+#include "context.hxx"
+#include "functions_gw.hxx"
+#include "macrovarvisitor.hxx"
+#include "list.hxx"
+
+#include <iostream>
+#include <fstream>
+#include <string>
+
+extern "C"
+{
+#include "Scierror.h"
+#include "localization.h"
+}
+
+using namespace types;
+using namespace ast;
+using namespace std;
+
+InternalType* createString(std::list<std::wstring>& lst);
+void addIn(MacrovarVisitor& pVisit, std::list<symbol::Symbol>* pSym);
+void addOut(MacrovarVisitor& pVisit, std::list<symbol::Symbol>* pSym);
+
+Function::ReturnValue sci_macrovar(types::typed_list &in, int _iRetCount, types::typed_list &out)
+{
+    if (in.size() != 1)
+    {
+        Scierror(999, _("%s: Wrong number of input arguments: %d expected.\n"), "macrovar" , 1);
+        return Function::Error;
+    }
+
+    if (_iRetCount != 1)
+    {
+        Scierror(999, _("%s: Wrong number of output arguments: %d expected.\n"), "macrovar" , 1);
+        return Function::Error;
+    }
+
+    Macro* pM = NULL;
+    switch (in[0]->getType())
+    {
+        case InternalType::RealMacro :
+        {
+            pM = in[0]->getAs<Macro>();
+            break;
+        }
+        case InternalType::RealMacroFile :
+        {
+            MacroFile* pMF = in[0]->getAs<MacroFile>();
+            pM = pMF->getMacro();
+            break;
+        }
+        default :
+            Scierror(999, _("%s: Wrong type for input arguments: macro expected.\n"), "macrovar");
+            return Function::Error;
+    }
+
+
+    MacrovarVisitor visit;
+
+    addIn(visit, pM->inputs_get());
+    addOut(visit, pM->outputs_get());
+
+    pM->getBody()->accept(visit);
+
+    List* pL = new List();
+
+    pL->append(createString(visit.getIn()));
+    pL->append(createString(visit.getOut()));
+    pL->append(createString(visit.getExternal()));
+    pL->append(createString(visit.getCalled()));
+    pL->append(createString(visit.getLocal()));
+
+    out.push_back(pL);
+    return Function::OK;
+}
+
+
+InternalType* createString(std::list<std::wstring>& lst)
+{
+    if (lst.size() == 0)
+    {
+        return Double::Empty();
+    }
+
+    String* pS = new String((int)lst.size(), 1);
+    std::list<std::wstring>::iterator it = lst.begin();
+    for (int i = 0 ; it != lst.end() ; it++, i++)
+    {
+        pS->set(i, (*it).c_str());
+    }
+
+    return pS;
+}
+
+void addOut(MacrovarVisitor& visit, std::list<symbol::Symbol>* pSym)
+{
+    if (pSym == 0 || pSym->size() == 0)
+    {
+        return;
+    }
+
+    std::list<symbol::Symbol>::iterator it = pSym->begin();
+    for (int i = 0 ; it != pSym->end() ; it++, i++)
+    {
+        visit.addOut((*it).name_get().c_str());
+    }
+}
+
+void addIn(MacrovarVisitor& visit, std::list<symbol::Symbol>* pSym)
+{
+    if (pSym == 0 || pSym->size() == 0)
+    {
+        return;
+    }
+
+    std::list<symbol::Symbol>::iterator it = pSym->begin();
+    for (int i = 0 ; it != pSym->end() ; it++, i++)
+    {
+        visit.addIn((*it).name_get().c_str());
+    }
+}
\ No newline at end of file
index a74df84..ae22971 100644 (file)
@@ -26,4 +26,5 @@
     <gateway name="sci_getCurrentThreadId"  function="getCurrentThreadId"   type="1" />
     <gateway name="sci_mode"                function="mode"                 type="1" />
     <gateway name="sci_getThreads"          function="getThreads"           type="1" />
+    <gateway name="sci_macrovar"            function="macrovar"           type="1" />
 </module>