Module: HDLRuby::Low::OneChildMutable

Included in:
Cast, Unary
Defined in:
lib/HDLRuby/hruby_low_mutable.rb

Overview

Module for mutable expressions with one child.

Instance Method Summary collapse

Instance Method Details

#map_nodes!(&ruby_block) ⇒ Object

Maps on the child.



1401
1402
1403
1404
# File 'lib/HDLRuby/hruby_low_mutable.rb', line 1401

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.



1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
# File 'lib/HDLRuby/hruby_low_mutable.rb', line 1412

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.



1390
1391
1392
1393
1394
1395
1396
1397
1398
# File 'lib/HDLRuby/hruby_low_mutable.rb', line 1390

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