[Scilab] New parameter targetversion to specify the Scilab target version (5, 6, ..) for code generation

With Scilab 6 target specified, identifier names truncation is disabled (no longer necessary)

Signed-off-by: Simon Marchetto <simon.marchetto@scilab-enterprises.com>
This commit is contained in:
Simon Marchetto 2017-04-12 13:54:42 +02:00
commit c06c9b3853
3 changed files with 114 additions and 87 deletions

View file

@ -7,11 +7,15 @@ the issue number to the end of the URL: https://github.com/swig/swig/issues/
Version 3.0.13 (in progress) Version 3.0.13 (in progress)
============================ ============================
2017-04-12: smarchetto
[Scilab] New parameter targetversion to specify the Scilab target version (5, 6, ..) for code generation
With Scilab 6 target specified, identifier names truncation is disabled (no longer necessary)
2017-02-29: tamuratak 2017-02-29: tamuratak
[Ruby] #917 - Add Enumerable module to all container class wrappers. It was missing [Ruby] #917 - Add Enumerable module to all container class wrappers. It was missing
for std::list, std::multiset, std::unordered_multiset and std::unordered_map. for std::list, std::multiset, std::unordered_multiset and std::unordered_map.
2017-03-24: tamuratak 2017-03-24: tamuratak
[Ruby] Fix #939 - Wrapping std::vector<bool> fix due to incorrect null checks [Ruby] Fix #939 - Wrapping std::vector<bool> fix due to incorrect null checks
on VALUE obj. on VALUE obj.

View file

@ -304,6 +304,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> <td>Generate the gateway XML with the given &lt;gateway_id&gt;</td>
</tr> </tr>
<tr>
<td><tt>-targetversion</tt></td>
<td>Generate for Scilab target (major) version</td>
</tr>
</table> </table>
<p> <p>
@ -331,13 +336,17 @@ There are a few exceptions, such as constants and enumerations, which can be wra
<p> <p>
In Scilab 5.x, identifier names are composed of 24 characters maximum (this limitation should disappear from Scilab 6.0 onwards). In Scilab 5.x, identifier names are composed of 24 characters maximum (this limitation disappears from Scilab 6.0 onwards).
<br>Thus long function or variable names may be truncated and this can cause ambiguities. <br>By default, variable, member, and function names longer than 24 charaters are truncated, and a warning is produced for each truncation.
</p> </p>
<p>This happens especially when wrapping structs/classes, for which the wrapped function name is composed of the struct/class name and field names. <p>This can cause ambiguities, especially when wrapping structs/classes, for which the wrapped function name is composed of the struct/class name and field names.
In these cases, the <a href="SWIG.html#SWIG_rename_ignore">%rename directive</a> can be used to choose a different Scilab name. In these cases, the <a href="SWIG.html#SWIG_rename_ignore">%rename directive</a> can be used to choose a different Scilab name.
</p> </p>
<p>
Note: truncations can be disabled by specifying the target version 6 of Scilab in the <tt>targetversion</tt> argument (i.e. <tt>-targetversion 6</tt>).
</p>
<H3><a name="Scilab_wrapping_functions">39.3.3 Functions</a></H3> <H3><a name="Scilab_wrapping_functions">39.3.3 Functions</a></H3>

View file

