56 lines
947 B
C++
56 lines
947 B
C++
|
#include "Location.h"
|
||
|
#include "StringConversion.h"
|
||
|
#include <sstream>
|
||
|
|
||
|
Location::Location(int ln, int col, std::string file)
|
||
|
: line(ln), column(col), fname(file)
|
||
|
{
|
||
|
}
|
||
|
|
||
|
Location::~Location()
|
||
|
{
|
||
|
}
|
||
|
|
||
|
std::string Location::to_string() const
|
||
|
{
|
||
|
std::ostringstream ss;
|
||
|
ss << fname;
|
||
|
ss << ":";
|
||
|
ss << int_to_string(line);
|
||
|
ss << ":";
|
||
|
ss << int_to_string(column);
|
||
|
return ss.str();
|
||
|
}
|
||
|
|
||
|
std::string Location::to_parenthesized_string() const
|
||
|
{
|
||
|
return "(" + this->to_string() + ")";
|
||
|
}
|
||
|
|
||
|
void Location::advance()
|
||
|
{
|
||
|
++column;
|
||
|
}
|
||
|
|
||
|
void Location::pos_from_char(const char& character)
|
||
|
{
|
||
|
if(character == '\n')
|
||
|
{
|
||
|
++line;
|
||
|
column = 0;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void Location::operator=(const Location &other)
|
||
|
{
|
||
|
this->parent = other.parent;
|
||
|
this->line = other.line;
|
||
|
this->column = other.column;
|
||
|
this->fname.assign(other.fname.c_str());
|
||
|
}
|
||
|
|
||
|
void Location::copy(const Location &other)
|
||
|
{
|
||
|
this->operator=(other);
|
||
|
}
|