1// Copyright 2009 The Go Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style
3// license that can be found in the LICENSE file.
4
5package obj
6
7import (
8	"cmd/internal/goobj"
9	"cmd/internal/src"
10)
11
12// AddImport adds a package to the list of imported packages.
13func (ctxt *Link) AddImport(pkg string, fingerprint goobj.FingerprintType) {
14	ctxt.Imports = append(ctxt.Imports, goobj.ImportedPkg{Pkg: pkg, Fingerprint: fingerprint})
15}
16
17func linkgetlineFromPos(ctxt *Link, xpos src.XPos) (f string, l int32) {
18	pos := ctxt.PosTable.Pos(xpos)
19	if !pos.IsKnown() {
20		pos = src.Pos{}
21	}
22	// TODO(gri) Should this use relative or absolute line number?
23	return pos.SymFilename(), int32(pos.RelLine())
24}
25
26// getFileIndexAndLine returns the file index (local to the CU), and the line number for a position.
27func getFileIndexAndLine(ctxt *Link, xpos src.XPos) (int, int32) {
28	f, l := linkgetlineFromPos(ctxt, xpos)
29	return ctxt.PosTable.FileIndex(f), l
30}
31