...
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 ...interface{}) {
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
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
91 var predeclOnce sync.Once
92 var predecl []types.Type
93
94 func predeclared() []types.Type {
95 predeclOnce.Do(func() {
96
97
98 predecl = []types.Type{
99 types.Typ[types.Bool],
100 types.Typ[types.Int],
101 types.Typ[types.Int8],
102 types.Typ[types.Int16],
103 types.Typ[types.Int32],
104 types.Typ[types.Int64],
105 types.Typ[types.Uint],
106 types.Typ[types.Uint8],
107 types.Typ[types.Uint16],
108 types.Typ[types.Uint32],
109 types.Typ[types.Uint64],
110 types.Typ[types.Uintptr],
111 types.Typ[types.Float32],
112 types.Typ[types.Float64],
113 types.Typ[types.Complex64],
114 types.Typ[types.Complex128],
115 types.Typ[types.String],
116
117
118 types.Universe.Lookup("byte").Type(),
119 types.Universe.Lookup("rune").Type(),
120
121
122 types.Universe.Lookup("error").Type(),
123
124
125 types.Typ[types.UntypedBool],
126 types.Typ[types.UntypedInt],
127 types.Typ[types.UntypedRune],
128 types.Typ[types.UntypedFloat],
129 types.Typ[types.UntypedComplex],
130 types.Typ[types.UntypedString],
131 types.Typ[types.UntypedNil],
132
133
134 types.Typ[types.UnsafePointer],
135
136
137 types.Typ[types.Invalid],
138
139
140 anyType{},
141 }
142 predecl = append(predecl, additionalPredeclared()...)
143 })
144 return predecl
145 }
146
147 type anyType struct{}
148
149 func (t anyType) Underlying() types.Type { return t }
150 func (t anyType) String() string { return "any" }
151
View as plain text