mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Helper function to define the value of expressions.
This commit is contained in:
parent
0eef51ffa4
commit
e66ab6c036
@ -122,7 +122,7 @@ bool IRGeneratorForStatements::visit(Assignment const& _assignment)
|
||||
" := " <<
|
||||
expressionAsType(_assignment.rightHandSide(), *lvalue.annotation().type) <<
|
||||
"\n";
|
||||
m_code << "let " << m_context.variable(_assignment) << " := " << varName << "\n";
|
||||
defineExpression(_assignment) << varName << "\n";
|
||||
|
||||
return false;
|
||||
}
|
||||
@ -197,10 +197,7 @@ void IRGeneratorForStatements::endVisit(BinaryOperation const& _binOp)
|
||||
// special case: short-circuiting
|
||||
solUnimplementedAssert(false, "");
|
||||
else if (commonType->category() == Type::Category::RationalNumber)
|
||||
m_code <<
|
||||
"let " <<
|
||||
m_context.variable(_binOp) <<
|
||||
" := " <<
|
||||
defineExpression(_binOp) <<
|
||||
toCompactHexWithPrefix(commonType->literalValue(nullptr)) <<
|
||||
"\n";
|
||||
else
|
||||
@ -209,10 +206,7 @@ void IRGeneratorForStatements::endVisit(BinaryOperation const& _binOp)
|
||||
if (IntegerType const* type = dynamic_cast<IntegerType const*>(commonType))
|
||||
{
|
||||
solUnimplementedAssert(!type->isSigned(), "");
|
||||
m_code <<
|
||||
"let " <<
|
||||
m_context.variable(_binOp) <<
|
||||
" := " <<
|
||||
defineExpression(_binOp) <<
|
||||
m_utils.overflowCheckedUIntAddFunction(type->numBits()) <<
|
||||
"(" <<
|
||||
expressionAsType(_binOp.leftExpression(), *commonType) <<
|
||||
@ -241,10 +235,7 @@ bool IRGeneratorForStatements::visit(FunctionCall const& _functionCall)
|
||||
solAssert(_functionCall.arguments().size() == 1, "Expected one argument for type conversion");
|
||||
_functionCall.arguments().front()->accept(*this);
|
||||
|
||||
m_code <<
|
||||
"let " <<
|
||||
m_context.variable(_functionCall) <<
|
||||
" := " <<
|
||||
defineExpression(_functionCall) <<
|
||||
expressionAsType(*_functionCall.arguments().front(), *_functionCall.annotation().type) <<
|
||||
"\n";
|
||||
|
||||
@ -297,10 +288,7 @@ bool IRGeneratorForStatements::visit(FunctionCall const& _functionCall)
|
||||
if (auto functionDef = dynamic_cast<FunctionDefinition const*>(identifier->annotation().referencedDeclaration))
|
||||
{
|
||||
// @TODO The function can very well return multiple vars.
|
||||
m_code <<
|
||||
"let " <<
|
||||
m_context.variable(_functionCall) <<
|
||||
" := " <<
|
||||
defineExpression(_functionCall) <<
|
||||
m_context.virtualFunctionName(*functionDef) <<
|
||||
"(" <<
|
||||
joinHumanReadable(args) <<
|
||||
@ -313,10 +301,7 @@ bool IRGeneratorForStatements::visit(FunctionCall const& _functionCall)
|
||||
|
||||
// @TODO The function can very well return multiple vars.
|
||||
args = vector<string>{m_context.variable(_functionCall.expression())} + args;
|
||||
m_code <<
|
||||
"let " <<
|
||||
m_context.variable(_functionCall) <<
|
||||
" := " <<
|
||||
defineExpression(_functionCall) <<
|
||||
m_context.internalDispatch(functionType->parameterTypes().size(), functionType->returnParameterTypes().size()) <<
|
||||
"(" <<
|
||||
joinHumanReadable(args) <<
|
||||
@ -351,7 +336,7 @@ bool IRGeneratorForStatements::visit(Identifier const& _identifier)
|
||||
value = m_context.variableName(*varDecl);
|
||||
else
|
||||
solUnimplemented("");
|
||||
m_code << "let " << m_context.variable(_identifier) << " := " << value << "\n";
|
||||
defineExpression(_identifier) << value << "\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -364,7 +349,7 @@ bool IRGeneratorForStatements::visit(Literal const& _literal)
|
||||
case Type::Category::RationalNumber:
|
||||
case Type::Category::Bool:
|
||||
case Type::Category::Address:
|
||||
m_code << "let " << m_context.variable(_literal) << " := " << toCompactHexWithPrefix(type->literalValue(&_literal)) << "\n";
|
||||
defineExpression(_literal) << toCompactHexWithPrefix(type->literalValue(&_literal)) << "\n";
|
||||
break;
|
||||
case Type::Category::StringLiteral:
|
||||
solUnimplemented("");
|
||||
@ -385,3 +370,8 @@ string IRGeneratorForStatements::expressionAsType(Expression const& _expression,
|
||||
else
|
||||
return m_utils.conversionFunction(from, _to) + "(" + std::move(varName) + ")";
|
||||
}
|
||||
|
||||
ostream& IRGeneratorForStatements::defineExpression(Expression const& _expression)
|
||||
{
|
||||
return m_code << "let " << m_context.variable(_expression) << " := ";
|
||||
}
|
||||
|
@ -60,6 +60,7 @@ private:
|
||||
/// @returns a Yul expression representing the current value of @a _expression,
|
||||
/// converted to type @a _to if it does not yet have that type.
|
||||
std::string expressionAsType(Expression const& _expression, Type const& _to);
|
||||
std::ostream& defineExpression(Expression const& _expression);
|
||||
|
||||
std::ostringstream m_code;
|
||||
IRGenerationContext& m_context;
|
||||
|
Loading…
Reference in New Issue
Block a user