1
2
3
4
5 package ir
6
7 import (
8 "cmd/compile/internal/base"
9 "cmd/compile/internal/types"
10 "cmd/internal/src"
11 )
12
13
14
15
16 type typeNode struct {
17 miniNode
18 typ *types.Type
19 }
20
21 func newTypeNode(typ *types.Type) *typeNode {
22 n := &typeNode{typ: typ}
23 n.pos = src.NoXPos
24 n.op = OTYPE
25 n.SetTypecheck(1)
26 return n
27 }
28
29 func (n *typeNode) Type() *types.Type { return n.typ }
30 func (n *typeNode) Sym() *types.Sym { return n.typ.Sym() }
31
32
33 func TypeNode(t *types.Type) Node {
34 if n := t.Obj(); n != nil {
35 if n.Type() != t {
36 base.Fatalf("type skew: %v has type %v, but expected %v", n, n.Type(), t)
37 }
38 return n.(*Name)
39 }
40 return newTypeNode(t)
41 }
42
43
44
45 type DynamicType struct {
46 miniExpr
47
48
49
50
51
52 RType Node
53
54
55
56
57
58
59
60
61 ITab Node
62 }
63
64 func NewDynamicType(pos src.XPos, rtype Node) *DynamicType {
65 n := &DynamicType{RType: rtype}
66 n.pos = pos
67 n.op = ODYNAMICTYPE
68 return n
69 }
70
71
72 func (dt *DynamicType) ToStatic() Node {
73 if dt.Typecheck() == 0 {
74 base.Fatalf("missing typecheck: %v", dt)
75 }
76 if dt.RType != nil && dt.RType.Op() == OADDR {
77 addr := dt.RType.(*AddrExpr)
78 if addr.X.Op() == OLINKSYMOFFSET {
79 return TypeNode(dt.Type())
80 }
81 }
82 if dt.ITab != nil && dt.ITab.Op() == OADDR {
83 addr := dt.ITab.(*AddrExpr)
84 if addr.X.Op() == OLINKSYMOFFSET {
85 return TypeNode(dt.Type())
86 }
87 }
88 return nil
89 }
90
View as plain text