diff options
author | John McFarland <mcfarljm@gmail.com> | 2019-08-03 10:28:28 -0500 |
---|---|---|
committer | John McFarland <mcfarljm@gmail.com> | 2019-08-07 16:42:39 -0500 |
commit | 36f0e9919f0ba882ddd0208694b3b144b0beac26 (patch) | |
tree | 864dae1a5f114e6f4f797accb81fdf56d11c8298 /Source/Doxygen/pydoc.cxx | |
parent | eb11c025c7561f4879308bbae875509e0ee64d05 (diff) | |
download | swig-36f0e9919f0ba882ddd0208694b3b144b0beac26.tar.gz |
Add parameter direction to doxygen pydoc output
For doxygen comments that specify parameter direction (i.e.,
\param[in], \param[out], and \param[in,out]), the direction is
appended to the type definition in the generated Python documentation.
Updated expected python output for doxygen test case.
Diffstat (limited to 'Source/Doxygen/pydoc.cxx')
-rw-r--r-- | Source/Doxygen/pydoc.cxx | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/Source/Doxygen/pydoc.cxx b/Source/Doxygen/pydoc.cxx index 82f0d13fa..0238cbfa4 100644 --- a/Source/Doxygen/pydoc.cxx +++ b/Source/Doxygen/pydoc.cxx @@ -184,6 +184,21 @@ static string padCodeAndVerbatimBlocks(const string &docString) { return result; } +// Helper function to extract the option value from a command, +// e.g. param[in] -> in +static std::string getCommandOption(const std::string &command) { + string option; + + size_t opt_begin, opt_end; + opt_begin = command.find('['); + opt_end = command.find(']'); + if (opt_begin != string::npos && opt_end != string::npos) + option = command.substr(opt_begin+1, opt_end-opt_begin-1); + + return option; +} + + /* static */ PyDocConverter::TagHandlersMap::mapped_type PyDocConverter::make_handler(tagHandler handler) { return make_pair(handler, std::string()); @@ -636,8 +651,19 @@ void PyDocConverter::handleTagParam(DoxygenEntity &tag, std::string &translatedC const std::string ¶mName = paramNameEntity.data; const std::string paramType = getParamType(paramName); + + // Get command option, e.g. "in", "out", or "in,out" + string commandOpt = getCommandOption(tag.typeOfEntity); + if (commandOpt == "in,out") commandOpt = "in/out"; + + // If provided, append the parameter direction to the type + // information via a suffix: + std::string suffix; + if (commandOpt.size() > 0) + suffix = ", " + commandOpt; + if (!paramType.empty()) { - translatedComment += ":type " + paramName + ": " + paramType + "\n"; + translatedComment += ":type " + paramName + ": " + paramType + suffix + "\n"; translatedComment += indent.getFirstLineIndent(); } @@ -909,3 +935,4 @@ String *PyDocConverter::makeDocumentation(Node *n) { return NewString(pyDocString.c_str()); } + |