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


Golang types.Signature类代码示例

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


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

示例1: hasError

func hasError(sig *types.Signature) bool {
	res := sig.Results()
	if res == nil || res.Len() <= 0 {
		return false
	}

	nerr := 0
	for i := 0; i < res.Len(); i++ {
		ret := res.At(i)
		if isErrorType(ret.Type()) {
			nerr++
		}
	}

	switch {
	case nerr == 0:
		return false
	case nerr == 1:
		return true
	default:
		panic(fmt.Errorf(
			"gopy: invalid number of comma-errors (%d)",
			nerr,
		))
	}

	return false
}
开发者ID:ashrafulratul,项目名称:gopy,代码行数:28,代码来源:utils.go

示例2: FuncHasQuery

// FuncHasQuery returns the offset of the string parameter named "query", or
// none if no such parameter exists.
func FuncHasQuery(s *types.Signature) (offset int, ok bool) {
	params := s.Params()
	for i := 0; i < params.Len(); i++ {
		v := params.At(i)
		if v.Name() == "query" && v.Type() == stringType {
			return i, true
		}
	}
	return 0, false
}
开发者ID:johansglock,项目名称:safesql,代码行数:12,代码来源:safesql.go

示例3: formatIndex

// formatIndex returns the index of the format string parameter within
// a signature. If it cannot find any format string parameter, it
// returns -1.
func formatIndex(sig *types.Signature) int {
	if sig == nil {
		return -1
	}
	idx := -1
	for i := 0; i < sig.Params().Len(); i++ {
		p := sig.Params().At(i)
		if typ, ok := p.Type().(*types.Basic); ok && typ.Kind() == types.String {
			idx = i
		}
	}
	return idx
}
开发者ID:4ad,项目名称:go,代码行数:16,代码来源:print.go

示例4: writeSignature

// writeSignature writes to buf the signature sig in declaration syntax.
func writeSignature(buf *bytes.Buffer, from *types.Package, name string, sig *types.Signature, params []*Parameter) {
	buf.WriteString("func ")
	if recv := sig.Recv(); recv != nil {
		buf.WriteString("(")
		if n := params[0].Name(); n != "" {
			buf.WriteString(n)
			buf.WriteString(" ")
		}
		types.WriteType(buf, params[0].Type(), types.RelativeTo(from))
		buf.WriteString(") ")
	}
	buf.WriteString(name)
	types.WriteSignature(buf, sig, types.RelativeTo(from))
}
开发者ID:ChloeTigre,项目名称:golang-tools,代码行数:15,代码来源:func.go

示例5: signature

func (p *exporter) signature(sig *types.Signature) {
	// We need the receiver information (T vs *T)
	// for methods associated with named types.
	// We do not record interface receiver types in the
	// export data because 1) the importer can derive them
	// from the interface type and 2) they create cycles
	// in the type graph.
	if recv := sig.Recv(); recv != nil {
		if _, ok := recv.Type().Underlying().(*types.Interface); !ok {
			// 1-element tuple
			p.int(1)
			p.param(recv)
		} else {
			// 0-element tuple
			p.int(0)
		}
	} else {
		// 0-element tuple
		p.int(0)
	}
	p.tuple(sig.Params())
	p.tuple(sig.Results())
	if sig.Variadic() {
		p.int(1)
	} else {
		p.int(0)
	}
}
开发者ID:julesGoullee,项目名称:gopherjs,代码行数:28,代码来源:export.go

示例6: isImplementable

func isImplementable(sig *types.Signature) bool {
	params := sig.Params()
	for i := 0; i < params.Len(); i++ {
		if !isExported(params.At(i).Type()) {
			return false
		}
	}
	res := sig.Results()
	for i := 0; i < res.Len(); i++ {
		if !isExported(res.At(i).Type()) {
			return false
		}
	}
	return true
}
开发者ID:pankona,项目名称:mobile,代码行数:15,代码来源:types.go

示例7: translateCall

