Class: Mirah::JVM::Types::FixnumLiteral

Inherits:
NarrowingType show all
Defined in:
lib/mirah/jvm/types/literals.rb

Constant Summary collapse

BYTE_RANGE =
range(java.lang.Byte)
SHORT_RANGE =
range(java.lang.Short)
INT_RANGE =
range(java.lang.Integer)
LONG_RANGE =
range(java.lang.Long)

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from NarrowingType

#hash, #narrow!

Constructor Details

#initialize(literal) ⇒ FixnumLiteral

Returns a new instance of FixnumLiteral.



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/mirah/jvm/types/literals.rb', line 52

def initialize(literal)
  default_type = case literal
  when INT_RANGE
    Int
  else
    Long
  end

  # TODO chars?
  # There's not really any way to tell if we should narrow to a char
  # or a byte/short.  I suppose we could try both, but that seems ugly.
  # Maybe it's the right thing to do though?
  narrowed_type = case literal
  when BYTE_RANGE
    Byte
  when SHORT_RANGE
    Short
  when INT_RANGE
    Int
  else
    Long
  end

  super(default_type, narrowed_type)
end

Class Method Details

.range(type) ⇒ Object



43
44
45
# File 'lib/mirah/jvm/types/literals.rb', line 43

def self.range(type)
  type::MIN_VALUE .. type::MAX_VALUE
end