repodna-engine 1.0.1__py3-none-any.whl
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.
- repodna/__init__.py +3 -0
- repodna/__main__.py +10 -0
- repodna/advisor/__init__.py +17 -0
- repodna/advisor/engine.py +502 -0
- repodna/advisor/models.py +101 -0
- repodna/agent/__init__.py +87 -0
- repodna/agent/context.py +558 -0
- repodna/agent/deltas.py +198 -0
- repodna/agent/evidence.py +134 -0
- repodna/agent/expansion.py +447 -0
- repodna/agent/localization.py +518 -0
- repodna/agent/models.py +695 -0
- repodna/agent/patch.py +378 -0
- repodna/agent/postflight.py +278 -0
- repodna/agent/preflight.py +336 -0
- repodna/agent/ranking.py +318 -0
- repodna/agent/repo_map.py +392 -0
- repodna/agent/safety.py +111 -0
- repodna/agent/service.py +574 -0
- repodna/agent/sessions.py +264 -0
- repodna/agent/task.py +660 -0
- repodna/agent/telemetry.py +101 -0
- repodna/agent/token_budget.py +231 -0
- repodna/api/__init__.py +1 -0
- repodna/api/agent_routes.py +248 -0
- repodna/api/app.py +2904 -0
- repodna/benchmarks/__init__.py +29 -0
- repodna/benchmarks/baselines.py +126 -0
- repodna/benchmarks/budget_bench.py +162 -0
- repodna/benchmarks/engine.py +418 -0
- repodna/benchmarks/evaluator.py +310 -0
- repodna/benchmarks/metrics.py +206 -0
- repodna/benchmarks/models.py +194 -0
- repodna/benchmarks/scalability.py +166 -0
- repodna/brain/__init__.py +46 -0
- repodna/brain/evidence.py +276 -0
- repodna/brain/extractor.py +1207 -0
- repodna/brain/indexer.py +766 -0
- repodna/brain/models.py +275 -0
- repodna/brain/multilang_extractors.py +889 -0
- repodna/brain/retrieval.py +469 -0
- repodna/brain/tracer.py +203 -0
- repodna/cli/__init__.py +1 -0
- repodna/cli/__main__.py +10 -0
- repodna/cli/agent_cmd.py +228 -0
- repodna/cli/installer.py +590 -0
- repodna/cli/main.py +2173 -0
- repodna/cli/plugin_cmd.py +130 -0
- repodna/cli/workspace_cmd.py +211 -0
- repodna/context/__init__.py +9 -0
- repodna/context/builder.py +379 -0
- repodna/context/models.py +133 -0
- repodna/contract/__init__.py +39 -0
- repodna/contract/evaluator.py +318 -0
- repodna/contract/loader.py +260 -0
- repodna/contract/models.py +185 -0
- repodna/core/__init__.py +1 -0
- repodna/core/analyzer.py +1424 -0
- repodna/diff/__init__.py +35 -0
- repodna/diff/engine.py +332 -0
- repodna/diff/models.py +117 -0
- repodna/diff/snapshot.py +248 -0
- repodna/ecosystem/__init__.py +27 -0
- repodna/ecosystem/contracts.py +129 -0
- repodna/ecosystem/doctor.py +253 -0
- repodna/git_insights/__init__.py +1 -0
- repodna/git_insights/analyzer.py +273 -0
- repodna/graph/__init__.py +1 -0
- repodna/graph/engine.py +562 -0
- repodna/guardian/__init__.py +17 -0
- repodna/guardian/engine.py +369 -0
- repodna/guardian/models.py +104 -0
- repodna/history/__init__.py +40 -0
- repodna/history/cache.py +240 -0
- repodna/history/diff.py +394 -0
- repodna/history/engine.py +557 -0
- repodna/history/evidence.py +160 -0
- repodna/history/models.py +258 -0
- repodna/history/timeline.py +164 -0
- repodna/intelligence/__init__.py +33 -0
- repodna/intelligence/models.py +165 -0
- repodna/intelligence/service.py +570 -0
- repodna/live/__init__.py +94 -0
- repodna/live/alerts.py +443 -0
- repodna/live/coordinator.py +351 -0
- repodna/live/diff.py +444 -0
- repodna/live/events.py +471 -0
- repodna/live/filtering.py +329 -0
- repodna/live/history.py +637 -0
- repodna/live/models.py +505 -0
- repodna/live/observer.py +653 -0
- repodna/live/reconciliation.py +253 -0
- repodna/live/session.py +1547 -0
- repodna/mcp/__init__.py +5 -0
- repodna/mcp/__main__.py +6 -0
- repodna/mcp/agent_tools.py +258 -0
- repodna/mcp/server.py +3283 -0
- repodna/mcp/workspace_tools.py +200 -0
- repodna/parsers/__init__.py +13 -0
- repodna/parsers/base.py +126 -0
- repodna/parsers/capabilities.py +361 -0
- repodna/parsers/project_metadata.py +232 -0
- repodna/parsers/resolver.py +621 -0
- repodna/parsers/treesitter_parser.py +830 -0
- repodna/passport/__init__.py +64 -0
- repodna/passport/generator.py +546 -0
- repodna/passport/migrator.py +139 -0
- repodna/passport/models.py +224 -0
- repodna/passport/validator.py +143 -0
- repodna/performance/__init__.py +89 -0
- repodna/performance/cache.py +1584 -0
- repodna/performance/identity.py +341 -0
- repodna/performance/incremental.py +317 -0
- repodna/performance/models.py +157 -0
- repodna/performance/parallel.py +291 -0
- repodna/plugins/__init__.py +47 -0
- repodna/plugins/evaluator.py +334 -0
- repodna/plugins/models.py +113 -0
- repodna/plugins/validator.py +256 -0
- repodna/quality/__init__.py +91 -0
- repodna/quality/complexity.py +352 -0
- repodna/quality/config.py +159 -0
- repodna/quality/debt.py +73 -0
- repodna/quality/duplicates.py +330 -0
- repodna/quality/engine.py +282 -0
- repodna/quality/impact.py +198 -0
- repodna/quality/models.py +427 -0
- repodna/quality/rules.py +364 -0
- repodna/quality/sarif.py +107 -0
- repodna/quality/security_signals.py +278 -0
- repodna/quality/test_mapping.py +271 -0
- repodna/quality/unused.py +201 -0
- repodna/reports/__init__.py +1 -0
- repodna/reports/exporter.py +374 -0
- repodna/rules/__init__.py +1 -0
- repodna/rules/health.py +436 -0
- repodna/schemas/__init__.py +1 -0
- repodna/schemas/models.py +348 -0
- repodna/security/__init__.py +1 -0
- repodna/security/safe_yaml.py +81 -0
- repodna/security/validators.py +583 -0
- repodna/skills/__init__.py +0 -0
- repodna/skills/repodna/SKILL.md +59 -0
- repodna/skills/repodna/__init__.py +0 -0
- repodna/skills/repodna/examples/workflows.md +85 -0
- repodna/skills/repodna/references/architecture-rules.md +26 -0
- repodna/storage/__init__.py +1 -0
- repodna/storage/workspace.py +199 -0
- repodna/webui/__init__.py +1 -0
- repodna/webui/assets/DependencyGraph-km_Qo-nG.js +43 -0
- repodna/webui/assets/HealthReportView-WVL39aNO.js +1 -0
- repodna/webui/assets/index-ByZ5e5pe.js +506 -0
- repodna/webui/assets/index-CDj3e8hw.css +1 -0
- repodna/webui/index.html +21 -0
- repodna/workspace/__init__.py +131 -0
- repodna/workspace/compatibility.py +317 -0
- repodna/workspace/context.py +175 -0
- repodna/workspace/contracts.py +369 -0
- repodna/workspace/federation.py +411 -0
- repodna/workspace/identity.py +202 -0
- repodna/workspace/impact.py +111 -0
- repodna/workspace/manifest.py +266 -0
- repodna/workspace/models.py +461 -0
- repodna/workspace/packages.py +494 -0
- repodna/workspace/policies.py +142 -0
- repodna/workspace/services.py +238 -0
- repodna/workspace/topology.py +316 -0
- repodna_engine-1.0.1.dist-info/METADATA +129 -0
- repodna_engine-1.0.1.dist-info/RECORD +173 -0
- repodna_engine-1.0.1.dist-info/WHEEL +5 -0
- repodna_engine-1.0.1.dist-info/entry_points.txt +2 -0
- repodna_engine-1.0.1.dist-info/licenses/LICENSE +21 -0
- repodna_engine-1.0.1.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,889 @@
|
|
|
1
|
+
"""Deep Tree-sitter AST symbol, scope, and reference extractors for C#, Java, C, and C++."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import re
|
|
6
|
+
from typing import Any
|
|
7
|
+
|
|
8
|
+
from repodna.brain.evidence import extract_evidence_snippet
|
|
9
|
+
from repodna.brain.models import (
|
|
10
|
+
EvidenceReference,
|
|
11
|
+
EvidenceType,
|
|
12
|
+
ReferenceKind,
|
|
13
|
+
ResolutionStatus,
|
|
14
|
+
SymbolDefinition,
|
|
15
|
+
SymbolKind,
|
|
16
|
+
SymbolReference,
|
|
17
|
+
)
|
|
18
|
+
from repodna.parsers.treesitter_parser import (
|
|
19
|
+
_TS_PARSERS,
|
|
20
|
+
_extract_c_declarator_name,
|
|
21
|
+
_init_treesitter_parsers,
|
|
22
|
+
_node_text,
|
|
23
|
+
)
|
|
24
|
+
from repodna.schemas.models import LanguageSupportLevel
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def _extract_sig(lines: list[str], line_start: int) -> str:
|
|
28
|
+
if 1 <= line_start <= len(lines):
|
|
29
|
+
chunk = lines[line_start - 1 : min(len(lines), line_start + 2)]
|
|
30
|
+
sig = " ".join(ln.strip() for ln in chunk)
|
|
31
|
+
return sig[:157] + "..." if len(sig) > 160 else sig
|
|
32
|
+
return ""
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def _make_symbol_and_evidence(
|
|
36
|
+
*,
|
|
37
|
+
file_path: str,
|
|
38
|
+
content: str,
|
|
39
|
+
lines: list[str],
|
|
40
|
+
revision: str,
|
|
41
|
+
language: str,
|
|
42
|
+
support_lvl: LanguageSupportLevel,
|
|
43
|
+
name: str,
|
|
44
|
+
kind: SymbolKind,
|
|
45
|
+
node: Any,
|
|
46
|
+
container_name: str | None,
|
|
47
|
+
namespace_name: str | None,
|
|
48
|
+
visibility: str,
|
|
49
|
+
annotations: list[str],
|
|
50
|
+
is_exported: bool,
|
|
51
|
+
is_partial: bool = False,
|
|
52
|
+
is_override: bool = False,
|
|
53
|
+
has_syntax_error: bool = False,
|
|
54
|
+
sep: str = ".",
|
|
55
|
+
) -> tuple[SymbolDefinition, EvidenceReference]:
|
|
56
|
+
line_start = node.start_point[0] + 1
|
|
57
|
+
line_end = max(line_start, node.end_point[0] + 1)
|
|
58
|
+
col_start = node.start_point[1]
|
|
59
|
+
col_end = node.end_point[1]
|
|
60
|
+
|
|
61
|
+
q_parts = [p for p in (namespace_name, container_name, name) if p]
|
|
62
|
+
qualified = sep.join(q_parts) if q_parts else name
|
|
63
|
+
|
|
64
|
+
sym_id = SymbolDefinition.generate_id(file_path, name, kind, line_start, container_name)
|
|
65
|
+
ev_id = EvidenceReference.generate_id(
|
|
66
|
+
revision, file_path, line_start, line_end, EvidenceType.SYMBOL_DEFINITION, name
|
|
67
|
+
)
|
|
68
|
+
snippet, c_hash = extract_evidence_snippet(content, line_start, line_end, pre_split_lines=lines)
|
|
69
|
+
err_note = " (partial extraction: file has syntax errors)" if has_syntax_error else ""
|
|
70
|
+
ev = EvidenceReference(
|
|
71
|
+
evidence_id=ev_id,
|
|
72
|
+
repository_revision=revision,
|
|
73
|
+
file_path=file_path,
|
|
74
|
+
line_start=line_start,
|
|
75
|
+
line_end=line_end,
|
|
76
|
+
evidence_type=EvidenceType.SYMBOL_DEFINITION,
|
|
77
|
+
symbol_name=name,
|
|
78
|
+
symbol_kind=kind,
|
|
79
|
+
support_level=support_lvl,
|
|
80
|
+
confidence_reason=f"Tree-sitter {language} AST {kind.value} '{qualified}'{err_note}",
|
|
81
|
+
code_snippet=snippet,
|
|
82
|
+
content_hash=c_hash,
|
|
83
|
+
)
|
|
84
|
+
sym = SymbolDefinition(
|
|
85
|
+
id=sym_id,
|
|
86
|
+
name=name,
|
|
87
|
+
kind=kind,
|
|
88
|
+
file_path=file_path,
|
|
89
|
+
line_start=line_start,
|
|
90
|
+
line_end=line_end,
|
|
91
|
+
column_start=col_start,
|
|
92
|
+
column_end=col_end,
|
|
93
|
+
language=language,
|
|
94
|
+
container_name=container_name,
|
|
95
|
+
qualified_name=qualified,
|
|
96
|
+
namespace_name=namespace_name,
|
|
97
|
+
visibility=visibility,
|
|
98
|
+
annotations=annotations,
|
|
99
|
+
is_exported=is_exported,
|
|
100
|
+
is_partial=is_partial,
|
|
101
|
+
is_override=is_override,
|
|
102
|
+
has_syntax_error=has_syntax_error,
|
|
103
|
+
signature=_extract_sig(lines, line_start),
|
|
104
|
+
evidence_id=ev_id,
|
|
105
|
+
)
|
|
106
|
+
return sym, ev
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
def _parse_csharp_modifiers(source_bytes: bytes, node: Any) -> tuple[str, list[str], bool, bool]:
|
|
110
|
+
"""Return (visibility, annotations, is_partial, is_override) for a C# declaration node."""
|
|
111
|
+
mods: set[str] = set()
|
|
112
|
+
anns: list[str] = []
|
|
113
|
+
for child in node.named_children:
|
|
114
|
+
if child.type == "modifier":
|
|
115
|
+
mods.add(_node_text(source_bytes, child).strip().lower())
|
|
116
|
+
elif child.type == "attribute_list":
|
|
117
|
+
for attr in child.named_children:
|
|
118
|
+
if attr.type == "attribute":
|
|
119
|
+
aname = attr.child_by_field_name("name")
|
|
120
|
+
if aname is not None:
|
|
121
|
+
anns.append(_node_text(source_bytes, aname).strip())
|
|
122
|
+
else:
|
|
123
|
+
anns.append(_node_text(source_bytes, attr).strip().split("(")[0].strip())
|
|
124
|
+
if "public" in mods:
|
|
125
|
+
vis = "public"
|
|
126
|
+
elif "internal" in mods:
|
|
127
|
+
vis = "internal"
|
|
128
|
+
elif "protected" in mods:
|
|
129
|
+
vis = "protected"
|
|
130
|
+
elif "private" in mods:
|
|
131
|
+
vis = "private"
|
|
132
|
+
else:
|
|
133
|
+
vis = "private" if node.type not in (
|
|
134
|
+
"class_declaration",
|
|
135
|
+
"interface_declaration",
|
|
136
|
+
"struct_declaration",
|
|
137
|
+
"record_declaration",
|
|
138
|
+
"enum_declaration",
|
|
139
|
+
) else "internal"
|
|
140
|
+
is_partial = "partial" in mods
|
|
141
|
+
is_override = bool(mods & {"override", "virtual", "abstract"})
|
|
142
|
+
return vis, anns, is_partial, is_override
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
def extract_csharp_symbols(
|
|
146
|
+
file_path: str,
|
|
147
|
+
content: str,
|
|
148
|
+
source_bytes: bytes,
|
|
149
|
+
revision: str,
|
|
150
|
+
support_lvl: LanguageSupportLevel,
|
|
151
|
+
) -> tuple[list[SymbolDefinition], list[SymbolReference], list[EvidenceReference]]:
|
|
152
|
+
"""Extract C# namespaces, types, members, attributes, partial flags, and references via Tree-sitter."""
|
|
153
|
+
_init_treesitter_parsers()
|
|
154
|
+
ts_parser = _TS_PARSERS.get("c_sharp")
|
|
155
|
+
if ts_parser is None:
|
|
156
|
+
return [], [], []
|
|
157
|
+
|
|
158
|
+
symbols: list[SymbolDefinition] = []
|
|
159
|
+
references: list[SymbolReference] = []
|
|
160
|
+
evidence_items: list[EvidenceReference] = []
|
|
161
|
+
lines = content.replace("\r\n", "\n").replace("\r", "\n").splitlines()
|
|
162
|
+
|
|
163
|
+
tree = ts_parser.parse(source_bytes)
|
|
164
|
+
has_err = bool(tree.root_node.has_error)
|
|
165
|
+
|
|
166
|
+
# Detect file-scoped namespace once at compilation_unit level
|
|
167
|
+
file_namespace: str | None = None
|
|
168
|
+
for ch in tree.root_node.named_children:
|
|
169
|
+
if ch.type == "file_scoped_namespace_declaration":
|
|
170
|
+
n_node = ch.child_by_field_name("name")
|
|
171
|
+
if n_node is not None:
|
|
172
|
+
file_namespace = _node_text(source_bytes, n_node).strip()
|
|
173
|
+
break
|
|
174
|
+
|
|
175
|
+
_TYPE_KIND_MAP: dict[str, SymbolKind] = {
|
|
176
|
+
"class_declaration": SymbolKind.CLASS,
|
|
177
|
+
"interface_declaration": SymbolKind.INTERFACE,
|
|
178
|
+
"struct_declaration": SymbolKind.STRUCT,
|
|
179
|
+
"record_declaration": SymbolKind.RECORD,
|
|
180
|
+
"enum_declaration": SymbolKind.ENUM,
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
def visit(node: Any, cur_ns: str | None, cur_container: str | None) -> None:
|
|
184
|
+
ntype = node.type
|
|
185
|
+
line_no = node.start_point[0] + 1
|
|
186
|
+
col_no = node.start_point[1]
|
|
187
|
+
|
|
188
|
+
if ntype == "using_directive":
|
|
189
|
+
raw = _node_text(source_bytes, node).strip().rstrip(";").strip()
|
|
190
|
+
cleaned = re.sub(r"^(?:global\s+)?using\s+(?:static\s+)?", "", raw).strip()
|
|
191
|
+
alias_name: str | None = None
|
|
192
|
+
if "=" in cleaned:
|
|
193
|
+
left, right = cleaned.split("=", 1)
|
|
194
|
+
alias_name = left.strip()
|
|
195
|
+
cleaned = right.strip()
|
|
196
|
+
if cleaned:
|
|
197
|
+
references.append(
|
|
198
|
+
SymbolReference(
|
|
199
|
+
file_path=file_path,
|
|
200
|
+
line=line_no,
|
|
201
|
+
column=col_no,
|
|
202
|
+
symbol_name=cleaned.split(".")[-1],
|
|
203
|
+
reference_kind=ReferenceKind.IMPORT,
|
|
204
|
+
module_specifier=cleaned,
|
|
205
|
+
alias_name=alias_name,
|
|
206
|
+
source_symbol_name=cur_container,
|
|
207
|
+
resolution_status=ResolutionStatus.UNRESOLVED,
|
|
208
|
+
confidence_reason=f"C# using directive '{cleaned}'",
|
|
209
|
+
)
|
|
210
|
+
)
|
|
211
|
+
return
|
|
212
|
+
|
|
213
|
+
if ntype in ("namespace_declaration", "file_scoped_namespace_declaration"):
|
|
214
|
+
n_node = node.child_by_field_name("name")
|
|
215
|
+
ns_name = _node_text(source_bytes, n_node).strip() if n_node is not None else cur_ns
|
|
216
|
+
next_ns = f"{cur_ns}.{ns_name}" if cur_ns and ns_name and cur_ns != ns_name else ns_name
|
|
217
|
+
for ch in node.named_children:
|
|
218
|
+
if ch is not n_node:
|
|
219
|
+
visit(ch, next_ns, cur_container)
|
|
220
|
+
return
|
|
221
|
+
|
|
222
|
+
if ntype in _TYPE_KIND_MAP:
|
|
223
|
+
kind = _TYPE_KIND_MAP[ntype]
|
|
224
|
+
name_node = node.child_by_field_name("name")
|
|
225
|
+
if name_node is not None:
|
|
226
|
+
tname = _node_text(source_bytes, name_node).strip()
|
|
227
|
+
vis, anns, is_partial, is_override = _parse_csharp_modifiers(source_bytes, node)
|
|
228
|
+
sym, ev = _make_symbol_and_evidence(
|
|
229
|
+
file_path=file_path,
|
|
230
|
+
content=content,
|
|
231
|
+
lines=lines,
|
|
232
|
+
revision=revision,
|
|
233
|
+
language="C#",
|
|
234
|
+
support_lvl=support_lvl,
|
|
235
|
+
name=tname,
|
|
236
|
+
kind=kind,
|
|
237
|
+
node=node,
|
|
238
|
+
container_name=cur_container,
|
|
239
|
+
namespace_name=cur_ns,
|
|
240
|
+
visibility=vis,
|
|
241
|
+
annotations=anns,
|
|
242
|
+
is_exported=(vis in ("public", "internal")),
|
|
243
|
+
is_partial=is_partial,
|
|
244
|
+
is_override=is_override,
|
|
245
|
+
has_syntax_error=has_err or bool(node.has_error),
|
|
246
|
+
)
|
|
247
|
+
symbols.append(sym)
|
|
248
|
+
evidence_items.append(ev)
|
|
249
|
+
|
|
250
|
+
# Extract base_list inheritance / interface implementations
|
|
251
|
+
for ch in node.named_children:
|
|
252
|
+
if ch.type == "base_list":
|
|
253
|
+
for btype in ch.named_children:
|
|
254
|
+
btext = _node_text(source_bytes, btype).strip().split("<")[0].strip()
|
|
255
|
+
if btext:
|
|
256
|
+
references.append(
|
|
257
|
+
SymbolReference(
|
|
258
|
+
file_path=file_path,
|
|
259
|
+
line=btype.start_point[0] + 1,
|
|
260
|
+
column=btype.start_point[1],
|
|
261
|
+
symbol_name=btext.split(".")[-1],
|
|
262
|
+
qualifier=btext.rsplit(".", 1)[0] if "." in btext else None,
|
|
263
|
+
reference_kind=ReferenceKind.INHERITANCE,
|
|
264
|
+
source_symbol_name=tname,
|
|
265
|
+
resolution_status=ResolutionStatus.CANDIDATE,
|
|
266
|
+
confidence_reason=f"C# base type/interface '{btext}' on '{tname}'",
|
|
267
|
+
)
|
|
268
|
+
)
|
|
269
|
+
|
|
270
|
+
next_container = f"{cur_container}.{tname}" if cur_container else tname
|
|
271
|
+
body = node.child_by_field_name("body")
|
|
272
|
+
if body is not None:
|
|
273
|
+
for ch in body.named_children:
|
|
274
|
+
visit(ch, cur_ns, next_container)
|
|
275
|
+
return
|
|
276
|
+
|
|
277
|
+
if ntype in ("method_declaration", "constructor_declaration", "destructor_declaration", "property_declaration"):
|
|
278
|
+
name_node = node.child_by_field_name("name")
|
|
279
|
+
if name_node is not None:
|
|
280
|
+
mname = _node_text(source_bytes, name_node).strip()
|
|
281
|
+
vis, anns, is_partial, is_override = _parse_csharp_modifiers(source_bytes, node)
|
|
282
|
+
kind_map = {
|
|
283
|
+
"method_declaration": SymbolKind.METHOD,
|
|
284
|
+
"constructor_declaration": SymbolKind.CONSTRUCTOR,
|
|
285
|
+
"destructor_declaration": SymbolKind.DESTRUCTOR,
|
|
286
|
+
"property_declaration": SymbolKind.PROPERTY,
|
|
287
|
+
}
|
|
288
|
+
kind = kind_map[ntype]
|
|
289
|
+
sym, ev = _make_symbol_and_evidence(
|
|
290
|
+
file_path=file_path,
|
|
291
|
+
content=content,
|
|
292
|
+
lines=lines,
|
|
293
|
+
revision=revision,
|
|
294
|
+
language="C#",
|
|
295
|
+
support_lvl=support_lvl,
|
|
296
|
+
name=mname,
|
|
297
|
+
kind=kind,
|
|
298
|
+
node=node,
|
|
299
|
+
container_name=cur_container,
|
|
300
|
+
namespace_name=cur_ns,
|
|
301
|
+
visibility=vis,
|
|
302
|
+
annotations=anns,
|
|
303
|
+
is_exported=(vis in ("public", "protected", "internal")),
|
|
304
|
+
is_partial=is_partial,
|
|
305
|
+
is_override=is_override,
|
|
306
|
+
has_syntax_error=has_err or bool(node.has_error),
|
|
307
|
+
)
|
|
308
|
+
symbols.append(sym)
|
|
309
|
+
evidence_items.append(ev)
|
|
310
|
+
|
|
311
|
+
# Traverse body for calls & creations
|
|
312
|
+
for ch in node.named_children:
|
|
313
|
+
visit(ch, cur_ns, cur_container)
|
|
314
|
+
return
|
|
315
|
+
|
|
316
|
+
if ntype in ("field_declaration", "event_field_declaration", "event_declaration"):
|
|
317
|
+
vis, anns, is_partial, is_override = _parse_csharp_modifiers(source_bytes, node)
|
|
318
|
+
kind = SymbolKind.EVENT if "event" in ntype else SymbolKind.FIELD
|
|
319
|
+
for ch in node.named_children:
|
|
320
|
+
if ch.type == "variable_declaration":
|
|
321
|
+
for vd in ch.named_children:
|
|
322
|
+
if vd.type == "variable_declarator":
|
|
323
|
+
vname_n = vd.child_by_field_name("name") or (
|
|
324
|
+
vd.named_children[0] if vd.named_children else None
|
|
325
|
+
)
|
|
326
|
+
if vname_n is not None:
|
|
327
|
+
vname = _node_text(source_bytes, vname_n).strip()
|
|
328
|
+
if vname:
|
|
329
|
+
sym, ev = _make_symbol_and_evidence(
|
|
330
|
+
file_path=file_path,
|
|
331
|
+
content=content,
|
|
332
|
+
lines=lines,
|
|
333
|
+
revision=revision,
|
|
334
|
+
language="C#",
|
|
335
|
+
support_lvl=support_lvl,
|
|
336
|
+
name=vname,
|
|
337
|
+
kind=kind,
|
|
338
|
+
node=vd,
|
|
339
|
+
container_name=cur_container,
|
|
340
|
+
namespace_name=cur_ns,
|
|
341
|
+
visibility=vis,
|
|
342
|
+
annotations=anns,
|
|
343
|
+
is_exported=(vis in ("public", "protected", "internal")),
|
|
344
|
+
is_partial=is_partial,
|
|
345
|
+
is_override=is_override,
|
|
346
|
+
has_syntax_error=has_err or bool(node.has_error),
|
|
347
|
+
)
|
|
348
|
+
symbols.append(sym)
|
|
349
|
+
evidence_items.append(ev)
|
|
350
|
+
return
|
|
351
|
+
|
|
352
|
+
if ntype == "invocation_expression":
|
|
353
|
+
fn = node.child_by_field_name("function")
|
|
354
|
+
if fn is not None:
|
|
355
|
+
ftext = _node_text(source_bytes, fn).strip()
|
|
356
|
+
base_call = ftext.split("<")[0].strip()
|
|
357
|
+
if "." in base_call:
|
|
358
|
+
qual, callee = base_call.rsplit(".", 1)
|
|
359
|
+
else:
|
|
360
|
+
qual, callee = None, base_call
|
|
361
|
+
if callee and callee.isidentifier():
|
|
362
|
+
references.append(
|
|
363
|
+
SymbolReference(
|
|
364
|
+
file_path=file_path,
|
|
365
|
+
line=line_no,
|
|
366
|
+
column=col_no,
|
|
367
|
+
symbol_name=callee,
|
|
368
|
+
qualifier=qual,
|
|
369
|
+
reference_kind=ReferenceKind.CALL,
|
|
370
|
+
source_symbol_name=cur_container,
|
|
371
|
+
resolution_status=ResolutionStatus.CANDIDATE,
|
|
372
|
+
confidence_reason=f"C# method invocation '{ftext}' (overload/virtual dispatch static candidate)",
|
|
373
|
+
)
|
|
374
|
+
)
|
|
375
|
+
elif ntype == "object_creation_expression":
|
|
376
|
+
tnode = node.child_by_field_name("type")
|
|
377
|
+
if tnode is not None:
|
|
378
|
+
ttext = _node_text(source_bytes, tnode).strip().split("<")[0].strip()
|
|
379
|
+
tname = ttext.split(".")[-1]
|
|
380
|
+
if tname and tname.isidentifier():
|
|
381
|
+
references.append(
|
|
382
|
+
SymbolReference(
|
|
383
|
+
file_path=file_path,
|
|
384
|
+
line=line_no,
|
|
385
|
+
column=col_no,
|
|
386
|
+
symbol_name=tname,
|
|
387
|
+
qualifier=ttext.rsplit(".", 1)[0] if "." in ttext else None,
|
|
388
|
+
reference_kind=ReferenceKind.TYPE_USAGE,
|
|
389
|
+
source_symbol_name=cur_container,
|
|
390
|
+
resolution_status=ResolutionStatus.CANDIDATE,
|
|
391
|
+
confidence_reason=f"C# object creation 'new {ttext}(...)'",
|
|
392
|
+
)
|
|
393
|
+
)
|
|
394
|
+
|
|
395
|
+
for ch in node.named_children:
|
|
396
|
+
visit(ch, cur_ns, cur_container)
|
|
397
|
+
|
|
398
|
+
visit(tree.root_node, file_namespace, None)
|
|
399
|
+
return symbols, references, evidence_items
|
|
400
|
+
|
|
401
|
+
|
|
402
|
+
def _parse_java_modifiers(source_bytes: bytes, node: Any) -> tuple[str, list[str], bool]:
|
|
403
|
+
vis = "package_private"
|
|
404
|
+
anns: list[str] = []
|
|
405
|
+
is_override = False
|
|
406
|
+
for ch in node.named_children:
|
|
407
|
+
if ch.type == "modifiers":
|
|
408
|
+
raw_text = _node_text(source_bytes, ch)
|
|
409
|
+
for mod_kw in ("public", "protected", "private"):
|
|
410
|
+
if re.search(rf"\b{mod_kw}\b", raw_text):
|
|
411
|
+
vis = mod_kw
|
|
412
|
+
break
|
|
413
|
+
if re.search(r"\babstract\b", raw_text):
|
|
414
|
+
is_override = True
|
|
415
|
+
for mchild in ch.named_children:
|
|
416
|
+
if mchild.type in ("marker_annotation", "annotation"):
|
|
417
|
+
aname = mchild.child_by_field_name("name")
|
|
418
|
+
atxt = (
|
|
419
|
+
_node_text(source_bytes, aname).strip()
|
|
420
|
+
if aname is not None
|
|
421
|
+
else _node_text(source_bytes, mchild).lstrip("@").split("(")[0].strip()
|
|
422
|
+
)
|
|
423
|
+
if atxt:
|
|
424
|
+
anns.append(atxt)
|
|
425
|
+
if atxt == "Override":
|
|
426
|
+
is_override = True
|
|
427
|
+
return vis, anns, is_override
|
|
428
|
+
|
|
429
|
+
|
|
430
|
+
def extract_java_symbols(
|
|
431
|
+
file_path: str,
|
|
432
|
+
content: str,
|
|
433
|
+
source_bytes: bytes,
|
|
434
|
+
revision: str,
|
|
435
|
+
support_lvl: LanguageSupportLevel,
|
|
436
|
+
) -> tuple[list[SymbolDefinition], list[SymbolReference], list[EvidenceReference]]:
|
|
437
|
+
"""Extract Java packages, imports, types, annotations, members, and references via Tree-sitter."""
|
|
438
|
+
_init_treesitter_parsers()
|
|
439
|
+
ts_parser = _TS_PARSERS.get("java")
|
|
440
|
+
if ts_parser is None:
|
|
441
|
+
return [], [], []
|
|
442
|
+
|
|
443
|
+
symbols: list[SymbolDefinition] = []
|
|
444
|
+
references: list[SymbolReference] = []
|
|
445
|
+
evidence_items: list[EvidenceReference] = []
|
|
446
|
+
lines = content.replace("\r\n", "\n").replace("\r", "\n").splitlines()
|
|
447
|
+
|
|
448
|
+
tree = ts_parser.parse(source_bytes)
|
|
449
|
+
has_err = bool(tree.root_node.has_error)
|
|
450
|
+
|
|
451
|
+
pkg_name: str | None = None
|
|
452
|
+
for ch in tree.root_node.named_children:
|
|
453
|
+
if ch.type == "package_declaration":
|
|
454
|
+
raw_pkg = _node_text(source_bytes, ch).strip().removeprefix("package").rstrip(";").strip()
|
|
455
|
+
if raw_pkg:
|
|
456
|
+
pkg_name = raw_pkg
|
|
457
|
+
break
|
|
458
|
+
|
|
459
|
+
_TYPE_KIND_MAP: dict[str, SymbolKind] = {
|
|
460
|
+
"class_declaration": SymbolKind.CLASS,
|
|
461
|
+
"interface_declaration": SymbolKind.INTERFACE,
|
|
462
|
+
"enum_declaration": SymbolKind.ENUM,
|
|
463
|
+
"record_declaration": SymbolKind.RECORD,
|
|
464
|
+
"annotation_type_declaration": SymbolKind.INTERFACE,
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
def visit(node: Any, cur_container: str | None) -> None:
|
|
468
|
+
ntype = node.type
|
|
469
|
+
line_no = node.start_point[0] + 1
|
|
470
|
+
col_no = node.start_point[1]
|
|
471
|
+
|
|
472
|
+
if ntype == "import_declaration":
|
|
473
|
+
raw = _node_text(source_bytes, node).strip().rstrip(";").strip()
|
|
474
|
+
is_static = "import static " in raw
|
|
475
|
+
cleaned = re.sub(r"^import\s+(?:static\s+)?", "", raw).strip()
|
|
476
|
+
if cleaned:
|
|
477
|
+
references.append(
|
|
478
|
+
SymbolReference(
|
|
479
|
+
file_path=file_path,
|
|
480
|
+
line=line_no,
|
|
481
|
+
column=col_no,
|
|
482
|
+
symbol_name=cleaned.split(".")[-1],
|
|
483
|
+
reference_kind=ReferenceKind.IMPORT,
|
|
484
|
+
module_specifier=cleaned,
|
|
485
|
+
source_symbol_name=cur_container,
|
|
486
|
+
resolution_status=ResolutionStatus.UNRESOLVED,
|
|
487
|
+
confidence_reason=(
|
|
488
|
+
f"Java {'static ' if is_static else ''}import '{cleaned}'"
|
|
489
|
+
+ (" (wildcard ambiguity)" if cleaned.endswith(".*") else "")
|
|
490
|
+
),
|
|
491
|
+
)
|
|
492
|
+
)
|
|
493
|
+
return
|
|
494
|
+
|
|
495
|
+
if ntype in _TYPE_KIND_MAP:
|
|
496
|
+
kind = _TYPE_KIND_MAP[ntype]
|
|
497
|
+
name_node = node.child_by_field_name("name")
|
|
498
|
+
if name_node is not None:
|
|
499
|
+
tname = _node_text(source_bytes, name_node).strip()
|
|
500
|
+
vis, anns, is_override = _parse_java_modifiers(source_bytes, node)
|
|
501
|
+
sym, ev = _make_symbol_and_evidence(
|
|
502
|
+
file_path=file_path,
|
|
503
|
+
content=content,
|
|
504
|
+
lines=lines,
|
|
505
|
+
revision=revision,
|
|
506
|
+
language="Java",
|
|
507
|
+
support_lvl=support_lvl,
|
|
508
|
+
name=tname,
|
|
509
|
+
kind=kind,
|
|
510
|
+
node=node,
|
|
511
|
+
container_name=cur_container,
|
|
512
|
+
namespace_name=pkg_name,
|
|
513
|
+
visibility=vis,
|
|
514
|
+
annotations=anns,
|
|
515
|
+
is_exported=(vis in ("public", "protected", "package_private")),
|
|
516
|
+
is_override=is_override,
|
|
517
|
+
has_syntax_error=has_err or bool(node.has_error),
|
|
518
|
+
)
|
|
519
|
+
symbols.append(sym)
|
|
520
|
+
evidence_items.append(ev)
|
|
521
|
+
|
|
522
|
+
# Superclass / interfaces
|
|
523
|
+
for ch in node.named_children:
|
|
524
|
+
if ch.type in ("superclass", "super_interfaces", "extends_interfaces"):
|
|
525
|
+
raw_inh = _node_text(source_bytes, ch)
|
|
526
|
+
raw_inh = re.sub(r"^\s*(extends|implements)\s+", "", raw_inh).strip()
|
|
527
|
+
for part in raw_inh.split(","):
|
|
528
|
+
btext = part.strip().split("<")[0].strip()
|
|
529
|
+
if btext:
|
|
530
|
+
references.append(
|
|
531
|
+
SymbolReference(
|
|
532
|
+
file_path=file_path,
|
|
533
|
+
line=ch.start_point[0] + 1,
|
|
534
|
+
column=ch.start_point[1],
|
|
535
|
+
symbol_name=btext.split(".")[-1],
|
|
536
|
+
reference_kind=ReferenceKind.INHERITANCE,
|
|
537
|
+
source_symbol_name=tname,
|
|
538
|
+
resolution_status=ResolutionStatus.CANDIDATE,
|
|
539
|
+
confidence_reason=f"Java inheritance/interface '{btext}' on '{tname}'",
|
|
540
|
+
)
|
|
541
|
+
)
|
|
542
|
+
|
|
543
|
+
next_container = f"{cur_container}.{tname}" if cur_container else tname
|
|
544
|
+
body = node.child_by_field_name("body")
|
|
545
|
+
if body is not None:
|
|
546
|
+
for ch in body.named_children:
|
|
547
|
+
visit(ch, next_container)
|
|
548
|
+
return
|
|
549
|
+
|
|
550
|
+
if ntype in ("method_declaration", "constructor_declaration"):
|
|
551
|
+
name_node = node.child_by_field_name("name")
|
|
552
|
+
if name_node is not None:
|
|
553
|
+
mname = _node_text(source_bytes, name_node).strip()
|
|
554
|
+
vis, anns, is_override = _parse_java_modifiers(source_bytes, node)
|
|
555
|
+
kind = SymbolKind.CONSTRUCTOR if ntype == "constructor_declaration" else SymbolKind.METHOD
|
|
556
|
+
sym, ev = _make_symbol_and_evidence(
|
|
557
|
+
file_path=file_path,
|
|
558
|
+
content=content,
|
|
559
|
+
lines=lines,
|
|
560
|
+
revision=revision,
|
|
561
|
+
language="Java",
|
|
562
|
+
support_lvl=support_lvl,
|
|
563
|
+
name=mname,
|
|
564
|
+
kind=kind,
|
|
565
|
+
node=node,
|
|
566
|
+
container_name=cur_container,
|
|
567
|
+
namespace_name=pkg_name,
|
|
568
|
+
visibility=vis,
|
|
569
|
+
annotations=anns,
|
|
570
|
+
is_exported=(vis in ("public", "protected")),
|
|
571
|
+
is_override=is_override,
|
|
572
|
+
has_syntax_error=has_err or bool(node.has_error),
|
|
573
|
+
)
|
|
574
|
+
symbols.append(sym)
|
|
575
|
+
evidence_items.append(ev)
|
|
576
|
+
|
|
577
|
+
for ch in node.named_children:
|
|
578
|
+
visit(ch, cur_container)
|
|
579
|
+
return
|
|
580
|
+
|
|
581
|
+
if ntype == "field_declaration":
|
|
582
|
+
vis, anns, _ = _parse_java_modifiers(source_bytes, node)
|
|
583
|
+
for ch in node.named_children:
|
|
584
|
+
if ch.type == "variable_declarator":
|
|
585
|
+
vn = ch.child_by_field_name("name")
|
|
586
|
+
if vn is not None:
|
|
587
|
+
vname = _node_text(source_bytes, vn).strip()
|
|
588
|
+
if vname:
|
|
589
|
+
sym, ev = _make_symbol_and_evidence(
|
|
590
|
+
file_path=file_path,
|
|
591
|
+
content=content,
|
|
592
|
+
lines=lines,
|
|
593
|
+
revision=revision,
|
|
594
|
+
language="Java",
|
|
595
|
+
support_lvl=support_lvl,
|
|
596
|
+
name=vname,
|
|
597
|
+
kind=SymbolKind.FIELD,
|
|
598
|
+
node=ch,
|
|
599
|
+
container_name=cur_container,
|
|
600
|
+
namespace_name=pkg_name,
|
|
601
|
+
visibility=vis,
|
|
602
|
+
annotations=anns,
|
|
603
|
+
is_exported=(vis in ("public", "protected")),
|
|
604
|
+
has_syntax_error=has_err or bool(node.has_error),
|
|
605
|
+
)
|
|
606
|
+
symbols.append(sym)
|
|
607
|
+
evidence_items.append(ev)
|
|
608
|
+
return
|
|
609
|
+
|
|
610
|
+
if ntype == "method_invocation":
|
|
611
|
+
mname_n = node.child_by_field_name("name")
|
|
612
|
+
obj_n = node.child_by_field_name("object")
|
|
613
|
+
if mname_n is not None:
|
|
614
|
+
callee = _node_text(source_bytes, mname_n).strip()
|
|
615
|
+
qual = _node_text(source_bytes, obj_n).strip() if obj_n is not None else None
|
|
616
|
+
if callee and callee.isidentifier():
|
|
617
|
+
references.append(
|
|
618
|
+
SymbolReference(
|
|
619
|
+
file_path=file_path,
|
|
620
|
+
line=line_no,
|
|
621
|
+
column=col_no,
|
|
622
|
+
symbol_name=callee,
|
|
623
|
+
qualifier=qual,
|
|
624
|
+
reference_kind=ReferenceKind.CALL,
|
|
625
|
+
source_symbol_name=cur_container,
|
|
626
|
+
resolution_status=ResolutionStatus.CANDIDATE,
|
|
627
|
+
confidence_reason=f"Java method invocation '{(qual + '.') if qual else ''}{callee}(...)'",
|
|
628
|
+
)
|
|
629
|
+
)
|
|
630
|
+
elif ntype == "object_creation_expression":
|
|
631
|
+
tnode = node.child_by_field_name("type")
|
|
632
|
+
if tnode is not None:
|
|
633
|
+
ttext = _node_text(source_bytes, tnode).strip().split("<")[0].strip()
|
|
634
|
+
tname = ttext.split(".")[-1]
|
|
635
|
+
if tname and tname.isidentifier():
|
|
636
|
+
references.append(
|
|
637
|
+
SymbolReference(
|
|
638
|
+
file_path=file_path,
|
|
639
|
+
line=line_no,
|
|
640
|
+
column=col_no,
|
|
641
|
+
symbol_name=tname,
|
|
642
|
+
reference_kind=ReferenceKind.TYPE_USAGE,
|
|
643
|
+
source_symbol_name=cur_container,
|
|
644
|
+
resolution_status=ResolutionStatus.CANDIDATE,
|
|
645
|
+
confidence_reason=f"Java object creation 'new {ttext}(...)'",
|
|
646
|
+
)
|
|
647
|
+
)
|
|
648
|
+
|
|
649
|
+
for ch in node.named_children:
|
|
650
|
+
visit(ch, cur_container)
|
|
651
|
+
|
|
652
|
+
visit(tree.root_node, None)
|
|
653
|
+
return symbols, references, evidence_items
|
|
654
|
+
|
|
655
|
+
|
|
656
|
+
def extract_c_cpp_symbols(
|
|
657
|
+
file_path: str,
|
|
658
|
+
content: str,
|
|
659
|
+
source_bytes: bytes,
|
|
660
|
+
revision: str,
|
|
661
|
+
language: str,
|
|
662
|
+
parser_key: str,
|
|
663
|
+
support_lvl: LanguageSupportLevel,
|
|
664
|
+
) -> tuple[list[SymbolDefinition], list[SymbolReference], list[EvidenceReference]]:
|
|
665
|
+
"""Extract C/C++ includes, macros, namespaces, types, functions, methods, and calls via Tree-sitter."""
|
|
666
|
+
_init_treesitter_parsers()
|
|
667
|
+
ts_parser = _TS_PARSERS.get(parser_key)
|
|
668
|
+
if ts_parser is None:
|
|
669
|
+
return [], [], []
|
|
670
|
+
|
|
671
|
+
symbols: list[SymbolDefinition] = []
|
|
672
|
+
references: list[SymbolReference] = []
|
|
673
|
+
evidence_items: list[EvidenceReference] = []
|
|
674
|
+
lines = content.replace("\r\n", "\n").replace("\r", "\n").splitlines()
|
|
675
|
+
|
|
676
|
+
tree = ts_parser.parse(source_bytes)
|
|
677
|
+
has_err = bool(tree.root_node.has_error)
|
|
678
|
+
|
|
679
|
+
def _is_static(node: Any) -> bool:
|
|
680
|
+
for ch in node.named_children:
|
|
681
|
+
if ch.type == "storage_class_specifier" and _node_text(source_bytes, ch).strip() == "static":
|
|
682
|
+
return True
|
|
683
|
+
return False
|
|
684
|
+
|
|
685
|
+
def visit(node: Any, cur_ns: str | None, cur_container: str | None) -> None:
|
|
686
|
+
ntype = node.type
|
|
687
|
+
line_no = node.start_point[0] + 1
|
|
688
|
+
col_no = node.start_point[1]
|
|
689
|
+
|
|
690
|
+
if ntype == "preproc_include":
|
|
691
|
+
pnode = node.child_by_field_name("path")
|
|
692
|
+
if pnode is not None:
|
|
693
|
+
raw_inc = _node_text(source_bytes, pnode).strip()
|
|
694
|
+
is_local = raw_inc.startswith('"')
|
|
695
|
+
header = raw_inc.strip('<>" ')
|
|
696
|
+
if header:
|
|
697
|
+
references.append(
|
|
698
|
+
SymbolReference(
|
|
699
|
+
file_path=file_path,
|
|
700
|
+
line=line_no,
|
|
701
|
+
column=col_no,
|
|
702
|
+
symbol_name=header.rsplit("/", 1)[-1],
|
|
703
|
+
reference_kind=ReferenceKind.IMPORT,
|
|
704
|
+
module_specifier=header,
|
|
705
|
+
source_symbol_name=cur_container,
|
|
706
|
+
resolution_status=ResolutionStatus.UNRESOLVED,
|
|
707
|
+
confidence_reason=(
|
|
708
|
+
f"{language} local #include \"{header}\""
|
|
709
|
+
if is_local
|
|
710
|
+
else f"{language} system #include <{header}>"
|
|
711
|
+
),
|
|
712
|
+
)
|
|
713
|
+
)
|
|
714
|
+
return
|
|
715
|
+
|
|
716
|
+
if ntype in ("preproc_def", "preproc_function_def"):
|
|
717
|
+
n_node = node.child_by_field_name("name")
|
|
718
|
+
if n_node is not None:
|
|
719
|
+
mname = _node_text(source_bytes, n_node).strip()
|
|
720
|
+
if mname:
|
|
721
|
+
sym, ev = _make_symbol_and_evidence(
|
|
722
|
+
file_path=file_path,
|
|
723
|
+
content=content,
|
|
724
|
+
lines=lines,
|
|
725
|
+
revision=revision,
|
|
726
|
+
language=language,
|
|
727
|
+
support_lvl=support_lvl,
|
|
728
|
+
name=mname,
|
|
729
|
+
kind=SymbolKind.MACRO,
|
|
730
|
+
node=node,
|
|
731
|
+
container_name=cur_container,
|
|
732
|
+
namespace_name=cur_ns,
|
|
733
|
+
visibility="unknown",
|
|
734
|
+
annotations=[],
|
|
735
|
+
is_exported=True,
|
|
736
|
+
has_syntax_error=has_err or bool(node.has_error),
|
|
737
|
+
sep="::",
|
|
738
|
+
)
|
|
739
|
+
symbols.append(sym)
|
|
740
|
+
evidence_items.append(ev)
|
|
741
|
+
return
|
|
742
|
+
|
|
743
|
+
if ntype == "namespace_definition":
|
|
744
|
+
n_node = node.child_by_field_name("name")
|
|
745
|
+
ns_seg = _node_text(source_bytes, n_node).strip() if n_node is not None else "<anonymous>"
|
|
746
|
+
next_ns = f"{cur_ns}::{ns_seg}" if cur_ns else ns_seg
|
|
747
|
+
body = node.child_by_field_name("body")
|
|
748
|
+
if body is not None:
|
|
749
|
+
for ch in body.named_children:
|
|
750
|
+
visit(ch, next_ns, cur_container)
|
|
751
|
+
return
|
|
752
|
+
|
|
753
|
+
if ntype in ("class_specifier", "struct_specifier", "enum_specifier"):
|
|
754
|
+
name_node = node.child_by_field_name("name")
|
|
755
|
+
body_node = node.child_by_field_name("body")
|
|
756
|
+
if name_node is not None and body_node is not None:
|
|
757
|
+
tname = _node_text(source_bytes, name_node).strip()
|
|
758
|
+
kind = (
|
|
759
|
+
SymbolKind.CLASS
|
|
760
|
+
if ntype == "class_specifier"
|
|
761
|
+
else SymbolKind.STRUCT
|
|
762
|
+
if ntype == "struct_specifier"
|
|
763
|
+
else SymbolKind.ENUM
|
|
764
|
+
)
|
|
765
|
+
sym, ev = _make_symbol_and_evidence(
|
|
766
|
+
file_path=file_path,
|
|
767
|
+
content=content,
|
|
768
|
+
lines=lines,
|
|
769
|
+
revision=revision,
|
|
770
|
+
language=language,
|
|
771
|
+
support_lvl=support_lvl,
|
|
772
|
+
name=tname,
|
|
773
|
+
kind=kind,
|
|
774
|
+
node=node,
|
|
775
|
+
container_name=cur_container,
|
|
776
|
+
namespace_name=cur_ns,
|
|
777
|
+
visibility="public",
|
|
778
|
+
annotations=[],
|
|
779
|
+
is_exported=True,
|
|
780
|
+
has_syntax_error=has_err or bool(node.has_error),
|
|
781
|
+
sep="::",
|
|
782
|
+
)
|
|
783
|
+
symbols.append(sym)
|
|
784
|
+
evidence_items.append(ev)
|
|
785
|
+
next_container = f"{cur_container}::{tname}" if cur_container else tname
|
|
786
|
+
for ch in body_node.named_children:
|
|
787
|
+
visit(ch, cur_ns, next_container)
|
|
788
|
+
return
|
|
789
|
+
|
|
790
|
+
if ntype == "type_definition":
|
|
791
|
+
decl = node.child_by_field_name("declarator")
|
|
792
|
+
td_name = _extract_c_declarator_name(source_bytes, decl)
|
|
793
|
+
if td_name:
|
|
794
|
+
sym, ev = _make_symbol_and_evidence(
|
|
795
|
+
file_path=file_path,
|
|
796
|
+
content=content,
|
|
797
|
+
lines=lines,
|
|
798
|
+
revision=revision,
|
|
799
|
+
language=language,
|
|
800
|
+
support_lvl=support_lvl,
|
|
801
|
+
name=td_name,
|
|
802
|
+
kind=SymbolKind.TYPE,
|
|
803
|
+
node=node,
|
|
804
|
+
container_name=cur_container,
|
|
805
|
+
namespace_name=cur_ns,
|
|
806
|
+
visibility="public",
|
|
807
|
+
annotations=[],
|
|
808
|
+
is_exported=True,
|
|
809
|
+
has_syntax_error=has_err or bool(node.has_error),
|
|
810
|
+
sep="::",
|
|
811
|
+
)
|
|
812
|
+
symbols.append(sym)
|
|
813
|
+
evidence_items.append(ev)
|
|
814
|
+
return
|
|
815
|
+
|
|
816
|
+
if ntype == "function_definition":
|
|
817
|
+
decl = node.child_by_field_name("declarator")
|
|
818
|
+
raw_fname = _extract_c_declarator_name(source_bytes, decl)
|
|
819
|
+
if raw_fname:
|
|
820
|
+
eff_container: str | None = cur_container
|
|
821
|
+
fname = raw_fname
|
|
822
|
+
if "::" in raw_fname:
|
|
823
|
+
qual_part, fname = raw_fname.rsplit("::", 1)
|
|
824
|
+
eff_container = f"{cur_container}::{qual_part}" if cur_container else qual_part
|
|
825
|
+
is_stat = _is_static(node)
|
|
826
|
+
if fname.startswith("~"):
|
|
827
|
+
kind = SymbolKind.DESTRUCTOR
|
|
828
|
+
elif eff_container and fname == eff_container.rsplit("::", 1)[-1]:
|
|
829
|
+
kind = SymbolKind.CONSTRUCTOR
|
|
830
|
+
elif eff_container:
|
|
831
|
+
kind = SymbolKind.METHOD
|
|
832
|
+
else:
|
|
833
|
+
kind = SymbolKind.FUNCTION
|
|
834
|
+
sym, ev = _make_symbol_and_evidence(
|
|
835
|
+
file_path=file_path,
|
|
836
|
+
content=content,
|
|
837
|
+
lines=lines,
|
|
838
|
+
revision=revision,
|
|
839
|
+
language=language,
|
|
840
|
+
support_lvl=support_lvl,
|
|
841
|
+
name=fname,
|
|
842
|
+
kind=kind,
|
|
843
|
+
node=node,
|
|
844
|
+
container_name=eff_container,
|
|
845
|
+
namespace_name=cur_ns,
|
|
846
|
+
visibility="static" if is_stat else "public",
|
|
847
|
+
annotations=[],
|
|
848
|
+
is_exported=not is_stat,
|
|
849
|
+
has_syntax_error=has_err or bool(node.has_error),
|
|
850
|
+
sep="::",
|
|
851
|
+
)
|
|
852
|
+
symbols.append(sym)
|
|
853
|
+
evidence_items.append(ev)
|
|
854
|
+
|
|
855
|
+
body = node.child_by_field_name("body")
|
|
856
|
+
if body is not None:
|
|
857
|
+
for ch in body.named_children:
|
|
858
|
+
visit(ch, cur_ns, cur_container)
|
|
859
|
+
return
|
|
860
|
+
|
|
861
|
+
if ntype == "call_expression":
|
|
862
|
+
fn = node.child_by_field_name("function")
|
|
863
|
+
if fn is not None:
|
|
864
|
+
ftext = _node_text(source_bytes, fn).strip()
|
|
865
|
+
clean = ftext.replace("->", ".").replace("::", ".")
|
|
866
|
+
if "." in clean:
|
|
867
|
+
qual, callee = clean.rsplit(".", 1)
|
|
868
|
+
else:
|
|
869
|
+
qual, callee = None, clean
|
|
870
|
+
if callee and callee.isidentifier():
|
|
871
|
+
references.append(
|
|
872
|
+
SymbolReference(
|
|
873
|
+
file_path=file_path,
|
|
874
|
+
line=line_no,
|
|
875
|
+
column=col_no,
|
|
876
|
+
symbol_name=callee,
|
|
877
|
+
qualifier=qual,
|
|
878
|
+
reference_kind=ReferenceKind.CALL,
|
|
879
|
+
source_symbol_name=cur_container,
|
|
880
|
+
resolution_status=ResolutionStatus.CANDIDATE,
|
|
881
|
+
confidence_reason=f"{language} call expression '{ftext}' (macros/overloads not compiler-resolved)",
|
|
882
|
+
)
|
|
883
|
+
)
|
|
884
|
+
|
|
885
|
+
for ch in node.named_children:
|
|
886
|
+
visit(ch, cur_ns, cur_container)
|
|
887
|
+
|
|
888
|
+
visit(tree.root_node, None, None)
|
|
889
|
+
return symbols, references, evidence_items
|