X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=lib%2Fas3%2Fparser.y;h=37ad268b396d14be3cedaa08dc302efb64009b65;hb=322a2f4bf5cdb00be99a0fe660372b1596265a4d;hp=a574b88bc76f6540950ed390ad4e8485ef7785d7;hpb=8384058f169f17c67c30f29aa30a285ed1e36b1b;p=swftools.git diff --git a/lib/as3/parser.y b/lib/as3/parser.y index a574b88..37ad268 100644 --- a/lib/as3/parser.y +++ b/lib/as3/parser.y @@ -573,7 +573,7 @@ void initialize_file(char*filename) if(!state->method) syntaxerror("internal error: skewed tokencount"); function_initvars(state->method, 0, 0, 0, 1); - global->init = abc_initscript(global->file); + global->init = 0; } } @@ -586,9 +586,12 @@ void finish_file() if(as3_pass==2) { dict_del(global->file2token2info, current_filename); code_t*header = method_header(state->method); - code_t*c = wrap_function(header, 0, global->init->method->body->code); - global->init->method->body->code = abc_returnvoid(c); - free(state->method);state->method=0; + //if(global->init->method->body->code || global->init->traits) { + if(global->init) { + code_t*c = wrap_function(header, 0, global->init->method->body->code); + global->init->method->body->code = abc_returnvoid(c); + free(state->method);state->method=0; + } } //free(state->package);state->package=0; // used in registry @@ -665,6 +668,9 @@ static code_t*defaultvalue(code_t*c, classinfo_t*type) c = abc_pushnan(c); } else if(TYPE_IS_BOOLEAN(type)) { c = abc_pushfalse(c); + } else if(TYPE_IS_STRING(type)) { + c = abc_pushnull(c); + c = abc_coerce_s(c); } else if(!type) { //c = abc_pushundefined(c); syntaxerror("internal error: can't generate default value for * type"); @@ -727,14 +733,12 @@ static code_t* var_block(code_t*body) code_t*k = 0; int t; int num=0; - for(t=0;tvars->hashsize;t++) { - DICT_ITERATE_DATA(state->vars, variable_t*, v) { - if(v->type && v->init) { - c = defaultvalue(c, v->type); - c = abc_setlocal(c, v->index); - k = abc_kill(k, v->index); - num++; - } + DICT_ITERATE_DATA(state->vars, variable_t*, v) { + if(v->type && v->init) { + c = defaultvalue(c, v->type); + c = abc_setlocal(c, v->index); + k = abc_kill(k, v->index); + num++; } } @@ -1468,6 +1472,7 @@ static abc_method_t* endfunction(modifiers_t*mod, enum yytokentype getset, char* multiname_t mname = {QNAME, &mname_ns, 0, name}; f = abc_method_new(global->file, type2, 1); + if(!global->init) global->init = abc_initscript(global->file); trait_t*t = trait_new_method(&global->init->traits, multiname_clone(&mname), f); //abc_code_t*c = global->init->method->body->code; } @@ -1589,12 +1594,18 @@ code_t*converttype(code_t*c, classinfo_t*from, classinfo_t*to) if(TYPE_IS_STRING(to)) return abc_convert_s(c); if(TYPE_IS_OBJECT(to)) - return abc_convert_o(c); + return abc_coerce2(c, &m); + if(TYPE_IS_OBJECT(from) && TYPE_IS_XMLLIST(to)) + return abc_coerce2(c, &m); + if(TYPE_IS_OBJECT(from) && TYPE_IS_ARRAY(to)) + return abc_coerce2(c, &m); classinfo_t*supertype = from; while(supertype) { if(supertype == to) { - // target type is one of from's superclasses + /* target type is one of from's superclasses. + (not sure we need this coerce - as far as the verifier + is concerned, object==object (i think) */ return abc_coerce2(c, &m); } int t=0; @@ -1620,7 +1631,17 @@ code_t*converttype(code_t*c, classinfo_t*from, classinfo_t*to) return c; } -/* move to ast.c todo end */ +code_t* coerce_to_type(code_t*c, classinfo_t*t) +{ + if(!t) { + return abc_coerce_a(c); + } else if(TYPE_IS_STRING(t)) { + return abc_coerce_s(c); + } else { + MULTINAME(m, t); + return abc_coerce2(c, &m); + } +} char is_pushundefined(code_t*c) { @@ -1962,8 +1983,12 @@ CODEBLOCK : CODEPIECE %prec below_semicolon {$$=$1;} /* ------------ package init code ------------------- */ PACKAGE_INITCODE: CODE_STATEMENT { - code_t**cc = &global->init->method->body->code; - *cc = code_append(*cc, $1); + if($1) { + if(!global->init) + global->init = abc_initscript(global->file); + code_t**cc = &global->init->method->body->code; + *cc = code_append(*cc, $1); + } } /* ------------ conditional compilation ------------- */ @@ -2597,6 +2622,7 @@ IDECLARATION : MAYBE_MODIFIERS "function" GETSET T_IDENTIFIER '(' MAYBE_PARAM_LI code_t**code=0; if(!state->cls) { // global variable + if(!global->init) global->init = abc_initscript(global->file); ns.name = state->package; traits = &global->init->traits; code = &global->init->method->body->code; @@ -2608,6 +2634,10 @@ IDECLARATION : MAYBE_MODIFIERS "function" GETSET T_IDENTIFIER '(' MAYBE_PARAM_LI // instance variable traits = &state->cls->abc->traits; code = &state->cls->init->header; + + if(ns.access == ACCESS_PROTECTED) { + ns.name = concat3(state->cls->info->package,":",state->cls->info->name); + } } if(c) *c = code; @@ -3074,8 +3104,8 @@ FUNCTIONCALL : E '(' MAYBE_EXPRESSION_LIST ')' { // calling a class is like a typecast $$.t = (classinfo_t*)v.t->data; } else { - $$.c = abc_coerce_a($$.c); $$.t = TYPE_ANY; + $$.c = abc_coerce_a($$.c); } }