Implements complex tables
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2019-06-12 15:19:28 +02:00
parent ba4fe888fa
commit c022c91777
21 changed files with 272 additions and 50 deletions

View File

@@ -6,6 +6,7 @@
#include <vector>
#include <memory>
#include "Binder/BoundVariables/BoundVariableKey.hpp"
#include "Utilities/HashedString.hpp"
using namespace std;
@@ -73,6 +74,24 @@ public:
}
};
class StringScriptType : public ScriptType{
bool _isKnownAtBind;
int _hashValue;
public:
explicit StringScriptType(bool knownAtBind, int hashValue): ScriptType(TypeClass::String){
_isKnownAtBind = knownAtBind;
_hashValue = hashValue;
}
bool IsKnownAtBind(){
return _isKnownAtBind;
}
int GetHashValue(){
return _hashValue;
}
};
class FunctionScriptType : public ScriptType{
shared_ptr<ScriptType> _returnType;
vector<shared_ptr<ScriptType>> _parameterTypes;
@@ -104,24 +123,22 @@ public:
}
};
class TableScriptType : public ScriptType{
shared_ptr<ScriptType> _keyType;
class NumericalTableScriptType : public ScriptType{
shared_ptr<ScriptType> _valueType;
// Consider adding a check whether the table actually contains a type if every key is static.
public:
TableScriptType(shared_ptr<ScriptType> keyType, shared_ptr<ScriptType> valueType) : ScriptType(TypeClass::Table){
_keyType = std::move(keyType);
explicit NumericalTableScriptType(shared_ptr<ScriptType> valueType) : ScriptType(TypeClass::Table){
_valueType = std::move(valueType);
}
bool CanBeIndexedWith(ScriptType* indexer) final{
return _keyType.get()->operator==(indexer);
return indexer->GetClass() == TypeClass ::Number;
}
shared_ptr<ScriptType> GetIndexedType(ScriptType* indexer) final{
return _valueType;
}
};
#endif //PORYGONLANG_SCRIPTTYPE_HPP