Skip to content

Commit

Permalink
Update DecisionTree.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
LPeter1997 committed Oct 4, 2023
1 parent 6eb2810 commit 3ab626c
Showing 1 changed file with 30 additions and 14 deletions.
44 changes: 30 additions & 14 deletions src/Draco.Compiler/Internal/FlowAnalysis/DecisionTree.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,45 +40,61 @@ public abstract class Node
/// <summary>
/// The parent node of this one.
/// </summary>
public virtual Node? Parent => null;

/// <summary>
/// The index of the row this node originated from in the parent.
/// </summary>
public virtual int? ParentRowIndex => null;
public abstract Node? Parent { get; }

/// <summary>
/// True, if this is an action node, meaning that there is a match.
/// </summary>
public virtual bool IsAction => false;
public abstract bool IsAction { get; }

/// <summary>
/// The action that's associated with the node.
/// The arm that's associated with the node.
/// </summary>
[MemberNotNullWhen(true, nameof(IsAction))]
public virtual TAction? Action => default;
public abstract Arm? Arm { get; }

/// <summary>
/// True, if this is a failure node.
/// </summary>
public virtual bool IsFail => false;
public abstract bool IsFail { get; }

/// <summary>
/// The counterexample of this node, if it's a failure node and a counterexample could be produced.
/// The counterexample in this case means a pattern that was not covered.
/// </summary>
public virtual BoundPattern? Counterexample => null;
public abstract BoundPattern? Counterexample { get; }

/// <summary>
/// The expression being matched on, if any.
/// </summary>
public virtual BoundExpression? MatchedOn => null;
public abstract BoundExpression? MatchedOn { get; }

/// <summary>
/// The child nodes of this one, associated to the pattern to match to take the route to the child.
/// </summary>
public virtual ImmutableArray<KeyValuePair<BoundPattern, Node>> Children =>
ImmutableArray<KeyValuePair<BoundPattern, Node>>.Empty;
public abstract ImmutableArray<KeyValuePair<BoundPattern, Node>> Children { get; }
}

private sealed class MutableNode : Node
{
// Observers
public override Node? Parent { get; }
public override bool IsAction => this.Arm is not null;
public override Arm? Arm => this.MatchingArm;
public override bool IsFail => this.PatternMatrix.Count == 0;
public override BoundPattern? Counterexample => throw new NotImplementedException();
public override BoundExpression? MatchedOn => throw new NotImplementedException();
public override ImmutableArray<KeyValuePair<BoundPattern, Node>> Children =>
this.builtChildren ??= this.MutableChildren.ToImmutableArray();
private ImmutableArray<KeyValuePair<BoundPattern, Node>>? builtChildren;

// Mutators
public List<BoundExpression> Arguments { get; }

Check warning on line 92 in src/Draco.Compiler/Internal/FlowAnalysis/DecisionTree.cs

View workflow job for this annotation

GitHub Actions / tests-ubuntu-latest

Non-nullable property 'Arguments' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check warning on line 92 in src/Draco.Compiler/Internal/FlowAnalysis/DecisionTree.cs

View workflow job for this annotation

GitHub Actions / tests-ubuntu-latest

Non-nullable property 'Arguments' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check warning on line 92 in src/Draco.Compiler/Internal/FlowAnalysis/DecisionTree.cs

View workflow job for this annotation

GitHub Actions / tests-windows-latest

Non-nullable property 'Arguments' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check warning on line 92 in src/Draco.Compiler/Internal/FlowAnalysis/DecisionTree.cs

View workflow job for this annotation

GitHub Actions / tests-windows-latest

Non-nullable property 'Arguments' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check warning on line 92 in src/Draco.Compiler/Internal/FlowAnalysis/DecisionTree.cs

View workflow job for this annotation

GitHub Actions / tests-macOS-latest

Non-nullable property 'Arguments' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check warning on line 92 in src/Draco.Compiler/Internal/FlowAnalysis/DecisionTree.cs

View workflow job for this annotation

GitHub Actions / tests-macOS-latest

Non-nullable property 'Arguments' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.
public List<int> ArgumentOrder { get; }

Check warning on line 93 in src/Draco.Compiler/Internal/FlowAnalysis/DecisionTree.cs

View workflow job for this annotation

GitHub Actions / tests-ubuntu-latest

Non-nullable property 'ArgumentOrder' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check warning on line 93 in src/Draco.Compiler/Internal/FlowAnalysis/DecisionTree.cs

View workflow job for this annotation

GitHub Actions / tests-windows-latest

Non-nullable property 'ArgumentOrder' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check warning on line 93 in src/Draco.Compiler/Internal/FlowAnalysis/DecisionTree.cs

View workflow job for this annotation

GitHub Actions / tests-macOS-latest

Non-nullable property 'ArgumentOrder' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.
public List<List<BoundPattern>> PatternMatrix { get; }

Check warning on line 94 in src/Draco.Compiler/Internal/FlowAnalysis/DecisionTree.cs

View workflow job for this annotation

GitHub Actions / tests-ubuntu-latest

Non-nullable property 'PatternMatrix' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check warning on line 94 in src/Draco.Compiler/Internal/FlowAnalysis/DecisionTree.cs

View workflow job for this annotation

GitHub Actions / tests-windows-latest

Non-nullable property 'PatternMatrix' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check warning on line 94 in src/Draco.Compiler/Internal/FlowAnalysis/DecisionTree.cs

View workflow job for this annotation

GitHub Actions / tests-macOS-latest

Non-nullable property 'PatternMatrix' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.
public List<Arm> Arms { get; }

Check warning on line 95 in src/Draco.Compiler/Internal/FlowAnalysis/DecisionTree.cs

View workflow job for this annotation

GitHub Actions / tests-ubuntu-latest

Non-nullable property 'Arms' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check warning on line 95 in src/Draco.Compiler/Internal/FlowAnalysis/DecisionTree.cs

View workflow job for this annotation

GitHub Actions / tests-windows-latest

Non-nullable property 'Arms' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check warning on line 95 in src/Draco.Compiler/Internal/FlowAnalysis/DecisionTree.cs

View workflow job for this annotation

GitHub Actions / tests-macOS-latest

Non-nullable property 'Arms' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.
public Arm? MatchingArm { get; set; }
public List<KeyValuePair<BoundPattern, Node>> MutableChildren { get; }

Check warning on line 97 in src/Draco.Compiler/Internal/FlowAnalysis/DecisionTree.cs

View workflow job for this annotation

GitHub Actions / tests-ubuntu-latest

Non-nullable property 'MutableChildren' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check warning on line 97 in src/Draco.Compiler/Internal/FlowAnalysis/DecisionTree.cs

View workflow job for this annotation

GitHub Actions / tests-windows-latest

Non-nullable property 'MutableChildren' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check warning on line 97 in src/Draco.Compiler/Internal/FlowAnalysis/DecisionTree.cs

View workflow job for this annotation

GitHub Actions / tests-macOS-latest

Non-nullable property 'MutableChildren' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.
}

/// <summary>
Expand Down

0 comments on commit 3ab626c

Please sign in to comment.