1
2
3
4
5
6
7 package gcimporter
8
9 import (
10 "fmt"
11 "go/token"
12 "go/types"
13 "sync"
14 )
15
16 func errorf(format string, args ...interface{}) {
17 panic(fmt.Sprintf(format, args...))
18 }
19
20
21
22
23 const deltaNewFile = -64
24
25
26 type fakeFileSet struct {
27 fset *token.FileSet
28 files map[string]*token.File
29 }
30
31 func (s *fakeFileSet) pos(file string, line, column int) token.Pos {
32
33
34
35
36 const maxlines = 64 * 1024
37 f := s.files[file]
38 if f == nil {
39 f = s.fset.AddFile(file, -1, maxlines)
40 s.files[file] = f
41
42
43 fakeLinesOnce.Do(func() {
44 fakeLines = make([]int, maxlines)
45 for i := range fakeLines {
46 fakeLines[i] = i
47 }
48 })
49 f.SetLines(fakeLines)
50 }
51
52 if line > maxlines {
53 line = 1
54 }
55
56
57
58 return f.Pos(line - 1)
59 }
60
61 var (
62 fakeLines []int
63 fakeLinesOnce sync.Once
64 )
65
66 func chanDir(d int) types.ChanDir {
67
68 switch d {
69 case 1 :
70 return types.RecvOnly
71 case 2 :
72 return types.SendOnly
73 case 3 :
74 return types.SendRecv
75 default:
76 errorf("unexpected channel dir %d", d)
77 return 0
78 }
79 }
80
81 var predeclared = []types.Type{
82
83 types.Typ[types.Bool],
84 types.Typ[types.Int],
85 types.Typ[types.Int8],
86 types.Typ[types.Int16],
87 types.Typ[types.Int32],
88 types.Typ[types.Int64],
89 types.Typ[types.Uint],
90 types.Typ[types.Uint8],
91 types.Typ[types.Uint16],
92 types.Typ[types.Uint32],
93 types.Typ[types.Uint64],
94 types.Typ[types.Uintptr],
95 types.Typ[types.Float32],
96 types.Typ[types.Float64],
97 types.Typ[types.Complex64],
98 types.Typ[types.Complex128],
99 types.Typ[types.String],
100
101
102 types.Universe.Lookup("byte").Type(),
103 types.Universe.Lookup("rune").Type(),
104
105
106 types.Universe.Lookup("error").Type(),
107
108
109 types.Typ[types.UntypedBool],
110 types.Typ[types.UntypedInt],
111 types.Typ[types.UntypedRune],
112 types.Typ[types.UntypedFloat],
113 types.Typ[types.UntypedComplex],
114 types.Typ[types.UntypedString],
115 types.Typ[types.UntypedNil],
116
117
118 types.Typ[types.UnsafePointer],
119
120
121 types.Typ[types.Invalid],
122
123
124 anyType{},
125 }
126
127 type anyType struct{}
128
129 func (t anyType) Underlying() types.Type { return t }
130 func (t anyType) String() string { return "any" }
131
View as plain text