Skip to content

Commit 41afc87

Browse files
committed
internal/core/adt: automatic renaming
This is the last step to make List- and StructMarker a type different from Value and Expr. Rename: Vertex.Value -> Vertex.BaseValue Vertex.ActualValue() -> Vertex.Value() This generated changes should be used as a last manual check that the values are used correctly. Issue #598 Change-Id: Iadb8eb6d782099cbba4deb7cf99f129ce0363371 Reviewed-on: https://cue-review.googlesource.com/c/cue/+/7766 Reviewed-by: Tony Worm <[email protected]> Reviewed-by: Marcel van Lohuizen <[email protected]> Reviewed-by: CUE cueckoo <[email protected]>
1 parent 08a1652 commit 41afc87

File tree

25 files changed

+128
-128
lines changed

25 files changed

+128
-128
lines changed

cue/context.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ func (v Value) eval(ctx *context) adt.Value {
7676
panic("undefined value")
7777
}
7878
x := ctx.manifest(v.v)
79-
return x.ActualValue()
79+
return x.Value()
8080
}
8181

8282
// func (v Value) evalFull(u value) (Value, adt.Value) {

cue/load/config.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -536,12 +536,12 @@ func (c Config) complete() (cfg *Config, err error) {
536536
v.Finalize(ctx)
537537
prefix := v.Lookup(ctx.StringLabel("module"))
538538
if prefix != nil {
539-
name := ctx.StringValue(prefix.ActualValue())
539+
name := ctx.StringValue(prefix.Value())
540540
if err := ctx.Err(); err != nil {
541541
return &c, err.Err
542542
}
543543
pos := token.NoPos
544-
src := prefix.ActualValue().Source()
544+
src := prefix.Value().Source()
545545
if src != nil {
546546
pos = src.Pos()
547547
}

cue/types.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,7 @@ type Value struct {
565565
}
566566

567567
func newErrValue(v Value, b *adt.Bottom) Value {
568-
node := &adt.Vertex{Value: b}
568+
node := &adt.Vertex{BaseValue: b}
569569
if v.v != nil {
570570
node.Label = v.v.Label
571571
node.Parent = v.v.Parent
@@ -635,9 +635,9 @@ func MakeValue(ctx *adt.OpContext, v adt.Value) Value {
635635
}
636636

637637
func makeValue(idx *index, v *adt.Vertex) Value {
638-
if v.Status() == 0 || v.Value == nil {
638+
if v.Status() == 0 || v.BaseValue == nil {
639639
panic(fmt.Sprintf("not properly initialized (state: %v, value: %T)",
640-
v.Status(), v.Value))
640+
v.Status(), v.BaseValue))
641641
}
642642
return Value{idx, v}
643643
}
@@ -656,7 +656,7 @@ func remakeValue(base Value, env *adt.Environment, v adt.Expr) Value {
656656
}
657657

658658
func remakeFinal(base Value, env *adt.Environment, v adt.Value) Value {
659-
n := &adt.Vertex{Parent: base.v.Parent, Label: base.v.Label, Value: v}
659+
n := &adt.Vertex{Parent: base.v.Parent, Label: base.v.Label, BaseValue: v}
660660
n.UpdateStatus(adt.Finalized)
661661
return makeValue(base.idx, n)
662662
}
@@ -843,7 +843,7 @@ func (v Value) Kind() Kind {
843843
if v.v == nil {
844844
return BottomKind
845845
}
846-
c := v.v.Value
846+
c := v.v.BaseValue
847847
if !v.v.IsConcrete() {
848848
return BottomKind
849849
}
@@ -1061,7 +1061,7 @@ func (v Value) Source() ast.Node {
10611061
if len(v.v.Conjuncts) == 1 {
10621062
return v.v.Conjuncts[0].Source()
10631063
}
1064-
return v.v.ActualValue().Source()
1064+
return v.v.Value().Source()
10651065
}
10661066

10671067
// Err returns the error represented by v or nil v is not an error.
@@ -1100,7 +1100,7 @@ func (v Value) IsConcrete() bool {
11001100
if v.v == nil {
11011101
return false // any is neither concrete, not a list or struct.
11021102
}
1103-
if b, ok := v.v.Value.(*adt.Bottom); ok {
1103+
if b, ok := v.v.BaseValue.(*adt.Bottom); ok {
11041104
return !b.IsIncomplete()
11051105
}
11061106
if !adt.IsConcrete(v.v) {
@@ -1125,7 +1125,7 @@ func (v Value) Exists() bool {
11251125
if v.v == nil {
11261126
return false
11271127
}
1128-
if err, ok := v.v.Value.(*adt.Bottom); ok {
1128+
if err, ok := v.v.BaseValue.(*adt.Bottom); ok {
11291129
return err.Code != codeNotExist
11301130
}
11311131
return true
@@ -2164,15 +2164,15 @@ func (v Value) Expr() (Op, []Value) {
21642164
var env *adt.Environment
21652165

21662166
if v.v.IsData() {
2167-
expr = v.v.ActualValue()
2167+
expr = v.v.Value()
21682168

21692169
} else {
21702170
switch len(v.v.Conjuncts) {
21712171
case 0:
2172-
if v.v.Value == nil {
2172+
if v.v.BaseValue == nil {
21732173
return NoOp, []Value{makeValue(v.idx, v.v)}
21742174
}
2175-
expr = v.v.ActualValue()
2175+
expr = v.v.Value()
21762176

21772177
case 1:
21782178
// the default case, processed below.

cue/types_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2499,7 +2499,7 @@ func TestWalk(t *testing.T) {
24992499
case ListKind:
25002500
buf = append(buf, '[')
25012501
default:
2502-
if b, _ := v.v.Value.(*adt.Bottom); b != nil {
2502+
if b, _ := v.v.BaseValue.(*adt.Bottom); b != nil {
25032503
s := debugStr(v.ctx(), b)
25042504
buf = append(buf, fmt.Sprint(s, ",")...)
25052505
return true

internal/core/adt/adt.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ func Pos(n Node) token.Pos {
144144

145145
func (x *Vertex) Concreteness() Concreteness {
146146
// Depends on concreteness of value.
147-
switch v := x.Value.(type) {
147+
switch v := x.BaseValue.(type) {
148148
case nil:
149149
return Concrete // Should be indetermined.
150150

internal/core/adt/composite.go

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -178,9 +178,9 @@ type Vertex struct {
178178
// SelfCount is used for tracking self-references.
179179
SelfCount int
180180

181-
// Value is the value associated with this vertex. For lists and structs
181+
// BaseValue is the value associated with this vertex. For lists and structs
182182
// this is a sentinel value indicating its kind.
183-
Value BaseValue
183+
BaseValue BaseValue
184184

185185
// ChildErrors is the collection of all errors of children.
186186
ChildErrors *Bottom
@@ -249,25 +249,25 @@ func (v *Vertex) UpdateStatus(s VertexStatus) {
249249
if v.status > s+1 {
250250
panic(fmt.Sprintf("attempt to regress status from %d to %d", v.Status(), s))
251251
}
252-
if s == Finalized && v.Value == nil {
252+
if s == Finalized && v.BaseValue == nil {
253253
// panic("not finalized")
254254
}
255255
v.status = s
256256
}
257257

258-
// ActualValue returns the Value of v without definitions if it is a scalar
258+
// Value returns the Value of v without definitions if it is a scalar
259259
// or itself otherwise.
260-
func (v *Vertex) ActualValue() Value {
260+
func (v *Vertex) Value() Value {
261261
// TODO: rename to Value.
262-
switch x := v.Value.(type) {
262+
switch x := v.BaseValue.(type) {
263263
case nil:
264264
return nil
265265
case *StructMarker, *ListMarker:
266266
return v
267267
case Value:
268268
return x
269269
default:
270-
panic(fmt.Sprintf("unexpected type %T", v.Value))
270+
panic(fmt.Sprintf("unexpected type %T", v.BaseValue))
271271
}
272272
}
273273

@@ -302,7 +302,7 @@ func (v *Vertex) ToDataAll() *Vertex {
302302
}
303303
w := *v
304304

305-
w.Value = toDataAll(w.Value)
305+
w.BaseValue = toDataAll(w.BaseValue)
306306
w.Arcs = arcs
307307
w.isData = true
308308
w.Conjuncts = make([]Conjunct, len(v.Conjuncts))
@@ -352,7 +352,7 @@ func toDataAll(v BaseValue) BaseValue {
352352

353353
func (v *Vertex) IsErr() bool {
354354
// if v.Status() > Evaluating {
355-
if _, ok := v.Value.(*Bottom); ok {
355+
if _, ok := v.BaseValue.(*Bottom); ok {
356356
return true
357357
}
358358
// }
@@ -361,7 +361,7 @@ func (v *Vertex) IsErr() bool {
361361

362362
func (v *Vertex) Err(c *OpContext, state VertexStatus) *Bottom {
363363
c.Unify(c, v, state)
364-
if b, ok := v.Value.(*Bottom); ok {
364+
if b, ok := v.BaseValue.(*Bottom); ok {
365365
return b
366366
}
367367
return nil
@@ -374,12 +374,12 @@ func (v *Vertex) Finalize(c *OpContext) {
374374
}
375375

376376
func (v *Vertex) AddErr(ctx *OpContext, b *Bottom) {
377-
v.Value = CombineErrors(nil, v.ActualValue(), b)
377+
v.BaseValue = CombineErrors(nil, v.Value(), b)
378378
v.UpdateStatus(Finalized)
379379
}
380380

381381
func (v *Vertex) SetValue(ctx *OpContext, state VertexStatus, value BaseValue) *Bottom {
382-
v.Value = value
382+
v.BaseValue = value
383383
v.UpdateStatus(state)
384384
return nil
385385
}
@@ -391,8 +391,8 @@ func ToVertex(v Value) *Vertex {
391391
return x
392392
default:
393393
n := &Vertex{
394-
status: Finalized,
395-
Value: x,
394+
status: Finalized,
395+
BaseValue: x,
396396
}
397397
n.AddConjunct(MakeRootConjunct(nil, v))
398398
return n
@@ -406,7 +406,7 @@ func Unwrap(v Value) Value {
406406
if !ok {
407407
return v
408408
}
409-
return x.ActualValue()
409+
return x.Value()
410410
}
411411

412412
// Acceptor is a single interface that reports whether feature f is a valid
@@ -443,10 +443,10 @@ const (
443443
func (v *Vertex) Kind() Kind {
444444
// This is possible when evaluating comprehensions. It is potentially
445445
// not known at this time what the type is.
446-
if v.Value == nil {
446+
if v.BaseValue == nil {
447447
return TopKind
448448
}
449-
return v.Value.Kind()
449+
return v.BaseValue.Kind()
450450
}
451451

452452
func (v *Vertex) OptionalTypes() OptionalType {
@@ -461,7 +461,7 @@ func (v *Vertex) OptionalTypes() OptionalType {
461461
}
462462

463463
func (v *Vertex) IsClosed(ctx *OpContext) bool {
464-
switch x := v.Value.(type) {
464+
switch x := v.BaseValue.(type) {
465465
case *ListMarker:
466466
// TODO: use one mechanism.
467467
if x.IsOpen {
@@ -505,7 +505,7 @@ func (v *Vertex) MatchAndInsert(ctx *OpContext, arc *Vertex) {
505505
}
506506

507507
func (v *Vertex) IsList() bool {
508-
_, ok := v.Value.(*ListMarker)
508+
_, ok := v.BaseValue.(*ListMarker)
509509
return ok
510510
}
511511

@@ -547,7 +547,7 @@ func (v *Vertex) Source() ast.Node { return nil }
547547

548548
// AddConjunct adds the given Conjuncts to v if it doesn't already exist.
549549
func (v *Vertex) AddConjunct(c Conjunct) *Bottom {
550-
if v.Value != nil {
550+
if v.BaseValue != nil {
551551
// TODO: investigate why this happens at all. Removing it seems to
552552
// change the order of fields in some cases.
553553
//

internal/core/adt/context.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ func (c *OpContext) Resolve(env *Environment, r Resolver) (*Vertex, *Bottom) {
372372
}
373373

374374
for {
375-
x, ok := arc.Value.(*Vertex)
375+
x, ok := arc.BaseValue.(*Vertex)
376376
if !ok {
377377
break
378378
}
@@ -449,7 +449,7 @@ func (c *OpContext) getDefault(v Value, scalar bool) (result Value, ok bool) {
449449

450450
case *Vertex:
451451
// TODO: return vertex if not disjunction.
452-
switch t := x.Value.(type) {
452+
switch t := x.BaseValue.(type) {
453453
case *Disjunction:
454454
d = t
455455

@@ -460,7 +460,7 @@ func (c *OpContext) getDefault(v Value, scalar bool) (result Value, ok bool) {
460460
if !scalar {
461461
return x, true
462462
}
463-
return x.ActualValue(), true
463+
return x.Value(), true
464464
}
465465

466466
case *Disjunction:
@@ -551,7 +551,7 @@ func (c *OpContext) evalState(v Expr, state VertexStatus) (result Value) {
551551
}
552552
if isIncomplete(arc) {
553553
if arc != nil {
554-
return arc.ActualValue() // *Bottom
554+
return arc.Value() // *Bottom
555555
}
556556
return nil
557557
}
@@ -573,8 +573,8 @@ func (c *OpContext) lookup(x *Vertex, pos token.Pos, l Feature) *Vertex {
573573
}
574574

575575
var kind Kind
576-
if x.Value != nil {
577-
kind = x.Value.Kind()
576+
if x.BaseValue != nil {
577+
kind = x.BaseValue.Kind()
578578
}
579579

580580
switch kind {
@@ -676,7 +676,7 @@ func (c *OpContext) node(x Expr, scalar bool) *Vertex {
676676

677677
node, ok := v.(*Vertex)
678678
if ok {
679-
v = node.ActualValue()
679+
v = node.Value()
680680
}
681681
switch nv := v.(type) {
682682
case nil:
@@ -966,7 +966,7 @@ func (c *OpContext) newBool(b bool) Value {
966966
}
967967

968968
func (c *OpContext) newList(src ast.Node, parent *Vertex) *Vertex {
969-
return &Vertex{Parent: parent, Value: &ListMarker{}}
969+
return &Vertex{Parent: parent, BaseValue: &ListMarker{}}
970970
}
971971

972972
// Str reports a debug string of x.

internal/core/adt/default.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ func (d *Disjunction) Default() Value {
4343

4444
// Default returns the default value or itself if there is no default.
4545
func (v *Vertex) Default() *Vertex {
46-
switch d := v.Value.(type) {
46+
switch d := v.BaseValue.(type) {
4747
default:
4848
return v
4949

@@ -57,7 +57,7 @@ func (v *Vertex) Default() *Vertex {
5757
w = d.Values[0]
5858
default:
5959
x := *v
60-
x.Value = &Disjunction{
60+
x.BaseValue = &Disjunction{
6161
Src: d.Src,
6262
Values: d.Values[:d.NumDefaults],
6363
NumDefaults: 0,
@@ -79,7 +79,7 @@ func (v *Vertex) Default() *Vertex {
7979

8080
w := *v
8181
w.Closed = nil
82-
w.Value = &m
82+
w.BaseValue = &m
8383
return &w
8484
}
8585
}

internal/core/adt/errors.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ func isIncomplete(v *Vertex) bool {
130130
if v == nil {
131131
return true
132132
}
133-
if b, ok := v.Value.(*Bottom); ok {
133+
if b, ok := v.BaseValue.(*Bottom); ok {
134134
return b.IsIncomplete()
135135
}
136136
return false
@@ -148,10 +148,10 @@ func (v *Vertex) AddChildError(recursive *Bottom) {
148148
if recursive.IsIncomplete() {
149149
return
150150
}
151-
x := v.Value
151+
x := v.BaseValue
152152
err, _ := x.(*Bottom)
153153
if err == nil {
154-
v.Value = &Bottom{
154+
v.BaseValue = &Bottom{
155155
Code: recursive.Code,
156156
Value: v,
157157
HasRecursive: true,
@@ -166,7 +166,7 @@ func (v *Vertex) AddChildError(recursive *Bottom) {
166166
err.Code = recursive.Code
167167
}
168168

169-
v.Value = err
169+
v.BaseValue = err
170170
}
171171

172172
// CombineErrors combines two errors that originate at the same Vertex.

0 commit comments

Comments
 (0)