From: Owen Avery Date: Mon, 3 Jul 2023 17:33:16 +0000 (-0400) Subject: gccrs: Reduce Linemap/Gcc_linemap abstraction further X-Git-Tag: basepoints/gcc-15~2397 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=05ef8df6827f2528ff81a0faec9054fdd5a103ff;p=thirdparty%2Fgcc.git gccrs: Reduce Linemap/Gcc_linemap abstraction further gcc/rust/ChangeLog: * expand/rust-macro-builtins.cc (source_relative_path): Use LOCATION_FILE. (MacroBuiltin::file_handler): Likewise. (MacroBuiltin::column_handler): Use LOCATION_COLUMN. (MacroBuiltin::line_handler): Use LOCATION_LINE. * rust-linemap.cc (Gcc_linemap::location_file): Remove. (Gcc_linemap::location_line): Remove. (Gcc_linemap::location_column): Remove. * rust-linemap.h (Linemap::location_file): Remove. (Linemap::location_line): Remove. (Linemap::location_column): Remove. (Linemap::location_to_file): Remove. (Linemap::location_to_line): Remove. (Linemap::location_to_column): Remove. Signed-off-by: Owen Avery --- diff --git a/gcc/rust/expand/rust-macro-builtins.cc b/gcc/rust/expand/rust-macro-builtins.cc index 363819b35c57..8d000383287c 100644 --- a/gcc/rust/expand/rust-macro-builtins.cc +++ b/gcc/rust/expand/rust-macro-builtins.cc @@ -354,8 +354,7 @@ parse_single_string_literal (BuiltinMacro kind, std::string source_relative_path (std::string path, Location locus) { - std::string compile_fname - = Session::get_instance ().linemap->location_file (locus); + std::string compile_fname = LOCATION_FILE (locus); auto dir_separator_pos = compile_fname.rfind (file_separator); @@ -410,8 +409,7 @@ MacroBuiltin::assert_handler (Location invoc_locus, AST::MacroInvocData &invoc) AST::Fragment MacroBuiltin::file_handler (Location invoc_locus, AST::MacroInvocData &) { - auto current_file - = Session::get_instance ().linemap->location_file (invoc_locus); + auto current_file = LOCATION_FILE (invoc_locus); auto file_str = AST::SingleASTNode (make_string (invoc_locus, current_file)); auto str_token = make_token (Token::make_string (invoc_locus, std::move (current_file))); @@ -422,8 +420,7 @@ MacroBuiltin::file_handler (Location invoc_locus, AST::MacroInvocData &) AST::Fragment MacroBuiltin::column_handler (Location invoc_locus, AST::MacroInvocData &) { - auto current_column - = Session::get_instance ().linemap->location_to_column (invoc_locus); + auto current_column = LOCATION_COLUMN (invoc_locus); auto column_tok = make_token ( Token::make_int (invoc_locus, std::to_string (current_column))); @@ -896,8 +893,7 @@ MacroBuiltin::include_handler (Location invoc_locus, AST::MacroInvocData &invoc) AST::Fragment MacroBuiltin::line_handler (Location invoc_locus, AST::MacroInvocData &) { - auto current_line - = Session::get_instance ().linemap->location_to_line (invoc_locus); + auto current_line = LOCATION_LINE (invoc_locus); auto line_no = AST::SingleASTNode (std::unique_ptr ( new AST::LiteralExpr (std::to_string (current_line), AST::Literal::INT, diff --git a/gcc/rust/rust-linemap.cc b/gcc/rust/rust-linemap.cc index 33d786f985c9..532655ec6563 100644 --- a/gcc/rust/rust-linemap.cc +++ b/gcc/rust/rust-linemap.cc @@ -38,12 +38,6 @@ public: std::string to_string (Location); - std::string location_file (Location); - - int location_line (Location); - - int location_column (Location); - private: // Whether we are currently reading a file. bool in_file_; @@ -87,29 +81,6 @@ Gcc_linemap::to_string (Location location) return ss.str (); } -// Return the file name for a given location. - -std::string -Gcc_linemap::location_file (Location loc) -{ - return LOCATION_FILE (loc); -} - -// Return the line number for a given location. - -int -Gcc_linemap::location_line (Location loc) -{ - return LOCATION_LINE (loc); -} - -// Return the column number for a given location. -int -Gcc_linemap::location_column (Location loc) -{ - return LOCATION_COLUMN (loc); -} - // Stop getting locations. void diff --git a/gcc/rust/rust-linemap.h b/gcc/rust/rust-linemap.h index aa4fa9026ecd..50875d565ee7 100644 --- a/gcc/rust/rust-linemap.h +++ b/gcc/rust/rust-linemap.h @@ -66,15 +66,6 @@ public: // unknown locations. virtual std::string to_string (Location) = 0; - // Return the file name for a given location. - virtual std::string location_file (Location) = 0; - - // Return the line number for a given location. - virtual int location_line (Location) = 0; - - // Return the column number for a given location. - virtual int location_column (Location) = 0; - protected: // The single existing instance of Linemap. static Linemap *instance_; @@ -96,26 +87,6 @@ public: rust_assert (Linemap::instance_ != NULL); return Linemap::instance_->to_string (loc); } - - // Return the file name of a location. - static std::string location_to_file (Location loc) - { - rust_assert (Linemap::instance_ != NULL); - return Linemap::instance_->location_file (loc); - } - - // Return line number of a location. - static int location_to_line (Location loc) - { - rust_assert (Linemap::instance_ != NULL); - return Linemap::instance_->location_line (loc); - } - - static int location_to_column (Location loc) - { - rust_assert (Linemap::instance_ != NULL); - return Linemap::instance_->location_column (loc); - } }; #endif // !defined(RUST_LINEMAP_H)