3 Compiler for parsing Flash2 AVM2 ABC Actionscript
5 Extension module for the rfxswf library.
6 Part of the swftools package.
8 Copyright (c) 2008/2009 Matthias Kramm <kramm@quiss.org>
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.
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.
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 */
24 #include "tokenizer.h"
27 #include "parser.tab.h"
30 /* flex/bison definitions */
31 extern int a3_parse();
33 extern int as3_lex_destroy();
35 void as3_setverbosity(int level)
39 void as3_add_include_dir(char*dir)
44 static char registry_initialized = 0;
45 static char parser_initialized = 0;
47 //#define STORE_TOKENS
58 int token = as3_lex();
59 /* FIXME: current_file needs to be stored, too */
60 mem_put(&tokens, &token, sizeof(token));
61 mem_put(&tokens, &a3_lval, sizeof(a3_lval));
62 mem_put(&tokens, ¤t_line, sizeof(current_line));
63 mem_put(&tokens, ¤t_column, sizeof(current_column));
67 mem_get(&tokens, &token, sizeof(token));
68 mem_get(&tokens, &a3_lval, sizeof(a3_lval));
69 mem_get(&tokens, ¤t_line, sizeof(current_line));
70 mem_get(&tokens, ¤t_column, sizeof(current_column));
78 static void as3_parse(const char*name, const char*filename, void*mem, int length)
80 if(!registry_initialized) {
81 registry_initialized = 1;
84 if(!parser_initialized) {
85 parser_initialized = 1;
87 #if defined(STORE_TOKENS)
99 fi = enter_file2(name, filename, 0);
102 enter_file(name, name, 0);
103 as3_buffer_input(mem, length);
109 initialize_file(name);
120 fi = enter_file2(name, filename, 0);
123 enter_file(name, name, 0);
124 as3_buffer_input(mem, length);
130 initialize_file(name);
140 void as3_parse_bytearray(const char*name, void*mem, int length)
142 as3_parse(name, 0, mem, length);
145 void as3_parse_file(const char*filename)
147 char*fullfilename = find_file(filename);
150 as3_parse(filename, fullfilename, 0,0);
153 static void*as3code = 0;
156 if(parser_initialized) {
157 parser_initialized = 0;
158 as3code = finish_parser();
162 char* as3_getglobalclass()
164 return as3_globalclass;
169 if(parser_initialized) {
170 parser_initialized = 0;
171 swf_FreeABC(finish_parser());
176 if(as3_globalclass) {
177 free(as3_globalclass);as3_globalclass=0;