sapphire/src/Location.h

39 lines
967 B
C
Raw Normal View History

#pragma once
2022-06-16 13:56:10 +00:00
#include "sapphirepch.h"
/* Struct to represent a location in a file. */
struct Location
{
2022-06-16 13:56:10 +00:00
int line;
int column;
2022-08-26 10:00:14 +00:00
std::string filename;
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-06-16 13:56:10 +00:00
/* Creates a Location with the given parameters. */
2022-08-26 10:00:14 +00:00
Location(int line, int column, std::string filename);
Location(Location&& other);
Location(const Location& other);
Location operator=(const Location& other)
{
return Location(other);
}
2022-06-16 13:56:10 +00:00
~Location();
2022-06-16 13:56:10 +00:00
/* Returns a string of the format FILE:LINE:COL. */
std::string str() const;
2022-06-16 13:56:10 +00:00
/* Advance to the next column in the file. */
void advance();
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-08-26 10:00:14 +00:00
/* Returns a copy of the original Location. */
static Location copy(const Location& other);
};