Changes to support memberin typemap
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@813 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
1a1e64d919
commit
5821746d4d
6 changed files with 58 additions and 36 deletions
|
|
@ -181,6 +181,7 @@ public:
|
|||
char *name; // Name of the member
|
||||
char *iname; // Name of member in the interpreter
|
||||
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 line; // What line number was this member on
|
||||
char *file; // What file was this in?
|
||||
|
|
@ -205,7 +206,6 @@ public:
|
|||
SwigType *ret_type;
|
||||
ParmList *parms;
|
||||
int new_object;
|
||||
int is_virtual;
|
||||
|
||||
CPP_function(char *n, char *i, SwigType *t, ParmList *l, int s, int v = 0) {
|
||||
name = Swig_copy_string(n);
|
||||
|
|
@ -417,8 +417,10 @@ public:
|
|||
t = Copy(type);
|
||||
update_local_type(t);
|
||||
/* Check to see if it's read-only */
|
||||
if (SwigType_isarray(t) || SwigType_isconst(t))
|
||||
Status = Status | STAT_READONLY;
|
||||
if (SwigType_isarray(t) || SwigType_isconst(t)) {
|
||||
if (!(Swig_typemap_search("memberin",t,name)))
|
||||
Status = Status | STAT_READONLY;
|
||||
}
|
||||
|
||||
if (!is_static) {
|
||||
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.
|
||||
|
||||
if (Inherit_mode) {
|
||||
if (current_class->search_member(temp_iname)) {
|
||||
return;
|
||||
}
|
||||
CPP_member *m = current_class->search_member(temp_iname);
|
||||
if (m) return;
|
||||
}
|
||||
|
||||
// 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 (is_virtual)
|
||||
if (is_virtual == PURE_VIRTUAL)
|
||||
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)));
|
||||
|
||||
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();
|
||||
|
||||
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)) {
|
||||
prev_wrap = GetChar(member_hash,key);
|
||||
} else {
|
||||
|
|
@ -1963,7 +1969,14 @@ void cplus_emit_variable_set(char *classname, char *classtype, char *classrename
|
|||
if ((mode) && (ccode)) {
|
||||
Wrapper_print(w,f_wrappers);
|
||||
} else if (!mode) {
|
||||
emit_set_action(Swig_cmemberset_call(mname,type));
|
||||
/* 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));
|
||||
else
|
||||
emit_set_action(tm);
|
||||
Delete(target);
|
||||
}
|
||||
lang->create_function(Wrapper_Getname(w),iname, Wrapper_Gettype(w), Wrapper_Getparms(w));
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -88,7 +88,6 @@ void Language::cpp_close_class() {
|
|||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
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 *prefix;
|
||||
|
||||
|
|
@ -100,19 +99,6 @@ void Language::cpp_member_func(char *name, char *iname, SwigType *t, ParmList *l
|
|||
} else {
|
||||
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 */
|
||||
|
||||
if (iname) {
|
||||
|
|
@ -125,7 +111,7 @@ void Language::cpp_member_func(char *name, char *iname, SwigType *t, ParmList *l
|
|||
|
||||
if (add_symbol(new_name)) {
|
||||
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;
|
||||
}
|
||||
cplus_emit_member_func(ClassName, ClassType, ClassRename, name, iname, t, l, AddMethods);
|
||||
|
|
|
|||
|
|
@ -2333,7 +2333,7 @@ cpp_member : type declaration LPAREN parms RPAREN cpp_end {
|
|||
if ($3.is_reference) SwigType_add_reference($2);
|
||||
iname = make_name($3.id);
|
||||
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();
|
||||
Delete($2);
|
||||
|
|
|
|||
|
|
@ -33,6 +33,10 @@ extern "C" {
|
|||
extern FILE *swig_log;
|
||||
#endif
|
||||
|
||||
#define PLAIN_VIRTUAL 1
|
||||
#define PURE_VIRTUAL 2
|
||||
#define SUPER_VIRTUAL 3
|
||||
|
||||
extern FILE *f_runtime; // Runtime code
|
||||
extern DOH *f_header; // Headers
|
||||
extern DOH *f_wrappers; // Wrappers
|
||||
|
|
|
|||
|
|
@ -200,7 +200,15 @@ void Swig_cresult(Wrapper *w, SwigType *t, String_or_char *name, String_or_char
|
|||
}
|
||||
|
||||
/* 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) {
|
||||
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));
|
||||
break;
|
||||
default:
|
||||
Printf(fcall,";\n");
|
||||
/* A sick hack */
|
||||
{
|
||||
char *c = Char(decl) + Len(decl) - 1;
|
||||
if (!((*c == ';') || (*c == '}')))
|
||||
Printf(fcall, ";");
|
||||
}
|
||||
Printf(fcall,"\n");
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
@ -429,16 +443,19 @@ Swig_cppdestructor_call() {
|
|||
String *
|
||||
Swig_cmemberset_call(String_or_char *name, SwigType *type) {
|
||||
DOH *func;
|
||||
String *pname;
|
||||
func = NewString("");
|
||||
|
||||
/*
|
||||
if (SwigType_type(type) == T_USER) {
|
||||
Printf(func,"%s %s->%s; ", Swig_clocal_assign(type,""), Swig_cparm_name(0,0), name);
|
||||
} else {
|
||||
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->%s = %s",Swig_cparm_name(0,0),name, Swig_clocal_deref(type, Swig_cparm_name(0,1)));
|
||||
return Swig_temp_result(func);
|
||||
}
|
||||
|
||||
|
|
@ -796,7 +813,8 @@ Swig_cmemberset_wrapper(String_or_char *classname,
|
|||
p = NewParm(lt,"value");
|
||||
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) {
|
||||
/* No code supplied. Write a function manually */
|
||||
|
|
@ -806,7 +824,8 @@ Swig_cmemberset_wrapper(String_or_char *classname,
|
|||
Printv(w->code, code, "\n", 0);
|
||||
}
|
||||
Printf(w->code,"}\n");
|
||||
Wrapper_Settype(w,lt);
|
||||
/* Wrapper_Settype(w,lt); */
|
||||
Wrapper_Settype(w,"void");
|
||||
Wrapper_Setparms(w,l);
|
||||
Delete(l);
|
||||
Delete(lt);
|
||||
|
|
|
|||
|
|
@ -294,7 +294,7 @@ Wrapper_Gettype(Wrapper *w) {
|
|||
void
|
||||
Wrapper_Settype(Wrapper *w, SwigType *t) {
|
||||
Delete(w->_type);
|
||||
w->_type = Copy(t);
|
||||
w->_type = NewString(t);
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue