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