mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Enable internal library calls
This commit is contained in:
parent
64bce597a1
commit
d3da878200
@ -135,6 +135,11 @@ string IRGenerationContext::internalDispatch(size_t _in, size_t _out)
|
|||||||
templ("arrow", _out > 0 ? "->" : "");
|
templ("arrow", _out > 0 ? "->" : "");
|
||||||
templ("assignment_op", _out > 0 ? ":=" : "");
|
templ("assignment_op", _out > 0 ? ":=" : "");
|
||||||
templ("out", suffixedVariableNameList("out_", 0, _out));
|
templ("out", suffixedVariableNameList("out_", 0, _out));
|
||||||
|
|
||||||
|
// UNIMPLEMENTED: Internal library calls via pointers are not implemented yet.
|
||||||
|
// We're not generating code for internal library functions here even though it's possible
|
||||||
|
// to call them via pointers. Right now such calls end up triggering the `default` case in
|
||||||
|
// the switch above.
|
||||||
vector<map<string, string>> functions;
|
vector<map<string, string>> functions;
|
||||||
for (auto const& contract: mostDerivedContract().annotation().linearizedBaseContracts)
|
for (auto const& contract: mostDerivedContract().annotation().linearizedBaseContracts)
|
||||||
for (FunctionDefinition const* function: contract->definedFunctions())
|
for (FunctionDefinition const* function: contract->definedFunctions())
|
||||||
|
@ -567,6 +567,14 @@ void IRGeneratorForStatements::endVisit(FunctionCall const& _functionCall)
|
|||||||
arguments.push_back(callArguments[std::distance(callArgumentNames.begin(), it)]);
|
arguments.push_back(callArguments[std::distance(callArgumentNames.begin(), it)]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (auto memberAccess = dynamic_cast<MemberAccess const*>(&_functionCall.expression()))
|
||||||
|
if (auto expressionType = dynamic_cast<TypeType const*>(memberAccess->expression().annotation().type))
|
||||||
|
if (auto contractType = dynamic_cast<ContractType const*>(expressionType->actualType()))
|
||||||
|
solUnimplementedAssert(
|
||||||
|
!contractType->contractDefinition().isLibrary() || functionType->kind() == FunctionType::Kind::Internal,
|
||||||
|
"Only internal function calls implemented for libraries"
|
||||||
|
);
|
||||||
|
|
||||||
solUnimplementedAssert(!functionType->bound(), "");
|
solUnimplementedAssert(!functionType->bound(), "");
|
||||||
switch (functionType->kind())
|
switch (functionType->kind())
|
||||||
{
|
{
|
||||||
@ -582,7 +590,7 @@ void IRGeneratorForStatements::endVisit(FunctionCall const& _functionCall)
|
|||||||
optional<FunctionDefinition const*> functionDef;
|
optional<FunctionDefinition const*> functionDef;
|
||||||
if (auto memberAccess = dynamic_cast<MemberAccess const*>(&_functionCall.expression()))
|
if (auto memberAccess = dynamic_cast<MemberAccess const*>(&_functionCall.expression()))
|
||||||
{
|
{
|
||||||
solAssert(!functionType->bound(), "");
|
solUnimplementedAssert(!functionType->bound(), "Internal calls to bound functions are not yet implemented for libraries and not allowed for contracts");
|
||||||
|
|
||||||
functionDef = dynamic_cast<FunctionDefinition const*>(memberAccess->annotation().referencedDeclaration);
|
functionDef = dynamic_cast<FunctionDefinition const*>(memberAccess->annotation().referencedDeclaration);
|
||||||
if (functionDef.value() != nullptr)
|
if (functionDef.value() != nullptr)
|
||||||
@ -1325,9 +1333,9 @@ void IRGeneratorForStatements::endVisit(Identifier const& _identifier)
|
|||||||
define(_identifier) << to_string(functionDef->resolveVirtual(m_context.mostDerivedContract()).id()) << "\n";
|
define(_identifier) << to_string(functionDef->resolveVirtual(m_context.mostDerivedContract()).id()) << "\n";
|
||||||
else if (VariableDeclaration const* varDecl = dynamic_cast<VariableDeclaration const*>(declaration))
|
else if (VariableDeclaration const* varDecl = dynamic_cast<VariableDeclaration const*>(declaration))
|
||||||
handleVariableReference(*varDecl, _identifier);
|
handleVariableReference(*varDecl, _identifier);
|
||||||
else if (auto contract = dynamic_cast<ContractDefinition const*>(declaration))
|
else if (dynamic_cast<ContractDefinition const*>(declaration))
|
||||||
{
|
{
|
||||||
solUnimplementedAssert(!contract->isLibrary(), "Libraries not yet supported.");
|
// no-op
|
||||||
}
|
}
|
||||||
else if (dynamic_cast<EventDefinition const*>(declaration))
|
else if (dynamic_cast<EventDefinition const*>(declaration))
|
||||||
{
|
{
|
||||||
|
@ -15,5 +15,7 @@ contract B {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ====
|
||||||
|
// compileViaYul: also
|
||||||
// ----
|
// ----
|
||||||
// g() -> 1
|
// g() -> 1
|
||||||
|
@ -17,5 +17,7 @@ contract C {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ====
|
||||||
|
// compileViaYul: also
|
||||||
// ----
|
// ----
|
||||||
// f() -> 2
|
// f() -> 2
|
||||||
|
@ -22,5 +22,7 @@ contract C {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ====
|
||||||
|
// compileViaYul: also
|
||||||
// ----
|
// ----
|
||||||
// f() -> 2
|
// f() -> 2
|
||||||
|
@ -6,6 +6,8 @@ contract C {
|
|||||||
return L.f(v);
|
return L.f(v);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// ====
|
||||||
|
// compileViaYul: also
|
||||||
// ----
|
// ----
|
||||||
// g(uint256): 1 -> 1
|
// g(uint256): 1 -> 1
|
||||||
// g(uint256): 2 -> 4
|
// g(uint256): 2 -> 4
|
||||||
|
Loading…
Reference in New Issue
Block a user