added support members with namespace access
[swftools.git] / lib / as3 / parser.y
index ce8f262..33ab3de 100644 (file)
@@ -175,7 +175,7 @@ extern int a3_lex();
 %type <code> CODEBLOCK MAYBECODE MAYBE_CASE_LIST CASE_LIST DEFAULT CASE SWITCH WITH
 %type <code> PACKAGE_DECLARATION SLOT_DECLARATION
 %type <code> FUNCTION_DECLARATION PACKAGE_INITCODE
-%type <code> VARIABLE_DECLARATION ONE_VARIABLE VARIABLE_LIST THROW 
+%type <code> VARIABLE_DECLARATION ONE_VARIABLE VARIABLE_LIST THROW
 %type <exception> CATCH FINALLY
 %type <catch_list> CATCH_LIST CATCH_FINALLY_LIST
 %type <code> CLASS_DECLARATION
@@ -328,6 +328,7 @@ struct _methodstate {
 
     abc_method_t*abc;
     int var_index; // for inner methods
+    int slot_index; // for inner methods
     char is_a_slot; // for inner methods
 
     code_t*header;
@@ -376,8 +377,10 @@ DECLARE_LIST(state);
     multiname_t m;\
     namespace_t m##_ns;\
     if(f) { \
-        m##_ns.access = ((slotinfo_t*)(f))->access; \
-        m##_ns.name = ""; \
+        if((m##_ns.access = ((slotinfo_t*)(f))->access)==ACCESS_NAMESPACE) \
+            m##_ns.name = ((slotinfo_t*)(f))->package; \
+        else \
+            m##_ns.name = ""; \
         m.type = QNAME; \
         m.ns = &m##_ns; \
         m.namespace_set = 0; \
@@ -722,7 +725,7 @@ static code_t* method_header(methodstate_t*m)
             c = abc_newfunction(c, l->methodstate->abc);
             c = abc_dup(c);
             c = abc_setlocal(c, l->methodstate->var_index);
-            c = abc_setslot(c, l->methodstate->var_index);
+            c = abc_setslot(c, l->methodstate->slot_index);
         } else {
             c = abc_newfunction(c, l->methodstate->abc);
             c = abc_setlocal(c, l->methodstate->var_index);
@@ -817,7 +820,9 @@ static void function_initvars(methodstate_t*m, params_t*params, int flags, char
     }
     if(m->uses_slots) {
         /* as variables and slots share the same number, make sure
-           that those variable indices are reserved */
+           that those variable indices are reserved. It's up to the
+           optimizer to later shuffle the variables down to lower
+           indices */
         m->variable_count = m->uses_slots; 
     }
 
@@ -833,6 +838,7 @@ static void function_initvars(methodstate_t*m, params_t*params, int flags, char
         methodstate_t*m = l->methodstate;
         variable_t* v = new_variable2(m->info->name, TYPE_FUNCTION(m->info), 0, 1);
         m->var_index = v->index;
+        m->slot_index = v->index;
         v->is_inner_method = m;
         l = l->next;
     }
@@ -1899,7 +1905,7 @@ MAYBECODE: {$$=code_new();}
 CODE: CODE CODEPIECE {$$=code_append($1,$2);}
 CODE: CODEPIECE {$$=$1;}
 
-// code which also may appear outside a method
+// code which may appear outside of methods
 CODE_STATEMENT: IMPORT 
 CODE_STATEMENT: FOR 
 CODE_STATEMENT: FOR_IN 
@@ -1914,7 +1920,7 @@ CODE_STATEMENT: USE_NAMESPACE
 CODE_STATEMENT: '{' CODE '}' {$$=$2;}
 CODE_STATEMENT: '{' '}' {$$=0;}
 
-// code which may appear anywhere
+// code which may appear in methods
 CODEPIECE: ';' {$$=0;}
 CODEPIECE: CODE_STATEMENT
 CODEPIECE: VARIABLE_DECLARATION
@@ -3250,7 +3256,7 @@ E : E '?' E ':' E %prec below_assignment {
               code_t*j2 = $$.c = abc_jump($$.c, 0);
               $$.c = j1->branch = abc_label($$.c);
               $$.c = code_append($$.c, $5.c);
-              $$.c = converttype($$.c, $3.t, $$.t);
+              $$.c = converttype($$.c, $5.t, $$.t);
               $$.c = j2->branch = abc_label($$.c);
             }
 
@@ -3330,7 +3336,6 @@ E : "super" '.' T_IDENTIFIER
               if(!t) t = TYPE_OBJECT;
 
               memberinfo_t*f = registry_findmember(t, $3, 1);
-              namespace_t ns = {f->access, ""};
               MEMBER_MULTINAME(m, f, $3);
               $$.c = 0;
               $$.c = abc_getlocal_0($$.c);