X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=lib%2Fas3%2Fparser.y;h=3abeaa3c6a88db79b95b2b34cd6f3c2cb3d18a4e;hb=79e69e1d109a95f9495b96b29a723758d06a71d9;hp=a81e4e04cedda223b9595aeba7cbe2a92dac16d5;hpb=71c8242a8242eeb6e8b6dcf57239550a6f35c88a;p=swftools.git diff --git a/lib/as3/parser.y b/lib/as3/parser.y index a81e4e0..3abeaa3 100644 --- a/lib/as3/parser.y +++ b/lib/as3/parser.y @@ -332,6 +332,7 @@ struct _methodstate { char uses_parent_function; int uses_slots; dict_t*slots; + int activation_var; abc_method_t*abc; int var_index; // for inner methods @@ -354,6 +355,8 @@ typedef struct _state { import_list_t*wildcard_imports; dict_t*import_toplevel_packages; dict_t*imports; + + namespace_list_t*active_namespace_urls; char has_own_imports; char new_vars; // e.g. transition between two functions @@ -445,6 +448,9 @@ static void new_state() state->new_vars = 0; trie_remember(active_namespaces); + + if(oldstate) + state->active_namespace_urls = list_clone(oldstate->active_namespace_urls); } static void state_has_imports() { @@ -486,6 +492,9 @@ static void state_destroy(state_t*state) dict_destroy(state->vars);state->vars=0; } + list_free(state->active_namespace_urls) + state->active_namespace_urls = 0; + free(state); } @@ -507,7 +516,7 @@ static void old_state() free(leaving->cls); leaving->cls=0; } - + state_destroy(leaving); } @@ -616,6 +625,7 @@ typedef struct _variable { int index; classinfo_t*type; char init; + char is_parameter; methodstate_t*is_inner_method; } variable_t; @@ -747,17 +757,26 @@ static void parsererror(const char*file, int line, const char*f) } -static code_t* add_scope_code(code_t*c, methodstate_t*m) +static code_t* add_scope_code(code_t*c, methodstate_t*m, char init) { - if(m->uses_slots || (m->late_binding && !m->inner)) { + if(m->uses_slots || (m->late_binding && !m->inner)) { //???? especially inner functions need the pushscope c = abc_getlocal_0(c); c = abc_pushscope(c); } if(m->uses_slots) { - /* FIXME: does this need to be the same activation object as - in the function header? */ - c = abc_newactivation(c); - c = abc_pushscope(c); + /* FIXME: this alloc_local() causes variable indexes to be + different in pass2 than in pass1 */ + if(!m->activation_var) + m->activation_var = alloc_local(); + if(init) { + c = abc_newactivation(c); + c = abc_dup(c); + c = abc_pushscope(c); + c = abc_setlocal(c, m->activation_var); + } else { + c = abc_getlocal(c, m->activation_var); + c = abc_pushscope(c); + } } return c; } @@ -766,7 +785,7 @@ static code_t* method_header(methodstate_t*m) { code_t*c = 0; - c = add_scope_code(c, m); + c = add_scope_code(c, m, 1); methodstate_list_t*l = m->innerfunctions; while(l) { @@ -793,6 +812,19 @@ static code_t* method_header(methodstate_t*m) c = abc_getlocal_0(c); c = abc_constructsuper(c, 0); } + + if(m->slots) { + /* all parameters that are used by inner functions + need to be copied from local to slot */ + parserassert(m->activation_var); + DICT_ITERATE_ITEMS(m->slots,char*,name,variable_t*,v) { + if(v->is_parameter) { + c = abc_getlocal(c, m->activation_var); + c = abc_getlocal(c, v->index); + c = abc_setslot(c, v->index); + } + } + } list_free(m->innerfunctions); m->innerfunctions = 0; return c; @@ -848,6 +880,7 @@ static namespace_t modifiers2access(modifiers_t*mod) if(!url) { /* shouldn't happen- the tokenizer only reports something as a namespace if it was already registered */ + trie_dump(active_namespaces); syntaxerror("unknown namespace: %s", mod->ns); } ns.name = url; @@ -870,10 +903,16 @@ static namespace_t modifiers2access(modifiers_t*mod) } static slotinfo_t* find_class(const char*name); -memberinfo_t* findmember_nsset(classinfo_t*cls, const char*name, char recurse) +static memberinfo_t* findmember_nsset(classinfo_t*cls, const char*name, char recurse) { - /* FIXME- we need to loop through namespaces here */ - return registry_findmember(cls, "", name, recurse); + return registry_findmember_nsset(cls, state->active_namespace_urls, name, recurse); +} + +void add_active_url(const char*url) +{ + NEW(namespace_t,n); + n->name = url; + list_append(state->active_namespace_urls, n); } static void function_initvars(methodstate_t*m, params_t*params, int flags, char var0) @@ -902,15 +941,14 @@ static void function_initvars(methodstate_t*m, params_t*params, int flags, char if(params) { param_list_t*p=0; for(p=params->list;p;p=p->next) { - new_variable(p->param->name, p->param->type, 0, 1); + variable_t*v = new_variable2(p->param->name, p->param->type, 0, 1); + v->is_parameter = 1; } } - - if(as3_pass==2) { - m->scope_code = add_scope_code(m->scope_code, m); + if(m->uses_slots) { + dict_dump(m->slots, stdout, ""); } - methodstate_list_t*l = m->innerfunctions; while(l) { methodstate_t*m = l->methodstate; @@ -923,14 +961,19 @@ static void function_initvars(methodstate_t*m, params_t*params, int flags, char l = l->next; } + if(as3_pass==2) { + m->scope_code = add_scope_code(m->scope_code, m, 0); + } + if(as3_pass==2 && m->slots) { /* exchange unresolved identifiers with the actual objects */ DICT_ITERATE_ITEMS(m->slots, char*, name, variable_t*, v) { if(v->type && v->type->kind == INFOTYPE_UNRESOLVED) { - v->type = (classinfo_t*)registry_resolve((slotinfo_t*)v->type); - if(!v->type || v->type->kind != INFOTYPE_CLASS) { - syntaxerror("Couldn't find class %s", v->type->name); + classinfo_t*type = (classinfo_t*)registry_resolve((slotinfo_t*)v->type); + if(!type || type->kind != INFOTYPE_CLASS) { + syntaxerror("Couldn't find class %s::%s (%s)", v->type->package, v->type->name, name); } + v->type = type; } } } @@ -2606,8 +2649,6 @@ IMPORT : "import" PACKAGEANDCLASS { if(!s && as3_pass==1) {// || !(s->flags&FLAG_BUILTIN)) { as3_schedule_class($2->package, $2->name); } - - PASS2 classinfo_t*c = $2; if(!c) syntaxerror("Couldn't import class\n"); @@ -2622,7 +2663,6 @@ IMPORT : "import" PACKAGE '.' '*' { as3_schedule_package($2); } - PASS2 NEW(import_t,i); i->package = $2; state_has_imports(); @@ -2930,7 +2970,7 @@ CLASS: X_IDENTIFIER { c->nsset = get_current_imports(); /* make the compiler look for this class in the current directory, just in case: */ - as3_schedule_class_noerror(state->package, $1); + //as3_schedule_class_noerror(state->package, $1); } $$ = (classinfo_t*)c; PASS2 @@ -3679,15 +3719,17 @@ E : E '.' T_IDENTIFIER { } else if($1.c && $1.c->opcode == OPCODE___PUSHPACKAGE__) { string_t*package = $1.c->data[0]; char*package2 = concat3(package->str, ".", $3); - if(dict_contains(state->import_toplevel_packages, package2)) { + + slotinfo_t*a = registry_find(package->str, $3); + if(a) { + $$ = push_class(a); + } else if(dict_contains(state->import_toplevel_packages, package2) || + registry_ispackage(package2)) { $$.c = $1.c; $$.c->data[0] = string_new4(package2); $$.t = 0; } else { - slotinfo_t*a = registry_find(package->str, $3); - if(!a) - syntaxerror("couldn't resolve %s", package2); - $$ = push_class(a); + syntaxerror("couldn't resolve %s", package2); } } else { /* when resolving a property on an unknown type, we do know the @@ -3713,9 +3755,9 @@ VAR_READ : T_IDENTIFIER { unknown_variable($1); } - /* let the compiler know that it might check the current directory/package + /* let the compiler know that it might want to check the current directory/package for this identifier- maybe there's a file $1.as defining $1. */ - as3_schedule_class_noerror(state->package, $1); + //as3_schedule_class_noerror(state->package, $1); PASS2 $$.t = 0; @@ -3741,8 +3783,11 @@ VAR_READ : T_IDENTIFIER { int i_am_static = (state->method && state->method->info)?(state->method->info->flags&FLAG_STATIC):FLAG_STATIC; /* look at current class' members */ - if(state->cls && (f = findmember_nsset(state->cls->info, $1, 1)) && - (f->flags&FLAG_STATIC) >= i_am_static) { + if(!state->method->inner && + state->cls && + (f = findmember_nsset(state->cls->info, $1, 1)) && + (f->flags&FLAG_STATIC) >= i_am_static) + { // $1 is a function in this class int var_is_static = (f->flags&FLAG_STATIC); @@ -3783,7 +3828,8 @@ VAR_READ : T_IDENTIFIER { } /* look through package prefixes */ - if(dict_contains(state->import_toplevel_packages, $1)) { + if(dict_contains(state->import_toplevel_packages, $1) || + registry_ispackage($1)) { $$.c = abc___pushpackage__($$.c, $1); $$.t = 0; break; @@ -3842,9 +3888,17 @@ NAMESPACE_DECLARATION : MAYBE_MODIFIERS NAMESPACE_ID { } USE_NAMESPACE : "use" "namespace" CLASS_SPEC { - PASS12 - char*url = 0; - trie_put(active_namespaces, $3->name, url); + + const char*url = $3->name; + varinfo_t*s = (varinfo_t*)$3; + if(!s || s->kind != INFOTYPE_SLOT) + syntaxerror("%s.%s is not a public namespace (%d)", $3->package, $3->name, s?s->kind:-1); + if(!s->value || !NS_TYPE(s->value->type)) + syntaxerror("%s.%s is not a namespace", $3->package, $3->name); + url = s->value->ns->name; + + trie_put(active_namespaces, $3->name, (void*)url); + add_active_url(url); $$=0; }