func (c *funcContext) translateCall(e *ast.CallExpr, sig *types.Signature, fun *expression) *expression {
	args := c.translateArgs(sig, e.Args, e.Ellipsis.IsValid(), false)
	if c.Blocking[e] {
		resumeCase := c.caseCounter
		c.caseCounter++
		returnVar := "$r"
		if sig.Results().Len() != 0 {
			returnVar = c.newVariable("_r")
		}
		c.Printf("%[1]s = %[2]s(%[3]s); /* */ $s = %[4]d; case %[4]d: if($c) { $c = false; %[1]s = %[1]s.$blk(); } if (%[1]s && %[1]s.$blk !== undefined) { break s; }", returnVar, fun, strings.Join(args, ", "), resumeCase)
		if sig.Results().Len() != 0 {
			return c.formatExpr("%s", returnVar)
		}
		return c.formatExpr("")
	}
	return c.formatExpr("%s(%s)", fun, strings.Join(args, ", "))
}
开发者ID:camlistore,项目名称:camlistore,代码行数:17,代码来源:expressions.go

示例8: translateArgs

func (c *funcContext) translateArgs(sig *types.Signature, argExprs []ast.Expr, ellipsis, clone bool) []string {
	if len(argExprs) == 1 {
		if tuple, isTuple := c.p.TypeOf(argExprs[0]).(*types.Tuple); isTuple {
			tupleVar := c.newVariable("_tuple")
			c.Printf("%s = %s;", tupleVar, c.translateExpr(argExprs[0]))
			argExprs = make([]ast.Expr, tuple.Len())
			for i := range argExprs {
				argExprs[i] = c.newIdent(c.formatExpr("%s[%d]", tupleVar, i).String(), tuple.At(i).Type())
			}
		}
	}

	paramsLen := sig.Params().Len()

	var varargType *types.Slice
	if sig.Variadic() && !ellipsis {
		varargType = sig.Params().At(paramsLen - 1).Type().(*types.Slice)
	}

	preserveOrder := false
	for i := 1; i < len(argExprs); i++ {
		preserveOrder = preserveOrder || c.Blocking[argExprs[i]]
	}

	args := make([]string, len(argExprs))
	for i, argExpr := range argExprs {
		var argType types.Type
		switch {
		case varargType != nil && i >= paramsLen-1:
			argType = varargType.Elem()
		default:
			argType = sig.Params().At(i).Type()
		}

		var arg string
		switch {
		case clone:
			arg = c.translateImplicitConversionWithCloning(argExpr, argType).String()
		default:
			arg = c.translateImplicitConversion(argExpr, argType).String()
		}

		if preserveOrder && c.p.Types[argExpr].Value == nil {
			argVar := c.newVariable("_arg")
			c.Printf("%s = %s;", argVar, arg)
			arg = argVar
		}

		args[i] = arg
	}

	if varargType != nil {
		return append(args[:paramsLen-1], fmt.Sprintf("new %s([%s])", c.typeName(varargType), strings.Join(args[paramsLen-1:], ", ")))
	}
	return args
}
开发者ID:snyderep,项目名称:pongish,代码行数:56,代码来源:utils.go

示例9: newFuncFrom

func newFuncFrom(p *Package, parent string, obj types.Object, sig *types.Signature) (Func, error) {
	haserr := false
	res := sig.Results()
	var ret types.Type

	switch res.Len() {
	case 2:
		if !isErrorType(res.At(1).Type()) {
			return Func{}, fmt.Errorf(
				"bind: second result value must be of type error: %s",
				obj,
			)
		}
		haserr = true
		ret = res.At(0).Type()

	case 1:
		if isErrorType(res.At(0).Type()) {
			haserr = true
			ret = nil
		} else {
			ret = res.At(0).Type()
		}
	case 0:
		ret = nil
	default:
		return Func{}, fmt.Errorf("bind: too many results to return: %v", obj)
	}

	id := obj.Pkg().Name() + "_" + obj.Name()
	if parent != "" {
		id = obj.Pkg().Name() + "_" + parent + "_" + obj.Name()
	}

	return Func{
		pkg:  p,
		sig:  newSignatureFrom(p, sig),
		typ:  obj.Type(),
		name: obj.Name(),
		id:   id,
		doc:  p.getDoc(parent, obj),
		ret:  ret,
		err:  haserr,
	}, nil
}
开发者ID:ashrafulratul,项目名称:gopy,代码行数:45,代码来源:package.go

