Rename some arguments for consistency

This commit is contained in:
Nigel Tao committed 2017-12-09 16:03:18 +11:00
1 parent 90f1fcc328
commit 3b822f8b17
2 files changed
+20 -20

No files matched your search

+8 -8
View File
@@ -1168,35 +1168,35 @@ func (q *checker) bcheckExprAssociativeOp(n *a.Expr, depth uint32) (*big.Int, *b
return lMin, lMax, nil return lMin, lMax, nil
} }
func (q *checker) bcheckTypeExpr(n *a.TypeExpr) (*big.Int, *big.Int, error) { func (q *checker) bcheckTypeExpr(typ *a.TypeExpr) (*big.Int, *big.Int, error) {
if n.IsIdeal() { if typ.IsIdeal() {
// TODO: can an ideal type be refined?? // TODO: can an ideal type be refined??
return nil, nil, nil return nil, nil, nil
} }
switch n.Decorator().Key() { switch typ.Decorator().Key() {
case t.KeyPtr, t.KeyOpenBracket, t.KeyColon: case t.KeyPtr, t.KeyOpenBracket, t.KeyColon:
return nil, nil, nil return nil, nil, nil
} }
switch n.Name().Key() { switch typ.Name().Key() {
case t.KeyReader1, t.KeyWriter1: case t.KeyReader1, t.KeyWriter1:
return nil, nil, nil return nil, nil, nil
} }
b := [2]*big.Int{} b := [2]*big.Int{}
if key := n.Name().Key(); key < t.Key(len(numTypeBounds)) { if key := typ.Name().Key(); key < t.Key(len(numTypeBounds)) {
b = numTypeBounds[key] b = numTypeBounds[key]
} }
if b[0] == nil || b[1] == nil { if b[0] == nil || b[1] == nil {
return nil, nil, nil return nil, nil, nil
} }
if n.IsRefined() { if typ.IsRefined() {
if x := n.Min(); x != nil { if x := typ.Min(); x != nil {
if cv := x.ConstValue(); cv != nil && b[0].Cmp(cv) < 0 { if cv := x.ConstValue(); cv != nil && b[0].Cmp(cv) < 0 {
b[0] = cv b[0] = cv
} }
} }
if x := n.Max(); x != nil { if x := typ.Max(); x != nil {
if cv := x.ConstValue(); cv != nil && b[1].Cmp(cv) > 0 { if cv := x.ConstValue(); cv != nil && b[1].Cmp(cv) > 0 {
b[1] = cv b[1] = cv
} }
+12 -12
View File
@@ -1106,17 +1106,17 @@ func (q *checker) tcheckExprAssociativeOp(n *a.Expr, depth uint32) error {
return fmt.Errorf("check: unrecognized token.Key (0x%X) for tcheckExprAssociativeOp", n.ID0().Key()) return fmt.Errorf("check: unrecognized token.Key (0x%X) for tcheckExprAssociativeOp", n.ID0().Key())
} }
func (q *checker) tcheckTypeExpr(n *a.TypeExpr, depth uint32) error { func (q *checker) tcheckTypeExpr(typ *a.TypeExpr, depth uint32) error {
if depth > a.MaxTypeExprDepth { if depth > a.MaxTypeExprDepth {
return fmt.Errorf("check: type expression recursion depth too large") return fmt.Errorf("check: type expression recursion depth too large")
} }
depth++ depth++
swtch: swtch:
switch n.Decorator().Key() { switch typ.Decorator().Key() {
case 0: case 0:
if n.Name().IsNumType() { if typ.Name().IsNumType() {
for _, b := range n.Bounds() { for _, b := range typ.Bounds() {
if b == nil { if b == nil {
continue continue
} }
@@ -1129,22 +1129,22 @@ swtch:
} }
break break
} }
if n.Min() != nil || n.Max() != nil { if typ.Min() != nil || typ.Max() != nil {
// TODO: reject. You can only refine numeric types. // TODO: reject. You can only refine numeric types.
} }
switch n.Name().Key() { switch typ.Name().Key() {
case t.KeyBool, t.KeyStatus, t.KeyReader1, t.KeyWriter1: case t.KeyBool, t.KeyStatus, t.KeyReader1, t.KeyWriter1:
break swtch break swtch
} }
for _, s := range q.c.structs { for _, s := range q.c.structs {
if s.ID == n.Name() { if s.ID == typ.Name() {
break swtch break swtch
} }
} }
return fmt.Errorf("check: %q is not a type", n.Name().Str(q.tm)) return fmt.Errorf("check: %q is not a type", typ.Name().Str(q.tm))
case t.KeyOpenBracket: case t.KeyOpenBracket:
aLen := n.ArrayLength() aLen := typ.ArrayLength()
if err := q.tcheckExpr(aLen, 0); err != nil { if err := q.tcheckExpr(aLen, 0); err != nil {
return err return err
} }
@@ -1155,18 +1155,18 @@ swtch:
// TODO: also check t.KeyNptr? Where else should we look for nptr? // TODO: also check t.KeyNptr? Where else should we look for nptr?
case t.KeyPtr, t.KeyColon: case t.KeyPtr, t.KeyColon:
if err := q.tcheckTypeExpr(n.Inner(), depth); err != nil { if err := q.tcheckTypeExpr(typ.Inner(), depth); err != nil {
return err return err
} }
default: default:
// TODO: don't hard-code deflate.decoder as an acceptable type. // TODO: don't hard-code deflate.decoder as an acceptable type.
if q.tm.ByID(n.Decorator()) == "deflate" && q.tm.ByID(n.Name()) == "decoder" { if q.tm.ByID(typ.Decorator()) == "deflate" && q.tm.ByID(typ.Name()) == "decoder" {
break break
} }
return fmt.Errorf("check: unrecognized node for tcheckTypeExpr") return fmt.Errorf("check: unrecognized node for tcheckTypeExpr")
} }
n.Node().SetTypeChecked() typ.Node().SetTypeChecked()
return nil return nil
} }