Class: Ikra::Types::ArrayType

Inherits:
Object
  • Object
show all
Includes:
RubyType
Defined in:
lib/types/types/array_type.rb

Direct Known Subclasses

LocationAwareArrayType

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from RubyType

#class_id, #eql?, #hash, #inspect, #is_primitive?, #is_union_type?, #should_generate_self_arg?, #to_array_type, #to_str, #to_union_type

Constructor Details

#initialize(inner_type) ⇒ ArrayType

Returns a new instance of ArrayType.



30
31
32
33
34
35
36
# File 'lib/types/types/array_type.rb', line 30

def initialize(inner_type)
    if not inner_type.is_union_type?
        raise AssertionError.new("Union type expected")
    end

    @inner_type = inner_type
end

Instance Attribute Details

#inner_typeObject (readonly)

Returns the value of attribute inner_type.



24
25
26
# File 'lib/types/types/array_type.rb', line 24

def inner_type
  @inner_type
end

Class Method Details

.new(inner_type) ⇒ Object

Ensure singleton per class



12
13
14
15
16
17
18
19
20
21
# File 'lib/types/types/array_type.rb', line 12

def new(inner_type)
    if @cache == nil
        @cache = {}
        @cache.default_proc = proc do |hash, key|
            hash[key] = new_original(key)
        end
    end

    return @cache[inner_type]
end

.new_originalObject



9
# File 'lib/types/types/array_type.rb', line 9

alias_method :new_original, :new

Instance Method Details

#==(other) ⇒ Object



26
27
28
# File 'lib/types/types/array_type.rb', line 26

def ==(other)
    return other.class == self.class && other.inner_type == self.inner_type
end

#to_c_typeObject



42
43
44
# File 'lib/types/types/array_type.rb', line 42

def to_c_type
    return "#{@inner_type.to_c_type} *"
end

#to_ffi_typeObject



46
47
48
# File 'lib/types/types/array_type.rb', line 46

def to_ffi_type
    return :pointer
end

#to_ruby_typeObject



50
51
52
# File 'lib/types/types/array_type.rb', line 50

def to_ruby_type
    return ::Array
end

#to_sObject



38
39
40
# File 'lib/types/types/array_type.rb', line 38

def to_s
    return "[#{self.class.to_s}, inner_type = #{inner_type}]"
end