From 7b6c52cf4ef53d4f4816cbcd7e086daa1c872d29 Mon Sep 17 00:00:00 2001 From: Owen Avery Date: Sat, 8 Jul 2023 22:28:30 -0400 Subject: [PATCH] gccrs: Merge Gcc_linemap into Linemap 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 --- gcc/rust/rust-linemap.cc | 35 ++++++----------------------------- gcc/rust/rust-linemap.h | 19 +++++++++++-------- 2 files changed, 17 insertions(+), 37 deletions(-) diff --git a/gcc/rust/rust-linemap.cc b/gcc/rust/rust-linemap.cc index 532655ec6563..87b72f8fbeb6 100644 --- a/gcc/rust/rust-linemap.cc +++ b/gcc/rust/rust-linemap.cc @@ -20,35 +20,12 @@ #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) diff --git a/gcc/rust/rust-linemap.h b/gcc/rust/rust-linemap.h index a91aa289bca9..5b74464b2624 100644 --- a/gcc/rust/rust-linemap.h +++ b/gcc/rust/rust-linemap.h @@ -33,38 +33,37 @@ 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) -- 2.47.2