causoryn 0.0.0-stage → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/plugin.json +36 -0
- package/.codex-plugin/mcp.json +19 -0
- package/.codex-plugin/plugin.json +38 -0
- package/.zcode-plugin/plugin.json +42 -0
- package/LICENSE +21 -0
- package/README.md +171 -2
- package/THIRD-PARTY-NOTICES.md +443 -0
- package/dist/bundle-manifest.json +39 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.js +253 -0
- package/dist/doctor.d.ts +13 -0
- package/dist/doctor.js +507 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +10 -0
- package/dist/mcp-server.mjs +288477 -0
- package/dist/mcp-server.mjs.LEGAL.txt +17 -0
- package/dist/node_modules/better-sqlite3/LICENSE +21 -0
- package/dist/node_modules/better-sqlite3/lib/binding.js +62 -0
- package/dist/node_modules/better-sqlite3/lib/darwin-arm64.js +3 -0
- package/dist/node_modules/better-sqlite3/lib/darwin-x64.js +3 -0
- package/dist/node_modules/better-sqlite3/lib/database.js +109 -0
- package/dist/node_modules/better-sqlite3/lib/index.js +3 -0
- package/dist/node_modules/better-sqlite3/lib/linux-arm64.js +3 -0
- package/dist/node_modules/better-sqlite3/lib/linux-x64.js +3 -0
- package/dist/node_modules/better-sqlite3/lib/linuxmusl-arm64.js +4 -0
- package/dist/node_modules/better-sqlite3/lib/linuxmusl-x64.js +4 -0
- package/dist/node_modules/better-sqlite3/lib/methods/aggregate.js +43 -0
- package/dist/node_modules/better-sqlite3/lib/methods/backup.js +67 -0
- package/dist/node_modules/better-sqlite3/lib/methods/explain.js +9 -0
- package/dist/node_modules/better-sqlite3/lib/methods/function.js +31 -0
- package/dist/node_modules/better-sqlite3/lib/methods/inspect.js +7 -0
- package/dist/node_modules/better-sqlite3/lib/methods/pragma.js +12 -0
- package/dist/node_modules/better-sqlite3/lib/methods/serialize.js +16 -0
- package/dist/node_modules/better-sqlite3/lib/methods/table.js +195 -0
- package/dist/node_modules/better-sqlite3/lib/methods/transaction.js +78 -0
- package/dist/node_modules/better-sqlite3/lib/methods/wrappers.js +54 -0
- package/dist/node_modules/better-sqlite3/lib/sqlite-error.js +25 -0
- package/dist/node_modules/better-sqlite3/lib/util.js +12 -0
- package/dist/node_modules/better-sqlite3/lib/win32-arm64.js +3 -0
- package/dist/node_modules/better-sqlite3/lib/win32-x64.js +3 -0
- package/dist/node_modules/better-sqlite3/package.json +67 -0
- package/dist/node_modules/better-sqlite3/prebuilds/darwin-arm64.node +0 -0
- package/dist/node_modules/better-sqlite3/prebuilds/darwin-x64.node +0 -0
- package/dist/node_modules/better-sqlite3/prebuilds/linux-arm64.node +0 -0
- package/dist/node_modules/better-sqlite3/prebuilds/linux-x64.node +0 -0
- package/dist/node_modules/better-sqlite3/prebuilds/linuxmusl-arm64.node +0 -0
- package/dist/node_modules/better-sqlite3/prebuilds/linuxmusl-x64.node +0 -0
- package/dist/node_modules/better-sqlite3/prebuilds/win32-arm64.node +0 -0
- package/dist/node_modules/better-sqlite3/prebuilds/win32-x64.node +0 -0
- package/dist/runtime-stage.d.ts +8 -0
- package/dist/runtime-stage.js +159 -0
- package/dist/setup.d.ts +15 -0
- package/dist/setup.js +735 -0
- package/dist/toml-patch.d.ts +10 -0
- package/dist/toml-patch.js +587 -0
- package/dist/types.d.ts +144 -0
- package/dist/types.js +35 -0
- package/dist/typescript-lib/lib.d.ts +22 -0
- package/dist/typescript-lib/lib.decorators.d.ts +384 -0
- package/dist/typescript-lib/lib.decorators.legacy.d.ts +22 -0
- package/dist/typescript-lib/lib.dom.asynciterable.d.ts +41 -0
- package/dist/typescript-lib/lib.dom.d.ts +39429 -0
- package/dist/typescript-lib/lib.dom.iterable.d.ts +571 -0
- package/dist/typescript-lib/lib.es2015.collection.d.ts +147 -0
- package/dist/typescript-lib/lib.es2015.core.d.ts +597 -0
- package/dist/typescript-lib/lib.es2015.d.ts +28 -0
- package/dist/typescript-lib/lib.es2015.generator.d.ts +77 -0
- package/dist/typescript-lib/lib.es2015.iterable.d.ts +605 -0
- package/dist/typescript-lib/lib.es2015.promise.d.ts +81 -0
- package/dist/typescript-lib/lib.es2015.proxy.d.ts +128 -0
- package/dist/typescript-lib/lib.es2015.reflect.d.ts +144 -0
- package/dist/typescript-lib/lib.es2015.symbol.d.ts +46 -0
- package/dist/typescript-lib/lib.es2015.symbol.wellknown.d.ts +326 -0
- package/dist/typescript-lib/lib.es2016.array.include.d.ts +116 -0
- package/dist/typescript-lib/lib.es2016.d.ts +21 -0
- package/dist/typescript-lib/lib.es2016.full.d.ts +23 -0
- package/dist/typescript-lib/lib.es2016.intl.d.ts +31 -0
- package/dist/typescript-lib/lib.es2017.arraybuffer.d.ts +21 -0
- package/dist/typescript-lib/lib.es2017.d.ts +26 -0
- package/dist/typescript-lib/lib.es2017.date.d.ts +31 -0
- package/dist/typescript-lib/lib.es2017.full.d.ts +23 -0
- package/dist/typescript-lib/lib.es2017.intl.d.ts +44 -0
- package/dist/typescript-lib/lib.es2017.object.d.ts +49 -0
- package/dist/typescript-lib/lib.es2017.sharedmemory.d.ts +135 -0
- package/dist/typescript-lib/lib.es2017.string.d.ts +45 -0
- package/dist/typescript-lib/lib.es2017.typedarrays.d.ts +53 -0
- package/dist/typescript-lib/lib.es2018.asyncgenerator.d.ts +77 -0
- package/dist/typescript-lib/lib.es2018.asynciterable.d.ts +53 -0
- package/dist/typescript-lib/lib.es2018.d.ts +24 -0
- package/dist/typescript-lib/lib.es2018.full.d.ts +24 -0
- package/dist/typescript-lib/lib.es2018.intl.d.ts +83 -0
- package/dist/typescript-lib/lib.es2018.promise.d.ts +30 -0
- package/dist/typescript-lib/lib.es2018.regexp.d.ts +37 -0
- package/dist/typescript-lib/lib.es2019.array.d.ts +79 -0
- package/dist/typescript-lib/lib.es2019.d.ts +24 -0
- package/dist/typescript-lib/lib.es2019.full.d.ts +24 -0
- package/dist/typescript-lib/lib.es2019.intl.d.ts +23 -0
- package/dist/typescript-lib/lib.es2019.object.d.ts +33 -0
- package/dist/typescript-lib/lib.es2019.string.d.ts +37 -0
- package/dist/typescript-lib/lib.es2019.symbol.d.ts +24 -0
- package/dist/typescript-lib/lib.es2020.bigint.d.ts +765 -0
- package/dist/typescript-lib/lib.es2020.d.ts +27 -0
- package/dist/typescript-lib/lib.es2020.date.d.ts +42 -0
- package/dist/typescript-lib/lib.es2020.full.d.ts +24 -0
- package/dist/typescript-lib/lib.es2020.intl.d.ts +474 -0
- package/dist/typescript-lib/lib.es2020.number.d.ts +28 -0
- package/dist/typescript-lib/lib.es2020.promise.d.ts +47 -0
- package/dist/typescript-lib/lib.es2020.sharedmemory.d.ts +99 -0
- package/dist/typescript-lib/lib.es2020.string.d.ts +44 -0
- package/dist/typescript-lib/lib.es2020.symbol.wellknown.d.ts +41 -0
- package/dist/typescript-lib/lib.es2021.d.ts +23 -0
- package/dist/typescript-lib/lib.es2021.full.d.ts +24 -0
- package/dist/typescript-lib/lib.es2021.intl.d.ts +166 -0
- package/dist/typescript-lib/lib.es2021.promise.d.ts +48 -0
- package/dist/typescript-lib/lib.es2021.string.d.ts +33 -0
- package/dist/typescript-lib/lib.es2021.weakref.d.ts +78 -0
- package/dist/typescript-lib/lib.es2022.array.d.ts +121 -0
- package/dist/typescript-lib/lib.es2022.d.ts +25 -0
- package/dist/typescript-lib/lib.es2022.error.d.ts +75 -0
- package/dist/typescript-lib/lib.es2022.full.d.ts +24 -0
- package/dist/typescript-lib/lib.es2022.intl.d.ts +145 -0
- package/dist/typescript-lib/lib.es2022.object.d.ts +26 -0
- package/dist/typescript-lib/lib.es2022.regexp.d.ts +39 -0
- package/dist/typescript-lib/lib.es2022.string.d.ts +25 -0
- package/dist/typescript-lib/lib.es2023.array.d.ts +924 -0
- package/dist/typescript-lib/lib.es2023.collection.d.ts +21 -0
- package/dist/typescript-lib/lib.es2023.d.ts +22 -0
- package/dist/typescript-lib/lib.es2023.full.d.ts +24 -0
- package/dist/typescript-lib/lib.es2023.intl.d.ts +56 -0
- package/dist/typescript-lib/lib.es2024.arraybuffer.d.ts +65 -0
- package/dist/typescript-lib/lib.es2024.collection.d.ts +29 -0
- package/dist/typescript-lib/lib.es2024.d.ts +26 -0
- package/dist/typescript-lib/lib.es2024.full.d.ts +24 -0
- package/dist/typescript-lib/lib.es2024.object.d.ts +29 -0
- package/dist/typescript-lib/lib.es2024.promise.d.ts +35 -0
- package/dist/typescript-lib/lib.es2024.regexp.d.ts +25 -0
- package/dist/typescript-lib/lib.es2024.sharedmemory.d.ts +68 -0
- package/dist/typescript-lib/lib.es2024.string.d.ts +29 -0
- package/dist/typescript-lib/lib.es5.d.ts +4601 -0
- package/dist/typescript-lib/lib.es6.d.ts +23 -0
- package/dist/typescript-lib/lib.esnext.array.d.ts +35 -0
- package/dist/typescript-lib/lib.esnext.collection.d.ts +96 -0
- package/dist/typescript-lib/lib.esnext.d.ts +29 -0
- package/dist/typescript-lib/lib.esnext.decorators.d.ts +28 -0
- package/dist/typescript-lib/lib.esnext.disposable.d.ts +193 -0
- package/dist/typescript-lib/lib.esnext.error.d.ts +24 -0
- package/dist/typescript-lib/lib.esnext.float16.d.ts +445 -0
- package/dist/typescript-lib/lib.esnext.full.d.ts +24 -0
- package/dist/typescript-lib/lib.esnext.intl.d.ts +21 -0
- package/dist/typescript-lib/lib.esnext.iterator.d.ts +148 -0
- package/dist/typescript-lib/lib.esnext.promise.d.ts +34 -0
- package/dist/typescript-lib/lib.esnext.sharedmemory.d.ts +25 -0
- package/dist/typescript-lib/lib.scripthost.d.ts +322 -0
- package/dist/typescript-lib/lib.webworker.asynciterable.d.ts +41 -0
- package/dist/typescript-lib/lib.webworker.d.ts +13150 -0
- package/dist/typescript-lib/lib.webworker.importscripts.d.ts +23 -0
- package/dist/typescript-lib/lib.webworker.iterable.d.ts +340 -0
- package/licenses/Apache-2.0.txt +55 -0
- package/licenses/TypeScript-ThirdPartyNoticeText.txt +193 -0
- package/licenses/better-sqlite3-LICENSE.txt +21 -0
- package/mcp_config.json +16 -0
- package/native/go-worker/PROTOCOL.md +316 -0
- package/native/go-worker/cmd/worker/main.go +440 -0
- package/native/go-worker/go.mod +3 -0
- package/native/go-worker/internal/analyze/analyze.go +820 -0
- package/native/go-worker/internal/analyze/model.go +182 -0
- package/native/go-worker/internal/analyze/routes.go +181 -0
- package/native/python-worker/PROTOCOL.md +342 -0
- package/native/python-worker/worker.py +1190 -0
- package/native/roslyn-worker/Causoryn.RoslynWorker.csproj +40 -0
- package/native/roslyn-worker/Causoryn.RoslynWorker.deps.json +59 -0
- package/native/roslyn-worker/Causoryn.RoslynWorker.dll +0 -0
- package/native/roslyn-worker/Causoryn.RoslynWorker.runtimeconfig.json +13 -0
- package/native/roslyn-worker/Microsoft.CodeAnalysis.CSharp.dll +0 -0
- package/native/roslyn-worker/Microsoft.CodeAnalysis.dll +0 -0
- package/native/roslyn-worker/PROTOCOL.md +285 -0
- package/native/roslyn-worker/Program.cs +249 -0
- package/native/roslyn-worker/Protocol.cs +397 -0
- package/native/roslyn-worker/ReferenceResolver.cs +235 -0
- package/native/roslyn-worker/WorkerAnalyzer.cs +1669 -0
- package/native/roslyn-worker/packages.lock.json +30 -0
- package/native/rust-worker/Cargo.lock +107 -0
- package/native/rust-worker/Cargo.toml +23 -0
- package/native/rust-worker/PROTOCOL.md +294 -0
- package/native/rust-worker/src/analyzer.rs +1209 -0
- package/native/rust-worker/src/main.rs +127 -0
- package/native/rust-worker/src/protocol.rs +284 -0
- package/native/rust-worker/src/sha256.rs +136 -0
- package/package.json +71 -4
- package/plugin.json +17 -0
- package/scripts/causoryn.mjs +40 -0
- package/scripts/lib/node-version-guard.mjs +24 -0
- package/scripts/plugin-mcp-launcher.mjs +111 -0
- package/skills/causoryn/SKILL.md +53 -0
- package/skills/map-system/SKILL.md +69 -0
- package/skills/preflight-change/SKILL.md +38 -0
- package/skills/verify-change/SKILL.md +31 -0
|
@@ -0,0 +1,1669 @@
|
|
|
1
|
+
using System.Security.Cryptography;
|
|
2
|
+
using System.Text;
|
|
3
|
+
using System.Text.Json;
|
|
4
|
+
using System.Text.RegularExpressions;
|
|
5
|
+
using Microsoft.CodeAnalysis;
|
|
6
|
+
using Microsoft.CodeAnalysis.CSharp;
|
|
7
|
+
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
|
8
|
+
|
|
9
|
+
namespace Causoryn.RoslynWorker;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Roslyn çekirdek çözümleyici — TŞ v2.1 §7 "C#/.NET ASP.NET Core → Roslyn
|
|
13
|
+
* sidecar, L2 hedef, controller/minimal API L3" dilimi (sprint-2 / B1).
|
|
14
|
+
*
|
|
15
|
+
* Çıkarım disiplini (adapters/typescript/src/analyzer.ts ile aynı sözleşme):
|
|
16
|
+
* - CONTAINS : File → üst düzey tip bildirimi; Tip → üye Method (istek
|
|
17
|
+
* gereği property bildirimleri de Method düğümüyle eşlenir —
|
|
18
|
+
* property, CIL düzeyinde erişimci metotlarına çözülür; bu
|
|
19
|
+
* yaklaşım PROTOCOL.md'de belgelenmiştir).
|
|
20
|
+
* - CALLS : çağrı/nesne-oluşturma ifadeleri Roslyn semantic model ile
|
|
21
|
+
* hedef sembole çözümlenir (verified); çözümleme analizin
|
|
22
|
+
* DIŞINA taşarsa açık UnknownExternal node (checker dayanaklı
|
|
23
|
+
* verified); hiç çözümlenemezse UnknownExternal + unresolved —
|
|
24
|
+
* uydurma kenar YOK (TŞ §8 resolution kuralı).
|
|
25
|
+
* - ROUTES_TO : ASP.NET Core controller öznitelikleri ([Route]/[HttpGet]...)
|
|
26
|
+
* ve minimal API MapGet/MapPost... çağrı kalıbı → Endpoint
|
|
27
|
+
* node + Endpoint → handler kenarı (route-attribute kanıtı).
|
|
28
|
+
* Öznitelik/uzantı tipi semantic model ile Microsoft.* köküne
|
|
29
|
+
* çözülürse verified; yalnızca bilinen ad kuralı varsa
|
|
30
|
+
* heuristic + açık ambiguity (TŞ §8: "bilinen kural ama kesin
|
|
31
|
+
* çözümleme yok").
|
|
32
|
+
*
|
|
33
|
+
* Invariant'lar (TŞ §8): (i) verified kenar ≥1 kanıt; (ii) dangling edge
|
|
34
|
+
* yok — dış kaynaklar açık UnknownExternal node; (iv/vi) deterministik
|
|
35
|
+
* çıktı — girdi sıralanır, çıktı kanonik anahtarla sıralanır, saat okunmaz.
|
|
36
|
+
*
|
|
37
|
+
* Hata izolasyonu: tek dosyadaki sorun analizi düşürmez; tanılar dosya
|
|
38
|
+
* başına toplanır, status "partial" bildirilir.
|
|
39
|
+
*/
|
|
40
|
+
public static class WorkerAnalyzer
|
|
41
|
+
{
|
|
42
|
+
/** Minimal API endpoint kayıt metot adları (bilinen kural kapısı). */
|
|
43
|
+
private static readonly HashSet<string> MinimalApiMapNames = new(StringComparer.Ordinal)
|
|
44
|
+
{
|
|
45
|
+
"MapGet", "MapPost", "MapPut", "MapDelete", "MapPatch",
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
/** HTTP fiil öznitelik adı → fiil (bilinen kural tablosu). */
|
|
49
|
+
private static readonly Dictionary<string, string> VerbAttributeNames =
|
|
50
|
+
new(StringComparer.OrdinalIgnoreCase)
|
|
51
|
+
{
|
|
52
|
+
["HttpGet"] = "GET",
|
|
53
|
+
["HttpPost"] = "POST",
|
|
54
|
+
["HttpPut"] = "PUT",
|
|
55
|
+
["HttpPatch"] = "PATCH",
|
|
56
|
+
["HttpDelete"] = "DELETE",
|
|
57
|
+
["HttpHead"] = "HEAD",
|
|
58
|
+
["HttpOptions"] = "OPTIONS",
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
private const string AspNetMvcNamespace = "Microsoft.AspNetCore.Mvc";
|
|
62
|
+
private const string EndpointRouteBuilderExtensions = "Microsoft.AspNetCore.Builder.EndpointRouteBuilderExtensions";
|
|
63
|
+
|
|
64
|
+
/** Bu dilimde modellenmeyen dil yapıları (TŞ §7 C# satırı: reflection, dynamic DI, source generators). */
|
|
65
|
+
private static readonly string[] UnsupportedConstructs =
|
|
66
|
+
{
|
|
67
|
+
"reflection/dynamic-dispatch",
|
|
68
|
+
"dynamic-di-configuration",
|
|
69
|
+
"source-generators",
|
|
70
|
+
"function-local-declarations",
|
|
71
|
+
"inline-anonymous-route-handlers",
|
|
72
|
+
"constructor-initializer-chains",
|
|
73
|
+
"field-initializer-calls",
|
|
74
|
+
"convention-routing-templates",
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
/* ------------------------------------------------------------------ */
|
|
78
|
+
/* Kayıt yapıları */
|
|
79
|
+
/* ------------------------------------------------------------------ */
|
|
80
|
+
|
|
81
|
+
private sealed record SourceEntry(string RelativePath, string SourceHash, SyntaxTree Tree);
|
|
82
|
+
|
|
83
|
+
private sealed record NodeRecord(NodeRefOut Ref, NodeOut Node, string Key);
|
|
84
|
+
|
|
85
|
+
private sealed record AttributeMatch(AttributeSyntax Node, string SimpleName, bool Semantic, string? Template, string? Verb);
|
|
86
|
+
|
|
87
|
+
private sealed record ControllerInfo(TypeDeclarationSyntax Declaration, NodeRecord Record, string QualifiedName);
|
|
88
|
+
|
|
89
|
+
private sealed class GraphAssembler
|
|
90
|
+
{
|
|
91
|
+
private readonly Dictionary<string, NodeRecord> _nodes = new(StringComparer.Ordinal);
|
|
92
|
+
private readonly Dictionary<string, EdgeRecord> _edges = new(StringComparer.Ordinal);
|
|
93
|
+
private readonly HashSet<string> _warningSeen = new(StringComparer.Ordinal);
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Güvenlik bulgusu 4: yanıt node bütçesi. _nodes.Count limitte
|
|
97
|
+
* kaldığında yeni node'lar ADMIT EDİLMEZ; admit edilmemiş uçlu
|
|
98
|
+
* kenarlar da eklenmez (dangling edge yok — worker çıktısı
|
|
99
|
+
* createSnapshot dangling refine'ından geçmek zorundadır).
|
|
100
|
+
* Truncated=true → yanıt RESPONSE_TRUNCATED tanısı alır ve
|
|
101
|
+
* status "partial" olur (sessiz kesim yoktur).
|
|
102
|
+
*/
|
|
103
|
+
private readonly int _nodeLimit;
|
|
104
|
+
|
|
105
|
+
public bool Truncated { get; private set; }
|
|
106
|
+
|
|
107
|
+
public GraphAssembler(int nodeLimit)
|
|
108
|
+
{
|
|
109
|
+
_nodeLimit = nodeLimit;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
public List<string> Warnings { get; } = new();
|
|
113
|
+
|
|
114
|
+
public NodeRecord EnsureNode(string kind, string qualifiedName, string? relativePath, Dictionary<string, object>? attributes)
|
|
115
|
+
{
|
|
116
|
+
if (!GraphKinds.NodeKinds.Contains(kind))
|
|
117
|
+
{
|
|
118
|
+
throw new ProtocolException(
|
|
119
|
+
ProtocolErrorCodes.InternalError,
|
|
120
|
+
$"TŞ §8 node kataloğu dışı tür üretilemez: {kind}");
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
var key = NodeKey(kind, qualifiedName, relativePath);
|
|
124
|
+
if (_nodes.TryGetValue(key, out var existing))
|
|
125
|
+
{
|
|
126
|
+
return existing;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
var record = new NodeRecord(
|
|
130
|
+
new NodeRefOut { Kind = kind, QualifiedName = qualifiedName, RelativePath = relativePath },
|
|
131
|
+
new NodeOut
|
|
132
|
+
{
|
|
133
|
+
Kind = kind,
|
|
134
|
+
QualifiedName = qualifiedName,
|
|
135
|
+
Language = ProtocolConstants.Language,
|
|
136
|
+
RelativePath = relativePath,
|
|
137
|
+
Attributes = attributes ?? new Dictionary<string, object>(),
|
|
138
|
+
},
|
|
139
|
+
key);
|
|
140
|
+
if (_nodes.Count >= _nodeLimit)
|
|
141
|
+
{
|
|
142
|
+
// Limit dolu: kayıt EMİSİYONA GİRMEZ; referansı döner ki
|
|
143
|
+
// çağıran akış bozulmasın, ama AddEdge bu kaydı admit
|
|
144
|
+
// saymaz (dangling üretmez).
|
|
145
|
+
Truncated = true;
|
|
146
|
+
return record;
|
|
147
|
+
}
|
|
148
|
+
_nodes.Add(key, record);
|
|
149
|
+
return record;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
public NodeRecord EnsureExternal(string qualifiedName)
|
|
153
|
+
{
|
|
154
|
+
return EnsureNode("UnknownExternal", qualifiedName, null, null);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
public void AddEdge(string kind, NodeRecord from, NodeRecord to, string resolution, EvidenceOut evidence, AmbiguityOut? ambiguity)
|
|
158
|
+
{
|
|
159
|
+
if (!GraphKinds.EdgeKinds.Contains(kind))
|
|
160
|
+
{
|
|
161
|
+
throw new ProtocolException(
|
|
162
|
+
ProtocolErrorCodes.InternalError,
|
|
163
|
+
$"TŞ §8 edge kataloğu dışı tür üretilemez: {kind}");
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
// Güvenlik bulgusu 4: ucu admit edilmemiş (limit aşımı) kenar
|
|
167
|
+
// yayınlanmaz — truncated kenar, dangling üretmemek için bilinçli
|
|
168
|
+
// düşüştür; Truncated zaten node reddinde işaretlenir.
|
|
169
|
+
if (!_nodes.ContainsKey(from.Key) || !_nodes.ContainsKey(to.Key))
|
|
170
|
+
{
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
var key = $"{kind}\u001e{from.Key}\u001e{to.Key}";
|
|
175
|
+
if (!_edges.TryGetValue(key, out var record))
|
|
176
|
+
{
|
|
177
|
+
record = new EdgeRecord(from, to, kind, resolution, ambiguity);
|
|
178
|
+
_edges.Add(key, record);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
record.AddEvidence(evidence);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
public void AddWarning(string message)
|
|
185
|
+
{
|
|
186
|
+
if (_warningSeen.Add(message))
|
|
187
|
+
{
|
|
188
|
+
Warnings.Add(message);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
public List<NodeOut> SortedNodes() =>
|
|
193
|
+
_nodes.Values.OrderBy(n => n.Key, StringComparer.Ordinal).Select(n => n.Node).ToList();
|
|
194
|
+
|
|
195
|
+
public List<EdgeOut> SortedEdges() =>
|
|
196
|
+
_edges.Values.OrderBy(EdgeSortKey, StringComparer.Ordinal).Select(e => e.ToOut()).ToList();
|
|
197
|
+
|
|
198
|
+
public List<EvidenceOut> SortedDistinctEvidence()
|
|
199
|
+
{
|
|
200
|
+
var seen = new Dictionary<string, EvidenceOut>(StringComparer.Ordinal);
|
|
201
|
+
foreach (var edge in _edges.Values)
|
|
202
|
+
{
|
|
203
|
+
foreach (var evidence in edge.Evidence)
|
|
204
|
+
{
|
|
205
|
+
var key = EvidenceKey(evidence);
|
|
206
|
+
if (!seen.ContainsKey(key))
|
|
207
|
+
{
|
|
208
|
+
seen.Add(key, evidence);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
return seen.OrderBy(p => p.Key, StringComparer.Ordinal).Select(p => p.Value).ToList();
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
private static string EdgeSortKey(EdgeRecord e) => $"{e.Kind}\u001e{e.From.Key}\u001e{e.To.Key}";
|
|
217
|
+
|
|
218
|
+
private static string NodeKey(string kind, string qualifiedName, string? relativePath) =>
|
|
219
|
+
$"{kind}\u001f{qualifiedName}\u001f{relativePath ?? string.Empty}";
|
|
220
|
+
|
|
221
|
+
internal static string EvidenceKey(EvidenceOut e)
|
|
222
|
+
{
|
|
223
|
+
var span = e.Span is null
|
|
224
|
+
? string.Empty
|
|
225
|
+
: $"{e.Span.RelativePath}\u001e{e.Span.StartLine}\u001e{e.Span.EndLine}\u001e{e.Span.SourceHash}";
|
|
226
|
+
return $"{e.Kind}\u001e{e.AnalyzerId}\u001e{e.AnalyzerVersion}\u001e{e.Rationale}\u001e{span}";
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
private sealed class EdgeRecord
|
|
230
|
+
{
|
|
231
|
+
private readonly Dictionary<string, EvidenceOut> _evidence = new(StringComparer.Ordinal);
|
|
232
|
+
|
|
233
|
+
public EdgeRecord(NodeRecord from, NodeRecord to, string kind, string resolution, AmbiguityOut? ambiguity)
|
|
234
|
+
{
|
|
235
|
+
From = from;
|
|
236
|
+
To = to;
|
|
237
|
+
Kind = kind;
|
|
238
|
+
Resolution = resolution;
|
|
239
|
+
Ambiguity = ambiguity;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
public NodeRecord From { get; }
|
|
243
|
+
public NodeRecord To { get; }
|
|
244
|
+
public string Kind { get; }
|
|
245
|
+
public string Resolution { get; }
|
|
246
|
+
public AmbiguityOut? Ambiguity { get; }
|
|
247
|
+
public IReadOnlyCollection<EvidenceOut> Evidence => _evidence.Values;
|
|
248
|
+
|
|
249
|
+
public void AddEvidence(EvidenceOut evidence)
|
|
250
|
+
{
|
|
251
|
+
var key = GraphAssembler.EvidenceKey(evidence);
|
|
252
|
+
if (!_evidence.ContainsKey(key))
|
|
253
|
+
{
|
|
254
|
+
_evidence.Add(key, evidence);
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
public EdgeOut ToOut() => new()
|
|
259
|
+
{
|
|
260
|
+
Kind = Kind,
|
|
261
|
+
From = From.Ref,
|
|
262
|
+
To = To.Ref,
|
|
263
|
+
Resolution = Resolution,
|
|
264
|
+
Evidence = _evidence.Values.OrderBy(GraphAssembler.EvidenceKey, StringComparer.Ordinal).ToList(),
|
|
265
|
+
Ambiguity = Ambiguity,
|
|
266
|
+
};
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
/**
|
|
271
|
+
* Analiz bağlamı. Sınıf (record değil), çünkü gezinme sırasında mutasyon
|
|
272
|
+
* durumu taşır: derinlik tanısının dosya başına tek kez verilmesi.
|
|
273
|
+
*/
|
|
274
|
+
private sealed class CallContext
|
|
275
|
+
{
|
|
276
|
+
public CallContext(
|
|
277
|
+
SourceEntry entry,
|
|
278
|
+
IReadOnlyList<SourceEntry> entries,
|
|
279
|
+
SemanticModel model,
|
|
280
|
+
GraphAssembler assembler,
|
|
281
|
+
Dictionary<ISymbol, NodeRecord> registry,
|
|
282
|
+
List<DiagnosticOut> diagnostics)
|
|
283
|
+
{
|
|
284
|
+
Entry = entry;
|
|
285
|
+
Entries = entries;
|
|
286
|
+
Model = model;
|
|
287
|
+
Assembler = assembler;
|
|
288
|
+
Registry = registry;
|
|
289
|
+
Diagnostics = diagnostics;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
public SourceEntry Entry { get; }
|
|
293
|
+
public IReadOnlyList<SourceEntry> Entries { get; }
|
|
294
|
+
public SemanticModel Model { get; }
|
|
295
|
+
public GraphAssembler Assembler { get; }
|
|
296
|
+
public Dictionary<ISymbol, NodeRecord> Registry { get; }
|
|
297
|
+
public List<DiagnosticOut> Diagnostics { get; }
|
|
298
|
+
|
|
299
|
+
/** Derinlik sınırı tanısı dosya başına yalnızca bir kez verilir. */
|
|
300
|
+
public bool DepthReported { get; set; }
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
/* ------------------------------------------------------------------ */
|
|
304
|
+
/* Ana giriş */
|
|
305
|
+
/* ------------------------------------------------------------------ */
|
|
306
|
+
|
|
307
|
+
public static WorkerResponse Analyze(WorkerRequest request)
|
|
308
|
+
{
|
|
309
|
+
ValidateRequest(request);
|
|
310
|
+
|
|
311
|
+
// Güvenlik bulgusu 4: yanıt node bütçesi — istekteki opsiyonel
|
|
312
|
+
// maxNodes veya sert tavan (ProtocolConstants.MaxResponseNodes).
|
|
313
|
+
var nodeLimit = request.MaxNodes ?? ProtocolConstants.MaxResponseNodes;
|
|
314
|
+
|
|
315
|
+
var assembler = new GraphAssembler(nodeLimit);
|
|
316
|
+
var warnings = assembler.Warnings;
|
|
317
|
+
|
|
318
|
+
// 1) Kaynaklar: yol normalizasyonu, çakışma reddi, deterministik sıra.
|
|
319
|
+
// Parse, dosya başına izole edilir: derin AST Roslyn parser'ında
|
|
320
|
+
// InsufficientExecutionStackException üretebilir (guard'lı, yakalanabilir);
|
|
321
|
+
// tek dosyanın sorunu analizi düşürmez (TŞ §5.1 / TS adapter kuralı).
|
|
322
|
+
var entries = new List<SourceEntry>();
|
|
323
|
+
var seenPaths = new HashSet<string>(StringComparer.Ordinal);
|
|
324
|
+
var parseDiagnostics = new List<DiagnosticOut>();
|
|
325
|
+
foreach (var file in request.Files!)
|
|
326
|
+
{
|
|
327
|
+
var relativePath = NormalizeRelativePath(file.Path);
|
|
328
|
+
if (!seenPaths.Add(relativePath))
|
|
329
|
+
{
|
|
330
|
+
throw new ProtocolException(
|
|
331
|
+
ProtocolErrorCodes.InvalidArgument,
|
|
332
|
+
$"Aynı kaynak yolu iki kez verildi: {relativePath}");
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
SyntaxTree tree;
|
|
336
|
+
try
|
|
337
|
+
{
|
|
338
|
+
tree = CSharpSyntaxTree.ParseText(
|
|
339
|
+
file.Content,
|
|
340
|
+
new CSharpParseOptions(languageVersion: LanguageVersion.Latest),
|
|
341
|
+
path: relativePath);
|
|
342
|
+
}
|
|
343
|
+
catch (Exception ex)
|
|
344
|
+
{
|
|
345
|
+
parseDiagnostics.Add(new DiagnosticOut
|
|
346
|
+
{
|
|
347
|
+
RelativePath = relativePath,
|
|
348
|
+
Code = "ADAPTER_INTERNAL",
|
|
349
|
+
Message = $"dosya ayrıştırılamadı, analiz setinden çıkarıldı: {ex.Message}",
|
|
350
|
+
Line = 0,
|
|
351
|
+
});
|
|
352
|
+
continue;
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
entries.Add(new SourceEntry(relativePath, Sha256Hex(file.Content), tree));
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
entries.Sort((a, b) => string.CompareOrdinal(a.RelativePath, b.RelativePath));
|
|
359
|
+
|
|
360
|
+
// 2) Referanslar + derleme (bellek-içi; workspace'e dokunulmaz — ADR-008).
|
|
361
|
+
var referencePaths = ReferenceResolver.Resolve(request.ReferenceDirs, "net10.0", warnings);
|
|
362
|
+
var references = referencePaths.Select(p => (MetadataReference)MetadataReference.CreateFromFile(p)).ToList();
|
|
363
|
+
// Top-level statement içeren girdi yürütülebilir derlenmelidir
|
|
364
|
+
// (CS8805); aksi halde kütüphane çıktısı CS5001 uyarısı üretmez.
|
|
365
|
+
// Her iki durum da girdiden türetilir → deterministik.
|
|
366
|
+
var hasTopLevelStatements = entries.Any(e =>
|
|
367
|
+
e.Tree.GetRoot() is CompilationUnitSyntax unit &&
|
|
368
|
+
unit.Members.OfType<GlobalStatementSyntax>().Any());
|
|
369
|
+
var outputKind = hasTopLevelStatements ? OutputKind.ConsoleApplication : OutputKind.DynamicallyLinkedLibrary;
|
|
370
|
+
var compilation = CSharpCompilation.Create(
|
|
371
|
+
"CausorynWorker.Analysis",
|
|
372
|
+
entries.Select(e => e.Tree),
|
|
373
|
+
references,
|
|
374
|
+
new CSharpCompilationOptions(
|
|
375
|
+
outputKind,
|
|
376
|
+
nullableContextOptions: NullableContextOptions.Enable));
|
|
377
|
+
|
|
378
|
+
// 3) Tanılar: Roslyn 5.0 GetDiagnostics (parse+declaration+semantic+body)
|
|
379
|
+
// tek çağrı; Warning+Error korunur, dosyaya eşlenir (1 tabanlı satır)
|
|
380
|
+
// ve kanonik sıraya dizilir (TŞ §8 invariant iv). Aşama izole:
|
|
381
|
+
// derin AST'de Roslyn bind/tanı aşaması InsufficientExecutionStackException
|
|
382
|
+
// fırlatabilir (guard'lı) — yakalanır, bütün girdiye ADAPTER_INTERNAL
|
|
383
|
+
// tanısı + uyarı yazılır ve analiz partial olarak sürer.
|
|
384
|
+
var entryByTree = entries.ToDictionary(e => e.Tree, e => e);
|
|
385
|
+
var diagnostics = parseDiagnostics;
|
|
386
|
+
try
|
|
387
|
+
{
|
|
388
|
+
foreach (var diagnostic in compilation.GetDiagnostics())
|
|
389
|
+
{
|
|
390
|
+
if (diagnostic.Severity is not (DiagnosticSeverity.Error or DiagnosticSeverity.Warning))
|
|
391
|
+
{
|
|
392
|
+
continue;
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
if (diagnostic.Location.SourceTree is not SyntaxTree sourceTree ||
|
|
396
|
+
!entryByTree.TryGetValue(sourceTree, out var entry))
|
|
397
|
+
{
|
|
398
|
+
continue; // dosya-dışı derleme tanısı bu protokolde taşınmaz
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
var lineSpan = diagnostic.Location.GetLineSpan();
|
|
402
|
+
var line = lineSpan.IsValid ? lineSpan.StartLinePosition.Line + 1 : 0;
|
|
403
|
+
diagnostics.Add(new DiagnosticOut
|
|
404
|
+
{
|
|
405
|
+
RelativePath = entry.RelativePath,
|
|
406
|
+
Code = diagnostic.Id,
|
|
407
|
+
Message = diagnostic.GetMessage(),
|
|
408
|
+
Line = line,
|
|
409
|
+
});
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
catch (Exception ex)
|
|
413
|
+
{
|
|
414
|
+
foreach (var entry in entries)
|
|
415
|
+
{
|
|
416
|
+
diagnostics.Add(new DiagnosticOut
|
|
417
|
+
{
|
|
418
|
+
RelativePath = entry.RelativePath,
|
|
419
|
+
Code = "ADAPTER_INTERNAL",
|
|
420
|
+
Message = $"derleme tanı aşaması tamamlanamadı ({ex.GetType().Name}); girdi derinliği kod bütçesini aşıyor",
|
|
421
|
+
Line = 0,
|
|
422
|
+
});
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
warnings.Add("tanı aşaması tamamlanamadı: " + ex.Message);
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
diagnostics.Sort((a, b) =>
|
|
429
|
+
{
|
|
430
|
+
var byPath = string.CompareOrdinal(a.RelativePath, b.RelativePath);
|
|
431
|
+
if (byPath != 0)
|
|
432
|
+
{
|
|
433
|
+
return byPath;
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
var byLine = a.Line.CompareTo(b.Line);
|
|
437
|
+
if (byLine != 0)
|
|
438
|
+
{
|
|
439
|
+
return byLine;
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
var byCode = string.CompareOrdinal(a.Code, b.Code);
|
|
443
|
+
return byCode != 0 ? byCode : string.CompareOrdinal(a.Message, b.Message);
|
|
444
|
+
});
|
|
445
|
+
|
|
446
|
+
var registry = new Dictionary<ISymbol, NodeRecord>(SymbolEqualityComparer.Default);
|
|
447
|
+
var controllers = new List<(SourceEntry Entry, ControllerInfo Info)>();
|
|
448
|
+
|
|
449
|
+
/**
|
|
450
|
+
* Aşama izolasyonu (TS adapter runPhase kuralı): tek dosyadaki
|
|
451
|
+
* sorun — Roslyn semantic aşamalarının derinlik guard'ı dahil —
|
|
452
|
+
* analizi düşürmez; ADAPTER_INTERNAL tanısı olarak toplanır ve
|
|
453
|
+
* analiz partial olarak sürer.
|
|
454
|
+
*/
|
|
455
|
+
void RunPhaseIsolated(SourceEntry phaseEntry, Action phase)
|
|
456
|
+
{
|
|
457
|
+
try
|
|
458
|
+
{
|
|
459
|
+
phase();
|
|
460
|
+
}
|
|
461
|
+
catch (InsufficientExecutionStackException)
|
|
462
|
+
{
|
|
463
|
+
diagnostics.Add(new DiagnosticOut
|
|
464
|
+
{
|
|
465
|
+
RelativePath = phaseEntry.RelativePath,
|
|
466
|
+
Code = "ADAPTER_INTERNAL",
|
|
467
|
+
Message = "çözümleme aşaması derinlik sınırına takıldı (InsufficientExecutionStackException); aşama bu dosya için atlandı",
|
|
468
|
+
Line = 0,
|
|
469
|
+
});
|
|
470
|
+
warnings.Add($"çözümleme derinlik sınırı: {phaseEntry.RelativePath} (aşama atlandı)");
|
|
471
|
+
}
|
|
472
|
+
catch (Exception ex)
|
|
473
|
+
{
|
|
474
|
+
diagnostics.Add(new DiagnosticOut
|
|
475
|
+
{
|
|
476
|
+
RelativePath = phaseEntry.RelativePath,
|
|
477
|
+
Code = "ADAPTER_INTERNAL",
|
|
478
|
+
Message = ex.Message,
|
|
479
|
+
Line = 0,
|
|
480
|
+
});
|
|
481
|
+
warnings.Add($"çözümleme aşaması hata verdi: {phaseEntry.RelativePath} ({ex.GetType().Name})");
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
// 4) Faz 1: bildirimler (CONTAINS + registry) — önce TÜM dosyalar,
|
|
486
|
+
// böylece çapraz-dosya sembol araması registry'de tam olur.
|
|
487
|
+
foreach (var entry in entries)
|
|
488
|
+
{
|
|
489
|
+
RunPhaseIsolated(entry, () =>
|
|
490
|
+
{
|
|
491
|
+
var model = compilation.GetSemanticModel(entry.Tree);
|
|
492
|
+
var fileRecord = assembler.EnsureNode(
|
|
493
|
+
"File", entry.RelativePath, entry.RelativePath,
|
|
494
|
+
new Dictionary<string, object> { ["sourceHash"] = entry.SourceHash });
|
|
495
|
+
WalkCompilationUnit(entry, fileRecord.Node, model, assembler, registry, controllers);
|
|
496
|
+
});
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
// 5) Faz 2: çağrılar + minimal API rotaları (semantic model).
|
|
500
|
+
foreach (var entry in entries)
|
|
501
|
+
{
|
|
502
|
+
RunPhaseIsolated(entry, () =>
|
|
503
|
+
{
|
|
504
|
+
var model = compilation.GetSemanticModel(entry.Tree);
|
|
505
|
+
VisitCalls(entry, entries, model, assembler, registry, diagnostics);
|
|
506
|
+
});
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
// 6) Faz 3: controller öznitelik rotaları (semantic + bilinen ad kuralı).
|
|
510
|
+
foreach (var (entry, info) in controllers)
|
|
511
|
+
{
|
|
512
|
+
RunPhaseIsolated(entry, () =>
|
|
513
|
+
{
|
|
514
|
+
var model = compilation.GetSemanticModel(entry.Tree);
|
|
515
|
+
ExtractControllerRoutes(entry, info, model, assembler, registry);
|
|
516
|
+
});
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
// 7) Kanonik çıktı (TŞ §8 invariant iv/vi).
|
|
520
|
+
if (assembler.Truncated)
|
|
521
|
+
{
|
|
522
|
+
// Güvenlik bulgusu 4: sessiz kesim yok — tanı düşer, status
|
|
523
|
+
// aşağıdaki mevcut ifadeyle "partial" olur.
|
|
524
|
+
diagnostics.Add(new DiagnosticOut
|
|
525
|
+
{
|
|
526
|
+
RelativePath = string.Empty,
|
|
527
|
+
Code = "RESPONSE_TRUNCATED",
|
|
528
|
+
Message = $"yanıt node bütçesi aşıldı (maxNodes={nodeLimit.ToString(System.Globalization.CultureInfo.InvariantCulture)}); aşan node/kenarlar yayınlanmadı",
|
|
529
|
+
Line = 0,
|
|
530
|
+
});
|
|
531
|
+
}
|
|
532
|
+
var edges = assembler.SortedEdges();
|
|
533
|
+
var verified = edges.Count(e => e.Resolution == "verified");
|
|
534
|
+
var coverageRatio = edges.Count == 0
|
|
535
|
+
? 0d
|
|
536
|
+
: Math.Round((double)verified * 10000d / edges.Count, 4, MidpointRounding.AwayFromZero) / 10000d;
|
|
537
|
+
|
|
538
|
+
return new WorkerResponse
|
|
539
|
+
{
|
|
540
|
+
Id = request.Id,
|
|
541
|
+
Status = diagnostics.Count > 0 ? "partial" : "ready",
|
|
542
|
+
Worker = new WorkerInfo(),
|
|
543
|
+
Capabilities = new CapabilitiesOut
|
|
544
|
+
{
|
|
545
|
+
AstParse = true,
|
|
546
|
+
SymbolResolution = true,
|
|
547
|
+
ContainsEdges = true,
|
|
548
|
+
CallEdges = true,
|
|
549
|
+
ImportEdges = false,
|
|
550
|
+
FrameworkLinkers = false,
|
|
551
|
+
},
|
|
552
|
+
CoverageRatio = coverageRatio,
|
|
553
|
+
UnsupportedConstructs = UnsupportedConstructs.ToList(),
|
|
554
|
+
Warnings = warnings,
|
|
555
|
+
Diagnostics = diagnostics,
|
|
556
|
+
Nodes = assembler.SortedNodes(),
|
|
557
|
+
Edges = edges,
|
|
558
|
+
Evidence = assembler.SortedDistinctEvidence(),
|
|
559
|
+
};
|
|
560
|
+
}
|
|
561
|
+
|
|
562
|
+
private static void ValidateRequest(WorkerRequest request)
|
|
563
|
+
{
|
|
564
|
+
if (request.Id.ValueKind is JsonValueKind.Undefined or JsonValueKind.Null)
|
|
565
|
+
{
|
|
566
|
+
throw new ProtocolException(ProtocolErrorCodes.InvalidArgument, "'id' alanı zorunludur");
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
if (string.IsNullOrWhiteSpace(request.Type))
|
|
570
|
+
{
|
|
571
|
+
throw new ProtocolException(ProtocolErrorCodes.InvalidArgument, "'type' alanı zorunludur");
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
if (request.ProtocolVersion is not null && request.ProtocolVersion != ProtocolConstants.ProtocolVersion)
|
|
575
|
+
{
|
|
576
|
+
throw new ProtocolException(
|
|
577
|
+
ProtocolErrorCodes.InvalidArgument,
|
|
578
|
+
$"Desteklenmeyen protokol sürümü: '{request.ProtocolVersion}' (desteklenen: '{ProtocolConstants.ProtocolVersion}')");
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
if (request.ExtensionData is { Count: > 0 })
|
|
582
|
+
{
|
|
583
|
+
throw new ProtocolException(
|
|
584
|
+
ProtocolErrorCodes.InvalidArgument,
|
|
585
|
+
$"İstek bilinmeyen alan içeriyor: {string.Join(", ", request.ExtensionData.Keys)}");
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
if (request.Files is null || request.Files.Count == 0)
|
|
589
|
+
{
|
|
590
|
+
throw new ProtocolException(ProtocolErrorCodes.InvalidArgument, "'files' alanı zorunludur (en az bir kaynak)");
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
// Kaynak sınırları (TŞ §9 resource budget; K-010: yalnızca boyut
|
|
594
|
+
// limitleri) — aşım LIMIT_EXCEEDED, süreç ölmez.
|
|
595
|
+
if (request.Files.Count > ProtocolConstants.MaxFileCount)
|
|
596
|
+
{
|
|
597
|
+
throw new ProtocolException(
|
|
598
|
+
ProtocolErrorCodes.LimitExceeded,
|
|
599
|
+
$"files sayısı sınırı aşıldı: {request.Files.Count} > {ProtocolConstants.MaxFileCount}");
|
|
600
|
+
}
|
|
601
|
+
|
|
602
|
+
// Güvenlik bulgusu 4: maxNodes aralık denetimi — null → sert tavan;
|
|
603
|
+
// 1..MaxResponseNodes dışı açık INVALID_ARGUMENT reddi (sessiz
|
|
604
|
+
// clamp yerine; ADR-010 açık red kültürü).
|
|
605
|
+
if (request.MaxNodes is < 1 or > ProtocolConstants.MaxResponseNodes)
|
|
606
|
+
{
|
|
607
|
+
throw new ProtocolException(
|
|
608
|
+
ProtocolErrorCodes.InvalidArgument,
|
|
609
|
+
$"maxNodes 1..{ProtocolConstants.MaxResponseNodes} aralığında olmalı; gelen: {request.MaxNodes?.ToString(System.Globalization.CultureInfo.InvariantCulture) ?? "null"}");
|
|
610
|
+
}
|
|
611
|
+
|
|
612
|
+
foreach (var file in request.Files)
|
|
613
|
+
{
|
|
614
|
+
if (file.Path is null || file.Content is null)
|
|
615
|
+
{
|
|
616
|
+
throw new ProtocolException(
|
|
617
|
+
ProtocolErrorCodes.InvalidArgument,
|
|
618
|
+
"files[] girdisi 'path' ve 'content' alanlarını zorunlu kılar");
|
|
619
|
+
}
|
|
620
|
+
|
|
621
|
+
if (file.ExtensionData is { Count: > 0 })
|
|
622
|
+
{
|
|
623
|
+
throw new ProtocolException(
|
|
624
|
+
ProtocolErrorCodes.InvalidArgument,
|
|
625
|
+
$"files[] girdisi bilinmeyen alan içeriyor: {string.Join(", ", file.ExtensionData.Keys)}");
|
|
626
|
+
}
|
|
627
|
+
|
|
628
|
+
var contentBytes = Encoding.UTF8.GetByteCount(file.Content);
|
|
629
|
+
if (contentBytes > ProtocolConstants.MaxFileContentBytes)
|
|
630
|
+
{
|
|
631
|
+
throw new ProtocolException(
|
|
632
|
+
ProtocolErrorCodes.LimitExceeded,
|
|
633
|
+
$"dosya içerik boyutu sınırı aşıldı: {file.Path} ({contentBytes} bayt > {ProtocolConstants.MaxFileContentBytes})");
|
|
634
|
+
}
|
|
635
|
+
}
|
|
636
|
+
}
|
|
637
|
+
|
|
638
|
+
private static string NormalizeRelativePath(string raw)
|
|
639
|
+
{
|
|
640
|
+
var posix = raw.Replace('\\', '/');
|
|
641
|
+
if (posix.StartsWith('/') || Regex.IsMatch(posix, "^[a-zA-Z]:"))
|
|
642
|
+
{
|
|
643
|
+
throw new ProtocolException(
|
|
644
|
+
ProtocolErrorCodes.InvalidArgument,
|
|
645
|
+
$"Mutlak kaynak yolu kabul edilmez: {raw}");
|
|
646
|
+
}
|
|
647
|
+
|
|
648
|
+
foreach (var segment in posix.Split('/'))
|
|
649
|
+
{
|
|
650
|
+
if (segment.Length == 0 || segment == ".")
|
|
651
|
+
{
|
|
652
|
+
throw new ProtocolException(
|
|
653
|
+
ProtocolErrorCodes.InvalidArgument,
|
|
654
|
+
$"Kaynak yolu boş/geçersiz segment içeriyor: {raw}");
|
|
655
|
+
}
|
|
656
|
+
|
|
657
|
+
if (segment == "..")
|
|
658
|
+
{
|
|
659
|
+
throw new ProtocolException(
|
|
660
|
+
ProtocolErrorCodes.InvalidArgument,
|
|
661
|
+
$"Kaynak yolu kök dışına çıkıyor: {raw}");
|
|
662
|
+
}
|
|
663
|
+
}
|
|
664
|
+
|
|
665
|
+
return posix;
|
|
666
|
+
}
|
|
667
|
+
|
|
668
|
+
private static string Sha256Hex(string content)
|
|
669
|
+
{
|
|
670
|
+
var hash = SHA256.HashData(Encoding.UTF8.GetBytes(content));
|
|
671
|
+
return Convert.ToHexString(hash).ToLowerInvariant();
|
|
672
|
+
}
|
|
673
|
+
|
|
674
|
+
/* ------------------------------------------------------------------ */
|
|
675
|
+
/* Faz 1: bildirimler → CONTAINS + registry */
|
|
676
|
+
/* ------------------------------------------------------------------ */
|
|
677
|
+
|
|
678
|
+
private static void WalkCompilationUnit(
|
|
679
|
+
SourceEntry entry,
|
|
680
|
+
NodeOut fileNode,
|
|
681
|
+
SemanticModel model,
|
|
682
|
+
GraphAssembler assembler,
|
|
683
|
+
Dictionary<ISymbol, NodeRecord> registry,
|
|
684
|
+
List<(SourceEntry Entry, ControllerInfo Info)> controllers)
|
|
685
|
+
{
|
|
686
|
+
if (entry.Tree.GetRoot() is not CompilationUnitSyntax unit)
|
|
687
|
+
{
|
|
688
|
+
return;
|
|
689
|
+
}
|
|
690
|
+
|
|
691
|
+
foreach (var member in unit.Members)
|
|
692
|
+
{
|
|
693
|
+
WalkMember(entry, member, string.Empty, fileNode, model, assembler, registry, controllers);
|
|
694
|
+
}
|
|
695
|
+
}
|
|
696
|
+
|
|
697
|
+
private static void WalkMember(
|
|
698
|
+
SourceEntry entry,
|
|
699
|
+
SyntaxNode member,
|
|
700
|
+
string nsPrefix,
|
|
701
|
+
NodeOut fileNode,
|
|
702
|
+
SemanticModel model,
|
|
703
|
+
GraphAssembler assembler,
|
|
704
|
+
Dictionary<ISymbol, NodeRecord> registry,
|
|
705
|
+
List<(SourceEntry Entry, ControllerInfo Info)> controllers)
|
|
706
|
+
{
|
|
707
|
+
switch (member)
|
|
708
|
+
{
|
|
709
|
+
case NamespaceDeclarationSyntax ns:
|
|
710
|
+
foreach (var child in ns.Members)
|
|
711
|
+
{
|
|
712
|
+
WalkMember(entry, child, JoinNamespace(nsPrefix, ns.Name.ToString()), fileNode, model, assembler, registry, controllers);
|
|
713
|
+
}
|
|
714
|
+
|
|
715
|
+
break;
|
|
716
|
+
|
|
717
|
+
case FileScopedNamespaceDeclarationSyntax fsns:
|
|
718
|
+
foreach (var child in fsns.Members)
|
|
719
|
+
{
|
|
720
|
+
WalkMember(entry, child, JoinNamespace(nsPrefix, fsns.Name.ToString()), fileNode, model, assembler, registry, controllers);
|
|
721
|
+
}
|
|
722
|
+
|
|
723
|
+
break;
|
|
724
|
+
|
|
725
|
+
case TypeDeclarationSyntax typeDecl:
|
|
726
|
+
RegisterType(entry, typeDecl, nsPrefix, fileNode, model, assembler, registry, controllers);
|
|
727
|
+
foreach (var child in typeDecl.Members)
|
|
728
|
+
{
|
|
729
|
+
WalkMember(entry, child, nsPrefix, fileNode, model, assembler, registry, controllers);
|
|
730
|
+
}
|
|
731
|
+
|
|
732
|
+
break;
|
|
733
|
+
|
|
734
|
+
case GlobalStatementSyntax { Statement: LocalFunctionStatementSyntax localFunction }:
|
|
735
|
+
RegisterTopLevelLocalFunction(entry, localFunction, fileNode, model, assembler, registry);
|
|
736
|
+
break;
|
|
737
|
+
|
|
738
|
+
case EnumDeclarationSyntax enumDecl:
|
|
739
|
+
RegisterEnum(entry, enumDecl, nsPrefix, fileNode, model, assembler, registry);
|
|
740
|
+
break;
|
|
741
|
+
}
|
|
742
|
+
}
|
|
743
|
+
|
|
744
|
+
private static string JoinNamespace(string prefix, string name)
|
|
745
|
+
{
|
|
746
|
+
var trimmed = name.Trim();
|
|
747
|
+
return prefix.Length == 0 ? trimmed : $"{prefix}.{trimmed}";
|
|
748
|
+
}
|
|
749
|
+
|
|
750
|
+
private static void RegisterType(
|
|
751
|
+
SourceEntry entry,
|
|
752
|
+
TypeDeclarationSyntax typeDecl,
|
|
753
|
+
string nsPrefix,
|
|
754
|
+
NodeOut fileNode,
|
|
755
|
+
SemanticModel model,
|
|
756
|
+
GraphAssembler assembler,
|
|
757
|
+
Dictionary<ISymbol, NodeRecord> registry,
|
|
758
|
+
List<(SourceEntry Entry, ControllerInfo Info)> controllers)
|
|
759
|
+
{
|
|
760
|
+
var name = typeDecl.Identifier.ValueText;
|
|
761
|
+
var kind = TypeKindOf(typeDecl);
|
|
762
|
+
var qualifiedName = JoinNamespace(nsPrefix, name);
|
|
763
|
+
var record = assembler.EnsureNode(kind, qualifiedName, entry.RelativePath, null);
|
|
764
|
+
var symbol = model.GetDeclaredSymbol(typeDecl);
|
|
765
|
+
if (symbol is not null)
|
|
766
|
+
{
|
|
767
|
+
registry[symbol] = record;
|
|
768
|
+
}
|
|
769
|
+
|
|
770
|
+
AddContains(assembler, entry, typeDecl, fileNode, record,
|
|
771
|
+
$"CONTAINS: {entry.RelativePath} dosyasındaki {qualifiedName} {kind.ToLowerInvariant()} bildirimi AST span kanıtıyla eşlendi.");
|
|
772
|
+
|
|
773
|
+
if (typeDecl is ClassDeclarationSyntax classDecl)
|
|
774
|
+
{
|
|
775
|
+
controllers.Add((entry, new ControllerInfo(classDecl, record, qualifiedName)));
|
|
776
|
+
}
|
|
777
|
+
|
|
778
|
+
RegisterTypeMembers(entry, typeDecl, qualifiedName, record, model, assembler, registry);
|
|
779
|
+
}
|
|
780
|
+
|
|
781
|
+
private static void RegisterTypeMembers(
|
|
782
|
+
SourceEntry entry,
|
|
783
|
+
TypeDeclarationSyntax typeDecl,
|
|
784
|
+
string ownerQualifiedName,
|
|
785
|
+
NodeRecord ownerRecord,
|
|
786
|
+
SemanticModel model,
|
|
787
|
+
GraphAssembler assembler,
|
|
788
|
+
Dictionary<ISymbol, NodeRecord> registry)
|
|
789
|
+
{
|
|
790
|
+
foreach (var member in typeDecl.Members)
|
|
791
|
+
{
|
|
792
|
+
switch (member)
|
|
793
|
+
{
|
|
794
|
+
case MethodDeclarationSyntax method:
|
|
795
|
+
RegisterMember(entry, method, ownerQualifiedName, ownerRecord, "Method",
|
|
796
|
+
method.Identifier.ValueText, model, assembler, registry);
|
|
797
|
+
break;
|
|
798
|
+
|
|
799
|
+
case ConstructorDeclarationSyntax ctor:
|
|
800
|
+
RegisterMember(entry, ctor, ownerQualifiedName, ownerRecord, "Method", "constructor",
|
|
801
|
+
model, assembler, registry);
|
|
802
|
+
break;
|
|
803
|
+
|
|
804
|
+
case PropertyDeclarationSyntax property:
|
|
805
|
+
// Belgelenmiş yaklaşım: property, CIL düzeyinde erişimci
|
|
806
|
+
// metotlarına çözüldüğü için Method düğümüyle temsil edilir.
|
|
807
|
+
RegisterMember(entry, property, ownerQualifiedName, ownerRecord, "Method",
|
|
808
|
+
property.Identifier.ValueText, model, assembler, registry);
|
|
809
|
+
break;
|
|
810
|
+
}
|
|
811
|
+
}
|
|
812
|
+
}
|
|
813
|
+
|
|
814
|
+
private static void RegisterMember(
|
|
815
|
+
SourceEntry entry,
|
|
816
|
+
SyntaxNode declaration,
|
|
817
|
+
string ownerQualifiedName,
|
|
818
|
+
NodeRecord ownerRecord,
|
|
819
|
+
string kind,
|
|
820
|
+
string memberName,
|
|
821
|
+
SemanticModel model,
|
|
822
|
+
GraphAssembler assembler,
|
|
823
|
+
Dictionary<ISymbol, NodeRecord> registry)
|
|
824
|
+
{
|
|
825
|
+
var qualifiedName = $"{ownerQualifiedName}.{memberName}";
|
|
826
|
+
var record = assembler.EnsureNode(kind, qualifiedName, entry.RelativePath, null);
|
|
827
|
+
var symbol = declaration switch
|
|
828
|
+
{
|
|
829
|
+
MethodDeclarationSyntax m => (ISymbol?)model.GetDeclaredSymbol(m),
|
|
830
|
+
ConstructorDeclarationSyntax c => (ISymbol?)model.GetDeclaredSymbol(c),
|
|
831
|
+
PropertyDeclarationSyntax p => (ISymbol?)model.GetDeclaredSymbol(p),
|
|
832
|
+
_ => null,
|
|
833
|
+
};
|
|
834
|
+
if (symbol is not null)
|
|
835
|
+
{
|
|
836
|
+
registry[symbol] = record;
|
|
837
|
+
}
|
|
838
|
+
|
|
839
|
+
AddContains(assembler, entry, declaration, ownerRecord.Node, record,
|
|
840
|
+
$"CONTAINS: {ownerQualifiedName} bildirimi içindeki {memberName} üyesi AST span kanıtıyla eşlendi.");
|
|
841
|
+
}
|
|
842
|
+
|
|
843
|
+
private static void RegisterTopLevelLocalFunction(
|
|
844
|
+
SourceEntry entry,
|
|
845
|
+
LocalFunctionStatementSyntax localFunction,
|
|
846
|
+
NodeOut fileNode,
|
|
847
|
+
SemanticModel model,
|
|
848
|
+
GraphAssembler assembler,
|
|
849
|
+
Dictionary<ISymbol, NodeRecord> registry)
|
|
850
|
+
{
|
|
851
|
+
var symbol = model.GetDeclaredSymbol(localFunction);
|
|
852
|
+
// Top-level local function sentetik Program sınıfına derlenir; bu
|
|
853
|
+
// kural PROTOCOL.md'de belgelenmiştir (qualifiedName: Program.<ad>).
|
|
854
|
+
var ownerDisplay = symbol?.ContainingType?.ToDisplayString() ?? "Program";
|
|
855
|
+
var qualifiedName = $"{ownerDisplay}.{localFunction.Identifier.ValueText}";
|
|
856
|
+
var record = assembler.EnsureNode("Function", qualifiedName, entry.RelativePath, null);
|
|
857
|
+
if (symbol is not null)
|
|
858
|
+
{
|
|
859
|
+
registry[symbol] = record;
|
|
860
|
+
}
|
|
861
|
+
|
|
862
|
+
AddContains(assembler, entry, localFunction, fileNode, record,
|
|
863
|
+
$"CONTAINS: {entry.RelativePath} dosyasındaki {qualifiedName} yerel fonksiyon bildirimi AST span kanıtıyla eşlendi.");
|
|
864
|
+
}
|
|
865
|
+
|
|
866
|
+
private static string TypeKindOf(TypeDeclarationSyntax typeDecl) => typeDecl switch
|
|
867
|
+
{
|
|
868
|
+
ClassDeclarationSyntax => "Class",
|
|
869
|
+
InterfaceDeclarationSyntax => "Interface",
|
|
870
|
+
StructDeclarationSyntax => "Type",
|
|
871
|
+
RecordDeclarationSyntax recordDecl =>
|
|
872
|
+
recordDecl.ClassOrStructKeyword.IsKind(SyntaxKind.StructKeyword) ? "Type" : "Class",
|
|
873
|
+
_ => "Type",
|
|
874
|
+
};
|
|
875
|
+
|
|
876
|
+
private static void RegisterEnum(
|
|
877
|
+
SourceEntry entry,
|
|
878
|
+
EnumDeclarationSyntax enumDecl,
|
|
879
|
+
string nsPrefix,
|
|
880
|
+
NodeOut fileNode,
|
|
881
|
+
SemanticModel model,
|
|
882
|
+
GraphAssembler assembler,
|
|
883
|
+
Dictionary<ISymbol, NodeRecord> registry)
|
|
884
|
+
{
|
|
885
|
+
var name = enumDecl.Identifier.ValueText;
|
|
886
|
+
var qualifiedName = JoinNamespace(nsPrefix, name);
|
|
887
|
+
var record = assembler.EnsureNode("Type", qualifiedName, entry.RelativePath, null);
|
|
888
|
+
var symbol = model.GetDeclaredSymbol(enumDecl);
|
|
889
|
+
if (symbol is not null)
|
|
890
|
+
{
|
|
891
|
+
registry[symbol] = record;
|
|
892
|
+
}
|
|
893
|
+
|
|
894
|
+
AddContains(assembler, entry, enumDecl, fileNode, record,
|
|
895
|
+
$"CONTAINS: {entry.RelativePath} dosyasındaki {qualifiedName} enum bildirimi AST span kanıtıyla eşlendi.");
|
|
896
|
+
}
|
|
897
|
+
|
|
898
|
+
private static void AddContains(
|
|
899
|
+
GraphAssembler assembler,
|
|
900
|
+
SourceEntry entry,
|
|
901
|
+
SyntaxNode declaration,
|
|
902
|
+
NodeOut fromNode,
|
|
903
|
+
NodeRecord toRecord,
|
|
904
|
+
string rationale)
|
|
905
|
+
{
|
|
906
|
+
var from = assembler.EnsureNode(fromNode.Kind, fromNode.QualifiedName, fromNode.RelativePath, null);
|
|
907
|
+
assembler.AddEdge("CONTAINS", from, toRecord, "verified",
|
|
908
|
+
SpanEvidence(entry, declaration, "ast-span", rationale), null);
|
|
909
|
+
}
|
|
910
|
+
|
|
911
|
+
/* ------------------------------------------------------------------ */
|
|
912
|
+
/* Faz 2: çağrılar + minimal API */
|
|
913
|
+
/* ------------------------------------------------------------------ */
|
|
914
|
+
|
|
915
|
+
/**
|
|
916
|
+
* AST gezinme derinlik üst sınırı (denetim bulgusu düzeltmesi):
|
|
917
|
+
* sınırsız özyineleme patolojik derin AST'de StackOverflowException
|
|
918
|
+
* üretir (.NET'te yakalanamaz, süreç ölür). Sınır aşımında alt ağaç
|
|
919
|
+
* atlanır, ADAPTER_INTERNAL tanısı + uyarı verilir ve analiz
|
|
920
|
+
* "partial" olarak raporlanır — "tek dosyadaki sorun analizi
|
|
921
|
+
* düşürmez" hedefiyle (sınıf başlığı) uyumlu. Çöküş kanıtı: eski
|
|
922
|
+
* binary 5000 katmanlı ifadede 0xC00000FD ile ölmüştü; yeni kod aynı
|
|
923
|
+
* girdide tanı üretip yanıtı döner (tests/roslyn-worker.test.ts).
|
|
924
|
+
*/
|
|
925
|
+
private const int MaxTraversalDepth = 1000;
|
|
926
|
+
|
|
927
|
+
private static void VisitCalls(
|
|
928
|
+
SourceEntry entry,
|
|
929
|
+
IReadOnlyList<SourceEntry> entries,
|
|
930
|
+
SemanticModel model,
|
|
931
|
+
GraphAssembler assembler,
|
|
932
|
+
Dictionary<ISymbol, NodeRecord> registry,
|
|
933
|
+
List<DiagnosticOut> diagnostics)
|
|
934
|
+
{
|
|
935
|
+
var context = new CallContext(entry, entries, model, assembler, registry, diagnostics);
|
|
936
|
+
VisitNode(context, entry.Tree.GetRoot(), null, depth: 0);
|
|
937
|
+
}
|
|
938
|
+
|
|
939
|
+
private static void VisitNode(CallContext context, SyntaxNode node, NodeRecord? caller, int depth)
|
|
940
|
+
{
|
|
941
|
+
if (depth > MaxTraversalDepth)
|
|
942
|
+
{
|
|
943
|
+
ReportDepthExceeded(context, node);
|
|
944
|
+
return; // derin alt ağaç atlanır
|
|
945
|
+
}
|
|
946
|
+
|
|
947
|
+
var currentCaller = CallerFor(context, node) ?? caller;
|
|
948
|
+
|
|
949
|
+
if (node is InvocationExpressionSyntax invocation)
|
|
950
|
+
{
|
|
951
|
+
TryMinimalApiRoute(context, invocation, currentCaller);
|
|
952
|
+
EmitCall(context, invocation, currentCaller);
|
|
953
|
+
}
|
|
954
|
+
else if (node is ObjectCreationExpressionSyntax or ImplicitObjectCreationExpressionSyntax)
|
|
955
|
+
{
|
|
956
|
+
EmitCreation(context, node, currentCaller);
|
|
957
|
+
}
|
|
958
|
+
|
|
959
|
+
foreach (var child in node.ChildNodes())
|
|
960
|
+
{
|
|
961
|
+
VisitNode(context, child, currentCaller, depth + 1);
|
|
962
|
+
}
|
|
963
|
+
}
|
|
964
|
+
|
|
965
|
+
/** Derinlik aşımı tanısı: dosya başına bir kez (CallContext.DepthReported). */
|
|
966
|
+
private static void ReportDepthExceeded(CallContext context, SyntaxNode node)
|
|
967
|
+
{
|
|
968
|
+
if (context.DepthReported)
|
|
969
|
+
{
|
|
970
|
+
return;
|
|
971
|
+
}
|
|
972
|
+
|
|
973
|
+
context.DepthReported = true;
|
|
974
|
+
var lineSpan = context.Entry.Tree.GetLineSpan(node.Span);
|
|
975
|
+
context.Diagnostics.Add(new DiagnosticOut
|
|
976
|
+
{
|
|
977
|
+
RelativePath = context.Entry.RelativePath,
|
|
978
|
+
Code = "ADAPTER_INTERNAL",
|
|
979
|
+
Message = $"AST gezinme derinliği {MaxTraversalDepth} sınırını aştı; derin alt ağaçlar atlandı",
|
|
980
|
+
Line = lineSpan.IsValid ? lineSpan.StartLinePosition.Line + 1 : 0,
|
|
981
|
+
});
|
|
982
|
+
context.Assembler.AddWarning(
|
|
983
|
+
$"AST derinlik sınırı aşıldı: {context.Entry.RelativePath} (derin alt ağaçlar atlandı)");
|
|
984
|
+
}
|
|
985
|
+
|
|
986
|
+
private static NodeRecord? CallerFor(CallContext context, SyntaxNode node)
|
|
987
|
+
{
|
|
988
|
+
ISymbol? symbol = node switch
|
|
989
|
+
{
|
|
990
|
+
MethodDeclarationSyntax m => (ISymbol?)context.Model.GetDeclaredSymbol(m),
|
|
991
|
+
ConstructorDeclarationSyntax c => (ISymbol?)context.Model.GetDeclaredSymbol(c),
|
|
992
|
+
PropertyDeclarationSyntax p => (ISymbol?)context.Model.GetDeclaredSymbol(p),
|
|
993
|
+
AccessorDeclarationSyntax acc when acc.Parent?.Parent is PropertyDeclarationSyntax p2 =>
|
|
994
|
+
(ISymbol?)context.Model.GetDeclaredSymbol(p2),
|
|
995
|
+
LocalFunctionStatementSyntax lf => (ISymbol?)context.Model.GetDeclaredSymbol(lf),
|
|
996
|
+
_ => null,
|
|
997
|
+
};
|
|
998
|
+
return symbol is null ? null : RegistryLookup(context, symbol);
|
|
999
|
+
}
|
|
1000
|
+
|
|
1001
|
+
private static NodeRecord? RegistryLookup(CallContext context, ISymbol symbol)
|
|
1002
|
+
{
|
|
1003
|
+
if (context.Registry.TryGetValue(symbol, out var hit))
|
|
1004
|
+
{
|
|
1005
|
+
return hit;
|
|
1006
|
+
}
|
|
1007
|
+
|
|
1008
|
+
var original = symbol.OriginalDefinition;
|
|
1009
|
+
if (!SymbolEqualityComparer.Default.Equals(original, symbol) &&
|
|
1010
|
+
context.Registry.TryGetValue(original, out var originalHit))
|
|
1011
|
+
{
|
|
1012
|
+
return originalHit;
|
|
1013
|
+
}
|
|
1014
|
+
|
|
1015
|
+
return null;
|
|
1016
|
+
}
|
|
1017
|
+
|
|
1018
|
+
private static void EmitCall(CallContext context, InvocationExpressionSyntax invocation, NodeRecord? caller)
|
|
1019
|
+
{
|
|
1020
|
+
if (caller is null)
|
|
1021
|
+
{
|
|
1022
|
+
// Çağıran bağlamı modellenmeyen çağrılar (top-level ifadeler,
|
|
1023
|
+
// alan başlatıcıları) bu dilimde CALLS kenarı üretmez (TS
|
|
1024
|
+
// adapter'daki "modül üstü çağrılar" kuralıyla aynı).
|
|
1025
|
+
return;
|
|
1026
|
+
}
|
|
1027
|
+
|
|
1028
|
+
var expressionText = invocation.Expression.ToString().Trim();
|
|
1029
|
+
var info = context.Model.GetSymbolInfo(invocation);
|
|
1030
|
+
|
|
1031
|
+
if (info.Symbol is null && info.CandidateSymbols.Length > 0)
|
|
1032
|
+
{
|
|
1033
|
+
EmitUnresolvedCall(context, caller, invocation, expressionText, new AmbiguityOut
|
|
1034
|
+
{
|
|
1035
|
+
Candidates = info.CandidateSymbols.Select(s => s.ToDisplayString()).ToList(),
|
|
1036
|
+
Reason = "Aşırı yükleme belirsizliği; semantik model tek aday seçemedi.",
|
|
1037
|
+
});
|
|
1038
|
+
return;
|
|
1039
|
+
}
|
|
1040
|
+
|
|
1041
|
+
if (info.Symbol is null)
|
|
1042
|
+
{
|
|
1043
|
+
EmitUnresolvedCall(context, caller, invocation, expressionText, null);
|
|
1044
|
+
return;
|
|
1045
|
+
}
|
|
1046
|
+
|
|
1047
|
+
var target = ResolveTargetRecord(context, info.Symbol);
|
|
1048
|
+
if (target is not null)
|
|
1049
|
+
{
|
|
1050
|
+
context.Assembler.AddEdge("CALLS", caller, target, "verified",
|
|
1051
|
+
SpanEvidence(context.Entry, invocation, "semantic-symbol",
|
|
1052
|
+
$"CALLS: {caller.Node.QualifiedName} içindeki çağrı ifadesi Roslyn semantic model ile {target.Node.QualifiedName} sembolüne çözümlendi (verified)."),
|
|
1053
|
+
null);
|
|
1054
|
+
return;
|
|
1055
|
+
}
|
|
1056
|
+
|
|
1057
|
+
// Semantik çözümleme var ama hedef analiz setinin dışında: açık
|
|
1058
|
+
// UnknownExternal node + checker dayanaklı verified kenar (TS
|
|
1059
|
+
// adapter ile aynı kural).
|
|
1060
|
+
var externalName = ExternalQualifiedName(info.Symbol);
|
|
1061
|
+
var external = context.Assembler.EnsureExternal(externalName);
|
|
1062
|
+
context.Assembler.AddEdge("CALLS", caller, external, "verified",
|
|
1063
|
+
SpanEvidence(context.Entry, invocation, "semantic-symbol",
|
|
1064
|
+
$"CALLS: {caller.Node.QualifiedName} içindeki çağrı analiz seti dışındaki {externalName} sembolüne çözümlendi; dış kaynak açık UnknownExternal node olarak temsil edildi."),
|
|
1065
|
+
null);
|
|
1066
|
+
}
|
|
1067
|
+
|
|
1068
|
+
private static void EmitCreation(CallContext context, SyntaxNode creation, NodeRecord? caller)
|
|
1069
|
+
{
|
|
1070
|
+
if (caller is null)
|
|
1071
|
+
{
|
|
1072
|
+
return;
|
|
1073
|
+
}
|
|
1074
|
+
|
|
1075
|
+
var expressionText = creation.ToString().Trim();
|
|
1076
|
+
var info = context.Model.GetSymbolInfo(creation);
|
|
1077
|
+
|
|
1078
|
+
if (info.Symbol is null && info.CandidateSymbols.Length > 0)
|
|
1079
|
+
{
|
|
1080
|
+
EmitUnresolvedCall(context, caller, creation, expressionText, new AmbiguityOut
|
|
1081
|
+
{
|
|
1082
|
+
Candidates = info.CandidateSymbols.Select(s => s.ToDisplayString()).ToList(),
|
|
1083
|
+
Reason = "Kurucu aşırı yükleme belirsizliği; semantik model tek aday seçemedi.",
|
|
1084
|
+
});
|
|
1085
|
+
return;
|
|
1086
|
+
}
|
|
1087
|
+
|
|
1088
|
+
var ctor = info.Symbol as IMethodSymbol;
|
|
1089
|
+
var containingType = ctor?.ContainingType;
|
|
1090
|
+
if (containingType is null)
|
|
1091
|
+
{
|
|
1092
|
+
EmitUnresolvedCall(context, caller, creation, expressionText, null);
|
|
1093
|
+
return;
|
|
1094
|
+
}
|
|
1095
|
+
|
|
1096
|
+
// new X() hedefi TS adapter kuralıyla kurulan SINIFIN kendisidir.
|
|
1097
|
+
var target = ResolveTargetRecord(context, containingType);
|
|
1098
|
+
if (target is not null)
|
|
1099
|
+
{
|
|
1100
|
+
context.Assembler.AddEdge("CALLS", caller, target, "verified",
|
|
1101
|
+
SpanEvidence(context.Entry, creation, "semantic-symbol",
|
|
1102
|
+
$"CALLS: {caller.Node.QualifiedName} içindeki nesne oluşturma {target.Node.QualifiedName} sınıfına çözümlendi (semantic-symbol, verified)."),
|
|
1103
|
+
null);
|
|
1104
|
+
return;
|
|
1105
|
+
}
|
|
1106
|
+
|
|
1107
|
+
var externalName = ExternalQualifiedName(containingType);
|
|
1108
|
+
var external = context.Assembler.EnsureExternal(externalName);
|
|
1109
|
+
context.Assembler.AddEdge("CALLS", caller, external, "verified",
|
|
1110
|
+
SpanEvidence(context.Entry, creation, "semantic-symbol",
|
|
1111
|
+
$"CALLS: {caller.Node.QualifiedName} içindeki nesne oluşturma analiz seti dışındaki {externalName} sınıfına çözümlendi; dış kaynak açık UnknownExternal node olarak temsil edildi."),
|
|
1112
|
+
null);
|
|
1113
|
+
}
|
|
1114
|
+
|
|
1115
|
+
private static void EmitUnresolvedCall(
|
|
1116
|
+
CallContext context,
|
|
1117
|
+
NodeRecord caller,
|
|
1118
|
+
SyntaxNode callSite,
|
|
1119
|
+
string callText,
|
|
1120
|
+
AmbiguityOut? ambiguity)
|
|
1121
|
+
{
|
|
1122
|
+
var target = context.Assembler.EnsureExternal(callText);
|
|
1123
|
+
context.Assembler.AddEdge("CALLS", caller, target, "unresolved",
|
|
1124
|
+
SpanEvidence(context.Entry, callSite, "ast-span",
|
|
1125
|
+
$"CALLS: {caller.Node.QualifiedName} içindeki '{callText}' çağrısı çözümlenemedi; uydurma hedef yerine açık UnknownExternal node üzerinde unresolved işaretlendi."),
|
|
1126
|
+
ambiguity);
|
|
1127
|
+
context.Assembler.AddWarning(
|
|
1128
|
+
$"CALLS çözümlenemedi: {context.Entry.RelativePath} '{callText}' (unresolved, UnknownExternal node üretildi)");
|
|
1129
|
+
}
|
|
1130
|
+
|
|
1131
|
+
private static NodeRecord? ResolveTargetRecord(CallContext context, ISymbol symbol)
|
|
1132
|
+
{
|
|
1133
|
+
var hit = RegistryLookup(context, symbol);
|
|
1134
|
+
if (hit is not null)
|
|
1135
|
+
{
|
|
1136
|
+
return hit;
|
|
1137
|
+
}
|
|
1138
|
+
|
|
1139
|
+
var declaringReference = symbol.DeclaringSyntaxReferences.FirstOrDefault();
|
|
1140
|
+
if (declaringReference is null)
|
|
1141
|
+
{
|
|
1142
|
+
return null; // metadata sembolü — set dışı
|
|
1143
|
+
}
|
|
1144
|
+
|
|
1145
|
+
// Analiz setinde bildirilmiş ama registry'de yok: bildirimden türet.
|
|
1146
|
+
return DeriveRecord(context, symbol);
|
|
1147
|
+
}
|
|
1148
|
+
|
|
1149
|
+
private static NodeRecord? DeriveRecord(CallContext context, ISymbol symbol)
|
|
1150
|
+
{
|
|
1151
|
+
string kind;
|
|
1152
|
+
string qualifiedName;
|
|
1153
|
+
|
|
1154
|
+
switch (symbol)
|
|
1155
|
+
{
|
|
1156
|
+
case IMethodSymbol method when method.MethodKind is MethodKind.Constructor or MethodKind.StaticConstructor:
|
|
1157
|
+
return method.ContainingType is null ? null : DeriveRecord(context, method.ContainingType);
|
|
1158
|
+
|
|
1159
|
+
case IMethodSymbol method when method.MethodKind == MethodKind.LocalFunction:
|
|
1160
|
+
kind = "Function";
|
|
1161
|
+
qualifiedName = $"{method.ContainingType?.ToDisplayString() ?? "Program"}.{method.Name}";
|
|
1162
|
+
break;
|
|
1163
|
+
|
|
1164
|
+
case IMethodSymbol method:
|
|
1165
|
+
kind = "Method";
|
|
1166
|
+
qualifiedName = $"{TypeQualifiedName(method.ContainingType)}.{method.Name}";
|
|
1167
|
+
break;
|
|
1168
|
+
|
|
1169
|
+
case IPropertySymbol property:
|
|
1170
|
+
kind = "Method"; // property → Method yaklaşımı (PROTOCOL.md)
|
|
1171
|
+
qualifiedName = $"{TypeQualifiedName(property.ContainingType)}.{property.Name}";
|
|
1172
|
+
break;
|
|
1173
|
+
|
|
1174
|
+
case INamedTypeSymbol type:
|
|
1175
|
+
kind = CatalogKindOf(type);
|
|
1176
|
+
qualifiedName = TypeQualifiedName(type);
|
|
1177
|
+
break;
|
|
1178
|
+
|
|
1179
|
+
default:
|
|
1180
|
+
return null;
|
|
1181
|
+
}
|
|
1182
|
+
|
|
1183
|
+
var relativePath = RelativePathOfDeclaration(context, symbol);
|
|
1184
|
+
return context.Assembler.EnsureNode(kind, qualifiedName, relativePath, null);
|
|
1185
|
+
}
|
|
1186
|
+
|
|
1187
|
+
private static string? RelativePathOfDeclaration(CallContext context, ISymbol symbol)
|
|
1188
|
+
{
|
|
1189
|
+
foreach (var reference in symbol.DeclaringSyntaxReferences)
|
|
1190
|
+
{
|
|
1191
|
+
foreach (var entry in context.Entries)
|
|
1192
|
+
{
|
|
1193
|
+
if (entry.Tree.Equals(reference.SyntaxTree))
|
|
1194
|
+
{
|
|
1195
|
+
return entry.RelativePath;
|
|
1196
|
+
}
|
|
1197
|
+
}
|
|
1198
|
+
}
|
|
1199
|
+
|
|
1200
|
+
return null;
|
|
1201
|
+
}
|
|
1202
|
+
|
|
1203
|
+
private static string CatalogKindOf(INamedTypeSymbol type) => type.TypeKind switch
|
|
1204
|
+
{
|
|
1205
|
+
TypeKind.Interface => "Interface",
|
|
1206
|
+
TypeKind.Struct or TypeKind.Enum => "Type",
|
|
1207
|
+
TypeKind.Class when type.IsRecord && type.IsValueType => "Type",
|
|
1208
|
+
TypeKind.Class => "Class",
|
|
1209
|
+
_ => "Type",
|
|
1210
|
+
};
|
|
1211
|
+
|
|
1212
|
+
private static string TypeQualifiedName(INamedTypeSymbol? type)
|
|
1213
|
+
{
|
|
1214
|
+
if (type is null)
|
|
1215
|
+
{
|
|
1216
|
+
return string.Empty;
|
|
1217
|
+
}
|
|
1218
|
+
|
|
1219
|
+
var owner = type.ContainingType is null
|
|
1220
|
+
? type.Name
|
|
1221
|
+
: $"{TypeQualifiedName(type.ContainingType)}.{type.Name}";
|
|
1222
|
+
var ns = type.ContainingNamespace;
|
|
1223
|
+
return ns is { IsGlobalNamespace: false } ? $"{ns.ToDisplayString()}.{owner}" : owner;
|
|
1224
|
+
}
|
|
1225
|
+
|
|
1226
|
+
private static string ExternalQualifiedName(ISymbol symbol)
|
|
1227
|
+
{
|
|
1228
|
+
var ns = symbol.ContainingNamespace;
|
|
1229
|
+
var nsPrefix = ns is { IsGlobalNamespace: false } ? $"{ns.ToDisplayString()}." : string.Empty;
|
|
1230
|
+
return symbol switch
|
|
1231
|
+
{
|
|
1232
|
+
IMethodSymbol method => $"{nsPrefix}{TypeQualifiedName(method.ContainingType)}.{method.OriginalDefinition.Name}",
|
|
1233
|
+
IPropertySymbol property => $"{nsPrefix}{TypeQualifiedName(property.ContainingType)}.{property.OriginalDefinition.Name}",
|
|
1234
|
+
INamedTypeSymbol type => $"{nsPrefix}{TypeQualifiedName(type)}",
|
|
1235
|
+
_ => $"{nsPrefix}{symbol.Name}",
|
|
1236
|
+
};
|
|
1237
|
+
}
|
|
1238
|
+
|
|
1239
|
+
/* ------------------------------------------------------------------ */
|
|
1240
|
+
/* Faz 2a: minimal API rotaları */
|
|
1241
|
+
/* ------------------------------------------------------------------ */
|
|
1242
|
+
|
|
1243
|
+
private static void TryMinimalApiRoute(CallContext context, InvocationExpressionSyntax invocation, NodeRecord? caller)
|
|
1244
|
+
{
|
|
1245
|
+
var name = invocation.Expression switch
|
|
1246
|
+
{
|
|
1247
|
+
MemberAccessExpressionSyntax memberAccess => memberAccess.Name.Identifier.ValueText,
|
|
1248
|
+
IdentifierNameSyntax identifier => identifier.Identifier.ValueText,
|
|
1249
|
+
GenericNameSyntax generic => generic.Identifier.ValueText,
|
|
1250
|
+
_ => null,
|
|
1251
|
+
};
|
|
1252
|
+
|
|
1253
|
+
var isMethods = name == "MapMethods";
|
|
1254
|
+
if (name is null || (!isMethods && !MinimalApiMapNames.Contains(name)))
|
|
1255
|
+
{
|
|
1256
|
+
return;
|
|
1257
|
+
}
|
|
1258
|
+
|
|
1259
|
+
var assembler = context.Assembler;
|
|
1260
|
+
var info = context.Model.GetSymbolInfo(invocation.Expression);
|
|
1261
|
+
// MapGet/MapPost aile birçok overload taşır; semantik kapı, çözülen
|
|
1262
|
+
// veya aday sembollerin içerici tipini denetler (probe kanıtı:
|
|
1263
|
+
// method-group argümanı Symbol=null + candidate döner).
|
|
1264
|
+
var mapSymbols = info.Symbol is null
|
|
1265
|
+
? info.CandidateSymbols
|
|
1266
|
+
: [info.Symbol];
|
|
1267
|
+
var semanticBasis = mapSymbols
|
|
1268
|
+
.OfType<IMethodSymbol>()
|
|
1269
|
+
.Any(methodSymbol => methodSymbol.ContainingType.ToDisplayString() == EndpointRouteBuilderExtensions);
|
|
1270
|
+
|
|
1271
|
+
var arguments = invocation.ArgumentList.Arguments;
|
|
1272
|
+
if (arguments.Count == 0)
|
|
1273
|
+
{
|
|
1274
|
+
return;
|
|
1275
|
+
}
|
|
1276
|
+
|
|
1277
|
+
var pathValue = context.Model.GetConstantValue(arguments[0].Expression);
|
|
1278
|
+
if (!pathValue.HasValue || pathValue.Value is not string path)
|
|
1279
|
+
{
|
|
1280
|
+
assembler.AddWarning(
|
|
1281
|
+
$"Minimal API rotası modellenmedi: {context.Entry.RelativePath} '{name}(...)' — rota kalıbı sabit string değil");
|
|
1282
|
+
return;
|
|
1283
|
+
}
|
|
1284
|
+
|
|
1285
|
+
List<string> verbs;
|
|
1286
|
+
if (isMethods)
|
|
1287
|
+
{
|
|
1288
|
+
verbs = arguments.Count > 1 ? ParseVerbsArgument(context, arguments[1].Expression) : new List<string>();
|
|
1289
|
+
if (verbs.Count == 0)
|
|
1290
|
+
{
|
|
1291
|
+
assembler.AddWarning(
|
|
1292
|
+
$"Minimal API rotası modellenmedi: {context.Entry.RelativePath} 'MapMethods(...)' — HTTP fiilleri sabit string dizisi değil");
|
|
1293
|
+
return;
|
|
1294
|
+
}
|
|
1295
|
+
}
|
|
1296
|
+
else
|
|
1297
|
+
{
|
|
1298
|
+
verbs = new List<string> { name.Substring(3).ToUpperInvariant() };
|
|
1299
|
+
}
|
|
1300
|
+
|
|
1301
|
+
foreach (var verb in verbs)
|
|
1302
|
+
{
|
|
1303
|
+
var endpoint = assembler.EnsureNode(
|
|
1304
|
+
"Endpoint",
|
|
1305
|
+
$"{verb} {path}",
|
|
1306
|
+
context.Entry.RelativePath,
|
|
1307
|
+
new Dictionary<string, object> { ["method"] = verb, ["path"] = path });
|
|
1308
|
+
|
|
1309
|
+
var handlerRecord = ResolveHandler(context, arguments);
|
|
1310
|
+
if (handlerRecord is null)
|
|
1311
|
+
{
|
|
1312
|
+
continue; // endpoint node korunur, uydurma kenar üretilmez
|
|
1313
|
+
}
|
|
1314
|
+
|
|
1315
|
+
var basisText = semanticBasis
|
|
1316
|
+
? "EndpointRouteBuilderExtensions uzantı metodu semantic model ile doğrulandı"
|
|
1317
|
+
: "bilinen ad kuralı (semantic model uzantı metodunu çözümlemedi)";
|
|
1318
|
+
var resolution = semanticBasis ? "verified" : "heuristic";
|
|
1319
|
+
AmbiguityOut? ambiguity = semanticBasis
|
|
1320
|
+
? null
|
|
1321
|
+
: new AmbiguityOut
|
|
1322
|
+
{
|
|
1323
|
+
Candidates = new List<string> { name },
|
|
1324
|
+
Reason = "Minimal API kayıt metodu ad kuralı ile tanındı; Microsoft.AspNetCore.Builder semantiği çözümlenemedi.",
|
|
1325
|
+
};
|
|
1326
|
+
|
|
1327
|
+
assembler.AddEdge("ROUTES_TO", endpoint, handlerRecord, resolution,
|
|
1328
|
+
SpanEvidence(context.Entry, invocation, "route-attribute",
|
|
1329
|
+
$"ROUTES_TO: '{verb} {path}' minimal API kaydı ({basisText}) {handlerRecord.Node.QualifiedName} handler'ına çözümlendi."),
|
|
1330
|
+
ambiguity);
|
|
1331
|
+
}
|
|
1332
|
+
}
|
|
1333
|
+
|
|
1334
|
+
private static List<string> ParseVerbsArgument(CallContext context, ExpressionSyntax expression)
|
|
1335
|
+
{
|
|
1336
|
+
IEnumerable<ExpressionSyntax>? initializers = expression switch
|
|
1337
|
+
{
|
|
1338
|
+
ImplicitArrayCreationExpressionSyntax implicitArray => implicitArray.Initializer?.Expressions,
|
|
1339
|
+
ArrayCreationExpressionSyntax arrayCreation => arrayCreation.Initializer?.Expressions,
|
|
1340
|
+
CollectionExpressionSyntax collection => collection.Elements
|
|
1341
|
+
.OfType<ExpressionElementSyntax>()
|
|
1342
|
+
.Select(element => element.Expression),
|
|
1343
|
+
_ => null,
|
|
1344
|
+
};
|
|
1345
|
+
|
|
1346
|
+
var verbs = new List<string>();
|
|
1347
|
+
if (initializers is null)
|
|
1348
|
+
{
|
|
1349
|
+
return verbs;
|
|
1350
|
+
}
|
|
1351
|
+
|
|
1352
|
+
foreach (var initializer in initializers)
|
|
1353
|
+
{
|
|
1354
|
+
var value = context.Model.GetConstantValue(initializer);
|
|
1355
|
+
if (value.HasValue && value.Value is string verb)
|
|
1356
|
+
{
|
|
1357
|
+
verbs.Add(verb.ToUpperInvariant());
|
|
1358
|
+
}
|
|
1359
|
+
}
|
|
1360
|
+
|
|
1361
|
+
return verbs;
|
|
1362
|
+
}
|
|
1363
|
+
|
|
1364
|
+
private static NodeRecord? ResolveHandler(CallContext context, SeparatedSyntaxList<ArgumentSyntax> arguments)
|
|
1365
|
+
{
|
|
1366
|
+
foreach (var argument in arguments.Skip(1))
|
|
1367
|
+
{
|
|
1368
|
+
var expression = argument.Expression;
|
|
1369
|
+
if (expression is AnonymousFunctionExpressionSyntax)
|
|
1370
|
+
{
|
|
1371
|
+
context.Assembler.AddWarning(
|
|
1372
|
+
$"Route handler modellenmedi: {context.Entry.RelativePath} minimal API kaydı — inline/anonymous handler unsupportedConstructs kapsamında");
|
|
1373
|
+
return null;
|
|
1374
|
+
}
|
|
1375
|
+
|
|
1376
|
+
if (expression is not (IdentifierNameSyntax or MemberAccessExpressionSyntax))
|
|
1377
|
+
{
|
|
1378
|
+
continue;
|
|
1379
|
+
}
|
|
1380
|
+
|
|
1381
|
+
var info = context.Model.GetSymbolInfo(expression);
|
|
1382
|
+
var symbol = info.Symbol
|
|
1383
|
+
?? (info.CandidateSymbols.Length == 1 ? info.CandidateSymbols[0] : null);
|
|
1384
|
+
if (symbol is null)
|
|
1385
|
+
{
|
|
1386
|
+
// Çok adaylı method-group: analiz setindeki aday tercih edilir
|
|
1387
|
+
// (ör. top-level local function, tek adayda olduğu gibi).
|
|
1388
|
+
foreach (var candidate in info.CandidateSymbols)
|
|
1389
|
+
{
|
|
1390
|
+
var candidateRecord = ResolveTargetRecord(context, candidate);
|
|
1391
|
+
if (candidateRecord is not null)
|
|
1392
|
+
{
|
|
1393
|
+
return candidateRecord;
|
|
1394
|
+
}
|
|
1395
|
+
}
|
|
1396
|
+
|
|
1397
|
+
context.Assembler.AddWarning(
|
|
1398
|
+
$"ROUTES_TO çözümlenemedi: {context.Entry.RelativePath} minimal API handler sembolü bulunamadı ('{expression}')");
|
|
1399
|
+
return null;
|
|
1400
|
+
}
|
|
1401
|
+
|
|
1402
|
+
var record = ResolveTargetRecord(context, symbol);
|
|
1403
|
+
if (record is null)
|
|
1404
|
+
{
|
|
1405
|
+
// Handler analiz seti dışında: açık external node (TS adapter kuralı).
|
|
1406
|
+
return context.Assembler.EnsureExternal(ExternalQualifiedName(symbol));
|
|
1407
|
+
}
|
|
1408
|
+
|
|
1409
|
+
return record;
|
|
1410
|
+
}
|
|
1411
|
+
|
|
1412
|
+
return null;
|
|
1413
|
+
}
|
|
1414
|
+
|
|
1415
|
+
/* ------------------------------------------------------------------ */
|
|
1416
|
+
/* Faz 3: controller öznitelik rotaları */
|
|
1417
|
+
/* ------------------------------------------------------------------ */
|
|
1418
|
+
|
|
1419
|
+
private static void ExtractControllerRoutes(
|
|
1420
|
+
SourceEntry entry,
|
|
1421
|
+
ControllerInfo controller,
|
|
1422
|
+
SemanticModel model,
|
|
1423
|
+
GraphAssembler assembler,
|
|
1424
|
+
Dictionary<ISymbol, NodeRecord> registry)
|
|
1425
|
+
{
|
|
1426
|
+
var declaration = controller.Declaration;
|
|
1427
|
+
var classSymbol = model.GetDeclaredSymbol(declaration);
|
|
1428
|
+
if (!IsController(classSymbol, controller.QualifiedName))
|
|
1429
|
+
{
|
|
1430
|
+
return;
|
|
1431
|
+
}
|
|
1432
|
+
|
|
1433
|
+
var classRoute = FindAttribute(declaration.AttributeLists, model,
|
|
1434
|
+
semanticDisplay: $"{AspNetMvcNamespace}.RouteAttribute",
|
|
1435
|
+
simpleNames: new HashSet<string>(StringComparer.OrdinalIgnoreCase) { "Route", "RouteAttribute" });
|
|
1436
|
+
|
|
1437
|
+
if (classRoute is null || classRoute.Template is null)
|
|
1438
|
+
{
|
|
1439
|
+
assembler.AddWarning(
|
|
1440
|
+
$"Controller rotası modellenmedi: {controller.QualifiedName} — [Route] özniteliği yok; convention routing kalıbı statik olarak belirlenemez (unsupportedConstructs: convention-routing-templates)");
|
|
1441
|
+
return;
|
|
1442
|
+
}
|
|
1443
|
+
|
|
1444
|
+
var controllerName = declaration.Identifier.ValueText;
|
|
1445
|
+
foreach (var method in declaration.Members.OfType<MethodDeclarationSyntax>())
|
|
1446
|
+
{
|
|
1447
|
+
foreach (var verbAttribute in FindVerbAttributes(method.AttributeLists, model))
|
|
1448
|
+
{
|
|
1449
|
+
var methodRoute = FindAttribute(method.AttributeLists, model,
|
|
1450
|
+
semanticDisplay: $"{AspNetMvcNamespace}.RouteAttribute",
|
|
1451
|
+
simpleNames: new HashSet<string>(StringComparer.OrdinalIgnoreCase) { "Route", "RouteAttribute" });
|
|
1452
|
+
|
|
1453
|
+
var template = ComposeTemplate(
|
|
1454
|
+
classRoute.Template,
|
|
1455
|
+
methodRoute?.Template ?? verbAttribute.Template ?? string.Empty,
|
|
1456
|
+
controllerName,
|
|
1457
|
+
method.Identifier.ValueText);
|
|
1458
|
+
|
|
1459
|
+
var verb = verbAttribute.Verb ?? string.Empty;
|
|
1460
|
+
var endpoint = assembler.EnsureNode(
|
|
1461
|
+
"Endpoint",
|
|
1462
|
+
$"{verb} {template}",
|
|
1463
|
+
entry.RelativePath,
|
|
1464
|
+
new Dictionary<string, object> { ["method"] = verb, ["path"] = template });
|
|
1465
|
+
|
|
1466
|
+
var actionSymbol = model.GetDeclaredSymbol(method);
|
|
1467
|
+
var actionRecord = actionSymbol is null ? null : RegistryLookupPlain(registry, actionSymbol);
|
|
1468
|
+
if (actionRecord is null)
|
|
1469
|
+
{
|
|
1470
|
+
assembler.AddWarning(
|
|
1471
|
+
$"ROUTES_TO çözümlenemedi: {controller.QualifiedName}.{method.Identifier.ValueText} action kaydı registry'de yok");
|
|
1472
|
+
continue;
|
|
1473
|
+
}
|
|
1474
|
+
|
|
1475
|
+
var allSemantic = classRoute.Semantic && verbAttribute.Semantic && (methodRoute is null || methodRoute.Semantic);
|
|
1476
|
+
var resolution = allSemantic ? "verified" : "heuristic";
|
|
1477
|
+
AmbiguityOut? ambiguity = null;
|
|
1478
|
+
if (!allSemantic)
|
|
1479
|
+
{
|
|
1480
|
+
var unresolvedNames = new List<string>();
|
|
1481
|
+
if (!classRoute.Semantic)
|
|
1482
|
+
{
|
|
1483
|
+
unresolvedNames.Add(classRoute.SimpleName);
|
|
1484
|
+
}
|
|
1485
|
+
|
|
1486
|
+
if (!verbAttribute.Semantic)
|
|
1487
|
+
{
|
|
1488
|
+
unresolvedNames.Add(verbAttribute.SimpleName);
|
|
1489
|
+
}
|
|
1490
|
+
|
|
1491
|
+
if (methodRoute is { Semantic: false })
|
|
1492
|
+
{
|
|
1493
|
+
unresolvedNames.Add(methodRoute.SimpleName);
|
|
1494
|
+
}
|
|
1495
|
+
|
|
1496
|
+
ambiguity = new AmbiguityOut
|
|
1497
|
+
{
|
|
1498
|
+
Candidates = unresolvedNames,
|
|
1499
|
+
Reason = "ASP.NET Core öznitelik tipleri semantic model ile Microsoft.AspNetCore.Mvc köküne çözümlenemedi; bilinen ad kuralı uygulandı (TŞ §8 heuristic).",
|
|
1500
|
+
};
|
|
1501
|
+
}
|
|
1502
|
+
|
|
1503
|
+
var basisText = allSemantic
|
|
1504
|
+
? "öznitelik tipleri semantic model ile Microsoft.AspNetCore.Mvc köküne çözümlendi"
|
|
1505
|
+
: "bilinen ad kuralı (semantic model öznitelik tipini çözümlemedi)";
|
|
1506
|
+
|
|
1507
|
+
assembler.AddEdge("ROUTES_TO", endpoint, actionRecord, resolution,
|
|
1508
|
+
SpanEvidence(entry, verbAttribute.Node, "route-attribute",
|
|
1509
|
+
$"ROUTES_TO: '{verbAttribute.Verb} {template}' controller route kaydı ({basisText}) {actionRecord.Node.QualifiedName} action'ına çözümlendi."),
|
|
1510
|
+
ambiguity);
|
|
1511
|
+
}
|
|
1512
|
+
}
|
|
1513
|
+
}
|
|
1514
|
+
|
|
1515
|
+
private static NodeRecord? RegistryLookupPlain(Dictionary<ISymbol, NodeRecord> registry, ISymbol symbol)
|
|
1516
|
+
{
|
|
1517
|
+
if (registry.TryGetValue(symbol, out var hit))
|
|
1518
|
+
{
|
|
1519
|
+
return hit;
|
|
1520
|
+
}
|
|
1521
|
+
|
|
1522
|
+
var original = symbol.OriginalDefinition;
|
|
1523
|
+
return !SymbolEqualityComparer.Default.Equals(original, symbol) && registry.TryGetValue(original, out var originalHit)
|
|
1524
|
+
? originalHit
|
|
1525
|
+
: null;
|
|
1526
|
+
}
|
|
1527
|
+
|
|
1528
|
+
private static bool IsController(INamedTypeSymbol? classSymbol, string qualifiedName)
|
|
1529
|
+
{
|
|
1530
|
+
if (qualifiedName.EndsWith("Controller", StringComparison.Ordinal))
|
|
1531
|
+
{
|
|
1532
|
+
return true;
|
|
1533
|
+
}
|
|
1534
|
+
|
|
1535
|
+
var baseType = classSymbol?.BaseType;
|
|
1536
|
+
while (baseType is not null)
|
|
1537
|
+
{
|
|
1538
|
+
var display = baseType.OriginalDefinition.ToDisplayString();
|
|
1539
|
+
if (display is "Microsoft.AspNetCore.Mvc.ControllerBase" or "Microsoft.AspNetCore.Mvc.Controller")
|
|
1540
|
+
{
|
|
1541
|
+
return true;
|
|
1542
|
+
}
|
|
1543
|
+
|
|
1544
|
+
baseType = baseType.BaseType;
|
|
1545
|
+
}
|
|
1546
|
+
|
|
1547
|
+
return false;
|
|
1548
|
+
}
|
|
1549
|
+
|
|
1550
|
+
private static List<AttributeMatch> FindVerbAttributes(SyntaxList<AttributeListSyntax> attributeLists, SemanticModel model)
|
|
1551
|
+
{
|
|
1552
|
+
var matches = new List<AttributeMatch>();
|
|
1553
|
+
foreach (var attribute in attributeLists.SelectMany(list => list.Attributes))
|
|
1554
|
+
{
|
|
1555
|
+
var simpleName = AttributeSimpleName(attribute.Name);
|
|
1556
|
+
if (!VerbAttributeNames.TryGetValue(simpleName, out var verb))
|
|
1557
|
+
{
|
|
1558
|
+
continue;
|
|
1559
|
+
}
|
|
1560
|
+
|
|
1561
|
+
var semantic = IsAspNetMvcAttribute(attribute, model, $"{AspNetMvcNamespace}.{simpleName}Attribute");
|
|
1562
|
+
var template = FirstPositionalConstantString(attribute, model);
|
|
1563
|
+
matches.Add(new AttributeMatch(attribute, simpleName, semantic, template, verb));
|
|
1564
|
+
}
|
|
1565
|
+
|
|
1566
|
+
return matches;
|
|
1567
|
+
}
|
|
1568
|
+
|
|
1569
|
+
private static AttributeMatch? FindAttribute(
|
|
1570
|
+
SyntaxList<AttributeListSyntax> attributeLists,
|
|
1571
|
+
SemanticModel model,
|
|
1572
|
+
string semanticDisplay,
|
|
1573
|
+
HashSet<string> simpleNames)
|
|
1574
|
+
{
|
|
1575
|
+
foreach (var attribute in attributeLists.SelectMany(list => list.Attributes))
|
|
1576
|
+
{
|
|
1577
|
+
var simpleName = AttributeSimpleName(attribute.Name);
|
|
1578
|
+
if (!simpleNames.Contains(simpleName))
|
|
1579
|
+
{
|
|
1580
|
+
continue;
|
|
1581
|
+
}
|
|
1582
|
+
|
|
1583
|
+
var semantic = IsAspNetMvcAttribute(attribute, model, semanticDisplay);
|
|
1584
|
+
var template = FirstPositionalConstantString(attribute, model);
|
|
1585
|
+
return new AttributeMatch(attribute, simpleName, semantic, template, null);
|
|
1586
|
+
}
|
|
1587
|
+
|
|
1588
|
+
return null;
|
|
1589
|
+
}
|
|
1590
|
+
|
|
1591
|
+
private static string AttributeSimpleName(NameSyntax name) => name switch
|
|
1592
|
+
{
|
|
1593
|
+
SimpleNameSyntax simple => simple.Identifier.ValueText,
|
|
1594
|
+
QualifiedNameSyntax qualified => qualified.Right.Identifier.ValueText,
|
|
1595
|
+
AliasQualifiedNameSyntax alias => alias.Name.Identifier.ValueText,
|
|
1596
|
+
_ => name.ToString(),
|
|
1597
|
+
};
|
|
1598
|
+
|
|
1599
|
+
private static bool IsAspNetMvcAttribute(AttributeSyntax attribute, SemanticModel model, string expectedDisplay)
|
|
1600
|
+
{
|
|
1601
|
+
var info = model.GetSymbolInfo(attribute);
|
|
1602
|
+
return info.Symbol is IMethodSymbol ctor &&
|
|
1603
|
+
ctor.ContainingType.OriginalDefinition.ToDisplayString() == expectedDisplay;
|
|
1604
|
+
}
|
|
1605
|
+
|
|
1606
|
+
private static string? FirstPositionalConstantString(AttributeSyntax attribute, SemanticModel model)
|
|
1607
|
+
{
|
|
1608
|
+
var first = attribute.ArgumentList?.Arguments
|
|
1609
|
+
.FirstOrDefault(a => a.NameEquals is null && a.NameColon is null);
|
|
1610
|
+
if (first is null)
|
|
1611
|
+
{
|
|
1612
|
+
return null;
|
|
1613
|
+
}
|
|
1614
|
+
|
|
1615
|
+
var value = model.GetConstantValue(first.Expression);
|
|
1616
|
+
return value.HasValue && value.Value is string text ? text : null;
|
|
1617
|
+
}
|
|
1618
|
+
|
|
1619
|
+
private static string ComposeTemplate(string classTemplate, string methodTemplate, string controllerName, string actionName)
|
|
1620
|
+
{
|
|
1621
|
+
// ASP.NET kuralı: '~/...' metot kalıbı sınıf kalıbını EZER.
|
|
1622
|
+
if (methodTemplate.StartsWith("~/", StringComparison.Ordinal))
|
|
1623
|
+
{
|
|
1624
|
+
return NormalizeTemplate(methodTemplate.Substring(2), controllerName, actionName);
|
|
1625
|
+
}
|
|
1626
|
+
|
|
1627
|
+
var parts = new[] { classTemplate.Trim('/'), methodTemplate.Trim('/') }
|
|
1628
|
+
.Where(p => p.Length > 0);
|
|
1629
|
+
return NormalizeTemplate(string.Join("/", parts), controllerName, actionName);
|
|
1630
|
+
}
|
|
1631
|
+
|
|
1632
|
+
private static string NormalizeTemplate(string template, string controllerName, string actionName)
|
|
1633
|
+
{
|
|
1634
|
+
var controllerBaseName = controllerName.EndsWith("Controller", StringComparison.Ordinal)
|
|
1635
|
+
? controllerName.Substring(0, controllerName.Length - "Controller".Length)
|
|
1636
|
+
: controllerName;
|
|
1637
|
+
|
|
1638
|
+
var replaced = template
|
|
1639
|
+
.Replace("[controller]", controllerBaseName, StringComparison.OrdinalIgnoreCase)
|
|
1640
|
+
.Replace("[action]", actionName, StringComparison.OrdinalIgnoreCase);
|
|
1641
|
+
|
|
1642
|
+
// "[area]" bu dilimde çözülemez — olduğu gibi kalır (PROTOCOL.md belgeli).
|
|
1643
|
+
var collapsed = Regex.Replace(replaced, "/{2,}", "/").Trim('/');
|
|
1644
|
+
return "/" + collapsed;
|
|
1645
|
+
}
|
|
1646
|
+
|
|
1647
|
+
/* ------------------------------------------------------------------ */
|
|
1648
|
+
/* Kanıt */
|
|
1649
|
+
/* ------------------------------------------------------------------ */
|
|
1650
|
+
|
|
1651
|
+
private static EvidenceOut SpanEvidence(SourceEntry entry, SyntaxNode node, string kind, string rationale)
|
|
1652
|
+
{
|
|
1653
|
+
var lineSpan = entry.Tree.GetLineSpan(node.Span);
|
|
1654
|
+
return new EvidenceOut
|
|
1655
|
+
{
|
|
1656
|
+
Kind = kind,
|
|
1657
|
+
Span = new SpanOut
|
|
1658
|
+
{
|
|
1659
|
+
RelativePath = entry.RelativePath,
|
|
1660
|
+
StartLine = lineSpan.StartLinePosition.Line + 1,
|
|
1661
|
+
EndLine = lineSpan.EndLinePosition.Line + 1,
|
|
1662
|
+
SourceHash = entry.SourceHash,
|
|
1663
|
+
},
|
|
1664
|
+
AnalyzerId = ProtocolConstants.AnalyzerId,
|
|
1665
|
+
AnalyzerVersion = ProtocolConstants.AnalyzerVersion,
|
|
1666
|
+
Rationale = rationale,
|
|
1667
|
+
};
|
|
1668
|
+
}
|
|
1669
|
+
}
|