Merge pull request #11902 from ethereum/addHelperForContext

Refactor: Add helper for context.
This commit is contained in:
chriseth 2021-09-06 18:28:17 +02:00 committed by GitHub
commit 4615e62514
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 18 deletions

View File

@ -179,7 +179,7 @@ string IRGenerator::generate(
); );
t("useSrcMapCreation", useSrcMap); t("useSrcMapCreation", useSrcMap);
t("sourceLocationComment", sourceLocationComment(_contract, m_context)); t("sourceLocationComment", sourceLocationComment(_contract));
t("CreationObject", IRNames::creationObject(_contract)); t("CreationObject", IRNames::creationObject(_contract));
t("library", _contract.isLibrary()); t("library", _contract.isLibrary());
@ -294,7 +294,7 @@ InternalDispatchMap IRGenerator::generateInternalDispatchFunctions(ContractDefin
} }
<sourceLocationComment> <sourceLocationComment>
)"); )");
templ("sourceLocationComment", sourceLocationComment(_contract, m_context)); templ("sourceLocationComment", sourceLocationComment(_contract));
templ("functionName", funName); templ("functionName", funName);
templ("panic", m_utils.panicFunction(PanicCode::InvalidInternalFunction)); templ("panic", m_utils.panicFunction(PanicCode::InvalidInternalFunction));
templ("in", suffixedVariableNameList("in_", 0, arity.in)); templ("in", suffixedVariableNameList("in_", 0, arity.in));
@ -347,10 +347,10 @@ string IRGenerator::generateFunction(FunctionDefinition const& _function)
<contractSourceLocationComment> <contractSourceLocationComment>
)"); )");
t("sourceLocationComment", sourceLocationComment(_function, m_context)); t("sourceLocationComment", sourceLocationComment(_function));
t( t(
"contractSourceLocationComment", "contractSourceLocationComment",
sourceLocationComment(m_context.mostDerivedContract(), m_context) sourceLocationComment(m_context.mostDerivedContract())
); );
t("functionName", functionName); t("functionName", functionName);
@ -436,10 +436,10 @@ string IRGenerator::generateModifier(
_modifierInvocation.name().annotation().referencedDeclaration _modifierInvocation.name().annotation().referencedDeclaration
); );
solAssert(modifier, ""); solAssert(modifier, "");
t("sourceLocationComment", sourceLocationComment(*modifier, m_context)); t("sourceLocationComment", sourceLocationComment(*modifier));
t( t(
"contractSourceLocationComment", "contractSourceLocationComment",
sourceLocationComment(m_context.mostDerivedContract(), m_context) sourceLocationComment(m_context.mostDerivedContract())
); );
switch (*_modifierInvocation.name().annotation().requiredLookup) switch (*_modifierInvocation.name().annotation().requiredLookup)
@ -499,10 +499,10 @@ string IRGenerator::generateFunctionWithModifierInner(FunctionDefinition const&
} }
<contractSourceLocationComment> <contractSourceLocationComment>
)"); )");
t("sourceLocationComment", sourceLocationComment(_function, m_context)); t("sourceLocationComment", sourceLocationComment(_function));
t( t(
"contractSourceLocationComment", "contractSourceLocationComment",
sourceLocationComment(m_context.mostDerivedContract(), m_context) sourceLocationComment(m_context.mostDerivedContract())
); );
t("functionName", functionName); t("functionName", functionName);
vector<string> retParams; vector<string> retParams;
@ -547,10 +547,10 @@ string IRGenerator::generateGetter(VariableDeclaration const& _varDecl)
} }
<contractSourceLocationComment> <contractSourceLocationComment>
)") )")
("sourceLocationComment", sourceLocationComment(_varDecl, m_context)) ("sourceLocationComment", sourceLocationComment(_varDecl))
( (
"contractSourceLocationComment", "contractSourceLocationComment",
sourceLocationComment(m_context.mostDerivedContract(), m_context) sourceLocationComment(m_context.mostDerivedContract())
) )
("functionName", functionName) ("functionName", functionName)
("id", to_string(_varDecl.id())) ("id", to_string(_varDecl.id()))
@ -566,10 +566,10 @@ string IRGenerator::generateGetter(VariableDeclaration const& _varDecl)
} }
<contractSourceLocationComment> <contractSourceLocationComment>
)") )")
("sourceLocationComment", sourceLocationComment(_varDecl, m_context)) ("sourceLocationComment", sourceLocationComment(_varDecl))
( (
"contractSourceLocationComment", "contractSourceLocationComment",
sourceLocationComment(m_context.mostDerivedContract(), m_context) sourceLocationComment(m_context.mostDerivedContract())
) )
("functionName", functionName) ("functionName", functionName)
("constantValueFunction", IRGeneratorForStatements(m_context, m_utils).constantValueFunction(_varDecl)) ("constantValueFunction", IRGeneratorForStatements(m_context, m_utils).constantValueFunction(_varDecl))
@ -692,10 +692,10 @@ string IRGenerator::generateGetter(VariableDeclaration const& _varDecl)
("params", joinHumanReadable(parameters)) ("params", joinHumanReadable(parameters))
("retVariables", joinHumanReadable(returnVariables)) ("retVariables", joinHumanReadable(returnVariables))
("code", std::move(code)) ("code", std::move(code))
("sourceLocationComment", sourceLocationComment(_varDecl, m_context)) ("sourceLocationComment", sourceLocationComment(_varDecl))
( (
"contractSourceLocationComment", "contractSourceLocationComment",
sourceLocationComment(m_context.mostDerivedContract(), m_context) sourceLocationComment(m_context.mostDerivedContract())
) )
.render(); .render();
}); });
@ -820,13 +820,12 @@ void IRGenerator::generateConstructors(ContractDefinition const& _contract)
t("sourceLocationComment", sourceLocationComment( t("sourceLocationComment", sourceLocationComment(
contract->constructor() ? contract->constructor() ?
contract->constructor()->location() : dynamic_cast<ASTNode const&>(*contract->constructor()) :
contract->location(), dynamic_cast<ASTNode const&>(*contract)
m_context
)); ));
t( t(
"contractSourceLocationComment", "contractSourceLocationComment",
sourceLocationComment(m_context.mostDerivedContract(), m_context) sourceLocationComment(m_context.mostDerivedContract())
); );
t("params", joinHumanReadable(params)); t("params", joinHumanReadable(params));
@ -1073,3 +1072,8 @@ void IRGenerator::resetContext(ContractDefinition const& _contract, ExecutionCon
for (auto const& var: ContractType(_contract).stateVariables()) for (auto const& var: ContractType(_contract).stateVariables())
m_context.addStateVariable(*get<0>(var), get<1>(var), get<2>(var)); m_context.addStateVariable(*get<0>(var), get<1>(var), get<2>(var));
} }
string IRGenerator::sourceLocationComment(ASTNode const& _node) const
{
return ::sourceLocationComment(_node, m_context);
}

View File

@ -119,6 +119,8 @@ private:
void resetContext(ContractDefinition const& _contract, ExecutionContext _context); void resetContext(ContractDefinition const& _contract, ExecutionContext _context);
std::string sourceLocationComment(ASTNode const& _node) const;
langutil::EVMVersion const m_evmVersion; langutil::EVMVersion const m_evmVersion;
OptimiserSettings const m_optimiserSettings; OptimiserSettings const m_optimiserSettings;