class RBS::Resolver::ConstantResolver::Table

def children(name)

def children(name)
  children_table[name]
end

def constant(name)

def constant(name)
  constants_table[name]
end

def constant_of_constant(name, entry)

def constant_of_constant(name, entry)
  Constant.new(name: name, type: entry.decl.type, entry: entry)
end

def constant_of_module(name, entry)

def constant_of_module(name, entry)
  type = Types::ClassSingleton.new(
    name: name,
    location: nil
  )
  Constant.new(name: name, type: type, entry: entry)
end

def initialize(environment)

def initialize(environment)
  @children_table = {}
  @toplevel = {}
  @constants_table = {}
  environment.class_decls.each_key do |name|
    children_table[name] = {}
  end
  environment.class_decls.each do |name, entry|
    constant = constant_of_module(name, entry)
    unless name.namespace.empty?
      parent = name.namespace.to_type_name
      table = children_table[parent] or raise "#{parent} not found by #{name}"
    else
      table = toplevel
    end
    table[name.name] = constant
    constants_table[name] = constant
  end
  environment.class_alias_decls.each do |name, entry|
    normalized_entry = environment.normalized_module_class_entry(name) or next
    constant = constant_of_module(name, normalized_entry)
    # Insert class/module aliases into `children_table` and `toplevel` table
    unless name.namespace.empty?
      normalized_parent = environment.normalize_module_name?(name.namespace.to_type_name) or raise
      table = children_table[normalized_parent] or raise
      table[name.name] = constant
    else
      toplevel[name.name] = constant
    end
  end
  environment.constant_decls.each do |name, entry|
    unless name.namespace.empty?
      parent = name.namespace.to_type_name
      table = children_table[parent] or raise
      constant = constant_of_constant(name, entry)
    else
      table = toplevel
      constant = constant_of_constant(name, entry)
    end
    table[name.name] = constant
  end
end