// paramName replaces incompatible name with a p0-pN name. // Missing names, or existing names of the form p[0-9] are incompatible. // TODO(crawshaw): Replace invalid unicode names. func paramName(params *types.Tuple, pos int) string { name := params.At(pos).Name() if name == "" || name == "_" || paramRE.MatchString(name) { name = fmt.Sprintf("p%d", pos) } return name }
func newVars(tuple *types.Tuple) []*Var { vars := make([]*Var, 0, tuple.Len()) for i := 0; i < tuple.Len(); i++ { vars = append(vars, newVar(tuple.At(i))) } return vars }
func (p *exporter) tuple(t *types.Tuple) { n := t.Len() p.int(n) for i := 0; i < n; i++ { p.param(t.At(i)) } }
func (h Hasher) hashTuple(tuple *types.Tuple) uint32 { // See go/types.identicalTypes for rationale. n := tuple.Len() var hash uint32 = 9137 + 2*uint32(n) for i := 0; i < n; i++ { hash += 3 * h.Hash(tuple.At(i).Type()) } return hash }
func (sym *symtab) processTuple(tuple *types.Tuple) { if tuple == nil { return } for i := 0; i < tuple.Len(); i++ { ivar := tuple.At(i) ityp := ivar.Type() isym := sym.symtype(ityp) if isym == nil { sym.addType(ivar, ityp) } } }
func (g *goGen) tupleString(tuple *types.Tuple) string { n := tuple.Len() if n <= 0 { return "" } str := make([]string, 0, n) for i := 0; i < tuple.Len(); i++ { v := tuple.At(i) n := v.Name() typ := v.Type() str = append(str, n+" "+g.qualifiedType(typ)) } return strings.Join(str, ", ") }
func (p *printer) writeTuple(this *types.Package, tup *types.Tuple, variadic bool, visited []types.Type) { p.print("(") for i, n := 0, tup.Len(); i < n; i++ { if i > 0 { p.print(", ") } v := tup.At(i) if name := v.Name(); name != "" { p.print(name) p.print(" ") } typ := v.Type() if variadic && i == n-1 { p.print("...") typ = typ.(*types.Slice).Elem() } p.writeTypeInternal(this, typ, visited) } p.print(")") }
func (fr *frame) setupUnwindBlock(rec *ssa.BasicBlock, results *types.Tuple) { recoverbb := llvm.AddBasicBlock(fr.function, "") if rec != nil { fr.translateBlock(rec, recoverbb) } else if results.Len() == 0 || results.At(0).Anonymous() { // TODO(pcc): Remove this code after https://codereview.appspot.com/87210044/ lands fr.builder.SetInsertPointAtEnd(recoverbb) values := make([]llvm.Value, results.Len()) for i := range values { values[i] = llvm.ConstNull(fr.llvmtypes.ToLLVM(results.At(i).Type())) } fr.retInf.encode(llvm.GlobalContext(), fr.allocaBuilder, fr.builder, values) } else { fr.builder.SetInsertPointAtEnd(recoverbb) fr.builder.CreateUnreachable() } checkunwindbb := llvm.AddBasicBlock(fr.function, "") fr.builder.SetInsertPointAtEnd(checkunwindbb) exc := fr.createLandingPad(true) fr.runDefers() frame := fr.builder.CreateLoad(fr.frameptr, "") shouldresume := fr.builder.CreateIsNull(frame, "") resumebb := llvm.AddBasicBlock(fr.function, "") fr.builder.CreateCondBr(shouldresume, resumebb, recoverbb) fr.builder.SetInsertPointAtEnd(resumebb) fr.builder.CreateResume(exc) fr.builder.SetInsertPointAtEnd(fr.unwindBlock) fr.createLandingPad(false) fr.runtime.checkDefer.invoke(fr, checkunwindbb, fr.frameptr) fr.runDefers() fr.builder.CreateBr(recoverbb) }