sapphire/src/Location.cpp

49 lines
983 B
C++
Raw Normal View History

#include "Location.h"
#include "FormatString/FormatString.hpp"
#include <sstream>
2022-08-26 10:00:14 +00:00
Location::Location(int line, int column, std::string filename)
: line(line), column(column), filename(std::move(filename))
{
}
Location::~Location()
{
}
2022-06-16 13:56:10 +00:00
std::string Location::str() const
{
2022-08-26 10:00:14 +00:00
return format_string("%s:%d:%d", filename, line, column);
}
void Location::advance()
{
2022-06-16 13:56:10 +00:00
++column;
}
void Location::pos_from_char(const char& character)
{
2022-06-16 13:56:10 +00:00
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))
{
}
2022-08-26 10:00:14 +00:00
Location Location::copy(const Location& other)
{
2022-08-26 10:00:14 +00:00
Location result(other.line, other.column, other.filename);
result.parent = other.parent;
return result;
}