Class: Yoda::Typing::Tree::Base Abstract

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/yoda/typing/tree/base.rb

Overview

This class is abstract.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(node:, tracer:, context:, parent: nil) ⇒ Base

Returns a new instance of Base.

Parameters:



29
30
31
32
33
34
# File 'lib/yoda/typing/tree/base.rb', line 29

def initialize(node:, tracer:, context:, parent: nil)
  @node = node
  @tracer = tracer
  @context = context
  @parent = parent
end

Instance Attribute Details

#context ⇒ Contexts::BaseContext (readonly)



18
19
20
# File 'lib/yoda/typing/tree/base.rb', line 18

def context
  @context
end

#node ⇒ AST::Vnode (readonly)

Returns:



12
13
14
# File 'lib/yoda/typing/tree/base.rb', line 12

def node
  @node
end

#tracer ⇒ Inferencer::Tracer (readonly)

Returns:



15
16
17
# File 'lib/yoda/typing/tree/base.rb', line 15

def tracer
  @tracer
end

Instance Method Details

#build_child(node, context: self.context) ⇒ Base

Parameters:

Returns:



52
53
54
# File 'lib/yoda/typing/tree/base.rb', line 52

def build_child(node, context: self.context)
  Tree.build(node, context: context, tracer: tracer, parent: self)
end

#generator ⇒ Types::Generator

Returns:



23
# File 'lib/yoda/typing/tree/base.rb', line 23

delegate [:generator] => :context

#infer_child(node, **kwargs) ⇒ Types::Type

Parameters:

Returns:



59
60
61
# File 'lib/yoda/typing/tree/base.rb', line 59

def infer_child(node, **kwargs)
  build_child(node, **kwargs).type
end

#inspect ⇒ Object



77
78
79
# File 'lib/yoda/typing/tree/base.rb', line 77

def inspect
  pretty_print_inspect
end

#pretty_print(pp) ⇒ Object

Parameters:

  • pp (PP)


64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/yoda/typing/tree/base.rb', line 64

def pretty_print(pp)
  pp.object_group(self) do
    pp.breakable
    pp.text "@node="
    pp.pp node
    pp.text "@context="
    pp.pp context
    pp.comma_breakable
    pp.text "@tracer="
    pp.pp tracer
  end
end

#type ⇒ Types::Type

Returns:



37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/yoda/typing/tree/base.rb', line 37

def type
  @type ||= begin
    bind_tree(node: node, tree: self)
    bind_context(node: node, context: context)
    Logger.trace("Traversing #{node}")
    type = infer_type
    Logger.trace("Traversed #{node} -> #{type.to_s}")
    bind_type(node: node, type: type, context: context)

    type
  end
end