From 437018ea2b6dc966ce40cd5dd684054126ddda6b Mon Sep 17 00:00:00 2001 From: Than McIntosh Date: Tue, 27 Sep 2016 20:49:05 +0000 Subject: compiler: add src information to AST dumps (part 1 of 2). When emitting AST dumps, tag the end of selected statements with with source file and line number information where available. Example: tmp.76832448 = 0 // p.go:6 Requires a corresponding change in gcc/go as well as this change to gofrontend. Reviewed-on: https://go-review.googlesource.com/29856 * go-linemap.cc (Gcc_linemap::to_string): New method. From-SVN: r240558 --- gcc/go/go-linemap.cc | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'gcc/go/go-linemap.cc') diff --git a/gcc/go/go-linemap.cc b/gcc/go/go-linemap.cc index b41559e..b58a54b 100644 --- a/gcc/go/go-linemap.cc +++ b/gcc/go/go-linemap.cc @@ -29,6 +29,9 @@ class Gcc_linemap : public Linemap void stop(); + std::string + to_string(Location); + protected: Location get_predeclared_location(); @@ -60,6 +63,31 @@ Gcc_linemap::start_file(const char *file_name, unsigned line_begin) this->in_file_ = true; } +// Stringify a location + +std::string +Gcc_linemap::to_string(Location location) +{ + const line_map_ordinary *lmo; + source_location resolved_location; + + // Screen out unknown and predeclared locations; produce output + // only for simple file:line locations. + resolved_location = + linemap_resolve_location (line_table, location.gcc_location(), + LRK_SPELLING_LOCATION, &lmo); + if (lmo == NULL || resolved_location < RESERVED_LOCATION_COUNT) + return ""; + const char *path = LINEMAP_FILE (lmo); + if (!path) + return ""; + + // Strip the source file down to the base file, to reduce clutter. + std::stringstream ss; + ss << lbasename(path) << ":" << SOURCE_LINE (lmo, location.gcc_location()); + return ss.str(); +} + // Stop getting locations. void -- cgit v1.1