codegraph-engine 2.3.0__py3-none-any.whl → 3.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.
- codegraph/__init__.py +1 -1
- codegraph/__main__.py +7 -0
- codegraph/agent_brain.py +253 -2
- codegraph/agent_capabilities.py +1348 -67
- codegraph/agent_rules.py +2 -1
- codegraph/api_drift.py +455 -0
- codegraph/architecture_rules.py +123 -0
- codegraph/async_queue/__init__.py +50 -0
- codegraph/async_queue/detectors/__init__.py +48 -0
- codegraph/async_queue/detectors/celery.py +160 -0
- codegraph/async_queue/detectors/kafka.py +168 -0
- codegraph/async_queue/detectors/rabbitmq.py +116 -0
- codegraph/async_queue/detectors/redis.py +130 -0
- codegraph/async_queue/detectors/sqs.py +135 -0
- codegraph/async_queue/models.py +161 -0
- codegraph/async_queue/otel_models.py +74 -0
- codegraph/async_queue/otel_parser.py +337 -0
- codegraph/async_queue/reconciler.py +427 -0
- codegraph/async_queue/scanner.py +291 -0
- codegraph/async_queue/traversal.py +447 -0
- codegraph/change_impact.py +320 -110
- codegraph/changelog.py +170 -0
- codegraph/cli.py +1605 -62
- codegraph/cli_output.py +17 -2
- codegraph/context.py +135 -24
- codegraph/context_freshness.py +2 -0
- codegraph/database/__init__.py +14 -0
- codegraph/database/extractor.py +712 -17
- codegraph/database/interrogation.py +388 -2
- codegraph/database/schema_drift.py +862 -0
- codegraph/dataflow_propagation.py +118 -0
- codegraph/dead_code.py +387 -0
- codegraph/epistemic.py +15 -0
- codegraph/evidence_contract.py +34 -3
- codegraph/federation.py +245 -0
- codegraph/frameworks.py +234 -12
- codegraph/frameworks_nestjs.py +502 -0
- codegraph/frameworks_nextjs.py +337 -0
- codegraph/frameworks_react.py +457 -0
- codegraph/freshness.py +2 -0
- codegraph/frontend_html.py +109 -0
- codegraph/git.py +2 -0
- codegraph/git_state.py +2 -0
- codegraph/graph/traversal.py +150 -7
- codegraph/graph_csr.py +218 -0
- codegraph/incremental.py +150 -0
- codegraph/indexing/__init__.py +7 -1
- codegraph/indexing/classifier.py +5 -0
- codegraph/indexing/indexer.py +292 -38
- codegraph/indexing/languages/__init__.py +1 -0
- codegraph/indexing/languages/cpp.py +457 -0
- codegraph/indexing/languages/go.py +459 -0
- codegraph/indexing/languages/jvm.py +583 -0
- codegraph/indexing/languages/rust.py +507 -0
- codegraph/indexing/models.py +15 -1
- codegraph/indexing/parser.py +385 -9
- codegraph/indexing/pool.py +136 -0
- codegraph/indexing/protocols.py +220 -0
- codegraph/indexing/scanner.py +23 -0
- codegraph/indexing/templates.py +418 -0
- codegraph/interrogation.py +207 -39
- codegraph/lsp.py +318 -0
- codegraph/lsp_bridge/__init__.py +16 -0
- codegraph/lsp_bridge/bridge.py +102 -0
- codegraph/lsp_bridge/client.py +207 -0
- codegraph/lsp_bridge/models.py +71 -0
- codegraph/mcp/server.py +502 -29
- codegraph/memory/trajectory.py +282 -0
- codegraph/models.py +7 -0
- codegraph/monorepo.py +3 -0
- codegraph/multi_agent/__init__.py +13 -0
- codegraph/multi_agent/coordinator.py +229 -0
- codegraph/multi_agent/models.py +76 -0
- codegraph/optimizer.py +42 -5
- codegraph/polymorphism.py +95 -0
- codegraph/pr_review.py +296 -0
- codegraph/process_lifecycle.py +50 -12
- codegraph/reachability.py +198 -0
- codegraph/reachability_index.py +74 -0
- codegraph/refactor/__init__.py +48 -0
- codegraph/refactor/models.py +114 -0
- codegraph/refactor/patcher.py +348 -0
- codegraph/refactor/renamer.py +844 -0
- codegraph/refactor/transactions.py +414 -0
- codegraph/repair.py +233 -0
- codegraph/resolver.py +1357 -161
- codegraph/retrieval_policy.py +22 -1
- codegraph/roblox.py +2174 -0
- codegraph/route_composer.py +7 -0
- codegraph/route_topology.py +172 -0
- codegraph/runtime/__init__.py +25 -0
- codegraph/runtime/collector.py +155 -0
- codegraph/runtime/db_watcher.py +191 -0
- codegraph/runtime/ingestor.py +30 -10
- codegraph/runtime/otel_receiver.py +208 -0
- codegraph/runtime/port_inspector.py +304 -0
- codegraph/runtime/runner.py +155 -6
- codegraph/runtime/trace_linker.py +175 -0
- codegraph/sandbox.py +215 -0
- codegraph/search/hybrid.py +26 -0
- codegraph/security/supply_chain.py +188 -0
- codegraph/security/taint.py +421 -0
- codegraph/semantic_decorators.py +34 -3
- codegraph/structural_diff.py +2 -0
- codegraph/styles.py +144 -0
- codegraph/symbol_history.py +2 -0
- codegraph/test_gen.py +437 -0
- codegraph/tsconfig.py +236 -0
- codegraph/ui/__init__.py +6 -0
- codegraph/ui/server.py +876 -0
- codegraph/watcher.py +323 -0
- {codegraph_engine-2.3.0.dist-info → codegraph_engine-3.0.1.dist-info}/METADATA +365 -67
- codegraph_engine-3.0.1.dist-info/RECORD +164 -0
- {codegraph_engine-2.3.0.dist-info → codegraph_engine-3.0.1.dist-info}/WHEEL +1 -1
- codegraph_engine-2.3.0.dist-info/RECORD +0 -94
- {codegraph_engine-2.3.0.dist-info → codegraph_engine-3.0.1.dist-info}/entry_points.txt +0 -0
- {codegraph_engine-2.3.0.dist-info → codegraph_engine-3.0.1.dist-info}/licenses/LICENSE +0 -0
- {codegraph_engine-2.3.0.dist-info → codegraph_engine-3.0.1.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,457 @@
|
|
|
1
|
+
"""Deep, production-grade C/C++ (.c, .cc, .cpp, .cxx, .h, .hpp, .hxx) language parser and framework resolver for CodeGraph.
|
|
2
|
+
|
|
3
|
+
Provides deep AST extraction for:
|
|
4
|
+
- Full scope tree: namespace -> class / struct / union / enum -> method / function
|
|
5
|
+
- Header includes (#include <...> and #include "...")
|
|
6
|
+
- Exact parameters, type signatures, return types, and parameter counts
|
|
7
|
+
- Doxygen comments (/** ... */ and /// ...) attached to symbols
|
|
8
|
+
- Class / struct inheritance hierarchies (InheritanceRef)
|
|
9
|
+
- Modern C++ Web & RPC routes:
|
|
10
|
+
- Crow (CROW_ROUTE(app, "/path"))
|
|
11
|
+
- Pistache (Routes::Get(router, "/path", ...))
|
|
12
|
+
- Drogon (ADD_METHOD_TO(Class::method, "/path", Get))
|
|
13
|
+
- cpp-httplib (svr.Get("/path", ...), svr.Post(...))
|
|
14
|
+
- Caller-to-callee enclosing linkage (CallRef with caller_canonical_id and receiver)
|
|
15
|
+
- Local variable bindings (BindingRef)
|
|
16
|
+
"""
|
|
17
|
+
from __future__ import annotations
|
|
18
|
+
|
|
19
|
+
import hashlib
|
|
20
|
+
import re
|
|
21
|
+
from typing import Any
|
|
22
|
+
|
|
23
|
+
from codegraph.frameworks import RouteDetection, RouterMountDetection
|
|
24
|
+
from codegraph.indexing.models import (
|
|
25
|
+
BindingRef,
|
|
26
|
+
CallRef,
|
|
27
|
+
ImportRef,
|
|
28
|
+
InheritanceRef,
|
|
29
|
+
Symbol,
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def parse_cpp(content: str, file_path: str) -> Any:
|
|
34
|
+
"""Parse C/C++ source code with deep scope tracking, caller linking, and C++ route resolution."""
|
|
35
|
+
from codegraph.indexing.parser import ParseResult
|
|
36
|
+
|
|
37
|
+
source_hash = hashlib.sha256(content.encode("utf-8", errors="replace")).hexdigest()
|
|
38
|
+
lines = content.splitlines()
|
|
39
|
+
is_header = file_path.lower().endswith((".h", ".hpp", ".hxx"))
|
|
40
|
+
lang_name = "cpp_header" if is_header else "cpp"
|
|
41
|
+
|
|
42
|
+
symbols: list[Symbol] = []
|
|
43
|
+
imports: list[ImportRef] = []
|
|
44
|
+
calls: list[CallRef] = []
|
|
45
|
+
inheritance: list[InheritanceRef] = []
|
|
46
|
+
routes: list[RouteDetection] = []
|
|
47
|
+
mounts: list[RouterMountDetection] = []
|
|
48
|
+
bindings: list[BindingRef] = []
|
|
49
|
+
exports: list[str] = []
|
|
50
|
+
|
|
51
|
+
# 1. Includes Extraction (#include <...> and #include "...")
|
|
52
|
+
include_re = re.compile(r'^\s*#\s*include\s+([<"])([^>"]+)[>"]')
|
|
53
|
+
for line_idx, line in enumerate(lines, start=1):
|
|
54
|
+
clean = line.strip()
|
|
55
|
+
m_inc = include_re.match(clean)
|
|
56
|
+
if m_inc:
|
|
57
|
+
inc_kind = m_inc.group(1)
|
|
58
|
+
inc_path = m_inc.group(2)
|
|
59
|
+
inc_name = inc_path.split("/")[-1]
|
|
60
|
+
imports.append(
|
|
61
|
+
ImportRef(
|
|
62
|
+
module=inc_path,
|
|
63
|
+
source_file=file_path,
|
|
64
|
+
name=inc_name,
|
|
65
|
+
line=line_idx,
|
|
66
|
+
alias="system" if inc_kind == "<" else "local",
|
|
67
|
+
)
|
|
68
|
+
)
|
|
69
|
+
|
|
70
|
+
# 2. Block tracking helper via curly brace counting
|
|
71
|
+
def find_block_end(start_idx: int) -> int:
|
|
72
|
+
brace_count = 0
|
|
73
|
+
found_open = False
|
|
74
|
+
for i in range(start_idx - 1, len(lines)):
|
|
75
|
+
line_str = lines[i]
|
|
76
|
+
for ch in line_str:
|
|
77
|
+
if ch == "{":
|
|
78
|
+
brace_count += 1
|
|
79
|
+
found_open = True
|
|
80
|
+
elif ch == "}":
|
|
81
|
+
brace_count -= 1
|
|
82
|
+
if found_open and brace_count <= 0:
|
|
83
|
+
return i + 1
|
|
84
|
+
return len(lines)
|
|
85
|
+
|
|
86
|
+
# 3. Doxygen comment extraction helper
|
|
87
|
+
def extract_doxygen(start_idx: int) -> str | None:
|
|
88
|
+
idx = start_idx - 2
|
|
89
|
+
doc_lines: list[str] = []
|
|
90
|
+
# Check single line /// comments above
|
|
91
|
+
if idx >= 0 and lines[idx].strip().startswith("///"):
|
|
92
|
+
while idx >= 0 and lines[idx].strip().startswith("///"):
|
|
93
|
+
doc_lines.insert(0, lines[idx].strip().lstrip("/").strip())
|
|
94
|
+
idx -= 1
|
|
95
|
+
return "\n".join(doc_lines)
|
|
96
|
+
|
|
97
|
+
in_doc = False
|
|
98
|
+
while idx >= 0:
|
|
99
|
+
doc_line = lines[idx].strip()
|
|
100
|
+
if doc_line.endswith("*/"):
|
|
101
|
+
in_doc = True
|
|
102
|
+
if in_doc:
|
|
103
|
+
cleaned = doc_line.lstrip("/*").rstrip("*/").strip()
|
|
104
|
+
if cleaned:
|
|
105
|
+
doc_lines.insert(0, cleaned)
|
|
106
|
+
if doc_line.startswith("/**"):
|
|
107
|
+
break
|
|
108
|
+
elif not doc_line:
|
|
109
|
+
idx -= 1
|
|
110
|
+
continue
|
|
111
|
+
else:
|
|
112
|
+
break
|
|
113
|
+
idx -= 1
|
|
114
|
+
return "\n".join(doc_lines) if doc_lines else None
|
|
115
|
+
|
|
116
|
+
# Namespace regex: namespace foo { or namespace foo::bar {
|
|
117
|
+
namespace_re = re.compile(r"^\s*namespace\s+([A-Za-z0-9_:]+)\s*\{")
|
|
118
|
+
|
|
119
|
+
# Class / Struct regex:
|
|
120
|
+
# template <typename T> class MyClass : public BaseClass, private IOther
|
|
121
|
+
# struct Point {
|
|
122
|
+
class_struct_re = re.compile(
|
|
123
|
+
r"^(?:template\s*<[^>]+>\s*)?"
|
|
124
|
+
r"(?:(?:public|private|protected|virtual|final|alignas\([^)]+\))\s+)*"
|
|
125
|
+
r"(class|struct|union|enum\s+class|enum)\s+([A-Za-z0-9_]+)"
|
|
126
|
+
r"(?:\s*final)?"
|
|
127
|
+
r"(?:\s*:\s*([^{;]+))?"
|
|
128
|
+
r"\s*(?:\{|;)"
|
|
129
|
+
)
|
|
130
|
+
|
|
131
|
+
# Function / Method regex:
|
|
132
|
+
# int add(int a, int b) {
|
|
133
|
+
# virtual void ProcessRequest(const Request& req, Response* res) override {
|
|
134
|
+
# auto compute(double x) -> double {
|
|
135
|
+
func_method_re = re.compile(
|
|
136
|
+
r"^(?:template\s*<[^>]+>\s*)?"
|
|
137
|
+
r"(?:(?:static|inline|virtual|constexpr|explicit|friend|const)\s+)*"
|
|
138
|
+
r"([A-Za-z0-9_:*&<>~]+(?:\s*[*&]+)?)\s+([A-Za-z0-9_:]+)\s*\(([^)]*)\)"
|
|
139
|
+
r"(?:\s*const)?"
|
|
140
|
+
r"(?:\s*noexcept)?"
|
|
141
|
+
r"(?:\s*override|\s*final)?"
|
|
142
|
+
r"(?:\s*->\s*[A-Za-z0-9_:*&<>]+)?"
|
|
143
|
+
r"\s*\{"
|
|
144
|
+
)
|
|
145
|
+
|
|
146
|
+
# Local variable bindings:
|
|
147
|
+
# auto client = std::make_shared<HttpClient>();
|
|
148
|
+
# int count = get_total_count();
|
|
149
|
+
binding_re = re.compile(r"^\s*(?:auto|[A-Za-z0-9_:<>&*]+)\s+([a-zA-Z0-9_]+)\s*=\s*([A-Za-z0-9_:.]+\s*\([^;]*\));")
|
|
150
|
+
|
|
151
|
+
# Route patterns for C++ Web Frameworks:
|
|
152
|
+
# Crow: CROW_ROUTE(app, "/api/users")([]() { ... })
|
|
153
|
+
crow_route_re = re.compile(r'CROW_ROUTE\s*\(\s*([a-zA-Z0-9_]+)\s*,\s*["\']([^"\']+)["\']\s*\)')
|
|
154
|
+
# Pistache: Routes::Get(router, "/api/users", ...);
|
|
155
|
+
pistache_route_re = re.compile(r'Routes::(Get|Post|Put|Delete)\s*\(\s*([a-zA-Z0-9_]+)\s*,\s*["\']([^"\']+)["\']\s*,\s*Routes::bind\s*\(\s*&?([A-Za-z0-9_:]+)')
|
|
156
|
+
# Drogon: ADD_METHOD_TO(UserController::getUsers, "/api/users", Get);
|
|
157
|
+
drogon_route_re = re.compile(r'ADD_METHOD_TO\s*\(\s*([A-Za-z0-9_:]+)\s*,\s*["\']([^"\']+)["\']\s*,\s*([A-Za-z0-9_]+)\s*\)')
|
|
158
|
+
# cpp-httplib: svr.Get("/api/users", handler);
|
|
159
|
+
httplib_route_re = re.compile(r'([a-zA-Z0-9_]+)\.(Get|Post|Put|Delete|Patch)\s*\(\s*["\']([^"\']+)["\']\s*,\s*([^)]+)\)')
|
|
160
|
+
|
|
161
|
+
class ScopeContext:
|
|
162
|
+
def __init__(self, name: str, kind: str, canonical_id: str, start: int, end: int):
|
|
163
|
+
self.name = name
|
|
164
|
+
self.kind = kind
|
|
165
|
+
self.canonical_id = canonical_id
|
|
166
|
+
self.start = start
|
|
167
|
+
self.end = end
|
|
168
|
+
|
|
169
|
+
scope_stack: list[ScopeContext] = []
|
|
170
|
+
|
|
171
|
+
# First pass: namespaces, classes, functions, routes
|
|
172
|
+
line_idx = 1
|
|
173
|
+
total_lines = len(lines)
|
|
174
|
+
while line_idx <= total_lines:
|
|
175
|
+
line = lines[line_idx - 1]
|
|
176
|
+
clean = line.strip()
|
|
177
|
+
|
|
178
|
+
if not clean or clean.startswith("//") or clean.startswith("/*") or clean.startswith("*"):
|
|
179
|
+
line_idx += 1
|
|
180
|
+
continue
|
|
181
|
+
|
|
182
|
+
# Check for Namespace
|
|
183
|
+
m_ns = namespace_re.match(clean)
|
|
184
|
+
if m_ns:
|
|
185
|
+
ns_name = m_ns.group(1)
|
|
186
|
+
end_line = find_block_end(line_idx)
|
|
187
|
+
current_ns = [s for s in scope_stack if s.kind == "namespace"]
|
|
188
|
+
prefix = f"{current_ns[-1].canonical_id}::" if current_ns else "cpp:"
|
|
189
|
+
canonical_id = f"{prefix}{ns_name}"
|
|
190
|
+
scope_stack.append(ScopeContext(ns_name, "namespace", canonical_id, line_idx, end_line))
|
|
191
|
+
line_idx += 1
|
|
192
|
+
continue
|
|
193
|
+
|
|
194
|
+
# Check for Class / Struct / Enum
|
|
195
|
+
m_cls = class_struct_re.match(clean)
|
|
196
|
+
if m_cls and not clean.endswith(";"):
|
|
197
|
+
kw = m_cls.group(1)
|
|
198
|
+
cls_name = m_cls.group(2)
|
|
199
|
+
end_line = find_block_end(line_idx)
|
|
200
|
+
|
|
201
|
+
active_ns = [s for s in scope_stack if s.kind in ("namespace", "class")]
|
|
202
|
+
prefix = f"{active_ns[-1].canonical_id}::" if active_ns else "cpp:"
|
|
203
|
+
canonical_id = f"{prefix}{cls_name}"
|
|
204
|
+
doc = extract_doxygen(line_idx)
|
|
205
|
+
|
|
206
|
+
kind = "struct" if "struct" in kw else ("enum" if "enum" in kw else "class")
|
|
207
|
+
symbols.append(
|
|
208
|
+
Symbol(
|
|
209
|
+
name=cls_name,
|
|
210
|
+
qualified_name=f"{prefix}{cls_name}".replace("cpp:", ""),
|
|
211
|
+
kind=kind,
|
|
212
|
+
start_line=line_idx,
|
|
213
|
+
end_line=end_line,
|
|
214
|
+
file_path=file_path,
|
|
215
|
+
canonical_id=canonical_id,
|
|
216
|
+
language=lang_name,
|
|
217
|
+
module=active_ns[-1].name if active_ns else "",
|
|
218
|
+
scope=active_ns[-1].canonical_id if active_ns else "cpp:global",
|
|
219
|
+
documentation=doc,
|
|
220
|
+
visibility="public",
|
|
221
|
+
)
|
|
222
|
+
)
|
|
223
|
+
exports.append(canonical_id)
|
|
224
|
+
|
|
225
|
+
# Check Inheritance
|
|
226
|
+
inheritance_str = m_cls.group(3)
|
|
227
|
+
if inheritance_str:
|
|
228
|
+
for base in inheritance_str.split(","):
|
|
229
|
+
clean_b = re.sub(r"\b(public|private|protected|virtual)\b", "", base).strip()
|
|
230
|
+
if clean_b:
|
|
231
|
+
inheritance.append(
|
|
232
|
+
InheritanceRef(
|
|
233
|
+
source_symbol=cls_name,
|
|
234
|
+
base_name=clean_b,
|
|
235
|
+
relationship="EXTENDS",
|
|
236
|
+
source_file=file_path,
|
|
237
|
+
line=line_idx,
|
|
238
|
+
source_canonical_id=canonical_id,
|
|
239
|
+
)
|
|
240
|
+
)
|
|
241
|
+
|
|
242
|
+
scope_stack.append(ScopeContext(cls_name, "class", canonical_id, line_idx, end_line))
|
|
243
|
+
line_idx += 1
|
|
244
|
+
continue
|
|
245
|
+
|
|
246
|
+
# Check for Function / Method
|
|
247
|
+
m_fn = func_method_re.match(clean)
|
|
248
|
+
if m_fn:
|
|
249
|
+
ret_type = m_fn.group(1).strip()
|
|
250
|
+
fn_name = m_fn.group(2).strip()
|
|
251
|
+
params = m_fn.group(3).strip()
|
|
252
|
+
|
|
253
|
+
# Skip control structures
|
|
254
|
+
if fn_name not in ("if", "for", "while", "switch", "catch"):
|
|
255
|
+
end_line = find_block_end(line_idx)
|
|
256
|
+
active_parent = [s for s in scope_stack if s.kind in ("class", "namespace")]
|
|
257
|
+
prefix = f"{active_parent[-1].canonical_id}::" if active_parent else "cpp:"
|
|
258
|
+
canonical_id = f"{prefix}{fn_name}" if "::" not in fn_name else f"cpp:{fn_name}"
|
|
259
|
+
doc = extract_doxygen(line_idx)
|
|
260
|
+
|
|
261
|
+
param_count = len([p for p in params.split(",") if p.strip()]) if params else 0
|
|
262
|
+
sig = f"({params}) -> {ret_type}"
|
|
263
|
+
|
|
264
|
+
is_method = any(s.kind == "class" for s in scope_stack) or "::" in fn_name
|
|
265
|
+
symbols.append(
|
|
266
|
+
Symbol(
|
|
267
|
+
name=fn_name,
|
|
268
|
+
qualified_name=f"{prefix}{fn_name}".replace("cpp:", ""),
|
|
269
|
+
kind="method" if is_method else "function",
|
|
270
|
+
start_line=line_idx,
|
|
271
|
+
end_line=end_line,
|
|
272
|
+
file_path=file_path,
|
|
273
|
+
canonical_id=canonical_id,
|
|
274
|
+
language=lang_name,
|
|
275
|
+
module=active_parent[-1].name if active_parent else "",
|
|
276
|
+
scope=active_parent[-1].canonical_id if active_parent else "cpp:global",
|
|
277
|
+
signature=sig,
|
|
278
|
+
parameter_count=param_count,
|
|
279
|
+
return_type=ret_type,
|
|
280
|
+
documentation=doc,
|
|
281
|
+
visibility="public",
|
|
282
|
+
)
|
|
283
|
+
)
|
|
284
|
+
exports.append(canonical_id)
|
|
285
|
+
|
|
286
|
+
scope_stack.append(ScopeContext(fn_name, "method" if is_method else "function", canonical_id, line_idx, end_line))
|
|
287
|
+
line_idx += 1
|
|
288
|
+
continue
|
|
289
|
+
|
|
290
|
+
line_idx += 1
|
|
291
|
+
|
|
292
|
+
# Second pass: C++ Web Framework Routes, Local Bindings, and Caller-to-Callee Calls
|
|
293
|
+
for line_idx, line in enumerate(lines, start=1):
|
|
294
|
+
clean = line.strip()
|
|
295
|
+
if not clean or clean.startswith("//") or clean.startswith("/*") or clean.startswith("*"):
|
|
296
|
+
continue
|
|
297
|
+
|
|
298
|
+
# Find enclosing scope
|
|
299
|
+
active_scope: ScopeContext | None = None
|
|
300
|
+
for sc in reversed(scope_stack):
|
|
301
|
+
if sc.start <= line_idx <= sc.end:
|
|
302
|
+
active_scope = sc
|
|
303
|
+
break
|
|
304
|
+
|
|
305
|
+
# 1. Crow Routes: CROW_ROUTE(app, "/api/users")
|
|
306
|
+
m_crow = crow_route_re.search(clean)
|
|
307
|
+
if m_crow:
|
|
308
|
+
route_path = m_crow.group(2)
|
|
309
|
+
handler_id = active_scope.canonical_id if active_scope else f"cpp:{file_path}:{line_idx}"
|
|
310
|
+
routes.append(
|
|
311
|
+
RouteDetection(
|
|
312
|
+
framework="crow",
|
|
313
|
+
http_method="ANY",
|
|
314
|
+
route_path=route_path,
|
|
315
|
+
normalized_route=route_path,
|
|
316
|
+
handler_name=handler_id,
|
|
317
|
+
handler_canonical_id=handler_id,
|
|
318
|
+
file_path=file_path,
|
|
319
|
+
line=line_idx,
|
|
320
|
+
confidence="HIGH",
|
|
321
|
+
evidence=f"Crow route '{route_path}' registered on line {line_idx}",
|
|
322
|
+
)
|
|
323
|
+
)
|
|
324
|
+
|
|
325
|
+
# 2. Pistache Routes: Routes::Get(router, "/api/users", Routes::bind(&Class::method))
|
|
326
|
+
m_pis = pistache_route_re.search(clean)
|
|
327
|
+
if m_pis:
|
|
328
|
+
verb = m_pis.group(1).upper()
|
|
329
|
+
route_path = m_pis.group(3)
|
|
330
|
+
handler = m_pis.group(4)
|
|
331
|
+
routes.append(
|
|
332
|
+
RouteDetection(
|
|
333
|
+
framework="pistache",
|
|
334
|
+
http_method=verb,
|
|
335
|
+
route_path=route_path,
|
|
336
|
+
normalized_route=route_path,
|
|
337
|
+
handler_name=handler,
|
|
338
|
+
handler_canonical_id=f"cpp:{handler}",
|
|
339
|
+
file_path=file_path,
|
|
340
|
+
line=line_idx,
|
|
341
|
+
confidence="HIGH",
|
|
342
|
+
evidence=f"Pistache {verb} route '{route_path}' bound to {handler}",
|
|
343
|
+
)
|
|
344
|
+
)
|
|
345
|
+
|
|
346
|
+
# 3. Drogon Routes: ADD_METHOD_TO(UserController::getUsers, "/api/users", Get)
|
|
347
|
+
m_dro = drogon_route_re.search(clean)
|
|
348
|
+
if m_dro:
|
|
349
|
+
handler = m_dro.group(1)
|
|
350
|
+
route_path = m_dro.group(2)
|
|
351
|
+
verb = m_dro.group(3).upper()
|
|
352
|
+
routes.append(
|
|
353
|
+
RouteDetection(
|
|
354
|
+
framework="drogon",
|
|
355
|
+
http_method=verb,
|
|
356
|
+
route_path=route_path,
|
|
357
|
+
normalized_route=route_path,
|
|
358
|
+
handler_name=handler,
|
|
359
|
+
handler_canonical_id=f"cpp:{handler}",
|
|
360
|
+
file_path=file_path,
|
|
361
|
+
line=line_idx,
|
|
362
|
+
confidence="HIGH",
|
|
363
|
+
evidence=f"Drogon {verb} route '{route_path}' bound to {handler}",
|
|
364
|
+
)
|
|
365
|
+
)
|
|
366
|
+
|
|
367
|
+
# 4. cpp-httplib Routes: svr.Get("/api/users", handler)
|
|
368
|
+
m_http = httplib_route_re.search(clean)
|
|
369
|
+
if m_http and m_http.group(2).upper() in ("GET", "POST", "PUT", "DELETE", "PATCH"):
|
|
370
|
+
verb = m_http.group(2).upper()
|
|
371
|
+
route_path = m_http.group(3)
|
|
372
|
+
handler = m_http.group(4).strip()
|
|
373
|
+
routes.append(
|
|
374
|
+
RouteDetection(
|
|
375
|
+
framework="cpp-httplib",
|
|
376
|
+
http_method=verb,
|
|
377
|
+
route_path=route_path,
|
|
378
|
+
normalized_route=route_path,
|
|
379
|
+
handler_name=handler,
|
|
380
|
+
handler_canonical_id=f"cpp:{handler}" if not handler.startswith("[") else (active_scope.canonical_id if active_scope else f"cpp:{file_path}:{line_idx}"),
|
|
381
|
+
file_path=file_path,
|
|
382
|
+
line=line_idx,
|
|
383
|
+
confidence="HIGH",
|
|
384
|
+
evidence=f"cpp-httplib {verb} route '{route_path}' registered on line {line_idx}",
|
|
385
|
+
)
|
|
386
|
+
)
|
|
387
|
+
|
|
388
|
+
# 5. Local variable bindings: auto x = ...
|
|
389
|
+
m_bind = binding_re.match(clean)
|
|
390
|
+
if m_bind:
|
|
391
|
+
var_name = m_bind.group(1)
|
|
392
|
+
src_expr = m_bind.group(2)
|
|
393
|
+
scope_str = active_scope.canonical_id if active_scope else "cpp:global"
|
|
394
|
+
bindings.append(
|
|
395
|
+
BindingRef(
|
|
396
|
+
target_name=var_name,
|
|
397
|
+
file_path=file_path,
|
|
398
|
+
line=line_idx,
|
|
399
|
+
scope=scope_str,
|
|
400
|
+
expr_kind="CALL" if "(" in src_expr else "IDENTIFIER",
|
|
401
|
+
source_expr=src_expr,
|
|
402
|
+
)
|
|
403
|
+
)
|
|
404
|
+
|
|
405
|
+
# 6. Caller-linked Method & Function Calls
|
|
406
|
+
# obj.method() or ptr->method()
|
|
407
|
+
call_matches = re.finditer(r"\b([a-zA-Z0-9_]+)(?:\.|\->)([a-zA-Z0-9_]+)\s*\(", clean)
|
|
408
|
+
for cm in call_matches:
|
|
409
|
+
receiver = cm.group(1)
|
|
410
|
+
callee_name = cm.group(2)
|
|
411
|
+
if receiver not in ("std", "cout", "cin", "cerr", "endl", "this"):
|
|
412
|
+
calls.append(
|
|
413
|
+
CallRef(
|
|
414
|
+
source_file=file_path,
|
|
415
|
+
callee=callee_name,
|
|
416
|
+
qualified_callee=f"{receiver}->{callee_name}",
|
|
417
|
+
line=line_idx,
|
|
418
|
+
confidence="HIGH" if active_scope else "MEDIUM",
|
|
419
|
+
caller_symbol=active_scope.name if active_scope else None,
|
|
420
|
+
caller_canonical_id=active_scope.canonical_id if active_scope else "cpp:global",
|
|
421
|
+
receiver=receiver,
|
|
422
|
+
)
|
|
423
|
+
)
|
|
424
|
+
|
|
425
|
+
# Free functions / namespace calls: ns::function()
|
|
426
|
+
ns_call_matches = re.finditer(r"\b([a-zA-Z0-9_]+)::([a-zA-Z0-9_]+)\s*\(", clean)
|
|
427
|
+
for ncm in ns_call_matches:
|
|
428
|
+
ns = ncm.group(1)
|
|
429
|
+
fn = ncm.group(2)
|
|
430
|
+
if ns not in ("std", "boost", "crow", "Routes"):
|
|
431
|
+
calls.append(
|
|
432
|
+
CallRef(
|
|
433
|
+
source_file=file_path,
|
|
434
|
+
callee=fn,
|
|
435
|
+
qualified_callee=f"{ns}::{fn}",
|
|
436
|
+
line=line_idx,
|
|
437
|
+
confidence="HIGH" if active_scope else "MEDIUM",
|
|
438
|
+
caller_symbol=active_scope.name if active_scope else None,
|
|
439
|
+
caller_canonical_id=active_scope.canonical_id if active_scope else "cpp:global",
|
|
440
|
+
receiver=ns,
|
|
441
|
+
)
|
|
442
|
+
)
|
|
443
|
+
|
|
444
|
+
return ParseResult(
|
|
445
|
+
path=file_path,
|
|
446
|
+
language=lang_name,
|
|
447
|
+
source_hash=source_hash,
|
|
448
|
+
symbols=tuple(symbols),
|
|
449
|
+
imports=tuple(imports),
|
|
450
|
+
calls=tuple(calls),
|
|
451
|
+
inheritance=tuple(inheritance),
|
|
452
|
+
routes=tuple(routes),
|
|
453
|
+
mounts=tuple(mounts),
|
|
454
|
+
bindings=tuple(bindings),
|
|
455
|
+
exports=tuple(exports),
|
|
456
|
+
parse_failed=False,
|
|
457
|
+
)
|