// This file is part of the Luau programming language and is licensed under MIT License; see LICENSE.txt for details #pragma once #include "Luau/Def.h" #include "Luau/NotNull.h" #include "Luau/Variant.h" #include #include namespace Luau { using NullableBreadcrumbId = const struct Breadcrumb*; using BreadcrumbId = NotNull; struct FieldMetadata { std::string prop; }; struct SubscriptMetadata { BreadcrumbId key; }; using Metadata = Variant; struct Breadcrumb { NullableBreadcrumbId previous; DefId def; std::optional metadata; std::vector children; }; inline Breadcrumb* asMutable(NullableBreadcrumbId breadcrumb) { LUAU_ASSERT(breadcrumb); return const_cast(breadcrumb); } template const T* getMetadata(NullableBreadcrumbId breadcrumb) { if (!breadcrumb || !breadcrumb->metadata) return nullptr; return get_if(&*breadcrumb->metadata); } struct BreadcrumbArena { TypedAllocator allocator; template BreadcrumbId add(NullableBreadcrumbId previous, DefId def, Args&&... args) { Breadcrumb* bc = allocator.allocate(Breadcrumb{previous, def, std::forward(args)...}); if (previous) asMutable(previous)->children.push_back(NotNull{bc}); return NotNull{bc}; } template BreadcrumbId emplace(NullableBreadcrumbId previous, DefId def, Args&&... args) { Breadcrumb* bc = allocator.allocate(Breadcrumb{previous, def, Metadata{T{std::forward(args)...}}}); if (previous) asMutable(previous)->children.push_back(NotNull{bc}); return NotNull{bc}; } }; } // namespace Luau