@@ -93,24 +93,30 @@ type PosBase struct {
93
93
pos Pos
94
94
filename string
95
95
line , col uint32
96
+ trimmed bool // whether -trimpath has been applied
96
97
}
97
98
98
99
// NewFileBase returns a new PosBase for the given filename.
99
100
// A file PosBase's position is relative to itself, with the
100
101
// position being filename:1:1.
101
102
func NewFileBase (filename string ) * PosBase {
102
- base := & PosBase {MakePos (nil , linebase , colbase ), filename , linebase , colbase }
103
- base .pos .base = base
104
- return base
103
+ return NewTrimmedFileBase (filename , false )
104
+ }
105
+
106
+ // NewTrimmedFileBase is like NewFileBase, but allows specifying Trimmed.
107
+ func NewTrimmedFileBase (filename string , trimmed bool ) * PosBase {
108
+ base := & PosBase {MakePos (nil , linebase , colbase ), filename , linebase , colbase , trimmed }
109
+ base .pos .base = base
110
+ return base
105
111
}
106
112
107
113
// NewLineBase returns a new PosBase for a line directive "line filename:line:col"
108
114
// relative to pos, which is the position of the character immediately following
109
115
// the comment containing the line directive. For a directive in a line comment,
110
116
// that position is the beginning of the next line (i.e., the newline character
111
117
// belongs to the line comment).
112
- func NewLineBase (pos Pos , filename string , line , col uint ) * PosBase {
113
- return & PosBase {pos , filename , sat32 (line ), sat32 (col )}
118
+ func NewLineBase (pos Pos , filename string , trimmed bool , line , col uint ) * PosBase {
119
+ return & PosBase {pos , filename , sat32 (line ), sat32 (col ), trimmed }
114
120
}
115
121
116
122
func (base * PosBase ) IsFileBase () bool {
@@ -148,6 +154,13 @@ func (base *PosBase) Col() uint {
148
154
return uint (base .col )
149
155
}
150
156
157
+ func (base * PosBase ) Trimmed () bool {
158
+ if base == nil {
159
+ return false
160
+ }
161
+ return base .trimmed
162
+ }
163
+
151
164
func sat32 (x uint ) uint32 {
152
165
if x > PosMax {
153
166
return PosMax
0 commit comments