...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package path
18
19 import (
20 "math/bits"
21
22 "cuelang.org/go/cue"
23 "cuelang.org/go/internal/core/adt"
24 "cuelang.org/go/internal/core/runtime"
25 )
26
27
28 func ToFeatureType(t cue.SelectorType) adt.FeatureType {
29 t = t.LabelType()
30 return adt.FeatureType(bits.Len16(uint16(t)))
31 }
32
33
34 func MakeFeature(r *runtime.Runtime, s cue.Selector) adt.Feature {
35 constraintType := s.ConstraintType()
36 labelType := s.LabelType()
37
38 if constraintType == cue.PatternConstraint {
39 switch labelType {
40 case cue.StringLabel:
41 return adt.AnyString
42 case cue.IndexLabel:
43 return adt.AnyIndex
44
45
46 case cue.DefinitionLabel:
47 return adt.AnyDefinition
48 case cue.HiddenLabel:
49 return adt.AnyHidden
50 case cue.HiddenDefinitionLabel:
51 return adt.AnyHidden
52 default:
53 panic("unreachable")
54 }
55 }
56
57 switch labelType {
58 case cue.StringLabel:
59 return adt.MakeStringLabel(r, s.Unquoted())
60
61 case cue.IndexLabel:
62 return adt.MakeIntLabel(adt.IntLabel, int64(s.Index()))
63
64 case cue.DefinitionLabel:
65 return adt.MakeNamedLabel(r, adt.DefinitionLabel, s.String())
66
67 case cue.HiddenLabel:
68 str := adt.HiddenKey(s.String(), s.PkgPath())
69 return adt.MakeNamedLabel(r, adt.HiddenLabel, str)
70
71 case cue.HiddenDefinitionLabel:
72 str := adt.HiddenKey(s.String(), s.PkgPath())
73 return adt.MakeNamedLabel(r, adt.HiddenDefinitionLabel, str)
74
75 default:
76 return adt.InvalidLabel
77 }
78 }
79
View as plain text