MCPcopy
hub / github.com/golang/protobuf / Compute

Function Compute

protoc-gen-go/generator/internal/remap/remap.go:44–59  ·  view source on GitHub ↗

Compute constructs a location mapping from input to output. An error is reported if any of the tokens of output cannot be mapped.

(input, output []byte)

Source from the content-addressed store, hash-verified

42// Compute constructs a location mapping from input to output. An error is
43// reported if any of the tokens of output cannot be mapped.
44func Compute(input, output []byte) (Map, error) {
45 itok := tokenize(input)
46 otok := tokenize(output)
47 if len(itok) != len(otok) {
48 return nil, fmt.Errorf("wrong number of tokens, %d ≠ %d", len(itok), len(otok))
49 }
50 m := make(Map)
51 for i, ti := range itok {
52 to := otok[i]
53 if ti.Token != to.Token {
54 return nil, fmt.Errorf("token %d type mismatch: %s ≠ %s", i+1, ti, to)
55 }
56 m.add(ti.pos, ti.end, to.pos, to.end)
57 }
58 return m, nil
59}
60
61// tokinfo records the span and type of a source token.
62type tokinfo struct {

Callers 3

generateMethod · 0.92
TestErrorsFunction · 0.85
TestMatchingFunction · 0.85

Calls 2

tokenizeFunction · 0.85
addMethod · 0.80

Tested by 2

TestErrorsFunction · 0.68
TestMatchingFunction · 0.68