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:
Maciej Drwal 2008-07-21 15:52:30 +00:00
commit 6fd77fa609
4 changed files with 70 additions and 61 deletions

View file

@ -66,9 +66,6 @@ public:
SWIG_typemap_lang("c");
SWIG_config_file("c.swg");
// FIXME
Swig_typemap_class_distinguish(false);
// look for certain command line options
for (int i = 1; i < argc; i++) {
if (argv[i]) {
@ -261,18 +258,61 @@ public:
/* ----------------------------------------------------------------------
* getMangledType()
*
* incomplete for now...
* ---------------------------------------------------------------------- */
const char *getMangledType(String *type) {
char *c = Char(type);
if (strcmp(c, "int") == 0)
return "i";
if (strcmp(c, "double") == 0)
return "d";
String *getMangledType(SwigType *type_arg) {
static String *result = 0;
SwigType *prefix = 0;
if (result)
Delete(result);
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
if (Getattr(n, "sym:overloaded")) {
if (!Getattr(n, "copy_constructor")) {
if (parms)
Append(over_suffix, "_");
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);
}
@ -703,7 +744,7 @@ public:
* --------------------------------------------------------------------- */
virtual int staticmemberfunctionHandler(Node *n) {
String *name = Getattr(n, "name");
String *name = Copy(Getattr(n, "sym:name"));
String *classname = Getattr(parentNode(n), "typename");
String *newclassname = Getattr(parentNode(n), "sym:name");
String *new_name = NewString("");
@ -717,12 +758,12 @@ public:
Delitem(arg_lnames, DOH_END);
// modify method name
Printv(new_name, newclassname, "_", name, NIL);
new_name = Swig_name_member(newclassname, name);
Setattr(n, "sym:name", new_name);
// generate action code
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);
functionWrapper(n);
@ -730,6 +771,7 @@ public:
Delete(arg_lnames);
Delete(code);
Delete(new_name);
Delete(name);
return SWIG_OK;
}
@ -738,7 +780,7 @@ public:
* --------------------------------------------------------------------- */
virtual int memberfunctionHandler(Node *n) {
String *name = Getattr(n, "name");
String *name = Copy(Getattr(n, "sym:name"));
String *classname = Getattr(parentNode(n), "classtype");
String *newclassname = Getattr(parentNode(n), "sym:name");
String *sobj_name = NewString("");
@ -776,14 +818,14 @@ public:
Delitem(arg_lnames, DOH_END);
// modify method name
Printv(new_name, newclassname, "_", name, NIL);
new_name = Swig_name_member(newclassname, name);
Setattr(n, "sym:name", new_name);
// generate action code
if (typecheck_flag)
emit_runtime_typecheck(newclassname, new_name, code);
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);
functionWrapper(n);
@ -794,6 +836,7 @@ public:
Delete(stype);
Delete(ctype);
Delete(sobj_name);
Delete(name);
return SWIG_OK;
}

View file

@ -377,7 +377,6 @@ extern int ParmList_is_compactdefargs(ParmList *p);
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_class_distinguish(int b);
/* --- Code fragment support --- */

View file

@ -47,7 +47,6 @@ static void replace_embedded_typemap(String *s);
static Hash *typemaps[MAX_SCOPE];
static int tm_scope = 0;
static int class_distinguish = 0;
static Hash *get_typemap(int tm_scope, SwigType *type) {
Hash *tm = 0;
@ -61,6 +60,7 @@ static Hash *get_typemap(int tm_scope, SwigType *type) {
}
tm = Getattr(typemaps[tm_scope], type);
if (dtype) {
if (!tm) {
String *t_name = SwigType_templateprefix(type);
@ -583,10 +583,6 @@ static SwigType *strip_arrays(SwigType *type) {
return t;
}
void Swig_typemap_class_distinguish(int b) {
class_distinguish = b;
}
/* -----------------------------------------------------------------------------
* Swig_typemap_search()
*
@ -605,21 +601,6 @@ Hash *Swig_typemap_search(const String_or_char *op, SwigType *type, const String
const String *cname = 0;
SwigType *unstripped = 0;
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))
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 */
primitive = SwigType_default(type);
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);
if (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;
}
{
if (class_distinguish)
Replaceall(primitive, "SWIGCLASSTYPE", "SWIGTYPE");
SwigType *nprim = SwigType_default(primitive);
Delete(primitive);
primitive = nprim;
@ -746,10 +716,6 @@ Hash *Swig_typemap_search(const String_or_char *op, SwigType *type, const String
result = backup;
ret_result:
if (class_distinguish) {
Replaceall(type, "SWIGCLASSTYPE", base);
Replaceall(primitive, "SWIGCLASSTYPE", base);
}
if (noarrays)
Delete(noarrays);
if (primitive)
@ -761,7 +727,6 @@ ret_result:
}
if (type != ctype)
Delete(ctype);
return result;
}