forked from system-pclub/GCatch
/
list_all_sync_global.go
executable file
·68 lines (55 loc) · 1.9 KB
/
list_all_sync_global.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
65
66
67
68
package prepare
import (
"github.com/system-pclub/GCatch/GFix/dispatcher/global"
"github.com/system-pclub/GCatch/GFix/dispatcher/tools/go/ssa"
"strings"
)
func List_all_sync_global(all_sync_struct []*global.Sync_struct, prog *ssa.Program) []*ssa.Global {//TODO: This function is proved to be sound by checking with etcd, but not proved to be complete
all_sync_global := *new([]*ssa.Global)
for _, pkg := range prog.AllPackages() { //loop all packages
if pkg == nil {
continue
}
//Skip builtin packages, vendor packages. Test functions are automatically skipped. Include packages in "include"
if Is_path_include(pkg.Pkg.Path()) {
} else {
continue
}
all_sync_struct_type := *new([]string)
for _,sync_struct := range all_sync_struct {
all_sync_struct_type = append(all_sync_struct_type,sync_struct.Type)
}
for _,mem := range pkg.Members { //loop through all members; the member may be a func or a type; if it is type, loop through all its methods
mem_as_global,ok := mem.(*ssa.Global)
if ok {
//This member is a global
if is_type_sync((*mem_as_global).Type().String()) {//This global is of sync type
all_sync_global = append(all_sync_global,mem_as_global)
continue
}
if is_type_sync_struct((*mem_as_global).Type().String(),all_sync_struct_type) {
all_sync_global = append(all_sync_global,mem_as_global)
continue
}
}
} // end of member loop
} //end of package loop
return all_sync_global
}
func is_type_sync_struct(str string, all_sync_struct_type []string) bool {
str = strings.ReplaceAll(str,"*","")
str = strings.ReplaceAll(str,"[]","")
for _,sync_struct_type := range all_sync_struct_type {
if strings.HasPrefix(str,sync_struct_type){
return true
}
}
if strings.Contains(str,"map[") {
for _,sync_struct_type := range all_sync_struct_type {
if strings.Contains(str,sync_struct_type){
return true
}
}
}
return false
}