Rename PackageOrDecorator to Decorator.

This commit is contained in:
Nigel Tao committed 2017-06-10 10:55:51 +10:00
1 parent aed3aa9925
commit ebf3713555
6 files changed
+24 -24

No files matched your search

+4 -4
View File
@@ -546,7 +546,7 @@ func (g *gen) writeFuncImpl(n *a.Func) error {
badArg := false badArg := false
for _, o := range n.In().Fields() { for _, o := range n.In().Fields() {
o := o.Field() 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 // TODO: check for type refinements: u32[..4095] instead of
// u32. Also check for types, for array-typed arguments. // u32. Also check for types, for array-typed arguments.
continue continue
@@ -601,7 +601,7 @@ func (g *gen) writeField(n *a.Field, namePrefix string) error {
convertible, nPtr := true, 0 convertible, nPtr := true, 0
for x := n.XType(); x != nil; x = x.Inner() { 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 { if nPtr == maxNPtr {
return fmt.Errorf("cannot convert Puffs type %q to C: too many ptr's", n.XType().String(g.tm)) 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)) g.writes(n.Name().String(g.tm))
for x := n.XType(); x != nil; x = x.Inner() { for x := n.XType(); x != nil; x = x.Inner() {
if x.PackageOrDecorator() == t.IDOpenBracket { if x.Decorator() == t.IDOpenBracket {
g.writeb('[') g.writeb('[')
g.writes(x.ArrayLength().ConstValue().String()) g.writes(x.ArrayLength().ConstValue().String())
g.writeb(']') 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 { 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 k := n.Name().Key(); k < t.Key(len(cTypeNames)) {
if s := cTypeNames[k]; s != "" { if s := cTypeNames[k]; s != "" {
g.writes(s) g.writes(s)
+9 -9
View File
@@ -440,7 +440,7 @@ func NewJump(keyword t.ID, label t.ID) *Jump {
// MaxTypeExprDepth is an advisory limit for a TypeExpr's recursion depth. // MaxTypeExprDepth is an advisory limit for a TypeExpr's recursion depth.
const MaxTypeExprDepth = 63 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": // or "[8] T":
// - ID0: <0|package name|IDPtr|IDOpenBracket> // - ID0: <0|package name|IDPtr|IDOpenBracket>
// - ID1: <0|type name> // - ID1: <0|type name>
@@ -460,14 +460,14 @@ const MaxTypeExprDepth = 63
// TODO: function / method types. // TODO: function / method types.
type TypeExpr Node type TypeExpr Node
func (n *TypeExpr) Node() *Node { return (*Node)(n) } func (n *TypeExpr) Node() *Node { return (*Node)(n) }
func (n *TypeExpr) PackageOrDecorator() t.ID { return n.id0 } func (n *TypeExpr) Decorator() t.ID { return n.id0 }
func (n *TypeExpr) Name() t.ID { return n.id1 } func (n *TypeExpr) Name() t.ID { return n.id1 }
func (n *TypeExpr) ArrayLength() *Expr { return n.lhs.Expr() } 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) Bounds() [2]*Expr { return [2]*Expr{n.lhs.Expr(), n.mhs.Expr()} }
func (n *TypeExpr) Min() *Expr { return n.lhs.Expr() } func (n *TypeExpr) Min() *Expr { return n.lhs.Expr() }
func (n *TypeExpr) Max() *Expr { return n.mhs.Expr() } func (n *TypeExpr) Max() *Expr { return n.mhs.Expr() }
func (n *TypeExpr) Inner() *TypeExpr { return n.rhs.TypeExpr() } func (n *TypeExpr) Inner() *TypeExpr { return n.rhs.TypeExpr() }
func (n *TypeExpr) IsBool() bool { func (n *TypeExpr) IsBool() bool {
return n.id0 == 0 && n.id1.Key() == t.KeyBool && n.lhs == nil && n.mhs == nil && n.rhs == nil return n.id0 == 0 && n.id1.Key() == t.KeyBool && n.lhs == nil && n.mhs == nil && n.rhs == nil
+3 -3
View File
@@ -145,7 +145,7 @@ func (n *TypeExpr) String(tm *t.Map) string {
if n == nil { if n == nil {
return "" 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 tm.ByID(n.Name())
} }
return string(n.appendString(nil, tm, 0)) 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!"...) return append(buf, "!invalid_type!"...)
} }
switch n.PackageOrDecorator().Key() { switch n.Decorator().Key() {
case 0: case 0:
buf = append(buf, tm.ByID(n.Name())...) buf = append(buf, tm.ByID(n.Name())...)
case t.KeyPtr: case t.KeyPtr:
@@ -172,7 +172,7 @@ func (n *TypeExpr) appendString(buf []byte, tm *t.Map, depth uint32) []byte {
buf = append(buf, "] "...) buf = append(buf, "] "...)
return n.Inner().appendString(buf, tm, depth) return n.Inner().appendString(buf, tm, depth)
default: default:
buf = append(buf, tm.ByID(n.PackageOrDecorator())...) buf = append(buf, tm.ByID(n.Decorator())...)
buf = append(buf, '.') buf = append(buf, '.')
buf = append(buf, tm.ByID(n.Name())...) buf = append(buf, tm.ByID(n.Name())...)
} }
+2 -2
View File
@@ -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 { 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: case t.KeyPtr:
// TODO: handle. // TODO: handle.
return nil 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) { 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: case t.KeyPtr, t.KeyOpenBracket:
return nil, nil, nil return nil, nil, nil
} }
+2 -2
View File
@@ -201,7 +201,7 @@ func (c *Checker) checkFields(fields []*a.Node, banPtrTypes bool) error {
} }
if banPtrTypes { if banPtrTypes {
for x := f.XType(); x.Inner() != nil; x = x.Inner() { 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. // TODO: implement nptr (nullable pointer) types.
return fmt.Errorf("check: ptr type %q not allowed for field %q; use nptr instead", return fmt.Errorf("check: ptr type %q not allowed for field %q; use nptr instead",
x.String(c.tm), f.Name().String(c.tm)) 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 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", 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)) f.XType().String(c.tm), f.Name().String(c.tm))
} }
+4 -4
View File
@@ -358,7 +358,7 @@ func (q *checker) tcheckExprOther(n *a.Expr, depth uint32) error {
return err return err
} }
lTyp := lhs.MType() 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", 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)) 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 return err
} }
lTyp := lhs.MType() 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. // TODO.
return fmt.Errorf("check: unsupported package-or-decorator for tcheckDot") 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++ depth++
switch n.PackageOrDecorator().Key() { switch n.Decorator().Key() {
case 0: case 0:
if n.Name().IsNumType() { if n.Name().IsNumType() {
for _, b := range n.Bounds() { for _, b := range n.Bounds() {