2021-10-30 04:25:12 +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/Ast.h"
|
|
|
|
#include "Luau/Common.h"
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
namespace Luau
|
|
|
|
{
|
|
|
|
|
|
|
|
struct Symbol
|
|
|
|
{
|
|
|
|
Symbol()
|
|
|
|
: local(nullptr)
|
|
|
|
, global()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
Symbol(AstLocal* local)
|
|
|
|
: local(local)
|
|
|
|
, global()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
Symbol(const AstName& global)
|
|
|
|
: local(nullptr)
|
|
|
|
, global(global)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-06-04 06:15:45 +08:00
|
|
|
template<typename T>
|
|
|
|
Symbol(const T&) = delete;
|
|
|
|
|
2021-10-30 04:25:12 +08:00
|
|
|
AstLocal* local;
|
|
|
|
AstName global;
|
|
|
|
|
2023-02-25 05:49:38 +08:00
|
|
|
explicit operator bool() const
|
|
|
|
{
|
|
|
|
return local != nullptr || global.value != nullptr;
|
|
|
|
}
|
|
|
|
|
2023-07-28 23:13:53 +08:00
|
|
|
bool operator==(const Symbol& rhs) const;
|
2021-10-30 04:25:12 +08:00
|
|
|
|
|
|
|
bool operator!=(const Symbol& rhs) const
|
|
|
|
{
|
|
|
|
return !(*this == rhs);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool operator<(const Symbol& rhs) const
|
|
|
|
{
|
|
|
|
if (local && rhs.local)
|
|
|
|
return local < rhs.local;
|
|
|
|
else if (global.value && rhs.global.value)
|
|
|
|
return global < rhs.global;
|
|
|
|
else if (local)
|
|
|
|
return true;
|
2022-10-22 01:54:01 +08:00
|
|
|
|
|
|
|
return false;
|
2021-10-30 04:25:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
AstName astName() const
|
|
|
|
{
|
|
|
|
if (local)
|
|
|
|
return local->name;
|
|
|
|
|
|
|
|
LUAU_ASSERT(global.value);
|
|
|
|
return global;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char* c_str() const
|
|
|
|
{
|
|
|
|
if (local)
|
|
|
|
return local->name.value;
|
|
|
|
|
|
|
|
LUAU_ASSERT(global.value);
|
|
|
|
return global.value;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
std::string toString(const Symbol& name);
|
|
|
|
|
|
|
|
} // namespace Luau
|
|
|
|
|
|
|
|
namespace std
|
|
|
|
{
|
|
|
|
template<>
|
|
|
|
struct hash<Luau::Symbol>
|
|
|
|
{
|
|
|
|
std::size_t operator()(const Luau::Symbol& s) const noexcept
|
|
|
|
{
|
|
|
|
return std::hash<const Luau::AstLocal*>()(s.local) ^ (s.global.value ? std::hash<std::string_view>()(s.global.value) : 0);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
} // namespace std
|