@codua/codeoutline-win32-x64 0.2.4 → 0.2.6

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.
@@ -0,0 +1,534 @@
1
+ -- Bounded static registrations, derived on demand; never evaluate source.
2
+ local M = {}
3
+ local control = require('codeoutline.control')
4
+ local callable = { ['function'] = true, method = true, constructor = true }
5
+
6
+ local function site_key(from, line, recv, name)
7
+ return from .. ':' .. line .. ':' .. tostring(recv) .. ':' .. tostring(name)
8
+ end
9
+
10
+ local function literal(T, i)
11
+ local s = T:text(i)
12
+ if T.k[i] == 'str' and (s:sub(1, 1) == '"' or s:sub(1, 1) == "'")
13
+ and s:sub(-1) == s:sub(1, 1) and not s:find('\\', 1, true) then return s:sub(2, -2) end
14
+ end
15
+
16
+ -- Necessary syntax only: leave scope, shadowing and registration validation to
17
+ -- the collector. Token checks work identically with native and Lua scanners.
18
+ local function has_dispatch(T, lua)
19
+ local declared, called = {}, {}
20
+ for i = 1, T.n do
21
+ if i % 4096 == 0 then control.check() end
22
+ if lua then
23
+ if T.k[i] == 'kw' and T:text(i) == 'local' then
24
+ local j = i + 1
25
+ while T.k[j] == 'id' do
26
+ if T:text(j + 1) == '=' and T:text(j + 2) == '{' then declared[T:text(j)] = true end
27
+ -- A necessary-syntax prefilter only; lexical validity is
28
+ -- checked below. Include aliases so they cannot hide sites.
29
+ if T:text(j + 1) == '=' and T.k[j + 2] == 'id' and declared[T:text(j + 2)] then
30
+ declared[T:text(j)] = true
31
+ end
32
+ if T:text(j + 1) ~= ',' then break end
33
+ j = j + 2
34
+ end
35
+ elseif T.k[i] == 'id' then
36
+ local tail
37
+ if T:text(i + 1) == '.' and T.k[i + 2] == 'id' then tail = i + 3
38
+ elseif T:text(i + 1) == '[' and T.m[i + 1] then tail = T.m[i + 1] + 1 end
39
+ if tail and T:text(tail) == '(' then called[T:text(i)] = true end
40
+ end
41
+ else
42
+ if T.k[i] == 'kw' and (T:text(i) == 'struct' or T:text(i) == 'class')
43
+ and T.k[i + 1] == 'id' and T:text(i + 2) == '{' and T.m[i + 2] then
44
+ for j = i + 3, T.m[i + 2] - 1 do
45
+ if j % 4096 == 0 then control.check() end
46
+ if T.k[j] == 'id' and T:text(j - 1) == '*' and T:text(j - 2) == '('
47
+ and T:text(j + 1) == ')' and T:text(j + 2) == '(' then declared[T:text(j)] = true end
48
+ end
49
+ elseif T.k[i] == 'id' and (T:text(i - 1) == '.' or T:text(i - 1) == '->') then
50
+ if T:text(i + 1) == '(' or T:text(i + 1) == ')' and T:text(i + 2) == '(' then
51
+ called[T:text(i)] = true
52
+ end
53
+ end
54
+ end
55
+ end
56
+ for name in pairs(declared) do if called[name] then return true end end
57
+ return false
58
+ end
59
+
60
+ function M.collect(r, T)
61
+ local lua = r.language == 'lua'
62
+ if not lua and r.language ~= 'c' and r.language ~= 'cpp' then return end
63
+ local executable
64
+ for _, node in ipairs(r.nodes) do if callable[node.kind] then executable = true; break end end
65
+ if not executable then return end
66
+ -- Reject cheap negatives before collecting compact query hints.
67
+ for i = 1, T.n do
68
+ if i % 4096 == 0 then control.check() end
69
+ local registration
70
+ if T.k[i] == 'op' and lua and T:text(i) == '=' and T.k[i + 1] == 'id' then
71
+ local prev, before = T:text(i - 1), T:text(i - 2)
72
+ registration = prev == ']' or T.k[i - 1] == 'id'
73
+ and (before == '.' or before == '{' or before == ',' or before == ';')
74
+ end
75
+ if registration or (not lua and T.k[i] == 'op' and T:text(i) == '*' and T:text(i - 1) == '(') then
76
+ r.static_dispatch_candidate = true; break
77
+ end
78
+ end
79
+ if not r.static_dispatch_candidate then return end
80
+ if not has_dispatch(T, lua) then r.static_dispatch_candidate = nil; return end
81
+ local scopes, ends, stack, owners = {}, { [0] = T.n }, {}, {}
82
+ local opens = { ['function'] = true, ['if'] = true, ['do'] = true, ['repeat'] = true }
83
+ for i = 1, T.n do
84
+ local s = T:text(i)
85
+ if lua and T.k[i] == 'kw' and (s == 'end' or s == 'until') then
86
+ local top = table.remove(stack); if top then ends[top] = i end
87
+ elseif not lua and s == '}' then table.remove(stack) end
88
+ scopes[i] = stack[#stack] or 0
89
+ if (lua and T.k[i] == 'kw' and opens[s]) or (not lua and s == '{') then
90
+ stack[#stack + 1] = i
91
+ if not lua then ends[i] = T.m[i] or T.n end
92
+ end
93
+ end
94
+ -- Only executable owners: an initializer belongs to no caller function.
95
+ local ordered = {}
96
+ for id, n in ipairs(r.nodes) do if callable[n.kind] then ordered[#ordered + 1] = id end end
97
+ table.sort(ordered, function(a, b) return r.nodes[a].ti < r.nodes[b].ti end)
98
+ local cursor = 1; stack = {}
99
+ for i = 1, T.n do
100
+ while ordered[cursor] and r.nodes[ordered[cursor]].ti <= i do
101
+ stack[#stack + 1] = ordered[cursor]; cursor = cursor + 1
102
+ end
103
+ while stack[#stack] and r.nodes[stack[#stack]].tj < i do table.remove(stack) end
104
+ owners[i] = stack[#stack] or 0
105
+ end
106
+ local data = { sites = {} }
107
+ r.static_dispatch = data
108
+ local bindings, structs = {}, {}
109
+ local function bind(name, token, scope, value)
110
+ value = value or {}
111
+ value.token, value.scope, value.finish = token, scope, ends[scope] or T.n
112
+ bindings[name] = bindings[name] or {}
113
+ for i, previous in ipairs(bindings[name]) do
114
+ if previous.token == token and previous.scope == scope then bindings[name][i] = value; return value end
115
+ end
116
+ table.insert(bindings[name], value)
117
+ return value
118
+ end
119
+ local function binding(name, token)
120
+ local best
121
+ for _, b in ipairs(bindings[name] or {}) do
122
+ if b.token <= token and b.scope <= token and b.finish >= token
123
+ and (not best or b.scope > best.scope or b.scope == best.scope and b.token > best.token) then best = b end
124
+ end
125
+ return best
126
+ end
127
+ local function function_target(name, at, depth)
128
+ depth = depth or 0
129
+ if depth > 8 then return nil end
130
+ local b = binding(name, at)
131
+ if b then
132
+ if b.alias then
133
+ if b.invalid then return nil end
134
+ return function_target(b.alias, b.token - 1, depth + 1)
135
+ end
136
+ if depth > 0 and b.invalid then return nil end
137
+ if not b.function_name then return nil end
138
+ for id, n in ipairs(r.nodes) do
139
+ if callable[n.kind] and n.name == name and n.ti == b.token then return id end
140
+ end
141
+ return nil
142
+ end
143
+ -- Alias propagation is limited to lexical locals. Global functions can
144
+ -- be replaced outside this file and have no stable local binding.
145
+ if lua and depth > 0 then return nil end
146
+ local best, best_scope
147
+ for id, n in ipairs(r.nodes) do
148
+ local scope = scopes[n.ti] or 0
149
+ if callable[n.kind] and n.name == name and n.qualified == name
150
+ and scope <= at and (ends[scope] or T.n) >= at and (not lua or n.ti < at)
151
+ and (not best_scope or scope > best_scope or scope == best_scope and n.ti > r.nodes[best].ti) then best, best_scope = id, scope end
152
+ end
153
+ return best
154
+ end
155
+ local function register(bucket, key, a, b, site)
156
+ -- Anonymous/named table functions already belong to the ordinary Lua
157
+ -- binding resolver. Do not replace those edges with an unknown slot.
158
+ if lua and T:text(a) == 'function' then bucket[key] = nil; return end
159
+ if T:text(a) == '&' then a = a + 1 end
160
+ local target = a == b and T.k[a] == 'id' and T:text(a)
161
+ local index = target and function_target(target, a)
162
+ if target and binding(target, a) and not index then target = nil end
163
+ bucket[key] = bucket[key] or {}
164
+ if lua and #bucket[key] > 0 then bucket[key].unknown = true end
165
+ if not target or (lua and not index) then bucket[key].unknown = true; return end
166
+ table.insert(bucket[key], { name = index and r.nodes[index].name or target,
167
+ index = index, line = T:line(site), from = owners[a] })
168
+ end
169
+ local function parts(a, b, separator)
170
+ local result, first, i = {}, a, a
171
+ while i <= b do
172
+ if T:text(i) == separator or lua and T:text(i) == ';' then
173
+ result[#result + 1] = { first, i - 1 }; first = i + 1
174
+ elseif T.m[i] and T.m[i] > i then i = T.m[i]
175
+ elseif lua and ends[i] then i = ends[i] end
176
+ i = i + 1
177
+ end
178
+ if first <= b then result[#result + 1] = { first, b } end
179
+ return result
180
+ end
181
+ local function lvalue_end(i)
182
+ if T.k[i] ~= 'id' then return nil end
183
+ local j = i + 1
184
+ while true do
185
+ if T:text(j) == '.' and T.k[j + 1] == 'id' then j = j + 2
186
+ elseif T:text(j) == '[' and T.m[j] then j = T.m[j] + 1
187
+ else return j end
188
+ end
189
+ end
190
+ local function assignment_end(i)
191
+ local j = lvalue_end(i)
192
+ while j and T:text(j) == ',' do j = lvalue_end(j + 1) end
193
+ return j and T:text(j) == '=' and j or nil
194
+ end
195
+ if lua then
196
+ local statement = { ['local'] = true, ['function'] = true, ['return'] = true,
197
+ ['if'] = true, ['for'] = true, ['while'] = true, ['repeat'] = true,
198
+ ['do'] = true, ['end'] = true, ['else'] = true, ['elseif'] = true,
199
+ ['until'] = true, ['break'] = true, ['goto'] = true }
200
+ local function alias_end(i)
201
+ local next = T:text(i + 1)
202
+ return next == '' or next == ';' or statement[next]
203
+ or T.l[i + 1] > T.l[i] and T.k[i + 1] == 'id'
204
+ end
205
+ -- Lexical local bindings (including unknown parameters) prevent name leaks.
206
+ for i = 1, T.n do
207
+ if T:text(i) == 'function' and T.k[i] == 'kw' then
208
+ local p = i + 1
209
+ while p <= T.n and T:text(p) ~= '(' do p = p + 1 end
210
+ for j = p + 1, (T.m[p] or p) - 1 do
211
+ if T.k[j] == 'id' then bind(T:text(j), j, i) end
212
+ end
213
+ elseif T:text(i) == 'local' and T.k[i] == 'kw' then
214
+ local j = i + 1
215
+ if T:text(j) == 'function' then
216
+ bind(T:text(j + 1), i, scopes[i], { function_name = true })
217
+ else
218
+ while T.k[j] == 'id' do
219
+ local b = bind(T:text(j), j, scopes[i])
220
+ if T:text(j + 1) == '=' and T:text(j + 2) == '{' and T.m[j + 2] then
221
+ b.slots, b.open = {}, j + 2
222
+ elseif T:text(j - 1) == 'local' and T:text(j + 1) == '='
223
+ and T.k[j + 2] == 'id' and alias_end(j + 2) then
224
+ b.alias = T:text(j + 2)
225
+ end
226
+ if T:text(j + 1) ~= ',' then break end
227
+ j = j + 2
228
+ end
229
+ end
230
+ elseif T:text(i) == 'for' and T.k[i] == 'kw' then
231
+ local first, body = i + 1, i + 1
232
+ while body <= T.n and T:text(body) ~= 'do' do
233
+ if T.m[body] and T.m[body] > body then body = T.m[body] end
234
+ body = body + 1
235
+ end
236
+ while T.k[first] == 'id' do
237
+ bind(T:text(first), first, body)
238
+ if T:text(first + 1) ~= ',' then break end
239
+ first = first + 2
240
+ end
241
+ end
242
+ end
243
+ for i = 1, T.n do
244
+ local prev = T:text(i - 1)
245
+ if T.k[i] == 'id' and prev ~= '.' and prev ~= ':' and prev ~= '{' and prev ~= ',' then
246
+ local eq = assignment_end(i)
247
+ local definition = prev == 'function' and T:text(i - 2) ~= 'local' and T:text(i + 1) == '('
248
+ if eq or definition then
249
+ local j = i
250
+ while j < (eq or i + 1) do
251
+ local tail = definition and i + 1 or lvalue_end(j)
252
+ local existing = binding(T:text(j), j)
253
+ if tail == j + 1 and existing and existing.token ~= j and prev ~= 'local' then
254
+ existing.invalid = true
255
+ bind(T:text(j), j, scopes[j])
256
+ end
257
+ j = tail + 1
258
+ end
259
+ end
260
+ end
261
+ end
262
+ -- Share registry state, not copies: writes through any alias must
263
+ -- invalidate the same slots. Resolve at the initializer's lexical point.
264
+ local function registry(b, depth)
265
+ if not b or depth > 8 then return nil end
266
+ if b.slots then return b end
267
+ if b.alias then return registry(binding(b.alias, b.token - 1), depth + 1) end
268
+ end
269
+ for _, list in pairs(bindings) do
270
+ for _, b in ipairs(list) do
271
+ if b.alias then b.registry = registry(b, 0) end
272
+ end
273
+ end
274
+ for _, list in pairs(bindings) do
275
+ for _, b in ipairs(list) do
276
+ if b.slots then
277
+ for _, span in ipairs(parts(b.open + 1, T.m[b.open] - 1, ',')) do
278
+ local a, z, key, eq = span[1], span[2]
279
+ if T.k[a] == 'id' and T:text(a + 1) == '=' then key, eq = T:text(a), a + 1
280
+ elseif T:text(a) == '[' and T.m[a] == a + 2 and T:text(a + 3) == '=' then key, eq = literal(T, a + 1), a + 3 end
281
+ if key then register(b.slots, key, eq + 1, z, a) end
282
+ end
283
+ end
284
+ end
285
+ end
286
+ else
287
+ -- Inline function-pointer declarations only; typedefs/macros need separate evidence.
288
+ for i = 1, T.n - 2 do
289
+ if (T:text(i) == 'struct' or T:text(i) == 'class') and T.k[i + 1] == 'id'
290
+ and T:text(i + 2) == '{' and T.m[i + 2] then
291
+ local fields, slots = {}, {}
292
+ for _, span in ipairs(parts(i + 3, T.m[i + 2] - 1, ';')) do
293
+ local a, z, name, pointer = span[1], span[2]
294
+ for j = a, z do
295
+ if T:text(j) == '(' and T:text(j + 1) == '*' and T.k[j + 2] == 'id'
296
+ and T:text(j + 3) == ')' and T:text(j + 4) == '(' then
297
+ name, pointer = T:text(j + 2), true; break
298
+ end
299
+ if T.k[j] == 'id' then name = T:text(j) end
300
+ end
301
+ fields[#fields + 1] = { name = name, pointer = pointer }
302
+ if pointer then slots[name] = {} end
303
+ end
304
+ local name = T:text(i + 1)
305
+ if structs[name] then structs[name].ambiguous = true
306
+ else structs[name] = { fields = fields, slots = slots } end
307
+ end
308
+ end
309
+ -- Unknown parameters/locals shadow file-scope registries and handler names.
310
+ for _, id in ipairs(ordered) do
311
+ local n = r.nodes[id]
312
+ local p = n.ti
313
+ while p <= n.tj and T:text(p) ~= '(' do p = p + 1 end
314
+ ends[n.ti] = n.tj
315
+ if T.m[p] then
316
+ for _, span in ipairs(parts(p + 1, T.m[p] - 1, ',')) do
317
+ local j = span[2]
318
+ if T.k[j] == 'id' and j > span[1] then bind(T:text(j), j, n.ti) end
319
+ end
320
+ end
321
+ end
322
+ for i = 1, T.n - 1 do
323
+ if owners[i] > 0 and T.k[i] == 'id' and (T:text(i + 1) == '=' or T:text(i + 1) == ';') then
324
+ local j = i - 1
325
+ while T:text(j) == '*' or T:text(j) == '&' do j = j - 1 end
326
+ if (T.k[j] == 'id' or T.k[j] == 'kw') and T:text(j) ~= 'return'
327
+ and (T:text(j - 1) == ';' or T:text(j - 1) == '{') then
328
+ bind(T:text(i), i, scopes[i])
329
+ end
330
+ end
331
+ end
332
+ for i = 1, T.n - 1 do
333
+ local ty = structs[T:text(i)]
334
+ if ty and not ty.ambiguous and (T.k[i] == 'id') then
335
+ local j = i + 1
336
+ while T:text(j) == '*' or T:text(j) == '&' or T:text(j) == 'const' do j = j + 1 end
337
+ if T.k[j] == 'id' and (T:text(j + 1) == '=' or T:text(j + 1) == ';'
338
+ or T:text(j + 1) == ',' or T:text(j + 1) == ')' or T:text(j + 1) == '[') then
339
+ local scope = scopes[j]
340
+ local owner = owners[j]
341
+ if owner > 0 then
342
+ local n = r.nodes[owner]
343
+ -- Parameter scopes start at the function, not the enclosing file.
344
+ if scope == scopes[n.ti] then scope = n.ti; ends[scope] = n.tj end
345
+ end
346
+ local b = bind(T:text(j), j, scope, { type = ty })
347
+ local eq = j + 1
348
+ if T:text(eq) == '[' and T.m[eq] then eq = T.m[eq] + 1; b.array = true end
349
+ if T:text(eq) == '=' and T:text(eq + 1) == '{' and T.m[eq + 1] then
350
+ local function row(a, z)
351
+ for k, span in ipairs(parts(a, z, ',')) do
352
+ local x, y, field = span[1], span[2], ty.fields[k]
353
+ if T:text(x) == '.' and T.k[x + 1] == 'id' and T:text(x + 2) == '=' then
354
+ field = { name = T:text(x + 1), pointer = ty.slots[T:text(x + 1)] ~= nil }; x = x + 3
355
+ end
356
+ if field and field.pointer then register(ty.slots, field.name, x, y, span[1]) end
357
+ end
358
+ end
359
+ if b.array then
360
+ for _, span in ipairs(parts(eq + 2, T.m[eq + 1] - 1, ',')) do
361
+ if T:text(span[1]) == '{' and T.m[span[1]] == span[2] then row(span[1] + 1, span[2] - 1) end
362
+ end
363
+ else row(eq + 2, T.m[eq + 1] - 1) end
364
+ end
365
+ end
366
+ end
367
+ end
368
+ end
369
+ for i = 1, T.n do
370
+ if i % 4096 == 0 then control.check() end
371
+ if T.k[i] ~= 'id' or T:text(i - 1) == '.' or T:text(i - 1) == '->'
372
+ or lua and T:text(i - 1) == ':' then goto continue end
373
+ local b = binding(T:text(i), i)
374
+ if not b or (not b.slots and not b.type and not b.registry) then goto continue end
375
+ if lua and T:text(i + 1) == '=' and i ~= b.token then b.invalid = true end
376
+ local key, tail, dynamic
377
+ local member = i + 1
378
+ if not lua and b.array and T:text(member) == '[' and T.m[member] then member = T.m[member] + 1 end
379
+ if T:text(member) == '.' or not lua and T:text(member) == '->' then
380
+ if T.k[member + 1] == 'id' then key, tail = T:text(member + 1), member + 2 end
381
+ elseif lua and T:text(i + 1) == '[' and T.m[i + 1] then
382
+ local close = T.m[i + 1]
383
+ key = close == i + 3 and literal(T, i + 2) or nil
384
+ tail, dynamic = close + 1, not key
385
+ end
386
+ if not tail then goto continue end
387
+ local registry = b.registry or b
388
+ local slots = registry.slots or b.type.slots
389
+ if lua and T:text(tail) == ',' then
390
+ -- A member in a multiple-assignment LHS cannot retain a proven
391
+ -- registration. Do not attempt to pair its RHS expression.
392
+ if assignment_end(i) then
393
+ if dynamic then registry.invalid = true else slots[key] = { unknown = true } end
394
+ end
395
+ elseif T:text(tail) == '=' then
396
+ if dynamic then registry.invalid = true
397
+ elseif lua or slots[key] then
398
+ local last = tail + 1
399
+ if T:text(last) == '&' then last = last + 1 end
400
+ local next = T:text(last + 1)
401
+ local simple = next == ';' or next == '' or lua and (T.l[last + 1] > T.l[last] or next == 'end')
402
+ if lua and (scopes[i] ~= registry.scope or T:text(i - 1) == ',') then slots[key] = { unknown = true }
403
+ else register(slots, key, tail + 1, simple and last or last + 1, i) end
404
+ end
405
+ elseif lua and T:text(i - 1) == 'function' then slots[key] = nil
406
+ elseif (T:text(tail) == '(' or not lua and T:text(tail) == ')' and T:text(tail + 1) == '('
407
+ and T:text(i - 1) == '*' and T:text(i - 2) == '(' and T.m[i - 2] == tail)
408
+ and owners[i] > 0 and (dynamic or slots[key]) then
409
+ data.sites[#data.sites + 1] = { from = owners[i], line = T:line(i), recv = T:text(i),
410
+ ref_recv = member == i + 1 and T:text(i) or false,
411
+ name = key, binding = b, slots = slots, dynamic = dynamic,
412
+ kind = lua and 'indirect:registry' or 'indirect:fn-pointer' }
413
+ end
414
+ ::continue::
415
+ end
416
+ -- Flatten shared temporary tables; no tokens/source survive query parsing.
417
+ for _, site in ipairs(data.sites) do
418
+ local entries = site.name and site.slots[site.name]
419
+ local b, valid, depth = site.binding, true, 0
420
+ while b do
421
+ if b.invalid or depth > 8 then valid = false; break end
422
+ depth = depth + 1
423
+ b = b.alias and binding(b.alias, b.token - 1) or nil
424
+ end
425
+ site.registrations = valid and entries and not entries.unknown and entries or {}
426
+ site.slots, site.binding = nil, nil
427
+ end
428
+ if not r.collect_static_dispatch then
429
+ local targets, members = {}, {}
430
+ for _, site in ipairs(data.sites) do
431
+ if site.name then members[site_key(site.from, site.line, site.ref_recv, site.name)] = true end
432
+ for _, registration in ipairs(site.registrations) do targets[registration.name] = true end
433
+ end
434
+ r.static_dispatch_candidate = #data.sites > 0 and { targets = targets, members = members } or nil
435
+ r.static_dispatch = nil
436
+ end
437
+ end
438
+
439
+ function M.query(G, report)
440
+ local graph = require('codeoutline.graph')
441
+ local cache, entries = {}, 0
442
+ local empty = { sites = {} }
443
+ local function data(f)
444
+ local rec = G.files[f]
445
+ if rec.static_dispatch then return rec.static_dispatch end
446
+ if not rec.static_dispatch_candidate or not G.root then return empty end
447
+ if cache[f] then return cache[f] end
448
+ local h = assert(io.open(G.root .. '/' .. rec.path, 'rb'), 'cannot read static dispatch source: ' .. rec.path)
449
+ local raw = h:read('a'); h:close()
450
+ local crc = xcompress and xcompress.crc32 and xcompress.crc32(raw) or xutils.sha256_hex(raw)
451
+ assert(#raw == rec.size and crc == rec.crc, 'source changed during query; retry: ' .. rec.path)
452
+ local source = raw
453
+ if rec.encoding ~= 'utf-8' and rec.encoding ~= 'utf-8-bom' then
454
+ source = assert(xutils.to_utf8(raw, rec.encoding == 'gbk' and 'gbk' or 'auto'))
455
+ end
456
+ local parsed = require('codeoutline.parse').parse(rec.path, source,
457
+ { ranges = false, dispatch_only = true, static_dispatch = true })
458
+ assert(#parsed.nodes == #rec.nodes, 'source encoding changed; refresh index: ' .. rec.path)
459
+ for i, n in ipairs(parsed.nodes) do
460
+ assert(n.qualified == rec.nodes[i].qualified and n.line == rec.nodes[i].line, 'source encoding changed; refresh index: ' .. rec.path)
461
+ end
462
+ local result = parsed.static_dispatch or { sites = {} }
463
+ entries = entries + 1 + #result.sites
464
+ for _, site in ipairs(result.sites) do entries = entries + #site.registrations end
465
+ assert(entries <= (M.max_query_entries or 100000), 'static dispatch query limit exceeded; narrow the project scope')
466
+ cache[f] = result
467
+ return result
468
+ end
469
+ local function scan(f, only, wanted)
470
+ local result, deps, paired = {}
471
+ for _, site in ipairs(data(f).sites) do
472
+ local src = G.id_of[f][site.from]
473
+ if not only or only == src then
474
+ local seen = {}
475
+ for _, registration in ipairs(site.registrations) do
476
+ local ids
477
+ if registration.index then ids = { G.id_of[f][registration.index] }
478
+ else
479
+ if not deps then deps, paired = graph.dependencies(G, f) end
480
+ ids = graph.resolve(G, f, G.id_of[f][registration.from], registration.name, 'call', nil, deps, paired) or {}
481
+ end
482
+ for _, id in ipairs(ids) do
483
+ if not seen[id] and (not wanted or wanted[id]) then
484
+ seen[id] = true
485
+ result[src] = result[src] or {}
486
+ result[src][#result[src] + 1] = { target = id, line = site.line, kind = site.kind }
487
+ if report then report:add({ source = src, target = id, line = site.line, kind = site.kind,
488
+ call = site.recv .. '.' .. (site.name or '?'), registered_at = G.files[f].path .. ':' .. registration.line }) end
489
+ end
490
+ end
491
+ end
492
+ if report and only and not next(seen) then report:add({ source = src, line = site.line,
493
+ call = site.recv .. '.' .. (site.name or '?'), reason = site.dynamic and 'dynamic registry key'
494
+ or 'static registration missing, overwritten or unsupported' }) end
495
+ end
496
+ end
497
+ return result
498
+ end
499
+ return {
500
+ outgoing = function(id) return scan(G.node_file[id], id)[id] or {} end,
501
+ incoming = function(wanted)
502
+ local result = {}
503
+ local names = {}
504
+ for id in pairs(wanted) do names[G.nodes[id].name] = true end
505
+ for _, f in ipairs(G.file_order) do
506
+ control.check()
507
+ local hint = G.files[f].static_dispatch_candidate
508
+ local relevant = G.files[f].static_dispatch ~= nil or hint == true
509
+ if type(hint) == 'table' then
510
+ for name in pairs(names) do if hint.targets[name] then relevant = true; break end end
511
+ end
512
+ if relevant then
513
+ for src, edges in pairs(scan(f, nil, wanted)) do result[src] = edges end
514
+ end
515
+ end
516
+ return result
517
+ end,
518
+ handles = function(f, i)
519
+ local refs = G.files[f].refs
520
+ if refs.kind[i] ~= 'member_call' then return false end
521
+ local hint = G.files[f].static_dispatch_candidate
522
+ if type(hint) == 'table' then
523
+ return hint.members[site_key(refs.from[i], refs.line[i], refs.recv[i], refs.name[i])] == true
524
+ end
525
+ for _, site in ipairs(data(f).sites) do
526
+ if site.from == refs.from[i] and site.line == refs.line[i] and site.ref_recv == refs.recv[i]
527
+ and site.name == refs.name[i] then return true end
528
+ end
529
+ return false
530
+ end,
531
+ }
532
+ end
533
+
534
+ return M
@@ -1 +1 @@
1
- return 13
1
+ return 15
@@ -1 +1 @@
1
- return '0.2.4'
1
+ return '0.2.6'