started integrating expression ast
[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
47 /* class flags */
48 #define FLAG_DYNAMIC 8
49 #define FLAG_INTERFACE 16
50
51 #define INFOTYPE_SLOT 1
52 #define INFOTYPE_METHOD 2
53 #define INFOTYPE_CLASS 3
54 #define INFOTYPE_UNRESOLVED 4
55 #define SUBTYPE_GET 1
56 #define SUBTYPE_SET 2
57 #define SUBTYPE_GETSET 3
58
59 struct _slotinfo {
60     U8 kind,subtype,flags,access;
61     const char*package;
62     const char*name;
63     int slot;
64 };
65 struct _unresolvedinfo {
66     U8 kind,subtype,flags,access;
67     const char*package;
68     const char*name;
69     int slot;
70     namespace_list_t*nsset;
71 };
72 struct _classinfo {
73     U8 kind,subtype,flags,access;
74     const char*package;
75     const char*name;
76     int slot;
77     classinfo_t*superclass;
78     dict_t members;
79     void*data; //TODO: get rid of this- parser.y should pass type/value/code triples around
80     classinfo_t*interfaces[];
81 };
82 struct _memberinfo {
83     U8 kind,subtype,flags,access;
84     const char*package;
85     const char*name;
86     int slot;
87     union {
88         classinfo_t*return_type;
89         classinfo_t*type;
90     };
91     classinfo_t*parent;
92 };
93 struct _methodinfo {
94     U8 kind,subtype,flags,access;
95     const char*package;
96     const char*name;
97     int slot;
98     classinfo_t*return_type;
99     classinfo_t*parent;
100     classinfo_list_t*params;
101 };
102 struct _varinfo {
103     U8 kind,subtype,flags,access;
104     const char*package;
105     const char*name;
106     int slot;
107     classinfo_t*type;
108     classinfo_t*parent;
109     constant_t*value;
110 };
111
112 extern type_t memberinfo_type;
113 extern type_t slotinfo_type;
114 char slotinfo_equals(slotinfo_t*c1, slotinfo_t*c2);
115
116 void registry_init();
117         
118 classinfo_t* classinfo_register(int access, const char*package, const char*name, int num_interfaces);
119 methodinfo_t* methodinfo_register_onclass(classinfo_t*cls, U8 access, const char*ns, const char*name);
120 methodinfo_t* methodinfo_register_global(U8 access, const char*package, const char*name);
121 varinfo_t* varinfo_register_onclass(classinfo_t*cls, U8 access,  const char*ns, const char*name);
122 varinfo_t* varinfo_register_global(U8 access, const char*package, const char*name);
123
124 slotinfo_t* registry_resolve(slotinfo_t*s);
125 void registry_resolve_all();
126
127 slotinfo_t* registry_find(const char*package, const char*name);
128 void registry_dump();
129 memberinfo_t* registry_findmember(classinfo_t*cls, const char*ns, const char*name, char superclasses);
130 memberinfo_t* registry_findmember_nsset(classinfo_t*cls, namespace_list_t*ns, const char*name, char superclasses);
131
132 void registry_fill_multiname(multiname_t*m, namespace_t*n, slotinfo_t*c);
133 multiname_t* classinfo_to_multiname(slotinfo_t*cls);
134
135 char registry_isfunctionclass();
136 char registry_isclassclass();
137
138 classinfo_t* slotinfo_asclass(slotinfo_t*f);
139 classinfo_t* slotinfo_gettype(slotinfo_t*);
140
141 namespace_t access2namespace(U8 access, char*package);
142
143 char registry_ispackage(char*package);
144
145 // static multinames
146 classinfo_t* registry_getanytype();
147 classinfo_t* registry_getarrayclass();
148 classinfo_t* registry_getobjectclass();
149 classinfo_t* registry_getnumberclass();
150 classinfo_t* registry_getstringclass();
151 classinfo_t* registry_getintclass();
152 classinfo_t* registry_getuintclass();
153 classinfo_t* registry_getnullclass();
154 classinfo_t* registry_getregexpclass();
155 classinfo_t* registry_getbooleanclass();
156 classinfo_t* registry_getMovieClip();
157 classinfo_t* registry_getclassclass(classinfo_t*a);
158 classinfo_t* registry_getnamespaceclass();
159
160 char* infotypename(slotinfo_t*s);
161
162 /* convenience functions */
163 #define sig2mname(x) (x->superclass,classinfo_to_multiname((slotinfo_t*)(x)))
164
165 #define TYPE_ANY                     registry_getanytype()
166 #define TYPE_IS_ANY(t)       ((t) == registry_getanytype())
167 #define TYPE_INT                     registry_getintclass()
168 #define TYPE_IS_INT(t)       ((t) == registry_getintclass())
169 #define TYPE_UINT                    registry_getuintclass()
170 #define TYPE_IS_UINT(t)      ((t) == registry_getuintclass())
171 #define TYPE_NUMBER                  registry_getnumberclass()
172 #define TYPE_IS_NUMBER(t)    ((t) == registry_getnumberclass())
173 #define TYPE_FLOAT                   registry_getnumberclass()
174 #define TYPE_IS_FLOAT(t)     ((t) == registry_getnumberclass())
175 #define TYPE_BOOLEAN                 registry_getbooleanclass()
176 #define TYPE_IS_BOOLEAN(t)   ((t) == registry_getbooleanclass())
177 #define TYPE_STRING                  registry_getstringclass()
178 #define TYPE_IS_STRING(t)    ((t) == registry_getstringclass())
179 #define TYPE_OBJECT                  registry_getobjectclass()
180 #define TYPE_IS_OBJECT(t)    ((t) == registry_getobjectclass())
181 #define TYPE_REGEXP                  registry_getregexpclass()
182 #define TYPE_IS_REGEXP(t)    ((t) == registry_getregexpclass())
183 #define TYPE_NAMESPACE            registry_getnamespaceclass()
184 #define TYPE_IS_NAMESPACE(t) ((t) == registry_getnamespaceclass())
185 #define TYPE_FUNCTION(f)     ((f)->return_type,slotinfo_asclass((slotinfo_t*)(f)))
186 #define TYPE_IS_FUNCTION(t)  registry_isfunctionclass(t)
187 #define TYPE_CLASS(f)        ((f)->superclass,slotinfo_asclass((slotinfo_t*)(f)))
188 #define TYPE_IS_CLASS(t)     registry_isclassclass(t)
189 #define TYPE_NULL            registry_getnullclass()
190 #define TYPE_IS_NULL(t)      ((t) == registry_getnullclass())
191         
192 #define TYPE_IS_BUILTIN_SIMPLE(type) (TYPE_IS_INT(type) || \
193                                       TYPE_IS_UINT(type) || \
194                                       TYPE_IS_FLOAT(type) || \
195                                       TYPE_IS_BOOLEAN(type) || \
196                                       TYPE_IS_STRING(type))
197
198
199 #endif