In Files

  • rbs-2.1.0/lib/rbs/type_alias_dependency.rb

Class/Module Index [+]

Quicksearch

RBS::TypeAliasDependency

Attributes

dependencies[R]

A hash which stores the transitive closure of the directed graph

direct_dependencies[R]

Direct dependencies corresponds to a directed graph with vertices as types and directions based on assignment of types

env[R]

Public Class Methods

new(env:) click to toggle source
 
               # File rbs-2.1.0/lib/rbs/type_alias_dependency.rb, line 12
def initialize(env))
  @env = env
end
            

Public Instance Methods

build_dependencies() click to toggle source
 
               # File rbs-2.1.0/lib/rbs/type_alias_dependency.rb, line 25
def build_dependencies
  return if @direct_dependencies

  # Initialize hash(a directed graph)
  @direct_dependencies = {}
  # Initialize dependencies as an empty hash
  @dependencies = {}
  # Iterate over alias declarations inserted into environment
  env.alias_decls.each do |name, entry|
    # Construct a directed graph by recursively extracting type aliases
    @direct_dependencies[name] = direct_dependency(entry.decl.type)
    # Initialize dependencies with an empty hash
    @dependencies[name] = {}
  end
end
            
circular_definition?(alias_name) click to toggle source

Check if an alias type definition is circular & prohibited

 
               # File rbs-2.1.0/lib/rbs/type_alias_dependency.rb, line 17
def circular_definition?(alias_name)
  # Construct transitive closure, if not constructed already
  transitive_closure() unless @dependencies

  # Check for recursive type alias
  @dependencies[alias_name][alias_name]
end
            
transitive_closure() click to toggle source
 
               # File rbs-2.1.0/lib/rbs/type_alias_dependency.rb, line 41
def transitive_closure
  # Construct a graph of direct dependencies
  build_dependencies()
  # Construct transitive closure by using DFS(recursive technique)
  @direct_dependencies.each_key do |name|
    dependency(name, name)
  end
end