Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Roblox
GitHub Repository: Roblox/luau
Path: blob/master/Analysis/include/Luau/Predicate.h
2727 views
1
// This file is part of the Luau programming language and is licensed under MIT License; see LICENSE.txt for details
2
#pragma once
3
4
#include "Luau/Location.h"
5
#include "Luau/LValue.h"
6
#include "Luau/Variant.h"
7
#include "Luau/TypeFwd.h"
8
9
#include <vector>
10
11
namespace Luau
12
{
13
14
struct TruthyPredicate;
15
struct IsAPredicate;
16
struct TypeGuardPredicate;
17
struct EqPredicate;
18
struct AndPredicate;
19
struct OrPredicate;
20
struct NotPredicate;
21
22
using Predicate = Variant<TruthyPredicate, IsAPredicate, TypeGuardPredicate, EqPredicate, AndPredicate, OrPredicate, NotPredicate>;
23
using PredicateVec = std::vector<Predicate>;
24
25
struct TruthyPredicate
26
{
27
LValue lvalue;
28
Location location;
29
};
30
31
struct IsAPredicate
32
{
33
LValue lvalue;
34
Location location;
35
TypeId ty;
36
};
37
38
struct TypeGuardPredicate
39
{
40
LValue lvalue;
41
Location location;
42
std::string kind; // TODO: When singleton types arrive, replace this with `TypeId ty;`
43
bool isTypeof;
44
};
45
46
struct EqPredicate
47
{
48
LValue lvalue;
49
TypeId type;
50
Location location;
51
};
52
53
struct AndPredicate
54
{
55
PredicateVec lhs;
56
PredicateVec rhs;
57
58
AndPredicate(PredicateVec&& lhs, PredicateVec&& rhs);
59
};
60
61
struct OrPredicate
62
{
63
PredicateVec lhs;
64
PredicateVec rhs;
65
66
OrPredicate(PredicateVec&& lhs, PredicateVec&& rhs);
67
};
68
69
struct NotPredicate
70
{
71
PredicateVec predicates;
72
};
73
74
// Outside definition works around clang 15 issue where vector instantiation is triggered while Predicate is still incomplete
75
inline AndPredicate::AndPredicate(PredicateVec&& lhs, PredicateVec&& rhs)
76
: lhs(std::move(lhs))
77
, rhs(std::move(rhs))
78
{
79
}
80
81
inline OrPredicate::OrPredicate(PredicateVec&& lhs, PredicateVec&& rhs)
82
: lhs(std::move(lhs))
83
, rhs(std::move(rhs))
84
{
85
}
86
87
template<typename T>
88
const T* get(const Predicate& predicate)
89
{
90
return get_if<T>(&predicate);
91
}
92
93
} // namespace Luau
94
95