From 5fcb1c138b5b1e13807359c0afc517261854bf35 Mon Sep 17 00:00:00 2001 From: Richard Beare Date: Thu, 10 May 2018 13:31:16 +1000 Subject: [PATCH 01/11] trial changing member list processing --- Source/Modules/r.cxx | 85 ++++++++++++++++++++++++++++++++++++-------- 1 file changed, 70 insertions(+), 15 deletions(-) diff --git a/Source/Modules/r.cxx b/Source/Modules/r.cxx index bb43dad48..0181e8bce 100644 --- a/Source/Modules/r.cxx +++ b/Source/Modules/r.cxx @@ -15,6 +15,10 @@ #include "swigmod.h" #include "cparse.h" +#define R_MEMBER_NORMAL 0 +#define R_MEMBER_SET 1 +#define R_MEMBER_GET 2 + static String* replaceInitialDash(const String *name) { String *retval; @@ -369,9 +373,15 @@ protected: int processing_class_member_function; - List *class_member_functions; - List *class_member_set_functions; - + // List *class_member_functions; + // List *class_member_set_functions; + // Spread out the lists so that they are simpler to process + // by storing the type of the method (i.e. set, get or nothing) + // and having separate lists for name, membername and wrapper + List *class_member_function_types; + List *class_member_function_names; + List *class_member_function_membernames; + List *class_member_function_wrappernames; /* */ Hash *ClassMemberTable; Hash *ClassMethodsTable; @@ -430,8 +440,12 @@ R::R() : member_name(0), class_name(0), processing_class_member_function(0), - class_member_functions(0), - class_member_set_functions(0), + // class_member_functions(0), + // class_member_set_functions(0), + class_member_function_types(0), + class_member_function_names(0), + class_member_function_wrappernames(0), + class_member_function_membernames(0), ClassMemberTable(0), ClassMethodsTable(0), SClassDefs(0), @@ -988,6 +1002,7 @@ int R::OutputClassMemberTable(Hash *tb, File *out) { return n; } + /* -------------------------------------------------------------- * Write the methods for $ or $<- for accessing a member field in an * struct or union (or class). @@ -1060,6 +1075,7 @@ int R::OutputMemberReferenceMethod(String *className, int isSet, char *ptr = Char(dup); ptr = &ptr[Len(dup) - 3]; + // Check the type here instead of the name if (!strcmp(ptr, "get")) { Printf(f->code, "%s'%s'", first ? "" : ", ", item); first = 0; @@ -1336,6 +1352,7 @@ int R::variableWrapper(Node *n) { void R::addAccessor(String *memberName, Wrapper *wrapper, String *name, int isSet) { +#if 0 if(isSet < 0) { int n = Len(name); char *ptr = Char(name); @@ -1343,7 +1360,7 @@ void R::addAccessor(String *memberName, Wrapper *wrapper, String *name, isSet = Strcmp(NewString(&ptr[n-4]), "_set") == 0; } } - +/// RJB List *l = isSet ? class_member_set_functions : class_member_functions; if(!l) { @@ -1360,6 +1377,20 @@ void R::addAccessor(String *memberName, Wrapper *wrapper, String *name, String *tmp = NewString(""); Wrapper_print(wrapper, tmp); Append(l, tmp); +#endif + if (!class_member_function_names) { + class_member_function_names = NewList(); + class_member_function_membernames = NewList(); + class_member_function_wrappernames = NewList(); + class_member_function_types = NewList(); + } + Append(class_member_function_types, isSet); + Append(class_member_function_names, name); + Append(class_member_function_membernames, memberName); + + String *tmp = NewString(""); + Wrapper_print(wrapper, tmp); + Append(class_member_function_wrappernames, tmp); // if we could put the wrapper in directly: Append(l, Copy(sfun)); if (debugMode) Printf(stdout, "Adding accessor: %s (%s) => %s\n", memberName, name, tmp); @@ -2261,7 +2292,13 @@ int R::functionWrapper(Node *n) { Would like to be able to do this so that we can potentially insert */ if(processing_member_access_function || processing_class_member_function) { - addAccessor(member_name, sfun, iname); + int method_type(R_MEMBER_NORMAL); + if (GetFlag("memberset", n)) { + method_type = R_MEMBER_SET; + } else if (GetFlag("memberget", n)) { + method_type = R_MEMBER_GET; + } + addAccessor(member_name, sfun, iname, method_type); } if (Getattr(n, "sym:overloaded") && @@ -2456,19 +2493,37 @@ int R::classDeclaration(Node *n) { // OutputArrayMethod(name, class_member_functions, sfile); +#if 0 + // RJB - this bit will need to change if (class_member_functions) OutputMemberReferenceMethod(name, 0, class_member_functions, sfile); if (class_member_set_functions) OutputMemberReferenceMethod(name, 1, class_member_set_functions, sfile); +#else + // filter the class_member_lists by type, then call + // OutputMemberReferenceMethod + +#endif + + // if(class_member_functions) { + // Delete(class_member_functions); + // class_member_functions = NULL; + // } + // if(class_member_set_functions) { + // Delete(class_member_set_functions); + // class_member_set_functions = NULL; + // } - if(class_member_functions) { - Delete(class_member_functions); - class_member_functions = NULL; - } - if(class_member_set_functions) { - Delete(class_member_set_functions); - class_member_set_functions = NULL; - } + if (class_member_function_types) { + Delete(class_member_function_types); + class_member_function_types = NULL; + Delete(class_member_function_names); + class_member_function_names = NULL; + Delete(class_member_function_membernames); + class_member_function_membernames = NULL; + Delete(class_member_function_wrappernames); + class_member_function_wrappernames = NULL; + } if (Getattr(n, "has_destructor")) { Printf(sfile, "setMethod('delete', '_p%s', function(obj) {delete%s(obj)})\n", getRClassName(name), getRClassName(name)); From c42fb730f4ff0a58a7ece60b5a6be9ba9b27fb50 Mon Sep 17 00:00:00 2001 From: Richard Beare Date: Thu, 10 May 2018 19:13:39 +1000 Subject: [PATCH 02/11] first pass at removing string comparisons for set/get methods --- Source/Modules/r.cxx | 93 +++++++++++++++++++++++++++----------------- 1 file changed, 57 insertions(+), 36 deletions(-) diff --git a/Source/Modules/r.cxx b/Source/Modules/r.cxx index 0181e8bce..5668abfc4 100644 --- a/Source/Modules/r.cxx +++ b/Source/Modules/r.cxx @@ -15,10 +15,6 @@ #include "swigmod.h" #include "cparse.h" -#define R_MEMBER_NORMAL 0 -#define R_MEMBER_SET 1 -#define R_MEMBER_GET 2 - static String* replaceInitialDash(const String *name) { String *retval; @@ -289,7 +285,10 @@ protected: int generateCopyRoutines(Node *n); int DumpCode(Node *n); - int OutputMemberReferenceMethod(String *className, int isSet, List *el, File *out); + //int OutputMemberReferenceMethod(String *className, int isSet, List *el, File *out); + int OutputMemberReferenceMethod(String *className, int isSet, + List *memberList, List *nameList, + List *typeList, File *out); int OutputArrayMethod(String *className, List *el, File *out); int OutputClassMemberTable(Hash *tb, File *out); int OutputClassMethodsTable(File *out); @@ -338,7 +337,7 @@ protected: void addAccessor(String *memberName, Wrapper *f, - String *name, int isSet = -1); + String *name, String *methodSetGet); static int getFunctionPointerNumArgs(Node *n, SwigType *tt); @@ -371,6 +370,9 @@ protected: String *member_name; String *class_name; + String *R_MEMBER_NORMAL; + String *R_MEMBER_SET; + String *R_MEMBER_GET; int processing_class_member_function; // List *class_member_functions; @@ -439,13 +441,16 @@ R::R() : processing_member_access_function(0), member_name(0), class_name(0), + R_MEMBER_NORMAL(NewString("normal")), + R_MEMBER_SET(NewString("set")), + R_MEMBER_GET(NewString("get")), processing_class_member_function(0), // class_member_functions(0), // class_member_set_functions(0), class_member_function_types(0), class_member_function_names(0), - class_member_function_wrappernames(0), class_member_function_membernames(0), + class_member_function_wrappernames(0), ClassMemberTable(0), ClassMethodsTable(0), SClassDefs(0), @@ -990,7 +995,7 @@ int R::OutputClassMemberTable(Hash *tb, File *out) { } // OutputArrayMethod(className, el, out); - OutputMemberReferenceMethod(className, isSet, el, out); + //OutputMemberReferenceMethod(className, isSet, el, out); if(outputNamespaceInfo) Printf(s_namespace, "\"%s\"%s", className, i < n-1 ? "," : ""); @@ -1002,7 +1007,6 @@ int R::OutputClassMemberTable(Hash *tb, File *out) { return n; } - /* -------------------------------------------------------------- * Write the methods for $ or $<- for accessing a member field in an * struct or union (or class). @@ -1015,9 +1019,10 @@ int R::OutputClassMemberTable(Hash *tb, File *out) { * out - the stream where we write the code. * --------------------------------------------------------------*/ -int R::OutputMemberReferenceMethod(String *className, int isSet, - List *el, File *out) { - int numMems = Len(el), j; +int R::OutputMemberReferenceMethod(String *className, int isSet, + List *memberList, List *nameList, + List *typeList, File *out) { + int numMems = Len(memberList), j; int varaccessor = 0; if (numMems == 0) return SWIG_OK; @@ -1032,13 +1037,20 @@ int R::OutputMemberReferenceMethod(String *className, int isSet, Node *itemList = NewHash(); bool has_prev = false; - for(j = 0; j < numMems; j+=3) { - String *item = Getitem(el, j); - String *dup = Getitem(el, j + 1); - char *ptr = Char(dup); - ptr = &ptr[Len(dup) - 3]; + for(j = 0; j < numMems; j++) { + String *item = Getitem(memberList, j); + String *dup = Getitem(nameList, j); + String *setgetmethod = Getitem(typeList, j); - if (!strcmp(ptr, "get")) + // skip this one if it isn't a set method but we're + // creating a modification method + if (isSet && (setgetmethod != R_MEMBER_SET)) + continue; + // skip the set methods when creating accessor methods + if ((!isSet) && (setgetmethod == R_MEMBER_SET)) + continue; + + if ((!isSet) && (setgetmethod == R_MEMBER_GET)) varaccessor++; if (Getattr(itemList, item)) @@ -1068,17 +1080,15 @@ int R::OutputMemberReferenceMethod(String *className, int isSet, if (!isSet && varaccessor > 0) { Printf(f->code, "%svaccessors = c(", tab8); - int first = 1; - for(j = 0; j < numMems; j+=3) { - String *item = Getitem(el, j); - String *dup = Getitem(el, j + 1); - char *ptr = Char(dup); - ptr = &ptr[Len(dup) - 3]; + bool first = true; + for(j = 0; j < numMems; j++) { + String *item = Getitem(memberList, j); + String *setgetmethod = Getitem(typeList, j); // Check the type here instead of the name - if (!strcmp(ptr, "get")) { + if (setgetmethod == R_MEMBER_GET) { Printf(f->code, "%s'%s'", first ? "" : ", ", item); - first = 0; + first = false; } } Printf(f->code, ");\n"); @@ -1351,7 +1361,7 @@ int R::variableWrapper(Node *n) { * --------------------------------------------------------------*/ void R::addAccessor(String *memberName, Wrapper *wrapper, String *name, - int isSet) { + String *methodSetGet) { #if 0 if(isSet < 0) { int n = Len(name); @@ -1384,7 +1394,7 @@ void R::addAccessor(String *memberName, Wrapper *wrapper, String *name, class_member_function_wrappernames = NewList(); class_member_function_types = NewList(); } - Append(class_member_function_types, isSet); + Append(class_member_function_types, methodSetGet); Append(class_member_function_names, name); Append(class_member_function_membernames, memberName); @@ -1846,10 +1856,10 @@ int R::functionWrapper(Node *n) { /* Add the name of this member to a list for this class_name. We will dump all these at the end. */ - int n = Len(iname); + int nlen = Len(iname); char *ptr = Char(iname); bool isSet(0); - if (n > 4) isSet = Strcmp(NewString(&ptr[n-4]), "_set") == 0; + if (nlen > 4) isSet = Strcmp(NewString(&ptr[nlen-4]), "_set") == 0; String *tmp = NewString(""); @@ -2292,10 +2302,10 @@ int R::functionWrapper(Node *n) { Would like to be able to do this so that we can potentially insert */ if(processing_member_access_function || processing_class_member_function) { - int method_type(R_MEMBER_NORMAL); - if (GetFlag("memberset", n)) { + String *method_type = R_MEMBER_NORMAL; + if (GetFlag(n, "memberset")) { method_type = R_MEMBER_SET; - } else if (GetFlag("memberget", n)) { + } else if (GetFlag(n, "memberget")) { method_type = R_MEMBER_GET; } addAccessor(member_name, sfun, iname, method_type); @@ -2500,9 +2510,20 @@ int R::classDeclaration(Node *n) { if (class_member_set_functions) OutputMemberReferenceMethod(name, 1, class_member_set_functions, sfile); #else - // filter the class_member_lists by type, then call - // OutputMemberReferenceMethod - + if (class_member_function_types) { + // count the number of set methods + unsigned setcount = 0; + Iterator ItType; + for (ItType = First(class_member_function_types) ; ItType.item; ItType = Next(ItType)) { + if (ItType.item == R_MEMBER_SET) ++setcount; + } + if (Len(class_member_function_types) - setcount > 0) { + OutputMemberReferenceMethod(name, 0, class_member_function_membernames, class_member_function_names, class_member_function_types, sfile); + } + if (setcount > 0) { + OutputMemberReferenceMethod(name, 1, class_member_function_membernames, class_member_function_names, class_member_function_types, sfile); + } + } #endif // if(class_member_functions) { From 9affb871de64c8a0724ad7e296c0a29e4f3279ba Mon Sep 17 00:00:00 2001 From: Richard Beare Date: Wed, 6 Jun 2018 08:50:05 +1000 Subject: [PATCH 03/11] commenting out unused code --- Source/Modules/r.cxx | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Source/Modules/r.cxx b/Source/Modules/r.cxx index 5668abfc4..108bc2e5a 100644 --- a/Source/Modules/r.cxx +++ b/Source/Modules/r.cxx @@ -289,10 +289,13 @@ protected: int OutputMemberReferenceMethod(String *className, int isSet, List *memberList, List *nameList, List *typeList, File *out); +#if 0 + // not used int OutputArrayMethod(String *className, List *el, File *out); int OutputClassMemberTable(Hash *tb, File *out); int OutputClassMethodsTable(File *out); int OutputClassAccessInfo(Hash *tb, File *out); +#endif int defineArrayAccessors(SwigType *type); @@ -908,6 +911,8 @@ int R::DumpCode(Node *n) { +# if 0 +// not called /* ------------------------------------------------------------- * We may need to do more.... so this is left as a * stub for the moment. @@ -1007,6 +1012,8 @@ int R::OutputClassMemberTable(Hash *tb, File *out) { return n; } +// end not used +#endif /* -------------------------------------------------------------- * Write the methods for $ or $<- for accessing a member field in an * struct or union (or class). @@ -1149,6 +1156,8 @@ int R::OutputMemberReferenceMethod(String *className, int isSet, return SWIG_OK; } +#if 0 +// not used /* ------------------------------------------------------------- * Write the methods for [ or [<- for accessing a member field in an * struct or union (or class). @@ -1188,6 +1197,7 @@ int R::OutputArrayMethod(String *className, List *el, File *out) { return SWIG_OK; } +#endif /* ------------------------------------------------------------- * Called when a enumeration is to be processed. From dd24a5dffbf499d37c8fe1022948238451887b84 Mon Sep 17 00:00:00 2001 From: Richard Beare Date: Wed, 6 Jun 2018 10:41:48 +1000 Subject: [PATCH 04/11] Alternative version of using memberlist processing. This clarifies the logic within OutputMemberReferenceMethod by filtering the lists into classes, rather than doing it internally. Code isn't any shorter. --- Source/Modules/r.cxx | 76 +++++++++++++++++++++++++++++++++----------- 1 file changed, 57 insertions(+), 19 deletions(-) diff --git a/Source/Modules/r.cxx b/Source/Modules/r.cxx index 108bc2e5a..60ee56916 100644 --- a/Source/Modules/r.cxx +++ b/Source/Modules/r.cxx @@ -344,6 +344,10 @@ protected: static int getFunctionPointerNumArgs(Node *n, SwigType *tt); + // filtering of class member lists by function type. Used in constructing accessors + // are we allowed to use stl style functors to customise this? + List* filterMemberList(List *class_member_function_types, List *class_member_other, String *R_MEMBER, bool equal); + protected: bool copyStruct; bool memoryProfile; @@ -910,6 +914,30 @@ int R::DumpCode(Node *n) { } +List *R::filterMemberList(List *class_member_types, + List *class_member_other, + String *R_MEMBER, bool equal) { + // filters class_member_other based on whether corresponding elements of + // class_member_function_types are equal or notequal to R_MEMBER + List *CM = NewList(); + Iterator ftype, other; + + for (ftype = First(class_member_types), other = First(class_member_other); + ftype.item; + ftype=Next(ftype), other=Next(other)) { + // verbose, clean up later if the overall structure works + if (equal) { + if (ftype.item == R_MEMBER) { + Append(CM, other.item); + } + } else { + if (ftype.item != R_MEMBER) { + Append(CM, other.item); + } + } + } + return(CM); +} # if 0 // not called @@ -1049,15 +1077,7 @@ int R::OutputMemberReferenceMethod(String *className, int isSet, String *dup = Getitem(nameList, j); String *setgetmethod = Getitem(typeList, j); - // skip this one if it isn't a set method but we're - // creating a modification method - if (isSet && (setgetmethod != R_MEMBER_SET)) - continue; - // skip the set methods when creating accessor methods - if ((!isSet) && (setgetmethod == R_MEMBER_SET)) - continue; - - if ((!isSet) && (setgetmethod == R_MEMBER_GET)) + if (setgetmethod == R_MEMBER_GET) varaccessor++; if (Getattr(itemList, item)) @@ -2521,18 +2541,36 @@ int R::classDeclaration(Node *n) { OutputMemberReferenceMethod(name, 1, class_member_set_functions, sfile); #else if (class_member_function_types) { - // count the number of set methods - unsigned setcount = 0; - Iterator ItType; - for (ItType = First(class_member_function_types) ; ItType.item; ItType = Next(ItType)) { - if (ItType.item == R_MEMBER_SET) ++setcount; + + // collect the "set" methods + List *class_set_membernames = filterMemberList(class_member_function_types, + class_member_function_membernames, R_MEMBER_SET, true); + List *class_set_functionnames = filterMemberList(class_member_function_types, + class_member_function_names, R_MEMBER_SET, true); + // this one isn't used - collecting to keep code simpler + List *class_set_functiontypes = filterMemberList(class_member_function_types, + class_member_function_types, R_MEMBER_SET, true); + + // collect the others + List *class_other_membernames = filterMemberList(class_member_function_types, + class_member_function_membernames, R_MEMBER_SET, false); + List *class_other_functionnames = filterMemberList(class_member_function_types, + class_member_function_names, R_MEMBER_SET, false); + List *class_other_functiontypes = filterMemberList(class_member_function_types, + class_member_function_types, R_MEMBER_SET, false); + + if (Len(class_other_membernames) > 0) { + OutputMemberReferenceMethod(name, 0, class_other_membernames, class_other_functionnames, class_other_functiontypes, sfile); } - if (Len(class_member_function_types) - setcount > 0) { - OutputMemberReferenceMethod(name, 0, class_member_function_membernames, class_member_function_names, class_member_function_types, sfile); - } - if (setcount > 0) { - OutputMemberReferenceMethod(name, 1, class_member_function_membernames, class_member_function_names, class_member_function_types, sfile); + if (Len(class_set_membernames) > 0) { + OutputMemberReferenceMethod(name, 1, class_set_membernames, class_set_functionnames, class_set_functiontypes, sfile); } + Delete(class_set_membernames); + Delete(class_set_functionnames); + Delete(class_set_functiontypes); + Delete(class_other_membernames); + Delete(class_other_functionnames); + Delete(class_other_functiontypes); } #endif From 504ef74948a329440d88de3467283ba2444debc3 Mon Sep 17 00:00:00 2001 From: Richard Beare Date: Mon, 10 Sep 2018 21:57:19 +1000 Subject: [PATCH 05/11] Removed last instance of using Strcmp to check for a set/get method. Replaced with check for flag. --- Source/Modules/r.cxx | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/Source/Modules/r.cxx b/Source/Modules/r.cxx index 60ee56916..752135cf3 100644 --- a/Source/Modules/r.cxx +++ b/Source/Modules/r.cxx @@ -1886,11 +1886,7 @@ int R::functionWrapper(Node *n) { /* Add the name of this member to a list for this class_name. We will dump all these at the end. */ - int nlen = Len(iname); - char *ptr = Char(iname); - bool isSet(0); - if (nlen > 4) isSet = Strcmp(NewString(&ptr[nlen-4]), "_set") == 0; - + bool isSet(GetFlag(n, "memberset")); String *tmp = NewString(""); Printf(tmp, "%s_%s", class_name, isSet ? "set" : "get"); From 7b7e5b001212274e91633be3ed5a2e5ed8f164ce Mon Sep 17 00:00:00 2001 From: Richard Beare Date: Tue, 11 Sep 2018 09:58:33 +1000 Subject: [PATCH 06/11] Used Swig_name_register so that Swig_name_wrapper produces the correct name without a separate replace call. --- Source/Modules/r.cxx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Source/Modules/r.cxx b/Source/Modules/r.cxx index 752135cf3..4d4f71079 100644 --- a/Source/Modules/r.cxx +++ b/Source/Modules/r.cxx @@ -1906,7 +1906,7 @@ int R::functionWrapper(Node *n) { int nargs; String *wname = Swig_name_wrapper(iname); - Replace(wname, "_wrap", "R_swig", DOH_REPLACE_FIRST); + if(overname) Append(wname, overname); Setattr(n,"wrap:name", wname); @@ -2924,6 +2924,9 @@ void R::main(int argc, char *argv[]) { } /// copyToR copyToC functions. + // Register the naming functions + Swig_name_register("wrapper", "R_swig_%f"); + } } From 5f865bdc7e550b420bacb954edb10a67e107048a Mon Sep 17 00:00:00 2001 From: Richard Beare Date: Tue, 11 Sep 2018 10:32:58 +1000 Subject: [PATCH 07/11] calling Swig_name_setget --- Source/Modules/r.cxx | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Source/Modules/r.cxx b/Source/Modules/r.cxx index 4d4f71079..b09828fc9 100644 --- a/Source/Modules/r.cxx +++ b/Source/Modules/r.cxx @@ -1888,8 +1888,11 @@ int R::functionWrapper(Node *n) { bool isSet(GetFlag(n, "memberset")); - String *tmp = NewString(""); - Printf(tmp, "%s_%s", class_name, isSet ? "set" : "get"); + String *tmp = NewString(isSet ? Swig_name_set(NSPACE_TODO, class_name) : Swig_name_get(NSPACE_TODO, class_name)); + + if (debugMode) { + Printf(stdout, "functionWrapper TMP: %s\n", tmp); + } List *memList = Getattr(ClassMemberTable, tmp); if(!memList) { From b4c02b3267c5a018d1363e99fc771a9bdf663388 Mon Sep 17 00:00:00 2001 From: Richard Beare Date: Tue, 11 Sep 2018 11:21:03 +1000 Subject: [PATCH 08/11] moved registration routine and use swig_name_get --- Source/Modules/r.cxx | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/Source/Modules/r.cxx b/Source/Modules/r.cxx index b09828fc9..e59ee54df 100644 --- a/Source/Modules/r.cxx +++ b/Source/Modules/r.cxx @@ -781,6 +781,8 @@ int R::top(Node *n) { Swig_register_filebyname("snamespace", s_namespace); Printf(s_namespace, "useDynLib(%s)\n", DllName); } + // Register the naming functions + Swig_name_register("wrapper", "R_swig_%f"); /* Associate the different streams with names so that they can be used in %insert directives by the typemap code. */ @@ -1890,10 +1892,6 @@ int R::functionWrapper(Node *n) { String *tmp = NewString(isSet ? Swig_name_set(NSPACE_TODO, class_name) : Swig_name_get(NSPACE_TODO, class_name)); - if (debugMode) { - Printf(stdout, "functionWrapper TMP: %s\n", tmp); - } - List *memList = Getattr(ClassMemberTable, tmp); if(!memList) { memList = NewList(); @@ -2927,9 +2925,6 @@ void R::main(int argc, char *argv[]) { } /// copyToR copyToC functions. - // Register the naming functions - Swig_name_register("wrapper", "R_swig_%f"); - } } From aca44d9d3ae339c0d7355919de9b93ee27ee6c50 Mon Sep 17 00:00:00 2001 From: Richard Beare Date: Fri, 30 Aug 2019 21:23:07 +1000 Subject: [PATCH 09/11] Removed some remaining commented sections --- Source/Modules/r.cxx | 76 ++------------------------------------------ 1 file changed, 2 insertions(+), 74 deletions(-) diff --git a/Source/Modules/r.cxx b/Source/Modules/r.cxx index e59ee54df..2ad377af1 100644 --- a/Source/Modules/r.cxx +++ b/Source/Modules/r.cxx @@ -36,11 +36,6 @@ static String * getRTypeName(SwigType *t, int *outCount = NULL) { if(Strncmp(b, "struct ", 7) == 0) Replace(b, "struct ", "", DOH_REPLACE_FIRST); - /* Printf(stdout, " %s,base = %s\n", t, b); - for(i = 0; i < Len(els); i++) - Printf(stdout, "%d) %s, ", i, Getitem(els,i)); - Printf(stdout, "\n"); */ - for(i = 0; i < Len(els); i++) { String *el = Getitem(els, i); if(Strcmp(el, "p.") == 0 || Strncmp(el, "a(", 2) == 0) { @@ -56,13 +51,6 @@ static String * getRTypeName(SwigType *t, int *outCount = NULL) { Insert(tmp, 0, retName); return tmp; - /* - if(count) - return(b); - - Delete(b); - return(NewString("")); - */ } /* -------------------------------------------------------------- @@ -285,7 +273,6 @@ protected: int generateCopyRoutines(Node *n); int DumpCode(Node *n); - //int OutputMemberReferenceMethod(String *className, int isSet, List *el, File *out); int OutputMemberReferenceMethod(String *className, int isSet, List *memberList, List *nameList, List *typeList, File *out); @@ -452,8 +439,6 @@ R::R() : R_MEMBER_SET(NewString("set")), R_MEMBER_GET(NewString("get")), processing_class_member_function(0), - // class_member_functions(0), - // class_member_set_functions(0), class_member_function_types(0), class_member_function_names(0), class_member_function_membernames(0), @@ -536,7 +521,7 @@ String * R::createFunctionPointerHandler(SwigType *t, Node *n, int *numArgs) { SwigType *funcparams = SwigType_functionpointer_decompose(rettype); String *rtype = SwigType_str(rettype, 0); - // ParmList *parms = Getattr(n, "parms"); + // ParmList *parms = Getattr(n, "parms"); // memory leak ParmList *parms = SwigType_function_parms(SwigType_del_pointer(Copy(t)), n); @@ -1029,9 +1014,6 @@ int R::OutputClassMemberTable(Hash *tb, File *out) { isSet = strcmp(ptr, "_set") == 0; } - // OutputArrayMethod(className, el, out); - //OutputMemberReferenceMethod(className, isSet, el, out); - if(outputNamespaceInfo) Printf(s_namespace, "\"%s\"%s", className, i < n-1 ? "," : ""); } @@ -1123,15 +1105,6 @@ int R::OutputMemberReferenceMethod(String *className, int isSet, Printf(f->code, ");\n"); } - - /* Printv(f->code, tab8, - "idx = pmatch(name, names(accessorFuns))\n", - tab8, - "if(is.na(idx)) {\n", - tab8, tab4, - "stop(\"No ", (isSet ? "modifiable" : "accessible"), " field named \", name, \" in ", className, - ": fields are \", paste(names(accessorFuns), sep = \", \")", - ")", "\n}\n", NIL); */ Printv(f->code, ";", tab8, "idx = pmatch(name, names(accessorFuns));\n", tab8, @@ -1265,7 +1238,6 @@ int R::enumDeclaration(Node *n) { Printf(enum_def_calls, "defineEnumeration(\"%s\",\n .values=c(%s))\n\n", ename, enum_values); Delete(enum_values); Delete(ename); - //Delete(symname); } return SWIG_OK; } @@ -1394,32 +1366,7 @@ int R::variableWrapper(Node *n) { void R::addAccessor(String *memberName, Wrapper *wrapper, String *name, String *methodSetGet) { -#if 0 - if(isSet < 0) { - int n = Len(name); - char *ptr = Char(name); - if (n>4) { - isSet = Strcmp(NewString(&ptr[n-4]), "_set") == 0; - } - } -/// RJB - List *l = isSet ? class_member_set_functions : class_member_functions; - if(!l) { - l = NewList(); - if(isSet) - class_member_set_functions = l; - else - class_member_functions = l; - } - - Append(l, memberName); - Append(l, name); - - String *tmp = NewString(""); - Wrapper_print(wrapper, tmp); - Append(l, tmp); -#endif if (!class_member_function_names) { class_member_function_names = NewList(); class_member_function_membernames = NewList(); @@ -1463,11 +1410,6 @@ List * R::Swig_overload_rank(Node *n, c = Getattr(c,"sym:nextSibling"); continue; } - /* if (SmartPointer && Getattr(c,"cplus:staticbase")) { - c = Getattr(c,"sym:nextSibling"); - continue; - } */ - /* Make a list of all the declarations (methods) that are overloaded with * this one particular method name */ @@ -1927,11 +1869,6 @@ int R::functionWrapper(Node *n) { if(!isVoidReturnType) addCopyParam = addCopyParameter(rtype); - - // Can we get the nodeType() of the type node! and see if it is a struct. - // int addCopyParam = SwigType_isclass(rtype); - - // if(addCopyParam) if (debugMode) Printf(stdout, "Adding a .copy argument to %s for %s = %s\n", iname, type, addCopyParam ? "yes" : "no"); @@ -2569,16 +2506,7 @@ int R::classDeclaration(Node *n) { Delete(class_other_functionnames); Delete(class_other_functiontypes); } -#endif - - // if(class_member_functions) { - // Delete(class_member_functions); - // class_member_functions = NULL; - // } - // if(class_member_set_functions) { - // Delete(class_member_set_functions); - // class_member_set_functions = NULL; - // } +#endif if (class_member_function_types) { Delete(class_member_function_types); From bb65049517f68a60c266cb05418c17cce21c636c Mon Sep 17 00:00:00 2001 From: Richard Beare Date: Fri, 30 Aug 2019 22:31:46 +1000 Subject: [PATCH 10/11] ENH R accessor processing test Test of accessors generated via the new internal structures. This test confirms that the old incorrect accessors are not present and runs the correct version, confirming the values. --- Examples/test-suite/r/abstract_access_runme.R | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 Examples/test-suite/r/abstract_access_runme.R diff --git a/Examples/test-suite/r/abstract_access_runme.R b/Examples/test-suite/r/abstract_access_runme.R new file mode 100644 index 000000000..1e73dcabf --- /dev/null +++ b/Examples/test-suite/r/abstract_access_runme.R @@ -0,0 +1,50 @@ +clargs <- commandArgs(trailing=TRUE) +source(file.path(clargs[1], "unittest.R")) + +dyn.load(paste("abstract_access", .Platform$dynlib.ext, sep="")) +source("abstract_access.R") + +dd <- D() +unittest(1, dd$z()) +unittest(1, dd$do_x()) + +## Original version allowed dd$z <- 2 +tryCatch({ + dd$z <- 2 +}, error = function(e) { + message("Correct - no dollar assignment method found") +} +) + +tryCatch({ + dd[["z"]] <- 2 +}, error = function(e) { + message("Correct - no dollar assignment method found") +} +) + +## The methods are attached to the parent class - see if we can get +## them +tryCatch({ + m1 <- getMethod('$', "_p_A") +}, error = function(e) { + stop("No $ method found - there should be one") +} +) + +## These methods should not be present +## They correspond to the tests that are expected +## to fail above. +tryCatch({ + m2 <- getMethod('$<-', "_p_A") +}, error = function(e) { + message("Correct - no dollar assignment method found") +} +) + +tryCatch({ + m3 <- getMethod('[[<-', "_p_A") +}, error = function(e) { + message("Correct - no list assignment method found") +} +) From 25a9e3552cb8a8e63d8f1d3e665aef718b824453 Mon Sep 17 00:00:00 2001 From: Richard Beare Date: Sat, 31 Aug 2019 17:02:46 +1000 Subject: [PATCH 11/11] ENH R abstract_access_runme Improved the exception handling components of test. --- Examples/test-suite/r/abstract_access_runme.R | 30 +++++++++++++++++-- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/Examples/test-suite/r/abstract_access_runme.R b/Examples/test-suite/r/abstract_access_runme.R index 1e73dcabf..f6fb4099d 100644 --- a/Examples/test-suite/r/abstract_access_runme.R +++ b/Examples/test-suite/r/abstract_access_runme.R @@ -11,15 +11,27 @@ unittest(1, dd$do_x()) ## Original version allowed dd$z <- 2 tryCatch({ dd$z <- 2 + # force an error if the previous line doesn't raise an exception + stop("Test Failure A") }, error = function(e) { + if (e$message == "Test Failure A") { + # Raise the error again to cause a failed test + stop(e) + } message("Correct - no dollar assignment method found") } ) tryCatch({ dd[["z"]] <- 2 + # force an error if the previous line doesn't raise an exception + stop("Test Failure B") }, error = function(e) { - message("Correct - no dollar assignment method found") + if (e$message == "Test Failure B") { + # Raise the error again to cause a failed test + stop(e) + } + message("Correct - no dollar assignment method found") } ) @@ -37,14 +49,26 @@ tryCatch({ ## to fail above. tryCatch({ m2 <- getMethod('$<-', "_p_A") + # force an error if the previous line doesn't raise an exception + stop("Test Failure C") }, error = function(e) { - message("Correct - no dollar assignment method found") + if (e$message == "Test Failure C") { + # Raise the error again to cause a failed test + stop(e) + } + message("Correct - no dollar assignment method found") } ) tryCatch({ m3 <- getMethod('[[<-', "_p_A") + # force an error if the previous line doesn't raise an exception + stop("Test Failure D") }, error = function(e) { - message("Correct - no list assignment method found") + if (e$message == "Test Failure D") { + # Raise the error again to cause a failed test + stop(e) + } + message("Correct - no list assignment method found") } )