public inbox for gdb-cvs@sourceware.org
help / color / mirror / Atom feed
* [binutils-gdb] Make some line_header methods const
@ 2020-03-26 15:33 Tom Tromey
  0 siblings, 0 replies; only message in thread
From: Tom Tromey @ 2020-03-26 15:33 UTC (permalink / raw)
  To: gdb-cvs

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=8844c11b8bc1cfa70a63a8875e08345c96abecfe

commit 8844c11b8bc1cfa70a63a8875e08345c96abecfe
Author: Tom Tromey <tom@tromey.com>
Date:   Thu Mar 26 09:28:08 2020 -0600

    Make some line_header methods const
    
    This changes a few line_header methods to be const.  In some cases, a
    const overload is added.
    
    gdb/ChangeLog
    2020-03-26  Tom Tromey  <tom@tromey.com>
    
            * dwarf2/line-header.h (struct line_header) <is_valid_file_index,
            file_names_size, file_full_name, file_file_name>: Use const.
            <file_name_at, file_names>: Add const overload.
            * dwarf2/line-header.c (line_header::file_file_name)
            (line_header::file_full_name): Update.

Diff:
---
 gdb/ChangeLog            |  8 ++++++++
 gdb/dwarf2/line-header.c |  4 ++--
 gdb/dwarf2/line-header.h | 18 ++++++++++++++----
 3 files changed, 24 insertions(+), 6 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 70b58f22455..4599b0df4ff 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,11 @@
+2020-03-26  Tom Tromey  <tom@tromey.com>
+
+	* dwarf2/line-header.h (struct line_header) <is_valid_file_index,
+	file_names_size, file_full_name, file_file_name>: Use const.
+	<file_name_at, file_names>: Add const overload.
+	* dwarf2/line-header.c (line_header::file_file_name)
+	(line_header::file_full_name): Update.
+
 2020-03-26  Tom Tromey  <tom@tromey.com>
 
 	* dwarf2/read.c (dwarf2_macro_malformed_definition_complaint)
diff --git a/gdb/dwarf2/line-header.c b/gdb/dwarf2/line-header.c
index 56dfb5c2dd2..f417f2d0fae 100644
--- a/gdb/dwarf2/line-header.c
+++ b/gdb/dwarf2/line-header.c
@@ -59,7 +59,7 @@ line_header::add_file_name (const char *name,
 }
 
 gdb::unique_xmalloc_ptr<char>
-line_header::file_file_name (int file)
+line_header::file_file_name (int file) const
 {
   /* Is the file number a valid index into the line header's file name
      table?  Remember that file numbers start with one, not zero.  */
@@ -95,7 +95,7 @@ line_header::file_file_name (int file)
 }
 
 gdb::unique_xmalloc_ptr<char>
-line_header::file_full_name (int file, const char *comp_dir)
+line_header::file_full_name (int file, const char *comp_dir) const
 {
   /* Is the file number a valid index into the line header's file name
      table?  Remember that file numbers start with one, not zero.  */
diff --git a/gdb/dwarf2/line-header.h b/gdb/dwarf2/line-header.h
index 08cf7b0810f..30bc37fb85a 100644
--- a/gdb/dwarf2/line-header.h
+++ b/gdb/dwarf2/line-header.h
@@ -96,7 +96,7 @@ struct line_header
     return m_include_dirs[vec_index];
   }
 
-  bool is_valid_file_index (int file_index)
+  bool is_valid_file_index (int file_index) const
   {
     if (version >= 5)
       return 0 <= file_index && file_index < file_names_size ();
@@ -117,11 +117,21 @@ struct line_header
     return &m_file_names[vec_index];
   }
 
+  /* A const overload of the same.  */
+  const file_entry *file_name_at (file_name_index index) const
+  {
+    line_header *lh = const_cast<line_header *> (this);
+    return lh->file_name_at (index);
+  }
+
   /* The indexes are 0-based in DWARF 5 and 1-based in DWARF 4. Therefore,
      this method should only be used to iterate through all file entries in an
      index-agnostic manner.  */
   std::vector<file_entry> &file_names ()
   { return m_file_names; }
+  /* A const overload of the same.  */
+  const std::vector<file_entry> &file_names () const
+  { return m_file_names; }
 
   /* Offset of line number information in .debug_line section.  */
   sect_offset sect_off {};
@@ -145,7 +155,7 @@ struct line_header
      element is standard_opcode_lengths[opcode_base - 1].  */
   std::unique_ptr<unsigned char[]> standard_opcode_lengths;
 
-  int file_names_size ()
+  int file_names_size () const
   { return m_file_names.size(); }
 
   /* The start and end of the statement program following this
@@ -157,13 +167,13 @@ struct line_header
      compilation.  The result is allocated using xmalloc; the caller
      is responsible for freeing it.  */
   gdb::unique_xmalloc_ptr<char> file_full_name (int file,
-						const char *comp_dir);
+						const char *comp_dir) const;
 
   /* Return file name relative to the compilation directory of file
      number I in this object's file name table.  The result is
      allocated using xmalloc; the caller is responsible for freeing
      it.  */
-  gdb::unique_xmalloc_ptr<char> file_file_name (int file);
+  gdb::unique_xmalloc_ptr<char> file_file_name (int file) const;
 
  private:
   /* The include_directories table.  Note these are observing


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2020-03-26 15:33 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-26 15:33 [binutils-gdb] Make some line_header methods const Tom Tromey

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).