Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Roblox
GitHub Repository: Roblox/luau
Path: blob/master/Analysis/src/Refinement.cpp
2725 views
1
// This file is part of the Luau programming language and is licensed under MIT License; see LICENSE.txt for details
2
#include "Luau/Refinement.h"
3
#include <algorithm>
4
5
namespace Luau
6
{
7
8
RefinementId RefinementArena::variadic(const std::vector<RefinementId>& refis)
9
{
10
bool hasRefinements = false;
11
for (RefinementId r : refis)
12
hasRefinements |= bool(r);
13
14
if (!hasRefinements)
15
return nullptr;
16
17
return NotNull{allocator.allocate(Variadic{refis})};
18
}
19
20
RefinementId RefinementArena::negation(RefinementId refinement)
21
{
22
if (!refinement)
23
return nullptr;
24
25
return NotNull{allocator.allocate(Negation{refinement})};
26
}
27
28
RefinementId RefinementArena::conjunction(RefinementId lhs, RefinementId rhs)
29
{
30
if (!lhs && !rhs)
31
return nullptr;
32
33
return NotNull{allocator.allocate(Conjunction{lhs, rhs})};
34
}
35
36
RefinementId RefinementArena::disjunction(RefinementId lhs, RefinementId rhs)
37
{
38
if (!lhs && !rhs)
39
return nullptr;
40
41
return NotNull{allocator.allocate(Disjunction{lhs, rhs})};
42
}
43
44
RefinementId RefinementArena::equivalence(RefinementId lhs, RefinementId rhs)
45
{
46
if (!lhs && !rhs)
47
return nullptr;
48
49
return NotNull{allocator.allocate(Equivalence{lhs, rhs})};
50
}
51
52
RefinementId RefinementArena::proposition(const RefinementKey* key, TypeId discriminantTy)
53
{
54
if (!key)
55
return nullptr;
56
57
return NotNull{allocator.allocate(Proposition{key, discriminantTy, false})};
58
}
59
60
RefinementId RefinementArena::implicitProposition(const RefinementKey* key, TypeId discriminantTy)
61
{
62
if (!key)
63
return nullptr;
64
65
return NotNull{allocator.allocate(Proposition{key, discriminantTy, true})};
66
}
67
68
} // namespace Luau
69
70