当前位置: 首页>>代码示例>>Golang>>正文


Golang types.Tuple类代码示例

本文整理汇总了Golang中code/google/com/p/go/tools/go/types.Tuple的典型用法代码示例。如果您正苦于以下问题:Golang Tuple类的具体用法?Golang Tuple怎么用?Golang Tuple使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Tuple类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: ReturnStmt

func (cdd *CDD) ReturnStmt(w *bytes.Buffer, s *ast.ReturnStmt, resultT string, tup *types.Tuple) (end bool) {
	switch len(s.Results) {
	case 0:
		if resultT == "void" {
			w.WriteString("return;\n")
		} else {
			w.WriteString("goto end;\n")
			end = true
		}

	case 1:
		w.WriteString("return ")
		cdd.Expr(w, s.Results[0], tup.At(0).Type())
		w.WriteString(";\n")

	default:
		w.WriteString("return (" + resultT + "){")
		for i, e := range s.Results {
			if i > 0 {
				w.WriteString(", ")
			}
			cdd.Expr(w, e, tup.At(i).Type())
		}
		w.WriteString("};\n")
	}
	return
}
开发者ID:rjammala,项目名称:emgo,代码行数:27,代码来源:stmt.go

示例2: tuple

func (p *exporter) tuple(t *types.Tuple) {
	n := t.Len()
	p.int(n)
	for i := 0; i < n; i++ {
		p.param(t.At(i))
	}
}
开发者ID:hackrole,项目名称:daily-program,代码行数:7,代码来源:export.go

示例3: typeArray

func (c *funcContext) typeArray(t *types.Tuple) string {
	s := make([]string, t.Len())
	for i := range s {
		s[i] = c.typeName(t.At(i).Type())
	}
	return "[" + strings.Join(s, ", ") + "]"
}
开发者ID:hajimehoshi,项目名称:gopherjs,代码行数:7,代码来源:utils.go

示例4: rtypeSlice

func (tm *TypeMap) rtypeSlice(t *types.Tuple) llvm.Value {
	rtypes := make([]llvm.Value, t.Len())
	for i := range rtypes {
		rtypes[i] = tm.ToRuntime(t.At(i).Type())
	}
	slicetyp := tm.runtime.funcType.llvm.StructElementTypes()[2]
	return tm.makeSlice(rtypes, slicetyp)
}
开发者ID:minux,项目名称:llgo,代码行数:8,代码来源:typemap.go

示例5: hashTuple

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
}
开发者ID:Karthikvb,项目名称:15640_projects,代码行数:9,代码来源:map.go

示例6: writeParams

func (w *Walker) writeParams(buf *bytes.Buffer, t *types.Tuple, variadic bool) {
	buf.WriteByte('(')
	for i, n := 0, t.Len(); i < n; i++ {
		if i > 0 {
			buf.WriteString(", ")
		}
		typ := t.At(i).Type()
		if variadic && i+1 == n {
			buf.WriteString("...")
			typ = typ.(*types.Slice).Elem()
		}
		w.writeType(buf, typ)
	}
	buf.WriteByte(')')
}
开发者ID:bryanxu,项目名称:go-zh,代码行数:15,代码来源:goapi.go

示例7: checkTypes

func checkTypes(args *types.Tuple, types []string) (any, all bool) {
	matched := make([]bool, len(types))
	for i := 0; i < args.Len(); i++ {
		for k, toCheck := range types {
			if args.At(i).Type().String() == toCheck {
				matched[k] = true
				any = true
			}
		}
	}

	for _, b := range matched {
		if !b {
			return any, false
		}
	}

	return any, true
}
开发者ID:kisielk,项目名称:uses,代码行数:19,代码来源:main.go

示例8: writeTuple

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(")")
}
开发者ID:Karthikvb,项目名称:15640_projects,代码行数:20,代码来源:writetype.go

示例9: results

func (cdd *CDD) results(tup *types.Tuple) (res results) {
	if tup == nil {
		res.typ = "void"
		return
	}

	n := tup.Len()

	res.names = make([]string, n)
	for i := 0; i < n; i++ {
		name := tup.At(i).Name()
		switch name {
		case "":
			name = "_" + strconv.Itoa(n)

		case "_":
			res.hasNames = true

		default:
			name += "$"
			res.hasNames = true
		}
		res.names[i] = name
	}
	if n > 1 {
		res.typ, res.fields, res.acds = cdd.tupleName(tup)
		return
	}
	v := tup.At(0)
	field0 := types.NewField(v.Pos(), v.Pkg(), "_0", v.Type(), false)
	res.fields = []*types.Var{field0}
	res.typ, res.dim, res.acds = cdd.TypeStr(v.Type())
	return
}
开发者ID:rjammala,项目名称:emgo,代码行数:34,代码来源:type.go

示例10: argsToString

func argsToString(args *types.Tuple) string {
	ret := make([]string, args.Len())
	for i := 0; i < args.Len(); i++ {
		name := noDot(args.At(i).Name())
		typ := args.At(i).Type().String()

		if len(name) == 0 {
			ret[i] = typ
		} else {
			ret[i] = name + " " + typ
		}
	}

	return strings.Join(ret, ", ")
}
开发者ID:kisielk,项目名称:uses,代码行数:15,代码来源:main.go

