@@ -103,11 +103,15 @@ namespace attributes {
103
103
104
104
// Known attribute names & parameters
105
105
const char * const kExportAttribute = " export" ;
106
+ const char * const kExportName = " name" ;
107
+ const char * const kExportRng = " rng" ;
106
108
const char * const kDependsAttribute = " depends" ;
107
109
const char * const kPluginsAttribute = " plugins" ;
108
110
const char * const kInterfacesAttribute = " interfaces" ;
109
111
const char * const kInterfaceR = " r" ;
110
112
const char * const kInterfaceCpp = " cpp" ;
113
+ const char * const kParamValueFalse = " false" ;
114
+ const char * const kParamValueTrue = " true" ;
111
115
112
116
// Type info
113
117
class Type {
@@ -244,10 +248,29 @@ namespace attributes {
244
248
}
245
249
246
250
std::string exportedName () const {
247
- if (!params ().empty ())
251
+
252
+ // check for explicit name parameter
253
+ if (hasParameter (kExportName ))
254
+ {
255
+ return paramNamed (kExportName ).value ();
256
+ }
257
+ // otherwise un-named parameter in the first slot
258
+ else if (!params ().empty () && params ()[0 ].value ().empty ())
259
+ {
248
260
return params ()[0 ].name ();
249
- else
261
+ }
262
+ // otherwise the actual function name
263
+ {
250
264
return function ().name ();
265
+ }
266
+ }
267
+
268
+ bool rng () const {
269
+ Param rngParam = paramNamed (kExportRng );
270
+ if (!rngParam.empty ())
271
+ return rngParam.value () != kParamValueFalse ;
272
+ else
273
+ return true ;
251
274
}
252
275
253
276
const std::vector<std::string>& roxygen () const { return roxygen_; }
@@ -740,6 +763,7 @@ namespace attributes {
740
763
}
741
764
else {
742
765
name_ = paramText;
766
+ trimWhitespace (&name_);
743
767
stripQuotes (&name_);
744
768
}
745
769
}
@@ -984,6 +1008,34 @@ namespace attributes {
984
1008
function = parseFunction (lineNumber + 1 );
985
1009
else
986
1010
rcppExportWarning (" No function found" , lineNumber);
1011
+
1012
+ // validate parameters
1013
+ for (std::size_t i=0 ; i<params.size (); i++) {
1014
+
1015
+ std::string name = params[i].name ();
1016
+ std::string value = params[i].value ();
1017
+
1018
+ // un-named parameter that isn't the first parameter
1019
+ if (value.empty () && (i > 0 )) {
1020
+ rcppExportWarning (" No value specified for parameter '" +
1021
+ name + " '" ,
1022
+ lineNumber);
1023
+ }
1024
+ // parameter that isn't name or rng
1025
+ else if (!value.empty () &&
1026
+ (name != kExportName ) &&
1027
+ (name != kExportRng )) {
1028
+ rcppExportWarning (" Unrecognized parameter '" + name + " '" ,
1029
+ lineNumber);
1030
+ }
1031
+ // rng that isn't true or false
1032
+ else if (name == kExportRng ) {
1033
+ if (value != kParamValueFalse && value != kParamValueTrue ) {
1034
+ rcppExportWarning (" rng value must be true or false" ,
1035
+ lineNumber);
1036
+ }
1037
+ }
1038
+ }
987
1039
}
988
1040
989
1041
// validate interfaces parameter
@@ -1014,7 +1066,7 @@ namespace attributes {
1014
1066
std::vector<Param> SourceFileAttributesParser::parseParameters (
1015
1067
const std::string& input) {
1016
1068
1017
- const std::string delimiters (" ," );
1069
+ const std::string delimiters (" ," );
1018
1070
1019
1071
std::vector<Param> params;
1020
1072
std::string::size_type current;
@@ -1694,7 +1746,8 @@ namespace attributes {
1694
1746
ostr () << " }" << std::endl;
1695
1747
ostr () << " RObject __result;" << std::endl;
1696
1748
ostr () << " {" << std::endl;
1697
- ostr () << " RNGScope __rngScope;" << std::endl;
1749
+ if (it->rng ())
1750
+ ostr () << " RNGScope __rngScope;" << std::endl;
1698
1751
ostr () << " __result = " << ptrName << " (" ;
1699
1752
1700
1753
const std::vector<Argument>& args = function.arguments ();
@@ -2226,7 +2279,7 @@ namespace attributes {
2226
2279
ostr << " BEGIN_RCPP" << std::endl;
2227
2280
if (!function.type ().isVoid ())
2228
2281
ostr << " Rcpp::RObject __result;" << std::endl;
2229
- if (!cppInterface)
2282
+ if (!cppInterface && attribute. rng () )
2230
2283
ostr << " Rcpp::RNGScope __rngScope;" << std::endl;
2231
2284
for (size_t i = 0 ; i<arguments.size (); i++) {
2232
2285
const Argument& argument = arguments[i];
@@ -2268,7 +2321,8 @@ namespace attributes {
2268
2321
<< std::endl;
2269
2322
ostr << " SEXP __result;" << std::endl;
2270
2323
ostr << " {" << std::endl;
2271
- ostr << " Rcpp::RNGScope __rngScope;" << std::endl;
2324
+ if (attribute.rng ())
2325
+ ostr << " Rcpp::RNGScope __rngScope;" << std::endl;
2272
2326
ostr << " __result = PROTECT(" << funcName
2273
2327
<< kTrySuffix << " (" ;
2274
2328
for (size_t i = 0 ; i<arguments.size (); i++) {
0 commit comments