Skip to content

Commit

Permalink
cue: remove dead code
Browse files Browse the repository at this point in the history
Change-Id: Ie7700e845d50cf0a6ae54d77ee41f597f992fbc8
Reviewed-on: https://cue-review.googlesource.com/c/cue/+/6861
Reviewed-by: CUE cueckoo <cueckoo@gmail.com>
Reviewed-by: Marcel van Lohuizen <mpvl@golang.org>
  • Loading branch information
mpvl committed Aug 18, 2020
1 parent 304b02e commit 40a6bcd
Show file tree
Hide file tree
Showing 5 changed files with 2 additions and 244 deletions.
113 changes: 0 additions & 113 deletions cue/builtin.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,50 +171,6 @@ func mustParseConstBuiltin(ctx *context, name, val string) adt.Expr {

}

var lenBuiltin = &builtin{
Name: "len",
Params: []kind{stringKind | bytesKind | listKind | structKind},
Result: intKind,
Func: func(c *callCtxt) {
v := c.value(0)
switch k := v.IncompleteKind(); k {
case StructKind:
s, err := v.structValData(c.ctx)
if err != nil {
c.ret = err
break
}
c.ret = s.Len()
case ListKind:
i := 0
iter, err := v.List()
if err != nil {
c.ret = err
break
}
for ; iter.Next(); i++ {
}
c.ret = i
case BytesKind:
b, err := v.Bytes()
if err != nil {
c.ret = err
break
}
c.ret = len(b)
case StringKind:
s, err := v.String()
if err != nil {
c.ret = err
break
}
c.ret = len(s)
default:
c.ret = c.ctx.opCtx.Newf("invalid argument type %v", k)
}
},
}

