summaryrefslogtreecommitdiff
path: root/src/pkg/exp
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2010-03-30 10:34:57 -0700
committerRuss Cox <rsc@golang.org>2010-03-30 10:34:57 -0700
commit74119689619c24f5871056d13d07d56f69ad5f60 (patch)
tree2ad4647a66bf21bf56d761edba537c237b8e318a /src/pkg/exp
parent74339da2d519a795f33d78f8694eb7b97065d9d7 (diff)
downloadgolang-74119689619c24f5871056d13d07d56f69ad5f60.tar.gz
single argument panic
note that sortmain.go has been run through hg gofmt; only the formatting of the day initializers changed. i'm happy to revert that formatting if you'd prefer. stop on error in doc/progs/run R=r CC=golang-dev http://codereview.appspot.com/850041
Diffstat (limited to 'src/pkg/exp')
-rw-r--r--src/pkg/exp/eval/eval_test.go2
-rw-r--r--src/pkg/exp/eval/expr.go6
-rw-r--r--src/pkg/exp/eval/expr1.go62
-rw-r--r--src/pkg/exp/eval/gen.go8
-rw-r--r--src/pkg/exp/eval/type.go10
-rw-r--r--src/pkg/exp/ogle/rvalue.go4
-rw-r--r--src/pkg/exp/ogle/vars.go2
7 files changed, 45 insertions, 49 deletions
diff --git a/src/pkg/exp/eval/eval_test.go b/src/pkg/exp/eval/eval_test.go
index 911c7e4a5..837c4fabd 100644
--- a/src/pkg/exp/eval/eval_test.go
+++ b/src/pkg/exp/eval/eval_test.go
@@ -196,7 +196,7 @@ func toValue(val interface{}) Value {
return &funcV{val}
}
log.Crashf("toValue(%T) not implemented", val)
- panic()
+ panic("unreachable")
}
/*
diff --git a/src/pkg/exp/eval/expr.go b/src/pkg/exp/eval/expr.go
index 5547aee31..e630578bd 100644
--- a/src/pkg/exp/eval/expr.go
+++ b/src/pkg/exp/eval/expr.go
@@ -642,7 +642,7 @@ func (a *exprCompiler) compile(x ast.Expr, callCtx bool) *expr {
return ei.compileUnaryExpr(x.Op, v)
}
log.Crashf("unexpected ast node type %T", x)
- panic()
+ panic("unreachable")
typeexpr:
if !callCtx {
@@ -704,7 +704,7 @@ func (a *exprInfo) compileIdent(b *block, constant bool, callCtx bool, name stri
return nil
}
log.Crashf("name %s has unknown type %T", name, def)
- panic()
+ panic("unreachable")
}
func (a *exprInfo) compileVariable(level int, v *Variable) *expr {
@@ -1424,7 +1424,7 @@ func (a *exprInfo) compileBuiltinCallExpr(b *block, ft *FuncType, as []*expr) *e
}
log.Crashf("unexpected built-in function '%s'", ft.builtin)
- panic()
+ panic("unreachable")
}
func (a *exprInfo) compileStarExpr(v *expr) *expr {
diff --git a/src/pkg/exp/eval/expr1.go b/src/pkg/exp/eval/expr1.go
index 28da8eea1..0e83053f4 100644
--- a/src/pkg/exp/eval/expr1.go
+++ b/src/pkg/exp/eval/expr1.go
@@ -12,9 +12,15 @@ import (
* "As" functions. These retrieve evaluator functions from an
* expr, panicking if the requested evaluator has the wrong type.
*/
-func (a *expr) asBool() func(*Thread) bool { return a.eval.(func(*Thread) bool) }
-func (a *expr) asUint() func(*Thread) uint64 { return a.eval.(func(*Thread) uint64) }
-func (a *expr) asInt() func(*Thread) int64 { return a.eval.(func(*Thread) int64) }
+func (a *expr) asBool() func(*Thread) bool {
+ return a.eval.(func(*Thread) bool)
+}
+func (a *expr) asUint() func(*Thread) uint64 {
+ return a.eval.(func(*Thread) uint64)
+}
+func (a *expr) asInt() func(*Thread) int64 {
+ return a.eval.(func(*Thread) int64)
+}
func (a *expr) asIdealInt() func() *bignum.Integer {
return a.eval.(func() *bignum.Integer)
}
@@ -33,10 +39,18 @@ func (a *expr) asArray() func(*Thread) ArrayValue {
func (a *expr) asStruct() func(*Thread) StructValue {
return a.eval.(func(*Thread) StructValue)
}
-func (a *expr) asPtr() func(*Thread) Value { return a.eval.(func(*Thread) Value) }
-func (a *expr) asFunc() func(*Thread) Func { return a.eval.(func(*Thread) Func) }
-func (a *expr) asSlice() func(*Thread) Slice { return a.eval.(func(*Thread) Slice) }
-func (a *expr) asMap() func(*Thread) Map { return a.eval.(func(*Thread) Map) }
+func (a *expr) asPtr() func(*Thread) Value {
+ return a.eval.(func(*Thread) Value)
+}
+func (a *expr) asFunc() func(*Thread) Func {
+ return a.eval.(func(*Thread) Func)
+}
+func (a *expr) asSlice() func(*Thread) Slice {
+ return a.eval.(func(*Thread) Slice)
+}
+func (a *expr) asMap() func(*Thread) Map {
+ return a.eval.(func(*Thread) Map)
+}
func (a *expr) asMulti() func(*Thread) []Value {
return a.eval.(func(*Thread) []Value)
}
@@ -72,7 +86,7 @@ func (a *expr) asInterface() func(*Thread) interface{} {
default:
log.Crashf("unexpected expression node type %T at %v", a.eval, a.pos)
}
- panic()
+ panic("fail")
}
/*
@@ -210,26 +224,17 @@ func (a *expr) genUnaryOpNeg(v *expr) {
switch a.t.lit().(type) {
case *uintType:
vf := v.asUint()
- a.eval = func(t *Thread) uint64 {
- v := vf(t)
- return -v
- }
+ a.eval = func(t *Thread) uint64 { v := vf(t); return -v }
case *intType:
vf := v.asInt()
- a.eval = func(t *Thread) int64 {
- v := vf(t)
- return -v
- }
+ a.eval = func(t *Thread) int64 { v := vf(t); return -v }
case *idealIntType:
v := v.asIdealInt()()
val := v.Neg()
a.eval = func() *bignum.Integer { return val }
case *floatType:
vf := v.asFloat()
- a.eval = func(t *Thread) float64 {
- v := vf(t)
- return -v
- }
+ a.eval = func(t *Thread) float64 { v := vf(t); return -v }
case *idealFloatType:
v := v.asIdealFloat()()
val := v.Neg()
@@ -243,10 +248,7 @@ func (a *expr) genUnaryOpNot(v *expr) {
switch a.t.lit().(type) {
case *boolType:
vf := v.asBool()
- a.eval = func(t *Thread) bool {
- v := vf(t)
- return !v
- }
+ a.eval = func(t *Thread) bool { v := vf(t); return !v }
default:
log.Crashf("unexpected type %v at %v", a.t, a.pos)
}
@@ -256,16 +258,10 @@ func (a *expr) genUnaryOpXor(v *expr) {
switch a.t.lit().(type) {
case *uintType:
vf := v.asUint()
- a.eval = func(t *Thread) uint64 {
- v := vf(t)
- return ^v
- }
+ a.eval = func(t *Thread) uint64 { v := vf(t); return ^v }
case *intType:
vf := v.asInt()
- a.eval = func(t *Thread) int64 {
- v := vf(t)
- return ^v
- }
+ a.eval = func(t *Thread) int64 { v := vf(t); return ^v }
case *idealIntType:
v := v.asIdealInt()()
val := v.Neg().Sub(bignum.Int(1))
@@ -1905,5 +1901,5 @@ func genAssign(lt Type, r *expr) func(lv Value, t *Thread) {
default:
log.Crashf("unexpected left operand type %v at %v", lt, r.pos)
}
- panic()
+ panic("fail")
}
diff --git a/src/pkg/exp/eval/gen.go b/src/pkg/exp/eval/gen.go
index ea421ff9c..969d65586 100644
--- a/src/pkg/exp/eval/gen.go
+++ b/src/pkg/exp/eval/gen.go
@@ -103,12 +103,12 @@ var binOps = []Op{
Op{Name: "Sub", Expr: "l - r", ConstExpr: "l.Sub(r)", Types: numbers},
Op{Name: "Mul", Expr: "l * r", ConstExpr: "l.Mul(r)", Types: numbers},
Op{Name: "Quo",
- Body: "if r == 0 { t.Abort(DivByZeroError{}) } ret = l / r",
+ Body: "if r == 0 { t.Abort(DivByZeroError{}) }; ret = l / r",
ConstExpr: "l.Quo(r)",
Types: numbers,
},
Op{Name: "Rem",
- Body: "if r == 0 { t.Abort(DivByZeroError{}) } ret = l % r",
+ Body: "if r == 0 { t.Abort(DivByZeroError{}) }; ret = l % r",
ConstExpr: "l.Rem(r)",
Types: integers,
},
@@ -186,7 +186,7 @@ func (a *expr) asInterface() (func(*Thread) interface{}) {
default:
log.Crashf("unexpected expression node type %T at %v", a.eval, a.pos);
}
- panic();
+ panic("fail");
}
/*
@@ -357,7 +357,7 @@ func genAssign(lt Type, r *expr) (func(lv Value, t *Thread)) {
default:
log.Crashf("unexpected left operand type %v at %v", lt, r.pos);
}
- panic();
+ panic("fail");
}
`
diff --git a/src/pkg/exp/eval/type.go b/src/pkg/exp/eval/type.go
index 2b2a632cd..fbb428679 100644
--- a/src/pkg/exp/eval/type.go
+++ b/src/pkg/exp/eval/type.go
@@ -231,7 +231,7 @@ func (t *uintType) Zero() Value {
res := uint64V(0)
return &res
}
- panic("unexpected uint bit count: ", t.Bits)
+ panic("unexpected uint bit count")
}
func (t *uintType) minVal() *bignum.Rational { return bignum.Rat(0, 1) }
@@ -304,7 +304,7 @@ func (t *intType) Zero() Value {
res := intV(0)
return &res
}
- panic("unexpected int bit count: ", t.Bits)
+ panic("unexpected int bit count")
}
func (t *intType) minVal() *bignum.Rational {
@@ -390,7 +390,7 @@ func (t *floatType) Zero() Value {
res := floatV(0)
return &res
}
- panic("unexpected float bit count: ", t.Bits)
+ panic("unexpected float bit count")
}
var maxFloat32Val = bignum.MakeRat(bignum.Int(0xffffff).Shl(127-23), bignum.Nat(1))
@@ -410,7 +410,7 @@ func (t *floatType) minVal() *bignum.Rational {
return minFloat64Val
}
log.Crashf("unexpected floating point bit count: %d", bits)
- panic()
+ panic("unreachable")
}
func (t *floatType) maxVal() *bignum.Rational {
@@ -425,7 +425,7 @@ func (t *floatType) maxVal() *bignum.Rational {
return maxFloat64Val
}
log.Crashf("unexpected floating point bit count: %d", bits)
- panic()
+ panic("unreachable")
}
/*
diff --git a/src/pkg/exp/ogle/rvalue.go b/src/pkg/exp/ogle/rvalue.go
index ba915ed5c..3d630f936 100644
--- a/src/pkg/exp/ogle/rvalue.go
+++ b/src/pkg/exp/ogle/rvalue.go
@@ -232,7 +232,7 @@ func (v remoteFloat) aGet(a aborter) float64 {
case 8:
return v.r.p.ToFloat64(bits)
}
- panic("Unexpected float size ", v.size)
+ panic("Unexpected float size")
}
func (v remoteFloat) Set(t *eval.Thread, x float64) {
@@ -247,7 +247,7 @@ func (v remoteFloat) aSet(a aborter, x float64) {
case 8:
bits = v.r.p.FromFloat64(x)
default:
- panic("Unexpected float size ", v.size)
+ panic("Unexpected float size")
}
v.r.Set(a, v.size, bits)
}
diff --git a/src/pkg/exp/ogle/vars.go b/src/pkg/exp/ogle/vars.go
index e6298bc48..eed60acec 100644
--- a/src/pkg/exp/ogle/vars.go
+++ b/src/pkg/exp/ogle/vars.go
@@ -63,7 +63,7 @@ func (v remoteFramePtr) Get(t *eval.Thread) eval.Value {
}
t.Abort(NotOnStack{v.fn, g})
- panic()
+ panic("fail")
}
func (v remoteFramePtr) Set(t *eval.Thread, x eval.Value) {