FE 0.13.1
Header-only C++ frontend library
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 ()=default
 Creates an invalid Location.
constexpr Loc (const Src *src, Pos begin, Pos end)
constexpr Loc (const Src *src, Pos pos)
 The empty Location at pos.
constexpr Loc (Pos begin, Pos end)
constexpr Loc (Pos pos)
constexpr Loc anew_begin () const
constexpr Loc anew_end () const
constexpr uint32_t size () const
constexpr Loc operator+ (Pos pos) const
constexpr Loc operator+ (Loc loc) const
 The hull of both Locations.
constexpr Loc operator& (Loc loc) const
 The overlap of both Locations - invalid if they are disjoint or sit in different files.
constexpr operator bool () const
 Is a valid Location?
constexpr bool operator== (Loc other) const
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 46 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 48 of file loc.h.

Constructor & Destructor Documentation

◆ Loc() [1/5]

fe::Loc::Loc ( )
constexprdefault

◆ Loc() [2/5]

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

Definition at line 56 of file loc.h.

References begin, end, and src.

◆ Loc() [3/5]

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

The empty Location at pos.

Definition at line 60 of file loc.h.

References Loc(), and src.

◆ Loc() [4/5]

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

Definition at line 62 of file loc.h.

References begin, end, and Loc().

◆ Loc() [5/5]

fe::Loc::Loc ( Pos pos)
inlineconstexpr

Definition at line 64 of file loc.h.

References Loc().

Member Function Documentation

◆ anew_begin()

Loc fe::Loc::anew_begin ( ) const
inlineconstexpr

Definition at line 67 of file loc.h.

References begin, Loc(), and src.

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

◆ anew_end()

Loc fe::Loc::anew_end ( ) const
inlineconstexpr

Definition at line 68 of file loc.h.

References end, Loc(), and src.

◆ dump()

void fe::Loc::dump ( ) const

◆ operator bool()

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

Is a valid Location?

Definition at line 88 of file loc.h.

References begin.

◆ operator&()

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

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 81 of file loc.h.

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

◆ operator+() [1/2]

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

The hull of both Locations.

Definition at line 74 of file loc.h.

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

◆ operator+() [2/2]

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

Definition at line 73 of file loc.h.

References begin, Loc(), and src.

◆ operator==()

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

Definition at line 90 of file loc.h.

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

◆ size()

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

Definition at line 69 of file loc.h.

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

◆ 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.

fe/loc.h only declares the stream output and dump helpers. Link fe-lib for the default implementation, or provide your own.

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 95 of file loc.h.

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

◆ src

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

Definition at line 93 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: