added getarrayclass()
[swftools.git] / lib / as3 / registry.c
index 2263038..f160b5c 100644 (file)
@@ -93,13 +93,12 @@ classinfo_t* classinfo_register(int access, char*package, char*name, int num_int
     return c;
 }
 
-/* function pointers get their own type class */
-static dict_t* functionobjects = 0;
-classinfo_t* registry_getfunctionclass(memberinfo_t*f) {
-    if(!functionobjects) {
-        functionobjects = dict_new2(&ptr_type);
+static dict_t* classobjects = 0;
+classinfo_t* registry_getclassclass(classinfo_t*a) {
+    if(!classobjects) {
+        classobjects = dict_new2(&ptr_type);
     } else {
-        classinfo_t*c = dict_lookup(functionobjects, f);
+        classinfo_t*c = dict_lookup(classobjects, a);
         if(c)
             return c;
     }
@@ -107,11 +106,11 @@ classinfo_t* registry_getfunctionclass(memberinfo_t*f) {
     NEW(classinfo_t,c);
     c->access = ACCESS_PUBLIC;
     c->package = "";
-    c->name = "Function";
+    c->name = "Class";
     dict_init(&c->members,1);
-    dict_put(&c->members, "call", f);
+    c->cls = a;
 
-    dict_put(functionobjects, f, c);
+    dict_put(classobjects, a, c);
     return c;
 }
 
@@ -169,6 +168,43 @@ multiname_t* classinfo_to_multiname(classinfo_t*cls)
     return multiname_new(ns,cls->name);
 }
 
+// ----------------------- memberinfo methods ------------------------------
+
+/* function and class pointers get their own type class */
+static dict_t* functionobjects = 0;
+classinfo_t* memberinfo_asclass(memberinfo_t*f) {
+    if(!functionobjects) {
+        functionobjects = dict_new2(&ptr_type);
+    } else {
+        classinfo_t*c = dict_lookup(functionobjects, f);
+        if(c)
+            return c;
+    }
+
+    NEW(classinfo_t,c);
+    c->access = ACCESS_PUBLIC;
+    c->package = "";
+    c->name = "Function";
+    
+    dict_init(&c->members,1);
+    c->function = f;
+
+    dict_put(functionobjects, f, c);
+    return c;
+}
+
+classinfo_t* memberinfo_gettype(memberinfo_t*f)
+{
+    if(f) {
+       if(f->kind == MEMBER_METHOD) {
+           return memberinfo_asclass(f);
+       } else {
+           return f->type;
+       }
+    } else {
+       return registry_getanytype();
+    }
+}
 // ----------------------- builtin types ------------------------------
 classinfo_t* registry_getanytype() {return 0;}
 
@@ -176,6 +212,10 @@ char registry_isfunctionclass(classinfo_t*c) {
     return (c && c->package && c->name && 
             !strcmp(c->package, "") && !strcmp(c->name, "Function"));
 }
+char registry_isclassclass(classinfo_t*c) {
+    return (c && c->package && c->name && 
+            !strcmp(c->package, "") && !strcmp(c->name, "Class"));
+}
 
 classinfo_t* registry_getobjectclass() {
     static classinfo_t*c = 0;
@@ -187,6 +227,11 @@ classinfo_t* registry_getstringclass() {
     if(!c) c = registry_safefindclass("", "String");
     return c;
 }
+classinfo_t* registry_getarrayclass() {
+    static classinfo_t*c = 0;
+    if(!c) c = registry_safefindclass("", "Array");
+    return c;
+}
 classinfo_t* registry_getintclass() {
     static classinfo_t*c = 0;
     if(!c) c = registry_safefindclass("", "int");