diff options
author | Than McIntosh <thanm@google.com> | 2016-09-27 20:49:05 +0000 |
---|---|---|
committer | Ian Lance Taylor <ian@gcc.gnu.org> | 2016-09-27 20:49:05 +0000 |
commit | 437018ea2b6dc966ce40cd5dd684054126ddda6b (patch) | |
tree | 10cc817706743a8a7bea457f727d3ab9ee181ab8 /gcc/go/go-linemap.cc | |
parent | 6e39060a7f6f58dacf4e74762fd5dd85a5afb0d8 (diff) | |
download | gcc-437018ea2b6dc966ce40cd5dd684054126ddda6b.zip gcc-437018ea2b6dc966ce40cd5dd684054126ddda6b.tar.gz gcc-437018ea2b6dc966ce40cd5dd684054126ddda6b.tar.bz2 |
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
Diffstat (limited to 'gcc/go/go-linemap.cc')
-rw-r--r-- | gcc/go/go-linemap.cc | 28 |
1 files changed, 28 insertions, 0 deletions
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 |