Re: [perl #48014] [DEPRECATED] PMC union struct

[email protected] (Christoph Otto) Thu, 22 Jan 2009 04:03:13 -0800
Newsgroups perl.perl6.internals
Message-ID <[email protected]>
Bernhard Schmalhofer via RT wrote:
> Christoph Otto schrieb:
>> Christoph Otto via RT wrote:
>>
>> The attached patch implements this behavior and fixes two core PMCs 
>> that had been doing the inheritance manually.  All tests in make test 
>> pass.  I didn't bother testing any HLLs as this is more of a "here's 
>> what I'm thinking" patch, but it's not likely there will need to be 
>> any changes other than nuking a few more now-redundant ATTRs.  
>> Obviously, the HLLs will get a test before this gets committed, 
>> barring any other objections.
> 
> +    #prepend parent ATTRs to this PMC's ATTR list
> +    if (@{$pmc->{parents}} > 0 && $pmc->{parents}[0] ne 'default') {
> +        my $got_attrs_from = '';
> +        foreach my $parent (@{$pmc->{parents}}) {
> +            my $parent_dump = $pmc2cMain->read_dump(lc($parent).'.dump');
> +            if ($got_attrs_from ne '' && $parent_dump->{has_attribute}) {
> +                die "$filename is trying to extend $got_attrs_from and $parent, ".
> +                    "but both these PMCs have ATTRs.";
> +            }
> +            if ($parent_dump->{has_attribute}) {
> +                $got_attrs_from = $parent;
> +                foreach my $parent_attrs (@{$parent_dump->{attributes}}) {
> +                    $pmc->add_attribute($parent_attrs);
> +                }
> +            }
> +        }
> +    }
> +
> 
> I am wondering about the check with check with $got_attrs_from.
> How is the case handled, where an PMC 'child' inherits from the PMC 'parent'
> and 'child' wants to add an attribute to the attributes inherited from 
> 'parent' ?
> 
> Regards,
>    Bernhard
> 
> 

Currently, there are no PMCs which multiply inherit from parents where more 
than one parent has ATTRs.  As far as I know, this currently falls under the 
"don't do that" category.

The case where a child wants to have some ATTRs in addition to the ones its 
parent has is handled gracefully.  That's why the patch removes some ATTRs 
from a couple PMCs.  A child's ATTRs are a strict superset of the parent's.