Merge pull request #10234 from ethereum/smt_named_arguments

[SMTChecker] Support named arguments in function calls
This commit is contained in:
Leonardo
2020-11-20 12:24:51 -01:00
committed by GitHub
12 changed files with 120 additions and 41 deletions
+38
View File
@@ -757,6 +757,44 @@ FunctionCallAnnotation& FunctionCall::annotation() const
return initAnnotation<FunctionCallAnnotation>();
}
vector<ASTPointer<Expression const>> FunctionCall::sortedArguments() const
{
// normal arguments
if (m_names.empty())
return arguments();
// named arguments
FunctionTypePointer functionType;
if (*annotation().kind == FunctionCallKind::StructConstructorCall)
{
auto const& type = dynamic_cast<TypeType const&>(*m_expression->annotation().type);
auto const& structType = dynamic_cast<StructType const&>(*type.actualType());
functionType = structType.constructorType();
}
else
functionType = dynamic_cast<FunctionType const*>(m_expression->annotation().type);
vector<ASTPointer<Expression const>> sorted;
for (auto const& parameterName: functionType->parameterNames())
{
bool found = false;
for (size_t j = 0; j < m_names.size() && !found; j++)
if ((found = (parameterName == *m_names.at(j))))
// we found the actual parameter position
sorted.push_back(m_arguments.at(j));
solAssert(found, "");
}
if (!functionType->takesArbitraryParameters())
{
solAssert(m_arguments.size() == functionType->parameterTypes().size(), "");
solAssert(m_arguments.size() == m_names.size(), "");
solAssert(m_arguments.size() == sorted.size(), "");
}
return sorted;
}
IdentifierAnnotation& Identifier::annotation() const
{
return initAnnotation<IdentifierAnnotation>();