return t
}
-func typ(et EType) *Type {
- t := new(Type)
- t.Etype = et
- t.Width = BADWIDTH
- t.Lineno = lineno
- t.Orig = t
- return t
-}
-
// methcmp sorts by symbol, then by package path for unexported symbols.
type methcmp []*Type
return false
}
-func shallow(t *Type) *Type {
- if t == nil {
- return nil
- }
- nt := typ(0)
- *nt = *t
- if t.Orig == t {
- nt.Orig = nt
- }
- return nt
-}
-
func deep(t *Type) *Type {
if t == nil {
return nil
nt = t // share from here down
case TANY:
- nt = shallow(t)
+ nt = t.Copy()
nt.Copyany = true
case TPTR32, TPTR64, TCHAN, TARRAY:
- nt = shallow(t)
+ nt = t.Copy()
nt.Type = deep(t.Type)
case TMAP:
- nt = shallow(t)
+ nt = t.Copy()
nt.Down = deep(t.Down)
nt.Type = deep(t.Type)
case TFUNC:
- nt = shallow(t)
+ nt = t.Copy()
*nt.RecvP() = deep(t.Recv())
*nt.ResultsP() = deep(t.Results())
*nt.ParamsP() = deep(t.Params())
case TSTRUCT:
- nt = shallow(t)
- nt.Type = shallow(t.Type)
+ nt = t.Copy()
+ nt.Type = t.Type.Copy()
xt := nt.Type
for t = t.Type; t != nil; t = t.Down {
xt.Type = deep(t.Type)
- xt.Down = shallow(t.Down)
+ xt.Down = t.Down.Copy()
xt = xt.Down
}
}
for sl := slist; sl != nil; sl = sl.link {
if sl.good {
// add it to the base type method list
- f = typ(TFIELD)
-
- *f = *sl.field
+ f := sl.field.Copy()
f.Embedded = 1 // needs a trampoline
if sl.followptr {
f.Embedded = 2
Lastfn *Node // for usefield
}
+// typ returns a new Type of the specified kind.
+func typ(et EType) *Type {
+ t := &Type{
+ Etype: et,
+ Width: BADWIDTH,
+ Lineno: lineno,
+ }
+ t.Orig = t
+ return t
+}
+
+// Copy returns a shallow copy of the Type.
+func (t *Type) Copy() *Type {
+ if t == nil {
+ return nil
+ }
+ nt := new(Type)
+ *nt = *t
+ // TODO(mdempsky): Find out why this is necessary and explain.
+ if t.Orig == t {
+ nt.Orig = nt
+ }
+ return nt
+}
+
// Iter provides an abstraction for iterating across struct fields and
// interface methods.
type Iter struct {
typecheck(&nt, Etype)
if nt.Type == nil {
// type check failed; leave empty func
+ // TODO(mdempsky): Fix Type rekinding.
n.Type.Etype = TFUNC
-
n.Type.Nod = nil
return
}
}
}
+ // TODO(mdempsky): Fix Type rekinding.
*n.Type = *nt.Type
n.Type.Nod = nil
checkwidth(n.Type)
maplineno := int(n.Type.Maplineno)
embedlineno := int(n.Type.Embedlineno)
-
l := n.Type.Copyto
+
+ // TODO(mdempsky): Fix Type rekinding.
*n.Type = *t
t = n.Type