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