X-Git-Url: http://git.asbjorn.it/?a=blobdiff_plain;f=lib%2Fas3%2Fabc.c;h=04ce6990ce0cd347478fc6b56396ff6be2a0dd30;hb=d39393539c367410d6e5c6b996f563d43b9a4260;hp=5c9b87b51d95a3880cf95ec70871ae21d4088d60;hpb=70080bc309ba2a414647d27e2f413f22bc7823e4;p=swftools.git diff --git a/lib/as3/abc.c b/lib/as3/abc.c index 5c9b87b..04ce699 100644 --- a/lib/as3/abc.c +++ b/lib/as3/abc.c @@ -175,12 +175,14 @@ abc_method_body_t* add_method(abc_file_t*file, abc_class_t*cls, multiname_t*retu /* construct code (method body) object */ NEW(abc_method_body_t,c); array_append(file->method_bodies, NO_KEY, c); + c->index = array_length(file->method_bodies); c->file = file; c->traits = list_new(); c->code = 0; /* construct method object */ NEW(abc_method_t,m); + m->index = array_length(file->methods); array_append(file->methods, NO_KEY, m); m->return_type = returntype; @@ -260,7 +262,13 @@ abc_method_body_t* abc_class_method(abc_class_t*cls, multiname_t*returntype, cha va_start(va, num_params); abc_method_body_t* c = add_method(cls->file, cls, returntype, num_params, va); va_end(va); - list_append(cls->traits, trait_new_method(multiname_fromstring(name), c->method)); + trait_t*t = trait_new_method(multiname_fromstring(name), c->method); + c->method->trait = t; + /* start assigning traits at position #1. + Weird things happen when assigning slot 0- slot 0 and 1 seem + to be identical */ + t->slot_id = list_length(cls->traits)+1; + list_append(cls->traits, t); return c; } @@ -268,13 +276,26 @@ trait_t* abc_class_slot(abc_class_t*cls, char*name, multiname_t*type) { abc_file_t*file = cls->file; multiname_t*m_name = multiname_fromstring(name); - multiname_t*m_type = type; + multiname_t*m_type = multiname_clone(type); trait_t*t = trait_new_member(m_type, m_name, 0); - t->slot_id = list_length(cls->traits); + t->slot_id = list_length(cls->traits)+1; list_append(cls->traits, t); return t; } +trait_t* abc_class_find_slotid(abc_class_t*cls, int slotid) +{ + trait_list_t*l; + trait_t*t=0; + for(l=cls->traits;l;l=l->next) { + if(l->trait->slot_id==slotid) { + t=l->trait; + break; + } + } + return t; +} + void abc_method_body_addClassTrait(abc_method_body_t*code, char*multiname, int slotid, abc_class_t*cls) { abc_file_t*file = code->file; @@ -343,7 +364,12 @@ static void dump_method(FILE*fo, const char*prefix, const char*type, const char* if(flags&METHOD_SET_DXNS) {fprintf(fo, " set_dxns");flags&=~METHOD_SET_DXNS;} if(flags&METHOD_HAS_PARAM_NAMES) {fprintf(fo, " has_param_names");flags&=~METHOD_HAS_PARAM_NAMES;} if(flags) fprintf(fo, " %02x", flags); - fprintf(fo, "]\n"); + fprintf(fo, "]"); + + if(m->trait) { + fprintf(fo, " slot:%d", m->trait->slot_id); + } + fprintf(fo, "\n"); char prefix2[80]; @@ -406,10 +432,12 @@ static trait_list_t* traits_parse(TAG*tag, pool_t*pool, abc_file_t*file) if(kind == TRAIT_METHOD || kind == TRAIT_GETTER || kind == TRAIT_SETTER) { // method / getter / setter trait->disp_id = swf_GetU30(tag); trait->method = (abc_method_t*)array_getvalue(file->methods, swf_GetU30(tag)); + trait->method->trait = trait; DEBUG printf(" method/getter/setter\n"); } else if(kind == TRAIT_FUNCTION) { // function trait->slot_id = swf_GetU30(tag); trait->method = (abc_method_t*)array_getvalue(file->methods, swf_GetU30(tag)); + trait->method->trait = trait; } else if(kind == TRAIT_CLASS) { // class trait->slot_id = swf_GetU30(tag); trait->cls = (abc_class_t*)array_getvalue(file->classes, swf_GetU30(tag)); @@ -688,7 +716,6 @@ void* swf_ReadABC(TAG*tag) DEBUG printf("method %d) %s %s flags=%02x\n", t, m->name, params_tostring(m->parameters), m->flags); if(m->flags&0x08) { - /* TODO optional parameters */ m->optional_parameters = list_new(); int num = swf_GetU30(tag); int s; @@ -707,6 +734,7 @@ void* swf_ReadABC(TAG*tag) l = l->next; } } + m->index = array_length(file->methods); array_append(file->methods, NO_KEY, m); } @@ -874,6 +902,7 @@ void swf_WriteABC(TAG*abctag, void*code) if(!(c->flags&CLASS_INTERFACE)) { NEW(abc_method_t,m);array_append(file->methods, NO_KEY, m); NEW(abc_method_body_t,body);array_append(file->method_bodies, NO_KEY, body); + // don't bother to set m->index body->method = m; m->body = body; __ returnvoid(body); c->constructor = m; @@ -1061,10 +1090,15 @@ void swf_WriteABC(TAG*abctag, void*code) //swf_SetU30(tag, c->old.max_scope_depth); swf_SetU30(tag, c->stats->max_stack); - if(list_length(c->method->parameters)+1 <= c->stats->local_count) + + int param_num = list_length(c->method->parameters)+1; + if(c->method->flags&METHOD_NEED_REST) + param_num++; + if(param_num <= c->stats->local_count) swf_SetU30(tag, c->stats->local_count); else - swf_SetU30(tag, list_length(c->method->parameters)+1); + swf_SetU30(tag, param_num); + swf_SetU30(tag, c->init_scope_depth); swf_SetU30(tag, c->stats->max_scope_depth+ c->init_scope_depth);