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", keep: Keep::NONE) ⇒ TreeMerger
constructor
A new instance of TreeMerger.
- #visit(node) ⇒ Object
Methods inherited from Visitor
Constructor Details
#initialize(output, left_name: "left", right_name: "right", keep: Keep::NONE) ⇒ TreeMerger
Returns a new instance of TreeMerger.
103 104 105 106 107 108 109 110 111 112 |
# File 'lib/rbi/rewriters/merge_trees.rb', line 103 def initialize(output, left_name: "left", right_name: "right", keep: Keep::NONE) 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 @keep = keep @conflicts = T.let([], T::Array[Conflict]) end |
Instance Attribute Details
#conflicts ⇒ Object (readonly)
Returns the value of attribute conflicts.
100 101 102 |
# File 'lib/rbi/rewriters/merge_trees.rb', line 100 def conflicts @conflicts end |
Instance Method Details
#visit(node) ⇒ Object
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 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 |
# File 'lib/rbi/rewriters/merge_trees.rb', line 115 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) elsif @keep == Keep::LEFT # do nothing it's already merged elsif @keep == Keep::RIGHT prev = replace_scope_header(prev, 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) elsif @keep == Keep::LEFT # do nothing it's already merged elsif @keep == Keep::RIGHT prev.replace(node) else make_conflict_tree(prev, node) end else current_scope << node.dup end end end |