コード例 #1
0
ファイル: etc.go プロジェクト: JamesLinus/pl0
// Bind attempts to bind the name in t to node. Errors are reported to report.
func (b *Bindings) Bind(t xc.Token, node Node, report *xc.Report) {
	nm := t.Val
	if x := b.Map[nm]; x != nil {
		ok := false
		switch e := x.Node.(type) {
		case *ConstSpec, *Variable:
		case *ProcSpec:
			ok = e == nil
		default:
			panic("internal error")
		}

		if !ok {
			report.ErrTok(t, "redeclaration of %s at %s", xc.Dict.S(nm), position(x.Pos))
			return
		}
	}

	b.Map[nm] = &Binding{node, t.Pos()}
}