summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWilliam S Fulton <wsf@fultondesigns.co.uk>2017-02-14 08:15:12 +0000
committerWilliam S Fulton <wsf@fultondesigns.co.uk>2017-02-14 08:15:12 +0000
commitdf30236a64f2783c507e873b3a043024428b13ba (patch)
tree5a7d695e5dfc7551cae710125f8caad844441d1e
parent294026b41d91f8e1073504a3f507747d7a21a202 (diff)
downloadswig-df30236a64f2783c507e873b3a043024428b13ba.tar.gz
run make beautify-file on matlab.cxx
-rw-r--r--Source/Modules/matlab.cxx1465
1 files changed, 737 insertions, 728 deletions
diff --git a/Source/Modules/matlab.cxx b/Source/Modules/matlab.cxx
index 7354500b3..c8e99c897 100644
--- a/Source/Modules/matlab.cxx
+++ b/Source/Modules/matlab.cxx
@@ -21,7 +21,7 @@ Matlab Options (available with -matlab)\n\
-mexname <name> - Set mex function name to <name> [default: '<module>MEX']\n\
\n";
-class MATLAB : public Language {
+class MATLAB:public Language {
public:
MATLAB();
virtual void main(int argc, char *argv[]);
@@ -54,8 +54,8 @@ public:
int classDirectorDisown(Node *n);
protected:
- File* f_wrap_m;
- File* f_setup_m;
+ File *f_wrap_m;
+ File *f_setup_m;
File *f_gateway;
File *f_constants;
File *f_begin;
@@ -68,12 +68,12 @@ protected:
File *f_directors;
File *f_directors_h;
File *f_runtime_h;
- String* class_name;
- String* mex_name;
- String* base_init;
- String* get_field;
- String* set_field;
- String* static_methods;
+ String *class_name;
+ String *mex_name;
+ String *base_init;
+ String *get_field;
+ String *set_field;
+ String *static_methods;
// Current constant
int con_id;
@@ -115,16 +115,16 @@ protected:
void createSwigMem();
void createSwigGet();
void createSwigStorage();
- void autodoc_to_m(File* f, Node *n);
+ void autodoc_to_m(File *f, Node *n);
void process_autodoc(Node *n);
void make_autodocParmList(Node *n, String *decl_str, String *args_str);
void addMissingParameterNames(ParmList *plist, int arg_offset);
- String* convertValue(String *v, SwigType *t);
- const char* get_implicitconv_flag(Node *n);
+ String *convertValue(String *v, SwigType *t);
+ const char *get_implicitconv_flag(Node *n);
void dispatchFunction(Node *n);
- static String* matlab_escape(String *_s);
- void wrapConstructor(int gw_ind, String *symname, String *fullname, Node* n);
- void wrapConstructorDirector(int gw_ind, String *symname, String *fullname, Node* n);
+ static String *matlab_escape(String *_s);
+ void wrapConstructor(int gw_ind, String *symname, String *fullname, Node *n);
+ void wrapConstructorDirector(int gw_ind, String *symname, String *fullname, Node *n);
int getRangeNumReturns(Node *n, int &max_num_returns, int &min_num_returns);
void checkValidSymName(Node *node);
};
@@ -135,7 +135,7 @@ extern "C" Language *swig_matlab(void) {
// Only implementations from here on
-MATLAB::MATLAB() :
+MATLAB::MATLAB():
f_wrap_m(0),
f_setup_m(0),
f_gateway(0),
@@ -162,14 +162,13 @@ MATLAB::MATLAB() :
op_prefix(0),
pkg_name(0),
pkg_name_fullpath(0),
- no_header_file(0)
-{
+ no_header_file(0) {
/* Add code to manage protected constructors and directors */
director_prot_ctor_code = NewString("");
Printv(director_prot_ctor_code,
- "if ( argc==1 ) { /* subclassed */\n",
- " $director_new \n",
- "} else {\n", " mexErrMsgIdAndTxt(\"SWIG:RuntimeError\",\"accessing abstract class or protected constructor\"); \n", " SWIG_fail;\n", "}\n", NIL);
+ "if ( argc==1 ) { /* subclassed */\n",
+ " $director_new \n",
+ "} else {\n", " mexErrMsgIdAndTxt(\"SWIG:RuntimeError\",\"accessing abstract class or protected constructor\"); \n", " SWIG_fail;\n", "}\n", NIL);
enable_cplus_runtime_mode();
allow_overloading();
@@ -179,51 +178,51 @@ MATLAB::MATLAB() :
void MATLAB::main(int argc, char *argv[]) {
int cppcast = 1;
- redirectoutput=false;
+ redirectoutput = false;
- for (int i=1; i<argc; i++) {
+ for (int i = 1; i < argc; i++) {
if (argv[i]) {
if (strcmp(argv[i], "-help") == 0) {
- fputs(usage, stdout);
+ fputs(usage, stdout);
} else if (strcmp(argv[i], "-opprefix") == 0) {
- if (argv[i+1]) {
- op_prefix = NewString(argv[i+1]);
- Swig_mark_arg(i);
- Swig_mark_arg(i+1);
- i++;
- } else {
- Swig_arg_error();
- }
+ if (argv[i + 1]) {
+ op_prefix = NewString(argv[i + 1]);
+ Swig_mark_arg(i);
+ Swig_mark_arg(i + 1);
+ i++;
+ } else {
+ Swig_arg_error();
+ }
} else if (strcmp(argv[i], "-cppcast") == 0) {
- cppcast = 1;
- Swig_mark_arg(i);
+ cppcast = 1;
+ Swig_mark_arg(i);
} else if (strcmp(argv[i], "-nocppcast") == 0) {
- cppcast = 0;
- Swig_mark_arg(i);
+ cppcast = 0;
+ Swig_mark_arg(i);
} else if (strcmp(argv[i], "-noh") == 0) {
- no_header_file = 1;
- Swig_mark_arg(i);
+ no_header_file = 1;
+ Swig_mark_arg(i);
} else if (strcmp(argv[i], "-pkgname") == 0) {
- if (argv[i+1]) {
- pkg_name = NewString(argv[i+1]);
- Swig_mark_arg(i);
- Swig_mark_arg(i+1);
- i++;
- } else {
- Swig_arg_error();
- }
+ if (argv[i + 1]) {
+ pkg_name = NewString(argv[i + 1]);
+ Swig_mark_arg(i);
+ Swig_mark_arg(i + 1);
+ i++;
+ } else {
+ Swig_arg_error();
+ }
} else if (strcmp(argv[i], "-mexname") == 0) {
- if (argv[i+1]) {
- mex_name = NewString(argv[i+1]);
- Swig_mark_arg(i);
- Swig_mark_arg(i+1);
- i++;
- } else {
- Swig_arg_error();
- }
+ if (argv[i + 1]) {
+ mex_name = NewString(argv[i + 1]);
+ Swig_mark_arg(i);
+ Swig_mark_arg(i + 1);
+ i++;
+ } else {
+ Swig_arg_error();
+ }
} else if (strcmp(argv[i], "-redirectoutput") == 0) {
- redirectoutput = true;
- Swig_mark_arg(i);
+ redirectoutput = true;
+ Swig_mark_arg(i);
}
}
}
@@ -252,28 +251,28 @@ int MATLAB::top(Node *n) {
if (mod) {
Node *options = Getattr(mod, "options");
if (options) {
- int dirprot = 0;
- if (Getattr(options, "dirprot")) {
- dirprot = 1;
- }
- if (Getattr(options, "nodirprot")) {
- dirprot = 0;
- }
- if (Getattr(options, "directors")) {
- allow_directors();
- if (dirprot)
- allow_dirprot();
- }
- // Set package name via module option if not set via command-line
- // Otherwise use module name as default (see below)
- if (!pkg_name && Getattr(options, "package")) {
- pkg_name = Getattr(options, "package");
- }
- // Set mex name via module option if not set via command-line
- // Otherwise use module name as default (see below)
- if (!mex_name && Getattr(options, "mexname")) {
- mex_name = Getattr(options, "mexname");
- }
+ int dirprot = 0;
+ if (Getattr(options, "dirprot")) {
+ dirprot = 1;
+ }
+ if (Getattr(options, "nodirprot")) {
+ dirprot = 0;
+ }
+ if (Getattr(options, "directors")) {
+ allow_directors();
+ if (dirprot)
+ allow_dirprot();
+ }
+ // Set package name via module option if not set via command-line
+ // Otherwise use module name as default (see below)
+ if (!pkg_name && Getattr(options, "package")) {
+ pkg_name = Getattr(options, "package");
+ }
+ // Set mex name via module option if not set via command-line
+ // Otherwise use module name as default (see below)
+ if (!mex_name && Getattr(options, "mexname")) {
+ mex_name = Getattr(options, "mexname");
+ }
}
}
}
@@ -306,12 +305,12 @@ int MATLAB::top(Node *n) {
l_modules = NewList();
// Create subdirectory
- String* pkg_directory_name = NewString("+");
+ String *pkg_directory_name = NewString("+");
Append(pkg_directory_name, pkg_name);
- (void)Replace(pkg_directory_name,".","/+", DOH_REPLACE_ANY);
+ (void) Replace(pkg_directory_name, ".", "/+", DOH_REPLACE_ANY);
pkg_name_fullpath = NewString("");
Printf(pkg_name_fullpath, "%s%s", SWIG_output_directory(), pkg_directory_name);
- Swig_new_subdirectory((String*)SWIG_output_directory(), pkg_directory_name);
+ Swig_new_subdirectory((String *) SWIG_output_directory(), pkg_directory_name);
// Create output (mex) file
f_begin = NewFile(outfile, "w", SWIG_output_files());
@@ -323,7 +322,7 @@ int MATLAB::top(Node *n) {
/* The name of the compiled mex-wrapper is modulenameMEX by default, but this
can be overridden by setting the mexname opion */
if (!mex_name) {
- mex_name=NewString(module);
+ mex_name = NewString(module);
Append(mex_name, "MEX");
}
@@ -345,8 +344,8 @@ int MATLAB::top(Node *n) {
if (!no_header_file) {
f_runtime_h = NewFile(outfile_h, "w", SWIG_output_files());
if (!f_runtime_h) {
- FileErrorDisplay(outfile_h);
- SWIG_exit(EXIT_FAILURE);
+ FileErrorDisplay(outfile_h);
+ SWIG_exit(EXIT_FAILURE);
}
} else {
f_runtime_h = f_runtime;
@@ -435,7 +434,7 @@ int MATLAB::top(Node *n) {
Delete(l_modules);
/* Load this module */
- Printf(f_init,"SWIG_InitializeModule(0);\n\n");
+ Printf(f_init, "SWIG_InitializeModule(0);\n\n");
if (directorsEnabled()) {
Swig_insert_file("director.swg", f_runtime);
@@ -446,7 +445,7 @@ int MATLAB::top(Node *n) {
This was left open such that any dynamic_cast variables are
set inside that function (as those are set via %init in swig.swg, see macro
DYNAMIC_CAST).
- */
+ */
Printf(f_init, "}\n");
SwigType_emit_type_table(f_runtime, f_wrappers);
@@ -469,139 +468,139 @@ int MATLAB::top(Node *n) {
Wrapper_pretty_print(f_init, f_begin);
// Get constant name by index, internal
- Printf(f_begin,"\n");
- Printf(f_begin,"const char* swigConstantName_(int con_id) {\n");
- Printf(f_begin," switch (con_id) {\n");
+ Printf(f_begin, "\n");
+ Printf(f_begin, "const char* swigConstantName_(int con_id) {\n");
+ Printf(f_begin, " switch (con_id) {\n");
// Add cases and deallocate list
- int c=0;
+ int c = 0;
for (i = First(l_cnames); i.item; i = Next(i)) {
- Printf(f_begin," case %d: return \"%s\";\n", c++, i.item);
+ Printf(f_begin, " case %d: return \"%s\";\n", c++, i.item);
Delete(i.item);
}
Delete(l_cnames);
// Default case
- Printf(f_begin," default: return 0;\n");
- Printf(f_begin," }\n");
- Printf(f_begin,"}\n");
+ Printf(f_begin, " default: return 0;\n");
+ Printf(f_begin, " }\n");
+ Printf(f_begin, "}\n");
// Get constant name by index
- Printf(f_begin,"\n");
- Printf(f_begin,"int swigConstantName(int resc, mxArray *resv[], int argc, mxArray *argv[]) {\n");
+ Printf(f_begin, "\n");
+ Printf(f_begin, "int swigConstantName(int resc, mxArray *resv[], int argc, mxArray *argv[]) {\n");
// The first argument is always the ID
- Printf(f_begin," if (argc!=1 || !mxIsDouble(*argv) || mxGetNumberOfElements(*argv)!=1) {\n");
- Printf(f_begin," SWIG_Error(SWIG_RuntimeError, \"This mex file should only be called from "
- "inside the .m files generated by SWIG. The input should be the constant ID.\");\n");
- Printf(f_begin," return 1;\n");
- Printf(f_begin," }\n");
+ Printf(f_begin, " if (argc!=1 || !mxIsDouble(*argv) || mxGetNumberOfElements(*argv)!=1) {\n");
+ Printf(f_begin, " SWIG_Error(SWIG_RuntimeError, \"This mex file should only be called from "
+ "inside the .m files generated by SWIG. The input should be the constant ID.\");\n");
+ Printf(f_begin, " return 1;\n");
+ Printf(f_begin, " }\n");
// Make sure one output
- Printf(f_begin," if (resc!=1) {\n");
- Printf(f_begin," SWIG_Error(SWIG_RuntimeError, \"The function should have one output.\");\n");
- Printf(f_begin," return 1;\n");
- Printf(f_begin," }\n");
+ Printf(f_begin, " if (resc!=1) {\n");
+ Printf(f_begin, " SWIG_Error(SWIG_RuntimeError, \"The function should have one output.\");\n");
+ Printf(f_begin, " return 1;\n");
+ Printf(f_begin, " }\n");
// Get the string
- Printf(f_begin," int con_id = (int)mxGetScalar(*argv);\n");
- Printf(f_begin," const char* s = swigConstantName_(con_id);\n");
+ Printf(f_begin, " int con_id = (int)mxGetScalar(*argv);\n");
+ Printf(f_begin, " const char* s = swigConstantName_(con_id);\n");
// Make sure found
- Printf(f_begin," if (s==0) {\n");
- Printf(f_begin," SWIG_Error(SWIG_RuntimeError, \"No such constant ID.\");\n");
- Printf(f_begin," return 1;\n");
- Printf(f_begin," }\n");
+ Printf(f_begin, " if (s==0) {\n");
+ Printf(f_begin, " SWIG_Error(SWIG_RuntimeError, \"No such constant ID.\");\n");
+ Printf(f_begin, " return 1;\n");
+ Printf(f_begin, " }\n");
// Return string
- Printf(f_begin," *resv = mxCreateString(s);\n");
- Printf(f_begin," return 0;\n");
- Printf(f_begin,"}\n\n");
+ Printf(f_begin, " *resv = mxCreateString(s);\n");
+ Printf(f_begin, " return 0;\n");
+ Printf(f_begin, "}\n\n");
Dump(f_constants, f_begin);
// Get function name by index, internal
- Printf(f_begin,"\n");
- Printf(f_begin,"const char* swigFunctionName_(int fcn_id) {\n");
- Printf(f_begin," switch(fcn_id) {\n");
+ Printf(f_begin, "\n");
+ Printf(f_begin, "const char* swigFunctionName_(int fcn_id) {\n");
+ Printf(f_begin, " switch(fcn_id) {\n");
// Add cases and deallocate list
- c=0;
+ c = 0;
for (i = First(l_fnames); i.item; i = Next(i)) {
- Printf(f_begin," case %d: return \"%s\";\n", c++, i.item);
+ Printf(f_begin, " case %d: return \"%s\";\n", c++, i.item);
Delete(i.item);
}
Delete(l_fnames);
// Default case
- Printf(f_begin," default: return 0;\n");
- Printf(f_begin," }\n");
- Printf(f_begin,"}\n");
+ Printf(f_begin, " default: return 0;\n");
+ Printf(f_begin, " }\n");
+ Printf(f_begin, "}\n");
// Get function name by index
- Printf(f_begin,"\n");
- Printf(f_begin,"int swigFunctionName(int resc, mxArray *resv[], int argc, mxArray *argv[]) {\n");
+ Printf(f_begin, "\n");
+ Printf(f_begin, "int swigFunctionName(int resc, mxArray *resv[], int argc, mxArray *argv[]) {\n");
// The first argument is always the ID
- Printf(f_begin," if (argc!=1 || !mxIsDouble(*argv) || mxGetNumberOfElements(*argv)!=1) {\n");
- Printf(f_begin," SWIG_Error(SWIG_RuntimeError, \"This mex file should only be called from "
- "inside the .m files generated by SWIG. The input should be the function ID.\");\n");
- Printf(f_begin," return 1;\n");
- Printf(f_begin," }\n");
+ Printf(f_begin, " if (argc!=1 || !mxIsDouble(*argv) || mxGetNumberOfElements(*argv)!=1) {\n");
+ Printf(f_begin, " SWIG_Error(SWIG_RuntimeError, \"This mex file should only be called from "
+ "inside the .m files generated by SWIG. The input should be the function ID.\");\n");
+ Printf(f_begin, " return 1;\n");
+ Printf(f_begin, " }\n");
// Make sure one output
- Printf(f_begin," if (resc!=1) {\n");
- Printf(f_begin," SWIG_Error(SWIG_RuntimeError, \"The function should have one output.\");\n");
- Printf(f_begin," return 1;\n");
- Printf(f_begin," }\n");
+ Printf(f_begin, " if (resc!=1) {\n");
+ Printf(f_begin, " SWIG_Error(SWIG_RuntimeError, \"The function should have one output.\");\n");
+ Printf(f_begin, " return 1;\n");
+ Printf(f_begin, " }\n");
// Get the string
- Printf(f_begin," int fcn_id = (int)mxGetScalar(*argv);\n");
- Printf(f_begin," const char* s = swigFunctionName_(fcn_id);\n");
+ Printf(f_begin, " int fcn_id = (int)mxGetScalar(*argv);\n");
+ Printf(f_begin, " const char* s = swigFunctionName_(fcn_id);\n");
// Make sure found
- Printf(f_begin," if (s==0) {\n");
- Printf(f_begin," SWIG_Error(SWIG_RuntimeError, \"No such function ID.\");\n");
- Printf(f_begin," return 1;\n");
- Printf(f_begin," }\n");
+ Printf(f_begin, " if (s==0) {\n");
+ Printf(f_begin, " SWIG_Error(SWIG_RuntimeError, \"No such function ID.\");\n");
+ Printf(f_begin, " return 1;\n");
+ Printf(f_begin, " }\n");
// Return string
- Printf(f_begin," *resv = mxCreateString(s);\n");
- Printf(f_begin," return 0;\n");
- Printf(f_begin,"}\n\n");
+ Printf(f_begin, " *resv = mxCreateString(s);\n");
+ Printf(f_begin, " return 0;\n");
+ Printf(f_begin, "}\n\n");
// Get memory
- Printf(f_begin,"int swigThis(int resc, mxArray *resv[], int argc, mxArray *argv[]) {\n");
+ Printf(f_begin, "int swigThis(int resc, mxArray *resv[], int argc, mxArray *argv[]) {\n");
// Make sure only one input and max one output
- Printf(f_begin," if (argc!=1 || resc!=1) {\n");
- Printf(f_begin," SWIG_Error(SWIG_RuntimeError, \"swigThis should have one input and one output.\");\n");
- Printf(f_begin," return 1;\n");
- Printf(f_begin," }\n");
+ Printf(f_begin, " if (argc!=1 || resc!=1) {\n");
+ Printf(f_begin, " SWIG_Error(SWIG_RuntimeError, \"swigThis should have one input and one output.\");\n");
+ Printf(f_begin, " return 1;\n");
+ Printf(f_begin, " }\n");
// Get the SwigPtr object
- Printf(f_begin," SwigPtr* swig_ptr = SWIG_Matlab_getSwigPtr(argv[0]);\n");
- Printf(f_begin," if (!swig_ptr) {\n");
- Printf(f_begin," SWIG_Error(SWIG_RuntimeError, \"The argument should be a SWIG class.\");\n");
- Printf(f_begin," return 1;\n");
- Printf(f_begin," }\n");
+ Printf(f_begin, " SwigPtr* swig_ptr = SWIG_Matlab_getSwigPtr(argv[0]);\n");
+ Printf(f_begin, " if (!swig_ptr) {\n");
+ Printf(f_begin, " SWIG_Error(SWIG_RuntimeError, \"The argument should be a SWIG class.\");\n");
+ Printf(f_begin, " return 1;\n");
+ Printf(f_begin, " }\n");
// Convert to uint64 and return
- Printf(f_begin," resv[0] = mxCreateNumericMatrix(1, 1, mxUINT64_CLASS, mxREAL);\n");
- Printf(f_begin," *(uint64_T *)mxGetData(resv[0]) = (uint64_T)swig_ptr->ptr;\n");
- Printf(f_begin," return 0;\n");
- Printf(f_begin,"}\n\n");
+ Printf(f_begin, " resv[0] = mxCreateNumericMatrix(1, 1, mxUINT64_CLASS, mxREAL);\n");
+ Printf(f_begin, " *(uint64_T *)mxGetData(resv[0]) = (uint64_T)swig_ptr->ptr;\n");
+ Printf(f_begin, " return 0;\n");
+ Printf(f_begin, "}\n\n");
// Touch module
- Printf(f_begin,"int swigTouch(int resc, mxArray** /*resv*/, int argc, mxArray** /*argv*/) {\n");
+ Printf(f_begin, "int swigTouch(int resc, mxArray** /*resv*/, int argc, mxArray** /*argv*/) {\n");
// Make sure no inputs or outputs
- Printf(f_begin," if (argc!=0 || resc!=0) {\n");
- Printf(f_begin," SWIG_Error(SWIG_RuntimeError, \"swigTouch should have no inputs or outputs.\");\n");
- Printf(f_begin," return 1;\n");
- Printf(f_begin," }\n");
- Printf(f_begin," return 0;\n");
- Printf(f_begin,"}\n\n");
+ Printf(f_begin, " if (argc!=0 || resc!=0) {\n");
+ Printf(f_begin, " SWIG_Error(SWIG_RuntimeError, \"swigTouch should have no inputs or outputs.\");\n");
+ Printf(f_begin, " return 1;\n");
+ Printf(f_begin, " }\n");
+ Printf(f_begin, " return 0;\n");
+ Printf(f_begin, "}\n\n");
Dump(f_gateway, f_begin);
@@ -654,7 +653,7 @@ void MATLAB::process_autodoc(Node *n) {
Delete(type_str);
}
- Append(decl_info, Getattr(n, "sym:name") );
+ Append(decl_info, Getattr(n, "sym:name"));
Append(decl_info, " (");
Append(decl_info, decl_str);
Append(decl_info, ")\n");
@@ -795,7 +794,7 @@ void MATLAB::make_autodocParmList(Node *n, String *decl_str, String *args_str) {
if (tm) {
pnext = Getattr(p, "tmap:in:next");
if (checkAttribute(p, "tmap:in:numinputs", "0")) {
- continue;
+ continue;
}
} else {
pnext = nextSibling(p);
@@ -835,11 +834,11 @@ void MATLAB::make_autodocParmList(Node *n, String *decl_str, String *args_str) {
if (value) {
String *new_value = convertValue(value, Getattr(p, "type"));
if (new_value) {
- value = new_value;
+ value = new_value;
} else {
- Node *lookup = Swig_symbol_clookup(value, 0);
- if (lookup)
- value = Getattr(lookup, "sym:name");
+ Node *lookup = Swig_symbol_clookup(value, 0);
+ if (lookup)
+ value = Getattr(lookup, "sym:name");
}
Printf(decl_str, " = %s", value);
}
@@ -857,15 +856,15 @@ void MATLAB::make_autodocParmList(Node *n, String *decl_str, String *args_str) {
Delete(plist);
}
-String* MATLAB::convertValue(String *v, SwigType *t) {
+String *MATLAB::convertValue(String *v, SwigType *t) {
if (v && Len(v) > 0) {
char fc = (Char(v))[0];
if (('0' <= fc && fc <= '9') || '\'' == fc || '"' == fc) {
/* number or string (or maybe NULL pointer) */
if (SwigType_ispointer(t) && Strcmp(v, "0") == 0)
- return NewString("None");
+ return NewString("None");
else
- return v;
+ return v;
}
if (Strcmp(v, "NULL") == 0 || Strcmp(v, "nullptr") == 0)
return SwigType_ispointer(t) ? NewString("nil") : NewString("0");
@@ -917,22 +916,19 @@ int MATLAB::functionWrapper(Node *n) {
Append(f->code, "int is_owned;\n");
}
- Printf(f->code, "if (!SWIG_check_num_args(\"%s\",argc,%i,%i,%i)) "
- "{\n SWIG_fail;\n }\n", iname, num_arguments, num_required, varargs);
+ Printf(f->code, "if (!SWIG_check_num_args(\"%s\",argc,%i,%i,%i)) " "{\n SWIG_fail;\n }\n", iname, num_arguments, num_required, varargs);
if (num_arguments == 0 && num_required == 0) {
Printf(f->code, "(void)argv; // Unused variable\n");
- }
- else if (constructor && num_arguments == 1 && num_required == 1) {
+ } else 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);
+ String *desc = NewStringf("SWIGTYPE%s", SwigType_manglestr(Getattr(n, "type")));
+ Printf(f->code, "if (SWIG_CheckImplicit(%s)) SWIG_fail;\n", desc);
+ Delete(desc);
}
}
}
-
// Check if owned here, before possibly disowning in the typemaps
if (destructor) {
Append(f->code, "is_owned = SWIG_Matlab_isOwned(argv[0]);\n");
@@ -948,8 +944,8 @@ int MATLAB::functionWrapper(Node *n) {
String *tm = Getattr(p, "tmap:in");
if (tm) {
if (!tm || checkAttribute(p, "tmap:in:numinputs", "0")) {
- p = nextSibling(p);
- continue;
+ p = nextSibling(p);
+ continue;
}
sprintf(source, "argv[%d]", j);
@@ -960,26 +956,26 @@ int MATLAB::functionWrapper(Node *n) {
Replaceall(tm, "$target", Getattr(p, "lname"));
if (Getattr(p, "wrap:disown") || (Getattr(p, "tmap:in:disown"))) {
- Replaceall(tm, "$disown", "SWIG_POINTER_DISOWN");
+ Replaceall(tm, "$disown", "SWIG_POINTER_DISOWN");
} else {
- Replaceall(tm, "$disown", "0");
+ Replaceall(tm, "$disown", "0");
}
if (Getattr(p, "tmap:in:implicitconv")) {
- const char *convflag = "0";
- if (!Getattr(p, "hidden")) {
- SwigType *ptype = Getattr(p, "type");
- convflag = get_implicitconv_flag(classLookup(ptype));
- }
- Replaceall(tm, "$implicitconv", convflag);
- Setattr(p, "implicitconv", convflag);
+ const char *convflag = "0";
+ if (!Getattr(p, "hidden")) {
+ SwigType *ptype = Getattr(p, "type");
+ convflag = get_implicitconv_flag(classLookup(ptype));
+ }
+ Replaceall(tm, "$implicitconv", convflag);
+ Setattr(p, "implicitconv", convflag);
}
String *getargs = NewString("");
if (j >= num_required)
- Printf(getargs, "if (%d<argc) {\n%s\n}", j, tm);
+ Printf(getargs, "if (%d<argc) {\n%s\n}", j, tm);
else
- Printv(getargs, tm, NIL);
+ Printv(getargs, tm, NIL);
Printv(f->code, getargs, "\n", NIL);
Delete(getargs);
@@ -1015,18 +1011,18 @@ int MATLAB::functionWrapper(Node *n) {
for (p = l; p;) {
if ((tm = Getattr(p, "tmap:freearg"))) {
if (Getattr(p, "tmap:freearg:implicitconv")) {
- const char *convflag = "0";
- if (!Getattr(p, "hidden")) {
- SwigType *ptype = Getattr(p, "type");
- convflag = get_implicitconv_flag(classLookup(ptype));
- }
- if (strcmp(convflag, "0") == 0) {
- tm = 0;
- }
+ const char *convflag = "0";
+ if (!Getattr(p, "hidden")) {
+ SwigType *ptype = Getattr(p, "type");
+ convflag = get_implicitconv_flag(classLookup(ptype));
+ }
+ if (strcmp(convflag, "0") == 0) {
+ tm = 0;
+ }
}
if (tm && (Len(tm) != 0)) {
- Replaceall(tm, "$source", Getattr(p, "lname"));
- Printv(cleanup, tm, "\n", NIL);
+ Replaceall(tm, "$source", Getattr(p, "lname"));
+ Printv(cleanup, tm, "\n", NIL);
}
p = Getattr(p, "tmap:freearg:next");
} else {
@@ -1098,8 +1094,9 @@ int MATLAB::functionWrapper(Node *n) {
// Check if void return
if (SwigType_issimple(d)) {
- String * typestr = SwigType_str(d, 0);
- if (Strcmp(typestr,"void")==0) num_returns--;
+ String *typestr = SwigType_str(d, 0);
+ if (Strcmp(typestr, "void") == 0)
+ num_returns--;
Delete(typestr);
}
@@ -1152,9 +1149,8 @@ int MATLAB::functionWrapper(Node *n) {
Printf(f->code, "%s\n", tm);
Delete(tm);
}
-
// Store the number of return values to the node
- String* num_returns_str=NewStringf("%d", num_returns);
+ String *num_returns_str = NewStringf("%d", num_returns);
Setattr(n, "matlab:num_returns", num_returns_str);
Printf(f->code, "return 0;\n");
@@ -1184,10 +1180,12 @@ int MATLAB::functionWrapper(Node *n) {
int MATLAB::globalfunctionHandler(Node *n) {
// Emit C wrappers
int flag = Language::globalfunctionHandler(n);
- if (flag!=SWIG_OK) return flag;
+ if (flag != SWIG_OK)
+ return flag;
// Skip if inside class
- if (class_name) return flag;
+ if (class_name)
+ return flag;
// Name of function
String *symname = Getattr(n, "sym:name");
@@ -1195,10 +1193,11 @@ int MATLAB::globalfunctionHandler(Node *n) {
// No MATLAB wrapper for the overloads
bool overloaded = !!Getattr(n, "sym:overloaded");
bool last_overload = overloaded && !Getattr(n, "sym:nextSibling");
- if (overloaded && !last_overload) return flag;
+ if (overloaded && !last_overload)
+ return flag;
// Create MATLAB proxy
- String* mfile = NewString("");
+ String *mfile = NewString("");
Printf(mfile, "%s/%s.m", pkg_name_fullpath, symname);
if (f_wrap_m)
SWIG_exit(EXIT_FAILURE);
@@ -1207,35 +1206,34 @@ int MATLAB::globalfunctionHandler(Node *n) {
FileErrorDisplay(mfile);
SWIG_exit(EXIT_FAILURE);
}
-
// Add to function switch
String *wname = Swig_name_wrapper(symname);
- int gw_ind = toGateway(wname,wname);
+ int gw_ind = toGateway(wname, wname);
// Add function to matlab proxy
checkValidSymName(n);
- Printf(f_wrap_m,"function varargout = %s(varargin)\n",symname);
+ Printf(f_wrap_m, "function varargout = %s(varargin)\n", symname);
autodoc_to_m(f_wrap_m, n);
- const char* varginstr = GetFlag(n, "feature:varargin") ? "varargin" : "varargin{:}";
+ const char *varginstr = GetFlag(n, "feature:varargin") ? "varargin" : "varargin{:}";
if (have_matlabprepend(n)) {
- Printf(f_wrap_m, "%s\n",matlabprepend(n));
+ Printf(f_wrap_m, "%s\n", matlabprepend(n));
}
if (GetFlag(n, "feature:optionalunpack")) {
- Printf(f_wrap_m," out = %s(%d, %s);\n", mex_name, gw_ind, varginstr);
- Printf(f_wrap_m," if nargout<=1\n");
- Printf(f_wrap_m," varargout{1}=out;\n");
- Printf(f_wrap_m," else\n");
- Printf(f_wrap_m," nargoutchk(length(out),length(out))\n");
- Printf(f_wrap_m," for i=1:nargout\n");
- Printf(f_wrap_m," varargout{i} = out(i);\n");
- Printf(f_wrap_m," end\n");
- Printf(f_wrap_m," end\n");
+ Printf(f_wrap_m, " out = %s(%d, %s);\n", mex_name, gw_ind, varginstr);
+ Printf(f_wrap_m, " if nargout<=1\n");
+ Printf(f_wrap_m, " varargout{1}=out;\n");
+ Printf(f_wrap_m, " else\n");
+ Printf(f_wrap_m, " nargoutchk(length(out),length(out))\n");
+ Printf(f_wrap_m, " for i=1:nargout\n");
+ Printf(f_wrap_m, " varargout{i} = out(i);\n");
+ Printf(f_wrap_m, " end\n");
+ Printf(f_wrap_m, " end\n");
} else {
- Printf(f_wrap_m," [varargout{1:nargout}] = %s(%d, %s);\n", mex_name, gw_ind, varginstr);
+ Printf(f_wrap_m, " [varargout{1:nargout}] = %s(%d, %s);\n", mex_name, gw_ind, varginstr);
}
if (have_matlabappend(n))
- Printf(f_wrap_m, "%s\n",matlabappend(n));
- Printf(f_wrap_m,"end\n");
+ Printf(f_wrap_m, "%s\n", matlabappend(n));
+ Printf(f_wrap_m, "end\n");
Delete(wname);
Delete(mfile);
@@ -1253,13 +1251,14 @@ int MATLAB::variableWrapper(Node *n) {
return SWIG_ERROR;
// Skip if inside class // FIXME(@jaeandersson) ignores varin, varout
- if (class_name) return Language::variableWrapper(n);
+ if (class_name)
+ return Language::variableWrapper(n);
// Name of variable
checkValidSymName(n);
// Create MATLAB proxy
- String* mfile = NewString("");
+ String *mfile = NewString("");
Printf(mfile, "%s/%s.m", pkg_name_fullpath, iname);
if (f_wrap_m)
SWIG_exit(EXIT_FAILURE);
@@ -1268,11 +1267,10 @@ int MATLAB::variableWrapper(Node *n) {
FileErrorDisplay(mfile);
SWIG_exit(EXIT_FAILURE);
}
-
// Add getter function
String *getname = Swig_name_get(NSPACE_TODO, iname);
String *getwname = Swig_name_wrapper(getname);
- int gw_ind_get = toGateway(getname,getwname);
+ int gw_ind_get = toGateway(getname, getwname);
// varout typemap
String *tm;
@@ -1301,15 +1299,15 @@ int MATLAB::variableWrapper(Node *n) {
if (!is_assignable(n)) {
// Only getter
if (!class_name) {
- Printf(f_wrap_m,"function v = %s()\n",iname);
- Printf(f_wrap_m," v = %s(%d);\n",mex_name,gw_ind_get);
- Printf(f_wrap_m,"end\n");
+ Printf(f_wrap_m, "function v = %s()\n", iname);
+ Printf(f_wrap_m, " v = %s(%d);\n", mex_name, gw_ind_get);
+ Printf(f_wrap_m, "end\n");
}
} else {
// Add setter function
String *setname = Swig_name_set(NSPACE_TODO, iname);
String *setwname = Swig_name_wrapper(setname);
- int gw_ind_set = toGateway(setname,setwname);
+ int gw_ind_set = toGateway(setname, setwname);
// varin typemap
Wrapper *setf = NewWrapper();
@@ -1320,7 +1318,7 @@ int MATLAB::variableWrapper(Node *n) {
Replaceall(tm, "$target", name);
Replaceall(tm, "$input", "argv[0]");
if (Getattr(n, "tmap:varin:implicitconv")) {
- Replaceall(tm, "$implicitconv", get_implicitconv_flag(n));
+ Replaceall(tm, "$implicitconv", get_implicitconv_flag(n));
}
emit_action_code(n, setf->code, tm);
Delete(tm);
@@ -1335,16 +1333,16 @@ int MATLAB::variableWrapper(Node *n) {
// Getter and setter
if (!class_name) {
- Printf(f_wrap_m,"function varargout = %s(varargin)\n",iname);
- Printf(f_wrap_m," narginchk(0,1)\n");
- Printf(f_wrap_m," if nargin==0\n");
- Printf(f_wrap_m," nargoutchk(0,1)\n");
- Printf(f_wrap_m," varargout{1} = %s(%d);\n",mex_name,gw_ind_get);
- Printf(f_wrap_m," else\n");
- Printf(f_wrap_m," nargoutchk(0,0)\n");
- Printf(f_wrap_m," %s(%d,varargin{1});\n",mex_name,gw_ind_set);
- Printf(f_wrap_m," end\n");
- Printf(f_wrap_m,"end\n");
+ Printf(f_wrap_m, "function varargout = %s(varargin)\n", iname);
+ Printf(f_wrap_m, " narginchk(0,1)\n");
+ Printf(f_wrap_m, " if nargin==0\n");
+ Printf(f_wrap_m, " nargoutchk(0,1)\n");
+ Printf(f_wrap_m, " varargout{1} = %s(%d);\n", mex_name, gw_ind_get);
+ Printf(f_wrap_m, " else\n");
+ Printf(f_wrap_m, " nargoutchk(0,0)\n");
+ Printf(f_wrap_m, " %s(%d,varargin{1});\n", mex_name, gw_ind_set);
+ Printf(f_wrap_m, " end\n");
+ Printf(f_wrap_m, "end\n");
}
// Tidy up
@@ -1389,7 +1387,7 @@ int MATLAB::constantWrapper(Node *n) {
Replaceall(tm, "$target", name);
Replaceall(tm, "$value", CPlusPlus && cppvalue ? cppvalue : value);
Replaceall(tm, "$nsname", symname);
- con_id = toConstant(symname,tm);
+ con_id = toConstant(symname, tm);
} else {
Swig_warning(WARN_TYPEMAP_CONST_UNDEF, input_file, line_number, "Unsupported constant value.\n");
return SWIG_NOWRAP;
@@ -1397,7 +1395,7 @@ int MATLAB::constantWrapper(Node *n) {
if (!class_name) {
// Create MATLAB proxy
- String* mfile = NewString("");
+ String *mfile = NewString("");
Printf(mfile, "%s/%s.m", pkg_name_fullpath, symname);
if (f_wrap_m)
SWIG_exit(EXIT_FAILURE);
@@ -1406,16 +1404,15 @@ int MATLAB::constantWrapper(Node *n) {
FileErrorDisplay(mfile);
SWIG_exit(EXIT_FAILURE);
}
-
// Add getter function
checkValidSymName(n);
- Printf(f_wrap_m,"function v = %s()\n",symname);
- Printf(f_wrap_m," persistent vInitialized;\n");
- Printf(f_wrap_m," if isempty(vInitialized)\n");
- Printf(f_wrap_m," vInitialized = %s(0, %d);\n",mex_name,con_id);
- Printf(f_wrap_m," end\n");
- Printf(f_wrap_m," v = vInitialized;\n");
- Printf(f_wrap_m,"end\n");
+ Printf(f_wrap_m, "function v = %s()\n", symname);
+ Printf(f_wrap_m, " persistent vInitialized;\n");
+ Printf(f_wrap_m, " if isempty(vInitialized)\n");
+ Printf(f_wrap_m, " vInitialized = %s(0, %d);\n", mex_name, con_id);
+ Printf(f_wrap_m, " end\n");
+ Printf(f_wrap_m, " v = vInitialized;\n");
+ Printf(f_wrap_m, "end\n");
// Tidy up
Delete(mfile);
@@ -1637,14 +1634,14 @@ int MATLAB::classDirectorMethod(Node *n, Node *parent, String *super) {
Swig_typemap_attach_parms("throws", throw_parm_list, 0);
for (p = throw_parm_list; p; p = nextSibling(p)) {
if (Getattr(p, "tmap:throws")) {
- if (gencomma++) {
- Append(w->def, ", ");
- Append(declaration, ", ");
- }
- String *str = SwigType_str(Getattr(p, "type"), 0);
- Append(w->def, str);
- Append(declaration, str);
- Delete(str);
+ if (gencomma++) {
+ Append(w->def, ", ");
+ Append(declaration, ", ");
+ }
+ String *str = SwigType_str(Getattr(p, "type"), 0);
+ Append(w->def, str);
+ Append(declaration, str);
+ Delete(str);
}
}
@@ -1670,13 +1667,13 @@ int MATLAB::classDirectorMethod(Node *n, Node *parent, String *super) {
if (ignored_method) {
if (!pure_virtual) {
if (!is_void)
- Printf(w->code, "return ");
+ Printf(w->code, "return ");
String *super_call = Swig_method_call(super, l);
Printf(w->code, "%s;\n", super_call);
Delete(super_call);
} else {
Printf(w->code, "Swig::DirectorPureVirtualException::raise(\"Attempted to invoke pure virtual method %s::%s\");\n", SwigType_namestr(c_classname),
- SwigType_namestr(name));
+ SwigType_namestr(name));
}
} else {
/* attach typemaps to arguments (C/C++ -> MATLAB) */
@@ -1703,8 +1700,8 @@ int MATLAB::classDirectorMethod(Node *n, Node *parent, String *super) {
int use_parse = 0;
while (p) {
if (checkAttribute(p, "tmap:in:numinputs", "0")) {
- p = Getattr(p, "tmap:in:next");
- continue;
+ p = Getattr(p, "tmap:in:next");
+ continue;
}
/* old style? caused segfaults without the p!=0 check
@@ -1713,109 +1710,109 @@ int MATLAB::classDirectorMethod(Node *n, Node *parent, String *super) {
while (Getattr(p, "tmap:ignore")) {
p = Getattr(p, "tmap:ignore:next");
}
- */
+ */
if (Getattr(p, "tmap:directorargout") != 0)
- outputs++;
+ outputs++;
String *pname = Getattr(p, "name");
String *ptype = Getattr(p, "type");
Putc(',', arglist);
if ((tm = Getattr(p, "tmap:directorin")) != 0) {
- String *parse = Getattr(p, "tmap:directorin:parse");
- if (!parse) {
- sprintf(source, "obj%d", idx++);
- String *input = NewString(source);
- Setattr(p, "emit:directorinput", input);
- Replaceall(tm, "$input", input);
- Delete(input);
- Replaceall(tm, "$owner", "0");
- /* Wrapper_add_localv(w, source, "SwigVar_mxArray", source, "= 0", NIL); */
- Printv(wrap_args, "SwigVar_mxArray ", source, ";\n", NIL);
-
- Printv(wrap_args, tm, "\n", NIL);
- Printv(arglist, "(mxArray *)", source, NIL);
- Putc('O', parse_args);
- } else {
- use_parse = 1;
- Append(parse_args, parse);
- Setattr(p, "emit:directorinput", pname);
- Replaceall(tm, "$input", pname);
- Replaceall(tm, "$owner", "0");
- if (Len(tm) == 0)
- Append(tm, pname);
- Append(arglist, tm);
- }
- p = Getattr(p, "tmap:directorin:next");
- continue;
+ String *parse = Getattr(p, "tmap:directorin:parse");
+ if (!parse) {
+ sprintf(source, "obj%d", idx++);
+ String *input = NewString(source);
+ Setattr(p, "emit:directorinput", input);
+ Replaceall(tm, "$input", input);
+ Delete(input);
+ Replaceall(tm, "$owner", "0");
+ /* Wrapper_add_localv(w, source, "SwigVar_mxArray", source, "= 0", NIL); */
+ Printv(wrap_args, "SwigVar_mxArray ", source, ";\n", NIL);
+
+ Printv(wrap_args, tm, "\n", NIL);
+ Printv(arglist, "(mxArray *)", source, NIL);
+ Putc('O', parse_args);
+ } else {
+ use_parse = 1;
+ Append(parse_args, parse);
+ Setattr(p, "emit:directorinput", pname);
+ Replaceall(tm, "$input", pname);
+ Replaceall(tm, "$owner", "0");
+ if (Len(tm) == 0)
+ Append(tm, pname);
+ Append(arglist, tm);
+ }
+ p = Getattr(p, "tmap:directorin:next");
+ continue;
} else if (Cmp(ptype, "void")) {
- /* special handling for pointers to other C++ director classes.
- * ideally this would be left to a typemap, but there is currently no
- * way to selectively apply the dynamic_cast<> to classes that have
- * directors. in other words, the type "SwigDirector_$1_lname" only exists
- * for classes with directors. we avoid the problem here by checking
- * module.wrap::directormap, but it's not clear how to get a typemap to
- * do something similar. perhaps a new default typemap (in addition
- * to SWIGTYPE) called DIRECTORTYPE?
- */
- if (SwigType_ispointer(ptype) || SwigType_isreference(ptype)) {
- Node *module = Getattr(parent, "module");
- Node *target = Swig_directormap(module, ptype);
- sprintf(source, "obj%d", idx++);
- String *nonconst = 0;
- /* strip pointer/reference --- should move to Swig/stype.c */
- String *nptype = NewString(Char(ptype) + 2);
- /* name as pointer */
- String *ppname = Copy(pname);
- if (SwigType_isreference(ptype)) {
- Insert(ppname, 0, "&");
- }
- /* if necessary, cast away const since MATLAB doesn't support it! */
- if (SwigType_isconst(nptype)) {
- nonconst = NewStringf("nc_tmp_%s", pname);
- String *nonconst_i = NewStringf("= const_cast< %s >(%s)", SwigType_lstr(ptype, 0), ppname);
- Wrapper_add_localv(w, nonconst, SwigType_lstr(ptype, 0), nonconst, nonconst_i, NIL);
- Delete(nonconst_i);
- Swig_warning(WARN_LANG_DISCARD_CONST, input_file, line_number,
- "Target language argument '%s' discards const in director method %s::%s.\n",
- SwigType_str(ptype, pname), SwigType_namestr(c_classname), SwigType_namestr(name));
- } else {
- nonconst = Copy(ppname);
- }
- Delete(nptype);
- Delete(ppname);
- String *mangle = SwigType_manglestr(ptype);
- if (target) {
- String *director = NewStringf("director_%s", mangle);
- Wrapper_add_localv(w, director, "Swig::Director *", director, "= 0", NIL);
- Wrapper_add_localv(w, source, "SwigVar_mxArray", source, "= 0", NIL);
- Printf(wrap_args, "%s = SWIG_DIRECTOR_CAST(%s);\n", director, nonconst);
- Printf(wrap_args, "if (!%s) {\n", director);
- Printf(wrap_args, "%s = SWIG_InternalNewPointerObj(%s, SWIGTYPE%s, 0);\n", source, nonconst, mangle);
- Append(wrap_args, "} else {\n");
- Printf(wrap_args, "%s = %s->swig_get_self();\n", source, director);
- Printf(wrap_args, "Py_INCREF((mxArray *)%s);\n", source);
- Append(wrap_args, "}\n");
- Delete(director);
- Printv(arglist, source, NIL);
- } else {
- Wrapper_add_localv(w, source, "SwigVar_mxArray", source, "= 0", NIL);
- Printf(wrap_args, "%s = SWIG_InternalNewPointerObj(%s, SWIGTYPE%s, 0);\n", source, nonconst, mangle);
- //Printf(wrap_args, "%s = SWIG_NewPointerObj(%s, SWIGTYPE_p_%s, 0);\n",
- // source, nonconst, base);
- Printv(arglist, source, NIL);
- }
- Putc('O', parse_args);
- Delete(mangle);
- Delete(nonconst);
- } else {
- Swig_warning(WARN_TYPEMAP_DIRECTORIN_UNDEF, input_file, line_number,
- "Unable to use type %s as a function argument in director method %s::%s (skipping method).\n", SwigType_str(ptype, 0),
- SwigType_namestr(c_classname), SwigType_namestr(name));
- status = SWIG_NOWRAP;
- break;
- }
+ /* special handling for pointers to other C++ director classes.
+ * ideally this would be left to a typemap, but there is currently no
+ * way to selectively apply the dynamic_cast<> to classes that have
+ * directors. in other words, the type "SwigDirector_$1_lname" only exists
+ * for classes with directors. we avoid the problem here by checking
+ * module.wrap::directormap, but it's not clear how to get a typemap to
+ * do something similar. perhaps a new default typemap (in addition
+ * to SWIGTYPE) called DIRECTORTYPE?
+ */
+ if (SwigType_ispointer(ptype) || SwigType_isreference(ptype)) {
+ Node *module = Getattr(parent, "module");
+ Node *target = Swig_directormap(module, ptype);
+ sprintf(source, "obj%d", idx++);
+ String *nonconst = 0;
+ /* strip pointer/reference --- should move to Swig/stype.c */
+ String *nptype = NewString(Char(ptype) + 2);
+ /* name as pointer */
+ String *ppname = Copy(pname);
+ if (SwigType_isreference(ptype)) {
+ Insert(ppname, 0, "&");
+ }
+ /* if necessary, cast away const since MATLAB doesn't support it! */
+ if (SwigType_isconst(nptype)) {
+ nonconst = NewStringf("nc_tmp_%s", pname);
+ String *nonconst_i = NewStringf("= const_cast< %s >(%s)", SwigType_lstr(ptype, 0), ppname);
+ Wrapper_add_localv(w, nonconst, SwigType_lstr(ptype, 0), nonconst, nonconst_i, NIL);
+ Delete(nonconst_i);
+ Swig_warning(WARN_LANG_DISCARD_CONST, input_file, line_number,
+ "Target language argument '%s' discards const in director method %s::%s.\n",
+ SwigType_str(ptype, pname), SwigType_namestr(c_classname), SwigType_namestr(name));
+ } else {
+ nonconst = Copy(ppname);
+ }
+ Delete(nptype);
+ Delete(ppname);
+ String *mangle = SwigType_manglestr(ptype);
+ if (target) {
+ String *director = NewStringf("director_%s", mangle);
+ Wrapper_add_localv(w, director, "Swig::Director *", director, "= 0", NIL);
+ Wrapper_add_localv(w, source, "SwigVar_mxArray", source, "= 0", NIL);
+ Printf(wrap_args, "%s = SWIG_DIRECTOR_CAST(%s);\n", director, nonconst);
+ Printf(wrap_args, "if (!%s) {\n", director);
+ Printf(wrap_args, "%s = SWIG_InternalNewPointerObj(%s, SWIGTYPE%s, 0);\n", source, nonconst, mangle);
+ Append(wrap_args, "} else {\n");
+ Printf(wrap_args, "%s = %s->swig_get_self();\n", source, director);
+ Printf(wrap_args, "Py_INCREF((mxArray *)%s);\n", source);
+ Append(wrap_args, "}\n");
+ Delete(director);
+ Printv(arglist, source, NIL);
+ } else {
+ Wrapper_add_localv(w, source, "SwigVar_mxArray", source, "= 0", NIL);
+ Printf(wrap_args, "%s = SWIG_InternalNewPointerObj(%s, SWIGTYPE%s, 0);\n", source, nonconst, mangle);
+ //Printf(wrap_args, "%s = SWIG_NewPointerObj(%s, SWIGTYPE_p_%s, 0);\n",
+ // source, nonconst, base);
+ Printv(arglist, source, NIL);
+ }
+ Putc('O', parse_args);
+ Delete(mangle);
+ Delete(nonconst);
+ } else {
+ Swig_warning(WARN_TYPEMAP_DIRECTORIN_UNDEF, input_file, line_number,
+ "Unable to use type %s as a function argument in director method %s::%s (skipping method).\n", SwigType_str(ptype, 0),
+ SwigType_namestr(c_classname), SwigType_namestr(name));
+ status = SWIG_NOWRAP;
+ break;
+ }
}
p = nextSibling(p);
}
@@ -1835,27 +1832,23 @@ int MATLAB::classDirectorMethod(Node *n, Node *parent, String *super) {
if (Len(parse_args) > 0) {
if (use_parse) {
} else {
- Printf(w->code, "mxArray* dispatch_in[%d] = {swig_get_self()%s};\n", Len(parse_args)+1, arglist);
- if (outputs) {
- Printf(w->code, "mxArray* dispatch_out[%d];\n", outputs);
- Printf(w->code, "mxArray* error = SWIG_Matlab_CallInterpEx(%d, dispatch_out, %d, dispatch_in, \"%s\");\n",
- outputs, Len(parse_args)+1, symname);
- Printf(w->code, "mxArray* %s = dispatch_out[0];\n",Swig_cresult_name());
- } else {
- Printf(w->code, "mxArray* error = SWIG_Matlab_CallInterpEx(0, 0, %d, dispatch_in, \"%s\");\n",
- Len(parse_args)+1, symname);
- }
+ Printf(w->code, "mxArray* dispatch_in[%d] = {swig_get_self()%s};\n", Len(parse_args) + 1, arglist);
+ if (outputs) {
+ Printf(w->code, "mxArray* dispatch_out[%d];\n", outputs);
+ Printf(w->code, "mxArray* error = SWIG_Matlab_CallInterpEx(%d, dispatch_out, %d, dispatch_in, \"%s\");\n", outputs, Len(parse_args) + 1, symname);
+ Printf(w->code, "mxArray* %s = dispatch_out[0];\n", Swig_cresult_name());
+ } else {
+ Printf(w->code, "mxArray* error = SWIG_Matlab_CallInterpEx(0, 0, %d, dispatch_in, \"%s\");\n", Len(parse_args) + 1, symname);
+ }
}
} else {
Printf(w->code, "mxArray* dispatch_in[1] = {swig_get_self()};\n");
if (outputs) {
- Printf(w->code, "mxArray* dispatch_out[%d];\n", outputs);
- Printf(w->code, "mxArray* error = SWIG_Matlab_CallInterpEx(%d, dispatch_out, 1, dispatch_in, \"%s\");\n",
- outputs, symname);
- Printf(w->code, "mxArray* %s = dispatch_out[0];\n",Swig_cresult_name());
+ Printf(w->code, "mxArray* dispatch_out[%d];\n", outputs);
+ Printf(w->code, "mxArray* error = SWIG_Matlab_CallInterpEx(%d, dispatch_out, 1, dispatch_in, \"%s\");\n", outputs, symname);
+ Printf(w->code, "mxArray* %s = dispatch_out[0];\n", Swig_cresult_name());
} else {
- Printf(w->code, "mxArray* error = SWIG_Matlab_CallInterpEx(0, 0, 1, dispatch_in, \"%s\");\n",
- symname);
+ Printf(w->code, "mxArray* error = SWIG_Matlab_CallInterpEx(0, 0, 1, dispatch_in, \"%s\");\n", symname);
}
}
// todo: destroy
@@ -1869,7 +1862,7 @@ int MATLAB::classDirectorMethod(Node *n, Node *parent, String *super) {
if (!tm) {
tm = Getattr(n, "feature:director:except");
if (tm)
- tm = Copy(tm);
+ tm = Copy(tm);
}
Printf(w->code, "if (error != 0) {\n", Swig_cresult_name());
Printf(w->code, "mexCallMATLAB(0, (mxArray **)NULL,1, &error, \"throw\");");
@@ -1910,50 +1903,50 @@ int MATLAB::classDirectorMethod(Node *n, Node *parent, String *super) {
if (!is_void) {
tm = Swig_typemap_lookup("directorout", n, Swig_cresult_name(), w);
if (tm != 0) {
- if (outputs > 1) {
- Printf(w->code, "output = PyTuple_GetItem(%s, %d);\n", Swig_cresult_name(), idx++);
- Replaceall(tm, "$input", "output");
- } else {
- Replaceall(tm, "$input", Swig_cresult_name());
- }
- char temp[24];
- sprintf(temp, "%d", idx);
- Replaceall(tm, "$argnum", temp);
-
- /* TODO check this */
- if (Getattr(n, "wrap:disown")) {
- Replaceall(tm, "$disown", "SWIG_POINTER_DISOWN");
- } else {
- Replaceall(tm, "$disown", "0");
- }
- if (Getattr(n, "tmap:directorout:implicitconv")) {
- Replaceall(tm, "$implicitconv", get_implicitconv_flag(n));
- }
- Replaceall(tm, "$result", "c_result");
- Printv(w->code, tm, "\n", NIL);
- Delete(tm);
+ if (outputs > 1) {
+ Printf(w->code, "output = PyTuple_GetItem(%s, %d);\n", Swig_cresult_name(), idx++);
+ Replaceall(tm, "$input", "output");
+ } else {
+ Replaceall(tm, "$input", Swig_cresult_name());
+ }
+ char temp[24];
+ sprintf(temp, "%d", idx);
+ Replaceall(tm, "$argnum", temp);
+
+ /* TODO check this */
+ if (Getattr(n, "wrap:disown")) {
+ Replaceall(tm, "$disown", "SWIG_POINTER_DISOWN");
+ } else {
+ Replaceall(tm, "$disown", "0");
+ }
+ if (Getattr(n, "tmap:directorout:implicitconv")) {
+ Replaceall(tm, "$implicitconv", get_implicitconv_flag(n));
+ }
+ Replaceall(tm, "$result", "c_result");
+ Printv(w->code, tm, "\n", NIL);
+ Delete(tm);
} else {
- Swig_warning(WARN_TYPEMAP_DIRECTOROUT_UNDEF, input_file, line_number,
- "Unable to use return type %s in director method %s::%s (skipping method).\n", SwigType_str(returntype, 0), SwigType_namestr(c_classname),
- SwigType_namestr(name));
- status = SWIG_ERROR;
+ Swig_warning(WARN_TYPEMAP_DIRECTOROUT_UNDEF, input_file, line_number,
+ "Unable to use return type %s in director method %s::%s (skipping method).\n", SwigType_str(returntype, 0), SwigType_namestr(c_classname),
+ SwigType_namestr(name));
+ status = SWIG_ERROR;
}
}
/* marshal outputs */
for (p = l; p;) {
if ((tm = Getattr(p, "tmap:directorargout")) != 0) {
- if (outputs > 1) {
- Printf(w->code, "output = PyTuple_GetItem(%s, %d);\n", Swig_cresult_name(), idx++);
- Replaceall(tm, "$result", "output");
- } else {
- Replaceall(tm, "$result", Swig_cresult_name());
- }
- Replaceall(tm, "$input", Getattr(p, "emit:directorinput"));
- Printv(w->code, tm, "\n", NIL);
- p = Getattr(p, "tmap:directorargout:next");
+ if (outputs > 1) {
+ Printf(w->code, "output = PyTuple_GetItem(%s, %d);\n", Swig_cresult_name(), idx++);
+ Replaceall(tm, "$result", "output");
+ } else {
+ Replaceall(tm, "$result", Swig_cresult_name());
+ }
+ Replaceall(tm, "$input", Getattr(p, "emit:directorinput"));
+ Printv(w->code, tm, "\n", NIL);
+ p = Getattr(p, "tmap:directorargout:next");
} else {
- p = nextSibling(p);
+ p = nextSibling(p);
}
}
@@ -1967,9 +1960,9 @@ int MATLAB::classDirectorMethod(Node *n, Node *parent, String *super) {
if (!(ignored_method && !pure_virtual)) {
String *rettype = SwigType_str(returntype, 0);
if (!SwigType_isreference(returntype)) {
- Printf(w->code, "return (%s) c_result;\n", rettype);
+ Printf(w->code, "return (%s) c_result;\n", rettype);
} else {
- Printf(w->code, "return (%s) *c_result;\n", rettype);
+ Printf(w->code, "return (%s) *c_result;\n", rettype);
}
Delete(rettype);
}
@@ -2028,7 +2021,8 @@ int MATLAB::enumvalueDeclaration(Node *n) {
int MATLAB::classHandler(Node *n) {
// Save current class name
- if (class_name) SWIG_exit(EXIT_FAILURE);
+ if (class_name)
+ SWIG_exit(EXIT_FAILURE);
class_name = Getattr(n, "sym:name");
// Wrappers cannot be emitted
@@ -2036,7 +2030,7 @@ int MATLAB::classHandler(Node *n) {
String *mangled_classname = Swig_name_mangle(Getattr(n, "name"));
if (Getattr(emitted, mangled_classname)) {
Delete(mangled_classname);
- class_name=0;
+ class_name = 0;
return SWIG_NOWRAP;
}
Setattr(emitted, mangled_classname, "1");
@@ -2055,14 +2049,12 @@ int MATLAB::classHandler(Node *n) {
SwigType_remember_clientdata(smart, quoted_class_name);
Delete(spt);
Delete(smart);
+ } else {
+ SwigType *t = Copy(Getattr(n, "name"));
+ SwigType_add_pointer(t);
+ SwigType_remember_clientdata(t, quoted_class_name);
+ Delete(t);
}
- else
- {
- SwigType *t = Copy(Getattr(n, "name"));
- SwigType_add_pointer(t);
- SwigType_remember_clientdata(t, quoted_class_name);
- Delete(t);
- }
Delete(quoted_class_name);
Delete(smartptr);
}
@@ -2071,11 +2063,12 @@ int MATLAB::classHandler(Node *n) {
have_destructor = false;
// Name of wrapper .m file
- String* mfile = NewString("");
+ String *mfile = NewString("");
Printf(mfile, "%s/%s.m", pkg_name_fullpath, class_name);
// Create wrapper .m file
- if (f_wrap_m) SWIG_exit(EXIT_FAILURE);
+ if (f_wrap_m)
+ SWIG_exit(EXIT_FAILURE);
f_wrap_m = NewFile(mfile, "w", SWIG_output_files());
if (!f_wrap_m) {
FileErrorDisplay(mfile);
@@ -2083,10 +2076,10 @@ int MATLAB::classHandler(Node *n) {
}
// Declare MATLAB class
- Printf(f_wrap_m,"classdef %s < ", Getattr(n,"sym:name"));
+ Printf(f_wrap_m, "classdef %s < ", Getattr(n, "sym:name"));
// Initialization of base classes
- base_init=NewString("");
+ base_init = NewString("");
// Declare base classes, if any
List *baselist = Getattr(n, "bases");
@@ -2098,57 +2091,59 @@ int MATLAB::classHandler(Node *n) {
#if 0
// some prints for debugging
{
- String *tmpname = Getattr(b.item, "name");
- if (tmpname)
- Printf(stderr,"BASE %s\n", tmpname);
- tmpname = Getattr(b.item, "sym:name");
- if (tmpname)
- Printf(stderr,"BASEsym %s\n", tmpname);
+ String *tmpname = Getattr(b.item, "name");
+ if (tmpname)
+ Printf(stderr, "BASE %s\n", tmpname);
+ tmpname = Getattr(b.item, "sym:name");
+ if (tmpname)
+ Printf(stderr, "BASEsym %s\n", tmpname);
}
#endif
String *bname = Getattr(b.item, "sym:name");
Node *bpkgNode = Getattr(b.item, "module");
String *bpkg = Getattr(bpkgNode, "name");
- if (!bname || !bpkg || GetFlag(b.item,"feature:ignore")) continue;
+ if (!bname || !bpkg || GetFlag(b.item, "feature:ignore"))
+ continue;
base_count++;
// Separate multiple base classes with &
- if (base_count>1) Printf(f_wrap_m," & ");
+ if (base_count > 1)
+ Printf(f_wrap_m, " & ");
// Add to list of bases
- Printf(f_wrap_m,"%s.%s",bpkg,bname);
+ Printf(f_wrap_m, "%s.%s", bpkg, bname);
// Add to initialization
- Printf(base_init," self@%s.%s(SwigRef.Null);\n",bpkg,bname);
+ Printf(base_init, " self@%s.%s(SwigRef.Null);\n", bpkg, bname);
}
}
// Getters and setters for fields
- get_field=NewString("");
- set_field=NewString("");
+ get_field = NewString("");
+ set_field = NewString("");
// Static methods
- static_methods=NewString("");
+ static_methods = NewString("");
// If no bases, top level class
- if (base_count==0) {
- Printf(f_wrap_m,"SwigRef");
+ if (base_count == 0) {
+ Printf(f_wrap_m, "SwigRef");
}
// End of class def
- Printf(f_wrap_m,"\n");
+ Printf(f_wrap_m, "\n");
// Emit documentation
autodoc_to_m(f_wrap_m, n);
// Declare class methods
- Printf(f_wrap_m," methods\n");
+ Printf(f_wrap_m, " methods\n");
// swig_this (not needed if defined in base class)
- if (base_count!=1) { // If >1 bases, need to define to avoid ambiguity
- Printf(f_wrap_m," function this = swig_this(self)\n");
- Printf(f_wrap_m," this = %s(3, self);\n", mex_name); // swigThis has index 3
- Printf(f_wrap_m," end\n");
+ if (base_count != 1) { // If >1 bases, need to define to avoid ambiguity
+ Printf(f_wrap_m, " function this = swig_this(self)\n");
+ Printf(f_wrap_m, " this = %s(3, self);\n", mex_name); // swigThis has index 3
+ Printf(f_wrap_m, " end\n");
}
// Emit member functions
@@ -2157,28 +2152,28 @@ int MATLAB::classHandler(Node *n) {
// Add constructor, if none added
if (!have_constructor) {
checkValidSymName(n);
- wrapConstructor(-1,class_name,0,n);
+ wrapConstructor(-1, class_name, 0, n);
have_constructor = true;
}
// End of non-static methods
- Printf(f_wrap_m," end\n");
+ Printf(f_wrap_m, " end\n");
// Add static methods
- Printf(f_wrap_m," methods(Static)\n");
- Printf(f_wrap_m,"%s",static_methods);
- Printf(f_wrap_m," end\n");
+ Printf(f_wrap_m, " methods(Static)\n");
+ Printf(f_wrap_m, "%s", static_methods);
+ Printf(f_wrap_m, " end\n");
// Finalize file
- Printf(f_wrap_m,"end\n");
+ Printf(f_wrap_m, "end\n");
// Tidy up
Delete(base_init);
- base_init=0;
+ base_init = 0;
Delete(f_wrap_m);
f_wrap_m = 0;
//note: don't Delete class_name as it's not a new object
- class_name=0;
+ class_name = 0;
Delete(mfile);
Delete(get_field);
get_field = 0;
@@ -2192,101 +2187,104 @@ int MATLAB::classHandler(Node *n) {
int MATLAB::memberfunctionHandler(Node *n) {
// Emit C wrappers
int flag = Language::memberfunctionHandler(n);
- if (flag!=SWIG_OK) return flag;
+ if (flag != SWIG_OK)
+ return flag;
// No MATLAB wrapper for the overloads
bool overloaded = !!Getattr(n, "sym:overloaded");
bool last_overload = overloaded && !Getattr(n, "sym:nextSibling");
- if (overloaded && !last_overload) return flag;
+ if (overloaded && !last_overload)
+ return flag;
// Add to function switch
String *symname = Getattr(n, "sym:name");
String *fullname = Swig_name_member(NSPACE_TODO, class_name, symname);
String *wname = Swig_name_wrapper(fullname);
- int gw_ind = toGateway(fullname,wname);
+ int gw_ind = toGateway(fullname, wname);
// Add function to .m wrapper
checkValidSymName(n);
- const char* varginstr = GetFlag(n, "feature:varargin") ? "varargin" : "varargin{:}";
- Printf(f_wrap_m," function varargout = %s(self,varargin)\n",symname);
+ const char *varginstr = GetFlag(n, "feature:varargin") ? "varargin" : "varargin{:}";
+ Printf(f_wrap_m, " function varargout = %s(self,varargin)\n", symname);
autodoc_to_m(f_wrap_m, n);
if (have_matlabprepend(n))
- Printf(f_wrap_m, "%s\n",matlabprepend(n));
+ Printf(f_wrap_m, "%s\n", matlabprepend(n));
if (GetFlag(n, "feature:convertself") && checkAttribute(n, "qualifier", "q(const).")) {
// explicit type conversion of self
- Printf(f_wrap_m," if ~isa(self,'%s.%s')\n",pkg_name,class_name);
- Printf(f_wrap_m," self = %s.%s(self);\n", pkg_name,class_name);
- Printf(f_wrap_m," end\n");
+ Printf(f_wrap_m, " if ~isa(self,'%s.%s')\n", pkg_name, class_name);
+ Printf(f_wrap_m, " self = %s.%s(self);\n", pkg_name, class_name);
+ Printf(f_wrap_m, " end\n");
}
if (GetFlag(n, "feature:optionalunpack")) {
- Printf(f_wrap_m," out = %s(%d, self, %s);\n", mex_name, gw_ind, varginstr);
- Printf(f_wrap_m," if nargout<=1\n");
- Printf(f_wrap_m," varargout{1}=out;\n");
- Printf(f_wrap_m," else\n");
- Printf(f_wrap_m," nargoutchk(length(out),length(out))\n");
- Printf(f_wrap_m," for i=1:nargout\n");
- Printf(f_wrap_m," varargout{i} = out(i);\n");
- Printf(f_wrap_m," end\n");
- Printf(f_wrap_m," end\n");
+ Printf(f_wrap_m, " out = %s(%d, self, %s);\n", mex_name, gw_ind, varginstr);
+ Printf(f_wrap_m, " if nargout<=1\n");
+ Printf(f_wrap_m, " varargout{1}=out;\n");
+ Printf(f_wrap_m, " else\n");
+ Printf(f_wrap_m, " nargoutchk(length(out),length(out))\n");
+ Printf(f_wrap_m, " for i=1:nargout\n");
+ Printf(f_wrap_m, " varargout{i} = out(i);\n");
+ Printf(f_wrap_m, " end\n");
+ Printf(f_wrap_m, " end\n");
} else {
- Printf(f_wrap_m," [varargout{1:nargout}] = %s(%d, self, %s);\n", mex_name, gw_ind, varginstr);
+ Printf(f_wrap_m, " [varargout{1:nargout}] = %s(%d, self, %s);\n", mex_name, gw_ind, varginstr);
}
if (have_matlabappend(n))
- Printf(f_wrap_m, "%s\n",matlabappend(n));
- Printf(f_wrap_m," end\n");
+ Printf(f_wrap_m, "%s\n", matlabappend(n));
+ Printf(f_wrap_m, " end\n");
Delete(wname);
Delete(fullname);
return flag;
}
void MATLAB::initGateway() {
- if (CPlusPlus) Printf(f_gateway,"extern \"C\"\n");
- Printf(f_gateway,"void mexFunction(int resc, mxArray *resv[], int argc, const mxArray *argv[]) {\n");
+ if (CPlusPlus)
+ Printf(f_gateway, "extern \"C\"\n");
+ Printf(f_gateway, "void mexFunction(int resc, mxArray *resv[], int argc, const mxArray *argv[]) {\n");
// Load module if first call
- Printf(f_gateway," /* Initialize module if first call */\n");
- Printf(f_gateway," SWIG_Matlab_LoadModule();\n\n");
+ Printf(f_gateway, " /* Initialize module if first call */\n");
+ Printf(f_gateway, " SWIG_Matlab_LoadModule();\n\n");
// The first argument is always the ID
- Printf(f_gateway," if (--argc < 0 || !mxIsDouble(*argv) || mxGetNumberOfElements(*argv)!=1)\n");
- Printf(f_gateway," mexErrMsgTxt(\"This mex file should only be called from inside the .m files generated by SWIG. First input should be the function ID .\");\n");
- Printf(f_gateway," int fcn_id = (int)mxGetScalar(*argv++);\n");
+ Printf(f_gateway, " if (--argc < 0 || !mxIsDouble(*argv) || mxGetNumberOfElements(*argv)!=1)\n");
+ Printf(f_gateway,
+ " mexErrMsgTxt(\"This mex file should only be called from inside the .m files generated by SWIG. First input should be the function ID .\");\n");
+ Printf(f_gateway, " int fcn_id = (int)mxGetScalar(*argv++);\n");
// Redirect std::cout and std::cerr to SWIG_Matlab_cout
if (CPlusPlus && redirectoutput) {
Printf(f_gateway, " std::streambuf *cout_backup = std::cout.rdbuf(&swig::SWIG_Matlab_buf);\n");
Printf(f_gateway, " std::streambuf *cerr_backup = std::cerr.rdbuf(&swig::SWIG_Matlab_buf);\n");
}
-
// Begin the switch:
- Printf(f_gateway," int flag=0;\n");
- Printf(f_gateway," switch (fcn_id) {\n");
+ Printf(f_gateway, " int flag=0;\n");
+ Printf(f_gateway, " switch (fcn_id) {\n");
// List of function names
l_fnames = NewList();
// Constants retrieval function has index 0
- String* fname=NewString("swigConstant");
+ String *fname = NewString("swigConstant");
toGateway(fname, fname);
Delete(fname);
// Function name retrieval function has index 1
- fname=NewString("swigFunctionName");
+ fname = NewString("swigFunctionName");
toGateway(fname, fname);
Delete(fname);
// Constant name retrieval function has index 2
- fname=NewString("swigConstantName");
+ fname = NewString("swigConstantName");
toGateway(fname, fname);
Delete(fname);
// Memory retrieval function has index 3
- fname=NewString("swigThis");
+ fname = NewString("swigThis");
toGateway(fname, fname);
Delete(fname);
// Just touching the module (to load) has index 4
- fname=NewString("swigTouch");
+ fname = NewString("swigTouch");
toGateway(fname, fname);
Delete(fname);
}
@@ -2296,38 +2294,40 @@ int MATLAB::toGateway(String *fullname, String *wname) {
Append(l_fnames, Copy(fullname));
// Add to gateway
- Printf(f_gateway," case %d: flag=%s(resc,resv,argc,(mxArray**)(argv)); break;\n",num_gateway, wname);
+ Printf(f_gateway, " case %d: flag=%s(resc,resv,argc,(mxArray**)(argv)); break;\n", num_gateway, wname);
return num_gateway++;
}
void MATLAB::finalizeGateway() {
- Printf(f_gateway," default: flag=1, SWIG_Error(SWIG_RuntimeError, \"No function id %%d.\", fcn_id);\n");
- Printf(f_gateway," }\n");
+ Printf(f_gateway, " default: flag=1, SWIG_Error(SWIG_RuntimeError, \"No function id %%d.\", fcn_id);\n");
+ Printf(f_gateway, " }\n");
// Restore std::cout and std::cerr
if (CPlusPlus && redirectoutput) {
Printf(f_gateway, " std::cout.rdbuf(cout_backup);\n");
Printf(f_gateway, " std::cerr.rdbuf(cerr_backup);\n");
}
- Printf(f_gateway," if (flag) {\n");
- Printf(f_gateway," mexErrMsgIdAndTxt(SWIG_ErrorType(SWIG_lasterror_code), SWIG_lasterror_msg);\n");
- Printf(f_gateway," }\n");
- Printf(f_gateway,"}\n");
+ Printf(f_gateway, " if (flag) {\n");
+ Printf(f_gateway, " mexErrMsgIdAndTxt(SWIG_ErrorType(SWIG_lasterror_code), SWIG_lasterror_msg);\n");
+ Printf(f_gateway, " }\n");
+ Printf(f_gateway, "}\n");
}
void MATLAB::initConstant() {
- if (CPlusPlus) Printf(f_constants,"extern \"C\"\n");
- Printf(f_constants,"int swigConstant(int /*resc*/, mxArray *resv[], int argc, mxArray *argv[]) {\n");
+ if (CPlusPlus)
+ Printf(f_constants, "extern \"C\"\n");
+ Printf(f_constants, "int swigConstant(int /*resc*/, mxArray *resv[], int argc, mxArray *argv[]) {\n");
// The first argument is always the ID
- Printf(f_constants," if (--argc < 0 || !mxIsDouble(*argv) || mxGetNumberOfElements(*argv)!=1) {\n");
- Printf(f_constants," SWIG_Error(SWIG_RuntimeError, \"This function should only be called from inside the .m files generated by SWIG. First input should be the constant ID .\");\n");
- Printf(f_constants," return 1;\n");
- Printf(f_constants," }\n");
- Printf(f_constants," int con_id = (int)mxGetScalar(*argv++);\n");
+ Printf(f_constants, " if (--argc < 0 || !mxIsDouble(*argv) || mxGetNumberOfElements(*argv)!=1) {\n");
+ Printf(f_constants,
+ " SWIG_Error(SWIG_RuntimeError, \"This function should only be called from inside the .m files generated by SWIG. First input should be the constant ID .\");\n");
+ Printf(f_constants, " return 1;\n");
+ Printf(f_constants, " }\n");
+ Printf(f_constants, " int con_id = (int)mxGetScalar(*argv++);\n");
// Begin the switch:
- Printf(f_constants," switch (con_id) {\n");
+ Printf(f_constants, " switch (con_id) {\n");
// List of all constants
l_cnames = NewList();
@@ -2338,20 +2338,20 @@ int MATLAB::toConstant(String *constname, String *constdef) {
Append(l_cnames, Copy(constname));
// Add to gateway
- Printf(f_constants," case %d: *resv = %s; break;\n",num_constant,constdef);
+ Printf(f_constants, " case %d: *resv = %s; break;\n", num_constant, constdef);
return num_constant++;
}
void MATLAB::finalizeConstant() {
- Printf(f_constants," default:\n");
- Printf(f_constants," SWIG_Error(SWIG_RuntimeError, \"No such constant.\");\n");
- Printf(f_constants," return 1;\n");
- Printf(f_constants," }\n");
+ Printf(f_constants, " default:\n");
+ Printf(f_constants, " SWIG_Error(SWIG_RuntimeError, \"No such constant.\");\n");
+ Printf(f_constants, " return 1;\n");
+ Printf(f_constants, " }\n");
if (num_constant == 0) {
- Printf(f_constants," (void)resv; // Unused variable\n");
+ Printf(f_constants, " (void)resv; // Unused variable\n");
}
- Printf(f_constants," return 0;\n");
- Printf(f_constants,"}\n");
+ Printf(f_constants, " return 0;\n");
+ Printf(f_constants, "}\n");
}
int MATLAB::membervariableHandler(Node *n) {
@@ -2362,30 +2362,30 @@ int MATLAB::membervariableHandler(Node *n) {
// Add getter function
String *getname = Swig_name_get(NSPACE_TODO, Swig_name_member(NSPACE_TODO, class_name, symname));
String *getwname = Swig_name_wrapper(getname);
- int gw_ind_get = toGateway(getname,getwname);
+ int gw_ind_get = toGateway(getname, getwname);
if (!is_assignable(n)) {
// Only getter function
- Printf(f_wrap_m," function v = %s(self)\n", symname);
- Printf(f_wrap_m," v = %s(%d, self);\n", mex_name, gw_ind_get);
- Printf(f_wrap_m," end\n");
+ Printf(f_wrap_m, " function v = %s(self)\n", symname);
+ Printf(f_wrap_m, " v = %s(%d, self);\n", mex_name, gw_ind_get);
+ Printf(f_wrap_m, " end\n");
} else {
// Add setter function
String *setname = Swig_name_set(NSPACE_TODO, Swig_name_member(NSPACE_TODO, class_name, symname));
String *setwname = Swig_name_wrapper(setname);
- int gw_ind_set = toGateway(setname,setwname);
+ int gw_ind_set = toGateway(setname, setwname);
// Getter and setter function
- Printf(f_wrap_m," function varargout = %s(self, varargin)\n", symname);
- Printf(f_wrap_m," narginchk(1, 2)\n");
- Printf(f_wrap_m," if nargin==1\n");
- Printf(f_wrap_m," nargoutchk(0, 1)\n");
- Printf(f_wrap_m," varargout{1} = %s(%d, self);\n", mex_name, gw_ind_get);
- Printf(f_wrap_m," else\n");
- Printf(f_wrap_m," nargoutchk(0, 0)\n");
- Printf(f_wrap_m," %s(%d, self, varargin{1});\n", mex_name, gw_ind_set);
- Printf(f_wrap_m," end\n");
- Printf(f_wrap_m," end\n");
+ Printf(f_wrap_m, " function varargout = %s(self, varargin)\n", symname);
+ Printf(f_wrap_m, " narginchk(1, 2)\n");
+ Printf(f_wrap_m, " if nargin==1\n");
+ Printf(f_wrap_m, " nargoutchk(0, 1)\n");
+ Printf(f_wrap_m, " varargout{1} = %s(%d, self);\n", mex_name, gw_ind_get);
+ Printf(f_wrap_m, " else\n");
+ Printf(f_wrap_m, " nargoutchk(0, 0)\n");
+ Printf(f_wrap_m, " %s(%d, self, varargin{1});\n", mex_name, gw_ind_set);
+ Printf(f_wrap_m, " end\n");
+ Printf(f_wrap_m, " end\n");
// Tidy up
Delete(setname);
@@ -2400,55 +2400,57 @@ int MATLAB::membervariableHandler(Node *n) {
}
void MATLAB::wrapConstructor(int gw_ind, String *symname, String *fullname, Node *n) {
- Printf(f_wrap_m," function self = %s(varargin)\n",symname);
- Printf(f_wrap_m,"%s",base_init);
- Printf(f_wrap_m," if nargin==1 && strcmp(class(varargin{1}),'SwigRef')\n");
- Printf(f_wrap_m," if ~isnull(varargin{1})\n");
- Printf(f_wrap_m," self.swigPtr = varargin{1}.swigPtr;\n");
- Printf(f_wrap_m," end\n");
- Printf(f_wrap_m," else\n");
- if (fullname==0) {
- Printf(f_wrap_m," error('No matching constructor');\n");
+ Printf(f_wrap_m, " function self = %s(varargin)\n", symname);
+ Printf(f_wrap_m, "%s", base_init);
+ Printf(f_wrap_m, " if nargin==1 && strcmp(class(varargin{1}),'SwigRef')\n");
+ Printf(f_wrap_m, " if ~isnull(varargin{1})\n");
+ Printf(f_wrap_m, " self.swigPtr = varargin{1}.swigPtr;\n");
+ Printf(f_wrap_m, " end\n");
+ Printf(f_wrap_m, " else\n");
+ if (fullname == 0) {
+ Printf(f_wrap_m, " error('No matching constructor');\n");
} else {
// How to get working on C side? Commented out, replaced by hack below
// Printf(f_wrap_m," self.swigPtr = %s(%d, varargin{:});\n", mex_name, gw_ind);
if (have_matlabprepend(n))
- Printf(f_wrap_m, "%s\n",matlabprepend(n));
- Printf(f_wrap_m," tmp = %s(%d, varargin{:});\n", mex_name, gw_ind);
- Printf(f_wrap_m," self.swigPtr = tmp.swigPtr;\n");
- Printf(f_wrap_m," tmp.swigPtr = [];\n");
+ Printf(f_wrap_m, "%s\n", matlabprepend(n));
+ Printf(f_wrap_m, " tmp = %s(%d, varargin{:});\n", mex_name, gw_ind);
+ Printf(f_wrap_m, " self.swigPtr = tmp.swigPtr;\n");
+ Printf(f_wrap_m, " tmp.swigPtr = [];\n");
if (have_matlabappend(n))
- Printf(f_wrap_m, "%s\n",matlabappend(n));
+ Printf(f_wrap_m, "%s\n", matlabappend(n));
}
- Printf(f_wrap_m," end\n");
- Printf(f_wrap_m," end\n");
+ Printf(f_wrap_m, " end\n");
+ Printf(f_wrap_m, " end\n");
}
void MATLAB::wrapConstructorDirector(int gw_ind, String *symname, String *fullname, Node *n) {
- Printf(f_wrap_m," function self = %s(varargin)\n",symname);
- Printf(f_wrap_m,"%s",base_init);
- Printf(f_wrap_m," if nargin==1 && strcmp(class(varargin{1}),'SwigRef')\n");
- Printf(f_wrap_m," if ~isnull(varargin{1})\n");
- Printf(f_wrap_m," self.swigPtr = varargin{1}.swigPtr;\n");
- Printf(f_wrap_m," end\n");
- Printf(f_wrap_m," else\n");
- if (fullname==0) {
- Printf(f_wrap_m," error('No matching constructor');\n");
+ Printf(f_wrap_m, " function self = %s(varargin)\n", symname);
+ Printf(f_wrap_m, "%s", base_init);
+ Printf(f_wrap_m, " if nargin==1 && strcmp(class(varargin{1}),'SwigRef')\n");
+ Printf(f_wrap_m, " if ~isnull(varargin{1})\n");
+ Printf(f_wrap_m, " self.swigPtr = varargin{1}.swigPtr;\n");
+ Printf(f_wrap_m, " end\n");
+ Printf(f_wrap_m, " else\n");
+ if (fullname == 0) {
+ Printf(f_wrap_m, " error('No matching constructor');\n");
} else {
// How to get working on C side? Commented out, replaed by hack below
// Printf(f_wrap_m," self.swigPtr = %s(%d, varargin{:});\n", mex_name, gw_ind);
- if (have_matlabprepend(n)) Printf(f_wrap_m, "%s\n", matlabprepend(n));
- Printf(f_wrap_m," if strcmp(class(self),'director_basic.%s')\n", symname);
- Printf(f_wrap_m," tmp = %s(%d, 0, varargin{:});\n", mex_name, gw_ind);
- Printf(f_wrap_m," else\n");
- Printf(f_wrap_m," tmp = %s(%d, self, varargin{:});\n", mex_name, gw_ind);
- Printf(f_wrap_m," end\n");
- Printf(f_wrap_m," self.swigPtr = tmp.swigPtr;\n");
- Printf(f_wrap_m," tmp.swigPtr = [];\n");
- if (have_matlabappend(n)) Printf(f_wrap_m, "%s\n",matlabappend(n));
- }
- Printf(f_wrap_m," end\n");
- Printf(f_wrap_m," end\n");
+ if (have_matlabprepend(n))
+ Printf(f_wrap_m, "%s\n", matlabprepend(n));
+ Printf(f_wrap_m, " if strcmp(class(self),'director_basic.%s')\n", symname);
+ Printf(f_wrap_m, " tmp = %s(%d, 0, varargin{:});\n", mex_name, gw_ind);
+ Printf(f_wrap_m, " else\n");
+ Printf(f_wrap_m, " tmp = %s(%d, self, varargin{:});\n", mex_name, gw_ind);
+ Printf(f_wrap_m, " end\n");
+ Printf(f_wrap_m, " self.swigPtr = tmp.swigPtr;\n");
+ Printf(f_wrap_m, " tmp.swigPtr = [];\n");
+ if (have_matlabappend(n))
+ Printf(f_wrap_m, "%s\n", matlabappend(n));
+ }
+ Printf(f_wrap_m, " end\n");
+ Printf(f_wrap_m, " end\n");
}
int MATLAB::constructorHandler(Node *n) {
@@ -2464,14 +2466,14 @@ int MATLAB::constructorHandler(Node *n) {
// Add to function switch
String *wname = Swig_name_wrapper(fullname);
- int gw_ind = toGateway(fullname,wname);
+ int gw_ind = toGateway(fullname, wname);
// Add to .m file
checkValidSymName(n);
if (use_director) {
- wrapConstructorDirector(gw_ind,symname,fullname, n);
+ wrapConstructorDirector(gw_ind, symname, fullname, n);
} else {
- wrapConstructor(gw_ind,symname,fullname, n);
+ wrapConstructor(gw_ind, symname, fullname, n);
}
Delete(wname);
@@ -2502,22 +2504,22 @@ int MATLAB::constructorHandler(Node *n) {
int MATLAB::destructorHandler(Node *n) {
have_destructor = true;
- Printf(f_wrap_m," function delete(self)\n");
+ Printf(f_wrap_m, " function delete(self)\n");
String *symname = Getattr(n, "sym:name");
String *fullname = Swig_name_destroy(NSPACE_TODO, symname);
// Add to function switch
String *wname = Swig_name_wrapper(fullname);
- int gw_ind = toGateway(fullname,wname);
- Printf(f_wrap_m," if self.swigPtr\n");
- Printf(f_wrap_m," %s(%d, self);\n", mex_name, gw_ind);
+ int gw_ind = toGateway(fullname, wname);
+ Printf(f_wrap_m, " if self.swigPtr\n");
+ Printf(f_wrap_m, " %s(%d, self);\n", mex_name, gw_ind);
// Prevent that the object gets deleted another time.
// This is important for MATLAB as for class hierarchies, it calls delete for
// each class in the hierarchy. This isn't the case for C++ which only calls the
// destructor of the "leaf-class", which should take care of deleting everything.
- Printf(f_wrap_m," self.swigPtr=[];\n");
- Printf(f_wrap_m," end\n");
- Printf(f_wrap_m," end\n");
+ Printf(f_wrap_m, " self.swigPtr=[];\n");
+ Printf(f_wrap_m, " end\n");
+ Printf(f_wrap_m, " end\n");
Delete(wname);
Delete(fullname);
@@ -2528,45 +2530,47 @@ int MATLAB::destructorHandler(Node *n) {
int MATLAB::staticmemberfunctionHandler(Node *n) {
// Emit C wrappers
int flag = Language::staticmemberfunctionHandler(n);
- if (flag!=SWIG_OK) return flag;
+ if (flag != SWIG_OK)
+ return flag;
// No MATLAB wrapper for the overloads
bool overloaded = !!Getattr(n, "sym:overloaded");
bool last_overload = overloaded && !Getattr(n, "sym:nextSibling");
- if (overloaded && !last_overload) return flag;
+ if (overloaded && !last_overload)
+ return flag;
// Add to function switch
String *symname = Getattr(n, "sym:name");
String *fullname = Swig_name_member(NSPACE_TODO, class_name, symname);
String *wname = Swig_name_wrapper(fullname);
- int gw_ind = toGateway(fullname,wname);
+ int gw_ind = toGateway(fullname, wname);
// Add function to .m wrapper
checkValidSymName(n);
File *wrapper = GetFlag(n, "feature:nonstatic") ? f_wrap_m : static_methods;
- const char* varginstr = GetFlag(n, "feature:varargin") ? "varargin" : "varargin{:}";
- Printf(wrapper," function varargout = %s(varargin)\n",symname);
+ const char *varginstr = GetFlag(n, "feature:varargin") ? "varargin" : "varargin{:}";
+ Printf(wrapper, " function varargout = %s(varargin)\n", symname);
autodoc_to_m(wrapper, n);
if (have_matlabprepend(n)) {
Printf(wrapper, "%s\n", Char(matlabprepend(n)));
}
if (GetFlag(n, "feature:optionalunpack")) {
- Printf(wrapper," out = %s(%d, %s);\n", mex_name, gw_ind, varginstr);
- Printf(wrapper," if nargout<=1\n");
- Printf(wrapper," varargout{1}=out;\n");
- Printf(wrapper," else\n");
- Printf(wrapper," nargoutchk(length(out),length(out))\n");
- Printf(wrapper," for i=1:nargout\n");
- Printf(wrapper," varargout{i} = out(i);\n");
- Printf(wrapper," end\n");
- Printf(wrapper," end\n");
+ Printf(wrapper, " out = %s(%d, %s);\n", mex_name, gw_ind, varginstr);
+ Printf(wrapper, " if nargout<=1\n");
+ Printf(wrapper, " varargout{1}=out;\n");
+ Printf(wrapper, " else\n");
+ Printf(wrapper, " nargoutchk(length(out),length(out))\n");
+ Printf(wrapper, " for i=1:nargout\n");
+ Printf(wrapper, " varargout{i} = out(i);\n");
+ Printf(wrapper, " end\n");
+ Printf(wrapper, " end\n");
} else {
- Printf(wrapper," [varargout{1:nargout}] = %s(%d, %s);\n", mex_name, gw_ind, varginstr);
+ Printf(wrapper, " [varargout{1:nargout}] = %s(%d, %s);\n", mex_name, gw_ind, varginstr);
}
if (have_matlabappend(n)) {
Printf(wrapper, "%s\n", Char(matlabappend(n)));
}
- Printf(wrapper," end\n");
+ Printf(wrapper, " end\n");
Delete(wname);
Delete(fullname);
@@ -2576,7 +2580,8 @@ int MATLAB::staticmemberfunctionHandler(Node *n) {
int MATLAB::memberconstantHandler(Node *n) {
// Emit C wrappers
int flag = Language::memberconstantHandler(n);
- if (flag!=SWIG_OK) return flag;
+ if (flag != SWIG_OK)
+ return flag;
// Name of variable
String *symname = Getattr(n, "sym:name");
@@ -2586,13 +2591,13 @@ int MATLAB::memberconstantHandler(Node *n) {
// Add getter function
checkValidSymName(n);
- Printf(static_methods," function v = %s()\n", symname);
- Printf(static_methods," persistent vInitialized;\n");
- Printf(static_methods," if isempty(vInitialized)\n");
- Printf(static_methods," vInitialized = %s(0, %d);\n", mex_name, con_id);
- Printf(static_methods," end\n");
- Printf(static_methods," v = vInitialized;\n");
- Printf(static_methods," end\n");
+ Printf(static_methods, " function v = %s()\n", symname);
+ Printf(static_methods, " persistent vInitialized;\n");
+ Printf(static_methods, " if isempty(vInitialized)\n");
+ Printf(static_methods, " vInitialized = %s(0, %d);\n", mex_name, con_id);
+ Printf(static_methods, " end\n");
+ Printf(static_methods, " v = vInitialized;\n");
+ Printf(static_methods, " end\n");
// Tidy up
Delete(fullname);
@@ -2621,7 +2626,8 @@ int MATLAB::staticmembervariableHandler(Node *n) {
return SWIG_ERROR;
// Quick return if already wrapped
- if (GetFlag(n, "wrappedasconstant"))return SWIG_OK;
+ if (GetFlag(n, "wrappedasconstant"))
+ return SWIG_OK;
// Name of variable
checkValidSymName(n);
@@ -2630,38 +2636,38 @@ int MATLAB::staticmembervariableHandler(Node *n) {
// Add getter function
String *getname = Swig_name_get(NSPACE_TODO, Swig_name_member(NSPACE_TODO, class_name, symname));
String *getwname = Swig_name_wrapper(getname);
- int gw_ind_get = toGateway(getname,getwname);
+ int gw_ind_get = toGateway(getname, getwname);
if (!is_assignable(n)) {
// Only getter
- Printf(static_methods," function v = %s()\n",symname);
+ Printf(static_methods, " function v = %s()\n", symname);
if (have_matlabprepend(n))
Printf(static_methods, "%s\n", Char(matlabprepend(n)));
- Printf(static_methods," v = %s(%d);\n",mex_name, gw_ind_get);
+ Printf(static_methods, " v = %s(%d);\n", mex_name, gw_ind_get);
if (have_matlabappend(n))
Printv(static_methods, "%s\n", Char(matlabappend(n)));
- Printf(static_methods," end\n");
+ Printf(static_methods, " end\n");
} else {
// Add setter function
String *setname = Swig_name_set(NSPACE_TODO, Swig_name_member(NSPACE_TODO, class_name, symname));
String *setwname = Swig_name_wrapper(setname);
- int gw_ind_set = toGateway(setname,setwname);
+ int gw_ind_set = toGateway(setname, setwname);
// Getter and setter
- Printf(static_methods," function varargout = %s(varargin)\n",symname);
- Printf(static_methods," narginchk(0,1)\n");
+ Printf(static_methods, " function varargout = %s(varargin)\n", symname);
+ Printf(static_methods, " narginchk(0,1)\n");
if (have_matlabprepend(n))
Printf(static_methods, "%s\n", Char(matlabprepend(n)));
- Printf(static_methods," if nargin==0\n");
- Printf(static_methods," nargoutchk(0,1)\n");
- Printf(static_methods," varargout{1} = %s(%d);\n",mex_name,gw_ind_get);
- Printf(static_methods," else\n");
- Printf(static_methods," nargoutchk(0,0)\n");
- Printf(static_methods," %s(%d, varargin{1});\n",mex_name,gw_ind_set);
- Printf(static_methods," end\n");
+ Printf(static_methods, " if nargin==0\n");
+ Printf(static_methods, " nargoutchk(0,1)\n");
+ Printf(static_methods, " varargout{1} = %s(%d);\n", mex_name, gw_ind_get);
+ Printf(static_methods, " else\n");
+ Printf(static_methods, " nargoutchk(0,0)\n");
+ Printf(static_methods, " %s(%d, varargin{1});\n", mex_name, gw_ind_set);
+ Printf(static_methods, " end\n");
if (have_matlabappend(n))
Printf(static_methods, "%s\n", Char(matlabappend(n)));
- Printf(static_methods," end\n");
+ Printf(static_methods, " end\n");
// Tidy up
Delete(setname);
@@ -2684,10 +2690,10 @@ int MATLAB::staticmembervariableHandler(Node *n) {
void MATLAB::nameUnnamedParams(ParmList *parms, bool all) {
Parm *p;
int i;
- for (p = parms, i=1; p; p = nextSibling(p),i++) {
- if (all || !Getattr(p,"name")) {
- String* parname=NewStringf("swig_par_name_%d", i);
- Setattr(p,"name",parname);
+ for (p = parms, i = 1; p; p = nextSibling(p), i++) {
+ if (all || !Getattr(p, "name")) {
+ String *parname = NewStringf("swig_par_name_%d", i);
+ Setattr(p, "name", parname);
}
}
@@ -2703,44 +2709,44 @@ String *MATLAB::getOverloadedName(Node *n) {
void MATLAB::createSwigRef() {
// Create file
- String* mfile = NewString(SWIG_output_directory());
+ String *mfile = NewString(SWIG_output_directory());
Append(mfile, "SwigRef.m");
- if (f_wrap_m) SWIG_exit(EXIT_FAILURE);
+ if (f_wrap_m)
+ SWIG_exit(EXIT_FAILURE);
f_wrap_m = NewFile(mfile, "w", SWIG_output_files());
if (!f_wrap_m) {
FileErrorDisplay(mfile);
SWIG_exit(EXIT_FAILURE);
}
-
// Output SwigRef abstract base class
- Printf(f_wrap_m,"classdef SwigRef < handle\n");
- Printf(f_wrap_m," properties(Hidden = true, Access = public) \n");
- Printf(f_wrap_m," swigPtr\n");
- Printf(f_wrap_m," end\n");
- Printf(f_wrap_m," methods(Static = true, Access = protected)\n");
- Printf(f_wrap_m," function obj = Null()\n");
- Printf(f_wrap_m," persistent obj_null\n");
- Printf(f_wrap_m," if isempty(obj_null)\n");
- Printf(f_wrap_m," obj_null = SwigRef();\n");
- Printf(f_wrap_m," end\n");
- Printf(f_wrap_m," obj = obj_null;\n");
- Printf(f_wrap_m," end\n");
- Printf(f_wrap_m," end\n");
- Printf(f_wrap_m," methods\n");
- Printf(f_wrap_m," function out = saveobj(self)\n");
- Printf(f_wrap_m," error('Serializing SWIG objects not supported.')\n");
- Printf(f_wrap_m," end\n");
- Printf(f_wrap_m," function b = isnull(self)\n");
- Printf(f_wrap_m," b = isempty(self.swigPtr);\n");
- Printf(f_wrap_m," end\n");
- Printf(f_wrap_m," function SwigSet(self,ptr)\n");
- Printf(f_wrap_m," self.swigPtr = ptr;\n");
- Printf(f_wrap_m," end\n");
- Printf(f_wrap_m," function ptr = SwigGet(self)\n");
- Printf(f_wrap_m," ptr = self.swigPtr;\n");
- Printf(f_wrap_m," end\n");
- Printf(f_wrap_m," end\n");
- Printf(f_wrap_m,"end\n");
+ Printf(f_wrap_m, "classdef SwigRef < handle\n");
+ Printf(f_wrap_m, " properties(Hidden = true, Access = public) \n");
+ Printf(f_wrap_m, " swigPtr\n");
+ Printf(f_wrap_m, " end\n");
+ Printf(f_wrap_m, " methods(Static = true, Access = protected)\n");
+ Printf(f_wrap_m, " function obj = Null()\n");
+ Printf(f_wrap_m, " persistent obj_null\n");
+ Printf(f_wrap_m, " if isempty(obj_null)\n");
+ Printf(f_wrap_m, " obj_null = SwigRef();\n");
+ Printf(f_wrap_m, " end\n");
+ Printf(f_wrap_m, " obj = obj_null;\n");
+ Printf(f_wrap_m, " end\n");
+ Printf(f_wrap_m, " end\n");
+ Printf(f_wrap_m, " methods\n");
+ Printf(f_wrap_m, " function out = saveobj(self)\n");
+ Printf(f_wrap_m, " error('Serializing SWIG objects not supported.')\n");
+ Printf(f_wrap_m, " end\n");
+ Printf(f_wrap_m, " function b = isnull(self)\n");
+ Printf(f_wrap_m, " b = isempty(self.swigPtr);\n");
+ Printf(f_wrap_m, " end\n");
+ Printf(f_wrap_m, " function SwigSet(self,ptr)\n");
+ Printf(f_wrap_m, " self.swigPtr = ptr;\n");
+ Printf(f_wrap_m, " end\n");
+ Printf(f_wrap_m, " function ptr = SwigGet(self)\n");
+ Printf(f_wrap_m, " ptr = self.swigPtr;\n");
+ Printf(f_wrap_m, " end\n");
+ Printf(f_wrap_m, " end\n");
+ Printf(f_wrap_m, "end\n");
// Tidy up
Delete(f_wrap_m);
@@ -2750,34 +2756,34 @@ void MATLAB::createSwigRef() {
void MATLAB::createSwigMem() {
// Create file
- String* mfile = NewString(SWIG_output_directory());
+ String *mfile = NewString(SWIG_output_directory());
Append(mfile, "SwigMem.m");
- if (f_wrap_m) SWIG_exit(EXIT_FAILURE);
+ if (f_wrap_m)
+ SWIG_exit(EXIT_FAILURE);
f_wrap_m = NewFile(mfile, "w", SWIG_output_files());
if (!f_wrap_m) {
FileErrorDisplay(mfile);
SWIG_exit(EXIT_FAILURE);
}
-
// Output SwigMem function
- Printf(f_wrap_m,"function varargout = SwigMem(varargin)\n");
- Printf(f_wrap_m," persistent mem\n");
- Printf(f_wrap_m," mlock\n");
- Printf(f_wrap_m," if (nargin > 1)\n");
- Printf(f_wrap_m," error('Too many input arguments')\n");
- Printf(f_wrap_m," end\n");
- Printf(f_wrap_m," if nargin==0\n");
- Printf(f_wrap_m," if (nargout > 1)\n");
- Printf(f_wrap_m," error('Too many output arguments')\n");
- Printf(f_wrap_m," end\n");
- Printf(f_wrap_m," varargout{1} = mem;\n");
- Printf(f_wrap_m," else\n");
- Printf(f_wrap_m," if (nargout > 0)\n");
- Printf(f_wrap_m," error('Too many output arguments')\n");
- Printf(f_wrap_m," end\n");
- Printf(f_wrap_m," mem = varargin{1};\n");
- Printf(f_wrap_m," end\n");
- Printf(f_wrap_m,"end\n");
+ Printf(f_wrap_m, "function varargout = SwigMem(varargin)\n");
+ Printf(f_wrap_m, " persistent mem\n");
+ Printf(f_wrap_m, " mlock\n");
+ Printf(f_wrap_m, " if (nargin > 1)\n");
+ Printf(f_wrap_m, " error('Too many input arguments')\n");
+ Printf(f_wrap_m, " end\n");
+ Printf(f_wrap_m, " if nargin==0\n");
+ Printf(f_wrap_m, " if (nargout > 1)\n");
+ Printf(f_wrap_m, " error('Too many output arguments')\n");
+ Printf(f_wrap_m, " end\n");
+ Printf(f_wrap_m, " varargout{1} = mem;\n");
+ Printf(f_wrap_m, " else\n");
+ Printf(f_wrap_m, " if (nargout > 0)\n");
+ Printf(f_wrap_m, " error('Too many output arguments')\n");
+ Printf(f_wrap_m, " end\n");
+ Printf(f_wrap_m, " mem = varargin{1};\n");
+ Printf(f_wrap_m, " end\n");
+ Printf(f_wrap_m, "end\n");
// Tidy up
Delete(f_wrap_m);
@@ -2787,19 +2793,19 @@ void MATLAB::createSwigMem() {
void MATLAB::createSwigGet() {
// Create file
- String* mfile = NewString(SWIG_output_directory());
+ String *mfile = NewString(SWIG_output_directory());
Append(mfile, "SwigGet.m");
- if (f_wrap_m) SWIG_exit(EXIT_FAILURE);
+ if (f_wrap_m)
+ SWIG_exit(EXIT_FAILURE);
f_wrap_m = NewFile(mfile, "w", SWIG_output_files());
if (!f_wrap_m) {
FileErrorDisplay(mfile);
SWIG_exit(EXIT_FAILURE);
}
-
// Output SwigMem function
- Printf(f_wrap_m,"function ptr = SwigGet(self)\n");
- Printf(f_wrap_m," ptr = [];\n");
- Printf(f_wrap_m,"end\n");
+ Printf(f_wrap_m, "function ptr = SwigGet(self)\n");
+ Printf(f_wrap_m, " ptr = [];\n");
+ Printf(f_wrap_m, "end\n");
// Tidy up
Delete(f_wrap_m);
@@ -2809,35 +2815,35 @@ void MATLAB::createSwigGet() {
void MATLAB::createSwigStorage() {
// Create file
- String* mfile = NewString(SWIG_output_directory());
+ String *mfile = NewString(SWIG_output_directory());
Append(mfile, "SwigStorage.m");
- if (f_wrap_m) SWIG_exit(EXIT_FAILURE);
+ if (f_wrap_m)
+ SWIG_exit(EXIT_FAILURE);
f_wrap_m = NewFile(mfile, "w", SWIG_output_files());
if (!f_wrap_m) {
FileErrorDisplay(mfile);
SWIG_exit(EXIT_FAILURE);
}
-
// Output SwigMem function
- Printf(f_wrap_m,"function varargout = SwigStorage(field, varargin)\n");
- Printf(f_wrap_m," persistent dir_mem\n");
- Printf(f_wrap_m," mlock\n");
- Printf(f_wrap_m," narginchk(1,2)\n");
- Printf(f_wrap_m," if isempty(dir_mem)\n");
- Printf(f_wrap_m," dir_mem = struct;\n");
- Printf(f_wrap_m," end\n");
- Printf(f_wrap_m," if nargin==1\n");
- Printf(f_wrap_m," nargoutchk(0,1)\n");
- Printf(f_wrap_m," varargout{1} = dir_mem.(field);\n");
- Printf(f_wrap_m," else\n");
- Printf(f_wrap_m," nargoutchk(0,0)\n");
- Printf(f_wrap_m," if isempty(varargin{1})\n");
- Printf(f_wrap_m," dir_mem = rmfield(dir_mem, field);\n");
- Printf(f_wrap_m," else\n");
- Printf(f_wrap_m," dir_mem.(field) = varargin{1};\n");
- Printf(f_wrap_m," end\n");
- Printf(f_wrap_m," end\n");
- Printf(f_wrap_m,"end\n");
+ Printf(f_wrap_m, "function varargout = SwigStorage(field, varargin)\n");
+ Printf(f_wrap_m, " persistent dir_mem\n");
+ Printf(f_wrap_m, " mlock\n");
+ Printf(f_wrap_m, " narginchk(1,2)\n");
+ Printf(f_wrap_m, " if isempty(dir_mem)\n");
+ Printf(f_wrap_m, " dir_mem = struct;\n");
+ Printf(f_wrap_m, " end\n");
+ Printf(f_wrap_m, " if nargin==1\n");
+ Printf(f_wrap_m, " nargoutchk(0,1)\n");
+ Printf(f_wrap_m, " varargout{1} = dir_mem.(field);\n");
+ Printf(f_wrap_m, " else\n");
+ Printf(f_wrap_m, " nargoutchk(0,0)\n");
+ Printf(f_wrap_m, " if isempty(varargin{1})\n");
+ Printf(f_wrap_m, " dir_mem = rmfield(dir_mem, field);\n");
+ Printf(f_wrap_m, " else\n");
+ Printf(f_wrap_m, " dir_mem.(field) = varargin{1};\n");
+ Printf(f_wrap_m, " end\n");
+ Printf(f_wrap_m, " end\n");
+ Printf(f_wrap_m, "end\n");
// Tidy up
Delete(f_wrap_m);
@@ -2845,7 +2851,7 @@ void MATLAB::createSwigStorage() {
f_wrap_m = 0;
}
-const char* MATLAB::get_implicitconv_flag(Node *n) {
+const char *MATLAB::get_implicitconv_flag(Node *n) {
int conv = 0;
if (n && GetFlag(n, "feature:implicitconv")) {
conv = 1;
@@ -2864,7 +2870,7 @@ void MATLAB::dispatchFunction(Node *n) {
Node *sibl = n;
while (Getattr(sibl, "sym:previousSibling"))
- sibl = Getattr(sibl, "sym:previousSibling"); // go all the way up
+ sibl = Getattr(sibl, "sym:previousSibling"); // go all the way up
String *protoTypes = NewString("");
do {
String *fulldecl = Swig_name_decl(sibl);
@@ -2875,7 +2881,7 @@ void MATLAB::dispatchFunction(Node *n) {
Printf(f->def, "int %s (int resc, mxArray *resv[], int argc, mxArray *argv[]) {", wname);
Printv(f->code, dispatch, "\n", NIL);
Printf(f->code, "SWIG_Error(SWIG_RuntimeError, \"No matching function for overload function '%s'.\"\n", iname);
- Printf(f->code, " \" Possible C/C++ prototypes are:\\n\"%s);\n",protoTypes);
+ Printf(f->code, " \" Possible C/C++ prototypes are:\\n\"%s);\n", protoTypes);
Printf(f->code, "return 1;\n");
Printv(f->code, "}\n", NIL);
@@ -2888,12 +2894,12 @@ void MATLAB::dispatchFunction(Node *n) {
// this function is used on autodoc strings
// it currently just appends " %" after every explicit newline
-String* MATLAB::matlab_escape(String *_s) {
- const char* s=(const char*)Data(_s);
- while (*s&&(*s=='\t'||*s=='\r'||*s=='\n'||*s==' '))
+String *MATLAB::matlab_escape(String *_s) {
+ const char *s = (const char *) Data(_s);
+ while (*s && (*s == '\t' || *s == '\r' || *s == '\n' || *s == ' '))
++s;
String *r = NewString("");
- for (int j=0;s[j];++j) {
+ for (int j = 0; s[j]; ++j) {
if (s[j] == '\n') {
Append(r, "\n %");
} else
@@ -2902,8 +2908,7 @@ String* MATLAB::matlab_escape(String *_s) {
return r;
}
-void MATLAB::autodoc_to_m(File* f, Node *n)
-{
+void MATLAB::autodoc_to_m(File *f, Node *n) {
if (!n)
return;
process_autodoc(n);
@@ -2912,14 +2917,14 @@ void MATLAB::autodoc_to_m(File* f, Node *n)
// String *cdecl_info = Getattr(n, "matlab:cdecl_info");
String *args_info = Getattr(n, "matlab:args_info");
- if (Len(synopsis)>0)
- Printf(f," %%%s\n", matlab_escape(synopsis));
- if (Len(decl_info)>0)
- Printf(f," %%%s\n", matlab_escape(decl_info));
+ if (Len(synopsis) > 0)
+ Printf(f, " %%%s\n", matlab_escape(synopsis));
+ if (Len(decl_info) > 0)
+ Printf(f, " %%%s\n", matlab_escape(decl_info));
// if (Len(cdecl_info)>0)
// Printf(f," %%%s\n", matlab_escape(cdecl_info));
- if (Len(args_info)>0)
- Printf(f," %%%s\n", matlab_escape(args_info));
+ if (Len(args_info) > 0)
+ Printf(f, " %%%s\n", matlab_escape(args_info));
}
int MATLAB::getRangeNumReturns(Node *n, int &max_num_returns, int &min_num_returns) {
@@ -2927,18 +2932,23 @@ int MATLAB::getRangeNumReturns(Node *n, int &max_num_returns, int &min_num_retur
Node *n_overload = n;
while (n_overload) {
String *symname = Getattr(n_overload, "sym:name");
- if (symname==0) return SWIG_ERROR;
+ if (symname == 0)
+ return SWIG_ERROR;
String *num_returns_str = Getattr(n_overload, "matlab:num_returns");
- if (num_returns_str==0) return SWIG_ERROR;
+ if (num_returns_str == 0)
+ return SWIG_ERROR;
int num_returns = 0;
sscanf(Char(num_returns_str), "%d", &num_returns);
- if (n==n_overload) {
+ if (n == n_overload) {
max_num_returns = min_num_returns = num_returns;
} else {
- if (num_returns < min_num_returns) min_num_returns = num_returns;
- if (num_returns > max_num_returns) max_num_returns = num_returns;
+ if (num_returns < min_num_returns)
+ min_num_returns = num_returns;
+ if (num_returns > max_num_returns)
+ max_num_returns = num_returns;
}
- if (!overloaded) break;
+ if (!overloaded)
+ break;
n_overload = Getattr(n_overload, "sym:previousSibling");
}
return SWIG_OK;
@@ -2949,8 +2959,7 @@ void MATLAB::checkValidSymName(Node *node) {
String *kind = Getattr(node, "kind");
if (symname && !Strncmp(symname, "_", 1)) {
Printf(stderr, "Warning: invalid MATLAB symbol '%s' (%s)\n"
- " Symbols may not start with '_'. Maybe try something like this: %%rename(u%s) %s;\n",
- symname, kind, symname, symname);
+ " Symbols may not start with '_'. Maybe try something like this: %%rename(u%s) %s;\n", symname, kind, symname, symname);
}
}