Beautify scilab.cxx

This commit is contained in:
William S Fulton 2014-06-26 20:29:33 +01:00
commit 081cb1af53

View file

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