typo on last commit
[mono.git] / mcs / ilasm / parser / ILParser.jay
index acd09867441a43a6d0897cdc3dbddd35d293f7bd..67c9d234af1832d42a69b145f5b1b42b584a2df6 100644 (file)
@@ -24,15 +24,32 @@ namespace Mono.ILASM {
                 private string pinvoke_mod;\r
                 private string pinvoke_meth;\r
                 private PEAPI.PInvokeAttr pinvoke_attr;\r
-                \r
-               public ILParser (CodeGen codegen) {\r
+                private ILTokenizer tokenizer;\r
+                                \r
+               public ILParser (CodeGen codegen, ILTokenizer tokenizer)\r
+                {\r
                        this.codegen = codegen;\r
+                        this.tokenizer = tokenizer;\r
                }\r
 \r
                public CodeGen CodeGen {\r
                        get { return codegen; }\r
                }\r
-               \r
+\r
+                private ITypeRef GetTypeRef (ITypeRef b)\r
+                {\r
+                        ExternTypeRefInst etri = b as ExternTypeRefInst;\r
+                        ExternTypeRef etr;\r
+\r
+                        if (etri != null)\r
+                                return etri.Clone ();\r
+\r
+                        etr = b as ExternTypeRef;\r
+                        if (etr != null)\r
+                                return etr.Clone ();\r
+\r
+                        return b;\r
+                }\r
 %}\r
 \r
 %token EOF\r
@@ -46,6 +63,9 @@ namespace Mono.ILASM {
 /* SQSTRING - single quoted string */\r
 %token SQSTRING\r
 \r
+/* COMP_NAME - A name with dots */\r
+%token COMP_NAME\r
+\r
 /* INT32 - 32 bit integer */\r
 %token INT32\r
 \r
@@ -432,7 +452,8 @@ vtfixup_decl                : D_VTFIXUP OPEN_BRACKET int32 CLOSE_BRACKET
                        ;\r
 \r
 vtfixup_attr           : /* EMPTY */\r
-                       | vtfixup_attr int64\r
+                       | vtfixup_attr K_INT32\r
+                       | vtfixup_attr K_INT64\r
                        | vtfixup_attr K_FROMUNMANAGED\r
                        | vtfixup_attr K_CALLMOSTDERIVED\r
                        ;\r
@@ -493,7 +514,8 @@ class_attr          : /* EMPTY */
                        | class_attr K_NESTED K_FAMANDASSEM     { $$ = (TypeAttr)$1 | TypeAttr.NestedFamAndAssem; }\r
                        | class_attr K_NESTED K_FAMORASSEM      { $$ = (TypeAttr)$1 | TypeAttr.NestedFamOrAssem; }\r
                        | class_attr K_VALUE                    { is_value_class = true; }\r
-                       | class_attr K_ENUM                     { is_enum_class = true; }\r
+                       | class_attr K_ENUM                     { is_enum_class = true; is_value_class = true;\r
+                         }\r
                        | class_attr K_INTERFACE                { $$ = (TypeAttr)$1 | TypeAttr.Interface; }\r
                        | class_attr K_SEALED                   { $$ = (TypeAttr)$1 | TypeAttr.Sealed; }\r
                        | class_attr K_ABSTRACT                 { $$ = (TypeAttr)$1 | TypeAttr.Abstract; }\r
@@ -598,10 +620,17 @@ class_ref         : OPEN_BRACKET slashed_name CLOSE_BRACKET slashed_name
                                 if (codegen.IsThisAssembly ((string) $2)) {\r
                                         $$ = new TypeRef ((string) $4, false, null);\r
                                 } else {\r
-                                        $$ = new ExternTypeRef ((string) $2, (string) $4, false);\r
+                                        $$ = codegen.ExternTable.GetTypeRef ((string) $2, (string) $4, false);\r
                                 }\r
                           }\r
                        | OPEN_BRACKET D_MODULE slashed_name CLOSE_BRACKET slashed_name\r
+                          {\r
+                                if (codegen.IsThisModule ((string) $3)) {\r
+                                        $$ = new TypeRef ((string) $5, false, null);\r
+                                } else {\r
+                                        $$ = codegen.ExternTable.GetModuleTypeRef ((string) $3, (string) $5, false);\r
+                                }\r
+                          }\r
                        | slashed_name\r
                           {\r
                                 PrimitiveTypeRef prim = PrimitiveTypeRef.GetPrimitiveType ((string) $1);\r
@@ -687,53 +716,67 @@ type                      : K_CLASS class_ref
                           }\r
                        | K_VALUETYPE OPEN_BRACKET slashed_name CLOSE_BRACKET slashed_name\r
                           {\r
-                                $$ = new ExternTypeRef ((string) $3, (string) $5, true);\r
+                                ExternTypeRef ext_ref = codegen.ExternTable.GetTypeRef ((string) $3, (string) $5, false);\r
+                                ExternTypeRefInst inst = new ExternTypeRefInst (ext_ref, true);\r
+                                $$ = inst;\r
                           }\r
                         | K_VALUETYPE slashed_name\r
                           {\r
-                                $$ = new TypeRef ((string) $2, true, null);\r
+                                TypeRef t_ref = new TypeRef ((string) $2, true, null);\r
+                                t_ref.MakeValueClass ();\r
+                                $$ = t_ref;\r
                           }\r
                        | type OPEN_BRACKET CLOSE_BRACKET\r
                           {\r
-                                ITypeRef base_type = (ITypeRef) $1;\r
+                                ITypeRef base_type = GetTypeRef ((ITypeRef) $1);\r
                                 base_type.MakeArray ();\r
+                                $$ = base_type;\r
                           }\r
                        | type OPEN_BRACKET bounds CLOSE_BRACKET\r
                           {\r
-                                ITypeRef base_type = (ITypeRef) $1;\r
+                                ITypeRef base_type = GetTypeRef ((ITypeRef) $1);\r
                                 ArrayList bound_list = (ArrayList) $3;\r
                                 base_type.MakeBoundArray (bound_list);\r
+                                $$ = base_type;\r
                           }\r
                        | type AMPERSAND\r
                           {\r
-                                ITypeRef base_type = (ITypeRef) $1;\r
+                                ITypeRef base_type = GetTypeRef ((ITypeRef) $1);\r
                                 base_type.MakeManagedPointer ();\r
+                                $$ = base_type;\r
                           }\r
                        | type STAR\r
                           {\r
-                                ITypeRef base_type = (ITypeRef) $1;\r
+                                ITypeRef base_type = GetTypeRef ((ITypeRef) $1);\r
                                 base_type.MakeUnmanagedPointer ();\r
+                                $$ = base_type;\r
                           }\r
                        | type K_PINNED\r
                           {\r
-                                ITypeRef base_type = (ITypeRef) $1;\r
+                                ITypeRef base_type = GetTypeRef ((ITypeRef) $1);\r
                                 base_type.MakePinned ();\r
+                                $$ = base_type;\r
                           }\r
                        | type K_MODREQ OPEN_PARENS class_ref CLOSE_PARENS\r
                           {\r
-                                ITypeRef base_type = (ITypeRef) $1;\r
+                                ITypeRef base_type = GetTypeRef ((ITypeRef) $1);\r
                                 IClassRef class_ref = (IClassRef) $4;\r
                                 base_type.MakeCustomModified (codegen,\r
-                                        CustomModifier.modopt, class_ref);    \r
+                                        CustomModifier.modopt, class_ref);\r
+                                $$ = base_type;\r
                           }\r
                        | type K_MODOPT OPEN_PARENS class_ref CLOSE_PARENS\r
                           {\r
-                                ITypeRef base_type = (ITypeRef) $1;\r
+                                ITypeRef base_type = GetTypeRef ((ITypeRef) $1);\r
                                 IClassRef class_ref = (IClassRef) $4;\r
                                 base_type.MakeCustomModified (codegen,\r
-                                        CustomModifier.modopt, class_ref);    \r
+                                        CustomModifier.modopt, class_ref);\r
+                                $$ = base_type;\r
                           }\r
                        | K_METHOD call_conv type STAR OPEN_PARENS sig_args CLOSE_PARENS\r
