Merged changes from trunk up to revision 12416.

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/szager-python-builtin@12417 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Stefan Zager 2011-01-30 05:24:00 +00:00
commit 9c796f0333
127 changed files with 2571 additions and 1771 deletions

View file

@ -2343,6 +2343,7 @@ public:
SwigType *pt = Getattr(p, "type");
if ((tm = Getattr(p, "tmap:csvarin"))) {
substituteClassname(pt, tm);
Replaceall(tm, "$csinput", "value");
Replaceall(tm, "$imcall", imcall);
excodeSubstitute(n, tm, "csvarin", p);
Printf(proxy_class_code, "%s", tm);
@ -3472,7 +3473,6 @@ public:
String *callback_def = NewString("");
String *callback_code = NewString("");
String *imcall_args = NewString("");
int gencomma = 0;
bool ignored_method = GetFlag(n, "feature:ignore") ? true : false;
// Kludge Alert: functionWrapper sets sym:overload properly, but it
@ -3616,14 +3616,14 @@ public:
Printf(w->code, "} else {\n");
/* Go through argument list, convert from native to Java */
for (p = l; p; /* empty */ ) {
for (i = 0, p = l; p; ++i) {
/* Is this superfluous? */
while (checkAttribute(p, "tmap:directorin:numinputs", "0")) {
p = Getattr(p, "tmap:directorin:next");
}
SwigType *pt = Getattr(p, "type");
String *ln = Copy(Getattr(p, "name"));
String *ln = makeParameterName(n, p, i, false);
String *c_param_type = NULL;
String *c_decl = NewString("");
String *arg = NewString("");
@ -3631,7 +3631,7 @@ public:
Printf(arg, "j%s", ln);
/* And add to the upcall args */
if (gencomma > 0)
if (i > 0)
Printf(jupcall_args, ", ");
Printf(jupcall_args, "%s", arg);
@ -3659,7 +3659,7 @@ public:
Delete(tm);
/* Add C type to callback typedef */
if (gencomma > 0)
if (i > 0)
Printf(callback_typedef_parms, ", ");
Printf(callback_typedef_parms, "%s", c_param_type);
@ -3680,7 +3680,7 @@ public:
substituteClassname(pt, din);
Replaceall(din, "$iminput", ln);
if (gencomma > 0) {
if (i > 0) {
Printf(delegate_parms, ", ");
Printf(proxy_method_types, ", ");
Printf(imcall_args, ", ");
@ -3726,7 +3726,7 @@ public:
p = nextSibling(p);
}
gencomma++;
Delete(ln);
Delete(arg);
Delete(c_decl);
Delete(c_param_type);

View file

@ -1867,7 +1867,6 @@ public:
String *callback_def = NewString("");
String *callback_code = NewString("");
String *imcall_args = NewString("");
int gencomma = 0;
bool ignored_method = GetFlag(n, "feature:ignore") ? true : false;
// Kludge Alert: functionWrapper sets sym:overload properly, but it
@ -2007,14 +2006,14 @@ public:
Printf(w->code, "} else {\n");
// Go through argument list.
for (p = l; p; /* empty */) {
for (i = 0, p = l; p; ++i) {
/* Is this superfluous? */
while (checkAttribute(p, "tmap:directorin:numinputs", "0")) {
p = Getattr(p, "tmap:directorin:next");
}
SwigType *pt = Getattr(p, "type");
String *ln = Copy(Getattr(p, "name"));
String *ln = makeParameterName(n, p, i, false);
String *c_param_type = NULL;
String *c_decl = NewString("");
String *arg = NewString("");
@ -2071,7 +2070,7 @@ public:
Replaceall(din, "$winput", ln);
Printf(delegate_parms, ", ");
if (gencomma > 0) {
if (i > 0) {
Printf(proxy_method_param_list, ", ");
Printf(imcall_args, ", ");
}
@ -2123,10 +2122,10 @@ public:
p = nextSibling(p);
}
gencomma++;
Delete(arg);
Delete(c_decl);
Delete(c_param_type);
Delete(ln);
}
/* header declaration, start wrapper definition */
@ -2631,6 +2630,8 @@ private:
if (!static_flag) {
Printf(imcall, "cast(void*)swigCPtr");
}
String *proxy_param_types = NewString("");
// Write the parameter list for the proxy function declaration and the
// wrapper function call.
@ -2705,10 +2706,13 @@ private:
"No dtype typemap defined for %s\n", SwigType_str(pt, 0));
}
if (gencomma >= 2)
if (gencomma >= 2) {
Printf(function_code, ", ");
Printf(proxy_param_types, ", ");
}
gencomma = 2;
Printf(function_code, "%s %s", proxy_type, param_name);
Append(proxy_param_types, proxy_type);
Delete(proxy_type);
}
@ -2773,9 +2777,11 @@ private:
String *excode = NewString("");
if (!Cmp(return_type, "void"))
Printf(excode, "if (this.classinfo == %s.classinfo) %s; else %s", proxy_class_name, imcall, ex_imcall);
Printf(excode, "if (swigIsMethodOverridden!(%s delegate(%s), %s function(%s), %s)()) %s; else %s",
return_type, proxy_param_types, return_type, proxy_param_types, proxy_function_name, ex_imcall, imcall);
else
Printf(excode, "((this.classinfo == %s.classinfo) ? %s : %s)", proxy_class_name, imcall, ex_imcall);
Printf(excode, "((swigIsMethodOverridden!(%s delegate(%s), %s function(%s), %s)()) ? %s : %s)",
return_type, proxy_param_types, return_type, proxy_param_types, proxy_function_name, ex_imcall, imcall);
Clear(imcall);
Printv(imcall, excode, NIL);
@ -2789,6 +2795,8 @@ private:
Swig_warning(WARN_D_TYPEMAP_DOUT_UNDEF, input_file, line_number,
"No dout typemap defined for %s\n", SwigType_str(t, 0));
}
Delete(proxy_param_types);
// The whole function body is now in stored tm (if there was a matching type
// map, of course), so simply append it to the code buffer. The braces are
@ -3419,7 +3427,7 @@ private:
// Only emit it if the proxy class has at least one method.
if (first_class_dmethod < curr_class_dmethod) {
Printf(proxy_class_body_code, "\n");
Printf(proxy_class_body_code, "private bool swigIsMethodOverridden(DelegateType, FunctionType, alias fn)() {\n");
Printf(proxy_class_body_code, "private bool swigIsMethodOverridden(DelegateType, FunctionType, alias fn)() %s{\n", (d_version > 1) ? "const " : "");
Printf(proxy_class_body_code, " DelegateType dg = &fn;\n");
Printf(proxy_class_body_code, " return dg.funcptr != SwigNonVirtualAddressOf!(FunctionType, fn);\n");
Printf(proxy_class_body_code, "}\n");
@ -3653,7 +3661,7 @@ private:
String *getPrimitiveDptype(Node *node, SwigType *type) {
SwigType *stripped_type = SwigType_typedef_resolve_all(type);
// A reference can only be the »outermost element« of a typ.
// A reference can only be the »outermost element« of a type.
bool mutable_ref = false;
if (SwigType_isreference(stripped_type)) {
SwigType_del_reference(stripped_type);

View file

@ -43,11 +43,9 @@ class GO:public Language {
File *f_go_runtime;
File *f_go_header;
File *f_go_wrappers;
File *f_go_once;
File *f_gc_runtime;
File *f_gc_header;
File *f_gc_wrappers;
File *f_gc_once;
// True if we imported a module.
bool saw_import;
@ -100,11 +98,9 @@ public:
f_go_runtime(NULL),
f_go_header(NULL),
f_go_wrappers(NULL),
f_go_once(NULL),
f_gc_runtime(NULL),
f_gc_header(NULL),
f_gc_wrappers(NULL),
f_gc_once(NULL),
saw_import(false),
imported_package(NULL),
interfaces(NULL),
@ -303,12 +299,10 @@ private:
f_go_runtime = NewString("");
f_go_header = NewString("");
f_go_wrappers = NewString("");
f_go_once = NewString("");
if (!gccgo_flag) {
f_gc_runtime = NewString("");
f_gc_header = NewString("");
f_gc_wrappers = NewString("");
f_gc_once = NewString("");
}
Swig_register_filebyname("begin", f_c_begin);
@ -322,13 +316,11 @@ private:
Swig_register_filebyname("go_runtime", f_go_runtime);
Swig_register_filebyname("go_header", f_go_header);
Swig_register_filebyname("go_wrapper", f_go_wrappers);
Swig_register_filebyname("go_once", f_go_once);
if (!gccgo_flag) {
Swig_register_filebyname("gc_begin", f_gc_begin);
Swig_register_filebyname("gc_runtime", f_gc_runtime);
Swig_register_filebyname("gc_header", f_gc_header);
Swig_register_filebyname("gc_wrapper", f_gc_wrappers);
Swig_register_filebyname("gc_once", f_gc_once);
}
Swig_banner(f_c_begin);
@ -349,6 +341,7 @@ private:
if (!gccgo_flag) {
Swig_banner(f_gc_begin);
Printf(f_gc_begin, "\n/* This file should be compiled with 6c/8c. */\n");
Printf(f_gc_begin, "#pragma dynimport _ _ \"%s\"\n", soname);
}
// Output module initialization code.
@ -414,16 +407,10 @@ private:
Dump(f_c_wrappers, f_c_begin);
Dump(f_c_init, f_c_begin);
Dump(f_go_header, f_go_begin);
if (!saw_import) {
Dump(f_go_once, f_go_begin);
}
Dump(f_go_runtime, f_go_begin);
Dump(f_go_wrappers, f_go_begin);
if (!gccgo_flag) {
Dump(f_gc_header, f_gc_begin);
if (!saw_import) {
Dump(f_gc_once, f_gc_begin);
}
Dump(f_gc_runtime, f_gc_begin);
Dump(f_gc_wrappers, f_gc_begin);
}
@ -1011,8 +998,9 @@ private:
int gcFunctionWrapper(Node *n, String *name, String *go_name, String *overname, String *wname, ParmList *parms, SwigType *result, bool is_static, bool needs_wrapper) {
Wrapper *f = NewWrapper();
Printv(f->def, "#pragma dynimport ", wname, " ", wname, " \"", soname, "\"\n", NULL);
Printv(f->def, "void (*", wname, ")(void*);\n", NULL);
Printv(f->def, "#pragma dynimport ", wname, " ", wname, " \"\"\n", NULL);
Printv(f->def, "extern void (*", wname, ")(void*);\n", NULL);
Printv(f->def, "static void (*x", wname, ")(void*) = ", wname, ";\n", NULL);
Printv(f->def, "\n", NULL);
Printv(f->def, "void\n", NULL);
@ -1068,7 +1056,7 @@ private:
Delete(parm_size);
Printv(f->code, "{\n", NULL);
Printv(f->code, "\truntime\xc2\xb7" "cgocall(", wname, ", &p);\n", NULL);
Printv(f->code, "\truntime\xc2\xb7" "cgocall(x", wname, ", &p);\n", NULL);
Printv(f->code, "}\n", NULL);
Printv(f->code, "\n", NULL);
@ -1166,7 +1154,7 @@ private:
p = nextParm(p);
}
if (SwigType_type(result) != T_VOID) {
Printv(f->code, "\t\tint : 0;\n", NULL);
Printv(f->code, "\t\tlong : 0;\n", NULL);
String *ln = NewString("result");
String *ct = gcCTypeForGoValue(n, result, ln);
Delete(ln);
@ -1270,7 +1258,11 @@ private:
Parm *p = parms;
for (int i = 0; i < parm_count; ++i) {
p = getParm(p);
SwigType *pt = Getattr(p, "type");
SwigType *pt = Copy(Getattr(p, "type"));
if (SwigType_isarray(pt)) {
SwigType_del_array(pt);
SwigType_add_pointer(pt);
}
String *pn = NewString("g");
Append(pn, Getattr(p, "lname"));
String *ct = gccgoCTypeForGoValue(p, pt, pn);
@ -1280,6 +1272,7 @@ private:
Printv(fnname, ct, NULL);
Delete(ct);
Delete(pn);
Delete(pt);
p = nextParm(p);
}
@ -3415,7 +3408,7 @@ private:
p = Getattr(p, "tmap:directorin:next");
}
if (SwigType_type(result) != T_VOID) {
Printv(f->code, " int : 0;\n", NULL);
Printv(f->code, " long : 0;\n", NULL);
String *rname = NewString("result");
String *cg = gcCTypeForGoValue(n, result, rname);
Printv(f->code, " ", cg, ";\n", NULL);
@ -3545,7 +3538,7 @@ private:
}
} else {
assert(is_pure_virtual);
Printv(f->code, " _swig_gopanic(\"call to pure virtual function ", Getattr(parent, "sym:name"), name, "\");\n");
Printv(f->code, " _swig_gopanic(\"call to pure virtual function ", Getattr(parent, "sym:name"), name, "\");\n", NULL);
if (SwigType_type(result) != T_VOID) {
String *retstr = SwigType_rcaststr(Getattr(n, "returntype"), "c_result");
Printv(f->code, " return ", retstr, ";\n", NULL);

View file

@ -3548,7 +3548,6 @@ public:
String *callback_def = NewString("");
String *callback_code = NewString("");
String *imcall_args = NewString("");
int gencomma = 0;
int classmeth_off = curr_class_dmethod - first_class_dmethod;
bool ignored_method = GetFlag(n, "feature:ignore") ? true : false;
@ -3767,14 +3766,14 @@ public:
Delete(tp);
/* Go through argument list, convert from native to Java */
for (p = l; p; /* empty */ ) {
for (i = 0, p = l; p; ++i) {
/* Is this superfluous? */
while (checkAttribute(p, "tmap:directorin:numinputs", "0")) {
p = Getattr(p, "tmap:directorin:next");
}
SwigType *pt = Getattr(p, "type");
String *ln = Copy(Getattr(p, "name"));
String *ln = makeParameterName(n, p, i, false);
String *c_param_type = NULL;
String *c_decl = NewString("");
String *arg = NewString("");
@ -3833,7 +3832,7 @@ public:
substituteClassname(pt, din);
Replaceall(din, "$jniinput", ln);
if (++gencomma > 1)
if (i > 0)
Printf(imcall_args, ", ");
Printf(callback_def, ", %s %s", tm, ln);
@ -3896,6 +3895,7 @@ public:
Delete(arg);
Delete(c_decl);
Delete(c_param_type);
Delete(ln);
}
/* header declaration, start wrapper definition */

View file

@ -3011,7 +3011,7 @@ Node *Language::symbolLookup(String *s, const_String_or_char_ptr scope) {
* Tries to locate a class from a type definition
* ----------------------------------------------------------------------------- */
Node *Language::classLookup(SwigType *s) {
Node *Language::classLookup(const SwigType *s) {
Node *n = 0;
/* Look in hash of cached values */

View file

@ -35,7 +35,7 @@ static String *classname = 0;
static String *module = 0;
static String *init_func_def = 0;
static String *f_classtemplate = 0;
static String *name_qualifier = 0;
static SwigType *name_qualifier_type = 0;
static Hash *seen_enums = 0;
static Hash *seen_enumvalues = 0;
@ -898,12 +898,12 @@ public:
String *name = Getattr(n, "feature:symname");
SwigType *type = Getattr(n, "type");
String *value = Getattr(n, "value");
String *qvalue = Getattr(n, "qualified:value");
SwigType *qname = Getattr(n, "qualified:name");
String *rvalue = NewString("");
String *temp = 0;
if (qvalue)
value = qvalue;
if (qname)
value = qname;
if (!name) {
name = mangleNameForCaml(Getattr(n, "name"));
@ -1228,20 +1228,18 @@ public:
return out;
}
String *fully_qualify_enum_name(Node *n, String *name) {
SwigType *fully_qualified_enum_type(Node *n) {
Node *parent = 0;
String *qualification = NewString("");
String *fully_qualified_name = NewString("");
String *parent_type = 0;
String *normalized_name;
parent = parentNode(n);
while (parent) {
parent_type = nodeType(parent);
if (Getattr(parent, "name")) {
String *parent_copy = NewStringf("%s::", Getattr(parent, "name"));
if (!Cmp(parent_type, "class") || !Cmp(parent_type, "namespace"))
Insert(qualification, 0, parent_copy);
if (Cmp(parent_type, "class") == 0 || Cmp(parent_type, "namespace") == 0)
Insert(fully_qualified_name, 0, parent_copy);
Delete(parent_copy);
}
if (!Cmp(parent_type, "class"))
@ -1249,25 +1247,18 @@ public:
parent = parentNode(parent);
}
Printf(fully_qualified_name, "%s%s", qualification, name);
normalized_name = normalizeTemplatedClassName(fully_qualified_name);
if (!strncmp(Char(normalized_name), "enum ", 5)) {
Insert(normalized_name, 5, qualification);
}
return normalized_name;
return fully_qualified_name;
}
/* Benedikt Grundmann inspired --> Enum wrap styles */
int enumvalueDeclaration(Node *n) {
String *name = Getattr(n, "name");
String *qvalue = 0;
SwigType *qtype = 0;
if (name_qualifier) {
qvalue = Copy(name_qualifier);
Printv(qvalue, name, NIL);
if (name_qualifier_type) {
qtype = Copy(name_qualifier_type);
Printv(qtype, name, NIL);
}
if (const_enum && name && !Getattr(seen_enumvalues, name)) {
@ -1275,10 +1266,10 @@ public:
SetFlag(n, "feature:immutable");
Setattr(n, "feature:enumvalue", "1"); // this does not appear to be used
if (qvalue)
Setattr(n, "qualified:value", qvalue);
if (qtype)
Setattr(n, "qualified:name", SwigType_namestr(qtype));
String *evname = SwigType_manglestr(qvalue);
String *evname = SwigType_manglestr(qtype);
Insert(evname, 0, "SWIG_ENUM_");
Setattr(n, "feature:enumvname", name);
@ -1309,10 +1300,10 @@ public:
/* name is now fully qualified */
String *fully_qualified_name = NewString(name);
bool seen_enum = false;
if (name_qualifier)
Delete(name_qualifier);
if (name_qualifier_type)
Delete(name_qualifier_type);
char *strip_position;
name_qualifier = fully_qualify_enum_name(n, NewString(""));
name_qualifier_type = fully_qualified_enum_type(n);
strip_position = strstr(Char(oname), "::");

View file

@ -126,7 +126,7 @@ static enum {
} wrapperType = standard;
extern "C" {
static void (*r_prevtracefunc) (SwigType *t, String *mangled, String *clientdata) = 0;
static void (*r_prevtracefunc) (const SwigType *t, String *mangled, String *clientdata) = 0;
}
static void SwigPHP_emit_resource_registrations() {
@ -2710,7 +2710,7 @@ static PHP *maininstance = 0;
// We use this function to be able to write out zend_register_list_destructor_ex
// lines for most things in the type table
// NOTE: it's a function NOT A PHP::METHOD
extern "C" void typetrace(SwigType *ty, String *mangled, String *clientdata) {
extern "C" void typetrace(const SwigType *ty, String *mangled, String *clientdata) {
Node *class_node;
if (!zend_types) {
zend_types = NewHash();

View file

@ -213,7 +213,7 @@ public:
virtual int addSymbol(const String *s, const Node *n, const_String_or_char_ptr scope = ""); /* Add symbol */
virtual void dumpSymbols();
virtual Node *symbolLookup(String *s, const_String_or_char_ptr scope = ""); /* Symbol lookup */
virtual Node *classLookup(SwigType *s); /* Class lookup */
virtual Node *classLookup(const SwigType *s); /* Class lookup */
virtual Node *enumLookup(SwigType *s); /* Enum lookup */
virtual int abstractClassTest(Node *n); /* Is class really abstract? */
virtual int is_assignable(Node *n); /* Is variable assignable? */

View file

@ -254,12 +254,17 @@ class TypePass:private Dispatcher {
Delete(smartnamestr);
/* setup inheritance relationship between smart pointer templates */
SwigType_inherit(smart, bsmart, 0, convcode);
if (!GetFlag(bclass, "feature:smartptr"))
Swig_warning(WARN_LANG_SMARTPTR_MISSING, Getfile(first), Getline(first), "Base class '%s' of '%s' is not similarly marked as a smart pointer.\n", SwigType_namestr(Getattr(bclass, "name")), SwigType_namestr(Getattr(first, "name")));
Delete(convcode);
Delete(bsmart);
Delete(smart);
} else {
Swig_error(Getfile(first), Getline(first), "Invalid type (%s) in 'smartptr' feature for class %s.\n", SwigType_namestr(smartptr), SwigType_namestr(clsname));
}
} else {
if (GetFlag(bclass, "feature:smartptr"))
Swig_warning(WARN_LANG_SMARTPTR_MISSING, Getfile(first), Getline(first), "Derived class '%s' of '%s' is not similarly marked as a smart pointer.\n", SwigType_namestr(Getattr(first, "name")), SwigType_namestr(Getattr(bclass, "name")));
}
if (!importmode) {
String *btype = Copy(bname);