Class: Duby::JVM::Types::FixnumLiteral

Inherits:
NarrowingType show all
Defined in:
lib/duby/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)

Constants inherited from AST::TypeReference

AST::TypeReference::BlockType, AST::TypeReference::ErrorType, AST::TypeReference::NoType, AST::TypeReference::NullType, AST::TypeReference::UnreachableType

Instance Attribute Summary

Attributes inherited from Type

#inner_class

Attributes inherited from AST::TypeReference

#array, #meta

Attributes included from AST::Named

#name

Attributes inherited from AST::Node

#children, #inferred_type, #newline, #parent, #position

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from NarrowingType

#hash, #narrow!

Methods inherited from PrimitiveType

#add_intrinsics, #convertible_to?, #interfaces, #newarray, #primitive?, #primitive_type, #superclass

Methods inherited from Type

#add_enumerable_macros, #add_intrinsics, #add_macro, #add_method, #aload, #array?, #array_type, #assignable_from?, #astore, #basic_type, #compatible?, #component_type, #constructor, #declared_class_methods, #declared_constructors, #declared_instance_methods, #declared_intrinsics, #dynamic?, #expand_each, #field_getter, #field_setter, #get_method, #init_value, #inner_class?, #inner_class_getter, #inspect, #interface?, #interfaces, #intrinsics, #is_parent, #iterable?, #java_method, #jvm_type, #load, #log, #meta, #meta?, #newarray, #prefix, #primitive?, #return, #store, #superclass, #to_source, #unmeta, #void?, #wide?

Methods included from MethodLookup

#each_is_exact, #each_is_exact_or_subtype_or_convertible, #field_lookup, #find_jls, #find_method, #inner_class, #is_more_specific?, #log, #phase1, #phase2, #phase3, #primitive_convertible?

Methods inherited from AST::TypeReference

#==, #block?, #compatible?, #component_type, #eql?, #error?, #hash, #is_parent, #iterable?, #meta?, #narrow, #null?, #primitive?, #to_s, #unmeta, #unreachable?

Methods included from AST::Named

#to_s

Methods inherited from AST::Node

#<<, ===, #[], #_set_parent, child, child_name, #each, #empty?, #expr?, #initialize_copy, #insert, #inspect, #line_number, #log, #precompile, #resolve_if, #resolved!, #resolved?, #simple_name, #temp, #to_s

Constructor Details

#initialize(literal) ⇒ FixnumLiteral

Returns a new instance of FixnumLiteral.



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/duby/jvm/types/literals.rb', line 37

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



28
29
30
# File 'lib/duby/jvm/types/literals.rb', line 28

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