From e351d7faee228acacc6cad893521ae10885e2a6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20DAVID?= Date: Fri, 31 Mar 2023 10:05:21 +0200 Subject: scilab: add a gateway xml v6 with full function names --- CHANGES.current | 6 +++-- Doc/Manual/Scilab.html | 21 ++++++++++++++- Source/Modules/scilab.cxx | 65 ++++++++++++++++++++++++++++++++++++++++++++--- 3 files changed, 85 insertions(+), 7 deletions(-) diff --git a/CHANGES.current b/CHANGES.current index ff60f6a03..f341d52b7 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -7,8 +7,10 @@ the issue number to the end of the URL: https://github.com/swig/swig/issues/ Version 4.2.0 (in progress) =========================== -2023-04-19: davidcl - [Scilab] Add support for Scilab 2023.x +2023-04-19: davidcl + [Scilab] Add support for Scilab 2023.x. + Introduce a `-gatewayxml6` options to generate an XML with full + function names. 2023-04-19: mmomtchev https://sourceforge.net/p/swig/bugs/1163/ #2525 Fix preprocessor diff --git a/Doc/Manual/Scilab.html b/Doc/Manual/Scilab.html index 650d52158..7d2c6a66e 100644 --- a/Doc/Manual/Scilab.html +++ b/Doc/Manual/Scilab.html @@ -303,6 +303,11 @@ The following table lists the Scilab specific command line options in addition t Generate the gateway XML with the given <gateway_id> + +-gatewayxml6 +Generate a gateway XML file compatible with Scilab 6 + +

