FIX: references to enums now functioning

There is some consolidation work to be done. The
core of the change is getRClassName2, which will
probably eventually replace getRClassName.

getRClassName seems to be in a funny state, with
a middle argument that is commented out and never
used.

My next step is to verify whether the new version
can replace it.
This commit is contained in:
Richard Beare 2019-03-06 20:57:04 +11:00
commit 43af20ab3b
4 changed files with 47 additions and 69 deletions

View file

@ -51,9 +51,8 @@ unittest(v, s$speedTest3(v))
unittest(v, s$speedTest4(v)) unittest(v, s$speedTest4(v))
unittest(v, s$speedTest5(v)) unittest(v, s$speedTest5(v))
unittest(v, s$speedTest6(v)) unittest(v, s$speedTest6(v))
# Not handling enum references - probably needs a typemap unittest(v, s$speedTest7(v))
# unittest(v, s$speedTest7(v)) unittest(v, s$speedTest8(v))
# unittest(v, s$speedTest8(v))
## speedTest methods not in the class ## speedTest methods not in the class
@ -62,7 +61,7 @@ unittest(v, speedTest2(v))
unittest(v, speedTest3(v)) unittest(v, speedTest3(v))
unittest(v, speedTest4(v)) unittest(v, speedTest4(v))
# enum reference # enum reference
# unittest(v, speedTest5(v)) unittest(v, speedTest5(v))
## member access ## member access
s <- SpeedClass() s <- SpeedClass()
@ -132,7 +131,7 @@ unittest(g, tt$scientistsTestG(g))
unittest(g, tt$scientistsTestH(g)) unittest(g, tt$scientistsTestH(g))
unittest(g, tt$scientistsTestI(g)) unittest(g, tt$scientistsTestI(g))
# enum reference # enum reference
#unittest(g, tt$scientistsTestJ(g)) unittest(g, tt$scientistsTestJ(g))
unittest(g, scientistsTest1(g)) unittest(g, scientistsTest1(g))
@ -143,7 +142,7 @@ unittest(g, scientistsTest5(g))
unittest(g, scientistsTest6(g)) unittest(g, scientistsTest6(g))
unittest(g, scientistsTest7(g)) unittest(g, scientistsTest7(g))
## enum reference ## enum reference
## unittest(g, scientistsTest8(g)) unittest(g, scientistsTest8(g))
tt <- TClassInt() tt <- TClassInt()
b <- "bell" b <- "bell"
@ -331,7 +330,7 @@ unittest(b, hairTest9(b))
unittest(b, hairTestA(b)) unittest(b, hairTestA(b))
unittest(b, hairTestB(b)) unittest(b, hairTestB(b))
## enum reference ## enum reference
##unittest(b, hairTestC(b)) unittest(b, hairTestC(b))
unittest(b, hairTestA1(b)) unittest(b, hairTestA1(b))
unittest(b, hairTestA2(b)) unittest(b, hairTestA2(b))
unittest(b, hairTestA3(b)) unittest(b, hairTestA3(b))
@ -344,7 +343,7 @@ unittest(b, hairTestA9(b))
unittest(b, hairTestAA(b)) unittest(b, hairTestAA(b))
unittest(b, hairTestAB(b)) unittest(b, hairTestAB(b))
## enum reference ## enum reference
## unittest(b, hairTestAC(b)) unittest(b, hairTestAC(b))
unittest(b, hairTestB1(b)) unittest(b, hairTestB1(b))
unittest(b, hairTestB2(b)) unittest(b, hairTestB2(b))
@ -358,7 +357,7 @@ unittest(b, hairTestB9(b))
unittest(b, hairTestBA(b)) unittest(b, hairTestBA(b))
unittest(b, hairTestBB(b)) unittest(b, hairTestBB(b))
## enum reference ## enum reference
## unittest(b, hairTestBC(b)) unittest(b, hairTestBC(b))
f <- FirStruct() f <- FirStruct()
b <- "blonde" b <- "blonde"

View file

