X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=lib%2Fas3%2Fparser.y;h=9940fa56fac18165d477389f5ced95545a0556f5;hb=d730cd0a68888a4bee1484276735db5185ed7c5b;hp=89d80ecb15e22e33dc9b11b80defa4157c087a20;hpb=6ead8227212dc074744a3a4282a6a572d120fecc;p=swftools.git diff --git a/lib/as3/parser.y b/lib/as3/parser.y index 89d80ec..9940fa5 100644 --- a/lib/as3/parser.y +++ b/lib/as3/parser.y @@ -764,16 +764,18 @@ static void startfunction(token_t*ns, int flags, enum yytokentype getset, char*n multiname_t mname = {QNAME, &mname_ns, 0, name}; multiname_t*type2 = sig2mname(return_type); + int slot = 0; if(!strcmp(state->clsinfo->name,name)) { state->m = abc_class_constructor(state->cls, type2); + name = "__as3_constructor__"; } else { if(flags&FLAG_STATIC) state->m = abc_class_staticmethod(state->cls, type2, &mname); else state->m = abc_class_method(state->cls, type2, &mname); - int slot = state->m->trait->slot_id; - state->minfo = registerfunction(getset, flags, name, params, return_type, slot); + slot = state->m->trait->slot_id; } + state->minfo = registerfunction(getset, flags, name, params, return_type, slot); if(getset == KW_GET) state->m->trait->kind = TRAIT_GETTER; if(getset == KW_SET) state->m->trait->kind = TRAIT_SETTER; @@ -796,7 +798,7 @@ static void startfunction(token_t*ns, int flags, enum yytokentype getset, char*n } /* state->vars is initialized by state_new */ - if(new_variable("this", state->clsinfo)!=0) syntaxerror("Internal error"); + if(new_variable((flags&FLAG_STATIC)?"class":"this", state->clsinfo)!=0) syntaxerror("Internal error"); for(p=params->list;p;p=p->next) { new_variable(p->param->name, p->param->type); @@ -926,6 +928,40 @@ void parserassert(int b) if(!b) syntaxerror("internal error: assertion failed"); } +static classinfo_t* find_class(char*name) +{ + classinfo_t*c=0; + + c = registry_findclass(state->package, name); + + /* try explicit imports */ + dictentry_t* e = dict_get_slot(state->imports, name); + while(e) { + if(c) + break; + if(!strcmp(e->key, name)) { + c = (classinfo_t*)e->data; + } + e = e->next; + } + + /* try package.* imports */ + import_list_t*l = state->wildcard_imports; + while(l) { + if(c) + break; + //printf("does package %s contain a class %s?\n", l->import->package, name); + c = registry_findclass(l->import->package, name); + l = l->next; + } + + /* try global package */ + if(!c) { + c = registry_findclass("", name); + } + return c; +} + static code_t* toreadwrite(code_t*in, code_t*middlepart, char justassign, char readbefore) { /* converts this: @@ -1326,18 +1362,18 @@ SLOT_DECLARATION: MAYBE_MODIFIERS VARCONST T_IDENTIFIER MAYBETYPE MAYBEEXPRESSIO if($4) { MULTINAME(m, $4); t=abc_class_slot(state->cls, &mname, &m); - info->slot = t->slot_id; } else { t=abc_class_slot(state->cls, &mname, 0); } + info->slot = t->slot_id; } else { if($4) { MULTINAME(m, $4); t=abc_class_staticslot(state->cls, &mname, &m); - //info->slot = t->slot_id; } else { t=abc_class_staticslot(state->cls, &mname, 0); } + info->slot = t->slot_id; } if($5.c && !is_pushundefined($5.c)) { code_t*c = 0; @@ -1430,34 +1466,7 @@ FUNCTION_DECLARATION: MAYBE_MODIFIERS "function" GETSET T_IDENTIFIER '(' MAYBE_P CLASS: T_IDENTIFIER { /* try current package */ - $$ = registry_findclass(state->package, $1); - - /* try explicit imports */ - dictentry_t* e = dict_get_slot(state->imports, $1); - while(e) { - if($$) - break; - if(!strcmp(e->key, $1)) { - $$ = (classinfo_t*)e->data; - } - e = e->next; - } - - /* try package.* imports */ - import_list_t*l = state->wildcard_imports; - while(l) { - if($$) - break; - //printf("does package %s contain a class %s?\n", l->import->package, $1); - $$ = registry_findclass(l->import->package, $1); - l = l->next; - } - - /* try global package */ - if(!$$) { - $$ = registry_findclass("", $1); - } - + $$ = find_class($1); if(!$$) syntaxerror("Could not find class %s\n", $1); } @@ -1503,8 +1512,12 @@ NEW : "new" CLASS MAYBE_PARAM_VALUES { MULTINAME(m, $2); $$.c = code_new(); - /* TODO: why do we have to *find* our own classes? */ - $$.c = abc_findpropstrict2($$.c, &m); + if($2->slot) { + $$.c = abc_getglobalscope($$.c); + $$.c = abc_getslot($$.c, $2->slot); + } else { + $$.c = abc_findpropstrict2($$.c, &m); + } typedcode_list_t*l = $3; int len = 0; @@ -1513,7 +1526,10 @@ NEW : "new" CLASS MAYBE_PARAM_VALUES { l = l->next; len ++; } - $$.c = abc_constructprop2($$.c, &m, len); + if($2->slot) + $$.c = abc_construct($$.c, len); + else + $$.c = abc_constructprop2($$.c, &m, len); $$.t = $2; } @@ -1841,10 +1857,21 @@ E : "--" E { code_t*c = 0; E : E '.' T_IDENTIFIER {$$.c = $1.c; - if($$.t) { - memberinfo_t*f = registry_findmember($$.t, $3); + classinfo_t*t = $1.t; + char is_static = 0; + if(TYPE_IS_CLASS(t)) { + memberinfo_t*m = registry_findmember($1.t, "prototype"); + if(!m) syntaxerror("identifier '%s' not found in anonymous class", $3); + t = m->type; + is_static = 1; + } + if(t) { + memberinfo_t*f = registry_findmember(t, $3); + char noslot = 0; + if(f && !is_static != !(f->flags&FLAG_STATIC)) + noslot=1; - if(f && f->slot) { + if(f && f->slot && !noslot) { $$.c = abc_getslot($$.c, f->slot); } else { if(f) { @@ -1882,13 +1909,20 @@ VAR_READ : T_IDENTIFIER { $$.t = 0; $$.c = 0; int i; + classinfo_t*a = 0; memberinfo_t*f = 0; + + /* look at variables */ if((i = find_variable($1, &$$.t)) >= 0) { // $1 is a local variable $$.c = abc_getlocal($$.c, i); - } else if(f = registry_findmember(state->clsinfo, $1)) { + + /* look at current class' members */ + } else if((f = registry_findmember(state->clsinfo, $1))) { // $1 is a function in this class - if(f->flags&FLAG_STATIC) { + int var_is_static = (f->flags&FLAG_STATIC); + int i_am_static = (state->minfo?(state->minfo->flags&FLAG_STATIC):FLAG_STATIC); + if(var_is_static != i_am_static) { /* there doesn't seem to be any "static" way to access static properties of a class */ state->late_binding = 1; @@ -1913,10 +1947,22 @@ VAR_READ : T_IDENTIFIER { } else { $$.t = f->type; } + + /* look at classes in the current package and imported classes */ + } else if((a = find_class($1))) { + if(a->slot) { + $$.c = abc_getglobalscope($$.c); + $$.c = abc_getslot($$.c, a->slot); + } else { + MULTINAME(m, a); + $$.c = abc_getlex2($$.c, &m); + } + $$.t = TYPE_CLASS(a); + + /* unknown object, let the avm2 resolve it */ } else { - // let the avm2 resolve $1 if(strcmp($1,"trace")) - warning("Couldn't resolve %s, doing late binding", $1); + warning("Couldn't resolve %s, doing late binding", $1); state->late_binding = 1; multiname_t m = {MULTINAME, 0, &nopackage_namespace_set, $1};