mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
[SolYul] Partially implement constructor.
This commit is contained in:
parent
021b312264
commit
63a072f122
@ -71,6 +71,8 @@ pair<string, string> IRGenerator::run(ContractDefinition const& _contract)
|
|||||||
|
|
||||||
string IRGenerator::generate(ContractDefinition const& _contract)
|
string IRGenerator::generate(ContractDefinition const& _contract)
|
||||||
{
|
{
|
||||||
|
solUnimplementedAssert(!_contract.isLibrary(), "Libraries not yet implemented.");
|
||||||
|
|
||||||
Whiskers t(R"(
|
Whiskers t(R"(
|
||||||
object "<CreationObject>" {
|
object "<CreationObject>" {
|
||||||
code {
|
code {
|
||||||
@ -90,9 +92,10 @@ string IRGenerator::generate(ContractDefinition const& _contract)
|
|||||||
)");
|
)");
|
||||||
|
|
||||||
resetContext(_contract);
|
resetContext(_contract);
|
||||||
|
|
||||||
t("CreationObject", creationObjectName(_contract));
|
t("CreationObject", creationObjectName(_contract));
|
||||||
t("memoryInit", memoryInit());
|
t("memoryInit", memoryInit());
|
||||||
t("constructor", _contract.constructor() ? constructorCode(*_contract.constructor()) : "");
|
t("constructor", constructorCode(_contract));
|
||||||
t("deploy", deployCode(_contract));
|
t("deploy", deployCode(_contract));
|
||||||
// We generate code for all functions and rely on the optimizer to remove them again
|
// We generate code for all functions and rely on the optimizer to remove them again
|
||||||
// TODO it would probably be better to only generate functions when internalDispatch or
|
// TODO it would probably be better to only generate functions when internalDispatch or
|
||||||
@ -146,15 +149,21 @@ string IRGenerator::generateFunction(FunctionDefinition const& _function)
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
string IRGenerator::constructorCode(FunctionDefinition const& _constructor)
|
string IRGenerator::constructorCode(ContractDefinition const& _contract)
|
||||||
{
|
{
|
||||||
string out;
|
// TODO initialize state variables in base to derived order.
|
||||||
if (!_constructor.isPayable())
|
// TODO base constructors
|
||||||
out = callValueCheck();
|
// TODO callValueCheck if there is no constructor.
|
||||||
|
if (FunctionDefinition const* constructor = _contract.constructor())
|
||||||
|
{
|
||||||
|
string out;
|
||||||
|
if (!constructor->isPayable())
|
||||||
|
out = callValueCheck();
|
||||||
|
solUnimplementedAssert(constructor->parameters().empty(), "");
|
||||||
|
return move(out) + m_context.functionName(*constructor) + "()\n";
|
||||||
|
}
|
||||||
|
|
||||||
solUnimplemented("Constructors are not yet implemented.");
|
return {};
|
||||||
|
|
||||||
return out;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
string IRGenerator::deployCode(ContractDefinition const& _contract)
|
string IRGenerator::deployCode(ContractDefinition const& _contract)
|
||||||
|
@ -57,7 +57,7 @@ private:
|
|||||||
/// Generates code for and returns the name of the function.
|
/// Generates code for and returns the name of the function.
|
||||||
std::string generateFunction(FunctionDefinition const& _function);
|
std::string generateFunction(FunctionDefinition const& _function);
|
||||||
|
|
||||||
std::string constructorCode(FunctionDefinition const& _constructor);
|
std::string constructorCode(ContractDefinition const& _contract);
|
||||||
std::string deployCode(ContractDefinition const& _contract);
|
std::string deployCode(ContractDefinition const& _contract);
|
||||||
std::string callValueCheck();
|
std::string callValueCheck();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user