Revert "Octave: whitespace/indentation/style cleanup of octave.cxx"

This reverts commit 5ac475cbcd.

Reverting a series of Octave commits for re-applying again without
incorrect whitespace changes.
This commit is contained in:
William S Fulton 2014-10-09 19:34:06 +01:00
commit 376ebc2d85

View file

@ -25,8 +25,7 @@ Octave Options (available with -octave)\n\
\n"; \n";
class OCTAVE: public Language class OCTAVE:public Language {
{
private: private:
File *f_begin; File *f_begin;
File *f_runtime; File *f_runtime;
@ -51,7 +50,8 @@ private:
if (dld) { if (dld) {
String *tname = texinfo_name(n, "std::string()"); String *tname = texinfo_name(n, "std::string()");
Printf(f, "SWIG_DEFUN( %s, %s, %s ) {", cname, wname, tname); Printf(f, "SWIG_DEFUN( %s, %s, %s ) {", cname, wname, tname);
} else { }
else {
Printf(f, "static octave_value_list %s (const octave_value_list& args, int nargout) {", wname); Printf(f, "static octave_value_list %s (const octave_value_list& args, int nargout) {", wname);
} }
} }
@ -73,9 +73,10 @@ public:
have_constructor(0), have_constructor(0),
have_destructor(0), have_destructor(0),
constructor_name(0), constructor_name(0),
docs(0) { docs(0)
{
/* Add code to manage protected constructors and directors */ /* Add code to manage protected constructors and directors */
director_prot_ctor_code = NewStringEmpty(); director_prot_ctor_code = NewString("");
Printv(director_prot_ctor_code, Printv(director_prot_ctor_code,
"if ( $comparison ) { /* subclassed */\n", "if ( $comparison ) { /* subclassed */\n",
" $director_new \n", " $director_new \n",
@ -115,12 +116,10 @@ public:
} }
} }
if (!global_name) { if (!global_name)
global_name = NewString("cvar"); global_name = NewString("cvar");
} if (!op_prefix)
if (!op_prefix) {
op_prefix = NewString("op_"); op_prefix = NewString("op_");
}
SWIG_library_directory("octave"); SWIG_library_directory("octave");
Preprocessor_define("SWIGOCTAVE 1", 0); Preprocessor_define("SWIGOCTAVE 1", 0);
@ -129,10 +128,9 @@ public:
allow_overloading(); allow_overloading();
// Octave API is C++, so output must be C++ compatibile even when wrapping C code // Octave API is C++, so output must be C++ compatibile even when wrapping C code
if (!cparse_cplusplus) { if (!cparse_cplusplus)
Swig_cparse_cplusplusout(1); Swig_cparse_cplusplusout(1);
} }
}
virtual int top(Node *n) { virtual int top(Node *n) {
{ {
@ -149,13 +147,12 @@ public:
} }
if (Getattr(options, "directors")) { if (Getattr(options, "directors")) {
allow_directors(); allow_directors();
if (dirprot) { if (dirprot)
allow_dirprot(); allow_dirprot();
} }
} }
} }
} }
}
String *module = Getattr(n, "name"); String *module = Getattr(n, "name");
String *outfile = Getattr(n, "outfile"); String *outfile = Getattr(n, "outfile");
@ -164,15 +161,15 @@ public:
FileErrorDisplay(outfile); FileErrorDisplay(outfile);
SWIG_exit(EXIT_FAILURE); SWIG_exit(EXIT_FAILURE);
} }
f_runtime = NewStringEmpty(); f_runtime = NewString("");
f_header = NewStringEmpty(); f_header = NewString("");
f_doc = NewStringEmpty(); f_doc = NewString("");
f_wrappers = NewStringEmpty(); f_wrappers = NewString("");
f_init = NewStringEmpty(); f_init = NewString("");
f_initbeforefunc = NewStringEmpty(); f_initbeforefunc = NewString("");
f_directors_h = NewStringEmpty(); f_directors_h = NewString("");
f_directors = NewStringEmpty(); f_directors = NewString("");
s_global_tab = NewStringEmpty(); s_global_tab = NewString("");
Swig_register_filebyname("begin", f_begin); Swig_register_filebyname("begin", f_begin);
Swig_register_filebyname("runtime", f_runtime); Swig_register_filebyname("runtime", f_runtime);
Swig_register_filebyname("header", f_header); Swig_register_filebyname("header", f_header);
@ -208,23 +205,19 @@ public:
Printf(s_global_tab, "\nstatic const struct swig_octave_member swig_globals[] = {\n"); Printf(s_global_tab, "\nstatic const struct swig_octave_member swig_globals[] = {\n");
Printf(f_init, "static bool SWIG_init_user(octave_swig_type* module_ns)\n{\n"); Printf(f_init, "static bool SWIG_init_user(octave_swig_type* module_ns)\n{\n");
if (!CPlusPlus) { if (!CPlusPlus)
Printf(f_header,"extern \"C\" {\n"); Printf(f_header,"extern \"C\" {\n");
}
Language::top(n); Language::top(n);
if (!CPlusPlus) { if (!CPlusPlus)
Printf(f_header,"}\n"); Printf(f_header,"}\n");
}
if (Len(docs)) { if (Len(docs))
emit_doc_texinfo(); emit_doc_texinfo();
}
if (directorsEnabled()) { if (directorsEnabled())
Swig_insert_file("director.swg", f_runtime); Swig_insert_file("director.swg", f_runtime);
}
Printf(f_init, "return true;\n}\n"); Printf(f_init, "return true;\n}\n");
Printf(s_global_tab, "{0,0,0,0,0}\n};\n"); Printf(s_global_tab, "{0,0,0,0,0}\n};\n");
@ -258,10 +251,9 @@ public:
String *texinfo_escape(String *_s) { String *texinfo_escape(String *_s) {
const char* s=(const char*)Data(_s); const char* s=(const char*)Data(_s);
while (*s && (*s == '\t' || *s == '\r' || *s == '\n' || *s == ' ')) { while (*s&&(*s=='\t'||*s=='\r'||*s=='\n'||*s==' '))
++s; ++s;
} String *r = NewString("");
String* r = NewStringEmpty();
for (int j=0;s[j];++j) { for (int j=0;s[j];++j) {
if (s[j] == '\n') { if (s[j] == '\n') {
Append(r, "\\n\\\n"); Append(r, "\\n\\\n");
@ -275,10 +267,9 @@ public:
Append(r, "\\\'"); Append(r, "\\\'");
} else if (s[j] == '\"') { } else if (s[j] == '\"') {
Append(r, "\\\""); Append(r, "\\\"");
} else { } else
Putc(s[j], r); Putc(s[j], r);
} }
}
return r; return r;
} }
void emit_doc_texinfo() { void emit_doc_texinfo() {
@ -290,16 +281,15 @@ public:
String *cdecl_info = Getattr(it.item, "cdecl_info"); String *cdecl_info = Getattr(it.item, "cdecl_info");
String *args_info = Getattr(it.item, "args_info"); String *args_info = Getattr(it.item, "args_info");
String* doc_str = NewStringEmpty(); String *doc_str = NewString("");
Printv(doc_str, synopsis, decl_info, cdecl_info, args_info, NIL); Printv(doc_str, synopsis, decl_info, cdecl_info, args_info, NIL);
String *escaped_doc_str = texinfo_escape(doc_str); String *escaped_doc_str = texinfo_escape(doc_str);
if (Len(doc_str)>0) { if (Len(doc_str)>0) {
Printf(f_doc,"static const char* %s_texinfo = ",wrap_name); Printf(f_doc,"static const char* %s_texinfo = ",wrap_name);
Printf(f_doc,"\"-*- texinfo -*-\\n\\\n%s", escaped_doc_str); Printf(f_doc,"\"-*- texinfo -*-\\n\\\n%s", escaped_doc_str);
if (Len(decl_info)) { if (Len(decl_info))
Printf(f_doc,"\\n\\\n@end deftypefn"); Printf(f_doc,"\\n\\\n@end deftypefn");
}
Printf(f_doc,"\";\n"); Printf(f_doc,"\";\n");
} }
@ -310,9 +300,8 @@ public:
Printf(f_doc,"\n"); Printf(f_doc,"\n");
} }
bool is_empty_doc_node(Node* n) { bool is_empty_doc_node(Node* n) {
if (!n) { if (!n)
return true; return true;
}
String *synopsis = Getattr(n, "synopsis"); String *synopsis = Getattr(n, "synopsis");
String *decl_info = Getattr(n, "decl_info"); String *decl_info = Getattr(n, "decl_info");
String *cdecl_info = Getattr(n, "cdecl_info"); String *cdecl_info = Getattr(n, "cdecl_info");
@ -321,16 +310,15 @@ public:
!Len(cdecl_info) && !Len(args_info); !Len(cdecl_info) && !Len(args_info);
} }
String *texinfo_name(Node* n, const char* defval = "0") { String *texinfo_name(Node* n, const char* defval = "0") {
String* tname = NewStringEmpty(); String *tname = NewString("");
String *iname = Getattr(n, "sym:name"); String *iname = Getattr(n, "sym:name");
String *wname = Swig_name_wrapper(iname); String *wname = Swig_name_wrapper(iname);
Node* d = Getattr(docs, wname); Node* d = Getattr(docs, wname);
if (is_empty_doc_node(d)) { if (is_empty_doc_node(d))
Printf(tname, defval); Printf(tname, defval);
} else { else
Printf(tname, "%s_texinfo", wname); Printf(tname, "%s_texinfo", wname);
}
return tname; return tname;
} }
@ -343,10 +331,10 @@ public:
Node* d = Getattr(docs, wname); Node* d = Getattr(docs, wname);
if (!d) { if (!d) {
d = NewHash(); d = NewHash();
Setattr(d, "synopsis", NewStringEmpty()); Setattr(d, "synopsis", NewString(""));
Setattr(d, "decl_info", NewStringEmpty()); Setattr(d, "decl_info", NewString(""));
Setattr(d, "cdecl_info", NewStringEmpty()); Setattr(d, "cdecl_info", NewString(""));
Setattr(d, "args_info", NewStringEmpty()); Setattr(d, "args_info", NewString(""));
Setattr(docs, wname, d); Setattr(docs, wname, d);
} }
@ -358,8 +346,8 @@ public:
// * couldn't we just emit the docs here? // * couldn't we just emit the docs here?
if (autodoc_enabled) { if (autodoc_enabled) {
String* decl_str = NewStringEmpty(); String *decl_str = NewString("");
String* args_str = NewStringEmpty(); String *args_str = NewString("");
make_autodocParmList(n, decl_str, args_str); make_autodocParmList(n, decl_str, args_str);
Append(decl_info, "@deftypefn {Loadable Function} "); Append(decl_info, "@deftypefn {Loadable Function} ");
@ -396,9 +384,8 @@ public:
virtual int importDirective(Node *n) { virtual int importDirective(Node *n) {
String *modname = Getattr(n, "module"); String *modname = Getattr(n, "module");
if (modname) { if (modname)
Printf(f_init, "if (!SWIG_Octave_LoadModule(\"%s\")) return false;\n", modname); Printf(f_init, "if (!SWIG_Octave_LoadModule(\"%s\")) return false;\n", modname);
}
return Language::importDirective(n); return Language::importDirective(n);
} }
@ -476,20 +463,17 @@ public:
type = type ? type : Getattr(p, "type"); type = type ? type : Getattr(p, "type");
value = value ? value : Getattr(p, "value"); value = value ? value : Getattr(p, "value");
if (SwigType_isvarargs(type)) { if (SwigType_isvarargs(type))
break; break;
}
String* tex_name = NewStringEmpty(); String *tex_name = NewString("");
if (name) { if (name)
Printf(tex_name, "@var{%s}", name); Printf(tex_name, "@var{%s}", name);
} else { else
Printf(tex_name, "@var{?}"); Printf(tex_name, "@var{?}");
}
if (Len(decl_str)) { if (Len(decl_str))
Append(decl_str, ", "); Append(decl_str, ", ");
}
Append(decl_str, tex_name); Append(decl_str, tex_name);
if (value) { if (value) {
@ -498,10 +482,9 @@ public:
value = new_value; value = new_value;
} else { } else {
Node *lookup = Swig_symbol_clookup(value, 0); Node *lookup = Swig_symbol_clookup(value, 0);
if (lookup) { if (lookup)
value = Getattr(lookup, "sym:name"); value = Getattr(lookup, "sym:name");
} }
}
Printf(decl_str, " = %s", value); Printf(decl_str, " = %s", value);
} }
@ -513,9 +496,8 @@ public:
Delete(tex_name); Delete(tex_name);
Delete(name); Delete(name);
} }
if (pdocs) { if (pdocs)
Setattr(n, "feature:pdocs", pdocs); Setattr(n, "feature:pdocs", pdocs);
}
Delete(plist); Delete(plist);
} }
@ -529,22 +511,18 @@ public:
char fc = (Char(v))[0]; char fc = (Char(v))[0];
if (('0' <= fc && fc <= '9') || '\'' == fc || '"' == fc) { if (('0' <= fc && fc <= '9') || '\'' == fc || '"' == fc) {
/* number or string (or maybe NULL pointer) */ /* number or string (or maybe NULL pointer) */
if (SwigType_ispointer(t) && Strcmp(v, "0") == 0) { if (SwigType_ispointer(t) && Strcmp(v, "0") == 0)
return NewString("None"); return NewString("None");
} else { else
return v; return v;
} }
} if (Strcmp(v, "NULL") == 0 || Strcmp(v, "nullptr") == 0)
if (Strcmp(v, "NULL") == 0 || Strcmp(v, "nullptr") == 0) {
return SwigType_ispointer(t) ? NewString("nil") : NewString("0"); return SwigType_ispointer(t) ? NewString("nil") : NewString("0");
} if (Strcmp(v, "true") == 0 || Strcmp(v, "TRUE") == 0)
if (Strcmp(v, "true") == 0 || Strcmp(v, "TRUE") == 0) {
return NewString("true"); return NewString("true");
} if (Strcmp(v, "false") == 0 || Strcmp(v, "FALSE") == 0)
if (Strcmp(v, "false") == 0 || Strcmp(v, "FALSE") == 0) {
return NewString("false"); return NewString("false");
} }
}
return 0; return 0;
} }
@ -566,23 +544,20 @@ public:
SwigType *d = Getattr(n, "type"); SwigType *d = Getattr(n, "type");
ParmList *l = Getattr(n, "parms"); ParmList *l = Getattr(n, "parms");
if (!overloaded && !addSymbol(iname, n)) { if (!overloaded && !addSymbol(iname, n))
return SWIG_ERROR; return SWIG_ERROR;
}
if (overloaded) { if (overloaded)
Append(overname, Getattr(n, "sym:overname")); Append(overname, Getattr(n, "sym:overname"));
}
if (!overloaded || last_overload) { if (!overloaded || last_overload)
process_autodoc(n); process_autodoc(n);
}
Wrapper* w = NewWrapper(); Wrapper *f = NewWrapper();
Octave_begin_function(n, w->def, iname, overname, !overloaded); Octave_begin_function(n, f->def, iname, overname, !overloaded);
emit_parameter_variables(l, w); emit_parameter_variables(l, f);
emit_attach_parmmaps(l, w); emit_attach_parmmaps(l, f);
Setattr(n, "wrap:parms", l); Setattr(n, "wrap:parms", l);
int num_arguments = emit_num_arguments(l); int num_arguments = emit_num_arguments(l);
@ -590,7 +565,7 @@ public:
int varargs = emit_isvarargs(l); int varargs = emit_isvarargs(l);
char source[64]; char source[64];
Printf(w->code, "if (!SWIG_check_num_args(\"%s\",args.length(),%i,%i,%i)) " Printf(f->code, "if (!SWIG_check_num_args(\"%s\",args.length(),%i,%i,%i)) "
"{\n SWIG_fail;\n }\n", iname, num_arguments, num_required, varargs); "{\n SWIG_fail;\n }\n", iname, num_arguments, num_required, varargs);
if (constructor && num_arguments == 1 && num_required == 1) { if (constructor && num_arguments == 1 && num_required == 1) {
@ -598,7 +573,7 @@ public:
Node *parent = Swig_methodclass(n); Node *parent = Swig_methodclass(n);
if (GetFlag(parent, "feature:implicitconv")) { if (GetFlag(parent, "feature:implicitconv")) {
String *desc = NewStringf("SWIGTYPE%s", SwigType_manglestr(Getattr(n, "type"))); String *desc = NewStringf("SWIGTYPE%s", SwigType_manglestr(Getattr(n, "type")));
Printf(w->code, "if (SWIG_CheckImplicit(%s)) SWIG_fail;\n", desc); Printf(f->code, "if (SWIG_CheckImplicit(%s)) SWIG_fail;\n", desc);
Delete(desc); Delete(desc);
} }
} }
@ -641,13 +616,12 @@ public:
Setattr(p, "implicitconv", convflag); Setattr(p, "implicitconv", convflag);
} }
String* getargs = NewStringEmpty(); String *getargs = NewString("");
if (j >= num_required) { if (j >= num_required)
Printf(getargs, "if (%d<args.length()) {\n%s\n}", j, tm); Printf(getargs, "if (%d<args.length()) {\n%s\n}", j, tm);
} else { else
Printv(getargs, tm, NIL); Printv(getargs, tm, NIL);
} Printv(f->code, getargs, "\n", NIL);
Printv(w->code, getargs, "\n", NIL);
Delete(getargs); Delete(getargs);
p = Getattr(p, "tmap:in:next"); p = Getattr(p, "tmap:in:next");
@ -662,7 +636,7 @@ public:
if (varargs) { if (varargs) {
if (p && (tm = Getattr(p, "tmap:in"))) { if (p && (tm = Getattr(p, "tmap:in"))) {
Replaceall(tm, "$input", "varargs"); Replaceall(tm, "$input", "varargs");
Printv(w->code, tm, "\n", NIL); Printv(f->code, tm, "\n", NIL);
} }
} }
@ -670,7 +644,7 @@ public:
for (p = l; p;) { for (p = l; p;) {
if ((tm = Getattr(p, "tmap:check"))) { if ((tm = Getattr(p, "tmap:check"))) {
Replaceall(tm, "$target", Getattr(p, "lname")); Replaceall(tm, "$target", Getattr(p, "lname"));
Printv(w->code, tm, "\n", NIL); Printv(f->code, tm, "\n", NIL);
p = Getattr(p, "tmap:check:next"); p = Getattr(p, "tmap:check:next");
} else { } else {
p = nextSibling(p); p = nextSibling(p);
@ -678,7 +652,7 @@ public:
} }
// Insert cleanup code // Insert cleanup code
String* cleanup = NewStringEmpty(); String *cleanup = NewString("");
for (p = l; p;) { for (p = l; p;) {
if ((tm = Getattr(p, "tmap:freearg"))) { if ((tm = Getattr(p, "tmap:freearg"))) {
if (Getattr(p, "tmap:freearg:implicitconv")) { if (Getattr(p, "tmap:freearg:implicitconv")) {
@ -702,7 +676,7 @@ public:
} }
// Insert argument output code // Insert argument output code
String* outarg = NewStringEmpty(); String *outarg = NewString("");
for (p = l; p;) { for (p = l; p;) {
if ((tm = Getattr(p, "tmap:argout"))) { if ((tm = Getattr(p, "tmap:argout"))) {
Replaceall(tm, "$source", Getattr(p, "lname")); Replaceall(tm, "$source", Getattr(p, "lname"));
@ -719,72 +693,70 @@ public:
int director_method = is_member_director(n) && !is_smart_pointer() && !destructor; int director_method = is_member_director(n) && !is_smart_pointer() && !destructor;
if (director_method) { if (director_method) {
Wrapper_add_local(w, "upcall", "bool upcall = false"); Wrapper_add_local(f, "upcall", "bool upcall = false");
Append(w->code, "upcall = !!dynamic_cast<Swig::Director*>(arg1);\n"); Append(f->code, "upcall = !!dynamic_cast<Swig::Director*>(arg1);\n");
} }
Setattr(n, "wrap:name", overname); Setattr(n, "wrap:name", overname);
Swig_director_emit_dynamic_cast(n, w); Swig_director_emit_dynamic_cast(n, f);
String *actioncode = emit_action(n); String *actioncode = emit_action(n);
Wrapper_add_local(w, "_out", "octave_value_list _out"); Wrapper_add_local(f, "_out", "octave_value_list _out");
Wrapper_add_local(w, "_outp", "octave_value_list *_outp=&_out"); Wrapper_add_local(f, "_outp", "octave_value_list *_outp=&_out");
Wrapper_add_local(w, "_outv", "octave_value _outv"); Wrapper_add_local(f, "_outv", "octave_value _outv");
// Return the function value // Return the function value
if ((tm = Swig_typemap_lookup_out("out", n, Swig_cresult_name(), w, actioncode))) { if ((tm = Swig_typemap_lookup_out("out", n, Swig_cresult_name(), f, actioncode))) {
Replaceall(tm, "$source", Swig_cresult_name()); Replaceall(tm, "$source", Swig_cresult_name());
Replaceall(tm, "$target", "_outv"); Replaceall(tm, "$target", "_outv");
Replaceall(tm, "$result", "_outv"); Replaceall(tm, "$result", "_outv");
if (GetFlag(n, "feature:new")) { if (GetFlag(n, "feature:new"))
Replaceall(tm, "$owner", "1"); Replaceall(tm, "$owner", "1");
} else { else
Replaceall(tm, "$owner", "0"); Replaceall(tm, "$owner", "0");
}
Printf(w->code, "%s\n", tm); Printf(f->code, "%s\n", tm);
Printf(w->code, "if (_outv.is_defined()) _outp = " "SWIG_Octave_AppendOutput(_outp, _outv);\n"); Printf(f->code, "if (_outv.is_defined()) _outp = " "SWIG_Octave_AppendOutput(_outp, _outv);\n");
Delete(tm); Delete(tm);
} else { } 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); 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);
} }
emit_return_variable(n, d, w); emit_return_variable(n, d, f);
Printv(w->code, outarg, NIL); Printv(f->code, outarg, NIL);
Printv(w->code, cleanup, NIL); Printv(f->code, cleanup, NIL);
if (GetFlag(n, "feature:new")) { if (GetFlag(n, "feature:new")) {
if ((tm = Swig_typemap_lookup("newfree", n, Swig_cresult_name(), 0))) { if ((tm = Swig_typemap_lookup("newfree", n, Swig_cresult_name(), 0))) {
Replaceall(tm, "$source", Swig_cresult_name()); Replaceall(tm, "$source", Swig_cresult_name());
Printf(w->code, "%s\n", tm); Printf(f->code, "%s\n", tm);
} }
} }
if ((tm = Swig_typemap_lookup("ret", n, Swig_cresult_name(), 0))) { if ((tm = Swig_typemap_lookup("ret", n, Swig_cresult_name(), 0))) {
Replaceall(tm, "$source", Swig_cresult_name()); Replaceall(tm, "$source", Swig_cresult_name());
Replaceall(tm, "$result", "_outv"); Replaceall(tm, "$result", "_outv");
Printf(w->code, "%s\n", tm); Printf(f->code, "%s\n", tm);
Delete(tm); Delete(tm);
} }
Printf(w->code, "return _out;\n"); Printf(f->code, "return _out;\n");
Printf(w->code, "fail:\n"); // we should free locals etc if this happens Printf(f->code, "fail:\n"); // we should free locals etc if this happens
Printv(w->code, cleanup, NIL); Printv(f->code, cleanup, NIL);
Printf(w->code, "return octave_value_list();\n"); Printf(f->code, "return octave_value_list();\n");
Printf(w->code, "}\n"); Printf(f->code, "}\n");
/* Substitute the cleanup code */ /* Substitute the cleanup code */
Replaceall(w->code, "$cleanup", cleanup); Replaceall(f->code, "$cleanup", cleanup);
Replaceall(w->code, "$symname", iname); Replaceall(f->code, "$symname", iname);
Wrapper_print(w, f_wrappers); Wrapper_print(f, f_wrappers);
DelWrapper(w); DelWrapper(f);
if (last_overload) { if (last_overload)
dispatchFunction(n); dispatchFunction(n);
}
if (!overloaded || last_overload) { if (!overloaded || last_overload) {
String *tname = texinfo_name(n); String *tname = texinfo_name(n);
@ -801,30 +773,29 @@ public:
} }
void dispatchFunction(Node *n) { void dispatchFunction(Node *n) {
Wrapper* w = NewWrapper(); Wrapper *f = NewWrapper();
String *iname = Getattr(n, "sym:name"); String *iname = Getattr(n, "sym:name");
String *wname = Swig_name_wrapper(iname); String *wname = Swig_name_wrapper(iname);
int maxargs; int maxargs;
String *dispatch = Swig_overload_dispatch(n, "return %s(args, nargout);", &maxargs); String *dispatch = Swig_overload_dispatch(n, "return %s(args, nargout);", &maxargs);
String* tmp = NewStringEmpty(); String *tmp = NewString("");
Octave_begin_function(n, w->def, iname, wname, true); Octave_begin_function(n, f->def, iname, wname, true);
Wrapper_add_local(w, "argc", "int argc = args.length()"); Wrapper_add_local(f, "argc", "int argc = args.length()");
Printf(tmp, "octave_value_ref argv[%d]={", maxargs); Printf(tmp, "octave_value_ref argv[%d]={", maxargs);
for (int j = 0; j < maxargs; ++j) { for (int j = 0; j < maxargs; ++j)
Printf(tmp, "%soctave_value_ref(args,%d)", j ? "," : " ", j); Printf(tmp, "%soctave_value_ref(args,%d)", j ? "," : " ", j);
}
Printf(tmp, "}"); Printf(tmp, "}");
Wrapper_add_local(w, "argv", tmp); Wrapper_add_local(f, "argv", tmp);
Printv(w->code, dispatch, "\n", NIL); Printv(f->code, dispatch, "\n", NIL);
Printf(w->code, "error(\"No matching function for overload\");\n", iname); Printf(f->code, "error(\"No matching function for overload\");\n", iname);
Printf(w->code, "return octave_value_list();\n"); Printf(f->code, "return octave_value_list();\n");
Printv(w->code, "}\n", NIL); Printv(f->code, "}\n", NIL);
Wrapper_print(w, f_wrappers); Wrapper_print(f, f_wrappers);
Delete(tmp); Delete(tmp);
DelWrapper(w); DelWrapper(f);
Delete(dispatch); Delete(dispatch);
Delete(wname); Delete(wname);
} }
@ -834,13 +805,12 @@ public:
String *iname = Getattr(n, "sym:name"); String *iname = Getattr(n, "sym:name");
SwigType *t = Getattr(n, "type"); SwigType *t = Getattr(n, "type");
if (!addSymbol(iname, n)) { if (!addSymbol(iname, n))
return SWIG_ERROR; return SWIG_ERROR;
}
String *tm; String *tm;
Wrapper* getw = NewWrapper(); Wrapper *getf = NewWrapper();
Wrapper* setw = NewWrapper(); Wrapper *setf = NewWrapper();
String *getname = Swig_name_get(NSPACE_TODO, iname); String *getname = Swig_name_get(NSPACE_TODO, iname);
String *setname = Swig_name_set(NSPACE_TODO, iname); String *setname = Swig_name_set(NSPACE_TODO, iname);
@ -848,8 +818,8 @@ public:
String *getwname = Swig_name_wrapper(getname); String *getwname = Swig_name_wrapper(getname);
String *setwname = Swig_name_wrapper(setname); String *setwname = Swig_name_wrapper(setname);
Octave_begin_function(n, setw->def, setname, setwname, true); Octave_begin_function(n, setf->def, setname, setwname, true);
Printf(setw->def, "if (!SWIG_check_num_args(\"%s_set\",args.length(),1,1,0)) return octave_value_list();", iname); Printf(setf->def, "if (!SWIG_check_num_args(\"%s_set\",args.length(),1,1,0)) return octave_value_list();", iname);
if (is_assignable(n)) { if (is_assignable(n)) {
Setattr(n, "wrap:name", setname); Setattr(n, "wrap:name", setname);
if ((tm = Swig_typemap_lookup("varin", n, name, 0))) { if ((tm = Swig_typemap_lookup("varin", n, name, 0))) {
@ -859,46 +829,46 @@ public:
if (Getattr(n, "tmap:varin:implicitconv")) { if (Getattr(n, "tmap:varin:implicitconv")) {
Replaceall(tm, "$implicitconv", get_implicitconv_flag(n)); Replaceall(tm, "$implicitconv", get_implicitconv_flag(n));
} }
emit_action_code(n, setw->code, tm); emit_action_code(n, setf->code, tm);
Delete(tm); Delete(tm);
} else { } else {
Swig_warning(WARN_TYPEMAP_VARIN_UNDEF, input_file, line_number, "Unable to set variable of type %s.\n", SwigType_str(t, 0)); Swig_warning(WARN_TYPEMAP_VARIN_UNDEF, input_file, line_number, "Unable to set variable of type %s.\n", SwigType_str(t, 0));
} }
Append(setw->code, "fail:\n"); Append(setf->code, "fail:\n");
Printf(setw->code, "return octave_value_list();\n"); Printf(setf->code, "return octave_value_list();\n");
} else { } else {
Printf(setw->code, "return octave_set_immutable(args,nargout);"); Printf(setf->code, "return octave_set_immutable(args,nargout);");
} }
Append(setw->code, "}\n"); Append(setf->code, "}\n");
Wrapper_print(setw, f_wrappers); Wrapper_print(setf, f_wrappers);
Setattr(n, "wrap:name", getname); Setattr(n, "wrap:name", getname);
int addfail = 0; int addfail = 0;
Octave_begin_function(n, getw->def, getname, getwname, true); Octave_begin_function(n, getf->def, getname, getwname, true);
Wrapper_add_local(getw, "obj", "octave_value obj"); Wrapper_add_local(getf, "obj", "octave_value obj");
if ((tm = Swig_typemap_lookup("varout", n, name, 0))) { if ((tm = Swig_typemap_lookup("varout", n, name, 0))) {
Replaceall(tm, "$source", name); Replaceall(tm, "$source", name);
Replaceall(tm, "$target", "obj"); Replaceall(tm, "$target", "obj");
Replaceall(tm, "$result", "obj"); Replaceall(tm, "$result", "obj");
addfail = emit_action_code(n, getw->code, tm); addfail = emit_action_code(n, getf->code, tm);
Delete(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)); Swig_warning(WARN_TYPEMAP_VAROUT_UNDEF, input_file, line_number, "Unable to read variable of type %s\n", SwigType_str(t, 0));
} }
Append(getw->code, " return obj;\n"); Append(getf->code, " return obj;\n");
if (addfail) { if (addfail) {
Append(getw->code, "fail:\n"); Append(getf->code, "fail:\n");
Append(getw->code, " return octave_value_list();\n"); Append(getf->code, " return octave_value_list();\n");
} }
Append(getw->code, "}\n"); Append(getf->code, "}\n");
Wrapper_print(getw, f_wrappers); Wrapper_print(getf, f_wrappers);
Printf(s_global_tab, "{\"%s\",0,%s,%s,2,0},\n", iname, getwname, setwname); Printf(s_global_tab, "{\"%s\",0,%s,%s,2,0},\n", iname, getwname, setwname);
Delete(getwname); Delete(getwname);
Delete(setwname); Delete(setwname);
DelWrapper(setw); DelWrapper(setf);
DelWrapper(getw); DelWrapper(getf);
return SWIG_OK; return SWIG_OK;
} }
@ -912,9 +882,8 @@ public:
String *cppvalue = Getattr(n, "cppvalue"); String *cppvalue = Getattr(n, "cppvalue");
String *tm; String *tm;
if (!addSymbol(iname, n)) { if (!addSymbol(iname, n))
return SWIG_ERROR; return SWIG_ERROR;
}
if (SwigType_type(type) == T_MPOINTER) { if (SwigType_type(type) == T_MPOINTER) {
String *wname = Swig_name_wrapper(iname); String *wname = Swig_name_wrapper(iname);
@ -960,9 +929,8 @@ public:
class_name = Getattr(n, "sym:name"); class_name = Getattr(n, "sym:name");
if (!addSymbol(class_name, n)) { if (!addSymbol(class_name, n))
return SWIG_ERROR; return SWIG_ERROR;
}
// This is a bug, due to the fact that swig_type -> octave_class mapping // This is a bug, due to the fact that swig_type -> octave_class mapping
// is 1-to-n. // is 1-to-n.
@ -976,7 +944,7 @@ public:
Delete(mangled_classname); Delete(mangled_classname);
assert(!s_members_tab); assert(!s_members_tab);
s_members_tab = NewStringEmpty(); s_members_tab = NewString("");
Printv(s_members_tab, "static swig_octave_member swig_", class_name, "_members[] = {\n", NIL); Printv(s_members_tab, "static swig_octave_member swig_", class_name, "_members[] = {\n", NIL);
Language::classHandler(n); Language::classHandler(n);
@ -1012,8 +980,8 @@ public:
Printf(s_members_tab, "{0,0,0,0}\n};\n"); Printf(s_members_tab, "{0,0,0,0}\n};\n");
Printv(f_wrappers, s_members_tab, NIL); Printv(f_wrappers, s_members_tab, NIL);
String* base_class_names = NewStringEmpty(); String *base_class_names = NewString("");
String* base_class = NewStringEmpty(); String *base_class = NewString("");
List *baselist = Getattr(n, "bases"); List *baselist = Getattr(n, "bases");
if (baselist && Len(baselist)) { if (baselist && Len(baselist)) {
Iterator b; Iterator b;
@ -1048,9 +1016,8 @@ public:
Delete(tname); Delete(tname);
Delete(wcname); Delete(wcname);
Delete(cname); Delete(cname);
} else { } else
Printv(f_wrappers, "0,0,", NIL); Printv(f_wrappers, "0,0,", NIL);
}
if (have_destructor) { if (have_destructor) {
String *nspace = Getattr(n, "sym:nspace"); String *nspace = Getattr(n, "sym:nspace");
String *cname = Swig_name_destroy(nspace, class_name); String *cname = Swig_name_destroy(nspace, class_name);
@ -1058,9 +1025,8 @@ public:
Printf(f_wrappers, "%s,", wcname); Printf(f_wrappers, "%s,", wcname);
Delete(wcname); Delete(wcname);
Delete(cname); Delete(cname);
} else { } else
Printv(f_wrappers, "0", ",", NIL); Printv(f_wrappers, "0", ",", NIL);
}
Printf(f_wrappers, "swig_%s_members,swig_%s_base_names,swig_%s_base };\n\n", class_name, class_name, class_name); Printf(f_wrappers, "swig_%s_members,swig_%s_base_names,swig_%s_base };\n\n", class_name, class_name, class_name);
Delete(base_class); Delete(base_class);
@ -1088,9 +1054,8 @@ public:
String *tname = texinfo_name(n); String *tname = texinfo_name(n);
String *rname = Copy(wname); String *rname = Copy(wname);
bool overloaded = !!Getattr(n, "sym:overloaded"); bool overloaded = !!Getattr(n, "sym:overloaded");
if (overloaded) { if (overloaded)
Delslice(rname, Len(rname) - Len(Getattr(n, "sym:overname")), DOH_END); Delslice(rname, Len(rname) - Len(Getattr(n, "sym:overname")), DOH_END);
}
Printf(s_members_tab, "{\"%s\",%s,0,0,0,%s},\n", Printf(s_members_tab, "{\"%s\",%s,0,0,0,%s},\n",
realname, rname, tname); realname, rname, tname);
Delete(rname); Delete(rname);
@ -1125,9 +1090,8 @@ public:
virtual int constructorHandler(Node *n) { virtual int constructorHandler(Node *n) {
have_constructor = 1; have_constructor = 1;
if (!constructor_name) { if (!constructor_name)
constructor_name = NewString(Getattr(n, "sym:name")); constructor_name = NewString(Getattr(n, "sym:name"));
}
int use_director = Swig_directorclass(n); int use_director = Swig_directorclass(n);
if (use_director) { if (use_director) {
@ -1140,9 +1104,8 @@ public:
Delete(type); Delete(type);
Delete(name); Delete(name);
Setattr(self, "lname", "self_obj"); Setattr(self, "lname", "self_obj");
if (parms) { if (parms)
set_nextSibling(self, parms); set_nextSibling(self, parms);
}
Setattr(n, "parms", self); Setattr(n, "parms", self);
Setattr(n, "wrap:self", "1"); Setattr(n, "wrap:self", "1");
Setattr(n, "hidden", "1"); Setattr(n, "hidden", "1");
@ -1172,9 +1135,8 @@ public:
String *tname = texinfo_name(n); String *tname = texinfo_name(n);
String *rname = Copy(wname); String *rname = Copy(wname);
bool overloaded = !!Getattr(n, "sym:overloaded"); bool overloaded = !!Getattr(n, "sym:overloaded");
if (overloaded) { if (overloaded)
Delslice(rname, Len(rname) - Len(Getattr(n, "sym:overname")), DOH_END); Delslice(rname, Len(rname) - Len(Getattr(n, "sym:overname")), DOH_END);
}
Printf(s_members_tab, "{\"%s\",%s,0,0,1,%s},\n", Printf(s_members_tab, "{\"%s\",%s,0,0,1,%s},\n",
realname, rname, tname); realname, rname, tname);
Delete(rname); Delete(rname);
@ -1229,10 +1191,10 @@ public:
int classDirectorConstructor(Node *n) { int classDirectorConstructor(Node *n) {
Node *parent = Getattr(n, "parentNode"); Node *parent = Getattr(n, "parentNode");
String* sub = NewStringEmpty(); String *sub = NewString("");
String *decl = Getattr(n, "decl"); String *decl = Getattr(n, "decl");
String *supername = Swig_class_name(parent); String *supername = Swig_class_name(parent);
String* classname = NewStringEmpty(); String *classname = NewString("");
Printf(classname, "SwigDirector_%s", supername); Printf(classname, "SwigDirector_%s", supername);
// insert self parameter // insert self parameter
@ -1300,11 +1262,11 @@ public:
String *classname = Getattr(parent, "sym:name"); String *classname = Getattr(parent, "sym:name");
String *c_classname = Getattr(parent, "name"); String *c_classname = Getattr(parent, "name");
String *symname = Getattr(n, "sym:name"); String *symname = Getattr(n, "sym:name");
String* declaration = NewStringEmpty(); String *declaration = NewString("");
ParmList *l = Getattr(n, "parms"); ParmList *l = Getattr(n, "parms");
Wrapper *w = NewWrapper(); Wrapper *w = NewWrapper();
String *tm; String *tm;
String* wrap_args = NewStringEmpty(); String *wrap_args = NewString("");
String *value = Getattr(n, "value"); String *value = Getattr(n, "value");
String *storage = Getattr(n, "storage"); String *storage = Getattr(n, "storage");
bool pure_virtual = false; bool pure_virtual = false;
@ -1347,9 +1309,8 @@ public:
Append(w->def, " throw("); Append(w->def, " throw(");
Append(declaration, " throw("); Append(declaration, " throw(");
if (throw_parm_list) { if (throw_parm_list)
Swig_typemap_attach_parms("throws", throw_parm_list, 0); Swig_typemap_attach_parms("throws", throw_parm_list, 0);
}
for (p = throw_parm_list; p; p = nextSibling(p)) { for (p = throw_parm_list; p; p = nextSibling(p)) {
if (Getattr(p, "tmap:throws")) { if (Getattr(p, "tmap:throws")) {
if (gencomma++) { if (gencomma++) {
@ -1383,9 +1344,8 @@ public:
if (ignored_method) { if (ignored_method) {
if (!pure_virtual) { if (!pure_virtual) {
if (!is_void) { if (!is_void)
Printf(w->code, "return "); Printf(w->code, "return ");
}
String *super_call = Swig_method_call(super, l); String *super_call = Swig_method_call(super, l);
Printf(w->code, "%s;\n", super_call); Printf(w->code, "%s;\n", super_call);
Delete(super_call); Delete(super_call);
@ -1395,7 +1355,7 @@ public:
} }
} else { } else {
// attach typemaps to arguments (C/C++ -> Python) // attach typemaps to arguments (C/C++ -> Python)
String* parse_args = NewStringEmpty(); String *parse_args = NewString("");
Swig_director_parms_fixup(l); Swig_director_parms_fixup(l);
@ -1406,9 +1366,8 @@ public:
Parm *p; Parm *p;
int outputs = 0; int outputs = 0;
if (!is_void) { if (!is_void)
outputs++; outputs++;
}
// build argument list and type conversion string // build argument list and type conversion string
p = l; p = l;
@ -1418,9 +1377,8 @@ public:
continue; continue;
} }
if (Getattr(p, "tmap:directorargout") != 0) { if (Getattr(p, "tmap:directorargout") != 0)
outputs++; outputs++;
}
String *pname = Getattr(p, "name"); String *pname = Getattr(p, "name");
String *ptype = Getattr(p, "type"); String *ptype = Getattr(p, "type");
@ -1440,10 +1398,9 @@ public:
Setattr(p, "emit:directorinput", pname); Setattr(p, "emit:directorinput", pname);
Replaceall(tm, "$input", pname); Replaceall(tm, "$input", pname);
Replaceall(tm, "$owner", "0"); Replaceall(tm, "$owner", "0");
if (Len(tm) == 0) { if (Len(tm) == 0)
Append(tm, pname); Append(tm, pname);
} }
}
p = Getattr(p, "tmap:directorin:next"); p = Getattr(p, "tmap:directorin:next");
continue; continue;
} else if (Cmp(ptype, "void")) { } else if (Cmp(ptype, "void")) {
@ -1468,8 +1425,8 @@ public:
Printf(w->code, "idx.push_back(args);\n"); Printf(w->code, "idx.push_back(args);\n");
Printf(w->code, "out=swig_get_self()->subsref(\".(\",idx,%d);\n", outputs); Printf(w->code, "out=swig_get_self()->subsref(\".(\",idx,%d);\n", outputs);
String* cleanup = NewStringEmpty(); String *cleanup = NewString("");
String* outarg = NewStringEmpty(); String *outarg = NewString("");
idx = 0; idx = 0;
// marshal return value // marshal return value
@ -1535,15 +1492,14 @@ public:
Append(w->code, "}\n"); Append(w->code, "}\n");
// We expose protected methods via an extra public inline method which makes a straight call to the wrapped class' method // We expose protected methods via an extra public inline method which makes a straight call to the wrapped class' method
String* inline_extra_method = NewStringEmpty(); String *inline_extra_method = NewString("");
if (dirprot_mode() && !is_public(n) && !pure_virtual) { if (dirprot_mode() && !is_public(n) && !pure_virtual) {
Printv(inline_extra_method, declaration, NIL); Printv(inline_extra_method, declaration, NIL);
String *extra_method_name = NewStringf("%sSwigPublic", name); String *extra_method_name = NewStringf("%sSwigPublic", name);
Replaceall(inline_extra_method, name, extra_method_name); Replaceall(inline_extra_method, name, extra_method_name);
Replaceall(inline_extra_method, ";\n", " {\n "); Replaceall(inline_extra_method, ";\n", " {\n ");
if (!is_void) { if (!is_void)
Printf(inline_extra_method, "return "); Printf(inline_extra_method, "return ");
}
String *methodcall = Swig_method_call(super, l); String *methodcall = Swig_method_call(super, l);
Printv(inline_extra_method, methodcall, ";\n }\n", NIL); Printv(inline_extra_method, methodcall, ";\n }\n", NIL);
Delete(methodcall); Delete(methodcall);
@ -1566,7 +1522,7 @@ public:
} }
String *runtimeCode() { String *runtimeCode() {
String* s = NewStringEmpty(); String *s = NewString("");
String *srun = Swig_include_sys("octrun.swg"); String *srun = Swig_include_sys("octrun.swg");
if (!srun) { if (!srun) {
Printf(stderr, "*** Unable to open 'octrun.swg'\n"); Printf(stderr, "*** Unable to open 'octrun.swg'\n");
@ -1582,7 +1538,6 @@ public:
} }
}; };
extern "C" Language* swig_octave(void) extern "C" Language *swig_octave(void) {
{
return new OCTAVE(); return new OCTAVE();
} }