-
Notifications
You must be signed in to change notification settings - Fork 501
/
tools.go
60 lines (54 loc) · 1.07 KB
/
tools.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
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
package lib // import "go.opentelemetry.io/contrib/instrgen/lib"
import (
"os"
"path/filepath"
)
// SearchFiles.
func SearchFiles(root string, ext string) []string {
var files []string
err := filepath.Walk(root, func(path string, info os.FileInfo, err error) error {
if filepath.Ext(path) == ext {
files = append(files, path)
}
return nil
})
if err != nil {
panic(err)
}
return files
}
func isPath(
callGraph map[FuncDescriptor][]FuncDescriptor,
current FuncDescriptor,
goal FuncDescriptor,
visited map[FuncDescriptor]bool,
) bool {
if current == goal {
return true
}
value, ok := callGraph[current]
if ok {
for _, child := range value {
exists := visited[child]
if exists {
continue
}
visited[child] = true
if isPath(callGraph, child, goal, visited) {
return true
}
}
}
return false
}
// Contains.
func Contains(a []FuncDescriptor, x FuncDescriptor) bool {
for _, n := range a {
if x.TypeHash() == n.TypeHash() {
return true
}
}
return false
}