This commit is contained in:
Daniel Kirchner 2023-06-24 07:55:10 +02:00
parent 4a84818669
commit 60e1e53f20
4 changed files with 9 additions and 15 deletions

View File

@ -37,10 +37,10 @@ m_analysis(_analysis),
m_errorReporter(_analysis.errorReporter()),
m_typeSystem(_analysis.typeSystem())
{
m_voidType = m_typeSystem.builtinType(BuiltinType::Void, {});
m_wordType = m_typeSystem.builtinType(BuiltinType::Word, {});
m_integerType = m_typeSystem.builtinType(BuiltinType::Integer, {});
m_unitType = m_typeSystem.builtinType(BuiltinType::Unit, {});
m_voidType = m_typeSystem.type(BuiltinType::Void, {});
m_wordType = m_typeSystem.type(BuiltinType::Word, {});
m_integerType = m_typeSystem.type(BuiltinType::Integer, {});
m_unitType = m_typeSystem.type(BuiltinType::Unit, {});
m_env = &m_typeSystem.env();
}
@ -63,7 +63,7 @@ bool TypeInference::visit(FunctionDefinition const& _functionDefinition)
auto typeFromParameterList = [&](ParameterList const* _list) {
if (!_list)
return m_typeSystem.builtinType(BuiltinType::Unit, {});
return m_unitType;
auto& listAnnotation = annotation(*_list);
solAssert(listAnnotation.type);
return *listAnnotation.type;

View File

@ -355,11 +355,6 @@ void TypeSystem::declareTypeConstructor(TypeExpression::Constructor _typeConstru
solAssert(newlyInserted, "Type constructor already declared.");
}
experimental::Type TypeSystem::builtinType(BuiltinType _builtinType, std::vector<Type> _arguments) const
{
return type(_builtinType, std::move(_arguments));
}
experimental::Type TypeSystem::type(TypeExpression::Constructor _constructor, std::vector<Type> _arguments) const
{
// TODO: proper error handling
@ -413,12 +408,12 @@ void TypeSystem::instantiateClass(TypeExpression::Constructor _typeConstructor,
experimental::Type TypeSystemHelpers::tupleType(vector<Type> _elements) const
{
if (_elements.empty())
return typeSystem.builtinType(BuiltinType::Unit, {});
return typeSystem.type(BuiltinType::Unit, {});
if (_elements.size() == 1)
return _elements.front();
Type result = _elements.back();
for (Type type: _elements | ranges::views::reverse | ranges::views::drop_exactly(1))
result = typeSystem.builtinType(BuiltinType::Pair, {type, result});
result = typeSystem.type(BuiltinType::Pair, {type, result});
return result;
}
@ -459,7 +454,7 @@ vector<experimental::Type> TypeSystemHelpers::destTupleType(Type _tupleType) con
experimental::Type TypeSystemHelpers::functionType(experimental::Type _argType, experimental::Type _resultType) const
{
return typeSystem.builtinType(BuiltinType::Function, {_argType, _resultType});
return typeSystem.type(BuiltinType::Function, {_argType, _resultType});
}
tuple<TypeExpression::Constructor, vector<experimental::Type>> TypeSystemHelpers::destTypeExpression(Type _type) const

View File

@ -148,7 +148,6 @@ public:
TypeSystem() {}
TypeSystem(TypeSystem const&) = delete;
TypeSystem const& operator=(TypeSystem const&) = delete;
Type builtinType(BuiltinType _builtinType, std::vector<Type> _arguments) const;
Type type(TypeExpression::Constructor _typeConstructor, std::vector<Type> _arguments) const;
std::string typeName(TypeExpression::Constructor _typeConstructor) const
{

View File

@ -98,7 +98,7 @@ private:
auto type = m_context.analysis.annotation<TypeInference>(*varDecl).type;
solAssert(type);
type = m_context.env->resolve(*type);
solAssert(*type == m_context.analysis.typeSystem().builtinType(BuiltinType::Word, {}));
solAssert(*type == m_context.analysis.typeSystem().type(BuiltinType::Word, {}));
string value = IRNames::localVariable(*varDecl);
return yul::Identifier{_identifier.debugData, yul::YulString{value}};
}