Class: MilkTea::TypeVisitor

Inherits:
Object
  • Object
show all
Defined in:
lib/milk_tea/core/types/visitor.rb

Instance Method Summary collapse

Constructor Details

#initializeTypeVisitor

Returns a new instance of TypeVisitor.



7
8
9
# File 'lib/milk_tea/core/types/visitor.rb', line 7

def initialize
  @visited = {}
end

Instance Method Details

#dispatch(type) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/milk_tea/core/types/visitor.rb', line 19

def dispatch(type)
  case type
  when Types::Nullable then visit_nullable(type)
  when Types::GenericInstance then visit_generic_instance(type)
  when Types::Span then visit_span(type)
  when Types::Task then visit_task(type)
  when Types::GenericStructDefinition then visit_generic_struct_definition(type)
  when Types::GenericVariantDefinition then visit_generic_variant_definition(type)
  when Types::Struct then visit_struct(type)
  when Types::Union then visit_union(type)
  when Types::StructInstance then visit_struct_instance(type)
  when Types::Variant then visit_variant(type)
  when Types::VariantInstance then visit_variant_instance(type)
  when Types::VariantArmPayload then visit_variant_arm_payload(type)
  when Types::Proc then visit_proc(type)
  when Types::Function then visit_function(type)
  when Types::Parameter then visit_parameter(type)
  when Types::TypeVar then visit_type_var(type)
  when Types::Null then visit_null(type)
  when Types::Tuple then visit_tuple(type)
  when Types::Dyn then visit_dyn(type)
  when Types::SoA then visit_soa(type)
  when Types::Simd then visit_simd(type)
  when Types::Event then visit_event(type)
  when Types::LifetimeRef then visit_lifetime_ref(type)
  else visit_default(type)
  end
end

#visit(type) ⇒ Object



11
12
13
14
15
16
17
# File 'lib/milk_tea/core/types/visitor.rb', line 11

def visit(type)
  return if type.nil?
  return if @visited[type.object_id]

  @visited[type.object_id] = true
  dispatch(type)
end

#visit_children(type) ⇒ Object



48
49
50
# File 'lib/milk_tea/core/types/visitor.rb', line 48

def visit_children(type)
  type.children.each { |child| visit(child) }
end

#visit_default(type) ⇒ Object



76
# File 'lib/milk_tea/core/types/visitor.rb', line 76

def visit_default(type); end

#visit_dyn(type) ⇒ Object



68
# File 'lib/milk_tea/core/types/visitor.rb', line 68

def visit_dyn(type); visit_children(type); end

#visit_event(type) ⇒ Object



71
# File 'lib/milk_tea/core/types/visitor.rb', line 71

def visit_event(type); visit_children(type); end

#visit_function(type) ⇒ Object



65
# File 'lib/milk_tea/core/types/visitor.rb', line 65

def visit_function(type); visit_children(type); end

#visit_generic_instance(type) ⇒ Object



53
# File 'lib/milk_tea/core/types/visitor.rb', line 53

def visit_generic_instance(type); visit_children(type); end

#visit_generic_struct_definition(type) ⇒ Object



56
# File 'lib/milk_tea/core/types/visitor.rb', line 56

def visit_generic_struct_definition(type); visit_children(type); end

#visit_generic_variant_definition(type) ⇒ Object



57
# File 'lib/milk_tea/core/types/visitor.rb', line 57

def visit_generic_variant_definition(type); visit_children(type); end

#visit_lifetime_ref(type) ⇒ Object



75
# File 'lib/milk_tea/core/types/visitor.rb', line 75

def visit_lifetime_ref(type); end

#visit_null(type) ⇒ Object



74
# File 'lib/milk_tea/core/types/visitor.rb', line 74

def visit_null(type); end

#visit_nullable(type) ⇒ Object



52
# File 'lib/milk_tea/core/types/visitor.rb', line 52

def visit_nullable(type); visit_children(type); end

#visit_parameter(type) ⇒ Object



66
# File 'lib/milk_tea/core/types/visitor.rb', line 66

def visit_parameter(type); visit_children(type); end

#visit_proc(type) ⇒ Object



64
# File 'lib/milk_tea/core/types/visitor.rb', line 64

def visit_proc(type); visit_children(type); end

#visit_simd(type) ⇒ Object



70
# File 'lib/milk_tea/core/types/visitor.rb', line 70

def visit_simd(type); visit_children(type); end

#visit_soa(type) ⇒ Object



69
# File 'lib/milk_tea/core/types/visitor.rb', line 69

def visit_soa(type); visit_children(type); end

#visit_span(type) ⇒ Object



54
# File 'lib/milk_tea/core/types/visitor.rb', line 54

def visit_span(type); visit_children(type); end

#visit_struct(type) ⇒ Object



58
# File 'lib/milk_tea/core/types/visitor.rb', line 58

def visit_struct(type); visit_children(type); end

#visit_struct_instance(type) ⇒ Object



60
# File 'lib/milk_tea/core/types/visitor.rb', line 60

def visit_struct_instance(type); visit_children(type); end

#visit_task(type) ⇒ Object



55
# File 'lib/milk_tea/core/types/visitor.rb', line 55

def visit_task(type); visit_children(type); end

#visit_tuple(type) ⇒ Object



67
# File 'lib/milk_tea/core/types/visitor.rb', line 67

def visit_tuple(type); visit_children(type); end

#visit_type_var(type) ⇒ Object



73
# File 'lib/milk_tea/core/types/visitor.rb', line 73

def visit_type_var(type); end

#visit_union(type) ⇒ Object



59
# File 'lib/milk_tea/core/types/visitor.rb', line 59

def visit_union(type); visit_children(type); end

#visit_variant(type) ⇒ Object



61
# File 'lib/milk_tea/core/types/visitor.rb', line 61

def visit_variant(type); visit_children(type); end

#visit_variant_arm_payload(type) ⇒ Object



63
# File 'lib/milk_tea/core/types/visitor.rb', line 63

def visit_variant_arm_payload(type); visit_children(type); end

#visit_variant_instance(type) ⇒ Object



62
# File 'lib/milk_tea/core/types/visitor.rb', line 62

def visit_variant_instance(type); visit_children(type); end