Skip to content

Commit

Permalink
clean up some code
Browse files Browse the repository at this point in the history
  • Loading branch information
Baozeng Ding committed Aug 17, 2009
1 parent 8ee9175 commit d567ff5
Showing 1 changed file with 50 additions and 52 deletions.
102 changes: 50 additions & 52 deletions Source/Modules/scilab.cxx
Expand Up @@ -122,12 +122,12 @@ class SCILAB:public Language {
if (CPlusPlus)
Printf(f_wrappers, "}\n");

/* create the file to generate the module: "builder.sce" */
/* Create the file to generate the module: "builder.sce" */
if(hasfunction_flag) {
Printf(f_builder_code, "];\n");
Printf(f_builder_code, "ilib_build(ilib_name,table,files,libs);\n");
Printf(f_builder_code, "exit");
File *f_builder=NewFile(NewStringf("%sbuilder.sce", SWIG_output_directory()), "w", SWIG_output_files());
File *f_builder = NewFile(NewStringf("%sbuilder.sce", SWIG_output_directory()), "w", SWIG_output_files());
Printv(f_builder, f_builder_code, NIL);
Close(f_builder);
Delete(f_builder);
Expand Down Expand Up @@ -169,13 +169,12 @@ class SCILAB:public Language {
String *tm;
int j;

/* Get the useful information from the node */
String *nodeType = Getattr(n, "nodeType");
int constructor = (!Cmp(nodeType, "constructor"));
// int destructor = (!Cmp(nodeType, "destructor"));
String *storage = Getattr(n, "storage");
/* Determine whether the function is overloaded or not */
bool overloaded = !!Getattr(n, "sym:overloaded");

/* Determine whether the function is the last overloaded */
bool last_overload = overloaded && !Getattr(n, "sym:nextSibling");

String *iname = Getattr(n, "sym:name");
String *wname = Swig_name_wrapper(iname);
String *overname = Copy(wname);
Expand All @@ -201,22 +200,9 @@ class SCILAB:public Language {
int num_arguments = emit_num_arguments(l);
int num_required = emit_num_required(l);

/* the number of the output */
/* The number of the output */
int out_required = 0;
//int varargs = emit_isvarargs(l);


if (constructor && num_arguments == 1 && num_required == 1) {
if (Cmp(storage, "explicit") == 0) {
Node *parent = Swig_methodclass(n);
if (GetFlag(parent, "feature:implicitconv")) {
String *desc = NewStringf("SWIGTYPE%s", SwigType_manglestr(Getattr(n, "type")));
Printf(f->code, "if (SWIG_CheckImplicit(%s)) SWIG_fail;\n", desc);
Delete(desc);
}
}
}

/* Walk the function parameter list and generate code to get arguments */
for (j = 0, p = l; j < num_arguments; ++j) {
while (checkAttribute(p, "tmap:in:numinputs", "0")) {
Expand All @@ -234,15 +220,18 @@ class SCILAB:public Language {
continue;
}
String *getargs = NewString("");

/* The paremeter is variable */
if (j >= num_required)
Printf(getargs, "if (Rhs > %d) {\n%s\n}", j, tm);
else
Printv(getargs, tm, NIL);
Printv(f->code, getargs, "\n", NIL);
Delete(getargs);
p = Getattr(p, "tmap:in:next");
continue;
} else {
Printv(f->code, getargs, "\n", NIL);
Delete(getargs);
p = Getattr(p, "tmap:in:next");
continue;
}
else {
Swig_warning(WARN_TYPEMAP_IN_UNDEF, input_file, line_number, "Unable to use type %s as a function argument.\n", SwigType_str(pt, 0));
break;
}
Expand All @@ -259,11 +248,13 @@ class SCILAB:public Language {

if ((tm = Swig_typemap_lookup_out("out", n, "result", f, actioncode))) {
Replaceall(tm, "$result", "result");
if(out_required>0)
Printf(f->code,"iOutNum++;\niVarOut++;\n");

/* There are more than one output */
if (out_required > 0)
Printf(f->code, "iOutNum ++;\niVarOut ++;\n");
Printf(f->code, "%s\n", tm);
if(strlen(Char(tm))!=0)
out_required++;
if (strlen(Char(tm)) != 0)
out_required ++;
}
else {
Swig_warning(WARN_TYPEMAP_OUT_UNDEF, input_file, line_number, "Unable to use return type %s in function %s.\n", SwigType_str(d, 0), iname);
Expand All @@ -273,11 +264,11 @@ class SCILAB:public Language {
String *outarg = NewString("");
for (p = l; p;) {
if ((tm = Getattr(p, "tmap:argout"))) {
if(out_required>0)
Printf(f->code,"iOutNum++;\niVarOut++;\n");
if (out_required > 0)
Printf(f->code,"iOutNum ++;\niVarOut ++;\n");
Printv(outarg, tm, "\n", NIL);
p = Getattr(p, "tmap:argout:next");
out_required++;
out_required ++;
} else {
p = nextSibling(p);
}
Expand Down Expand Up @@ -309,21 +300,24 @@ class SCILAB:public Language {

/* Output cleanup code */
Printv(f->code, cleanup, NIL);
Delete(cleanup);

/* Insert the code checking for the number of input and output */
int flag;
if(out_required == 0) {
if (out_required == 0) {
out_required = 1;
flag = 0;
}
else {
flag = 1;
}

/* Insert the code checking the number of input */
Printf(f->def, "CheckRhs(%d, %d);\n",num_required,num_arguments);
Printf(f->def, "CheckLhs(%d, %d);\n",out_required,out_required);

/* Insert the order of output parameters*/
if(flag)
if (flag)
Printf(f->def, "\nint iOutNum = 1;\nint iVarOut = Rhs + 1;");

/* Finish the the code for the function */
Expand Down Expand Up @@ -358,22 +352,23 @@ class SCILAB:public Language {
String *iname = Getattr(n, "sym:name");
String *wname = Swig_name_wrapper(iname);
int maxargs;

/* Generate the dispatch function */
String *dispatch = Swig_overload_dispatch(n, "return %s(fname, fname_len);", &maxargs);
String *tmp = NewString("");

Printv(f->def, "int ", wname, " (char *fname, unsigned long fname_len) {\n", NIL);

/* Get the number of the parameters */
Wrapper_add_local(f, "argc", "int argc = Rhs;");
//Printf(tmp, "octave_value_ref argv[%d]={", maxargs);
//for (int j = 0; j < maxargs; ++j)
//Printf(tmp, "%soctave_value_ref(args,%d)", j ? "," : " ", j);
//Printf(tmp, "}");
//Wrapper_add_local(f, "argv", tmp);

/* Dump the dispatch function */
Printv(f->code, dispatch, "\n", NIL);
Printf(f->code, "Scierror(999, _(\"No matching function for overload\"));\n");
Printf(f->code, "return 0;\n");
Printv(f->code, "}\n", NIL);

Wrapper_print(f, f_wrappers);

Delete(tmp);
DelWrapper(f);
Delete(dispatch);
Expand All @@ -396,14 +391,15 @@ class SCILAB:public Language {
if (!addSymbol(iname, n))
return SWIG_ERROR;

/* The rows and cols name of the variable */
String *rowname = NewString("");
String *colname = NewString("");
String *iscomplexname = NewString("");
Printf(rowname, "iRows_%s", iname);
Printf(colname, "iCols_%s", iname);
Printf(iscomplexname, "isComplex_%s", iname);

/* two wrapper function to get and set the variable */
/* Two wrapper function to get and set the variable */
String *tm;
String *globalVar = NewString("");
Wrapper *getf = NewWrapper();
Expand All @@ -424,10 +420,10 @@ class SCILAB:public Language {
Printf(setf->def, "CheckRhs(1, 1);\n");
Printf(setf->def, "CheckLhs(1, 1);\n");

/* add the local variable */
/* Add the local variable */
Wrapper_add_local(setf, "piAddrVar", "int *piAddrVar");

/* deal with the set function */
/* Deal with the set function */
if (is_assignable(n)) {
Setattr(n, "wrap:name", setname);
if (Getattr(n, "unnamedinstance"))
Expand All @@ -450,7 +446,7 @@ class SCILAB:public Language {
Wrapper_print(setf, f_wrappers);
Printf(f_builder_code, "\"%s\",\"%s\";", setname, setname);

/* deal with the get function */
/* Deal with the get function */
Setattr(n, "wrap:name", getname);
int addfail = 0;
Printv(getf->def, "int ", getname, " (char *fname, unsigned long fname_len){\n", NIL);
Expand All @@ -459,7 +455,7 @@ class SCILAB:public Language {
Printf(getf->def, "CheckRhs(0, 0);\n");
Printf(getf->def, "CheckLhs(1, 1);\n");

/* Insert the order of output parameters*/
/* Insert the order of output parameters */
Printf(getf->def, "\nint iOutNum=1;\nint iVarOut=Rhs+1;");

if ((tm = Swig_typemap_lookup("varout", n, name, 0))) {
Expand All @@ -474,11 +470,12 @@ class SCILAB:public Language {
Replaceall(tm, "isComplex", iscomplexname);
addfail = emit_action_code(n, getf->code, tm);
Delete(tm);
} else {
}
else {
Swig_warning(WARN_TYPEMAP_VAROUT_UNDEF, input_file, line_number, "Unable to read variable of type %s\n", SwigType_str(t, 0));
}

/*Dump the wrapper function */
/* Dump the wrapper function */
Append(getf->code, "}\n");
Wrapper_print(getf, f_wrappers);
Printf(f_header,"%s", globalVar);
Expand All @@ -491,9 +488,8 @@ class SCILAB:public Language {
DelWrapper(setf);
DelWrapper(getf);


return SWIG_OK;
}
}

/* -----------------------------------------------------------------------
* constantWrapper()
Expand All @@ -514,7 +510,7 @@ class SCILAB:public Language {
if (!addSymbol(iname, n))
return SWIG_ERROR;

/*use the get function to get the constant value */
/* Use the get function to get the constant value */
Wrapper *getf = NewWrapper();
String *getname = Swig_name_get(iname);
Setattr(n, "wrap:name", getname);
Expand All @@ -538,10 +534,12 @@ class SCILAB:public Language {
Swig_warning(WARN_TYPEMAP_VAROUT_UNDEF, input_file, line_number, "Unable to read variable of type %s\n", SwigType_str(type, 0));
}

/*Dump the wrapper function */
/* Dump the wrapper function */
Append(getf->code, "}\n");
Wrapper_print(getf, f_wrappers);
Printf(f_builder_code, "\"%s\",\"%s\";", getname, getname);

DelWrapper(getf);

return SWIG_OK;
}
Expand Down

0 comments on commit d567ff5

Please sign in to comment.