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