mirror of
https://github.com/golang/go
synced 2024-11-19 03:24:40 -07:00
cmd/compile: add typWrapper and Type.Wrapped
Passes toolstash -cmp. Change-Id: I7dffd9bc5bab323590df6fb591bf1e73edf2e465 Reviewed-on: https://go-review.googlesource.com/21305 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
parent
09c672d50a
commit
e3c7497327
@ -198,14 +198,12 @@ func dowidth(t *Type) {
|
|||||||
|
|
||||||
// make fake type to check later to
|
// make fake type to check later to
|
||||||
// trigger channel argument check.
|
// trigger channel argument check.
|
||||||
t1 := typ(TCHANARGS)
|
t1 := typWrapper(TCHANARGS, t)
|
||||||
|
|
||||||
t1.Type = t
|
|
||||||
checkwidth(t1)
|
checkwidth(t1)
|
||||||
|
|
||||||
case TCHANARGS:
|
case TCHANARGS:
|
||||||
t1 := t.Type
|
t1 := t.Wrapped()
|
||||||
dowidth(t.Type) // just in case
|
dowidth(t1) // just in case
|
||||||
if t1.Type.Width >= 1<<16 {
|
if t1.Type.Width >= 1<<16 {
|
||||||
Yyerror("channel element type too large (>64kB)")
|
Yyerror("channel element type too large (>64kB)")
|
||||||
}
|
}
|
||||||
@ -273,22 +271,17 @@ func dowidth(t *Type) {
|
|||||||
// make fake type to check later to
|
// make fake type to check later to
|
||||||
// trigger function argument computation.
|
// trigger function argument computation.
|
||||||
case TFUNC:
|
case TFUNC:
|
||||||
t1 := typ(TFUNCARGS)
|
t1 := typWrapper(TFUNCARGS, t)
|
||||||
|
|
||||||
t1.Type = t
|
|
||||||
checkwidth(t1)
|
checkwidth(t1)
|
||||||
|
w = int64(Widthptr) // width of func type is pointer
|
||||||
// width of func type is pointer
|
|
||||||
w = int64(Widthptr)
|
|
||||||
|
|
||||||
// function is 3 cated structures;
|
// function is 3 cated structures;
|
||||||
// compute their widths as side-effect.
|
// compute their widths as side-effect.
|
||||||
case TFUNCARGS:
|
case TFUNCARGS:
|
||||||
t1 := t.Type
|
t1 := t.Wrapped()
|
||||||
|
w = widstruct(t1, t1.Recvs(), 0, 0)
|
||||||
w = widstruct(t.Type, t1.Recvs(), 0, 0)
|
w = widstruct(t1, t1.Params(), w, Widthreg)
|
||||||
w = widstruct(t.Type, t1.Params(), w, Widthreg)
|
w = widstruct(t1, t1.Results(), w, Widthreg)
|
||||||
w = widstruct(t.Type, t1.Results(), w, Widthreg)
|
|
||||||
t1.Argwid = w
|
t1.Argwid = w
|
||||||
if w%int64(Widthreg) != 0 {
|
if w%int64(Widthreg) != 0 {
|
||||||
Warn("bad type %v %d\n", t1, w)
|
Warn("bad type %v %d\n", t1, w)
|
||||||
|
@ -517,7 +517,7 @@ func (p *exporter) typ(t *Type) {
|
|||||||
case TDDDFIELD:
|
case TDDDFIELD:
|
||||||
// see p.param use of TDDDFIELD
|
// see p.param use of TDDDFIELD
|
||||||
p.tag(dddTag)
|
p.tag(dddTag)
|
||||||
p.typ(t.Type)
|
p.typ(t.Wrapped())
|
||||||
|
|
||||||
case TSTRUCT:
|
case TSTRUCT:
|
||||||
p.tag(structTag)
|
p.tag(structTag)
|
||||||
@ -666,7 +666,7 @@ func (p *exporter) param(q *Field, n int, numbered bool) {
|
|||||||
t := q.Type
|
t := q.Type
|
||||||
if q.Isddd {
|
if q.Isddd {
|
||||||
// create a fake type to encode ... just for the p.typ call
|
// create a fake type to encode ... just for the p.typ call
|
||||||
t = &Type{Etype: TDDDFIELD, Type: t.Type}
|
t = typWrapper(TDDDFIELD, t.Type)
|
||||||
}
|
}
|
||||||
p.typ(t)
|
p.typ(t)
|
||||||
if n > 0 {
|
if n > 0 {
|
||||||
|
@ -267,6 +267,18 @@ func typeChan(elem *Type, dir uint8) *Type {
|
|||||||
return t
|
return t
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// typWrapper returns a new wrapper psuedo-type.
|
||||||
|
func typWrapper(et EType, wrapped *Type) *Type {
|
||||||
|
switch et {
|
||||||
|
case TCHANARGS, TFUNCARGS, TDDDFIELD:
|
||||||
|
default:
|
||||||
|
Fatalf("typWrapper bad etype %s", et)
|
||||||
|
}
|
||||||
|
t := typ(et)
|
||||||
|
t.Type = wrapped
|
||||||
|
return t
|
||||||
|
}
|
||||||
|
|
||||||
func newField() *Field {
|
func newField() *Field {
|
||||||
return &Field{
|
return &Field{
|
||||||
Offset: BADWIDTH,
|
Offset: BADWIDTH,
|
||||||
@ -474,6 +486,16 @@ func (t *Type) Val() *Type {
|
|||||||
return t.Type
|
return t.Type
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Wrapped returns the type that pseudo-type t wraps.
|
||||||
|
func (t *Type) Wrapped() *Type {
|
||||||
|
switch t.Etype {
|
||||||
|
case TCHANARGS, TFUNCARGS, TDDDFIELD:
|
||||||
|
default:
|
||||||
|
Fatalf("Type.Wrapped %s", t.Etype)
|
||||||
|
}
|
||||||
|
return t.Type
|
||||||
|
}
|
||||||
|
|
||||||
func (t *Type) Methods() *Fields {
|
func (t *Type) Methods() *Fields {
|
||||||
// TODO(mdempsky): Validate t?
|
// TODO(mdempsky): Validate t?
|
||||||
return &t.methods
|
return &t.methods
|
||||||
|
Loading…
Reference in New Issue
Block a user