changeset 30259:03ff3f1020cf

store file name in classdef class object * ov-classdef.h, ov-classdef.cc (octave_classdef_meta::file_name): New function. * pt-classdef.h, pt-classdef.cc (tree_classdef::m_file_name): New data member. (tree_classdef::tree_classdef): Also accept file name in constructor argument list. (tree_classdef::file_name): New function. * oct-parse.yy (base_parser::make_classdef): Store full file name in created tree_classdef object. * cdef-class.h, cdef-class.cc (cdef_class_rep::file_name, cdef_class::file_name): New functions. (cdef_class:make_meta_class): Store file name in returned class object.
author John W. Eaton <jwe@octave.org>
date Sat, 30 Oct 2021 09:45:23 -0400
parents b3beb8273630
children bfbe6e528af5
files libinterp/octave-value/cdef-class.cc libinterp/octave-value/cdef-class.h libinterp/octave-value/ov-classdef.cc libinterp/octave-value/ov-classdef.h libinterp/parse-tree/oct-parse.yy libinterp/parse-tree/pt-classdef.h
diffstat 6 files changed, 41 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/octave-value/cdef-class.cc	Sat Oct 30 13:03:02 2021 +0200
+++ b/libinterp/octave-value/cdef-class.cc	Sat Oct 30 09:45:23 2021 -0400
@@ -847,11 +847,11 @@
                                tree_classdef *t, bool is_at_folder)
   {
     cdef_class retval;
-    std::string class_name, full_class_name;
 
     // Class creation
 
-    class_name = full_class_name = t->ident ()->name ();
+    std::string class_name = t->ident ()->name ();
+    std::string full_class_name = class_name;
     if (! t->package_name ().empty ())
       full_class_name = t->package_name () + '.' + full_class_name;
 
@@ -896,6 +896,7 @@
     retval = cdm.make_class (full_class_name, slist);
 
     retval.doc_string (t->doc_string ());
+    retval.file_name (t->file_name ());
 
     // Package owning this class
 
--- a/libinterp/octave-value/cdef-class.h	Sat Oct 30 13:03:02 2021 +0200
+++ b/libinterp/octave-value/cdef-class.h	Sat Oct 30 09:45:23 2021 -0400
@@ -161,6 +161,10 @@
 
       std::string doc_string (void) const { return m_doc_string; }
 
+      void file_name (const std::string& nm) { m_file_name = nm; }
+
+      std::string file_name (void) const { return m_file_name; }
+
     private:
 
       OCTINTERP_API void load_all_methods (void);
@@ -188,6 +192,8 @@
 
       std::string m_doc_string;
 
+      std::string m_file_name;
+
       // The methods defined by this class.
 
       std::map<std::string,cdef_method> m_method_map;
@@ -393,6 +399,10 @@
 
     std::string doc_string (void) const { return get_rep ()->doc_string (); }
 
+    void file_name (const std::string& nm) { get_rep ()->file_name (nm); }
+
+    std::string file_name (void) const { return get_rep ()->file_name (); }
+
   public:
 
     enum
--- a/libinterp/octave-value/ov-classdef.cc	Sat Oct 30 13:03:02 2021 +0200
+++ b/libinterp/octave-value/ov-classdef.cc	Sat Oct 30 09:45:23 2021 -0400
@@ -458,6 +458,18 @@
   return "";
 }
 
+std::string octave_classdef_meta::file_name (void) const
+{
+  if (m_object.is_class ())
+    {
+      octave::cdef_class cls (m_object);
+
+      return cls.file_name ();
+    }
+
+  return "";
+}
+
 octave_value_list
 octave_classdef_superclass_ref::execute (octave::tree_evaluator& tw,
                                          int nargout,
--- a/libinterp/octave-value/ov-classdef.h	Sat Oct 30 13:03:02 2021 +0200
+++ b/libinterp/octave-value/ov-classdef.h	Sat Oct 30 09:45:23 2021 -0400
@@ -231,6 +231,8 @@
 
   OCTINTERP_API std::string doc_string (const std::string& meth_name) const;
 
+  OCTINTERP_API std::string file_name (void) const;
+
 private:
 
   octave::cdef_meta_object m_object;
--- a/libinterp/parse-tree/oct-parse.yy	Sat Oct 30 13:03:02 2021 +0200
+++ b/libinterp/parse-tree/oct-parse.yy	Sat Oct 30 09:45:23 2021 -0400
@@ -4305,14 +4305,16 @@
 
     std::string cls_name = id->name ();
 
-    std::string nm = m_lexer.m_fcn_file_name;
-
-    std::size_t pos = nm.find_last_of (sys::file_ops::dir_sep_chars ());
+    std::string full_name = m_lexer.m_fcn_file_full_name;
+    std::string short_name = m_lexer.m_fcn_file_name;
+
+    std::size_t pos
+      = short_name.find_last_of (sys::file_ops::dir_sep_chars ());
 
     if (pos != std::string::npos)
-      nm = m_lexer.m_fcn_file_name.substr (pos+1);
-
-    if (nm != cls_name)
+      short_name = short_name.substr (pos+1);
+
+    if (short_name != cls_name)
       {
         int l = id->line ();
         int c = id->column ();
@@ -4339,7 +4341,7 @@
 
             retval = new tree_classdef (m_lexer.m_symtab_context.curr_scope (),
                                         a, id, sc, body, lc, tc,
-                                        m_curr_package_name, l, c);
+                                        m_curr_package_name, full_name, l, c);
           }
         else
           {
--- a/libinterp/parse-tree/pt-classdef.h	Sat Oct 30 13:03:02 2021 +0200
+++ b/libinterp/parse-tree/pt-classdef.h	Sat Oct 30 09:45:23 2021 -0400
@@ -768,10 +768,10 @@
                    tree_classdef_superclass_list *sc,
                    tree_classdef_body *b, comment_list *lc,
                    comment_list *tc, const std::string& pn = "",
-                   int l = -1, int c = -1)
+                   const std::string& fn = "", int l = -1, int c = -1)
       : tree_command (l, c), m_scope (scope), m_attr_list (a), m_id (i),
         m_supclass_list (sc), m_element_list (b), m_lead_comm (lc),
-        m_trail_comm (tc), m_pack_name (pn)
+        m_trail_comm (tc), m_pack_name (pn), m_file_name (fn)
     { }
 
     // No copying!
@@ -807,6 +807,8 @@
 
     std::string package_name (void) const { return m_pack_name; }
 
+    std::string file_name (void) const { return m_file_name; }
+
     octave_value make_meta_class (interpreter& interp,
                                   bool is_at_folder = false);
 
@@ -840,6 +842,7 @@
     comment_list *m_trail_comm;
 
     std::string m_pack_name;
+    std::string m_file_name;
   };
 }