mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Update to let inlining
This commit is contained in:
parent
bbd7ef447f
commit
4101c67cba
@ -484,8 +484,8 @@ namespace
|
|||||||
SMTLib2Expression & operator[](std::string const& varName)
|
SMTLib2Expression & operator[](std::string const& varName)
|
||||||
{
|
{
|
||||||
auto it = bindings.find(varName);
|
auto it = bindings.find(varName);
|
||||||
assert(it != bindings.end());
|
solAssert(it != bindings.end());
|
||||||
assert(!it->second.empty());
|
solAssert(!it->second.empty());
|
||||||
return it->second.back();
|
return it->second.back();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -529,47 +529,46 @@ namespace
|
|||||||
auto const& atom = asAtom(expr);
|
auto const& atom = asAtom(expr);
|
||||||
if (bindings.has(atom))
|
if (bindings.has(atom))
|
||||||
expr = bindings[atom];
|
expr = bindings[atom];
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
else
|
auto& subexprs = asSubExpressions(expr);
|
||||||
|
solAssert(!subexprs.empty());
|
||||||
|
auto const& first = subexprs.at(0);
|
||||||
|
if (isAtom(first) && asAtom(first) == "let")
|
||||||
{
|
{
|
||||||
auto& subexprs = asSubExpressions(expr);
|
solAssert(subexprs.size() >= 3);
|
||||||
assert(!subexprs.empty());
|
solAssert(!isAtom(subexprs[1]));
|
||||||
auto const& first = subexprs.at(0);
|
auto& bindingExpressions = asSubExpressions(subexprs[1]);
|
||||||
if (isAtom(first) && asAtom(first) == "let")
|
// process new bindings
|
||||||
|
std::vector<std::pair<std::string, SMTLib2Expression>> newBindings;
|
||||||
|
for (auto& binding: bindingExpressions)
|
||||||
{
|
{
|
||||||
solAssert(!isAtom(subexprs[1]));
|
solAssert(!isAtom(binding));
|
||||||
auto& bindingExpressions = asSubExpressions(subexprs[1]);
|
auto& bindingPair = asSubExpressions(binding);
|
||||||
// process new bindings
|
solAssert(bindingPair.size() == 2);
|
||||||
std::vector<std::pair<std::string, SMTLib2Expression>> newBindings;
|
solAssert(isAtom(bindingPair.at(0)));
|
||||||
for (auto& binding: bindingExpressions)
|
inlineLetExpressions(bindingPair.at(1), bindings);
|
||||||
{
|
newBindings.emplace_back(asAtom(bindingPair.at(0)), bindingPair.at(1));
|
||||||
solAssert(!isAtom(binding));
|
|
||||||
auto& bindingPair = asSubExpressions(binding);
|
|
||||||
solAssert(bindingPair.size() == 2);
|
|
||||||
solAssert(isAtom(bindingPair.at(0)));
|
|
||||||
inlineLetExpressions(bindingPair.at(1), bindings);
|
|
||||||
newBindings.emplace_back(asAtom(bindingPair.at(0)), bindingPair.at(1));
|
|
||||||
}
|
|
||||||
bindings.pushScope();
|
|
||||||
for (auto&& [name, expr] : newBindings)
|
|
||||||
bindings.addBinding(std::move(name), std::move(expr));
|
|
||||||
newBindings.clear();
|
|
||||||
|
|
||||||
// get new subexpression
|
|
||||||
inlineLetExpressions(subexprs.at(2), bindings);
|
|
||||||
// remove the new bindings
|
|
||||||
bindings.popScope();
|
|
||||||
|
|
||||||
// update the expression
|
|
||||||
auto tmp = std::move(subexprs.at(2));
|
|
||||||
expr = std::move(tmp);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// not a let expression, just process all arguments
|
|
||||||
for (auto& subexpr: subexprs)
|
|
||||||
{
|
|
||||||
inlineLetExpressions(subexpr, bindings);
|
|
||||||
}
|
}
|
||||||
|
bindings.pushScope();
|
||||||
|
for (auto&& [name, expr]: newBindings)
|
||||||
|
bindings.addBinding(std::move(name), std::move(expr));
|
||||||
|
newBindings.clear();
|
||||||
|
|
||||||
|
// get new subexpression
|
||||||
|
inlineLetExpressions(subexprs.at(2), bindings);
|
||||||
|
// remove the new bindings
|
||||||
|
bindings.popScope();
|
||||||
|
|
||||||
|
// update the expression
|
||||||
|
auto tmp = std::move(subexprs.at(2));
|
||||||
|
expr = std::move(tmp);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// not a let expression, just process all arguments
|
||||||
|
for (auto& subexpr: subexprs)
|
||||||
|
{
|
||||||
|
inlineLetExpressions(subexpr, bindings);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user