public void AnyVariableExpressionShouldMatch() { var variable = new DummyVariable("variable"); var pattern = ExpressionPattern.Variable <DummyInstruction>(); Assert.True(pattern.Matches(new VariableExpression <DummyInstruction>(variable))); }
public void InstructionWithOneStackArgumentShouldResultInAssignmentAndExpressionStatementWithArgument() { var cfg = ConstructAst(new[] { DummyInstruction.Push(0, 1), DummyInstruction.Pop(1, 1), DummyInstruction.Ret(2) }); var variableCapture = new CaptureGroup("variable"); var pattern = new SequencePattern <Statement <DummyInstruction> >( // stack_slot = push 1() StatementPattern .Assignment <DummyInstruction>() .WithExpression(ExpressionPattern.Instruction(new DummyInstructionPattern(DummyOpCode.Push))) .CaptureVariables(variableCapture), // pop(stack_slot) StatementPattern.Expression(ExpressionPattern .Instruction(new DummyInstructionPattern(DummyOpCode.Pop)) .WithArguments(ExpressionPattern .Variable <DummyInstruction>() .CaptureVariable(variableCapture))), // ret() StatementPattern.Instruction(new DummyInstructionPattern(DummyOpCode.Ret)) ); var result = pattern.Match(cfg.Nodes[0].Contents.Instructions); Assert.True(result.IsSuccess); Assert.Single(result.Captures[variableCapture].Distinct()); }
public void DifferentSpecificVariableShouldMatch() { var variable1 = new DummyVariable("variable1"); var variable2 = new DummyVariable("variable2"); var pattern = ExpressionPattern.Variable <DummyInstruction>(variable1); Assert.False(pattern.Matches(new VariableExpression <DummyInstruction>(variable2))); }