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

Method IntegerNode

compiler/compiler.go:332–390  ·  view source on GitHub ↗
(node *ast.IntegerNode)

Source from the content-addressed store, hash-verified

330}
331
332func (c *compiler) IntegerNode(node *ast.IntegerNode) {
333 t := node.Type()
334 if t == nil {
335 c.emitPush(node.Value)
336 return
337 }
338 switch t.Kind() {
339 case reflect.Float32:
340 c.emitPush(float32(node.Value))
341 case reflect.Float64:
342 c.emitPush(float64(node.Value))
343 case reflect.Int:
344 c.emitPush(node.Value)
345 case reflect.Int8:
346 if node.Value > math.MaxInt8 || node.Value < math.MinInt8 {
347 panic(fmt.Sprintf("constant %d overflows int8", node.Value))
348 }
349 c.emitPush(int8(node.Value))
350 case reflect.Int16:
351 if node.Value > math.MaxInt16 || node.Value < math.MinInt16 {
352 panic(fmt.Sprintf("constant %d overflows int16", node.Value))
353 }
354 c.emitPush(int16(node.Value))
355 case reflect.Int32:
356 if node.Value > math.MaxInt32 || node.Value < math.MinInt32 {
357 panic(fmt.Sprintf("constant %d overflows int32", node.Value))
358 }
359 c.emitPush(int32(node.Value))
360 case reflect.Int64:
361 c.emitPush(int64(node.Value))
362 case reflect.Uint:
363 if node.Value < 0 {
364 panic(fmt.Sprintf("constant %d overflows uint", node.Value))
365 }
366 c.emitPush(uint(node.Value))
367 case reflect.Uint8:
368 if node.Value > math.MaxUint8 || node.Value < 0 {
369 panic(fmt.Sprintf("constant %d overflows uint8", node.Value))
370 }
371 c.emitPush(uint8(node.Value))
372 case reflect.Uint16:
373 if node.Value > math.MaxUint16 || node.Value < 0 {
374 panic(fmt.Sprintf("constant %d overflows uint16", node.Value))
375 }
376 c.emitPush(uint16(node.Value))
377 case reflect.Uint32:
378 if node.Value < 0 {
379 panic(fmt.Sprintf("constant %d overflows uint32", node.Value))
380 }
381 c.emitPush(uint32(node.Value))
382 case reflect.Uint64:
383 if node.Value < 0 {
384 panic(fmt.Sprintf("constant %d overflows uint64", node.Value))
385 }
386 c.emitPush(uint64(node.Value))
387 default:
388 c.emitPush(node.Value)
389 }

Callers 1

compileMethod · 0.95

Calls 3

emitPushMethod · 0.95
SprintfMethod · 0.80
TypeMethod · 0.65

Tested by

no test coverage detected