# Unlike most Values, Record *can* be subclassed.
class Record(Value):
+ @classmethod
+ def like(cls, other, name=None, name_suffix=None, src_loc_at=0):
+ if name is not None:
+ new_name = str(name)
+ elif name_suffix is not None:
+ new_name = other.name + str(name_suffix)
+ else:
+ new_name = tracer.get_var_name(depth=2 + src_loc_at, default=None)
+ return cls(other.layout, new_name)
+
def __init__(self, layout, name=None, *, fields=None):
if name is None:
name = tracer.get_var_name(default=None)
self.assertIs(r.stb, ns)
self.assertIs(r.info, nr)
+ def test_like(self):
+ r1 = Record([("a", 1), ("b", 2)])
+ r2 = Record.like(r1)
+ self.assertEqual(r1.layout, r2.layout)
+ self.assertEqual(r2.name, "r2")
+ r3 = Record.like(r1, name="foo")
+ self.assertEqual(r3.name, "foo")
+ r4 = Record.like(r1, name_suffix="foo")
+ self.assertEqual(r4.name, "r1foo")
+
class ConnectTestCase(FHDLTestCase):
def setUp_flat(self):