+                          {\r
+                                $$ = new MethodPointerTypeRef ((CallConv) $2, (ITypeRef) $3, (ArrayList) $6);\r
+                          }\r
                        | K_TYPEDREF\r
                           {\r
                                 $$ = new PrimitiveTypeRef (PrimitiveType.TypedRef,\r
@@ -743,6 +786,10 @@ type                       : K_CLASS class_ref
                           {\r
                                 $$ = new PrimitiveTypeRef (PrimitiveType.Char, "System.Char");\r
                           }\r
+                       | K_WCHAR\r
+                         {\r
+                               $$ = new PrimitiveTypeRef (PrimitiveType.Char, "System.Char");\r
+                         }\r
                        | K_VOID\r
                           {\r
                                 $$ = new PrimitiveTypeRef (PrimitiveType.Void, "System.Void");\r
@@ -808,7 +855,8 @@ type                        : K_CLASS class_ref
                           }\r
                         | BANG BANG int32\r
                           {\r
-                                // access method type parameter by number\r
+                                MVar mvar = new MVar ((int) $3);\r
+                                $$ = new GenericTypeRef (mvar, $3.ToString ());\r
                           }\r
                         | K_CLASS slashed_name OPEN_ANGLE_BRACKET BANG int32 CLOSE_ANGLE_BRACKET\r
                           {\r
@@ -837,6 +885,10 @@ bounds                     : bound
                        ;\r
 \r
 bound                  : /* EMPTY */\r
+                          {\r
+                                // This is shortref for no lowerbound or size\r
+                                $$ = new DictionaryEntry (TypeRef.Ellipsis, TypeRef.Ellipsis);\r
+                          }\r
                        | ELLIPSIS\r
                           {\r
                                 // No lower bound or size\r
@@ -1094,11 +1146,11 @@ field_decl              : D_FIELD repeat_opt field_attr type id at_opt init_opt
                                 if ($2 != null) {\r
                                         field_def.SetOffset ((uint) $2);\r
                                 }\r
-                                \r
+\r
                                 if ($6 != null) {\r
                                         field_def.AddDataValue ((string) $6);\r
                                 }\r
-                                \r
+\r
                                 if ($7 != null) {\r
                                         field_def.SetValue ((Constant) $7);\r
                                 }\r
@@ -1202,7 +1254,7 @@ field_init                : K_FLOAT32 OPEN_PARENS float64 CLOSE_PARENS
                           }\r
                        | K_FLOAT64 OPEN_PARENS int64 CLOSE_PARENS\r
                           {\r
-                                $$ = new DoubleConst (Convert.ToDouble (3));\r
+                                $$ = new DoubleConst (Convert.ToDouble ($3));\r
                           }\r
                        | K_INT64 OPEN_PARENS int64 CLOSE_PARENS\r
                           {\r
@@ -1220,6 +1272,10 @@ field_init               : K_FLOAT32 OPEN_PARENS float64 CLOSE_PARENS
                           {\r
                                 $$ = new CharConst (Convert.ToChar ($3));\r
                           }\r
+                       | K_WCHAR OPEN_PARENS int64 CLOSE_PARENS\r
+                         {\r
+                               $$ = new CharConst (Convert.ToChar ($3));\r
+                         }\r
                        | K_INT8 OPEN_PARENS int64 CLOSE_PARENS\r
                           {\r
                                 $$ = new IntConst (Convert.ToByte ($3));\r
@@ -1228,9 +1284,9 @@ field_init                : K_FLOAT32 OPEN_PARENS float64 CLOSE_PARENS
                           {\r
                                 $$ = new BoolConst ((bool) $3);\r
                           }\r
-                       | K_BYTEARRAY OPEN_PARENS bytes CLOSE_PARENS\r
+                       | K_BYTEARRAY bytes_list\r
                           {\r
-                                $$ = new ByteArrConst ((byte[]) $3);\r
+                                $$ = new ByteArrConst ((byte[]) $2);\r
                           }\r
                        | comp_qstring\r
                           {\r
@@ -1297,23 +1353,28 @@ dataitem                : K_CHAR STAR OPEN_PARENS comp_qstring CLOSE_PARENS
                           {\r
                                 $$ = new StringConst ((string) $4);\r
                           }\r
+                       | K_WCHAR STAR OPEN_PARENS comp_qstring CLOSE_PARENS\r
+                         {\r
+                               $$ = new StringConst ((string) $4);\r
+                         }\r
                        | AMPERSAND OPEN_PARENS id CLOSE_PARENS\r
                           {\r
                            //     DataDef def = codegen.CurrentTypeDef.GetDataDef ((string) $3);\r
                            //     $$ = new AddressConstant ((DataConstant) def.PeapiConstant);\r
                           }\r
-                       | K_BYTEARRAY ASSIGN OPEN_PARENS bytes CLOSE_PARENS\r
+                       | K_BYTEARRAY ASSIGN bytes_list\r
                           {\r
-                                $$ = new ByteArrConst ((byte[]) $4);\r
+                                $$ = new ByteArrConst ((byte[]) $3);\r
                           }\r
-                       | K_BYTEARRAY OPEN_PARENS bytes CLOSE_PARENS\r
+                       | K_BYTEARRAY bytes_list\r
                           {\r
                                 // ******** THIS IS NOT IN THE SPECIFICATION ******** //\r
-                                $$ = new ByteArrConst ((byte[]) $3);\r
+                                $$ = new ByteArrConst ((byte[]) $2);\r
                           }\r
                        | K_FLOAT32 OPEN_PARENS float64 CLOSE_PARENS repeat_opt\r
                           {\r
-                                FloatConst float_const = new FloatConst ((float) $3);\r
+                                double d = (double) $3;\r
+                                FloatConst float_const = new FloatConst ((float) d);\r
 \r
                                 if ($5 != null)\r
                                         $$ = new RepeatedConstant (float_const, (int) $5);\r
@@ -1349,7 +1410,8 @@ dataitem          : K_CHAR STAR OPEN_PARENS comp_qstring CLOSE_PARENS
                           }\r
                        | K_INT16 OPEN_PARENS int32 CLOSE_PARENS repeat_opt\r
                           {\r
-                                IntConst int_const = new IntConst ((short) $3);\r
+                                int i = (int) $3;\r
+                                IntConst int_const = new IntConst ((short) i);\r
 \r
                                 if ($5 != null)\r
                                         $$ = new RepeatedConstant (int_const, (int) $5);\r
@@ -1358,7 +1420,8 @@ dataitem          : K_CHAR STAR OPEN_PARENS comp_qstring CLOSE_PARENS
                           }\r
                        | K_INT8 OPEN_PARENS int32 CLOSE_PARENS repeat_opt\r
                           {\r
-                                IntConst int_const = new IntConst ((sbyte) $3);\r
+                                int i = (int) $3;\r
+                                IntConst int_const = new IntConst ((sbyte) i);\r
 \r
                                 if ($5 != null)\r
                                         $$ = new RepeatedConstant (int_const, (int) $5);\r
@@ -1436,7 +1499,8 @@ method_head               : D_METHOD meth_attr call_conv param_attr type method_name
                                 codegen.BeginMethodDef (methdef);\r
 \r
                                 if (pinvoke_info) {\r
-                                        methdef.AddPInvokeInfo (pinvoke_attr, pinvoke_mod, pinvoke_meth);\r
+                                        ExternModule mod = codegen.ExternTable.AddModule (pinvoke_mod);\r
+                                        methdef.AddPInvokeInfo (pinvoke_attr, mod, pinvoke_meth);\r
                                         pinvoke_info = false;\r
                                 }\r
 \r
@@ -1632,6 +1696,9 @@ method_decl               : D_EMITBYTE int32
                                 codegen.CurrentMethodDef.EntryPoint ();\r
                           }\r
                        | D_ZEROINIT\r
+                          {\r
+                                codegen.CurrentMethodDef.ZeroInit ();\r
+                          }\r
                        | D_EXPORT OPEN_BRACKET int32 CLOSE_BRACKET\r
                        | D_EXPORT OPEN_BRACKET int32 CLOSE_BRACKET K_AS id\r
                        | D_VTENTRY int32 COLON int32 \r
@@ -1704,6 +1771,16 @@ type_spec                : class_ref
                                 // assembly. This is not supported in the MS version of ilasm\r
                           }\r
                        | OPEN_BRACKET D_MODULE slashed_name CLOSE_BRACKET\r
+                          {\r
+                                string module = (string) $3;\r
+\r
+                                if (codegen.IsThisModule (module)) {\r
+                                    // This is not handled yet.\r
+                                } else {\r
+                                    $$ = codegen.ExternTable.GetModuleTypeRef ((string) $3, "<Module>", false);\r
+                                }\r
+\r
+                          }\r
                        | type\r
                        ;\r
 \r
@@ -1901,7 +1978,7 @@ instr                     : INSTR_NONE
                                         break;\r
                                 }\r
                           }\r
-                       | INSTR_R OPEN_PARENS bytes CLOSE_PARENS\r
+                       | INSTR_R bytes_list\r
                        | INSTR_BRTARGET int32\r
                           {\r
                                LabelInfo target = codegen.CurrentMethodDef.AddLabel ((int) $2);\r
@@ -1944,8 +2021,18 @@ instr                    : INSTR_NONE
                                 if ((MiscInstr) $1 == MiscInstr.ldstr)\r
                                         codegen.CurrentMethodDef.AddInstr (new LdstrInstr ((string) $2));\r
                           }\r
-                       | INSTR_STRING K_BYTEARRAY ASSIGN OPEN_PARENS bytes CLOSE_PARENS\r
-                       | INSTR_STRING K_BYTEARRAY OPEN_PARENS bytes CLOSE_PARENS               // ****** ADDED\r
+                       | INSTR_STRING K_BYTEARRAY ASSIGN bytes_list\r
+                          {\r
+                                byte[] bs = (byte[]) $4;\r
+                                if ((MiscInstr) $1 == MiscInstr.ldstr)\r
+                                        codegen.CurrentMethodDef.AddInstr (new LdstrInstr (bs));\r
+                          }\r
+                       | INSTR_STRING K_BYTEARRAY bytes_list\r
+                          {\r
+                                byte[] bs = (byte[]) $3;\r
+                                if ((MiscInstr) $1 == MiscInstr.ldstr)\r
+                                        codegen.CurrentMethodDef.AddInstr (new LdstrInstr (bs));\r
+                          }\r
                        | INSTR_SIG call_conv type OPEN_PARENS type_list CLOSE_PARENS\r
                           {\r
                                 ArrayList arg_list = (ArrayList) $5;\r
@@ -1954,7 +2041,7 @@ instr                     : INSTR_NONE
                                 if (arg_list != null)\r
                                         arg_array = (ITypeRef[]) arg_list.ToArray (typeof (ITypeRef));\r
 \r
-                                codegen.CurrentMethodDef.AddInstr (new CalliInstr ((CallConv) $1,\r
+                                codegen.CurrentMethodDef.AddInstr (new CalliInstr ((CallConv) $2,\r
                                         (ITypeRef) $3, arg_array));\r
                           }     \r
                        | INSTR_TOK owner_type\r
@@ -1975,25 +2062,28 @@ instr                   : INSTR_NONE
                           }\r
                        ;\r
 \r
-method_ref             : call_conv type type_spec DOUBLE_COLON method_name \r
-                         OPEN_PARENS type_list CLOSE_PARENS\r
+method_ref             : call_conv type type_spec DOUBLE_COLON method_name\r
+                          OPEN_PARENS type_list CLOSE_PARENS \r
                           {\r
                                 ITypeRef owner = (ITypeRef) $3;\r
                                 ArrayList arg_list = (ArrayList) $7;\r
                                 ITypeRef[] param_list;\r
-  \r
+                                IMethodRef methref;\r
+\r
                                 if (arg_list != null)\r
                                         param_list = (ITypeRef[]) arg_list.ToArray (typeof (ITypeRef));\r
                                 else\r
                                         param_list = new ITypeRef[0];\r
 \r
                                 if (owner.UseTypeSpec) {\r
-                                        $$ = new TypeSpecMethodRef (owner, (ITypeRef) $2,\r
+                                        methref = new TypeSpecMethodRef (owner, (ITypeRef) $2,\r
                                                 (CallConv) $1, (string) $5, param_list);\r
                                 } else {\r
-                                        $$ = owner.GetMethodRef ((ITypeRef) $2,\r
+                                        methref = owner.GetMethodRef ((ITypeRef) $2,\r
                                                 (CallConv) $1, (string) $5, param_list);\r
                                 }\r
+\r
+                                $$ = methref;\r
                           }\r
                        | call_conv type method_name \r
                          OPEN_PARENS type_list CLOSE_PARENS\r
@@ -2009,6 +2099,36 @@ method_ref               : call_conv type type_spec DOUBLE_COLON method_name
                                 $$ = new GlobalMethodRef ((ITypeRef) $2, (CallConv) $1,\r
                                         (string) $3, param_list);\r
                           }\r
+                        | call_conv type type_spec DOUBLE_COLON method_name\r
+                          typars_clause OPEN_PARENS type_list CLOSE_PARENS \r
+                          {\r
+                                ITypeRef owner = (ITypeRef) $3;\r
+                                ArrayList arg_list = (ArrayList) $8;\r
+                                ITypeRef[] param_list;\r
+                                IMethodRef methref;\r
+\r
+                                if (arg_list != null)\r
+                                        param_list = (ITypeRef[]) arg_list.ToArray (typeof (ITypeRef));\r
+                                else\r
+                                        param_list = new ITypeRef[0];\r
+\r
+                                if (owner.UseTypeSpec) {\r
+                                        methref = new TypeSpecMethodRef (owner, (ITypeRef) $2,\r
+                                                (CallConv) $1, (string) $5, param_list);\r
+                                } else {\r
+                                        methref = owner.GetMethodRef ((ITypeRef) $2,\r
+                                                (CallConv) $1, (string) $5, param_list);\r
+                                }\r
+\r
+                                if ($6 != null) {\r
+                                        ArrayList tp = (ArrayList) $6;\r
+                                        ITypeRef[] ta = (ITypeRef[]) tp.ToArray (typeof (ITypeRef));\r
+                                        \r
+                                        methref = new GenericMethodRef (methref, new GenericMethodSig (ta));\r
+                                }\r
+                                \r
+                                $$ = methref;\r
+                          }\r
                        ;\r
 \r
 labels                 : /* EMPTY */\r
@@ -2145,6 +2265,9 @@ prop_attr                 : /* EMPTY */
                           {\r
                                 $$ = (FeatureAttr) $1 | FeatureAttr.Specialname;\r
                           }\r
+                        | prop_attr K_INSTANCE\r
+                          {\r
+                          }\r
                        ;\r
 \r
 prop_decls             : /* EMPTY */\r
@@ -2173,15 +2296,15 @@ customattr_decl         : D_CUSTOM custom_type
                                 $$ = new CustomAttr ((IMethodRef) $2, null);\r
                           }\r
                        | D_CUSTOM custom_type ASSIGN comp_qstring\r
-                       | D_CUSTOM custom_type ASSIGN OPEN_PARENS bytes CLOSE_PARENS\r
+                       | D_CUSTOM custom_type ASSIGN bytes_list\r
                           {\r
                                 $$ = new CustomAttr ((IMethodRef) $2,\r
-                                        (byte[]) $5);\r
+                                        (byte[]) $4);\r
                           }\r
                        | D_CUSTOM OPEN_PARENS owner_type CLOSE_PARENS custom_type\r
                        | D_CUSTOM OPEN_PARENS owner_type CLOSE_PARENS custom_type ASSIGN comp_qstring\r
                        | D_CUSTOM OPEN_PARENS owner_type CLOSE_PARENS custom_type ASSIGN\r
-                         OPEN_PARENS bytes CLOSE_PARENS\r
+                         bytes_list\r
                        ;\r
                        \r
 custom_type            : call_conv type type_spec DOUBLE_COLON D_CTOR OPEN_PARENS type_list CLOSE_PARENS\r
@@ -2215,7 +2338,7 @@ custom_type               : call_conv type type_spec DOUBLE_COLON D_CTOR OPEN_PARENS type_lis
 \r
 sec_decl               : D_PERMISSION sec_action type_spec OPEN_PARENS nameval_pairs CLOSE_PARENS\r
                        | D_PERMISSION sec_action type_spec\r
-                       | D_PERMISSIONSET sec_action ASSIGN OPEN_PARENS bytes CLOSE_PARENS\r
+                       | D_PERMISSIONSET sec_action ASSIGN bytes_list\r
                        ;\r
 \r
 nameval_pairs          : nameval_pair \r
@@ -2253,21 +2376,48 @@ sec_action              : K_REQUEST
                        ;\r
 \r
 module_head            : D_MODULE\r
+                          {\r
+                          }\r
                        | D_MODULE comp_name\r
+                          {\r
+                                codegen.SetModuleName ((string) $2);\r
+                          }\r
                        | D_MODULE K_EXTERN comp_name\r
+                          {\r
+                                codegen.ExternTable.AddModule ((string) $3);                         \r
+                          }\r
                        ;\r
 \r
 file_decl              : D_FILE file_attr comp_name file_entry D_HASH ASSIGN\r
-                         OPEN_PARENS bytes CLOSE_PARENS file_entry\r
+                         bytes_list file_entry\r
+                          {\r
+                                codegen.SetFileRef (new FileRef ((string) $3, (byte []) $7, (bool) $2, (bool) $8)); \r
+                          }\r
                        | D_FILE file_attr comp_name file_entry\r
+                          {\r
+                                // We need to compute the hash ourselves. :-(\r
+                                // AssemblyName an = AssemblyName.GetName ((string) $3);\r
+                          }\r
                        ;\r
 \r
 file_attr              : /* EMPTY */\r
+                          {\r
+                                $$ = true;\r
+                          }\r
                        | file_attr K_NOMETADATA\r
+                          {\r
+                                $$ = false;\r
+                          }\r
                        ;\r
 \r
 file_entry             : /* EMPTY */\r
+                          {\r
+                                $$ = false;\r
+                          }\r
                        | D_ENTRYPOINT\r
+                          {\r
+                                $$ = true;\r
+                          }\r
                        ;\r
 \r
 assembly_all           : assembly_head OPEN_BRACE assembly_decls CLOSE_BRACE\r
@@ -2289,15 +2439,34 @@ assembly_decls          : /* EMPTY */
                        | assembly_decls assembly_decl\r
                        ;\r
 \r
-assembly_decl          : D_HASH K_ALGORITHM int32\r
+assembly_decl          : D_PUBLICKEY ASSIGN bytes_list\r
+                         {\r
+                               codegen.SetAssemblyPublicKey ((byte []) $3);\r
+                         }\r
+                       | D_VER int32 COLON int32 COLON int32 COLON int32\r
+                         {\r
+                               codegen.SetAssemblyVersion ((int) $2, (int) $4, (int) $6, (int) $8);\r
+                         }\r
+                       | D_LOCALE comp_qstring\r
+                         {\r
+                               codegen.SetAssemblyLocale ((string) $2);\r
+                         }\r
+                       | D_LOCALE ASSIGN bytes_list\r
+                       | D_HASH K_ALGORITHM int32\r
+                         {\r
+                               codegen.SetAssemblyHashAlgorithm ((int) $3);\r
+                         }\r
+                       | customattr_decl\r
+                         {\r
+                               codegen.AddAssemblyCustomAttribute ((CustomAttr) $1);\r
+                         }\r
                        | sec_decl\r
-                       | asm_or_ref_decl\r
                        ;\r
 \r
-asm_or_ref_decl                : D_PUBLICKEY ASSIGN OPEN_PARENS bytes CLOSE_PARENS\r
+asm_or_ref_decl                : D_PUBLICKEY ASSIGN bytes_list\r
                        | D_VER int32 COLON int32 COLON int32 COLON int32 \r
                        | D_LOCALE comp_qstring\r
-                       | D_LOCALE ASSIGN OPEN_PARENS bytes CLOSE_PARENS\r
+                       | D_LOCALE ASSIGN bytes_list\r
                        | customattr_decl\r
                        ;\r
 \r
@@ -2309,14 +2478,14 @@ assemblyref_head        : D_ASSEMBLY K_EXTERN slashed_name
                                 System.Reflection.AssemblyName asmb_name = \r
                                        new System.Reflection.AssemblyName ();\r
                                asmb_name.Name = (string) $3;\r
-                               codegen.ExternTable.AddAssembly ((string) $3, asmb_name);\r
+                               codegen.BeginAssemblyRef ((string) $3, asmb_name);\r
                           }\r
                        | D_ASSEMBLY K_EXTERN slashed_name K_AS slashed_name\r
                           {\r
                                 System.Reflection.AssemblyName asmb_name = \r
                                        new System.Reflection.AssemblyName ();\r
                                asmb_name.Name = (string) $3;\r
-                               codegen.ExternTable.AddAssembly ((string) $5, asmb_name);\r
+                               codegen.BeginAssemblyRef ((string) $5, asmb_name);\r
                           }\r
                        ;\r
 \r
@@ -2324,9 +2493,32 @@ assemblyref_decls        : /* EMPTY */
                        | assemblyref_decls assemblyref_decl\r
                        ;\r
 \r
-assemblyref_decl       : D_HASH ASSIGN OPEN_PARENS bytes CLOSE_PARENS\r
-                       | asm_or_ref_decl\r
-                       | D_PUBLICKEYTOKEN ASSIGN OPEN_PARENS bytes CLOSE_PARENS\r
+assemblyref_decl       : D_VER int32 COLON int32 COLON int32 COLON int32\r
+                          {\r
+                                codegen.CurrentAssemblyRef.SetVersion ((int) $2, (int) $4, (int) $6, (int) $8);\r
+                          }\r
+                        | D_PUBLICKEY ASSIGN bytes_list\r
+                          {\r
+                                codegen.CurrentAssemblyRef.SetPublicKey ((byte []) $3);\r
+                          }\r
+                        | D_PUBLICKEYTOKEN ASSIGN bytes_list\r
+                          {\r
+                                codegen.CurrentAssemblyRef.SetPublicKeyToken ((byte []) $3);\r
+                          }\r
+                       | D_LOCALE comp_qstring\r
+                          {\r
+                                codegen.CurrentAssemblyRef.SetLocale ((string) $2);\r
+                          }\r
+                       | D_LOCALE ASSIGN bytes_list\r
+                       \r
+                        | D_HASH ASSIGN bytes_list\r
+                          {\r
+                                codegen.CurrentAssemblyRef.SetHash ((byte []) $3);\r
+                          }\r
+                        | customattr_decl\r
+                          {\r
+                                codegen.CurrentAssemblyRef.AddCustomAttribute ((CustomAttr) $1);\r
+                          }\r
                        ;\r
 \r
 exptype_all            : exptype_head OPEN_BRACE exptype_decls CLOSE_BRACE\r
@@ -2384,7 +2576,7 @@ int32                     : INT64
                           {\r
                                 long l = (long) $1;\r
                                 byte[] intb = BitConverter.GetBytes (l);\r
-                                $$ = BitConverter.ToInt32 (intb, 0);\r
+                                $$ = BitConverter.ToInt32 (intb, BitConverter.IsLittleEndian ? 0 : 4);\r
                           }\r
                        ;\r
 \r
@@ -2396,33 +2588,39 @@ float64                 : FLOAT64
                           {\r
                                 int i = (int) $3;\r
                                 byte[] intb = BitConverter.GetBytes (i);\r
-                                $$ = (double) BitConverter.ToSingle (intb, 0);\r
+                                $$ = (double) BitConverter.ToSingle (intb, BitConverter.IsLittleEndian ? 0 : 4);\r
                           }\r
                         | K_FLOAT32 OPEN_PARENS INT64 CLOSE_PARENS\r
                           {\r
                                 long l = (long) $3;\r
                                 byte[] intb = BitConverter.GetBytes (l);\r
-                                $$ = (double) BitConverter.ToSingle (intb, 0);\r
+                                $$ = (double) BitConverter.ToSingle (intb, BitConverter.IsLittleEndian ? 0 : 4);\r
                           }\r
                        | K_FLOAT64 OPEN_PARENS INT64 CLOSE_PARENS\r
                           {\r
                                 byte[] intb = BitConverter.GetBytes ((long) $3);\r
-                               $$ = BitConverter.ToDouble (intb, 0);\r
+                               $$ = BitConverter.ToDouble (intb, BitConverter.IsLittleEndian ? 0 : 4);\r
                           }\r
                         | K_FLOAT64 OPEN_PARENS INT32 CLOSE_PARENS\r
                           {\r
                                 byte[] intb = BitConverter.GetBytes ((int) $3);\r
-                                $$ = (double) BitConverter.ToSingle (intb, 0);\r
+                                $$ = (double) BitConverter.ToSingle (intb, BitConverter.IsLittleEndian ? 0 : 4);\r
                           }\r
                        ;\r
 \r
-hexbyte                        : HEXBYTE\r
-                        | INT64         { $$ = Convert.ToByte ($1); }\r
-                        | ID\r
+hexbyte                        : HEXBYTE       { }\r
+                       ;\r
+\r
+bytes_list              : OPEN_PARENS\r
                           {\r
-                                $$ = Byte.Parse ((string) $1, NumberStyles.HexNumber);\r
+                                tokenizer.InByteArray = true;\r
                           }\r
-                       ;\r
+                          bytes CLOSE_PARENS\r
+                          {\r
+                                $$ = $3;\r
+                                tokenizer.InByteArray = false;\r
+                          }\r
+                        ;\r
 \r
 bytes                  : /* EMPTY */   { $$ = new byte[0]; }\r
                        | hexbytes\r
@@ -2446,7 +2644,13 @@ hexbytes         : hexbyte
                        ;\r
 \r
 truefalse              : K_TRUE\r
+                          {\r
+                                $$ = true;\r
+                          }\r
                        | K_FALSE\r
+                          {\r
+                                $$ = false;\r
+                          }\r
                        ;\r
 \r
 id                     : ID\r
@@ -2458,6 +2662,7 @@ comp_name         : id
                           {\r
                                 $$ = (string) $1 + '.' + (string) $3;\r
                           }\r
+                        | COMP_NAME\r
                        ;\r
 \r
 %%\r