- SWF swf;
- memset(&swf, 0, sizeof(SWF));
- TAG*tag = swf_InsertTag(0, ST_RAWABC);
- memfile_t*file = memfile_open(filename);
- tag->data = file->data;
- tag->len = file->len;
- abc_file_t*abc = swf_ReadABC(tag);
- //swf_DumpABC(stdout, abc, "");
-
- int*index = malloc(abc->classes->num*sizeof(int));
- int t;
- tosort=abc->classes;
- for(t=0;t<abc->classes->num;t++) {index[t]=t;}
- qsort(index, abc->classes->num, sizeof(int), compare_classes);
-
- for(t=0;t<abc->classes->num;t++) {
- abc_class_t*cls = array_getvalue(abc->classes, index[t]);
- int access = cls->classname->ns->access;
- if(access==ACCESS_PRIVATE ||
- access==ACCESS_PACKAGEINTERNAL)
- continue;
- if(!strncmp(cls->classname->ns->name, "__AS3", 5))
- continue;
-
- const char*package = cls->classname->ns->name;
- const char*name = cls->classname->name;
- const char*superpackage = 0;
- const char*supername = 0;
- char*superid = 0;
- if(cls->superclass) {
- superpackage = cls->superclass->ns->name;
- supername = cls->superclass->name;
- superid = mkid(superpackage, supername);
- }
- char*id = mkid(package, name);
-
- if(pass==0)
- fprintf(fi, "static class_signature_t %s;\n", id);
- else if(pass==1) {
- fprintf(fi, "static class_signature_t %s = {0x%02x, \"%s\", \"%s\"", id, access, package, name);
- if(superid)
- fprintf(fi, ", &%s, interfaces:{", superid);
- else
- fprintf(fi, ", 0, {");
- if(cls->interfaces) {
- multiname_list_t*i=cls->interfaces;
- while(i) {
- char*iid = mkid2(i->multiname);
- fprintf(fi, "&%s, ", iid);
- i = i->next;
- }
- }
- fprintf(fi, "0}};\n");
- } else if(pass==2) {
- trait_list_t*l=cls->traits;
- fprintf(fi, " dict_put(d, &%s, &%s);\n", id, id);
- fprintf(fi, " dict_init(&%s.members, %d);\n", id, list_length(l)+1);
- int j;
- dict_t*d = dict_new();
- for(;l;l=l->next) {
- trait_t*trait = l->trait;
- if(trait->name->ns->access==ACCESS_PRIVATE)
- continue;
- char*type="something";
- const char*name = trait->name->name;
- if(dict_lookup(d, name)) {
- continue;
- } else {
- dict_put(d, (char*)name, (char*)name);
- }
- switch(trait->kind) {
- case TRAIT_METHOD: type="method";break;
- case TRAIT_CONST: type="const";break;
- case TRAIT_FUNCTION: type="function";break;
- case TRAIT_GETTER: type="member";break;
- case TRAIT_SETTER: type="member";break;
- case TRAIT_SLOT: type="member";break;
- case TRAIT_CLASS: type="subclass";break;
- }
- fprintf(fi, " dict_put(&%s.members, \"%s\", \"%s\");\n",
- id, name, type);
+ trait_t* x1 = *(trait_t**)v1;
+ trait_t* x2 = *(trait_t**)v2;
+ int i = strcmp(x1->name->ns->name, x2->name->ns->name);
+ if(i)
+ return i;
+ return strcmp(x1->name->name, x2->name->name);
+}
+
+dict_t* builtin_getclasses()
+{
+ return dict_new2(&slotinfo_type);
+}
+
+extern dict_t*registry_classes;
+
+char*mktype(slotinfo_t*s)
+{
+ if(s->kind == INFOTYPE_CLASS) {
+ return "classinfo_t";
+ } else if(s->kind == INFOTYPE_METHOD) {
+ return "methodinfo_t";
+ } else if(s->kind == INFOTYPE_VAR) {
+ return "varinfo_t";
+ }
+ return "**ERROR**";
+}
+
+void write_slotinfo(FILE*fi, slotinfo_t*s, char*id, char*prefix);
+
+void write_slotinfo_decl(FILE*fi, slotinfo_t*s, char*prefix)
+{
+ fprintf(fi, "%s", prefix);
+ char*id = mkid(s);
+ fprintf(fi, "static %s %s;\n", mktype(s), id);
+
+ if(s->kind == INFOTYPE_CLASS) {
+ classinfo_t*c = (classinfo_t*)s;
+ dict_t*d = &c->members;
+ int t;
+ for(t=0;t<d->hashsize;t++) {
+ dictentry_t*l = d->slots[t];
+ while(l) {
+ slotinfo_t*s2 = (slotinfo_t*)l->data;
+ fprintf(fi, "static %s %s;\n", mktype(s2), mkid2(id, s2->name));
+ l = l->next;