management of overload in iconvert. 86/11486/7
Cedric Delamarre [Tue, 14 May 2013 08:54:36 +0000 (10:54 +0200)]
Change-Id: I0aeeb44dd197ccaef48a21fcfd538c324fa0c370

scilab/modules/api_scilab/src/cpp/overload.cpp
scilab/modules/integer/Makefile.am
scilab/modules/integer/Makefile.in
scilab/modules/integer/includes/integer_gw.hxx
scilab/modules/integer/macros/%_iconvert.sci [moved from scilab/modules/integer/macros/iconvert.sci with 58% similarity]
scilab/modules/integer/sci_gateway/cpp/integer_gw.cpp
scilab/modules/integer/sci_gateway/cpp/sci_iconvert.cpp [new file with mode: 0644]
scilab/modules/integer/src/cpp/integer_gw.vcxproj
scilab/modules/integer/src/cpp/integer_gw.vcxproj.filters

index 3b59d61..dcc882e 100644 (file)
@@ -52,13 +52,29 @@ types::Function::ReturnValue Overload::call(std::wstring _stOverloadingFunctionN
 
     if (pIT == NULL || pIT->isCallable() == false)
     {
+        char pstError1[512];
+        char pstError2[512];
+        char *pstFuncName = wide_string_to_UTF8(_stOverloadingFunctionName.c_str());
+        wchar_t* pwstError = NULL;
         if (_isOperator)
         {
-            throw ast::ScilabError(_W("Undefined operation for the given operands.\ncheck or define function ") + _stOverloadingFunctionName + _W(" for overloading.\n"), 144, *new Location());
+            sprintf(pstError2, _("  check or define function %s for overloading.\n"), pstFuncName);
+            sprintf(pstError1, "%s%s", _("Undefined operation for the given operands.\n"), pstError2);
+            pwstError = to_wide_string(pstError1);
+            std::wstring wstError(pwstError);
+            FREE(pwstError);
+            FREE(pstFuncName);
+            throw ast::ScilabError(wstError, 144, *new Location());
         }
         else
         {
-            throw ast::ScilabError(_W("Function not defined for given argument type(s),\n  check arguments or define function ") + _stOverloadingFunctionName + _W(" for overloading.\n"), 246, *new Location());
+            sprintf(pstError2, _("  check arguments or define function %s for overloading.\n"), pstFuncName);
+            sprintf(pstError1, "%s%s", _("Function not defined for given argument type(s),\n"), pstError2);
+            pwstError = to_wide_string(pstError1);
+            std::wstring wstError(pwstError);
+            FREE(pwstError);
+            FREE(pstFuncName);
+            throw ast::ScilabError(wstError, 246, *new Location());
         }
     }
     types::Callable *pCall = pIT->getAs<types::Callable>();
index 73f32d4..8393388 100644 (file)
@@ -74,7 +74,8 @@ GATEWAY_CPP_SOURCES = \
                                sci_gateway/cpp/integer_gw.cpp \
                                sci_gateway/cpp/sci_inttype.cpp \
                                sci_gateway/cpp/sci_double.cpp \
-                               sci_gateway/cpp/sci_int.cpp
+                               sci_gateway/cpp/sci_int.cpp \
+                               sci_gateway/cpp/sci_iconvert.cpp
 
 GATEWAY_FORTRAN_SOURCES = \
 sci_gateway/fortran/sci_i_mput.f \
@@ -101,6 +102,11 @@ libsciinteger_la_CPPFLAGS = -I$(srcdir)/includes/ \
                                -I$(top_srcdir)/modules/ast/includes/ \
                                -I$(top_srcdir)/modules/symbol/includes/ \
                                -I$(top_srcdir)/modules/dynamic_link/includes/ \
+                               -I$(top_srcdir)/modules/system_env/includes/ \
+                               -I$(top_srcdir)/modules/threads/includes/ \
+                               -I$(top_srcdir)/modules/string/includes/ \
+                               -I$(top_srcdir)/modules/console/includes/ \
+                               $(EIGEN_CPPFLAGS)
                                $(AM_CPPFLAGS)
 
 if MAINTAINER_MODE
index 18cf03f..d111bc6 100644 (file)
@@ -184,7 +184,7 @@ am__objects_4 = sci_i_mput.lo sci_int32.lo sci_int16.lo sci_mgeti.lo \
        sci_i_triu.lo sci_inttype.lo
 am__objects_5 = libsciinteger_la-integer_gw.lo \
        libsciinteger_la-sci_inttype.lo libsciinteger_la-sci_double.lo \
-       libsciinteger_la-sci_int.lo
+       libsciinteger_la-sci_int.lo libsciinteger_la-sci_iconvert.lo
 am_libsciinteger_la_OBJECTS = $(am__objects_3) $(am__objects_4) \
        $(am__objects_5)
 libsciinteger_la_OBJECTS = $(am_libsciinteger_la_OBJECTS)
@@ -567,7 +567,8 @@ GATEWAY_CPP_SOURCES = \
                                sci_gateway/cpp/integer_gw.cpp \
                                sci_gateway/cpp/sci_inttype.cpp \
                                sci_gateway/cpp/sci_double.cpp \
-                               sci_gateway/cpp/sci_int.cpp
+                               sci_gateway/cpp/sci_int.cpp \
+                               sci_gateway/cpp/sci_iconvert.cpp
 
 GATEWAY_FORTRAN_SOURCES = \
 sci_gateway/fortran/sci_i_mput.f \
@@ -594,7 +595,11 @@ libsciinteger_la_CPPFLAGS = -I$(srcdir)/includes/ \
                                -I$(top_srcdir)/modules/ast/includes/ \
                                -I$(top_srcdir)/modules/symbol/includes/ \
                                -I$(top_srcdir)/modules/dynamic_link/includes/ \
-                               $(AM_CPPFLAGS)
+                               -I$(top_srcdir)/modules/system_env/includes/ \
+                               -I$(top_srcdir)/modules/threads/includes/ \
+                               -I$(top_srcdir)/modules/string/includes/ \
+                               -I$(top_srcdir)/modules/console/includes/ \
+                               $(EIGEN_CPPFLAGS)
 
 @MAINTAINER_MODE_TRUE@pkglib_LTLIBRARIES = libsciinteger.la
 @MAINTAINER_MODE_FALSE@noinst_LTLIBRARIES = libsciinteger-algo.la libsciinteger.la
@@ -820,6 +825,7 @@ distclean-compile:
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libsciinteger_la-gw_integer.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libsciinteger_la-integer_gw.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libsciinteger_la-sci_double.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libsciinteger_la-sci_iconvert.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libsciinteger_la-sci_int.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libsciinteger_la-sci_inttype.Plo@am__quote@
 
@@ -1131,6 +1137,13 @@ libsciinteger_la-sci_int.lo: sci_gateway/cpp/sci_int.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) $(libsciinteger_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o libsciinteger_la-sci_int.lo `test -f 'sci_gateway/cpp/sci_int.cpp' || echo '$(srcdir)/'`sci_gateway/cpp/sci_int.cpp
 
+libsciinteger_la-sci_iconvert.lo: sci_gateway/cpp/sci_iconvert.cpp
+@am__fastdepCXX_TRUE@  $(LIBTOOL)  --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libsciinteger_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT libsciinteger_la-sci_iconvert.lo -MD -MP -MF $(DEPDIR)/libsciinteger_la-sci_iconvert.Tpo -c -o libsciinteger_la-sci_iconvert.lo `test -f 'sci_gateway/cpp/sci_iconvert.cpp' || echo '$(srcdir)/'`sci_gateway/cpp/sci_iconvert.cpp
+@am__fastdepCXX_TRUE@  $(am__mv) $(DEPDIR)/libsciinteger_la-sci_iconvert.Tpo $(DEPDIR)/libsciinteger_la-sci_iconvert.Plo
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@     source='sci_gateway/cpp/sci_iconvert.cpp' object='libsciinteger_la-sci_iconvert.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) $(libsciinteger_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o libsciinteger_la-sci_iconvert.lo `test -f 'sci_gateway/cpp/sci_iconvert.cpp' || echo '$(srcdir)/'`sci_gateway/cpp/sci_iconvert.cpp
+
 .f.o:
        $(F77COMPILE) -c -o $@ $<
 
@@ -1555,6 +1568,7 @@ uninstall-am: uninstall-libsciinteger_la_etcDATA \
        uninstall-libsciinteger_la_sci_gatewayDATA \
        uninstall-pkglibLTLIBRARIES
 
+                               $(AM_CPPFLAGS)
 
 # This target enables tests for Scilab
 check-local: $(top_builddir)/scilab-bin test
index a92fd1e..dc3b874 100644 (file)
 class IntegerModule
 {
 private :
-       IntegerModule(){};
-       ~IntegerModule(){};
+    IntegerModule() {};
+    ~IntegerModule() {};
 public :
-       INTEGER_GW_IMPEXP static int Load();
+    INTEGER_GW_IMPEXP static int Load();
 };
 
 CPP_GATEWAY_PROTOTYPE(sci_inttype);
 CPP_GATEWAY_PROTOTYPE(sci_double);
+CPP_GATEWAY_PROTOTYPE(sci_iconvert);
 //YaSp
 CPP_GATEWAY_PROTOTYPE(sci_integer8);
 CPP_GATEWAY_PROTOTYPE(sci_uinteger8);
similarity index 58%
rename from scilab/modules/integer/macros/iconvert.sci
rename to scilab/modules/integer/macros/%_iconvert.sci
index 693b446..63c1a5c 100644 (file)
@@ -7,30 +7,7 @@
 // are also available at
 // http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
 
-
-function x = iconvert(a,typeToConvert)
-
-    [lhs, rhs] = argn();
-
-    if rhs <> 2 then
-        error(msprintf(_("%s: Wrong number of input argument(s): %d expected.\n"), "iconvert", 2));
-    end
-
-    if lhs <> 1 then
-        error(msprintf(_("%s: Wrong number of output argument(s): %d expected.\n"), "iconvert", 1));
-    end
-
-    if typeof(a) <> "constant" & type(a) <> 8 & typeof(a) <> "boolean" then
-        error(msprintf(_("%s: Wrong type for input argument #%d: ''%s'', ''%s'' or ''%s'' expected.\n"), "iconvert", 1, "integer", "boolean", "double"));
-    end
-
-    if typeof(a) == "constant" & isreal(a) == %f then
-        error(msprintf(_("%s: Wrong type for argument #%d: Real matrix expected.\n"), "iconvert", 1));
-    end
-
-    if floor(typeToConvert) <> typeToConvert then
-        error(msprintf(_("%s: Wrong value for input argument #%d: An integer value expected.\n"), "iconvert", 2));
-    end
+function x = %_iconvert(a,typeToConvert)
 
     if typeof(typeToConvert) <> "constant" | size(typeToConvert, "*") <> 1 then
         error(msprintf(_("%s: Wrong size for argument #%d: Real scalar expected.\n"), "iconvert", 2));
index eddd757..0f8d340 100644 (file)
@@ -34,5 +34,6 @@ int IntegerModule::Load()
     symbol::Context::getInstance()->addFunction(Function::createFunction(L"uint64", &sci_uinteger64, MODULE_NAME));
     symbol::Context::getInstance()->addFunction(Function::createFunction(L"inttype", &sci_inttype, MODULE_NAME));
     symbol::Context::getInstance()->addFunction(Function::createFunction(L"double", &sci_double, MODULE_NAME));
+    symbol::Context::getInstance()->addFunction(Function::createFunction(L"iconvert", &sci_iconvert, MODULE_NAME));
     return 1;
 }
