+static void dump_traits(FILE*fo, const char*prefix, trait_list_t*traits, abc_file_t*file);
+
+static void dump_method(FILE*fo, const char*prefix, const char*type, const char*name, abc_method_t*m, abc_file_t*file)
+{
+ const char*return_type = "";
+ if(m->return_type)
+ return_type = multiname_to_string(m->return_type);
+
+ char*paramstr = params_to_string(m->parameters);
+
+ fprintf(fo, "%s%s %s %s=%s %s\n", prefix, type, return_type, name, m->name, paramstr);
+
+ abc_method_body_t*c = m->body;
+ if(!c) {
+ return;
+ }
+
+ fprintf(fo, "%s[%d %d %d %d %d]\n", prefix, c->max_stack, c->local_count, c->init_scope_depth, c->max_scope_depth, c->exception_count);
+
+ char prefix2[80];
+ sprintf(prefix2, "%s ", prefix);
+ if(c->traits)
+ dump_traits(fo, prefix, c->traits, file);
+ fprintf(fo, "%s{\n", prefix);
+ dump_code(c->code, file, prefix2, fo);
+ fprintf(fo, "%s}\n\n", prefix);
+}
+
+static void traits_free(trait_list_t*traits)
+{
+ trait_list_t*t = traits;
+ while(t) {
+ free(t->trait);t->trait = 0;
+ t = t->next;
+ }
+ list_free(traits);
+}
+
+static trait_list_t* traits_parse(TAG*tag, pool_t*pool, abc_file_t*file)
+{
+ int num_traits = swf_GetU30(tag);
+ trait_list_t*traits = list_new();
+ int t;
+ if(num_traits) {
+ DEBUG printf("%d traits\n", num_traits);
+ }
+
+ for(t=0;t<num_traits;t++) {
+ trait_t*trait = malloc(sizeof(trait_t));
+ memset(trait, 0, sizeof(trait_t));
+ list_append(traits, trait);
+
+ trait->name = pool_lookup_multiname(pool, swf_GetU30(tag)); // always a QName (ns,name)
+
+ const char*name = 0;
+ DEBUG name = multiname_to_string(trait->name);
+ U8 kind = swf_GetU8(tag);
+ U8 attributes = kind&0xf0;
+ kind&=0x0f;
+ trait->kind = kind;
+ trait->attributes = attributes;
+ DEBUG printf(" trait %d) %s type=%02x\n", t, name, kind);
+ 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));
+ 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));
+ } else if(kind == TRAIT_CLASS) { // class
+ trait->slot_id = swf_GetU30(tag);
+ trait->cls = (abc_class_t*)array_getvalue(file->classes, swf_GetU30(tag));
+ DEBUG printf(" class %s %d %d\n", name, trait->slot_id, trait->cls);
+ } else if(kind == TRAIT_SLOT || kind == TRAIT_CONST) { // slot, const
+ /* a slot is a variable in a class that is shared amonst all instances
+ of the same type, but which has a unique location in each object
+ (in other words, slots are non-static, traits are static)
+ */
+ trait->slot_id = swf_GetU30(tag);
+ trait->type_name = (multiname_t*)array_getvalue(pool->multinames, swf_GetU30(tag));
+ trait->vindex = swf_GetU30(tag);
+ if(trait->vindex) {
+ trait->vkind = swf_GetU8(tag);
+ }
+ DEBUG printf(" slot %s %d %s (vindex=%d)\n", name, trait->slot_id, trait->type_name->name, trait->vindex);
+ } else {
+ fprintf(stderr, "Can't parse trait type %d\n", kind);
+ }
+ if(attributes&0x40) {
+ int num = swf_GetU30(tag);
+ int s;
+ for(s=0;s<num;s++) {
+ swf_GetU30(tag); //index into metadata array
+ }
+ }
+ }
+ return traits;
+}
+
+void traits_skip(TAG*tag)
+{
+ int num_traits = swf_GetU30(tag);
+ int t;
+ for(t=0;t<num_traits;t++) {
+ swf_GetU30(tag);
+ U8 kind = swf_GetU8(tag);
+ U8 attributes = kind&0xf0;
+ kind&=0x0f;
+ swf_GetU30(tag);
+ swf_GetU30(tag);
+ if(kind == TRAIT_SLOT || kind == TRAIT_CONST) {
+ if(swf_GetU30(tag)) swf_GetU8(tag);
+ } else if(kind>TRAIT_CONST) {
+ fprintf(stderr, "Can't parse trait type %d\n", kind);
+ }
+ if(attributes&0x40) {
+ int s, num = swf_GetU30(tag);
+ for(s=0;s<num;s++) swf_GetU30(tag);
+ }
+ }
+}
+
+
+static void traits_write(pool_t*pool, TAG*tag, trait_list_t*traits)