3 Routines for compiling Flash2 AVM2 ABC Actionscript
5 Extension module for the rfxswf library.
6 Part of the swftools package.
8 Copyright (c) 2008 Matthias Kramm <kramm@quiss.org>
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
29 static dict_t*classes=0;
31 // ----------------------- class signature ------------------------------
33 char classinfo_equals(classinfo_t*c1, classinfo_t*c2)
37 /* notice: access right is *not* respected */
38 if(!strcmp(c1->name, c2->name) &&
39 !strcmp(c1->package, c2->package)) {
44 static unsigned int classinfo_hash(classinfo_t*c)
46 unsigned int hash = 0;
47 hash = crc32_add_string(hash, c->package);
48 hash = crc32_add_string(hash, c->name);
52 static void* dummy_clone(void*other) {return other;}
53 static void dummy_destroy(classinfo_t*c) {}
55 type_t classinfo_type = {
56 hash: (hash_func)classinfo_hash,
57 equals: (equals_func)classinfo_equals,
58 /* all signatures are static */
59 dup: (dup_func)dummy_clone,
60 free: (free_func)dummy_destroy,
63 // ----------------------- function signature ------------------------------
65 static char memberinfo_equals(memberinfo_t*f1, memberinfo_t*f2)
67 return !strcmp(f1->name, f2->name);
69 static unsigned int memberinfo_hash(memberinfo_t*f)
71 return crc32_add_string(0, f->name);
73 type_t memberinfo_type = {
74 hash: (hash_func)memberinfo_hash,
75 equals: (equals_func)memberinfo_equals,
76 /* all signatures are static */
77 dup: (dup_func)dummy_clone,
78 free: (free_func)dummy_destroy,
81 // ------------------------- constructors --------------------------------
83 #define AVERAGE_NUMBER_OF_MEMBERS 8
84 classinfo_t* classinfo_register(int access, const char*package, const char*name, int num_interfaces)
86 classinfo_t*c = rfx_calloc(sizeof(classinfo_t)+(sizeof(classinfo_t*)*(num_interfaces+1)));
91 dict_put(classes, c, c);
92 dict_init(&c->members,AVERAGE_NUMBER_OF_MEMBERS);
96 static dict_t* classobjects = 0;
97 classinfo_t* registry_getclassclass(classinfo_t*a) {
99 classobjects = dict_new2(&ptr_type);
101 classinfo_t*c = dict_lookup(classobjects, a);
106 classinfo_t*c = rfx_calloc(sizeof(classinfo_t)+sizeof(classinfo_t*));
107 c->access = ACCESS_PUBLIC;
110 dict_init(&c->members,1);
113 dict_put(classobjects, a, c);
117 memberinfo_t* memberinfo_register(classinfo_t*cls, const char*name, U8 kind)
121 m->name = strdup(name);
123 dict_put(&cls->members, name, m);
126 memberinfo_t* memberinfo_register_global(U8 access, const char*package, const char*name, U8 kind)
128 NEW(memberinfo_t, m);
130 m->flags = FLAG_STATIC;
134 classinfo_t*c = classinfo_register(access, package, name, 0);
136 c->flags |= FLAG_METHOD;
141 // --------------- builtin classes (from builtin.c) ----------------------
145 classes = builtin_getclasses();
147 classinfo_t* registry_safefindclass(const char*package, const char*name)
149 classinfo_t*c = registry_findclass(package, name);
154 classinfo_t* registry_findclass(const char*package, const char*name)
158 tmp.package = package;
160 classinfo_t* c = (classinfo_t*)dict_lookup(classes, &tmp);
162 printf("%s.%s->%08x (%s.%s)\n", package, name, c, c->package, c->name);*/
165 void registry_dumpclasses()
168 for(t=0;t<classes->hashsize;t++) {
169 dictentry_t*e = classes->slots[t];
171 dictentry_t*next = e->next;
172 classinfo_t*i = (classinfo_t*)e->key;
173 printf("%s.%s\n", i->package, i->name);
179 memberinfo_t* registry_findmember(classinfo_t*cls, const char*name, char recursive)
182 return (memberinfo_t*)dict_lookup(&cls->members, name);
184 /* look at classes directly extended by this class */
188 m = (memberinfo_t*)dict_lookup(&s->members, name);
192 /* look at interfaces, and parent interfaces */
194 while(cls->interfaces[t]) {
195 classinfo_t*s = cls->interfaces[t];
197 m = (memberinfo_t*)dict_lookup(&s->members, name);
206 void registry_fill_multiname(multiname_t*m, namespace_t*n, classinfo_t*c)
210 m->ns->access = c->access;
211 m->ns->name = (char*)c->package;
213 m->namespace_set = 0;
215 multiname_t* classinfo_to_multiname(classinfo_t*cls)
220 namespace_t ns = {cls->access, (char*)cls->package};
221 return multiname_new(&ns,cls->name);
224 // ----------------------- memberinfo methods ------------------------------
226 /* function and class pointers get their own type class */
227 static dict_t* functionobjects = 0;
228 classinfo_t* memberinfo_asclass(memberinfo_t*f) {
229 if(!functionobjects) {
230 functionobjects = dict_new2(&ptr_type);
232 classinfo_t*c = dict_lookup(functionobjects, f);
237 classinfo_t*c = rfx_calloc(sizeof(classinfo_t)+sizeof(classinfo_t*));
238 c->access = ACCESS_PUBLIC;
240 c->name = "Function";
242 dict_init(&c->members,1);
245 dict_put(functionobjects, f, c);
249 classinfo_t* memberinfo_gettype(memberinfo_t*f)
252 if(f->kind == MEMBER_METHOD) {
253 return memberinfo_asclass(f);
258 return registry_getanytype();
261 // ----------------------- builtin types ------------------------------
262 classinfo_t* registry_getanytype() {return 0;}
264 char registry_isfunctionclass(classinfo_t*c) {
265 return (c && c->package && c->name &&
266 !strcmp(c->package, "") && !strcmp(c->name, "Function"));
268 char registry_isclassclass(classinfo_t*c) {
269 return (c && c->package && c->name &&
270 !strcmp(c->package, "") && !strcmp(c->name, "Class"));
273 classinfo_t* registry_getobjectclass() {
274 static classinfo_t*c = 0;
275 if(!c) c = registry_safefindclass("", "Object");
278 classinfo_t* registry_getstringclass() {
279 static classinfo_t*c = 0;
280 if(!c) c = registry_safefindclass("", "String");
283 classinfo_t* registry_getarrayclass() {
284 static classinfo_t*c = 0;
285 if(!c) c = registry_safefindclass("", "Array");
288 classinfo_t* registry_getintclass() {
289 static classinfo_t*c = 0;
290 if(!c) c = registry_safefindclass("", "int");
293 classinfo_t* registry_getuintclass() {
294 static classinfo_t*c = 0;
295 if(!c) c = registry_safefindclass("", "uint");
298 classinfo_t* registry_getbooleanclass() {
299 static classinfo_t*c = 0;
300 if(!c) c = registry_safefindclass("", "Boolean");
303 classinfo_t* registry_getnumberclass() {
304 static classinfo_t*c = 0;
305 if(!c) c = registry_safefindclass("", "Number");
308 classinfo_t* registry_getregexpclass() {
309 static classinfo_t*c = 0;
310 if(!c) c = registry_safefindclass("", "RegExp");
313 classinfo_t* registry_getMovieClip() {
314 static classinfo_t*c = 0;
315 if(!c) c = registry_safefindclass("flash.display", "MovieClip");
319 // ----------------------- builtin dummy types -------------------------
320 classinfo_t nullclass = {
321 ACCESS_PACKAGE, 0, "", "null", 0, 0, 0,
323 classinfo_t* registry_getnullclass() {
327 // ---------------------------------------------------------------------
328 namespace_t flags2namespace(int flags, char*package)
332 if(flags&FLAG_PUBLIC) {
333 ns.access = ACCESS_PACKAGE;
334 } else if(flags&FLAG_PRIVATE) {
335 ns.access = ACCESS_PRIVATE;
336 } else if(flags&FLAG_PROTECTED) {
337 ns.access = ACCESS_PROTECTED;
338 } else if(flags&FLAG_NAMESPACE_ADOBE) {
339 ns.access = ACCESS_NAMESPACE;
340 assert(!package || !package[0]);
341 ns.name = "http://adobe.com/AS3/2006/builtin";
343 ns.access = ACCESS_PACKAGEINTERNAL;