mirror of
https://github.com/golang/go
synced 2024-11-19 01:04: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
|
||||
// trigger channel argument check.
|
||||
t1 := typ(TCHANARGS)
|
||||
|
||||
t1.Type = t
|
||||
t1 := typWrapper(TCHANARGS, t)
|
||||
checkwidth(t1)
|
||||
|
||||
case TCHANARGS:
|
||||
t1 := t.Type
|
||||
dowidth(t.Type) // just in case
|
||||
t1 := t.Wrapped()
|
||||
dowidth(t1) // just in case
|
||||
if t1.Type.Width >= 1<<16 {
|
||||
Yyerror("channel element type too large (>64kB)")
|
||||
}
|
||||
@ -273,22 +271,17 @@ func dowidth(t *Type) {
|
||||
// make fake type to check later to
|
||||
// trigger function argument computation.
|
||||
case TFUNC:
|
||||
t1 := typ(TFUNCARGS)
|
||||
|
||||
t1.Type = t
|
||||
t1 := typWrapper(TFUNCARGS, t)
|
||||
checkwidth(t1)
|
||||
|
||||
// width of func type is pointer
|
||||
w = int64(Widthptr)
|
||||
w = int64(Widthptr) // width of func type is pointer
|
||||
|
||||
// function is 3 cated structures;
|
||||
// compute their widths as side-effect.
|
||||
case TFUNCARGS:
|
||||
t1 := t.Type
|
||||
|
||||
w = widstruct(t.Type, t1.Recvs(), 0, 0)
|
||||
w = widstruct(t.Type, t1.Params(), w, Widthreg)
|
||||
w = widstruct(t.Type, t1.Results(), w, Widthreg)
|
||||
t1 := t.Wrapped()
|
||||
w = widstruct(t1, t1.Recvs(), 0, 0)
|
||||
w = widstruct(t1, t1.Params(), w, Widthreg)
|
||||
w = widstruct(t1, t1.Results(), w, Widthreg)
|
||||
t1.Argwid = w
|
||||
if w%int64(Widthreg) != 0 {
|
||||
Warn("bad type %v %d\n", t1, w)
|
||||
|
@ -517,7 +517,7 @@ func (p *exporter) typ(t *Type) {
|
||||
case TDDDFIELD:
|
||||
// see p.param use of TDDDFIELD
|
||||
p.tag(dddTag)
|
||||
p.typ(t.Type)
|
||||
p.typ(t.Wrapped())
|
||||
|
||||
case TSTRUCT:
|
||||
p.tag(structTag)
|
||||
@ -666,7 +666,7 @@ func (p *exporter) param(q *Field, n int, numbered bool) {
|
||||
t := q.Type
|
||||
if q.Isddd {
|
||||
// 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)
|
||||
if n > 0 {
|
||||
|
@ -267,6 +267,18 @@ func typeChan(elem *Type, dir uint8) *Type {
|
||||
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 {
|
||||
return &Field{
|
||||
Offset: BADWIDTH,
|
||||
@ -474,6 +486,16 @@ func (t *Type) Val() *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 {
|
||||
// TODO(mdempsky): Validate t?
|
||||
return &t.methods
|
||||
|
Loading…
Reference in New Issue
Block a user