1
2
3
4
5 package typecheck
6
7 import (
8 "go/constant"
9
10 "cmd/compile/internal/base"
11 "cmd/compile/internal/ir"
12 "cmd/compile/internal/types"
13 "cmd/internal/src"
14 )
15
16
17
18 func importalias(pos src.XPos, s *types.Sym, t *types.Type) *ir.Name {
19 return importobj(pos, s, ir.OTYPE, ir.PEXTERN, t)
20 }
21
22
23
24 func importconst(pos src.XPos, s *types.Sym, t *types.Type, val constant.Value) *ir.Name {
25 n := importobj(pos, s, ir.OLITERAL, ir.PEXTERN, t)
26 n.SetVal(val)
27 return n
28 }
29
30
31
32 func importfunc(pos src.XPos, s *types.Sym, t *types.Type) *ir.Name {
33 n := importobj(pos, s, ir.ONAME, ir.PFUNC, t)
34 n.Func = ir.NewFunc(pos)
35 n.Func.Nname = n
36 return n
37 }
38
39
40
41 func importobj(pos src.XPos, s *types.Sym, op ir.Op, ctxt ir.Class, t *types.Type) *ir.Name {
42 n := importsym(pos, s, op, ctxt)
43 n.SetType(t)
44 if ctxt == ir.PFUNC {
45 n.Sym().SetFunc(true)
46 }
47 return n
48 }
49
50 func importsym(pos src.XPos, s *types.Sym, op ir.Op, ctxt ir.Class) *ir.Name {
51 if n := s.PkgDef(); n != nil {
52 base.Fatalf("importsym of symbol that already exists: %v", n)
53 }
54
55 n := ir.NewDeclNameAt(pos, op, s)
56 n.Class = ctxt
57 s.SetPkgDef(n)
58 return n
59 }
60
61
62
63
64 func importtype(pos src.XPos, s *types.Sym) *ir.Name {
65 n := importsym(pos, s, ir.OTYPE, ir.PEXTERN)
66 n.SetType(types.NewNamed(n))
67 return n
68 }
69
70
71
72 func importvar(pos src.XPos, s *types.Sym, t *types.Type) *ir.Name {
73 return importobj(pos, s, ir.ONAME, ir.PEXTERN, t)
74 }
75
View as plain text