Beispiel #1
0
Datei: job.go Projekt: cznic/c
func (j *Job) signature(n cc.Node, t cc.Type) {
	ps, variadic := t.Parameters()
	j.body("(")
	names := false
	var groups [][]cc.Parameter
	var group []cc.Parameter
	var prevT cc.Type
	for i, p := range ps {
		if p.Name != 0 {
			names = true
		}
		if i == 0 {
			group = []cc.Parameter{p}
			prevT = p.Type
			continue
		}

		if !eqTypes(n, prevT, p.Type) {
			groups = append(groups, group)
			group = []cc.Parameter{p}
			prevT = p.Type
			continue
		}

		group = append(group, p)
	}
	if group != nil {
		groups = append(groups, group)
	}
	for _, g := range groups {
		switch {
		case names:
			for i, p := range g {
				j.body("%s", xc.Dict.S(mangleIdent(p.Name, false)))
				if i < len(g)-1 {
					j.body(", ")
				}
			}
			t := g[0].Type
			if t.Kind() == cc.Array {
				j.body("*")
			}
			j.typ(g[0].Declarator, t)
			j.body(", ")
		default:
			t := g[0].Type
			for range g {
				if t.Kind() == cc.Array {
					j.body("*")
				}
				j.typ(g[0].Declarator, t)
				j.body(", ")
			}
		}
	}
	if variadic {
		if names {
			j.body("args")
		}
		j.body("...interface{}")
	}
	j.body(")")
	if t := t.Result(); t.Kind() != cc.Void {
		if t.Kind() == cc.Array {
			j.body("*")
		}
		j.typ(n, t)
	}
}