use constant pool only while reading and writing
[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 struct _trait {
62     unsigned char type;
63     multiname_t*name;
64
65     union {
66         int disp_id;
67         int slot_id;
68         int data1;
69     };
70     union {
71         abc_method_t*method;
72         abc_class_t*cls;
73         multiname_t*type_name;
74         int data2;
75     };
76     int vindex;
77     int vkind;
78 };
79
80 struct _abc_class {
81     abc_file_t*pool;
82     
83     multiname_t*classname;
84     multiname_t*superclass;
85     const char*protectedNS;
86
87     multiname_list_t*interfaces;
88
89     abc_method_t*constructor;
90     U8 flags;
91     
92     abc_method_t*static_constructor;
93
94     trait_list_t*static_constructor_traits;
95     trait_list_t*traits;
96     
97     int index; //filled in during writing
98 };
99
100 abc_class_t* abc_class_new(abc_file_t*pool, char*classname, char*superclass);
101 void abc_class_sealed(abc_class_t*c);
102 void abc_class_final(abc_class_t*c);
103 void abc_class_interface(abc_class_t*c);
104 void abc_class_protectedNS(abc_class_t*c, char*namespace);
105
106 abc_method_body_t* abc_class_staticconstructor(abc_class_t*cls, char*returntype, int num_params, ...);
107 abc_method_body_t* abc_class_constructor(abc_class_t*cls, char*returntype, int num_params, ...);
108 abc_method_body_t* abc_class_method(abc_class_t*cls, char*returntype, char*name, int num_params, ...);
109
110 struct _abc_code {
111     U8 opcode;
112     U8 len;
113     void*params[2];
114     abc_code_t*next;
115     abc_code_t*prev;
116     abc_code_t*parent;
117 };
118
119 struct _abc_method_body {
120     abc_file_t*pool;
121     //abc_class_t*cls;
122     abc_method_t*method;
123     abc_code_t*code;
124     int max_stack;
125     int local_count;
126     int init_scope_depth;
127     int max_scope_depth;
128     int exception_count;
129     trait_list_t*traits;
130     
131     int index; // filled in during writing
132 };
133
134 typedef struct _abc_label {
135 } abc_label_t;
136
137 typedef struct _abc_script {
138     abc_method_t*method;
139     abc_file_t*pool;
140     trait_list_t*traits;
141 } abc_script_t;
142
143 abc_script_t* abc_initscript(abc_file_t*pool, char*returntype, int num_params, ...);
144
145 #define __ 
146
147 #endif