@@ -2134,6 +2139,20 @@ clear get_file_path;

  • fcts: vector of character strings. The name of new Scilab function.
  • +

    36.7.3 Gateway XML files

    + +

    If you need to post-process the entry points, Scilab gateway files are XML files that can be used to retrieve all SWIG-generated entry points. With these XML files you can write your own builder_swig.sce file to add custom Scilab for building or linking the generated code. Documentation stubs can also be generated thanks to these function listings.

    +

    As an example, for a SWIG module named fmuswig the Scilab code below can be used to store all SWIG-generated functions in a variable named funs.

    +
    +  // src_swig_path is a path to the directory containing the fmuswig.i file
    +
    +  doc = xmlRead(src_swig_path + "/fmuswig_gateway.xml");
    +  names = xmlAsText(xmlXPath(doc, "//gateway/@name"));
    +  funs = xmlAsText(xmlXPath(doc, "//gateway/@function"));
    +  xmlDelete(doc);
    +
    +
    +

    36.8 Other resources

    @@ -2141,7 +2160,7 @@ clear get_file_path; diff --git a/Source/Modules/scilab.cxx b/Source/Modules/scilab.cxx index aabd2d842..fede06df2 100644 --- a/Source/Modules/scilab.cxx +++ b/Source/Modules/scilab.cxx @@ -26,6 +26,7 @@ Scilab options (available with -scilab)\n \ -buildersources - Add the (comma separated) files to the builder sources\n \ -builderverbositylevel - Set the builder verbosity level to (default 0: off, 2: high)\n \ -gatewayxml - Generate gateway xml with the given \n \ + -gatewayxml6 - Generate gateway xml for Scilab 6\n \ \n"; @@ -64,6 +65,10 @@ protected: String *gatewayID; int primitiveID; + bool createGatewayXMLV6; + File *gatewayXMLFileV6; + String *gatewayXMLV6; + bool createLoader; File *loaderFile; String *loaderScript; @@ -93,6 +98,10 @@ public: gatewayXMLFile = NULL; gatewayID = NULL; + createGatewayXMLV6 = false; + gatewayXMLV6 = NULL; + gatewayXMLFileV6 = NULL; + createLoader = true; loaderFile = NULL; loaderScript = NULL; @@ -141,6 +150,9 @@ public: createGatewayXML = true; gatewayID = NewString(argv[argIndex + 1]); Swig_mark_arg(argIndex + 1); + } else if (strcmp(argv[argIndex], "-gatewayxml6") == 0) { + Swig_mark_arg(argIndex); + createGatewayXMLV6 = true; } } } @@ -216,6 +228,11 @@ public: createGatewayXMLFile(gatewayName); } + // Create gateway XML V6 if required + if (createGatewayXMLV6) { + createGatewayXMLFileV6(gatewayName); + } + // Create loader script if required if (createLoader) { createLoaderFile(gatewayLibraryName); @@ -277,6 +294,9 @@ public: if (createGatewayXML) { saveGatewayXMLFile(); } + if (createGatewayXMLV6) { + saveGatewayXMLFileV6(); + } if (createLoader) { saveLoaderFile(gatewayLibraryName); @@ -360,7 +380,7 @@ public: int maxInputArguments = emit_num_arguments(functionParamsList); int minInputArguments = emit_num_required(functionParamsList); int minOutputArguments = 0; - int maxOutputArguments = 1; + int maxOutputArguments = 0; if (!emit_isvarargs(functionParamsList)) { Printf(wrapper->code, "SWIG_CheckInputArgument(pvApiCtx, $mininputarguments, $maxinputarguments);\n"); @@ -812,6 +832,10 @@ public: if (gatewayXMLFile) { Printf(gatewayXML, "\n", gatewayID, primitiveID++, scilabSmallFunctionName); } + + if (gatewayXMLFileV6) { + Printf(gatewayXMLV6, "\n", scilabFunctionName, scilabFunctionName); + } } @@ -941,6 +965,39 @@ public: Delete(builderFile); } + /* ----------------------------------------------------------------------- + * createGatewayXMLFileV6() + * This XML file is used by Scilab 6 in the context of internal modules or + * to get the function list. + * ----------------------------------------------------------------------- */ + + void createGatewayXMLFileV6(String *gatewayName) { + String *gatewayXMLFilename = NewStringf("%s_gateway.xml", gatewayName); + gatewayXMLFileV6 = NewFile(gatewayXMLFilename, "w", SWIG_output_files()); + if (!gatewayXMLFileV6) { + FileErrorDisplay(gatewayXMLFilename); + Exit(EXIT_FAILURE); + } + // Add a slightly modified SWIG banner to the gateway XML ("--modify" is illegal in XML) + gatewayXMLV6 = NewString(""); + Printf(gatewayXMLV6, "\n"); + Printf(gatewayXMLV6, "\n"); + Printf(gatewayXMLV6, "\n"); + Printf(gatewayXMLV6, "\n", gatewayName); + } + + /* ----------------------------------------------------------------------- + * saveGatewayXMLFileV6() + * ----------------------------------------------------------------------- */ + + void saveGatewayXMLFileV6() { + Printf(gatewayXMLV6, "\n"); + Printv(gatewayXMLFileV6, gatewayXMLV6, NIL); + Delete(gatewayXMLFileV6); + } + /* ----------------------------------------------------------------------- * createGatewayXMLFile() * This XML file is used by Scilab in the context of internal modules @@ -1046,10 +1103,10 @@ public: Printf(gatewayHeaderV6, "return 1;\n"); Printf(gatewayHeaderV6, "};\n"); - Printf(gatewayHeader, "#if SWIG_SCILAB_VERSION >= 600\n"); - Printv(gatewayHeader, gatewayHeaderV6, NIL); - Printf(gatewayHeader, "#else\n"); + Printf(gatewayHeader, "#if SCI_VERSION_MAJOR < 6\n"); Printv(gatewayHeader, gatewayHeaderV5, NIL); + Printf(gatewayHeader, "#else\n"); + Printv(gatewayHeader, gatewayHeaderV6, NIL); Printf(gatewayHeader, "#endif\n"); } -- cgit v1.2.1