Interface ExpressionMatcher.Context
- All Known Implementing Classes:
OrExpressionSolver.Matchers
- Enclosing interface:
ExpressionMatcher<T extends PatternExpression>
Implementations of this interface have easy access to factory methods for each kind of
PatternExpression
. Additionally, the class itself provide a convenient container for
saving important sub-matchers, so that important sub-expression can be readily retrieved. For
example:
static class MyMatchers implements ExpressionMatcher.Context {
ExpressionMatcher<ConstantValue> shamt = var(ConstantValue.class);
ExpressionMatcher<LeftShiftExpression> exp = shl(var(), shamt);
}
static final MyMatchers MATCHERS = new MyMatchers();
public long getConstantShift(PatternExpression expression) {
Map<ExpressionMatcher<?>, PatternExpression> result = MATCHERS.exp.match(expression);
if (result == null) {
return -1;
}
return MATCHERS.shamt.get(result).getValue();
}
Saving a sub-matcher to a field (as in the example) also permits that sub-matcher to appear
in multiple places. In that case, the sub-matcher must match identical expressions wherever
it appears. For example, if cv
matches any constant value, then plus(cv, cv)
would match 2 + 2
, but not 2 + 3
.
-
Method Summary
Modifier and TypeMethodDescriptiondefault ExpressionMatcher
<AndExpression> and
(ExpressionMatcher<?> left, ExpressionMatcher<?> right) Match the formL & R
orR & L
default ExpressionMatcher
<ConstantValue> cv
(long value) Match a given constant valuedefault ExpressionMatcher
<DivExpression> div
(ExpressionMatcher<?> left, ExpressionMatcher<?> right) Match the formL / R
default ExpressionMatcher
<PatternValue> fldSz
(ExpressionMatcher<?> size) Match a field by its sizedefault ExpressionMatcher
<MultExpression> mul
(ExpressionMatcher<?> left, ExpressionMatcher<?> right) Match the formL * R
orR * L
default ExpressionMatcher
<MinusExpression> neg
(ExpressionMatcher<?> unary) Match the form-U
default ExpressionMatcher
<NotExpression> not
(ExpressionMatcher<?> unary) Match the form~U
default ExpressionMatcher
<OperandValue> opnd
(ExpressionMatcher<?> def) Match an operand valuedefault ExpressionMatcher
<OrExpression> or
(ExpressionMatcher<?> left, ExpressionMatcher<?> right) Match the formL | R
orR | L
default ExpressionMatcher
<PlusExpression> plus
(ExpressionMatcher<?> left, ExpressionMatcher<?> right) Match the formL + R
orR + L
default ExpressionMatcher
<LeftShiftExpression> shl
(ExpressionMatcher<?> left, ExpressionMatcher<?> right) Match the formL << R
default ExpressionMatcher
<RightShiftExpression> shr
(ExpressionMatcher<?> left, ExpressionMatcher<?> right) Match the formL >> R
default ExpressionMatcher
<SubExpression> sub
(ExpressionMatcher<?> left, ExpressionMatcher<?> right) Match the formL - R
default ExpressionMatcher
<PatternExpression> var()
Match any expressiondefault <T extends PatternExpression>
ExpressionMatcher<T> Match any expression of the given typedefault ExpressionMatcher
<XorExpression> xor
(ExpressionMatcher<?> left, ExpressionMatcher<?> right) Match the formL $xor R
orR $xor L
-
Method Details
-
and
Match the formL & R
orR & L
- Parameters:
left
- the matcher for the left operandright
- the matcher for the right operand- Returns:
- the matcher
-
div
Match the formL / R
- Parameters:
left
- the matcher for the dividendright
- the matcher for the divisor- Returns:
- the matcher for the quotient
-
shl
default ExpressionMatcher<LeftShiftExpression> shl(ExpressionMatcher<?> left, ExpressionMatcher<?> right) Match the formL << R
- Parameters:
left
- the matcher for the left operandright
- the matcher for the shift amount- Returns:
- the matcher
-
mul
default ExpressionMatcher<MultExpression> mul(ExpressionMatcher<?> left, ExpressionMatcher<?> right) Match the formL * R
orR * L
- Parameters:
left
- the matcher for the left factorright
- the matcher for the right factor- Returns:
- the matcher for the product
-
or
Match the formL | R
orR | L
- Parameters:
left
- the matcher for the left operandright
- the matcher for the right operand- Returns:
- the matcher
-
plus
default ExpressionMatcher<PlusExpression> plus(ExpressionMatcher<?> left, ExpressionMatcher<?> right) Match the formL + R
orR + L
- Parameters:
left
- the matcher for the left termright
- the matcher for the right term- Returns:
- the matcher for the sum
-
shr
default ExpressionMatcher<RightShiftExpression> shr(ExpressionMatcher<?> left, ExpressionMatcher<?> right) Match the formL >> R
- Parameters:
left
- the matcher for the left operandright
- the matcher for the shift amount- Returns:
- the matcher
-
sub
Match the formL - R
- Parameters:
left
- the matcher for the left termright
- the matcher for the right term- Returns:
- the matcher for the difference
-
xor
Match the formL $xor R
orR $xor L
- Parameters:
left
- the matcher for the left operandright
- the matcher for the right operand- Returns:
- the matcher
-
cv
Match a given constant valueNOTE: To match an unspecified constant value, use
var(Class)
withConstantValue
.- Parameters:
value
- the value to match- Returns:
- the matcher
-
var
Match any expressionThis matches any expression without consideration of its operands, except insofar when it appears in multiple places, it will check that subsequent matches are identical to the first.
- Returns:
- the matcher
-
var
Match any expression of the given type- Type Parameters:
T
- the type of expression to match- Parameters:
cls
- the class of expression to match- Returns:
- the matcher
-
opnd
Match an operand valueTypically, this must wrap any use of a field, since that field is considered an operand from the constructor's perspective.
- Parameters:
def
- the matcher for the operand's defining expression.- Returns:
- the operand matcher
-
fldSz
Match a field by its sizeThis matches either a
TokenField
or aContextField
. If matched, it then passes aConstantValue
of the field's size (in bits) into the given size matcher.- Parameters:
size
- the matcher for the field's size- Returns:
- the field matcher
-
neg
Match the form-U
- Parameters:
unary
- the child matcher- Returns:
- the matcher
-
not
Match the form~U
- Parameters:
unary
- the child matcher- Returns:
- the matcher
-