Mercurial > octave
changeset 33139:4e0f8b80bd2f stable
Find class/ctor help for 'CLS.m' if CLS has no method named 'm' (bug #65398)
* help.h, help.cc (help_system::raw_help_for_class): New function,
extracted from help_system:raw_help_from_symbol_table.
* help.cc (help_system:raw_help_from_symbol_table): Call raw_help_for_class twice:
first in the location of the original code and then again at the end of the
function in a last attempt to find help for CLS if we are searching for the
documentation for CLS.m and there is no method 'm' in the class CLS.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Mon, 04 Mar 2024 00:41:31 -0500 |
parents | 38eb7d69c315 |
children | 8504d3f2b17e e006d8ce57b5 |
files | libinterp/corefcn/help.cc libinterp/corefcn/help.h |
diffstat | 2 files changed, 59 insertions(+), 40 deletions(-) [+] |
line wrap: on
line diff
--- a/libinterp/corefcn/help.cc Sun Mar 03 11:55:08 2024 -0800 +++ b/libinterp/corefcn/help.cc Mon Mar 04 00:41:31 2024 -0500 @@ -684,6 +684,52 @@ return symbol_found; } +bool +help_system::raw_help_for_class (const cdef_class& cls, + const std::string& name, + std::string& help, std::string& what, + bool& symbol_found) const +{ + if (cls.ok ()) + { + // Is the class documented? + help = cls.doc_string (); + + if (! help.empty ()) + { + what = "class"; + + symbol_found = true; + return true; + } + + // Look for constructor. + std::size_t pos = name.rfind ('.'); + + if (pos != std::string::npos) + { + std::string nm = name.substr (pos+1); + + octave_value ov_meth = cls.get_method (nm); + + if (get_help_from_fcn (nm, ov_meth, help, what, symbol_found)) + { + what = "constructor"; + return true; + } + } + + // We found a class, but no docstring for it or its constructor. + // Create a generic doc string. + help = name + " is an undocumented class"; + what = "class"; + symbol_found = true; + return true; + } + + return false; +} + // FIXME: There is a lot of duplication between the following function // and help_system::which. Some refactoring would probably be useful. @@ -734,45 +780,8 @@ cdef_class cls = cdm.find_class (name, false, true); - if (cls.ok ()) - { - // Is the class documented? - - help = cls.doc_string (); - - if (! help.empty ()) - { - what = "class"; - - symbol_found = true; - return true; - } - - // Look for constructor. - - pos = name.rfind ('.'); - - if (pos != std::string::npos) - { - std::string nm = name.substr (pos+1); - - octave_value ov_meth = cls.get_method (nm); - - if (get_help_from_fcn (nm, ov_meth, help, what, symbol_found)) - { - what = "constructor"; - return true; - } - } - - // We found a class but no doc string for it or its constructor. - // Create a generic doc string. - - help = name + " is an undocumented class"; - what = "class"; - symbol_found = true; - return true; - } + if (raw_help_for_class (cls, name, help, what, symbol_found)) + return true; cdef_package pkg = cdm.find_package (name, false, true); @@ -795,7 +804,9 @@ cls = cdm.find_class (prefix, false, true); - if (cls.ok ()) + bool found_class = cls.ok (); + + if (found_class) { // FIXME: Should we only find public methods here? @@ -833,6 +844,9 @@ return true; } + if (nm == "m" && raw_help_for_class (cls, prefix, help, what, symbol_found)) + return true; + return false; }
--- a/libinterp/corefcn/help.h Sun Mar 03 11:55:08 2024 -0800 +++ b/libinterp/corefcn/help.h Mon Mar 04 00:41:31 2024 -0500 @@ -38,6 +38,7 @@ OCTAVE_BEGIN_NAMESPACE(octave) +class cdef_class; class interpreter; class help_system @@ -191,6 +192,10 @@ string_vector local_functions () const; + bool raw_help_for_class (const cdef_class& cls, const std::string& nm, + std::string& h, std::string& w, + bool& symbol_found) const; + bool raw_help_from_symbol_table (const std::string& nm, std::string& h, std::string& w, bool& symbol_found) const;