| 1 | package ctyscip-go gomod github.com/zclconf/go-cty . `github.com/zclconf/go-cty/cty`/ |
| 2 | |
| 3 | import "math/bigscip-go gomod github.com/golang/go/src go1.18 `math/big`/" |
| 4 | |
| 5 | // primitiveType is the hidden implementation of the various primitive types |
| 6 | // that are exposed as variables in this package. |
| 7 | type primitiveTypescip-go gomod github.com/zclconf/go-cty . `github.com/zclconf/go-cty/cty`/primitiveType# struct { |
| 8 | typeImplSigilscip-go gomod github.com/zclconf/go-cty . `github.com/zclconf/go-cty/cty`/primitiveType#typeImplSigil. |
| 9 | Kindscip-go gomod github.com/zclconf/go-cty . `github.com/zclconf/go-cty/cty`/primitiveType#Kind. primitiveTypeKindscip-go gomod github.com/zclconf/go-cty . `github.com/zclconf/go-cty/cty`/primitiveTypeKind# |
| 10 | } |
| 11 | |
| 12 | type primitiveTypeKindscip-go gomod github.com/zclconf/go-cty . `github.com/zclconf/go-cty/cty`/primitiveTypeKind# byte |
| 13 | |
| 14 | const ( |
| 15 | primitiveTypeBoolscip-go gomod github.com/zclconf/go-cty . `github.com/zclconf/go-cty/cty`/primitiveTypeBool. primitiveTypeKindscip-go gomod github.com/zclconf/go-cty . `github.com/zclconf/go-cty/cty`/primitiveTypeKind# = 'B' |
| 16 | primitiveTypeNumberscip-go gomod github.com/zclconf/go-cty . `github.com/zclconf/go-cty/cty`/primitiveTypeNumber. primitiveTypeKindscip-go gomod github.com/zclconf/go-cty . `github.com/zclconf/go-cty/cty`/primitiveTypeKind# = 'N' |
| 17 | primitiveTypeStringscip-go gomod github.com/zclconf/go-cty . `github.com/zclconf/go-cty/cty`/primitiveTypeString. primitiveTypeKindscip-go gomod github.com/zclconf/go-cty . `github.com/zclconf/go-cty/cty`/primitiveTypeKind# = 'S' |
| 18 | ) |
| 19 | |
| 20 | func (t primitiveTypescip-go gomod github.com/zclconf/go-cty . `github.com/zclconf/go-cty/cty`/primitiveType#) Equalsscip-go gomod github.com/zclconf/go-cty . `github.com/zclconf/go-cty/cty`/primitiveType#Equals().(other Typescip-go gomod github.com/zclconf/go-cty . `github.com/zclconf/go-cty/cty`/Type#) bool { |
| 21 | if otherP, ok := other.typeImplscip-go gomod github.com/zclconf/go-cty . `github.com/zclconf/go-cty/cty`/Type#typeImpl..(primitiveTypescip-go gomod github.com/zclconf/go-cty . `github.com/zclconf/go-cty/cty`/primitiveType#); ok { |
| 22 | return otherP.Kindscip-go gomod github.com/zclconf/go-cty . `github.com/zclconf/go-cty/cty`/primitiveType#Kind. == t.Kindscip-go gomod github.com/zclconf/go-cty . `github.com/zclconf/go-cty/cty`/primitiveType#Kind. |
| 23 | } |
| 24 | return false |
| 25 | } |
| 26 | |
| 27 | func (t primitiveTypescip-go gomod github.com/zclconf/go-cty . `github.com/zclconf/go-cty/cty`/primitiveType#) FriendlyNamescip-go gomod github.com/zclconf/go-cty . `github.com/zclconf/go-cty/cty`/primitiveType#FriendlyName().(mode friendlyTypeNameModescip-go gomod github.com/zclconf/go-cty . `github.com/zclconf/go-cty/cty`/friendlyTypeNameMode#) string { |
| 28 | switch t.Kindscip-go gomod github.com/zclconf/go-cty . `github.com/zclconf/go-cty/cty`/primitiveType#Kind. { |
| 29 | case primitiveTypeBoolscip-go gomod github.com/zclconf/go-cty . `github.com/zclconf/go-cty/cty`/primitiveTypeBool.: |
| 30 | return "bool" |
| 31 | case primitiveTypeNumberscip-go gomod github.com/zclconf/go-cty . `github.com/zclconf/go-cty/cty`/primitiveTypeNumber.: |
| 32 | return "number" |
| 33 | case primitiveTypeStringscip-go gomod github.com/zclconf/go-cty . `github.com/zclconf/go-cty/cty`/primitiveTypeString.: |
| 34 | return "string" |
| 35 | default: |
| 36 | // should never happen |
| 37 | panic("invalid primitive type") |
| 38 | } |
| 39 | } |
| 40 | |
| 41 | func (t primitiveTypescip-go gomod github.com/zclconf/go-cty . `github.com/zclconf/go-cty/cty`/primitiveType#) GoStringscip-go gomod github.com/zclconf/go-cty . `github.com/zclconf/go-cty/cty`/primitiveType#GoString().() string { |
| 42 | switch t.Kindscip-go gomod github.com/zclconf/go-cty . `github.com/zclconf/go-cty/cty`/primitiveType#Kind. { |
| 43 | case primitiveTypeBoolscip-go gomod github.com/zclconf/go-cty . `github.com/zclconf/go-cty/cty`/primitiveTypeBool.: |
| 44 | return "cty.Bool" |
| 45 | case primitiveTypeNumberscip-go gomod github.com/zclconf/go-cty . `github.com/zclconf/go-cty/cty`/primitiveTypeNumber.: |
| 46 | return "cty.Number" |
| 47 | case primitiveTypeStringscip-go gomod github.com/zclconf/go-cty . `github.com/zclconf/go-cty/cty`/primitiveTypeString.: |
| 48 | return "cty.String" |
| 49 | default: |
| 50 | // should never happen |
| 51 | panic("invalid primitive type") |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | // rawNumberEqual is our cty-specific definition of whether two big floats |
| 56 | // underlying cty.Number are "equal" for the purposes of the Value.Equals and |
| 57 | // Value.RawEquals methods. |
| 58 | // |
| 59 | // The built-in equality for big.Float is a direct comparison of the mantissa |
| 60 | // bits and the exponent, but that's too precise a check for cty because we |
| 61 | // routinely send numbers through decimal approximations and back and so |
| 62 | // we only promise to accurately represent the subset of binary floating point |
| 63 | // numbers that can be derived from a decimal string representation. |
| 64 | // |
| 65 | // In respect of the fact that cty only tries to preserve numbers that can |
| 66 | // reasonably be written in JSON documents, we use the string representation of |
| 67 | // a decimal approximation of the number as our comparison, relying on the |
| 68 | // big.Float type's heuristic for discarding extraneous mantissa bits that seem |
| 69 | // likely to only be there as a result of an earlier decimal-to-binary |
| 70 | // approximation during parsing, e.g. in ParseNumberVal. |
| 71 | func rawNumberEqualscip-go gomod github.com/zclconf/go-cty . `github.com/zclconf/go-cty/cty`/rawNumberEqual().(a, b *bigscip-go gomod github.com/golang/go/src go1.18 `math/big`/.Floatscip-go gomod github.com/golang/go/src go1.18 `math/big`/Float#) bool { |
| 72 | switch { |
| 73 | case (a == nil) != (b == nil): |
| 74 | return false |
| 75 | case a == nil: // b == nil too then, due to previous case |
| 76 | return true |
| 77 | case a.Signscip-go gomod github.com/golang/go/src go1.18 `math/big`/Float#Sign().() != b.Signscip-go gomod github.com/golang/go/src go1.18 `math/big`/Float#Sign().(): |
| 78 | return false |
| 79 | default: |
| 80 | // This format and precision matches that used by cty/json.Marshal, |
| 81 | // and thus achieves our definition of "two numbers are equal if |
| 82 | // we'd use the same JSON serialization for both of them". |
| 83 | const format = 'f' |
| 84 | const prec = -1 |
| 85 | aStr := a.Textscip-go gomod github.com/golang/go/src go1.18 `math/big`/Float#Text().(format, prec) |
| 86 | bStr := b.Textscip-go gomod github.com/golang/go/src go1.18 `math/big`/Float#Text().(format, prec) |
| 87 | |
| 88 | // The one exception to our rule about equality-by-stringification is |
| 89 | // negative zero, because we want -0 to always be equal to +0. |
| 90 | const posZero = "0" |
| 91 | const negZero = "-0" |
| 92 | if aStr == negZero { |
| 93 | aStr = posZero |
| 94 | } |
| 95 | if bStr == negZero { |
| 96 | bStr = posZero |
| 97 | } |
| 98 | return aStr == bStr |
| 99 | } |
| 100 | } |
| 101 | |
| 102 | // Number is the numeric type. Number values are arbitrary-precision |
| 103 | // decimal numbers, which can then be converted into Go's various numeric |
| 104 | // types only if they are in the appropriate range. |
| 105 | var Numberscip-go gomod github.com/zclconf/go-cty . `github.com/zclconf/go-cty/cty`/Number. Typescip-go gomod github.com/zclconf/go-cty . `github.com/zclconf/go-cty/cty`/Type# |
| 106 | |
| 107 | // String is the string type. String values are sequences of unicode codepoints |
| 108 | // encoded internally as UTF-8. |
| 109 | var Stringscip-go gomod github.com/zclconf/go-cty . `github.com/zclconf/go-cty/cty`/String. Typescip-go gomod github.com/zclconf/go-cty . `github.com/zclconf/go-cty/cty`/Type# |
| 110 | |
| 111 | // Bool is the boolean type. The two values of this type are True and False. |
| 112 | var Boolscip-go gomod github.com/zclconf/go-cty . `github.com/zclconf/go-cty/cty`/Bool. Typescip-go gomod github.com/zclconf/go-cty . `github.com/zclconf/go-cty/cty`/Type# |
| 113 | |
| 114 | // True is the truthy value of type Bool |
| 115 | var Truescip-go gomod github.com/zclconf/go-cty . `github.com/zclconf/go-cty/cty`/True. Valuescip-go gomod github.com/zclconf/go-cty . `github.com/zclconf/go-cty/cty`/Value# |
| 116 | |
| 117 | // False is the falsey value of type Bool |
| 118 | var Falsescip-go gomod github.com/zclconf/go-cty . `github.com/zclconf/go-cty/cty`/False. Valuescip-go gomod github.com/zclconf/go-cty . `github.com/zclconf/go-cty/cty`/Value# |
| 119 | |
| 120 | // Zero is a number value representing exactly zero. |
| 121 | var Zeroscip-go gomod github.com/zclconf/go-cty . `github.com/zclconf/go-cty/cty`/Zero. Valuescip-go gomod github.com/zclconf/go-cty . `github.com/zclconf/go-cty/cty`/Value# |
| 122 | |
| 123 | // PositiveInfinity is a Number value representing positive infinity |
| 124 | var PositiveInfinityscip-go gomod github.com/zclconf/go-cty . `github.com/zclconf/go-cty/cty`/PositiveInfinity. Valuescip-go gomod github.com/zclconf/go-cty . `github.com/zclconf/go-cty/cty`/Value# |
| 125 | |
| 126 | // NegativeInfinity is a Number value representing negative infinity |
| 127 | var NegativeInfinityscip-go gomod github.com/zclconf/go-cty . `github.com/zclconf/go-cty/cty`/NegativeInfinity. Valuescip-go gomod github.com/zclconf/go-cty . `github.com/zclconf/go-cty/cty`/Value# |
| 128 | |
| 129 | func initscip-go gomod github.com/zclconf/go-cty . `github.com/zclconf/go-cty/cty`/init().() { |
| 130 | Numberscip-go gomod github.com/zclconf/go-cty . `github.com/zclconf/go-cty/cty`/Number. = Typescip-go gomod github.com/zclconf/go-cty . `github.com/zclconf/go-cty/cty`/Type#{ |
| 131 | primitiveTypescip-go gomod github.com/zclconf/go-cty . `github.com/zclconf/go-cty/cty`/primitiveType#{Kindscip-go gomod github.com/zclconf/go-cty . `github.com/zclconf/go-cty/cty`/primitiveType#Kind.: primitiveTypeNumberscip-go gomod github.com/zclconf/go-cty . `github.com/zclconf/go-cty/cty`/primitiveTypeNumber.}, |
| 132 | } |
| 133 | Stringscip-go gomod github.com/zclconf/go-cty . `github.com/zclconf/go-cty/cty`/String. = Typescip-go gomod github.com/zclconf/go-cty . `github.com/zclconf/go-cty/cty`/Type#{ |
| 134 | primitiveTypescip-go gomod github.com/zclconf/go-cty . `github.com/zclconf/go-cty/cty`/primitiveType#{Kindscip-go gomod github.com/zclconf/go-cty . `github.com/zclconf/go-cty/cty`/primitiveType#Kind.: primitiveTypeStringscip-go gomod github.com/zclconf/go-cty . `github.com/zclconf/go-cty/cty`/primitiveTypeString.}, |
| 135 | } |
| 136 | Boolscip-go gomod github.com/zclconf/go-cty . `github.com/zclconf/go-cty/cty`/Bool. = Typescip-go gomod github.com/zclconf/go-cty . `github.com/zclconf/go-cty/cty`/Type#{ |
| 137 | primitiveTypescip-go gomod github.com/zclconf/go-cty . `github.com/zclconf/go-cty/cty`/primitiveType#{Kindscip-go gomod github.com/zclconf/go-cty . `github.com/zclconf/go-cty/cty`/primitiveType#Kind.: primitiveTypeBoolscip-go gomod github.com/zclconf/go-cty . `github.com/zclconf/go-cty/cty`/primitiveTypeBool.}, |
| 138 | } |
| 139 | Truescip-go gomod github.com/zclconf/go-cty . `github.com/zclconf/go-cty/cty`/True. = Valuescip-go gomod github.com/zclconf/go-cty . `github.com/zclconf/go-cty/cty`/Value#{ |
| 140 | tyscip-go gomod github.com/zclconf/go-cty . `github.com/zclconf/go-cty/cty`/Value#ty.: Boolscip-go gomod github.com/zclconf/go-cty . `github.com/zclconf/go-cty/cty`/Bool., |
| 141 | vscip-go gomod github.com/zclconf/go-cty . `github.com/zclconf/go-cty/cty`/Value#v.: true, |
| 142 | } |
| 143 | Falsescip-go gomod github.com/zclconf/go-cty . `github.com/zclconf/go-cty/cty`/False. = Valuescip-go gomod github.com/zclconf/go-cty . `github.com/zclconf/go-cty/cty`/Value#{ |
| 144 | tyscip-go gomod github.com/zclconf/go-cty . `github.com/zclconf/go-cty/cty`/Value#ty.: Boolscip-go gomod github.com/zclconf/go-cty . `github.com/zclconf/go-cty/cty`/Bool., |
| 145 | vscip-go gomod github.com/zclconf/go-cty . `github.com/zclconf/go-cty/cty`/Value#v.: false, |
| 146 | } |
| 147 | Zeroscip-go gomod github.com/zclconf/go-cty . `github.com/zclconf/go-cty/cty`/Zero. = Valuescip-go gomod github.com/zclconf/go-cty . `github.com/zclconf/go-cty/cty`/Value#{ |
| 148 | tyscip-go gomod github.com/zclconf/go-cty . `github.com/zclconf/go-cty/cty`/Value#ty.: Numberscip-go gomod github.com/zclconf/go-cty . `github.com/zclconf/go-cty/cty`/Number., |
| 149 | vscip-go gomod github.com/zclconf/go-cty . `github.com/zclconf/go-cty/cty`/Value#v.: bigscip-go gomod github.com/golang/go/src go1.18 `math/big`/.NewFloatscip-go gomod github.com/golang/go/src go1.18 `math/big`/NewFloat().(0), |
| 150 | } |
| 151 | PositiveInfinityscip-go gomod github.com/zclconf/go-cty . `github.com/zclconf/go-cty/cty`/PositiveInfinity. = Valuescip-go gomod github.com/zclconf/go-cty . `github.com/zclconf/go-cty/cty`/Value#{ |
| 152 | tyscip-go gomod github.com/zclconf/go-cty . `github.com/zclconf/go-cty/cty`/Value#ty.: Numberscip-go gomod github.com/zclconf/go-cty . `github.com/zclconf/go-cty/cty`/Number., |
| 153 | vscip-go gomod github.com/zclconf/go-cty . `github.com/zclconf/go-cty/cty`/Value#v.: (&bigscip-go gomod github.com/golang/go/src go1.18 `math/big`/.Floatscip-go gomod github.com/golang/go/src go1.18 `math/big`/Float#{}).SetInfscip-go gomod github.com/golang/go/src go1.18 `math/big`/Float#SetInf().(false), |
| 154 | } |
| 155 | NegativeInfinityscip-go gomod github.com/zclconf/go-cty . `github.com/zclconf/go-cty/cty`/NegativeInfinity. = Valuescip-go gomod github.com/zclconf/go-cty . `github.com/zclconf/go-cty/cty`/Value#{ |
| 156 | tyscip-go gomod github.com/zclconf/go-cty . `github.com/zclconf/go-cty/cty`/Value#ty.: Numberscip-go gomod github.com/zclconf/go-cty . `github.com/zclconf/go-cty/cty`/Number., |
| 157 | vscip-go gomod github.com/zclconf/go-cty . `github.com/zclconf/go-cty/cty`/Value#v.: (&bigscip-go gomod github.com/golang/go/src go1.18 `math/big`/.Floatscip-go gomod github.com/golang/go/src go1.18 `math/big`/Float#{}).SetInfscip-go gomod github.com/golang/go/src go1.18 `math/big`/Float#SetInf().(true), |
| 158 | } |
| 159 | } |
| 160 | |
| 161 | // IsPrimitiveType returns true if and only if the reciever is a primitive |
| 162 | // type, which means it's either number, string, or bool. Any two primitive |
| 163 | // types can be safely compared for equality using the standard == operator |
| 164 | // without panic, which is not a guarantee that holds for all types. Primitive |
| 165 | // types can therefore also be used in switch statements. |
| 166 | func (t Typescip-go gomod github.com/zclconf/go-cty . `github.com/zclconf/go-cty/cty`/Type#) IsPrimitiveTypescip-go gomod github.com/zclconf/go-cty . `github.com/zclconf/go-cty/cty`/Type#IsPrimitiveType().() bool { |
| 167 | _, ok := t.typeImplscip-go gomod github.com/zclconf/go-cty . `github.com/zclconf/go-cty/cty`/Type#typeImpl..(primitiveTypescip-go gomod github.com/zclconf/go-cty . `github.com/zclconf/go-cty/cty`/primitiveType#) |
| 168 | return ok |
| 169 | } |