src

package standard library
go1.10beta2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 11, 2018 License: BSD-3-Clause Imports: 1 Imported by: 0

Documentation

Index

Constants

View Source
const FileSymPrefix = "gofile.."

Variables

This section is empty.

Functions

This section is empty.

Types

type Pos

type Pos struct {
	// contains filtered or unexported fields
}

A Pos encodes a source position consisting of a (line, column) number pair and a position base. A zero Pos is a ready to use "unknown" position (nil position base and zero line number).

The (line, column) values refer to a position in a file independent of any position base ("absolute" file position).

The position base is used to determine the "relative" position, that is the filename and line number relative to the position base. If the base refers to the current file, there is no difference between absolute and relative positions. If it refers to a //line pragma, a relative position is relative to that pragma. A position base in turn contains the position at which it was introduced in the current file.

var NoPos Pos

NoPos is a valid unknown position.

func MakePos

func MakePos(base *PosBase, line, col uint) Pos

MakePos creates a new Pos value with the given base, and (file-absolute) line and column.

func (Pos) AbsFilename

func (p Pos) AbsFilename() string

AbsFilename() returns the absolute filename recorded with the position's base.

func (Pos) After

func (p Pos) After(q Pos) bool

After reports whether the position p comes after q in the source. For positions in different files, ordering is by filename.

func (Pos) Base

func (p Pos) Base() *PosBase

Base returns the position base.

func (Pos) Before

func (p Pos) Before(q Pos) bool

Before reports whether the position p comes before q in the source. For positions in different files, ordering is by filename.

func (Pos) Col

func (x Pos) Col() uint

func (Pos) Filename

func (p Pos) Filename() string

Filename returns the name of the actual file containing this position.

func (Pos) Format

func (p Pos) Format(showCol, showOrig bool) string

Format formats a position as "filename:line" or "filename:line:column", controlled by the showCol flag. A position relative to a line directive is always formatted without column information. In that case, if showOrig is set, the original position (again controlled by showCol) is appended in square brackets: "filename:line[origfile:origline:origcolumn]".

func (Pos) IsKnown

func (p Pos) IsKnown() bool

IsKnown reports whether the position p is known. A position is known if it either has a non-nil position base, or a non-zero line number.

func (Pos) Line

func (x Pos) Line() uint

func (Pos) RelFilename

func (p Pos) RelFilename() string

RelFilename returns the filename recorded with the position's base.

func (Pos) RelLine

func (p Pos) RelLine() uint

RelLine returns the line number relative to the positions's base.

func (*Pos) SetBase

func (p *Pos) SetBase(base *PosBase)

SetBase sets the position base.

func (Pos) String

func (p Pos) String() string

func (Pos) SymFilename

func (p Pos) SymFilename() string

SymFilename() returns the absolute filename recorded with the position's base, prefixed by FileSymPrefix to make it appropriate for use as a linker symbol.

type PosBase

type PosBase struct {
	// contains filtered or unexported fields
}

A PosBase encodes a filename and base line number. Typically, each file and line pragma introduce a PosBase. A nil *PosBase is a ready to use file PosBase for an unnamed file with line numbers starting at 1.

func NewFileBase

func NewFileBase(filename, absFilename string) *PosBase

NewFileBase returns a new *PosBase for a file with the given (relative and absolute) filenames.

func NewInliningBase

func NewInliningBase(old *PosBase, inlTreeIndex int) *PosBase

NewInliningBase returns a copy of the old PosBase with the given inlining index. If old == nil, the resulting PosBase has no filename.

func NewLinePragmaBase

func NewLinePragmaBase(pos Pos, filename, absFilename string, line uint) *PosBase

NewLinePragmaBase returns a new *PosBase for a line pragma of the form

//line filename:line

at position pos.

func (*PosBase) AbsFilename

func (b *PosBase) AbsFilename() string

AbsFilename returns the absolute filename recorded with the base. If b == nil, the result is the empty string.

func (*PosBase) Filename

func (b *PosBase) Filename() string

Filename returns the filename recorded with the base. If b == nil, the result is the empty string.

func (*PosBase) InliningIndex

func (b *PosBase) InliningIndex() int

InliningIndex returns the index into the global inlining tree recorded with the base. If b == nil or the base has not been inlined, the result is < 0.

func (*PosBase) Line

func (b *PosBase) Line() uint

Line returns the line number recorded with the base. If b == nil, the result is 0.

func (*PosBase) Pos

func (b *PosBase) Pos() *Pos

Pos returns the position at which base is located. If b == nil, the result is the zero position.

func (*PosBase) SymFilename

func (b *PosBase) SymFilename() string

SymFilename returns the absolute filename recorded with the base, prefixed by FileSymPrefix to make it appropriate for use as a linker symbol. If b is nil, SymFilename returns FileSymPrefix + "??".

type PosTable

type PosTable struct {
	// contains filtered or unexported fields
}

A PosTable tracks Pos -> XPos conversions and vice versa. Its zero value is a ready-to-use PosTable.

func (*PosTable) Pos

func (t *PosTable) Pos(p XPos) Pos

Pos returns the corresponding Pos for the given p. If p cannot be translated via t, the function panics.

func (*PosTable) XPos

func (t *PosTable) XPos(pos Pos) XPos

XPos returns the corresponding XPos for the given pos, adding pos to t if necessary.

type XPos

type XPos struct {
	// contains filtered or unexported fields
}

XPos is a more compact representation of Pos.

var NoXPos XPos

NoXPos is a valid unknown position.

func (XPos) After

func (p XPos) After(q XPos) bool

After reports whether the position p comes after q in the source. For positions with different bases, ordering is by base index.

func (XPos) Before

func (p XPos) Before(q XPos) bool

Before reports whether the position p comes before q in the source. For positions with different bases, ordering is by base index.

func (XPos) Col

func (x XPos) Col() uint

func (XPos) IsKnown

func (p XPos) IsKnown() bool

IsKnown reports whether the position p is known. XPos.IsKnown() matches Pos.IsKnown() for corresponding positions.

func (XPos) Line

func (x XPos) Line() uint

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL