mirror of
https://github.com/luau-lang/luau.git
synced 2024-12-13 13:30:40 +00:00
a5c6a38b10
* Fix autocompletion of if-then-else expressions * Fix a potential crash surrounding improper use of `%*` in a string format specifier * All Python scripts now invoke Python via `python3` rather than `python`. * Improved error handling for string interpolation with too many arguments. Co-authored-by: Arseny Kapoulkine <arseny.kapoulkine@gmail.com> Co-authored-by: Vyacheslav Egorov <vegorov@roblox.com>
95 lines
1.8 KiB
C++
95 lines
1.8 KiB
C++
// This file is part of the Luau programming language and is licensed under MIT License; see LICENSE.txt for details
|
|
#pragma once
|
|
|
|
#include "Luau/Location.h"
|
|
#include "Luau/LValue.h"
|
|
#include "Luau/Variant.h"
|
|
|
|
#include <vector>
|
|
|
|
namespace Luau
|
|
{
|
|
|
|
struct Type;
|
|
using TypeId = const Type*;
|
|
|
|
struct TruthyPredicate;
|
|
struct IsAPredicate;
|
|
struct TypeGuardPredicate;
|
|
struct EqPredicate;
|
|
struct AndPredicate;
|
|
struct OrPredicate;
|
|
struct NotPredicate;
|
|
|
|
using Predicate = Variant<TruthyPredicate, IsAPredicate, TypeGuardPredicate, EqPredicate, AndPredicate, OrPredicate, NotPredicate>;
|
|
using PredicateVec = std::vector<Predicate>;
|
|
|
|
struct TruthyPredicate
|
|
{
|
|
LValue lvalue;
|
|
Location location;
|
|
};
|
|
|
|
struct IsAPredicate
|
|
{
|
|
LValue lvalue;
|
|
Location location;
|
|
TypeId ty;
|
|
};
|
|
|
|
struct TypeGuardPredicate
|
|
{
|
|
LValue lvalue;
|
|
Location location;
|
|
std::string kind; // TODO: When singleton types arrive, replace this with `TypeId ty;`
|
|
bool isTypeof;
|
|
};
|
|
|
|
struct EqPredicate
|
|
{
|
|
LValue lvalue;
|
|
TypeId type;
|
|
Location location;
|
|
};
|
|
|
|
struct AndPredicate
|
|
{
|
|
PredicateVec lhs;
|
|
PredicateVec rhs;
|
|
|
|
AndPredicate(PredicateVec&& lhs, PredicateVec&& rhs);
|
|
};
|
|
|
|
struct OrPredicate
|
|
{
|
|
PredicateVec lhs;
|
|
PredicateVec rhs;
|
|
|
|
OrPredicate(PredicateVec&& lhs, PredicateVec&& rhs);
|
|
};
|
|
|
|
struct NotPredicate
|
|
{
|
|
PredicateVec predicates;
|
|
};
|
|
|
|
// Outside definition works around clang 15 issue where vector instantiation is triggered while Predicate is still incomplete
|
|
inline AndPredicate::AndPredicate(PredicateVec&& lhs, PredicateVec&& rhs)
|
|
: lhs(std::move(lhs))
|
|
, rhs(std::move(rhs))
|
|
{
|
|
}
|
|
|
|
inline OrPredicate::OrPredicate(PredicateVec&& lhs, PredicateVec&& rhs)
|
|
: lhs(std::move(lhs))
|
|
, rhs(std::move(rhs))
|
|
{
|
|
}
|
|
|
|
template<typename T>
|
|
const T* get(const Predicate& predicate)
|
|
{
|
|
return get_if<T>(&predicate);
|
|
}
|
|
|
|
} // namespace Luau
|