| Name | Message | Date |
|---|---|---|
| 📄 CalleBuilder.cs | 7 days ago | |
| 📄 CallGraph.cs | 7 days ago | |
| 📄 Cfa.csproj | 7 days ago | |
| 📄 CompilationsExtensions.cs | 7 days ago | |
| 📄 packages.lock.json | 7 days ago | |
| 📄 Scanner.cs | 7 days ago |
📄
core/src/CalleBuilder.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
using System.Collections.Generic; using System.Collections.Immutable; using System.Linq; using System.Threading; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp.Syntax; namespace Cfa; internal sealed class CalleeBuilder(IReadOnlyCollection<Compilation> compilations) { private readonly IReadOnlyCollection<Compilation> compilations = compilations; private readonly HashSet<ISymbol> visitedSymbols = []; public IImmutableList<Callee> FindCallees(ISymbol symbol, CancellationToken cancellationToken) { if (!visitedSymbols.Add(symbol)) { return []; } var callees = ImmutableList.CreateBuilder<Callee>(); foreach (var reference in symbol.DeclaringSyntaxReferences) { var syntax = reference.GetSyntax(cancellationToken); var semanticModelForSyntax = compilations.GetSemanticModel(syntax.SyntaxTree); var invocations = syntax.DescendantNodesAndSelf().OfType<InvocationExpressionSyntax>(); foreach (var invocation in invocations) { var invokedSymbol = semanticModelForSyntax.GetSymbolInfo(invocation, cancellationToken).Symbol; if (invokedSymbol is { DeclaringSyntaxReferences.Length: > 0 }) { callees.Add( new Callee(invokedSymbol, LinkKind.Direct, FindCallees(invokedSymbol, cancellationToken)) ); } } } return callees.ToImmutable(); } }