Java directors implementation contributed by Scott Michel.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@5076 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
a2734b3f71
commit
a562a53bcb
4 changed files with 75 additions and 22 deletions
|
|
@ -176,6 +176,10 @@
|
|||
#define WARN_JAVA_TYPEMAP_PTRCONSTMOD_UNDEF 816
|
||||
#define WARN_JAVA_TYPEMAP_JAVAOUT_UNDEF 817
|
||||
#define WARN_JAVA_TYPEMAP_JAVAIN_UNDEF 818
|
||||
#define WARN_JAVA_TYPEMAP_JNIDESC_UNDEF 819
|
||||
#define WARN_JAVA_TYPEMAP_DIRECTORIN_UNDEF 820
|
||||
#define WARN_JAVA_TYPEMAP_DIRECTOROUT_UNDEF 821
|
||||
#define WARN_JAVA_TYPEMAP_NODIRECTOR_CODE 822
|
||||
|
||||
/* please leave 810-829 free for Java */
|
||||
|
||||
|
|
|
|||
|
|
@ -37,6 +37,7 @@ Swig_cparm_name(Parm *p, int i) {
|
|||
if (p) {
|
||||
Setattr(p,"lname",name);
|
||||
}
|
||||
|
||||
return name;
|
||||
}
|
||||
|
||||
|
|
@ -341,7 +342,7 @@ Swig_cconstructor_call(String_or_char *name) {
|
|||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
String *
|
||||
Swig_cppconstructor_base_call(String_or_char *name, ParmList *parms, int skip_self, int disown) {
|
||||
Swig_cppconstructor_base_call(String_or_char *name, ParmList *parms, int skip_self) {
|
||||
String *func;
|
||||
String *nname;
|
||||
int i = 0;
|
||||
|
|
@ -360,17 +361,20 @@ Swig_cppconstructor_base_call(String_or_char *name, ParmList *parms, int skip_se
|
|||
pt = Getattr(p,"type");
|
||||
if ((SwigType_type(pt) != T_VOID)) {
|
||||
if (comma) Printf(func,",");
|
||||
pname = Swig_cparm_name(p,i);
|
||||
if (!Getattr(p, "arg:byname")) {
|
||||
pname = Swig_cparm_name(p,i);
|
||||
i++;
|
||||
} else {
|
||||
if ((pname = Getattr(p, "value")))
|
||||
pname = Copy(pname);
|
||||
else
|
||||
pname = Copy(Getattr(p, "name"));
|
||||
}
|
||||
Printf(func,"%s", SwigType_rcaststr(pt, pname));
|
||||
comma = 1;
|
||||
i++;
|
||||
}
|
||||
p = nextSibling(p);
|
||||
}
|
||||
if (disown >= 0) {
|
||||
if (comma) Printf(func, ",");
|
||||
Printf(func, "%d", disown);
|
||||
}
|
||||
Printf(func,")");
|
||||
Delete(nname);
|
||||
return func;
|
||||
|
|
@ -378,17 +382,17 @@ Swig_cppconstructor_base_call(String_or_char *name, ParmList *parms, int skip_se
|
|||
|
||||
String *
|
||||
Swig_cppconstructor_call(String_or_char *name, ParmList *parms) {
|
||||
return Swig_cppconstructor_base_call(name, parms, 0, -1);
|
||||
return Swig_cppconstructor_base_call(name, parms, 0);
|
||||
}
|
||||
|
||||
String *
|
||||
Swig_cppconstructor_nodirector_call(String_or_char *name, ParmList *parms) {
|
||||
return Swig_cppconstructor_base_call(name, parms, 1, -1);
|
||||
return Swig_cppconstructor_base_call(name, parms, 1);
|
||||
}
|
||||
|
||||
String *
|
||||
Swig_cppconstructor_director_call(String_or_char *name, ParmList *parms) {
|
||||
return Swig_cppconstructor_base_call(name, parms, 0, 0);
|
||||
return Swig_cppconstructor_base_call(name, parms, 0);
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
|
|
@ -595,9 +599,13 @@ Node *
|
|||
Swig_directormap(Node *module, String *type) {
|
||||
int is_void = !Cmp(type, "void");
|
||||
if (!is_void && module) {
|
||||
/* ?? follow the inheritance hierarchy? */
|
||||
|
||||
String* base = SwigType_base(type);
|
||||
|
||||
Node *directormap = Getattr(module, "wrap:directormap");
|
||||
if (directormap) return Getattr(directormap, base);
|
||||
if (directormap)
|
||||
return Getattr(directormap, base);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -611,9 +619,11 @@ Swig_directormap(Node *module, String *type) {
|
|||
|
||||
int
|
||||
Swig_ConstructorToFunction(Node *n, String *classname,
|
||||
String *none_comparison, int cplus, int flags)
|
||||
String *none_comparison, String *director_ctor, int cplus, int flags)
|
||||
{
|
||||
ParmList *parms;
|
||||
Parm *p;
|
||||
ParmList *directorparms;
|
||||
SwigType *type;
|
||||
String *membername;
|
||||
String *mangled;
|
||||
|
|
@ -627,6 +637,32 @@ Swig_ConstructorToFunction(Node *n, String *classname,
|
|||
mangled = Swig_name_mangle(membername);
|
||||
|
||||
parms = CopyParmList(nonvoid_parms(Getattr(n,"parms")));
|
||||
if ((p = Getattr(n,"director:prefix_args")) != NULL) {
|
||||
Parm *p2, *p3;
|
||||
|
||||
directorparms = CopyParmList(p);
|
||||
for (p = directorparms; nextSibling(p); p = nextSibling(p));
|
||||
for (p2 = parms; p2; p2 = nextSibling(p2)) {
|
||||
p3 = CopyParm(p2);
|
||||
set_nextSibling(p, p3);
|
||||
p = p3;
|
||||
}
|
||||
} else
|
||||
directorparms = parms;
|
||||
|
||||
if ((p = Getattr(n,"director:postfix_args")) != NULL) {
|
||||
Parm *p2, *p3, *p4;
|
||||
|
||||
if (directorparms == parms) /* no prefix args from above. */
|
||||
directorparms = CopyParmList(parms);
|
||||
|
||||
for (p2 = directorparms; nextSibling(p2); p2 = nextSibling(p2));
|
||||
for (p3 = p; p3; p3 = nextSibling(p)) {
|
||||
p4 = CopyParm(p3);
|
||||
set_nextSibling(p2, p4);
|
||||
p2 = p4;
|
||||
}
|
||||
}
|
||||
|
||||
type = NewString(classname);
|
||||
SwigType_add_pointer(type);
|
||||
|
|
@ -661,8 +697,9 @@ Swig_ConstructorToFunction(Node *n, String *classname,
|
|||
|
||||
Replaceall( tmp_none_comparison, "$arg", "arg1" );
|
||||
|
||||
director_call = Swig_cppconstructor_director_call(directorname, parms);
|
||||
director_call = Swig_cppconstructor_director_call(directorname, directorparms);
|
||||
nodirector_call = Swig_cppconstructor_nodirector_call(classname, parms);
|
||||
|
||||
if (abstract) {
|
||||
/* whether or not the abstract class has been subclassed in python,
|
||||
* create a director instance (there's no way to create a normal
|
||||
|
|
@ -672,15 +709,19 @@ Swig_ConstructorToFunction(Node *n, String *classname,
|
|||
*/
|
||||
Printv(action, Swig_cresult(type, "result", director_call), NULL);
|
||||
} else {
|
||||
/* if the proxy class has been subclassed, create a director instance.
|
||||
* otherwise, just create a normal instance.
|
||||
*/
|
||||
Printv(action,
|
||||
"if (",tmp_none_comparison,") {/* subclassed */\n",
|
||||
Swig_cresult(type, "result", director_call),
|
||||
"} else {\n",
|
||||
Swig_cresult(type, "result", nodirector_call),
|
||||
"}\n", NULL);
|
||||
/* (scottm): The code for creating a new director is now a string
|
||||
template that gets passed in via the director_ctor argument.
|
||||
|
||||
$comparison : an 'if' comparison from none_comparison
|
||||
$director_new: Call new for director class
|
||||
$nondirector_new: Call new for non-director class
|
||||
*/
|
||||
Printv(action, director_ctor, NIL);
|
||||
Replaceall( action, "$comparison", tmp_none_comparison);
|
||||
Replaceall( action, "$director_new",
|
||||
Swig_cresult(type, "result", director_call) );
|
||||
Replaceall( action, "$nondirector_new",
|
||||
Swig_cresult(type, "result", nodirector_call) );
|
||||
}
|
||||
Setattr(n, "wrap:action", action);
|
||||
Delete(tmp_none_comparison);
|
||||
|
|
@ -696,6 +737,8 @@ Swig_ConstructorToFunction(Node *n, String *classname,
|
|||
Setattr(n,"type",type);
|
||||
Setattr(n,"parms", parms);
|
||||
Delete(type);
|
||||
if (directorparms != parms)
|
||||
Delete(directorparms);
|
||||
Delete(parms);
|
||||
Delete(mangled);
|
||||
Delete(membername);
|
||||
|
|
|
|||
|
|
@ -47,6 +47,7 @@ Parm *CopyParm(Parm *p) {
|
|||
String *value;
|
||||
String *ignore;
|
||||
String *alttype;
|
||||
String *byname;
|
||||
|
||||
Parm *np = NewHash();
|
||||
t = Getattr(p,"type");
|
||||
|
|
@ -55,6 +56,7 @@ Parm *CopyParm(Parm *p) {
|
|||
value = Getattr(p,"value");
|
||||
ignore = Getattr(p,"ignore");
|
||||
alttype = Getattr(p,"alttype");
|
||||
byname = Getattr(p, "arg:byname");
|
||||
|
||||
if (t)
|
||||
Setattr(np,"type",Copy(t));
|
||||
|
|
@ -68,6 +70,8 @@ Parm *CopyParm(Parm *p) {
|
|||
Setattr(np,"ignore", Copy(ignore));
|
||||
if (alttype)
|
||||
Setattr(np,"alttype", Copy(alttype));
|
||||
if (byname)
|
||||
Setattr(np, "arg:byname", Copy(byname));
|
||||
|
||||
Setfile(np,Getfile(p));
|
||||
Setline(np,Getline(p));
|
||||
|
|
|
|||
|
|
@ -201,6 +201,7 @@ extern SwigType *SwigType_pop_arrays(SwigType *t);
|
|||
extern void SwigType_add_reference(SwigType *t);
|
||||
extern void SwigType_del_reference(SwigType *t);
|
||||
extern void SwigType_add_qualifier(SwigType *t, String_or_char *qual);
|
||||
extern void SwigType_del_qualifier(SwigType *t);
|
||||
extern void SwigType_add_function(SwigType *t, ParmList *parms);
|
||||
extern void SwigType_add_template(SwigType *t, ParmList *parms);
|
||||
extern SwigType *SwigType_pop_function(SwigType *t);
|
||||
|
|
@ -442,6 +443,7 @@ extern String *Swig_cmemberget_call(String_or_char *name, SwigType *t, String
|
|||
extern int Swig_MethodToFunction(Node *n, String *classname, int flags);
|
||||
extern int Swig_ConstructorToFunction(Node *n, String *classname,
|
||||
String *none_comparison,
|
||||
String *director_ctor,
|
||||
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);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue