@@ -14,18 +14,44 @@ import (
14
14
"cmd/internal/src"
15
15
)
16
16
17
+ // NewBool returns an OLITERAL representing b as an untyped boolean.
17
18
func NewBool (pos src.XPos , b bool ) Node {
18
- return NewBasicLit (pos , constant .MakeBool (b ))
19
+ return NewBasicLit (pos , types . UntypedBool , constant .MakeBool (b ))
19
20
}
20
21
22
+ // NewInt returns an OLITERAL representing v as an untyped integer.
21
23
func NewInt (pos src.XPos , v int64 ) Node {
22
- return NewBasicLit (pos , constant .MakeInt64 (v ))
24
+ return NewBasicLit (pos , types . UntypedInt , constant .MakeInt64 (v ))
23
25
}
24
26
27
+ // NewString returns an OLITERAL representing s as an untyped string.
25
28
func NewString (pos src.XPos , s string ) Node {
26
- return NewBasicLit (pos , constant .MakeString (s ))
29
+ return NewBasicLit (pos , types . UntypedString , constant .MakeString (s ))
27
30
}
28
31
32
+ // NewOne returns an OLITERAL representing 1 with the given type.
33
+ func NewOne (pos src.XPos , typ * types.Type ) Node {
34
+ var val constant.Value
35
+ switch {
36
+ case typ .IsInteger ():
37
+ val = intOne
38
+ case typ .IsFloat ():
39
+ val = floatOne
40
+ case typ .IsComplex ():
41
+ val = complexOne
42
+ default :
43
+ base .FatalfAt (pos , "%v cannot represent 1" , typ )
44
+ }
45
+
46
+ return NewBasicLit (pos , typ , val )
47
+ }
48
+
49
+ var (
50
+ intOne = constant .MakeInt64 (1 )
51
+ floatOne = constant .ToFloat (intOne )
52
+ complexOne = constant .ToComplex (intOne )
53
+ )
54
+
29
55
const (
30
56
// Maximum size in bits for big.Ints before signaling
31
57
// overflow and also mantissa precision for big.Floats.
0 commit comments