@@ -13,6 +13,8 @@ NC_InternalsClass <- R6::R6Class(
1313 allFieldNames_self = character (), # not including inherited methods
1414 classname = character (),
1515 cpp_classname = character (),
16+ all_methodName_to_cpp_code_name = list (),
17+ orig_methodName_to_cpp_code_name = list (),
1618 compileInfo = list (),
1719 inherit_base_provided = FALSE ,
1820 # compileInfo will include interface ("full", "generic", or "none"),
@@ -27,6 +29,9 @@ NC_InternalsClass <- R6::R6Class(
2729 env = NULL ,
2830 inheritQ = NULL ,
2931 process_inherit_done = FALSE ,
32+ virtualMethodNames_self = character (), # will be used when checking inherited method validity, only for locally implemented methods
33+ virtualMethodNames = character (),
34+ check_inherit_done = FALSE ,
3035 initialize = function (classname ,
3136 Cpublic ,
3237 isOnlyC = FALSE ,
@@ -45,10 +50,12 @@ NC_InternalsClass <- R6::R6Class(
4550 numEntries <- length(Cpublic )
4651 if (numEntries ) {
4752 isMethod <- rep(FALSE , numEntries )
53+ isVirtual <- rep(FALSE , numEntries )
4854 for (i in seq_along(Cpublic )) {
4955 if (isNF(Cpublic [[i ]])) {
5056 isMethod [i ] <- TRUE
51- NFinternals(Cpublic [[i ]])$ isMethod <- TRUE
57+ isVirtual [i ] <- isTRUE(NFinternals(Cpublic [[i ]])$ compileInfo $ virtual )
58+ # NFinternals(Cpublic[[i]])$isMethod <- TRUE
5259 next ;
5360 }
5461 if (is.function(Cpublic [[i ]])) {
@@ -57,17 +64,25 @@ NC_InternalsClass <- R6::R6Class(
5764 call. = FALSE )
5865 }
5966 }
67+ self $ virtualMethodNames <- names(Cpublic )[isVirtual ]
6068 self $ symbolTable <- argTypeList2symbolTable(Cpublic [! isMethod ], evalEnv = env )
6169 self $ cppSymbolNames <- Rname2CppName(symbolTable $ getSymbolNames())
6270 self $ methodNames <- names(Cpublic )[isMethod ]
6371 self $ allMethodNames_self <- methodNames
72+ self $ virtualMethodNames_self <- names(Cpublic )[isVirtual ]
6473 self $ allMethodNames <- methodNames
6574 self $ fieldNames <- names(Cpublic )[! isMethod ]
6675 self $ allFieldNames_self <- fieldNames
6776 self $ allFieldNames <- fieldNames
68- if (! is.null(self $ compileInfo $ inherit $ base ))
69- self $ inherit_base_provided <- TRUE
77+ self $ orig_methodName_to_cpp_code_name <- structure(vector(" list" , length = length(methodNames )),
78+ names = methodNames )
79+ for (mN in methodNames ) {
80+ self $ orig_methodName_to_cpp_code_name [[mN ]] <- NFinternals(Cpublic [[mN ]])$ cpp_code_name
81+ }
7082 }
83+ # An over-riding base class can be provided either through inherit or nClass_inherit.
84+ if (! is.null(self $ compileInfo $ inherit $ base ) || ! is.null(self $ compileInfo $ nClass_inherit $ base ))
85+ self $ inherit_base_provided <- TRUE
7186 if (! is.null(enableDerivs )) {
7287 if (! is.list(enableDerivs ))
7388 enableDerivs <- as.list(enableDerivs )
@@ -84,29 +99,38 @@ NC_InternalsClass <- R6::R6Class(
8499 # These are steps that need to be done after all classes are defined
85100 # and do not require recursion up the inheritance tree.
86101 if (! is.null(self $ inheritQ )) {
87- inherit_obj <- eval(self $ inheritQ , envir = self $ env )
102+ inherit_obj <- eval(self $ inheritQ , envir = self $ env ) # inheritQ can be an expression but it must always return the same generator object
88103 if (! isNCgenerator(inherit_obj ))
89104 stop(" An inherit argument that was provided to nClass is not nClass generator." )
90105 self $ inheritNCinternals <- NCinternals(inherit_obj )
91106 message(" add check that base class has interface 'none'" )
92- if (! self $ inherit_base_provided )
93- self $ compileInfo $ inherit $ base <- paste(" public" ,
94- self $ inheritNCinternals $ cpp_classname )
95- process_inherit_done <- FALSE
96- } else {
97- process_inherit_done <- TRUE
107+ if (! self $ inherit_base_provided ) {
108+ self $ compileInfo $ nClass_inherit $ base <- self $ inheritNCinternals $ cpp_classname # don't paste "public" because it will go in interface_resolver<
109+ }
98110 }
111+ self $ process_inherit_done <- FALSE
112+ self $ check_inherit_done <- FALSE
99113 },
100114 process_inherit = function () {
101115 # These are steps that need to be done after connect_inherit
102116 # and require recursion up the inheritance tree, using flags.
117+ # TO-DO: Error trap in methods of same name but different argument signatures.
103118 if (self $ process_inherit_done ) return ()
104119 if (! is.null(self $ inheritQ )) {
105120 self $ inheritNCinternals $ process_inherit()
106121 self $ symbolTable $ setParentST(self $ inheritNCinternals $ symbolTable )
107- self $ allMethodNames <- c(self $ allMethodNames_self , self $ inheritNCinternals $ allMethodNames )
122+ newMethodNames <- setdiff(self $ allMethodNames_self ,
123+ self $ inheritNCinternals $ allMethodNames )
124+ self $ allMethodNames <- c(newMethodNames , self $ inheritNCinternals $ allMethodNames )
125+ self $ all_methodName_to_cpp_code_name <- c(self $ orig_methodName_to_cpp_code_name [newMethodNames ],
126+ self $ inheritNCinternals $ all_methodName_to_cpp_code_name )
108127 self $ allFieldNames <- c(self $ allFieldNames_self , self $ inheritNCinternals $ allFieldNames )
109- }
128+ } else {
129+ self $ allMethodNames <- self $ allMethodNames_self
130+ self $ all_methodName_to_cpp_code_name <- self $ orig_methodName_to_cpp_code_name
131+ self $ allFieldNames <- self $ allFieldNames_self
132+ self $ symbolTable $ setParentST(NULL )
133+ }
110134 self $ process_inherit_done <- TRUE
111135 }
112136 )
0 commit comments