2017-04-05 08:06:18 +00:00
|
|
|
#pragma once
|
|
|
|
|
2018-02-02 05:31:56 +00:00
|
|
|
#include "maybe.h"
|
2017-05-19 07:02:01 +00:00
|
|
|
#include "serializer.h"
|
2017-07-19 07:12:04 +00:00
|
|
|
#include "utils.h"
|
2017-05-19 07:02:01 +00:00
|
|
|
|
2018-02-02 05:31:56 +00:00
|
|
|
#include <stdint.h>
|
|
|
|
#include <string>
|
|
|
|
|
2017-04-05 08:06:18 +00:00
|
|
|
struct Position {
|
2018-01-14 19:39:29 +00:00
|
|
|
int16_t line;
|
|
|
|
int16_t column;
|
2017-04-05 08:06:18 +00:00
|
|
|
|
|
|
|
Position();
|
2017-05-21 23:22:00 +00:00
|
|
|
Position(int16_t line, int16_t column);
|
2017-04-05 08:06:18 +00:00
|
|
|
explicit Position(const char* encoded);
|
|
|
|
|
2018-02-02 06:31:43 +00:00
|
|
|
bool HasValue() const { return line >= 0; }
|
2017-04-05 08:06:18 +00:00
|
|
|
std::string ToString();
|
|
|
|
std::string ToPrettyString(const std::string& filename);
|
|
|
|
|
|
|
|
// Compare two Positions and check if they are equal. Ignores the value of
|
|
|
|
// |interesting|.
|
|
|
|
bool operator==(const Position& that) const;
|
|
|
|
bool operator!=(const Position& that) const;
|
|
|
|
bool operator<(const Position& that) const;
|
|
|
|
};
|
2017-09-22 01:14:57 +00:00
|
|
|
static_assert(
|
|
|
|
sizeof(Position) == 4,
|
|
|
|
"Investigate, Position should be 32-bits for indexer size reasons");
|
2017-07-19 07:12:04 +00:00
|
|
|
MAKE_HASHABLE(Position, t.line, t.column);
|
2017-04-05 08:06:18 +00:00
|
|
|
|
|
|
|
struct Range {
|
|
|
|
Position start;
|
|
|
|
Position end;
|
|
|
|
|
|
|
|
Range();
|
2017-05-15 03:51:53 +00:00
|
|
|
explicit Range(Position position);
|
2017-04-19 05:28:33 +00:00
|
|
|
Range(Position start, Position end);
|
2017-04-05 08:06:18 +00:00
|
|
|
explicit Range(const char* encoded);
|
|
|
|
|
2018-02-02 06:31:43 +00:00
|
|
|
bool HasValue() const { return start.HasValue(); }
|
2017-04-11 05:43:01 +00:00
|
|
|
bool Contains(int line, int column) const;
|
2018-02-01 05:01:31 +00:00
|
|
|
Range RemovePrefix(Position position) const;
|
2017-04-11 05:43:01 +00:00
|
|
|
|
2017-04-05 08:06:18 +00:00
|
|
|
std::string ToString();
|
|
|
|
|
|
|
|
bool operator==(const Range& that) const;
|
|
|
|
bool operator!=(const Range& that) const;
|
|
|
|
bool operator<(const Range& that) const;
|
2017-05-19 07:02:01 +00:00
|
|
|
};
|
2017-07-19 07:12:04 +00:00
|
|
|
MAKE_HASHABLE(Range, t.start, t.end);
|
2017-05-19 07:02:01 +00:00
|
|
|
|
|
|
|
// Reflection
|
|
|
|
void Reflect(Reader& visitor, Position& value);
|
|
|
|
void Reflect(Writer& visitor, Position& value);
|
|
|
|
void Reflect(Reader& visitor, Range& value);
|
|
|
|
void Reflect(Writer& visitor, Range& value);
|