FE 0.13.1
Header-only C++ frontend library
Loading...
Searching...
No Matches
fe Namespace Reference

Namespaces

namespace  cli
 A small command-line parser for a single command - no subcommands.
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  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. 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...
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...
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  Tab
 Keeps track of indentation level during output. More...
class  Vector
 This is a thin wrapper for absl::InlinedVector<T, N, A> which is a drop-in replacement for std::vector<T, A>. 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  Formattable
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  Vectorlike
 Something which behaves like std::vector or std::array.

Typedefs

using ostream_formatter = basic_ostream_formatter<char>
template<class T, size_t N = std::dynamic_extent>
using View = Span<const T, N>
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, std::queue<detail::WorklistElem<Set>>>
template<class Set>
using DFSWorklist = Worklist<Set, std::stack<detail::WorklistElem<Set>>>
DbgMap/DbgSet
template<class V>
using DbgMap = std::unordered_map<Dbg, V, Dbg::Hash, Dbg::Eq>
using DbgSet = std::unordered_set<Dbg, Dbg::Hash, Dbg::Eq>
SymMap/SymSet

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

template<class V>
using SymMap = std::unordered_map<Sym, V, Sym::Hash, Sym::Eq>
using SymSet = std::unordered_set<Sym, Sym::Hash, Sym::Eq>

Functions

template<class T = std::logic_error, class... Args>
void throwf (std::format_string< Args... > fmt, Args &&... args)
 Throws a T (a std::logic_error by default) whose message is std::format(fmt, args...).
void unreachable ()
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<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
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={}) noexcept
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={}) noexcept
constexpr std::string_view subview (std::string_view s, size_t i, size_t n=std::string_view::npos) noexcept
 Like std::string::substr, but works on std::string_view and clamps i instead of throwing.
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)
template<class C, class K>
auto lookup (C &container, const K &key)
 Yields pointer to element (or the element itself if it is already a pointer), if found and nullptr otherwise.
template<class C, class K>
decltype(auto) assert_lookup (C &container, const K &key)
 Looks up key in container, asserts that it exists, and returns a reference to the mapped value.
template<class C, class... Args>
auto assert_emplace (C &container, Args &&... 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
Bit Mixers

These finalizers scramble a single word.

They are bijective, i.e., they don't introduce any collisions on their own - they merely spread the input bits.

constexpr uint32_t murmur3 (uint32_t h) noexcept
 MurmurHash3's 32-bit finalizer fmix32.
constexpr uint64_t splitmix64 (uint64_t h) noexcept
 SplitMix64's 64-bit finalizer.
constexpr size_t hash (size_t h) noexcept
 Mixes h with murmur3 or splitmix64 - whichever matches sizeof(size_t).
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 >
template<class I, class A = std::allocator<typename std::iterator_traits<I>::value_type>>
 Vector (I, I, A=A()) -> Vector< typename std::iterator_traits< I >::value_type, Default_Inlined_Size< typename std::iterator_traits< I >::value_type >, A >
erase
template<class T, size_t N, class A, class U>
Vector< T, N, A >::size_type erase (Vector< T, N, A > &c, const U &value)
template<class T, size_t N, class A, class Pred>
Vector< T, N, A >::size_type erase_if (Vector< T, N, A > &c, Pred pred)

Variables

template<class T>
static constexpr size_t Default_Inlined_Size = std::max((size_t)1, 4 * sizeof(size_t) / sizeof(T))
 Use up to 4 words (i.e., 4 * sizeof(size_t)) of inlined storage, rounded up.

FNV-1 Hash

See Wikipedia.

Use hash_begin to seed a hash chain and hash_combine to fold in one value after another:

auto h = fe::hash_begin(x);
for (auto elem : elems) h = fe::hash_combine(h, elem);
constexpr size_t hash_begin() noexcept
Seeds a hash chain with the FNV-1 offset basis.
Definition hash.h:64
constexpr size_t hash_combine(size_t seed, T v) noexcept
Mixes v into seed word-wise, reusing the FNV-1 prime as multiplier.
Definition hash.h:68
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.
constexpr size_t fnv1_offset = sizeof(size_t) == 4 ? size_t(UINT32_C(2166136261)) : size_t(UINT64_C(14695981039346656037))
 FNV-1 magic numbers for sizeof(size_t).
constexpr size_t fnv1_prime = sizeof(size_t) == 4 ? size_t(UINT32_C( 16777619)) : size_t(UINT64_C( 1099511628211))
constexpr size_t hash_begin () noexcept
 Seeds a hash chain with the FNV-1 offset basis.
template<std::integral T>
constexpr size_t hash_combine (size_t seed, T v) noexcept
 Mixes v into seed word-wise, reusing the FNV-1 prime as multiplier.
template<std::integral T>
constexpr size_t hash_begin (T v) noexcept
 Shorthand for hash_combine(hash_begin(), v).

Typedef Documentation

◆ BFSWorklist

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

Definition at line 78 of file worklist.h.

◆ DbgMap

template<class V>
using fe::DbgMap = std::unordered_map<Dbg, V, Dbg::Hash, Dbg::Eq>

Definition at line 93 of file dbg.h.

◆ DbgSet

using fe::DbgSet = std::unordered_set<Dbg, Dbg::Hash, Dbg::Eq>

Definition at line 94 of file dbg.h.

◆ DFSWorklist

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

Definition at line 80 of file worklist.h.

◆ ostream_formatter

Definition at line 64 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 39 of file src.h.

◆ SymMap

template<class V>
using fe::SymMap = std::unordered_map<Sym, V, Sym::Hash, Sym::Eq>

Definition at line 246 of file sym.h.

◆ SymSet

using fe::SymSet = std::unordered_set<Sym, Sym::Hash, Sym::Eq>

Definition at line 247 of file sym.h.

◆ View

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

Definition at line 106 of file span.h.

Function Documentation

◆ assert_emplace()

template<class C, class... Args>
auto fe::assert_emplace ( C & container,
Args &&... args )

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

Definition at line 63 of file container.h.

References assert_emplace(), and assert_unused.

Referenced by assert_emplace().

◆ assert_lookup()

template<class C, class K>
decltype(auto) fe::assert_lookup ( C & container,
const K & key )
nodiscard

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

Definition at line 55 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 = {} )
nodiscardconstexprnoexcept

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 = {} )
nodiscardconstexprnoexcept

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 41 of file assert.h.

