Ticket #299: attributes_inheritance.patch
File attributes_inheritance.patch, 7.1 KB (added by NotFound, 13 years ago) |
---|
-
src/pmc/exceptionhandler.pmc
192 192 STRING * const sev = CONST_STRING(interp, "severity"); 193 193 STRING * const ex_str = CONST_STRING(interp, "Exception"); 194 194 195 Parrot_ExceptionHandler_attributes * const core_struct =196 PARROT_EXCEPTIONHANDLER(SELF);197 195 INTVAL severity = VTABLE_get_integer_keyed_str(interp, exception, sev); 198 196 199 197 if (exception->vtable->base_type == enum_class_Exception 200 198 || 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; 202 202 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); 203 206 204 if (severity < core_struct->min_severity) {207 if (severity < min_severity) { 205 208 RETURN(INTVAL 0); 206 209 } 207 if (core_struct->max_severity > 0 208 && severity > core_struct->max_severity) { 210 if (max_severity > 0 && severity > max_severity) { 209 211 RETURN(INTVAL 0); 210 212 } 211 213 if (! PMC_IS_NULL(handled_types)) { … … 222 224 223 225 RETURN(INTVAL 0); 224 226 } 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); 227 229 const INTVAL type = VTABLE_get_integer_keyed_str(interp, exception, CONST_STRING(interp, "type")); 228 230 INTVAL i; 229 231 230 232 for (i = 0; i < elems; i++) { 231 233 const INTVAL handled_type = VTABLE_get_integer_keyed_int(interp, 232 core_struct->handled_types_except, i);234 handled_types_except, i); 233 235 if (handled_type == type) 234 236 RETURN(INTVAL 0); 235 237 } 236 238 237 239 RETURN(INTVAL 1); 238 240 } 239 else if (core_struct->max_severity > 0 || 240 core_struct->min_severity > 0) { 241 else if (max_severity > 0 || min_severity > 0) { 241 242 RETURN(INTVAL 1); 242 243 } 243 244 -
src/pmc/pmcproxy.pmc
160 160 Parrot_oo_extract_methods_from_namespace(interp, SELF, 161 161 proxy_info->_namespace); 162 162 } 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 } 163 180 } 164 181 165 182 /* -
lib/Parrot/Vtable.pm
175 175 PMC *pmc_class; /* for PMCs: a PMC of that type 176 176 for objects: the class PMC */ 177 177 PMC *mro; /* array PMC of [class, parents ... ] */ 178 const char *inheritable_args; /* list of ARGS inheritable from classes */ 178 179 struct _vtable *ro_variant_vtable; /* A variant of this vtable with the 179 180 opposite IS_READONLY flag */ 180 181 /* Vtable Functions */ -
lib/Parrot/Pmc2c/PMCEmitter.pm
435 435 NULL, /* isa_hash */ 436 436 NULL, /* class */ 437 437 NULL, /* mro */ 438 inh_args, /* inheritable_args */ 438 439 NULL, /* ro_variant_vtable */ 439 440 $methlist 440 441 }; … … 487 488 void 488 489 Parrot_${classname}_class_init(PARROT_INTERP, int entry, int pass) 489 490 { 491 static const char inh_args [] = 492 EOC 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"; 490 505 $vtable_decl 491 506 EOC 492 507 -
lib/Parrot/Pmc2c/Attribute.pm
104 104 my $isptrtostring = qr/STRING\s*\*$/; 105 105 my $isptrtopmc = qr/PMC\s*\*$/; 106 106 107 my $inherit = 1; 107 108 my $decl = <<"EOA"; 108 109 109 110 /* Generated macro accessors for '$attrname' attribute of $pmcname PMC. */ … … 116 117 $decl .= <<"EOA"; 117 118 PMC *attr_value = VTABLE_get_attr_str(interp, \\ 118 119 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)); \\ 120 121 EOA 121 122 } 122 123 elsif ($attrtype eq "FLOATVAL") { 123 124 $decl .= <<"EOA"; 124 125 PMC *attr_value = VTABLE_get_attr_str(interp, \\ 125 126 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)); \\ 127 128 EOA 128 129 } 129 130 elsif ($attrtype =~ $isptrtostring) { 130 131 $decl .= <<"EOA"; 131 132 PMC *attr_value = VTABLE_get_attr_str(interp, \\ 132 133 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)); \\ 134 135 EOA 135 136 } 136 137 elsif ($attrtype =~ $isptrtopmc) { … … 141 142 } 142 143 143 144 else { 145 $inherit = 0; 144 146 $decl .= <<"EOA"; 145 147 Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION, \\ 146 148 "Attributes of type '$attrtype' cannot be " \\ … … 206 208 207 209 EOA 208 210 211 $self->{inherit} = $inherit; 212 209 213 $h->emit($decl); 210 214 211 215 return 1;