-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrelation.go
More file actions
67 lines (57 loc) · 2.12 KB
/
Copy pathrelation.go
File metadata and controls
67 lines (57 loc) · 2.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package codegraph
import "github.com/compforge/codegraph/internal/confidence"
type RelationKind string
const (
Contains RelationKind = "contains"
Declares RelationKind = "declares"
Imports RelationKind = "imports"
Calls RelationKind = "calls"
References RelationKind = "references"
Extends RelationKind = "extends"
Implements RelationKind = "implements"
)
// Confidence describes evidence strength, not a calibrated probability.
type Confidence = confidence.Level
const (
Exact = confidence.Exact // established by supported static semantics in the supplied snapshot
Scoped = confidence.Scoped // constrained by bindings, imports, receivers or types
NameOnly = confidence.NameOnly // name match without a proven binding
Heuristic = confidence.Heuristic // convention or incomplete structural similarity
)
// Evidence records one derivation. Location, when present, points to supporting syntax.
type Evidence struct {
Basis string `json:"basis"`
Confidence Confidence `json:"confidence"`
Location *Location `json:"location,omitempty"`
}
// Relation identifies one relation at one source location, including parallel calls.
type Relation struct {
ID string `json:"id"`
Source string `json:"source"`
Target string `json:"target"`
Kind RelationKind `json:"kind"`
// Confidence is the strongest independent Evidence confidence when published.
Confidence Confidence `json:"confidence"`
Evidence []Evidence `json:"evidence"`
Location Location `json:"location"`
}
// Path lists nodes in traversal order; Relations retain their stored direction.
type Path struct {
Nodes []Node `json:"nodes"`
Relations []Relation `json:"relations"`
}
type Subgraph struct {
Nodes []Node `json:"nodes"`
Relations []Relation `json:"relations"`
}
// cloneRelation detaches both the proof list and optional supporting locations.
func cloneRelation(r Relation) Relation {
r.Evidence = append([]Evidence(nil), r.Evidence...)
for i := range r.Evidence {
if r.Evidence[i].Location != nil {
loc := *r.Evidence[i].Location
r.Evidence[i].Location = &loc
}
}
return r
}