X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=lib%2Fas3%2Fabc.c;h=e7690c3e109bb516bf51c495a79ae6728bcf01ab;hb=f0d1089c6506371456902bfef02776e3da65c204;hp=cea6338e6fc8e5f94d51866098f9a1253e88b2b3;hpb=d625d3512dabbc51ed13bc411369bb87344b0475;p=swftools.git diff --git a/lib/as3/abc.c b/lib/as3/abc.c index cea6338..e7690c3 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,18 +262,38 @@ 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; } -void abc_AddSlot(abc_class_t*cls, char*name, int slot, char*type) +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 = multiname_fromstring(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) @@ -342,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]; @@ -405,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)); @@ -706,6 +735,7 @@ void* swf_ReadABC(TAG*tag) l = l->next; } } + m->index = array_length(file->methods); array_append(file->methods, NO_KEY, m); } @@ -873,6 +903,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; @@ -1301,6 +1332,10 @@ void swf_AddButtonLinks(SWF*swf, char stop_each_frame, char events) __ debugline(f, 1); __ getlocal_0(f); __ pushscope(f); + if(stop_each_frame) { + __ findpropstrict(f, "[package]::stop"); + __ callpropvoid(f, "[package]::stop", 0); + } } if(tag->id == ST_DEFINEBUTTON || tag->id == ST_DEFINEBUTTON2) { @@ -1313,10 +1348,6 @@ void swf_AddButtonLinks(SWF*swf, char stop_each_frame, char events) __ getlex(f,functionname); __ callpropvoid(f, "::addEventListener" ,2); - if(stop_each_frame) { - __ findpropstrict(f, "[package]::stop"); - __ callpropvoid(f, "[package]::stop", 0); - } needs_framescript = 1; abc_method_body_t*h = @@ -1394,7 +1425,8 @@ void swf_AddButtonLinks(SWF*swf, char stop_each_frame, char events) if(tag->id == ST_DEFINEBUTTON || tag->id == ST_DEFINEBUTTON2) { char buttonname[80]; sprintf(buttonname, "::button%d", swf_GetDefineID(tag)); - abc_AddSlot(cls, buttonname, 0, "flash.display::SimpleButton"); + multiname_t*s = multiname_fromstring(buttonname); + abc_class_slot(cls, buttonname, s); } tag = tag->next; }