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