Skip to content

Commit 399ba76

Browse files
committed
internal/core/eval: export fieldSet fields
Prepare to move those to StructLit so that they can be precompiled. Change-Id: Ic4cefff516c8b18b9b3d1994396d3ca4aa11e07e Reviewed-on: https://cue-review.googlesource.com/c/cue/+/7982 Reviewed-by: Marcel van Lohuizen <[email protected]> Reviewed-by: CUE cueckoo <[email protected]>
1 parent 359685a commit 399ba76

File tree

3 files changed

+38
-38
lines changed

3 files changed

+38
-38
lines changed

internal/core/eval/closed.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -718,12 +718,12 @@ func (c *acceptor) verifySets(ctx *adt.OpContext, id adt.ID, f adt.Feature) (fou
718718
return false, false
719719
}
720720
for isRegular := f.IsRegular(); o != nil; o = o.next {
721-
if isRegular && (len(o.additional) > 0 || o.isOpen) {
721+
if isRegular && (len(o.Additional) > 0 || o.IsOpen) {
722722
return true, false
723723
}
724724

725-
for _, g := range o.fields {
726-
if f == g.label {
725+
for _, g := range o.Fields {
726+
if f == g.Label {
727727
return true, false
728728
}
729729
}
@@ -732,7 +732,7 @@ func (c *acceptor) verifySets(ctx *adt.OpContext, id adt.ID, f adt.Feature) (fou
732732
continue
733733
}
734734

735-
for _, b := range o.bulk {
735+
for _, b := range o.Bulk {
736736
if b.check.Match(ctx, o.env, f) {
737737
return true, false
738738
}

internal/core/eval/closed_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ func TestVerifyArcAllowed(t *testing.T) {
361361
fs := &fieldSet{}
362362
c.Fields = append(c.Fields, fs)
363363
for _, id := range f {
364-
fs.fields = append(fs.fields, field{label: id})
364+
fs.Fields = append(fs.Fields, FieldInfo{Label: id})
365365
}
366366
}
367367

internal/core/eval/optionals.go

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -31,52 +31,52 @@ type fieldSet struct {
3131
env *adt.Environment
3232
id adt.ID
3333

34-
// field marks the optional conjuncts of all explicit fields.
35-
// Required fields are marked as empty
36-
fields []field
34+
// field marks the optional conjuncts of all explicit Fields.
35+
// Required Fields are marked as empty
36+
Fields []FieldInfo
3737

3838
// excluded are all literal fields that already exist.
39-
bulk []bulkField
39+
Bulk []bulkField
4040

41-
additional []adt.Expr
42-
isOpen bool // has a ...
41+
Additional []adt.Expr
42+
IsOpen bool // has a ...
4343
}
4444

4545
func (o *fieldSet) OptionalTypes() (mask adt.OptionalType) {
46-
for _, f := range o.fields {
47-
if len(f.optional) > 0 {
46+
for _, f := range o.Fields {
47+
if len(f.Optional) > 0 {
4848
mask = adt.HasField
4949
break
5050
}
5151
}
52-
for _, b := range o.bulk {
52+
for _, b := range o.Bulk {
5353
if b.expr == nil {
5454
mask |= adt.HasDynamic
5555
} else {
5656
mask |= adt.HasPattern
5757
}
5858
}
59-
if o.additional != nil {
59+
if o.Additional != nil {
6060
mask |= adt.HasAdditional
6161
}
62-
if o.isOpen {
62+
if o.IsOpen {
6363
mask |= adt.IsOpen
6464
}
6565
return mask
6666
}
6767

6868
func (o *fieldSet) IsOptional(label adt.Feature) bool {
69-
for _, f := range o.fields {
70-
if f.label == label && len(f.optional) > 0 {
69+
for _, f := range o.Fields {
70+
if f.Label == label && len(f.Optional) > 0 {
7171
return true
7272
}
7373
}
7474
return false
7575
}
7676

77-
type field struct {
78-
label adt.Feature
79-
optional []adt.Node
77+
type FieldInfo struct {
78+
Label adt.Feature
79+
Optional []adt.Node
8080
}
8181

8282
type bulkField struct {
@@ -86,13 +86,13 @@ type bulkField struct {
8686
}
8787

8888
func (o *fieldSet) Accept(c *adt.OpContext, f adt.Feature) bool {
89-
if len(o.additional) > 0 {
89+
if len(o.Additional) > 0 {
9090
return true
9191
}
9292
if o.fieldIndex(f) >= 0 {
9393
return true
9494
}
95-
for _, b := range o.bulk {
95+
for _, b := range o.Bulk {
9696
if b.check.Match(c, o.env, f) {
9797
return true
9898
}
@@ -109,9 +109,9 @@ func (o *fieldSet) MatchAndInsert(c *adt.OpContext, arc *adt.Vertex) {
109109
// Match normal fields
110110
matched := false
111111
outer:
112-
for _, f := range o.fields {
113-
if f.label == arc.Label {
114-
for _, e := range f.optional {
112+
for _, f := range o.Fields {
113+
if f.Label == arc.Label {
114+
for _, e := range f.Optional {
115115
arc.AddConjunct(adt.MakeConjunct(env, e, o.id))
116116
}
117117
matched = true
@@ -129,7 +129,7 @@ outer:
129129
bulkEnv.Cycles = nil
130130

131131
// match bulk optional fields / pattern properties
132-
for _, f := range o.bulk {
132+
for _, f := range o.Bulk {
133133
if matched && f.additional {
134134
continue
135135
}
@@ -149,14 +149,14 @@ outer:
149149
addEnv.Cycles = nil
150150

151151
// match others
152-
for _, x := range o.additional {
152+
for _, x := range o.Additional {
153153
arc.AddConjunct(adt.MakeConjunct(&addEnv, x, o.id))
154154
}
155155
}
156156

157157
func (o *fieldSet) fieldIndex(f adt.Feature) int {
158-
for i := range o.fields {
159-
if o.fields[i].label == f {
158+
for i := range o.Fields {
159+
if o.Fields[i].Label == f {
160160
return i
161161
}
162162
}
@@ -165,22 +165,22 @@ func (o *fieldSet) fieldIndex(f adt.Feature) int {
165165

166166
func (o *fieldSet) MarkField(c *adt.OpContext, f adt.Feature) {
167167
if o.fieldIndex(f) < 0 {
168-
o.fields = append(o.fields, field{label: f})
168+
o.Fields = append(o.Fields, FieldInfo{Label: f})
169169
}
170170
}
171171

172172
func (o *fieldSet) AddOptional(c *adt.OpContext, x *adt.OptionalField) {
173173
p := o.fieldIndex(x.Label)
174174
if p < 0 {
175-
p = len(o.fields)
176-
o.fields = append(o.fields, field{label: x.Label})
175+
p = len(o.Fields)
176+
o.Fields = append(o.Fields, FieldInfo{Label: x.Label})
177177
}
178-
o.fields[p].optional = append(o.fields[p].optional, x)
178+
o.Fields[p].Optional = append(o.Fields[p].Optional, x)
179179
}
180180

181181
func (o *fieldSet) AddDynamic(c *adt.OpContext, x *adt.DynamicField) {
182182
// not in bulk: count as regular field?
183-
o.bulk = append(o.bulk, bulkField{dynamicMatcher{x.Key}, nil, false})
183+
o.Bulk = append(o.Bulk, bulkField{dynamicMatcher{x.Key}, nil, false})
184184
}
185185

186186
func (o *fieldSet) AddBulk(c *adt.OpContext, x *adt.BulkOptionalField) {
@@ -191,7 +191,7 @@ func (o *fieldSet) AddBulk(c *adt.OpContext, x *adt.BulkOptionalField) {
191191
}
192192

193193
if m := o.getMatcher(c, v); m != nil {
194-
o.bulk = append(o.bulk, bulkField{m, x, false})
194+
o.Bulk = append(o.Bulk, bulkField{m, x, false})
195195
}
196196
}
197197

@@ -211,10 +211,10 @@ func (o *fieldSet) getMatcher(c *adt.OpContext, v adt.Value) fieldMatcher {
211211
func (o *fieldSet) AddEllipsis(c *adt.OpContext, x *adt.Ellipsis) {
212212
expr := x.Value
213213
if x.Value == nil {
214-
o.isOpen = true
214+
o.IsOpen = true
215215
expr = &adt.Top{}
216216
}
217-
o.additional = append(o.additional, expr)
217+
o.Additional = append(o.Additional, expr)
218218
}
219219

220220
type fieldMatcher interface {

0 commit comments

Comments
 (0)