2022-03-11 16:00:09 +00:00
|
|
|
#include "Location.h"
|
2022-08-25 18:02:23 +00:00
|
|
|
#include "FormatString/FormatString.hpp"
|
2022-03-11 16:00:09 +00:00
|
|
|
#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))
|
2022-03-11 16:00:09 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
Location::~Location()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-06-16 13:56:10 +00:00
|
|
|
std::string Location::str() const
|
2022-03-11 16:00:09 +00:00
|
|
|
{
|
2022-08-26 10:00:14 +00:00
|
|
|
return format_string("%s:%d:%d", filename, line, column);
|
2022-03-11 16:00:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Location::advance()
|
|
|
|
{
|
2022-06-16 13:56:10 +00:00
|
|
|
++column;
|
2022-03-11 16:00:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Location::pos_from_char(const char& character)
|
|
|
|
{
|
2022-06-16 13:56:10 +00:00
|
|
|
if (character == '\n')
|
|
|
|
{
|
|
|
|
++line;
|
|
|
|
column = 0;
|
|
|
|
}
|
2022-03-11 16:00:09 +00:00
|
|
|
}
|
|
|
|
|
2022-06-14 14:29:51 +00:00
|
|
|
void Location::operator=(const Location& other)
|
2022-03-11 16:00:09 +00:00
|
|
|
{
|
2022-08-26 10:00:14 +00:00
|
|
|
Location copied = copy(other);
|
|
|
|
line = copied.line;
|
|
|
|
column = copied.column;
|
|
|
|
parent = copied.parent;
|
|
|
|
filename = std::move(copied.filename);
|
2022-03-11 16:00:09 +00:00
|
|
|
}
|
|
|
|
|
2022-08-26 10:00:14 +00:00
|
|
|
Location Location::copy(const Location& other)
|
2022-03-11 16:00:09 +00:00
|
|
|
{
|
2022-08-26 10:00:14 +00:00
|
|
|
Location result(other.line, other.column, other.filename);
|
|
|
|
result.parent = other.parent;
|
|
|
|
return std::move(result);
|
2022-03-11 16:00:09 +00:00
|
|
|
}
|