bugfixes
[swftools.git] / lib / as3 / abc.h
1 /* abc.h
2
3    Routines for handling Flash2 AVM2 ABC Actionscript (header file)
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 __swfabc_h__
25 #define __swfabc_h__
26
27 #include "../q.h"
28 #include "pool.h"
29
30 DECLARE(abc_file);
31 DECLARE(abc_method);
32 DECLARE(abc_method_body);
33 DECLARE(abc_interface);
34 DECLARE(abc_class);
35 DECLARE(abc_exception);
36 DECLARE(abc_asset);
37 DECLARE(asset_dependency);
38 DECLARE(asset_tag);
39 DECLARE_LIST(abc_asset);
40 DECLARE_LIST(asset_dependency);
41 DECLARE_LIST(asset_tag);
42 DECLARE_LIST(abc_exception);
43 DECLARE_LIST(TAG);
44
45 #include "code.h"
46 #include "opcodes.h"
47
48 DECLARE(trait);
49
50
51 #define METHOD_NEED_ARGUMENTS 1
52 #define METHOD_NEED_ACTIVATION 2
53 #define METHOD_NEED_REST 4
54 #define METHOD_HAS_OPTIONAL 8
55 #define METHOD_SET_DXNS 0x40
56 #define METHOD_HAS_PARAM_NAMES 0x80
57
58 struct _abc_method {
59     multiname_t*return_type;
60     multiname_list_t*parameters;
61     constant_list_t*optional_parameters;
62     const char*name;
63     U8 flags;
64     abc_method_body_t*body;
65
66     trait_t*trait;
67     
68     int index; //filled in during writing
69 };
70
71 #define ABCFILE_LAZY 1
72 struct _abc_file {
73     // abc_file
74
75     const char*name;
76     U32 flags;
77     array_t*metadata;
78     array_t*methods;
79     array_t*classes;
80     array_t*scripts;
81     array_t*method_bodies;
82 };
83
84 abc_file_t*abc_file_new();
85
86 #define TRAIT_SLOT 0
87 #define TRAIT_METHOD 1
88 #define TRAIT_GETTER 2
89 #define TRAIT_SETTER 3
90 #define TRAIT_CLASS 4
91 #define TRAIT_FUNCTION 5
92 #define TRAIT_CONST 6
93             
94 #define TRAIT_ATTR_FINAL 0x10
95 #define TRAIT_ATTR_OVERRIDE 0x20
96 #define TRAIT_ATTR_METADATA 0x40
97
98
99 struct _trait {
100     unsigned char kind;
101     unsigned char attributes;
102     multiname_t*name;
103
104     union {
105         int disp_id;
106         int slot_id;
107         int data1;
108     };
109     union {
110         abc_method_t*method;
111         abc_class_t*cls;
112         multiname_t*type_name;
113         int data2;
114     };
115     constant_t*value;
116 };
117
118 trait_t*trait_new_method(trait_list_t**traits, multiname_t*name, abc_method_t*m);
119 trait_t*trait_new_member(trait_list_t**traits, multiname_t*type, multiname_t*name, constant_t*v);
120
121 #define CLASS_SEALED 1
122 #define CLASS_FINAL 2
123 #define CLASS_INTERFACE 4
124 #define CLASS_PROTECTED_NS 8
125
126 struct _abc_class {
127     abc_file_t*file;
128     
129     multiname_t*classname;
130     multiname_t*superclass;
131     namespace_t*protectedNS;
132
133     multiname_list_t*interfaces;
134
135     abc_method_t*constructor;
136     trait_list_t*traits;
137     
138     abc_method_t*static_constructor;
139     trait_list_t*static_traits;
140     
141     U8 flags;
142
143     abc_asset_t*asset; // swf tags needed for this class
144
145     int init_scope_depth; // volatile, might be increased during code verification
146     int index; //filled in during writing
147 };
148
149 void abc_method_init(abc_method_t*m, abc_file_t*file, multiname_t*returntype, char body);
150 abc_method_t* abc_method_new(abc_file_t*file, multiname_t*returntype, char body);
151
152 abc_class_t* abc_class_new(abc_file_t*file, multiname_t*classname, multiname_t*superclass);
153 abc_class_t* abc_class_new2(abc_file_t*file, char*classname, char*superclass);
154 void abc_class_sealed(abc_class_t*c);
155 void abc_class_final(abc_class_t*c);
156 void abc_class_interface(abc_class_t*c);
157 void abc_class_protectedNS(abc_class_t*c, char*namespace);
158 void abc_class_add_interface(abc_class_t*c, multiname_t*interface);
159 char*abc_class_fullname(abc_class_t*cls);
160
161 trait_t* traits_find_slotid(trait_list_t*traits, int slotid);
162
163 abc_method_t* abc_class_getconstructor(abc_class_t*cls, multiname_t*returntype);
164 abc_method_t* abc_class_getstaticconstructor(abc_class_t*cls, multiname_t*returntype);
165
166 abc_method_t* abc_class_method(abc_class_t*cls, multiname_t*returntype, multiname_t*name);
167 abc_method_t* abc_class_staticmethod(abc_class_t*cls, multiname_t*returntype, multiname_t*name);
168 trait_t*      abc_class_slot(abc_class_t*cls, multiname_t*name, multiname_t*type);
169 trait_t*      abc_class_staticslot(abc_class_t*cls, multiname_t*name, multiname_t*type);
170
171 struct _abc_exception {
172     code_t*from;
173     code_t*to;
174     code_t*target;
175     multiname_t*exc_type;
176     multiname_t*var_name;
177 };
178
179 struct _abc_method_body {
180     abc_file_t*file;
181     //abc_class_t*cls;
182     abc_method_t*method;
183     code_t*code;
184
185     struct {
186         //for dumping: filled in during parsing
187         int max_stack;
188         int local_count;
189         int max_scope_depth;
190         int init_scope_depth;
191     } old;
192
193     int init_scope_depth; // volatile, might be increased during code verification
194
195     abc_exception_list_t* exceptions;
196
197     trait_list_t*traits;
198     
199     int index; // filled in during writing
200     codestats_t*stats; //filled in during writing
201 };
202
203 typedef struct _abc_script {
204     abc_method_t*method;
205     abc_file_t*file;
206     trait_list_t*traits;
207 } abc_script_t;
208
209 struct _asset_dependency {
210     abc_asset_t*asset;
211     int patch_pos;
212 };
213 struct _asset_tag {
214     TAG*tag;
215     asset_dependency_t*deps;
216     int num_deps;
217 };
218 struct _abc_asset {
219     asset_tag_list_t*tags;
220     U16 id;
221 };
222
223 abc_method_t* abc_nullmethod(abc_file_t*file);
224 abc_script_t* abc_initscript(abc_file_t*file);
225 trait_t*abc_initscript_addClassTrait(abc_script_t*script, multiname_t*multiname, abc_class_t*cls);
226
227 #define __ 
228
229 #endif