1 Star 0 Fork 0

张中南/gocode

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
scope.go 1.25 KB
一键复制 编辑 原始数据 按行查看 历史
nsf 提交于 2012-02-24 23:14 +08:00 . Big refactoring, CamelCase -> words_with_underscores.
package main
//-------------------------------------------------------------------------
// scope
//-------------------------------------------------------------------------
type scope struct {
parent *scope // nil for universe scope
entities map[string]*decl
}
func new_scope(outer *scope) *scope {
s := new(scope)
s.parent = outer
s.entities = make(map[string]*decl)
return s
}
// returns: new, prev
func advance_scope(s *scope) (*scope, *scope) {
if len(s.entities) == 0 {
return s, s.parent
}
return new_scope(s), s
}
// adds declaration or returns an existing one
func (s *scope) add_named_decl(d *decl) *decl {
return s.add_decl(d.name, d)
}
func (s *scope) add_decl(name string, d *decl) *decl {
decl, ok := s.entities[name]
if !ok {
s.entities[name] = d
return d
}
return decl
}
func (s *scope) replace_decl(name string, d *decl) {
s.entities[name] = d
}
func (s *scope) merge_decl(d *decl) {
decl, ok := s.entities[d.name]
if !ok {
s.entities[d.name] = d
} else {
decl := decl.deep_copy()
decl.expand_or_replace(d)
s.entities[d.name] = decl
}
}
func (s *scope) lookup(name string) *decl {
decl, ok := s.entities[name]
if !ok {
if s.parent != nil {
return s.parent.lookup(name)
} else {
return nil
}
}
return decl
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/zhangzhongnan/gocode.git
git@gitee.com:zhangzhongnan/gocode.git
zhangzhongnan
gocode
gocode
adab99b939af

搜索帮助