MCPcopy
hub / github.com/google/mangle / makeDepGraph

Function makeDepGraph

analysis/stratification.go:43–71  ·  view source on GitHub ↗
(program Program)

Source from the content-addressed store, hash-verified

41}
42
43func makeDepGraph(program Program) depGraph {
44 dep := make(depGraph)
45 for _, rule := range program.Rules {
46 s := rule.Head.Predicate
47 dep.initNode(s)
48 for _, premise := range rule.Premises {
49 switch p := premise.(type) {
50 case ast.Atom:
51 if _, ok := builtin.Predicates[p.Predicate]; ok {
52 continue
53 }
54 if _, ok := program.EdbPredicates[p.Predicate]; !ok {
55 if rule.Transform == nil || rule.Transform.IsLetTransform() {
56 dep.addEdge(s, p.Predicate, false)
57 } else {
58 // Recursion through a do-transform is not permitted.
59 // We treat this as if it was a negation.
60 dep.addEdge(s, p.Predicate, true)
61 }
62 }
63 case ast.NegAtom:
64 if _, ok := program.EdbPredicates[p.Atom.Predicate]; !ok {
65 dep.addEdge(s, p.Atom.Predicate, true)
66 }
67 }
68 }
69 }
70 return dep
71}
72
73// Stratify checks whether a program can be stratified. It returns strongly-connected components
74// and a map from predicate to stratum in the affirmative case, an error otherwise.

Callers 1

StratifyFunction · 0.85

Calls 3

initNodeMethod · 0.80
IsLetTransformMethod · 0.80
addEdgeMethod · 0.80

Tested by

no test coverage detected