Skip to content

Commit c561f1f

Browse files
committed
internal/core: automated rename
This is to support the comprehension changes. As part of this change, (partial) comprehensions can be the expression of a Conjunct. This means that `Expr` must now return an `Elem`. We will also need an `Expr` method that will return the comprehension value when applicable. To avoid awkward naming, and to minimize diffs and make changes clear, we do this rename in a separate CL. Change-Id: I7cbbb81302519d8e4ba0727e7eb53d59be693f2f Signed-off-by: Marcel van Lohuizen <mpvl@golang.org> Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/529512 Unity-Result: CUEcueckoo <cueckoo@cuelang.org> Reviewed-by: Marcel van Lohuizen <mpvl@gmail.com>
1 parent b67dc4d commit c561f1f

File tree

21 files changed

+56
-56
lines changed

21 files changed

+56
-56
lines changed

cue/types.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -644,7 +644,7 @@ func Dereference(v Value) Value {
644644
}
645645

646646
c := n.Conjuncts[0]
647-
r, _ := c.Expr().(adt.Resolver)
647+
r, _ := c.Elem().(adt.Resolver)
648648
if r == nil {
649649
return v
650650
}
@@ -1072,7 +1072,7 @@ func (v hiddenValue) Split() []Value {
10721072
}
10731073
a := []Value{}
10741074
for _, x := range v.v.Conjuncts {
1075-
a = append(a, remakeValue(v, x.Env, x.Expr()))
1075+
a = append(a, remakeValue(v, x.Env, x.Elem()))
10761076
}
10771077
return a
10781078
}
@@ -1932,7 +1932,7 @@ func (v Value) ReferencePath() (root Value, p Path) {
19321932
ctx := v.ctx()
19331933
c := v.v.Conjuncts[0]
19341934

1935-
x, path := reference(v.idx, ctx, c.Env, c.Expr())
1935+
x, path := reference(v.idx, ctx, c.Env, c.Elem())
19361936
if x == nil {
19371937
return Value{}, Path{}
19381938
}
@@ -2237,7 +2237,7 @@ func (v Value) Expr() (Op, []Value) {
22372237
// the default case, processed below.
22382238
c := v.v.Conjuncts[0]
22392239
env = c.Env
2240-
expr = c.Expr()
2240+
expr = c.Elem()
22412241
if w, ok := expr.(*adt.Vertex); ok {
22422242
return Value{v.idx, w, v.parent_}.Expr()
22432243
}

internal/core/adt/adt.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ func Resolve(ctx *OpContext, c Conjunct) *Vertex {
3333

3434
var v Value
3535

36-
expr := c.Expr()
36+
expr := c.Elem()
3737
switch x := expr.(type) {
3838
case Value:
3939
v = x
@@ -54,7 +54,7 @@ func Resolve(ctx *OpContext, c Conjunct) *Vertex {
5454
default:
5555
// Unknown type.
5656
v = ctx.NewErrf(
57-
"could not evaluate expression %s of type %T", c.Expr(), c)
57+
"could not evaluate expression %s of type %T", c.Elem(), c)
5858
}
5959

6060
return ToVertex(v)

internal/core/adt/closed_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ func TestClosedness(t *testing.T) {
4040
if err != nil {
4141
t.Fatal(err)
4242
}
43-
st := expr.Expr().(*adt.StructLit)
43+
st := expr.Elem().(*adt.StructLit)
4444
st.Init()
4545

4646
return &adt.StructInfo{

internal/core/adt/composite.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -810,7 +810,7 @@ func (c *Conjunct) Field() Node {
810810
return c.x
811811
}
812812

813-
func (c *Conjunct) Expr() Expr {
813+
func (c *Conjunct) Elem() Expr {
814814
switch x := c.x.(type) {
815815
case Expr:
816816
return x

internal/core/adt/default.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ func (v *Vertex) Default() *Vertex {
7272
if w.Conjuncts == nil {
7373
for _, c := range v.Conjuncts {
7474
// TODO: preserve field information.
75-
expr, _ := stripNonDefaults(c.Expr())
75+
expr, _ := stripNonDefaults(c.Elem())
7676
w.Conjuncts = append(w.Conjuncts, MakeRootConjunct(c.Env, expr))
7777
}
7878
}

internal/core/adt/eval.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1174,7 +1174,7 @@ func (n *nodeContext) addExprConjunct(v Conjunct) {
11741174
env := v.Env
11751175
id := v.CloseInfo
11761176

1177-
switch x := v.Expr().(type) {
1177+
switch x := v.Elem().(type) {
11781178
case *Vertex:
11791179
if x.IsData() {
11801180
n.addValueConjunct(env, x, id)
@@ -1240,7 +1240,7 @@ func (n *nodeContext) evalExpr(v Conjunct) {
12401240
}
12411241
}()
12421242

1243-
switch x := v.Expr().(type) {
1243+
switch x := v.Elem().(type) {
12441244
case Resolver:
12451245
arc, err := ctx.Resolve(v.Env, x)
12461246
if err != nil && !err.IsIncomplete() {
@@ -1252,12 +1252,12 @@ func (n *nodeContext) evalExpr(v Conjunct) {
12521252
break
12531253
}
12541254

1255-
n.addVertexConjuncts(v.Env, v.CloseInfo, v.Expr(), arc, false)
1255+
n.addVertexConjuncts(v.Env, v.CloseInfo, v.Elem(), arc, false)
12561256

12571257
case Evaluator:
12581258
// Interpolation, UnaryExpr, BinaryExpr, CallExpr
12591259
// Could be unify?
1260-
val := ctx.evaluateRec(v.Env, v.Expr(), Partial)
1260+
val := ctx.evaluateRec(v.Env, v.Elem(), Partial)
12611261
if b, ok := val.(*Bottom); ok && b.IsIncomplete() {
12621262
n.exprs = append(n.exprs, envExpr{v, b})
12631263
break
@@ -1473,7 +1473,7 @@ func updateCyclic(c Conjunct, cyclic bool, deref *Vertex, a []*Vertex) Conjunct
14731473
if deref != nil {
14741474
env.Cycles = append(env.Cycles, deref)
14751475
}
1476-
return MakeConjunct(env, c.Expr(), c.CloseInfo)
1476+
return MakeConjunct(env, c.Elem(), c.CloseInfo)
14771477
}
14781478

14791479
func (n *nodeContext) addValueConjunct(env *Environment, v Value, id CloseInfo) {

internal/core/adt/expr.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1687,7 +1687,7 @@ func (x *IfClause) yield(ctx *OpContext, f YieldFunc) {
16871687

16881688
// An LetClause represents a let clause in a comprehension.
16891689
//
1690-
// for k, v in src {}
1690+
// let x = y
16911691
//
16921692
type LetClause struct {
16931693
Src *ast.LetClause

internal/core/compile/compile_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ func TestCompile(t *testing.T) {
6767
fmt.Fprintln(t)
6868
}
6969
fmt.Fprintln(t, "---", t.Rel(f.Filename))
70-
debug.WriteNode(t, r, v.Conjuncts[i].Expr(), &debug.Config{
70+
debug.WriteNode(t, r, v.Conjuncts[i].Elem(), &debug.Config{
7171
Cwd: t.Dir,
7272
})
7373
}
@@ -102,5 +102,5 @@ func TestX(t *testing.T) {
102102
if err != nil {
103103
t.Error(errors.Details(err, nil))
104104
}
105-
t.Error(debug.NodeString(r, arc.Conjuncts[0].Expr(), nil))
105+
t.Error(debug.NodeString(r, arc.Conjuncts[0].Elem(), nil))
106106
}

internal/core/convert/go.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -765,7 +765,7 @@ store:
765765
ctx.AddBottom(b)
766766
x = b
767767
} else {
768-
x = c.Expr()
768+
x = c.Elem()
769769
}
770770
ctx.StoreType(t, e, x)
771771
return e, x

internal/core/debug/compact.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ func (w *compactPrinter) node(n adt.Node) {
3939
if i > 0 {
4040
w.string(" & ")
4141
}
42-
w.node(c.Expr())
42+
w.node(c.Elem())
4343
}
4444
return
4545
}

0 commit comments

Comments
 (0)