Skip to content

Commit 91aea52

Browse files
committed
Add invisible param to export attribute
1 parent b9e1738 commit 91aea52

File tree

1 file changed

+27
-3
lines changed

1 file changed

+27
-3
lines changed

src/attributes.cpp

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ namespace attributes {
153153
const char * const kExportAttribute = "export";
154154
const char * const kExportName = "name";
155155
const char * const kExportRng = "rng";
156+
const char * const kExportInvisible = "invisible";
156157
const char * const kInitAttribute = "init";
157158
const char * const kDependsAttribute = "depends";
158159
const char * const kPluginsAttribute = "plugins";
@@ -381,6 +382,15 @@ namespace attributes {
381382
return true;
382383
}
383384

385+
bool invisible() const {
386+
Param invisibleParam = paramNamed(kExportInvisible);
387+
if (!invisibleParam.empty())
388+
return invisibleParam.value() == kParamValueTrue || // #nocov
389+
invisibleParam.value() == kParamValueTRUE; // #nocov
390+
else
391+
return false;
392+
}
393+
384394
const std::vector<std::string>& roxygen() const { return roxygen_; }
385395

386396
private:
@@ -1352,7 +1362,8 @@ namespace attributes {
13521362
// parameter that isn't name or rng
13531363
else if (!value.empty() &&
13541364
(name != kExportName) &&
1355-
(name != kExportRng)) {
1365+
(name != kExportRng) &&
1366+
(name != kExportInvisible)) {
13561367
rcppExportWarning("Unrecognized parameter '" + name + "'",
13571368
lineNumber);
13581369
}
@@ -1366,6 +1377,16 @@ namespace attributes {
13661377
lineNumber); // #nocov end
13671378
}
13681379
}
1380+
// invisible that isn't true of false
1381+
else if (name == kExportInvisible) {
1382+
if (value != kParamValueFalse &&
1383+
value != kParamValueTrue &&
1384+
value != kParamValueFALSE &&
1385+
value != kParamValueTRUE) {
1386+
rcppExportWarning("invisible value must be true or false",
1387+
lineNumber); // #nocov end
1388+
}
1389+
}
13691390
}
13701391
}
13711392

@@ -2413,11 +2434,14 @@ namespace attributes {
24132434
// determine the function name
24142435
std::string name = attribute.exportedName();
24152436

2437+
// determine if return invisible
2438+
bool invisible = function.type().isVoid() || attribute.invisible();
2439+
24162440
// write the function
24172441
ostr() << name << " <- function(" << args << ") {"
24182442
<< std::endl;
24192443
ostr() << " ";
2420-
if (function.type().isVoid())
2444+
if (invisible)
24212445
ostr() << "invisible("; // #nocov
24222446
ostr() << ".Call(";
24232447
if (!registration_)
@@ -2435,7 +2459,7 @@ namespace attributes {
24352459
for (size_t i = 0; i<arguments.size(); i++)
24362460
ostr() << ", " << arguments[i].name(); // #nocov
24372461
ostr() << ")";
2438-
if (function.type().isVoid())
2462+
if (invisible)
24392463
ostr() << ")"; // #nocov
24402464
ostr() << std::endl;
24412465

0 commit comments

Comments
 (0)