Renaming and type mangling fixes. Reverted to normal typemaps searching.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2008-maciekd@10694 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
9c5ef7558c
commit
6fd77fa609
4 changed files with 70 additions and 61 deletions
|
|
@ -47,16 +47,18 @@ typedef struct {
|
||||||
|
|
||||||
%typemap(in) short, int, long, char, float, double, bool "$1 = ($1_type) $input;"
|
%typemap(in) short, int, long, char, float, double, bool "$1 = ($1_type) $input;"
|
||||||
%typemap(in) void *, short *, int *, long *, char *, float *, double *, bool * "$1 = ($1_type) $input;"
|
%typemap(in) void *, short *, int *, long *, char *, float *, double *, bool * "$1 = ($1_type) $input;"
|
||||||
%typemap(in) void **, short **, int **, long **, char **, float **, double **, bool * "$1 = ($1_type) $input;"
|
%typemap(in) void **, short **, int **, long **, char **, float **, double **, bool * "$1 = ($1_basetype **) $input;"
|
||||||
%typemap(in) unsigned short *, unsigned int *, unsigned long *, unsigned char * "$1 = ($1_type) $input;"
|
%typemap(in) unsigned short *, unsigned int *, unsigned long *, unsigned char * "$1 = ($1_type) $input;"
|
||||||
%typemap(in) unsigned short **, unsigned int **, unsigned long **, unsigned char ** "$1 = ($1_type) $input;"
|
%typemap(in) unsigned short **, unsigned int **, unsigned long **, unsigned char ** "$1 = ($1_type) $input;"
|
||||||
%typemap(in) const void *, const short *, const int *, const long *, const char *, const float *, const double *, const bool * "$1 = ($1_basetype *) $input;"
|
%typemap(in) const void *, const short *, const int *, const long *, const char *, const float *, const double *, const bool * "$1 = ($1_basetype *) $input;"
|
||||||
%typemap(in) const unsigned short *, const unsigned int *, const unsigned long *, const unsigned char * "$1 = ($1_type) $input;"
|
%typemap(in) const unsigned short *, const unsigned int *, const unsigned long *, const unsigned char * "$1 = ($1_type) $input;"
|
||||||
%typemap(in) unsigned short, unsigned int, unsigned long, unsigned char "$1 = ($1_type) $input;"
|
%typemap(in) unsigned short, unsigned int, unsigned long, unsigned char "$1 = ($1_type) $input;"
|
||||||
%typemap(in) short &, int &, long &, char &, float &, double &, bool & "$1 = ($1_basetype *) $input;"
|
%typemap(in) short &, int &, long &, char &, float &, double &, bool & "$1 = ($1_basetype *) $input;"
|
||||||
%typemap(in) const short &, const int &, const long &, const char &, const float &, const double &, const bool & "$1 = ($1_basetype const *) $input;"
|
%typemap(in) const short &, const int &, const long &, const char &, const float &, const double &, const bool & "$1 = ($1_basetype *) $input;"
|
||||||
%typemap(in) unsigned short &, unsigned int &, unsigned long &, unsigned char & "$1 = ($1_basetype *) $input;"
|
%typemap(in) unsigned short &, unsigned int &, unsigned long &, unsigned char & "$1 = ($1_basetype *) $input;"
|
||||||
%typemap(in) const unsigned short &, const unsigned int &, const unsigned long &, const unsigned char & "$1 = ($1_basetype const *) $input;"
|
%typemap(in) const unsigned short &, const unsigned int &, const unsigned long &, const unsigned char & "$1 = ($1_basetype *) $input;"
|
||||||
|
|
||||||
|
%typemap(in) void * [ANY], short * [ANY], int * [ANY], long * [ANY], char * [ANY], float * [ANY], double * [ANY], bool * [ANY] "$1 = ($1_basetype *) $input;"
|
||||||
|
|
||||||
%typemap(in, fragment="stdbool_inc") bool, bool *, bool **, const bool, const bool *, bool * [ANY] "$1 = ($1_type) $input;"
|
%typemap(in, fragment="stdbool_inc") bool, bool *, bool **, const bool, const bool *, bool * [ANY] "$1 = ($1_type) $input;"
|
||||||
%typemap(in, fragment="stdbool_inc") bool &, const bool & "$1 = ($1_basetype *) $input;"
|
%typemap(in, fragment="stdbool_inc") bool &, const bool & "$1 = ($1_basetype *) $input;"
|
||||||
|
|
|
||||||
|
|
@ -66,9 +66,6 @@ public:
|
||||||
SWIG_typemap_lang("c");
|
SWIG_typemap_lang("c");
|
||||||
SWIG_config_file("c.swg");
|
SWIG_config_file("c.swg");
|
||||||
|
|
||||||
// FIXME
|
|
||||||
Swig_typemap_class_distinguish(false);
|
|
||||||
|
|
||||||
// look for certain command line options
|
// look for certain command line options
|
||||||
for (int i = 1; i < argc; i++) {
|
for (int i = 1; i < argc; i++) {
|
||||||
if (argv[i]) {
|
if (argv[i]) {
|
||||||
|
|
@ -261,18 +258,61 @@ public:
|
||||||
|
|
||||||
/* ----------------------------------------------------------------------
|
/* ----------------------------------------------------------------------
|
||||||
* getMangledType()
|
* getMangledType()
|
||||||
*
|
|
||||||
* incomplete for now...
|
|
||||||
* ---------------------------------------------------------------------- */
|
* ---------------------------------------------------------------------- */
|
||||||
|
|
||||||
const char *getMangledType(String *type) {
|
String *getMangledType(SwigType *type_arg) {
|
||||||
char *c = Char(type);
|
static String *result = 0;
|
||||||
if (strcmp(c, "int") == 0)
|
SwigType *prefix = 0;
|
||||||
return "i";
|
if (result)
|
||||||
if (strcmp(c, "double") == 0)
|
Delete(result);
|
||||||
return "d";
|
result = NewString("");
|
||||||
|
|
||||||
return "UNKNOWN";
|
/*Printf(stderr, "MANGLING TYPE: %s\n", type_arg);*/
|
||||||
|
|
||||||
|
SwigType *type = Copy(type_arg);
|
||||||
|
|
||||||
|
if (SwigType_ismemberpointer(type)) {
|
||||||
|
SwigType_del_memberpointer(type);
|
||||||
|
SwigType_add_pointer(type);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (SwigType_ispointer(type)) {
|
||||||
|
SwigType_del_pointer(type);
|
||||||
|
if (SwigType_isfunction(type)) {
|
||||||
|
Printf(result, "f");
|
||||||
|
goto ready;
|
||||||
|
}
|
||||||
|
Delete(type);
|
||||||
|
type = Copy(type_arg);
|
||||||
|
}
|
||||||
|
|
||||||
|
prefix = SwigType_prefix(type);
|
||||||
|
Replaceall(prefix, ".", "");
|
||||||
|
Replaceall(prefix, "const", "c");
|
||||||
|
Replaceall(prefix, "volatile", "v");
|
||||||
|
Replaceall(prefix, "a(", "a");
|
||||||
|
Replaceall(prefix, "m(", "m");
|
||||||
|
Replaceall(prefix, "q(", "");
|
||||||
|
Replaceall(prefix, ")", "");
|
||||||
|
Replaceall(prefix, " ", "");
|
||||||
|
Printf(result, "%s", prefix);
|
||||||
|
|
||||||
|
type = SwigType_base(type);
|
||||||
|
if (SwigType_isbuiltin(type))
|
||||||
|
Printf(result, "%c", *Char(SwigType_base(type)));
|
||||||
|
else if (SwigType_isenum(type))
|
||||||
|
Printf(result, "e%s", Swig_scopename_last(type));
|
||||||
|
else
|
||||||
|
Printf(result, "%s", Char(SwigType_base(type)));
|
||||||
|
|
||||||
|
ready:
|
||||||
|
/*Printf(stderr, " RESULT: %s\n", result);*/
|
||||||
|
|
||||||
|
if (prefix)
|
||||||
|
Delete(prefix);
|
||||||
|
if (type)
|
||||||
|
Delete(type);
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ----------------------------------------------------------------------
|
/* ----------------------------------------------------------------------
|
||||||
|
|
@ -362,10 +402,11 @@ public:
|
||||||
// mangle name if function is overloaded
|
// mangle name if function is overloaded
|
||||||
if (Getattr(n, "sym:overloaded")) {
|
if (Getattr(n, "sym:overloaded")) {
|
||||||
if (!Getattr(n, "copy_constructor")) {
|
if (!Getattr(n, "copy_constructor")) {
|
||||||
if (parms)
|
|
||||||
Append(over_suffix, "_");
|
|
||||||
for (p = parms; p; p = nextSibling(p)) {
|
for (p = parms; p; p = nextSibling(p)) {
|
||||||
Append(over_suffix, getMangledType(Getattr(p, "type")));
|
if (Getattr(p, "c:objstruct"))
|
||||||
|
continue;
|
||||||
|
String *mangled = getMangledType(Getattr(p, "type"));
|
||||||
|
Printv(over_suffix, "_", mangled, NIL);
|
||||||
}
|
}
|
||||||
Append(name, over_suffix);
|
Append(name, over_suffix);
|
||||||
}
|
}
|
||||||
|
|
@ -703,7 +744,7 @@ public:
|
||||||
* --------------------------------------------------------------------- */
|
* --------------------------------------------------------------------- */
|
||||||
|
|
||||||
virtual int staticmemberfunctionHandler(Node *n) {
|
virtual int staticmemberfunctionHandler(Node *n) {
|
||||||
String *name = Getattr(n, "name");
|
String *name = Copy(Getattr(n, "sym:name"));
|
||||||
String *classname = Getattr(parentNode(n), "typename");
|
String *classname = Getattr(parentNode(n), "typename");
|
||||||
String *newclassname = Getattr(parentNode(n), "sym:name");
|
String *newclassname = Getattr(parentNode(n), "sym:name");
|
||||||
String *new_name = NewString("");
|
String *new_name = NewString("");
|
||||||
|
|
@ -717,12 +758,12 @@ public:
|
||||||
Delitem(arg_lnames, DOH_END);
|
Delitem(arg_lnames, DOH_END);
|
||||||
|
|
||||||
// modify method name
|
// modify method name
|
||||||
Printv(new_name, newclassname, "_", name, NIL);
|
new_name = Swig_name_member(newclassname, name);
|
||||||
Setattr(n, "sym:name", new_name);
|
Setattr(n, "sym:name", new_name);
|
||||||
|
|
||||||
// generate action code
|
// generate action code
|
||||||
Printv(code, (Strcmp(Getattr(n, "type"), "void") != 0) ? "$cppresult = $mod " : "", NIL);
|
Printv(code, (Strcmp(Getattr(n, "type"), "void") != 0) ? "$cppresult = $mod " : "", NIL);
|
||||||
Printv(code, classname, "::", name, "(", arg_lnames, ");\n", NIL);
|
Printv(code, classname, "::", Getattr(n, "name"), "(", arg_lnames, ");\n", NIL);
|
||||||
Setattr(n, "wrap:action", code);
|
Setattr(n, "wrap:action", code);
|
||||||
|
|
||||||
functionWrapper(n);
|
functionWrapper(n);
|
||||||
|
|
@ -730,6 +771,7 @@ public:
|
||||||
Delete(arg_lnames);
|
Delete(arg_lnames);
|
||||||
Delete(code);
|
Delete(code);
|
||||||
Delete(new_name);
|
Delete(new_name);
|
||||||
|
Delete(name);
|
||||||
return SWIG_OK;
|
return SWIG_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -738,7 +780,7 @@ public:
|
||||||
* --------------------------------------------------------------------- */
|
* --------------------------------------------------------------------- */
|
||||||
|
|
||||||
virtual int memberfunctionHandler(Node *n) {
|
virtual int memberfunctionHandler(Node *n) {
|
||||||
String *name = Getattr(n, "name");
|
String *name = Copy(Getattr(n, "sym:name"));
|
||||||
String *classname = Getattr(parentNode(n), "classtype");
|
String *classname = Getattr(parentNode(n), "classtype");
|
||||||
String *newclassname = Getattr(parentNode(n), "sym:name");
|
String *newclassname = Getattr(parentNode(n), "sym:name");
|
||||||
String *sobj_name = NewString("");
|
String *sobj_name = NewString("");
|
||||||
|
|
@ -776,14 +818,14 @@ public:
|
||||||
Delitem(arg_lnames, DOH_END);
|
Delitem(arg_lnames, DOH_END);
|
||||||
|
|
||||||
// modify method name
|
// modify method name
|
||||||
Printv(new_name, newclassname, "_", name, NIL);
|
new_name = Swig_name_member(newclassname, name);
|
||||||
Setattr(n, "sym:name", new_name);
|
Setattr(n, "sym:name", new_name);
|
||||||
|
|
||||||
// generate action code
|
// generate action code
|
||||||
if (typecheck_flag)
|
if (typecheck_flag)
|
||||||
emit_runtime_typecheck(newclassname, new_name, code);
|
emit_runtime_typecheck(newclassname, new_name, code);
|
||||||
Printv(code, (Strcmp(Getattr(n, "type"), "void") != 0) ? "$cppresult = $mod " : "", NIL);
|
Printv(code, (Strcmp(Getattr(n, "type"), "void") != 0) ? "$cppresult = $mod " : "", NIL);
|
||||||
Printv(code, "((", classname, "*) arg1->obj)->", name, "(", arg_call_lnames, ");\n", NIL);
|
Printv(code, "((", classname, "*) arg1->obj)->", Getattr(n, "name"), "(", arg_call_lnames, ");\n", NIL);
|
||||||
Setattr(n, "wrap:action", code);
|
Setattr(n, "wrap:action", code);
|
||||||
|
|
||||||
functionWrapper(n);
|
functionWrapper(n);
|
||||||
|
|
@ -794,6 +836,7 @@ public:
|
||||||
Delete(stype);
|
Delete(stype);
|
||||||
Delete(ctype);
|
Delete(ctype);
|
||||||
Delete(sobj_name);
|
Delete(sobj_name);
|
||||||
|
Delete(name);
|
||||||
return SWIG_OK;
|
return SWIG_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -377,7 +377,6 @@ extern int ParmList_is_compactdefargs(ParmList *p);
|
||||||
extern Hash *Swig_typemap_pop_scope(void);
|
extern Hash *Swig_typemap_pop_scope(void);
|
||||||
|
|
||||||
extern void Swig_typemap_attach_parms(const String_or_char *op, ParmList *parms, Wrapper *f);
|
extern void Swig_typemap_attach_parms(const String_or_char *op, ParmList *parms, Wrapper *f);
|
||||||
extern void Swig_typemap_class_distinguish(int b);
|
|
||||||
|
|
||||||
/* --- Code fragment support --- */
|
/* --- Code fragment support --- */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -47,7 +47,6 @@ static void replace_embedded_typemap(String *s);
|
||||||
|
|
||||||
static Hash *typemaps[MAX_SCOPE];
|
static Hash *typemaps[MAX_SCOPE];
|
||||||
static int tm_scope = 0;
|
static int tm_scope = 0;
|
||||||
static int class_distinguish = 0;
|
|
||||||
|
|
||||||
static Hash *get_typemap(int tm_scope, SwigType *type) {
|
static Hash *get_typemap(int tm_scope, SwigType *type) {
|
||||||
Hash *tm = 0;
|
Hash *tm = 0;
|
||||||
|
|
@ -61,6 +60,7 @@ static Hash *get_typemap(int tm_scope, SwigType *type) {
|
||||||
}
|
}
|
||||||
tm = Getattr(typemaps[tm_scope], type);
|
tm = Getattr(typemaps[tm_scope], type);
|
||||||
|
|
||||||
|
|
||||||
if (dtype) {
|
if (dtype) {
|
||||||
if (!tm) {
|
if (!tm) {
|
||||||
String *t_name = SwigType_templateprefix(type);
|
String *t_name = SwigType_templateprefix(type);
|
||||||
|
|
@ -583,10 +583,6 @@ static SwigType *strip_arrays(SwigType *type) {
|
||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Swig_typemap_class_distinguish(int b) {
|
|
||||||
class_distinguish = b;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* -----------------------------------------------------------------------------
|
/* -----------------------------------------------------------------------------
|
||||||
* Swig_typemap_search()
|
* Swig_typemap_search()
|
||||||
*
|
*
|
||||||
|
|
@ -605,21 +601,6 @@ Hash *Swig_typemap_search(const String_or_char *op, SwigType *type, const String
|
||||||
const String *cname = 0;
|
const String *cname = 0;
|
||||||
SwigType *unstripped = 0;
|
SwigType *unstripped = 0;
|
||||||
String *tmop = tmop_name(op);
|
String *tmop = tmop_name(op);
|
||||||
SwigType *base = 0;
|
|
||||||
int isbuiltin = 0;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* HACK:
|
|
||||||
* try to distinguish between built-in types (int, char, etc.) and defined classes
|
|
||||||
* this allows C module to use different typemaps for classes
|
|
||||||
*/
|
|
||||||
|
|
||||||
if (class_distinguish) {
|
|
||||||
base = SwigType_base(type);
|
|
||||||
isbuiltin = SwigType_isbuiltin(base);
|
|
||||||
if (!isbuiltin)
|
|
||||||
Replaceall(type, base, "SWIGCLASSTYPE");
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((name) && Len(name))
|
if ((name) && Len(name))
|
||||||
cname = name;
|
cname = name;
|
||||||
|
|
@ -705,16 +686,7 @@ Hash *Swig_typemap_search(const String_or_char *op, SwigType *type, const String
|
||||||
/* Hmmm. Well, no match seems to be found at all. See if there is some kind of default mapping */
|
/* Hmmm. Well, no match seems to be found at all. See if there is some kind of default mapping */
|
||||||
|
|
||||||
primitive = SwigType_default(type);
|
primitive = SwigType_default(type);
|
||||||
|
|
||||||
while (primitive) {
|
while (primitive) {
|
||||||
|
|
||||||
if (class_distinguish) {
|
|
||||||
if (!isbuiltin) {
|
|
||||||
Replaceall(primitive, "SWIGTYPE", "SWIGCLASSTYPE");
|
|
||||||
/*Printf(stdout, "Swig_typemap_search: new type is %s\n", primitive);*/
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
tm = get_typemap(ts, primitive);
|
tm = get_typemap(ts, primitive);
|
||||||
if (tm && cname) {
|
if (tm && cname) {
|
||||||
tm1 = Getattr(tm, cname);
|
tm1 = Getattr(tm, cname);
|
||||||
|
|
@ -730,8 +702,6 @@ Hash *Swig_typemap_search(const String_or_char *op, SwigType *type, const String
|
||||||
goto ret_result;
|
goto ret_result;
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
if (class_distinguish)
|
|
||||||
Replaceall(primitive, "SWIGCLASSTYPE", "SWIGTYPE");
|
|
||||||
SwigType *nprim = SwigType_default(primitive);
|
SwigType *nprim = SwigType_default(primitive);
|
||||||
Delete(primitive);
|
Delete(primitive);
|
||||||
primitive = nprim;
|
primitive = nprim;
|
||||||
|
|
@ -746,10 +716,6 @@ Hash *Swig_typemap_search(const String_or_char *op, SwigType *type, const String
|
||||||
result = backup;
|
result = backup;
|
||||||
|
|
||||||
ret_result:
|
ret_result:
|
||||||
if (class_distinguish) {
|
|
||||||
Replaceall(type, "SWIGCLASSTYPE", base);
|
|
||||||
Replaceall(primitive, "SWIGCLASSTYPE", base);
|
|
||||||
}
|
|
||||||
if (noarrays)
|
if (noarrays)
|
||||||
Delete(noarrays);
|
Delete(noarrays);
|
||||||
if (primitive)
|
if (primitive)
|
||||||
|
|
@ -761,7 +727,6 @@ ret_result:
|
||||||
}
|
}
|
||||||
if (type != ctype)
|
if (type != ctype)
|
||||||
Delete(ctype);
|
Delete(ctype);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue