MCPcopy
hub / github.com/expr-lang/expr / FromType

Method FromType

checker/nature/nature.go:118–148  ·  view source on GitHub ↗

FromType returns a Nature describing a value of type "t". If "t" is nil then it returns a Nature describing an unknown value.

(t reflect.Type)

Source from the content-addressed store, hash-verified

116// FromType returns a Nature describing a value of type "t". If "t" is nil then
117// it returns a Nature describing an unknown value.
118func (c *Cache) FromType(t reflect.Type) Nature {
119 if t == nil {
120 return Nature{}
121 }
122 var td *TypeData
123 var isInteger, isFloat bool
124 k := t.Kind()
125 switch k {
126 case reflect.Struct:
127 // c can be nil when we call the package function FromType, which uses a
128 // nil *Cache to call this method.
129 if c != nil {
130 return c.getStruct(t)
131 }
132 fallthrough
133 case reflect.Func:
134 td = new(TypeData)
135 case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64,
136 reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr:
137 _, isInteger = builtinInt[t]
138 case reflect.Float32, reflect.Float64:
139 _, isFloat = builtinFloat[t]
140 }
141 return Nature{
142 Type: t,
143 Kind: k,
144 TypeData: td,
145 IsInteger: isInteger,
146 IsFloat: isFloat,
147 }
148}
149
150func (c *Cache) getStruct(t reflect.Type) Nature {
151 if c.structs == nil {

Callers 15

NatureOfMethod · 0.95
FromTypeFunction · 0.95
EnvWithCacheFunction · 0.80
visitMethod · 0.80
identMethod · 0.80
unaryNodeMethod · 0.80
binaryNodeMethod · 0.80
memberNodeMethod · 0.80
builtinNodeMethod · 0.80
checkFunctionMethod · 0.80
predicateNodeMethod · 0.80
conditionalNodeMethod · 0.80

Calls 1

getStructMethod · 0.95

Tested by

no test coverage detected