template<typename Derived, typename Element>
slang::syntax::SyntaxListBase class

Common base for the three syntax-list container types.

Derived classes

template<typename T>
class SyntaxList
A container of syntax nodes.

Public functions

bool empty() const noexcept

Protected static functions

static size_t headeredSize(uintptr_t ptrBits) noexcept
static uintptr_t allocateContiguous(BumpAllocator& alloc, std::span<const Element> elements)
Allocates a contiguous block of count elements (no header) and returns the resulting (untagged) raw pointer.
static uintptr_t allocateHeadered(BumpAllocator& alloc, std::span<const Element> elements)
Allocates a [size_t header][N elements] block and returns the resulting (untagged) raw pointer to the elements.

Protected functions

uintptr_t tag() const noexcept
uintptr_t rawPtrBits() const noexcept

Protected variables

uintptr_t raw_
All three derived classes (SyntaxList, TokenList, SeparatedSyntaxList) share the same single-pointer representation: a tagged uintptr_t in raw_.

Function documentation

template<typename Derived, typename Element>
bool slang::syntax::SyntaxListBase<Derived, Element>::empty() const noexcept

Returns true if the list is empty, false otherwise.

template<typename Derived, typename Element>
static size_t slang::syntax::SyntaxListBase<Derived, Element>::headeredSize(uintptr_t ptrBits) protected noexcept

Returns the size encoded in the header preceding the storage at ptrBits. The caller must ensure that ptrBits actually points at a headered block.

template<typename Derived, typename Element>
uintptr_t slang::syntax::SyntaxListBase<Derived, Element>::tag() const protected noexcept

Returns the encoding tag for a non-empty list.

template<typename Derived, typename Element>
uintptr_t slang::syntax::SyntaxListBase<Derived, Element>::rawPtrBits() const protected noexcept

Returns the masked-off pointer bits (only meaningful when raw_ != 0).

Variable documentation

template<typename Derived, typename Element>
uintptr_t slang::syntax::SyntaxListBase<Derived, Element>::raw_ protected

All three derived classes (SyntaxList, TokenList, SeparatedSyntaxList) share the same single-pointer representation: a tagged uintptr_t in raw_.

The encoding scheme uses the low two bits of raw_ to distinguish small-list optimizations from a "headered" allocation of the form [size_t header][N elements...], where the size lives in the slot just before the data pointer.

SyntaxList exploits the fact that its element type is itself a pointer; a one-element list stores the single T* value directly in raw_ with no allocation at all, in which case &raw_ reinterpreted as T** is a valid one-element span/iterator. To keep that direct encoding tag-free, SyntaxList uses tag 01 for headered and tag 10 for two-element.The other two list types whose elements aren't pointers keep the simpler "tag `00` = headered" encoding.

raw_ == 0 always means empty (no allocation).

An empty list costs only sizeof(void*), and small lists save the size_t header allocation. Single-element SyntaxList<T> saves any heap allocation entirely.