本文整理汇总了Golang中go/types.Object.Name方法的典型用法代码示例。如果您正苦于以下问题:Golang Object.Name方法的具体用法?Golang Object.Name怎么用?Golang Object.Name使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类go/types.Object
的用法示例。
在下文中一共展示了Object.Name方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: formatMember
func formatMember(obj types.Object, maxname int) string {
qualifier := types.RelativeTo(obj.Pkg())
var buf bytes.Buffer
fmt.Fprintf(&buf, "%-5s %-*s", tokenOf(obj), maxname, obj.Name())
switch obj := obj.(type) {
case *types.Const:
fmt.Fprintf(&buf, " %s = %s", types.TypeString(obj.Type(), qualifier), obj.Val().String())
case *types.Func:
fmt.Fprintf(&buf, " %s", types.TypeString(obj.Type(), qualifier))
case *types.TypeName:
// Abbreviate long aggregate type names.
var abbrev string
switch t := obj.Type().Underlying().(type) {
case *types.Interface:
if t.NumMethods() > 1 {
abbrev = "interface{...}"
}
case *types.Struct:
if t.NumFields() > 1 {
abbrev = "struct{...}"
}
}
if abbrev == "" {
fmt.Fprintf(&buf, " %s", types.TypeString(obj.Type().Underlying(), qualifier))
} else {
fmt.Fprintf(&buf, " %s", abbrev)
}
case *types.Var:
fmt.Fprintf(&buf, " %s", types.TypeString(obj.Type(), qualifier))
}
return buf.String()
}
示例2: createDef
func createDef(obj types.Object, ident *ast.Ident, ctx *getDefinitionsContext, isType bool) *Definition {
fullName := getFullName(obj, ctx, isType)
if def, ok := ctx.defs[fullName]; ok {
return def
}
def := new(Definition)
def.Name = fullName
def.Pkg = obj.Pkg()
def.IsExported = obj.Exported()
def.TypeOf = reflect.TypeOf(obj)
def.SimpleName = obj.Name()
def.Usages = make([]*Usage, 0)
def.InterfacesDefs = make([]*Definition, 0)
if ident != nil {
position := ctx.fset.Position(ident.Pos())
def.File = position.Filename
def.Line = position.Line
def.Offset = position.Offset
def.Col = position.Column
}
if !types.IsInterface(obj.Type()) {
fillInterfaces(def, obj, ctx)
}
ctx.defs[def.Name] = def
logDefinition(def, obj, ident, ctx)
return def
}
示例3: getFullName
//getFullName is returning unique name of obj.
func getFullName(obj types.Object, ctx *getDefinitionsContext, isType bool) string {
if obj == nil {
return ""
}
if isType {
return obj.Type().String()
}
result := ""
switch obj.(type) {
case *types.Func:
f := obj.(*types.Func)
r := strings.NewReplacer("(", "", "*", "", ")", "")
result = r.Replace(f.FullName())
default:
if obj.Pkg() != nil {
result += obj.Pkg().Path()
result += "."
}
if packageName, ok := ctx.structs[posToStr(ctx.fset, obj.Pos())]; ok {
result += packageName
result += "."
}
result += obj.Name()
}
return result
}
示例4: lookup
// lookup returns the address of the named variable identified by obj
// that is local to function f or one of its enclosing functions.
// If escaping, the reference comes from a potentially escaping pointer
// expression and the referent must be heap-allocated.
//
func (f *Function) lookup(obj types.Object, escaping bool) Value {
if v, ok := f.objects[obj]; ok {
if alloc, ok := v.(*Alloc); ok && escaping {
alloc.Heap = true
}
return v // function-local var (address)
}
// Definition must be in an enclosing function;
// plumb it through intervening closures.
if f.parent == nil {
panic("no ssa.Value for " + obj.String())
}
outer := f.parent.lookup(obj, true) // escaping
v := &FreeVar{
name: obj.Name(),
typ: outer.Type(),
pos: outer.Pos(),
outer: outer,
parent: f,
}
f.objects[obj] = v
f.FreeVars = append(f.FreeVars, v)
return v
}
示例5: updateGetDefinitionsContext
func updateGetDefinitionsContext(ctx *getDefinitionsContext, def *Definition, ident *ast.Ident, obj types.Object) {
switch obj.(type) {
case *types.Var:
//Processing vars later to be sure that all info about structs already filled
ctx.vars = append(ctx.vars, newObjectWithIdent(obj, ident))
case *types.Func:
//Processing funcs later to be sure that all info about interfaces already filled
ctx.funcs = append(ctx.funcs, newObjectWithIdent(obj, ident))
case *types.TypeName:
//If the underlying type is struct, then filling
//positions of struct's fields (key) and struct name(value)
//to map. Then we can extract struct name for fields when
//will be analyze them.
t := obj.(*types.TypeName)
underlyingType := t.Type().Underlying()
switch underlyingType.(type) {
case *types.Struct:
s := underlyingType.(*types.Struct)
for i := 0; i < s.NumFields(); i++ {
field := s.Field(i)
ctx.structs[posToStr(ctx.fset, field.Pos())] = obj.Name()
}
}
}
//Check for interfaces
underlyingType := obj.Type().Underlying()
switch underlyingType.(type) {
case *types.Interface:
d := new(defWithInterface)
d.def = def
d.interfac = underlyingType.(*types.Interface)
ctx.interfaces = append(ctx.interfaces, d)
}
}
示例6: isStringer
func isStringer(obj types.Object) bool {
switch obj := obj.(type) {
case *types.Func:
if obj.Name() != "String" {
return false
}
sig, ok := obj.Type().(*types.Signature)
if !ok {
return false
}
if sig.Recv() == nil {
return false
}
if sig.Params().Len() != 0 {
return false
}
res := sig.Results()
if res.Len() != 1 {
return false
}
ret := res.At(0).Type()
if ret != types.Universe.Lookup("string").Type() {
return false
}
return true
default:
return false
}
return false
}
示例7: appendObject
func (b *candidateCollector) appendObject(obj types.Object) {
// TODO(mdempsky): Change this to true.
const proposeBuiltins = false
if obj.Pkg() != b.localpkg {
if obj.Parent() == types.Universe {
if !proposeBuiltins {
return
}
} else if !obj.Exported() {
return
}
}
// TODO(mdempsky): Reconsider this functionality.
if b.filter != nil && !b.filter(obj) {
return
}
if b.filter != nil || strings.HasPrefix(obj.Name(), b.partial) {
b.exact = append(b.exact, obj)
} else if strings.HasPrefix(strings.ToLower(obj.Name()), strings.ToLower(b.partial)) {
b.badcase = append(b.badcase, obj)
}
}
示例8: asCandidate
func (b *candidateCollector) asCandidate(obj types.Object) Candidate {
objClass := classifyObject(obj)
var typ types.Type
switch objClass {
case "const", "func", "var":
typ = obj.Type()
case "type":
typ = obj.Type().Underlying()
}
var typStr string
switch t := typ.(type) {
case *types.Interface:
typStr = "interface"
case *types.Struct:
typStr = "struct"
default:
if _, isBuiltin := obj.(*types.Builtin); isBuiltin {
typStr = builtinTypes[obj.Name()]
} else if t != nil {
typStr = types.TypeString(t, b.qualify)
}
}
return Candidate{
Class: objClass,
Name: obj.Name(),
Type: typStr,
}
}
示例9: typesObjectString
func typesObjectString(obj types.Object) string {
var prefix string
switch obj.(type) {
case *types.Builtin:
prefix = "builtin"
case *types.Func:
prefix = "func"
case *types.Const:
prefix = "const"
case *types.PkgName:
prefix = "package"
case *types.Var:
prefix = "var"
case *types.Label:
prefix = "label"
case *types.Nil:
return "nil"
case *types.TypeName:
prefix = "type"
default:
panic(fmt.Sprintf("unexpected type: %T", obj))
}
return prefix + " " + obj.Name()
}
示例10: qualifiedName
func (p *exporter) qualifiedName(obj types.Object) {
if obj == nil {
p.string("")
return
}
p.string(obj.Name())
p.pkg(obj.Pkg(), false)
}
示例11: memberFromObject
// memberFromObject populates package pkg with a member for the
// typechecker object obj.
//
// For objects from Go source code, syntax is the associated syntax
// tree (for funcs and vars only); it will be used during the build
// phase.
//
func memberFromObject(pkg *Package, obj types.Object, syntax ast.Node) {
name := obj.Name()
switch obj := obj.(type) {
case *types.TypeName:
pkg.Members[name] = &Type{
object: obj,
pkg: pkg,
}
case *types.Const:
c := &NamedConst{
object: obj,
Value: NewConst(obj.Val(), obj.Type()),
pkg: pkg,
}
pkg.values[obj] = c.Value
pkg.Members[name] = c
case *types.Var:
g := &Global{
Pkg: pkg,
name: name,
object: obj,
typ: types.NewPointer(obj.Type()), // address
pos: obj.Pos(),
}
pkg.values[obj] = g
pkg.Members[name] = g
case *types.Func:
sig := obj.Type().(*types.Signature)
if sig.Recv() == nil && name == "init" {
pkg.ninit++
name = fmt.Sprintf("init#%d", pkg.ninit)
}
fn := &Function{
name: name,
object: obj,
Signature: sig,
syntax: syntax,
pos: obj.Pos(),
Pkg: pkg,
Prog: pkg.Prog,
}
if syntax == nil {
fn.Synthetic = "loaded from gc object file"
}
pkg.values[obj] = fn
if sig.Recv() == nil {
pkg.Members[name] = fn // package-level function
}
default: // (incl. *types.Package)
panic("unexpected Object type: " + obj.String())
}
}
示例12: addParamObj
func (f *Function) addParamObj(obj types.Object) *Parameter {
name := obj.Name()
if name == "" {
name = fmt.Sprintf("arg%d", len(f.Params))
}
param := f.addParam(name, obj.Type(), obj.Pos())
param.object = obj
return param
}
示例13: joinQuery
func joinQuery(pkg *types.Package, parent types.Object, obj types.Object, suffix string) string {
var args []string
args = append(args, pkg.Name())
if parent != nil {
args = append(args, parent.Name())
}
args = append(args, nameExported(obj.Name()))
return strings.Join(args, ".") + suffix
}
示例14: addSpilledParam
// addSpilledParam declares a parameter that is pre-spilled to the
// stack; the function body will load/store the spilled location.
// Subsequent lifting will eliminate spills where possible.
//
func (f *Function) addSpilledParam(obj types.Object) {
param := f.addParamObj(obj)
spill := &Alloc{Comment: obj.Name()}
spill.setType(types.NewPointer(obj.Type()))
spill.setPos(obj.Pos())
f.objects[obj] = spill
f.Locals = append(f.Locals, spill)
f.emit(spill)
f.emit(&Store{Addr: spill, Val: param})
}
示例15: addSymbol
func (sym *symtab) addSymbol(obj types.Object) {
fn := types.ObjectString(obj, nil)
n := obj.Name()
pkg := obj.Pkg()
id := n
if pkg != nil {
id = pkg.Name() + "_" + n
}
switch obj.(type) {
case *types.Const:
sym.syms[fn] = &symbol{
gopkg: pkg,
goobj: obj,
kind: skConst,
id: id,
goname: n,
cgoname: "cgo_const_" + id,
cpyname: "cpy_const_" + id,
}
sym.addType(obj, obj.Type())
case *types.Var:
sym.syms[fn] = &symbol{
gopkg: pkg,
goobj: obj,
kind: skVar,
id: id,
goname: n,
cgoname: "cgo_var_" + id,
cpyname: "cpy_var_" + id,
}
sym.addType(obj, obj.Type())
case *types.Func:
sym.syms[fn] = &symbol{
gopkg: pkg,
goobj: obj,
kind: skFunc,
id: id,
goname: n,
cgoname: "cgo_func_" + id,
cpyname: "cpy_func_" + id,
}
sig := obj.Type().Underlying().(*types.Signature)
sym.processTuple(sig.Params())
sym.processTuple(sig.Results())
case *types.TypeName:
sym.addType(obj, obj.Type())
default:
panic(fmt.Errorf("gopy: handled object [%#v]", obj))
}
}