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

A Symbol just wraps a pointer to Sym::String, so pass Sym itself around as value. More...

#include <fe/sym.h>

Classes

struct  String
struct  Hash
struct  Eq

Public Member Functions

constexpr Sym () noexcept=default
Getters
constexpr bool empty () const noexcept
constexpr size_t size () const noexcept
constexpr uintptr_t raw () const noexcept
Access
constexpr char operator[] (size_t i) const noexcept
constexpr char front () const noexcept
constexpr char back () const noexcept
Iterators
constexpr auto begin () const noexcept
constexpr auto end () const noexcept
constexpr auto cbegin () const noexcept
constexpr auto cend () const noexcept
constexpr auto rbegin () const noexcept
constexpr auto rend () const noexcept
constexpr auto crbegin () const noexcept
constexpr auto crend () const noexcept
Conversions
constexpr std::string_view view () const noexcept
constexpr operator std::string_view () const noexcept
constexpr std::string_view operator* () const noexcept
constexpr std::string str () const
 This involves a copy.
constexpr operator std::string () const
 explicit as this involves a copy.
constexpr operator bool () const noexcept
 Is not empty?

Static Public Attributes

static constexpr size_t Short_String_Bytes = sizeof(uintptr_t)
static constexpr size_t Short_String_Mask = Short_String_Bytes - 1

Friends

struct ::std::hash< fe::Sym >
class SymPool
template<class H>
constexpr H AbslHashValue (H h, Sym sym) noexcept
std::ostream & operator<< (std::ostream &os, Sym sym)
Comparison: Sym w/ Sym
constexpr auto operator<=> (Sym s1, Sym s2) noexcept
constexpr bool operator== (Sym s1, Sym s2) noexcept
Comparison: Sym w/ char
constexpr std::strong_ordering operator<=> (Sym s, char c) noexcept
constexpr std::strong_ordering operator<=> (char c, Sym s) noexcept
constexpr bool operator== (Sym s, char c) noexcept
constexpr bool operator== (char c, Sym s) noexcept
Comparison: Sym w/ convertible to std::string_view
constexpr auto operator<=> (Sym lhs, const std::convertible_to< std::string_view > auto &rhs) noexcept
constexpr auto operator<=> (const std::convertible_to< std::string_view > auto &lhs, Sym rhs) noexcept
constexpr bool operator== (Sym lhs, const std::convertible_to< std::string_view > auto &rhs) noexcept
constexpr bool operator== (const std::convertible_to< std::string_view > auto &lhs, Sym rhs) noexcept

Detailed Description

A Symbol just wraps a pointer to Sym::String, so pass Sym itself around as value.

Retrieving a std::string_view (via Sym::view) is basically free. You can also obtain a std::string (via Sym::str), but this involves a copy. The characters are not null-terminated. With the exception of the empty string, you should only create Symbols via SymPool::sym. This in turn will toss all Symbols into a big hash set. This makes Sym::operator== and Sym::operator!= an O(1) operation. The empty string is internally handled as nullptr. Thus, you can create a Symbol representing an empty string without having access to the SymPool.

Note
The empty std::string/std::string_view and nullptr are all identified as Sym::Sym().
Warning
Big endian version has not been tested.

Definition at line 37 of file sym.h.

Constructor & Destructor Documentation

◆ Sym()

fe::Sym::Sym ( )
constexprdefaultnoexcept

Referenced by fe::SymPool::sym().

Member Function Documentation

◆ back()

char fe::Sym::back ( ) const
inlineconstexprnoexcept

Definition at line 99 of file sym.h.

References size().

◆ begin()

auto fe::Sym::begin ( ) const
inlineconstexprnoexcept

Definition at line 104 of file sym.h.

References view().

Referenced by cbegin(), end(), and rend().

◆ cbegin()

auto fe::Sym::cbegin ( ) const
inlineconstexprnoexcept

Definition at line 106 of file sym.h.

References begin().

◆ cend()

auto fe::Sym::cend ( ) const
inlineconstexprnoexcept

Definition at line 107 of file sym.h.

References end().

◆ crbegin()

auto fe::Sym::crbegin ( ) const
inlineconstexprnoexcept

Definition at line 110 of file sym.h.

References rbegin().

◆ crend()

auto fe::Sym::crend ( ) const
inlineconstexprnoexcept

Definition at line 111 of file sym.h.

References rend().

◆ empty()

bool fe::Sym::empty ( ) const
inlinenodiscardconstexprnoexcept

Definition at line 83 of file sym.h.

References empty().

Referenced by fe::SymTab< V, Size >::emplace(), empty(), fe::SymTab< V, Size >::find(), size(), and view().

◆ end()

auto fe::Sym::end ( ) const
inlineconstexprnoexcept

Definition at line 105 of file sym.h.

References begin(), and size().

Referenced by cend(), and rbegin().

◆ front()

