Class: RBS::TypeAliasDependency
- Inherits:
-
Object
- Object
- RBS::TypeAliasDependency
- Defined in:
- lib/rbs/type_alias_dependency.rb
Instance Attribute Summary collapse
-
#dependencies ⇒ Object
readonly
A hash which stores the transitive closure of the directed graph.
-
#direct_dependencies ⇒ Object
readonly
Direct dependencies corresponds to a directed graph with vertices as types and directions based on assignment of types.
-
#env ⇒ Object
readonly
Returns the value of attribute env.
Instance Method Summary collapse
- #build_dependencies ⇒ Object
-
#circular_definition?(alias_name) ⇒ Boolean
Check if an alias type definition is circular & prohibited.
- #dependencies_of(name) ⇒ Object
- #direct_dependencies_of(name) ⇒ Object
-
#initialize(env:) ⇒ TypeAliasDependency
constructor
A new instance of TypeAliasDependency.
- #transitive_closure ⇒ Object
Constructor Details
#initialize(env:) ⇒ TypeAliasDependency
Returns a new instance of TypeAliasDependency.
14 15 16 |
# File 'lib/rbs/type_alias_dependency.rb', line 14 def initialize(env:) @env = env end |
Instance Attribute Details
#dependencies ⇒ Object (readonly)
A hash which stores the transitive closure of the directed graph
12 13 14 |
# File 'lib/rbs/type_alias_dependency.rb', line 12 def dependencies @dependencies end |
#direct_dependencies ⇒ Object (readonly)
Direct dependencies corresponds to a directed graph with vertices as types and directions based on assignment of types
9 10 11 |
# File 'lib/rbs/type_alias_dependency.rb', line 9 def direct_dependencies @direct_dependencies end |
#env ⇒ Object (readonly)
Returns the value of attribute env.
5 6 7 |
# File 'lib/rbs/type_alias_dependency.rb', line 5 def env @env end |
Instance Method Details
#build_dependencies ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/rbs/type_alias_dependency.rb', line 27 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.type_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) ⇒ Boolean
Check if an alias type definition is circular & prohibited
19 20 21 22 23 24 25 |
# File 'lib/rbs/type_alias_dependency.rb', line 19 def circular_definition?(alias_name) # Construct transitive closure, if not constructed already transitive_closure() unless @dependencies alias_name = env.normalize_type_name!(alias_name) @dependencies[alias_name][alias_name] end |
#dependencies_of(name) ⇒ Object
57 58 59 60 |
# File 'lib/rbs/type_alias_dependency.rb', line 57 def dependencies_of(name) name = env.normalize_type_name!(name) @dependencies[name].each_key.to_set end |
#direct_dependencies_of(name) ⇒ Object
52 53 54 55 |
# File 'lib/rbs/type_alias_dependency.rb', line 52 def direct_dependencies_of(name) name = env.normalize_type_name!(name) @direct_dependencies[name] end |
#transitive_closure ⇒ Object
43 44 45 46 47 48 49 50 |
# File 'lib/rbs/type_alias_dependency.rb', line 43 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 |