forked from ceph/go-ceph
/
inspector.go
64 lines (56 loc) · 1.42 KB
/
inspector.go
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
package implements
import (
"strings"
)
type foundFlags int
const (
isCalled = foundFlags(1)
isDocumented = foundFlags(2)
isDeprecated = foundFlags(4)
)
// Inspector types collect the high-level results from C and Go
// code scans.
type Inspector struct {
visitor *visitor
expected CFunctions
found map[string]foundFlags
deprecatedMissing int
}
// SetExpected sets the expected C functions, asuming the supplied prefix.
func (ii *Inspector) SetExpected(prefix string, expected CFunctions) error {
ii.expected = make([]CFunction, 0, len(expected))
for _, cfunc := range expected {
if strings.HasPrefix(cfunc.Name, prefix) {
logger.Printf("C function \"%s\" has matching prefix", cfunc.Name)
ii.expected = append(ii.expected, cfunc)
}
}
_, err := ii.expected.ensure()
return err
}
func (ii *Inspector) update() {
ii.found = map[string]foundFlags{}
ii.deprecatedMissing = 0
for i := range ii.expected {
n := ii.expected[i].Name
if _, found := ii.visitor.callMap[n]; found {
ii.found[n] |= isCalled
}
if _, found := ii.visitor.docMap[n]; found {
ii.found[n] |= isDocumented
}
if ii.expected[i].isDeprecated() {
if _, found := ii.found[n]; found {
ii.found[n] |= isDeprecated
} else {
ii.deprecatedMissing++
}
}
}
}
// NewInspector returns a newly created code inspector object.
func NewInspector() *Inspector {
return &Inspector{
visitor: newVisitor(),
}
}