implemented asset resolving
[swftools.git] / lib / as3 / registry.h
1 /* registry.h
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 #ifndef __abc_registry_h__
25 #define __abc_registry_h__
26
27 #include "abc.h"
28
29 DECLARE(asset_bundle);
30 DECLARE_LIST(asset_bundle);
31 DECLARE(slotinfo);
32 DECLARE(classinfo);
33 DECLARE(memberinfo);
34 DECLARE(methodinfo);
35 DECLARE(unresolvedinfo);
36 DECLARE(varinfo);
37 DECLARE_LIST(classinfo);
38 DECLARE_LIST(slotinfo);
39
40 /* member/class flags */
41 #define FLAG_FINAL 1
42 #define FLAG_BUILTIN 128
43 #define FLAG_ASSET 64
44
45 /* member flags */
46 #define FLAG_STATIC 2
47 #define FLAG_OVERRIDE 8
48 #define FLAG_NATIVE 16
49 #define FLAG_CONST 32
50
51 /* class flags */
52 #define FLAG_DYNAMIC 8
53 #define FLAG_INTERFACE 16
54
55 #define INFOTYPE_VAR 1
56 #define INFOTYPE_METHOD 2
57 #define INFOTYPE_CLASS 3
58 #define INFOTYPE_UNRESOLVED 4
59 #define SUBTYPE_GET 1
60 #define SUBTYPE_SET 2
61 #define SUBTYPE_GETSET 3
62
63 struct _slotinfo {
64     U8 kind,subtype,flags,access;
65     const char*package;
66     const char*name;
67     int slot;
68 };
69 struct _unresolvedinfo {
70     U8 kind,subtype,flags,access;
71     const char*package;
72     const char*name;
73     int slot;
74     namespace_list_t*nsset;
75 };
76 struct _classinfo {
77     U8 kind,subtype,flags,access;
78     const char*package;
79     const char*name;
80     int slot;
81     classinfo_t*superclass;
82     dict_t members;
83     dict_t static_members;
84     void*data; //TODO: get rid of this- parser.y should pass type/value/code triples around
85     asset_bundle_t*assets;
86     classinfo_t*interfaces[];
87 };
88 struct _memberinfo {
89     U8 kind,subtype,flags,access;
90     const char*package;
91     const char*name;
92     int slot;
93     union {
94         classinfo_t*return_type;
95         classinfo_t*type;
96     };
97     classinfo_t*parent;
98 };
99 struct _methodinfo /*extends memberinfo*/ {
100     U8 kind,subtype,flags,access;
101     const char*package;
102     const char*name;
103     int slot;
104     classinfo_t*return_type;
105     classinfo_t*parent;
106     classinfo_list_t*params;
107 };
108 struct _varinfo /*extends memberinfo*/ {
109     U8 kind,subtype,flags,access;
110     const char*package;
111     const char*name;
112     int slot;
113     classinfo_t*type;
114     classinfo_t*parent;
115     constant_t*value;
116 };
117
118 struct _asset_bundle {
119     abc_file_t*file;
120     char used;
121 };
122
123 extern type_t memberinfo_type;
124 extern type_t slotinfo_type;
125 char slotinfo_equals(slotinfo_t*c1, slotinfo_t*c2);
126
127 void registry_init();
128         
129 classinfo_t* classinfo_register(int access, const char*package, const char*name, int num_interfaces);
130 methodinfo_t* methodinfo_register_onclass(classinfo_t*cls, U8 access, const char*ns, const char*name, char is_static);
131 methodinfo_t* methodinfo_register_global(U8 access, const char*package, const char*name);
132 varinfo_t* varinfo_register_onclass(classinfo_t*cls, U8 access,  const char*ns, const char*name, char is_static);
133 varinfo_t* varinfo_register_global(U8 access, const char*package, const char*name);
134
135 slotinfo_t* registry_resolve(slotinfo_t*s);
136 void registry_resolve_all();
137
138 slotinfo_t* registry_find(const char*package, const char*name);
139 void registry_dump();
140 memberinfo_t* registry_findmember(classinfo_t*cls, const char*ns, const char*name, char superclasses, char is_static);
141 memberinfo_t* registry_findmember_nsset(classinfo_t*cls, namespace_list_t*ns, const char*name, char superclasses, char is_static);
142
143 void registry_fill_multiname(multiname_t*m, namespace_t*n, slotinfo_t*c);
144 #define MULTINAME(m,x) \
145     multiname_t m;\
146     namespace_t m##_ns;\
147     (x)->package; \
148     registry_fill_multiname(&m, &m##_ns, (slotinfo_t*)(x));
149                     
150 multiname_t* classinfo_to_multiname(slotinfo_t*cls);
151
152 char registry_isfunctionclass();
153 char registry_isclassclass();
154
155 classinfo_t* slotinfo_asclass(slotinfo_t*f);
156 classinfo_t* slotinfo_gettype(slotinfo_t*);
157
158 namespace_t access2namespace(U8 access, char*package);
159
160 char registry_ispackage(const char*package);
161
162 void registry_add_asset(asset_bundle_t*bundle);
163 void registry_use(slotinfo_t*s);
164 asset_bundle_list_t*registry_getassets();
165
166 // static multinames
167 classinfo_t voidclass;
168 classinfo_t* registry_getanytype();
169 classinfo_t* registry_getarrayclass();
170 classinfo_t* registry_getobjectclass();
171 classinfo_t* registry_getnumberclass();
172 classinfo_t* registry_getstringclass();
173 classinfo_t* registry_getdateclass();
174 classinfo_t* registry_getintclass();
175 classinfo_t* registry_getuintclass();
176 classinfo_t* registry_getnullclass();
177 classinfo_t* registry_getvoidclass();
178 classinfo_t* registry_getarrayclass();
179 classinfo_t* registry_getregexpclass();
180 classinfo_t* registry_getxmlclass();
181 classinfo_t* registry_getxmllistclass();
182 classinfo_t* registry_getbooleanclass();
183 classinfo_t* registry_getMovieClip();
184 classinfo_t* registry_getclassclass(classinfo_t*a);
185 classinfo_t* registry_getnamespaceclass();
186 extern classinfo_t voidclass;
187
188 char* infotypename(slotinfo_t*s);
189 void slotinfo_dump(slotinfo_t*s);
190
191 /* convenience functions */
192 #define sig2mname(x) (x->superclass,classinfo_to_multiname((slotinfo_t*)(x)))
193
194 #define TYPE_ANY             (0)
195 #define TYPE_IS_ANY(t)       ((t) == 0)
196 #define TYPE_INT                     registry_getintclass()
197 #define TYPE_IS_INT(t)       ((t) == registry_getintclass())
198 #define TYPE_UINT                    registry_getuintclass()
199 #define TYPE_IS_UINT(t)      ((t) == registry_getuintclass())
200 #define TYPE_NUMBER                  registry_getnumberclass()
201 #define TYPE_IS_NUMBER(t)    ((t) == registry_getnumberclass())
202 #define TYPE_FLOAT                   registry_getnumberclass()
203 #define TYPE_IS_FLOAT(t)     ((t) == registry_getnumberclass())
204 #define TYPE_BOOLEAN                 registry_getbooleanclass()
205 #define TYPE_IS_BOOLEAN(t)   ((t) == registry_getbooleanclass())
206 #define TYPE_STRING                  registry_getstringclass()
207 #define TYPE_IS_STRING(t)    ((t) == registry_getstringclass())
208 #define TYPE_DATE                    registry_getdateclass()
209 #define TYPE_IS_DATE(t)      ((t) == registry_getdateclass())
210 #define TYPE_OBJECT                  registry_getobjectclass()
211 #define TYPE_IS_OBJECT(t)    ((t) == registry_getobjectclass())
212 #define TYPE_REGEXP                  registry_getregexpclass()
213 #define TYPE_IS_REGEXP(t)    ((t) == registry_getregexpclass())
214 #define TYPE_VOID                    registry_getvoidclass()
215 #define TYPE_IS_VOID(t)      ((t) == registry_getvoidclass())
216 #define TYPE_ARRAY                   registry_getarrayclass()
217 #define TYPE_IS_ARRAY(t)     ((t) == registry_getarrayclass())
218 #define TYPE_NAMESPACE            registry_getnamespaceclass()
219 #define TYPE_IS_NAMESPACE(t) ((t) == registry_getnamespaceclass())
220 #define TYPE_FUNCTION(f)     ((f)->return_type,slotinfo_asclass((slotinfo_t*)(f)))
221 #define TYPE_IS_FUNCTION(t)  registry_isfunctionclass(t)
222 #define TYPE_CLASS(f)        ((f)->superclass,slotinfo_asclass((slotinfo_t*)(f)))
223 #define TYPE_IS_CLASS(t)     registry_isclassclass(t)
224 #define TYPE_NULL            registry_getnullclass()
225 #define TYPE_IS_NULL(t)      ((t) == registry_getnullclass())
226 #define TYPE_VOID            registry_getvoidclass()
227 #define TYPE_IS_VOID(t)      ((t) == registry_getvoidclass())
228 #define TYPE_XML            registry_getxmlclass()
229 #define TYPE_IS_XML(t)      ((t) == registry_getxmlclass())
230 #define TYPE_XMLLIST        registry_getxmllistclass()
231 #define TYPE_IS_XMLLIST(t)  ((t) == registry_getxmllistclass())
232         
233 #define TYPE_IS_BUILTIN_SIMPLE(type) (TYPE_IS_INT(type) || \
234                                       TYPE_IS_UINT(type) || \
235                                       TYPE_IS_FLOAT(type) || \
236                                       TYPE_IS_BOOLEAN(type) || \
237                                       TYPE_IS_STRING(type))
238
239 #define IS_NUMBER_OR_INT(a) (TYPE_IS_INT((a)) || TYPE_IS_UINT((a)) || TYPE_IS_NUMBER((a)))
240
241
242 #endif