From ebf3713555d5ad263078f77dc42e8dce393a73f0 Mon Sep 17 00:00:00 2001 From: Nigel Tao Date: Sat, 10 Jun 2017 10:55:51 +1000 Subject: [PATCH] Rename PackageOrDecorator to Decorator. --- cmd/puffs-gen-c/main.go | 8 ++++---- lang/ast/ast.go | 18 +++++++++--------- lang/ast/string.go | 6 +++--- lang/check/bounds.go | 4 ++-- lang/check/check.go | 4 ++-- lang/check/type.go | 8 ++++---- 6 files changed, 24 insertions(+), 24 deletions(-) diff --git a/cmd/puffs-gen-c/main.go b/cmd/puffs-gen-c/main.go index 6afb3c89..7ad094b8 100644 --- a/cmd/puffs-gen-c/main.go +++ b/cmd/puffs-gen-c/main.go @@ -546,7 +546,7 @@ func (g *gen) writeFuncImpl(n *a.Func) error { badArg := false for _, o := range n.In().Fields() { o := o.Field() - if o.XType().PackageOrDecorator().Key() != t.KeyPtr { + if o.XType().Decorator().Key() != t.KeyPtr { // TODO: check for type refinements: u32[..4095] instead of // u32. Also check for types, for array-typed arguments. continue @@ -601,7 +601,7 @@ func (g *gen) writeField(n *a.Field, namePrefix string) error { convertible, nPtr := true, 0 for x := n.XType(); x != nil; x = x.Inner() { - if p := x.PackageOrDecorator().Key(); p == t.KeyPtr { + if p := x.Decorator().Key(); p == t.KeyPtr { if nPtr == maxNPtr { return fmt.Errorf("cannot convert Puffs type %q to C: too many ptr's", n.XType().String(g.tm)) } @@ -635,7 +635,7 @@ func (g *gen) writeField(n *a.Field, namePrefix string) error { g.writes(n.Name().String(g.tm)) for x := n.XType(); x != nil; x = x.Inner() { - if x.PackageOrDecorator() == t.IDOpenBracket { + if x.Decorator() == t.IDOpenBracket { g.writeb('[') g.writes(x.ArrayLength().ConstValue().String()) g.writeb(']') @@ -1115,7 +1115,7 @@ func (g *gen) writeExprAssociativeOp(n *a.Expr, rp replacementPolicy, depth uint } func (g *gen) writeCTypeName(n *a.TypeExpr) error { - if n.PackageOrDecorator() == 0 { + if n.Decorator() == 0 { if k := n.Name().Key(); k < t.Key(len(cTypeNames)) { if s := cTypeNames[k]; s != "" { g.writes(s) diff --git a/lang/ast/ast.go b/lang/ast/ast.go index c629bc34..093fe49a 100644 --- a/lang/ast/ast.go +++ b/lang/ast/ast.go @@ -440,7 +440,7 @@ func NewJump(keyword t.ID, label t.ID) *Jump { // MaxTypeExprDepth is an advisory limit for a TypeExpr's recursion depth. const MaxTypeExprDepth = 63 -// TypeExpr is a type expression, such as "u32", "u32[:8]", "pkg.foo", "ptr T" +// TypeExpr is a type expression, such as "u32", "u32[..8]", "pkg.foo", "ptr T" // or "[8] T": // - ID0: <0|package name|IDPtr|IDOpenBracket> // - ID1: <0|type name> @@ -460,14 +460,14 @@ const MaxTypeExprDepth = 63 // TODO: function / method types. type TypeExpr Node -func (n *TypeExpr) Node() *Node { return (*Node)(n) } -func (n *TypeExpr) PackageOrDecorator() t.ID { return n.id0 } -func (n *TypeExpr) Name() t.ID { return n.id1 } -func (n *TypeExpr) ArrayLength() *Expr { return n.lhs.Expr() } -func (n *TypeExpr) Bounds() [2]*Expr { return [2]*Expr{n.lhs.Expr(), n.mhs.Expr()} } -func (n *TypeExpr) Min() *Expr { return n.lhs.Expr() } -func (n *TypeExpr) Max() *Expr { return n.mhs.Expr() } -func (n *TypeExpr) Inner() *TypeExpr { return n.rhs.TypeExpr() } +func (n *TypeExpr) Node() *Node { return (*Node)(n) } +func (n *TypeExpr) Decorator() t.ID { return n.id0 } +func (n *TypeExpr) Name() t.ID { return n.id1 } +func (n *TypeExpr) ArrayLength() *Expr { return n.lhs.Expr() } +func (n *TypeExpr) Bounds() [2]*Expr { return [2]*Expr{n.lhs.Expr(), n.mhs.Expr()} } +func (n *TypeExpr) Min() *Expr { return n.lhs.Expr() } +func (n *TypeExpr) Max() *Expr { return n.mhs.Expr() } +func (n *TypeExpr) Inner() *TypeExpr { return n.rhs.TypeExpr() } func (n *TypeExpr) IsBool() bool { return n.id0 == 0 && n.id1.Key() == t.KeyBool && n.lhs == nil && n.mhs == nil && n.rhs == nil diff --git a/lang/ast/string.go b/lang/ast/string.go index 13647b66..1f91b20d 100644 --- a/lang/ast/string.go +++ b/lang/ast/string.go @@ -145,7 +145,7 @@ func (n *TypeExpr) String(tm *t.Map) string { if n == nil { return "" } - if n.PackageOrDecorator() == 0 && n.Min() == nil && n.Max() == nil { + if n.Decorator() == 0 && n.Min() == nil && n.Max() == nil { return tm.ByID(n.Name()) } return string(n.appendString(nil, tm, 0)) @@ -160,7 +160,7 @@ func (n *TypeExpr) appendString(buf []byte, tm *t.Map, depth uint32) []byte { return append(buf, "!invalid_type!"...) } - switch n.PackageOrDecorator().Key() { + switch n.Decorator().Key() { case 0: buf = append(buf, tm.ByID(n.Name())...) case t.KeyPtr: @@ -172,7 +172,7 @@ func (n *TypeExpr) appendString(buf []byte, tm *t.Map, depth uint32) []byte { buf = append(buf, "] "...) return n.Inner().appendString(buf, tm, depth) default: - buf = append(buf, tm.ByID(n.PackageOrDecorator())...) + buf = append(buf, tm.ByID(n.Decorator())...) buf = append(buf, '.') buf = append(buf, tm.ByID(n.Name())...) } diff --git a/lang/check/bounds.go b/lang/check/bounds.go index 61c56d11..fc57215c 100644 --- a/lang/check/bounds.go +++ b/lang/check/bounds.go @@ -293,7 +293,7 @@ func (q *checker) bcheckAssignment(lhs *a.Expr, op t.ID, rhs *a.Expr) error { } func (q *checker) bcheckAssignment1(lhs *a.Expr, op t.ID, rhs *a.Expr) error { - switch lhs.MType().PackageOrDecorator().Key() { + switch lhs.MType().Decorator().Key() { case t.KeyPtr: // TODO: handle. return nil @@ -805,7 +805,7 @@ func (q *checker) bcheckExprAssociativeOp(n *a.Expr, depth uint32) (*big.Int, *b } func (q *checker) bcheckTypeExpr(n *a.TypeExpr) (*big.Int, *big.Int, error) { - switch n.PackageOrDecorator().Key() { + switch n.Decorator().Key() { case t.KeyPtr, t.KeyOpenBracket: return nil, nil, nil } diff --git a/lang/check/check.go b/lang/check/check.go index 2c087f76..c4688451 100644 --- a/lang/check/check.go +++ b/lang/check/check.go @@ -201,7 +201,7 @@ func (c *Checker) checkFields(fields []*a.Node, banPtrTypes bool) error { } if banPtrTypes { for x := f.XType(); x.Inner() != nil; x = x.Inner() { - if x.PackageOrDecorator().Key() == t.KeyPtr { + if x.Decorator().Key() == t.KeyPtr { // TODO: implement nptr (nullable pointer) types. return fmt.Errorf("check: ptr type %q not allowed for field %q; use nptr instead", x.String(c.tm), f.Name().String(c.tm)) @@ -209,7 +209,7 @@ func (c *Checker) checkFields(fields []*a.Node, banPtrTypes bool) error { } } if dv := f.DefaultValue(); dv != nil { - if f.XType().PackageOrDecorator() != 0 { + if f.XType().Decorator() != 0 { return fmt.Errorf("check: cannot set default value for qualified type %q for field %q", f.XType().String(c.tm), f.Name().String(c.tm)) } diff --git a/lang/check/type.go b/lang/check/type.go index da1f981f..303981d5 100644 --- a/lang/check/type.go +++ b/lang/check/type.go @@ -358,7 +358,7 @@ func (q *checker) tcheckExprOther(n *a.Expr, depth uint32) error { return err } lTyp := lhs.MType() - if lTyp.PackageOrDecorator().Key() != t.KeyOpenBracket { + if lTyp.Decorator().Key() != t.KeyOpenBracket { return fmt.Errorf("%s is an array-index expression but %s has type %s, not an array type", n.String(q.tm), lhs.String(q.tm), lTyp.String(q.tm)) } @@ -428,10 +428,10 @@ func (q *checker) tcheckDot(n *a.Expr, depth uint32) error { return err } lTyp := lhs.MType() - for ; lTyp.PackageOrDecorator().Key() == t.KeyPtr; lTyp = lTyp.Inner() { + for ; lTyp.Decorator().Key() == t.KeyPtr; lTyp = lTyp.Inner() { } - if lTyp.PackageOrDecorator() != 0 { + if lTyp.Decorator() != 0 { // TODO. return fmt.Errorf("check: unsupported package-or-decorator for tcheckDot") } @@ -658,7 +658,7 @@ func (q *checker) tcheckTypeExpr(n *a.TypeExpr, depth uint32) error { } depth++ - switch n.PackageOrDecorator().Key() { + switch n.Decorator().Key() { case 0: if n.Name().IsNumType() { for _, b := range n.Bounds() {