NewSourceInfo creates a simple SourceInfo object from an input common.Source value.
(src common.Source)
| 191 | |
| 192 | // NewSourceInfo creates a simple SourceInfo object from an input common.Source value. |
| 193 | func NewSourceInfo(src common.Source) *SourceInfo { |
| 194 | var lineOffsets []int32 |
| 195 | var desc string |
| 196 | baseLine := int32(0) |
| 197 | baseCol := int32(0) |
| 198 | if src != nil { |
| 199 | desc = src.Description() |
| 200 | lineOffsets = src.LineOffsets() |
| 201 | // Determine whether the source metadata should be computed relative |
| 202 | // to a base line and column value. This can be determined by requesting |
| 203 | // the location for offset 0 from the source object. |
| 204 | if loc, found := src.OffsetLocation(0); found { |
| 205 | baseLine = int32(loc.Line()) - 1 |
| 206 | baseCol = int32(loc.Column()) |
| 207 | } |
| 208 | } |
| 209 | return &SourceInfo{ |
| 210 | desc: desc, |
| 211 | lines: lineOffsets, |
| 212 | baseLine: baseLine, |
| 213 | baseCol: baseCol, |
| 214 | offsetRanges: make(map[int64]OffsetRange), |
| 215 | macroCalls: make(map[int64]Expr), |
| 216 | } |
| 217 | } |
| 218 | |
| 219 | // CopySourceInfo creates a deep copy of the MacroCalls within the input SourceInfo. |
| 220 | // |