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