introduced cross-asset dependencies
[swftools.git] / lib / as3 / registry.c
index 4b6b66c..5c947e5 100644 (file)
@@ -73,20 +73,46 @@ type_t memberinfo_type = {
 };
 
 // ----------------------- assets -------------------------------------
-void registry_use(slotinfo_t*s)
+static void use_asset(asset_bundle_t*a)
 {
-    if(s->kind == INFOTYPE_CLASS) {
-       classinfo_t*c=(classinfo_t*)s;
-       if(c->assets) c->assets->used = 1;
-    } else if(s->kind == INFOTYPE_METHOD) {
-       methodinfo_t*m=(methodinfo_t*)s;
-       if(m->parent) {
-           registry_use((slotinfo_t*)m->parent);
+    a->used = 1;
+    asset_bundle_list_t*l = a->dependencies;
+    while(l) {
+       if(!l->asset_bundle->used) {
+           use_asset(l->asset_bundle);
        }
-    } else if(s->kind == INFOTYPE_VAR) {
-       varinfo_t*v=(varinfo_t*)s;
-       if(v->parent) {
-           registry_use((slotinfo_t*)v->parent);
+       l = l->next;
+    }
+}
+void registry_use(slotinfo_t*s)
+{
+    if(!s) return;
+    if(!(s->flags&FLAG_USED)) {
+       s->flags |= FLAG_USED;
+       if(s->kind == INFOTYPE_CLASS) {
+           classinfo_t*c=(classinfo_t*)s;
+           if(c->assets) {
+               use_asset(c->assets);
+           }
+           int t=0;
+           while(c->interfaces[t]) {
+               registry_use((slotinfo_t*)c->interfaces[t]);
+               t++;
+           }
+           while(c->superclass) {
+               c = c->superclass;
+               registry_use((slotinfo_t*)c);
+           }
+       } else if(s->kind == INFOTYPE_METHOD) {
+           methodinfo_t*m=(methodinfo_t*)s;
+           if(m->parent) {
+               registry_use((slotinfo_t*)m->parent);
+           }
+       } else if(s->kind == INFOTYPE_VAR) {
+           varinfo_t*v=(varinfo_t*)s;
+           if(v->parent) {
+               registry_use((slotinfo_t*)v->parent);
+           }
        }
     }
 }