1 #include "state.h" 2 #include "common.h" 3 4 state_t* state = 0; 5 new_state()6void new_state() 7 { 8 NEW(state_t, s); 9 state_t*oldstate = state; 10 if(state) 11 memcpy(s, state, sizeof(state_t)); //shallow copy 12 if(!s->imports) { 13 s->imports = dict_new(); 14 } 15 if(!s->import_toplevel_packages) { 16 s->import_toplevel_packages = dict_new(); 17 } 18 state = s; 19 state->level++; 20 state->has_own_imports = 0; 21 state->vars = dict_new(); 22 state->old = oldstate; 23 state->new_vars = 0; 24 25 state->namespaces = dict_new(); 26 27 if(oldstate) 28 state->active_namespace_urls = list_clone(oldstate->active_namespace_urls); 29 } 30 state_destroy(state_t * state)31void state_destroy(state_t*state) 32 { 33 if(state->has_own_imports) { 34 list_free(state->wildcard_imports); 35 dict_destroy(state->imports);state->imports=0; 36 } 37 if(state->imports && (!state->old || state->old->imports!=state->imports)) { 38 dict_destroy(state->imports);state->imports=0; 39 } 40 if(state->vars) { 41 dict_destroy(state->vars);state->vars=0; 42 } 43 44 list_free(state->active_namespace_urls) 45 state->active_namespace_urls = 0; 46 47 free(state); 48 } 49 old_state()50void old_state() 51 { 52 if(!state || !state->old) 53 syntaxerror("invalid nesting"); 54 state_t*leaving = state; 55 56 state = state->old; 57 58 if(as3_pass>1 && leaving->method && leaving->method != state->method && !leaving->method->inner) { 59 methodstate_destroy(leaving->method);leaving->method=0; 60 } 61 if(as3_pass>1 && leaving->cls && leaving->cls != state->cls) { 62 free(leaving->cls); 63 leaving->cls=0; 64 } 65 66 state_destroy(leaving); 67 } 68 methodstate_new()69methodstate_t*methodstate_new() 70 { 71 NEW(methodstate_t,m); 72 m->allvars = dict_new(); 73 return m; 74 } 75 methodstate_destroy(methodstate_t * m)76void methodstate_destroy(methodstate_t*m) 77 { 78 dict_destroy(m->unresolved_variables); m->unresolved_variables = 0; 79 list_free(m->innerfunctions);m->innerfunctions=0; 80 81 if(m->allvars) { 82 DICT_ITERATE_DATA(m->allvars, void*, data) {free(data);} 83 m->allvars = 0; 84 } 85 } 86 87 dict_t*definitions=0; as3_set_define(const char * c)88void as3_set_define(const char*c) 89 { 90 if(!definitions) 91 definitions = dict_new(); 92 if(!dict_contains(definitions,c)) 93 dict_put(definitions,c,0); 94 } 95 96