FE 0.6.1
A header-only C++ library for writing frontends
Loading...
Searching...
No Matches
loc.cpp.h
Go to the documentation of this file.
1#pragma once
2/// Default `Pos`/`Loc` stream output and dump helpers.
3/// Include this header in exactly one translation unit, or provide your own definitions instead.
4
5#include "fe/format.h"
6#include "fe/loc.h"
7
8namespace fe {
9
10std::ostream& operator<<(std::ostream& os, Pos pos) {
11 if (pos.row) {
12 if (pos.col) return os << pos.row << ':' << pos.col;
13 return os << pos.row;
14 }
15 return os << "<unknown position>";
16}
17
18std::ostream& operator<<(std::ostream& os, Loc loc) {
19 if (loc) {
20 os << (loc.path ? loc.path->string() : "<unknown file>") << ':' << loc.begin;
21 if (loc.begin != loc.finis) os << '-' << loc.finis;
22 return os;
23 }
24 return os << "<unknown location>";
25}
26
27void Pos::dump() const { std::cout << *this << std::endl; }
28void Loc::dump() const { std::cout << *this << std::endl; }
29
30} // namespace fe
Default Pos/Loc stream output and dump helpers.
Definition arena.h:13
std::ostream & operator<<(std::ostream &os, Pos pos)
Definition loc.cpp.h:10
void dump() const
Definition loc.cpp.h:28
Pos finis
It's called finis because it refers to the last character within this Location.
Definition loc.h:59
Loc()=default
Creates an invalid Location.
const std::filesystem::path * path
Definition loc.h:57
Pos begin
Definition loc.h:58
uint16_t col
Definition loc.h:23
Pos()=default
Creates an invalid Position.
uint16_t row
Definition loc.h:22
void dump() const
Definition loc.cpp.h:27