Skip to content

Commit ddf6550

Browse files
committed
Merge pull request #193 from luckyrandom/attribute_parse
Attribute parse
2 parents bed9ad7 + d4bc42c commit ddf6550

File tree

4 files changed

+15
-4
lines changed

4 files changed

+15
-4
lines changed

R/Attributes.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ compileAttributes <- function(pkgdir = ".", verbose = getOption("verbose")) {
366366
dir.create(rDir)
367367

368368
# get a list of all source files
369-
cppFiles <- list.files(srcDir, pattern="\\.c(c|pp)$")
369+
cppFiles <- list.files(srcDir, pattern = "\\.(c(c|pp))|(h(pp)?)$")
370370

371371
# derive base names (will be used for modules)
372372
cppFileBasenames <- tools::file_path_sans_ext(cppFiles)

inst/unitTests/cpp/attributes.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,10 @@ std::string comments_test( /// // "\""" some '"// more / // ///garbge"
1010
) { // """
1111
return msg;
1212
}
13+
14+
std::string parse_declaration_test(std::string msg) {
15+
return msg;
16+
}
17+
18+
// [[Rcpp::export]]
19+
std::string parse_declaration_test(std::string msg = "Parse function declaration");

inst/unitTests/runit.attributes.R

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ if (.runThisTest) {
2828
comments_test(),
2929
"Start a C++ line comment with the characters \"//\""
3030
)
31+
checkEquals(
32+
parse_declaration_test(),
33+
"Parse function declaration"
34+
)
3135
}
3236

3337
}

src/attributes.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1162,12 +1162,12 @@ namespace attributes {
11621162
for (int i = lineNumber; i<lines_.size(); i++) {
11631163
std::string line;
11641164
line = lines_[i];
1165-
std::string::size_type bracePos = line.find('{');
1166-
if (bracePos == std::string::npos) {
1165+
std::string::size_type end = line.find_first_of("{;");
1166+
if (end == std::string::npos) {
11671167
signature.append(line);
11681168
signature.push_back(' ');
11691169
} else {
1170-
signature.append(line.substr(0, bracePos));
1170+
signature.append(line.substr(0, end));
11711171
return signature;
11721172
}
11731173
}

0 commit comments

Comments
 (0)