func GetRangeLines(f *token.File, Pos, End token.Pos, fileSize int) (lines []int, firstLineNum int) { lines = []int{} firstLineNum = -1 l := f.Line(Pos) for p := Pos; p <= End; p++ { if f.Line(p) > l { l = f.Line(p) if firstLineNum == -1 { firstLineNum = l } lines = append(lines, f.Offset(p)) } } print(End) print(" -> ") println(fileSize + f.Base() - 1) if (int(End) == fileSize+f.Base()-1) || f.Line(End+1) > l { lines = append(lines, f.Offset(End+1)) if firstLineNum == -1 { firstLineNum = f.Line(End + 1) } } return }
func GetLines(f *token.File) []int { lines := make([]int, 0, 20) l := -1 for i := f.Base(); i < f.Base()+f.Size(); i++ { if f.Line(token.Pos(i)) > l { l = f.Line(token.Pos(i)) lines = append(lines, f.Offset(token.Pos(i))) } } return lines }
func getRangeLinesAtLeastOne(f *token.File, Pos, End token.Pos, fileSize int) (lines []int, firstLineNum int) { lines = []int{} firstLineNum = -1 l := f.Line(Pos) for p := Pos; p <= End; p++ { if f.Line(p) > l { l = f.Line(p) if firstLineNum == -1 { firstLineNum = l } lines = append(lines, f.Offset(p)) } } if (int(End) == fileSize+f.Base()-1) || f.Line(End+1) > l { lines = append(lines, f.Offset(End+1)) if firstLineNum == -1 { firstLineNum = f.Line(End + 1) } } if firstLineNum < 0 { for p := End; ; p++ { if f.Line(p) > l { firstLineNum = l lines = append(lines, f.Offset(p)) break } } } return }
func printDecls(tf *token.File, f *ast.File) { for _, d := range f.Decls { fmt.Printf("> %d %d\n", tf.Offset(d.Pos()), tf.Offset(d.End())) } }