FE 0.15.0
A C++23 toolkit for writing compiler/interpreter frontends.
Loading...
Searching...
No Matches

Location within a Src: the half-open byte range [Loc::begin, Loc::end). More...

#include <fe/loc.h>

Public Types

enum class  Style {
  Full ,
  RowCol ,
  Row ,
  MSVC
}
 How much of a Loc a diagnostic spells out; see Diag::loc_style. More...

Public Member Functions

constexpr Loc () noexcept=default
 Creates an invalid Location.
constexpr Loc (const Src *src, Pos begin, Pos end) noexcept
constexpr Loc (const Src *src, Pos pos) noexcept
 The empty Location at pos.
constexpr Loc (Pos begin, Pos end) noexcept
constexpr Loc (Pos pos) noexcept
constexpr Loc anew_begin () const noexcept
constexpr Loc anew_end () const noexcept
constexpr uint32_t size () const noexcept
constexpr Loc operator+ (Pos pos) const noexcept
constexpr Loc operator+ (Loc loc) const noexcept
 The hull of both Locations.
constexpr Loc operator& (Loc loc) const noexcept
 The overlap of both Locations - invalid if they are disjoint or sit in different files.
constexpr operator bool () const noexcept
 Is a valid Location?
constexpr bool operator== (Loc other) const noexcept
void dump () const

Public Attributes

const Srcsrc = {}
Pos begin = {}
Pos end = {}
 It's called end because - just like an STL iterator - it refers to the byte one past the last one within this Location.

Friends

std::ostream & operator<< (std::ostream &os, Loc loc)
 Streams as path:row:col-row:col, resolved through Loc::src - or as raw offsets if it has none.

Detailed Description

Location within a Src: the half-open byte range [Loc::begin, Loc::end).

It's only two machine words on a 64 bit arch, so pass around as value. An empty range is a Location between two characters - what you want to point at when something is missing rather than wrong; see Loc::anew_end.

Warning
Loc::src is only a pointer and it is your job to guarantee that the underlying fe::Src outlives this Location; fe::SrcMap owns one for you.

Definition at line 42 of file loc.h.

Member Enumeration Documentation

◆ Style

enum class fe::Loc::Style
strong

How much of a Loc a diagnostic spells out; see Diag::loc_style.

Enumerator
Full 

path:row:col-row:col - the whole range.

RowCol 

path:row:col

Row 

path:row

MSVC 

path(row,col)

Definition at line 44 of file loc.h.

Constructor & Destructor Documentation

◆ Loc() [1/5]

fe::Loc::Loc ( )
constexprdefaultnoexcept

◆ Loc() [2/5]

fe::Loc::Loc ( const Src * src,
Pos begin,
Pos end )
inlineconstexprnoexcept

Definition at line 52 of file loc.h.

References begin, end, Loc(), and src.

◆ Loc() [3/5]

fe::Loc::Loc ( const Src * src,
Pos pos )
inlineconstexprnoexcept

The empty Location at pos.

Definition at line 56 of file loc.h.

References src.

◆ Loc() [4/5]

fe::Loc::Loc ( Pos begin,
Pos end )
inlineconstexprnoexcept

Definition at line 58 of file loc.h.

References begin, and end.

◆ Loc() [5/5]

fe::Loc::Loc ( Pos pos)
inlineconstexprnoexcept

Definition at line 60 of file loc.h.

Member Function Documentation

◆ anew_begin()

Loc fe::Loc::anew_begin ( ) const
inlineconstexprnoexcept

Definition at line 63 of file loc.h.

References begin, Loc(), and src.

Referenced by fe::Lexer< K, S >::start().

◆ anew_end()

Loc fe::Loc::anew_end ( ) const
inlineconstexprnoexcept

Definition at line 64 of file loc.h.

References end, Loc(), and src.

◆ dump()

void fe::Loc::dump ( ) const

◆ operator bool()

fe::Loc::operator bool ( ) const
inlineexplicitconstexprnoexcept

Is a valid Location?

Definition at line 84 of file loc.h.

References begin.

◆ operator&()

Loc fe::Loc::operator& ( Loc loc) const
inlineconstexprnoexcept

The overlap of both Locations - invalid if they are disjoint or sit in different files.

Dual to operator+; since an invalid Loc is falsy, if (a & b) also reads as "do they overlap?". An empty Loc overlaps nothing, not even itself.

Note
Loc::src is only compared via pointer equality - which is all it takes, as fe::SrcMap interns paths and hands out exactly one Src per file.

Definition at line 77 of file loc.h.

References begin, end, Loc(), and src.

◆ operator+() [1/2]

Loc fe::Loc::operator+ ( Loc loc) const
inlineconstexprnoexcept

The hull of both Locations.

Definition at line 70 of file loc.h.

References begin, Loc(), and src.

◆ operator+() [2/2]

Loc fe::Loc::operator+ ( Pos pos) const
inlineconstexprnoexcept

Definition at line 69 of file loc.h.

References begin, Loc(), and src.

◆ operator==()

bool fe::Loc::operator== ( Loc other) const
inlineconstexprnoexcept
Note
Loc::src is only checked via pointer equality.

Definition at line 86 of file loc.h.

References begin, end, Loc(), and src.

◆ size()

uint32_t fe::Loc::size ( ) const
inlineconstexprnoexcept

Definition at line 65 of file loc.h.

References begin, end, and fe::Pos::off.

Referenced by fe::Lexer< K, S >::view().

◆ operator<<

std::ostream & operator<< ( std::ostream & os,
Loc loc )
friend

Streams as path:row:col-row:col, resolved through Loc::src - or as raw offsets if it has none.

References Loc().

Member Data Documentation

◆ begin

◆ end

Pos fe::Loc::end = {}

It's called end because - just like an STL iterator - it refers to the byte one past the last one within this Location.

Definition at line 93 of file loc.h.

Referenced by fe::Lexer< K, S >::accept_while(), anew_end(), Loc(), Loc(), fe::Lexer< K, S >::next(), operator&(), operator==(), and size().

◆ src

const Src* fe::Loc::src = {}

Definition at line 91 of file loc.h.

Referenced by anew_begin(), anew_end(), Loc(), Loc(), operator&(), operator+(), operator+(), and operator==().


The documentation for this struct was generated from the following file: