fixed memory leaks
[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_body);
32 DECLARE(abc_interface);
33 DECLARE(abc_code);
34 DECLARE(abc_class);
35
36 DECLARE(trait);
37
38 typedef struct _abc_method {
39     multiname_t*return_type;
40     multiname_list_t*parameters;
41     const char*name;
42     U8 flags;
43     abc_method_body_t*body;
44     
45     int index; //filled in during writing
46 } abc_method_t;
47
48 struct _abc_file {
49     // abc_file
50
51     const char*name;
52     array_t*metadata;
53     array_t*methods;
54     array_t*classes;
55     array_t*scripts;
56     array_t*method_bodies;
57 };
58
59 abc_file_t*abc_file_new();
60
61 #define TRAIT_SLOT 0
62 #define TRAIT_METHOD 1
63 #define TRAIT_GETTER 2
64 #define TRAIT_SETTER 3
65 #define TRAIT_CLASS 4
66 #define TRAIT_FUNCTION 5
67 #define TRAIT_CONST 6
68
69 struct _trait {
70     unsigned char kind;
71     unsigned char attributes;
72     multiname_t*name;
73
74     union {
75         int disp_id;
76         int slot_id;
77         int data1;
78     };
79     union {
80         abc_method_t*method;
81         abc_class_t*cls;
82         multiname_t*type_name;
83         int data2;
84     };
85     int vindex;
86     int vkind;
87 };
88
89 struct _abc_class {
90     abc_file_t*pool;
91     
92     multiname_t*classname;
93     multiname_t*superclass;
94     namespace_t*protectedNS;
95
96     multiname_list_t*interfaces;
97
98     abc_method_t*constructor;
99     U8 flags;
100     
101     abc_method_t*static_constructor;
102
103     trait_list_t*static_constructor_traits;
104     trait_list_t*traits;
105     
106     int index; //filled in during writing
107 };
108
109 abc_class_t* abc_class_new(abc_file_t*pool, multiname_t*classname, multiname_t*superclass);
110 abc_class_t* abc_class_new2(abc_file_t*pool, char*classname, char*superclass);
111 void abc_class_sealed(abc_class_t*c);
112 void abc_class_final(abc_class_t*c);
113 void abc_class_interface(abc_class_t*c);
114 void abc_class_protectedNS(abc_class_t*c, char*namespace);
115 void abc_class_add_interface(abc_class_t*c, multiname_t*interface);
116
117 abc_method_body_t* abc_class_staticconstructor(abc_class_t*cls, char*returntype, int num_params, ...);
118 abc_method_body_t* abc_class_constructor(abc_class_t*cls, char*returntype, int num_params, ...);
119 abc_method_body_t* abc_class_method(abc_class_t*cls, char*returntype, char*name, int num_params, ...);
120
121 struct _abc_code {
122     U8 opcode;
123     U8 len;
124     void*params[2];
125     abc_code_t*next;
126     abc_code_t*prev;
127     abc_code_t*parent;
128 };
129
130 struct _abc_method_body {
131     abc_file_t*pool;
132     //abc_class_t*cls;
133     abc_method_t*method;
134     abc_code_t*code;
135     int max_stack;
136     int local_count;
137     int init_scope_depth;
138     int max_scope_depth;
139     int exception_count;
140     trait_list_t*traits;
141     
142     int index; // filled in during writing
143 };
144
145 typedef struct _abc_label {
146 } abc_label_t;
147
148 typedef struct _abc_script {
149     abc_method_t*method;
150     abc_file_t*pool;
151     trait_list_t*traits;
152 } abc_script_t;
153
154 abc_script_t* abc_initscript(abc_file_t*pool, char*returntype, int num_params, ...);
155
156 #define __ 
157
158 #endif