示例#1
0
func declareSymbol(b *builder, sym *sym8.Symbol) bool {
	// declare in the scope
	exists := b.scope.Declare(sym)
	if exists != nil {
		b.Errorf(sym.Pos, "%q already declared", sym.Name())
		b.Errorf(exists.Pos, "  previously declared here")
		return false
	}
	return true
}
示例#2
0
func (b *builder) refSym(sym *sym8.Symbol, pos *lex8.Pos) {
	// track file dependencies inside a package
	if b.deps == nil {
		return // no need to track deps
	}

	symPos := sym.Pos
	if symPos == nil {
		return // builtin
	}
	if sym.Pkg() != b.path {
		return // cross package reference
	}
	if pos.File == symPos.File {
		return
	}

	b.deps.add(pos.File, symPos.File)
}
示例#3
0
文件: lib.go 项目: NickDaison/e8vm
func (lib *lib) declare(s *sym8.Symbol) {
	_, found := lib.symbols[s.Name()]
	if found {
		panic("redeclare")
	}
	lib.symbols[s.Name()] = s

	switch s.Type {
	case SymConst:
		panic("todo")
	case SymFunc:
		lib.Pkg.DeclareFunc(s.Name())
	case SymVar:
		lib.Pkg.DeclareVar(s.Name())
	default:
		panic("declare with invalid sym type")
	}
}