1
2
3
4
5 package types
6
7 import "cmd/compile/internal/base"
8
9
10
11 type AlgKind int8
12
13
14
15 const (
16 AUNK AlgKind = iota
17 ANOEQ
18 ANOALG
19 AMEM
20 AMEM0
21 AMEM8
22 AMEM16
23 AMEM32
24 AMEM64
25 AMEM128
26 ASTRING
27 AINTER
28 ANILINTER
29 AFLOAT32
30 AFLOAT64
31 ACPLX64
32 ACPLX128
33 ASPECIAL
34 )
35
36
37
38 var algPriority = [ASPECIAL + 1]int8{ASPECIAL: 1, ANOEQ: 2, ANOALG: 3, AMEM: -1}
39
40
41
42 func (t *Type) setAlg(a AlgKind) {
43 if t.alg == AUNK {
44 base.Fatalf("setAlg(%v,%s) starting with unknown priority", t, a)
45 }
46 if algPriority[a] > algPriority[t.alg] {
47 t.alg = a
48 } else if a != t.alg && algPriority[a] == algPriority[t.alg] {
49 base.Fatalf("ambiguous priority %s and %s", a, t.alg)
50 }
51 }
52
53
54 func AlgType(t *Type) AlgKind {
55 CalcSize(t)
56 return t.alg
57 }
58
59
60
61 func TypeHasNoAlg(t *Type) bool {
62 return AlgType(t) == ANOALG
63 }
64
65
66 func IsComparable(t *Type) bool {
67 a := AlgType(t)
68 return a != ANOEQ && a != ANOALG
69 }
70
71
72 func IncomparableField(t *Type) *Field {
73 for _, f := range t.Fields() {
74 if !IsComparable(f.Type) {
75 return f
76 }
77 }
78 return nil
79 }
80
81
82
83 func IsPaddedField(t *Type, i int) bool {
84 if !t.IsStruct() {
85 base.Fatalf("IsPaddedField called non-struct %v", t)
86 }
87 end := t.width
88 if i+1 < t.NumFields() {
89 end = t.Field(i + 1).Offset
90 }
91 return t.Field(i).End() != end
92 }
93
View as plain text