示例11: writeParams

func (ts *TypeStringer) writeParams(buf *bytes.Buffer, params *types.Tuple, isVariadic bool) {
	buf.WriteByte('(')
	for i := 0; i < int(params.Len()); i++ {
		par := params.At(i)
		if i > 0 {
			buf.WriteString(", ")
		}
		if isVariadic && i == int(params.Len()-1) {
			buf.WriteString("...")
		}
		ts.writeType(buf, par.Type())
	}
	buf.WriteByte(')')
}
开发者ID:hzmangel,项目名称:llgo,代码行数:14,代码来源:types.go

示例12: makeParameters

func (e *exporter) makeParameters(tuple *types.Tuple, variadic bool) string {
	params := make([]string, tuple.Len())
	for i := range params {
		param := tuple.At(i)
		paramType := param.Type()
		dots := ""
		if variadic && i == tuple.Len()-1 {
			dots = "..."
			paramType = paramType.(*types.Slice).Elem()
		}
		params[i] = e.makeName(param) + " " + dots + e.makeType(paramType)
	}
	return strings.Join(params, ", ")
}
开发者ID:kpsmith,项目名称:gopherjs,代码行数:14,代码来源:gcexporter.go

示例13: tupleName

func (cdd *CDD) tupleName(tup *types.Tuple) (tupName string, fields []*types.Var, acds []*CDD) {
	n := tup.Len()
	for i := 0; i < n; i++ {
		if i != 0 {
			tupName += "$$"
		}
		name, dim, a := cdd.TypeStr(tup.At(i).Type())
		tupName += dimFuncPtr(name, dim)
		acds = append(acds, a...)

	}
	tupName = strings.Map(symToDol, tupName)

	fields = make([]*types.Var, n)
	for i := 0; i < n; i++ {
		v := tup.At(i)
		fields[i] = types.NewField(
			v.Pos(), v.Pkg(), "_"+strconv.Itoa(i), v.Type(), false,
		)
	}

	if _, ok := cdd.gtc.tupNames[tupName]; ok {
		return
	}

	cdd.gtc.tupNames[tupName] = struct{}{}

	s := types.NewStruct(fields, nil)
	o := types.NewTypeName(tup.At(0).Pos(), cdd.gtc.pkg, tupName, s)
	acd := cdd.gtc.newCDD(o, TypeDecl, 0)
	acd.structDecl(new(bytes.Buffer), tupName, s)
	cdd.DeclUses[o] = true
	acds = append(acds, acd)

	return
}
开发者ID:rjammala,项目名称:emgo,代码行数:36,代码来源:type.go

示例14: Stmt

