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