FE 0.16.1
Fast, Effecient FrontEnds
Loading...
Searching...
No Matches
fe Namespace Reference

Namespaces

namespace  dl
namespace  lct
namespace  sys
namespace  term
 Lightweight stream-based terminal colors for diagnostics and CLI output.
namespace  utf8
 UTF-8 helpers for decoding byte streams, encoding char32_t values, and running ASCII-style character classification on char32_t.

Classes

class  Arena
 An arena pre-allocates so-called pages of size Arena::page_size_. More...
struct  basic_ostream_formatter
 Make types that support ostream operators available for std::format. More...
class  Bitset
 A dynamically growing set of bits with small storage optimization. More...
class  Cite
 A borrowed fragment whose backticks stay markup; format_cite escapes every other argument. More...
class  Cited
 An owning message fragment that spells `citations` of its own; what format_cite yields. More...
class  Cli
 A small command-line parser for a single command - no subcommands. More...
class  CodeDiag
 The Diag a Driver installs by default: colors a `citation` and drops its backticks - or keeps them verbatim without color; \` is a literal backtick and \\ a literal backslash. More...
struct  Dbg
 The debug info of an entity: where it came from and what it was called. More...
class  DbgKey
 Opaque handle to a Dbg interned in a Driver; see Driver::dbg. More...
class  Diag
 How a diagnostic lays out - and how much of it an Error keeps. More...
struct  Driver
 Use/derive from this class for "global" variables that you need all over the place. More...
class  Error
 Collects diagnostics and hands each to the Diag that lays it out. More...
struct  is_bit_enum
class  Join
 Join elements of range with sep. More...
class  Lexer
 The blueprint for a lexer with a buffer of K tokens to peek into the future (Lexer::ahead). More...
struct  Loc
 Location within a Src: the half-open byte range [Loc::begin, Loc::end). More...
class  Log
 Facility to log what you are doing. More...
class  Parser
 The blueprint for a recursive descent/ ascent parser using a K lookahead of Tokens. More...
struct  PathHash
 Hashes a std::filesystem::path - consistent with its operator==, which compares lexically. More...
class  Patricia
 Hash-consed, immutable sets of D*, ordered by an unsigned id the elements carry themselves. More...
struct  Pos
 Byte offset into a Src; pass around as value. More...
class  Profiler
 Records wall-clock timings for (possibly nested) named Profiler::Spans and reports them in various formats. More...
class  Restore
 RAII guard that restores a value at the end of the scope. More...
class  Restore< T, nullptr, nullptr >
 Restores ref to its current value at the end of the scope. More...
class  Ring
 A ring buffer with N elements. More...
class  Ring< T, 1 >
 Specialization if N == 1 - doesn't need a ring. More...
class  Ring< T, 2 >
 Specialization if N == 2; doesn't need a ring, we just copy. More...
class  RuntimeCast
 Inherit from this class using CRTP, for some nice dynamic_cast-style wrappers. More...
struct  Snippet
 The underlined source excerpt that goes below a diagnostic. More...
class  Span
 This is a thin wrapper for std::span<T, N> with the following additional features: More...
class  Src
 The content of one source file together with the offsets its rows start at. More...
class  SrcMap
 Interns the text - and the std::filesystem::path - of every file a Loc may point into. More...
class  StreamFn
 Wrap a callable f(std::ostream&) -> std::ostream& so it streams via operator<< and std::format. More...
struct  StrHash
 Hashes the characters of a string; transparent, so std::string keys may be looked up by std::string_view. More...
class  Sym
 A Symbol just wraps a pointer to Sym::String, so pass Sym itself around as value. More...
class  SymPool
 Hash set where all strings - wrapped in Symbol - live in. More...
class  SymTab
 A fixed-capacity Symbol -> V map for a closed set of Size entries: filled once, then only looked up - a Lexer's reserved words, say. More...
class  Tab
 Keeps track of indentation level during output. More...
class  Vector
 This is a thin wrapper for ankerl::svector<T, N, A> which is a drop-in replacement for std::vector<T, A>. More...
class  VectorQueue
 A FIFO queue over a Vector. More...
class  VLA
 CRTP base that gives Self one VLA per element type in Self::VLA_Types directly behind it in memory - the C flexible array member, generalized to several arrays of different type. More...
class  Worklist
 A worklist that pushes each element at most once. More...
class  XTrie
 Hash-consed sets of D*. More...

Concepts

concept  BitEnum
concept  Diagnosable
 Every frontend building block reports into the Error of S::driver.
concept  Formattable
concept  Lexable
 What fe::Parser needs of its CRTP child S beyond fe::Diagnosable: the Lexer to pull Tokens from.
concept  Nodeable
concept  NodeSetable
 Like Nodeable, but for a class that spans a set of node kinds instead of a single one.
concept  Queuelike
 Something which behaves like std::queue.
concept  Stacklike
 Something which behaves like std::stack or std::priority_queue.
concept  Token
 What fe::Parser needs of its Token type: a Tag and a Loc, copied in and out of the lookahead by value.
concept  Vectorlike
 Something which behaves like std::vector or std::array.
concept  VLAed
 Does T carry VLAs?

Typedefs

using ostream_formatter = basic_ostream_formatter<char>
template<class T, size_t N = std::dynamic_extent>
using View = Span<const T, N>
 Read-only Span; use Span itself, if you want to write through its elements.
template<class V>
using PathMap = std::unordered_map<std::filesystem::path, V, PathHash>
 Maps a std::filesystem::path to V.
template<class Set>
using BFSWorklist = Worklist<Set, VectorQueue<detail::WorklistElem<Set>>>
template<class Set>
using DFSWorklist = Worklist<Set, std::stack<detail::WorklistElem<Set>, Vector<detail::WorklistElem<Set>>>>
template<class... Args>
using cite_string
 <
DbgMap/DbgSet
template<class V>
using DbgMap = ankerl::unordered_dense::map<Dbg, V, Dbg::Hash, Dbg::Eq>
using DbgSet = ankerl::unordered_dense::set<Dbg, Dbg::Hash, Dbg::Eq>
StrMap/StrSet

Keyed by std::string but also looked up by std::string_view or const char* without building a std::string.

template<class V>
using StrMap = ankerl::unordered_dense::map<std::string, V, StrHash, std::equal_to<>>
using StrSet = ankerl::unordered_dense::set<std::string, StrHash, std::equal_to<>>
SymMap/SymSet

Set/Map is keyed by pointer - which is hashed in SymPool.

template<class V>
using SymMap = ankerl::unordered_dense::map<Sym, V, Sym::Hash, Sym::Eq>
using SymSet = ankerl::unordered_dense::set<Sym, Sym::Hash, Sym::Eq>

Functions

void breakpoint ()
 Raise a breakpoint in the debugger.
FE_API std::ostream & operator<< (std::ostream &, Diag::Tag)
template<fe::BitEnum E>
constexpr bool has_flag (E value, E flag) noexcept
template<class F>
 StreamFn (F) -> StreamFn< F >
template<class R>
 Join (R &&, std::string_view=", ") -> Join< R >
template<std::integral T>
constexpr size_t hash_combine (size_t seed, T v) noexcept
 Folds v into seed like ankerl::unordered_dense hashes a tuple: one 128-bit multiply, halves xored.
template<class T>
 Restore (T &, T) -> Restore< T >
 The primary template has no two-argument constructor to deduce this one from.
template<size_t I, class T, size_t N>
requires (N != std::dynamic_extent)
constexpr decltype(auto) get (Span< T, N > span) noexcept
template<class T = std::logic_error, class... Args>
void throwf (cite_string< Args... > fmt, Args &&... args)
 <
template<class... Args>
Cited format_cite (cite_string< Args... > fmt, Args &&... args)
 <
Utility Functions
template<class D, class S>
requires (std::is_trivially_copyable_v<S> && std::is_trivially_copyable_v<D>)
constexpr D bitcast_resize (const S &src) noexcept
 A bitcast from src of type S to D, supporting different sizes.
constexpr std::uint64_t pad (std::uint64_t offset, std::uint64_t align) noexcept
 Rounds offset up to the next multiple of align.
constexpr bool is_aligned (std::uint64_t offset, std::uint64_t align) noexcept
Algorithms
template<std::random_access_iterator I, class T, class L = std::less<>>
constexpr I binary_find (I begin, I end, const T &val, L lt={})
template<std::ranges::random_access_range R, class T, class L = std::less<>>
requires std::ranges::common_range<R>
constexpr auto binary_find (R &&r, const T &val, L lt={})
void find_and_replace (std::string &str, std::string_view what, std::string_view repl)
 Replaces all occurrences of what with repl.
Helpers for Containers
template<Stacklike S>
S::value_type pop (S &s)
template<Queuelike Q>
Q::value_type pop (Q &q)
auto lookup (auto &container, const auto &key)
 Yields a pointer to the value mapped to key (or the value itself if it is a pointer) or nullptr if not found.
decltype(auto) assert_lookup (auto &container, const auto &key)
 Looks up key in container, asserts that it exists, and returns a reference to the mapped value.
auto assert_emplace (auto &container, auto &&... args)
 Invokes emplace on container, asserts that insertion actually happened, and returns the iterator.
Bit operations for enum classs

Provides all kind of bit and comparison operators for an enum class E.

Use like this:

enum class MyEnum : unsigned {
A = 1 << 0,
B = 1 << 1,
C = 1 << 2,
};
template<> struct fe::is_bit_enum<MyEnum> : std::true_type {};
template<fe::BitEnum E>
constexpr auto to_underlying (E e) noexcept
Deduction Guides
template<class I, class E>
 Span (I, E) -> Span< std::remove_reference_t< std::iter_reference_t< I > > >
template<class T, size_t N>
 Span (T(&)[N]) -> Span< T, N >
template<class T, size_t N>
 Span (std::array< T, N > &) -> Span< T, N >
template<class T, size_t N>
 Span (const std::array< T, N > &) -> Span< const T, N >
template<class R>
 Span (R &&) -> Span< std::remove_reference_t< std::ranges::range_reference_t< R > > >
template<Vectorlike Vec>
 Span (Vec &) -> Span< typename Vec::value_type, std::dynamic_extent >
template<Vectorlike Vec>
 Span (const Vec &) -> Span< const typename Vec::value_type, std::dynamic_extent >

Variables

template<class T>
static constexpr size_t Default_Inlined_Size = std::max((size_t)1, 4 * sizeof(size_t) / sizeof(T))
 Aims at 4 words (i.e., 4 * sizeof(size_t)) of inlined storage; svector's one-byte tag makes the object a word larger.

Typedef Documentation

◆ BFSWorklist

template<class Set>
using fe::BFSWorklist = Worklist<Set, VectorQueue<detail::WorklistElem<Set>>>

Definition at line 115 of file worklist.h.

◆ cite_string

template<class... Args>
using fe::term::cite_string

<

A borrowed fragment whose backticks stay markup; format_cite escapes every other argument.

A literal and a Cited convert implicitly - both are text someone wrote as markup. Runtime text has to say so: spell it Cite(s), so data never becomes markup by accident. A const char* - a ternary of two literals, say - counts as runtime text and needs Cite(s) too.

Warning
Borrows its text like a std::string_view does - a Cited outlives the expression, a Cite does not.

Definition at line 237 of file term.h.

◆ DbgMap

template<class V>
using fe::DbgMap = ankerl::unordered_dense::map<Dbg, V, Dbg::Hash, Dbg::Eq>

Definition at line 74 of file dbg.h.

◆ DbgSet

using fe::DbgSet = ankerl::unordered_dense::set<Dbg, Dbg::Hash, Dbg::Eq>

Definition at line 75 of file dbg.h.

◆ DFSWorklist

template<class Set>
using fe::DFSWorklist = Worklist<Set, std::stack<detail::WorklistElem<Set>, Vector<detail::WorklistElem<Set>>>>

Definition at line 117 of file worklist.h.

◆ ostream_formatter

Definition at line 61 of file format.h.

◆ PathMap

template<class V>
using fe::PathMap = std::unordered_map<std::filesystem::path, V, PathHash>

Maps a std::filesystem::path to V.

Warning
Node-based on purpose: fe::SrcMap stores its Srcs in here and a Loc points to one, so the values must never move.

Definition at line 26 of file src.h.

◆ StrMap

template<class V>
using fe::StrMap = ankerl::unordered_dense::map<std::string, V, StrHash, std::equal_to<>>

Definition at line 59 of file hash.h.

◆ StrSet

using fe::StrSet = ankerl::unordered_dense::set<std::string, StrHash, std::equal_to<>>

Definition at line 60 of file hash.h.

◆ SymMap

template<class V>
using fe::SymMap = ankerl::unordered_dense::map<Sym, V, Sym::Hash, Sym::Eq>

Definition at line 210 of file sym.h.

◆ SymSet

using fe::SymSet = ankerl::unordered_dense::set<Sym, Sym::Hash, Sym::Eq>

Definition at line 211 of file sym.h.

◆ View

template<class T, size_t N = std::dynamic_extent>
using fe::View = Span<const T, N>

Read-only Span; use Span itself, if you want to write through its elements.

Definition at line 107 of file span.h.

Function Documentation

◆ assert_emplace()

auto fe::assert_emplace ( auto & container,
auto &&... args )

Invokes emplace on container, asserts that insertion actually happened, and returns the iterator.

Definition at line 61 of file container.h.

References assert_emplace(), and assert_unused.

Referenced by assert_emplace().

◆ assert_lookup()

decltype(auto) fe::assert_lookup ( auto & container,
const auto & key )
nodiscard

Looks up key in container, asserts that it exists, and returns a reference to the mapped value.

Definition at line 54 of file container.h.

References assert_lookup().

Referenced by assert_lookup().

◆ binary_find() [1/2]

template<std::random_access_iterator I, class T, class L = std::less<>>
I fe::binary_find ( I begin,
I end,
const T & val,
L lt = {} )
nodiscardconstexpr

Definition at line 59 of file algo.h.

References binary_find().

Referenced by binary_find(), and binary_find().

◆ binary_find() [2/2]

template<std::ranges::random_access_range R, class T, class L = std::less<>>
requires std::ranges::common_range<R>
auto fe::binary_find ( R && r,
const T & val,
L lt = {} )
nodiscardconstexpr

Definition at line 69 of file algo.h.

References binary_find().

◆ bitcast_resize()

template<class D, class S>
requires (std::is_trivially_copyable_v<S> && std::is_trivially_copyable_v<D>)
D fe::bitcast_resize ( const S & src)
constexprnoexcept

A bitcast from src of type S to D, supporting different sizes.

Keeps the low-order bytes on either endianness: a wider D zero-fills the rest, a narrower one truncates.

Definition at line 26 of file algo.h.

References bitcast_resize().

Referenced by bitcast_resize().

◆ breakpoint()

void fe::breakpoint ( )
inline

Raise a breakpoint in the debugger.

Definition at line 12 of file assert.h.

References breakpoint().

Referenced by breakpoint(), and fe::Log::level2color().

◆ find_and_replace()

void fe::find_and_replace ( std::string & str,
std::string_view what,
std::string_view repl )
inline

Replaces all occurrences of what with repl.

Definition at line 74 of file algo.h.

References find_and_replace().

Referenced by find_and_replace().

◆ format_cite()

template<class... Args>
Cited fe::term::format_cite ( cite_string< Args... > fmt,
Args &&... args )

<

An owning message fragment that spells `citations` of its own; what format_cite yields.

Return this from a helper that assembles a fragment, and it stays valid wherever a Cite may go.

Definition at line 242 of file term.h.

Referenced by fe::Parser< Tok, Tag, K, S >::expect(), fe::RuntimeCast< B >::expect(), and fe::Parser< Tok, Tag, K, S >::tag2str_().

◆ get()

template<size_t I, class T, size_t N>
requires (N != std::dynamic_extent)
decltype(auto) fe::get ( Span< T, N > span)
constexprnoexcept

Definition at line 123 of file span.h.

References get().

Referenced by get().

◆ has_flag()

template<fe::BitEnum E>
bool fe::has_flag ( E value,
E flag )
constexprnoexcept
Note
flag must have at least one bit set; has_flag(value, E{}) would be vacuously true. flag is a runtime value, so this is a runtime assert rather than a static_assert (in a constexpr evaluation a zero flag turns it into a compile-time error all the same).

Definition at line 47 of file enum.h.

References has_flag(), and to_underlying().

Referenced by has_flag().

◆ hash_combine()

template<std::integral T>
size_t fe::hash_combine ( size_t seed,
T v )
constexprnoexcept

Folds v into seed like ankerl::unordered_dense hashes a tuple: one 128-bit multiply, halves xored.

Each step avalanches, so a chain needs no finalizer and suits a hasher that declares is_avalanching. Seed a chain with 0:

size_t h = 0;
for (auto elem : elems) h = fe::hash_combine(h, elem);
constexpr size_t hash_combine(size_t seed, T v) noexcept
Folds v into seed like ankerl::unordered_dense hashes a tuple: one 128-bit multiply,...
Definition hash.h:26
Note
These hashes are not stable: they differ between 32- and 64-bit builds and may change between fe releases. Never serialize them and never rely on the iteration order they induce.

Definition at line 26 of file hash.h.

References hash_combine().

Referenced by fe::Bitset::hash(), hash_combine(), and fe::XTrie< D, K, N >::Data::Hash::operator()().

◆ is_aligned()

bool fe::is_aligned ( std::uint64_t offset,
std::uint64_t align )
nodiscardconstexprnoexcept

Definition at line 50 of file algo.h.

References is_aligned().

Referenced by is_aligned().

◆ Join()

template<class R>
fe::Join ( R && ,
std::string_view = ", " ) -> Join< R >

◆ lookup()

auto fe::lookup ( auto & container,
const auto & key )
nodiscard

Yields a pointer to the value mapped to key (or the value itself if it is a pointer) or nullptr if not found.

Constness of container carries over to the result.

Warning
If the mapped value is not already a pointer, this lookup will simply take its address. This means that, e.g., a rehash of an ankerl::unordered_dense::map will invalidate this pointer.

Definition at line 45 of file container.h.

References lookup().

Referenced by lookup().

◆ operator<<()

FE_API std::ostream & fe::operator<< ( std::ostream & ,
Diag::Tag  )

References operator<<().

Referenced by operator<<().

◆ pad()

std::uint64_t fe::pad ( std::uint64_t offset,
std::uint64_t align )
nodiscardconstexprnoexcept

Rounds offset up to the next multiple of align.

Definition at line 42 of file algo.h.

References pad().

Referenced by pad().

◆ pop() [1/2]

template<Queuelike Q>
Q::value_type fe::pop ( Q & q)
nodiscard

Definition at line 35 of file container.h.

References pop().

◆ pop() [2/2]

template<Stacklike S>
S::value_type fe::pop ( S & s)
nodiscard

Definition at line 27 of file container.h.

References pop().

Referenced by pop(), pop(), and fe::Worklist< Set, C >::pop().

◆ Restore()

template<class T>
fe::Restore ( T & ,
T  ) -> Restore< T >

The primary template has no two-argument constructor to deduce this one from.

◆ Span() [1/7]

template<class T, size_t N>
fe::Span ( const std::array< T, N > & ) -> Span< const T, N >

◆ Span() [2/7]

template<Vectorlike Vec>
fe::Span ( const Vec & ) -> Span< const typename Vec::value_type, std::dynamic_extent >

◆ Span() [3/7]

template<class I, class E>
fe::Span ( I ,
E  ) -> Span< std::remove_reference_t< std::iter_reference_t< I > > >

◆ Span() [4/7]

template<class R>
fe::Span ( R && ) -> Span< std::remove_reference_t< std::ranges::range_reference_t< R > > >

◆ Span() [5/7]

template<class T, size_t N>
fe::Span ( std::array< T, N > & ) -> Span< T, N >

◆ Span() [6/7]

template<class T, size_t N>
fe::Span ( T(&) [N]) -> Span< T, N >

◆ Span() [7/7]

template<Vectorlike Vec>
fe::Span ( Vec & ) -> Span< typename Vec::value_type, std::dynamic_extent >

◆ StreamFn()

template<class F>
fe::StreamFn ( F ) -> StreamFn< F >

◆ throwf()

template<class T = std::logic_error, class... Args>
void fe::throwf ( cite_string< Args... > fmt,
Args &&... args )

<

std::format for a message that follows that convention; assemble a fragment of your own with it.

The Cited it yields is markup wherever it is used as an argument again - no re-wrapping needed. Throws a T (a std::logic_error by default) whose message is format_cite(fmt, args...). Use this for unrecoverable errors that should surface as a proper exception with a formatted message. The message is rendered here, so - like fe::Error::Bail - the what() is finished text a generic handler may print as is, not markup someone else still has to resolve. Colors follow term::auto_detached, just like the message fe::Log builds in a detached buffer.

Definition at line 274 of file term.h.

References fe::term::Red, fe::term::render_cite(), fe::term::Reset, and throwf().

Referenced by fe::RuntimeCast< B >::expect(), and throwf().

◆ to_underlying()

template<fe::BitEnum E>
auto fe::to_underlying ( E e)
constexprnoexcept

Definition at line 28 of file enum.h.

References to_underlying().

Referenced by has_flag(), operator&(), operator^(), operator|(), and to_underlying().

Variable Documentation

◆ Default_Inlined_Size

template<class T>
size_t fe::Default_Inlined_Size = std::max((size_t)1, 4 * sizeof(size_t) / sizeof(T))
staticconstexpr

Aims at 4 words (i.e., 4 * sizeof(size_t)) of inlined storage; svector's one-byte tag makes the object a word larger.

Definition at line 18 of file vector.h.