Ticket #299: attributes.patch
File attributes.patch, 5.7 KB (added by NotFound, 13 years ago) |
---|
-
src/pmc/object.pmc
104 104 return -1; 105 105 } 106 106 107 /* Get the first PMCProxy parent class, 108 * (works for single inheritance from a PMC, other usages untested) 109 * or PMCNULL if nothing appropiate is found 110 */ 111 static PMC * 112 getPMCProxy(PARROT_INTERP, PMC *self, STRING *name) 113 { 114 PMC *result = PMCNULL; 115 PMC *parents = PARROT_CLASS(PARROT_OBJECT(self)->_class)->all_parents; 116 INTVAL numparents = VTABLE_get_integer(interp, parents); 117 INTVAL i; 118 for (i= 0; i < numparents; ++i) { 119 if ((VTABLE_get_pmc_keyed_int(interp, parents, i)->vtable->base_type) 120 == enum_class_PMCProxy) { 121 STRING * const attrproxy = CONST_STRING(interp, "proxy"); 122 if (Parrot_str_not_equal(interp, name, attrproxy)) { 123 PMC *prx = VTABLE_get_attr_str(interp, self, attrproxy); 124 if (!(PMC_IS_NULL(prx) || prx == self)) 125 result = prx; 126 } 127 break; 128 } 129 } 130 return result; 131 } 132 107 133 pmclass Object need_ext { 108 134 ATTR PMC *_class; /* The class this is an instance of. */ 109 135 ATTR PMC *attrib_store; /* The attributes store - a resizable PMC array. */ … … 221 247 /* Look up the index. */ 222 248 index = get_attrib_index(interp, obj->_class, name); 223 249 224 /* If lookup failed, exception. */ 225 if (index == -1) 250 /* If lookup failed, use proxy PMC or exception. */ 251 if (index == -1) { 252 PMC *prx = getPMCProxy(interp, SELF, name); 253 if (! PMC_IS_NULL(prx)) 254 return VTABLE_get_attr_str(interp, prx, name); 226 255 Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_ATTRIB_NOT_FOUND, 227 256 "No such attribute '%S'", name); 257 } 228 258 229 259 return VTABLE_get_pmc_keyed_int(interp, obj->attrib_store, index); 230 260 } … … 281 311 282 312 index = get_attrib_index(interp, obj->_class, name); 283 313 284 /* If lookup failed, exception. */ 285 if (index == -1) 314 /* If lookup failed, use proxy PMC or exception. */ 315 if (index == -1) { 316 PMC *prx = getPMCProxy(interp, SELF, name); 317 if (! PMC_IS_NULL(prx)) { 318 VTABLE_set_attr_str(interp, prx, name, value); 319 return; 320 } 286 321 Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_ATTRIB_NOT_FOUND, 287 322 "No such attribute '%S'", name); 323 } 288 324 289 325 VTABLE_set_pmc_keyed_int(interp, obj->attrib_store, index, value); 290 326 } -
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 /* 195 196 Parrot_ExceptionHandler_attributes * const core_struct = 196 197 PARROT_EXCEPTIONHANDLER(SELF); 198 */ 197 199 INTVAL severity = VTABLE_get_integer_keyed_str(interp, exception, sev); 198 200 199 201 if (exception->vtable->base_type == enum_class_Exception 200 202 || VTABLE_isa(INTERP, exception, ex_str)) { 201 PMC * handled_types; 203 PMC *handled_types; 204 PMC *handled_types_except; 205 INTVAL min_severity; 206 INTVAL max_severity; 202 207 GET_ATTR_handled_types(INTERP, SELF, handled_types); 208 GET_ATTR_handled_types_except(INTERP, SELF, handled_types_except); 209 GET_ATTR_min_severity(INTERP, SELF, min_severity); 210 GET_ATTR_max_severity(INTERP, SELF, max_severity); 203 211 204 if (severity < core_struct->min_severity) {212 if (severity < min_severity) { 205 213 RETURN(INTVAL 0); 206 214 } 207 if ( core_struct->max_severity > 0208 && severity > core_struct->max_severity) {215 if (max_severity > 0 216 && severity > max_severity) { 209 217 RETURN(INTVAL 0); 210 218 } 211 219 if (! PMC_IS_NULL(handled_types)) { … … 222 230 223 231 RETURN(INTVAL 0); 224 232 } 225 if ( core_struct->handled_types_except != PMCNULL) {226 const INTVAL elems = VTABLE_elements(interp, core_struct->handled_types_except);233 if (handled_types_except != PMCNULL) { 234 const INTVAL elems = VTABLE_elements(interp, handled_types_except); 227 235 const INTVAL type = VTABLE_get_integer_keyed_str(interp, exception, CONST_STRING(interp, "type")); 228 236 INTVAL i; 229 237 230 238 for (i = 0; i < elems; i++) { 231 239 const INTVAL handled_type = VTABLE_get_integer_keyed_int(interp, 232 core_struct->handled_types_except, i);240 handled_types_except, i); 233 241 if (handled_type == type) 234 242 RETURN(INTVAL 0); 235 243 } 236 244 237 245 RETURN(INTVAL 1); 238 246 } 239 else if ( core_struct->max_severity > 0 ||240 core_struct->min_severity > 0) {247 else if (max_severity > 0 || 248 min_severity > 0) { 241 249 RETURN(INTVAL 1); 242 250 } 243 251 -
t/pmc/exceptionhandler.t
200 200 throw $P0 201 201 202 202 subclassed_failed: 203 .get_results($P1) 203 204 .return(0) 204 205 205 206 subclassed_handler: 207 .get_results($P1) 206 208 .return(1) 207 209 .end 208 210