Parse a function from the specified spot in the source file
| 1481 | |
| 1482 | // Parse a function from the specified spot in the source file |
| 1483 | Function SourceFileAttributesParser::parseFunction(size_t lineNumber) { |
| 1484 | |
| 1485 | // Establish the text to parse for the signature |
| 1486 | std::string signature = parseSignature(lineNumber); |
| 1487 | if (signature.empty()) { |
| 1488 | rcppExportNoFunctionFoundWarning(lineNumber); // #nocov |
| 1489 | return Function(); // #nocov |
| 1490 | } |
| 1491 | |
| 1492 | // Start at the end and look for the () that deliniates the arguments |
| 1493 | // (bail with an empty result if we can't find them) |
| 1494 | std::string::size_type endParenLoc = signature.find_last_of(')'); |
| 1495 | std::string::size_type beginParenLoc = signature.find_first_of('('); |
| 1496 | if (endParenLoc == std::string::npos || |
| 1497 | beginParenLoc == std::string::npos || |
| 1498 | endParenLoc < beginParenLoc) { |
| 1499 | |
| 1500 | rcppExportNoFunctionFoundWarning(lineNumber); // #nocov |
| 1501 | return Function(); // #nocov |
| 1502 | } |
| 1503 | |
| 1504 | // Find the type and name by scanning backwards for the whitespace that |
| 1505 | // delimites the type and name |
| 1506 | Type type; |
| 1507 | std::string name; |
| 1508 | const std::string preambleText = signature.substr(0, beginParenLoc); |
| 1509 | for (std::string::const_reverse_iterator |
| 1510 | it = preambleText.rbegin(); it != preambleText.rend(); ++it) { |
| 1511 | char ch = *it; |
| 1512 | if (isWhitespace(ch)) { |
| 1513 | if (!name.empty()) { |
| 1514 | // we are at the break between type and name so we can also |
| 1515 | // extract the type |
| 1516 | std::string typeText; |
| 1517 | while (++it != preambleText.rend()) |
| 1518 | typeText.insert(0U, 1U, *it); |
| 1519 | type = parseType(typeText); |
| 1520 | |
| 1521 | // break (since we now have the name and the type) |
| 1522 | break; |
| 1523 | } |
| 1524 | else |
| 1525 | continue; // #nocov |
| 1526 | } else { |
| 1527 | name.insert(0U, 1U, ch); |
| 1528 | } |
| 1529 | } |
| 1530 | |
| 1531 | // If we didn't find a name then bail |
| 1532 | if (name.empty()) { |
| 1533 | rcppExportNoFunctionFoundWarning(lineNumber); // #nocov |
| 1534 | return Function(); // #nocov |
| 1535 | } |
| 1536 | |
| 1537 | // If we didn't find a type then bail |
| 1538 | if (type.empty()) { // #nocov start |
| 1539 | rcppExportWarning("No function return type found", lineNumber); |
| 1540 | return Function(); // #nocov end |
nothing calls this directly
no test coverage detected