| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
package checker |
| 16 |
|
| 17 |
import ( |
| 18 |
"github.com/google/cel-go/common/types" |
| 19 |
) |
| 20 |
|
| 21 |
type mapping struct { |
| 22 |
mapping map[string]*types.Type |
| 23 |
} |
| 24 |
|
| 25 |
func newMapping() *mapping { |
| 26 |
return &mapping{ |
| 27 |
mapping: make(map[string]*types.Type), |
| 28 |
} |
| 29 |
} |
| 30 |
|
| 31 |
func (m *mapping) add(from, to *types.Type) { |
| 32 |
m.mapping[FormatCELType(from)] = to |
| 33 |
} |
| 34 |
|
| 35 |
func (m *mapping) find(from *types.Type) (*types.Type, bool) { |
| 36 |
if r, found := m.mapping[FormatCELType(from)]; found { |
| 37 |
return r, found |
| 38 |
} |
| 39 |
return nil, false |
| 40 |
} |
| 41 |
|
| 42 |
func (m *mapping) copy() *mapping { |
| 43 |
c := newMapping() |
| 44 |
|
| 45 |
for k, v := range m.mapping { |
| 46 |
c.mapping[k] = v |
| 47 |
} |
| 48 |
return c |
| 49 |
} |