Files
git.stella-ops.org/src/BinaryIndex/__Libraries/StellaOps.BinaryIndex.Decompiler/DecompiledCodeParser.Analysis.cs
2026-02-04 19:59:20 +02:00

51 lines
1.1 KiB
C#

// Copyright (c) StellaOps. All rights reserved.
// Licensed under BUSL-1.1. See LICENSE in the project root.
using System.Collections.Immutable;
namespace StellaOps.BinaryIndex.Decompiler;
public sealed partial class DecompiledCodeParser
{
private static int CountNodes(AstNode node)
{
var count = 1;
foreach (var child in node.Children)
{
count += CountNodes(child);
}
return count;
}
private static int ComputeDepth(AstNode node)
{
if (node.Children.Length == 0)
{
return 1;
}
var maxDepth = 0;
foreach (var child in node.Children)
{
var depth = ComputeDepth(child);
if (depth > maxDepth)
{
maxDepth = depth;
}
}
return 1 + maxDepth;
}
private static ImmutableArray<AstPattern> ExtractPatterns(AstNode node)
{
var patterns = new List<AstPattern>();
foreach (var child in node.Children)
{
patterns.AddRange(ExtractPatterns(child));
}
return [.. patterns];
}
}