scilab: fix comment and indentation

This commit is contained in:
Simon Marchetto 2014-04-16 18:02:50 +02:00
commit 656f2b8932

View file

@ -62,8 +62,7 @@ public:
/* ------------------------------------------------------------------------ /* ------------------------------------------------------------------------
* main() * main()
* ----------------------------------------------------------------------*/ * ----------------------------------------------------------------------*/
virtual void main(int argc, char *argv[]) {
virtual void main(int argc, char *argv[]) {
sourceFileList = NewList(); sourceFileList = NewList();
cflags = NewList(); cflags = NewList();
@ -77,50 +76,50 @@ 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], "-addsrc") == 0) { } else if (strcmp(argv[argIndex], "-addsrc") == 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) {
DohInsertitem(sourceFileList, Len(sourceFileList), sourceFile); DohInsertitem(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], "-addcflag") == 0) { } else if (strcmp(argv[argIndex], "-addcflag") == 0) {
Swig_mark_arg(argIndex); Swig_mark_arg(argIndex);
if (argv[argIndex + 1] != NULL) { if (argv[argIndex + 1] != NULL) {
DohInsertitem(cflags, Len(cflags), argv[argIndex + 1]); DohInsertitem(cflags, Len(cflags), argv[argIndex + 1]);
Swig_mark_arg(argIndex + 1); Swig_mark_arg(argIndex + 1);
} }
} else if (strcmp(argv[argIndex], "-addldflag") == 0) { } else if (strcmp(argv[argIndex], "-addldflag") == 0) {
Swig_mark_arg(argIndex); Swig_mark_arg(argIndex);
if (argv[argIndex + 1] != NULL) { if (argv[argIndex + 1] != NULL) {
DohInsertitem(ldflags, Len(ldflags), argv[argIndex + 1]); DohInsertitem(ldflags, Len(ldflags), argv[argIndex + 1]);
Swig_mark_arg(argIndex + 1); Swig_mark_arg(argIndex + 1);
} }
} else if (strcmp(argv[argIndex], "-vbl") == 0) { } else if (strcmp(argv[argIndex], "-vbl") == 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], "-buildflags") == 0) { } else if (strcmp(argv[argIndex], "-buildflags") == 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], "-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], "-gwid") == 0) { else if (strcmp(argv[argIndex], "-gwid") == 0) {
Swig_mark_arg(argIndex); Swig_mark_arg(argIndex);
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], "-Wextra") == 0) { else if (strcmp(argv[argIndex], "-Wextra") == 0) {
extraWarning = true; extraWarning = true;
} }
} }
} }
@ -149,7 +148,6 @@ public:
/* ------------------------------------------------------------------------ /* ------------------------------------------------------------------------
* top() * top()
* ----------------------------------------------------------------------*/ * ----------------------------------------------------------------------*/
virtual int top(Node *node) { virtual int top(Node *node) {
/* Get the module name */ /* Get the module name */
@ -260,7 +258,6 @@ 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, "// ");
@ -270,7 +267,6 @@ 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 */
@ -328,37 +324,36 @@ public:
Printf(wrapper->code, "SWIG_Scilab_SetFname(fname);\n"); Printf(wrapper->code, "SWIG_Scilab_SetFname(fname);\n");
for (paramIndex = 0, param = functionParamsList; paramIndex < maxInputArguments; ++paramIndex) { for (paramIndex = 0, param = functionParamsList; paramIndex < maxInputArguments; ++paramIndex) {
// Ignore parameter if the typemap specifies numinputs=0 // Ignore parameter if the typemap specifies numinputs=0
while (checkAttribute(param, "tmap:in:numinputs", "0")) { while (checkAttribute(param, "tmap:in:numinputs", "0")) {
param = Getattr(param, "tmap:in:next"); param = Getattr(param, "tmap:in:next");
} }
SwigType *paramType = Getattr(param, "type"); SwigType *paramType = Getattr(param, "type");
String *paramTypemap = Getattr(param, "tmap:in"); String *paramTypemap = Getattr(param, "tmap:in");
if (paramTypemap) { if (paramTypemap) {
// Replace $input by the position on Scilab stack // Replace $input by the position on Scilab stack
char source[64]; char source[64];
sprintf(source, "%d", paramIndex + 1); sprintf(source, "%d", paramIndex + 1);
Setattr(param, "emit:input", source); Setattr(param, "emit:input", source);
Replaceall(paramTypemap, "$input", Getattr(param, "emit:input")); Replaceall(paramTypemap, "$input", Getattr(param, "emit:input"));
if (Getattr(param, "wrap:disown") || (Getattr(param, "tmap:in:disown"))) { if (Getattr(param, "wrap:disown") || (Getattr(param, "tmap:in:disown"))) {
Replaceall(paramTypemap, "$disown", "SWIG_POINTER_DISOWN"); Replaceall(paramTypemap, "$disown", "SWIG_POINTER_DISOWN");
} else { } else {
Replaceall(paramTypemap, "$disown", "0"); Replaceall(paramTypemap, "$disown", "0");
} }
if (paramIndex >= minInputArguments) { /* Optional input argument management */ if (paramIndex >= minInputArguments) { /* Optional input argument management */
Printf(wrapper->code, "if (SWIG_NbInputArgument(pvApiCtx) > %d) {\n%s\n}\n", paramIndex, paramTypemap); Printf(wrapper->code, "if (SWIG_NbInputArgument(pvApiCtx) > %d) {\n%s\n}\n", paramIndex, paramTypemap);
} else { } else {
Printf(wrapper->code, "%s\n", paramTypemap); Printf(wrapper->code, "%s\n", paramTypemap);
} }
param = Getattr(param, "tmap:in:next"); param = Getattr(param, "tmap:in:next");
} else { } else {
Swig_warning(WARN_TYPEMAP_IN_UNDEF, input_file, line_number, "Unable to use type %s as a function argument.\n", SwigType_str(paramType, 0)); Swig_warning(WARN_TYPEMAP_IN_UNDEF, input_file, line_number, "Unable to use type %s as a function argument.\n", SwigType_str(paramType, 0));
break; break;
} }
} }
@ -380,22 +375,22 @@ public:
if (functionReturnTypemap) { if (functionReturnTypemap) {
// Result is actually the position of output value on stack // Result is actually the position of output value on stack
if (Len(functionReturnTypemap) > 0) { if (Len(functionReturnTypemap) > 0) {
Printf(wrapper->code, "SWIG_Scilab_SetOutputPosition(%d);\n", 1); Printf(wrapper->code, "SWIG_Scilab_SetOutputPosition(%d);\n", 1);
} }
Replaceall(functionReturnTypemap, "$result", "1"); Replaceall(functionReturnTypemap, "$result", "1");
if (GetFlag(node, "feature:new")) { if (GetFlag(node, "feature:new")) {
Replaceall(functionReturnTypemap, "$owner", "1"); Replaceall(functionReturnTypemap, "$owner", "1");
} else { } else {
Replaceall(functionReturnTypemap, "$owner", "0"); Replaceall(functionReturnTypemap, "$owner", "0");
} }
Printf(wrapper->code, "%s\n", functionReturnTypemap); Printf(wrapper->code, "%s\n", functionReturnTypemap);
/* If the typemap is not empty, the function return one more argument than the typemaps gives */ /* If the typemap is not empty, the function return one more argument than the typemaps gives */
if (Len(functionReturnTypemap) > 0) { if (Len(functionReturnTypemap) > 0) {
minOutputArguments++; minOutputArguments++;
maxOutputArguments++; maxOutputArguments++;
} }
Delete(functionReturnTypemap); Delete(functionReturnTypemap);
@ -408,30 +403,30 @@ public:
for (param = functionParamsList; param;) { for (param = functionParamsList; param;) {
String *paramTypemap = Getattr(param, "tmap:argout"); String *paramTypemap = Getattr(param, "tmap:argout");
if (paramTypemap) { if (paramTypemap) {
minOutputArguments++; minOutputArguments++;
maxOutputArguments++; maxOutputArguments++;
Printf(wrapper->code, "SWIG_Scilab_SetOutputPosition(%d);\n", minOutputArguments); Printf(wrapper->code, "SWIG_Scilab_SetOutputPosition(%d);\n", minOutputArguments);
char result[64] = { }; char result[64] = { };
sprintf(result, "%d", minOutputArguments); sprintf(result, "%d", minOutputArguments);
Replaceall(paramTypemap, "$result", result); Replaceall(paramTypemap, "$result", result);
Printf(wrapper->code, "%s\n", paramTypemap); Printf(wrapper->code, "%s\n", paramTypemap);
Delete(paramTypemap); Delete(paramTypemap);
param = Getattr(param, "tmap:argout:next"); param = Getattr(param, "tmap:argout:next");
} else { } else {
param = nextSibling(param); param = nextSibling(param);
} }
} }
/* Add cleanup code */ /* Add cleanup code */
for (param = functionParamsList; param;) { for (param = functionParamsList; param;) {
String *tm; String *tm;
if ((tm = Getattr(param, "tmap:freearg"))) { if ((tm = Getattr(param, "tmap:freearg"))) {
if (tm && (Len(tm) != 0)) { if (tm && (Len(tm) != 0)) {
Replaceall(tm, "$source", Getattr(param, "lname")); Replaceall(tm, "$source", Getattr(param, "lname"));
Printf(wrapper->code, "%s\n", tm); Printf(wrapper->code, "%s\n", tm);
} }
param = Getattr(param, "tmap:freearg:next"); param = Getattr(param, "tmap:freearg:next");
} else { } else {
param = nextSibling(param); param = nextSibling(param);
} }
} }
@ -485,7 +480,6 @@ public:
/* ----------------------------------------------------------------------- /* -----------------------------------------------------------------------
* dispatchFunction() * dispatchFunction()
* ----------------------------------------------------------------------- */ * ----------------------------------------------------------------------- */
void dispatchFunction(Node *node) { void dispatchFunction(Node *node) {
Wrapper *wrapper = NewWrapper(); Wrapper *wrapper = NewWrapper();
@ -524,7 +518,6 @@ public:
/* ----------------------------------------------------------------------- /* -----------------------------------------------------------------------
* variableWrapper() * variableWrapper()
* ----------------------------------------------------------------------- */ * ----------------------------------------------------------------------- */
virtual int variableWrapper(Node *node) { virtual int variableWrapper(Node *node) {
/* Get information about variable */ /* Get information about variable */
@ -573,9 +566,9 @@ public:
String *varinTypemap = Swig_typemap_lookup("varin", node, origVariableName, 0); String *varinTypemap = Swig_typemap_lookup("varin", node, origVariableName, 0);
if (varinTypemap != NULL) { if (varinTypemap != NULL) {
Replaceall(varinTypemap, "$input", "1"); Replaceall(varinTypemap, "$input", "1");
emit_action_code(node, setFunctionWrapper->code, varinTypemap); emit_action_code(node, setFunctionWrapper->code, varinTypemap);
Delete(varinTypemap); Delete(varinTypemap);
} }
Append(setFunctionWrapper->code, "return SWIG_OK;\n"); Append(setFunctionWrapper->code, "return SWIG_OK;\n");
Append(setFunctionWrapper->code, "}\n"); Append(setFunctionWrapper->code, "}\n");
@ -591,7 +584,6 @@ 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 */
@ -672,7 +664,6 @@ public:
/* --------------------------------------------------------------------- /* ---------------------------------------------------------------------
* enumvalueDeclaration() * enumvalueDeclaration()
* --------------------------------------------------------------------- */ * --------------------------------------------------------------------- */
virtual int enumvalueDeclaration(Node *node) { virtual int enumvalueDeclaration(Node *node) {
static int iPreviousEnumValue = 0; static int iPreviousEnumValue = 0;
@ -712,6 +703,11 @@ public:
return Language::enumvalueDeclaration(node); return Language::enumvalueDeclaration(node);
} }
/* -----------------------------------------------------------------------
* checkIdentifierName()
* Display a warning for too long generated identifier names
* 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) {
@ -722,11 +718,17 @@ public:
} }
} }
/* -----------------------------------------------------------------------
* 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");
} }
/* -----------------------------------------------------------------------
* 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());
@ -737,6 +739,9 @@ public:
emitBanner(builderFile); emitBanner(builderFile);
} }
/* -----------------------------------------------------------------------
* startBuilderCode()
* ----------------------------------------------------------------------- */
void startBuilderCode(String *moduleName, String *outputFilename) { void startBuilderCode(String *moduleName, String *outputFilename) {
builderFunctionCount = 0; builderFunctionCount = 0;
builderCode = NewString(""); builderCode = NewString("");
@ -796,8 +801,10 @@ public:
Printf(builderCode, "table = ["); Printf(builderCode, "table = [");
} }
/* -----------------------------------------------------------------------
* terminateBuilderCode()
* ----------------------------------------------------------------------- */
void terminateBuilderCode() { void terminateBuilderCode() {
Printf(builderCode, "];\n"); Printf(builderCode, "];\n");
Printf(builderCode, "err_msg = [];\n"); Printf(builderCode, "err_msg = [];\n");
Printf(builderCode, "if ~isempty(table) then\n"); Printf(builderCode, "if ~isempty(table) then\n");
@ -816,12 +823,18 @@ public:
Printf(builderCode, "end\n"); Printf(builderCode, "end\n");
} }
/* -----------------------------------------------------------------------
* saveBuilderCode():
* ----------------------------------------------------------------------- */
void saveBuilderFile() { void saveBuilderFile() {
// Save builder
Printv(builderFile, builderCode, NIL); Printv(builderFile, builderCode, NIL);
Delete(builderFile); Delete(builderFile);
} }
/* -----------------------------------------------------------------------
* createGatewayXMLFile()
* This 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());
@ -845,6 +858,9 @@ public:
Printf(gatewayXML, "-->\n"); Printf(gatewayXML, "-->\n");
} }
/* -----------------------------------------------------------------------
* saveGatewayXMLFile()
* ----------------------------------------------------------------------- */
void saveGatewayXMLFile() { void saveGatewayXMLFile() {
Printv(gatewayXML, "</GATEWAY>\n"); Printv(gatewayXML, "</GATEWAY>\n");
Printv(gatewayXMLFile, gatewayXML, NIL); Printv(gatewayXMLFile, gatewayXML, NIL);
@ -852,10 +868,9 @@ public:
} }
/* ----------------------------------------------------------------------- /* -----------------------------------------------------------------------
* addFunctionToScilab: add a function in Scilab (builder, XML, ...) * addFunctionToScilab(): add a function in Scilab (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) {
{
addFunctionInBuilder(scilabFunctionName, wrapperFunctionName); addFunctionInBuilder(scilabFunctionName, wrapperFunctionName);
if (gatewayID) { if (gatewayID) {
Printf(gatewayXML, "<PRIMITIVE gatewayId=\"%s\" primitiveId=\"%d\" primitiveName=\"%s\"/>\n", gatewayID, primitiveID++, scilabFunctionName); Printf(gatewayXML, "<PRIMITIVE gatewayId=\"%s\" primitiveId=\"%d\" primitiveName=\"%s\"/>\n", gatewayID, primitiveID++, scilabFunctionName);