X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=lib%2Fas3%2Ftokenizer.lex;h=805cf2e68ee516da0e3329719f3fc7d1df1356f6;hb=62a83d162b254d91da418cee25f5b87b067a3f92;hp=9ac960747dc3ed7343309b3089d38635e0210875;hpb=bb864e1a88e670c99d559c7dee4f74e9bf7d978b;p=swftools.git diff --git a/lib/as3/tokenizer.lex b/lib/as3/tokenizer.lex index 9ac9607..805cf2e 100644 --- a/lib/as3/tokenizer.lex +++ b/lib/as3/tokenizer.lex @@ -28,53 +28,12 @@ #include #include #include "../utf8.h" +#include "common.h" #include "tokenizer.h" #include "files.h" -int as3_pass = 0; -int as3_verbosity = 1; unsigned int as3_tokencount = 0; -void as3_error(const char*format, ...) -{ - char buf[1024]; - int l; - va_list arglist; - if(as3_verbosity<0) - exit(1); - va_start(arglist, format); - vsprintf(buf, format, arglist); - va_end(arglist); - fprintf(stderr, "%s:%d:%d: error: %s\n", current_filename_short, current_line, current_column, buf); - fflush(stderr); - exit(1); -} -void as3_warning(const char*format, ...) -{ - char buf[1024]; - int l; - va_list arglist; - if(as3_verbosity<1) - return; - va_start(arglist, format); - vsprintf(buf, format, arglist); - va_end(arglist); - fprintf(stderr, "%s:%d:%d: warning: %s\n", current_filename_short, current_line, current_column, buf); - fflush(stderr); -} -void as3_softwarning(const char*format, ...) -{ - char buf[1024]; - int l; - va_list arglist; - if(as3_verbosity<2) - return; - va_start(arglist, format); - vsprintf(buf, format, arglist); - va_end(arglist); - fprintf(stderr, "%s:%d:%d: warning: %s\n", current_filename_short, current_line, current_column, buf); - fflush(stderr); -} static void dbg(const char*format, ...) { char buf[1024]; @@ -295,12 +254,6 @@ static void handleCData(char*s, int len) static void handleString(char*s, int len) { - if(as3_pass < 2) { - // don't bother decoding strings in pass 1 - memset(&a3_lval, 0, sizeof(a3_lval)); - return; - } - if(s[0]=='"') { if(s[len-1]!='"') syntaxerror("String doesn't end with '\"'"); s++;len-=2; @@ -310,7 +263,6 @@ static void handleString(char*s, int len) s++;len-=2; } else syntaxerror("String incorrectly terminated"); - a3_lval.str = string_unescape(s, len); } @@ -339,22 +291,7 @@ static char*nrbuf() static inline int setint(int v) { a3_lval.number_int = v; - if(v>-128) - return T_BYTE; - else if(v>=-32768) - return T_SHORT; - else - return T_INT; -} -static inline int setuint(unsigned int v) -{ - a3_lval.number_uint = v; - if(v<128) - return T_BYTE; - else if(v<32768) - return T_SHORT; - else - return T_UINT; + return T_INT; } static inline int setfloat(double v) { @@ -374,7 +311,9 @@ static inline int handleint() char*s = nrbuf(); char l = (yytext[0]=='-'); - char*max = l?"1073741824":"2147483647"; + //char*max = l?"1073741824":"2147483647"; + char*max = l?"2147483648":"2147483647"; + if(yyleng-l>10) { as3_softwarning("integer overflow: %s (converted to Number)", s); return handlefloat(); @@ -400,7 +339,7 @@ static inline int handleint() v*=10; v+=yytext[t]-'0'; } - return setuint(v); + return setint(v); } } @@ -449,21 +388,21 @@ static inline int handlehex() else if((c>='a' && c<='f') || (c>='A' && c<='F')) v|=(c&0x0f)+9; } - if(l && v>1073741824) { + if(l && v>=0x80000000) { char*s = nrbuf(); - as3_softwarning("signed integer overflow: %s (converted to Number)", s); + as3_softwarning("integer overflow: %s (converted to Number)", s); return setfloat(v); } - if(!l && v>2147483647) { + if(!l && v>0x7fffffff) { char*s = nrbuf(); - as3_softwarning("unsigned integer overflow: %s (converted to Number)", s); + as3_softwarning("integer overflow: %s (converted to Number)", s); return setfloat(v); } if(l==3) { return setint(-(int)v); } else { - return setuint(v); + return setint(v); } } @@ -523,18 +462,18 @@ static inline void c() { current_column+=yyleng; } -static trie_t*namespaces = 0; -void tokenizer_register_namespace(const char*id) +trie_t*active_namespaces = 0; +/*void tokenizer_register_namespace(const char*id) { - trie_put(&namespaces, id); + trie_put(namespaces, id, 0); } void tokenizer_unregister_namespace(const char*id) { trie_remove(namespaces, id); -} +}*/ static inline tokenizer_is_namespace(const char*id) { - return trie_lookup(namespaces, id); + return trie_contains(active_namespaces, id); } static inline int handleIdentifier() @@ -609,6 +548,7 @@ REGEXP [/]([^/\n]|\\[/])*[/][a-zA-Z]* {HEXFLOAT}/{_} {c(); BEGIN(INITIAL);return handlehexfloat();} {INT}/{_} {c(); BEGIN(INITIAL);return handleint();} {FLOAT}/{_} {c(); BEGIN(INITIAL);return handlefloat();} +NaN {c(); BEGIN(INITIAL);return m(KW_NAN);} 3rr0r {/* for debugging: generates a tokenizer-level error */ syntaxerror("3rr0r");} @@ -765,7 +705,6 @@ char*token2string(enum yytokentype nr, YYSTYPE v) } else if(nr==T_INT) return ""; else if(nr==T_UINT) return ""; - else if(nr==T_BYTE) return ""; else if(nr==T_FLOAT) return ""; else if(nr==T_EOF) return "***END***"; else if(nr==T_GE) return ">=";