Beautify scilab.cxx
This commit is contained in:
parent
e9c8e98260
commit
081cb1af53
1 changed files with 155 additions and 148 deletions
|
|
@ -24,8 +24,7 @@ Scilab options (available with -scilab)\n\
|
||||||
-buildverbositylevel <level> - Set the build verbosity <level> (default 0)\n\
|
-buildverbositylevel <level> - Set the build verbosity <level> (default 0)\n\
|
||||||
-internalmodule <gateway id> - Generate internal module files with the given <gateway id>\n\
|
-internalmodule <gateway id> - Generate internal module files with the given <gateway id>\n\
|
||||||
-nobuilder - Do not generate builder script\n\
|
-nobuilder - Do not generate builder script\n\
|
||||||
-outputlibrary <name> - Set name of the output library to <name>\n\n"
|
-outputlibrary <name> - Set name of the output library to <name>\n\n";
|
||||||
;
|
|
||||||
|
|
||||||
class SCILAB:public Language {
|
class SCILAB:public Language {
|
||||||
protected:
|
protected:
|
||||||
|
|
@ -68,6 +67,7 @@ public:
|
||||||
/* ------------------------------------------------------------------------
|
/* ------------------------------------------------------------------------
|
||||||
* main()
|
* main()
|
||||||
* ----------------------------------------------------------------------*/
|
* ----------------------------------------------------------------------*/
|
||||||
|
|
||||||
virtual void main(int argc, char *argv[]) {
|
virtual void main(int argc, char *argv[]) {
|
||||||
|
|
||||||
sourceFileList = NewList();
|
sourceFileList = NewList();
|
||||||
|
|
@ -123,20 +123,17 @@ public:
|
||||||
} else if (strcmp(argv[argIndex], "-nobuilder") == 0) {
|
} else if (strcmp(argv[argIndex], "-nobuilder") == 0) {
|
||||||
Swig_mark_arg(argIndex);
|
Swig_mark_arg(argIndex);
|
||||||
generateBuilder = false;
|
generateBuilder = false;
|
||||||
}
|
} else if (strcmp(argv[argIndex], "-internalmodule") == 0) {
|
||||||
else if (strcmp(argv[argIndex], "-internalmodule") == 0) {
|
|
||||||
Swig_mark_arg(argIndex);
|
Swig_mark_arg(argIndex);
|
||||||
generateBuilder = false;
|
generateBuilder = false;
|
||||||
internalModule = true;
|
internalModule = 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], "-outputlibrary") == 0) {
|
||||||
else if (strcmp(argv[argIndex], "-outputlibrary") == 0) {
|
|
||||||
Swig_mark_arg(argIndex);
|
Swig_mark_arg(argIndex);
|
||||||
libraryName = NewString(argv[argIndex + 1]);
|
libraryName = NewString(argv[argIndex + 1]);
|
||||||
Swig_mark_arg(argIndex + 1);
|
Swig_mark_arg(argIndex + 1);
|
||||||
}
|
} else if (strcmp(argv[argIndex], "-Wextra") == 0) {
|
||||||
else if (strcmp(argv[argIndex], "-Wextra") == 0) {
|
|
||||||
extraWarning = true;
|
extraWarning = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -164,6 +161,7 @@ public:
|
||||||
/* ------------------------------------------------------------------------
|
/* ------------------------------------------------------------------------
|
||||||
* top()
|
* top()
|
||||||
* ----------------------------------------------------------------------*/
|
* ----------------------------------------------------------------------*/
|
||||||
|
|
||||||
virtual int top(Node *node) {
|
virtual int top(Node *node) {
|
||||||
|
|
||||||
/* Get the module name */
|
/* Get the module name */
|
||||||
|
|
@ -203,13 +201,11 @@ public:
|
||||||
createBuilderFile();
|
createBuilderFile();
|
||||||
startBuilderCode(outputFilename);
|
startBuilderCode(outputFilename);
|
||||||
}
|
}
|
||||||
|
|
||||||
// In the case of internal module, create gateway gateway XML and generation script
|
// In the case of internal module, create gateway gateway XML and generation script
|
||||||
if (internalModule) {
|
if (internalModule) {
|
||||||
createGatewayXMLFile(moduleName);
|
createGatewayXMLFile(moduleName);
|
||||||
createGatewayGeneratorFile();
|
createGatewayGeneratorFile();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Module initialization function
|
// Module initialization function
|
||||||
String *moduleInitFunctionName = NewString("");
|
String *moduleInitFunctionName = NewString("");
|
||||||
Printf(moduleInitFunctionName, "%s_Init", moduleName);
|
Printf(moduleInitFunctionName, "%s_Init", moduleName);
|
||||||
|
|
@ -234,7 +230,6 @@ public:
|
||||||
if (CPlusPlus) {
|
if (CPlusPlus) {
|
||||||
Printf(wrappersSection, "}\n");
|
Printf(wrappersSection, "}\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Close Scilab wrapper variables creation function
|
// Close Scilab wrapper variables creation function
|
||||||
Printf(variablesCode, " return SWIG_OK;\n}\n");
|
Printf(variablesCode, " return SWIG_OK;\n}\n");
|
||||||
|
|
||||||
|
|
@ -280,6 +275,7 @@ public:
|
||||||
/* ------------------------------------------------------------------------
|
/* ------------------------------------------------------------------------
|
||||||
* emitBanner()
|
* emitBanner()
|
||||||
* ----------------------------------------------------------------------*/
|
* ----------------------------------------------------------------------*/
|
||||||
|
|
||||||
void emitBanner(File *f) {
|
void emitBanner(File *f) {
|
||||||
Printf(f, "// ----------------------------------------------------------------------------\n");
|
Printf(f, "// ----------------------------------------------------------------------------\n");
|
||||||
Swig_banner_target_lang(f, "// ");
|
Swig_banner_target_lang(f, "// ");
|
||||||
|
|
@ -289,6 +285,7 @@ public:
|
||||||
/* ------------------------------------------------------------------------
|
/* ------------------------------------------------------------------------
|
||||||
* functionWrapper()
|
* functionWrapper()
|
||||||
* ----------------------------------------------------------------------*/
|
* ----------------------------------------------------------------------*/
|
||||||
|
|
||||||
virtual int functionWrapper(Node *node) {
|
virtual int functionWrapper(Node *node) {
|
||||||
|
|
||||||
/* Get some useful attributes of this function */
|
/* Get some useful attributes of this function */
|
||||||
|
|
@ -503,6 +500,7 @@ public:
|
||||||
/* -----------------------------------------------------------------------
|
/* -----------------------------------------------------------------------
|
||||||
* dispatchFunction()
|
* dispatchFunction()
|
||||||
* ----------------------------------------------------------------------- */
|
* ----------------------------------------------------------------------- */
|
||||||
|
|
||||||
void dispatchFunction(Node *node) {
|
void dispatchFunction(Node *node) {
|
||||||
Wrapper *wrapper = NewWrapper();
|
Wrapper *wrapper = NewWrapper();
|
||||||
|
|
||||||
|
|
@ -543,6 +541,7 @@ public:
|
||||||
/* -----------------------------------------------------------------------
|
/* -----------------------------------------------------------------------
|
||||||
* variableWrapper()
|
* variableWrapper()
|
||||||
* ----------------------------------------------------------------------- */
|
* ----------------------------------------------------------------------- */
|
||||||
|
|
||||||
virtual int variableWrapper(Node *node) {
|
virtual int variableWrapper(Node *node) {
|
||||||
|
|
||||||
/* Get information about variable */
|
/* Get information about variable */
|
||||||
|
|
@ -611,6 +610,7 @@ public:
|
||||||
/* -----------------------------------------------------------------------
|
/* -----------------------------------------------------------------------
|
||||||
* constantWrapper()
|
* constantWrapper()
|
||||||
* ----------------------------------------------------------------------- */
|
* ----------------------------------------------------------------------- */
|
||||||
|
|
||||||
virtual int constantWrapper(Node *node) {
|
virtual int constantWrapper(Node *node) {
|
||||||
|
|
||||||
/* Get the useful information from the node */
|
/* Get the useful information from the node */
|
||||||
|
|
@ -692,6 +692,7 @@ public:
|
||||||
/* ---------------------------------------------------------------------
|
/* ---------------------------------------------------------------------
|
||||||
* enumvalueDeclaration()
|
* enumvalueDeclaration()
|
||||||
* --------------------------------------------------------------------- */
|
* --------------------------------------------------------------------- */
|
||||||
|
|
||||||
virtual int enumvalueDeclaration(Node *node) {
|
virtual int enumvalueDeclaration(Node *node) {
|
||||||
static int iPreviousEnumValue = 0;
|
static int iPreviousEnumValue = 0;
|
||||||
|
|
||||||
|
|
@ -707,8 +708,7 @@ public:
|
||||||
if (enumValue) {
|
if (enumValue) {
|
||||||
// Value is in 'enumvalue'
|
// Value is in 'enumvalue'
|
||||||
iPreviousEnumValue = atoi(Char(enumValue));
|
iPreviousEnumValue = atoi(Char(enumValue));
|
||||||
}
|
} else if (enumValueEx) {
|
||||||
else if (enumValueEx) {
|
|
||||||
// Or value is in 'enumValueEx'
|
// Or value is in 'enumValueEx'
|
||||||
iPreviousEnumValue = atoi(Char(enumValueEx));
|
iPreviousEnumValue = atoi(Char(enumValueEx));
|
||||||
|
|
||||||
|
|
@ -716,14 +716,12 @@ public:
|
||||||
Printf(enumValue, "%d", iPreviousEnumValue);
|
Printf(enumValue, "%d", iPreviousEnumValue);
|
||||||
Setattr(node, "enumvalue", enumValue);
|
Setattr(node, "enumvalue", enumValue);
|
||||||
}
|
}
|
||||||
}
|
} else if (!enumValue && enumValueEx) {
|
||||||
else if (!enumValue && enumValueEx) {
|
|
||||||
// Value is not specified, set it by incrementing last value
|
// Value is not specified, set it by incrementing last value
|
||||||
enumValue = NewString("");
|
enumValue = NewString("");
|
||||||
Printf(enumValue, "%d", ++iPreviousEnumValue);
|
Printf(enumValue, "%d", ++iPreviousEnumValue);
|
||||||
Setattr(node, "enumvalue", enumValue);
|
Setattr(node, "enumvalue", enumValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Enums in Scilab are mapped to double
|
// Enums in Scilab are mapped to double
|
||||||
Setattr(node, "type", "double");
|
Setattr(node, "type", "double");
|
||||||
}
|
}
|
||||||
|
|
@ -736,12 +734,12 @@ public:
|
||||||
* Display a warning for too long generated identifier names
|
* Display a warning for too long generated identifier names
|
||||||
* Scilab identifier name (functions, variables) can have 24 chars max
|
* Scilab identifier name (functions, variables) can have 24 chars max
|
||||||
* ----------------------------------------------------------------------- */
|
* ----------------------------------------------------------------------- */
|
||||||
|
|
||||||
void checkIdentifierName(String *name) {
|
void checkIdentifierName(String *name) {
|
||||||
if (Len(name) > 24) {
|
if (Len(name) > 24) {
|
||||||
if (extraWarning) {
|
if (extraWarning) {
|
||||||
// Warning on too long identifiers
|
// Warning on too long identifiers
|
||||||
Swig_warning(WARN_LANG_IDENTIFIER, input_file, line_number,
|
Swig_warning(WARN_LANG_IDENTIFIER, input_file, line_number, "Identifier %s exceeds 24 characters, it may be impossible to use it.\n", name);
|
||||||
"Identifier %s exceeds 24 characters, it may be impossible to use it.\n", name);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -749,6 +747,7 @@ public:
|
||||||
/* -----------------------------------------------------------------------
|
/* -----------------------------------------------------------------------
|
||||||
* addHelperFunctions()
|
* addHelperFunctions()
|
||||||
* ----------------------------------------------------------------------- */
|
* ----------------------------------------------------------------------- */
|
||||||
|
|
||||||
void addHelperFunctions() {
|
void addHelperFunctions() {
|
||||||
addFunctionToScilab("SWIG_this", "SWIG_this");
|
addFunctionToScilab("SWIG_this", "SWIG_this");
|
||||||
addFunctionToScilab("SWIG_ptr", "SWIG_ptr");
|
addFunctionToScilab("SWIG_ptr", "SWIG_ptr");
|
||||||
|
|
@ -757,6 +756,7 @@ public:
|
||||||
/* -----------------------------------------------------------------------
|
/* -----------------------------------------------------------------------
|
||||||
* createBuilderCode()
|
* createBuilderCode()
|
||||||
* ----------------------------------------------------------------------- */
|
* ----------------------------------------------------------------------- */
|
||||||
|
|
||||||
void createBuilderFile() {
|
void createBuilderFile() {
|
||||||
String *builderFilename = NewStringf("%sbuilder.sce", SWIG_output_directory());
|
String *builderFilename = NewStringf("%sbuilder.sce", SWIG_output_directory());
|
||||||
builderFile = NewFile(builderFilename, "w", SWIG_output_files());
|
builderFile = NewFile(builderFilename, "w", SWIG_output_files());
|
||||||
|
|
@ -770,6 +770,7 @@ public:
|
||||||
/* -----------------------------------------------------------------------
|
/* -----------------------------------------------------------------------
|
||||||
* startBuilderCode()
|
* startBuilderCode()
|
||||||
* ----------------------------------------------------------------------- */
|
* ----------------------------------------------------------------------- */
|
||||||
|
|
||||||
void startBuilderCode(String *outputFilename) {
|
void startBuilderCode(String *outputFilename) {
|
||||||
builderFunctionCount = 0;
|
builderFunctionCount = 0;
|
||||||
builderCode = NewString("");
|
builderCode = NewString("");
|
||||||
|
|
@ -803,8 +804,7 @@ public:
|
||||||
Printf(builderCode, "ldflags = ldflags + \" %s\";\n", ldflag);
|
Printf(builderCode, "ldflags = ldflags + \" %s\";\n", ldflag);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
Printf(builderCode, "ldflags = [];\n");
|
Printf(builderCode, "ldflags = [];\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -814,7 +814,6 @@ public:
|
||||||
Printf(builderCode, "cflags = cflags + getCompilationFlags();\n");
|
Printf(builderCode, "cflags = cflags + getCompilationFlags();\n");
|
||||||
Printf(builderCode, "ldflags = ldflags + getLinkFlags();\n");
|
Printf(builderCode, "ldflags = ldflags + getLinkFlags();\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Additional sources
|
// Additional sources
|
||||||
Insert(sourceFileList, 0, outputFilename);
|
Insert(sourceFileList, 0, outputFilename);
|
||||||
for (int i = 0; i < Len(sourceFileList); i++) {
|
for (int i = 0; i < Len(sourceFileList); i++) {
|
||||||
|
|
@ -832,6 +831,7 @@ public:
|
||||||
/* -----------------------------------------------------------------------
|
/* -----------------------------------------------------------------------
|
||||||
* terminateBuilderCode()
|
* terminateBuilderCode()
|
||||||
* ----------------------------------------------------------------------- */
|
* ----------------------------------------------------------------------- */
|
||||||
|
|
||||||
void terminateBuilderCode() {
|
void terminateBuilderCode() {
|
||||||
Printf(builderCode, "];\n");
|
Printf(builderCode, "];\n");
|
||||||
Printf(builderCode, "err_msg = [];\n");
|
Printf(builderCode, "err_msg = [];\n");
|
||||||
|
|
@ -854,6 +854,7 @@ public:
|
||||||
/* -----------------------------------------------------------------------
|
/* -----------------------------------------------------------------------
|
||||||
* saveBuilderCode()
|
* saveBuilderCode()
|
||||||
* ----------------------------------------------------------------------- */
|
* ----------------------------------------------------------------------- */
|
||||||
|
|
||||||
void saveBuilderFile() {
|
void saveBuilderFile() {
|
||||||
Printv(builderFile, builderCode, NIL);
|
Printv(builderFile, builderCode, NIL);
|
||||||
Delete(builderFile);
|
Delete(builderFile);
|
||||||
|
|
@ -863,6 +864,7 @@ public:
|
||||||
* createGatewayXMLFile()
|
* createGatewayXMLFile()
|
||||||
* This XML file is used by Scilab in the context of internal modules
|
* This XML file is used by Scilab in the context of internal modules
|
||||||
* ----------------------------------------------------------------------- */
|
* ----------------------------------------------------------------------- */
|
||||||
|
|
||||||
void createGatewayXMLFile(String *moduleName) {
|
void createGatewayXMLFile(String *moduleName) {
|
||||||
String *gatewayXMLFilename = NewStringf("%s_gateway.xml", moduleName);
|
String *gatewayXMLFilename = NewStringf("%s_gateway.xml", moduleName);
|
||||||
gatewayXMLFile = NewFile(gatewayXMLFilename, "w", SWIG_output_files());
|
gatewayXMLFile = NewFile(gatewayXMLFilename, "w", SWIG_output_files());
|
||||||
|
|
@ -891,6 +893,7 @@ public:
|
||||||
/* -----------------------------------------------------------------------
|
/* -----------------------------------------------------------------------
|
||||||
* saveGatewayXMLFile()
|
* saveGatewayXMLFile()
|
||||||
* ----------------------------------------------------------------------- */
|
* ----------------------------------------------------------------------- */
|
||||||
|
|
||||||
void saveGatewayXMLFile() {
|
void saveGatewayXMLFile() {
|
||||||
Printv(gatewayXML, "</GATEWAY>\n");
|
Printv(gatewayXML, "</GATEWAY>\n");
|
||||||
Printv(gatewayXMLFile, gatewayXML, NIL);
|
Printv(gatewayXMLFile, gatewayXML, NIL);
|
||||||
|
|
@ -902,6 +905,7 @@ public:
|
||||||
* Creates a Scilab macro to generate the gateway source (entry point gw_<module>.c)
|
* Creates a Scilab macro to generate the gateway source (entry point gw_<module>.c)
|
||||||
* Used in the context of internal module generation (-internalmodule)
|
* Used in the context of internal module generation (-internalmodule)
|
||||||
* ----------------------------------------------------------------------- */
|
* ----------------------------------------------------------------------- */
|
||||||
|
|
||||||
void createGatewayGeneratorFile() {
|
void createGatewayGeneratorFile() {
|
||||||
String *gatewayGeneratorFilename = NewString("generate_gateway.sce");
|
String *gatewayGeneratorFilename = NewString("generate_gateway.sce");
|
||||||
gatewayGeneratorFile = NewFile(gatewayGeneratorFilename, "w", SWIG_output_files());
|
gatewayGeneratorFile = NewFile(gatewayGeneratorFilename, "w", SWIG_output_files());
|
||||||
|
|
@ -915,6 +919,7 @@ public:
|
||||||
/* -----------------------------------------------------------------------
|
/* -----------------------------------------------------------------------
|
||||||
* saveGatewayGenerator()
|
* saveGatewayGenerator()
|
||||||
* ----------------------------------------------------------------------- */
|
* ----------------------------------------------------------------------- */
|
||||||
|
|
||||||
void saveGatewayGeneratorFile(String *moduleName) {
|
void saveGatewayGeneratorFile(String *moduleName) {
|
||||||
Printf(gatewayGeneratorCode, "];\n");
|
Printf(gatewayGeneratorCode, "];\n");
|
||||||
Printv(gatewayGeneratorFile, gatewayGeneratorCode, NIL);
|
Printv(gatewayGeneratorFile, gatewayGeneratorCode, NIL);
|
||||||
|
|
@ -927,6 +932,7 @@ public:
|
||||||
* addFunctionToScilab()
|
* addFunctionToScilab()
|
||||||
* Add a function wrapper in Scilab file (builder, XML, ...)
|
* Add a function wrapper in Scilab file (builder, XML, ...)
|
||||||
* ----------------------------------------------------------------------- */
|
* ----------------------------------------------------------------------- */
|
||||||
|
|
||||||
void addFunctionToScilab(const_String_or_char_ptr scilabFunctionName, const_String_or_char_ptr wrapperFunctionName) {
|
void addFunctionToScilab(const_String_or_char_ptr scilabFunctionName, const_String_or_char_ptr wrapperFunctionName) {
|
||||||
if (generateBuilder) {
|
if (generateBuilder) {
|
||||||
addFunctionInScriptTable(scilabFunctionName, wrapperFunctionName, builderCode);
|
addFunctionInScriptTable(scilabFunctionName, wrapperFunctionName, builderCode);
|
||||||
|
|
@ -948,6 +954,7 @@ public:
|
||||||
* This table will be either given in parameter to ilib_build or ilib_gen_gateway,
|
* This table will be either given in parameter to ilib_build or ilib_gen_gateway,
|
||||||
* called later in the script
|
* called later in the script
|
||||||
* ----------------------------------------------------------------------- */
|
* ----------------------------------------------------------------------- */
|
||||||
|
|
||||||
void addFunctionInScriptTable(const_String_or_char_ptr scilabFunctionName, const_String_or_char_ptr wrapperFunctionName, String *scriptCode) {
|
void addFunctionInScriptTable(const_String_or_char_ptr scilabFunctionName, const_String_or_char_ptr wrapperFunctionName, String *scriptCode) {
|
||||||
if (++builderFunctionCount % 10 == 0) {
|
if (++builderFunctionCount % 10 == 0) {
|
||||||
Printf(scriptCode, "];\ntable = [table;");
|
Printf(scriptCode, "];\ntable = [table;");
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue