Class: Yoda::Typing::Contexts::BaseContext
Abstract
- Inherits:
-
Object
- Object
- Yoda::Typing::Contexts::BaseContext
show all
- Extended by:
- Forwardable
- Includes:
- ContextDerivation
- Defined in:
- lib/yoda/typing/contexts/base_context.rb
Overview
Instance Attribute Summary collapse
Instance Method Summary
collapse
#derive_block_context, #derive_class_context, #derive_method_context
Constructor Details
#initialize(environment:, receiver:, constant_ref:, parent: nil, binds: nil) ⇒ BaseContext
Returns a new instance of BaseContext.
34
35
36
37
38
39
40
|
# File 'lib/yoda/typing/contexts/base_context.rb', line 34
def initialize(environment:, receiver:, constant_ref:, parent: nil, binds: nil)
@environment = environment
@receiver = receiver
@constant_ref = constant_ref
@parent = parent
@type_binding = Inferencer::TypeBinding.new(parent: parent_variable_scope_context&.type_binding, binds: binds)
end
|
Instance Attribute Details
19
20
21
|
# File 'lib/yoda/typing/contexts/base_context.rb', line 19
def constant_ref
@constant_ref
end
|
13
14
15
|
# File 'lib/yoda/typing/contexts/base_context.rb', line 13
def environment
@environment
end
|
22
23
24
|
# File 'lib/yoda/typing/contexts/base_context.rb', line 22
def parent
@parent
end
|
16
17
18
|
# File 'lib/yoda/typing/contexts/base_context.rb', line 16
def receiver
@receiver
end
|
25
26
27
|
# File 'lib/yoda/typing/contexts/base_context.rb', line 25
def type_binding
@type_binding
end
|
Instance Method Details
77
78
79
|
# File 'lib/yoda/typing/contexts/base_context.rb', line 77
def constant_resolver
ConstantResolver.new(context: self)
end
|
72
73
74
|
# File 'lib/yoda/typing/contexts/base_context.rb', line 72
def generator
Types::Generator.new(environment: environment)
end
|
#lexical_scope_types ⇒ Array<Types::Type>
58
59
60
61
62
63
64
65
66
67
68
69
|
# File 'lib/yoda/typing/contexts/base_context.rb', line 58
def lexical_scope_types
@lexical_scope_types ||= begin
parent_types = parent&.lexical_scope_types || []
if parent.nil?
[constant_ref]
elsif parent && constant_ref != parent.constant_ref
parent_types + [constant_ref]
else
parent_types
end
end
end
|
#method_receiver ⇒ Object
47
48
49
|
# File 'lib/yoda/typing/contexts/base_context.rb', line 47
def method_receiver
constant_ref.instance_type
end
|
#parent_variable_scope_context ⇒ Context?
53
54
55
|
# File 'lib/yoda/typing/contexts/base_context.rb', line 53
def parent_variable_scope_context
fail NotImplementedError
end
|
#registry ⇒ Object
43
44
45
|
# File 'lib/yoda/typing/contexts/base_context.rb', line 43
def registry
environment.registry
end
|