PorygonLang/src/TableScriptType.hpp

58 lines
1.9 KiB
C++
Raw Normal View History

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