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 5, 2023
1 parent 23eb5de commit 0cf83ef
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions src/Draco.Compiler/Internal/FlowAnalysis/DecisionTree.cs
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,24 @@ private SpecializationComparer()
/// <param name="matchedValue">The matched value.</param>
/// <param name="arms">The arms of the match.</param>
/// <returns>The constructed decision tree.</returns>
public static DecisionTree<TAction> Build(BoundExpression matchedValue, ImmutableArray<Arm> arms) =>
throw new NotImplementedException();
public static DecisionTree<TAction> Build(BoundExpression matchedValue, ImmutableArray<Arm> arms)
{
// Construct root
var root = new MutableNode(
parent: null,
arguments: new List<BoundExpression> { matchedValue },
patternMatrix: arms
.Select(a => new List<BoundPattern> { a.Pattern })
.ToList(),
actions: arms
.Select(a => a.Action)
.ToList());
// Wrap in the tree
var tree = new DecisionTree<TAction>(root);
// Build it
tree.Build(root);
return tree;
}

/// <summary>
/// Stringifies the given <paramref name="pattern"/> to a user-readable format.
Expand Down

0 comments on commit 0cf83ef

Please sign in to comment.