]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: Merge Gcc_linemap into Linemap
authorOwen Avery <powerboat9.gamer@gmail.com>
Sun, 9 Jul 2023 02:28:30 +0000 (22:28 -0400)
committerArthur Cohen <arthur.cohen@embecosm.com>
Tue, 16 Jan 2024 17:49:35 +0000 (18:49 +0100)
gcc/rust/ChangeLog:

* rust-linemap.cc
(class Gcc_linemap): Remove.
(Gcc_linemap::start_file): Move to...
(Linemap::start_file): ... here.
(Gcc_linemap::to_string): Move to...
(Linemap::to_string): ... here.
(Gcc_linemap::stop): Move to...
(Linemap::stop): ... here.
(Gcc_linemap::start_line): Move to...
(Linemap::start_line): ... here.
(Gcc_linemap::get_location): Move to...
(Linemap::get_location): ... here.
(rust_get_linemap): Use Linemap.
* rust-linemap.h
(Linemap::in_file_): New field from Gcc_linemap.
(Linemap::Linemap): Initialize in_file_.
(Linemap::~Linemap): Make non-virtual.
(Linemap::start_file): Likewise.
(Linemap::start_line): Likewise.
(Linemap::get_location): Likewise.
(Linemap::stop): Likewise.
(Linemap::to_string): Likewise.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
gcc/rust/rust-linemap.cc
gcc/rust/rust-linemap.h

index 532655ec65631d228bbb47b3ff40e206da4ded64..87b72f8fbeb6ea93639ae5ed4e72fa233951294f 100644 (file)
 
 #include "rust-linemap.h"
 
-// This class implements the Linemap interface defined by the
-// frontend.
-
-class Gcc_linemap : public Linemap
-{
-public:
-  Gcc_linemap () : Linemap (), in_file_ (false) {}
-
-  void start_file (const char *file_name, unsigned int line_begin);
-
-  void start_line (unsigned int line_number, unsigned int line_size);
-
-  Location get_location (unsigned int column);
-
-  void stop ();
-
-  std::string to_string (Location);
-
-private:
-  // Whether we are currently reading a file.
-  bool in_file_;
-};
-
 Linemap *Linemap::instance_ = NULL;
 
 // Start getting locations from a new file.
 
 void
-Gcc_linemap::start_file (const char *file_name, unsigned line_begin)
+Linemap::start_file (const char *file_name, unsigned line_begin)
 {
   if (this->in_file_)
     linemap_add (line_table, LC_LEAVE, 0, NULL, 0);
@@ -59,7 +36,7 @@ Gcc_linemap::start_file (const char *file_name, unsigned line_begin)
 // Stringify a location
 
 std::string
-Gcc_linemap::to_string (Location location)
+Linemap::to_string (Location location)
 {
   const line_map_ordinary *lmo;
   location_t resolved_location;
@@ -84,7 +61,7 @@ Gcc_linemap::to_string (Location location)
 // Stop getting locations.
 
 void
-Gcc_linemap::stop ()
+Linemap::stop ()
 {
   linemap_add (line_table, LC_LEAVE, 0, NULL, 0);
   this->in_file_ = false;
@@ -93,7 +70,7 @@ Gcc_linemap::stop ()
 // Start a new line.
 
 void
-Gcc_linemap::start_line (unsigned lineno, unsigned linesize)
+Linemap::start_line (unsigned lineno, unsigned linesize)
 {
   linemap_line_start (line_table, lineno, linesize);
 }
@@ -101,7 +78,7 @@ Gcc_linemap::start_line (unsigned lineno, unsigned linesize)
 // Get a location.
 
 Location
-Gcc_linemap::get_location (unsigned column)
+Linemap::get_location (unsigned column)
 {
   return Location (linemap_position_for_column (line_table, column));
 }
@@ -111,7 +88,7 @@ Gcc_linemap::get_location (unsigned column)
 Linemap *
 rust_get_linemap ()
 {
-  return new Gcc_linemap;
+  return new Linemap;
 }
 
 RichLocation::RichLocation (Location root) : gcc_rich_loc (line_table, root)
index a91aa289bca97fc59446c1eebf84660b9c3f675e..5b74464b26245a7ebd0a0e3f04fe4d6e899bfb0f 100644 (file)
 class Linemap
 {
 public:
-  Linemap ()
+  Linemap () : in_file_ (false)
   {
     // Only one instance of Linemap is allowed to exist.
     rust_assert (Linemap::instance_ == NULL);
     Linemap::instance_ = this;
   }
 
-  virtual ~Linemap () { Linemap::instance_ = NULL; }
+  ~Linemap () { Linemap::instance_ = NULL; }
 
   // Subsequent Location values will come from the file named
   // FILE_NAME, starting at LINE_BEGIN.  Normally LINE_BEGIN will be
   // 0, but it will be non-zero if the Rust source has a //line comment.
-  virtual void start_file (const char *file_name, unsigned int line_begin) = 0;
+  void start_file (const char *file_name, unsigned int line_begin);
 
   // Subsequent Location values will come from the line LINE_NUMBER,
   // in the current file.  LINE_SIZE is the size of the line in bytes.
   // This will normally be called for every line in a source file.
-  virtual void start_line (unsigned int line_number, unsigned int line_size)
-    = 0;
+  void start_line (unsigned int line_number, unsigned int line_size);
 
   // Get a Location representing column position COLUMN on the current
   // line in the current file.
-  virtual Location get_location (unsigned int column) = 0;
+  Location get_location (unsigned int column);
 
   // Stop generating Location values.  This will be called after all
   // input files have been read, in case any cleanup is required.
-  virtual void stop () = 0;
+  void stop ();
 
   // Produce a human-readable description of a Location, e.g.
   // "foo.rust:10". Returns an empty string for predeclared, builtin or
   // unknown locations.
-  virtual std::string to_string (Location) = 0;
+  std::string to_string (Location);
 
 protected:
   // The single existing instance of Linemap.
@@ -84,6 +83,10 @@ public:
     rust_assert (Linemap::instance_ != NULL);
     return Linemap::instance_->to_string (loc);
   }
+
+private:
+  // Whether we are currently reading a file.
+  bool in_file_;
 };
 
 #endif // !defined(RUST_LINEMAP_H)