49 lines
983 B
C++
49 lines
983 B
C++
#include "Location.h"
|
|
#include "FormatString/FormatString.hpp"
|
|
#include <sstream>
|
|
|
|
Location::Location(int line, int column, std::string filename)
|
|
: line(line), column(column), filename(std::move(filename))
|
|
{
|
|
}
|
|
|
|
Location::~Location()
|
|
{
|
|
}
|
|
|
|
std::string Location::str() const
|
|
{
|
|
return format_string("%s:%d:%d", filename, line, column);
|
|
}
|
|
|
|
void Location::advance()
|
|
{
|
|
++column;
|
|
}
|
|
|
|
void Location::pos_from_char(const char& character)
|
|
{
|
|
if (character == '\n')
|
|
{
|
|
++line;
|
|
column = 0;
|
|
}
|
|
}
|
|
|
|
Location::Location(const Location& other)
|
|
: line(other.line), column(other.column), filename(other.filename), parent(other.parent)
|
|
{
|
|
}
|
|
|
|
Location::Location(Location&& other)
|
|
: line(other.line), column(other.column), filename(std::move(other.filename)), parent(std::move(other.parent))
|
|
{
|
|
}
|
|
|
|
Location Location::copy(const Location& other)
|
|
{
|
|
Location result(other.line, other.column, other.filename);
|
|
result.parent = other.parent;
|
|
return result;
|
|
}
|