Class: Laser::Analysis::Bindings::Base

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/laser/analysis/bindings.rb

Overview

This class represents a Base in Ruby. It may have a known type, class, value (if constant!), and a variety of other details.

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Methods included from Comparable

#<, #<=, #==, #>, #>=, #between?, compare_int

Constructor Details

- (Base) initialize(name, value)



12
13
14
15
16
17
18
# File 'lib/laser/analysis/bindings.rb', line 12

def initialize(name, value)
  @name = name
  @uses = Set.new
  @definition = @self_owner = nil
  @value = :uninitialized
  bind!(value)
end

Instance Attribute Details

- (Object) annotated_type

Returns the value of attribute annotated_type



8
9
10
# File 'lib/laser/analysis/bindings.rb', line 8

def annotated_type
  @annotated_type
end

- (Object) ast_node

Returns the value of attribute ast_node



8
9
10
# File 'lib/laser/analysis/bindings.rb', line 8

def ast_node
  @ast_node
end

- (Object) definition

Returns the value of attribute definition



9
10
11
# File 'lib/laser/analysis/bindings.rb', line 9

def definition
  @definition
end

- (Object) inferred_type

Returns the value of attribute inferred_type



8
9
10
# File 'lib/laser/analysis/bindings.rb', line 8

def inferred_type
  @inferred_type
end

- (Object) name

Returns the value of attribute name



8
9
10
# File 'lib/laser/analysis/bindings.rb', line 8

def name
  @name
end

- (Object) self_owner

Returns the value of attribute self_owner



9
10
11
# File 'lib/laser/analysis/bindings.rb', line 9

def self_owner
  @self_owner
end

- (Object) uses

Returns the value of attribute uses



8
9
10
# File 'lib/laser/analysis/bindings.rb', line 8

def uses
  @uses
end

- (Object) value (readonly)

Returns the value of attribute value



10
11
12
# File 'lib/laser/analysis/bindings.rb', line 10

def value
  @value
end

Instance Method Details

- (Object) <=>(other)



46
47
48
# File 'lib/laser/analysis/bindings.rb', line 46

def <=>(other)
  self.name <=> other.name
end

- (Object) bind!(value)



39
40
41
42
43
44
# File 'lib/laser/analysis/bindings.rb', line 39

def bind!(value)
  if respond_to?(:validate_value)
    validate_value(value)
  end
  @value = value
end

- (Object) class_used



54
55
56
# File 'lib/laser/analysis/bindings.rb', line 54

def class_used
  value.klass
end

- (Object) deep_dup



20
21
22
23
24
# File 'lib/laser/analysis/bindings.rb', line 20

def deep_dup
  result = self.class.new(@name, @value)
  result.initialize_dup_deep(self)
  result
end

- (Object) expr_type



34
35
36
37
# File 'lib/laser/analysis/bindings.rb', line 34

def expr_type
  annotated_type || inferred_type || Types::ClassType.new(
      (LaserObject === @value ? @value.klass.path : @value.class.name), :invariant)
end

- (Object) initialize_dup_deep(other)

like initialize_dup, but manually called and deep copy.



27
28
29
30
31
32
# File 'lib/laser/analysis/bindings.rb', line 27

def initialize_dup_deep(other)
  @annotated_type = other.annotated_type.dup if other.annotated_type
  @inferred_type = other.inferred_type.dup if other.inferred_type
  @ast_node = other.ast_node # immutable
  self
end

- (Object) inspect



62
63
64
# File 'lib/laser/analysis/bindings.rb', line 62

def inspect
  "#<#{self.class.name.split('::').last}: #{name}>"
end

- (Object) scope



50
51
52
# File 'lib/laser/analysis/bindings.rb', line 50

def scope
  value.scope
end

- (Object) to_s



58
59
60
# File 'lib/laser/analysis/bindings.rb', line 58

def to_s
  inspect
end