diff options
Diffstat (limited to 'src/pkg/go/token/position.go')
-rw-r--r-- | src/pkg/go/token/position.go | 33 |
1 files changed, 0 insertions, 33 deletions
diff --git a/src/pkg/go/token/position.go b/src/pkg/go/token/position.go index 23a3cc00f..c559e19f8 100644 --- a/src/pkg/go/token/position.go +++ b/src/pkg/go/token/position.go @@ -12,7 +12,6 @@ import ( "sync" ) - // Position describes an arbitrary source position // including the file, line, and column location. // A Position is valid if the line number is > 0. @@ -24,11 +23,9 @@ type Position struct { Column int // column number, starting at 1 (character count) } - // IsValid returns true if the position is valid. func (pos *Position) IsValid() bool { return pos.Line > 0 } - // String returns a string in one of several forms: // // file:line:column valid position with file name @@ -50,7 +47,6 @@ func (pos Position) String() string { return s } - // Pos is a compact encoding of a source position within a file set. // It can be converted into a Position for a more convenient, but much // larger, representation. @@ -73,7 +69,6 @@ func (pos Position) String() string { // type Pos int - // The zero value for Pos is NoPos; there is no file and line information // associated with it, and NoPos().IsValid() is false. NoPos is always // smaller than any other Pos value. The corresponding Position value @@ -81,18 +76,15 @@ type Pos int // const NoPos Pos = 0 - // IsValid returns true if the position is valid. func (p Pos) IsValid() bool { return p != NoPos } - func searchFiles(a []*File, x int) int { return sort.Search(len(a), func(i int) bool { return a[i].base > x }) - 1 } - func (s *FileSet) file(p Pos) *File { if f := s.last; f != nil && f.base <= int(p) && int(p) <= f.base+f.size { return f @@ -108,7 +100,6 @@ func (s *FileSet) file(p Pos) *File { return nil } - // File returns the file which contains the position p. // If no such file is found (for instance for p == NoPos), // the result is nil. @@ -122,7 +113,6 @@ func (s *FileSet) File(p Pos) (f *File) { return } - func (f *File) position(p Pos) (pos Position) { offset := int(p) - f.base pos.Offset = offset @@ -130,7 +120,6 @@ func (f *File) position(p Pos) (pos Position) { return } - // Position converts a Pos in the fileset into a general Position. func (s *FileSet) Position(p Pos) (pos Position) { if p != NoPos { @@ -147,14 +136,12 @@ func (s *FileSet) Position(p Pos) (pos Position) { return } - type lineInfo struct { offset int filename string line int } - // AddLineInfo adds alternative file and line number information for // a given file offset. The offset must be larger than the offset for // the previously added alternative line info and smaller than the @@ -171,7 +158,6 @@ func (f *File) AddLineInfo(offset int, filename string, line int) { f.set.mutex.Unlock() } - // A File is a handle for a file belonging to a FileSet. // A File has a name, size, and line offset table. // @@ -186,25 +172,21 @@ type File struct { infos []lineInfo } - // Name returns the file name of file f as registered with AddFile. func (f *File) Name() string { return f.name } - // Base returns the base offset of file f as registered with AddFile. func (f *File) Base() int { return f.base } - // Size returns the size of file f as registered with AddFile. func (f *File) Size() int { return f.size } - // LineCount returns the number of lines in file f. func (f *File) LineCount() int { f.set.mutex.RLock() @@ -213,7 +195,6 @@ func (f *File) LineCount() int { return n } - // AddLine adds the line offset for a new line. // The line offset must be larger than the offset for the previous line // and smaller than the file size; otherwise the line offset is ignored. @@ -226,7 +207,6 @@ func (f *File) AddLine(offset int) { f.set.mutex.Unlock() } - // SetLines sets the line offsets for a file and returns true if successful. // The line offsets are the offsets of the first character of each line; // for instance for the content "ab\nc\n" the line offsets are {0, 3}. @@ -251,7 +231,6 @@ func (f *File) SetLines(lines []int) bool { return true } - // SetLinesForContent sets the line offsets for the given file content. func (f *File) SetLinesForContent(content []byte) { var lines []int @@ -272,7 +251,6 @@ func (f *File) SetLinesForContent(content []byte) { f.set.mutex.Unlock() } - // Pos returns the Pos value for the given file offset; // the offset must be <= f.Size(). // f.Pos(f.Offset(p)) == p. @@ -284,7 +262,6 @@ func (f *File) Pos(offset int) Pos { return Pos(f.base + offset) } - // Offset returns the offset for the given file position p; // p must be a valid Pos value in that file. // f.Offset(f.Pos(offset)) == offset. @@ -296,7 +273,6 @@ func (f *File) Offset(p Pos) int { return int(p) - f.base } - // Line returns the line number for the given file position p; // p must be a Pos value in that file or NoPos. // @@ -305,7 +281,6 @@ func (f *File) Line(p Pos) int { return f.Position(p).Line } - // Position returns the Position value for the given file position p; // p must be a Pos value in that file or NoPos. // @@ -319,7 +294,6 @@ func (f *File) Position(p Pos) (pos Position) { return } - func searchInts(a []int, x int) int { // This function body is a manually inlined version of: // @@ -342,12 +316,10 @@ func searchInts(a []int, x int) int { return i - 1 } - func searchLineInfos(a []lineInfo, x int) int { return sort.Search(len(a), func(i int) bool { return a[i].offset > x }) - 1 } - // info returns the file name, line, and column number for a file offset. func (f *File) info(offset int) (filename string, line, column int) { filename = f.name @@ -367,7 +339,6 @@ func (f *File) info(offset int) (filename string, line, column int) { return } - // A FileSet represents a set of source files. // Methods of file sets are synchronized; multiple goroutines // may invoke them concurrently. @@ -379,7 +350,6 @@ type FileSet struct { last *File // cache of last file looked up } - // NewFileSet creates a new file set. func NewFileSet() *FileSet { s := new(FileSet) @@ -387,7 +357,6 @@ func NewFileSet() *FileSet { return s } - // Base returns the minimum base offset that must be provided to // AddFile when adding the next file. // @@ -399,7 +368,6 @@ func (s *FileSet) Base() int { } - // AddFile adds a new file with a given filename, base offset, and file size // to the file set s and returns the file. Multiple files may have the same // name. The base offset must not be smaller than the FileSet's Base(), and @@ -434,7 +402,6 @@ func (s *FileSet) AddFile(filename string, base, size int) *File { return f } - // Files returns the files added to the file set. func (s *FileSet) Files() <-chan *File { ch := make(chan *File) |