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.
-
#initialize(env:) ⇒ TypeAliasDependency
constructor
A new instance of TypeAliasDependency.
- #transitive_closure ⇒ Object
Constructor Details
#initialize(env:) ⇒ TypeAliasDependency
Returns a new instance of TypeAliasDependency.
12 13 14 |
# File 'lib/rbs/type_alias_dependency.rb', line 12 def initialize(env:) @env = env end |
Instance Attribute Details
#dependencies ⇒ Object (readonly)
A hash which stores the transitive closure of the directed graph
10 11 12 |
# File 'lib/rbs/type_alias_dependency.rb', line 10 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
7 8 9 |
# File 'lib/rbs/type_alias_dependency.rb', line 7 def direct_dependencies @direct_dependencies end |
#env ⇒ Object (readonly)
Returns the value of attribute env.
3 4 5 |
# File 'lib/rbs/type_alias_dependency.rb', line 3 def env @env end |
Instance Method Details
#build_dependencies ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File '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) ⇒ Boolean
Check if an alias type definition is circular & prohibited
17 18 19 20 21 22 23 |
# File '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 ⇒ Object
41 42 43 44 45 46 47 48 |
# File '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 |