X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=lib%2Fas3%2Fexpr.c;h=c07478b6066370fcf2978f56a92164135b7e0f94;hb=4dacf8e5890fb8cd0f53afbd4305c8b9ff9e7986;hp=25e0132c6e91bab460d5e6a395cc45574bf7f158;hpb=b8aa0577aae67db4da5221459102202febc5c103;p=swftools.git diff --git a/lib/as3/expr.c b/lib/as3/expr.c index 25e0132..c07478b 100644 --- a/lib/as3/expr.c +++ b/lib/as3/expr.c @@ -65,10 +65,27 @@ static classinfo_t*join_types(classinfo_t*type1, classinfo_t*type2, nodetype_t*t) { - if(!type1 || !type2) - return TYPE_ANY; - if(TYPE_IS_ANY(type1) || TYPE_IS_ANY(type2)) - return TYPE_ANY; + if(t == &node_plus) { + if((TYPE_IS_XMLLIST(type1) || TYPE_IS_XML(type1)) && + (TYPE_IS_XMLLIST(type2) || TYPE_IS_XML(type2))) + return TYPE_OBJECT; + if(BOTH_INT(type1, type2)) + return TYPE_INT; + if(IS_NUMBER_OR_INT(type1) && IS_NUMBER_OR_INT(type2)) + return TYPE_NUMBER; + if(TYPE_IS_DATE(type1) || TYPE_IS_DATE(type2)) + return TYPE_OBJECT; + if(TYPE_IS_STRING(type1) || TYPE_IS_STRING(type2)) { + /* depending on where the strings come from, the result type + of an "add" might be an object or a string, depending on the + verifier's mood. So basically we just don't know the type. */ + return TYPE_VOID; + } + if(TYPE_IS_ANY(type1) || TYPE_IS_ANY(type2)) + return TYPE_ANY; + return TYPE_OBJECT; // e.g. array+array = object + } + if(type1 == type2) return type1; return TYPE_ANY; @@ -132,7 +149,8 @@ static code_t* toreadwrite(code_t*in, code_t*middlepart, char justassign, char r write->opcode = OPCODE_SETPROPERTY; multiname_t*m = (multiname_t*)r->data[0]; write->data[0] = multiname_clone(m); - if(m->type == QNAME || m->type == MULTINAME) { + if(m->type == QNAME || m->type == MULTINAME || + m->type == QNAMEA || m->type == MULTINAMEA) { if(!justassign) { prefix = abc_dup(prefix); // we need the object, too } @@ -317,7 +335,6 @@ constant_t node_plus_eval(node_t*n) EVAL_HEADER_LEFTRIGHT; char left_int = left.type == CONSTANT_INT || left.type == CONSTANT_UINT; if(left_int && (right.type == CONSTANT_INT || right.type == CONSTANT_UINT)) { - /* FIXME: what to do about signed/unsigned overflows? */ int i = constant_to_int(&left) + constant_to_int(&right); r.type = CONSTANT_INT; r.i = i; @@ -2058,7 +2075,7 @@ typedcode_t node_pluseq_read(node_t*n) c = abc_add_i(c); } else { c = abc_add(c); - c = converttype(c, TYPE_NUMBER, left.t); + c = converttype(c, join_types(left.t,right.t,&node_plus), left.t); } c = toreadwrite(left.c, c, 0, 0, 1); t = left.t; @@ -2072,7 +2089,7 @@ code_t* node_pluseq_exec(node_t*n) c = abc_add_i(c); } else { c = abc_add(c); - c = converttype(c, TYPE_NUMBER, left.t); + c = converttype(c, join_types(left.t,right.t,&node_plus), left.t); } return toreadwrite(left.c, c, 0, 0, 0); } @@ -2831,8 +2848,8 @@ void node_dump2(node_t*n, const char*p1, const char*p2, FILE*fi) void node_dump(node_t*n) { - printf("---------------------------VVVV\n"); + printf("------------VVVV---------------\n"); node_dump2(n,"","",stdout); - printf("---------------------------^^^^\n"); + printf("-------------------------------\n"); }