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