added GPL headers
[swftools.git] / lib / as3 / registry.c
1 /* registry.c
2
3    Routines for compiling Flash2 AVM2 ABC Actionscript
4
5    Extension module for the rfxswf library.
6    Part of the swftools package.
7
8    Copyright (c) 2008 Matthias Kramm <kramm@quiss.org>
9  
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.
14
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.
19
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 */
23
24 #include "pool.h"
25 #include "registry.h"
26
27 static namespace_t static_empty_ns = {
28     ACCESS_PACKAGE, ""
29 };
30 static namespace_t static_flash_display_ns = {
31     ACCESS_PACKAGE, "flash.display"
32 };
33 static multiname_t static_object_class = {
34     QNAME, &static_empty_ns, 0, "Object"
35 };
36 static multiname_t static_anytype_class = {
37     QNAME, &static_empty_ns, 0, 0
38 };
39 static multiname_t static_string_class = {
40     QNAME, &static_empty_ns, 0, "String"
41 };
42 static multiname_t static_boolean_class = {
43     QNAME, &static_empty_ns, 0, "Boolean"
44 };
45 static multiname_t static_number_class = {
46     QNAME, &static_empty_ns, 0, "Number"
47 };
48 static multiname_t static_int_class = {
49     QNAME, &static_empty_ns, 0, "int"
50 };
51 static multiname_t static_uint_class = {
52     QNAME, &static_empty_ns, 0, "uint"
53 };
54 static multiname_t static_movieclip_class = {
55     QNAME, &static_flash_display_ns, 0, "MovieClip"
56 };
57
58 multiname_t* registry_getobjectclass() {return &static_object_class;}
59 multiname_t* registry_getanytype() {return &static_anytype_class;}
60 multiname_t* registry_getstringclass() {return &static_string_class;}
61 multiname_t* registry_getintclass() {return &static_int_class;}
62 multiname_t* registry_getuintclass() {return &static_uint_class;}
63 multiname_t* registry_getbooleanclass() {return &static_boolean_class;}
64 multiname_t* registry_getnumberclass() {return &static_number_class;}
65 multiname_t* registry_getMovieClip() {return &static_movieclip_class;}
66
67
68 multiname_t* registry_findclass(const char*package, const char*name)
69 {
70     multiname_t*m=0;
71     if(!package) {
72         m = multiname_new(0, name);
73     } else {
74         namespace_t*ns = 0;
75
76         /* things in the "flash" package are usually public */
77         if(!strncmp(package, "flash", 5))
78             ns =namespace_new_package(package);
79         else
80             ns = namespace_new_packageinternal(package);
81
82         m = multiname_new(ns,name);
83         namespace_destroy(ns);
84     }
85     return m;
86 }
87 multiname_t* registry_getsuperclass(multiname_t*m)
88 {
89     if(!m->name)
90         return 0;
91     if(!strcmp(m->name, "Object"))
92         return 0;
93
94     else if(!strcmp(m->name, "MovieClip"))
95         return multiname_fromstring("[package]flash.display::Sprite");
96     else if(!strcmp(m->name, "Sprite"))
97         return multiname_fromstring("[package]flash.display::DisplayObjectContainer");
98     else if(!strcmp(m->name, "DisplayObjectContainer"))
99         return multiname_fromstring("[package]flash.display::InteractiveObject");
100     else if(!strcmp(m->name, "InteractiveObject"))
101         return multiname_fromstring("[package]flash.display::DisplayObject");
102     else if(!strcmp(m->name, "DisplayObject"))
103         return multiname_fromstring("[package]flash.events::EventDispatcher");
104     else
105         return &static_object_class;
106 }
107