2022-01-07 07:26:14 +08:00
|
|
|
// This file is part of the Luau programming language and is licensed under MIT License; see LICENSE.txt for details
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "Luau/Variant.h"
|
|
|
|
#include "Luau/Symbol.h"
|
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
#include <unordered_map>
|
|
|
|
|
|
|
|
namespace Luau
|
|
|
|
{
|
|
|
|
|
2023-01-05 04:53:17 +08:00
|
|
|
struct Type;
|
|
|
|
using TypeId = const Type*;
|
2022-01-07 07:26:14 +08:00
|
|
|
|
|
|
|
struct Field;
|
2022-10-22 01:54:01 +08:00
|
|
|
|
|
|
|
// Deprecated. Do not use in new work.
|
2022-01-07 07:26:14 +08:00
|
|
|
using LValue = Variant<Symbol, Field>;
|
|
|
|
|
|
|
|
struct Field
|
|
|
|
{
|
|
|
|
std::shared_ptr<LValue> parent;
|
|
|
|
std::string key;
|
|
|
|
|
|
|
|
bool operator==(const Field& rhs) const;
|
|
|
|
bool operator!=(const Field& rhs) const;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct LValueHasher
|
|
|
|
{
|
|
|
|
size_t operator()(const LValue& lvalue) const;
|
|
|
|
};
|
|
|
|
|
|
|
|
const LValue* baseof(const LValue& lvalue);
|
|
|
|
|
|
|
|
std::optional<LValue> tryGetLValue(const class AstExpr& expr);
|
|
|
|
|
2022-04-15 07:57:43 +08:00
|
|
|
// Utility function: breaks down an LValue to get at the Symbol
|
|
|
|
Symbol getBaseSymbol(const LValue& lvalue);
|
|
|
|
|
2022-01-07 07:26:14 +08:00
|
|
|
template<typename T>
|
|
|
|
const T* get(const LValue& lvalue)
|
|
|
|
{
|
|
|
|
return get_if<T>(&lvalue);
|
|
|
|
}
|
|
|
|
|
2022-02-05 00:45:57 +08:00
|
|
|
using RefinementMap = std::unordered_map<LValue, TypeId, LValueHasher>;
|
2022-01-07 07:26:14 +08:00
|
|
|
|
|
|
|
void merge(RefinementMap& l, const RefinementMap& r, std::function<TypeId(TypeId, TypeId)> f);
|
|
|
|
void addRefinement(RefinementMap& refis, const LValue& lvalue, TypeId ty);
|
|
|
|
|
|
|
|
} // namespace Luau
|