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


Golang Scope.Lookup方法代码示例

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


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

示例1: declare

// Declare inserts a named object of the given kind in scope.
func (p *gcParser) declare(scope *ast.Scope, kind ast.ObjKind, name string) *ast.Object {
	// a type may have been declared before - if it exists
	// already in the respective package scope, return that
	// type
	if kind == ast.Typ {
		if obj := scope.Lookup(name); obj != nil {
			assert(obj.Kind == ast.Typ)
			return obj
		}
	}

	// any other object must be a newly declared object -
	// create it and insert it into the package scope
	obj := ast.NewObj(kind, name)
	if scope.Insert(obj) != nil {
		p.errorf("already declared: %v %s", kind, obj.Name)
	}

	// a new type object is a named type and may be referred
	// to before the underlying type is known - set it up
	if kind == ast.Typ {
		obj.Type = &Name{Obj: obj}
	}

	return obj
}
开发者ID:Quantumboost,项目名称:gcc,代码行数:27,代码来源:gcimporter.go

示例2: Lookup

func Lookup(scope *ast.Scope, name string) *ast.Object {
	for scope != nil {
		if obj := scope.Lookup(name); obj != nil {
			return obj
		}
		scope = scope.Outer
	}
	return nil
}
开发者ID:soniah,项目名称:gosloppy,代码行数:9,代码来源:scopewalker.go

示例3: findIdentInScope

func (p *parser) findIdentInScope(scope *ast.Scope) *ast.Ident {
	pos := p.pos
	name := "_"
	var obj *ast.Object
	if p.tok == token.IDENT {
		name = string(p.lit)
		obj = scope.Lookup(name)
		p.next()
	} else {
		p.expect(token.IDENT) // use expect() error handling
	}
	if obj == nil {
		// TODO(gri) At the moment we always arrive here because
		//           we don't track the lookup scope (and sometimes
		//           we can't). Just create a useable ident for now.
		obj = ast.NewObj(ast.Err, pos, name)
	}
	return &ast.Ident{pos, obj}
}
开发者ID:rapgamer,项目名称:golang-china,代码行数:19,代码来源:parser.go

示例4: declare

// Declare inserts a named object of the given kind in scope.
func (p *gcParser) declare(scope *ast.Scope, kind ast.ObjKind, name string) *ast.Object {
	// the object may have been imported before - if it exists
	// already in the respective package scope, return that object
	if obj := scope.Lookup(name); obj != nil {
		assert(obj.Kind == kind)
		return obj
	}

	// otherwise create a new object and insert it into the package scope
	obj := ast.NewObj(kind, name)
	if scope.Insert(obj) != nil {
		p.errorf("already declared: %v %s", kind, obj.Name)
	}

	// if the new type object is a named type it may be referred
	// to before the underlying type is known - set it up
	if kind == ast.Typ {
		obj.Type = &NamedType{Obj: obj}
	}

	return obj
}
开发者ID:hfeeki,项目名称:go,代码行数:23,代码来源:gcimporter.go


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