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

#initialize(name, value) ⇒ Base

Returns a new instance of Base



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

#annotated_typeObject

Returns the value of attribute annotated_type



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

def annotated_type
  @annotated_type
end

#ast_nodeObject

Returns the value of attribute ast_node



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

def ast_node
  @ast_node
end

#definitionObject

Returns the value of attribute definition



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

def definition
  @definition
end

#inferred_typeObject

Returns the value of attribute inferred_type



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

def inferred_type
  @inferred_type
end

#nameObject

Returns the value of attribute name



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

def name
  @name
end

#self_ownerObject

Returns the value of attribute self_owner



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

def self_owner
  @self_owner
end

#usesObject

Returns the value of attribute uses



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

def uses
  @uses
end

#valueObject (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

#<=>(other) ⇒ Object



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

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

#bind!(value) ⇒ Object



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

#class_usedObject



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

def class_used
  value.klass
end

#deep_dupObject



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

#expr_typeObject



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

#initialize_dup_deep(other) ⇒ Object

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

#inspectObject



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

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

#scopeObject



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

def scope
  value.scope
end

#to_sObject



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

def to_s
  inspect
end