github.com/shogo82148/std@v1.22.1-0.20240327122250-4e474527810c/cmd/internal/src/xpos.go (about)

     1  // Copyright 2016 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  
     5  // This file implements the compressed encoding of source
     6  // positions using a lookup table.
     7  
     8  package src
     9  
    10  // XPos is a more compact representation of Pos.
    11  type XPos struct {
    12  	index int32
    13  	lico
    14  }
    15  
    16  // NoXPos is a valid unknown position.
    17  var NoXPos XPos
    18  
    19  // IsKnown reports whether the position p is known.
    20  // XPos.IsKnown() matches Pos.IsKnown() for corresponding
    21  // positions.
    22  func (p XPos) IsKnown() bool
    23  
    24  // Before reports whether the position p comes before q in the source.
    25  // For positions with different bases, ordering is by base index.
    26  func (p XPos) Before(q XPos) bool
    27  
    28  // SameFile reports whether p and q are positions in the same file.
    29  func (p XPos) SameFile(q XPos) bool
    30  
    31  // SameFileAndLine reports whether p and q are positions on the same line in the same file.
    32  func (p XPos) SameFileAndLine(q XPos) bool
    33  
    34  // After reports whether the position p comes after q in the source.
    35  // For positions with different bases, ordering is by base index.
    36  func (p XPos) After(q XPos) bool
    37  
    38  // WithNotStmt returns the same location to be marked with DWARF is_stmt=0
    39  func (p XPos) WithNotStmt() XPos
    40  
    41  // WithDefaultStmt returns the same location with undetermined is_stmt
    42  func (p XPos) WithDefaultStmt() XPos
    43  
    44  // WithIsStmt returns the same location to be marked with DWARF is_stmt=1
    45  func (p XPos) WithIsStmt() XPos
    46  
    47  // WithBogusLine returns a bogus line that won't match any recorded for the source code.
    48  // Its use is to disrupt the statements within an infinite loop so that the debugger
    49  // will not itself loop infinitely waiting for the line number to change.
    50  // gdb chooses not to display the bogus line; delve shows it with a complaint, but the
    51  // alternative behavior is to hang.
    52  func (p XPos) WithBogusLine() XPos
    53  
    54  // WithXlogue returns the same location but marked with DWARF function prologue/epilogue
    55  func (p XPos) WithXlogue(x PosXlogue) XPos
    56  
    57  // LineNumber returns a string for the line number, "?" if it is not known.
    58  func (p XPos) LineNumber() string
    59  
    60  // FileIndex returns a smallish non-negative integer corresponding to the
    61  // file for this source position.  Smallish is relative; it can be thousands
    62  // large, but not millions.
    63  func (p XPos) FileIndex() int32
    64  
    65  func (p XPos) LineNumberHTML() string
    66  
    67  // AtColumn1 returns the same location but shifted to column 1.
    68  func (p XPos) AtColumn1() XPos
    69  
    70  // A PosTable tracks Pos -> XPos conversions and vice versa.
    71  // Its zero value is a ready-to-use PosTable.
    72  type PosTable struct {
    73  	baseList []*PosBase
    74  	indexMap map[*PosBase]int
    75  	nameMap  map[string]int
    76  }
    77  
    78  // XPos returns the corresponding XPos for the given pos,
    79  // adding pos to t if necessary.
    80  func (t *PosTable) XPos(pos Pos) XPos
    81  
    82  // Pos returns the corresponding Pos for the given p.
    83  // If p cannot be translated via t, the function panics.
    84  func (t *PosTable) Pos(p XPos) Pos
    85  
    86  // FileTable returns a slice of all files used to build this package.
    87  func (t *PosTable) FileTable() []string