func (cdd *CDD) Stmt(w *bytes.Buffer, stmt ast.Stmt, label, resultT string, tup *types.Tuple) (end bool, acds []*CDD) {
	updateEA := func(e bool, a []*CDD) {
		if e {
			end = true
		}
		acds = append(acds, a...)
	}

	cdd.Complexity++

	switch s := stmt.(type) {
	case *ast.DeclStmt:
		cdds := cdd.gtc.Decl(s.Decl, cdd.il)
		for _, c := range cdds {
			for u, typPtr := range c.FuncBodyUses {
				cdd.FuncBodyUses[u] = typPtr
			}
			w.Write(c.Decl)
		}
		for _, c := range cdds {
			w.Write(c.Def)
		}

	case *ast.AssignStmt:
		rhs := make([]string, len(s.Lhs))
		typ := make([]types.Type, len(s.Lhs))

		rhsIsTuple := len(s.Lhs) > 1 && len(s.Rhs) == 1

		if rhsIsTuple {
			tup := cdd.exprType(s.Rhs[0]).(*types.Tuple)
			tupName, _, a := cdd.tupleName(tup)
			acds = append(acds, a...)
			w.WriteString(tupName)
			tupName = "tmp" + cdd.gtc.uniqueId()
			w.WriteString(" " + tupName + " = ")
			cdd.Expr(w, s.Rhs[0], nil)
			w.WriteString(";\n")
			cdd.indent(w)
			for i, n := 0, tup.Len(); i < n; i++ {
				rhs[i] = tupName + "._" + strconv.Itoa(i)
				if s.Tok == token.DEFINE {
					typ[i] = tup.At(i).Type()
				}
			}
		} else {
			for i, e := range s.Rhs {
				var t types.Type
				if s.Tok == token.DEFINE {
					t = cdd.exprType(e)
				} else {
					t = cdd.exprType(s.Lhs[i])
				}
				rhs[i] = cdd.ExprStr(e, t)
				typ[i] = t
			}
		}

		lhs := make([]string, len(s.Lhs))

		if s.Tok == token.DEFINE {
			for i, e := range s.Lhs {
				name := cdd.NameStr(cdd.object(e.(*ast.Ident)), true)
				if name == "_$" {
					lhs[i] = "_"
				} else {
					t, dim, a := cdd.TypeStr(typ[i])
					acds = append(acds, a...)
					lhs[i] = t + " " + dimFuncPtr(name, dim)
				}
			}
		} else {
			for i, e := range s.Lhs {
				lhs[i] = cdd.ExprStr(e, nil)
			}
		}

		if len(s.Rhs) == len(s.Lhs) && len(s.Lhs) > 1 && s.Tok != token.DEFINE {
			for i, t := range typ {
				if i > 0 {
					cdd.indent(w)
				}
				if lhs[i] == "_" {
					w.WriteString("(void)(")
					w.WriteString(rhs[i])
					w.WriteString(");\n")
				} else {
					dim, a := cdd.Type(w, t)
					acds = append(acds, a...)
					tmp := "tmp" + cdd.gtc.uniqueId()
					w.WriteString(" " + dimFuncPtr(tmp, dim))
					w.WriteString(" = " + rhs[i] + ";\n")
					rhs[i] = tmp
				}
			}
			cdd.indent(w)
		}

		var atok string
		switch s.Tok {
//.........这里部分代码省略.........
开发者ID:rjammala,项目名称:emgo,代码行数:101,代码来源:stmt.go

示例15: buildFunction

// buildFunction takes a function Value, a list of parameters, and a body,
// and generates code for the function.
func (c *compiler) buildFunction(f *LLVMValue, context, params, results *types.Tuple, body *ast.BlockStmt) {
	if currblock := c.builder.GetInsertBlock(); !currblock.IsNil() {
		defer c.builder.SetInsertPointAtEnd(currblock)
	}
	llvm_fn := llvm.ConstExtractValue(f.LLVMValue(), []uint32{0})
	entry := llvm.AddBasicBlock(llvm_fn, "entry")
	c.builder.SetInsertPointAtEnd(entry)

	// For closures, context is the captured context values.
	var paramoffset int
	if context != nil {
		paramoffset++

		// Store the existing values. We're going to temporarily
		// replace the values with offsets into the context param.
		oldvalues := make([]*LLVMValue, context.Len())
		for i := range oldvalues {
			v := context.At(i)
			oldvalues[i] = c.objectdata[v].Value
		}
		defer func() {
			for i := range oldvalues {
				v := context.At(i)
				c.objectdata[v].Value = oldvalues[i]
			}
		}()

		// The context parameter is a pointer to a struct
		// whose elements are pointers to captured values.
		arg0 := llvm_fn.Param(0)
		for i := range oldvalues {
			v := context.At(i)
			argptr := c.builder.CreateStructGEP(arg0, i, "")
			argptr = c.builder.CreateLoad(argptr, "")
			ptrtyp := oldvalues[i].pointer.Type()
			newvalue := c.NewValue(argptr, ptrtyp)
			c.objectdata[v].Value = newvalue.makePointee()
		}
	}

	// Bind receiver, arguments and return values to their
	// identifiers/objects. We'll store each parameter on the stack so
	// they're addressable.
	nparams := int(params.Len())
	for i := 0; i < nparams; i++ {
		v := params.At(i)
		name := v.Name()
		if !isBlank(name) {
			value := llvm_fn.Param(i + paramoffset)
			c.newArgStackVar(i+1, f, v, value, name)
		}
	}

	funcstate := &function{LLVMValue: f, results: results}
	c.functions.push(funcstate)
	hasdefer := hasDefer(funcstate, body)

	// Allocate space on the stack for named results.
	for i := 0; i < results.Len(); i++ {
		v := results.At(i)
		name := v.Name()
		allocstack := !isBlank(name)
		if !allocstack && hasdefer {
			c.objectdata[v] = &ObjectData{}
			allocstack = true
		}
		if allocstack {
			typ := v.Type()
			llvmtyp := c.types.ToLLVM(typ)
			c.newStackVar(f, v, llvm.ConstNull(llvmtyp), name)
		}
	}

	// Create the function body.
	if hasdefer {
		c.makeDeferBlock(funcstate, body)
	}
	c.VisitBlockStmt(body, false)
	c.functions.pop()

	c.setDebugLine(body.End())

	// If the last instruction in the function is not a terminator, then
	// we either have unreachable code or a missing optional return statement
	// (the latter case is allowable only for functions without results).
	//
	// Use GetInsertBlock rather than LastBasicBlock, since the
	// last basic block might actually be a "defer" block.
	last := c.builder.GetInsertBlock()
	if in := last.LastInstruction(); in.IsNil() || in.IsATerminatorInst().IsNil() {
		c.builder.SetInsertPointAtEnd(last)
		if results.Len() == 0 {
			if funcstate.deferblock.IsNil() {
				c.builder.CreateRetVoid()
			} else {
				c.builder.CreateBr(funcstate.deferblock)
			}
		} else {
//.........这里部分代码省略.........
开发者ID:qioixiy,项目名称:llgo,代码行数:101,代码来源:decl.go


注:本文中的code/google/com/p/go/tools/go/types.Tuple类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。