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