From 0cf83eff62600496e07b571ebe6a875bea01688f Mon Sep 17 00:00:00 2001 From: LPeter1997 Date: Thu, 5 Oct 2023 10:09:06 +0200 Subject: [PATCH] Update DecisionTree.cs --- .../Internal/FlowAnalysis/DecisionTree.cs | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/Draco.Compiler/Internal/FlowAnalysis/DecisionTree.cs b/src/Draco.Compiler/Internal/FlowAnalysis/DecisionTree.cs index 6c23a59d4..924f50eb2 100644 --- a/src/Draco.Compiler/Internal/FlowAnalysis/DecisionTree.cs +++ b/src/Draco.Compiler/Internal/FlowAnalysis/DecisionTree.cs @@ -154,8 +154,24 @@ private SpecializationComparer() /// The matched value. /// The arms of the match. /// The constructed decision tree. - public static DecisionTree Build(BoundExpression matchedValue, ImmutableArray arms) => - throw new NotImplementedException(); + public static DecisionTree Build(BoundExpression matchedValue, ImmutableArray arms) + { + // Construct root + var root = new MutableNode( + parent: null, + arguments: new List { matchedValue }, + patternMatrix: arms + .Select(a => new List { a.Pattern }) + .ToList(), + actions: arms + .Select(a => a.Action) + .ToList()); + // Wrap in the tree + var tree = new DecisionTree(root); + // Build it + tree.Build(root); + return tree; + } /// /// Stringifies the given to a user-readable format.