Changes to support memberin typemap

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@813 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Dave Beazley 2000-09-03 19:14:55 +00:00
commit 77a76ff4ce
6 changed files with 58 additions and 36 deletions

View file

@ -181,6 +181,7 @@ public:
char *name; // Name of the member char *name; // Name of the member
char *iname; // Name of member in the interpreter char *iname; // Name of member in the interpreter
int is_static; // Is this a static member? int is_static; // Is this a static member?
int is_virtual; // Is this virtual?
int new_method; // Is this a new method (added by SWIG)? int new_method; // Is this a new method (added by SWIG)?
int line; // What line number was this member on int line; // What line number was this member on
char *file; // What file was this in? char *file; // What file was this in?
@ -205,7 +206,6 @@ public:
SwigType *ret_type; SwigType *ret_type;
ParmList *parms; ParmList *parms;
int new_object; int new_object;
int is_virtual;
CPP_function(char *n, char *i, SwigType *t, ParmList *l, int s, int v = 0) { CPP_function(char *n, char *i, SwigType *t, ParmList *l, int s, int v = 0) {
name = Swig_copy_string(n); name = Swig_copy_string(n);
@ -417,8 +417,10 @@ public:
t = Copy(type); t = Copy(type);
update_local_type(t); update_local_type(t);
/* Check to see if it's read-only */ /* Check to see if it's read-only */
if (SwigType_isarray(t) || SwigType_isconst(t)) if (SwigType_isarray(t) || SwigType_isconst(t)) {
if (!(Swig_typemap_search("memberin",t,name)))
Status = Status | STAT_READONLY; Status = Status | STAT_READONLY;
}
if (!is_static) { if (!is_static) {
lang->cpp_variable(name,iname,t); lang->cpp_variable(name,iname,t);
@ -1139,9 +1141,8 @@ void cplus_member_func(char *name, char *iname, SwigType *type, ParmList *l,
// Issue a warning. // Issue a warning.
if (Inherit_mode) { if (Inherit_mode) {
if (current_class->search_member(temp_iname)) { CPP_member *m = current_class->search_member(temp_iname);
return; if (m) return;
}
} }
// Add it to our C++ class list // Add it to our C++ class list
@ -1151,7 +1152,7 @@ void cplus_member_func(char *name, char *iname, SwigType *type, ParmList *l,
// If this is a pure virtual function, the class is abstract // If this is a pure virtual function, the class is abstract
if (is_virtual) if (is_virtual == PURE_VIRTUAL)
current_class->is_abstract = 1; current_class->is_abstract = 1;
} }
@ -1511,12 +1512,17 @@ void cplus_emit_member_func(char *classname, char *classtype, char *classrename,
strcpy(iname, Char(Swig_name_member(classrename, mrename))); strcpy(iname, Char(Swig_name_member(classrename, mrename)));
char *bc = cplus_base_class(mrename);
if (!bc) bc = classname;
if (strlen(bc) == 0) bc = classname;
Printf(key,"%s+%s",Wrapper_Getname(w), ParmList_protostr(l));
if (!member_hash) member_hash = NewHash(); if (!member_hash) member_hash = NewHash();
char *bc = cplus_base_class(mrename);
if (!bc || (strlen(bc) == 0)) {
bc = classname;
}
/* Printf(key,"%s+%s",Wrapper_Getname(w), ParmList_protostr(l));*/
Printf(key,"%s+%s", Swig_name_member(bc,mrename), ParmList_protostr(l));
/* Printf(stdout,"virtual = %d, bc = %s, mkey = %s\n", IsVirtual, bc, key); */
if (Getattr(member_hash,key)) { if (Getattr(member_hash,key)) {
prev_wrap = GetChar(member_hash,key); prev_wrap = GetChar(member_hash,key);
} else { } else {
@ -1963,7 +1969,14 @@ void cplus_emit_variable_set(char *classname, char *classtype, char *classrename
if ((mode) && (ccode)) { if ((mode) && (ccode)) {
Wrapper_print(w,f_wrappers); Wrapper_print(w,f_wrappers);
} else if (!mode) { } else if (!mode) {
/* Check for a member in typemap here */
String *target = NewStringf("%s->%s", Swig_cparm_name(0,0),mname);
char *tm = Swig_typemap_lookup("memberin",type,mname,Swig_cparm_name(0,1),target,0);
if (!tm)
emit_set_action(Swig_cmemberset_call(mname,type)); emit_set_action(Swig_cmemberset_call(mname,type));
else
emit_set_action(tm);
Delete(target);
} }
lang->create_function(Wrapper_Getname(w),iname, Wrapper_Gettype(w), Wrapper_Getparms(w)); lang->create_function(Wrapper_Getname(w),iname, Wrapper_Gettype(w), Wrapper_Getparms(w));
} else { } else {

View file

@ -88,7 +88,6 @@ void Language::cpp_close_class() {
* ----------------------------------------------------------------------------- */ * ----------------------------------------------------------------------------- */
void Language::cpp_member_func(char *name, char *iname, SwigType *t, ParmList *l) { void Language::cpp_member_func(char *name, char *iname, SwigType *t, ParmList *l) {
char cname[256]; /* Name of the C function */
char new_name[256]; char new_name[256];
char *prefix; char *prefix;
@ -100,19 +99,6 @@ void Language::cpp_member_func(char *name, char *iname, SwigType *t, ParmList *l
} else { } else {
prefix = ClassName; prefix = ClassName;
} }
/* Generate the C wrapper name for this method */
if (AddMethods) {
char *bc = cplus_base_class(name); /* Get base class name of this method */
if (bc)
strcpy(cname, Char(Swig_name_member(bc,name)));
else
strcpy(cname, Char(Swig_name_member(ClassName,name)));
} else {
strcpy(cname, Char(Swig_name_member(ClassName,name)));
}
/* Create the actual function name */ /* Create the actual function name */
if (iname) { if (iname) {
@ -125,7 +111,7 @@ void Language::cpp_member_func(char *name, char *iname, SwigType *t, ParmList *l
if (add_symbol(new_name)) { if (add_symbol(new_name)) {
Printf(stderr,"%s : Line %d. Function %s (member %s) multiply defined (2nd definition ignored).\n", Printf(stderr,"%s : Line %d. Function %s (member %s) multiply defined (2nd definition ignored).\n",
input_file, line_number, cname, name); input_file, line_number, iname, name);
return; return;
} }
cplus_emit_member_func(ClassName, ClassType, ClassRename, name, iname, t, l, AddMethods); cplus_emit_member_func(ClassName, ClassType, ClassRename, name, iname, t, l, AddMethods);

View file

@ -2333,7 +2333,7 @@ cpp_member : type declaration LPAREN parms RPAREN cpp_end {
if ($3.is_reference) SwigType_add_reference($2); if ($3.is_reference) SwigType_add_reference($2);
iname = make_name($3.id); iname = make_name($3.id);
if (iname == $3.id) iname = 0; if (iname == $3.id) iname = 0;
cplus_member_func($3.id,iname,$2,$5,$7); cplus_member_func($3.id,iname,$2,$5,$7 ? PURE_VIRTUAL : PLAIN_VIRTUAL);
} }
scanner_clear_start(); scanner_clear_start();
Delete($2); Delete($2);

View file

@ -33,6 +33,10 @@ extern "C" {
extern FILE *swig_log; extern FILE *swig_log;
#endif #endif
#define PLAIN_VIRTUAL 1
#define PURE_VIRTUAL 2
#define SUPER_VIRTUAL 3
extern FILE *f_runtime; // Runtime code extern FILE *f_runtime; // Runtime code
extern DOH *f_header; // Headers extern DOH *f_header; // Headers
extern DOH *f_wrappers; // Wrappers extern DOH *f_wrappers; // Wrappers

View file

@ -200,7 +200,15 @@ void Swig_cresult(Wrapper *w, SwigType *t, String_or_char *name, String_or_char
} }
/* Now print out function call */ /* Now print out function call */
Printv(fcall, decl, ";\n", 0); Printv(fcall,decl,0);
/* A sick hack */
{
char *c = Char(decl) + Len(decl) - 1;
if (!((*c == ';') || (*c == '}')))
Printf(fcall, ";");
}
Printf(fcall,"\n");
if (SwigType_type(t) == T_REFERENCE) { if (SwigType_type(t) == T_REFERENCE) {
Printf(fcall,"%s = (%s) &_result_ref;\n", name, SwigType_lstr(t,0)); Printf(fcall,"%s = (%s) &_result_ref;\n", name, SwigType_lstr(t,0));
@ -252,7 +260,13 @@ void Swig_cppresult(Wrapper *w, SwigType *t, String_or_char *name, String_or_cha
Printf(fcall, "%s = (%s) &_result_ref;\n", name, SwigType_lstr(t,0)); Printf(fcall, "%s = (%s) &_result_ref;\n", name, SwigType_lstr(t,0));
break; break;
default: default:
Printf(fcall,";\n"); /* A sick hack */
{
char *c = Char(decl) + Len(decl) - 1;
if (!((*c == ';') || (*c == '}')))
Printf(fcall, ";");
}
Printf(fcall,"\n");
break; break;
} }
@ -429,16 +443,19 @@ Swig_cppdestructor_call() {
String * String *
Swig_cmemberset_call(String_or_char *name, SwigType *type) { Swig_cmemberset_call(String_or_char *name, SwigType *type) {
DOH *func; DOH *func;
String *pname;
func = NewString(""); func = NewString("");
/*
if (SwigType_type(type) == T_USER) { if (SwigType_type(type) == T_USER) {
Printf(func,"%s %s->%s; ", Swig_clocal_assign(type,""), Swig_cparm_name(0,0), name); Printf(func,"%s %s->%s; ", Swig_clocal_assign(type,""), Swig_cparm_name(0,0), name);
} else { } else {
Printf(func,"%s ", Swig_clocal_assign(type,"")); Printf(func,"%s ", Swig_clocal_assign(type,""));
} }
Printf(func,"(%s->%s = ", Swig_cparm_name(0,0), name); */
/* Printf(func,"(%s->%s = ", Swig_cparm_name(0,0), name);
Printf(func,"%s)", Swig_clocal_deref(type, (pname = Swig_cparm_name(0,1)))); Printf(func,"%s)", Swig_clocal_deref(type, (pname = Swig_cparm_name(0,1))));
*/
Printf(func,"%s->%s = %s",Swig_cparm_name(0,0),name, Swig_clocal_deref(type, Swig_cparm_name(0,1)));
return Swig_temp_result(func); return Swig_temp_result(func);
} }
@ -796,7 +813,8 @@ Swig_cmemberset_wrapper(String_or_char *classname,
p = NewParm(lt,"value"); p = NewParm(lt,"value");
Setnext(l,p); Setnext(l,p);
Printf(w->def,"%s %s(%s) {", SwigType_str(lt,0), Wrapper_Getname(w), ParmList_str(l)); /* Printf(w->def,"%s %s(%s) {", SwigType_str(lt,0), Wrapper_Getname(w), ParmList_str(l)); */
Printf(w->def,"void %s(%s) {", Wrapper_Getname(w), ParmList_str(l));
if (!code) { if (!code) {
/* No code supplied. Write a function manually */ /* No code supplied. Write a function manually */
@ -806,7 +824,8 @@ Swig_cmemberset_wrapper(String_or_char *classname,
Printv(w->code, code, "\n", 0); Printv(w->code, code, "\n", 0);
} }
Printf(w->code,"}\n"); Printf(w->code,"}\n");
Wrapper_Settype(w,lt); /* Wrapper_Settype(w,lt); */
Wrapper_Settype(w,"void");
Wrapper_Setparms(w,l); Wrapper_Setparms(w,l);
Delete(l); Delete(l);
Delete(lt); Delete(lt);

View file

@ -294,7 +294,7 @@ Wrapper_Gettype(Wrapper *w) {
void void
Wrapper_Settype(Wrapper *w, SwigType *t) { Wrapper_Settype(Wrapper *w, SwigType *t) {
Delete(w->_type); Delete(w->_type);
w->_type = Copy(t); w->_type = NewString(t);
} }
/* ----------------------------------------------------------------------------- /* -----------------------------------------------------------------------------