@ -192,6 +192,11 @@ unsigned char *OUTPUT
free($1); free($1);
} }
%typemap(in) const enum SWIGTYPE & ($*1_ltype temp)
%{ temp = ($*1_ltype)INTEGER($input)[0];
$1 = &temp; %}
%typemap(out) const enum SWIGTYPE & %{ $result = Rf_ScalarInteger(*$1); %}
%typemap(memberin) char[] %{ %typemap(memberin) char[] %{
if ($input) strcpy($1, $input); if ($input) strcpy($1, $input);

View file

@ -16,6 +16,7 @@
%typemap("rtype") enum SWIGTYPE * "character"; %typemap("rtype") enum SWIGTYPE * "character";
%typemap("rtype") enum SWIGTYPE *const "character"; %typemap("rtype") enum SWIGTYPE *const "character";
%typemap("rtype") enum SWIGTYPE & "character"; %typemap("rtype") enum SWIGTYPE & "character";
%typemap("rtype") const enum SWIGTYPE & "character";
%typemap("rtype") enum SWIGTYPE && "character"; %typemap("rtype") enum SWIGTYPE && "character";
%typemap("rtype") SWIGTYPE * "$R_class"; %typemap("rtype") SWIGTYPE * "$R_class";
%typemap("rtype") SWIGTYPE *const "$R_class"; %typemap("rtype") SWIGTYPE *const "$R_class";
@ -86,9 +87,7 @@
%typemap(scoercein) enum SWIGTYPE %typemap(scoercein) enum SWIGTYPE
%{ $input = enumToInteger($input, "$R_class"); %} %{ $input = enumToInteger($input, "$R_class"); %}
%typemap(scoercein) enum SWIGTYPE & %typemap(scoercein) enum SWIGTYPE &
%{ $input = enumToInteger($input, "$R_class"); %} %{ $input = enumToInteger($input, "$*R_class"); %}
%typemap(scoercein) enum SWIGTYPE &&
%{ $input = enumToInteger($input, "$R_class"); %}
%typemap(scoercein) enum SWIGTYPE * %typemap(scoercein) enum SWIGTYPE *
%{ $input = enumToInteger($input, "$R_class"); %} %{ $input = enumToInteger($input, "$R_class"); %}
%typemap(scoercein) enum SWIGTYPE *const %typemap(scoercein) enum SWIGTYPE *const
@ -138,7 +137,7 @@ string &, std::string &
%{ $result = enumFromInteger($result, "$R_class"); %} %{ $result = enumFromInteger($result, "$R_class"); %}
%typemap(scoerceout) enum SWIGTYPE & %typemap(scoerceout) enum SWIGTYPE &
%{ $result = enumFromInteger($result, "$R_class"); %} %{ $result = enumFromInteger($result, "$*R_class"); %}
%typemap(scoerceout) enum SWIGTYPE && %typemap(scoerceout) enum SWIGTYPE &&
%{ $result = enumFromInteger($result, "$R_class"); %} %{ $result = enumFromInteger($result, "$R_class"); %}

View file

@ -74,61 +74,37 @@ static String * getRTypeName(SwigType *t, int *outCount = NULL) {
static String *getRClassName(String *retType, int /*addRef*/ = 1, int upRef=0) { static String *getRClassName(String *retType, int /*addRef*/ = 1, int upRef=0) {
String *tmp = NewString(""); String *tmp = NewString("");
SwigType *resolved = SwigType_typedef_resolve_all(retType); SwigType *resolved = SwigType_typedef_resolve_all(retType);
char *retName = Char(SwigType_manglestr(resolved));
if (upRef) { if (upRef) {
Printf(tmp, "_p%s", retName); SwigType_add_pointer(resolved);
} else{ }
char *retName = Char(SwigType_manglestr(resolved));
Insert(tmp, 0, retName); Insert(tmp, 0, retName);
}
return tmp; return tmp;
/* }
#if 1 /* --------------------------------------------------------------
List *l = SwigType_split(retType); * Tries to get the resolved name, with options of adding
int n = Len(l); * or removing a layer of references. Take care not
if(!l || n == 0) { * to request both
#ifdef R_SWIG_VERBOSE * --------------------------------------------------------------*/
if (debugMode)
Printf(stdout, "SwigType_split return an empty list for %s\n", static String *getRClassName2(String *retType, int deRef=0, int upRef=0) {
retType); SwigType *resolved = SwigType_typedef_resolve_all(retType);
#endif int ispointer = SwigType_ispointer(resolved);
int isreference = SwigType_isreference(resolved);
if (upRef) {
SwigType_add_pointer(resolved);
}
if (deRef) {
if (ispointer) {
SwigType_del_pointer(resolved);
}
if (isreference) {
SwigType_del_reference(resolved);
}
}
String *tmp = NewString("");
Insert(tmp, 0, Char(SwigType_manglestr(resolved)));
return(tmp); return(tmp);
}
String *el = Getitem(l, n-1);
char *ptr = Char(el);
if(strncmp(ptr, "struct ", 7) == 0)
ptr += 7;
Printf(tmp, "%s", ptr);
if(addRef) {
for(int i = 0; i < n; i++) {
if(Strcmp(Getitem(l, i), "p.") == 0 ||
Strncmp(Getitem(l, i), "a(", 2) == 0)
Printf(tmp, "Ref");
}
}
#else
char *retName = Char(SwigType_manglestr(retType));
if(!retName)
return(tmp);
if(addRef) {
while(retName && strlen(retName) > 1 && strncmp(retName, "_p", 2) == 0) {
retName += 2;
Printf(tmp, "Ref");
}
}
if(retName[0] == '_')
retName ++;
Insert(tmp, 0, retName);
#endif
return tmp;
*/
} }
/* -------------------------------------------------------------- /* --------------------------------------------------------------
@ -257,10 +233,9 @@ static int addCopyParameter(SwigType *type) {
} }
static void replaceRClass(String *tm, SwigType *type) { static void replaceRClass(String *tm, SwigType *type) {
String *tmp = getRClassName(type); String *tmp = getRClassName2(type, 0, 0);
String *tmp_base = getRClassName(type, 0); String *tmp_base = getRClassName2(type, 1, 0);
String *tmp_ref = getRClassName(type, 1, 1); String *tmp_ref = getRClassName2(type, 0, 1);
Replaceall(tm, "$R_class", tmp); Replaceall(tm, "$R_class", tmp);
Replaceall(tm, "$*R_class", tmp_base); Replaceall(tm, "$*R_class", tmp_base);
Replaceall(tm, "$&R_class", tmp_ref); Replaceall(tm, "$&R_class", tmp_ref);