abc constant pool implementation
[swftools.git] / lib / as3 / pool.h
1 /* pool.h
2
3    Routines for handling Flash2 AVM2 ABC contantpool entries.
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 __pool_h__
25 #define __pool_h__
26
27 #include "../q.h"
28 #include "../rfxswf.h"
29
30 DECLARE(pool);
31 DECLARE(multiname);
32 DECLARE(namespace);
33 DECLARE(namespace_set);
34 DECLARE_LIST(multiname);
35 DECLARE_LIST(namespace);
36 DECLARE_LIST(trait);
37
38 /* abc file constant pool */
39 struct _pool {
40     array_t*ints;
41     array_t*uints;
42     array_t*floats;
43     array_t*strings;
44     array_t*namespaces;
45     array_t*namespace_sets;
46     array_t*multinames;
47 };
48
49 typedef enum multiname_type
50 {QNAME=0x07,
51  QNAMEA=0x0D,
52  RTQNAME=0x0F,
53  RTQNAMEA=0x10,
54  RTQNAMEL=0x11,
55  RTQNAMELA=0x12,
56  MULTINAME=0x09,
57  MULTINAMEA=0x0E,
58  MULTINAMEL=0x1B,
59  MULTINAMELA=0x1C
60 } multiname_type_t;
61
62 char* access2str(int type);
63
64 struct _namespace {
65     U8 access;
66     char*name;
67 };
68 struct _namespace_set {
69     namespace_list_t*namespaces;
70 };
71 struct _multiname {
72     multiname_type_t type;
73     namespace_t*ns;
74     namespace_set_t*namespace_set;
75     const char*name;
76 };
77
78 /* object -> string */
79 char* namespace_set_to_string(namespace_set_t*set);
80 char* multiname_to_string(multiname_t*m);
81 char* namespace_to_string(namespace_t*ns);
82
83 /* integer -> object */
84 multiname_t*pool_lookup_multiname(pool_t*pool, int i);
85
86 /* object -> integer (lookup) */
87 int pool_find_namespace(pool_t*pool, namespace_t*ns);
88 int pool_find_namespace_set(pool_t*pool, namespace_set_t*set);
89 int pool_find_string(pool_t*pool, const char*s);
90 int pool_find_multiname(pool_t*pool, multiname_t*name);
91
92 /* object -> integer (lookup/creation) */
93 int pool_register_string(pool_t*pool, const char*s);
94 int pool_register_namespace(pool_t*pool, namespace_t*ns);
95 int pool_register_namespace_set(pool_t*pool, namespace_set_t*set);
96 int pool_register_multiname(pool_t*pool, multiname_t*n);
97 int pool_register_multiname2(pool_t*pool, char*name);
98
99 /* creation */
100 multiname_t* multiname_fromstring(const char*name);
101
102 pool_t*pool_new();
103 void pool_read(pool_t*pool, TAG*tag);
104 void pool_destroy(pool_t*pool);
105
106 #endif