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