Module: HDLRuby::Low::OneChildMutable
Overview
Module for mutable expressions with one child.
Instance Method Summary collapse
-
#map_nodes!(&ruby_block) ⇒ Object
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
Maps on the child.
1230 1231 1232 1233 |
# File 'lib/HDLRuby/hruby_low_mutable.rb', line 1230 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.
1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 |
# File 'lib/HDLRuby/hruby_low_mutable.rb', line 1241 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.
1219 1220 1221 1222 1223 1224 1225 1226 1227 |
# File 'lib/HDLRuby/hruby_low_mutable.rb', line 1219 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 |