module HDLRuby::Low::OneChildMutable

Module for mutable expressions with one child.

Public Instance Methods

map_nodes!(&ruby_block) click to toggle source

Maps on the child.

# File lib/HDLRuby/hruby_low_mutable.rb, line 1389
def map_nodes!(&ruby_block)
    @child = ruby_block.call(@child)
    @child.parent = self unless @child.parent
end
replace_expressions!(node2rep) click to toggle source

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.

# File lib/HDLRuby/hruby_low_mutable.rb, line 1400
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) click to toggle source

Sets the child.

# File lib/HDLRuby/hruby_low_mutable.rb, line 1378
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