-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdump_resolve.go
More file actions
58 lines (47 loc) · 1.6 KB
/
dump_resolve.go
File metadata and controls
58 lines (47 loc) · 1.6 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
package protoss
import (
"slices"
"strings"
)
func resolve_package_scope(package_scope, full_name string) (scoped_name string, err error) {
if strings.HasPrefix(full_name, ".") {
// remove first dot
non_prefixed_name := full_name[1:]
// split strings
package_scope_path := strings.Split(package_scope, ".")
name_path := strings.Split(non_prefixed_name, ".")
point_of_similarity := 0
for i := 0; i < len(name_path) && i < len(package_scope_path); i++ {
partial_scope_path := strings.Join(package_scope_path[:i+1], ".")
partial_name_path := strings.Join(name_path[:i+1], ".")
if partial_scope_path == partial_name_path {
point_of_similarity = i + 1
} else {
break
}
}
// if point_of_similarity < len(name_path) {
// point_of_similarity++
// }
// if point_of_similarity == len(name_path) {
// point_of_similarity--
// }
// Don't try to resolve where there may be confusion
resolved := name_path[point_of_similarity:]
if len(resolved) > 0 && len(package_scope_path) > 0 {
if slices.Contains(package_scope_path, resolved[0]) {
return full_name, nil
}
}
scoped_name = strings.Join(name_path[point_of_similarity:], ".")
return
}
return full_name, nil
}
// if package is main.package.id
// and full name is .main.package.other.thing
// scoped_name could successfully be other.thing
// since the main.package part is already implied
func (fd *filedumper) resolve_type_name_in_scope(full_name string) (scoped_name string, err error) {
return resolve_package_scope(fd.package_scope, full_name)
}