Browse Source

Support MatchInstruction in DataFlowVisitor

pull/2119/head
Siegfried Pammer 5 years ago
parent
commit
eac0e2257e
  1. 41
      ICSharpCode.Decompiler/FlowAnalysis/DataFlowVisitor.cs
  2. 7
      ICSharpCode.Decompiler/FlowAnalysis/DefiniteAssignmentVisitor.cs
  3. 7
      ICSharpCode.Decompiler/FlowAnalysis/ReachingDefinitionsVisitor.cs

41
ICSharpCode.Decompiler/FlowAnalysis/DataFlowVisitor.cs

@ -646,6 +646,8 @@ namespace ICSharpCode.Decompiler.FlowAnalysis @@ -646,6 +646,8 @@ namespace ICSharpCode.Decompiler.FlowAnalysis
} else {
return (state, bottomState.Clone());
}
} else if (inst is MatchInstruction match) {
return EvaluateMatch(match);
} else {
// other kind of condition
inst.AcceptVisitor(this);
@ -653,6 +655,45 @@ namespace ICSharpCode.Decompiler.FlowAnalysis @@ -653,6 +655,45 @@ namespace ICSharpCode.Decompiler.FlowAnalysis
}
}
protected internal override void VisitMatchInstruction(MatchInstruction inst)
{
var (onTrue, onFalse) = EvaluateMatch(inst);
state = onTrue;
state.JoinWith(onFalse);
}
/// <summary>
/// Evaluates a match instruction.
/// </summary>
/// <returns>
/// A pair of:
/// * The state after the pattern matches
/// * The state after the pattern fails to match
/// </returns>
/// <remarks>
/// <c>this.state</c> is invalid after this function was called, and must be overwritten
/// with one of the return values.
/// </remarks>
(State OnTrue, State OnFalse) EvaluateMatch(MatchInstruction inst)
{
DebugStartPoint(inst);
inst.TestedOperand.AcceptVisitor(this);
State onFalse = state.Clone();
if (!inst.CheckNotNull && !inst.CheckType) {
onFalse.ReplaceWithBottom();
}
HandleMatchStore(inst);
foreach (var subPattern in inst.SubPatterns) {
var (subTrue, subFalse) = EvaluateCondition(subPattern);
onFalse.JoinWith(subFalse);
state = subTrue;
}
DebugEndPoint(inst);
return (state, onFalse);
}
protected abstract void HandleMatchStore(MatchInstruction inst);
protected internal override void VisitNullCoalescingInstruction(NullCoalescingInstruction inst)
{
HandleBinaryWithOptionalEvaluation(inst, inst.ValueInst, inst.FallbackInst);

7
ICSharpCode.Decompiler/FlowAnalysis/DefiniteAssignmentVisitor.cs

@ -168,7 +168,12 @@ namespace ICSharpCode.Decompiler.FlowAnalysis @@ -168,7 +168,12 @@ namespace ICSharpCode.Decompiler.FlowAnalysis
inst.Value.AcceptVisitor(this);
HandleStore(inst.Variable);
}
protected override void HandleMatchStore(MatchInstruction inst)
{
HandleStore(inst.Variable);
}
protected override void BeginTryCatchHandler(TryCatchHandler inst)
{
HandleStore(inst.Variable);

7
ICSharpCode.Decompiler/FlowAnalysis/ReachingDefinitionsVisitor.cs

@ -380,7 +380,12 @@ namespace ICSharpCode.Decompiler.FlowAnalysis @@ -380,7 +380,12 @@ namespace ICSharpCode.Decompiler.FlowAnalysis
inst.Value.AcceptVisitor(this);
HandleStore(inst, inst.Variable);
}
protected override void HandleMatchStore(MatchInstruction inst)
{
HandleStore(inst, inst.Variable);
}
protected override void BeginTryCatchHandler(TryCatchHandler inst)
{
base.BeginTryCatchHandler(inst);

Loading…
Cancel
Save