%extend for static member varibles work in progress ... static member variable and global variable wrapper names changed so that they don't clash with the user supplied %extend function name

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@9606 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
William S Fulton 2006-12-05 22:10:56 +00:00
commit c4761132ac
2 changed files with 53 additions and 43 deletions

View file

@ -2139,8 +2139,6 @@ public:
String *iname = Getattr(n, "sym:name"); String *iname = Getattr(n, "sym:name");
SwigType *t = Getattr(n, "type"); SwigType *t = Getattr(n, "type");
String *getnamef;
String *setnamef;
static int have_globals = 0; static int have_globals = 0;
String *tm; String *tm;
Wrapper *getf, *setf; Wrapper *getf, *setf;
@ -2169,12 +2167,14 @@ public:
} }
} }
getnamef = Swig_name_get(iname); String *getname = Swig_name_get(iname);
setnamef = Swig_name_set(iname); String *setname = Swig_name_set(iname);
String *vargetname = NewStringf("Swig_var_%s", getname);
String *varsetname = NewStringf("Swig_var_%s", setname);
/* Create a function for setting the value of the variable */ /* Create a function for setting the value of the variable */
if (assignable) { if (assignable) {
Printf(setf->def, "SWIGINTERN int %s(PyObject *_val) {", setnamef); Printf(setf->def, "SWIGINTERN int %s(PyObject *_val) {", varsetname);
if ((tm = Swig_typemap_lookup_new("varin", n, name, 0))) { if ((tm = Swig_typemap_lookup_new("varin", n, name, 0))) {
Replaceall(tm, "$source", "_val"); Replaceall(tm, "$source", "_val");
Replaceall(tm, "$target", name); Replaceall(tm, "$target", name);
@ -2193,9 +2193,9 @@ public:
} else { } else {
/* Is a readonly variable. Issue an error */ /* Is a readonly variable. Issue an error */
if (CPlusPlus) { if (CPlusPlus) {
Printf(setf->def, "SWIGINTERN int %s(PyObject *) {", setnamef); Printf(setf->def, "SWIGINTERN int %s(PyObject *) {", varsetname);
} else { } else {
Printf(setf->def, "SWIGINTERN int %s(PyObject *_val SWIGUNUSED) {", setnamef); Printf(setf->def, "SWIGINTERN int %s(PyObject *_val SWIGUNUSED) {", varsetname);
} }
Printv(setf->code, ctab4, "SWIG_Error(SWIG_AttributeError,\"Variable ", iname, " is read-only.\");\n", ctab4, "return 1;\n", NIL); Printv(setf->code, ctab4, "SWIG_Error(SWIG_AttributeError,\"Variable ", iname, " is read-only.\");\n", ctab4, "return 1;\n", NIL);
} }
@ -2205,7 +2205,7 @@ public:
/* Create a function for getting the value of a variable */ /* Create a function for getting the value of a variable */
int addfail = 0; int addfail = 0;
Printf(getf->def, "SWIGINTERN PyObject *%s(void) {", getnamef); Printf(getf->def, "SWIGINTERN PyObject *%s(void) {", vargetname);
Wrapper_add_local(getf, "pyobj", "PyObject *pyobj = 0"); Wrapper_add_local(getf, "pyobj", "PyObject *pyobj = 0");
if ((tm = Swig_typemap_lookup_new("varout", n, name, 0))) { if ((tm = Swig_typemap_lookup_new("varout", n, name, 0))) {
Replaceall(tm, "$source", name); Replaceall(tm, "$source", name);
@ -2226,10 +2226,12 @@ public:
Wrapper_print(getf, f_wrappers); Wrapper_print(getf, f_wrappers);
/* Now add this to the variable linking mechanism */ /* Now add this to the variable linking mechanism */
Printf(f_init, "\t SWIG_addvarlink(SWIG_globals(),(char*)\"%s\",%s, %s);\n", iname, getnamef, setnamef); Printf(f_init, "\t SWIG_addvarlink(SWIG_globals(),(char*)\"%s\",%s, %s);\n", iname, vargetname, varsetname);
Delete(getnamef); Delete(vargetname);
Delete(setnamef); Delete(varsetname);
Delete(getname);
Delete(setname);
DelWrapper(setf); DelWrapper(setf);
DelWrapper(getf); DelWrapper(getf);
return SWIG_OK; return SWIG_OK;
@ -3061,27 +3063,27 @@ public:
if (shadow) { if (shadow) {
String *mname = Swig_name_member(class_name, symname); String *mname = Swig_name_member(class_name, symname);
String *sname = Swig_name_set(mname); String *setname = Swig_name_set(mname);
String *gname = Swig_name_get(mname); String *getname = Swig_name_get(mname);
if (shadow) { if (shadow) {
int assignable = is_assignable(n); int assignable = is_assignable(n);
if (!modern) { if (!modern) {
if (assignable) { if (assignable) {
Printv(f_shadow, tab4, "__swig_setmethods__[\"", symname, "\"] = ", module, ".", sname, "\n", NIL); Printv(f_shadow, tab4, "__swig_setmethods__[\"", symname, "\"] = ", module, ".", setname, "\n", NIL);
} }
Printv(f_shadow, tab4, "__swig_getmethods__[\"", symname, "\"] = ", module, ".", gname, "\n", NIL); Printv(f_shadow, tab4, "__swig_getmethods__[\"", symname, "\"] = ", module, ".", getname, "\n", NIL);
} }
if (!classic) { if (!classic) {
if (!assignable) { if (!assignable) {
Printv(f_shadow, tab4, modern ? "" : "if _newclass:", symname, " = _swig_property(", module, ".", gname, ")\n", NIL); Printv(f_shadow, tab4, modern ? "" : "if _newclass:", symname, " = _swig_property(", module, ".", getname, ")\n", NIL);
} else { } else {
Printv(f_shadow, tab4, modern ? "" : "if _newclass:", symname, " = _swig_property(", module, ".", gname, ", ", module, ".", sname, ")\n", NIL); Printv(f_shadow, tab4, modern ? "" : "if _newclass:", symname, " = _swig_property(", module, ".", getname, ", ", module, ".", setname, ")\n", NIL);
} }
} }
} }
Delete(mname); Delete(mname);
Delete(sname); Delete(setname);
Delete(gname); Delete(getname);
} }
return SWIG_OK; return SWIG_OK;
@ -3102,50 +3104,54 @@ public:
Delete(mname); Delete(mname);
} else { } else {
String *mname = Swig_name_member(class_name, symname); String *mname = Swig_name_member(class_name, symname);
String *gname = Swig_name_get(mname); String *getname = Swig_name_get(mname);
String *wgname = Swig_name_wrapper(gname); String *wrapgetname = Swig_name_wrapper(getname);
String *sname = Swig_name_set(mname); String *vargetname = NewStringf("Swig_var_%s", getname);
String *wsname = Swig_name_wrapper(sname); String *setname = Swig_name_set(mname);
String *wrapsetname = Swig_name_wrapper(setname);
String *varsetname = NewStringf("Swig_var_%s", setname);
Wrapper *f = NewWrapper(); Wrapper *f = NewWrapper();
Printv(f->def, "SWIGINTERN PyObject *", wgname, "(PyObject *SWIGUNUSEDPARM(self), PyObject *SWIGUNUSEDPARM(args)) {", NIL); Printv(f->def, "SWIGINTERN PyObject *", wrapgetname, "(PyObject *SWIGUNUSEDPARM(self), PyObject *SWIGUNUSEDPARM(args)) {", NIL);
Printv(f->code, " return ", gname, "();\n", NIL); Printv(f->code, " return ", vargetname, "();\n", NIL);
Append(f->code, "}\n"); Append(f->code, "}\n");
add_method(gname, wgname, 0); add_method(getname, wrapgetname, 0);
Wrapper_print(f, f_wrappers); Wrapper_print(f, f_wrappers);
DelWrapper(f); DelWrapper(f);
int assignable = is_assignable(n); int assignable = is_assignable(n);
if (assignable) { if (assignable) {
Wrapper *f = NewWrapper(); Wrapper *f = NewWrapper();
Printv(f->def, "SWIGINTERN PyObject *", wsname, "(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {", NIL); Printv(f->def, "SWIGINTERN PyObject *", wrapsetname, "(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {", NIL);
Wrapper_add_local(f, "value", "PyObject *value"); Wrapper_add_local(f, "value", "PyObject *value");
Wrapper_add_local(f, "res", "int res"); Wrapper_add_local(f, "res", "int res");
Append(f->code, "if (!PyArg_ParseTuple(args,(char *)\"O:set\",&value)) return NULL;\n"); Append(f->code, "if (!PyArg_ParseTuple(args,(char *)\"O:set\",&value)) return NULL;\n");
Printv(f->code, "res = ", sname, "(value);\n", NIL); Printv(f->code, "res = ", varsetname, "(value);\n", NIL);
Append(f->code, "return !res ? SWIG_Py_Void() : NULL;\n"); Append(f->code, "return !res ? SWIG_Py_Void() : NULL;\n");
Append(f->code, "}\n"); Append(f->code, "}\n");
Wrapper_print(f, f_wrappers); Wrapper_print(f, f_wrappers);
add_method(sname, wsname, 0); add_method(setname, wrapsetname, 0);
DelWrapper(f); DelWrapper(f);
} }
if (!modern) { if (!modern) {
if (assignable) { if (assignable) {
Printv(f_shadow, tab4, "__swig_setmethods__[\"", symname, "\"] = ", module, ".", sname, "\n", NIL); Printv(f_shadow, tab4, "__swig_setmethods__[\"", symname, "\"] = ", module, ".", setname, "\n", NIL);
} }
Printv(f_shadow, tab4, "__swig_getmethods__[\"", symname, "\"] = ", module, ".", gname, "\n", NIL); Printv(f_shadow, tab4, "__swig_getmethods__[\"", symname, "\"] = ", module, ".", getname, "\n", NIL);
} }
if (!classic) { if (!classic) {
if (!assignable) { if (!assignable) {
Printv(f_shadow, tab4, modern ? "" : "if _newclass:", symname, " = _swig_property(", module, ".", gname, ")\n", NIL); Printv(f_shadow, tab4, modern ? "" : "if _newclass:", symname, " = _swig_property(", module, ".", getname, ")\n", NIL);
} else { } else {
Printv(f_shadow, tab4, modern ? "" : "if _newclass:", symname, " = _swig_property(", module, ".", gname, ", ", module, ".", sname, ")\n", NIL); Printv(f_shadow, tab4, modern ? "" : "if _newclass:", symname, " = _swig_property(", module, ".", getname, ", ", module, ".", setname, ")\n", NIL);
} }
} }
Delete(mname); Delete(mname);
Delete(gname); Delete(getname);
Delete(wgname); Delete(wrapgetname);
Delete(sname); Delete(vargetname);
Delete(wsname); Delete(setname);
Delete(wrapsetname);
Delete(varsetname);
} }
} }
return SWIG_OK; return SWIG_OK;

View file

@ -549,7 +549,7 @@ public:
SwigType *t = Getattr(n, "type"); SwigType *t = Getattr(n, "type");
String *setname = 0; String *setname = 0;
String *getname = 0; String *setfname = 0;
Wrapper *setf = 0, *getf = 0; Wrapper *setf = 0, *getf = 0;
int readonly = 0; int readonly = 0;
String *tm; String *tm;
@ -560,8 +560,9 @@ public:
/* Create a function for getting a variable */ /* Create a function for getting a variable */
int addfail = 0; int addfail = 0;
getf = NewWrapper(); getf = NewWrapper();
getname = Swig_name_get(iname); String *getname = Swig_name_get(iname);
Printv(getf->def, "SWIGINTERN const char *", getname, "(ClientData clientData SWIGUNUSED, Tcl_Interp *interp, char *name1, char *name2, int flags) {", NIL); String *getfname = Swig_name_wrapper(getname);
Printv(getf->def, "SWIGINTERN const char *", getfname, "(ClientData clientData SWIGUNUSED, Tcl_Interp *interp, char *name1, char *name2, int flags) {", NIL);
Wrapper_add_local(getf, "value", "Tcl_Obj *value = 0"); Wrapper_add_local(getf, "value", "Tcl_Obj *value = 0");
if ((tm = Swig_typemap_lookup_new("varout", n, name, 0))) { if ((tm = Swig_typemap_lookup_new("varout", n, name, 0))) {
Replaceall(tm, "$source", name); Replaceall(tm, "$source", name);
@ -591,7 +592,8 @@ public:
if (is_assignable(n)) { if (is_assignable(n)) {
setf = NewWrapper(); setf = NewWrapper();
setname = Swig_name_set(iname); setname = Swig_name_set(iname);
Printv(setf->def, "SWIGINTERN const char *", setname, setfname = Swig_name_wrapper(setname);
Printv(setf->def, "SWIGINTERN const char *", setfname,
"(ClientData clientData SWIGUNUSED, Tcl_Interp *interp, char *name1, char *name2 SWIGUNUSED, int flags) {", NIL); "(ClientData clientData SWIGUNUSED, Tcl_Interp *interp, char *name1, char *name2 SWIGUNUSED, int flags) {", NIL);
Wrapper_add_local(setf, "value", "Tcl_Obj *value = 0"); Wrapper_add_local(setf, "value", "Tcl_Obj *value = 0");
Wrapper_add_local(setf, "name1o", "Tcl_Obj *name1o = 0"); Wrapper_add_local(setf, "name1o", "Tcl_Obj *name1o = 0");
@ -622,7 +624,7 @@ public:
} }
Printv(var_tab, tab4, "{ SWIG_prefix \"", iname, "\", 0, (swig_variable_func) ", getname, ",", NIL); Printv(var_tab, tab4, "{ SWIG_prefix \"", iname, "\", 0, (swig_variable_func) ", getfname, ",", NIL);
if (readonly) { if (readonly) {
static int readonlywrap = 0; static int readonlywrap = 0;
if (!readonlywrap) { if (!readonlywrap) {
@ -636,8 +638,10 @@ public:
} }
Printf(var_tab, "(swig_variable_func) swig_readonly},\n"); Printf(var_tab, "(swig_variable_func) swig_readonly},\n");
} else { } else {
Printv(var_tab, "(swig_variable_func) ", setname, "},\n", NIL); Printv(var_tab, "(swig_variable_func) ", setfname, "},\n", NIL);
} }
Delete(getfname);
Delete(setfname);
Delete(setname); Delete(setname);
Delete(getname); Delete(getname);
return SWIG_OK; return SWIG_OK;