where function plugged. 86/12386/4
Cedric Delamarre [Fri, 30 Aug 2013 07:29:11 +0000 (09:29 +0200)]
Change-Id: Ide5b909c05740cf2f83cabafc807f6af431bb7d5

scilab/modules/ast/includes/run_CallExp.hxx
scilab/modules/core/Makefile.am
scilab/modules/core/Makefile.in
scilab/modules/core/includes/core_gw.hxx
scilab/modules/core/sci_gateway/c/sci_where.c [deleted file]
scilab/modules/core/sci_gateway/cpp/core_gw.cpp
scilab/modules/core/sci_gateway/cpp/core_gw.vcxproj
scilab/modules/core/sci_gateway/cpp/core_gw.vcxproj.filters
scilab/modules/core/sci_gateway/cpp/sci_where.cpp [new file with mode: 0644]
scilab/modules/system_env/includes/configvariable.hxx
scilab/modules/system_env/src/cpp/configvariable.cpp

index a5bab15..1aab68d 100644 (file)
@@ -120,8 +120,12 @@ void visitprivate(const CallExp &e)
             ConfigVariable::resetError();
             //update verbose";" flag
             ConfigVariable::setVerbose(e.is_verbose());
+            // add line and function name in where
+            ConfigVariable::where_begin((int)e.location_get().first_line, pCall->getName());
             //call function
             types::Function::ReturnValue Ret = pCall->call(in, opt, iRetCount, out, this);
+            // remove the last call from where
+            ConfigVariable::where_end();
             expected_setSize(iSaveExpectedSize);
             result_clear();
 
