59 lines
1.5 KiB
C++
59 lines
1.5 KiB
C++
|
|
#ifndef PORYGONLANG_BOUNDVARIABLEKEY_HPP
|
|
#define PORYGONLANG_BOUNDVARIABLEKEY_HPP
|
|
|
|
#include <string>
|
|
#include "../../Utilities/HashedString.hpp"
|
|
#include "../../ScriptTypes/ScriptType.hpp"
|
|
|
|
namespace Porygon::Binder {
|
|
class BoundVariableKey {
|
|
const Utilities::HashedString _identifier;
|
|
const unsigned int _scopeId;
|
|
const bool _isCreation;
|
|
const uint64_t _hash;
|
|
shared_ptr<const ScriptType> _type;
|
|
|
|
static uint64_t KnuthsHash(unsigned int i1, unsigned int i2) {
|
|
uint64_t ret = i1;
|
|
ret *= 2654435761U;
|
|
return ret ^ i2;
|
|
}
|
|
|
|
public:
|
|
BoundVariableKey(const Utilities::HashedString& id, unsigned int scope, bool creation, shared_ptr<const ScriptType> type)
|
|
: _identifier(id),
|
|
_scopeId(scope),
|
|
_isCreation(creation),
|
|
_type(type),
|
|
_hash(KnuthsHash(id.GetHash(), scope)) {}
|
|
|
|
|
|
[[nodiscard]]
|
|
inline const Utilities::HashedString* GetIdentifier() const {
|
|
return &_identifier;
|
|
}
|
|
|
|
[[nodiscard]]
|
|
inline unsigned int GetScopeId() const {
|
|
return _scopeId;
|
|
}
|
|
|
|
[[nodiscard]]
|
|
inline bool IsCreation() const {
|
|
return _isCreation;
|
|
}
|
|
|
|
[[nodiscard]]
|
|
inline uint64_t GetHash() const {
|
|
return _hash;
|
|
}
|
|
|
|
inline shared_ptr<const ScriptType> GetType() const{
|
|
return _type;
|
|
}
|
|
};
|
|
}
|
|
|
|
#endif //PORYGONLANG_BOUNDVARIABLEKEY_HPP
|