X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=lib%2Fas3%2Fregistry.c;h=2789fdf7e021129421d16967b5cbf71aa93ab941;hb=36a1fac8ea3a7457f25b1b4209b5fc918cc6af44;hp=d1c13e3fa50e76f32d21517f7c06b21e81df31c3;hpb=434d5040b814eae784d080c695fe8c3d370a166b;p=swftools.git diff --git a/lib/as3/registry.c b/lib/as3/registry.c index d1c13e3..2789fdf 100644 --- a/lib/as3/registry.c +++ b/lib/as3/registry.c @@ -48,6 +48,12 @@ static unsigned int slotinfo_hash(slotinfo_t*c) hash = crc32_add_string(hash, c->name); return hash; } +static unsigned int memberinfo_hash(slotinfo_t*c) +{ + unsigned int hash = 0; + hash = crc32_add_string(hash, c->name); + return hash; +} static void* dummy_clone(void*other) {return other;} static void dummy_destroy(slotinfo_t*c) {} @@ -58,7 +64,81 @@ type_t slotinfo_type = { dup: (dup_func)dummy_clone, // all signatures are static free: (free_func)dummy_destroy, }; +type_t memberinfo_type = { + hash: (hash_func)memberinfo_hash, + equals: (equals_func)slotinfo_equals, + dup: (dup_func)dummy_clone, // all signatures are static + free: (free_func)dummy_destroy, +}; + +// ----------------------- resolving ---------------------------------- +slotinfo_t* registry_resolve(slotinfo_t*_s) +{ + if(!_s || _s->kind != INFOTYPE_UNRESOLVED) + return _s; + unresolvedinfo_t*s = (unresolvedinfo_t*)_s; + + if(s->package) + return registry_find(s->package, s->name); + + namespace_list_t*l = s->nsset; + while(l) { + slotinfo_t* n = registry_find(l->namespace->name, s->name); + if(n) return n; + l = l->next; + } + return 0; +} +static slotinfo_list_t*unresolved = 0; +static void schedule_for_resolve(slotinfo_t*s) +{ + list_append(unresolved, s); +} +static void resolve_on_slot(slotinfo_t*_member) +{ + if(_member->kind == INFOTYPE_SLOT) { + varinfo_t*member = (varinfo_t*)_member; + member->type = (classinfo_t*)registry_resolve((slotinfo_t*)member->type); + } else if(_member->kind == INFOTYPE_METHOD) { + methodinfo_t*member = (methodinfo_t*)_member; + member->return_type = (classinfo_t*)registry_resolve((slotinfo_t*)member->return_type); + classinfo_list_t*l = member->params; + while(l) { + l->classinfo = (classinfo_t*)registry_resolve((slotinfo_t*)l->classinfo); + l = l->next; + } + } else fprintf(stderr, "Internal Error: bad slot %s", _member->name); +} +static void resolve_on_class(slotinfo_t*_cls) +{ + classinfo_t*cls = (classinfo_t*)_cls; + cls->superclass = (classinfo_t*)registry_resolve((slotinfo_t*)cls->superclass); + DICT_ITERATE_DATA(&cls->members,slotinfo_t*,m) { + resolve_on_slot(m); + } + int t=0; + while(cls->interfaces[t]) { + cls->interfaces[t] = (classinfo_t*)registry_resolve((slotinfo_t*)cls->interfaces[t]); + t++; + } +} +void registry_resolve_all() +{ + while(unresolved) { + slotinfo_t*_s = unresolved->slotinfo; + if(_s->kind == INFOTYPE_CLASS) { + resolve_on_class(_s); + } else if(_s->kind == INFOTYPE_METHOD || _s->kind == INFOTYPE_SLOT) { + resolve_on_slot(_s); + } else { + fprintf(stderr, "Internal Error: object %s.%s has bad type\n", _s->package, _s->name); + } + slotinfo_list_t*tofree = unresolved; + unresolved = unresolved->next; + free(tofree); + } +} // ------------------------- constructors -------------------------------- #define AVERAGE_NUMBER_OF_MEMBERS 8 @@ -71,7 +151,9 @@ classinfo_t* classinfo_register(int access, const char*package, const char*name, c->package = package; c->name = name; dict_put(registry_classes, c, c); - dict_init2(&c->members, &slotinfo_type, AVERAGE_NUMBER_OF_MEMBERS); + dict_init2(&c->members, &memberinfo_type, AVERAGE_NUMBER_OF_MEMBERS); + + schedule_for_resolve((slotinfo_t*)c); return c; } methodinfo_t* methodinfo_register_onclass(classinfo_t*cls, U8 access, const char*ns, const char*name) @@ -106,6 +188,8 @@ methodinfo_t* methodinfo_register_global(U8 access, const char*package, const ch m->name = name; m->parent = 0; dict_put(registry_classes, m, m); + + schedule_for_resolve((slotinfo_t*)m); return m; } varinfo_t* varinfo_register_global(U8 access, const char*package, const char*name) @@ -118,6 +202,8 @@ varinfo_t* varinfo_register_global(U8 access, const char*package, const char*nam m->name = name; m->parent = 0; dict_put(registry_classes, m, m); + + schedule_for_resolve((slotinfo_t*)m); return m; } @@ -188,12 +274,14 @@ memberinfo_t* registry_findmember(classinfo_t*cls, const char*ns, const char*nam int t=0; while(cls->interfaces[t]) { classinfo_t*s = cls->interfaces[t]; - while(s) { - m = (slotinfo_t*)dict_lookup(&s->members, &tmp); - if(m) { - return (memberinfo_t*)m; + if(s->kind != INFOTYPE_UNRESOLVED) { + while(s) { + m = (slotinfo_t*)dict_lookup(&s->members, &tmp); + if(m) { + return (memberinfo_t*)m; + } + s = s->superclass; } - s = s->superclass; } t++; } @@ -256,7 +344,7 @@ classinfo_t* slotinfo_asclass(slotinfo_t*f) { c->name = "undefined"; } - dict_init2(&c->members, &slotinfo_type, 1); + dict_init2(&c->members, &memberinfo_type, 1); c->data = f; dict_put(functionobjects, f, c); return c; @@ -276,6 +364,13 @@ classinfo_t* slotinfo_gettype(slotinfo_t*f) return registry_getanytype(); } } + +// ----------------------- package handling --------------------------- +char registry_ispackage(char*package) +{ + /* crude approximation of "the real thing", but sufficient for now */ + return !strncmp(package, "flash", 5); +} // ----------------------- builtin types ------------------------------ classinfo_t* registry_getanytype() {return 0;} @@ -328,6 +423,11 @@ classinfo_t* registry_getregexpclass() { if(!c) c = (classinfo_t*)registry_safefind("", "RegExp"); return c; } +classinfo_t* registry_getnamespaceclass() { + static classinfo_t*c = 0; + if(!c) c = (classinfo_t*)registry_safefind("", "Namespace"); + return c; +} classinfo_t* registry_getMovieClip() { static classinfo_t*c = 0; if(!c) c = (classinfo_t*)registry_safefind("flash.display", "MovieClip");