Class: RBI::Rewriters::Merge::TreeMerger
- Extended by:
- T::Sig
- Defined in:
- lib/rbi/rewriters/merge_trees.rb
Instance Attribute Summary collapse
-
#conflicts ⇒ Object
readonly
Returns the value of attribute conflicts.
Instance Method Summary collapse
-
#initialize(output, left_name: "left", right_name: "right") ⇒ TreeMerger
constructor
A new instance of TreeMerger.
- #visit(node) ⇒ Object
Methods inherited from Visitor
Constructor Details
#initialize(output, left_name: "left", right_name: "right") ⇒ TreeMerger
Returns a new instance of TreeMerger.
92 93 94 95 96 97 98 99 100 |
# File 'lib/rbi/rewriters/merge_trees.rb', line 92 def initialize(output, left_name: "left", right_name: "right") super() @tree = output @index = T.let(output.index, Index) @scope_stack = T.let([@tree], T::Array[Tree]) @left_name = left_name @right_name = right_name @conflicts = T.let([], T::Array[Conflict]) end |
Instance Attribute Details
#conflicts ⇒ Object (readonly)
Returns the value of attribute conflicts.
89 90 91 |
# File 'lib/rbi/rewriters/merge_trees.rb', line 89 def conflicts @conflicts end |
Instance Method Details
#visit(node) ⇒ Object
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/rbi/rewriters/merge_trees.rb', line 103 def visit(node) return unless node case node when Scope prev = previous_definition(node) if prev.is_a?(Scope) if node.compatible_with?(prev) prev.merge_with(node) else make_conflict_scope(prev, node) end @scope_stack << prev else copy = node.dup_empty current_scope << copy @scope_stack << copy end visit_all(node.nodes) @scope_stack.pop when Tree current_scope.merge_with(node) visit_all(node.nodes) when Indexable prev = previous_definition(node) if prev if node.compatible_with?(prev) prev.merge_with(node) else make_conflict_tree(prev, node) end else current_scope << node.dup end end end |