From 943cc2fb6463ab8e06c2f2bcc4281a65e9dc4a78 Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Mon, 29 Oct 2018 18:44:39 +0000 Subject: compiler: add location_file Add support for getting the file name from a Location value. This will be used by later work. Reviewed-on: https://go-review.googlesource.com/c/145318 * go-linemap.cc (Gcc_linemap::location_file): New method. From-SVN: r265598 --- gcc/go/ChangeLog | 4 ++++ gcc/go/go-linemap.cc | 14 +++++++++++++- gcc/go/gofrontend/MERGE | 2 +- gcc/go/gofrontend/go-linemap.h | 16 ++++++++++++++-- 4 files changed, 32 insertions(+), 4 deletions(-) (limited to 'gcc/go') diff --git a/gcc/go/ChangeLog b/gcc/go/ChangeLog index 587013f..915630d 100644 --- a/gcc/go/ChangeLog +++ b/gcc/go/ChangeLog @@ -1,3 +1,7 @@ +2018-10-29 Ian Lance Taylor + + * go-linemap.cc (Gcc_linemap::location_file): New method. + 2018-10-17 David Malcolm * Make-lang.in (selftest-go): New. diff --git a/gcc/go/go-linemap.cc b/gcc/go/go-linemap.cc index 2accb95..a4d4b7d 100644 --- a/gcc/go/go-linemap.cc +++ b/gcc/go/go-linemap.cc @@ -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) { diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE index bf2b28f..7074d3e 100644 --- a/gcc/go/gofrontend/MERGE +++ b/gcc/go/gofrontend/MERGE @@ -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. diff --git a/gcc/go/gofrontend/go-linemap.h b/gcc/go/gofrontend/go-linemap.h index 704efdb..1811c9d 100644 --- a/gcc/go/gofrontend/go-linemap.h +++ b/gcc/go/gofrontend/go-linemap.h @@ -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) { -- cgit v1.1