#ifndef PORYGONLANG_TABLESCRIPTTYPE_HPP #define PORYGONLANG_TABLESCRIPTTYPE_HPP #include #include "../Binder/BoundVariables/BoundVariable.hpp" namespace Porygon{ class TableScriptType : public ScriptType{ const map* _values; const int _localVariableCount; public: explicit TableScriptType(map* values, int localVariableCount) : ScriptType(TypeClass::Table), _values(values), _localVariableCount(localVariableCount) {} explicit TableScriptType() : ScriptType(TypeClass::Table), _values(nullptr), _localVariableCount(0) {} ~TableScriptType() final{ if (_values != nullptr){ for (const auto& i : *_values){ delete i.second; } } delete _values; } [[nodiscard]] inline bool CanBeIndexedWith(const ScriptType* indexer) const final{ return indexer->GetClass() == TypeClass ::String; } [[nodiscard]] bool CanBeIndexedWithIdentifier(uint32_t hash) const final{ return true; } shared_ptr GetIndexedType(const ScriptType* indexer) const final{ auto stringKey = dynamic_cast(indexer); if (stringKey != nullptr && stringKey->IsKnownAtBind() && _values != nullptr){ return _values-> at(Utilities::HashedString::CreateLookup(stringKey->GetHashValue()))->GetType(); } return make_shared(TypeClass::Any); } [[nodiscard]] inline shared_ptr GetIndexedType(uint32_t hash) const final{ return _values-> at(Utilities::HashedString::CreateLookup(hash))->GetType(); } [[nodiscard]] inline const map* GetValues() const{ return _values; } [[nodiscard]] bool CanBeIterated() const final { return true; } [[nodiscard]] shared_ptr GetIteratorKeyType() const final { return make_shared(TypeClass::Any); } }; } #include "ScriptType.hpp" #endif //PORYGONLANG_TABLESCRIPTTYPE_HPP