moved from ../modules/
[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 #define DECLARE(x) struct _##x;typedef struct _##x x##_t;
28 #define DECLARE_LIST(x) \
29 struct _##x##_list { \
30     struct _##x* x; \
31     struct _##x##_list*next; \
32 }; \
33 typedef struct _##x##_list x##_list_t; \
34
35 DECLARE(abc_file);
36 DECLARE(abc_method_body);
37 DECLARE(abc_interface);
38 DECLARE(abc_multiname);
39 DECLARE(abc_namespace);
40
41 DECLARE_LIST(abc_multiname);
42
43 typedef struct _abc_method {
44     abc_multiname_t*return_type;
45     abc_multiname_list_t*parameters;
46     const char*name;
47     U8 flags;
48
49     int index;
50     int method_body_index;
51 } abc_method_t;
52
53 typedef enum multiname_type
54 {QNAME=0x07,
55  QNAMEA=0x0D,
56  RTQNAME=0x0F,
57  RTQNAMEA=0x10,
58  RTQNAMEL=0x11,
59  RTQNAMELA=0x12,
60  MULTINAME=0x09,
61  MULTINAMEA=0x0E,
62  MULTINAMEL=0x1B,
63  MULTINAMELA=0x1C
64 } multiname_type_t;
65
66 struct _abc_namespace {
67     U8 access;
68     char*name;
69 };
70
71 struct _abc_multiname {
72     multiname_type_t type;
73     abc_namespace_t*ns;
74     const char*namespace_set_name; // FIXME should be a struct
75     const char*name;
76 };
77
78 typedef struct _dict_entry {
79     const char*name;
80     void*data;
81 } dict_entry_t;
82
83 typedef struct _dict {
84     int num;
85     int size;
86     dict_entry_t*d;
87 } dict_t;
88
89 struct _abc_file {
90
91     // contant_pool
92
93     dict_t*ints;
94     dict_t*uints;
95     dict_t*floats;
96     dict_t*strings;
97     dict_t*namespaces;
98     dict_t*namespace_sets;
99     dict_t*sets;
100     dict_t*multinames;
101
102     // abc_file
103
104     dict_t*methods;
105     dict_t*classes;
106     dict_t*scripts;
107     dict_t*method_bodies;
108 };
109
110 abc_file_t*abc_file_new();
111
112 typedef struct _abc_trait {
113     unsigned char type;
114     int name_index;
115
116     union {
117         int disp_id;
118         int slot_id;
119         int data1;
120     };
121     union {
122         int nr;
123         int cls;
124         int type_index;
125         int data2;
126     };
127     int vindex;
128     int vkind;
129 } abc_trait_t;
130
131 typedef struct _abc_class {
132     int index;
133     abc_file_t*pool;
134     
135     const char*classname;
136     const char*superclass;
137     const char*protectedNS;
138
139     abc_multiname_list_t*interfaces;
140
141     int iinit;
142     U8 flags;
143     
144     int static_constructor_index;
145     dict_t*static_constructor_traits;
146
147     dict_t*traits;
148 } abc_class_t;
149
150 abc_class_t* abc_class_new(abc_file_t*pool, char*classname, char*superclass);
151 void abc_class_sealed(abc_class_t*c);
152 void abc_class_final(abc_class_t*c);
153 void abc_class_interface(abc_class_t*c);
154 void abc_class_protectedNS(abc_class_t*c, char*namespace);
155
156 abc_method_body_t* abc_class_staticconstructor(abc_class_t*cls, char*returntype, int num_params, ...);
157 abc_method_body_t* abc_class_constructor(abc_class_t*cls, char*returntype, int num_params, ...);
158 abc_method_body_t* abc_class_method(abc_class_t*cls, char*returntype, char*name, int num_params, ...);
159
160 struct _abc_method_body {
161     int index;
162     abc_file_t*pool;
163     //abc_class_t*cls;
164     abc_method_t*method;
165     TAG*tag;
166     int max_stack;
167     int local_count;
168     int init_scope_depth;
169     int max_scope_depth;
170     int exception_count;
171     dict_t*traits;
172 };
173
174 typedef struct _abc_label {
175 } abc_label_t;
176
177 typedef struct _abc_script {
178     abc_method_t*method;
179     abc_file_t*pool;
180     dict_t*traits;
181 } abc_script_t;
182
183 abc_script_t* abc_initscript(abc_file_t*pool, char*returntype, int num_params, ...);
184
185 #endif