示例10: newSignatureFrom

func newSignatureFrom(pkg *Package, sig *types.Signature) *Signature {
	var recv *Var
	if sig.Recv() != nil {
		recv = newVarFrom(pkg, sig.Recv())
	}

	return &Signature{
		ret:  newVarsFrom(pkg, sig.Results()),
		args: newVarsFrom(pkg, sig.Params()),
		recv: recv,
	}
}
开发者ID:ashrafulratul,项目名称:gopy,代码行数:12,代码来源:package.go

示例11: convertSignature

func (c *converter) convertSignature(v *gotypes.Signature) *types.Signature {
	if v == nil {
		return nil
	}
	if v, ok := c.converted[v]; ok {
		return v.(*types.Signature)
	}
	ret := types.NewSignature(
		c.convertParamVar(v.Recv()),
		c.convertTuple(v.Params(), c.convertParamVar),
		c.convertTuple(v.Results(), c.convertParamVar),
		v.Variadic(),
	)
	c.converted[v] = ret
	return ret
}
开发者ID:tcard,项目名称:sgo,代码行数:16,代码来源:importer.go

示例12: writeSignature

func (w *Walker) writeSignature(buf *bytes.Buffer, sig *types.Signature) {
	w.writeParams(buf, sig.Params(), sig.Variadic())
	switch res := sig.Results(); res.Len() {
	case 0:
		// nothing to do
	case 1:
		buf.WriteByte(' ')
		w.writeType(buf, res.At(0).Type())
	default:
		buf.WriteByte(' ')
		w.writeParams(buf, res, false)
	}
}
开发者ID:pombredanne,项目名称:goapi,代码行数:13,代码来源:goapi.go

示例13: sigParamsCompatible

// sigParamsCompatible determines if the parameter parts of two signatures of functions are compatible.
// They are compatible if:
// - The number of parameters equal and the types of parameters are compatible for each of them.
// - The latter parameters have exactly one extra parameter which is a variadic parameter.
func sigParamsCompatible(s1, s2 *types.Signature) bool {
	extra := tuplesCompatibleExtra(s1.Params(), s2.Params(), cmpLower)

	switch {
	case extra == nil:
		// s2 params is incompatible with s1 params
		return false

	case len(extra) == 0:
		// s2 params is compatible with s1 params
		return true

	case len(extra) == 1:
		// s2 params is compatible with s1 params with an extra variadic arg
		if s1.Variadic() == false && s2.Variadic() == true {
			return true
		}
	}

	return false
}
开发者ID:motemen,项目名称:gompatible,代码行数:25,代码来源:func.go

示例14: sigResultsCompatible

func sigResultsCompatible(s1, s2 *types.Signature) bool {
	if s1.Results().Len() == 0 {
		return true
	}

	extra := tuplesCompatibleExtra(s1.Results(), s2.Results(), cmpUpper)

	switch {
	case extra == nil:
		return false
	case len(extra) == 0:
		return true
	}

	return false
}
开发者ID:motemen,项目名称:gompatible,代码行数:16,代码来源:func.go

示例15: writeSignatureInternal

func (p *printer) writeSignatureInternal(this *types.Package, sig *types.Signature, visited []types.Type) {
	p.writeTuple(this, sig.Params(), sig.Variadic(), visited)

	res := sig.Results()
	n := res.Len()
	if n == 0 {
		// no result
		return
	}

	p.print(" ")
	if n == 1 && res.At(0).Name() == "" {
		// single unnamed result
		p.writeTypeInternal(this, res.At(0).Type(), visited)
		return
	}

	// multiple or named result(s)
	p.writeTuple(this, res, false, visited)
}
开发者ID:ChloeTigre,项目名称:golang-tools,代码行数:20,代码来源:writetype.go


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