mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Allow simplification patterns to signal failure
This commit is contained in:
parent
c7824932a4
commit
f95388011b
@ -203,6 +203,7 @@ ExpressionClasses::Id ExpressionClasses::tryToSimplify(Expression const& _expr)
|
||||
//cout << "with rule " << match->first.toString() << endl;
|
||||
//ExpressionTemplate t(match->second());
|
||||
//cout << "to " << match->second().toString() << endl;
|
||||
|
||||
return rebuildExpression(ExpressionTemplate(match->action(), _expr.item->location()));
|
||||
}
|
||||
|
||||
|
@ -36,9 +36,22 @@ namespace solidity
|
||||
template <class Pattern>
|
||||
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;
|
||||
std::function<Pattern()> action;
|
||||
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())])
|
||||
{
|
||||
if (rule.pattern.matches(_expr, _classes))
|
||||
return &rule;
|
||||
if (!rule.feasible || rule.feasible())
|
||||
return &rule;
|
||||
|
||||
resetMatchGroups();
|
||||
}
|
||||
return nullptr;
|
||||
|
@ -51,7 +51,8 @@ SimplificationRule<Pattern> const* SimplificationRules::findFirstMatch(
|
||||
{
|
||||
rules.resetMatchGroups();
|
||||
if (rule.pattern.matches(_expr, _dialect, _ssaValues))
|
||||
return &rule;
|
||||
if (!rule.feasible || rule.feasible())
|
||||
return &rule;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user