281c281
< cls._values[name] = param.convert(value)
---
> value = param.convert(value)
286a287,291
> cls._values[name] = value
> # if param value is a SimObject, make it a child too, so that
> # it gets cloned properly when the class is instantiated
> if isSimObjectOrVector(value) and not value.has_parent():
> cls._add_cls_child(name, value)
287a293,301
> def _add_cls_child(cls, name, child):
> # It's a little funky to have a class as a parent, but these
> # objects should never be instantiated (only cloned, which
> # clears the parent pointer), and this makes it clear that the
> # object is not an orphan and can provide better error
> # messages.
> child.set_parent(cls, name)
> cls._children[name] = child
>
337c351
< cls._children[attr] = coerceSimObjectOrVector(value)
---
> cls._add_cls_child(attr, coerceSimObjectOrVector(value))
510a525,532
> # Clone children specified at class level. No need for a
> # multidict here since we will be cloning everything.
> # Do children before parameter values so that children that
> # are also param values get cloned properly.
> self._children = {}
> for key,val in ancestor._children.iteritems():
> self.add_child(key, val(_memo=memo_dict))
>
521,526d542
< # Clone children specified at class level. No need for a
< # multidict here since we will be cloning everything.
< self._children = {}
< for key,val in ancestor._children.iteritems():
< self.add_child(key, val(_memo=memo_dict))
<
616a633,635
> # implicitly parent unparented objects assigned as params
> if isSimObjectOrVector(value) and not value.has_parent():
> self.add_child(attr, value)
650,653c669,671
< # use this rather than directly accessing _parent for symmetry
< # with SimObjectVector
< def get_parent(self):
< return self._parent
---
> # Also implemented by SimObjectVector
> def has_parent(self):
> return self._parent is not None
665,668c683,685
< if child.get_parent():
< raise RuntimeError, \
< "add_child('%s'): child '%s' already has parent '%s'" % \
< (name, child._name, child._parent)
---
> if child.has_parent():
> print "warning: add_child('%s'): child '%s' already has parent" % \
> (name, child.get_name())
687c704
< # SimObjectVector class so we can call get_parent()
---
> # SimObjectVector class so we can call has_parent()
690c707,709
< if isSimObjectOrVector(val) and not val.get_parent():
---
> if isSimObjectOrVector(val) and not val.has_parent():
> print "warning: %s adopting orphan SimObject param '%s'" \
> % (self, key)
695c714
< return '(orphan)'
---
> return '<orphan %s>' % self.__class__