mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge pull request #6318 from ethereum/signal-failure-and-such
Allow simplification patterns to signal failure
This commit is contained in:
commit
5245a66d91
@ -196,13 +196,16 @@ ExpressionClasses::Id ExpressionClasses::tryToSimplify(Expression const& _expr)
|
|||||||
if (auto match = rules.findFirstMatch(_expr, *this))
|
if (auto match = rules.findFirstMatch(_expr, *this))
|
||||||
{
|
{
|
||||||
// Debug info
|
// Debug info
|
||||||
//cout << "Simplifying " << *_expr.item << "(";
|
if (false)
|
||||||
//for (Id arg: _expr.arguments)
|
{
|
||||||
// cout << fullDAGToString(arg) << ", ";
|
cout << "Simplifying " << *_expr.item << "(";
|
||||||
//cout << ")" << endl;
|
for (Id arg: _expr.arguments)
|
||||||
//cout << "with rule " << match->first.toString() << endl;
|
cout << fullDAGToString(arg) << ", ";
|
||||||
//ExpressionTemplate t(match->second());
|
cout << ")" << endl;
|
||||||
//cout << "to " << match->second().toString() << endl;
|
cout << "with rule " << match->pattern.toString() << endl;
|
||||||
|
cout << "to " << match->action().toString() << endl;
|
||||||
|
}
|
||||||
|
|
||||||
return rebuildExpression(ExpressionTemplate(match->action(), _expr.item->location()));
|
return rebuildExpression(ExpressionTemplate(match->action(), _expr.item->location()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,9 +36,22 @@ namespace solidity
|
|||||||
template <class Pattern>
|
template <class Pattern>
|
||||||
struct SimplificationRule
|
struct SimplificationRule
|
||||||
{
|
{
|
||||||
|
SimplificationRule(
|
||||||
|
Pattern _pattern,
|
||||||
|
std::function<Pattern()> _action,
|
||||||
|
bool _removesNonConstants,
|
||||||
|
std::function<bool()> _feasible = {}
|
||||||
|
):
|
||||||
|
pattern(std::move(_pattern)),
|
||||||
|
action(std::move(_action)),
|
||||||
|
removesNonConstants(_removesNonConstants),
|
||||||
|
feasible(std::move(_feasible))
|
||||||
|
{}
|
||||||
|
|
||||||
Pattern pattern;
|
Pattern pattern;
|
||||||
std::function<Pattern()> action;
|
std::function<Pattern()> action;
|
||||||
bool removesNonConstants;
|
bool removesNonConstants;
|
||||||
|
std::function<bool()> feasible;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -51,7 +51,9 @@ SimplificationRule<Pattern> const* Rules::findFirstMatch(
|
|||||||
for (auto const& rule: m_rules[uint8_t(_expr.item->instruction())])
|
for (auto const& rule: m_rules[uint8_t(_expr.item->instruction())])
|
||||||
{
|
{
|
||||||
if (rule.pattern.matches(_expr, _classes))
|
if (rule.pattern.matches(_expr, _classes))
|
||||||
return &rule;
|
if (!rule.feasible || rule.feasible())
|
||||||
|
return &rule;
|
||||||
|
|
||||||
resetMatchGroups();
|
resetMatchGroups();
|
||||||
}
|
}
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
@ -51,7 +51,8 @@ SimplificationRule<Pattern> const* SimplificationRules::findFirstMatch(
|
|||||||
{
|
{
|
||||||
rules.resetMatchGroups();
|
rules.resetMatchGroups();
|
||||||
if (rule.pattern.matches(_expr, _dialect, _ssaValues))
|
if (rule.pattern.matches(_expr, _dialect, _ssaValues))
|
||||||
return &rule;
|
if (!rule.feasible || rule.feasible())
|
||||||
|
return &rule;
|
||||||
}
|
}
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user