1
2
3
4
5
6
7
8 package gcimporter
9
10 import (
11 "fmt"
12 "go/token"
13 "go/types"
14 "sync"
15 )
16
17 func errorf(format string, args ...any) {
18 panic(fmt.Sprintf(format, args...))
19 }
20
21 const deltaNewFile = -64
22
23
24 type fakeFileSet struct {
25 fset *token.FileSet
26 files map[string]*fileInfo
27 }
28
29 type fileInfo struct {
30 file *token.File
31 lastline int
32 }
33
34 const maxlines = 64 * 1024
35
36 func (s *fakeFileSet) pos(file string, line, column int) token.Pos {
37 _ = column
38
39
40
41
42
43 f := s.files[file]
44 if f == nil {
45 f = &fileInfo{file: s.fset.AddFile(file, -1, maxlines)}
46 s.files[file] = f
47 }
48 if line > maxlines {
49 line = 1
50 }
51 if line > f.lastline {
52 f.lastline = line
53 }
54
55
56 return token.Pos(f.file.Base() + line - 1)
57 }
58
59 func (s *fakeFileSet) setLines() {
60 fakeLinesOnce.Do(func() {
61 fakeLines = make([]int, maxlines)
62 for i := range fakeLines {
63 fakeLines[i] = i
64 }
65 })
66 for _, f := range s.files {
67 f.file.SetLines(fakeLines[:f.lastline])
68 }
69 }
70
71 var (
72 fakeLines []int
73 fakeLinesOnce sync.Once
74 )
75
76 func chanDir(d int) types.ChanDir {
77
78 switch d {
79 case 1 :
80 return types.RecvOnly
81 case 2 :
82 return types.SendOnly
83 case 3 :
84 return types.SendRecv
85 default:
86 errorf("unexpected channel dir %d", d)
87 return 0
88 }
89 }
90
View as plain text