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