References breakpoint().

Referenced by breakpoint().

◆ erase()

template<class T, size_t N, class A, class U>
Vector< T, N, A >::size_type fe::erase ( Vector< T, N, A > & c,
const U & value )

Definition at line 105 of file vector.h.

References erase().

Referenced by erase().

◆ erase_if()

template<class T, size_t N, class A, class Pred>
Vector< T, N, A >::size_type fe::erase_if ( Vector< T, N, A > & c,
Pred pred )

Definition at line 113 of file vector.h.

References erase_if().

Referenced by erase_if().

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

References find_and_replace().

Referenced by find_and_replace().

◆ 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 122 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()

size_t fe::hash ( size_t h)
constexprnoexcept

Mixes h with murmur3 or splitmix64 - whichever matches sizeof(size_t).

Definition at line 37 of file hash.h.

References hash(), murmur3(), and splitmix64().

Referenced by hash(), and hash_combine().

◆ hash_begin() [1/2]

size_t fe::hash_begin ( )
constexprnoexcept

Seeds a hash chain with the FNV-1 offset basis.

Definition at line 64 of file hash.h.

References fnv1_offset, and hash_begin().

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

◆ hash_begin() [2/2]

template<std::integral T>
size_t fe::hash_begin ( T v)
constexprnoexcept

Shorthand for hash_combine(hash_begin(), v).

Definition at line 74 of file hash.h.

References hash_begin(), and hash_combine().

◆ hash_combine()

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

Mixes v into seed word-wise, reusing the FNV-1 prime as multiplier.

Definition at line 68 of file hash.h.

References fnv1_prime, hash(), and hash_combine().

Referenced by fe::Bitset::hash(), hash_begin(), hash_combine(), fe::Dbg::Hash::operator()(), 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()

template<class C, class K>
auto fe::lookup ( C & container,
const K & key )
nodiscard

Yields pointer to element (or the element itself if it is already a pointer), if found and nullptr otherwise.

Constness of container carries over to the result.

Warning
If the element is not already a pointer, this lookup will simply take the address of this element. This means that, e.g., a rehash of an absl::flat_hash_map will invalidate this pointer.

Definition at line 45 of file container.h.

References lookup().

Referenced by lookup().

◆ murmur3()

uint32_t fe::murmur3 ( uint32_t h)
constexprnoexcept

MurmurHash3's 32-bit finalizer fmix32.

Definition at line 17 of file hash.h.

References murmur3().

Referenced by hash(), and murmur3().

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

◆ splitmix64()

uint64_t fe::splitmix64 ( uint64_t h)
constexprnoexcept

SplitMix64's 64-bit finalizer.

Definition at line 27 of file hash.h.

References splitmix64().

Referenced by hash(), and splitmix64().

◆ StreamFn()

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

◆ subview()

std::string_view fe::subview ( std::string_view s,
size_t i,
size_t n = std::string_view::npos )
nodiscardconstexprnoexcept

Like std::string::substr, but works on std::string_view and clamps i instead of throwing.

Definition at line 76 of file algo.h.

References subview().

Referenced by subview().

◆ throwf()

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

Throws a T (a std::logic_error by default) whose message is std::format(fmt, args...).

Use this for unrecoverable errors that should surface as a proper exception with a formatted message.

Definition at line 15 of file assert.h.

References 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().

◆ unreachable()

◆ Vector()

template<class I, class A = std::allocator<typename std::iterator_traits<I>::value_type>>
fe::Vector ( I ,
I ,
A = A() ) -> Vector< typename std::iterator_traits< I >::value_type, Default_Inlined_Size< typename std::iterator_traits< I >::value_type >, A >

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

Use up to 4 words (i.e., 4 * sizeof(size_t)) of inlined storage, rounded up.

Definition at line 21 of file vector.h.

Referenced by Vector().

◆ fnv1_offset

size_t fe::fnv1_offset = sizeof(size_t) == 4 ? size_t(UINT32_C(2166136261)) : size_t(UINT64_C(14695981039346656037))
inlineconstexpr

FNV-1 magic numbers for sizeof(size_t).

Definition at line 59 of file hash.h.

Referenced by hash_begin().

◆ fnv1_prime

size_t fe::fnv1_prime = sizeof(size_t) == 4 ? size_t(UINT32_C( 16777619)) : size_t(UINT64_C( 1099511628211))
inlineconstexpr

Definition at line 60 of file hash.h.

Referenced by hash_combine().