This patch to the Go frontend adds a location_file method to Linemap, adding support for getting the file name from a Location value. This will be used by later work. This requires a patch to the interface between the Go frontend and the rest of GCC. Bootstrapped and ran Go testsuite on x86_64-pc-linux-gnu. Committed to mainline.
Ian 2018-10-29 Ian Lance Taylor <i...@golang.org> * go-linemap.cc (Gcc_linemap::location_file): New method.
Index: gcc/go/go-linemap.cc =================================================================== --- gcc/go/go-linemap.cc (revision 265460) +++ gcc/go/go-linemap.cc (working copy) @@ -34,6 +34,9 @@ class Gcc_linemap : public Linemap std::string to_string(Location); + std::string + location_file(Location); + int location_line(Location); @@ -93,7 +96,16 @@ Gcc_linemap::to_string(Location location return ss.str(); } -// Return the line number for a given location (for debugging dumps) +// Return the file name for a given location. + +std::string +Gcc_linemap::location_file(Location loc) +{ + return LOCATION_FILE(loc.gcc_location()); +} + +// Return the line number for a given location. + int Gcc_linemap::location_line(Location loc) { Index: gcc/go/gofrontend/MERGE =================================================================== --- gcc/go/gofrontend/MERGE (revision 265541) +++ gcc/go/gofrontend/MERGE (working copy) @@ -1,4 +1,4 @@ -8902fb43c569e4d3ec5bd143bfa8cb6bf2836780 +e4a421a01ad1fcc4315e530e79272604f3683051 The first line of this file holds the git revision number of the last merge done from the gofrontend repository. Index: gcc/go/gofrontend/go-linemap.h =================================================================== --- gcc/go/gofrontend/go-linemap.h (revision 265460) +++ gcc/go/gofrontend/go-linemap.h (working copy) @@ -63,7 +63,11 @@ class Linemap virtual std::string to_string(Location) = 0; - // Return the line number for a given location (for debugging dumps) + // 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; @@ -140,7 +144,15 @@ class Linemap return Linemap::instance_->to_string(loc); } - // Return line number for location + // Return the file name of a location. + static std::string + location_to_file(Location loc) + { + go_assert(Linemap::instance_ != NULL); + return Linemap::instance_->location_file(loc); + } + + // Return line number of a location. static int location_to_line(Location loc) {