Interface ExpressionMatcher<T extends PatternExpression>

Type Parameters:
T - the type of expression matched
All Known Implementing Classes:
AbstractExpressionMatcher, AnyMatcher, BinaryExpressionMatcher, BinaryExpressionMatcher.Commutative, ConstantValueMatcher, FieldSizeMatcher, OperandValueMatcher, UnaryExpressionMatcher

public interface ExpressionMatcher<T extends PatternExpression>
A matcher for a form of patten expression

Some solvers may need to apply sophisticated heuristics to recognize certain forms that commonly occur in pattern expressions. These can certainly be programmed manually, but for many cases, the form recognition can be accomplished by describing the form as an expression matcher. For a shorter syntax to construct such matchers. See ExpressionMatcher.Context.

  • Method Details

    • match

      default Map<ExpressionMatcher<?>,PatternExpression> match(PatternExpression expression)
      Attempt to match the given expression, recording the substitutions if successful
      Parameters:
      expression - the expression to match
      Returns:
      a map of matchers to substituted expressions
    • get

      default T get(Map<ExpressionMatcher<?>,PatternExpression> results)
      Retrieve the expression substituted for this matcher from a previous successful match

      Calling this on the root matcher is relatively useless, as it would simply return the expression passed to match(PatternExpression). Instead, sub-matchers should be saved in a variable, allowing their values to be retrieved. See ExpressionMatcher.Context, for an example.

      Parameters:
      results - the previous match results
      Returns:
      the substituted expression
    • match

      boolean match(PatternExpression expression, Map<ExpressionMatcher<?>,PatternExpression> result)
      Attempt to match the given expression, recording substitutions in the given map

      Even if the match was unsuccessful, the result map may contain attempted substitutions. Thus, the map should be discarded if unsuccessful.

      Parameters:
      expression - the expression to match
      result - a map to store matchers to substituted expressions
      Returns:
      true if successful, false if not