2022-03-11 16:00:09 +00:00
|
|
|
#include "Location.h"
|
|
|
|
#include "StringConversion.h"
|
|
|
|
#include <sstream>
|
|
|
|
|
2022-06-14 14:29:51 +00:00
|
|
|
Location::Location(int ln, int col, std::string file) : line(ln), column(col), fname(file)
|
2022-03-11 16:00:09 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
Location::~Location()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string Location::to_string() const
|
|
|
|
{
|
2022-06-14 14:29:51 +00:00
|
|
|
std::ostringstream ss;
|
|
|
|
ss << fname;
|
|
|
|
ss << ":";
|
|
|
|
ss << int_to_string(line);
|
|
|
|
ss << ":";
|
|
|
|
ss << int_to_string(column);
|
|
|
|
return ss.str();
|
2022-03-11 16:00:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string Location::to_parenthesized_string() const
|
|
|
|
{
|
2022-06-14 14:29:51 +00:00
|
|
|
return "(" + this->to_string() + ")";
|
2022-03-11 16:00:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Location::advance()
|
|
|
|
{
|
2022-06-14 14:29:51 +00:00
|
|
|
++column;
|
2022-03-11 16:00:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Location::pos_from_char(const char& character)
|
|
|
|
{
|
2022-06-14 14:29:51 +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-06-14 14:29:51 +00:00
|
|
|
this->parent = other.parent;
|
|
|
|
this->line = other.line;
|
|
|
|
this->column = other.column;
|
|
|
|
this->fname.assign(other.fname.c_str());
|
2022-03-11 16:00:09 +00:00
|
|
|
}
|
|
|
|
|
2022-06-14 14:29:51 +00:00
|
|
|
void Location::copy(const Location& other)
|
2022-03-11 16:00:09 +00:00
|
|
|
{
|
2022-06-14 14:29:51 +00:00
|
|
|
this->operator=(other);
|
2022-03-11 16:00:09 +00:00
|
|
|
}
|