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