Home | History | Annotate | Download | only in token

Lines Matching defs:File

3 // license that can be found in the LICENSE file.
17 // including the file, line, and column location.
32 // file:line:column valid position with file name
33 // line:column valid position without file name
34 // file invalid position with file name
35 // - invalid position without file name
51 // Pos is a compact encoding of a source position within a file set.
55 // The Pos value for a given file is a number in the range [base, base+size],
56 // where base and size are specified when adding the file to the file set via
60 // first add the respective file to the current file set using FileSet.AddFile
61 // and then call File.Pos(offset) for that file. Given a Pos value p
62 // for a specific file set fset, the corresponding Position value is
66 // If two Pos values p and q are in the same file, comparing p and q is
67 // equivalent to comparing the respective source file offsets. If p and q
68 // are in different files, p < q is true if the file implied by p was added
69 // to the respective file set before the file implied by q.
73 // The zero value for Pos is NoPos; there is no file and line information
86 // File
88 // A File is a handle for a file belonging to a FileSet.
89 // A File has a name, size, and line offset table.
91 type File struct {
93 name string // file name as provided to AddFile
94 base int // Pos value range for this file is [base...base+size]
95 size int // file size as provided to AddFile
103 // Name returns the file name of file f as registered with AddFile.
104 func (f *File) Name() string {
108 // Base returns the base offset of file f as registered with AddFile.
109 func (f *File) Base() int {
113 // Size returns the size of file f as registered with AddFile.
114 func (f *File) Size() int {
118 // LineCount returns the number of lines in file f.
119 func (f *File) LineCount() int {
128 // and smaller than the file size; otherwise the line offset is ignored.
130 func (f *File) AddLine(offset int) {
143 func (f *File) MergeLine(line int) {
161 // SetLines sets the line offsets for a file and reports whether it succeeded.
164 // An empty file has an empty line offset table.
166 // and smaller than the file size; otherwise SetLines fails and returns
170 func (f *File) SetLines(lines []int) bool {
186 // SetLinesForContent sets the line offsets for the given file content.
188 func (f *File) SetLinesForContent(content []byte) {
207 // A lineInfo object describes alternative file and line number
209 // file) for a given file offset.
217 // AddLineInfo adds alternative file and line number information for
218 // a given file offset. The offset must be larger than the offset for
220 // file size; otherwise the information is ignored.
225 func (f *File) AddLineInfo(offset int, filename string, line int) {
233 // Pos returns the Pos value for the given file offset;
237 func (f *File) Pos(offset int) Pos {
239 panic("illegal file offset")
244 // Offset returns the offset for the given file position p;
245 // p must be a valid Pos value in that file.
248 func (f *File) Offset(p Pos) int {
255 // Line returns the line number for the given file position p;
256 // p must be a Pos value in that file or NoPos.
258 func (f *File) Line(p Pos) int {
266 // unpack returns the filename and line and column number for a file offset.
270 func (f *File) unpack(offset int, adjusted bool) (filename string, line, column int) {
290 func (f *File) position(p Pos, adjusted bool) (pos Position) {
297 // PositionFor returns the Position value for the given file position p.
302 func (f *File) PositionFor(p Pos, adjusted bool) (pos Position) {
312 // Position returns the Position value for the given file position p.
315 func (f *File) Position(p Pos) (pos Position) {
323 // Methods of file sets are synchronized; multiple goroutines
327 mutex sync.RWMutex // protects the file set
328 base int // base offset for the next file
329 files []*File // list of files in the order added to the set
330 last *File // cache of last file looked up
333 // NewFileSet creates a new file set.
341 // AddFile when adding the next file.
351 // AddFile adds a new file with a given filename, base offset, and file size
352 // to the file set s and returns the file. Multiple files may have the same
357 // Adding the file will set the file set's Base() value to base + size + 1
358 // as the minimum base value for the next file. The following relationship
359 // exists between a Pos value p for a given file offset offs:
364 // For convenience, File.Pos may be used to create file-specific position
365 // values from a file offset.
367 func (s *FileSet) AddFile(filename string, base, size int) *File {
377 f := &File{set: s, name: filename, base: base, size: size, lines: []int{0}}
380 panic("token.Pos offset overflow (> 2G of source code in file set)")
382 // add the file to the file set
389 // Iterate calls f for the files in the file set in the order they were added
392 func (s *FileSet) Iterate(f func(*File) bool) {
394 var file *File
397 file = s.files[i]
400 if file == nil || !f(file) {
406 func searchFiles(a []*File, x int) int {
410 func (s *FileSet) file(p Pos) *File {
412 // common case: p is in last file
417 // p is not in last file - search all files
433 // File returns the file that contains the position p.
434 // If no such file is found (for instance for p == NoPos),
437 func (s *FileSet) File(p Pos) (f *File) {
439 f = s.file(p)
451 if f := s.file(p); f != nil {