Refactoring yul source locations.

This commit is contained in:
Djordje Mijovic
2021-05-04 16:05:23 +02:00
parent fe4822a1d2
commit e404b6e7a6
62 changed files with 394 additions and 358 deletions
+12 -12
View File
@@ -34,13 +34,13 @@ using namespace solidity::util;
Statement ASTCopier::operator()(ExpressionStatement const& _statement)
{
return ExpressionStatement{ _statement.location, translate(_statement.expression) };
return ExpressionStatement{ _statement.debugData, translate(_statement.expression) };
}
Statement ASTCopier::operator()(VariableDeclaration const& _varDecl)
{
return VariableDeclaration{
_varDecl.location,
_varDecl.debugData,
translateVector(_varDecl.variables),
translate(_varDecl.value)
};
@@ -49,7 +49,7 @@ Statement ASTCopier::operator()(VariableDeclaration const& _varDecl)
Statement ASTCopier::operator()(Assignment const& _assignment)
{
return Assignment{
_assignment.location,
_assignment.debugData,
translateVector(_assignment.variableNames),
translate(_assignment.value)
};
@@ -58,7 +58,7 @@ Statement ASTCopier::operator()(Assignment const& _assignment)
Expression ASTCopier::operator()(FunctionCall const& _call)
{
return FunctionCall{
_call.location,
_call.debugData,
translate(_call.functionName),
translateVector(_call.arguments)
};
@@ -76,12 +76,12 @@ Expression ASTCopier::operator()(Literal const& _literal)
Statement ASTCopier::operator()(If const& _if)
{
return If{_if.location, translate(_if.condition), translate(_if.body)};
return If{_if.debugData, translate(_if.condition), translate(_if.body)};
}
Statement ASTCopier::operator()(Switch const& _switch)
{
return Switch{_switch.location, translate(_switch.expression), translateVector(_switch.cases)};
return Switch{_switch.debugData, translate(_switch.expression), translateVector(_switch.cases)};
}
Statement ASTCopier::operator()(FunctionDefinition const& _function)
@@ -92,7 +92,7 @@ Statement ASTCopier::operator()(FunctionDefinition const& _function)
ScopeGuard g([&]() { this->leaveFunction(_function); });
return FunctionDefinition{
_function.location,
_function.debugData,
translatedName,
translateVector(_function.parameters),
translateVector(_function.returnVariables),
@@ -106,7 +106,7 @@ Statement ASTCopier::operator()(ForLoop const& _forLoop)
ScopeGuard g([&]() { this->leaveScope(_forLoop.pre); });
return ForLoop{
_forLoop.location,
_forLoop.debugData,
translate(_forLoop.pre),
translate(_forLoop.condition),
translate(_forLoop.post),
@@ -148,17 +148,17 @@ Block ASTCopier::translate(Block const& _block)
enterScope(_block);
ScopeGuard g([&]() { this->leaveScope(_block); });
return Block{_block.location, translateVector(_block.statements)};
return Block{_block.debugData, translateVector(_block.statements)};
}
Case ASTCopier::translate(Case const& _case)
{
return Case{_case.location, translate(_case.value), translate(_case.body)};
return Case{_case.debugData, translate(_case.value), translate(_case.body)};
}
Identifier ASTCopier::translate(Identifier const& _identifier)
{
return Identifier{_identifier.location, translateIdentifier(_identifier.name)};
return Identifier{_identifier.debugData, translateIdentifier(_identifier.name)};
}
Literal ASTCopier::translate(Literal const& _literal)
@@ -168,7 +168,7 @@ Literal ASTCopier::translate(Literal const& _literal)
TypedName ASTCopier::translate(TypedName const& _typedName)
{
return TypedName{_typedName.location, translateIdentifier(_typedName.name), _typedName.type};
return TypedName{_typedName.debugData, translateIdentifier(_typedName.name), _typedName.type};
}
YulString FunctionCopier::translateIdentifier(YulString _name)
@@ -95,13 +95,13 @@ void CommonSubexpressionEliminator::visit(Expression& _e)
if (Identifier const* identifier = get_if<Identifier>(&_e))
{
YulString name = identifier->name;
if (m_value.count(name))
YulString identifierName = identifier->name;
if (m_value.count(identifierName))
{
assertThrow(m_value.at(name).value, OptimizerException, "");
if (Identifier const* value = get_if<Identifier>(m_value.at(name).value))
assertThrow(m_value.at(identifierName).value, OptimizerException, "");
if (Identifier const* value = get_if<Identifier>(m_value.at(identifierName).value))
if (inScope(value->name))
_e = Identifier{locationOf(_e), value->name};
_e = Identifier{debugDataOf(_e), value->name};
}
}
else
@@ -120,7 +120,7 @@ void CommonSubexpressionEliminator::visit(Expression& _e)
continue;
if (SyntacticallyEqual{}(_e, *value.value) && inScope(variable))
{
_e = Identifier{locationOf(_e), variable};
_e = Identifier{debugDataOf(_e), variable};
break;
}
}
+5 -5
View File
@@ -44,8 +44,8 @@ void ConditionalSimplifier::operator()(Switch& _switch)
(*this)(*_case.value);
_case.body.statements.insert(_case.body.statements.begin(),
Assignment{
_case.body.location,
{Identifier{_case.body.location, expr}},
_case.body.debugData,
{Identifier{_case.body.debugData, expr}},
make_unique<Expression>(*_case.value)
}
);
@@ -72,12 +72,12 @@ void ConditionalSimplifier::operator()(Block& _block)
)
{
YulString condition = std::get<Identifier>(*_if.condition).name;
langutil::SourceLocation location = _if.location;
std::shared_ptr<DebugData const> debugData = _if.debugData;
return make_vector<Statement>(
std::move(_s),
Assignment{
location,
{Identifier{location, condition}},
debugData,
{Identifier{debugData, condition}},
make_unique<Expression>(m_dialect.zeroLiteralForType(m_dialect.boolType))
}
);
+12 -14
View File
@@ -38,14 +38,14 @@ namespace
{
ExpressionStatement makeDiscardCall(
langutil::SourceLocation const& _location,
std::shared_ptr<DebugData const> const& _debugData,
BuiltinFunction const& _discardFunction,
Expression&& _expression
)
{
return {_location, FunctionCall{
_location,
Identifier{_location, _discardFunction.name},
return {_debugData, FunctionCall{
_debugData,
Identifier{_debugData, _discardFunction.name},
{std::move(_expression)}
}};
}
@@ -126,7 +126,7 @@ void ControlFlowSimplifier::visit(Statement& _st)
if (isTerminating && m_numContinueStatements == 0 && m_numBreakStatements == 0)
{
If replacement{forLoop.location, std::move(forLoop.condition), std::move(forLoop.body)};
If replacement{forLoop.debugData, std::move(forLoop.condition), std::move(forLoop.body)};
if (controlFlow == TerminationFinder::ControlFlow::Break)
replacement.body.statements.resize(replacement.body.statements.size() - 1);
_st = std::move(replacement);
@@ -149,7 +149,7 @@ void ControlFlowSimplifier::simplify(std::vector<yul::Statement>& _statements)
{
OptionalStatements s = vector<Statement>{};
s->emplace_back(makeDiscardCall(
_ifStmt.location,
_ifStmt.debugData,
*m_dialect.discardFunction(m_dialect.boolType),
std::move(*_ifStmt.condition)
));
@@ -191,10 +191,8 @@ OptionalStatements ControlFlowSimplifier::reduceNoCaseSwitch(Switch& _switchStmt
if (!discardFunction)
return {};
auto loc = locationOf(*_switchStmt.expression);
return make_vector<Statement>(makeDiscardCall(
loc,
debugDataOf(*_switchStmt.expression),
*discardFunction,
std::move(*_switchStmt.expression)
));
@@ -205,17 +203,17 @@ OptionalStatements ControlFlowSimplifier::reduceSingleCaseSwitch(Switch& _switch
yulAssert(_switchStmt.cases.size() == 1, "Expected only one case!");
auto& switchCase = _switchStmt.cases.front();
auto loc = locationOf(*_switchStmt.expression);
shared_ptr<DebugData const> debugData = debugDataOf(*_switchStmt.expression);
YulString type = m_typeInfo.typeOf(*_switchStmt.expression);
if (switchCase.value)
{
if (!m_dialect.equalityFunction(type))
return {};
return make_vector<Statement>(If{
std::move(_switchStmt.location),
std::move(_switchStmt.debugData),
make_unique<Expression>(FunctionCall{
loc,
Identifier{loc, m_dialect.equalityFunction(type)->name},
debugData,
Identifier{debugData, m_dialect.equalityFunction(type)->name},
{std::move(*switchCase.value), std::move(*_switchStmt.expression)}
}),
std::move(switchCase.body)
@@ -228,7 +226,7 @@ OptionalStatements ControlFlowSimplifier::reduceSingleCaseSwitch(Switch& _switch
return make_vector<Statement>(
makeDiscardCall(
loc,
debugData,
*m_dialect.discardFunction(type),
std::move(*_switchStmt.expression)
),
+1 -1
View File
@@ -39,5 +39,5 @@ void ExpressionSimplifier::visit(Expression& _expression)
ASTModifier::visit(_expression);
while (auto const* match = SimplificationRules::findFirstMatch(_expression, m_dialect, m_value))
_expression = match->action().toExpression(locationOf(_expression));
_expression = match->action().toExpression(debugDataOf(_expression));
}
+4 -4
View File
@@ -101,15 +101,15 @@ void ExpressionSplitter::outlineExpression(Expression& _expr)
visit(_expr);
SourceLocation location = locationOf(_expr);
shared_ptr<DebugData const> debugData = debugDataOf(_expr);
YulString var = m_nameDispenser.newName({});
YulString type = m_typeInfo.typeOf(_expr);
m_statementsToPrefix.emplace_back(VariableDeclaration{
location,
{{TypedName{location, var, type}}},
debugData,
{{TypedName{debugData, var, type}}},
make_unique<Expression>(std::move(_expr))
});
_expr = Identifier{location, var};
_expr = Identifier{debugData, var};
m_typeInfo.setVariableType(var, type);
}
@@ -39,25 +39,25 @@ void ForLoopConditionIntoBody::operator()(ForLoop& _forLoop)
!holds_alternative<Identifier>(*_forLoop.condition)
)
{
langutil::SourceLocation const loc = locationOf(*_forLoop.condition);
shared_ptr<DebugData const> debugData = debugDataOf(*_forLoop.condition);
_forLoop.body.statements.emplace(
begin(_forLoop.body.statements),
If {
loc,
debugData,
make_unique<Expression>(
FunctionCall {
loc,
{loc, m_dialect.booleanNegationFunction()->name},
debugData,
{debugData, m_dialect.booleanNegationFunction()->name},
util::make_vector<Expression>(std::move(*_forLoop.condition))
}
),
Block {loc, util::make_vector<Statement>(Break{{}})}
Block {debugData, util::make_vector<Statement>(Break{{}})}
}
);
_forLoop.condition = make_unique<Expression>(
Literal {
loc,
debugData,
LiteralKind::Boolean,
"true"_yulstring,
m_dialect.boolType
@@ -55,7 +55,7 @@ void ForLoopConditionOutOfBody::operator()(ForLoop& _forLoop)
return;
YulString iszero = m_dialect.booleanNegationFunction()->name;
langutil::SourceLocation location = locationOf(*firstStatement.condition);
shared_ptr<DebugData const> debugData = debugDataOf(*firstStatement.condition);
if (
holds_alternative<FunctionCall>(*firstStatement.condition) &&
@@ -64,8 +64,8 @@ void ForLoopConditionOutOfBody::operator()(ForLoop& _forLoop)
_forLoop.condition = make_unique<Expression>(std::move(std::get<FunctionCall>(*firstStatement.condition).arguments.front()));
else
_forLoop.condition = make_unique<Expression>(FunctionCall{
location,
Identifier{location, iszero},
debugData,
Identifier{debugData, iszero},
util::make_vector<Expression>(
std::move(*firstStatement.condition)
)
+5 -5
View File
@@ -268,7 +268,7 @@ vector<Statement> InlineModifier::performInline(Statement& _statement, FunctionC
auto newVariable = [&](TypedName const& _existingVariable, Expression* _value) {
YulString newName = m_nameDispenser.newName(_existingVariable.name);
variableReplacements[_existingVariable.name] = newName;
VariableDeclaration varDecl{_funCall.location, {{_funCall.location, newName, _existingVariable.type}}, {}};
VariableDeclaration varDecl{_funCall.debugData, {{_funCall.debugData, newName, _existingVariable.type}}, {}};
if (_value)
varDecl.value = make_unique<Expression>(std::move(*_value));
else
@@ -290,10 +290,10 @@ vector<Statement> InlineModifier::performInline(Statement& _statement, FunctionC
{
for (size_t i = 0; i < _assignment.variableNames.size(); ++i)
newStatements.emplace_back(Assignment{
_assignment.location,
_assignment.debugData,
{_assignment.variableNames[i]},
make_unique<Expression>(Identifier{
_assignment.location,
_assignment.debugData,
variableReplacements.at(function->returnVariables[i].name)
})
});
@@ -302,10 +302,10 @@ vector<Statement> InlineModifier::performInline(Statement& _statement, FunctionC
{
for (size_t i = 0; i < _varDecl.variables.size(); ++i)
newStatements.emplace_back(VariableDeclaration{
_varDecl.location,
_varDecl.debugData,
{std::move(_varDecl.variables[i])},
make_unique<Expression>(Identifier{
_varDecl.location,
_varDecl.debugData,
variableReplacements.at(function->returnVariables[i].name)
})
});
+1 -1
View File
@@ -35,7 +35,7 @@ void FunctionGrouper::operator()(Block& _block)
return;
vector<Statement> reordered;
reordered.emplace_back(Block{_block.location, {}});
reordered.emplace_back(Block{_block.debugData, {}});
for (auto&& statement: _block.statements)
{
+1 -1
View File
@@ -41,7 +41,7 @@ void FunctionHoister::operator()(Block& _block)
if (holds_alternative<FunctionDefinition>(statement))
{
m_functions.emplace_back(std::move(statement));
statement = Block{_block.location, {}};
statement = Block{_block.debugData, {}};
}
}
removeEmptyBlocks(_block);
+1 -1
View File
@@ -104,7 +104,7 @@ FunctionDefinition FunctionSpecializer::specialize(
if (argument)
missingVariableDeclarations.emplace_back(
VariableDeclaration{
_f.location,
_f.debugData,
vector<TypedName>{newFunction.parameters[index]},
make_unique<Expression>(move(*argument))
}
+1 -1
View File
@@ -84,7 +84,7 @@ Expression KnowledgeBase::simplify(Expression _expression)
arg = simplify(arg);
if (auto match = SimplificationRules::findFirstMatch(_expression, m_dialect, m_variableValues))
return simplify(match->action().toExpression(locationOf(_expression)));
return simplify(match->action().toExpression(debugDataOf(_expression)));
return _expression;
}
+3 -3
View File
@@ -85,12 +85,12 @@ void LoadResolver::tryResolve(
{
if (auto value = util::valueOrNullptr(m_storage, key))
if (inScope(*value))
_e = Identifier{locationOf(_e), *value};
_e = Identifier{debugDataOf(_e), *value};
}
else if (!m_containsMSize && _location == StoreLoadLocation::Memory)
if (auto value = util::valueOrNullptr(m_memory, key))
if (inScope(*value))
_e = Identifier{locationOf(_e), *value};
_e = Identifier{debugDataOf(_e), *value};
}
void LoadResolver::tryEvaluateKeccak(
@@ -140,7 +140,7 @@ void LoadResolver::tryEvaluateKeccak(
bytes contentAsBytes = toBigEndian(*memoryContent);
contentAsBytes.resize(static_cast<size_t>(*byteLength));
_e = Literal{
locationOf(_e),
debugDataOf(_e),
LiteralKind::Number,
YulString{u256(keccak256(contentAsBytes)).str()},
m_dialect.defaultType
+1 -1
View File
@@ -44,7 +44,7 @@ void MainFunction::operator()(Block& _block)
Block& block = std::get<Block>(_block.statements[0]);
FunctionDefinition main{
block.location,
block.debugData,
"main"_yulstring,
{},
{},
@@ -79,7 +79,7 @@ void ReasoningBasedSimplifier::operator()(If& _if)
if (result == CheckResult::UNSATISFIABLE)
{
Literal trueCondition = m_dialect.trueLiteral();
trueCondition.location = locationOf(*_if.condition);
trueCondition.debugData = debugDataOf(*_if.condition);
_if.condition = make_unique<yul::Expression>(move(trueCondition));
}
else
@@ -91,7 +91,7 @@ void ReasoningBasedSimplifier::operator()(If& _if)
if (result2 == CheckResult::UNSATISFIABLE)
{
Literal falseCondition = m_dialect.zeroLiteralForType(m_dialect.boolType);
falseCondition.location = locationOf(*_if.condition);
falseCondition.debugData = debugDataOf(*_if.condition);
_if.condition = make_unique<yul::Expression>(move(falseCondition));
_if.body = yul::Block{};
// Nothing left to be done.
+5 -5
View File
@@ -66,12 +66,12 @@ void SSAReverser::operator()(Block& _block)
else
return util::make_vector<Statement>(
Assignment{
std::move(assignment->location),
std::move(assignment->debugData),
assignment->variableNames,
std::move(varDecl->value)
},
VariableDeclaration{
std::move(varDecl->location),
std::move(varDecl->debugData),
std::move(varDecl->variables),
std::make_unique<Expression>(assignment->variableNames.front())
}
@@ -97,17 +97,17 @@ void SSAReverser::operator()(Block& _block)
)
{
auto varIdentifier2 = std::make_unique<Expression>(Identifier{
varDecl2->variables.front().location,
varDecl2->variables.front().debugData,
varDecl2->variables.front().name
});
return util::make_vector<Statement>(
VariableDeclaration{
std::move(varDecl2->location),
std::move(varDecl2->debugData),
std::move(varDecl2->variables),
std::move(varDecl->value)
},
VariableDeclaration{
std::move(varDecl->location),
std::move(varDecl->debugData),
std::move(varDecl->variables),
std::move(varIdentifier2)
}
+15 -16
View File
@@ -85,19 +85,19 @@ void IntroduceSSA::operator()(Block& _block)
// Replace "let a := v" by "let a_1 := v let a := a_1"
// Replace "let a, b := v" by "let a_1, b_1 := v let a := a_1 let b := b_2"
auto loc = varDecl.location;
shared_ptr<DebugData const> debugData = varDecl.debugData;
vector<Statement> statements;
statements.emplace_back(VariableDeclaration{loc, {}, std::move(varDecl.value)});
statements.emplace_back(VariableDeclaration{debugData, {}, std::move(varDecl.value)});
TypedNameList newVariables;
for (auto const& var: varDecl.variables)
{
YulString oldName = var.name;
YulString newName = m_nameDispenser.newName(oldName);
newVariables.emplace_back(TypedName{loc, newName, var.type});
newVariables.emplace_back(TypedName{debugData, newName, var.type});
statements.emplace_back(VariableDeclaration{
loc,
{TypedName{loc, oldName, var.type}},
make_unique<Expression>(Identifier{loc, newName})
debugData,
{TypedName{debugData, oldName, var.type}},
make_unique<Expression>(Identifier{debugData, newName})
});
}
std::get<VariableDeclaration>(statements.front()).variables = std::move(newVariables);
@@ -112,23 +112,22 @@ void IntroduceSSA::operator()(Block& _block)
// Replace "a := v" by "let a_1 := v a := v"
// Replace "a, b := v" by "let a_1, b_1 := v a := a_1 b := b_2"
auto loc = assignment.location;
std::shared_ptr<DebugData const> debugData = assignment.debugData;
vector<Statement> statements;
statements.emplace_back(VariableDeclaration{loc, {}, std::move(assignment.value)});
statements.emplace_back(VariableDeclaration{debugData, {}, std::move(assignment.value)});
TypedNameList newVariables;
for (auto const& var: assignment.variableNames)
{
YulString oldName = var.name;
YulString newName = m_nameDispenser.newName(oldName);
newVariables.emplace_back(TypedName{
loc,
newVariables.emplace_back(TypedName{debugData,
newName,
m_typeInfo.typeOfVariable(oldName)
});
statements.emplace_back(Assignment{
loc,
{Identifier{loc, oldName}},
make_unique<Expression>(Identifier{loc, newName})
debugData,
{Identifier{debugData, oldName}},
make_unique<Expression>(Identifier{debugData, newName})
});
}
std::get<VariableDeclaration>(statements.front()).variables = std::move(newVariables);
@@ -238,9 +237,9 @@ void IntroduceControlFlowSSA::operator()(Block& _block)
{
YulString newName = m_nameDispenser.newName(toReassign);
toPrepend.emplace_back(VariableDeclaration{
locationOf(_s),
{TypedName{locationOf(_s), newName, m_typeInfo.typeOfVariable(toReassign)}},
make_unique<Expression>(Identifier{locationOf(_s), toReassign})
debugDataOf(_s),
{TypedName{debugDataOf(_s), newName, m_typeInfo.typeOfVariable(toReassign)}},
make_unique<Expression>(Identifier{debugDataOf(_s), toReassign})
});
assignedVariables.insert(toReassign);
}
+5 -6
View File
@@ -234,27 +234,26 @@ evmasm::Instruction Pattern::instruction() const
return m_instruction;
}
Expression Pattern::toExpression(SourceLocation const& _location) const
Expression Pattern::toExpression(shared_ptr<DebugData const> const& _debugData) const
{
if (matchGroup())
return ASTCopier().translate(matchGroupValue());
if (m_kind == PatternKind::Constant)
{
assertThrow(m_data, OptimizerException, "No match group and no constant value given.");
return Literal{_location, LiteralKind::Number, YulString{util::formatNumber(*m_data)}, {}};
return Literal{_debugData, LiteralKind::Number, YulString{util::formatNumber(*m_data)}, {}};
}
else if (m_kind == PatternKind::Operation)
{
vector<Expression> arguments;
for (auto const& arg: m_arguments)
arguments.emplace_back(arg.toExpression(_location));
arguments.emplace_back(arg.toExpression(_debugData));
string name = instructionInfo(m_instruction).name;
transform(begin(name), end(name), begin(name), [](auto _c) { return tolower(_c); });
return FunctionCall{
_location,
Identifier{_location, YulString{name}},
return FunctionCall{_debugData,
Identifier{_debugData, YulString{name}},
std::move(arguments)
};
}
+1 -1
View File
@@ -130,7 +130,7 @@ public:
/// Turns this pattern into an actual expression. Should only be called
/// for patterns resulting from an action, i.e. with match groups assigned.
Expression toExpression(langutil::SourceLocation const& _location) const;
Expression toExpression(std::shared_ptr<DebugData const> const& _debugData) const;
private:
Expression const& matchGroupValue() const;
+19 -20
View File
@@ -31,7 +31,7 @@ namespace
{
vector<Statement> generateMemoryStore(
Dialect const& _dialect,
langutil::SourceLocation const& _loc,
shared_ptr<DebugData const> const& _debugData,
YulString _mpos,
Expression _value
)
@@ -39,26 +39,26 @@ vector<Statement> generateMemoryStore(
BuiltinFunction const* memoryStoreFunction = _dialect.memoryStoreFunction(_dialect.defaultType);
yulAssert(memoryStoreFunction, "");
vector<Statement> result;
result.emplace_back(ExpressionStatement{_loc, FunctionCall{
_loc,
Identifier{_loc, memoryStoreFunction->name},
result.emplace_back(ExpressionStatement{_debugData, FunctionCall{
_debugData,
Identifier{_debugData, memoryStoreFunction->name},
{
Literal{_loc, LiteralKind::Number, _mpos, {}},
Literal{_debugData, LiteralKind::Number, _mpos, {}},
std::move(_value)
}
}});
return result;
}
FunctionCall generateMemoryLoad(Dialect const& _dialect, langutil::SourceLocation const& _loc, YulString _mpos)
FunctionCall generateMemoryLoad(Dialect const& _dialect, std::shared_ptr<DebugData const> const& _debugData, YulString _mpos)
{
BuiltinFunction const* memoryLoadFunction = _dialect.memoryLoadFunction(_dialect.defaultType);
yulAssert(memoryLoadFunction, "");
return FunctionCall{
_loc,
Identifier{_loc, memoryLoadFunction->name}, {
_debugData,
Identifier{_debugData, memoryLoadFunction->name}, {
Literal{
_loc,
_debugData,
LiteralKind::Number,
_mpos,
{}
@@ -123,39 +123,38 @@ void StackToMemoryMover::operator()(Block& _block)
if (!leftHandSideNeedsMoving)
return {};
langutil::SourceLocation loc = _stmt.location;
if (_variables.size() == 1)
{
optional<YulString> offset = m_memoryOffsetTracker(_variables.front().name);
yulAssert(offset, "");
return generateMemoryStore(
m_context.dialect,
loc,
_stmt.debugData,
*offset,
_stmt.value ? *std::move(_stmt.value) : Literal{loc, LiteralKind::Number, "0"_yulstring, {}}
_stmt.value ? *std::move(_stmt.value) : Literal{_stmt.debugData, LiteralKind::Number, "0"_yulstring, {}}
);
}
VariableDeclaration tempDecl{loc, {}, std::move(_stmt.value)};
VariableDeclaration tempDecl{_stmt.debugData, {}, std::move(_stmt.value)};
vector<Statement> memoryAssignments;
vector<Statement> variableAssignments;
for (auto& var: _variables)
{
YulString tempVarName = m_nameDispenser.newName(var.name);
tempDecl.variables.emplace_back(TypedName{var.location, tempVarName, {}});
tempDecl.variables.emplace_back(TypedName{var.debugData, tempVarName, {}});
if (optional<YulString> offset = m_memoryOffsetTracker(var.name))
memoryAssignments += generateMemoryStore(
m_context.dialect,
loc,
_stmt.debugData,
*offset,
Identifier{loc, tempVarName}
Identifier{_stmt.debugData, tempVarName}
);
else
variableAssignments.emplace_back(StatementType{
loc, {move(var)},
make_unique<Expression>(Identifier{loc, tempVarName})
_stmt.debugData,
{move(var)},
make_unique<Expression>(Identifier{_stmt.debugData, tempVarName})
});
}
std::vector<Statement> result;
@@ -191,7 +190,7 @@ void StackToMemoryMover::visit(Expression& _expression)
ASTModifier::visit(_expression);
if (Identifier* identifier = std::get_if<Identifier>(&_expression))
if (optional<YulString> offset = m_memoryOffsetTracker(identifier->name))
_expression = generateMemoryLoad(m_context.dialect, identifier->location, *offset);
_expression = generateMemoryLoad(m_context.dialect, identifier->debugData, *offset);
}
optional<YulString> StackToMemoryMover::VariableMemoryOffsetTracker::operator()(YulString _variable) const
+8 -10
View File
@@ -40,33 +40,31 @@ FunctionDefinition unusedFunctionsCommon::createLinkingFunction(
auto generateTypedName = [&](TypedName t)
{
return TypedName{
t.location,
t.debugData,
_nameDispenser.newName(t.name),
t.type
};
};
langutil::SourceLocation loc = _original.location;
FunctionDefinition linkingFunction{
loc,
_original.debugData,
_linkingFunctionName,
util::applyMap(_original.parameters, generateTypedName),
util::applyMap(_original.returnVariables, generateTypedName),
{loc, {}} // body
{_original.debugData, {}} // body
};
FunctionCall call{loc, Identifier{loc, _originalFunctionName}, {}};
FunctionCall call{_original.debugData, Identifier{_original.debugData, _originalFunctionName}, {}};
for (auto const& p: filter(linkingFunction.parameters, _usedParametersAndReturns.first))
call.arguments.emplace_back(Identifier{loc, p.name});
call.arguments.emplace_back(Identifier{_original.debugData, p.name});
Assignment assignment{loc, {}, nullptr};
Assignment assignment{_original.debugData, {}, nullptr};
for (auto const& r: filter(linkingFunction.returnVariables, _usedParametersAndReturns.second))
assignment.variableNames.emplace_back(Identifier{loc, r.name});
assignment.variableNames.emplace_back(Identifier{_original.debugData, r.name});
if (assignment.variableNames.empty())
linkingFunction.body.statements.emplace_back(ExpressionStatement{loc, std::move(call)});
linkingFunction.body.statements.emplace_back(ExpressionStatement{_original.debugData, std::move(call)});
else
{
assignment.value = std::make_unique<Expression>(std::move(call));
+7 -7
View File
@@ -72,7 +72,7 @@ void UnusedPruner::operator()(Block& _block)
if (!used(funDef.name))
{
subtractReferences(ReferencesCounter::countReferences(funDef.body));
statement = Block{std::move(funDef.location), {}};
statement = Block{std::move(funDef.debugData), {}};
}
}
else if (holds_alternative<VariableDeclaration>(statement))
@@ -90,19 +90,19 @@ void UnusedPruner::operator()(Block& _block)
))
{
if (!varDecl.value)
statement = Block{std::move(varDecl.location), {}};
statement = Block{std::move(varDecl.debugData), {}};
else if (
SideEffectsCollector(m_dialect, *varDecl.value, m_functionSideEffects).
canBeRemoved(m_allowMSizeOptimization)
)
{
subtractReferences(ReferencesCounter::countReferences(*varDecl.value));
statement = Block{std::move(varDecl.location), {}};
statement = Block{std::move(varDecl.debugData), {}};
}
else if (varDecl.variables.size() == 1 && m_dialect.discardFunction(varDecl.variables.front().type))
statement = ExpressionStatement{varDecl.location, FunctionCall{
varDecl.location,
{varDecl.location, m_dialect.discardFunction(varDecl.variables.front().type)->name},
statement = ExpressionStatement{varDecl.debugData, FunctionCall{
varDecl.debugData,
{varDecl.debugData, m_dialect.discardFunction(varDecl.variables.front().type)->name},
{*std::move(varDecl.value)}
}};
}
@@ -116,7 +116,7 @@ void UnusedPruner::operator()(Block& _block)
)
{
subtractReferences(ReferencesCounter::countReferences(exprStmt.expression));
statement = Block{std::move(exprStmt.location), {}};
statement = Block{std::move(exprStmt.debugData), {}};
}
}
+1 -2
View File
@@ -47,11 +47,10 @@ void VarDeclInitializer::operator()(Block& _block)
else
{
OptionalStatements ret{vector<Statement>{}};
langutil::SourceLocation loc{std::move(_varDecl.location)};
for (auto& var: _varDecl.variables)
{
unique_ptr<Expression> expr = make_unique<Expression >(m_dialect.zeroLiteralForType(var.type));
ret->emplace_back(VariableDeclaration{loc, {std::move(var)}, std::move(expr)});
ret->emplace_back(VariableDeclaration{std::move(_varDecl.debugData), {std::move(var)}, std::move(expr)});
}
return ret;
}