Skip to content

Commit

Permalink
Add the kind component to all nodes.
Browse files Browse the repository at this point in the history
  • Loading branch information
GGG-KILLER committed Jan 28, 2024
1 parent d3d8fb7 commit 4811401
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions Tsu.Trees.RedGreen/sourcegen/TreeCreator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,16 @@ private static List<NodeInfo> ListAllNodes(TreeInfo root, IEnumerable<NodeInfo>
return nodes;
}

private static Node ProcessNode(NodeInfo node, ILookup<ISymbol?, NodeInfo> nodes, INamedTypeSymbol greenRoot, IEnumerable<Component> parentNodes, IEnumerable<Component> parentExtraData)
private static Node ProcessNode(
TreeInfo tree,
NodeInfo node,
ILookup<ISymbol?, NodeInfo> nodes,
IEnumerable<Component> parentNodes,
IEnumerable<Component> parentExtraData)
{
var fields = node.NodeType.GetMembers().OfType<IFieldSymbol>().Where(f => f.IsReadOnly);
var nodeChildren = fields.Where(x => x.Type.DerivesFrom(greenRoot)).Select(toComponent);
var nodeExtraData = fields.Where(x => !x.Type.DerivesFrom(greenRoot)).Select(toComponent);
var nodeChildren = fields.Where(x => x.Type.DerivesFrom(tree.GreenBase)).Select(toComponent);
var nodeExtraData = fields.Where(x => !x.Type.DerivesFrom(tree.GreenBase)).Select(toComponent);

var children = parentNodes.Select(x => x with { PassToBase = true })
.Concat(nodeChildren)
Expand All @@ -101,9 +106,12 @@ private static Node ProcessNode(NodeInfo node, ILookup<ISymbol?, NodeInfo> nodes
.Concat(nodeExtraData)
.ToImmutableArray();

if (SymbolEqualityComparer.Default.Equals(node.NodeType, tree.GreenBase))
extraData = extraData.Add(new Component(tree.KindEnum, "kind", false, false));

return new Node(
node.NodeType,
nodes[node.NodeType].Select(x => ProcessNode(x, nodes, greenRoot, children, extraData))
nodes[node.NodeType].Select(x => ProcessNode(tree, x, nodes, children, extraData))
.ToImmutableArray(),
children,
extraData);
Expand All @@ -121,7 +129,7 @@ public static IncrementalValuesProvider<Tree> BuildTree(IncrementalValuesProvide
var nodes = ListAllNodes(root, initialNodes.Where(x => x.NodeType.DerivesFrom(root.GreenBase)));
var subTrees = nodes.ToLookup(node => node.BaseType, SymbolEqualityComparer.Default);
var rootNodeInfo = subTrees[null].Single();
var rootNode = ProcessNode(rootNodeInfo, subTrees, root.GreenBase, [], []);
var rootNode = ProcessNode(root, rootNodeInfo, subTrees, [], []);

return new Tree(
root.GreenBase,
Expand Down

0 comments on commit 4811401

Please sign in to comment.