X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=lib%2Fas3%2Fabc.c;h=330417d4903d80f411c1e9d48b0ea539fa594b8b;hb=e4687b3aa2aed49fb16ba9e9561344d808750297;hp=43753000c42f973f92e8553656d6b3a763fb0765;hpb=3e3788c55ee5a26eb9973274c3c5ad9bb7495b4d;p=swftools.git diff --git a/lib/as3/abc.c b/lib/as3/abc.c index 4375300..330417d 100644 --- a/lib/as3/abc.c +++ b/lib/as3/abc.c @@ -119,7 +119,8 @@ abc_file_t*abc_file_new() abc_class_t* abc_class_new(abc_file_t*file, multiname_t*classname, multiname_t*superclass) { NEW(abc_class_t,c); - array_append(file->classes, NO_KEY, c); + if(file) + array_append(file->classes, NO_KEY, c); c->file = file; c->classname = multiname_clone(classname); @@ -157,10 +158,9 @@ void abc_class_add_interface(abc_class_t*c, multiname_t*interface) list_append(c->interfaces, multiname_clone(interface)); } -abc_method_t* abc_method_new(abc_file_t*file, multiname_t*returntype, char body) +void abc_method_init(abc_method_t*m, abc_file_t*file, multiname_t*returntype, char body) { /* 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; @@ -178,7 +178,11 @@ abc_method_t* abc_method_new(abc_file_t*file, multiname_t*returntype, char body) m->body = c; c->method = m; } - +} +abc_method_t* abc_method_new(abc_file_t*file, multiname_t*returntype, char body) +{ + NEW(abc_method_t,m); + abc_method_init(m, file, returntype, body); return m; } @@ -281,11 +285,11 @@ trait_t* abc_class_staticslot(abc_class_t*cls, multiname_t*name, multiname_t*typ } -trait_t* abc_class_find_slotid(abc_class_t*cls, int slotid) +trait_t* traits_find_slotid(trait_list_t*traits, int slotid) { trait_list_t*l; trait_t*t=0; - for(l=cls->traits;l;l=l->next) { + for(l=traits;l;l=l->next) { if(l->trait->slot_id==slotid) { t=l->trait; break; @@ -342,7 +346,7 @@ static void dump_method(FILE*fo, const char*prefix, if(m->return_type) return_type = multiname_tostring(m->return_type); else - return_type = strdup("void"); + return_type = strdup("*"); fprintf(fo, "%s", prefix); fprintf(fo, "%s %s ", attr, type); @@ -588,7 +592,7 @@ static void traits_dump(FILE*fo, const char*prefix, trait_list_t*traits, abc_fil char*value = constant_tostring(trait->value); fprintf(fo, "%sslot %d: %s %s:%s %s %s\n", prefix, trait->slot_id, kind==TRAIT_CONST?"const":"var", name, type_name, - value?"=":"", value?value:""); + trait->value?"=":"", trait->value?value:""); if(value) free(value); free(type_name); } else { @@ -644,6 +648,8 @@ void* swf_DumpABC(FILE*fo, void*code, char*prefix) char*supername = multiname_tostring(cls->superclass); fprintf(fo, " extends %s", supername); free(supername); + } + if(cls->interfaces) { multiname_list_t*ilist = cls->interfaces; if(ilist) fprintf(fo, " implements"); @@ -930,6 +936,8 @@ static pool_t*writeABC(TAG*abctag, void*code, pool_t*pool) abc_file_t*file = (abc_file_t*)code; if(!pool) pool = pool_new(); + if(!file) + file = abc_file_new(); TAG*tmp = swf_InsertTag(0,0); TAG*tag = tmp; @@ -944,7 +952,11 @@ static pool_t*writeABC(TAG*abctag, void*code, pool_t*pool) 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); + if(c->superclass && c->superclass->name && strcmp(c->superclass->name,"Object")) { + body->code = abc_getlocal_0(body->code); + body->code = abc_constructsuper(body->code, 0); + } + body->code = abc_returnvoid(body->code); c->constructor = m; } else { NEW(abc_method_t,m);array_append(file->methods, NO_KEY, m); @@ -955,7 +967,7 @@ static pool_t*writeABC(TAG*abctag, void*code, pool_t*pool) 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); body->method = m; m->body = body; - __ returnvoid(body); + body->code = abc_returnvoid(0); c->static_constructor = m; } } @@ -1119,6 +1131,9 @@ static pool_t*writeABC(TAG*abctag, void*code, pool_t*pool) swf_SetU30(tag, file->scripts->num); for(t=0;tscripts->num;t++) { abc_script_t*s = (abc_script_t*)array_getvalue(file->scripts, t); + if(!s->method->body || !s->method->body->code) { + fprintf(stderr, "Internal Error: initscript has no body\n"); + } swf_SetU30(tag, s->method->index); //!=t! traits_write(pool, tag, s->traits); }