#include "rust-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 ();
-
- std::string to_string (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)
+Linemap::start_file (const char *file_name, unsigned line_begin)
{
if (this->in_file_)
linemap_add (line_table, LC_LEAVE, 0, NULL, 0);
// Stringify a location
std::string
-Gcc_linemap::to_string (Location location)
+Linemap::to_string (Location location)
{
const line_map_ordinary *lmo;
location_t resolved_location;
// Stop getting locations.
void
-Gcc_linemap::stop ()
+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::start_line (unsigned lineno, unsigned linesize)
{
linemap_line_start (line_table, lineno, linesize);
}
// Get a location.
Location
-Gcc_linemap::get_location (unsigned column)
+Linemap::get_location (unsigned column)
{
return Location (linemap_position_for_column (line_table, column));
}
Linemap *
rust_get_linemap ()
{
- return new Gcc_linemap;
+ return new Linemap;
}
RichLocation::RichLocation (Location root) : gcc_rich_loc (line_table, root)
class Linemap
{
public:
- Linemap ()
+ Linemap () : in_file_ (false)
{
// Only one instance of Linemap is allowed to exist.
rust_assert (Linemap::instance_ == NULL);
Linemap::instance_ = this;
}
- virtual ~Linemap () { Linemap::instance_ = NULL; }
+ ~Linemap () { Linemap::instance_ = NULL; }
// Subsequent Location values will come from the file named
// FILE_NAME, starting at LINE_BEGIN. Normally LINE_BEGIN will be
// 0, but it will be non-zero if the Rust source has a //line comment.
- virtual void start_file (const char *file_name, unsigned int line_begin) = 0;
+ void start_file (const char *file_name, unsigned int line_begin);
// Subsequent Location values will come from the line LINE_NUMBER,
// in the current file. LINE_SIZE is the size of the line in bytes.
// This will normally be called for every line in a source file.
- virtual void start_line (unsigned int line_number, unsigned int line_size)
- = 0;
+ void start_line (unsigned int line_number, unsigned int line_size);
// Get a Location representing column position COLUMN on the current
// line in the current file.
- virtual Location get_location (unsigned int column) = 0;
+ Location get_location (unsigned int column);
// Stop generating Location values. This will be called after all
// input files have been read, in case any cleanup is required.
- virtual void stop () = 0;
+ void stop ();
// Produce a human-readable description of a Location, e.g.
// "foo.rust:10". Returns an empty string for predeclared, builtin or
// unknown locations.
- virtual std::string to_string (Location) = 0;
+ std::string to_string (Location);
protected:
// The single existing instance of Linemap.
rust_assert (Linemap::instance_ != NULL);
return Linemap::instance_->to_string (loc);
}
+
+private:
+ // Whether we are currently reading a file.
+ bool in_file_;
};
#endif // !defined(RUST_LINEMAP_H)