Merge pull request #11530 from ethereum/IRgen-refactors

IR Codegen: Small refactoring & comment fixes
This commit is contained in:
chriseth 2021-06-14 14:33:39 +02:00 committed by GitHub
commit b0a020ba97
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 22 additions and 22 deletions

View File

@ -36,7 +36,7 @@ YulArity YulArity::fromType(FunctionType const& _functionType)
string IRNames::function(FunctionDefinition const& _function)
{
if (_function.isConstructor())
return implicitConstructor(*_function.annotation().contract);
return constructor(*_function.annotation().contract);
return "fun_" + _function.name() + "_" + to_string(_function.id());
}
@ -78,7 +78,7 @@ string IRNames::internalDispatch(YulArity const& _arity)
"_out_" + to_string(_arity.out);
}
string IRNames::implicitConstructor(ContractDefinition const& _contract)
string IRNames::constructor(ContractDefinition const& _contract)
{
return "constructor_" + _contract.name() + "_" + to_string(_contract.id());
}

View File

@ -54,7 +54,7 @@ struct IRNames
static std::string creationObject(ContractDefinition const& _contract);
static std::string deployedObject(ContractDefinition const& _contract);
static std::string internalDispatch(YulArity const& _arity);
static std::string implicitConstructor(ContractDefinition const& _contract);
static std::string constructor(ContractDefinition const& _contract);
static std::string libraryAddressImmutable();
static std::string constantValueFunction(VariableDeclaration const& _constant);
static std::string localVariable(VariableDeclaration const& _declaration);

View File

@ -137,7 +137,7 @@ string IRGenerator::generate(
<?library>
<!library>
<?constructorHasParams> let <constructorParams> := <copyConstructorArguments>() </constructorHasParams>
<implicitConstructor>(<constructorParams>)
<constructor>(<constructorParams>)
</library>
<deploy>
<functions>
@ -178,10 +178,10 @@ string IRGenerator::generate(
}
t("constructorParams", joinHumanReadable(constructorParams));
t("constructorHasParams", !constructorParams.empty());
t("implicitConstructor", IRNames::implicitConstructor(_contract));
t("constructor", IRNames::constructor(_contract));
t("deploy", deployCode(_contract));
generateImplicitConstructors(_contract);
generateConstructors(_contract);
set<FunctionDefinition const*> creationFunctionList = generateQueuedFunctions();
InternalDispatchMap internalDispatchMap = generateInternalDispatchFunctions();
@ -710,17 +710,17 @@ string IRGenerator::initStateVariables(ContractDefinition const& _contract)
}
void IRGenerator::generateImplicitConstructors(ContractDefinition const& _contract)
void IRGenerator::generateConstructors(ContractDefinition const& _contract)
{
auto listAllParams = [&](
map<ContractDefinition const*, vector<string>> const& baseParams) -> vector<string>
{
vector<string> params;
for (ContractDefinition const* contract: _contract.annotation().linearizedBaseContracts)
if (baseParams.count(contract))
params += baseParams.at(contract);
return params;
};
auto listAllParams =
[&](map<ContractDefinition const*, vector<string>> const& baseParams) -> vector<string>
{
vector<string> params;
for (ContractDefinition const* contract: _contract.annotation().linearizedBaseContracts)
if (baseParams.count(contract))
params += baseParams.at(contract);
return params;
};
map<ContractDefinition const*, vector<string>> baseConstructorParams;
for (size_t i = 0; i < _contract.annotation().linearizedBaseContracts.size(); ++i)
@ -729,7 +729,7 @@ void IRGenerator::generateImplicitConstructors(ContractDefinition const& _contra
baseConstructorParams.erase(contract);
m_context.resetLocalVariables();
m_context.functionCollector().createFunction(IRNames::implicitConstructor(*contract), [&]() {
m_context.functionCollector().createFunction(IRNames::constructor(*contract), [&]() {
Whiskers t(R"(
function <functionName>(<params><comma><baseParams>) {
<evalBaseArguments>
@ -746,7 +746,7 @@ void IRGenerator::generateImplicitConstructors(ContractDefinition const& _contra
vector<string> baseParams = listAllParams(baseConstructorParams);
t("baseParams", joinHumanReadable(baseParams));
t("comma", !params.empty() && !baseParams.empty() ? ", " : "");
t("functionName", IRNames::implicitConstructor(*contract));
t("functionName", IRNames::constructor(*contract));
pair<string, map<ContractDefinition const*, vector<string>>> evaluatedArgs = evaluateConstructorArguments(*contract);
baseConstructorParams.insert(evaluatedArgs.second.begin(), evaluatedArgs.second.end());
t("evalBaseArguments", evaluatedArgs.first);
@ -754,7 +754,7 @@ void IRGenerator::generateImplicitConstructors(ContractDefinition const& _contra
{
t("hasNextConstructor", true);
ContractDefinition const* nextContract = _contract.annotation().linearizedBaseContracts[i + 1];
t("nextConstructor", IRNames::implicitConstructor(*nextContract));
t("nextConstructor", IRNames::constructor(*nextContract));
t("nextParams", joinHumanReadable(listAllParams(baseConstructorParams)));
}
else

View File

@ -87,10 +87,10 @@ private:
/// Generates code that assigns the initial value of the respective type.
std::string generateInitialAssignment(VariableDeclaration const& _varDecl);
/// Generates implicit constructors for all contracts in the inheritance hierarchy of
/// Generates constructors for all contracts in the inheritance hierarchy of
/// @a _contract
/// If there are user defined constructors, their body will be included in implicit constructors body.
void generateImplicitConstructors(ContractDefinition const& _contract);
/// If there are user defined constructors, their body will be included in the implicit constructor's body.
void generateConstructors(ContractDefinition const& _contract);
/// Evaluates constructor's arguments for all base contracts (listed in inheritance specifiers) of
/// @a _contract