func pos(n adt.Node) (p token.Pos) {
if n == nil {
return
Expand All @@ -226,71 +182,6 @@ func pos(n adt.Node) (p token.Pos) {
return src.Pos()
}

var closeBuiltin = &builtin{
Name: "close",
Params: []kind{structKind},
Result: structKind,
Func: func(c *callCtxt) {
s, ok := c.args[0].(*adt.Vertex)
if !ok {
c.ret = errors.Newf(pos(c.args[0]), "struct argument must be concrete")
return
}
if s.IsClosed(c.ctx.opCtx) {
c.ret = s
} else {
v := *s
v.Closed = nil // TODO: set dedicated Closer.
c.ret = &v
}
},
}

var andBuiltin = &builtin{
Name: "and",
Params: []kind{listKind},
Result: intKind,
Func: func(c *callCtxt) {
iter := c.iter(0)
if !iter.Next() {
c.ret = &top{}
return
}
var u adt.Expr = iter.Value().v
for iter.Next() {
u = &adt.BinaryExpr{Op: adt.AndOp, X: u, Y: iter.Value().v}
}
c.ret = u
},
}

var orBuiltin = &builtin{
Name: "or",
Params: []kind{listKind},
Result: intKind,
Func: func(c *callCtxt) {
iter := c.iter(0)
d := []adt.Disjunct{}
for iter.Next() {
d = append(d, adt.Disjunct{iter.Value().v, false})
}
c.ret = &adt.DisjunctionExpr{nil, d, false}
if len(d) == 0 {
// TODO(manifest): This should not be unconditionally incomplete,
// but it requires results from comprehensions and all to have
// some special status. Maybe this can be solved by having results
// of list comprehensions be open if they result from iterating over
// an open list or struct. This would actually be exactly what
// that means. The error here could then only add an incomplete
// status if the source is open.
c.ret = &adt.Bottom{
Code: adt.IncompleteError,
Err: errors.Newf(c.Pos(), "empty list in call to or"),
}
}
},
}

func (x *builtin) name(ctx *context) string {
if x.pkg == 0 {
return x.Name
Expand Down Expand Up @@ -430,10 +321,6 @@ func initBuiltins(pkgs map[string]*builtinPkg) {
}
}

func getBuiltinShorthandPkg(ctx *context, shorthand string) *structLit {
return getBuiltinPkg(ctx, "-/"+shorthand)
}

func getBuiltinPkg(ctx *context, path string) *structLit {
p, ok := builtins[path]
if !ok {
Expand Down
58 changes: 2 additions & 56 deletions cue/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@
package cue

import (
"fmt"
"reflect"

"cuelang.org/go/cue/errors"
"cuelang.org/go/cue/token"
"cuelang.org/go/internal/core/adt"
Expand Down Expand Up @@ -77,29 +74,10 @@ func (e *valueError) Path() (a []string) {
type errCode = adt.ErrorCode

const (
codeNone errCode = 0
codeFatal = adt.EvalError
codeNotExist = adt.NotExistError
codeTypeError = adt.EvalError
codeIncomplete = adt.IncompleteError
codeUser = adt.UserError
codeCycle = adt.CycleError
codeNotExist = adt.NotExistError
codeIncomplete = adt.IncompleteError
)

func isIncomplete(v value) bool {
if err, ok := v.(*bottom); ok {
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 false
}

var errNotExists = &adt.Bottom{
Code: codeNotExist,
Err: errors.Newf(token.NoPos, "undefined value"),
Expand Down Expand Up @@ -148,35 +126,3 @@ outer:
}
return e
}

func fixArg(idx *index, x interface{}) interface{} {
switch x.(type) {
case uint, int, string:
return x
case value:
return x
}
t := reflect.TypeOf(x)
// Store all non-ptr types as is, as they cannot change.
if k := t.Kind(); k == reflect.String || k <= reflect.Complex128 {
return x
}
return fmt.Sprint(x)
}

func isBottom(x adt.Node) bool {
if x == nil {
return true
}
b, _ := x.(*adt.Bottom)
return b != nil
}

func firstBottom(v ...value) *bottom {
for _, b := range v {
if isBottom(b) {
return b.(*bottom)
}
}
return nil
}
37 changes: 0 additions & 37 deletions cue/op.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,43 +61,6 @@ const (
InterpolationOp = adt.InterpolationOp
)

var opToOp = map[op]Op{
opUnify: AndOp,
// TODO(eval): opUnifyUnchecked is not the same as opUnify and should have its own
// category, if needed. More likely opUnifyUnchecked, should be
// represented as a separate embedding method.
opUnifyUnchecked: AndOp,
opDisjunction: OrOp,
opLand: BooleanAndOp,
opLor: BooleanOrOp,
opEql: EqualOp,
opNot: NotOp,
opNeq: NotEqualOp,
opLss: LessThanOp,
opLeq: LessThanEqualOp,
opGtr: GreaterThanOp,
opGeq: GreaterThanEqualOp,
opMat: RegexMatchOp,
opNMat: NotRegexMatchOp,
opAdd: AddOp,
opSub: SubtractOp,
opMul: MultiplyOp,
opQuo: FloatQuotientOp,
opIQuo: IntQuotientOp,
opIRem: IntRemainderOp,
opIDiv: IntDivideOp,
opIMod: IntModuloOp,
}

func opIn(op op, anyOf ...op) bool {
for _, o := range anyOf {
if o == op {
return true
}
}
return false
}

// isCmp reports whether an op is a comparator.
func (op op) isCmp() bool {
return opEql <= op && op <= opGeq
Expand Down
32 changes: 0 additions & 32 deletions cue/resolve_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ package cue
import (
"strings"
"testing"

"cuelang.org/go/internal/core/adt"
)

func TestX(t *testing.T) {
Expand All @@ -30,33 +28,3 @@ func TestX(t *testing.T) {
t.Skip()
}
}

// var traceOn = flag.Bool("debug", false, "enable tracing")

// func compileFileWithErrors(t *testing.T, body string) (*context, *structLit, error) {
// t.Helper()
// ctx, inst, err := compileInstance(t, body)
// return ctx, inst.root, err
// }

// func compileFile(t *testing.T, body string) (*context, *structLit) {
// t.Helper()
// ctx, inst, errs := compileInstance(t, body)
// if errs != nil {
// t.Fatal(errs)
// }
// return ctx, inst.root
// }

func compileInstance(t *testing.T, body string) (*context, *Instance, error) {
var r Runtime
inst, err := r.Compile("test", body)

if err != nil {
x := newInstance(newIndex(sharedIndex), nil, &adt.Vertex{})
ctx := x.newContext()
return ctx, x, err
}

return r.index().newContext(), inst, nil
}
6 changes: 0 additions & 6 deletions cue/types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2950,9 +2950,3 @@ func compactRawStr(v Value) string {
cfg := &debug.Config{Compact: true, Raw: true}
return debug.NodeString(ctx.opCtx, v.v, cfg)
}

func compactValueStr(v Value) string {
ctx := v.ctx()
cfg := &debug.Config{Compact: true}
return debug.NodeString(ctx.opCtx, v.v, cfg)
}

0 comments on commit 40a6bcd

Please sign in to comment.