MCPcopy Create free account
hub / github.com/google/gapid / translateMapping

Function translateMapping

gapil/bapi/bapi_test.go:85–102  ·  view source on GitHub ↗

translateMapping translates the keys of mapping from the nodes of the from API tree to their equivalent in the to API tree.

(from, to []*semantic.API, mapping *semantic.Mappings)

Source from the content-addressed store, hash-verified

83// translateMapping translates the keys of mapping from the nodes of the from
84// API tree to their equivalent in the to API tree.
85func translateMapping(from, to []*semantic.API, mapping *semantic.Mappings) {
86 out := &semantic.Mappings{}
87 remap := correlateNodes(from, to)
88 for sem, asts := range mapping.SemanticToAST {
89 if remapped, ok := remap[sem]; ok {
90 for _, ast := range asts {
91 out.Add(ast, remapped)
92 }
93 } else {
94 // If we hit this panic, we either have semantic nodes in the
95 // mapping that are not referenced by the API (which is bad), or
96 // we have nodes not being visited using semantic.Visit (which is
97 // also bad).
98 panic(fmt.Sprintf("No remap for %T %+v", sem, sem))
99 }
100 }
101 *mapping = *out
102}
103
104// correlateNodes traverses the from and to API trees to build and return a map
105// that translates all the nodes in from to to. This function requires the two

Callers 1

checkMappingsFunction · 0.85

Calls 2

AddMethod · 0.95
correlateNodesFunction · 0.85

Tested by

no test coverage detected