Class: Array

Inherits:
Object show all
Includes:
Ikra::Entity
Defined in:
lib/entity.rb,
lib/types/ruby_type.rb,
lib/type_aware_array.rb,
lib/types/array_type.rb,
lib/symbolic/symbolic.rb

Direct Known Subclasses

Scope

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.pnew(size, &block) ⇒ Object



235
236
237
# File 'lib/symbolic/symbolic.rb', line 235

def pnew(size, &block)
    Ikra::Symbolic::ArrayNewCommand.new(size, block)
end

.to_ikra_type_obj(object) ⇒ Object



42
43
44
45
46
47
48
49
50
# File 'lib/types/array_type.rb', line 42

def self.to_ikra_type_obj(object)
    inner_type = Ikra::Types::UnionType.new

    object.each do |element|
        inner_type.expand_with_singleton_type(element.class.to_ikra_type)
    end

    Ikra::Types::ArrayType.new(inner_type)
end

Instance Method Details

#[]=(index, element) ⇒ Object



47
48
49
50
51
52
53
54
55
# File 'lib/type_aware_array.rb', line 47

def []=(index, element)
    type_counter[self[index].class] -= 1
    if type_counter[self[index].class] == 0
        type_counter.delete(self[index].class)
    end
    
    old_set(index, element)
    type_counter[element.class] += 1
end

#all_typesObject



29
30
31
# File 'lib/type_aware_array.rb', line 29

def all_types
    type_counter.keys
end

#common_superclassObject

TODO: probably do not need this anymore



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/type_aware_array.rb', line 4

def common_superclass
    class_counter = {}
    class_counter.default = 0
    
    index = 0
    each do |cls|
        while (cls != BasicObject) do
            class_counter[cls] += 1
            cls = cls.superclass
        end
        index += 1
    end
    
    smallest = Object
    class_counter.each do |cls, counter|
        if counter == size
            if cls < smallest
                smallest = cls
            end
        end
    end
    
    smallest
end

#old_pushObject



33
# File 'lib/type_aware_array.rb', line 33

alias :old_push :push

#old_setObject



45
# File 'lib/type_aware_array.rb', line 45

alias :old_set :[]=

#pmap(&block) ⇒ Object



240
241
242
# File 'lib/symbolic/symbolic.rb', line 240

def pmap(&block)
    Ikra::Symbolic::ArrayMapCommand.new(to_command, block)
end

#push(*elements) ⇒ Object



35
36
37
38
39
40
41
42
43
# File 'lib/type_aware_array.rb', line 35

def push(*elements)
    old_push(*elements)

    for element in elements
        type_counter[element.class] += 1
    end

    self
end

#to_commandObject



244
245
246
# File 'lib/symbolic/symbolic.rb', line 244

def to_command
    Ikra::Symbolic::ArrayIdentityCommand.new(self)
end

#to_type_array_stringObject



40
41
42
43
44
# File 'lib/types/ruby_type.rb', line 40

def to_type_array_string
    "[" + map do |set|
        set.to_s
    end.join(", ") + "]"
end