devlensio 1.1.1 → 1.4.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/dist/graph/buildLookup.d.ts +30 -0
- package/dist/graph/buildLookup.js +36 -1
- package/dist/graph/edges/aliasChain.d.ts +7 -0
- package/dist/graph/edges/aliasChain.js +63 -0
- package/dist/graph/edges/aliasResolution.test.d.ts +1 -0
- package/dist/graph/edges/aliasResolution.test.js +351 -0
- package/dist/graph/edges/callEdges.js +178 -18
- package/dist/graph/edges/callEdges.test.js +119 -0
- package/dist/graph/edges/callOrder.test.d.ts +1 -0
- package/dist/graph/edges/callOrder.test.js +227 -0
- package/dist/graph/edges/importEdges.js +124 -0
- package/dist/graph/edges/propEdges.js +6 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/parser/callFlow.d.ts +15 -0
- package/dist/parser/callFlow.js +302 -0
- package/dist/parser/callOrder.test.d.ts +1 -0
- package/dist/parser/callOrder.test.js +407 -0
- package/dist/parser/declarationIds.d.ts +23 -0
- package/dist/parser/declarationIds.js +123 -0
- package/dist/parser/exportsMap.js +1 -90
- package/dist/parser/extractors/components.js +18 -28
- package/dist/parser/extractors/functions.d.ts +21 -1
- package/dist/parser/extractors/functions.js +92 -60
- package/dist/parser/extractors/moduleScope.d.ts +8 -0
- package/dist/parser/extractors/moduleScope.js +80 -0
- package/dist/parser/index.js +12 -0
- package/dist/parser/moduleScope.test.d.ts +1 -0
- package/dist/parser/moduleScope.test.js +176 -0
- package/dist/summarizer/index.js +53 -4
- package/dist/summarizer/prompts.js +111 -50
- package/dist/summarizer/prompts.test.d.ts +1 -0
- package/dist/summarizer/prompts.test.js +112 -0
- package/dist/types.d.ts +63 -0
- package/dist/version.d.ts +1 -0
- package/dist/version.js +2 -0
- package/extractors/go/bin/darwin-amd64/devlens_go_extractor +0 -0
- package/extractors/go/bin/darwin-arm64/devlens_go_extractor +0 -0
- package/extractors/go/bin/linux-amd64/devlens_go_extractor +0 -0
- package/extractors/go/bin/linux-arm64/devlens_go_extractor +0 -0
- package/extractors/go/bin/windows-amd64/devlens_go_extractor.exe +0 -0
- package/extractors/go/calls.go +131 -10
- package/extractors/go/nodes.go +29 -11
- package/extractors/go/parser.go +376 -41
- package/extractors/java/devlens_java_extractor.jar +0 -0
- package/extractors/java/src/devlens/extractor/Extractor.java +52 -12
- package/extractors/java/src/devlens/extractor/LookupMaps.java +2 -0
- package/extractors/java/src/devlens/extractor/Parser.java +420 -1
- package/extractors/java/src/devlens/extractor/edges/Calls.java +105 -5
- package/extractors/python/devlens_extractors_python/edges/calls.py +199 -36
- package/extractors/python/devlens_extractors_python/edges/imports.py +21 -1
- package/extractors/python/devlens_extractors_python/lookup.py +9 -0
- package/extractors/python/devlens_extractors_python/parser/__init__.py +11 -1
- package/extractors/python/devlens_extractors_python/parser/functions.py +199 -42
- package/extractors/rust/bin/darwin-amd64/devlens_rust_extractor +0 -0
- package/extractors/rust/bin/darwin-arm64/devlens_rust_extractor +0 -0
- package/extractors/rust/bin/linux-amd64/devlens_rust_extractor +0 -0
- package/extractors/rust/bin/linux-arm64/devlens_rust_extractor +0 -0
- package/extractors/rust/bin/windows-amd64/devlens_rust_extractor.exe +0 -0
- package/extractors/rust/src/calls.rs +114 -8
- package/extractors/rust/src/lookup.rs +66 -0
- package/extractors/rust/src/nodes.rs +29 -0
- package/extractors/rust/src/parser.rs +362 -27
- package/package.json +77 -73
package/extractors/go/parser.go
CHANGED
|
@@ -29,8 +29,37 @@ type CallSite struct {
|
|
|
29
29
|
ArgCount int // number of arguments at the call site
|
|
30
30
|
ArgTypes []string // per-arg type tags (Go type vocabulary, "unknown" when not cheaply inferable)
|
|
31
31
|
HasSpread bool // f(xs...) — variadic spread, runtime arity unknowable
|
|
32
|
+
|
|
33
|
+
// ── callOrder/v1 (docs/CALL_ORDER.md §3.1) — metadata only, never identity ──
|
|
34
|
+
Order int // 1-based lexical rank among the owner's recorded sites
|
|
35
|
+
Line int // 1-based line of the call expression
|
|
36
|
+
Col int // 0-based column, so two calls on one line stay distinct
|
|
37
|
+
Nested int // order of the enclosing call expression: outer(mid()) → 1
|
|
38
|
+
Scope string // scopeInline | scopeCallback | scopeNested | scopeModule
|
|
39
|
+
Defer string // deferTimer | deferEvent | deferOnReturn ("" = no evidence)
|
|
40
|
+
DeferDetail string // the scheduler symbol that produced Defer
|
|
41
|
+
Conc bool // go statement: may run alongside the frame
|
|
42
|
+
Repeat bool // loop body: may run 0..N times
|
|
43
|
+
Maybe bool // branch arm / block behind a terminating guard: may run 0 times
|
|
44
|
+
EarlyExit bool // Go has no `?` operator — always false; shared contract shape
|
|
32
45
|
}
|
|
33
46
|
|
|
47
|
+
// CallSite.Scope values — the execution region a site belongs to.
|
|
48
|
+
const (
|
|
49
|
+
scopeInline = "inline"
|
|
50
|
+
scopeCallback = "callback"
|
|
51
|
+
scopeNested = "nested"
|
|
52
|
+
scopeModule = "module"
|
|
53
|
+
)
|
|
54
|
+
|
|
55
|
+
// CallSite.Defer values Go can evidence. The remaining contract kinds
|
|
56
|
+
// (promise/microtask/postRender/unknown) simply stay absent for Go.
|
|
57
|
+
const (
|
|
58
|
+
deferTimer = "timer"
|
|
59
|
+
deferEvent = "event"
|
|
60
|
+
deferOnReturn = "onReturn"
|
|
61
|
+
)
|
|
62
|
+
|
|
34
63
|
type ParsedFunc struct {
|
|
35
64
|
Name string
|
|
36
65
|
IsMethod bool
|
|
@@ -81,15 +110,19 @@ type ImportSpec struct {
|
|
|
81
110
|
}
|
|
82
111
|
|
|
83
112
|
type ParsedFile struct {
|
|
84
|
-
RelPath
|
|
85
|
-
PkgName
|
|
86
|
-
|
|
113
|
+
RelPath string
|
|
114
|
+
PkgName string
|
|
115
|
+
PkgPath string // import path of the containing package (module + dir)
|
|
116
|
+
IsTest bool
|
|
87
117
|
Imports []ImportSpec
|
|
88
118
|
Funcs []*ParsedFunc
|
|
89
119
|
Structs []*ParsedStruct
|
|
90
120
|
Interfaces []*ParsedInterface
|
|
91
|
-
|
|
92
|
-
|
|
121
|
+
// FileCalls — calls in package-level VAR initializers (run at init time,
|
|
122
|
+
// owned by the FILE node). Function bodies stay on ParsedFunc.Calls.
|
|
123
|
+
FileCalls []CallSite
|
|
124
|
+
EndLine int
|
|
125
|
+
AST *ast.File // kept for go/types check (typeload.go)
|
|
93
126
|
// iota const blocks on named numeric types (enum pattern, stretch)
|
|
94
127
|
numericEnums []numericEnum
|
|
95
128
|
}
|
|
@@ -175,6 +208,7 @@ func parseFile(repoPath, rel string, pkg *ParsedPackage, addError errFn) *Parsed
|
|
|
175
208
|
pf := &ParsedFile{
|
|
176
209
|
RelPath: rel,
|
|
177
210
|
PkgName: f.Name.Name,
|
|
211
|
+
PkgPath: pkg.ImportPath,
|
|
178
212
|
IsTest: strings.HasSuffix(rel, "_test.go"),
|
|
179
213
|
AST: f,
|
|
180
214
|
}
|
|
@@ -258,6 +292,21 @@ func parseFile(repoPath, rel string, pkg *ParsedPackage, addError errFn) *Parsed
|
|
|
258
292
|
}
|
|
259
293
|
}
|
|
260
294
|
}
|
|
295
|
+
case token.VAR:
|
|
296
|
+
// Package-level initializers execute at init time — attribute
|
|
297
|
+
// their calls to the FILE node (function bodies stay on the
|
|
298
|
+
// ParsedFunc). const blocks are compile-time, no calls.
|
|
299
|
+
for _, spec := range d.Specs {
|
|
300
|
+
vs, ok := spec.(*ast.ValueSpec)
|
|
301
|
+
if !ok {
|
|
302
|
+
continue
|
|
303
|
+
}
|
|
304
|
+
for _, val := range vs.Values {
|
|
305
|
+
// ordinals continue the FILE node's sequence across every
|
|
306
|
+
// package-level var in the file
|
|
307
|
+
pf.FileCalls = append(pf.FileCalls, collectModuleCalls(fset, val, len(pf.FileCalls))...)
|
|
308
|
+
}
|
|
309
|
+
}
|
|
261
310
|
case token.CONST:
|
|
262
311
|
// Go const blocks inherit type + value from the previous spec
|
|
263
312
|
// (`Red Color = iota; Green; Blue`). Two passes: resolve names
|
|
@@ -340,7 +389,7 @@ func parseFuncDecl(fset *token.FileSet, src []byte, rel string, pkg *ParsedPacka
|
|
|
340
389
|
fn.IsTest = true
|
|
341
390
|
}
|
|
342
391
|
if d.Body != nil {
|
|
343
|
-
fn.Calls = collectCalls(d.Body)
|
|
392
|
+
fn.Calls = collectCalls(fset, d.Body)
|
|
344
393
|
}
|
|
345
394
|
return fn
|
|
346
395
|
}
|
|
@@ -362,49 +411,335 @@ func receiverTypeName(e ast.Expr) string {
|
|
|
362
411
|
return exprText(e)
|
|
363
412
|
}
|
|
364
413
|
|
|
365
|
-
//
|
|
366
|
-
|
|
367
|
-
//
|
|
368
|
-
//
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
414
|
+
// ── call collection (the only call-site walk) ──
|
|
415
|
+
|
|
416
|
+
// collectCalls — every call site of one function body, ONE RECORD PER
|
|
417
|
+
// OCCURRENCE (docs/CALL_ORDER.md §2). The recorded SET is unchanged from the
|
|
418
|
+
// pre-callOrder extractor: the walk descends into FuncLit bodies because Go has
|
|
419
|
+
// no nested func decls — a closure's calls belong to the enclosing function.
|
|
420
|
+
func collectCalls(fset *token.FileSet, body ast.Node) []CallSite {
|
|
421
|
+
w := &callWalk{
|
|
422
|
+
fset: fset,
|
|
423
|
+
inherit: callCtx{scope: scopeInline},
|
|
424
|
+
guarded: markEarlyExitGuards(body),
|
|
425
|
+
chanCb: channelCallbackVars(body),
|
|
426
|
+
}
|
|
427
|
+
w.walk(body)
|
|
428
|
+
return w.calls
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
// collectModuleCalls — calls in a package-level VAR initializer (FILE node).
|
|
432
|
+
// Closures are NOT module scope: `var h = func() { svc.Get() }` runs svc.Get
|
|
433
|
+
// when h is invoked, so the walk does not descend into FuncLit. `base` is the
|
|
434
|
+
// number of ordinals the FILE node already used.
|
|
435
|
+
func collectModuleCalls(fset *token.FileSet, root ast.Node, base int) []CallSite {
|
|
436
|
+
w := &callWalk{
|
|
437
|
+
fset: fset,
|
|
438
|
+
base: base,
|
|
439
|
+
inherit: callCtx{scope: scopeModule},
|
|
440
|
+
skipLit: true,
|
|
441
|
+
}
|
|
442
|
+
w.walk(root)
|
|
443
|
+
return w.calls
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
// callWalk — one ast.Inspect pass whose pre-order = source order, so the
|
|
447
|
+
// ordinal a site receives is its lexical rank among the owner's recorded
|
|
448
|
+
// sites. Every entered node pushes a frame (the exit callback pops it), which
|
|
449
|
+
// is how the flags of the ancestors reach the site.
|
|
450
|
+
type callWalk struct {
|
|
451
|
+
fset *token.FileSet
|
|
452
|
+
base int // ordinals already used by the owner
|
|
453
|
+
inherit callCtx // context at the root
|
|
454
|
+
guarded map[ast.Node]bool // statements behind a terminating guard
|
|
455
|
+
chanCb map[string]string // func values received from a channel
|
|
456
|
+
skipLit bool // do not descend into FuncLit (module scope)
|
|
457
|
+
stack []callFrame
|
|
458
|
+
calls []CallSite
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
// callCtx — the flags an owner region imposes on every site inside it.
|
|
462
|
+
type callCtx struct {
|
|
463
|
+
scope string
|
|
464
|
+
conc bool
|
|
465
|
+
repeat bool
|
|
466
|
+
maybe bool
|
|
467
|
+
deferKind string
|
|
468
|
+
deferDetail string
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
type callFrame struct {
|
|
472
|
+
node ast.Node
|
|
473
|
+
funcLit bool // function-literal boundary: `nested` never crosses it
|
|
474
|
+
order int // ordinal of this frame when it is a recorded call site
|
|
475
|
+
ctx callCtx
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
func (w *callWalk) walk(root ast.Node) {
|
|
479
|
+
ast.Inspect(root, func(n ast.Node) bool {
|
|
480
|
+
if n == nil {
|
|
481
|
+
w.stack = w.stack[:len(w.stack)-1]
|
|
482
|
+
return false
|
|
483
|
+
}
|
|
484
|
+
if _, isLit := n.(*ast.FuncLit); isLit && w.skipLit {
|
|
485
|
+
return false // no frame pushed — ast.Inspect sends no exit callback
|
|
486
|
+
}
|
|
487
|
+
parent := w.parent()
|
|
488
|
+
ctx := w.narrow(w.ctx(), n, parent)
|
|
489
|
+
order := 0
|
|
490
|
+
if call, ok := n.(*ast.CallExpr); ok {
|
|
491
|
+
if site := callSiteFrom(call); site != nil {
|
|
492
|
+
w.annotate(site, ctx)
|
|
493
|
+
w.calls = append(w.calls, *site)
|
|
494
|
+
order = site.Order
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
_, isLit := n.(*ast.FuncLit)
|
|
498
|
+
w.stack = append(w.stack, callFrame{node: n, funcLit: isLit, order: order, ctx: ctx})
|
|
499
|
+
return true
|
|
500
|
+
})
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
func (w *callWalk) parent() ast.Node {
|
|
504
|
+
if len(w.stack) == 0 {
|
|
505
|
+
return nil
|
|
506
|
+
}
|
|
507
|
+
return w.stack[len(w.stack)-1].node
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
func (w *callWalk) ctx() callCtx {
|
|
511
|
+
if len(w.stack) == 0 {
|
|
512
|
+
return w.inherit
|
|
513
|
+
}
|
|
514
|
+
return w.stack[len(w.stack)-1].ctx
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
// narrow — widen the inherited context for the subtree rooted at n. Only
|
|
518
|
+
// metadata changes here; the recorded set is decided by walk alone.
|
|
519
|
+
func (w *callWalk) narrow(ctx callCtx, n, parent ast.Node) callCtx {
|
|
520
|
+
switch n.(type) {
|
|
521
|
+
case *ast.FuncLit:
|
|
522
|
+
// a closure body: callback when registered, nested when declared
|
|
523
|
+
ctx.scope = funcLitScope(parent)
|
|
524
|
+
if kind, detail, ok := registrationScheduler(parent); ok {
|
|
525
|
+
ctx.deferKind, ctx.deferDetail = kind, detail
|
|
526
|
+
}
|
|
527
|
+
case *ast.GoStmt:
|
|
528
|
+
ctx.conc = true // go f() starts now — concurrent, NOT deferred
|
|
529
|
+
case *ast.DeferStmt:
|
|
530
|
+
ctx.deferKind, ctx.deferDetail = deferOnReturn, "defer"
|
|
531
|
+
case *ast.CaseClause, *ast.CommClause:
|
|
532
|
+
ctx.maybe = true // switch / type-switch / select arm
|
|
533
|
+
}
|
|
534
|
+
switch p := parent.(type) {
|
|
535
|
+
case *ast.IfStmt:
|
|
536
|
+
if p.Body == n || p.Else == n {
|
|
537
|
+
ctx.maybe = true // then arm, else arm, or an else-if chain
|
|
538
|
+
}
|
|
539
|
+
case *ast.RangeStmt:
|
|
540
|
+
if p.Body == n {
|
|
541
|
+
ctx.repeat = true // range body
|
|
542
|
+
}
|
|
543
|
+
case *ast.ForStmt:
|
|
544
|
+
if p.Body == n {
|
|
545
|
+
ctx.repeat = true // for body
|
|
546
|
+
}
|
|
547
|
+
}
|
|
548
|
+
if w.guarded[n] {
|
|
549
|
+
ctx.maybe = true // the rest of a block behind a terminating guard
|
|
550
|
+
}
|
|
551
|
+
return ctx
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
// annotate — write the callOrder/v1 fields of one recorded site.
|
|
555
|
+
func (w *callWalk) annotate(site *CallSite, ctx callCtx) {
|
|
556
|
+
pos := w.fset.Position(site.Pos)
|
|
557
|
+
site.Order = w.base + len(w.calls) + 1
|
|
558
|
+
site.Line = pos.Line
|
|
559
|
+
if pos.Column > 0 {
|
|
560
|
+
site.Col = pos.Column - 1
|
|
561
|
+
}
|
|
562
|
+
site.Scope = ctx.scope
|
|
563
|
+
if site.Scope == "" {
|
|
564
|
+
site.Scope = scopeInline
|
|
565
|
+
}
|
|
566
|
+
site.Conc = ctx.conc
|
|
567
|
+
site.Repeat = ctx.repeat
|
|
568
|
+
site.Maybe = ctx.maybe
|
|
569
|
+
site.Defer = ctx.deferKind
|
|
570
|
+
site.DeferDetail = ctx.deferDetail
|
|
571
|
+
|
|
572
|
+
// the nearest enclosing call expression, without crossing a closure: the
|
|
573
|
+
// calls of a callback passed to foo() are not evaluated as part of foo()
|
|
574
|
+
for i := len(w.stack) - 1; i >= 0; i-- {
|
|
575
|
+
f := w.stack[i]
|
|
576
|
+
if f.funcLit {
|
|
577
|
+
break
|
|
578
|
+
}
|
|
579
|
+
if f.order > 0 {
|
|
580
|
+
site.Nested = f.order
|
|
581
|
+
break
|
|
582
|
+
}
|
|
583
|
+
}
|
|
584
|
+
|
|
585
|
+
// a func value that arrived over a channel is registered externally
|
|
586
|
+
if site.Defer == "" && !site.IsSel {
|
|
587
|
+
if ch, ok := w.chanCb[site.Str]; ok {
|
|
588
|
+
site.Defer, site.DeferDetail = deferEvent, "<-"+ch
|
|
589
|
+
}
|
|
590
|
+
}
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
// funcLitScope — a closure body's scope: passed to a call (or dispatched by go
|
|
594
|
+
// / defer) is a callback; a variable initializer or any other position is a
|
|
595
|
+
// function declared inside the owner, i.e. "nested".
|
|
596
|
+
func funcLitScope(parent ast.Node) string {
|
|
597
|
+
switch parent.(type) {
|
|
598
|
+
case *ast.CallExpr, *ast.GoStmt, *ast.DeferStmt:
|
|
599
|
+
return scopeCallback
|
|
600
|
+
}
|
|
601
|
+
return scopeNested
|
|
602
|
+
}
|
|
603
|
+
|
|
604
|
+
// registrationScheduler — the call that receives this closure, when it is a
|
|
605
|
+
// scheduler the contract knows about (docs/CALL_ORDER.md §4.2).
|
|
606
|
+
func registrationScheduler(parent ast.Node) (string, string, bool) {
|
|
607
|
+
call, ok := parent.(*ast.CallExpr)
|
|
608
|
+
if !ok {
|
|
609
|
+
return "", "", false
|
|
610
|
+
}
|
|
611
|
+
text := exprText(call.Fun)
|
|
612
|
+
if text == "time.AfterFunc" || strings.HasSuffix(text, ".AfterFunc") {
|
|
613
|
+
return deferTimer, text, true
|
|
614
|
+
}
|
|
615
|
+
return "", "", false
|
|
616
|
+
}
|
|
617
|
+
|
|
618
|
+
// markEarlyExitGuards — the Go diamond `if err != nil { return }`: the rest of
|
|
619
|
+
// the block only runs when the guard did not fire, so its calls are `maybe`.
|
|
620
|
+
func markEarlyExitGuards(root ast.Node) map[ast.Node]bool {
|
|
621
|
+
guarded := map[ast.Node]bool{}
|
|
622
|
+
ast.Inspect(root, func(n ast.Node) bool {
|
|
623
|
+
block, ok := n.(*ast.BlockStmt)
|
|
373
624
|
if !ok {
|
|
374
625
|
return true
|
|
375
626
|
}
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
627
|
+
for i, stmt := range block.List {
|
|
628
|
+
if !terminatingGuard(stmt) {
|
|
629
|
+
continue
|
|
630
|
+
}
|
|
631
|
+
for _, rest := range block.List[i+1:] {
|
|
632
|
+
guarded[rest] = true
|
|
633
|
+
}
|
|
634
|
+
break
|
|
381
635
|
}
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
636
|
+
return true
|
|
637
|
+
})
|
|
638
|
+
return guarded
|
|
639
|
+
}
|
|
640
|
+
|
|
641
|
+
func terminatingGuard(stmt ast.Stmt) bool {
|
|
642
|
+
guard, ok := stmt.(*ast.IfStmt)
|
|
643
|
+
if !ok || guard.Else != nil {
|
|
644
|
+
return false
|
|
645
|
+
}
|
|
646
|
+
return terminates(guard.Body)
|
|
647
|
+
}
|
|
648
|
+
|
|
649
|
+
// terminates — the block always leaves the enclosing block (return, break,
|
|
650
|
+
// continue, goto, or a panic-style call).
|
|
651
|
+
func terminates(block *ast.BlockStmt) bool {
|
|
652
|
+
if block == nil || len(block.List) == 0 {
|
|
653
|
+
return false
|
|
654
|
+
}
|
|
655
|
+
switch last := block.List[len(block.List)-1].(type) {
|
|
656
|
+
case *ast.ReturnStmt, *ast.BranchStmt:
|
|
657
|
+
return true
|
|
658
|
+
case *ast.ExprStmt:
|
|
659
|
+
call, ok := last.X.(*ast.CallExpr)
|
|
660
|
+
if !ok {
|
|
661
|
+
return false
|
|
662
|
+
}
|
|
663
|
+
name := exprText(call.Fun)
|
|
664
|
+
if i := strings.LastIndex(name, "."); i >= 0 {
|
|
665
|
+
name = name[i+1:]
|
|
388
666
|
}
|
|
389
|
-
switch
|
|
390
|
-
case
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
667
|
+
switch name {
|
|
668
|
+
case "panic", "Fatal", "Fatalf", "Fatalln", "Exit", "Goexit":
|
|
669
|
+
return true
|
|
670
|
+
}
|
|
671
|
+
}
|
|
672
|
+
return false
|
|
673
|
+
}
|
|
674
|
+
|
|
675
|
+
// channelCallbackVars — `cb := <-cbCh`: a func value that arrives over a
|
|
676
|
+
// channel is triggered from outside the frame, so calling it is `defer:event`
|
|
677
|
+
// (the contract's "channel consumer", docs/CALL_ORDER.md §4.2).
|
|
678
|
+
func channelCallbackVars(root ast.Node) map[string]string {
|
|
679
|
+
vars := map[string]string{}
|
|
680
|
+
ast.Inspect(root, func(n ast.Node) bool {
|
|
681
|
+
switch s := n.(type) {
|
|
682
|
+
case *ast.AssignStmt:
|
|
683
|
+
if len(s.Lhs) == 1 && len(s.Rhs) == 1 {
|
|
684
|
+
addChannelVar(vars, s.Lhs[0], s.Rhs[0])
|
|
685
|
+
}
|
|
686
|
+
case *ast.ValueSpec:
|
|
687
|
+
for i, name := range s.Names {
|
|
688
|
+
if i < len(s.Values) {
|
|
689
|
+
addChannelVar(vars, name, s.Values[i])
|
|
690
|
+
}
|
|
691
|
+
}
|
|
404
692
|
}
|
|
405
693
|
return true
|
|
406
694
|
})
|
|
407
|
-
return
|
|
695
|
+
return vars
|
|
696
|
+
}
|
|
697
|
+
|
|
698
|
+
func addChannelVar(vars map[string]string, target, value ast.Expr) {
|
|
699
|
+
id, ok := target.(*ast.Ident)
|
|
700
|
+
if !ok {
|
|
701
|
+
return
|
|
702
|
+
}
|
|
703
|
+
recv, ok := value.(*ast.UnaryExpr)
|
|
704
|
+
if !ok || recv.Op != token.ARROW {
|
|
705
|
+
return
|
|
706
|
+
}
|
|
707
|
+
vars[id.Name] = exprText(recv.X)
|
|
708
|
+
}
|
|
709
|
+
|
|
710
|
+
// callSiteFrom — one CallExpr → CallSite (nil for inline func-literal
|
|
711
|
+
// invocation, which has no symbol to resolve). Each call records its argument
|
|
712
|
+
// shape (count, cheap type tags, spread) for arity-aware CALLS resolution.
|
|
713
|
+
func callSiteFrom(call *ast.CallExpr) *CallSite {
|
|
714
|
+
argCount := len(call.Args)
|
|
715
|
+
hasSpread := call.Ellipsis != token.NoPos
|
|
716
|
+
argTypes := make([]string, 0, argCount)
|
|
717
|
+
for _, arg := range call.Args {
|
|
718
|
+
argTypes = append(argTypes, argTypeTag(arg))
|
|
719
|
+
}
|
|
720
|
+
fun := call.Fun
|
|
721
|
+
// unwrap generic calls: f[T](...)
|
|
722
|
+
if idx, ok := fun.(*ast.IndexExpr); ok {
|
|
723
|
+
fun = idx.X
|
|
724
|
+
} else if idx, ok := fun.(*ast.IndexListExpr); ok {
|
|
725
|
+
fun = idx.X
|
|
726
|
+
}
|
|
727
|
+
switch f := fun.(type) {
|
|
728
|
+
case *ast.Ident:
|
|
729
|
+
return &CallSite{Str: f.Name, Node: f, Pos: call.Pos(), ArgCount: argCount, ArgTypes: argTypes, HasSpread: hasSpread}
|
|
730
|
+
case *ast.SelectorExpr:
|
|
731
|
+
return &CallSite{
|
|
732
|
+
Str: exprText(f),
|
|
733
|
+
Sel: f.Sel.Name,
|
|
734
|
+
Receiver: identName(f.X), // root ident survives call chains: DB.Model(...).Updates → "DB"
|
|
735
|
+
IsSel: true,
|
|
736
|
+
Node: f,
|
|
737
|
+
Pos: call.Pos(),
|
|
738
|
+
ArgCount: argCount, ArgTypes: argTypes, HasSpread: hasSpread,
|
|
739
|
+
}
|
|
740
|
+
}
|
|
741
|
+
// inline anonymous invocation — no symbol to resolve
|
|
742
|
+
return nil
|
|
408
743
|
}
|
|
409
744
|
|
|
410
745
|
// argTypeTag — cheap per-argument type tag in Go's own vocabulary: literals
|
|
Binary file
|
|
@@ -97,9 +97,18 @@ public final class Extractor {
|
|
|
97
97
|
|
|
98
98
|
// ── 2. build nodes + call facts ─────────────────────────────────
|
|
99
99
|
for (Parser.ParsedFile pf : parsedFiles) {
|
|
100
|
-
|
|
100
|
+
Map<String, Object> fileNode =
|
|
101
|
+
Contract.fileNode(pf.relPath, pf.endLine, pf.isTest ? "TEST" : "FILE", LANGUAGE);
|
|
102
|
+
if (!pf.isTest && !pf.fileCalls.isEmpty()) {
|
|
103
|
+
// Module-scope facts — same shape as METHOD metadata.
|
|
104
|
+
@SuppressWarnings("unchecked")
|
|
105
|
+
Map<String, Object> fmeta = (Map<String, Object>) fileNode.get("metadata");
|
|
106
|
+
fmeta.put("calls", pf.fileCalls.stream().map(c -> c.name).distinct().sorted().toList());
|
|
107
|
+
fmeta.put("callSites", callSitesOf(pf.fileCalls));
|
|
108
|
+
}
|
|
109
|
+
nodes.add(fileNode);
|
|
101
110
|
if (pf.isTest) {
|
|
102
|
-
continue;
|
|
111
|
+
continue;
|
|
103
112
|
}
|
|
104
113
|
List<String> childIds = new ArrayList<>();
|
|
105
114
|
for (Parser.TypeInfo t : pf.allTypes()) {
|
|
@@ -134,6 +143,11 @@ public final class Extractor {
|
|
|
134
143
|
// ── 3. shared lookup (built ONCE, consumed by every detector) ───
|
|
135
144
|
LookupMaps lookup = LookupMaps.build(parsedFiles, nodes);
|
|
136
145
|
lookup.methodCallFacts.putAll(methodCallFacts);
|
|
146
|
+
for (Parser.ParsedFile pf : parsedFiles) {
|
|
147
|
+
if (!pf.isTest && !pf.fileCalls.isEmpty()) {
|
|
148
|
+
lookup.fileCallFacts.put("file::" + pf.relPath, pf.fileCalls);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
137
151
|
lookup.testCases.putAll(testCases);
|
|
138
152
|
ThirdParty tp = new ThirdParty(fp.rawDependencies, allowedThirdPartyLibs);
|
|
139
153
|
|
|
@@ -271,17 +285,14 @@ public final class Extractor {
|
|
|
271
285
|
}
|
|
272
286
|
|
|
273
287
|
/**
|
|
274
|
-
* Structured call-site records
|
|
275
|
-
*
|
|
276
|
-
*
|
|
288
|
+
* Structured call-site records mirroring metadata.callSites in the
|
|
289
|
+
* TypeScript engine — ONE RECORD PER OCCURRENCE since callOrder/v1, so
|
|
290
|
+
* `order` is the node's lexical call sequence. No shape de-duplication and
|
|
291
|
+
* no reordering: the list is already in `order` (pre-order walk).
|
|
277
292
|
*/
|
|
278
293
|
private static List<Map<String, Object>> callSitesOf(List<Parser.CallInfo> calls) {
|
|
279
|
-
|
|
294
|
+
List<Map<String, Object>> out = new ArrayList<>();
|
|
280
295
|
for (Parser.CallInfo ci : calls) {
|
|
281
|
-
String key = ci.name + "/" + ci.argCount + "/" + String.join(",", ci.argTypes);
|
|
282
|
-
if (out.containsKey(key)) {
|
|
283
|
-
continue;
|
|
284
|
-
}
|
|
285
296
|
Map<String, Object> cs = new LinkedHashMap<>();
|
|
286
297
|
cs.put("name", ci.name);
|
|
287
298
|
cs.put("argCount", ci.argCount);
|
|
@@ -289,8 +300,37 @@ public final class Extractor {
|
|
|
289
300
|
if (ci.hasSpread) {
|
|
290
301
|
cs.put("hasSpread", true);
|
|
291
302
|
}
|
|
292
|
-
|
|
303
|
+
cs.put("kind", "call"); // Java records no hooks
|
|
304
|
+
cs.put("order", ci.order);
|
|
305
|
+
cs.put("line", ci.line);
|
|
306
|
+
cs.put("col", ci.col);
|
|
307
|
+
if (ci.nested != null) {
|
|
308
|
+
cs.put("nested", ci.nested);
|
|
309
|
+
}
|
|
310
|
+
cs.put("scope", ci.scope);
|
|
311
|
+
if (ci.awaited) {
|
|
312
|
+
cs.put("awaited", true);
|
|
313
|
+
}
|
|
314
|
+
if (ci.defer != null) {
|
|
315
|
+
cs.put("defer", ci.defer);
|
|
316
|
+
}
|
|
317
|
+
if (ci.deferDetail != null) {
|
|
318
|
+
cs.put("deferDetail", ci.deferDetail);
|
|
319
|
+
}
|
|
320
|
+
if (ci.conc) {
|
|
321
|
+
cs.put("conc", true);
|
|
322
|
+
}
|
|
323
|
+
if (ci.repeat) {
|
|
324
|
+
cs.put("repeat", true);
|
|
325
|
+
}
|
|
326
|
+
if (ci.maybe) {
|
|
327
|
+
cs.put("maybe", true);
|
|
328
|
+
}
|
|
329
|
+
if (ci.earlyExit) {
|
|
330
|
+
cs.put("earlyExit", true);
|
|
331
|
+
}
|
|
332
|
+
out.add(cs);
|
|
293
333
|
}
|
|
294
|
-
return
|
|
334
|
+
return out;
|
|
295
335
|
}
|
|
296
336
|
}
|
|
@@ -32,6 +32,8 @@ public final class LookupMaps {
|
|
|
32
32
|
public final Map<String, List<String>> methodOverloads = new LinkedHashMap<>();
|
|
33
33
|
/** method node id → parse-time call facts (CallInfo) */
|
|
34
34
|
public final Map<String, List<Parser.CallInfo>> methodCallFacts = new LinkedHashMap<>();
|
|
35
|
+
/** FILE node id → call facts from field initializers + { } blocks */
|
|
36
|
+
public final Map<String, List<Parser.CallInfo>> fileCallFacts = new LinkedHashMap<>();
|
|
35
37
|
/** test file relPath → test method names (metadata.testCases) */
|
|
36
38
|
public final Map<String, List<String>> testCases = new HashMap<>();
|
|
37
39
|
|