implemented conditional compilation
[swftools.git] / lib / as3 / registry.c
index 316c71f..28f57a8 100644 (file)
@@ -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,6 +64,12 @@ 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)
@@ -139,7 +151,7 @@ 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;
@@ -278,12 +290,19 @@ memberinfo_t* registry_findmember(classinfo_t*cls, const char*ns, const char*nam
 
 memberinfo_t* registry_findmember_nsset(classinfo_t*cls, namespace_list_t*ns, const char*name, char superclasses)
 {
+    memberinfo_t*m = 0;
     while(ns) {
-        memberinfo_t*m = registry_findmember(cls, ns->namespace->name, name, superclasses);
+        m = registry_findmember(cls, ns->namespace->name, name, superclasses);
         if(m) return m;
         ns = ns->next;
     }
-    return registry_findmember(cls, "", name, superclasses);
+    m = registry_findmember(cls, "", name, superclasses);
+    if(m) return m;
+    /* TODO: it maybe would be faster to just store the builtin namespace as "" in
+             builtins.c */
+    m = registry_findmember(cls, "http://adobe.com/AS3/2006/builtin", name, superclasses);
+    if(m) return m;
+    return 0;
 }
 
 
@@ -322,17 +341,19 @@ classinfo_t* slotinfo_asclass(slotinfo_t*f) {
     classinfo_t*c = rfx_calloc(sizeof(classinfo_t)+sizeof(classinfo_t*));
     c->access = ACCESS_PUBLIC;
     c->package = "";
-    if(f->kind == INFOTYPE_METHOD)
+    if(f->kind == INFOTYPE_METHOD) {
         c->name = "Function";
-    else if(f->kind == INFOTYPE_CLASS)
+        c->superclass = registry_getobjectclass();
+    } else if(f->kind == INFOTYPE_CLASS) {
         c->name = "Class";
-    else if(f->kind == INFOTYPE_SLOT)
+        c->superclass = registry_getobjectclass();
+    } else if(f->kind == INFOTYPE_SLOT) {
         c->name = "Object";
-    else {
+    } else {
         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;
@@ -352,6 +373,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;}