Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Roblox
GitHub Repository: Roblox/luau
Path: blob/master/Analysis/include/Luau/Polarity.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 <cstdint>
5
6
namespace Luau
7
{
8
9
enum struct Polarity : uint8_t
10
{
11
None = 0b000,
12
Positive = 0b001,
13
Negative = 0b010,
14
Mixed = 0b011,
15
Unknown = 0b100,
16
};
17
18
inline Polarity operator|(Polarity lhs, Polarity rhs)
19
{
20
return Polarity(uint8_t(lhs) | uint8_t(rhs));
21
}
22
23
inline Polarity& operator|=(Polarity& lhs, Polarity rhs)
24
{
25
lhs = lhs | rhs;
26
return lhs;
27
}
28
29
inline Polarity operator&(Polarity lhs, Polarity rhs)
30
{
31
return Polarity(uint8_t(lhs) & uint8_t(rhs));
32
}
33
34
inline Polarity& operator&=(Polarity& lhs, Polarity rhs)
35
{
36
lhs = lhs & rhs;
37
return lhs;
38
}
39
40
inline bool isPositive(Polarity p)
41
{
42
return bool(p & Polarity::Positive);
43
}
44
45
inline bool isNegative(Polarity p)
46
{
47
return bool(p & Polarity::Negative);
48
}
49
50
inline bool isKnown(Polarity p)
51
{
52
return p != Polarity::Unknown;
53
}
54
55
inline Polarity invert(Polarity p)
56
{
57
switch (p)
58
{
59
case Polarity::Positive:
60
return Polarity::Negative;
61
case Polarity::Negative:
62
return Polarity::Positive;
63
default:
64
return p;
65
}
66
}
67
68
} // namespace Luau
69
70