@ -18,13 +18,14 @@ static const int SCILAB_VARIABLE_NAME_CHAR_MAX = SCILAB_IDENTIFIER_NAME_CHAR_MAX
static const char *usage = (char *) " \ static const char *usage = (char *) " \
Scilab options (available with -scilab)\n \ Scilab options (available with -scilab)\n \
-builder - Generate a Scilab builder script\n \ -builder - Generate a Scilab builder script\n \
-buildercflags <cflags> - Add <cflags> to the builder compiler flags\n \ -buildercflags <cflags> - Add <cflags> to the builder compiler flags\n \
-builderflagscript <file> - Set the Scilab script <file> to use by builder to configure the build flags\n \ -builderflagscript <file> - Set the Scilab script <file> to use by builder to configure the build flags\n \
-builderldflags <ldflags> - Add <ldflags> to the builder linker flags\n \ -builderldflags <ldflags> - Add <ldflags> to the builder linker flags\n \
-buildersources <files> - Add the (comma separated) files <files> to the builder sources\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 \ -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 \ -gatewayxml <gateway_id> - Generate gateway xml with the given <gateway_id>\n \
-targetversion <scilab_major_version> - Generate for Scilab target (major) version (default: 5)\n \
\n"; \n";
@ -39,6 +40,8 @@ protected:
String *variablesCode; String *variablesCode;
int targetVersion;
bool generateBuilder; bool generateBuilder;
File *builderFile; File *builderFile;
String *builderCode; String *builderCode;
@ -71,6 +74,7 @@ public:
* ----------------------------------------------------------------------*/ * ----------------------------------------------------------------------*/
virtual void main(int argc, char *argv[]) { virtual void main(int argc, char *argv[]) {
targetVersion = 5;
generateBuilder = false; generateBuilder = false;
sourceFileList = NewList(); sourceFileList = NewList();
@ -95,48 +99,54 @@ public:
/* Manage command line arguments */ /* Manage command line arguments */
for (int argIndex = 1; argIndex < argc; argIndex++) { for (int argIndex = 1; argIndex < argc; argIndex++) {
if (argv[argIndex] != NULL) { if (argv[argIndex] != NULL) {
if (strcmp(argv[argIndex], "-help") == 0) { if (strcmp(argv[argIndex], "-help") == 0) {
Printf(stdout, "%s\n", usage); Printf(stdout, "%s\n", usage);
} else if (strcmp(argv[argIndex], "-builder") == 0) { } else if (strcmp(argv[argIndex], "-builder") == 0) {
Swig_mark_arg(argIndex); Swig_mark_arg(argIndex);
generateBuilder = true; generateBuilder = true;
createLoader = false; createLoader = false;
} else if (strcmp(argv[argIndex], "-buildersources") == 0) { } else if (strcmp(argv[argIndex], "-buildersources") == 0) {
if (argv[argIndex + 1] != NULL) { if (argv[argIndex + 1] != NULL) {
Swig_mark_arg(argIndex); Swig_mark_arg(argIndex);
char *sourceFile = strtok(argv[argIndex + 1], ","); char *sourceFile = strtok(argv[argIndex + 1], ",");
while (sourceFile != NULL) { while (sourceFile != NULL) {
Insert(sourceFileList, Len(sourceFileList), sourceFile); Insert(sourceFileList, Len(sourceFileList), sourceFile);
sourceFile = strtok(NULL, ","); sourceFile = strtok(NULL, ",");
} }
Swig_mark_arg(argIndex + 1); Swig_mark_arg(argIndex + 1);
} }
} else if (strcmp(argv[argIndex], "-buildercflags") == 0) { } else if (strcmp(argv[argIndex], "-buildercflags") == 0) {
Swig_mark_arg(argIndex); Swig_mark_arg(argIndex);
if (argv[argIndex + 1] != NULL) { if (argv[argIndex + 1] != NULL) {
Insert(cflags, Len(cflags), argv[argIndex + 1]); Insert(cflags, Len(cflags), argv[argIndex + 1]);
Swig_mark_arg(argIndex + 1); Swig_mark_arg(argIndex + 1);
} }
} else if (strcmp(argv[argIndex], "-builderldflags") == 0) { } else if (strcmp(argv[argIndex], "-builderldflags") == 0) {
Swig_mark_arg(argIndex); Swig_mark_arg(argIndex);
if (argv[argIndex + 1] != NULL) { if (argv[argIndex + 1] != NULL) {
Insert(ldflags, Len(ldflags), argv[argIndex + 1]); Insert(ldflags, Len(ldflags), argv[argIndex + 1]);
Swig_mark_arg(argIndex + 1); Swig_mark_arg(argIndex + 1);
} }
} else if (strcmp(argv[argIndex], "-builderverbositylevel") == 0) { } else if (strcmp(argv[argIndex], "-builderverbositylevel") == 0) {
Swig_mark_arg(argIndex); Swig_mark_arg(argIndex);
verboseBuildLevel = NewString(argv[argIndex + 1]); verboseBuildLevel = NewString(argv[argIndex + 1]);
Swig_mark_arg(argIndex + 1); Swig_mark_arg(argIndex + 1);
} else if (strcmp(argv[argIndex], "-builderflagscript") == 0) { } else if (strcmp(argv[argIndex], "-builderflagscript") == 0) {
Swig_mark_arg(argIndex); Swig_mark_arg(argIndex);
buildFlagsScript = NewString(argv[argIndex + 1]); buildFlagsScript = NewString(argv[argIndex + 1]);
Swig_mark_arg(argIndex + 1); Swig_mark_arg(argIndex + 1);
} else if (strcmp(argv[argIndex], "-gatewayxml") == 0) { } else if (strcmp(argv[argIndex], "-gatewayxml") == 0) {
Swig_mark_arg(argIndex); Swig_mark_arg(argIndex);
createGatewayXML = true; createGatewayXML = true;
gatewayID = NewString(argv[argIndex + 1]); gatewayID = NewString(argv[argIndex + 1]);
Swig_mark_arg(argIndex + 1); Swig_mark_arg(argIndex + 1);
} } else if (strcmp(argv[argIndex], "-targetversion") == 0) {
if (argv[argIndex + 1] != NULL) {
Swig_mark_arg(argIndex);
targetVersion = atoi(argv[argIndex + 1]);
Swig_mark_arg(argIndex + 1);
}
}
} }
} }
@ -784,57 +794,61 @@ public:
/* ----------------------------------------------------------------------- /* -----------------------------------------------------------------------
* checkIdentifierName() * checkIdentifierName()
* Truncates (and displays a warning) for too long identifier names * If Scilab target version is lower than 6:
* (applies on functions, variables, constants...) * truncates (and displays a warning) too long member identifier names
* (Scilab identifiers names are limited to 24 chars max) * (applies on members of structs, classes...)
* (Scilab 5 identifier names are limited to 24 chars max)
* ----------------------------------------------------------------------- */ * ----------------------------------------------------------------------- */
String *checkIdentifierName(String *name, int char_size_max) { String *checkIdentifierName(String *name, int char_size_max) {
String *scilabIdentifierName; String *scilabIdentifierName;
if (Len(name) > char_size_max) { if (targetVersion <= 5) {
scilabIdentifierName = DohNewStringWithSize(name, char_size_max); if (Len(name) > char_size_max) {
Swig_warning(WARN_SCILAB_TRUNCATED_NAME, input_file, line_number, scilabIdentifierName = DohNewStringWithSize(name, char_size_max);
"Identifier name '%s' exceeds 24 characters and has been truncated to '%s'.\n", name, scilabIdentifierName); Swig_warning(WARN_SCILAB_TRUNCATED_NAME, input_file, line_number,
} else "Identifier name '%s' exceeds 24 characters and has been truncated to '%s'.\n", name, scilabIdentifierName);
} else
scilabIdentifierName = name; scilabIdentifierName = name;
return scilabIdentifierName; } else {
scilabIdentifierName = DohNewString(name);
}
return scilabIdentifierName;
} }
/* ----------------------------------------------------------------------- /* -----------------------------------------------------------------------
* checkMemberIdentifierName() * checkMemberIdentifierName()
* Truncates (and displays a warning) too long member identifier names * If Scilab target version is lower than 6:
* (applies on members of structs, classes...) * truncates (and displays a warning) too long member identifier names
* (Scilab identifiers names are limited to 24 chars max) * (applies on members of structs, classes...)
* (Scilab 5 identifier names are limited to 24 chars max)
* ----------------------------------------------------------------------- */ * ----------------------------------------------------------------------- */
void checkMemberIdentifierName(Node *node, int char_size_max) { void checkMemberIdentifierName(Node *node, int char_size_max) {
if (targetVersion <= 5) {
String *memberName = Getattr(node, "sym:name");
Node *containerNode = parentNode(node);
String *containerName = Getattr(containerNode, "sym:name");
int lenContainerName = Len(containerName);
int lenMemberName = Len(memberName);
String *memberName = Getattr(node, "sym:name"); if (lenContainerName + lenMemberName + 1 > char_size_max) {
int lenScilabMemberName = char_size_max - lenContainerName - 1;
Node *containerNode = parentNode(node); if (lenScilabMemberName > 0) {
String *containerName = Getattr(containerNode, "sym:name"); String *scilabMemberName = DohNewStringWithSize(memberName, lenScilabMemberName);
Setattr(node, "sym:name", scilabMemberName);
int lenContainerName = Len(containerName); Swig_warning(WARN_SCILAB_TRUNCATED_NAME, input_file, line_number,
int lenMemberName = Len(memberName); "Wrapping functions names for member '%s.%s' will exceed 24 characters, "
"so member name has been truncated to '%s'.\n", containerName, memberName, scilabMemberName);
if (lenContainerName + lenMemberName + 1 > char_size_max) { } else {
int lenScilabMemberName = char_size_max - lenContainerName - 1; Swig_error(input_file, line_number,
"Wrapping functions names for member '%s.%s' will exceed 24 characters, "
if (lenScilabMemberName > 0) { "please rename the container of member '%s'.\n", containerName, memberName, containerName);
String *scilabMemberName = DohNewStringWithSize(memberName, lenScilabMemberName); }
Setattr(node, "sym:name", scilabMemberName); }
Swig_warning(WARN_SCILAB_TRUNCATED_NAME, input_file, line_number,
"Wrapping functions names for member '%s.%s' will exceed 24 characters, "
"so member name has been truncated to '%s'.\n", containerName, memberName, scilabMemberName);
} else
Swig_error(input_file, line_number,
"Wrapping functions names for member '%s.%s' will exceed 24 characters, "
"please rename the container of member '%s'.\n", containerName, memberName, containerName);
} }
} }
/* ----------------------------------------------------------------------- /* -----------------------------------------------------------------------
* addHelperFunctions() * addHelperFunctions()
* ----------------------------------------------------------------------- */ * ----------------------------------------------------------------------- */