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