Change expression parts to use strings instead of numbers.

This commit is contained in:
chriseth 2020-01-23 10:52:45 +01:00
parent 45caaf5ad8
commit 6ded158739
4 changed files with 11 additions and 14 deletions

View File

@ -108,12 +108,11 @@ string IRGenerationContext::variable(Expression const& _expression)
return suffixedVariableNameList(move(var) + "_", 1, 1 + size);
}
string IRGenerationContext::variablePart(Expression const& _expression, size_t _part)
string IRGenerationContext::variablePart(Expression const& _expression, string const& _part)
{
size_t numVars = _expression.annotation().type->sizeOnStack();
solAssert(numVars > 1, "");
solAssert(1 <= _part && _part <= numVars, "");
return "expr_" + to_string(_expression.id()) + "_" + to_string(_part);
return "expr_" + to_string(_expression.id()) + "_" + _part;
}
string IRGenerationContext::internalDispatch(size_t _in, size_t _out)

View File

@ -82,9 +82,8 @@ public:
/// @returns the variable (or comma-separated list of variables) that contain
/// the value of the given expression.
std::string variable(Expression const& _expression);
/// @returns the variable of a multi-variable expression. Variables are numbered
/// starting from 1.
std::string variablePart(Expression const& _expression, size_t _part);
/// @returns the sub-variable of a multi-variable expression.
std::string variablePart(Expression const& _expression, std::string const& _part);
std::string internalDispatch(size_t _in, size_t _out);

View File

@ -717,11 +717,11 @@ void IRGeneratorForStatements::endVisit(MemberAccess const& _memberAccess)
else
solAssert(false, "Contract member is neither variable nor function.");
defineExpressionPart(_memberAccess, 1) << expressionAsType(
defineExpressionPart(_memberAccess, "address") << expressionAsType(
_memberAccess.expression(),
type.isPayable() ? *TypeProvider::payableAddress() : *TypeProvider::address()
) << "\n";
defineExpressionPart(_memberAccess, 2) << formatNumber(identifier) << "\n";
defineExpressionPart(_memberAccess, "functionIdentifier") << formatNumber(identifier) << "\n";
}
else
solAssert(false, "Invalid member access in contract");
@ -1177,7 +1177,7 @@ void IRGeneratorForStatements::appendExternalFunctionCall(
templ("result", m_context.newYulVariable());
templ("freeMem", fetchFreeMem());
templ("shl28", m_utils.shiftLeftFunction(8 * (32 - 4)));
templ("funId", m_context.variablePart(_functionCall.expression(), 2));
templ("funId", m_context.variablePart(_functionCall.expression(), "functionIdentifier"));
// If the function takes arbitrary parameters or is a bare call, copy dynamic length data in place.
// Move arguments to memory, will not update the free memory pointer (but will update the memory
@ -1203,7 +1203,7 @@ void IRGeneratorForStatements::appendExternalFunctionCall(
else if (useStaticCall)
solAssert(!funType.valueSet(), "Value set for staticcall");
else if (funType.valueSet())
templ("value", m_context.variablePart(_functionCall.expression(), 4));
templ("value", m_context.variablePart(_functionCall.expression(), "value"));
else
templ("value", "0");
@ -1212,7 +1212,7 @@ void IRGeneratorForStatements::appendExternalFunctionCall(
templ("checkExistence", checkExistence);
if (funType.gasSet())
templ("gas", m_context.variablePart(_functionCall.expression(), 3));
templ("gas", m_context.variablePart(_functionCall.expression(), "gas"));
else if (m_context.evmVersion().canOverchargeGasForCall())
// Send all gas (requires tangerine whistle EVM)
templ("gas", "gas()");
@ -1285,7 +1285,7 @@ ostream& IRGeneratorForStatements::defineExpression(Expression const& _expressio
return m_code;
}
ostream& IRGeneratorForStatements::defineExpressionPart(Expression const& _expression, size_t _part)
ostream& IRGeneratorForStatements::defineExpressionPart(Expression const& _expression, string const& _part)
{
return m_code << "let " << m_context.variablePart(_expression, _part) << " := ";
}

View File

@ -80,8 +80,7 @@ private:
std::string expressionAsType(Expression const& _expression, Type const& _to);
std::ostream& defineExpression(Expression const& _expression);
/// Defines only one of many variables corresponding to an expression.
/// We start counting at 1 instead of 0.
std::ostream& defineExpressionPart(Expression const& _expression, size_t _part);
std::ostream& defineExpressionPart(Expression const& _expression, std::string const& _part);
void appendAndOrOperatorCode(BinaryOperation const& _binOp);
void appendSimpleUnaryOperation(UnaryOperation const& _operation, Expression const& _expr);