Class: MilkTea::ModuleBinder

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

Instance Method Summary collapse

Instance Method Details

#module_binding(analysis) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/milk_tea/core/module_binder.rb', line 5

def module_binding(analysis)
  types = {}
  type_declarations = {}
  interfaces = {}
  attributes = {}
  private_types = {}
  private_interfaces = {}
  private_attributes = {}
  values = {}
  private_values = {}
  functions = {}
  private_functions = {}

  analysis.ast.declarations.each do |declaration|
    case declaration
    when AST::StructDecl, AST::UnionDecl, AST::VariantDecl, AST::EnumDecl, AST::FlagsDecl, AST::OpaqueDecl, AST::TypeAliasDecl
      type_declarations[declaration.name] = declaration
      target = exported_declaration?(analysis, declaration) ? types : private_types
      target[declaration.name] = analysis.types.fetch(declaration.name)
    when AST::InterfaceDecl
      target = exported_declaration?(analysis, declaration) ? interfaces : private_interfaces
      target[declaration.name] = analysis.interfaces.fetch(declaration.name)
    when AST::AttributeDecl
      target = exported_declaration?(analysis, declaration) ? attributes : private_attributes
      target[declaration.name] = analysis.attributes.fetch(declaration.name)
    when AST::ConstDecl, AST::VarDecl, AST::EventDecl
      target = exported_declaration?(analysis, declaration) ? values : private_values
      target[declaration.name] = analysis.values.fetch(declaration.name)
    when AST::FunctionDef, AST::ExternFunctionDecl, AST::ForeignFunctionDecl
      target = exported_declaration?(analysis, declaration) ? functions : private_functions
      target[declaration.name] = analysis.functions.fetch(declaration.name)
    end
  end

  methods, private_methods = exported_methods(analysis, types)
  implemented_interfaces, private_implemented_interfaces = exported_interface_implementations(analysis, types, interfaces)

  ModuleBinding.new(
    name: analysis.module_name,
    types:,
    type_declarations:,
    interfaces:,
    attributes:,
    attribute_applications: analysis.attribute_applications,
    values:,
    functions:,
    methods:,
    implemented_interfaces:,
    imports: analysis.imports,
    private_types:,
    private_interfaces:,
    private_attributes:,
    private_values:,
    private_functions:,
    private_methods:,
    private_implemented_interfaces:,
  )
end