@@ -173,6 +177,9 @@ void visitprivate(const CallExp &e)
         }
         catch (ScilabMessage sm)
         {
+            // remove the last call from where
+            ConfigVariable::where_end();
+
             //clear input parameters
             for (unsigned int k = 0; k < in.size(); k++)
             {
index e82a07c..d8ed627 100644 (file)
@@ -168,7 +168,8 @@ GATEWAY_CPP_SOURCES =       \
        sci_gateway/cpp/sci_ieee.cpp \
        sci_gateway/cpp/sci_funcprot.cpp \
        sci_gateway/cpp/sci_mode.cpp \
-       sci_gateway/cpp/sci_typename.cpp
+       sci_gateway/cpp/sci_typename.cpp \
+       sci_gateway/cpp/sci_where.cpp
 
 
 libscicore_la_CPPFLAGS = \
index 0ea6f44..7711b65 100644 (file)
@@ -283,7 +283,7 @@ am__objects_8 = libscicore_la-core_gw.lo \
        libscicore_la-sci_stacksize.lo libscicore_la-sci_format.lo \
        libscicore_la-sci_sciargs.lo libscicore_la-sci_ieee.lo \
        libscicore_la-sci_funcprot.lo libscicore_la-sci_mode.lo \
-       libscicore_la-sci_typename.lo
+       libscicore_la-sci_typename.lo libscicore_la-sci_where.lo
 am_libscicore_la_OBJECTS = $(am__objects_6) $(am__objects_7) \
        $(am__objects_8)
 libscicore_la_OBJECTS = $(am_libscicore_la_OBJECTS)
@@ -693,7 +693,8 @@ GATEWAY_CPP_SOURCES = \
        sci_gateway/cpp/sci_ieee.cpp \
        sci_gateway/cpp/sci_funcprot.cpp \
        sci_gateway/cpp/sci_mode.cpp \
-       sci_gateway/cpp/sci_typename.cpp
+       sci_gateway/cpp/sci_typename.cpp \
+       sci_gateway/cpp/sci_where.cpp
 
 libscicore_la_CPPFLAGS = -I$(srcdir)/includes/ -I$(srcdir)/src/c/ \
        -I$(srcdir)/src/cpp/ \
@@ -1052,6 +1053,7 @@ distclean-compile:
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libscicore_la-sci_type.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libscicore_la-sci_typename.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libscicore_la-sci_warning.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libscicore_la-sci_where.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libscicore_la-sci_who.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libscicore_la-sci_with_module.Plo@am__quote@
 
@@ -1783,6 +1785,13 @@ libscicore_la-sci_typename.lo: sci_gateway/cpp/sci_typename.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) $(libscicore_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o libscicore_la-sci_typename.lo `test -f 'sci_gateway/cpp/sci_typename.cpp' || echo '$(srcdir)/'`sci_gateway/cpp/sci_typename.cpp
 
+libscicore_la-sci_where.lo: sci_gateway/cpp/sci_where.cpp
+@am__fastdepCXX_TRUE@  $(LIBTOOL)  --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libscicore_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT libscicore_la-sci_where.lo -MD -MP -MF $(DEPDIR)/libscicore_la-sci_where.Tpo -c -o libscicore_la-sci_where.lo `test -f 'sci_gateway/cpp/sci_where.cpp' || echo '$(srcdir)/'`sci_gateway/cpp/sci_where.cpp
+@am__fastdepCXX_TRUE@  $(am__mv) $(DEPDIR)/libscicore_la-sci_where.Tpo $(DEPDIR)/libscicore_la-sci_where.Plo
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@     source='sci_gateway/cpp/sci_where.cpp' object='libscicore_la-sci_where.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) $(libscicore_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o libscicore_la-sci_where.lo `test -f 'sci_gateway/cpp/sci_where.cpp' || echo '$(srcdir)/'`sci_gateway/cpp/sci_where.cpp
+
 .f.o:
        $(F77COMPILE) -c -o $@ $<
 
index 0d32e7d..785fbda 100644 (file)
@@ -55,5 +55,6 @@ CPP_GATEWAY_PROTOTYPE(sci_ieee);
 CPP_GATEWAY_PROTOTYPE(sci_funcprot);
 CPP_GATEWAY_PROTOTYPE(sci_mode);
 CPP_GATEWAY_PROTOTYPE(sci_typename);
+CPP_GATEWAY_PROTOTYPE(sci_where);
 
 #endif /* __CORE_GW_HXX__ */
diff --git a/scilab/modules/core/sci_gateway/c/sci_where.c b/scilab/modules/core/sci_gateway/c/sci_where.c
deleted file mode 100644 (file)
index 51cb4c5..0000000
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
- * Copyright (C) 2006 - INRIA - Allan CORNET
- *
- * 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 "gw_core.h"
-#include "api_scilab.h"
-#include "Scierror.h"
-#include "localization.h"
-/*--------------------------------------------------------------------------*/
-extern int C2F(where)(void);
-/*--------------------------------------------------------------------------*/
-int C2F(sci_where)(char *fname, void* pvApiCtx)
-{
-    if (Rhs > 0)
-    {
-        Scierror(39, _("%s: Wrong number of input arguments.\n"), "where");
-        return 0;
-    }
-
-    if (Lhs != 2)
-    {
-        Scierror(41, _("%s: Wrong number of output arguments: %d expected.\n"), "where", 2);
-        return 0;
-    }
-
-    C2F(where)();
-    return 0;
-}
-/*--------------------------------------------------------------------------*/
index 6e0c293..0d2f4de 100644 (file)
@@ -54,5 +54,6 @@ int CoreModule::Load()
     symbol::Context::getInstance()->addFunction(Function::createFunction(L"typename", &sci_typename, MODULE_NAME));
     symbol::Context::getInstance()->addFunction(Function::createFunction(L"funcprot", &sci_funcprot, MODULE_NAME));
     symbol::Context::getInstance()->addFunction(Function::createFunction(L"mode", &sci_mode, MODULE_NAME));
+    symbol::Context::getInstance()->addFunction(Function::createFunction(L"where", &sci_where, MODULE_NAME));
     return 1;
 }
index 6397147..3f4e1d5 100644 (file)
     <ClCompile Include="sci_stacksize.cpp" />
     <ClCompile Include="sci_typename.cpp" />
     <ClCompile Include="sci_warning.cpp" />
+    <ClCompile Include="sci_where.cpp" />
     <ClCompile Include="sci_who.cpp" />
     <ClCompile Include="sci_with_module.cpp" />
   </ItemGroup>
index 6d36575..7594bec 100644 (file)
     <ClCompile Include="sci_typename.cpp">
       <Filter>Source Files</Filter>
     </ClCompile>
+    <ClCompile Include="sci_where.cpp">
+      <Filter>Source Files</Filter>
+    </ClCompile>
   </ItemGroup>
   <ItemGroup>
     <ClInclude Include="..\..\includes\banner.hxx">
diff --git a/scilab/modules/core/sci_gateway/cpp/sci_where.cpp b/scilab/modules/core/sci_gateway/cpp/sci_where.cpp
new file mode 100644 (file)
index 0000000..db0fbd1
--- /dev/null
@@ -0,0 +1,65 @@
+/*
+ *  Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ *  Copyright (C) 2013 - scilab Enterprises - Cedric Delamarre
+ *
+ *  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 "core_gw.hxx"
+#include "function.hxx"
+#include "configvariable.hxx"
+#include "double.hxx"
+#include "string.hxx"
+
+extern "C"
+{
+#include "localization.h"
+#include "Scierror.h"
+}
+
+types::Function::ReturnValue sci_where(types::typed_list &in, int _iRetCount, types::typed_list &out)
+{
+    if (in.size() != 0)
+    {
+        Scierror(77, _("%s: Wrong number of input argument(s): %d expected."), "where", 0);
+        return types::Function::Error;
+    }
+
+    if (_iRetCount != 2)
+    {
+        Scierror(78, _("%s: Wrong number of output argument(s): %d expected."), "where", 2);
+        return types::Function::Error;
+    }
+
+    std::list<std::pair<int, std::wstring> > lWhereAmI = ConfigVariable::getWhere();
+    if (lWhereAmI.size() == 1)
+    {
+        out.push_back(types::Double::Empty());
+        out.push_back(types::Double::Empty());
+        return types::Function::OK;
+    }
+
+    std::list<std::pair<int, std::wstring> >::const_iterator it;
+    types::Double* pDblLines = new types::Double(lWhereAmI.size() - 1, 1);
+    types::String* pStrNames = new types::String(lWhereAmI.size() - 1, 1);
+
+    it = lWhereAmI.begin();
+    pStrNames->set(0, it->second.c_str());
+    it++;
+    for (int i = 0; it != lWhereAmI.end(); it++, i++)
+    {
+        pDblLines->set(i, (double)(it->first));
+        pStrNames->set(i + 1, it->second.c_str());
+    }
+
+    pDblLines->set(lWhereAmI.size() - 1, (double)(lWhereAmI.back().first));
+
+    out.push_back(pDblLines);
+    out.push_back(pStrNames);
+    return types::Function::OK;
+}
index 3943a7b..a693cac 100644 (file)
@@ -342,6 +342,15 @@ private :
 public :
     static void setFuncprot(int _iFuncprot);
     static int getFuncprot();
+
+    // where
+private :
+    static std::list< std::pair<int, std::wstring> > m_Where;
+public :
+    static void where_begin(int _iLineNum, std::wstring _wstName);
+    static void where_end();
+    static std::list< std::pair<int, std::wstring> >& getWhere();
+
 };
 
 #endif /* !__CONFIGVARIABLE_HXX__ */
index bdecb48..bf46c79 100644 (file)
@@ -967,3 +967,27 @@ int ConfigVariable::getFuncprot()
 /*
 ** \}
 */
+
+/*
+** where
+** \{
+*/
+
+std::list< std::pair<int, std::wstring> > ConfigVariable::m_Where;
+
+void ConfigVariable::where_begin(int _iLineNum, std::wstring _wstName)
+{
+    m_Where.push_back(std::pair<int, std::wstring>(_iLineNum, _wstName));
+}
+void ConfigVariable::where_end()
+{
+    m_Where.pop_back();
+}
+std::list< std::pair<int, std::wstring> >& ConfigVariable::getWhere()
+{
+    return m_Where;
+}
+
+/*
+** \}
+*/