2022-03-11 16:00:09 +00:00
|
|
|
#pragma once
|
2022-06-16 13:56:10 +00:00
|
|
|
#include "sapphirepch.h"
|
2022-03-11 16:00:09 +00:00
|
|
|
|
2022-06-08 17:59:14 +00:00
|
|
|
/* Struct to represent a location in a file. */
|
2022-03-11 16:00:09 +00:00
|
|
|
struct Location
|
|
|
|
{
|
2022-06-16 13:56:10 +00:00
|
|
|
int line;
|
|
|
|
int column;
|
|
|
|
std::string fname;
|
2022-03-11 16:00:09 +00:00
|
|
|
|
2022-06-16 13:56:10 +00:00
|
|
|
/* The location at which this location was imported, for error traces in imported files. */
|
|
|
|
std::shared_ptr<Location> parent = nullptr;
|
2022-03-11 16:00:09 +00:00
|
|
|
|
2022-06-16 13:56:10 +00:00
|
|
|
/* Creates a Location with the given parameters. */
|
|
|
|
Location(int ln, int col, std::string file);
|
2022-06-08 17:59:14 +00:00
|
|
|
|
2022-06-16 13:56:10 +00:00
|
|
|
~Location();
|
2022-03-11 16:00:09 +00:00
|
|
|
|
2022-06-16 13:56:10 +00:00
|
|
|
/* Returns a string of the format FILE:LINE:COL. */
|
|
|
|
std::string str() const;
|
|
|
|
/* Returns a string of the format (FILE:LINE:COL). */
|
|
|
|
std::string paren_str() const;
|
2022-06-08 17:59:14 +00:00
|
|
|
|
2022-06-16 13:56:10 +00:00
|
|
|
/* Advance to the next column in the file. */
|
|
|
|
void advance();
|
2022-06-08 17:59:14 +00:00
|
|
|
|
2022-06-16 13:56:10 +00:00
|
|
|
/* Advance to the next line if provided a newline. */
|
|
|
|
void pos_from_char(const char& character);
|
2022-03-11 16:00:09 +00:00
|
|
|
|
2022-06-16 13:56:10 +00:00
|
|
|
void operator=(const Location& other);
|
2022-03-11 16:00:09 +00:00
|
|
|
|
2022-06-16 13:56:10 +00:00
|
|
|
/* Copies the other location into this one. */
|
|
|
|
void copy(const Location& other);
|
2022-03-11 16:00:09 +00:00
|
|
|
};
|