diff options
author | Sanjoy Das <thedigitalangel@gmail.com> | 2011-11-29 19:10:50 +0000 |
---|---|---|
committer | Ian Lance Taylor <ian@gcc.gnu.org> | 2011-11-29 19:10:50 +0000 |
commit | 8afa2bfbdc60088acd7f199245244890a6e7773e (patch) | |
tree | f79cf7c9d2d4e5b74c516201a60c5753fe79c93f /gcc/go/go-linemap.cc | |
parent | 09ad58e618b0145ed98ee081ffc8117824390972 (diff) | |
download | gcc-8afa2bfbdc60088acd7f199245244890a6e7773e.zip gcc-8afa2bfbdc60088acd7f199245244890a6e7773e.tar.gz gcc-8afa2bfbdc60088acd7f199245244890a6e7773e.tar.bz2 |
compiler: Define and use backend-independent Location class.
From Sanjoy Das.
* go-location.h: New file.
* go-linemap.cc: New file.
* go-gcc.cc: Change all uses of source_location to Location.
* Make-lang.in (GO_OBJS): Add go/go-linemap.o.
(GO_LINEMAP_H): New variable.
(GO_LEX_H): Use $(GO_LINEMAP_H).
(GO_GOGO_H, GO_TYPES_H, GO_IMPORT_H): Likewise.
(go/go-linemap.o): New target.
Co-Authored-By: Ian Lance Taylor <iant@google.com>
From-SVN: r181813
Diffstat (limited to 'gcc/go/go-linemap.cc')
-rw-r--r-- | gcc/go/go-linemap.cc | 126 |
1 files changed, 126 insertions, 0 deletions
diff --git a/gcc/go/go-linemap.cc b/gcc/go/go-linemap.cc new file mode 100644 index 0000000..b41559e --- /dev/null +++ b/gcc/go/go-linemap.cc @@ -0,0 +1,126 @@ +// go-linemap.cc -- GCC implementation of Linemap. + +// Copyright 2011 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +#include "go-linemap.h" + +// This class implements the Linemap interface defined by the +// frontend. + +class Gcc_linemap : public Linemap +{ + public: + Gcc_linemap() + : Linemap(), + in_file_(false) + { } + + void + start_file(const char* file_name, unsigned int line_begin); + + void + start_line(unsigned int line_number, unsigned int line_size); + + Location + get_location(unsigned int column); + + void + stop(); + + protected: + Location + get_predeclared_location(); + + Location + get_unknown_location(); + + bool + is_predeclared(Location); + + bool + is_unknown(Location); + + private: + // Whether we are currently reading a file. + bool in_file_; +}; + +Linemap* Linemap::instance_ = NULL; + +// Start getting locations from a new file. + +void +Gcc_linemap::start_file(const char *file_name, unsigned line_begin) +{ + if (this->in_file_) + linemap_add(line_table, LC_LEAVE, 0, NULL, 0); + linemap_add(line_table, LC_ENTER, 0, file_name, line_begin); + this->in_file_ = true; +} + +// Stop getting locations. + +void +Gcc_linemap::stop() +{ + linemap_add(line_table, LC_LEAVE, 0, NULL, 0); + this->in_file_ = false; +} + +// Start a new line. + +void +Gcc_linemap::start_line(unsigned lineno, unsigned linesize) +{ + linemap_line_start(line_table, lineno, linesize); +} + +// Get a location. + +Location +Gcc_linemap::get_location(unsigned column) +{ + return Location(linemap_position_for_column(line_table, column)); +} + +// Get the unknown location. + +Location +Gcc_linemap::get_unknown_location() +{ + return Location(UNKNOWN_LOCATION); +} + +// Get the predeclared location. + +Location +Gcc_linemap::get_predeclared_location() +{ + return Location(BUILTINS_LOCATION); +} + +// Return whether a location is the predeclared location. + +bool +Gcc_linemap::is_predeclared(Location loc) +{ + return loc.gcc_location() == BUILTINS_LOCATION; +} + +// Return whether a location is the unknown location. + +bool +Gcc_linemap::is_unknown(Location loc) +{ + return loc.gcc_location() == UNKNOWN_LOCATION; +} + +// Return the Linemap to use for the gcc backend. + +Linemap* +go_get_linemap() +{ + return new Gcc_linemap; +} |