luau/Analysis/include/Luau/Refinement.h

79 lines
1.6 KiB
C
Raw Normal View History

2023-02-03 20:34:12 +08:00
// This file is part of the Luau programming language and is licensed under MIT License; see LICENSE.txt for details
#pragma once
2023-03-03 21:45:38 +08:00
#include "Luau/NotNull.h"
2023-02-03 20:34:12 +08:00
#include "Luau/TypedAllocator.h"
#include "Luau/Variant.h"
namespace Luau
{
2023-03-03 21:45:38 +08:00
using BreadcrumbId = NotNull<const struct Breadcrumb>;
2023-02-03 20:34:12 +08:00
struct Type;
using TypeId = const Type*;
2023-02-11 02:50:54 +08:00
struct Variadic;
2023-02-03 20:34:12 +08:00
struct Negation;
struct Conjunction;
struct Disjunction;
struct Equivalence;
struct Proposition;
2023-02-11 02:50:54 +08:00
using Refinement = Variant<Variadic, Negation, Conjunction, Disjunction, Equivalence, Proposition>;
2023-02-03 20:34:12 +08:00
using RefinementId = Refinement*; // Can and most likely is nullptr.
2023-02-11 02:50:54 +08:00
struct Variadic
{
std::vector<RefinementId> refinements;
};
2023-02-03 20:34:12 +08:00
struct Negation
{
RefinementId refinement;
};
struct Conjunction
{
RefinementId lhs;
RefinementId rhs;
};
struct Disjunction
{
RefinementId lhs;
RefinementId rhs;
};
struct Equivalence
{
RefinementId lhs;
RefinementId rhs;
};
struct Proposition
{
2023-03-03 21:45:38 +08:00
BreadcrumbId breadcrumb;
2023-02-03 20:34:12 +08:00
TypeId discriminantTy;
};
template<typename T>
const T* get(RefinementId refinement)
{
return get_if<T>(refinement);
}
struct RefinementArena
{
2023-02-11 02:50:54 +08:00
RefinementId variadic(const std::vector<RefinementId>& refis);
2023-02-03 20:34:12 +08:00
RefinementId negation(RefinementId refinement);
RefinementId conjunction(RefinementId lhs, RefinementId rhs);
RefinementId disjunction(RefinementId lhs, RefinementId rhs);
RefinementId equivalence(RefinementId lhs, RefinementId rhs);
2023-03-03 21:45:38 +08:00
RefinementId proposition(BreadcrumbId breadcrumb, TypeId discriminantTy);
2023-02-11 02:50:54 +08:00
private:
TypedAllocator<Refinement> allocator;
2023-02-03 20:34:12 +08:00
};
} // namespace Luau