diff --git a/Examples/test-suite/r/enum_thorough_runme.R b/Examples/test-suite/r/enum_thorough_runme.R index 608abc71a..a0f1270b7 100644 --- a/Examples/test-suite/r/enum_thorough_runme.R +++ b/Examples/test-suite/r/enum_thorough_runme.R @@ -51,9 +51,8 @@ unittest(v, s$speedTest3(v)) unittest(v, s$speedTest4(v)) unittest(v, s$speedTest5(v)) unittest(v, s$speedTest6(v)) -# Not handling enum references - probably needs a typemap -# unittest(v, s$speedTest7(v)) -# unittest(v, s$speedTest8(v)) +unittest(v, s$speedTest7(v)) +unittest(v, s$speedTest8(v)) ## speedTest methods not in the class @@ -62,7 +61,7 @@ unittest(v, speedTest2(v)) unittest(v, speedTest3(v)) unittest(v, speedTest4(v)) # enum reference -# unittest(v, speedTest5(v)) +unittest(v, speedTest5(v)) ## member access s <- SpeedClass() @@ -132,7 +131,7 @@ unittest(g, tt$scientistsTestG(g)) unittest(g, tt$scientistsTestH(g)) unittest(g, tt$scientistsTestI(g)) # enum reference -#unittest(g, tt$scientistsTestJ(g)) +unittest(g, tt$scientistsTestJ(g)) unittest(g, scientistsTest1(g)) @@ -143,7 +142,7 @@ unittest(g, scientistsTest5(g)) unittest(g, scientistsTest6(g)) unittest(g, scientistsTest7(g)) ## enum reference -## unittest(g, scientistsTest8(g)) +unittest(g, scientistsTest8(g)) tt <- TClassInt() b <- "bell" @@ -331,7 +330,7 @@ unittest(b, hairTest9(b)) unittest(b, hairTestA(b)) unittest(b, hairTestB(b)) ## enum reference -##unittest(b, hairTestC(b)) +unittest(b, hairTestC(b)) unittest(b, hairTestA1(b)) unittest(b, hairTestA2(b)) unittest(b, hairTestA3(b)) @@ -344,7 +343,7 @@ unittest(b, hairTestA9(b)) unittest(b, hairTestAA(b)) unittest(b, hairTestAB(b)) ## enum reference -## unittest(b, hairTestAC(b)) +unittest(b, hairTestAC(b)) unittest(b, hairTestB1(b)) unittest(b, hairTestB2(b)) @@ -358,7 +357,7 @@ unittest(b, hairTestB9(b)) unittest(b, hairTestBA(b)) unittest(b, hairTestBB(b)) ## enum reference -## unittest(b, hairTestBC(b)) +unittest(b, hairTestBC(b)) f <- FirStruct() b <- "blonde" diff --git a/Lib/r/r.swg b/Lib/r/r.swg index a9035331b..e6153892e 100644 --- a/Lib/r/r.swg +++ b/Lib/r/r.swg @@ -192,6 +192,11 @@ unsigned char *OUTPUT 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[] %{ if ($input) strcpy($1, $input); diff --git a/Lib/r/rtype.swg b/Lib/r/rtype.swg index c55c70377..bdc48c24e 100644 --- a/Lib/r/rtype.swg +++ b/Lib/r/rtype.swg @@ -16,6 +16,7 @@ %typemap("rtype") enum SWIGTYPE * "character"; %typemap("rtype") enum SWIGTYPE *const "character"; %typemap("rtype") enum SWIGTYPE & "character"; +%typemap("rtype") const enum SWIGTYPE & "character"; %typemap("rtype") enum SWIGTYPE && "character"; %typemap("rtype") SWIGTYPE * "$R_class"; %typemap("rtype") SWIGTYPE *const "$R_class"; @@ -86,9 +87,7 @@ %typemap(scoercein) enum SWIGTYPE %{ $input = enumToInteger($input, "$R_class"); %} %typemap(scoercein) enum SWIGTYPE & - %{ $input = enumToInteger($input, "$R_class"); %} -%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 *const @@ -138,7 +137,7 @@ string &, std::string & %{ $result = enumFromInteger($result, "$R_class"); %} %typemap(scoerceout) enum SWIGTYPE & - %{ $result = enumFromInteger($result, "$R_class"); %} + %{ $result = enumFromInteger($result, "$*R_class"); %} %typemap(scoerceout) enum SWIGTYPE && %{ $result = enumFromInteger($result, "$R_class"); %} diff --git a/Source/Modules/r.cxx b/Source/Modules/r.cxx index 5ae138f93..ff68b8cf4 100644 --- a/Source/Modules/r.cxx +++ b/Source/Modules/r.cxx @@ -74,61 +74,37 @@ static String * getRTypeName(SwigType *t, int *outCount = NULL) { static String *getRClassName(String *retType, int /*addRef*/ = 1, int upRef=0) { String *tmp = NewString(""); SwigType *resolved = SwigType_typedef_resolve_all(retType); - char *retName = Char(SwigType_manglestr(resolved)); if (upRef) { - Printf(tmp, "_p%s", retName); - } else{ - Insert(tmp, 0, retName); - } - - return tmp; -/* -#if 1 - List *l = SwigType_split(retType); - int n = Len(l); - if(!l || n == 0) { -#ifdef R_SWIG_VERBOSE - if (debugMode) - Printf(stdout, "SwigType_split return an empty list for %s\n", - retType); -#endif - 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 ++; + SwigType_add_pointer(resolved); + } + char *retName = Char(SwigType_manglestr(resolved)); Insert(tmp, 0, retName); -#endif - return tmp; -*/ +} +/* -------------------------------------------------------------- + * Tries to get the resolved name, with options of adding + * or removing a layer of references. Take care not + * to request both + * --------------------------------------------------------------*/ + +static String *getRClassName2(String *retType, int deRef=0, int upRef=0) { + SwigType *resolved = SwigType_typedef_resolve_all(retType); + 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); } /* -------------------------------------------------------------- @@ -257,10 +233,9 @@ static int addCopyParameter(SwigType *type) { } static void replaceRClass(String *tm, SwigType *type) { - String *tmp = getRClassName(type); - String *tmp_base = getRClassName(type, 0); - String *tmp_ref = getRClassName(type, 1, 1); - + String *tmp = getRClassName2(type, 0, 0); + String *tmp_base = getRClassName2(type, 1, 0); + String *tmp_ref = getRClassName2(type, 0, 1); Replaceall(tm, "$R_class", tmp); Replaceall(tm, "$*R_class", tmp_base); Replaceall(tm, "$&R_class", tmp_ref);