// a type for struct/interface/arglist
func tostruct(l []*Node) *types.Type {
t := types.New(TSTRUCT)
- tostruct0(t, l)
- return t
-}
-
-func tostruct0(t *types.Type, l []*Node) {
- if t == nil || !t.IsStruct() {
- Fatalf("struct expected")
- }
fields := make([]*types.Field, len(l))
for i, n := range l {
if !t.Broke() {
checkwidth(t)
}
+
+ return t
}
func tofunargs(l []*Node, funarg types.Funarg) *types.Type {
return types.Types[TINTER]
}
t := types.New(TINTER)
- tointerface0(t, l)
- return t
-}
-
-func tointerface0(t *types.Type, l []*Node) {
- if t == nil || !t.IsInterface() {
- Fatalf("interface expected")
- }
-
var fields []*types.Field
for _, n := range l {
f := interfacefield(n)
fields = append(fields, f)
}
t.SetInterface(fields)
+ return t
}
func fakeRecv() *Node {
// turn a parsed function declaration into a type
func functype(this *Node, in, out []*Node) *types.Type {
t := types.New(TFUNC)
- functype0(t, this, in, out)
- return t
-}
-
-func functype0(t *types.Type, this *Node, in, out []*Node) {
- if t == nil || t.Etype != TFUNC {
- Fatalf("function type expected")
- }
var rcvr []*Node
if this != nil {
}
t.FuncType().Outnamed = t.NumResults() > 0 && origSym(t.Results().Field(0).Sym) != nil
+
+ return t
}
func functypefield(this *types.Field, in, out []*types.Field) *types.Type {
t := types.New(TFUNC)
- functypefield0(t, this, in, out)
- return t
-}
-func functypefield0(t *types.Type, this *types.Field, in, out []*types.Field) {
var rcvr []*types.Field
if this != nil {
rcvr = []*types.Field{this}
t.FuncType().Results = tofunargsfield(out, types.FunargResults)
t.FuncType().Outnamed = t.NumResults() > 0 && origSym(t.Results().Field(0).Sym) != nil
+
+ return t
}
// origSym returns the original symbol written by the user.