X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=lib%2Fas3%2Fcompiler.c;h=fded71ec2ee80b24f501077d53b0bdc81797a0c8;hb=618a86d162d32d7b64cdf872d3033a56d548b526;hp=af418cbbc2f2bfbec319d544b46d58afe019a7d7;hpb=e531f5204757feafa7e09630e4c6b66dd6be6147;p=swftools.git diff --git a/lib/as3/compiler.c b/lib/as3/compiler.c index af418cb..fded71e 100644 --- a/lib/as3/compiler.c +++ b/lib/as3/compiler.c @@ -26,12 +26,12 @@ #include "parser.h" #include "parser.tab.h" #include "compiler.h" -#include /* flex/bison definitions */ -extern void avm2_set_in (FILE * in_str ); -extern int avm2_parse(); -extern int avm2_lex_destroy(); +extern void as3_set_in (FILE * in_str ); +extern int a3_parse(); +extern int as3_lex(); +extern int as3_lex_destroy(); void as3_setverbosity(int level) { @@ -45,6 +45,37 @@ void as3_add_include_dir(char*dir) static char registry_initialized = 0; static char parser_initialized = 0; +//#define STORE_TOKENS + +#ifdef STORE_TOKENS +static mem_t tokens; +#endif + +int a3_lex() +{ + as3_tokencount++; +#ifdef STORE_TOKENS + if(as3_pass==1) { + int token = as3_lex(); + /* FIXME: current_file needs to be stored, too */ + mem_put(&tokens, &token, sizeof(token)); + mem_put(&tokens, &a3_lval, sizeof(a3_lval)); + mem_put(&tokens, ¤t_line, sizeof(current_line)); + mem_put(&tokens, ¤t_column, sizeof(current_column)); + return token; + } else { + int token; + mem_get(&tokens, &token, sizeof(token)); + mem_get(&tokens, &a3_lval, sizeof(a3_lval)); + mem_get(&tokens, ¤t_line, sizeof(current_line)); + mem_get(&tokens, ¤t_column, sizeof(current_column)); + return token; + } +#else + return as3_lex(); +#endif +} + void as3_parse_file(char*filename) { if(!registry_initialized) { @@ -54,19 +85,44 @@ void as3_parse_file(char*filename) if(!parser_initialized) { parser_initialized = 1; initialize_parser(); +#if defined(STORE_TOKENS) + mem_init(&tokens); +#endif } - char*fullfilename = enter_file(filename, 0); - FILE*fi = fopen(fullfilename, "rb"); - if(!fi) { - syntaxerror("Couldn't find file %s: %s", fullfilename, strerror(errno)); - } - avm2_set_in(fi); +#ifdef STORE_TOKENS + tokens.pos = 0; + tokens.read_pos = 0; +#endif + + FILE*fi = enter_file2(filename, 0); + + /* pass 1 */ + as3_pass = 1; + as3_tokencount=0; + as3_set_in(fi); initialize_file(filename); - avm2_parse(); - avm2_lex_destroy(); - fclose(fi); + a3_parse(); + as3_lex_destroy(); + finish_file(); + +#ifdef STORE_TOKENS + tokens.read_pos = 0; +#endif + + /* pass 2 */ + as3_pass = 2; + as3_tokencount=0; + enter_file(filename, 0); + fseek(fi, 0, SEEK_SET); + as3_set_in(fi); + initialize_file(filename); + a3_parse(); + as3_lex_destroy(); finish_file(); + + fclose(fi); + } static void*as3code = 0; @@ -88,6 +144,9 @@ void as3_destroy() if(parser_initialized) { parser_initialized = 0; swf_FreeABC(finish_parser()); +#ifdef STORE_TOKENS + mem_clear(&tokens); +#endif } if(as3_globalclass) { free(as3_globalclass);as3_globalclass=0;