char fe::Sym::front ( ) const
inlineconstexprnoexcept

Definition at line 98 of file sym.h.

◆ operator bool()

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

Is not empty?

Definition at line 167 of file sym.h.

◆ operator std::string()

fe::Sym::operator std::string ( ) const
inlineexplicitconstexpr

explicit as this involves a copy.

Definition at line 166 of file sym.h.

References str().

◆ operator std::string_view()

fe::Sym::operator std::string_view ( ) const
inlineconstexprnoexcept

Definition at line 160 of file sym.h.

References view().

◆ operator*()

std::string_view fe::Sym::operator* ( ) const
inlineconstexprnoexcept

Definition at line 161 of file sym.h.

References view().

◆ operator[]()

char fe::Sym::operator[] ( size_t i) const
inlineconstexprnoexcept

Definition at line 94 of file sym.h.

References size(), and view().

◆ raw()

uintptr_t fe::Sym::raw ( ) const
inlinenodiscardconstexprnoexcept

Definition at line 89 of file sym.h.

◆ rbegin()

auto fe::Sym::rbegin ( ) const
inlineconstexprnoexcept

Definition at line 108 of file sym.h.

References end().

Referenced by crbegin().

◆ rend()

auto fe::Sym::rend ( ) const
inlineconstexprnoexcept

Definition at line 109 of file sym.h.

References begin().

Referenced by crend().

◆ size()

size_t fe::Sym::size ( ) const
inlinenodiscardconstexprnoexcept

Definition at line 84 of file sym.h.

References empty(), Short_String_Mask, and size().

Referenced by back(), end(), operator[](), size(), and view().

◆ str()

std::string fe::Sym::str ( ) const
inlineconstexpr

This involves a copy.

Definition at line 165 of file sym.h.

References view().

Referenced by operator std::string().

◆ view()

std::string_view fe::Sym::view ( ) const
inlinenodiscardconstexprnoexcept
Warning
For a short Symbol (size < Sym::Short_String_Bytes) the characters are stored inline within this object's ptr_, so the returned view points into this Symbol and is only valid as long as it lives - it dangles for a temporary (e.g. pool.sym("ab").view()). Use Sym::str if the string must outlive the Symbol.

Definition at line 151 of file sym.h.

References empty(), Short_String_Mask, and size().

Referenced by begin(), operator std::string_view(), operator*(), operator[](), and str().

◆ ::std::hash< fe::Sym >

friend struct ::std::hash< fe::Sym >
friend

Definition at line 171 of file sym.h.

References AbslHashValue.

◆ AbslHashValue

template<class H>
H AbslHashValue ( H h,
Sym sym )
friend

Definition at line 171 of file sym.h.

Referenced by ::std::hash< fe::Sym >.

◆ operator<<

std::ostream & operator<< ( std::ostream & os,
Sym sym )
friend

◆ operator<=> [1/5]

std::strong_ordering operator<=> ( char c,
Sym s )
friend

Definition at line 123 of file sym.h.

◆ operator<=> [2/5]

auto operator<=> ( const std::convertible_to< std::string_view > auto & lhs,
Sym rhs )
friend

Definition at line 133 of file sym.h.

◆ operator<=> [3/5]

auto operator<=> ( Sym lhs,
const std::convertible_to< std::string_view > auto & rhs )
friend

Definition at line 130 of file sym.h.

◆ operator<=> [4/5]

std::strong_ordering operator<=> ( Sym s,
char c )
friend

Definition at line 122 of file sym.h.

◆ operator<=> [5/5]

auto operator<=> ( Sym s1,
Sym s2 )
friend

Definition at line 116 of file sym.h.

◆ operator== [1/5]

bool operator== ( char c,
Sym s )
friend

Definition at line 125 of file sym.h.

◆ operator== [2/5]

bool operator== ( const std::convertible_to< std::string_view > auto & lhs,
Sym rhs )
friend

Definition at line 141 of file sym.h.

◆ operator== [3/5]

bool operator== ( Sym lhs,
const std::convertible_to< std::string_view > auto & rhs )
friend

Definition at line 137 of file sym.h.

◆ operator== [4/5]

bool operator== ( Sym s,
char c )
friend

Definition at line 124 of file sym.h.

◆ operator== [5/5]

bool operator== ( Sym s1,
Sym s2 )
friend

Definition at line 117 of file sym.h.

◆ SymPool

friend class SymPool
friend

Definition at line 209 of file sym.h.

References SymPool.

Referenced by SymPool.

Member Data Documentation

◆ Short_String_Bytes

size_t fe::Sym::Short_String_Bytes = sizeof(uintptr_t)
staticconstexpr

Definition at line 39 of file sym.h.

◆ Short_String_Mask

size_t fe::Sym::Short_String_Mask = Short_String_Bytes - 1
staticconstexpr

Definition at line 40 of file sym.h.

Referenced by size(), and view().


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