mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
fixup! User-defined literal suffixes: Code generation
This commit is contained in:
parent
b5f4fcc9b1
commit
134c5a951f
@ -698,33 +698,20 @@ bool ExpressionCompiler::visit(FunctionCall const& _functionCall)
|
||||
|
||||
evmasm::AssemblyItem returnLabel = m_context.pushNewTag();
|
||||
|
||||
if (!_functionCall.isSuffixCall())
|
||||
if (!_functionCall.isSuffixCall() || parameterTypes.size() == 1)
|
||||
{
|
||||
for (unsigned i = 0; i < arguments.size(); ++i)
|
||||
acceptAndConvert(*arguments[i], *parameterTypes[i]);
|
||||
}
|
||||
else
|
||||
{
|
||||
solAssert(arguments.size() == 1);
|
||||
solAssert(arguments[0]);
|
||||
solAssert(parameterTypes.size() == 2);
|
||||
solAssert(arguments.size() == 1 && arguments[0]);
|
||||
auto const* literal = dynamic_cast<Literal const*>(arguments[0].get());
|
||||
Type const& literalType = *literal->annotation().type;
|
||||
solAssert(literal);
|
||||
solAssert(literal->annotation().type);
|
||||
|
||||
if (parameterTypes.size() == 1)
|
||||
{
|
||||
if (literalType.category() != Type::Category::StringLiteral)
|
||||
// NOTE: For string literals we do not need to define the variable. The variable
|
||||
// value will be embedded inside the conversion function.
|
||||
m_context << literalType.literalValue(literal);
|
||||
utils().convertType(literalType, *parameterTypes.at(0));
|
||||
}
|
||||
else
|
||||
{
|
||||
solAssert(parameterTypes.size() == 2);
|
||||
|
||||
auto const* rationalNumberType = dynamic_cast<RationalNumberType const*>(&literalType);
|
||||
auto const* rationalNumberType = dynamic_cast<RationalNumberType const*>(literal->annotation().type);
|
||||
solAssert(rationalNumberType);
|
||||
|
||||
auto&& [mantissa, exponent] = rationalNumberType->fractionalDecomposition();
|
||||
@ -734,7 +721,6 @@ bool ExpressionCompiler::visit(FunctionCall const& _functionCall)
|
||||
m_context << exponent->literalValue(nullptr);
|
||||
utils().convertType(*exponent, *parameterTypes.at(1));
|
||||
}
|
||||
}
|
||||
|
||||
_functionCall.expression().accept(*this);
|
||||
|
||||
|
@ -1003,7 +1003,7 @@ void IRGeneratorForStatements::endVisit(FunctionCall const& _functionCall)
|
||||
vector<string> args;
|
||||
FunctionDefinition const* functionDef = nullptr;
|
||||
|
||||
if (!_functionCall.isSuffixCall())
|
||||
if (!_functionCall.isSuffixCall() || parameterTypes.size() == 1)
|
||||
{
|
||||
functionDef = ASTNode::resolveFunctionCall(_functionCall, &m_context.mostDerivedContract());
|
||||
|
||||
@ -1020,16 +1020,13 @@ void IRGeneratorForStatements::endVisit(FunctionCall const& _functionCall)
|
||||
solAssert(!functionDef->virtualSemantics());
|
||||
solAssert(!functionType->hasBoundFirstArgument());
|
||||
|
||||
solAssert(arguments.size() == 1);
|
||||
solAssert(arguments[0]);
|
||||
solAssert(parameterTypes.size() == 2);
|
||||
solAssert(arguments.size() == 1 && arguments[0]);
|
||||
auto const* literal = dynamic_cast<Literal const*>(arguments[0].get());
|
||||
Type const& literalType = *literal->annotation().type;
|
||||
solAssert(literal);
|
||||
solAssert(literal->annotation().type);
|
||||
|
||||
if (parameterTypes.size() == 2)
|
||||
{
|
||||
auto const* literalRationalType = dynamic_cast<RationalNumberType const*>(&literalType);
|
||||
auto const* literalRationalType = dynamic_cast<RationalNumberType const*>(literal->annotation().type);
|
||||
solAssert(literalRationalType);
|
||||
|
||||
auto&& [mantissa, exponent] = literalRationalType->fractionalDecomposition();
|
||||
@ -1043,18 +1040,6 @@ void IRGeneratorForStatements::endVisit(FunctionCall const& _functionCall)
|
||||
define(exponentVar) << toCompactHexWithPrefix(exponent->literalValue(literal)) << "\n";
|
||||
args += convert(exponentVar, *parameterTypes[1]).stackSlots();
|
||||
}
|
||||
else
|
||||
{
|
||||
solAssert(parameterTypes.size() == 1);
|
||||
|
||||
IRVariable value(m_context.newYulVariable(), literalType);
|
||||
if (literalType.category() != Type::Category::StringLiteral)
|
||||
// NOTE: For string literals we do not need to define the variable. The variable
|
||||
// value will be embedded inside the conversion function.
|
||||
define(value) << toCompactHexWithPrefix(literalType.literalValue(literal)) << "\n";
|
||||
args += convert(value, *parameterTypes[0]).stackSlots();
|
||||
}
|
||||
}
|
||||
|
||||
if (functionDef)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user