本文整理汇总了Golang中go/ast.Ident类的典型用法代码示例。如果您正苦于以下问题:Golang Ident类的具体用法?Golang Ident怎么用?Golang Ident使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Ident类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: compileIdent
func (a *typeCompiler) compileIdent(x *ast.Ident, allowRec bool) Type {
_, _, def := a.block.Lookup(x.Name())
if def == nil {
a.diagAt(x, "%s: undefined", x.Name())
return nil
}
switch def := def.(type) {
case *Constant:
a.diagAt(x, "constant %v used as type", x.Name())
return nil
case *Variable:
a.diagAt(x, "variable %v used as type", x.Name())
return nil
case *NamedType:
if !allowRec && def.incomplete {
a.diagAt(x, "illegal recursive type")
return nil
}
if !def.incomplete && def.Def == nil {
// Placeholder type from an earlier error
return nil
}
return def
case Type:
return def
}
log.Crashf("name %s has unknown type %T", x.Name(), def)
return nil
}
开发者ID:rapgamer,项目名称:golang-china,代码行数:29,代码来源:typec.go
示例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
}
开发者ID:rakyll,项目名称:GCSolutions,代码行数:33,代码来源:gounexport.go
示例3: findLexicalLabel
func (a *stmtCompiler) findLexicalLabel(name *ast.Ident, pred func(*label) bool, errOp, errCtx string) *label {
bc := a.blockCompiler
for ; bc != nil; bc = bc.parent {
if bc.label == nil {
continue
}
l := bc.label
if name == nil && pred(l) {
return l
}
if name != nil && l.name == name.Name() {
if !pred(l) {
a.diag("cannot %s to %s %s", errOp, l.desc, l.name)
return nil
}
return l
}
}
if name == nil {
a.diag("%s outside %s", errOp, errCtx)
} else {
a.diag("%s label %s not defined", errOp, name.Name())
}
return nil
}
开发者ID:rapgamer,项目名称:golang-china,代码行数:25,代码来源:stmt.go
示例4: emitFieldSelection
// emitFieldSelection emits to f code to select the index'th field of v.
//
// If wantAddr, the input must be a pointer-to-struct and the result
// will be the field's address; otherwise the result will be the
// field's value.
// Ident id is used for position and debug info.
//
func emitFieldSelection(f *Function, v Value, index int, wantAddr bool, id *ast.Ident) Value {
fld := deref(v.Type()).Underlying().(*types.Struct).Field(index)
if isPointer(v.Type()) {
instr := &FieldAddr{
X: v,
Field: index,
}
instr.setPos(id.Pos())
instr.setType(types.NewPointer(fld.Type()))
v = f.emit(instr)
// Load the field's value iff we don't want its address.
if !wantAddr {
v = emitLoad(f, v)
}
} else {
instr := &Field{
X: v,
Field: index,
}
instr.setPos(id.Pos())
instr.setType(fld.Type())
v = f.emit(instr)
}
emitDebugRef(f, id, v, wantAddr)
return v
}
开发者ID:himanshugpt,项目名称:evergreen,代码行数:33,代码来源:emit.go
示例5: DeclLhsPos
// DeclLhsPos returns the position of the ident's variable on the left hand
// side of the assignment operator with which it was declared.
func DeclLhsPos(ident *ast.Ident) (int, error) {
var identPos int
switch n := ident.Obj.Decl.(type) {
case *ast.AssignStmt:
// find position of ident on lhs of assignment
for i, exp := range n.Lhs {
if a, ok := exp.(*ast.Ident); ok && SameIdent(a, ident) {
identPos = i
break
}
}
case *ast.ValueSpec:
// find position of ident on lhs of assignment
for i, name := range n.Names {
if name.String() == ident.String() {
identPos = i
break
}
}
default:
return 0, errors.New("could not get lhs position of ident: unknown decl type")
}
return identPos, nil
}
开发者ID:guycook,项目名称:tenets,代码行数:30,代码来源:ident.go
示例6: Ident
func (s *Styler) Ident(id *ast.Ident) (text []byte, tag printer.HTMLTag) {
text = strings.Bytes(id.Name())
if s.highlight == id.Name() {
tag = printer.HTMLTag{"<span class=highlight>", "</span>"}
}
return
}
开发者ID:rapgamer,项目名称:golang-china,代码行数:7,代码来源:godoc.go
示例7: Ident
func (s *snippetStyler) Ident(id *ast.Ident) (text []byte, tag printer.HTMLTag) {
text = []byte(id.Name())
if s.highlight == id {
tag = printer.HTMLTag{"<span class=highlight>", "</span>"}
}
return
}
开发者ID:ivanwyc,项目名称:google-go,代码行数:7,代码来源:snippet.go
示例8: visitIdent
func (x *Indexer) visitIdent(kind SpotKind, id *ast.Ident) {
if id == nil {
return
}
name := x.intern(id.Name)
switch kind {
case TypeDecl, FuncDecl, ConstDecl, VarDecl:
x.curPkgExports[name] = kind
}
lists, found := x.words[name]
if !found {
lists = new(IndexResult)
x.words[name] = lists
}
if kind == Use || x.decl == nil {
if x.c.IndexGoCode {
// not a declaration or no snippet required
info := makeSpotInfo(kind, x.current.Line(id.Pos()), false)
lists.Others = append(lists.Others, Spot{x.file, info})
}
} else {
// a declaration with snippet
index := x.addSnippet(NewSnippet(x.fset, x.decl, id))
info := makeSpotInfo(kind, index, true)
lists.Decls = append(lists.Decls, Spot{x.file, info})
}
x.stats.Spots++
}
开发者ID:Bosh-for-Cpi,项目名称:bosh-2605,代码行数:32,代码来源:index.go
示例9: collectMethods
// collectMethods collects the method declarations from an AST File and
// returns a mapping from receiver types to their method FuncDecl's.
func (c *checker) collectMethods(file *ast.File) {
for _, decl := range file.Decls {
if funcdecl, ok := decl.(*ast.FuncDecl); ok && funcdecl.Recv != nil {
recvField := funcdecl.Recv.List[0]
var recv *ast.Ident
switch typ := recvField.Type.(type) {
case *ast.StarExpr:
recv = typ.X.(*ast.Ident)
case *ast.Ident:
recv = typ
case *ast.BadExpr:
return
}
if recv.Obj == nil {
// error reported elsewhere.
return
}
if recv.Obj.Kind != ast.Typ {
c.errorf(recv.Pos(), "%s is not a type", recv.Name)
return
}
// The Obj field of the funcdecl wll be nil, so we'll have to
// create a new one.
funcdecl.Name.Obj = ast.NewObj(ast.Fun, funcdecl.Name.String())
funcdecl.Name.Obj.Decl = funcdecl
c.methods[recv.Obj] = append(c.methods[recv.Obj], funcdecl.Name.Obj)
}
}
}
开发者ID:kelsieflynn,项目名称:llgo,代码行数:34,代码来源:check.go
示例10: SameIdent
// SameIdent returns true if a and b are the same.
func SameIdent(a, b *ast.Ident) bool {
// TODO(waigani) Don't rely on name, it could change and still be the same
// ident.
if a.String() != b.String() {
return false
}
// TODO(waigani) this happens if ident decl is outside of current
// file. We need to use the FileSet to find it.
if a.Obj == nil && b.Obj == nil {
return true
}
pa, err := DeclPos(a)
if err != nil {
// TODO(waigani) log error
return false
}
pb, err := DeclPos(b)
if err != nil {
// TODO(waigani) log error
return false
}
if pa != pb {
return false
}
return true
}
开发者ID:guycook,项目名称:tenets,代码行数:32,代码来源:ident.go
示例11: Visit
func (v *visitor) Visit(node ast.Node) bool {
descend := true
var ident *ast.Ident
var kind string
switch t := node.(type) {
case *ast.FuncDecl:
kind = "func"
ident = t.Name
descend = false
case *ast.TypeSpec:
kind = "type"
ident = t.Name
descend = false
}
if ident != nil && strings.Contains(strings.ToLower(ident.Name), v.query) {
f := v.fset.File(ident.Pos())
v.syms = append(v.syms, symbol{
Package: v.pkg.Name,
Path: f.Name(),
Name: ident.Name,
Kind: kind,
Line: f.Line(ident.Pos()) - 1,
})
}
return descend
}
开发者ID:DuoSoftware,项目名称:v6engine-deps,代码行数:30,代码来源:main.go
示例12: findField
// findField returns the object with the given name if visible in the type's scope.
// If no such object is found, an error is reported and a bad object is returned instead.
func (tc *typechecker) findField(typ *ast.Type, name *ast.Ident) (obj *ast.Object) {
// TODO(gri) This is simplistic at the moment and ignores anonymous fields.
obj = typ.Scope.Lookup(name.Name)
if obj == nil {
tc.Errorf(name.Pos(), "%s not declared", name.Name)
obj = ast.NewObj(ast.Bad, name.Name)
}
return
}
开发者ID:IntegerCompany,项目名称:linaro-android-gcc,代码行数:11,代码来源:scope.go
示例13: declInScope
// declInScope declares an object of a given kind and name in scope and sets the object's Decl and N fields.
// It returns the newly allocated object. If an object with the same name already exists in scope, an error
// is reported and the object is not inserted.
// (Objects with _ name are always inserted into a scope without errors, but they cannot be found.)
func (tc *typechecker) declInScope(scope *ast.Scope, kind ast.Kind, name *ast.Ident, decl interface{}, n int) *ast.Object {
obj := ast.NewObj(kind, name.Name)
obj.Decl = decl
obj.N = n
name.Obj = obj
if alt := scope.Insert(obj); alt != obj {
tc.Errorf(name.Pos(), "%s already declared at %s", name.Name, objPos(alt))
}
return obj
}
开发者ID:IntegerCompany,项目名称:linaro-android-gcc,代码行数:14,代码来源:scope.go
示例14: makeFunc
func (c *compiler) makeFunc(ident *ast.Ident, ftyp *types.Signature) *LLVMValue {
fname := ident.String()
if ftyp.Recv() == nil && fname == "init" {
// Make "init" functions anonymous.
fname = ""
} else {
var pkgname string
if recv := ftyp.Recv(); recv != nil {
var recvname string
switch recvtyp := recv.Type().(type) {
case *types.Pointer:
if named, ok := recvtyp.Elem().(*types.Named); ok {
obj := named.Obj()
recvname = "*" + obj.Name()
pkgname = obj.Pkg().Path()
}
case *types.Named:
named := recvtyp
obj := named.Obj()
recvname = obj.Name()
pkgname = obj.Pkg().Path()
}
if recvname != "" {
fname = fmt.Sprintf("%s.%s", recvname, fname)
} else {
// If the receiver is an unnamed struct, we're
// synthesising a method for an unnamed struct
// type. There's no meaningful name to give the
// function, so leave it up to LLVM.
fname = ""
}
} else {
obj := c.typeinfo.Objects[ident]
pkgname = obj.Pkg().Path()
}
if fname != "" {
fname = pkgname + "." + fname
}
}
// gcimporter may produce multiple AST objects for the same function.
llvmftyp := c.types.ToLLVM(ftyp)
var fn llvm.Value
if fname != "" {
fn = c.module.Module.NamedFunction(fname)
}
if fn.IsNil() {
llvmfptrtyp := llvmftyp.StructElementTypes()[0].ElementType()
fn = llvm.AddFunction(c.module.Module, fname, llvmfptrtyp)
}
fn = llvm.ConstInsertValue(llvm.ConstNull(llvmftyp), fn, []uint32{0})
return c.NewValue(fn, ftyp)
}
开发者ID:qioixiy,项目名称:llgo,代码行数:54,代码来源:decl.go
示例15: newSnippet
func newSnippet(fset *token.FileSet, decl ast.Decl, id *ast.Ident) *Snippet {
// TODO instead of pretty-printing the node, should use the original source instead
var buf1 bytes.Buffer
writeNode(&buf1, fset, decl)
// wrap text with <pre> tag
var buf2 bytes.Buffer
buf2.WriteString("<pre>")
FormatText(&buf2, buf1.Bytes(), -1, true, id.Name, nil)
buf2.WriteString("</pre>")
return &Snippet{fset.Position(id.Pos()).Line, buf2.String()}
}
开发者ID:qunhu,项目名称:go_src_comment,代码行数:11,代码来源:snippet.go
示例16: find
// find returns the object with the given name if visible in the current scope hierarchy.
// If no such object is found, an error is reported and a bad object is returned instead.
func (tc *typechecker) find(name *ast.Ident) (obj *ast.Object) {
for s := tc.topScope; s != nil && obj == nil; s = s.Outer {
obj = s.Lookup(name.Name)
}
if obj == nil {
tc.Errorf(name.Pos(), "%s not declared", name.Name)
obj = ast.NewObj(ast.Bad, name.Name)
}
name.Obj = obj
return
}
开发者ID:IntegerCompany,项目名称:linaro-android-gcc,代码行数:13,代码来源:scope.go
示例17: declInScope
// declInScope declares an object of a given kind and name in scope and sets the object's Decl and N fields.
// It returns the newly allocated object. If an object with the same name already exists in scope, an error
// is reported and the object is not inserted.
func (tc *typechecker) declInScope(scope *ast.Scope, kind ast.ObjKind, name *ast.Ident, decl interface{}, n int) *ast.Object {
obj := ast.NewObj(kind, name.Name)
obj.Decl = decl
//obj.N = n
name.Obj = obj
if name.Name != "_" {
if alt := scope.Insert(obj); alt != nil {
tc.Errorf(name.Pos(), "%s already declared at %s", name.Name, tc.fset.Position(alt.Pos()).String())
}
}
return obj
}
开发者ID:WXB506,项目名称:golang,代码行数:15,代码来源:scope.go
示例18: findImportedTypes
func findImportedTypes(name *ast.Ident, withImports []*ast.ImportSpec, dir GoDir) []*ast.TypeSpec {
importName := name.String()
for _, imp := range withImports {
path := strings.Trim(imp.Path.Value, `"`)
if pkg, err := dir.Import(path, importName); err == nil {
typs, _ := loadPkgTypeSpecs(pkg, dir)
addSelector(typs, importName)
return typs
}
}
return nil
}
开发者ID:jasonkeene,项目名称:hel,代码行数:12,代码来源:types.go
示例19: declIdent
func (p *parser) declIdent(scope *ast.Scope, id *ast.Ident) {
decl := scope.Declare(id.Obj)
if p.checkDecl && decl != id.Obj {
if decl.Kind == ast.Err {
// declared object is a forward declaration - update it
*decl = *id.Obj
id.Obj = decl
return
}
p.Error(id.Pos(), "'"+id.Name()+"' declared already at "+decl.Pos.String())
}
}
开发者ID:rapgamer,项目名称:golang-china,代码行数:12,代码来源:parser.go
示例20: handleUnresolved
func handleUnresolved(unresolved *ast.Ident) gxui.CodeSyntaxLayers {
layers := make(gxui.CodeSyntaxLayers, 0, 1)
switch unresolved.String() {
case "append", "cap", "close", "complex", "copy",
"delete", "imag", "len", "make", "new", "panic",
"print", "println", "real", "recover":
layers = append(layers, nodeLayer(unresolved, builtinColor))
case "nil":
layers = append(layers, nodeLayer(unresolved, nilColor))
}
return layers
}
开发者ID:gitter-badger,项目名称:vidar,代码行数:13,代码来源:unresolved.go
注:本文中的go/ast.Ident类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论