diff --git a/scilab/modules/integer/sci_gateway/cpp/sci_iconvert.cpp b/scilab/modules/integer/sci_gateway/cpp/sci_iconvert.cpp
new file mode 100644 (file)
index 0000000..c0853d8
--- /dev/null
@@ -0,0 +1,47 @@
+/*
+ *  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 "integer_gw.hxx"
+#include "function.hxx"
+#include "overload.hxx"
+#include "execvisitor.hxx"
+
+extern "C"
+{
+#include "Scierror.h"
+#include "localization.h"
+}
+
+types::Function::ReturnValue sci_iconvert(types::typed_list &in, int _iRetCount, types::typed_list &out)
+{
+    if (in.size() != 2)
+    {
+        Scierror(77, _("%s: Wrong number of input argument(s): %d expected.\n"), "iconvert", 2);
+        return types::Function::Error;
+    }
+
+    if(_iRetCount > 1)
+    {
+        Scierror(78, _("%s: Wrong number of output argument(s): %d expected.\n"), "iconvert", 1);
+        return types::Function::Error;
+    }
+
+    if(in[0]->isInt() == false && in[0]->isDouble() == false && in[0]->isBool() == false)
+    {
+        // call overload
+        std::wstring wstFuncName = L"%"  + in[0]->getShortTypeStr() + L"_iconvert";
+        return Overload::call(wstFuncName, in, _iRetCount, out, new ExecVisitor());
+    }
+
+    // perfom operation
+    return Overload::call(L"%_iconvert", in, _iRetCount, out, new ExecVisitor());
+}
index 546fb4c..c073af8 100644 (file)
     </Midl>
     <ClCompile>
       <Optimization>Disabled</Optimization>
-      <AdditionalIncludeDirectories>../../includes;../../../functions_manager/includes;../../../types/includes;../../../symbol/includes;../../../ast/includes;../../../elementary_functions/includes;../../../core/includes;../../../operations/includes;../../../api_scilab/includes;../../../localization/includes;../../../output_stream/includes;../../../../libs/intl;../../../dynamic_link/includes;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+      <AdditionalIncludeDirectories>../../includes;../../../functions_manager/includes;../../../types/includes;../../../symbol/includes;../../../ast/includes;../../../elementary_functions/includes;../../../core/includes;../../../operations/includes;../../../api_scilab/includes;../../../localization/includes;../../../output_stream/includes;../../../../libs/intl;../../../dynamic_link/includes;../../../system_env/includes;../../../threads/includes;../../../string/includes;../../../console/includes;../../../../libs/Eigen/includes;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
       <PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;_USRDLL;INTEGER_GW_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
       <MinimalRebuild>true</MinimalRebuild>
       <BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
   <ItemGroup>
     <ClCompile Include="..\..\sci_gateway\cpp\integer_gw.cpp" />
     <ClCompile Include="..\..\sci_gateway\cpp\sci_double.cpp" />
+    <ClCompile Include="..\..\sci_gateway\cpp\sci_iconvert.cpp" />
     <ClCompile Include="..\..\sci_gateway\cpp\sci_int.cpp" />
     <ClCompile Include="..\..\sci_gateway\cpp\sci_inttype.cpp" />
   </ItemGroup>
       <Project>{43c5bab1-1dca-4743-a183-77e0d42fe7d0}</Project>
       <ReferenceOutputAssembly>false</ReferenceOutputAssembly>
     </ProjectReference>
+    <ProjectReference Include="..\..\..\ast\ast.vcxproj">
+      <Project>{0d3fa25b-8116-44ec-a45e-260789daa3d9}</Project>
+    </ProjectReference>
+    <ProjectReference Include="..\..\..\console\src\c\console.vcxproj">
+      <Project>{445d3b85-c9b1-498b-9c88-0a3c2390b1cc}</Project>
+    </ProjectReference>
+    <ProjectReference Include="..\..\..\core\src\c\core.vcxproj">
+      <Project>{c6e2bc17-34d8-46e4-85f3-6293cb21adcd}</Project>
+    </ProjectReference>
     <ProjectReference Include="..\..\..\localization\src\localization.vcxproj">
       <Project>{ecffeb0c-1eda-45ee-9a10-b18143852e17}</Project>
       <ReferenceOutputAssembly>false</ReferenceOutputAssembly>
     </ProjectReference>
+    <ProjectReference Include="..\..\..\operations\operations.vcxproj">
+      <Project>{1bb396f7-ce61-4cfc-9c22-266b2cfb2e74}</Project>
+    </ProjectReference>
     <ProjectReference Include="..\..\..\output_stream\src\c\output_stream.vcxproj">
       <Project>{a5911cd7-f8e8-440c-a23e-4843a0636f3a}</Project>
       <ReferenceOutputAssembly>false</ReferenceOutputAssembly>
     </ProjectReference>
+    <ProjectReference Include="..\..\..\string\src\c\string.vcxproj">
+      <Project>{8d45767a-9b03-4905-97f6-d2f3f79141ea}</Project>
+    </ProjectReference>
     <ProjectReference Include="..\..\..\symbol\symbol.vcxproj">
       <Project>{2c60033b-0dbd-4ca4-80d3-176c9be9ce2f}</Project>
       <ReferenceOutputAssembly>false</ReferenceOutputAssembly>
     </ProjectReference>
+    <ProjectReference Include="..\..\..\system_env\system_env.vcxproj">
+      <Project>{7ca60aef-9afa-4d06-af28-613c0aa27640}</Project>
+    </ProjectReference>
+    <ProjectReference Include="..\..\..\threads\threads.vcxproj">
+      <Project>{50a1ffc8-adc2-4d9e-a2d0-5dcd63188ae9}</Project>
+    </ProjectReference>
     <ProjectReference Include="..\..\..\types\types.vcxproj">
       <Project>{64e090da-dcb5-4f4d-93d7-e88ddec9c2ef}</Project>
       <ReferenceOutputAssembly>false</ReferenceOutputAssembly>
     </ProjectReference>
+    <ProjectReference Include="..\..\..\types\typesmacro\typesmacro.vcxproj">
+      <Project>{9252a034-7f22-4cb1-a634-4577da69f2d0}</Project>
+    </ProjectReference>
     <ProjectReference Include="..\c\integer.vcxproj">
       <Project>{c7865caa-ec7c-41eb-8324-2b81c384ca20}</Project>
       <ReferenceOutputAssembly>false</ReferenceOutputAssembly>
index cc4bf42..f16f2f2 100644 (file)
@@ -27,6 +27,9 @@
     <ClCompile Include="..\..\sci_gateway\cpp\sci_int.cpp">
       <Filter>Source Files</Filter>
     </ClCompile>
+    <ClCompile Include="..\..\sci_gateway\cpp\sci_iconvert.cpp">
+      <Filter>Source Files</Filter>
+    </ClCompile>
   </ItemGroup>
   <ItemGroup>
     <ClInclude Include="..\..\includes\dynlib_integer_gw.h">