FE 0.6.0
A header-only C++ library for writing frontends
Loading...
Searching...
No Matches
loc.cpp.h
Go to the documentation of this file.
1#include "fe/format.h"
2#include "fe/loc.h"
3
4namespace fe {
5
6std::ostream& operator<<(std::ostream& os, Pos pos) {
7 if (pos.row) {
8 if (pos.col) return os << pos.row << ':' << pos.col;
9 return os << pos.row;
10 }
11 return os << "<unknown position>";
12}
13
14std::ostream& operator<<(std::ostream& os, Loc loc) {
15 if (loc) {
16 os << (loc.path ? loc.path->string() : "<unknown file>") << ':' << loc.begin;
17 if (loc.begin != loc.finis) os << '-' << loc.finis;
18 return os;
19 }
20 return os << "<unknown location>";
21}
22
23void Pos::dump() const { std::cout << *this << std::endl; }
24void Loc::dump() const { std::cout << *this << std::endl; }
25
26} // namespace fe
Definition arena.h:9
std::ostream & operator<<(std::ostream &os, Pos pos)
Definition loc.cpp.h:6
Location in a File.
Definition loc.h:33
void dump() const
Definition loc.cpp.h:24
Pos finis
It's called finis because it refers to the last character within this Location.
Definition loc.h:57
const std::filesystem::path * path
Definition loc.h:55
Pos begin
Definition loc.h:56
Position in a source file; pass around as value.
Definition loc.h:10
uint16_t col
Definition loc.h:23
uint16_t row
Definition loc.h:22
void dump() const
Definition loc.cpp.h:23