new function dumpclasses()
[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(packageinfo);
30 DECLARE(classinfo);
31 DECLARE(memberinfo);
32 DECLARE_LIST(classinfo);
33
34 /* member/class flags */
35 #define FLAG_PUBLIC 1
36 #define FLAG_PROTECTED 2
37 #define FLAG_NAMESPACE_ADOBE 4
38 #define FLAG_PRIVATE 8
39 #define FLAG_PACKAGEINTERNAL 16
40 #define FLAG_FINAL 32
41
42 /* member flags */
43 #define FLAG_STATIC 64
44 #define FLAG_OVERRIDE 128
45 #define FLAG_NATIVE 256
46
47 /* class flags */
48 #define FLAG_METHOD 64
49 #define FLAG_DYNAMIC 128
50
51 struct _classinfo {
52     U8 access;
53     U8 flags;
54     const char*package;
55     const char*name;
56     union {
57         ptroff_t slot;        // slot nr in initscript traits
58         classinfo_t*cls; // specific class of a Class type
59         memberinfo_t*function; //specific function of a Function type
60     };
61
62     classinfo_t*superclass;
63     dict_t members;
64     classinfo_t*interfaces[];
65 };
66 char classinfo_equals(classinfo_t*c1, classinfo_t*c2);
67
68 #define MEMBER_SLOT 1
69 #define MEMBER_GET 2
70 #define MEMBER_SET 4
71 #define MEMBER_GETSET 6
72 #define MEMBER_METHOD 8
73
74 struct _memberinfo {
75     U8 kind;
76     U8 flags;
77     const char*name;
78     union {
79         classinfo_t*return_type;
80         classinfo_t*type;
81     };
82     classinfo_t*parent;
83     classinfo_list_t*params;
84     int slot;
85 };
86
87 extern type_t classinfo_type;
88 extern type_t memberinfo_type;
89
90 void registry_init();
91         
92 classinfo_t* classinfo_register(int access, const char*package, const char*name, int num_interfaces);
93 memberinfo_t* memberinfo_register(classinfo_t*cls, const char*name, U8 type);
94 memberinfo_t* memberinfo_register_global(U8 access, const char*package, const char*name, U8 kind);
95
96 // static multinames
97 classinfo_t* registry_getanytype();
98 classinfo_t* registry_getarrayclass();
99 classinfo_t* registry_getobjectclass();
100 classinfo_t* registry_getnumberclass();
101 classinfo_t* registry_getstringclass();
102 classinfo_t* registry_getintclass();
103 classinfo_t* registry_getuintclass();
104 classinfo_t* registry_getnullclass();
105 classinfo_t* registry_getregexpclass();
106 classinfo_t* registry_getbooleanclass();
107 classinfo_t* registry_getMovieClip();
108 classinfo_t* memberinfo_asclass(memberinfo_t*f);
109 classinfo_t* registry_getclassclass(classinfo_t*a);
110
111 classinfo_t* registry_findclass(const char*package, const char*name);
112 void registry_dumpclasses();
113 memberinfo_t* registry_findmember(classinfo_t*cls, const char*name, char superclasses);
114
115 void registry_fill_multiname(multiname_t*m, namespace_t*n, classinfo_t*c);
116 multiname_t* classinfo_to_multiname(classinfo_t*cls);
117
118 char registry_isfunctionclass();
119 char registry_isclassclass();
120
121 classinfo_t* memberinfo_gettype(memberinfo_t*);
122
123 namespace_t flags2namespace(int flags, char*package);
124
125 /* convenience functions */
126 #define sig2mname(x) classinfo_to_multiname(x)
127 #define TYPE_ANY                  registry_getanytype()
128 #define TYPE_IS_ANY(t)    ((t) == registry_getanytype())
129 #define TYPE_INT                  registry_getintclass()
130 #define TYPE_IS_INT(t)    ((t) == registry_getintclass())
131 #define TYPE_UINT                 registry_getuintclass()
132 #define TYPE_IS_UINT(t)   ((t) == registry_getuintclass())
133 #define TYPE_NUMBER               registry_getnumberclass()
134 #define TYPE_IS_NUMBER(t) ((t) == registry_getnumberclass())
135 #define TYPE_FLOAT                registry_getnumberclass()
136 #define TYPE_IS_FLOAT(t)  ((t) == registry_getnumberclass())
137 #define TYPE_BOOLEAN              registry_getbooleanclass()
138 #define TYPE_IS_BOOLEAN(t)((t) == registry_getbooleanclass())
139 #define TYPE_STRING               registry_getstringclass()
140 #define TYPE_IS_STRING(t) ((t) == registry_getstringclass())
141 #define TYPE_REGEXP               registry_getregexpclass()
142 #define TYPE_IS_REGEXP(t) ((t) == registry_getregexpclass())
143
144 #define TYPE_OBJECT               registry_getobjectclass()
145
146 #define TYPE_FUNCTION(f)          memberinfo_asclass(f)
147 #define TYPE_IS_FUNCTION(t)       registry_isfunctionclass(t)
148
149 #define TYPE_CLASS(f)             registry_getclassclass(f)
150 #define TYPE_IS_CLASS(t)          registry_isclassclass(t)
151
152 #define TYPE_NULL                 registry_getnullclass()
153 #define TYPE_IS_NULL(t)   ((t) == registry_getnullclass())
154         
155 #define TYPE_IS_BUILTIN_SIMPLE(type) (TYPE_IS_INT(type) || \
156                                       TYPE_IS_UINT(type) || \
157                                       TYPE_IS_FLOAT(type) || \
158                                       TYPE_IS_BOOLEAN(type) || \
159                                       TYPE_IS_STRING(type))
160
161
162 #endif