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