Allow simplification patterns to signal failure

This commit is contained in:
Alex Beregszaszi 2019-02-25 11:31:35 +00:00 committed by Mathias Baumann
parent c7824932a4
commit f95388011b
4 changed files with 19 additions and 2 deletions

View File

@ -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()));
}

View File

@ -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;
};
}

View File

@ -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;

View File

@ -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;
}