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


Golang Type.MethodSet方法代码示例

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


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

示例1: lockPath

// lockPath returns a typePath describing the location of a lock value
// contained in typ. If there is no contained lock, it returns nil.
func lockPath(tpkg *types.Package, typ types.Type) typePath {
	if typ == nil {
		return nil
	}

	// We're only interested in the case in which the underlying
	// type is a struct. (Interfaces and pointers are safe to copy.)
	styp, ok := typ.Underlying().(*types.Struct)
	if !ok {
		return nil
	}

	// We're looking for cases in which a reference to this type
	// can be locked, but a value cannot. This differentiates
	// embedded interfaces from embedded values.
	if plock := types.NewPointer(typ).MethodSet().Lookup(tpkg, "Lock"); plock != nil {
		if lock := typ.MethodSet().Lookup(tpkg, "Lock"); lock == nil {
			return []types.Type{typ}
		}
	}

	nfields := styp.NumFields()
	for i := 0; i < nfields; i++ {
		ftyp := styp.Field(i).Type()
		subpath := lockPath(tpkg, ftyp)
		if subpath != nil {
			return append(subpath, typ)
		}
	}

	return nil
}
开发者ID:ufo22940268,项目名称:two-server-others,代码行数:34,代码来源:copylock.go

示例2: methodSet

func (visit *visitor) methodSet(typ types.Type) {
	mset := typ.MethodSet()
	for i, n := 0, mset.Len(); i < n; i++ {
		// Side-effect: creates all wrapper methods.
		visit.function(visit.prog.Method(mset.At(i)))
	}
}
开发者ID:nagyistge,项目名称:hm-workspace,代码行数:7,代码来源:visit.go

示例3: lookupMethod

// lookupMethod returns the method set for type typ, which may be one
// of the interpreter's fake types.
func lookupMethod(i *interpreter, typ types.Type, meth *types.Func) *ssa.Function {
	switch typ {
	case rtypeType:
		return i.rtypeMethods[meth.Id()]
	case errorType:
		return i.errorMethods[meth.Id()]
	}
	return i.prog.Method(typ.MethodSet().Lookup(meth.Pkg(), meth.Name()))
}
开发者ID:Bosh-for-Cpi,项目名称:bosh-2605,代码行数:11,代码来源:interp.go

示例4: hasMethod

// hasMethod reports whether the type contains a method with the given name.
// It is part of the workaround for Formatters and should be deleted when
// that workaround is no longer necessary. TODO: delete when fixed.
func hasMethod(typ types.Type, name string) bool {
	set := typ.MethodSet()
	for i := 0; i < set.Len(); i++ {
		if set.At(i).Obj().Name() == name {
			return true
		}
	}
	return false
}
开发者ID:ufo22940268,项目名称:two-server-others,代码行数:12,代码来源:types.go

示例5: IntuitiveMethodSet

// IntuitiveMethodSet returns the intuitive method set of a type, T.
//
// The result contains MethodSet(T) and additionally, if T is a
// concrete type, methods belonging to *T if there is no similarly
// named method on T itself.  This corresponds to user intuition about
// method sets; this function is intended only for user interfaces.
//
// The order of the result is as for types.MethodSet(T).
//
// TODO(gri): move this to go/types?
//
func IntuitiveMethodSet(T types.Type) []*types.Selection {
	var result []*types.Selection
	mset := T.MethodSet()
	if _, ok := T.Underlying().(*types.Interface); ok {
		for i, n := 0, mset.Len(); i < n; i++ {
			result = append(result, mset.At(i))
		}
	} else {
		pmset := types.NewPointer(T).MethodSet()
		for i, n := 0, pmset.Len(); i < n; i++ {
			meth := pmset.At(i)
			if m := mset.Lookup(meth.Obj().Pkg(), meth.Obj().Name()); m != nil {
				meth = m
			}
			result = append(result, meth)
		}
	}
	return result
}
开发者ID:nagyistge,项目名称:hm-workspace,代码行数:30,代码来源:print.go

示例6: makeMethods

// makeMethods ensures that all wrappers in the complete method set of
// T are generated.  It is equivalent to calling prog.Method() on all
// members of T.methodSet(), but acquires fewer locks.
//
// It reports whether the type's method set is non-empty.
//
// Thread-safe.
//
// EXCLUSIVE_LOCKS_ACQUIRED(prog.methodsMu)
//
func (prog *Program) makeMethods(T types.Type) bool {
	tmset := T.MethodSet()
	n := tmset.Len()
	if n == 0 {
		return false // empty (common case)
	}

	if prog.mode&LogSource != 0 {
		defer logStack("makeMethods %s", T)()
	}

	prog.methodsMu.Lock()
	defer prog.methodsMu.Unlock()

	mset := prog.createMethodSet(T)
	if !mset.complete {
		mset.complete = true
		for i := 0; i < n; i++ {
			prog.addMethod(mset, tmset.At(i))
		}
	}

	return true
}
开发者ID:Bosh-for-Cpi,项目名称:bosh-2605,代码行数:34,代码来源:promote.go

示例7: genMethodsOf

// genMethodsOf generates nodes and constraints for all methods of type T.
func (a *analysis) genMethodsOf(T types.Type) {
	mset := T.MethodSet()
	for i, n := 0, mset.Len(); i < n; i++ {
		a.valueNode(a.prog.Method(mset.At(i)))
	}
}
开发者ID:amulyas,项目名称:bosh-cloudstack-cpi,代码行数:7,代码来源:gen.go


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