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