don't generate a constructor method body for interfaces
[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     int index; //filled in during writing
60 };
61
62 #define ABCFILE_LAZY 1
63 struct _abc_file {
64     // abc_file
65
66     const char*name;
67     U32 flags;
68     array_t*metadata;
69     array_t*methods;
70     array_t*classes;
71     array_t*scripts;
72     array_t*method_bodies;
73 };
74
75 abc_file_t*abc_file_new();
76
77 #define TRAIT_SLOT 0
78 #define TRAIT_METHOD 1
79 #define TRAIT_GETTER 2
80 #define TRAIT_SETTER 3
81 #define TRAIT_CLASS 4
82 #define TRAIT_FUNCTION 5
83 #define TRAIT_CONST 6
84
85
86 struct _trait {
87     unsigned char kind;
88     unsigned char attributes;
89     multiname_t*name;
90
91     union {
92         int disp_id;
93         int slot_id;
94         int data1;
95     };
96     union {
97         abc_method_t*method;
98         abc_class_t*cls;
99         multiname_t*type_name;
100         int data2;
101     };
102     constant_t*value;
103 };
104
105 #define CLASS_SEALED 1
106 #define CLASS_FINAL 2
107 #define CLASS_INTERFACE 4
108 #define CLASS_PROTECTED_NS 8
109
110 struct _abc_class {
111     abc_file_t*file;
112     
113     multiname_t*classname;
114     multiname_t*superclass;
115     namespace_t*protectedNS;
116
117     multiname_list_t*interfaces;
118
119     abc_method_t*constructor;
120     trait_list_t*traits;
121     
122     abc_method_t*static_constructor;
123     trait_list_t*static_traits;
124     
125     U8 flags;
126
127     int init_scope_depth; // volatile, might be increased during code verification
128     
129     int index; //filled in during writing
130 };
131
132 abc_class_t* abc_class_new(abc_file_t*file, multiname_t*classname, multiname_t*superclass);
133 abc_class_t* abc_class_new2(abc_file_t*file, char*classname, char*superclass);
134 void abc_class_sealed(abc_class_t*c);
135 void abc_class_final(abc_class_t*c);
136 void abc_class_interface(abc_class_t*c);
137 void abc_class_protectedNS(abc_class_t*c, char*namespace);
138 void abc_class_add_interface(abc_class_t*c, multiname_t*interface);
139
140 abc_method_body_t* abc_class_staticconstructor(abc_class_t*cls, multiname_t*returntype, int num_params, ...);
141 abc_method_body_t* abc_class_constructor(abc_class_t*cls, multiname_t*returntype, int num_params, ...);
142 abc_method_body_t* abc_class_method(abc_class_t*cls, multiname_t*returntype, char*name, int num_params, ...);
143
144 struct _abc_exception {
145     code_t*from;
146     code_t*to;
147     code_t*target;
148     multiname_t*exc_type;
149     multiname_t*var_name;
150 };
151
152 struct _abc_method_body {
153     abc_file_t*file;
154     //abc_class_t*cls;
155     abc_method_t*method;
156     code_t*code;
157
158     struct {
159         //for dumping: filled in during parsing
160         int max_stack;
161         int local_count;
162         int max_scope_depth;
163         int init_scope_depth;
164     } old;
165
166     int init_scope_depth; // volatile, might be increased during code verification
167
168     abc_exception_list_t* exceptions;
169
170     trait_list_t*traits;
171     
172     int index; // filled in during writing
173     codestats_t*stats; //filled in during writing
174 };
175
176 typedef struct _abc_script {
177     abc_method_t*method;
178     abc_file_t*file;
179     trait_list_t*traits;
180 } abc_script_t;
181
182 abc_method_t* abc_nullmethod(abc_file_t*file);
183 abc_script_t* abc_initscript(abc_file_t*file, multiname_t*returntype, int num_params, ...);
184
185 #define __ 
186
187 #endif