2022-11-04 17:02:37 +00:00
|
|
|
// This file is part of the Luau programming language and is licensed under MIT License; see LICENSE.txt for details
|
2023-02-03 12:34:12 +00:00
|
|
|
#include "Luau/Refinement.h"
|
2023-10-20 21:36:26 +01:00
|
|
|
#include <algorithm>
|
2022-11-04 17:02:37 +00:00
|
|
|
|
|
|
|
namespace Luau
|
|
|
|
{
|
|
|
|
|
2023-03-03 13:45:38 +00:00
|
|
|
RefinementId RefinementArena::variadic(const std::vector<RefinementId>& refis)
|
|
|
|
{
|
2023-10-20 21:36:26 +01:00
|
|
|
bool hasRefinements = false;
|
|
|
|
for (RefinementId r : refis)
|
|
|
|
hasRefinements |= bool(r);
|
|
|
|
|
|
|
|
if (!hasRefinements)
|
|
|
|
return nullptr;
|
|
|
|
|
2023-03-03 13:45:38 +00:00
|
|
|
return NotNull{allocator.allocate(Variadic{refis})};
|
|
|
|
}
|
|
|
|
|
2023-02-03 12:34:12 +00:00
|
|
|
RefinementId RefinementArena::negation(RefinementId refinement)
|
2022-11-04 17:02:37 +00:00
|
|
|
{
|
2023-10-20 21:36:26 +01:00
|
|
|
if (!refinement)
|
|
|
|
return nullptr;
|
|
|
|
|
2023-02-03 12:34:12 +00:00
|
|
|
return NotNull{allocator.allocate(Negation{refinement})};
|
2022-11-04 17:02:37 +00:00
|
|
|
}
|
|
|
|
|
2023-02-03 12:34:12 +00:00
|
|
|
RefinementId RefinementArena::conjunction(RefinementId lhs, RefinementId rhs)
|
2022-11-04 17:02:37 +00:00
|
|
|
{
|
2023-10-20 21:36:26 +01:00
|
|
|
if (!lhs && !rhs)
|
|
|
|
return nullptr;
|
|
|
|
|
2022-11-04 17:02:37 +00:00
|
|
|
return NotNull{allocator.allocate(Conjunction{lhs, rhs})};
|
|
|
|
}
|
|
|
|
|
2023-02-03 12:34:12 +00:00
|
|
|
RefinementId RefinementArena::disjunction(RefinementId lhs, RefinementId rhs)
|
2022-11-04 17:02:37 +00:00
|
|
|
{
|
2023-10-20 21:36:26 +01:00
|
|
|
if (!lhs && !rhs)
|
|
|
|
return nullptr;
|
|
|
|
|
2022-11-04 17:02:37 +00:00
|
|
|
return NotNull{allocator.allocate(Disjunction{lhs, rhs})};
|
|
|
|
}
|
|
|
|
|
2023-02-03 12:34:12 +00:00
|
|
|
RefinementId RefinementArena::equivalence(RefinementId lhs, RefinementId rhs)
|
2022-11-04 17:02:37 +00:00
|
|
|
{
|
2023-10-20 21:36:26 +01:00
|
|
|
if (!lhs && !rhs)
|
|
|
|
return nullptr;
|
|
|
|
|
2022-11-04 17:02:37 +00:00
|
|
|
return NotNull{allocator.allocate(Equivalence{lhs, rhs})};
|
|
|
|
}
|
|
|
|
|
2023-10-20 21:36:26 +01:00
|
|
|
RefinementId RefinementArena::proposition(const RefinementKey* key, TypeId discriminantTy)
|
2022-11-04 17:02:37 +00:00
|
|
|
{
|
2023-10-20 21:36:26 +01:00
|
|
|
if (!key)
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
return NotNull{allocator.allocate(Proposition{key, discriminantTy})};
|
2023-02-10 18:50:54 +00:00
|
|
|
}
|
|
|
|
|
2022-11-04 17:02:37 +00:00
|
|
|
} // namespace Luau
|