Ticket #299: attributes_inheritance.patch

File attributes_inheritance.patch, 7.1 KB (added by NotFound, 13 years ago)
  • src/pmc/exceptionhandler.pmc

     
    192192        STRING * const sev    = CONST_STRING(interp, "severity"); 
    193193        STRING * const ex_str = CONST_STRING(interp, "Exception"); 
    194194 
    195         Parrot_ExceptionHandler_attributes * const core_struct = 
    196                     PARROT_EXCEPTIONHANDLER(SELF); 
    197195        INTVAL severity = VTABLE_get_integer_keyed_str(interp, exception, sev); 
    198196 
    199197        if (exception->vtable->base_type == enum_class_Exception 
    200198        ||  VTABLE_isa(INTERP, exception, ex_str)) { 
    201             PMC * handled_types; 
     199            PMC *handled_types; 
     200            PMC *handled_types_except; 
     201            INTVAL min_severity, max_severity; 
    202202            GET_ATTR_handled_types(INTERP, SELF, handled_types); 
     203            GET_ATTR_handled_types_except(INTERP, SELF, handled_types_except); 
     204            GET_ATTR_max_severity(INTERP, SELF, max_severity); 
     205            GET_ATTR_min_severity(INTERP, SELF, min_severity); 
    203206 
    204             if (severity < core_struct->min_severity) { 
     207            if (severity < min_severity) { 
    205208                RETURN(INTVAL 0); 
    206209            } 
    207             if (core_struct->max_severity > 0 
    208                  &&  severity                  > core_struct->max_severity) { 
     210            if (max_severity > 0 &&  severity > max_severity) { 
    209211                RETURN(INTVAL 0); 
    210212            } 
    211213            if (! PMC_IS_NULL(handled_types)) { 
     
    222224 
    223225                RETURN(INTVAL 0); 
    224226            } 
    225             if (core_struct->handled_types_except != PMCNULL) { 
    226                 const INTVAL elems = VTABLE_elements(interp, core_struct->handled_types_except); 
     227            if (handled_types_except != PMCNULL) { 
     228                const INTVAL elems = VTABLE_elements(interp, handled_types_except); 
    227229                const INTVAL type  = VTABLE_get_integer_keyed_str(interp, exception, CONST_STRING(interp, "type")); 
    228230                INTVAL i; 
    229231 
    230232                for (i = 0; i < elems; i++) { 
    231233                    const INTVAL handled_type = VTABLE_get_integer_keyed_int(interp, 
    232                             core_struct->handled_types_except, i); 
     234                            handled_types_except, i); 
    233235                    if (handled_type == type) 
    234236                        RETURN(INTVAL 0); 
    235237                } 
    236238 
    237239                RETURN(INTVAL 1); 
    238240            } 
    239             else if (core_struct->max_severity > 0 || 
    240                     core_struct->min_severity > 0) { 
     241            else if (max_severity > 0 || min_severity > 0) { 
    241242                RETURN(INTVAL 1); 
    242243            } 
    243244 
  • src/pmc/pmcproxy.pmc

     
    160160            Parrot_oo_extract_methods_from_namespace(interp, SELF, 
    161161                    proxy_info->_namespace); 
    162162        } 
     163 
     164        { /* Create inherited attributes */ 
     165            /* Each attribute is terminated by an space, 
     166             * the list is '\0' terminated 
     167             */ 
     168            const char * attr = interp->vtables[type_num]->inheritable_args; 
     169            while (* attr) { 
     170                const char * const current = attr; 
     171                STRING *sattr; 
     172                size_t l; 
     173                while (* attr != ' ') ++attr; 
     174                l= attr - current; 
     175                sattr = Parrot_str_new(interp, current, l); 
     176                SELF.add_attribute(sattr, NULL); 
     177                ++attr; 
     178            } 
     179        } 
    163180    } 
    164181 
    165182/* 
  • lib/Parrot/Vtable.pm

     
    175175    PMC    *pmc_class;      /* for PMCs: a PMC of that type 
    176176                               for objects: the class PMC */ 
    177177    PMC    *mro;            /* array PMC of [class, parents ... ] */ 
     178    const char *inheritable_args; /* list of ARGS inheritable from classes */ 
    178179    struct _vtable *ro_variant_vtable; /* A variant of this vtable with the 
    179180                                   opposite IS_READONLY flag */ 
    180181    /* Vtable Functions */ 
  • lib/Parrot/Pmc2c/PMCEmitter.pm

     
    435435        NULL,       /* isa_hash */ 
    436436        NULL,       /* class */ 
    437437        NULL,       /* mro */ 
     438        inh_args,   /* inheritable_args */ 
    438439        NULL,       /* ro_variant_vtable */ 
    439440        $methlist 
    440441    }; 
     
    487488void 
    488489Parrot_${classname}_class_init(PARROT_INTERP, int entry, int pass) 
    489490{ 
     491    static const char inh_args [] = 
     492EOC 
     493    $cout .= '        "'; 
     494 
     495    my $attributes = $self->attributes; 
     496    foreach my $attribute ( @$attributes ) { 
     497        # Temporarily all attributes are listed here, 
     498        # TODO: select the inheritables with same criteria as generate_accessor 
     499        $cout .= $attribute->name; 
     500        $cout .= ' '; 
     501    } 
     502 
     503    $cout .= "\";\n"; 
     504    $cout .= <<"EOC"; 
    490505$vtable_decl 
    491506EOC 
    492507 
  • lib/Parrot/Pmc2c/Attribute.pm

     
    104104    my $isptrtostring = qr/STRING\s*\*$/; 
    105105    my $isptrtopmc    = qr/PMC\s*\*$/; 
    106106 
     107    my $inherit        = 1; 
    107108    my $decl           = <<"EOA"; 
    108109 
    109110/* Generated macro accessors for '$attrname' attribute of $pmcname PMC. */ 
     
    116117        $decl .= <<"EOA"; 
    117118            PMC *attr_value = VTABLE_get_attr_str(interp, \\ 
    118119                              pmc, Parrot_str_new_constant(interp, "$attrname")); \\ 
    119             (dest) = VTABLE_get_integer(interp, attr_value); \\ 
     120            (dest) = (PMC_IS_NULL(attr_value) ? (INTVAL) 0: VTABLE_get_integer(interp, attr_value)); \\ 
    120121EOA 
    121122    } 
    122123    elsif ($attrtype eq "FLOATVAL") { 
    123124        $decl .= <<"EOA"; 
    124125            PMC *attr_value = VTABLE_get_attr_str(interp, \\ 
    125126                              pmc, Parrot_str_new_constant(interp, "$attrname")); \\ 
    126             (dest) = VTABLE_get_number(interp, attr_value); \\ 
     127            (dest) =  (PMC_IS_NULL(attr_value) ? (FLOATVAL) 0.0: VTABLE_get_number(interp, attr_value)); \\ 
    127128EOA 
    128129    } 
    129130    elsif ($attrtype =~ $isptrtostring) { 
    130131        $decl .= <<"EOA"; 
    131132            PMC *attr_value = VTABLE_get_attr_str(interp, \\ 
    132133                              pmc, Parrot_str_new_constant(interp, "$attrname")); \\ 
    133             (dest) = VTABLE_get_string(interp, attr_value); \\ 
     134            (dest) =  (PMC_IS_NULL(attr_value) ? (STRING *) 0: VTABLE_get_string(interp, attr_value)); \\ 
    134135EOA 
    135136    } 
    136137    elsif ($attrtype =~ $isptrtopmc) { 
     
    141142    } 
    142143 
    143144    else { 
     145        $inherit = 0; 
    144146        $decl .= <<"EOA"; 
    145147            Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION, \\ 
    146148                "Attributes of type '$attrtype' cannot be " \\ 
     
    206208 
    207209EOA 
    208210 
     211    $self->{inherit} = $inherit; 
     212 
    209213    $h->emit($decl); 
    210214 
    211215    return 1;