Added namespaces to most classes, general cleanup
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
This commit is contained in:
@@ -12,145 +12,147 @@
|
||||
|
||||
using namespace std;
|
||||
|
||||
enum class TypeClass{
|
||||
Error,
|
||||
Nil,
|
||||
Number,
|
||||
Bool,
|
||||
String,
|
||||
Function,
|
||||
UserData,
|
||||
Table,
|
||||
};
|
||||
|
||||
class ScriptType{
|
||||
TypeClass _class;
|
||||
public:
|
||||
explicit ScriptType(TypeClass c){
|
||||
_class = c;
|
||||
}
|
||||
|
||||
virtual ~ScriptType() = default;
|
||||
|
||||
const TypeClass GetClass() const{
|
||||
return _class;
|
||||
}
|
||||
|
||||
virtual bool operator ==(const ScriptType& b) const{
|
||||
return _class == b._class;
|
||||
namespace Porygon{
|
||||
enum class TypeClass{
|
||||
Error,
|
||||
Nil,
|
||||
Number,
|
||||
Bool,
|
||||
String,
|
||||
Function,
|
||||
UserData,
|
||||
Table,
|
||||
};
|
||||
|
||||
virtual bool operator ==(ScriptType* b) const{
|
||||
return _class == b->_class;
|
||||
class ScriptType{
|
||||
TypeClass _class;
|
||||
public:
|
||||
explicit ScriptType(TypeClass c){
|
||||
_class = c;
|
||||
}
|
||||
|
||||
virtual ~ScriptType() = default;
|
||||
|
||||
const TypeClass GetClass() const{
|
||||
return _class;
|
||||
}
|
||||
|
||||
virtual bool operator ==(const ScriptType& b) const{
|
||||
return _class == b._class;
|
||||
};
|
||||
|
||||
virtual bool operator ==(ScriptType* b) const{
|
||||
return _class == b->_class;
|
||||
};
|
||||
|
||||
virtual bool operator !=(const ScriptType& b) const{
|
||||
return ! (operator==(b));
|
||||
}
|
||||
virtual bool operator !=(ScriptType* b) const{
|
||||
return ! (operator==(b));
|
||||
}
|
||||
|
||||
virtual const bool CanBeIndexedWith(ScriptType* indexer) const;
|
||||
virtual const bool CanBeIndexedWithIdentifier(uint32_t hash) const{
|
||||
return false;
|
||||
}
|
||||
|
||||
virtual const shared_ptr<ScriptType> GetIndexedType(ScriptType* indexer) const;
|
||||
virtual const shared_ptr<ScriptType> GetIndexedType(uint32_t hash) const{
|
||||
throw "Shouldn't be possible";
|
||||
}
|
||||
};
|
||||
|
||||
virtual bool operator !=(const ScriptType& b) const{
|
||||
return ! (operator==(b));
|
||||
}
|
||||
virtual bool operator !=(ScriptType* b) const{
|
||||
return ! (operator==(b));
|
||||
}
|
||||
class NumericScriptType : public ScriptType{
|
||||
// Are we aware of whether this is a float or not?
|
||||
bool _awareOfFloat;
|
||||
// Is this value a float?
|
||||
bool _isFloat;
|
||||
public:
|
||||
explicit NumericScriptType(bool floatAware, bool isFloat) : ScriptType(TypeClass::Number){
|
||||
_awareOfFloat = floatAware;
|
||||
_isFloat = isFloat;
|
||||
}
|
||||
|
||||
virtual const bool CanBeIndexedWith(ScriptType* indexer) const;
|
||||
virtual const bool CanBeIndexedWithIdentifier(uint32_t hash) const{
|
||||
return false;
|
||||
}
|
||||
const bool IsAwareOfFloat() const{
|
||||
return _awareOfFloat;
|
||||
}
|
||||
|
||||
virtual const shared_ptr<ScriptType> GetIndexedType(ScriptType* indexer) const;
|
||||
virtual const shared_ptr<ScriptType> GetIndexedType(uint32_t hash) const{
|
||||
throw "Shouldn't be possible";
|
||||
}
|
||||
};
|
||||
const bool IsFloat() const{
|
||||
return _isFloat;
|
||||
}
|
||||
};
|
||||
|
||||
class NumericScriptType : public ScriptType{
|
||||
// Are we aware of whether this is a float or not?
|
||||
bool _awareOfFloat;
|
||||
// Is this value a float?
|
||||
bool _isFloat;
|
||||
public:
|
||||
explicit NumericScriptType(bool floatAware, bool isFloat) : ScriptType(TypeClass::Number){
|
||||
_awareOfFloat = floatAware;
|
||||
_isFloat = isFloat;
|
||||
}
|
||||
class StringScriptType : public ScriptType{
|
||||
bool _isKnownAtBind;
|
||||
uint32_t _hashValue;
|
||||
public:
|
||||
explicit StringScriptType(bool knownAtBind, uint32_t hashValue): ScriptType(TypeClass::String){
|
||||
_isKnownAtBind = knownAtBind;
|
||||
_hashValue = hashValue;
|
||||
}
|
||||
|
||||
const bool IsAwareOfFloat() const{
|
||||
return _awareOfFloat;
|
||||
}
|
||||
const bool IsKnownAtBind() const{
|
||||
return _isKnownAtBind;
|
||||
}
|
||||
|
||||
const bool IsFloat() const{
|
||||
return _isFloat;
|
||||
}
|
||||
};
|
||||
const uint32_t GetHashValue() const{
|
||||
return _hashValue;
|
||||
}
|
||||
};
|
||||
|
||||
class StringScriptType : public ScriptType{
|
||||
bool _isKnownAtBind;
|
||||
uint32_t _hashValue;
|
||||
public:
|
||||
explicit StringScriptType(bool knownAtBind, uint32_t hashValue): ScriptType(TypeClass::String){
|
||||
_isKnownAtBind = knownAtBind;
|
||||
_hashValue = hashValue;
|
||||
}
|
||||
class FunctionScriptType : public ScriptType{
|
||||
shared_ptr<ScriptType> _returnType;
|
||||
vector<shared_ptr<ScriptType>> _parameterTypes;
|
||||
vector<shared_ptr<Binder::BoundVariableKey>> _parameterKeys;
|
||||
int _scopeIndex;
|
||||
public:
|
||||
FunctionScriptType(std::shared_ptr<ScriptType> returnType, vector<shared_ptr<ScriptType>> parameterTypes,
|
||||
vector<shared_ptr<Binder::BoundVariableKey>> parameterKeys, int scopeIndex)
|
||||
: ScriptType(TypeClass::Function){
|
||||
_returnType = std::move(returnType);
|
||||
_parameterTypes = std::move(parameterTypes);
|
||||
_parameterKeys = std::move(parameterKeys);
|
||||
_scopeIndex = scopeIndex;
|
||||
}
|
||||
const shared_ptr<ScriptType> GetReturnType() const{
|
||||
return _returnType;
|
||||
}
|
||||
|
||||
const bool IsKnownAtBind() const{
|
||||
return _isKnownAtBind;
|
||||
}
|
||||
void SetReturnType(shared_ptr<ScriptType> t){
|
||||
_returnType = std::move(t);
|
||||
}
|
||||
|
||||
const uint32_t GetHashValue() const{
|
||||
return _hashValue;
|
||||
}
|
||||
};
|
||||
const vector<shared_ptr<ScriptType>> GetParameterTypes() const{
|
||||
return _parameterTypes;
|
||||
}
|
||||
|
||||
class FunctionScriptType : public ScriptType{
|
||||
shared_ptr<ScriptType> _returnType;
|
||||
vector<shared_ptr<ScriptType>> _parameterTypes;
|
||||
vector<shared_ptr<BoundVariableKey>> _parameterKeys;
|
||||
int _scopeIndex;
|
||||
public:
|
||||
FunctionScriptType(std::shared_ptr<ScriptType> returnType, vector<shared_ptr<ScriptType>> parameterTypes,
|
||||
vector<shared_ptr<BoundVariableKey>> parameterKeys, int scopeIndex)
|
||||
: ScriptType(TypeClass::Function){
|
||||
_returnType = std::move(returnType);
|
||||
_parameterTypes = std::move(parameterTypes);
|
||||
_parameterKeys = std::move(parameterKeys);
|
||||
_scopeIndex = scopeIndex;
|
||||
}
|
||||
const shared_ptr<ScriptType> GetReturnType() const{
|
||||
return _returnType;
|
||||
}
|
||||
const vector<shared_ptr<Binder::BoundVariableKey>> GetParameterKeys() const{
|
||||
return _parameterKeys;
|
||||
}
|
||||
|
||||
void SetReturnType(shared_ptr<ScriptType> t){
|
||||
_returnType = std::move(t);
|
||||
}
|
||||
const int GetScopeIndex() const{
|
||||
return _scopeIndex;
|
||||
}
|
||||
};
|
||||
|
||||
const vector<shared_ptr<ScriptType>> GetParameterTypes() const{
|
||||
return _parameterTypes;
|
||||
}
|
||||
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:
|
||||
explicit NumericalTableScriptType(shared_ptr<ScriptType> valueType) : ScriptType(TypeClass::Table){
|
||||
_valueType = std::move(valueType);
|
||||
}
|
||||
|
||||
const vector<shared_ptr<BoundVariableKey>> GetParameterKeys() const{
|
||||
return _parameterKeys;
|
||||
}
|
||||
const bool CanBeIndexedWith(ScriptType* indexer) const final{
|
||||
return indexer->GetClass() == TypeClass ::Number;
|
||||
}
|
||||
|
||||
const int GetScopeIndex() const{
|
||||
return _scopeIndex;
|
||||
}
|
||||
};
|
||||
|
||||
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:
|
||||
explicit NumericalTableScriptType(shared_ptr<ScriptType> valueType) : ScriptType(TypeClass::Table){
|
||||
_valueType = std::move(valueType);
|
||||
}
|
||||
|
||||
const bool CanBeIndexedWith(ScriptType* indexer) const final{
|
||||
return indexer->GetClass() == TypeClass ::Number;
|
||||
}
|
||||
|
||||
const shared_ptr<ScriptType> GetIndexedType(ScriptType* indexer) const final{
|
||||
return _valueType;
|
||||
}
|
||||
};
|
||||
const shared_ptr<ScriptType> GetIndexedType(ScriptType* indexer) const final{
|
||||
return _valueType;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
#endif //PORYGONLANG_SCRIPTTYPE_HPP
|
||||
|
||||
Reference in New Issue
Block a user