diff --git a/libsolidity/codegen/ir/IRGeneratorForStatements.cpp b/libsolidity/codegen/ir/IRGeneratorForStatements.cpp index 9c0b14a5f..8b1f4a4a5 100644 --- a/libsolidity/codegen/ir/IRGeneratorForStatements.cpp +++ b/libsolidity/codegen/ir/IRGeneratorForStatements.cpp @@ -116,7 +116,7 @@ bool IRGeneratorForStatements::visit(Assignment const& _assignment) _assignment.rightHandSide().accept(*this); Type const* intermediateType = _assignment.rightHandSide().annotation().type->closestTemporaryType( - _assignment.leftHandSide().annotation().type + &type(_assignment.leftHandSide()) ); string intermediateValue = m_context.newYulVariable(); m_code << "let " << intermediateValue << " := " << expressionAsType(_assignment.rightHandSide(), *intermediateType) << "\n"; @@ -228,21 +228,21 @@ void IRGeneratorForStatements::endVisit(FunctionCall const& _functionCall) "This type of function call is not yet implemented" ); - TypePointer const funcType = _functionCall.expression().annotation().type; + Type const& funcType = type(_functionCall.expression()); if (_functionCall.annotation().kind == FunctionCallKind::TypeConversion) { - solAssert(funcType->category() == Type::Category::TypeType, "Expected category to be TypeType"); + solAssert(funcType.category() == Type::Category::TypeType, "Expected category to be TypeType"); solAssert(_functionCall.arguments().size() == 1, "Expected one argument for type conversion"); defineExpression(_functionCall) << - expressionAsType(*_functionCall.arguments().front(), *_functionCall.annotation().type) << + expressionAsType(*_functionCall.arguments().front(), type(_functionCall)) << "\n"; return; } - FunctionTypePointer functionType = dynamic_cast(funcType); + FunctionTypePointer functionType = dynamic_cast(&funcType); TypePointers parameterTypes = functionType->parameterTypes(); vector> const& callArguments = _functionCall.arguments(); @@ -347,14 +347,14 @@ bool IRGeneratorForStatements::visit(Identifier const& _identifier) bool IRGeneratorForStatements::visit(Literal const& _literal) { - TypePointer type = _literal.annotation().type; + Type const& literalType = type(_literal); - switch (type->category()) + switch (literalType.category()) { case Type::Category::RationalNumber: case Type::Category::Bool: case Type::Category::Address: - defineExpression(_literal) << toCompactHexWithPrefix(type->literalValue(&_literal)) << "\n"; + defineExpression(_literal) << toCompactHexWithPrefix(literalType.literalValue(&_literal)) << "\n"; break; case Type::Category::StringLiteral: solUnimplemented(""); @@ -367,7 +367,7 @@ bool IRGeneratorForStatements::visit(Literal const& _literal) string IRGeneratorForStatements::expressionAsType(Expression const& _expression, Type const& _to) { - Type const& from = *_expression.annotation().type; + Type const& from = type(_expression); string varName = m_context.variable(_expression); if (from == _to) @@ -391,3 +391,9 @@ void IRGeneratorForStatements::setLValue(Expression const& _expression, unique_p else defineExpression(_expression) << _lvalue->retrieveValue() << "\n"; } + +Type const& IRGeneratorForStatements::type(Expression const& _expression) +{ + solAssert(_expression.annotation().type, "Type of expression not set."); + return *_expression.annotation().type; +} diff --git a/libsolidity/codegen/ir/IRGeneratorForStatements.h b/libsolidity/codegen/ir/IRGeneratorForStatements.h index 4ad86e924..f68e9042f 100644 --- a/libsolidity/codegen/ir/IRGeneratorForStatements.h +++ b/libsolidity/codegen/ir/IRGeneratorForStatements.h @@ -65,6 +65,8 @@ private: void setLValue(Expression const& _expression, std::unique_ptr _lvalue); + static Type const& type(Expression const& _expression); + std::ostringstream m_code; IRGenerationContext& m_context; YulUtilFunctions& m_utils;