* ILParser.jay: Add module refs, allow them to be referenced.
[mono.git] / mcs / ilasm / parser / ILParser.jay
index 4e9d7a62cd1e18f5a6c2d8730af5978d58639cf0..886f47990a93a1012a8fbb9d239ca671e07883d8 100644 (file)
@@ -610,6 +610,13 @@ class_ref          : OPEN_BRACKET slashed_name CLOSE_BRACKET slashed_name
                                 }\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
@@ -776,6 +783,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
@@ -871,6 +882,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
@@ -1128,11 +1143,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
@@ -1254,6 +1269,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
@@ -1331,6 +1350,10 @@ 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
@@ -1347,7 +1370,8 @@ dataitem          : K_CHAR STAR OPEN_PARENS comp_qstring CLOSE_PARENS
                           }\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
@@ -1383,7 +1407,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
@@ -1392,7 +1417,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
@@ -1741,6 +1767,9 @@ 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
+\r
+                          }\r
                        | type\r
                        ;\r
 \r
@@ -2336,8 +2365,16 @@ 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
@@ -2428,7 +2465,7 @@ assemblyref_decls : /* EMPTY */
 \r
 assemblyref_decl       : D_VER int32 COLON int32 COLON int32 COLON int32\r
                           {\r
-                                codegen.CurrentAssemblyRef.SetVersion ((int) $2, (int) $3, (int) $4, (int) $5);\r
+                                codegen.CurrentAssemblyRef.SetVersion ((int) $2, (int) $4, (int) $6, (int) $8);\r
                           }\r
                         | D_PUBLICKEY ASSIGN bytes_list\r
                           {\r
@@ -2506,7 +2543,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
@@ -2518,23 +2555,23 @@ 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