| 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
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 = [with(SymbolEqualityComparer.Default)]; public IImmutableList<Callee> FindCallees(ISymbol symbol, CancellationToken cancellationToken) { if (!visitedSymbols.Add(symbol)) { return []; } var seen = new HashSet<ISymbol>(SymbolEqualityComparer.Default); var callees = ImmutableList.CreateBuilder<Callee>(); foreach (var reference in symbol.DeclaringSyntaxReferences) { var syntax = reference.GetSyntax(cancellationToken); var semanticModelForSyntax = compilations.GetSemanticModel(syntax.SyntaxTree); var accesses = syntax .DescendantNodesAndSelf() .Where(node => node is SimpleNameSyntax or ElementAccessExpressionSyntax or ElementBindingExpressionSyntax ); foreach (var access in accesses) { var accessedSymbol = semanticModelForSyntax.GetSymbolInfo(access, cancellationToken).Symbol; if ( accessedSymbol is not (IMethodSymbol or IPropertySymbol) || !seen.Add(accessedSymbol) || !IsDeclaredInSource(accessedSymbol) ) { continue; } if (accessedSymbol is IPropertySymbol property && !HasBody(property, cancellationToken)) { continue; } callees.Add( new Callee(accessedSymbol, LinkKind.Direct, FindCallees(accessedSymbol, cancellationToken)) ); } } return callees.ToImmutable(); } private static bool IsDeclaredInSource(ISymbol symbol) => symbol.DeclaringSyntaxReferences.Length > 0 && !symbol.IsImplicitlyDeclared; private static bool HasBody(IPropertySymbol property, CancellationToken cancellationToken) => property.DeclaringSyntaxReferences.Any(reference => reference.GetSyntax(cancellationToken) switch { PropertyDeclarationSyntax { ExpressionBody: not null } => true, IndexerDeclarationSyntax { ExpressionBody: not null } => true, BasePropertyDeclarationSyntax declaration => declaration.AccessorList?.Accessors.Any(accessor => accessor.Body is not null || accessor.ExpressionBody is not null ) is true, _ => false, } ); }