summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClément DAVID <clement.david@3ds.com>2023-03-31 10:05:21 +0200
committerOlly Betts <olly@survex.com>2023-04-20 07:34:19 +1200
commite351d7faee228acacc6cad893521ae10885e2a6b (patch)
tree382fc0fd0d6338ef35be92108610de0ebc84ded1
parent321cc1bf33c007a9f69853ea70307b373f115caa (diff)
downloadswig-e351d7faee228acacc6cad893521ae10885e2a6b.tar.gz
scilab: add a gateway xml v6 with full function names
-rw-r--r--CHANGES.current6
-rw-r--r--Doc/Manual/Scilab.html21
-rw-r--r--Source/Modules/scilab.cxx65
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
<td>Generate the gateway XML with the given &lt;gateway_id&gt;</td>
</tr>
+<tr>
+<td><tt>-gatewayxml6</tt></td>
+<td>Generate a gateway XML file compatible with Scilab 6</td>
+</tr>
+
</table>
<p>
@@ -2134,6 +2139,20 @@ clear get_file_path;
<li><tt><b>fcts</b></tt>: vector of character strings. The name of new Scilab function.</li>
</ul>
+<H3><a name="Scilab_generated_scripts_gateway">36.7.3 Gateway XML files</a></H3>
+
+<p>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 <tt>builder_swig.sce</tt> file to add custom Scilab for building or linking the generated code. Documentation stubs can also be generated thanks to these function listings.</tt></p>
+<p>As an example, for a SWIG <a href="Modules.html">module</a> named <tt>fmuswig</tt> the Scilab code below can be used to store all SWIG-generated functions in a variable named <tt>funs</tt></tt>.</p>
+<div class="code"><pre>
+ // 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);
+
+</pre></div>
+
<H2><a name="Scilab_other_resources">36.8 Other resources</a></H2>
@@ -2141,7 +2160,7 @@ clear get_file_path;
<ul>
<li>Example use cases can be found in the <tt>Examples/scilab</tt> directory.</li>
<li>The test suite in the <tt>Examples/test-suite/scilab</tt> can be another source of useful use cases.</li>
-<li>The <a href="https://help.scilab.org/docs/5.5.0/en_US/api_scilab.html">Scilab API</a> is used in the generated code and is a useful reference when examining the output.</li>
+<li>The <a href="https://help.scilab.org/api_scilab.html">Scilab API</a> is used in the generated code and is a useful reference when examining the output.</li>
<li>This <a href="https://wiki.scilab.org/howto/Create%20a%20toolbox">guide</a> describes the Scilab external modules structure and files, in particular the files that are generated by SWIG for Scilab.</li>
</ul>
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 <files> - Add the (comma separated) files <files> to the builder sources\n \
-builderverbositylevel <level> - Set the builder verbosity level to <level> (default 0: off, 2: high)\n \
-gatewayxml <gateway_id> - Generate gateway xml with the given <gateway_id>\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, "<PRIMITIVE gatewayId=\"%s\" primitiveId=\"%d\" primitiveName=\"%s\"/>\n", gatewayID, primitiveID++, scilabSmallFunctionName);
}
+
+ if (gatewayXMLFileV6) {
+ Printf(gatewayXMLV6, "<gateway name=\"%s\" function=\"%s\" type=\"0\"/>\n", scilabFunctionName, scilabFunctionName);
+ }
}
@@ -942,6 +966,39 @@ public:
}
/* -----------------------------------------------------------------------
+ * 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, "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n");
+ Printf(gatewayXMLV6, "<!DOCTYPE module SYSTEM \"../../functions/xml/gateway.dtd\">\n");
+ Printf(gatewayXMLV6, "<!--\n");
+ Swig_banner_target_lang(gatewayXMLV6, "");
+ Printf(gatewayXMLV6, "-->\n");
+ Printf(gatewayXMLV6, "<module name=\"%s\">\n", gatewayName);
+ }
+
+ /* -----------------------------------------------------------------------
+ * saveGatewayXMLFileV6()
+ * ----------------------------------------------------------------------- */
+
+ void saveGatewayXMLFileV6() {
+ Printf(gatewayXMLV6, "</module>\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");
}