initial steps to clean up perl5 class methods (primarily constructors).
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@10743 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
b9a88dec5a
commit
2728e5a606
2 changed files with 52 additions and 17 deletions
|
|
@ -1,5 +1,5 @@
|
||||||
use imports_b;
|
use imports_b;
|
||||||
use imports_a;
|
use imports_a;
|
||||||
|
|
||||||
$x = imports_bc::new_B();
|
$x = imports_b::B->new();
|
||||||
imports_ac::A_hello($x);
|
imports_ac::A_hello($x);
|
||||||
|
|
|
||||||
|
|
@ -556,6 +556,7 @@ public:
|
||||||
String *iname = Getattr(n, "sym:name");
|
String *iname = Getattr(n, "sym:name");
|
||||||
SwigType *d = Getattr(n, "type");
|
SwigType *d = Getattr(n, "type");
|
||||||
ParmList *l = Getattr(n, "parms");
|
ParmList *l = Getattr(n, "parms");
|
||||||
|
ParmList *outer = Getattr(n, "perl5:implicits");
|
||||||
String *overname = 0;
|
String *overname = 0;
|
||||||
|
|
||||||
Parm *p;
|
Parm *p;
|
||||||
|
|
@ -565,7 +566,7 @@ public:
|
||||||
String *tm;
|
String *tm;
|
||||||
String *cleanup, *outarg;
|
String *cleanup, *outarg;
|
||||||
int num_saved = 0;
|
int num_saved = 0;
|
||||||
int num_arguments, num_required;
|
int num_arguments, num_required, num_implicits;
|
||||||
int varargs = 0;
|
int varargs = 0;
|
||||||
|
|
||||||
if (Getattr(n, "sym:overloaded")) {
|
if (Getattr(n, "sym:overloaded")) {
|
||||||
|
|
@ -587,6 +588,19 @@ public:
|
||||||
Printv(f->def, "XS(", wname, ") {\n", "{\n", /* scope to destroy C++ objects before croaking */
|
Printv(f->def, "XS(", wname, ") {\n", "{\n", /* scope to destroy C++ objects before croaking */
|
||||||
NIL);
|
NIL);
|
||||||
|
|
||||||
|
num_implicits = 0;
|
||||||
|
if(outer) {
|
||||||
|
Parm *tmp = outer;
|
||||||
|
Parm *tail;
|
||||||
|
while(tmp) {
|
||||||
|
tail = tmp;
|
||||||
|
num_implicits++;
|
||||||
|
tmp = nextSibling(tmp);
|
||||||
|
}
|
||||||
|
/* link the outer with inner parms */
|
||||||
|
set_nextSibling(tail, l);
|
||||||
|
}
|
||||||
|
|
||||||
emit_parameter_variables(l, f);
|
emit_parameter_variables(l, f);
|
||||||
emit_attach_parmmaps(l, f);
|
emit_attach_parmmaps(l, f);
|
||||||
Setattr(n, "wrap:parms", l);
|
Setattr(n, "wrap:parms", l);
|
||||||
|
|
@ -599,13 +613,28 @@ public:
|
||||||
|
|
||||||
/* Check the number of arguments */
|
/* Check the number of arguments */
|
||||||
if (!varargs) {
|
if (!varargs) {
|
||||||
Printf(f->code, " if ((items < %d) || (items > %d)) {\n", num_required, num_arguments);
|
Printf(f->code, " if ((items < %d) || (items > %d)) {\n",
|
||||||
|
num_required + num_implicits, num_arguments + num_implicits);
|
||||||
} else {
|
} else {
|
||||||
Printf(f->code, " if (items < %d) {\n", num_required);
|
Printf(f->code, " if (items < %d) {\n",
|
||||||
|
num_required + num_implicits);
|
||||||
}
|
}
|
||||||
Printf(f->code, " SWIG_croak(\"Usage: %s\");\n", usage_func(Char(iname), d, l));
|
Printf(f->code, " SWIG_croak(\"Usage: %s\");\n", usage_func(Char(iname), d, outer));
|
||||||
Printf(f->code, "}\n");
|
Printf(f->code, "}\n");
|
||||||
|
|
||||||
|
if (num_implicits) {
|
||||||
|
/* TODO: support implicits of types other than SVs */
|
||||||
|
Parm *p = outer;
|
||||||
|
for(i = 0; i < num_implicits; i++) {
|
||||||
|
String *pname = Getattr(p, "name");
|
||||||
|
String *pinit = SwigType_str(Getattr(p, "type"), pname);
|
||||||
|
Wrapper_add_local(f, pname, pinit);
|
||||||
|
Delete(pinit);
|
||||||
|
Printf(f->code, "%s = ST(%d);\n", pname, i++);
|
||||||
|
p = nextSibling(p);
|
||||||
|
}
|
||||||
|
Printf(f->code, "ax += %d;\n", num_implicits);
|
||||||
|
}
|
||||||
/* Write code to extract parameters. */
|
/* Write code to extract parameters. */
|
||||||
i = 0;
|
i = 0;
|
||||||
for (i = 0, p = l; i < num_arguments; i++) {
|
for (i = 0, p = l; i < num_arguments; i++) {
|
||||||
|
|
@ -795,6 +824,10 @@ public:
|
||||||
Printv(df->def, "XS(", dname, ") {\n", NIL);
|
Printv(df->def, "XS(", dname, ") {\n", NIL);
|
||||||
|
|
||||||
Wrapper_add_local(df, "dXSARGS", "dXSARGS");
|
Wrapper_add_local(df, "dXSARGS", "dXSARGS");
|
||||||
|
if(num_implicits) {
|
||||||
|
Printf(df->code, "ax += %d;\n", num_implicits);
|
||||||
|
Printf(df->code, "items -= %d;\n", num_implicits);
|
||||||
|
}
|
||||||
Printv(df->code, dispatch, "\n", NIL);
|
Printv(df->code, dispatch, "\n", NIL);
|
||||||
Printf(df->code, "croak(\"No matching function for overloaded '%s'\");\n", iname);
|
Printf(df->code, "croak(\"No matching function for overloaded '%s'\");\n", iname);
|
||||||
Printf(df->code, "XSRETURN(0);\n");
|
Printf(df->code, "XSRETURN(0);\n");
|
||||||
|
|
@ -1041,13 +1074,14 @@ public:
|
||||||
Clear(temp);
|
Clear(temp);
|
||||||
Printf(temp, "%s(", iname);
|
Printf(temp, "%s(", iname);
|
||||||
|
|
||||||
/* Now go through and print parameters */
|
|
||||||
p = l;
|
|
||||||
i = 0;
|
i = 0;
|
||||||
|
/* Now go through and print normal parameters */
|
||||||
|
p = l;
|
||||||
while (p != 0) {
|
while (p != 0) {
|
||||||
SwigType *pt = Getattr(p, "type");
|
SwigType *pt = Getattr(p, "type");
|
||||||
String *pn = Getattr(p, "name");
|
String *pn = Getattr(p, "name");
|
||||||
if (!checkAttribute(p,"tmap:in:numinputs","0")) {
|
if (!checkAttribute(p,"tmap:in:numinputs","0")) {
|
||||||
|
if(i > 0) Append(temp, ",");
|
||||||
/* If parameter has been named, use that. Otherwise, just print a type */
|
/* If parameter has been named, use that. Otherwise, just print a type */
|
||||||
if (SwigType_type(pt) != T_VOID) {
|
if (SwigType_type(pt) != T_VOID) {
|
||||||
if (Len(pn) > 0) {
|
if (Len(pn) > 0) {
|
||||||
|
|
@ -1057,16 +1091,8 @@ public:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
i++;
|
i++;
|
||||||
p = nextSibling(p);
|
|
||||||
if (p)
|
|
||||||
if (!checkAttribute(p,"tmap:in:numinputs","0"))
|
|
||||||
Putc(',', temp);
|
|
||||||
} else {
|
|
||||||
p = nextSibling(p);
|
|
||||||
if (p)
|
|
||||||
if ((i > 0) && (!checkAttribute(p,"tmap:in:numinputs","0")))
|
|
||||||
Putc(',', temp);
|
|
||||||
}
|
}
|
||||||
|
p = nextSibling(p);
|
||||||
}
|
}
|
||||||
Printf(temp, ");");
|
Printf(temp, ");");
|
||||||
return Char(temp);
|
return Char(temp);
|
||||||
|
|
@ -1490,6 +1516,15 @@ public:
|
||||||
|
|
||||||
String *symname = Getattr(n, "sym:name");
|
String *symname = Getattr(n, "sym:name");
|
||||||
|
|
||||||
|
{
|
||||||
|
String *type = NewString("SV");
|
||||||
|
SwigType_add_pointer(type);
|
||||||
|
Parm *p = NewParm(type, "proto");
|
||||||
|
Delete(type);
|
||||||
|
Setattr(n, "perl5:implicits", p);
|
||||||
|
Delete(p);
|
||||||
|
}
|
||||||
|
|
||||||
member_func = 1;
|
member_func = 1;
|
||||||
Language::constructorHandler(n);
|
Language::constructorHandler(n);
|
||||||
|
|
||||||
|
|
@ -1510,7 +1545,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
Printv(pcode,
|
Printv(pcode,
|
||||||
tab4, "my $pkg = shift;\n",
|
tab4, "my $pkg = $_[0];\n",
|
||||||
tab4, "my $self = ", cmodule, "::", Swig_name_construct(symname), "(@_);\n", tab4, "bless $self, $pkg if defined($self);\n", "}\n\n", NIL);
|
tab4, "my $self = ", cmodule, "::", Swig_name_construct(symname), "(@_);\n", tab4, "bless $self, $pkg if defined($self);\n", "}\n\n", NIL);
|
||||||
|
|
||||||
have_constructor = 1;
|
have_constructor = 1;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue