implement the naturalvar feature for global vars in java and csharp
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@8577 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
ccee08ce43
commit
d9bd8fff41
4 changed files with 41 additions and 32 deletions
|
|
@ -698,7 +698,7 @@ class CSHARP : public Language {
|
||||||
Swig_save("functionWrapper",n,"wrap:action",NIL);
|
Swig_save("functionWrapper",n,"wrap:action",NIL);
|
||||||
|
|
||||||
// below based on Swig_VargetToFunction()
|
// below based on Swig_VargetToFunction()
|
||||||
SwigType *ty = Swig_wrapped_var_type(Getattr(n,"type"));
|
SwigType *ty = Swig_wrapped_var_type(Getattr(n,"type"), use_naturalvar_mode(n));
|
||||||
Setattr(n,"wrap:action", NewStringf("result = (%s) %s;\n", SwigType_lstr(ty,0), Getattr(n, "value")));
|
Setattr(n,"wrap:action", NewStringf("result = (%s) %s;\n", SwigType_lstr(ty,0), Getattr(n, "value")));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -932,7 +932,7 @@ class JAVA : public Language {
|
||||||
Swig_save("functionWrapper",n,"wrap:action",NIL);
|
Swig_save("functionWrapper",n,"wrap:action",NIL);
|
||||||
|
|
||||||
// below based on Swig_VargetToFunction()
|
// below based on Swig_VargetToFunction()
|
||||||
SwigType *ty = Swig_wrapped_var_type(Getattr(n,"type"));
|
SwigType *ty = Swig_wrapped_var_type(Getattr(n,"type"), use_naturalvar_mode(n));
|
||||||
Setattr(n,"wrap:action", NewStringf("result = (%s) %s;\n", SwigType_lstr(ty,0), Getattr(n, "value")));
|
Setattr(n,"wrap:action", NewStringf("result = (%s) %s;\n", SwigType_lstr(ty,0), Getattr(n, "value")));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -102,9 +102,8 @@ Swig_clocal(SwigType *t, const String_or_char *name, const String_or_char *value
|
||||||
* This function only converts user defined types to pointers.
|
* This function only converts user defined types to pointers.
|
||||||
* ----------------------------------------------------------------------------- */
|
* ----------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static int varcref = 0;
|
|
||||||
String *
|
String *
|
||||||
Swig_wrapped_var_type(SwigType *t) {
|
Swig_wrapped_var_type(SwigType *t, int varcref) {
|
||||||
SwigType *ty;
|
SwigType *ty;
|
||||||
|
|
||||||
if (!Strstr(t,"enum $unnamed")) {
|
if (!Strstr(t,"enum $unnamed")) {
|
||||||
|
|
@ -115,13 +114,22 @@ Swig_wrapped_var_type(SwigType *t) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (SwigType_isclass(t)) {
|
if (SwigType_isclass(t)) {
|
||||||
|
if (varcref) {
|
||||||
|
if (cparse_cplusplus) {
|
||||||
|
if (!SwigType_isconst(ty)) SwigType_add_qualifier(ty, "const");
|
||||||
|
SwigType_add_reference(ty);
|
||||||
|
} else {
|
||||||
|
return Copy(ty);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
SwigType_add_pointer(ty);
|
SwigType_add_pointer(ty);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return ty;
|
return ty;
|
||||||
}
|
}
|
||||||
|
|
||||||
String *
|
String *
|
||||||
Swig_wrapped_member_var_type(SwigType *t) {
|
Swig_wrapped_member_var_type(SwigType *t, int varcref) {
|
||||||
SwigType *ty;
|
SwigType *ty;
|
||||||
|
|
||||||
if (!Strstr(t,"enum $unnamed")) {
|
if (!Strstr(t,"enum $unnamed")) {
|
||||||
|
|
@ -147,7 +155,7 @@ Swig_wrapped_member_var_type(SwigType *t) {
|
||||||
|
|
||||||
|
|
||||||
static String *
|
static String *
|
||||||
Swig_wrapped_var_deref(SwigType *t, String_or_char *name) {
|
Swig_wrapped_var_deref(SwigType *t, String_or_char *name, int varcref) {
|
||||||
if (SwigType_isclass(t)) {
|
if (SwigType_isclass(t)) {
|
||||||
if (varcref) {
|
if (varcref) {
|
||||||
if (cparse_cplusplus) {
|
if (cparse_cplusplus) {
|
||||||
|
|
@ -164,7 +172,7 @@ Swig_wrapped_var_deref(SwigType *t, String_or_char *name) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static String *
|
static String *
|
||||||
Swig_wrapped_var_assign(SwigType *t, const String_or_char *name) {
|
Swig_wrapped_var_assign(SwigType *t, const String_or_char *name, int varcref) {
|
||||||
if (SwigType_isclass(t)) {
|
if (SwigType_isclass(t)) {
|
||||||
if (varcref) {
|
if (varcref) {
|
||||||
return NewStringf("%s",name);
|
return NewStringf("%s",name);
|
||||||
|
|
@ -683,7 +691,7 @@ Swig_cppdestructor_call(Node *n) {
|
||||||
* ----------------------------------------------------------------------------- */
|
* ----------------------------------------------------------------------------- */
|
||||||
|
|
||||||
String *
|
String *
|
||||||
Swig_cmemberset_call(String_or_char *name, SwigType *type, String_or_char *self) {
|
Swig_cmemberset_call(String_or_char *name, SwigType *type, String_or_char *self, int varcref) {
|
||||||
String *func;
|
String *func;
|
||||||
String *pname0 = Swig_cparm_name(0,0);
|
String *pname0 = Swig_cparm_name(0,0);
|
||||||
String *pname1 = Swig_cparm_name(0,1);
|
String *pname1 = Swig_cparm_name(0,1);
|
||||||
|
|
@ -693,7 +701,7 @@ Swig_cmemberset_call(String_or_char *name, SwigType *type, String_or_char *self)
|
||||||
Replaceall(self,"this",pname0);
|
Replaceall(self,"this",pname0);
|
||||||
if (SwigType_type(type) != T_ARRAY) {
|
if (SwigType_type(type) != T_ARRAY) {
|
||||||
if (!Strstr(type,"enum $unnamed")) {
|
if (!Strstr(type,"enum $unnamed")) {
|
||||||
String *dref = Swig_wrapped_var_deref(type, pname1);
|
String *dref = Swig_wrapped_var_deref(type, pname1, varcref);
|
||||||
Printf(func,"if (%s) %s%s = %s",pname0, self,name,dref);
|
Printf(func,"if (%s) %s%s = %s",pname0, self,name,dref);
|
||||||
Delete(dref);
|
Delete(dref);
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -719,7 +727,7 @@ Swig_cmemberset_call(String_or_char *name, SwigType *type, String_or_char *self)
|
||||||
|
|
||||||
String *
|
String *
|
||||||
Swig_cmemberget_call(const String_or_char *name, SwigType *t,
|
Swig_cmemberget_call(const String_or_char *name, SwigType *t,
|
||||||
String_or_char *self) {
|
String_or_char *self, int varcref) {
|
||||||
String *func;
|
String *func;
|
||||||
String *call;
|
String *call;
|
||||||
String *pname0 = Swig_cparm_name(0,0);
|
String *pname0 = Swig_cparm_name(0,0);
|
||||||
|
|
@ -727,7 +735,7 @@ Swig_cmemberget_call(const String_or_char *name, SwigType *t,
|
||||||
else self = NewString(self);
|
else self = NewString(self);
|
||||||
Replaceall(self,"this",pname0);
|
Replaceall(self,"this",pname0);
|
||||||
func = NewStringEmpty();
|
func = NewStringEmpty();
|
||||||
call = Swig_wrapped_var_assign(t,"");
|
call = Swig_wrapped_var_assign(t,"", varcref);
|
||||||
Printf(func,"%s (%s%s)", call,self, name);
|
Printf(func,"%s (%s%s)", call,self, name);
|
||||||
Delete(self);
|
Delete(self);
|
||||||
Delete(call);
|
Delete(call);
|
||||||
|
|
@ -1213,7 +1221,7 @@ Swig_MembersetToFunction(Node *n, String *classname, int flags) {
|
||||||
String *self= 0;
|
String *self= 0;
|
||||||
String *sname;
|
String *sname;
|
||||||
|
|
||||||
varcref = flags & CWRAP_NATURAL_VAR;
|
int varcref = flags & CWRAP_NATURAL_VAR;
|
||||||
|
|
||||||
if (flags & CWRAP_SMART_POINTER) {
|
if (flags & CWRAP_SMART_POINTER) {
|
||||||
self = NewString("(*this)->");
|
self = NewString("(*this)->");
|
||||||
|
|
@ -1233,7 +1241,7 @@ Swig_MembersetToFunction(Node *n, String *classname, int flags) {
|
||||||
Setattr(parms,k_hidden,"1");
|
Setattr(parms,k_hidden,"1");
|
||||||
Delete(t);
|
Delete(t);
|
||||||
|
|
||||||
ty = Swig_wrapped_member_var_type(type);
|
ty = Swig_wrapped_member_var_type(type, varcref);
|
||||||
p = NewParm(ty,name);
|
p = NewParm(ty,name);
|
||||||
Setattr(parms,k_hidden,"1");
|
Setattr(parms,k_hidden,"1");
|
||||||
set_nextSibling(parms,p);
|
set_nextSibling(parms,p);
|
||||||
|
|
@ -1257,7 +1265,7 @@ Swig_MembersetToFunction(Node *n, String *classname, int flags) {
|
||||||
Delete(call);
|
Delete(call);
|
||||||
Delete(cres);
|
Delete(cres);
|
||||||
} else {
|
} else {
|
||||||
String *call = Swig_cmemberset_call(name,type,self);
|
String *call = Swig_cmemberset_call(name,type,self, varcref);
|
||||||
String *cres = NewStringf("%s;\n", call);
|
String *cres = NewStringf("%s;\n", call);
|
||||||
Setattr(n,k_wrapaction, cres);
|
Setattr(n,k_wrapaction, cres);
|
||||||
Delete(call);
|
Delete(call);
|
||||||
|
|
@ -1272,7 +1280,6 @@ Swig_MembersetToFunction(Node *n, String *classname, int flags) {
|
||||||
Delete(sname);
|
Delete(sname);
|
||||||
Delete(mangled);
|
Delete(mangled);
|
||||||
Delete(self);
|
Delete(self);
|
||||||
varcref = 0;
|
|
||||||
return SWIG_OK;
|
return SWIG_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1294,7 +1301,7 @@ Swig_MembergetToFunction(Node *n, String *classname, int flags) {
|
||||||
String *self = 0;
|
String *self = 0;
|
||||||
String *gname;
|
String *gname;
|
||||||
|
|
||||||
varcref = flags & CWRAP_NATURAL_VAR;
|
int varcref = flags & CWRAP_NATURAL_VAR;
|
||||||
|
|
||||||
if (flags & CWRAP_SMART_POINTER) {
|
if (flags & CWRAP_SMART_POINTER) {
|
||||||
if (checkAttribute(n, k_storage, k_static)) {
|
if (checkAttribute(n, k_storage, k_static)) {
|
||||||
|
|
@ -1320,7 +1327,7 @@ Swig_MembergetToFunction(Node *n, String *classname, int flags) {
|
||||||
Setattr(parms,k_hidden,"1");
|
Setattr(parms,k_hidden,"1");
|
||||||
Delete(t);
|
Delete(t);
|
||||||
|
|
||||||
ty = Swig_wrapped_member_var_type(type);
|
ty = Swig_wrapped_member_var_type(type, varcref);
|
||||||
if (flags & CWRAP_EXTEND) {
|
if (flags & CWRAP_EXTEND) {
|
||||||
String *call;
|
String *call;
|
||||||
String *cres;
|
String *cres;
|
||||||
|
|
@ -1335,7 +1342,7 @@ Swig_MembergetToFunction(Node *n, String *classname, int flags) {
|
||||||
Delete(cres);
|
Delete(cres);
|
||||||
Delete(call);
|
Delete(call);
|
||||||
} else {
|
} else {
|
||||||
String *call = Swig_cmemberget_call(name,type,self);
|
String *call = Swig_cmemberget_call(name,type,self, varcref);
|
||||||
String *cres = Swig_cresult(ty,k_result,call);
|
String *cres = Swig_cresult(ty,k_result,call);
|
||||||
Setattr(n,k_wrapaction, cres);
|
Setattr(n,k_wrapaction, cres);
|
||||||
Delete(call);
|
Delete(call);
|
||||||
|
|
@ -1349,8 +1356,6 @@ Swig_MembergetToFunction(Node *n, String *classname, int flags) {
|
||||||
Delete(gname);
|
Delete(gname);
|
||||||
Delete(mangled);
|
Delete(mangled);
|
||||||
|
|
||||||
varcref = 0;
|
|
||||||
|
|
||||||
return SWIG_OK;
|
return SWIG_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1361,23 +1366,25 @@ Swig_MembergetToFunction(Node *n, String *classname, int flags) {
|
||||||
* ----------------------------------------------------------------------------- */
|
* ----------------------------------------------------------------------------- */
|
||||||
|
|
||||||
int
|
int
|
||||||
Swig_VarsetToFunction(Node *n) {
|
Swig_VarsetToFunction(Node *n, int flags) {
|
||||||
String *name,*nname;
|
String *name,*nname;
|
||||||
ParmList *parms;
|
ParmList *parms;
|
||||||
SwigType *type, *ty;
|
SwigType *type, *ty;
|
||||||
|
|
||||||
|
int varcref = flags & CWRAP_NATURAL_VAR;
|
||||||
|
|
||||||
name = Getattr(n,k_name);
|
name = Getattr(n,k_name);
|
||||||
type = Getattr(n,k_type);
|
type = Getattr(n,k_type);
|
||||||
|
|
||||||
nname = SwigType_namestr(name);
|
nname = SwigType_namestr(name);
|
||||||
|
|
||||||
ty = Swig_wrapped_var_type(type);
|
ty = Swig_wrapped_var_type(type, varcref);
|
||||||
parms = NewParm(ty,name);
|
parms = NewParm(ty,name);
|
||||||
Delete(ty);
|
Delete(ty);
|
||||||
|
|
||||||
if (!Strstr(type,"enum $unnamed")) {
|
if (!Strstr(type,"enum $unnamed")) {
|
||||||
String *pname = Swig_cparm_name(0,0);
|
String *pname = Swig_cparm_name(0,0);
|
||||||
String *dref = Swig_wrapped_var_deref(type,pname);
|
String *dref = Swig_wrapped_var_deref(type,pname, varcref);
|
||||||
String *call = NewStringf("%s = %s;\n", nname, dref);
|
String *call = NewStringf("%s = %s;\n", nname, dref);
|
||||||
Setattr(n,k_wrapaction, call);
|
Setattr(n,k_wrapaction, call);
|
||||||
Delete(call);
|
Delete(call);
|
||||||
|
|
@ -1403,17 +1410,19 @@ Swig_VarsetToFunction(Node *n) {
|
||||||
* ----------------------------------------------------------------------------- */
|
* ----------------------------------------------------------------------------- */
|
||||||
|
|
||||||
int
|
int
|
||||||
Swig_VargetToFunction(Node *n) {
|
Swig_VargetToFunction(Node *n, int flags) {
|
||||||
String *cres, *call;
|
String *cres, *call;
|
||||||
String *name, *nname;
|
String *name, *nname;
|
||||||
SwigType *type, *ty;
|
SwigType *type, *ty;
|
||||||
|
|
||||||
|
int varcref = flags & CWRAP_NATURAL_VAR;
|
||||||
|
|
||||||
name = Getattr(n,k_name);
|
name = Getattr(n,k_name);
|
||||||
type = Getattr(n,k_type);
|
type = Getattr(n,k_type);
|
||||||
|
|
||||||
nname = SwigType_namestr(name);
|
nname = SwigType_namestr(name);
|
||||||
ty = Swig_wrapped_var_type(type);
|
ty = Swig_wrapped_var_type(type, varcref);
|
||||||
call = Swig_wrapped_var_assign(type,nname);
|
call = Swig_wrapped_var_assign(type,nname, varcref);
|
||||||
cres = Swig_cresult(ty,k_result,call);
|
cres = Swig_cresult(ty,k_result,call);
|
||||||
Setattr(n,k_wrapaction, cres);
|
Setattr(n,k_wrapaction, cres);
|
||||||
Delete(cres);
|
Delete(cres);
|
||||||
|
|
|
||||||
|
|
@ -480,7 +480,7 @@ extern void Swig_error_msg_format(ErrorMessageFormat format);
|
||||||
|
|
||||||
/* --- C Wrappers --- */
|
/* --- C Wrappers --- */
|
||||||
extern String *Swig_cparm_name(Parm *p, int i);
|
extern String *Swig_cparm_name(Parm *p, int i);
|
||||||
extern String *Swig_wrapped_var_type(SwigType *t);
|
extern String *Swig_wrapped_var_type(SwigType *t, int varcref);
|
||||||
extern int Swig_cargs(Wrapper *w, ParmList *l);
|
extern int Swig_cargs(Wrapper *w, ParmList *l);
|
||||||
extern String *Swig_cresult(SwigType *t, const String_or_char *name, const String_or_char *decl);
|
extern String *Swig_cresult(SwigType *t, const String_or_char *name, const String_or_char *decl);
|
||||||
|
|
||||||
|
|
@ -492,8 +492,8 @@ extern String *Swig_unref_call(Node *n);
|
||||||
extern String *Swig_ref_call(Node *n, const String* lname);
|
extern String *Swig_ref_call(Node *n, const String* lname);
|
||||||
extern String *Swig_cdestructor_call(Node *n);
|
extern String *Swig_cdestructor_call(Node *n);
|
||||||
extern String *Swig_cppdestructor_call(Node *n);
|
extern String *Swig_cppdestructor_call(Node *n);
|
||||||
extern String *Swig_cmemberset_call(String_or_char *name, SwigType *type, String_or_char *self);
|
extern String *Swig_cmemberset_call(String_or_char *name, SwigType *type, String_or_char *self, int varcref);
|
||||||
extern String *Swig_cmemberget_call(const String_or_char *name, SwigType *t, String_or_char *self);
|
extern String *Swig_cmemberget_call(const String_or_char *name, SwigType *t, String_or_char *self, int varcref);
|
||||||
|
|
||||||
extern String *Swig_extension_code(const String *function_name,
|
extern String *Swig_extension_code(const String *function_name,
|
||||||
ParmList *parms, SwigType* return_type, const String *code, int cplusplus);
|
ParmList *parms, SwigType* return_type, const String *code, int cplusplus);
|
||||||
|
|
@ -509,8 +509,8 @@ extern int Swig_ConstructorToFunction(Node *n, String *classname,
|
||||||
extern int Swig_DestructorToFunction(Node *n, String *classname, int cplus, int flags);
|
extern int Swig_DestructorToFunction(Node *n, String *classname, int cplus, int flags);
|
||||||
extern int Swig_MembersetToFunction(Node *n, String *classname, int flags);
|
extern int Swig_MembersetToFunction(Node *n, String *classname, int flags);
|
||||||
extern int Swig_MembergetToFunction(Node *n, String *classname, int flags);
|
extern int Swig_MembergetToFunction(Node *n, String *classname, int flags);
|
||||||
extern int Swig_VargetToFunction(Node *n);
|
extern int Swig_VargetToFunction(Node *n, int flags);
|
||||||
extern int Swig_VarsetToFunction(Node *n);
|
extern int Swig_VarsetToFunction(Node *n, int flags);
|
||||||
|
|
||||||
#define CWRAP_EXTEND 0x01
|
#define CWRAP_EXTEND 0x01
|
||||||
#define CWRAP_SMART_POINTER 0x02
|
#define CWRAP_SMART_POINTER 0x02
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue