cue: rename fields to ease transition to package adt
Change-Id: Id43c685bd700deb5b91657232e4a120a764fd6c8
Reviewed-on: https://cue-review.googlesource.com/c/cue/+/6511
Reviewed-by: Marcel van Lohuizen <mpvl@golang.org>
Reviewed-by: CUE cueckoo <cueckoo@gmail.com>
diff --git a/cue/ast.go b/cue/ast.go
index 09d9d36..35a278f 100644
--- a/cue/ast.go
+++ b/cue/ast.go
@@ -268,8 +268,8 @@
if isBottom(e) {
return e
}
- if e.kind()&structKind == 0 {
- return v1.errf(x, "can only embed structs (found %v)", e.kind())
+ if e.Kind()&structKind == 0 {
+ return v1.errf(x, "can only embed structs (found %v)", e.Kind())
}
ret = mkBin(v1.ctx(), x.Pos(), opUnifyUnchecked, ret, e)
// TODO: preserve order of embedded fields. We cannot split into
@@ -646,7 +646,7 @@
case *ast.BottomLit:
// TODO: record inline comment.
- ret = &bottom{baseValue: newExpr(n), code: codeUser, format: "from source"}
+ ret = &bottom{baseValue: newExpr(n), Code: codeUser, format: "from source"}
case *ast.BadDecl:
// nothing to do
@@ -670,7 +670,7 @@
ret = v.walk(n.Elts[0])
break
}
- lit := &interpolation{baseValue: newExpr(n), k: stringKind}
+ lit := &interpolation{baseValue: newExpr(n), K: stringKind}
ret = lit
info, prefixLen, _, err := literal.ParseQuotes(first.Value, last.Value)
if err != nil {
@@ -688,9 +688,9 @@
}
s = l.Value[prefixLen:]
x := parseString(v.ctx(), l, info, s)
- lit.parts = append(lit.parts, x)
+ lit.Parts = append(lit.Parts, x)
if i+1 < len(n.Elts) {
- lit.parts = append(lit.parts, v.walk(n.Elts[i+1]))
+ lit.Parts = append(lit.Parts, v.walk(n.Elts[i+1]))
}
prefix = ")"
prefixLen = 1
@@ -712,19 +712,19 @@
ret = &indexExpr{newExpr(n), v.walk(n.X), v.walk(n.Index)}
case *ast.SliceExpr:
- slice := &sliceExpr{baseValue: newExpr(n), x: v.walk(n.X)}
+ slice := &sliceExpr{baseValue: newExpr(n), X: v.walk(n.X)}
if n.Low != nil {
- slice.lo = v.walk(n.Low)
+ slice.Lo = v.walk(n.Low)
}
if n.High != nil {
- slice.hi = v.walk(n.High)
+ slice.Hi = v.walk(n.High)
}
ret = slice
case *ast.CallExpr:
- call := &callExpr{baseValue: newExpr(n), x: v.walk(n.Fun)}
+ call := &callExpr{baseValue: newExpr(n), Fun: v.walk(n.Fun)}
for _, a := range n.Args {
- call.args = append(call.args, v.walk(a))
+ call.Args = append(call.Args, v.walk(a))
}
ret = call
@@ -799,9 +799,9 @@
mark = true
n = x.X
}
- d.hasDefaults = true
+ d.HasDefaults = true
}
- d.values = append(d.values, dValue{v.walk(n), mark})
+ d.Values = append(d.Values, dValue{v.walk(n), mark})
}
func wrapClauses(v *astVisitor, y yielder, clauses []ast.Clause) yielder {
diff --git a/cue/binop.go b/cue/binop.go
index 01d0037..e10658f 100644
--- a/cue/binop.go
+++ b/cue/binop.go
@@ -54,8 +54,8 @@
left = convertBuiltin(left)
right = convertBuiltin(right)
- leftKind := left.kind()
- rightKind := right.kind()
+ leftKind := left.Kind()
+ rightKind := right.Kind()
kind, invert, msg := matchBinOpKind(op, leftKind, rightKind)
if kind == bottomKind {
simplify := func(v, orig value) value {
@@ -63,7 +63,7 @@
case *disjunction:
return orig
case *binaryExpr:
- if x.op == opDisjunction {
+ if x.Op == opDisjunction {
return orig
}
default:
@@ -73,8 +73,8 @@
}
var l, r value = left, right
if x, ok := src.(*binaryExpr); ok {
- l = simplify(x.left, left)
- r = simplify(x.right, right)
+ l = simplify(x.X, left)
+ r = simplify(x.Y, right)
}
return ctx.mkErr(src, msg, op, ctx.str(l), ctx.str(r), leftKind, rightKind)
}
@@ -151,24 +151,24 @@
func dist(ctx *context, d *disjunction, mark bool, op op, x, y mVal) {
if dx, ok := x.val.(*disjunction); ok {
- if dx.hasDefaults {
+ if dx.HasDefaults {
mark = true
- d.hasDefaults = true
+ d.HasDefaults = true
}
- for _, dxv := range dx.values {
- m := dxv.marked || !dx.hasDefaults
- dist(ctx, d, mark, op, mVal{dxv.val.evalPartial(ctx), m}, y)
+ for _, dxv := range dx.Values {
+ m := dxv.Default || !dx.HasDefaults
+ dist(ctx, d, mark, op, mVal{dxv.Val.evalPartial(ctx), m}, y)
}
return
}
if dy, ok := y.val.(*disjunction); ok {
- if dy.hasDefaults {
+ if dy.HasDefaults {
mark = true
- d.hasDefaults = true
+ d.HasDefaults = true
}
- for _, dxy := range dy.values {
- m := dxy.marked || !dy.hasDefaults
- dist(ctx, d, mark, op, x, mVal{dxy.val.evalPartial(ctx), m})
+ for _, dxy := range dy.Values {
+ m := dxy.Default || !dy.HasDefaults
+ dist(ctx, d, mark, op, x, mVal{dxy.Val.evalPartial(ctx), m})
}
return
}
@@ -191,7 +191,7 @@
progress = false
k := 0
- for i, vx := range x.values {
+ for i, vx := range x.Values {
a := binOp(ctx, src, opUnify, vx, v)
switch _, isUnify := a.(*unification); {
case isBottom(a):
@@ -200,7 +200,7 @@
}
fallthrough
case isUnify:
- x.values[k] = x.values[i]
+ x.Values[k] = x.Values[i]
k++
continue
}
@@ -214,9 +214,9 @@
if k == 0 {
return v
}
- x.values = x.values[:k]
+ x.Values = x.Values[:k]
}
- x.values = append(x.values, v)
+ x.Values = append(x.Values, v)
return nil
}
@@ -224,9 +224,9 @@
if _, isUnify := op.unifyType(); isUnify {
// Cannot be checked unification.
u := &unification{baseValue: baseValue{src}}
- u.values = append(u.values, x.values...)
+ u.Values = append(u.Values, x.Values...)
if y, ok := other.(*unification); ok {
- for _, vy := range y.values {
+ for _, vy := range y.Values {
if v := u.add(ctx, src, vy); v != nil {
return v
}
@@ -249,7 +249,7 @@
}
func (x *basicType) binOp(ctx *context, src source, op op, other evaluated) evaluated {
- k := unifyType(x.kind(), other.kind())
+ k := unifyType(x.Kind(), other.Kind())
switch y := other.(type) {
case *basicType:
switch op {
@@ -266,7 +266,7 @@
case *numLit:
if op == opUnify || op == opUnifyUnchecked {
- if k == y.k {
+ if k == y.K {
return y
}
return y.specialize(k)
@@ -284,7 +284,7 @@
func checkBounds(ctx *context, src source, r *bound, op op, a, b evaluated) evaluated {
v := binOp(ctx, src, op, a, b)
- if isBottom(v) || !v.(*boolLit).b {
+ if isBottom(v) || !v.(*boolLit).B {
return errOutOfBounds(ctx, src.Pos(), r, a)
}
return nil
@@ -296,7 +296,7 @@
}
e := mkBin(ctx, pos, opUnify, r, v)
msg := "invalid value %v (out of bound %v)"
- switch r.op {
+ switch r.Op {
case opNeq, opNMat:
msg = "invalid value %v (excluded by %v)"
case opMat:
@@ -326,35 +326,35 @@
}
func (x *bound) binOp(ctx *context, src source, op op, other evaluated) evaluated {
- xv := x.value.(evaluated)
+ xv := x.Expr.(evaluated)
newSrc := binSrc(src.Pos(), op, x, other)
switch op {
case opUnify, opUnifyUnchecked:
- k, _, msg := matchBinOpKind(opUnify, x.kind(), other.kind())
+ k, _, msg := matchBinOpKind(opUnify, x.Kind(), other.Kind())
if k == bottomKind {
- return ctx.mkErr(src, msg, opUnify, ctx.str(x), ctx.str(other), x.kind(), other.kind())
+ return ctx.mkErr(src, msg, opUnify, ctx.str(x), ctx.str(other), x.Kind(), other.Kind())
}
switch y := other.(type) {
case *basicType:
- k := unifyType(x.k, y.kind())
+ k := unifyType(x.k, y.Kind())
if k == x.k {
return x
}
- return newBound(ctx, newSrc.base(), x.op, k, xv)
+ return newBound(ctx, newSrc.base(), x.Op, k, xv)
case *bound:
- yv := y.value.(evaluated)
- if !xv.kind().isGround() || !yv.kind().isGround() {
+ yv := y.Expr.(evaluated)
+ if !xv.Kind().isGround() || !yv.Kind().isGround() {
return ctx.mkErr(newSrc, codeIncomplete, "cannot add incomplete values")
}
- cmp, xCat := opInfo(x.op)
- _, yCat := opInfo(y.op)
+ cmp, xCat := opInfo(x.Op)
+ _, yCat := opInfo(y.Op)
switch {
case xCat == yCat:
- if x.op == opNeq || x.op == opMat || x.op == opNMat {
+ if x.Op == opNeq || x.Op == opMat || x.Op == opNMat {
if test(ctx, x, opEql, xv, yv) {
return x
}
@@ -386,31 +386,31 @@
if xCat == -1 {
x, y = y, x
}
- a, aOK := x.value.(evaluated).(*numLit)
- b, bOK := y.value.(evaluated).(*numLit)
+ a, aOK := x.Expr.(evaluated).(*numLit)
+ b, bOK := y.Expr.(evaluated).(*numLit)
if !aOK || !bOK {
break
}
var d, lo, hi apd.Decimal
- lo.Set(&a.v)
- hi.Set(&b.v)
+ lo.Set(&a.X)
+ hi.Set(&b.X)
if k&floatKind == 0 {
// Readjust bounds for integers.
- if x.op == opGeq {
+ if x.Op == opGeq {
// >=3.4 ==> >=4
- _, _ = apd.BaseContext.Ceil(&lo, &a.v)
+ _, _ = apd.BaseContext.Ceil(&lo, &a.X)
} else {
// >3.4 ==> >3
- _, _ = apd.BaseContext.Floor(&lo, &a.v)
+ _, _ = apd.BaseContext.Floor(&lo, &a.X)
}
- if y.op == opLeq {
+ if y.Op == opLeq {
// <=2.3 ==> <= 2
- _, _ = apd.BaseContext.Floor(&hi, &b.v)
+ _, _ = apd.BaseContext.Floor(&hi, &b.X)
} else {
// <2.3 ==> < 3
- _, _ = apd.BaseContext.Ceil(&hi, &b.v)
+ _, _ = apd.BaseContext.Ceil(&hi, &b.X)
}
}
@@ -451,23 +451,23 @@
case diff == 1:
if k&floatKind == 0 {
- if x.op == opGeq && y.op == opLss {
+ if x.Op == opGeq && y.Op == opLss {
return n.set(&lo)
}
- if x.op == opGtr && y.op == opLeq {
+ if x.Op == opGtr && y.Op == opLeq {
return n.set(&hi)
}
}
case diff == 2:
- if k&floatKind == 0 && x.op == opGtr && y.op == opLss {
+ if k&floatKind == 0 && x.Op == opGtr && y.Op == opLss {
_, _ = apd.BaseContext.Add(&d, d.SetInt64(1), &lo)
return n.set(&d)
}
case diff == 0:
- if x.op == opGeq && y.op == opLeq {
+ if x.Op == opGeq && y.Op == opLeq {
return n.set(&lo)
}
fallthrough
@@ -477,24 +477,24 @@
ctx.str(x), ctx.str(y))
}
- case x.op == opNeq:
- if !test(ctx, x, y.op, xv, yv) {
+ case x.Op == opNeq:
+ if !test(ctx, x, y.Op, xv, yv) {
return y
}
- case y.op == opNeq:
- if !test(ctx, x, x.op, yv, xv) {
+ case y.Op == opNeq:
+ if !test(ctx, x, x.Op, yv, xv) {
return x
}
}
return &unification{newSrc, []evaluated{x, y}}
case *numLit:
- if err := checkBounds(ctx, src, x, x.op, y, xv); err != nil {
+ if err := checkBounds(ctx, src, x, x.Op, y, xv); err != nil {
return err
}
// Narrow down number type.
- if y.k != k {
+ if y.K != k {
return y.specialize(k)
}
return other
@@ -502,7 +502,7 @@
case *nullLit, *boolLit, *durationLit, *list, *structLit, *stringLit, *bytesLit:
// All remaining concrete types. This includes non-comparable types
// for comparison to null.
- if err := checkBounds(ctx, src, x, x.op, y, xv); err != nil {
+ if err := checkBounds(ctx, src, x, x.Op, y, xv); err != nil {
return err
}
return y
@@ -515,14 +515,14 @@
newSrc := binSrc(src.Pos(), op, x, other)
switch op {
case opUnify, opUnifyUnchecked:
- k, _, msg := matchBinOpKind(opUnify, x.kind(), other.kind())
+ k, _, msg := matchBinOpKind(opUnify, x.Kind(), other.Kind())
if k == bottomKind {
- return ctx.mkErr(src, msg, op, ctx.str(x), ctx.str(other), x.kind(), other.kind())
+ return ctx.mkErr(src, msg, op, ctx.str(x), ctx.str(other), x.Kind(), other.Kind())
}
switch y := other.(type) {
case *basicType:
- k := unifyType(x.kind(), y.kind())
- if k == x.kind() {
+ k := unifyType(x.Kind(), y.Kind())
+ if k == x.Kind() {
return x
}
return &unification{newSrc, []evaluated{x, y}}
@@ -538,7 +538,7 @@
return err
}
// Narrow down number type.
- if y.k != k {
+ if y.K != k {
return y.specialize(k)
}
return other
@@ -556,23 +556,23 @@
}
func (x *customValidator) check(ctx *context, v evaluated) evaluated {
- args := make([]evaluated, 1+len(x.args))
+ args := make([]evaluated, 1+len(x.Args))
args[0] = v
- for i, v := range x.args {
+ for i, v := range x.Args {
args[1+i] = v.(evaluated)
}
- res := x.call.call(ctx, x, args...)
+ res := x.Builtin.call(ctx, x, args...)
if isBottom(res) {
return res.(evaluated)
}
if b, ok := res.(*boolLit); !ok {
// should never reach here
return ctx.mkErr(x, "invalid custom validator")
- } else if !b.b {
+ } else if !b.B {
var buf bytes.Buffer
- fmt.Fprintf(&buf, "%s.%s", ctx.LabelStr(x.call.pkg), x.call.Name)
+ fmt.Fprintf(&buf, "%s.%s", ctx.LabelStr(x.Builtin.pkg), x.Builtin.Name)
buf.WriteString("(")
- for _, a := range x.args {
+ for _, a := range x.Args {
buf.WriteString(ctx.str(a))
}
buf.WriteString(")")
@@ -791,9 +791,9 @@
case *nullLit:
switch op {
case opEql:
- return &boolLit{baseValue: src.base(), b: true}
+ return &boolLit{baseValue: src.base(), B: true}
case opNeq:
- return &boolLit{baseValue: src.base(), b: false}
+ return &boolLit{baseValue: src.base(), B: false}
case opUnify, opUnifyUnchecked:
return x
}
@@ -808,9 +808,9 @@
default:
switch op {
case opEql:
- return &boolLit{baseValue: src.base(), b: false}
+ return &boolLit{baseValue: src.base(), B: false}
case opNeq:
- return &boolLit{baseValue: src.base(), b: true}
+ return &boolLit{baseValue: src.base(), B: true}
}
}
return ctx.mkIncompatible(src, op, x, other)
@@ -825,18 +825,18 @@
case *boolLit:
switch op {
case opUnify, opUnifyUnchecked:
- if x.b != y.b {
- return ctx.mkErr(x, "conflicting values %v and %v", x.b, y.b)
+ if x.B != y.B {
+ return ctx.mkErr(x, "conflicting values %v and %v", x.B, y.B)
}
return x
case opLand:
- return boolTonode(src, x.b && y.b)
+ return boolTonode(src, x.B && y.B)
case opLor:
- return boolTonode(src, x.b || y.b)
+ return boolTonode(src, x.B || y.B)
case opEql:
- return boolTonode(src, x.b == y.b)
+ return boolTonode(src, x.B == y.B)
case opNeq:
- return boolTonode(src, x.b != y.b)
+ return boolTonode(src, x.B != y.B)
}
}
return ctx.mkIncompatible(src, op, x, other)
@@ -854,43 +854,43 @@
switch op {
case opUnify, opUnifyUnchecked:
str := other.strValue()
- if x.str != str {
+ if x.Str != str {
src := mkBin(ctx, src.Pos(), op, x, other)
return ctx.mkErr(src, "conflicting values %v and %v",
ctx.str(x), ctx.str(y))
}
return x
case opLss, opLeq, opEql, opNeq, opGeq, opGtr:
- return cmpTonode(src, op, strings.Compare(x.str, str))
+ return cmpTonode(src, op, strings.Compare(x.Str, str))
case opAdd:
src := binSrc(src.Pos(), op, x, other)
- return &stringLit{src, x.str + str, nil}
+ return &stringLit{src, x.Str + str, nil}
case opMat:
- if y.re == nil {
+ if y.RE == nil {
// This really should not happen, but leave in for safety.
- b, err := regexp.MatchString(str, x.str)
+ b, err := regexp.MatchString(str, x.Str)
if err != nil {
return ctx.mkErr(src, "error parsing regexp: %v", err)
}
return boolTonode(src, b)
}
- return boolTonode(src, y.re.MatchString(x.str))
+ return boolTonode(src, y.RE.MatchString(x.Str))
case opNMat:
- if y.re == nil {
+ if y.RE == nil {
// This really should not happen, but leave in for safety.
- b, err := regexp.MatchString(str, x.str)
+ b, err := regexp.MatchString(str, x.Str)
if err != nil {
return ctx.mkErr(src, "error parsing regexp: %v", err)
}
return boolTonode(src, !b)
}
- return boolTonode(src, !y.re.MatchString(x.str))
+ return boolTonode(src, !y.RE.MatchString(x.Str))
}
case *numLit:
switch op {
case opMul:
src := binSrc(src.Pos(), op, x, other)
- return &stringLit{src, strings.Repeat(x.str, y.intValue(ctx)), nil}
+ return &stringLit{src, strings.Repeat(x.Str, y.intValue(ctx)), nil}
}
}
return ctx.mkIncompatible(src, op, x, other)
@@ -904,18 +904,18 @@
// TODO: rangelit
case *bytesLit:
- b := y.b
+ b := y.B
switch op {
case opUnify, opUnifyUnchecked:
- if !bytes.Equal(x.b, b) {
+ if !bytes.Equal(x.B, b) {
return ctx.mkErr(x, "conflicting values %v and %v",
ctx.str(x), ctx.str(y))
}
return x
case opLss, opLeq, opEql, opNeq, opGeq, opGtr:
- return cmpTonode(src, op, bytes.Compare(x.b, b))
+ return cmpTonode(src, op, bytes.Compare(x.B, b))
case opAdd:
- copy := append([]byte(nil), x.b...)
+ copy := append([]byte(nil), x.B...)
copy = append(copy, b...)
return &bytesLit{binSrc(src.Pos(), op, x, other), copy, nil}
}
@@ -924,7 +924,7 @@
switch op {
case opMul:
src := binSrc(src.Pos(), op, x, other)
- return &bytesLit{src, bytes.Repeat(x.b, y.intValue(ctx)), nil}
+ return &bytesLit{src, bytes.Repeat(x.B, y.intValue(ctx)), nil}
}
}
return ctx.mkIncompatible(src, op, x, other)
@@ -935,7 +935,7 @@
if isBottom(v) {
return false
}
- return v.(*boolLit).b
+ return v.(*boolLit).B
}
func leq(ctx *context, src source, a, b evaluated) bool {
@@ -946,7 +946,7 @@
if isBottom(v) {
return false
}
- return v.(*boolLit).b
+ return v.(*boolLit).B
}
// TODO: should these go?
@@ -955,11 +955,11 @@
case *numLit:
return x
case *bound:
- switch x.op {
+ switch x.Op {
case opLeq:
- return x.value
+ return x.Expr
case opLss:
- return &binaryExpr{x.baseValue, opSub, x.value, one}
+ return &binaryExpr{x.baseValue, opSub, x.Expr, one}
}
return &basicType{x.baseValue, intKind}
}
@@ -971,11 +971,11 @@
case *numLit:
return x
case *bound:
- switch x.op {
+ switch x.Op {
case opGeq:
- return x.value
+ return x.Expr
case opGtr:
- return &binaryExpr{x.baseValue, opAdd, x.value, one}
+ return &binaryExpr{x.baseValue, opAdd, x.Expr, one}
}
return &basicType{x.baseValue, intKind}
}
@@ -1008,59 +1008,59 @@
return y.binOp(ctx, src, op, x)
}
case *numLit:
- k, _, _ := matchBinOpKind(op, x.kind(), y.kind())
+ k, _, _ := matchBinOpKind(op, x.Kind(), y.Kind())
if k == bottomKind {
break
}
switch op {
case opLss, opLeq, opEql, opNeq, opGeq, opGtr:
- return cmpTonode(src, op, x.v.Cmp(&y.v))
+ return cmpTonode(src, op, x.X.Cmp(&y.X))
}
n := newNum(src.base(), k, x.rep|y.rep)
switch op {
case opUnify, opUnifyUnchecked:
- if x.v.Cmp(&y.v) != 0 {
+ if x.X.Cmp(&y.X) != 0 {
src = mkBin(ctx, src.Pos(), op, x, other)
return ctx.mkErr(src, "conflicting values %v and %v",
ctx.str(x), ctx.str(y))
}
- if k != x.k {
- n.v = x.v
+ if k != x.K {
+ n.X = x.X
return n
}
return x
case opAdd:
- _, _ = ctx.Add(&n.v, &x.v, &y.v)
+ _, _ = ctx.Add(&n.X, &x.X, &y.X)
case opSub:
- _, _ = ctx.Sub(&n.v, &x.v, &y.v)
+ _, _ = ctx.Sub(&n.X, &x.X, &y.X)
case opMul:
- _, _ = ctx.Mul(&n.v, &x.v, &y.v)
+ _, _ = ctx.Mul(&n.X, &x.X, &y.X)
case opQuo:
- cond, err := ctx.Quo(&n.v, &x.v, &y.v)
+ cond, err := ctx.Quo(&n.X, &x.X, &y.X)
if err != nil {
return ctx.mkErr(src, err.Error())
}
if cond.DivisionByZero() {
return ctx.mkErr(src, "division by zero")
}
- n.k = floatKind
+ n.K = floatKind
case opIDiv:
- if y.v.IsZero() {
+ if y.X.IsZero() {
return ctx.mkErr(src, "division by zero")
}
intOp(ctx, n, (*big.Int).Div, x, y)
case opIMod:
- if y.v.IsZero() {
+ if y.X.IsZero() {
return ctx.mkErr(src, "division by zero")
}
intOp(ctx, n, (*big.Int).Mod, x, y)
case opIQuo:
- if y.v.IsZero() {
+ if y.X.IsZero() {
return ctx.mkErr(src, "division by zero")
}
intOp(ctx, n, (*big.Int).Quo, x, y)
case opIRem:
- if y.v.IsZero() {
+ if y.X.IsZero() {
return ctx.mkErr(src, "division by zero")
}
intOp(ctx, n, (*big.Int).Rem, x, y)
@@ -1071,7 +1071,7 @@
if op == opMul {
fd := float64(y.d)
// TODO: check range
- f, _ := x.v.Float64()
+ f, _ := x.X.Float64()
d := time.Duration(f * fd)
return &durationLit{binSrc(src.Pos(), op, x, other), d}
}
@@ -1083,20 +1083,20 @@
func intOp(ctx *context, n *numLit, fn intFunc, a, b *numLit) {
var x, y apd.Decimal
- _, _ = ctx.RoundToIntegralValue(&x, &a.v)
+ _, _ = ctx.RoundToIntegralValue(&x, &a.X)
if x.Negative {
x.Coeff.Neg(&x.Coeff)
}
- _, _ = ctx.RoundToIntegralValue(&y, &b.v)
+ _, _ = ctx.RoundToIntegralValue(&y, &b.X)
if y.Negative {
y.Coeff.Neg(&y.Coeff)
}
- fn(&n.v.Coeff, &x.Coeff, &y.Coeff)
- if n.v.Coeff.Sign() < 0 {
- n.v.Coeff.Neg(&n.v.Coeff)
- n.v.Negative = true
+ fn(&n.X.Coeff, &x.Coeff, &y.Coeff)
+ if n.X.Coeff.Sign() < 0 {
+ n.X.Coeff.Neg(&n.X.Coeff)
+ n.X.Negative = true
}
- n.k = intKind
+ n.K = intKind
}
// TODO: check overflow
@@ -1133,11 +1133,11 @@
n := newFloat(src.base(), base10).setInt64(int64(x.d))
d := apd.New(int64(y.d), 0)
// TODO: check result if this code becomes undead.
- _, _ = ctx.Quo(&n.v, &n.v, d)
+ _, _ = ctx.Quo(&n.X, &n.X, d)
return n
case opIRem:
n := newInt(src.base(), base10).setInt64(int64(x.d % y.d))
- n.v.Exponent = -9
+ n.X.Exponent = -9
return n
}
@@ -1145,12 +1145,12 @@
switch op {
case opMul:
// TODO: check range
- f, _ := y.v.Float64()
+ f, _ := y.X.Float64()
d := time.Duration(float64(x.d) * f)
return &durationLit{binSrc(src.Pos(), op, x, other), d}
case opQuo:
// TODO: check range
- f, _ := y.v.Float64()
+ f, _ := y.X.Float64()
d := time.Duration(float64(x.d) * f)
return &durationLit{binSrc(src.Pos(), op, x, other), d}
case opIRem:
@@ -1241,7 +1241,7 @@
return n
case opMul:
- k := other.kind()
+ k := other.Kind()
if !k.isAnyOf(intKind) {
panic("multiplication must be int type")
}
diff --git a/cue/build.go b/cue/build.go
index 846c48f..9f86daf 100644
--- a/cue/build.go
+++ b/cue/build.go
@@ -227,6 +227,7 @@
}
return inst
}
+ errs := runtime.ResolveFiles(idx.Index, p, isBuiltin)
files := p.Files
inst := newInstance(idx, p)
idx.loaded[p] = inst
@@ -234,7 +235,7 @@
if inst.Err == nil {
// inst.instance.index.state = s
// inst.instance.inst = p
- inst.Err = runtime.ResolveFiles(idx.Index, p, isBuiltin)
+ inst.Err = errs
for _, f := range files {
err := inst.insertFile(f)
inst.Err = errors.Append(inst.Err, err)
diff --git a/cue/builtin.go b/cue/builtin.go
index 616cf4b..8532b7b 100644
--- a/cue/builtin.go
+++ b/cue/builtin.go
@@ -221,10 +221,10 @@
if x.isValidator() {
return x.Params[0]
}
- return x.kind()
+ return x.Kind()
}
-func (x *builtin) kind() kind {
+func (x *builtin) Kind() kind {
return lambdaKind
}
@@ -276,9 +276,9 @@
}
for i, a := range args {
if x.Params[i] != bottomKind {
- if unifyType(x.Params[i], a.kind()) == bottomKind {
+ if unifyType(x.Params[i], a.Kind()) == bottomKind {
const msg = "cannot use %s (type %s) as %s in argument %d to %s"
- return ctx.mkErr(src, x, msg, ctx.str(a), a.kind(), x.Params[i], i+1, x.name(ctx))
+ return ctx.mkErr(src, x, msg, ctx.str(a), a.Kind(), x.Params[i], i+1, x.name(ctx))
}
}
}
@@ -448,10 +448,10 @@
func (c *callCtxt) invalidArgType(arg value, i int, typ string, err error) {
if err != nil {
c.errf(c.src, err, "cannot use %s (type %s) as %s in argument %d to %s: %v",
- c.ctx.str(arg), arg.kind(), typ, i, c.name(), err)
+ c.ctx.str(arg), arg.Kind(), typ, i, c.name(), err)
} else {
c.errf(c.src, nil, "cannot use %s (type %s) as %s in argument %d to %s",
- c.ctx.str(arg), arg.kind(), typ, i, c.name())
+ c.ctx.str(arg), arg.Kind(), typ, i, c.name())
}
}
@@ -506,7 +506,7 @@
c.invalidArgType(c.args[i], i, "Decimal", err)
return nil
}
- return &c.args[i].(*numLit).v
+ return &c.args[i].(*numLit).X
}
func (c *callCtxt) float64(i int) float64 {
@@ -628,7 +628,7 @@
j, i, c.name(), err)
break
}
- a = append(a, &num.v)
+ a = append(a, &num.X)
}
return a
}
diff --git a/cue/context.go b/cue/context.go
index 947987d..a63e3e9 100644
--- a/cue/context.go
+++ b/cue/context.go
@@ -87,7 +87,7 @@
cons := c.constraints
c.constraints = c.constraints[:0]
for _, dc := range cons {
- v := binOp(c, dc, dc.op, dc.left.evalPartial(c), dc.right.evalPartial(c))
+ v := binOp(c, dc, dc.Op, dc.X.evalPartial(c), dc.Y.evalPartial(c))
if isBottom(v) {
return v
}
diff --git a/cue/debug.go b/cue/debug.go
index 12fbe73..4472abb 100644
--- a/cue/debug.go
+++ b/cue/debug.go
@@ -186,67 +186,67 @@
writef("<%s>", p.ctx.ref(x.node))
}
case *selectorExpr:
- f := lambdaName(x.feature, x.x)
- if _, ok := x.x.(*nodeRef); ok && !p.showNodeRef {
+ f := lambdaName(x.Sel, x.X)
+ if _, ok := x.X.(*nodeRef); ok && !p.showNodeRef {
write(p.label(f))
} else {
- p.str(x.x)
+ p.str(x.X)
writef(".%v", p.label(f))
}
case *indexExpr:
- p.str(x.x)
+ p.str(x.X)
write("[")
- p.str(x.index)
+ p.str(x.Index)
write("]")
case *sliceExpr:
- p.str(x.x)
+ p.str(x.X)
write("[")
- if x.lo != nil {
- p.str(x.lo)
+ if x.Lo != nil {
+ p.str(x.Lo)
}
write(":")
- if x.hi != nil {
- p.str(x.hi)
+ if x.Hi != nil {
+ p.str(x.Hi)
}
write("]")
case *callExpr:
- p.str(x.x)
+ p.str(x.Fun)
write(" (")
- for i, a := range x.args {
+ for i, a := range x.Args {
p.str(a)
- if i < len(x.args)-1 {
+ if i < len(x.Args)-1 {
write(",")
}
}
write(")")
case *customValidator:
- p.str(x.call)
+ p.str(x.Builtin)
write(" (")
- for i, a := range x.args {
+ for i, a := range x.Args {
p.str(a)
- if i < len(x.args)-1 {
+ if i < len(x.Args)-1 {
write(",")
}
}
write(")")
case *unaryExpr:
- write(x.op)
- p.str(x.x)
+ write(x.Op)
+ p.str(x.X)
case *binaryExpr:
- if x.op == opUnifyUnchecked {
- p.str(x.left)
+ if x.Op == opUnifyUnchecked {
+ p.str(x.X)
write(", ")
- p.str(x.right)
+ p.str(x.Y)
break
}
write("(")
- p.str(x.left)
- writef(" %v ", x.op)
- p.str(x.right)
+ p.str(x.X)
+ writef(" %v ", x.Op)
+ p.str(x.Y)
write(")")
case *unification:
write("(")
- for i, v := range x.values {
+ for i, v := range x.Values {
if i != 0 {
writef(" & ")
}
@@ -255,14 +255,14 @@
write(")")
case *disjunction:
write("(")
- for i, v := range x.values {
+ for i, v := range x.Values {
if i != 0 {
writef(" | ")
}
- if v.marked {
+ if v.Default {
writef("*")
}
- p.str(v.val)
+ p.str(v.Val)
}
write(")")
case *lambdaExpr:
@@ -418,22 +418,22 @@
a = x.fn.params.arcs[1]
p.writef(p.label(a.feature))
writef(" in ")
- p.str(x.source)
+ p.str(x.Src)
p.str(x.fn.value)
case *guard:
writef(" if ")
- p.str(x.condition)
- p.str(x.value)
+ p.str(x.Condition)
+ p.str(x.Dst)
case *nullLit:
write("null")
case *boolLit:
- writef("%v", x.b)
+ writef("%v", x.B)
case *stringLit:
- writef("%q", x.str)
+ writef("%q", x.Str)
case *bytesLit:
- str := strconv.Quote(string(x.b))
+ str := strconv.Quote(string(x.B))
str = str[1 : len(str)-1]
writef("'%s'", str)
case *numLit:
@@ -447,10 +447,10 @@
case floatKind:
p.writef("float & ")
}
- p.writef("%v", x.op)
- p.str(x.value)
+ p.writef("%v", x.Op)
+ p.str(x.Expr)
case *interpolation:
- for i, e := range x.parts {
+ for i, e := range x.Parts {
if i != 0 {
write("+")
}
@@ -469,7 +469,7 @@
}
ln := 0
if n != nil {
- x, _ := n.v.Int64()
+ x, _ := n.X.Int64()
ln = int(x)
}
open := false
@@ -532,7 +532,7 @@
case *top:
write("_") // ⊤
case *basicType:
- write(x.k.String())
+ write(x.K.String())
default:
panic(fmt.Sprintf("unimplemented type %T", x))
diff --git a/cue/errors.go b/cue/errors.go
index a8af56d..5788607 100644
--- a/cue/errors.go
+++ b/cue/errors.go
@@ -21,6 +21,7 @@
"cuelang.org/go/cue/ast"
"cuelang.org/go/cue/errors"
"cuelang.org/go/cue/token"
+ "cuelang.org/go/internal/core/adt"
)
var _ errors.Error = &nodeError{}
@@ -108,37 +109,37 @@
return a
}
-type errCode int
+type errCode = adt.ErrorCode
const (
- codeNone errCode = iota
- codeFatal
- codeNotExist
- codeTypeError
- codeIncomplete
- codeUser
- codeCycle
+ codeNone errCode = 0
+ codeFatal = adt.EvalError
+ codeNotExist = adt.NotExistError
+ codeTypeError = adt.EvalError
+ codeIncomplete = adt.IncompleteError
+ codeUser = adt.UserError
+ codeCycle = adt.CycleError
)
func isIncomplete(v value) bool {
if err, ok := v.(*bottom); ok {
- return err.code == codeIncomplete || err.code == codeCycle
+ return err.Code == codeIncomplete || err.Code == codeCycle
}
return false
}
func isLiteralBottom(v value) bool {
if err, ok := v.(*bottom); ok {
- return err.code == codeUser
+ return err.Code == codeUser
}
return false
}
-var errNotExists = &bottom{code: codeNotExist, format: "undefined value"}
+var errNotExists = &bottom{Code: codeNotExist, format: "undefined value"}
func exists(v value) bool {
if err, ok := v.(*bottom); ok {
- return err.code != codeNotExist
+ return err.Code != codeNotExist
}
return true
}
@@ -148,7 +149,7 @@
baseValue
index *index
- code errCode
+ Code errCode
exprDepth int
pos source
format string
@@ -160,7 +161,7 @@
wrapped *bottom
}
-func (x *bottom) kind() kind { return bottomKind }
+func (x *bottom) Kind() kind { return bottomKind }
func (x *bottom) Positions(ctx *context) []token.Pos {
var a []token.Pos
@@ -216,7 +217,7 @@
}
func cycleError(v evaluated) *bottom {
- if err, ok := v.(*bottom); ok && err.code == codeCycle {
+ if err, ok := v.(*bottom); ok && err.Code == codeCycle {
return err
}
return nil
@@ -228,7 +229,7 @@
}
e := mkBin(c, src.Pos(), op, a, b)
return c.mkErr(e, "invalid operation %s %s %s (mismatched types %s and %s)",
- c.str(a), op, c.str(b), a.kind(), b.kind())
+ c.str(a), op, c.str(b), a.Kind(), b.Kind())
}
func (idx *index) mkErr(src source, args ...interface{}) *bottom {
@@ -243,7 +244,7 @@
for i, a := range args {
switch x := a.(type) {
case errCode:
- e.code = x
+ e.Code = x
case *bottom:
e.wrapped = x
case []*bottom:
@@ -261,8 +262,8 @@
break outer
}
}
- if e.code == codeNone && e.wrapped != nil {
- e.code = e.wrapped.code
+ if e.Code == codeNone && e.wrapped != nil {
+ e.Code = e.wrapped.Code
}
return e
}
@@ -297,7 +298,7 @@
}
func isBottom(n value) bool {
- return n.kind() == bottomKind
+ return n.Kind() == bottomKind
}
func firstBottom(v ...value) *bottom {
diff --git a/cue/eval.go b/cue/eval.go
index 9965410..e348d26 100644
--- a/cue/eval.go
+++ b/cue/eval.go
@@ -30,23 +30,23 @@
func decycleRef(ctx *context, v value) (value, scope) {
switch x := v.(type) {
case *selectorExpr:
- v, sc := decycleRef(ctx, x.x)
+ v, sc := decycleRef(ctx, x.X)
if v == nil {
e := x.evalPartial(ctx)
v = e
if cycleError(e) != nil {
sc = &structLit{baseValue: x.base()}
- return &nodeRef{x.base(), sc, x.feature}, sc
+ return &nodeRef{x.base(), sc, x.Sel}, sc
}
return nil, nil
}
- return &selectorExpr{x.baseValue, v, x.feature}, sc
+ return &selectorExpr{x.baseValue, v, x.Sel}, sc
case *indexExpr:
- v, sc := decycleRef(ctx, x.x)
+ v, sc := decycleRef(ctx, x.X)
if v == x {
return nil, nil
}
- return &indexExpr{x.baseValue, v, x.index}, sc
+ return &indexExpr{x.baseValue, v, x.Index}, sc
case *nodeRef:
return nil, nil
}
@@ -117,20 +117,20 @@
e := newEval(ctx, true)
const msgType = "invalid operation: %[5]s (type %[3]s does not support selection)"
- v := e.eval(x.x, structKind|lambdaKind, msgType, x)
+ v := e.eval(x.X, structKind|lambdaKind, msgType, x)
if e.is(v, structKind|lambdaKind, "") {
sc, ok := v.(scope)
if !ok {
- return ctx.mkErr(x, "invalid subject to selector (found %v)", v.kind())
+ return ctx.mkErr(x, "invalid subject to selector (found %v)", v.Kind())
}
- n := sc.lookup(ctx, x.feature)
+ n := sc.lookup(ctx, x.Sel)
if n.optional {
- field := ctx.LabelStr(x.feature)
+ field := ctx.LabelStr(x.Sel)
return ctx.mkErr(x, codeIncomplete, "field %q is optional", field)
}
if n.val() == nil {
- field := ctx.LabelStr(x.feature)
+ field := ctx.LabelStr(x.Sel)
if st, ok := sc.(*structLit); ok && !st.isClosed() {
return ctx.mkErr(x, codeIncomplete, "undefined field %q", field)
}
@@ -140,7 +140,7 @@
}
return n.cache
}
- return e.err(&selectorExpr{x.baseValue, v, x.feature})
+ return e.err(&selectorExpr{x.baseValue, v, x.Sel})
}
func (x *selectorExpr) reference(ctx *context) (result value) {
@@ -152,20 +152,20 @@
e := newEval(ctx, true)
const msgType = "invalid operation: %[5]s (type %[3]s does not support selection)"
- v := e.eval(x.x, structKind|lambdaKind, msgType, x)
+ v := e.eval(x.X, structKind|lambdaKind, msgType, x)
if e.is(v, structKind|lambdaKind, "") {
sc, ok := v.(scope)
if !ok {
- return ctx.mkErr(x, "invalid subject to selector (found %v)", v.kind())
+ return ctx.mkErr(x, "invalid subject to selector (found %v)", v.Kind())
}
- n := sc.lookup(ctx, x.feature)
+ n := sc.lookup(ctx, x.Sel)
if n.optional {
- field := ctx.LabelStr(x.feature)
+ field := ctx.LabelStr(x.Sel)
return ctx.mkErr(x, codeIncomplete, "field %q is optional", field)
}
if n.val() == nil {
- field := ctx.LabelStr(x.feature)
+ field := ctx.LabelStr(x.Sel)
if st, ok := sc.(*structLit); ok && !st.isClosed() {
return ctx.mkErr(x, codeIncomplete, "undefined field %q", field)
}
@@ -175,7 +175,7 @@
}
return n.v
}
- return e.err(&selectorExpr{x.baseValue, v, x.feature})
+ return e.err(&selectorExpr{x.baseValue, v, x.Sel})
}
func (x *indexExpr) evalPartial(ctx *context) (result evaluated) {
@@ -189,9 +189,9 @@
const msgType = "invalid operation: %[5]s (type %[3]s does not support indexing)"
const msgIndexType = "invalid %[5]s index %[1]s (type %[3]s)"
- val := e.eval(x.x, listKind|structKind, msgType, x)
- k := val.kind()
- index := e.eval(x.index, stringKind|intKind, msgIndexType, k)
+ val := e.eval(x.X, listKind|structKind, msgType, x)
+ k := val.Kind()
+ index := e.eval(x.Index, stringKind|intKind, msgIndexType, k)
switch v := val.(type) {
case *structLit:
@@ -219,7 +219,7 @@
i := index.(*numLit).intValue(ctx)
if i < 0 {
const msg = "invalid %[4]s index %[1]s (index must be non-negative)"
- return e.mkErr(x.index, index, 0, k, msg)
+ return e.mkErr(x.Index, index, 0, k, msg)
}
return v.at(ctx, i)
}
@@ -238,9 +238,9 @@
const msgType = "invalid operation: %[5]s (type %[3]s does not support indexing)"
const msgIndexType = "invalid %[5]s index %[1]s (type %[3]s)"
- val := e.eval(x.x, listKind|structKind, msgType, x)
- k := val.kind()
- index := e.eval(x.index, stringKind|intKind, msgIndexType, k)
+ val := e.eval(x.X, listKind|structKind, msgType, x)
+ k := val.Kind()
+ index := e.eval(x.Index, stringKind|intKind, msgIndexType, k)
switch v := val.(type) {
case *structLit:
@@ -268,7 +268,7 @@
i := index.(*numLit).intValue(ctx)
if i < 0 {
const msg = "invalid %[4]s index %[1]s (index must be non-negative)"
- return e.mkErr(x.index, index, 0, k, msg)
+ return e.mkErr(x.Index, index, 0, k, msg)
}
return v.iterAt(ctx, i).v
}
@@ -278,7 +278,7 @@
i := index.(*numLit).intValue(ctx)
if i < 0 {
const msg = "invalid %[4]s index %[1]s (index must be non-negative)"
- return e.mkErr(x.index, index, 0, k, msg)
+ return e.mkErr(x.Index, index, 0, k, msg)
}
return v.at(ctx, i)
}
@@ -297,9 +297,9 @@
e := newEval(ctx, true)
const msgType = "cannot slice %[2]s (type %[3]s)"
const msgInvalidIndex = "invalid slice index %[1]s (type %[3]s)"
- val := e.eval(x.x, listKind, msgType)
- lo := e.evalAllowNil(x.lo, intKind, msgInvalidIndex)
- hi := e.evalAllowNil(x.hi, intKind, msgInvalidIndex)
+ val := e.eval(x.X, listKind, msgType)
+ lo := e.evalAllowNil(x.Lo, intKind, msgInvalidIndex)
+ hi := e.evalAllowNil(x.Hi, intKind, msgInvalidIndex)
var low, high *numLit
if lo != nil && e.is(lo, intKind, msgInvalidIndex) {
low = lo.(*numLit)
@@ -329,9 +329,9 @@
e := newEval(ctx, true)
- fn := e.eval(x.x, lambdaKind, "cannot call non-function %[2]s (type %[3]s)")
- args := make([]evaluated, len(x.args))
- for i, a := range x.args {
+ fn := e.eval(x.Fun, lambdaKind, "cannot call non-function %[2]s (type %[3]s)")
+ args := make([]evaluated, len(x.Args))
+ for i, a := range x.Args {
args[i] = e.evalPartial(a, typeKinds, "never triggers")
}
if !e.hasErr() {
@@ -343,7 +343,7 @@
// Construct a simplified call for reporting purposes.
err := &callExpr{x.baseValue, fn, nil}
for _, a := range args {
- err.args = append(err.args, a)
+ err.Args = append(err.Args, a)
}
return e.err(err)
}
@@ -361,17 +361,17 @@
defer uni(indent(ctx, "bound", x))
defer func() { ctx.debugPrint("result:", result) }()
}
- v := x.value.evalPartial(ctx)
+ v := x.Expr.evalPartial(ctx)
if isBottom(v) {
if isIncomplete(v) {
return v
}
return ctx.mkErr(x, v, "error evaluating bound")
}
- if v == x.value {
+ if v == x.Expr {
return x
}
- return newBound(ctx, x.baseValue, x.op, x.k, v)
+ return newBound(ctx, x.baseValue, x.Op, x.k, v)
}
func (x *interpolation) evalPartial(ctx *context) (result evaluated) {
@@ -381,14 +381,14 @@
}
buf := bytes.Buffer{}
var incomplete value
- for _, v := range x.parts {
+ for _, v := range x.Parts {
switch e := ctx.manifest(v).(type) {
case *bottom:
return e
case *stringLit, *numLit, *durationLit:
buf.WriteString(e.strValue())
default:
- k := e.kind()
+ k := e.Kind()
if k&stringableKind == bottomKind {
return ctx.mkErr(e, "expression in interpolation must evaluate to a number kind or string (found %v)", k)
}
@@ -471,7 +471,7 @@
if err := firstBottom(k, v); err != nil {
return err
}
- if !k.kind().isAnyOf(stringKind) {
+ if !k.Kind().isAnyOf(stringKind) {
return ctx.mkErr(k, "key must be of type string")
}
f := ctx.Label(k.strValue(), true)
@@ -518,23 +518,23 @@
}
dn := &disjunction{
x.baseValue,
- make([]dValue, 0, len(x.values)),
+ make([]dValue, 0, len(x.Values)),
make([]*bottom, 0, len(x.errors)),
- x.hasDefaults,
+ x.HasDefaults,
}
changed := false
- for _, v := range x.values {
- n := v.val.evalPartial(ctx)
- changed = changed || n != v.val
+ for _, v := range x.Values {
+ n := v.Val.evalPartial(ctx)
+ changed = changed || n != v.Val
// Including elements of disjunctions recursively makes default handling
// associative (*a | (*b|c)) == ((*a|*b) | c).
if d, ok := n.(*disjunction); ok {
changed = true
- for _, dv := range d.values {
- dn.add(ctx, dv.val, dv.marked)
+ for _, dv := range d.Values {
+ dn.add(ctx, dv.Val, dv.Default)
}
} else {
- dn.add(ctx, n, v.marked)
+ dn.add(ctx, n, v.Default)
}
}
if !changed {
@@ -547,12 +547,12 @@
}
func (x *disjunction) manifest(ctx *context) (result evaluated) {
- values := make([]dValue, 0, len(x.values))
+ values := make([]dValue, 0, len(x.Values))
validValue := false
- for _, dv := range x.values {
+ for _, dv := range x.Values {
switch {
- case isBottom(dv.val):
- case dv.marked:
+ case isBottom(dv.Val):
+ case dv.Default:
values = append(values, dv)
default:
validValue = true
@@ -565,8 +565,8 @@
case !validValue:
return x
default:
- for _, dv := range x.values {
- dv.marked = false
+ for _, dv := range x.Values {
+ dv.Default = false
values = append(values, dv)
}
}
@@ -576,7 +576,7 @@
return x
case 1:
- return values[0].val.evalPartial(ctx)
+ return values[0].Val.evalPartial(ctx)
}
x = &disjunction{x.baseValue, values, x.errors, true}
@@ -590,17 +590,17 @@
}
var left, right evaluated
- if _, isUnify := x.op.unifyType(); !isUnify {
+ if _, isUnify := x.Op.unifyType(); !isUnify {
ctx.incEvalDepth()
- left = ctx.manifest(x.left)
- right = ctx.manifest(x.right)
+ left = ctx.manifest(x.X)
+ right = ctx.manifest(x.Y)
ctx.decEvalDepth()
// TODO: allow comparing to a literal bottom only. Find something more
// principled perhaps. One should especially take care that two values
// evaluating to bottom don't evaluate to true. For now we check for
// bottom here and require that one of the values be a bottom literal.
- if isLiteralBottom(x.left) || isLiteralBottom(x.right) {
+ if isLiteralBottom(x.X) || isLiteralBottom(x.Y) {
if b := validate(ctx, left); b != nil {
left = b
}
@@ -609,7 +609,7 @@
}
leftBottom := isBottom(left)
rightBottom := isBottom(right)
- switch x.op {
+ switch x.Op {
case opEql:
return &boolLit{x.baseValue, leftBottom == rightBottom}
case opNeq:
@@ -617,13 +617,13 @@
}
}
} else {
- left = resolveReference(ctx, x.left)
- right = resolveReference(ctx, x.right)
+ left = resolveReference(ctx, x.X)
+ right = resolveReference(ctx, x.Y)
- if err := cycleError(left); err != nil && ctx.inSum == 0 && right.kind().isAtom() {
+ if err := cycleError(left); err != nil && ctx.inSum == 0 && right.Kind().isAtom() {
return ctx.delayConstraint(right, x)
}
- if err := cycleError(right); err != nil && ctx.inSum == 0 && left.kind().isAtom() {
+ if err := cycleError(right); err != nil && ctx.inSum == 0 && left.Kind().isAtom() {
return ctx.delayConstraint(left, x)
}
@@ -631,7 +631,7 @@
// If other value is a cycle or list, return the original forwarded,
// but ensure the value is not cached. Object/list error?
}
- return binOp(ctx, x, x.op, left, right)
+ return binOp(ctx, x, x.Op, left, right)
}
func (x *unaryExpr) evalPartial(ctx *context) (result evaluated) {
@@ -640,14 +640,14 @@
defer func() { ctx.debugPrint("result:", result) }()
}
- return evalUnary(ctx, x, x.op, x.x)
+ return evalUnary(ctx, x, x.Op, x.X)
}
func evalUnary(ctx *context, src source, op op, x value) evaluated {
v := ctx.manifest(x)
const numeric = numKind | durationKind
- kind := v.kind()
+ kind := v.Kind()
switch op {
case opSub:
if kind&numeric == bottomKind {
@@ -656,7 +656,7 @@
switch v := v.(type) {
case *numLit:
f := *v
- f.v.Neg(&v.v)
+ f.X.Neg(&v.X)
return &f
case *durationLit:
d := *v
@@ -675,7 +675,7 @@
case *top:
return &basicType{v.baseValue, numeric | nonGround}
case *basicType:
- return &basicType{v.baseValue, (v.k & numeric) | nonGround}
+ return &basicType{v.baseValue, (v.K & numeric) | nonGround}
}
return ctx.mkErr(src, codeIncomplete, "operand %s of '+' not concrete (was %s)", ctx.str(x), kind)
@@ -685,7 +685,7 @@
}
switch v := v.(type) {
case *boolLit:
- return &boolLit{src.base(), !v.b}
+ return &boolLit{src.base(), !v.B}
}
return ctx.mkErr(src, codeIncomplete, "operand %s of '!' not concrete (was %s)", ctx.str(x), kind)
}
diff --git a/cue/evaluator.go b/cue/evaluator.go
index 703879a..ccdc429 100644
--- a/cue/evaluator.go
+++ b/cue/evaluator.go
@@ -58,7 +58,7 @@
desc, // format string
eval, // 1
orig, // 2
- eval.kind(), // 3
+ eval.Kind(), // 3
want}, // 4
args...)
for i := 3; i < len(args); i++ {
@@ -86,7 +86,7 @@
e.bottom = append(e.bottom, eval.(*bottom))
return eval
}
- got := eval.kind()
+ got := eval.Kind()
if got&want == bottomKind {
return e.mkErr(v, eval, codeTypeError, want, desc, extraArgs...)
}
@@ -103,7 +103,7 @@
e.bottom = append(e.bottom, eval.(*bottom))
return eval
}
- got := eval.kind()
+ got := eval.Kind()
if got&want == bottomKind {
return e.mkErr(v, eval, codeTypeError, want, desc, extraArgs...)
}
@@ -122,7 +122,7 @@
// Even though errors are ground, we treat them as not allowed.
return false
}
- got := v.kind()
+ got := v.Kind()
if got&want == bottomKind {
e.mkErr(v, v, codeTypeError, want, desc, args...)
return false
@@ -136,11 +136,11 @@
// otherwise, try to extract a fatal error from the given value.
// otherwise return an incomplete error with the given value as offending.
for _, b := range e.bottom {
- if b.code != codeIncomplete {
+ if b.Code != codeIncomplete {
return b
}
}
b := *e.bottom[0]
- b.code = codeIncomplete
+ b.Code = codeIncomplete
return &b
}
diff --git a/cue/export.go b/cue/export.go
index f86592d..a16e956 100644
--- a/cue/export.go
+++ b/cue/export.go
@@ -168,7 +168,7 @@
case *feed:
feed := &ast.ForClause{
Value: p.identifier(x.fn.params.arcs[1].feature),
- Source: p.expr(x.source),
+ Source: p.expr(x.Src),
}
key := x.fn.params.arcs[0]
if p.ctx.LabelStr(key.feature) != "_" {
@@ -177,7 +177,7 @@
return feed, x.fn.value.(yielder)
case *guard:
- return &ast.IfClause{Condition: p.expr(x.condition)}, x.value
+ return &ast.IfClause{Condition: p.expr(x.Condition)}, x.Dst
}
panic(fmt.Sprintf("unsupported clause type %T", v))
}
@@ -350,13 +350,13 @@
// This may break some unnecessary cycles.
noResolve = true
}
- if isBottom(e) || (v.kind().hasReferences() && noResolve) {
+ if isBottom(e) || (v.Kind().hasReferences() && noResolve) {
return p.expr(v)
}
} else {
// Data mode.
- if p.mode.concrete && !m.kind().isGround() {
+ if p.mode.concrete && !m.Kind().isGround() {
p.addIncomplete(v)
}
// TODO: do something more principled than this hack.
@@ -367,7 +367,7 @@
if isDisjunction(v) || isBottom(e) {
return p.expr(v)
}
- if v.kind()&structKind == 0 {
+ if v.Kind()&structKind == 0 {
return p.expr(e)
}
if optional || isDisjunction(e) {
@@ -407,7 +407,7 @@
}
if !p.isComplete(x, true) {
- if p.mode.concrete && !x.kind().isGround() {
+ if p.mode.concrete && !x.Kind().isGround() {
p.addIncomplete(v)
}
switch {
@@ -417,7 +417,7 @@
}
p = &exporter{p.ctx, options{raw: true}, p.stack, p.top, p.imports, p.inDef, nil}
return p.expr(v)
- case v.kind().hasReferences() && !p.mode.resolveReferences:
+ case v.Kind().hasReferences() && !p.mode.resolveReferences:
case doEval(p.mode):
v = e
}
@@ -455,13 +455,13 @@
return ast.NewIdent(short)
case *selectorExpr:
- n := p.expr(x.x)
+ n := p.expr(x.X)
if n != nil {
- return ast.NewSel(n, p.ctx.LabelStr(x.feature))
+ return ast.NewSel(n, p.ctx.LabelStr(x.Sel))
}
- f := x.feature
+ f := x.Sel
ident := p.identifier(f)
- node, ok := x.x.(*nodeRef)
+ node, ok := x.X.(*nodeRef)
if !ok {
return p.badf("selector without node")
}
@@ -500,54 +500,54 @@
return ident
case *indexExpr:
- return &ast.IndexExpr{X: p.expr(x.x), Index: p.expr(x.index)}
+ return &ast.IndexExpr{X: p.expr(x.X), Index: p.expr(x.Index)}
case *sliceExpr:
return &ast.SliceExpr{
- X: p.expr(x.x),
- Low: p.expr(x.lo),
- High: p.expr(x.hi),
+ X: p.expr(x.X),
+ Low: p.expr(x.Lo),
+ High: p.expr(x.Hi),
}
case *callExpr:
call := &ast.CallExpr{}
- b := x.x.evalPartial(p.ctx)
+ b := x.Fun.evalPartial(p.ctx)
if b, ok := b.(*builtin); ok {
call.Fun = p.expr(b)
} else {
- call.Fun = p.expr(x.x)
+ call.Fun = p.expr(x.Fun)
}
- for _, a := range x.args {
+ for _, a := range x.Args {
call.Args = append(call.Args, p.expr(a))
}
return call
case *customValidator:
- call := ast.NewCall(p.expr(x.call))
- for _, a := range x.args {
+ call := ast.NewCall(p.expr(x.Builtin))
+ for _, a := range x.Args {
call.Args = append(call.Args, p.expr(a))
}
return call
case *unaryExpr:
- return &ast.UnaryExpr{Op: opMap[x.op], X: p.expr(x.x)}
+ return &ast.UnaryExpr{Op: opMap[x.Op], X: p.expr(x.X)}
case *binaryExpr:
// opUnifyUnchecked: represented as embedding. The two arguments must
// be structs.
- if x.op == opUnifyUnchecked {
+ if x.Op == opUnifyUnchecked {
s := ast.NewStruct()
return p.closeOrOpen(s, p.embedding(s, x))
}
- return ast.NewBinExpr(opMap[x.op], p.expr(x.left), p.expr(x.right))
+ return ast.NewBinExpr(opMap[x.Op], p.expr(x.X), p.expr(x.Y))
case *bound:
- return &ast.UnaryExpr{Op: opMap[x.op], X: p.expr(x.value)}
+ return &ast.UnaryExpr{Op: opMap[x.Op], X: p.expr(x.Expr)}
case *unification:
b := boundSimplifier{p: p}
vals := make([]evaluated, 0, 3)
- for _, v := range x.values {
+ for _, v := range x.Values {
if !b.add(v) {
vals = append(vals, v)
}
@@ -559,18 +559,18 @@
return e
case *disjunction:
- if len(x.values) == 1 {
- return p.expr(x.values[0].val)
+ if len(x.Values) == 1 {
+ return p.expr(x.Values[0].Val)
}
expr := func(v dValue) ast.Expr {
- e := p.expr(v.val)
- if v.marked {
+ e := p.expr(v.Val)
+ if v.Default {
e = &ast.UnaryExpr{Op: token.MUL, X: e}
}
return e
}
- bin := expr(x.values[0])
- for _, v := range x.values[1:] {
+ bin := expr(x.Values[0])
+ for _, v := range x.Values[1:] {
bin = ast.NewBinExpr(token.OR, bin, expr(v))
}
return bin
@@ -616,23 +616,23 @@
return ast.NewNull()
case *boolLit:
- return ast.NewBool(x.b)
+ return ast.NewBool(x.B)
case *stringLit:
return &ast.BasicLit{
Kind: token.STRING,
- Value: quote(x.str, '"'),
+ Value: quote(x.Str, '"'),
}
case *bytesLit:
return &ast.BasicLit{
Kind: token.STRING,
- Value: quote(string(x.b), '\''),
+ Value: quote(string(x.B), '\''),
}
case *numLit:
kind := token.FLOAT
- if x.k&intKind != 0 {
+ if x.K&intKind != 0 {
kind = token.INT
}
return &ast.BasicLit{Kind: kind, Value: x.String()}
@@ -644,8 +644,8 @@
t := &ast.Interpolation{}
multiline := false
// TODO: mark formatting in interpolation itself.
- for i := 0; i < len(x.parts); i += 2 {
- str := x.parts[i].(*stringLit).str
+ for i := 0; i < len(x.Parts); i += 2 {
+ str := x.Parts[i].(*stringLit).Str
if strings.IndexByte(str, '\n') >= 0 {
multiline = true
break
@@ -657,15 +657,15 @@
}
prefix := quote
suffix := `\(`
- for i, e := range x.parts {
+ for i, e := range x.Parts {
if i%2 == 1 {
t.Elts = append(t.Elts, p.expr(e))
} else {
buf := []byte(prefix)
- if i == len(x.parts)-1 {
+ if i == len(x.Parts)-1 {
suffix = quote
}
- str := e.(*stringLit).str
+ str := e.(*stringLit).Str
if multiline {
buf = appendEscapeMulti(buf, str, '"')
} else {
@@ -700,7 +700,7 @@
}
ln := 0
if num != nil {
- x, _ := num.v.Int64()
+ x, _ := num.X.Int64()
ln = int(x)
}
open := false
@@ -751,7 +751,7 @@
return p.ident("_")
case *basicType:
- return p.ident(x.k.String())
+ return p.ident(x.K.String())
case *lambdaExpr:
return p.ident("TODO: LAMBDA")
@@ -976,13 +976,13 @@
return p.isClosed(x)
case *binaryExpr:
- if x.op != opUnifyUnchecked {
+ if x.Op != opUnifyUnchecked {
// should not happen
s.Elts = append(s.Elts, &ast.EmbedDecl{Expr: p.expr(x)})
return false
}
- leftClosed := p.embedding(s, x.left)
- rightClosed := p.embedding(s, x.right)
+ leftClosed := p.embedding(s, x.X)
+ rightClosed := p.embedding(s, x.Y)
return leftClosed || rightClosed
}
s.Elts = append(s.Elts, &ast.EmbedDecl{Expr: p.expr(n)})
@@ -1103,7 +1103,7 @@
func (s *boundSimplifier) add(v value) (used bool) {
switch x := v.(type) {
case *basicType:
- switch x.k & scalarKinds {
+ switch x.K & scalarKinds {
case intKind:
s.isInt = true
return true
@@ -1113,10 +1113,10 @@
if x.k&concreteKind == intKind {
s.isInt = true
}
- switch x.op {
+ switch x.Op {
case opGtr:
- if n, ok := x.value.(*numLit); ok {
- if s.min == nil || s.minNum.v.Cmp(&n.v) != 1 {
+ if n, ok := x.Expr.(*numLit); ok {
+ if s.min == nil || s.minNum.X.Cmp(&n.X) != 1 {
s.min = x
s.minNum = n
}
@@ -1124,8 +1124,8 @@
}
case opGeq:
- if n, ok := x.value.(*numLit); ok {
- if s.min == nil || s.minNum.v.Cmp(&n.v) == -1 {
+ if n, ok := x.Expr.(*numLit); ok {
+ if s.min == nil || s.minNum.X.Cmp(&n.X) == -1 {
s.min = x
s.minNum = n
}
@@ -1133,8 +1133,8 @@
}
case opLss:
- if n, ok := x.value.(*numLit); ok {
- if s.max == nil || s.maxNum.v.Cmp(&n.v) != -1 {
+ if n, ok := x.Expr.(*numLit); ok {
+ if s.max == nil || s.maxNum.X.Cmp(&n.X) != -1 {
s.max = x
s.maxNum = n
}
@@ -1142,8 +1142,8 @@
}
case opLeq:
- if n, ok := x.value.(*numLit); ok {
- if s.max == nil || s.maxNum.v.Cmp(&n.v) == 1 {
+ if n, ok := x.Expr.(*numLit); ok {
+ if s.max == nil || s.maxNum.X.Cmp(&n.X) == 1 {
s.max = x
s.maxNum = n
}
@@ -1180,12 +1180,12 @@
e = ast.NewIdent(t)
break
}
- if sign := s.minNum.v.Sign(); sign == -1 {
+ if sign := s.minNum.X.Sign(); sign == -1 {
e = ast.NewIdent("int")
} else {
e = ast.NewIdent("uint")
- if sign == 0 && s.min.op == opGeq {
+ if sign == 0 && s.min.Op == opGeq {
s.min = nil
break
}
@@ -1209,26 +1209,26 @@
func (s *boundSimplifier) matchRange(ranges []builtinRange) (t string) {
for _, r := range ranges {
- if !s.minNum.v.IsZero() && s.min.op == opGeq && s.minNum.v.Cmp(r.lo) == 0 {
- switch s.maxNum.v.Cmp(r.hi) {
+ if !s.minNum.X.IsZero() && s.min.Op == opGeq && s.minNum.X.Cmp(r.lo) == 0 {
+ switch s.maxNum.X.Cmp(r.hi) {
case 0:
- if s.max.op == opLeq {
+ if s.max.Op == opLeq {
s.max = nil
}
s.min = nil
return r.typ
case -1:
- if !s.minNum.v.IsZero() {
+ if !s.minNum.X.IsZero() {
s.min = nil
return r.typ
}
case 1:
}
- } else if s.max.op == opLeq && s.maxNum.v.Cmp(r.hi) == 0 {
- switch s.minNum.v.Cmp(r.lo) {
+ } else if s.max.Op == opLeq && s.maxNum.X.Cmp(r.hi) == 0 {
+ switch s.minNum.X.Cmp(r.lo) {
case -1:
case 0:
- if s.min.op == opGeq {
+ if s.min.Op == opGeq {
s.min = nil
}
fallthrough
diff --git a/cue/go.go b/cue/go.go
index 2be1ae0..ece6aa6 100644
--- a/cue/go.go
+++ b/cue/go.go
@@ -230,22 +230,22 @@
case *big.Int:
n := newInt(src.base(), 0)
- n.v.Coeff.Set(v)
+ n.X.Coeff.Set(v)
if v.Sign() < 0 {
- n.v.Coeff.Neg(&n.v.Coeff)
- n.v.Negative = true
+ n.X.Coeff.Neg(&n.X.Coeff)
+ n.X.Negative = true
}
return n
case *big.Rat:
// should we represent this as a binary operation?
n := newNum(src, numKind, 0)
- _, err := ctx.Quo(&n.v, apd.NewWithBigInt(v.Num(), 0), apd.NewWithBigInt(v.Denom(), 0))
+ _, err := ctx.Quo(&n.X, apd.NewWithBigInt(v.Num(), 0), apd.NewWithBigInt(v.Denom(), 0))
if err != nil {
return ctx.mkErr(src, err)
}
if !v.IsInt() {
- n.k = floatKind
+ n.K = floatKind
}
return n
@@ -255,7 +255,7 @@
case *apd.Decimal:
n := newNum(src, numKind, 0).set(v)
if !n.isInt(ctx) {
- n.k = floatKind
+ n.K = floatKind
}
return n
@@ -514,15 +514,15 @@
switch reflect.Zero(t).Interface().(type) {
case *big.Int, big.Int:
- e = &basicType{k: intKind}
+ e = &basicType{K: intKind}
goto store
case *big.Float, big.Float, *big.Rat, big.Rat:
- e = &basicType{k: numKind}
+ e = &basicType{K: numKind}
goto store
case *apd.Decimal, apd.Decimal:
- e = &basicType{k: numKind}
+ e = &basicType{K: numKind}
goto store
}
@@ -565,13 +565,13 @@
e = predefinedRanges["int64"]
case reflect.String:
- e = &basicType{k: stringKind}
+ e = &basicType{K: stringKind}
case reflect.Bool:
- e = &basicType{k: boolKind}
+ e = &basicType{K: boolKind}
case reflect.Float32, reflect.Float64:
- e = &basicType{k: floatKind}
+ e = &basicType{K: floatKind}
case reflect.Struct:
// First iterate to create struct, then iterate another time to
@@ -630,7 +630,7 @@
case reflect.Array, reflect.Slice:
if t.Elem().Kind() == reflect.Uint8 {
- e = &basicType{k: bytesKind}
+ e = &basicType{K: bytesKind}
} else {
elem := goTypeToValueRec(ctx, allowNullDefault, t.Elem())
if elem == nil {
@@ -658,7 +658,7 @@
obj := newStruct(baseValue{})
sig := ¶ms{}
- sig.add(ctx.Label("_", true), &basicType{k: stringKind})
+ sig.add(ctx.Label("_", true), &basicType{K: stringKind})
v := goTypeToValueRec(ctx, allowNullDefault, t.Elem())
if v == nil {
return ctx.mkErr(baseValue{}, "unsupported Go type (%v)", t.Elem())
@@ -680,7 +680,7 @@
}
func wrapOrNull(e value) value {
- if e == nil || isBottom(e) || e.kind().isAnyOf(nullKind) {
+ if e == nil || isBottom(e) || e.Kind().isAnyOf(nullKind) {
return e
}
return makeNullable(e, true)
@@ -689,10 +689,10 @@
func makeNullable(e value, nullIsDefault bool) value {
return &disjunction{
baseValue: baseValue{e},
- values: []dValue{
- {val: &nullLit{}, marked: nullIsDefault},
- {val: e}},
+ Values: []dValue{
+ {Val: &nullLit{}, Default: nullIsDefault},
+ {Val: e}},
errors: nil,
- hasDefaults: nullIsDefault,
+ HasDefaults: nullIsDefault,
}
}
diff --git a/cue/instance.go b/cue/instance.go
index 4258436..e51c2bb 100644
--- a/cue/instance.go
+++ b/cue/instance.go
@@ -158,7 +158,7 @@
}
obj, ok := x.(*structLit)
if !ok {
- return ctx.mkErr(x, "instance is not a struct, found %s", x.kind())
+ return ctx.mkErr(x, "instance is not a struct, found %s", x.Kind())
}
v := newVisitor(ctx.index, nil, nil, obj, true)
return v.walk(expr).evalPartial(ctx)
diff --git a/cue/lit.go b/cue/lit.go
index 8cfa900..2d2c778 100644
--- a/cue/lit.go
+++ b/cue/lit.go
@@ -52,7 +52,7 @@
kind = intKind
}
n := newNum(newExpr(l), kind, 0)
- if err = p.num.Decimal(&n.v); err != nil {
+ if err = p.num.Decimal(&n.X); err != nil {
return ctx.mkErr(newNode(l), err)
}
return n
diff --git a/cue/lit_test.go b/cue/lit_test.go
index c7912be..9cf25cf 100644
--- a/cue/lit_test.go
+++ b/cue/lit_test.go
@@ -63,8 +63,8 @@
var (
nullSentinel = &nullLit{}
- trueSentinel = &boolLit{b: true}
- falseSentinel = &boolLit{b: false}
+ trueSentinel = &boolLit{B: true}
+ falseSentinel = &boolLit{B: false}
)
func TestLiterals(t *testing.T) {
@@ -82,29 +82,29 @@
{"true", trueSentinel},
{"false", falseSentinel},
{"fls", &bottom{}},
- {`"foo"`, &stringLit{str: "foo"}},
- {`#"foo"#`, &stringLit{str: "foo"}},
- {`#""foo"#`, &stringLit{str: `"foo`}},
- {`#" ""#`, &stringLit{str: ` "`}},
- {`"\"foo\""`, &stringLit{str: `"foo"`}},
- {`"foo\u0032"`, &stringLit{str: `foo2`}},
- {`"foo\U00000033"`, &stringLit{str: `foo3`}},
- {`"foo\U0001f499"`, &stringLit{str: `foo💙`}},
- {`"\a\b\f\n\r\t\v"`, &stringLit{str: "\a\b\f\n\r\t\v"}},
+ {`"foo"`, &stringLit{Str: "foo"}},
+ {`#"foo"#`, &stringLit{Str: "foo"}},
+ {`#""foo"#`, &stringLit{Str: `"foo`}},
+ {`#" ""#`, &stringLit{Str: ` "`}},
+ {`"\"foo\""`, &stringLit{Str: `"foo"`}},
+ {`"foo\u0032"`, &stringLit{Str: `foo2`}},
+ {`"foo\U00000033"`, &stringLit{Str: `foo3`}},
+ {`"foo\U0001f499"`, &stringLit{Str: `foo💙`}},
+ {`"\a\b\f\n\r\t\v"`, &stringLit{Str: "\a\b\f\n\r\t\v"}},
{`"""
- """`, &stringLit{str: ""}},
+ """`, &stringLit{Str: ""}},
{`"""
abc
- """`, &stringLit{str: "abc"}},
+ """`, &stringLit{Str: "abc"}},
{`"""
abc
def
- """`, &stringLit{str: "abc\ndef"}},
+ """`, &stringLit{Str: "abc\ndef"}},
{`"""
abc
def
- """`, &stringLit{str: "abc\n\tdef"}},
- {`'\xff'`, &bytesLit{b: []byte("\xff")}},
+ """`, &stringLit{Str: "abc\n\tdef"}},
+ {`'\xff'`, &bytesLit{B: []byte("\xff")}},
{"1", mkInt(1)},
{"100_000", hk},
{"1.", mkFloat("1")},
diff --git a/cue/rewrite.go b/cue/rewrite.go
index f329f29..82da452 100644
--- a/cue/rewrite.go
+++ b/cue/rewrite.go
@@ -62,17 +62,17 @@
}
func (x *selectorExpr) rewrite(ctx *context, fn rewriteFunc) value {
- v := rewrite(ctx, x.x, fn)
- if v == x.x {
+ v := rewrite(ctx, x.X, fn)
+ if v == x.X {
return x
}
- return &selectorExpr{x.baseValue, v, x.feature}
+ return &selectorExpr{x.baseValue, v, x.Sel}
}
func (x *indexExpr) rewrite(ctx *context, fn rewriteFunc) value {
- v := rewrite(ctx, x.x, fn)
- index := rewrite(ctx, x.index, fn)
- if v == x.x && index == x.index {
+ v := rewrite(ctx, x.X, fn)
+ index := rewrite(ctx, x.Index, fn)
+ if v == x.X && index == x.Index {
return x
}
return &indexExpr{x.baseValue, v, index}
@@ -92,9 +92,9 @@
func (x *durationLit) rewrite(ctx *context, fn rewriteFunc) value { return x }
func (x *customValidator) rewrite(ctx *context, fn rewriteFunc) value {
- args := make([]evaluated, len(x.args))
+ args := make([]evaluated, len(x.Args))
changed := false
- for i, a := range x.args {
+ for i, a := range x.Args {
v := rewrite(ctx, a, fn)
args[i] = v.(evaluated)
changed = changed || v != a
@@ -102,28 +102,28 @@
if !changed {
return x
}
- return &customValidator{baseValue: x.baseValue, args: args, call: x.call}
+ return &customValidator{baseValue: x.baseValue, Args: args, Builtin: x.Builtin}
}
func (x *bound) rewrite(ctx *context, fn rewriteFunc) value {
- v := rewrite(ctx, x.value, fn)
- if v == x.value {
+ v := rewrite(ctx, x.Expr, fn)
+ if v == x.Expr {
return x
}
- return newBound(ctx, x.baseValue, x.op, x.k, v)
+ return newBound(ctx, x.baseValue, x.Op, x.k, v)
}
func (x *interpolation) rewrite(ctx *context, fn rewriteFunc) value {
- parts := make([]value, len(x.parts))
+ parts := make([]value, len(x.Parts))
changed := false
- for i, p := range x.parts {
+ for i, p := range x.Parts {
parts[i] = rewrite(ctx, p, fn)
changed = changed || parts[i] != p
}
if !changed {
return x
}
- return &interpolation{x.baseValue, x.k, parts}
+ return &interpolation{x.baseValue, x.K, parts}
}
func (x *list) rewrite(ctx *context, fn rewriteFunc) value {
@@ -137,33 +137,33 @@
}
func (x *sliceExpr) rewrite(ctx *context, fn rewriteFunc) value {
- v := rewrite(ctx, x.x, fn)
+ v := rewrite(ctx, x.X, fn)
var lo, hi value
- if x.lo != nil {
- lo = rewrite(ctx, x.lo, fn)
+ if x.Lo != nil {
+ lo = rewrite(ctx, x.Lo, fn)
}
- if x.hi != nil {
- hi = rewrite(ctx, x.hi, fn)
+ if x.Hi != nil {
+ hi = rewrite(ctx, x.Hi, fn)
}
- if v == x.x && lo == x.lo && hi == x.hi {
+ if v == x.X && lo == x.Lo && hi == x.Hi {
return x
}
return &sliceExpr{x.baseValue, v, lo, hi}
}
func (x *callExpr) rewrite(ctx *context, fn rewriteFunc) value {
- args := make([]value, len(x.args))
+ args := make([]value, len(x.Args))
changed := false
- for i, a := range x.args {
+ for i, a := range x.Args {
v := rewrite(ctx, a, fn)
args[i] = v
changed = changed || v != a
}
- v := rewrite(ctx, x.x, fn)
- if !changed && v == x.x {
+ v := rewrite(ctx, x.Fun, fn)
+ if !changed && v == x.Fun {
return x
}
- return &callExpr{baseValue: x.baseValue, x: v, args: args}
+ return &callExpr{baseValue: x.baseValue, Fun: v, Args: args}
}
func (x *lambdaExpr) rewrite(ctx *context, fn rewriteFunc) value {
@@ -182,26 +182,26 @@
}
func (x *unaryExpr) rewrite(ctx *context, fn rewriteFunc) value {
- v := rewrite(ctx, x.x, fn)
- if v == x.x {
+ v := rewrite(ctx, x.X, fn)
+ if v == x.X {
return x
}
- return &unaryExpr{x.baseValue, x.op, v}
+ return &unaryExpr{x.baseValue, x.Op, v}
}
func (x *binaryExpr) rewrite(ctx *context, fn rewriteFunc) value {
- left := rewrite(ctx, x.left, fn)
- right := rewrite(ctx, x.right, fn)
- if left == x.left && right == x.right {
+ left := rewrite(ctx, x.X, fn)
+ right := rewrite(ctx, x.Y, fn)
+ if left == x.X && right == x.Y {
return x
}
- return updateBin(ctx, &binaryExpr{x.baseValue, x.op, left, right})
+ return updateBin(ctx, &binaryExpr{x.baseValue, x.Op, left, right})
}
func (x *unification) rewrite(ctx *context, fn rewriteFunc) value {
- values := make([]evaluated, len(x.values))
+ values := make([]evaluated, len(x.Values))
changed := false
- for i, v := range x.values {
+ for i, v := range x.Values {
values[i] = rewrite(ctx, v, fn).(evaluated)
changed = changed || v != values[i]
}
@@ -212,17 +212,17 @@
}
func (x *disjunction) rewrite(ctx *context, fn rewriteFunc) value {
- values := make([]dValue, len(x.values))
+ values := make([]dValue, len(x.Values))
changed := false
- for i, d := range x.values {
- v := rewrite(ctx, d.val, fn)
- values[i] = dValue{v, d.marked}
- changed = changed || v != d.val
+ for i, d := range x.Values {
+ v := rewrite(ctx, d.Val, fn)
+ values[i] = dValue{v, d.Default}
+ changed = changed || v != d.Val
}
if !changed {
return x
}
- return &disjunction{x.baseValue, values, x.errors, x.hasDefaults}
+ return &disjunction{x.baseValue, values, x.errors, x.HasDefaults}
}
func (x *listComprehension) rewrite(ctx *context, fn rewriteFunc) value {
@@ -259,18 +259,18 @@
}
func (x *guard) rewrite(ctx *context, fn rewriteFunc) value {
- condition := rewrite(ctx, x.condition, fn)
- value := rewrite(ctx, x.value, fn).(yielder)
- if condition == x.condition && value == x.value {
+ condition := rewrite(ctx, x.Condition, fn)
+ value := rewrite(ctx, x.Dst, fn).(yielder)
+ if condition == x.Condition && value == x.Dst {
return x
}
return &guard{x.baseValue, condition, value}
}
func (x *feed) rewrite(ctx *context, fn rewriteFunc) value {
- source := rewrite(ctx, x.source, fn)
+ source := rewrite(ctx, x.Src, fn)
lambda := rewrite(ctx, x.fn, fn).(*lambdaExpr)
- if source == x.source && lambda == x.fn {
+ if source == x.Src && lambda == x.fn {
return x
}
return &feed{x.baseValue, source, lambda}
diff --git a/cue/strip.go b/cue/strip.go
index 76c3ca6..c45bb0d 100644
--- a/cue/strip.go
+++ b/cue/strip.go
@@ -108,10 +108,10 @@
return obj
}
-func (x *mergedValues) kind() kind {
- k := x.values[0].kind()
+func (x *mergedValues) Kind() kind {
+ k := x.values[0].Kind()
for _, v := range x.values {
- k = unifyType(k, v.kind())
+ k = unifyType(k, v.Kind())
}
return k
}
diff --git a/cue/subsume.go b/cue/subsume.go
index e1e58d9..5d41200 100644
--- a/cue/subsume.go
+++ b/cue/subsume.go
@@ -121,8 +121,8 @@
gt = v
lt = w
}
- a := gt.kind()
- b := lt.kind()
+ a := gt.Kind()
+ b := lt.Kind()
switch {
case b == bottomKind:
return true
@@ -138,7 +138,7 @@
switch lt := lt.(type) {
case *unification:
if _, ok := gt.(*unification); !ok {
- for _, x := range lt.values {
+ for _, x := range lt.Values {
if s.subsumes(gt, x) {
return true
}
@@ -148,8 +148,8 @@
case *disjunction:
if _, ok := gt.(*disjunction); !ok {
- for _, x := range lt.values {
- if !s.subsumes(gt, x.val) {
+ for _, x := range lt.Values {
+ if !s.subsumes(gt, x.Val) {
return false
}
}
@@ -268,7 +268,7 @@
func (x *bottom) subsumesImpl(s *subsumer, v value) bool {
// never called.
- return v.kind() == bottomKind
+ return v.Kind() == bottomKind
}
func (x *basicType) subsumesImpl(s *subsumer, v value) bool {
@@ -280,14 +280,14 @@
if isBottom(v) {
return true
}
- kx := x.value.kind()
+ kx := x.Expr.Kind()
if !kx.isDone() || !kx.isGround() {
return false
}
switch y := v.(type) {
case *bound:
- if ky := y.value.kind(); ky.isDone() && ky.isGround() {
+ if ky := y.Expr.Kind(); ky.isDone() && ky.isGround() {
if (kx&ky)&^kx != 0 {
return false
}
@@ -303,29 +303,29 @@
//
// false if types or op direction doesn't match
- xv := x.value.(evaluated)
- yv := y.value.(evaluated)
- switch x.op {
+ xv := x.Expr.(evaluated)
+ yv := y.Expr.(evaluated)
+ switch x.Op {
case opGtr:
- if y.op == opGeq {
+ if y.Op == opGeq {
return test(ctx, x, opLss, xv, yv)
}
fallthrough
case opGeq:
- if y.op == opGtr || y.op == opGeq {
+ if y.Op == opGtr || y.Op == opGeq {
return test(ctx, x, opLeq, xv, yv)
}
case opLss:
- if y.op == opLeq {
+ if y.Op == opLeq {
return test(ctx, x, opGtr, xv, yv)
}
fallthrough
case opLeq:
- if y.op == opLss || y.op == opLeq {
+ if y.Op == opLss || y.Op == opLeq {
return test(ctx, x, opGeq, xv, yv)
}
case opNeq:
- switch y.op {
+ switch y.Op {
case opNeq:
return test(ctx, x, opEql, xv, yv)
case opGeq:
@@ -340,7 +340,7 @@
case opMat, opNMat:
// these are just approximations
- if y.op == x.op {
+ if y.Op == x.Op {
return test(ctx, x, opEql, xv, yv)
}
@@ -353,7 +353,7 @@
return false
case *numLit, *stringLit, *durationLit, *boolLit:
- return test(ctx, x, x.op, y.(evaluated), x.value.(evaluated))
+ return test(ctx, x, x.Op, y.(evaluated), x.Expr.(evaluated))
}
return false
}
@@ -363,20 +363,20 @@
}
func (x *boolLit) subsumesImpl(s *subsumer, v value) bool {
- return x.b == v.(*boolLit).b
+ return x.B == v.(*boolLit).B
}
func (x *stringLit) subsumesImpl(s *subsumer, v value) bool {
- return x.str == v.(*stringLit).str
+ return x.Str == v.(*stringLit).Str
}
func (x *bytesLit) subsumesImpl(s *subsumer, v value) bool {
- return bytes.Equal(x.b, v.(*bytesLit).b)
+ return bytes.Equal(x.B, v.(*bytesLit).B)
}
func (x *numLit) subsumesImpl(s *subsumer, v value) bool {
b := v.(*numLit)
- return x.v.Cmp(&b.v) == 0
+ return x.X.Cmp(&b.X) == 0
}
func (x *durationLit) subsumesImpl(s *subsumer, v value) bool {
@@ -441,8 +441,8 @@
// not the case, subsumes will return a false negative, which is
// allowed.
outer:
- for _, vx := range x.values {
- for _, vy := range y.values {
+ for _, vx := range x.Values {
+ for _, vy := range y.Values {
if s.subsumes(vx, vy) {
continue outer
}
@@ -453,7 +453,7 @@
return true
}
subsumed := true
- for _, vx := range x.values {
+ for _, vx := range x.Values {
subsumed = subsumed && s.subsumes(vx, v)
}
return subsumed
@@ -471,10 +471,10 @@
if d, ok := v.(*disjunction); ok {
// at least one value in x should subsume each value in d.
outer:
- for _, vd := range d.values {
+ for _, vd := range d.Values {
// v is subsumed if any value in x subsumes v.
- for _, vx := range x.values {
- if (vx.marked || !vd.marked) && s.subsumes(vx.val, vd.val) {
+ for _, vx := range x.Values {
+ if (vx.Default || !vd.Default) && s.subsumes(vx.Val, vd.Val) {
continue outer
}
}
@@ -483,8 +483,8 @@
return true
}
// v is subsumed if any value in x subsumes v.
- for _, vx := range x.values {
- if s.subsumes(vx.val, v) {
+ for _, vx := range x.Values {
+ if s.subsumes(vx.Val, v) {
return true
}
}
@@ -506,7 +506,7 @@
// structural equivalence
func (x *selectorExpr) subsumesImpl(s *subsumer, v value) bool {
if r, ok := v.(*selectorExpr); ok {
- return x.feature == r.feature && s.subsumes(x.x, r.x) // subChoose
+ return x.Sel == r.Sel && s.subsumes(x.X, r.X) // subChoose
}
return isBottom(v)
}
@@ -520,11 +520,11 @@
case *interpolation:
// structural equivalence
- if len(x.parts) != len(v.parts) {
+ if len(x.Parts) != len(v.Parts) {
return false
}
- for i, p := range x.parts {
- if !s.subsumes(p, v.parts[i]) {
+ for i, p := range x.Parts {
+ if !s.subsumes(p, v.Parts[i]) {
return false
}
}
@@ -539,7 +539,7 @@
if r, ok := v.(*indexExpr); ok {
// TODO: could be narrowed down if we know the exact value of the index
// and referenced value.
- return s.subsumes(x.x, r.x) && s.subsumes(x.index, r.index)
+ return s.subsumes(x.X, r.X) && s.subsumes(x.Index, r.Index)
}
return isBottom(v)
}
@@ -550,9 +550,9 @@
if r, ok := v.(*sliceExpr); ok {
// TODO: could be narrowed down if we know the exact value of the index
// and referenced value.
- return s.subsumes(x.x, r.x) &&
- s.subsumes(x.lo, r.lo) &&
- s.subsumes(x.hi, r.hi)
+ return s.subsumes(x.X, r.X) &&
+ s.subsumes(x.Lo, r.Lo) &&
+ s.subsumes(x.Hi, r.Hi)
}
return isBottom(v)
}
@@ -563,11 +563,11 @@
if !ok {
return isBottom(v)
}
- if x.call != y.call {
+ if x.Builtin != y.Builtin {
return false
}
- for i, v := range x.args {
- if !s.subsumes(v, y.args[i]) {
+ for i, v := range x.Args {
+ if !s.subsumes(v, y.Args[i]) {
return false
}
}
@@ -577,15 +577,15 @@
// structural equivalence
func (x *callExpr) subsumesImpl(s *subsumer, v value) bool {
if c, ok := v.(*callExpr); ok {
- if len(x.args) != len(c.args) {
+ if len(x.Args) != len(c.Args) {
return false
}
- for i, a := range x.args {
- if !s.subsumes(a, c.args[i]) {
+ for i, a := range x.Args {
+ if !s.subsumes(a, c.Args[i]) {
return false
}
}
- return s.subsumes(x.x, c.x)
+ return s.subsumes(x.Fun, c.Fun)
}
return isBottom(v)
}
@@ -593,7 +593,7 @@
// structural equivalence
func (x *unaryExpr) subsumesImpl(s *subsumer, v value) bool {
if b, ok := v.(*unaryExpr); ok {
- return x.op == b.op && s.subsumes(x.x, b.x)
+ return x.Op == b.Op && s.subsumes(x.X, b.X)
}
return isBottom(v)
}
@@ -601,9 +601,9 @@
// structural equivalence
func (x *binaryExpr) subsumesImpl(s *subsumer, v value) bool {
if b, ok := v.(*binaryExpr); ok {
- return x.op == b.op &&
- s.subsumes(x.left, b.left) &&
- s.subsumes(x.right, b.right)
+ return x.Op == b.Op &&
+ s.subsumes(x.X, b.X) &&
+ s.subsumes(x.Y, b.Y)
}
return isBottom(v)
}
@@ -646,7 +646,7 @@
// structural equivalence
func (x *feed) subsumesImpl(s *subsumer, v value) bool {
if b, ok := v.(*feed); ok {
- return s.subsumes(x.source, b.source) &&
+ return s.subsumes(x.Src, b.Src) &&
s.subsumes(x.fn, b.fn)
}
return isBottom(v)
@@ -655,8 +655,8 @@
// structural equivalence
func (x *guard) subsumesImpl(s *subsumer, v value) bool {
if b, ok := v.(*guard); ok {
- return s.subsumes(x.condition, b.condition) &&
- s.subsumes(x.value, b.value)
+ return s.subsumes(x.Condition, b.Condition) &&
+ s.subsumes(x.Dst, b.Dst)
}
return isBottom(v)
}
diff --git a/cue/subsume_test.go b/cue/subsume_test.go
index d41ada7..38276b8 100644
--- a/cue/subsume_test.go
+++ b/cue/subsume_test.go
@@ -463,7 +463,7 @@
s := subsumer{ctx: ctx, mode: tc.mode}
got := s.subsumes(a, b)
if got != tc.subsumes {
- t.Errorf("got %v; want %v (%v vs %v)", got, tc.subsumes, a.kind(), b.kind())
+ t.Errorf("got %v; want %v (%v vs %v)", got, tc.subsumes, a.Kind(), b.Kind())
}
})
}
diff --git a/cue/types.go b/cue/types.go
index bdbcbe0..3def979 100644
--- a/cue/types.go
+++ b/cue/types.go
@@ -342,16 +342,16 @@
if err != nil {
return 0, err
}
- if n.v.Form != 0 {
+ if n.X.Form != 0 {
return 0, ErrInfinite
}
if mant != nil {
- mant.Set(&n.v.Coeff)
- if n.v.Negative {
+ mant.Set(&n.X.Coeff)
+ if n.X.Negative {
mant.Neg(mant)
}
}
- return int(n.v.Exponent), nil
+ return int(n.X.Exponent), nil
}
// AppendInt appends the string representation of x in the given base to buf and
@@ -373,9 +373,9 @@
return nil, err
}
ctx := apd.BaseContext
- nd := int(apd.NumDigits(&n.v.Coeff)) + int(n.v.Exponent)
- if n.v.Form == apd.Infinite {
- if n.v.Negative {
+ nd := int(apd.NumDigits(&n.X.Coeff)) + int(n.X.Exponent)
+ if n.X.Form == apd.Infinite {
+ if n.X.Negative {
buf = append(buf, '-')
}
return append(buf, string('∞')...), nil
@@ -386,7 +386,7 @@
ctx.Precision = uint32(prec)
}
var d apd.Decimal
- ctx.Round(&d, &n.v)
+ ctx.Round(&d, &n.X)
return d.Append(buf, fmt), nil
}
@@ -413,11 +413,11 @@
if z == nil {
z = &big.Int{}
}
- if n.v.Exponent != 0 {
+ if n.X.Exponent != 0 {
panic("cue: exponent should always be nil for integer types")
}
- z.Set(&n.v.Coeff)
- if n.v.Negative {
+ z.Set(&n.X.Coeff)
+ if n.X.Negative {
z.Neg(z)
}
return z, nil
@@ -432,14 +432,14 @@
if err != nil {
return 0, err
}
- if !n.v.Coeff.IsInt64() {
- if n.v.Negative {
+ if !n.X.Coeff.IsInt64() {
+ if n.X.Negative {
return math.MinInt64, ErrAbove
}
return math.MaxInt64, ErrBelow
}
- i := n.v.Coeff.Int64()
- if n.v.Negative {
+ i := n.X.Coeff.Int64()
+ if n.X.Negative {
i = -i
}
return i, nil
@@ -454,13 +454,13 @@
if err != nil {
return 0, err
}
- if n.v.Negative {
+ if n.X.Negative {
return 0, ErrAbove
}
- if !n.v.Coeff.IsUint64() {
+ if !n.X.Coeff.IsUint64() {
return math.MaxUint64, ErrBelow
}
- i := n.v.Coeff.Uint64()
+ i := n.X.Coeff.Uint64()
return i, nil
}
@@ -528,22 +528,22 @@
if err != nil {
return 0, err
}
- if n.v.Negative {
- if n.v.Cmp(smallestNegFloat64) == 1 {
+ if n.X.Negative {
+ if n.X.Cmp(smallestNegFloat64) == 1 {
return -0, ErrAbove
}
- if n.v.Cmp(maxNegFloat64) == -1 {
+ if n.X.Cmp(maxNegFloat64) == -1 {
return math.Inf(-1), ErrBelow
}
} else {
- if n.v.Cmp(smallestPosFloat64) == -1 {
+ if n.X.Cmp(smallestPosFloat64) == -1 {
return 0, ErrBelow
}
- if n.v.Cmp(maxPosFloat64) == 1 {
+ if n.X.Cmp(maxPosFloat64) == 1 {
return math.Inf(1), ErrAbove
}
}
- f, _ := n.v.Float64()
+ f, _ := n.X.Float64()
return f, nil
}
@@ -571,7 +571,7 @@
}
a = append(a, f)
}
- return a, v.arc.cache.kind()
+ return a, v.arc.cache.Kind()
}
var validIdent = []*unicode.RangeTable{unicode.L, unicode.N}
@@ -701,26 +701,26 @@
func appendPath(ctx *context, a []label, v value) (path []label, n *nodeRef) {
switch x := v.(type) {
case *selectorExpr:
- a, n = appendPath(ctx, a, x.x)
+ a, n = appendPath(ctx, a, x.X)
if n == nil {
return nil, nil
}
- a = append(a, x.feature)
+ a = append(a, x.Sel)
case *indexExpr:
- e := x.index.evalPartial(ctx)
+ e := x.Index.evalPartial(ctx)
s, ok := e.(*stringLit)
if !ok {
return nil, nil
}
- a, n = appendPath(ctx, a, x.x)
+ a, n = appendPath(ctx, a, x.X)
if n == nil {
return nil, nil
}
- a = append(a, ctx.Label(s.str, false))
+ a = append(a, ctx.Label(s.Str, false))
case *nodeRef:
n = x
@@ -835,7 +835,7 @@
if c == nil {
c = v.path.v.evalPartial(v.ctx())
}
- k := c.kind()
+ k := c.Kind()
if k.isGround() {
switch {
case k.isAnyOf(nullKind):
@@ -872,9 +872,9 @@
case *builtin:
k = x.representedKind()
case *customValidator:
- k = x.call.Params[0]
+ k = x.Builtin.Params[0]
default:
- k = x.kind()
+ k = x.Kind()
}
vk := BottomKind // Everything is a bottom kind.
for i := kind(1); i < nonGround; i <<= 1 {
@@ -919,17 +919,17 @@
ctx := v.idx.newContext()
x := v.eval(ctx)
// TODO: implement marshalles in value.
- switch k := x.kind(); k {
+ switch k := x.Kind(); k {
case nullKind:
return json.Marshal(nil)
case boolKind:
- return json.Marshal(x.(*boolLit).b)
+ return json.Marshal(x.(*boolLit).B)
case intKind, floatKind, numKind:
- return x.(*numLit).v.MarshalText()
+ return x.(*numLit).X.MarshalText()
case stringKind:
- return json.Marshal(x.(*stringLit).str)
+ return json.Marshal(x.(*stringLit).Str)
case bytesKind:
- return json.Marshal(x.(*bytesLit).b)
+ return json.Marshal(x.(*bytesLit).B)
case listKind:
l := x.(*list)
i := Iterator{ctx: ctx, val: v, iter: l, len: len(l.elem.arcs)}
@@ -1054,7 +1054,7 @@
if v.path == nil {
return nil
}
- return v.path.v.syntax()
+ return v.path.v.Source()
}
// Err returns the error represented by v or nil v is not an error.
@@ -1109,7 +1109,7 @@
return false
}
// Other errors are considered ground.
- return x.kind().isConcrete()
+ return x.Kind().isConcrete()
}
// Deprecated: IsIncomplete
@@ -1119,7 +1119,7 @@
func (v Value) IsIncomplete() bool {
// TODO: remove
x := v.eval(v.ctx())
- if !x.kind().isConcrete() {
+ if !x.Kind().isConcrete() {
return true
}
return isIncomplete(x)
@@ -1142,7 +1142,7 @@
if b, ok := x.(*bottom); ok {
return b
}
- got := x.kind()
+ got := x.Kind()
if want != bottomKind {
if got&want&concreteKind == bottomKind {
return ctx.mkErr(x, "cannot use value %v (type %s) as %s",
@@ -1218,7 +1218,7 @@
// create error
continue
}
- x := fn.call(ctx, set.value, &basicType{k: stringKind})
+ x := fn.call(ctx, set.value, &basicType{K: stringKind})
a = append(a, [2]Value{v.makeElem(set.key), v.makeElem(x)})
}
@@ -1259,7 +1259,7 @@
if err := v.checkKind(ctx, boolKind); err != nil {
return false, v.toErr(err)
}
- return v.eval(ctx).(*boolLit).b, nil
+ return v.eval(ctx).(*boolLit).B, nil
}
// String returns the string value if v is a string or an error otherwise.
@@ -1269,7 +1269,7 @@
if err := v.checkKind(ctx, stringKind); err != nil {
return "", v.toErr(err)
}
- return v.eval(ctx).(*stringLit).str, nil
+ return v.eval(ctx).(*stringLit).Str, nil
}
// Bytes returns a byte slice if v represents a list of bytes or an error
@@ -1279,9 +1279,9 @@
ctx := v.ctx()
switch x := v.eval(ctx).(type) {
case *bytesLit:
- return append([]byte(nil), x.b...), nil
+ return append([]byte(nil), x.B...), nil
case *stringLit:
- return []byte(x.str), nil
+ return []byte(x.Str), nil
}
return nil, v.toErr(v.checkKind(ctx, bytesKind|stringKind))
}
@@ -1293,9 +1293,9 @@
ctx := v.ctx()
switch x := v.eval(ctx).(type) {
case *bytesLit:
- return bytes.NewReader(x.b), nil
+ return bytes.NewReader(x.B), nil
case *stringLit:
- return strings.NewReader(x.str), nil
+ return strings.NewReader(x.Str), nil
}
return nil, v.toErr(v.checkKind(ctx, stringKind|bytesKind))
}
@@ -1750,17 +1750,17 @@
var feature string
switch sel := v.path.v.(type) {
case *selectorExpr:
- x = sel.x
- feature = ctx.LabelStr(sel.feature)
+ x = sel.X
+ feature = ctx.LabelStr(sel.Sel)
case *indexExpr:
- e := sel.index.evalPartial(ctx)
+ e := sel.Index.evalPartial(ctx)
s, ok := e.(*stringLit)
if !ok {
return nil, nil
}
- x = sel.x
- feature = s.str
+ x = sel.X
+ feature = s.Str
default:
return nil, nil
@@ -1772,18 +1772,18 @@
func mkPath(c *context, up *valueData, x value, feature string, d int) (imp *Instance, a []string) {
switch x := x.(type) {
case *selectorExpr:
- imp, a = mkPath(c, up, x.x, c.LabelStr(x.feature), d+1)
+ imp, a = mkPath(c, up, x.X, c.LabelStr(x.Sel), d+1)
if imp == nil {
return nil, nil
}
case *indexExpr:
- e := x.index.evalPartial(c)
+ e := x.Index.evalPartial(c)
s, ok := e.(*stringLit)
if !ok {
return nil, nil
}
- imp, a = mkPath(c, up, x.x, s.str, d+1)
+ imp, a = mkPath(c, up, x.X, s.Str, d+1)
if imp == nil {
return nil, nil
}
@@ -1852,8 +1852,8 @@
switch x := v.(type) {
case *selectorExpr:
i := len(p.stack)
- p.stack = append(p.stack, x.feature)
- rewrite(ctx, x.x, p.find)
+ p.stack = append(p.stack, x.Sel)
+ rewrite(ctx, x.X, p.find)
p.stack = p.stack[:i]
return v, false
@@ -2046,7 +2046,7 @@
func (x *validator) before(v Value, o options) bool {
if err := v.checkKind(v.ctx(), bottomKind); err != nil {
if !o.concrete && isIncomplete(err) {
- if o.disallowCycles && err.code == codeCycle {
+ if o.disallowCycles && err.Code == codeCycle {
x.errs = errors.Append(x.errs, v.toErr(err))
}
return false
@@ -2125,7 +2125,7 @@
}
}
default:
- if !x.kind().isGround() {
+ if !x.Kind().isGround() {
return ctx.mkErr(v, "incomplete value (%v)", ctx.str(v))
}
}
@@ -2248,18 +2248,18 @@
op := NoOp
switch x := v.path.v.(type) {
case *binaryExpr:
- a = append(a, remakeValue(v, x.left))
- a = append(a, remakeValue(v, x.right))
- op = opToOp[x.op]
+ a = append(a, remakeValue(v, x.X))
+ a = append(a, remakeValue(v, x.Y))
+ op = opToOp[x.Op]
case *unaryExpr:
- a = append(a, remakeValue(v, x.x))
- op = opToOp[x.op]
+ a = append(a, remakeValue(v, x.X))
+ op = opToOp[x.Op]
case *bound:
- a = append(a, remakeValue(v, x.value))
- op = opToOp[x.op]
+ a = append(a, remakeValue(v, x.Expr))
+ op = opToOp[x.Op]
case *unification:
// pre-expanded unification
- for _, conjunct := range x.values {
+ for _, conjunct := range x.Values {
a = append(a, remakeValue(v, conjunct))
}
op = AndOp
@@ -2267,52 +2267,52 @@
// Filter defaults that are subsumed by another value.
count := 0
outer:
- for _, disjunct := range x.values {
- if disjunct.marked {
- for _, n := range x.values {
+ for _, disjunct := range x.Values {
+ if disjunct.Default {
+ for _, n := range x.Values {
s := subsumer{ctx: v.ctx()}
- if !n.marked && s.subsumes(n.val, disjunct.val) {
+ if !n.Default && s.subsumes(n.Val, disjunct.Val) {
continue outer
}
}
}
count++
- a = append(a, remakeValue(v, disjunct.val))
+ a = append(a, remakeValue(v, disjunct.Val))
}
if count > 1 {
op = OrOp
}
case *interpolation:
- for _, p := range x.parts {
+ for _, p := range x.Parts {
a = append(a, remakeValue(v, p))
}
op = InterpolationOp
case *selectorExpr:
- a = append(a, remakeValue(v, x.x))
+ a = append(a, remakeValue(v, x.X))
a = append(a, remakeValue(v, &stringLit{
x.baseValue,
- v.ctx().LabelStr(x.feature),
+ v.ctx().LabelStr(x.Sel),
nil,
}))
op = SelectorOp
case *indexExpr:
- a = append(a, remakeValue(v, x.x))
- a = append(a, remakeValue(v, x.index))
+ a = append(a, remakeValue(v, x.X))
+ a = append(a, remakeValue(v, x.Index))
op = IndexOp
case *sliceExpr:
- a = append(a, remakeValue(v, x.x))
- a = append(a, remakeValue(v, x.lo))
- a = append(a, remakeValue(v, x.hi))
+ a = append(a, remakeValue(v, x.X))
+ a = append(a, remakeValue(v, x.Lo))
+ a = append(a, remakeValue(v, x.Hi))
op = SliceOp
case *callExpr:
- a = append(a, remakeValue(v, x.x))
- for _, arg := range x.args {
+ a = append(a, remakeValue(v, x.Fun))
+ for _, arg := range x.Args {
a = append(a, remakeValue(v, arg))
}
op = CallOp
case *customValidator:
- a = append(a, remakeValue(v, x.call))
- for _, arg := range x.args {
+ a = append(a, remakeValue(v, x.Builtin))
+ for _, arg := range x.Args {
a = append(a, remakeValue(v, arg))
}
op = CallOp
diff --git a/cue/validate.go b/cue/validate.go
index 08d17f0..b0b949f 100644
--- a/cue/validate.go
+++ b/cue/validate.go
@@ -19,7 +19,7 @@
// validate returns whether there is any error, recursively.
func validate(ctx *context, v value) (err *bottom) {
eval := v.evalPartial(ctx)
- if err, ok := eval.(*bottom); ok && err.code != codeIncomplete && err.code != codeCycle {
+ if err, ok := eval.(*bottom); ok && err.Code != codeIncomplete && err.Code != codeCycle {
return eval.(*bottom)
}
switch x := eval.(type) {
diff --git a/cue/value.go b/cue/value.go
index 14ebb70..67c83ad 100644
--- a/cue/value.go
+++ b/cue/value.go
@@ -37,7 +37,7 @@
// evalPartial evaluates a value without choosing default values.
evalPartial(*context) evaluated
- kind() kind
+ Kind() kind
// subsumesImpl is only defined for non-reference types.
// It should only be called by the subsumes function.
@@ -77,7 +77,7 @@
if b, ok := x.(*bottom); ok {
return b
}
- got := x.kind()
+ got := x.Kind()
if got&want&concreteKind == bottomKind && want != bottomKind {
return ctx.mkErr(x, "cannot use value %v (type %s) as %s", ctx.str(x), got, want)
}
@@ -112,7 +112,7 @@
type source interface {
// syntax returns the parsed file of the underlying node or a computed
// node indicating that it is a computed binary expression.
- syntax() ast.Node
+ Source() ast.Node
computed() *computedSource
Pos() token.Pos
base() baseValue
@@ -152,7 +152,7 @@
return nil
}
-func (b baseValue) syntax() ast.Node {
+func (b baseValue) Source() ast.Node {
switch x := b.pos.(type) {
case ast.Node:
return x
@@ -170,28 +170,28 @@
// top is the top of the value lattice. It subsumes all possible values.
type top struct{ baseValue }
-func (x *top) kind() kind { return topKind }
+func (x *top) Kind() kind { return topKind }
// basicType represents the root class of any specific type.
type basicType struct {
baseValue
- k kind
+ K kind
}
-func (x *basicType) kind() kind { return x.k | nonGround }
+func (x *basicType) Kind() kind { return x.K | nonGround }
// Literals
type nullLit struct{ baseValue }
-func (x *nullLit) kind() kind { return nullKind }
+func (x *nullLit) Kind() kind { return nullKind }
type boolLit struct {
baseValue
- b bool
+ B bool
}
-func (x *boolLit) kind() kind { return boolKind }
+func (x *boolLit) Kind() kind { return boolKind }
func boolTonode(src source, b bool) evaluated {
return &boolLit{src.base(), b}
@@ -199,17 +199,17 @@
type bytesLit struct {
baseValue
- b []byte
+ B []byte
// Also support https://github.com/dlclark/regexp2 to
// accommodate JSON Schema?
- re *regexp.Regexp // only set if needed
+ RE *regexp.Regexp // only set if needed
}
-func (x *bytesLit) kind() kind { return bytesKind }
-func (x *bytesLit) strValue() string { return string(x.b) }
+func (x *bytesLit) Kind() kind { return bytesKind }
+func (x *bytesLit) strValue() string { return string(x.B) }
func (x *bytesLit) iterAt(ctx *context, i int) arc {
- if i >= len(x.b) {
+ if i >= len(x.B) {
return arc{}
}
v := x.at(ctx, i)
@@ -217,18 +217,18 @@
}
func (x *bytesLit) at(ctx *context, i int) evaluated {
- if i < 0 || i >= len(x.b) {
+ if i < 0 || i >= len(x.B) {
return ctx.mkErr(x, "index %d out of bounds", i)
}
// TODO: this is incorrect.
- return newInt(x, 0).setUInt64(uint64(x.b[i]))
+ return newInt(x, 0).setUInt64(uint64(x.B[i]))
}
-func (x *bytesLit) len() int { return len(x.b) }
+func (x *bytesLit) len() int { return len(x.B) }
func (x *bytesLit) slice(ctx *context, lo, hi *numLit) evaluated {
lox := 0
- hix := len(x.b)
+ hix := len(x.B)
if lo != nil {
lox = lo.intValue(ctx)
}
@@ -244,25 +244,25 @@
if hix < lox {
return ctx.mkErr(x, "invalid slice index: %d > %d", lox, hix)
}
- if len(x.b) < hix {
+ if len(x.B) < hix {
return ctx.mkErr(hi, "slice bounds out of range")
}
- return &bytesLit{x.baseValue, x.b[lox:hix], nil}
+ return &bytesLit{x.baseValue, x.B[lox:hix], nil}
}
type stringLit struct {
baseValue
- str string
- re *regexp.Regexp // only set if needed
+ Str string
+ RE *regexp.Regexp // only set if needed
// TODO: maintain extended grapheme index cache.
}
-func (x *stringLit) kind() kind { return stringKind }
-func (x *stringLit) strValue() string { return x.str }
+func (x *stringLit) Kind() kind { return stringKind }
+func (x *stringLit) strValue() string { return x.Str }
func (x *stringLit) iterAt(ctx *context, i int) arc {
- runes := []rune(x.str)
+ runes := []rune(x.Str)
if i >= len(runes) {
return arc{}
}
@@ -271,17 +271,17 @@
}
func (x *stringLit) at(ctx *context, i int) evaluated {
- runes := []rune(x.str)
+ runes := []rune(x.Str)
if i < 0 || i >= len(runes) {
return ctx.mkErr(x, "index %d out of bounds", i)
}
// TODO: this is incorrect.
return &stringLit{x.baseValue, string(runes[i : i+1]), nil}
}
-func (x *stringLit) len() int { return len([]rune(x.str)) }
+func (x *stringLit) len() int { return len([]rune(x.Str)) }
func (x *stringLit) slice(ctx *context, lo, hi *numLit) evaluated {
- runes := []rune(x.str)
+ runes := []rune(x.Str)
lox := 0
hix := len(runes)
if lo != nil {
@@ -308,15 +308,15 @@
type numLit struct {
baseValue
rep literal.Multiplier
- k kind
- v apd.Decimal
+ K kind
+ X apd.Decimal
}
func newNum(src source, k kind, rep literal.Multiplier) *numLit {
if k&numKind == 0 {
panic("not a number")
}
- return &numLit{baseValue: src.base(), rep: rep, k: k}
+ return &numLit{baseValue: src.base(), rep: rep, K: k}
}
func newInt(src source, rep literal.Multiplier) *numLit {
@@ -328,40 +328,40 @@
}
func (n numLit) specialize(k kind) *numLit {
- n.k = k
+ n.K = k
return &n
}
func (n *numLit) set(d *apd.Decimal) *numLit {
- n.v.Set(d)
+ n.X.Set(d)
return n
}
func (n *numLit) setInt(x int) *numLit {
- n.v.SetInt64(int64(x))
+ n.X.SetInt64(int64(x))
return n
}
func (n *numLit) setInt64(x int64) *numLit {
- n.v.SetInt64(x)
+ n.X.SetInt64(x)
return n
}
func (n *numLit) setUInt64(x uint64) *numLit {
- n.v.Coeff.SetUint64(x)
+ n.X.Coeff.SetUint64(x)
return n
}
func (n *numLit) setString(s string) *numLit {
- _, _, _ = n.v.SetString(s)
+ _, _, _ = n.X.SetString(s)
return n
}
func (n *numLit) String() string {
- if n.k&intKind != 0 {
- return n.v.Text('f') // also render info
+ if n.K&intKind != 0 {
+ return n.X.Text('f') // also render info
}
- s := n.v.Text('g')
+ s := n.X.Text('g')
if len(s) == 1 {
s += "."
}
@@ -370,7 +370,7 @@
func parseInt(k kind, s string) *numLit {
num := newInt(newExpr(ast.NewLit(token.INT, s)), 0)
- _, _, err := num.v.SetString(s)
+ _, _, err := num.X.SetString(s)
if err != nil {
panic(err)
}
@@ -379,7 +379,7 @@
func parseFloat(s string) *numLit {
num := newFloat(newExpr(ast.NewLit(token.FLOAT, s)), 0)
- _, _, err := num.v.SetString(s)
+ _, _, err := num.X.SetString(s)
if err != nil {
panic(err)
}
@@ -390,15 +390,15 @@
var one = parseInt(intKind, "1")
-func (x *numLit) kind() kind { return x.k }
-func (x *numLit) strValue() string { return x.v.String() }
+func (x *numLit) Kind() kind { return x.K }
+func (x *numLit) strValue() string { return x.X.String() }
func (x *numLit) isInt(ctx *context) bool {
- return x.kind()&intKind != 0
+ return x.Kind()&intKind != 0
}
func (x *numLit) intValue(ctx *context) int {
- v, err := x.v.Int64()
+ v, err := x.X.Int64()
if err != nil {
return 0
}
@@ -410,18 +410,18 @@
d time.Duration
}
-func (x *durationLit) kind() kind { return durationKind }
+func (x *durationLit) Kind() kind { return durationKind }
func (x *durationLit) strValue() string { return x.d.String() }
type bound struct {
baseValue
- op op // opNeq, opLss, opLeq, opGeq, or opGtr
- k kind // mostly used for number kind
- value value
+ Op op // opNeq, opLss, opLeq, opGeq, or opGtr
+ k kind // mostly used for number kind
+ Expr value
}
func newBound(ctx *context, base baseValue, op op, k kind, v value) evaluated {
- kv := v.kind()
+ kv := v.Kind()
if kv.isAnyOf(numKind) {
kv |= numKind
} else if op == opNeq && kv&atomKind == nullKind {
@@ -436,7 +436,7 @@
return &bound{base, op, unifyType(k&topKind, kv) | nonGround, v}
}
-func (x *bound) kind() kind {
+func (x *bound) Kind() kind {
return x.k
}
@@ -505,11 +505,11 @@
type interpolation struct {
baseValue
- k kind // string or bytes
- parts []value // odd: strings, even expressions
+ K kind // string or bytes
+ Parts []value // odd: strings, even expressions
}
-func (x *interpolation) kind() kind { return x.k | nonGround }
+func (x *interpolation) Kind() kind { return x.K | nonGround }
type list struct {
baseValue
@@ -529,7 +529,7 @@
}
func (x *list) manifest(ctx *context) evaluated {
- if x.kind().isGround() {
+ if x.Kind().isGround() {
return x
}
// A list is ground if its length is ground, or if the current length
@@ -546,7 +546,7 @@
return x
}
-func (x *list) kind() kind {
+func (x *list) Kind() kind {
k := listKind
if _, ok := x.len.(*numLit); ok {
return k
@@ -579,8 +579,8 @@
return a
}
max := maxNum(x.len.(evaluated))
- if max.kind().isGround() {
- if max.kind()&intKind == bottomKind {
+ if max.Kind().isGround() {
+ if max.Kind()&intKind == bottomKind {
v := ctx.mkErr(max, "length indicator of list not of type int")
return arc{cache: v}
}
@@ -593,7 +593,7 @@
}
func (x *list) isOpen() bool {
- return !x.len.kind().isGround()
+ return !x.len.Kind().isGround()
}
// lo and hi must be nil or a ground integer.
@@ -605,7 +605,7 @@
if n < 0 {
return ctx.mkErr(x, "negative slice index")
}
- if max.kind().isGround() && !leq(ctx, hi, hi, max) {
+ if max.Kind().isGround() && !leq(ctx, hi, hi, max) {
return ctx.mkErr(hi, "slice bounds out of range")
}
max = hi
@@ -619,7 +619,7 @@
if n < 0 {
return ctx.mkErr(x, "negative slice index")
}
- if n > 0 && max.kind().isGround() {
+ if n > 0 && max.Kind().isGround() {
if !leq(ctx, lo, lo, max) {
max := max.(*numLit).intValue(ctx)
return ctx.mkErr(x, "invalid slice index: %v > %v", n, max)
@@ -806,7 +806,7 @@
}
str := ctx.LabelStr(f)
- arg := &stringLit{str: str}
+ arg := &stringLit{Str: str}
found, ok := o.match(ctx, arg)
return found && ok
@@ -879,7 +879,7 @@
arg := label
if arg == nil {
- arg = &basicType{k: stringKind}
+ arg = &basicType{K: stringKind}
}
for _, s := range o.fields {
@@ -898,7 +898,7 @@
continue
}
add(fn.call(ctx, s.value, arg))
- if f, _ := s.value.base().syntax().(*ast.Field); f != nil {
+ if f, _ := s.value.base().Source().(*ast.Field); f != nil {
doc = &docNode{n: f, left: doc}
}
}
@@ -982,7 +982,7 @@
return &structLit{baseValue: src.base()}
}
-func (x *structLit) kind() kind { return structKind }
+func (x *structLit) Kind() kind { return structKind }
type arcs []arc
@@ -1065,7 +1065,7 @@
ctx.evalStack = append(ctx.evalStack, bottom{
baseValue: x.base(),
index: ctx.index,
- code: codeCycle,
+ Code: codeCycle,
value: x.arcs[i].v,
format: "cycle detected",
})
@@ -1299,7 +1299,7 @@
}
func wrapFinalize(ctx *context, v value) value {
- if v.kind().isAnyOf(structKind | listKind) {
+ if v.Kind().isAnyOf(structKind | listKind) {
switch x := v.(type) {
case *top:
return v
@@ -1328,8 +1328,8 @@
return x
case *disjunction:
- for _, d := range x.values {
- d.val = wrapFinalize(ctx, d.val)
+ for _, d := range x.Values {
+ d.Val = wrapFinalize(ctx, d.Val)
}
case *list:
@@ -1378,57 +1378,57 @@
label label // for direct ancestor nodes
}
-func (x *nodeRef) kind() kind {
+func (x *nodeRef) Kind() kind {
// TODO(REWORK): no context available
// n := x.node.deref(nil)
n := x.node
- return n.kind() | nonGround | referenceKind
+ return n.Kind() | nonGround | referenceKind
}
type selectorExpr struct {
baseValue
- x value
- feature label
+ X value
+ Sel label
}
// TODO: could this be narrowed down?
-func (x *selectorExpr) kind() kind {
- isRef := x.x.kind() & referenceKind
+func (x *selectorExpr) Kind() kind {
+ isRef := x.X.Kind() & referenceKind
return topKind | isRef
}
type indexExpr struct {
baseValue
- x value
- index value
+ X value
+ Index value
}
// TODO: narrow this down when we have list types.
-func (x *indexExpr) kind() kind { return topKind | referenceKind }
+func (x *indexExpr) Kind() kind { return topKind | referenceKind }
type sliceExpr struct {
baseValue
- x value
- lo value
- hi value
+ X value
+ Lo value
+ Hi value
}
// TODO: narrow this down when we have list types.
-func (x *sliceExpr) kind() kind { return topKind | referenceKind }
+func (x *sliceExpr) Kind() kind { return topKind | referenceKind }
type callExpr struct {
baseValue
- x value
- args []value
+ Fun value
+ Args []value
}
-func (x *callExpr) kind() kind {
+func (x *callExpr) Kind() kind {
// TODO: could this be narrowed down?
- switch c := x.x.(type) {
+ switch c := x.Fun.(type) {
case *lambdaExpr:
return c.returnKind() | nonGround
case *builtin:
- switch len(x.args) {
+ switch len(x.Args) {
case len(c.Params):
return c.Result
case len(c.Params) - 1:
@@ -1444,15 +1444,15 @@
type customValidator struct {
baseValue
- args []evaluated // any but the first value
- call *builtin // function must return a bool
+ Args []evaluated // any but the first value
+ Builtin *builtin // function must return a bool
}
-func (x *customValidator) kind() kind {
- if len(x.call.Params) == 0 {
+func (x *customValidator) Kind() kind {
+ if len(x.Builtin.Params) == 0 {
return bottomKind
}
- return x.call.Params[0] | nonGround
+ return x.Builtin.Params[0] | nonGround
}
type params struct {
@@ -1511,8 +1511,8 @@
}
// TODO: could this be narrowed down?
-func (x *lambdaExpr) kind() kind { return lambdaKind }
-func (x *lambdaExpr) returnKind() kind { return x.value.kind() }
+func (x *lambdaExpr) Kind() kind { return lambdaKind }
+func (x *lambdaExpr) returnKind() kind { return x.value.Kind() }
// call calls and evaluates a lambda expression. It is assumed that x may be
// destroyed, either because it is copied as a result of a reference or because
@@ -1544,27 +1544,27 @@
type unaryExpr struct {
baseValue
- op op
- x value
+ Op op
+ X value
}
-func (x *unaryExpr) kind() kind { return x.x.kind() }
+func (x *unaryExpr) Kind() kind { return x.X.Kind() }
func compileRegexp(ctx *context, v value) value {
var err error
switch x := v.(type) {
case *stringLit:
- if x.re == nil {
- x.re, err = regexp.Compile(x.str)
+ if x.RE == nil {
+ x.RE, err = regexp.Compile(x.Str)
if err != nil {
- return ctx.mkErr(v, "could not compile regular expression %q: %v", x.str, err)
+ return ctx.mkErr(v, "could not compile regular expression %q: %v", x.Str, err)
}
}
case *bytesLit:
- if x.re == nil {
- x.re, err = regexp.Compile(string(x.b))
+ if x.RE == nil {
+ x.RE, err = regexp.Compile(string(x.B))
if err != nil {
- return ctx.mkErr(v, "could not compile regular expression %q: %v", x.b, err)
+ return ctx.mkErr(v, "could not compile regular expression %q: %v", x.B, err)
}
}
}
@@ -1573,9 +1573,9 @@
type binaryExpr struct {
baseValue
- op op
- left value
- right value
+ Op op
+ X value
+ Y value
}
func mkBin(ctx *context, pos token.Pos, op op, left, right value) value {
@@ -1605,19 +1605,19 @@
}
func updateBin(ctx *context, bin *binaryExpr) value {
- switch bin.op {
+ switch bin.Op {
case opMat, opNMat:
- bin.right = compileRegexp(ctx, bin.right)
- if isBottom(bin.right) {
- return bin.right
+ bin.Y = compileRegexp(ctx, bin.Y)
+ if isBottom(bin.Y) {
+ return bin.Y
}
}
return bin
}
-func (x *binaryExpr) kind() kind {
+func (x *binaryExpr) Kind() kind {
// TODO: cache results
- kind, _, _ := matchBinOpKind(x.op, x.left.kind(), x.right.kind())
+ kind, _, _ := matchBinOpKind(x.Op, x.X.Kind(), x.Y.Kind())
return kind | nonGround
}
@@ -1627,13 +1627,13 @@
// resolve into a single value.
type unification struct {
baseValue
- values []evaluated
+ Values []evaluated
}
-func (x *unification) kind() kind {
+func (x *unification) Kind() kind {
k := topKind
- for _, v := range x.values {
- k &= v.kind()
+ for _, v := range x.Values {
+ k &= v.Kind()
}
return k | nonGround
}
@@ -1641,14 +1641,14 @@
type disjunction struct {
baseValue
- values []dValue
+ Values []dValue
// errors is used to keep track of all errors that occurred in
// a disjunction for better error reporting down the road.
// TODO: consider storing the errors in values.
errors []*bottom
- hasDefaults bool // also true if it had elminated defaults.
+ HasDefaults bool // also true if it had elminated defaults.
// bind is the node that a successful disjunction will bind to. This
// allows other arcs to point to this node before the disjunction is
@@ -1658,14 +1658,14 @@
}
type dValue struct {
- val value
- marked bool
+ Val value
+ Default bool
}
-func (x *disjunction) kind() kind {
+func (x *disjunction) Kind() kind {
k := kind(0)
- for _, v := range x.values {
- k |= v.val.kind()
+ for _, v := range x.Values {
+ k |= v.Val.Kind()
}
if k != bottomKind {
k |= nonGround
@@ -1673,11 +1673,11 @@
return k
}
-func (x *disjunction) Pos() token.Pos { return x.values[0].val.Pos() }
+func (x *disjunction) Pos() token.Pos { return x.Values[0].Val.Pos() }
// add add a value to the disjunction. It is assumed not to be a disjunction.
func (x *disjunction) add(ctx *context, v value, marked bool) {
- x.values = append(x.values, dValue{v, marked})
+ x.Values = append(x.Values, dValue{v, marked})
if b, ok := v.(*bottom); ok {
x.errors = append(x.errors, b)
}
@@ -1687,34 +1687,34 @@
// x must already have been evaluated.
func (x *disjunction) normalize(ctx *context, src source) mVal {
leq := func(ctx *context, lt, gt dValue) bool {
- if isBottom(lt.val) {
+ if isBottom(lt.Val) {
return true
}
s := subsumer{ctx: ctx}
- return (!lt.marked || gt.marked) && s.subsumes(gt.val, lt.val)
+ return (!lt.Default || gt.Default) && s.subsumes(gt.Val, lt.Val)
}
k := 0
hasMarked := false
var markedErr *bottom
outer:
- for i, v := range x.values {
+ for i, v := range x.Values {
// TODO: this is pre-evaluation is quite aggressive. Verify whether
// this does not trigger structural cycles (it does). If so, this can check for
// bottom and the validation can be delayed to as late as picking
// defaults. The drawback of this approach is that printed intermediate
// results will not look great.
- if err := validate(ctx, v.val); err != nil {
+ if err := validate(ctx, v.Val); err != nil {
x.errors = append(x.errors, err)
- if v.marked {
+ if v.Default {
markedErr = err
}
continue
}
- if v.marked {
+ if v.Default {
hasMarked = true
}
- for j, w := range x.values {
+ for j, w := range x.Values {
if i == j {
continue
}
@@ -1727,16 +1727,16 @@
// If there was a three-way equality, an element w, where w == v could
// already have been added.
for j := 0; j < k; j++ {
- if leq(ctx, v, x.values[j]) {
+ if leq(ctx, v, x.Values[j]) {
continue outer
}
}
// TODO: do not modify value, but create a new disjunction.
- x.values[k] = v
+ x.Values[k] = v
k++
}
- if !hasMarked && markedErr != nil && (k > 1 || !x.values[0].val.kind().isGround()) {
- x.values[k] = dValue{&bottom{}, true}
+ if !hasMarked && markedErr != nil && (k > 1 || !x.Values[0].Val.Kind().isGround()) {
+ x.Values[k] = dValue{&bottom{}, true}
k++
}
@@ -1744,18 +1744,18 @@
case 0:
// Empty disjunction. All elements must be errors.
// Take the first error as an example.
- err := x.values[0].val
+ err := x.Values[0].Val
if !isBottom(err) {
// TODO: use format instead of debugStr.
err = ctx.mkErr(src, ctx.str(err))
}
return mVal{x.computeError(ctx, src), false}
case 1:
- v := x.values[0]
- return mVal{v.val.(evaluated), v.marked}
+ v := x.Values[0]
+ return mVal{v.Val.(evaluated), v.Default}
}
// TODO: do not modify value, but create a new disjunction.
- x.values = x.values[:k]
+ x.Values = x.Values[:k]
return mVal{x, false}
}
@@ -1803,7 +1803,7 @@
clauses yielder
}
-func (x *listComprehension) kind() kind {
+func (x *listComprehension) Kind() kind {
return listKind | nonGround | referenceKind
}
@@ -1812,7 +1812,7 @@
clauses yielder
}
-func (x *structComprehension) kind() kind {
+func (x *structComprehension) Kind() kind {
return structKind | nonGround | referenceKind
}
@@ -1828,7 +1828,7 @@
attrs *attributes
}
-func (x *fieldComprehension) kind() kind {
+func (x *fieldComprehension) Kind() kind {
return structKind | nonGround
}
@@ -1844,7 +1844,7 @@
value value
}
-func (x *yield) kind() kind { return topKind | referenceKind }
+func (x *yield) Kind() kind { return topKind | referenceKind }
func (x *yield) yield(ctx *context, fn yieldFunc) *bottom {
v := x.value.evalPartial(ctx)
@@ -1859,22 +1859,22 @@
type guard struct { // rename to guard
baseValue
- condition value
- value yielder
+ Condition value
+ Dst yielder
}
-func (x *guard) kind() kind { return topKind | referenceKind }
+func (x *guard) Kind() kind { return topKind | referenceKind }
func (x *guard) yield(ctx *context, fn yieldFunc) *bottom {
- filter := ctx.manifest(x.condition)
+ filter := ctx.manifest(x.Condition)
if err, ok := filter.(*bottom); ok {
return err
}
if err := checkKind(ctx, filter, boolKind); err != nil {
return err
}
- if filter.(*boolLit).b {
- if err := x.value.yield(ctx, fn); err != nil {
+ if filter.(*boolLit).B {
+ if err := x.Dst.yield(ctx, fn); err != nil {
return err
}
}
@@ -1883,17 +1883,17 @@
type feed struct {
baseValue
- source value
- fn *lambdaExpr
+ Src value
+ fn *lambdaExpr
}
-func (x *feed) kind() kind { return topKind | referenceKind }
+func (x *feed) Kind() kind { return topKind | referenceKind }
func (x *feed) yield(ctx *context, yfn yieldFunc) (result *bottom) {
if ctx.trace {
defer uni(indent(ctx, "feed", x))
}
- source := ctx.manifest(x.source)
+ source := ctx.manifest(x.Src)
fn := x.fn // no need to evaluate eval
switch src := source.(type) {
@@ -1940,9 +1940,9 @@
if err, ok := source.(*bottom); ok {
return err
}
- if k := source.kind(); k&(structKind|listKind) == bottomKind {
- return ctx.mkErr(x, x.source, "feed source must be list or struct, found %s", k)
+ if k := source.Kind(); k&(structKind|listKind) == bottomKind {
+ return ctx.mkErr(x, x.Src, "feed source must be list or struct, found %s", k)
}
- return ctx.mkErr(x, x.source, codeIncomplete, "incomplete feed source")
+ return ctx.mkErr(x, x.Src, codeIncomplete, "incomplete feed source")
}
}