Module: HDLRuby::Low::OneChildMutable
Overview
Module for mutable expressions with one child.
Instance Method Summary collapse
-
#map_nodes!(&ruby_block) ⇒ Object
(also: #map_expressions!)
Maps on the child.
-
#replace_expressions!(node2rep) ⇒ Object
Replaces sub expressions using +node2rep+ table indicating the node to replace and the corresponding replacement.
-
#set_child!(child) ⇒ Object
Sets the child.
Instance Method Details
#map_nodes!(&ruby_block) ⇒ Object Also known as: map_expressions!
Maps on the child.
1366 1367 1368 1369 |
# File 'lib/HDLRuby/hruby_low_mutable.rb', line 1366 def map_nodes!(&ruby_block) @child = ruby_block.call(@child) @child.parent = self unless @child.parent end |
#replace_expressions!(node2rep) ⇒ Object
Replaces sub expressions using +node2rep+ table indicating the node to replace and the corresponding replacement. Returns the actually replaced nodes and their corresponding replacement.
NOTE: the replacement is duplicated.
1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 |
# File 'lib/HDLRuby/hruby_low_mutable.rb', line 1379 def replace_expressions!(node2rep) # First recurse on the child. res = self.child.replace_expressions!(node2rep) # Is there a replacement to do? rep = node2rep[self.child] if rep then # Yes, do it. rep = rep.clone node = self.child # node.set_parent!(nil) self.set_child!(rep) # And register the replacement. res[node] = rep end return res end |
#set_child!(child) ⇒ Object
Sets the child.
1355 1356 1357 1358 1359 1360 1361 1362 1363 |
# File 'lib/HDLRuby/hruby_low_mutable.rb', line 1355 def set_child!(child) # Check and set the child. unless child.is_a?(Expression) raise AnyError,"Invalid class for an expression: #{child.class}" end @child = child # And set its parent. child.parent = self end |