2019-06-12 13:19:28 +00:00
|
|
|
|
|
|
|
#ifndef PORYGONLANG_TABLESCRIPTTYPE_HPP
|
|
|
|
#define PORYGONLANG_TABLESCRIPTTYPE_HPP
|
|
|
|
#include <unordered_map>
|
|
|
|
#include "Binder/BoundVariables/BoundVariable.hpp"
|
|
|
|
|
2019-06-17 16:35:12 +00:00
|
|
|
namespace Porygon{
|
|
|
|
class TableScriptType : public ScriptType{
|
2019-06-23 13:58:14 +00:00
|
|
|
const map<Utilities::HashedString, BoundVariable*>* _values;
|
2019-06-17 16:35:12 +00:00
|
|
|
const int _localVariableCount;
|
|
|
|
public:
|
2019-06-23 13:58:14 +00:00
|
|
|
explicit TableScriptType(map<Utilities::HashedString, BoundVariable*>* values, int localVariableCount)
|
2019-06-17 16:35:12 +00:00
|
|
|
: ScriptType(TypeClass::Table),
|
|
|
|
_values(values),
|
|
|
|
_localVariableCount(localVariableCount)
|
2019-06-13 14:26:10 +00:00
|
|
|
{}
|
2019-06-12 13:19:28 +00:00
|
|
|
|
2019-06-17 16:35:12 +00:00
|
|
|
~TableScriptType() final{
|
|
|
|
for (auto i : *_values){
|
|
|
|
delete i.second;
|
|
|
|
}
|
|
|
|
delete _values;
|
2019-06-12 13:19:28 +00:00
|
|
|
}
|
|
|
|
|
2019-07-25 15:23:54 +00:00
|
|
|
[[nodiscard]]
|
|
|
|
inline bool CanBeIndexedWith(const ScriptType* indexer) const final{
|
2019-06-17 16:35:12 +00:00
|
|
|
return indexer->GetClass() == TypeClass ::String;
|
|
|
|
}
|
2019-06-12 13:19:28 +00:00
|
|
|
|
2019-07-25 15:23:54 +00:00
|
|
|
[[nodiscard]] bool CanBeIndexedWithIdentifier(uint32_t hash) const final{
|
2019-06-17 16:35:12 +00:00
|
|
|
return true;
|
|
|
|
}
|
2019-06-17 13:45:33 +00:00
|
|
|
|
2019-07-25 15:23:54 +00:00
|
|
|
shared_ptr<const ScriptType> GetIndexedType(const ScriptType* indexer) const final{
|
|
|
|
auto stringKey = dynamic_cast<const StringScriptType*>(indexer);
|
2019-06-17 16:35:12 +00:00
|
|
|
if (stringKey->IsKnownAtBind()){
|
2019-06-25 13:18:36 +00:00
|
|
|
return _values-> at(Utilities::HashedString::CreateLookup(stringKey->GetHashValue()))->GetType();
|
2019-06-17 16:35:12 +00:00
|
|
|
}
|
|
|
|
throw "TODO: indexing with dynamic keys";
|
2019-06-12 13:19:28 +00:00
|
|
|
}
|
|
|
|
|
2019-07-25 15:23:54 +00:00
|
|
|
[[nodiscard]] inline shared_ptr<const ScriptType> GetIndexedType(uint32_t hash) const final{
|
2019-06-25 13:18:36 +00:00
|
|
|
return _values-> at(Utilities::HashedString::CreateLookup(hash))->GetType();
|
2019-06-17 16:35:12 +00:00
|
|
|
}
|
2019-06-17 13:45:33 +00:00
|
|
|
|
2019-07-25 15:23:54 +00:00
|
|
|
[[nodiscard]] inline const map<Utilities::HashedString, BoundVariable*>* GetValues() const{
|
2019-06-17 16:35:12 +00:00
|
|
|
return _values;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
2019-06-12 13:19:28 +00:00
|
|
|
|
|
|
|
#include "ScriptType.hpp"
|
|
|
|
|
|
|
|
#endif //PORYGONLANG_TABLESCRIPTTYPE_HPP
|