New tests.
[mono.git] / mcs / ilasm / parser / ILParser.jay
index 5fbdb1edf0de03fafb8c1d580227b33df97140b8..b94d64121b1a36638fffc5c6fdd68b3f5c57b352 100644 (file)
@@ -312,6 +312,7 @@ namespace Mono.ILASM {
 %token K_FAMILY\r
 %token K_INITONLY\r
 %token K_RTSPECIALNAME\r
+%token K_STRICT\r
 %token K_SPECIALNAME\r
 %token K_ASSEMBLY\r
 %token K_FAMANDASSEM\r
@@ -768,6 +769,14 @@ formal_typar_attr  : /* EMPTY */
                           {\r
                                 $$ = new PEAPI.GenericParamAttributes ();\r
                           }\r
+                       | formal_typar_attr PLUS\r
+                          {\r
+                               $$ = (PEAPI.GenericParamAttributes) $1 | PEAPI.GenericParamAttributes.Covariant; \r
+                          }\r
+                       | formal_typar_attr DASH\r
+                          {\r
+                               $$ = (PEAPI.GenericParamAttributes) $1 | PEAPI.GenericParamAttributes.Contravariant; \r
+                          }\r
                        | formal_typar_attr D_CTOR\r
                           {\r
                                $$ = (PEAPI.GenericParamAttributes) $1 | PEAPI.GenericParamAttributes.DefaultConstructorConstrait; \r
@@ -907,8 +916,8 @@ class_decl          : method_all
                                         (CallConv) $6, (string) $4, param_list, 0);\r
 \r
                                // NOTICE: `owner' here might be wrong\r
-                                string sig = MethodDef.CreateSignature (owner, (string) $10,\r
-                                                                        param_list, 0);\r
+                                string sig = MethodDef.CreateSignature (owner, (CallConv) $6, (string) $10,\r
+                                                                        param_list, 0, false);\r
                                 codegen.CurrentTypeDef.AddOverride (sig, decl);                                        \r
                           }\r
                          OPEN_PARENS sig_args CLOSE_PARENS\r
@@ -1911,6 +1920,7 @@ meth_attr         : /* EMPTY */                   { $$ = new MethAttr (); }
                        | meth_attr K_REQSECOBJ         { $$ = (MethAttr) $1 | MethAttr.RequireSecObject; }\r
                        | meth_attr K_SPECIALNAME       { $$ = (MethAttr) $1 | MethAttr.SpecialName; }\r
                        | meth_attr K_RTSPECIALNAME     { $$ = (MethAttr) $1 | MethAttr.RTSpecialName; }\r
+                       | meth_attr K_STRICT            { $$ = (MethAttr) $1 | MethAttr.Strict; }\r
                         | meth_attr K_COMPILERCONTROLLED { /* Do nothing */ }\r
                        | meth_attr K_UNMANAGEDEXP      \r
                        | meth_attr K_PINVOKEIMPL OPEN_PARENS comp_qstring K_AS\r
@@ -2067,6 +2077,11 @@ method_decls             : /* EMPTY */
                        ;\r
 \r
 method_decl            : D_EMITBYTE int32\r
+                                               {\r
+                                                       codegen.CurrentMethodDef.AddInstr (new\r
+                                        EmitByteInstr ((int) $2, tokenizer.Location));\r
+                          \r
+                                               }\r
                        | D_MAXSTACK int32\r
                           {\r
                                 codegen.CurrentMethodDef.SetMaxStack ((int) $2);\r
@@ -2230,12 +2245,14 @@ scope_block             : scope_block_begin method_decls CLOSE_BRACE
                           {\r
                                 $$ = new HandlerBlock ((LabelInfo) $1,\r
                                         codegen.CurrentMethodDef.AddLabel ());\r
+                                codegen.CurrentMethodDef.EndLocalsScope ();\r
                           }\r
                        ;\r
 \r
 scope_block_begin       : OPEN_BRACE\r
                           {\r
                                 $$ = codegen.CurrentMethodDef.AddLabel ();\r
+                                codegen.CurrentMethodDef.BeginLocalsScope ();\r
                           }\r
                         ;\r
                         \r
@@ -2285,12 +2302,12 @@ seh_clauses             : seh_clause
                           }\r
                        ;\r
 \r
-seh_clause             : K_CATCH class_ref handler_block\r
+seh_clause             : K_CATCH type handler_block\r
                           {\r
                                if ($2.GetType () == typeof (PrimitiveTypeRef))\r
                                        Report.Error ("Exception not be of a primitive type.");\r
                                        \r
-                                BaseClassRef type = (BaseClassRef) $2;\r
+                                BaseTypeRef type = (BaseTypeRef) $2;\r
                                 CatchBlock cb = new CatchBlock (type);\r
                                 cb.SetHandlerBlock ((HandlerBlock) $3);\r
                                 $$ = cb;\r
@@ -2347,8 +2364,8 @@ handler_block             : scope_block
                           }\r
                        | K_HANDLER int32 K_TO int32\r
                          {\r
-                               LabelInfo from = codegen.CurrentMethodDef.AddLabelRef ((string) $2);\r
-                               LabelInfo to = codegen.CurrentMethodDef.AddLabelRef ((string) $4);\r
+                               LabelInfo from = codegen.CurrentMethodDef.AddLabel ((int) $2);\r
+                               LabelInfo to = codegen.CurrentMethodDef.AddLabel ((int) $4);\r
 \r
                                $$ = new HandlerBlock (from, to);\r
                          }\r
@@ -2367,6 +2384,8 @@ instr                     : INSTR_NONE
                         | INSTR_LOCAL id\r
                           {\r
                                 int slot = codegen.CurrentMethodDef.GetNamedLocalSlot ((string) $2);\r
+                                if (slot < 0)\r
+                                        Report.Error (String.Format ("Undeclared identifier '{0}'", (string) $2));\r
                                 codegen.CurrentMethodDef.AddInstr (\r
                                         new IntInstr ((IntOp) $1, slot, tokenizer.Location));\r
                           }\r
@@ -2392,6 +2411,8 @@ instr                     : INSTR_NONE
                        | INSTR_I id\r
                           {\r
                                 int slot = codegen.CurrentMethodDef.GetNamedLocalSlot ((string) $2);\r
+                                if (slot < 0)\r
+                                        Report.Error (String.Format ("Undeclared identifier '{0}'", (string) $2));\r
                                 codegen.CurrentMethodDef.AddInstr (new\r
                                         IntInstr ((IntOp) $1, slot, tokenizer.Location));\r
                           }\r
@@ -2428,13 +2449,23 @@ instr                   : INSTR_NONE
                           }\r
                        | INSTR_R bytes_list\r
                           {\r
+                               byte[] fpdata;\r
                                 switch ((MiscInstr) $1) {\r
                                         case MiscInstr.ldc_r4:\r
-                                                float s = BitConverter.ToSingle ((byte []) $2, 0);\r
+                                               fpdata = (byte []) $2;\r
+                                               if (!BitConverter.IsLittleEndian) {\r
+                                                       System.Array.Reverse (fpdata, 0, 4);\r
+                                               }\r
+                                                float s = BitConverter.ToSingle (fpdata, 0);\r
                                                 codegen.CurrentMethodDef.AddInstr (new LdcInstr ((MiscInstr) $1, s, tokenizer.Location));\r
                                                 break;\r
                                         case MiscInstr.ldc_r8:\r
-                                                double d = BitConverter.ToDouble ((byte []) $2, 0);\r
+                                               fpdata = (byte []) $2;\r
+                                               if (!BitConverter.IsLittleEndian) {\r
+                                                       // FIXME: handle the stupid ARM FPA format\r
+                                                       System.Array.Reverse (fpdata, 0, 8);\r
+                                               }\r
+                                                double d = BitConverter.ToDouble (fpdata, 0);\r
                                                 codegen.CurrentMethodDef.AddInstr (new LdcInstr ((MiscInstr) $1, d, tokenizer.Location));\r
                                                 break;\r
                                 }\r
@@ -2584,7 +2615,7 @@ labels                    : /* EMPTY */
                        | id\r
                           {\r
                                 ArrayList label_list = new ArrayList ();\r
-                                label_list.Add ($1);\r
+                                label_list.Add (codegen.CurrentMethodDef.AddLabelRef ((string) $1));\r
                                 $$ = label_list;\r
                           }\r
                        | int32\r
@@ -2596,7 +2627,7 @@ labels                    : /* EMPTY */
                        | labels COMMA id\r
                           {\r
                                 ArrayList label_list = (ArrayList) $1;\r
-                                label_list.Add ($3);\r
+                                label_list.Add (codegen.CurrentMethodDef.AddLabelRef ((string) $3));\r
                           }\r
                        | labels COMMA int32\r
                           {\r
@@ -2767,7 +2798,7 @@ customattr_decl           : D_CUSTOM custom_type
                          bytes_list\r
                        ;\r
                        \r
-custom_type            : call_conv type type_spec DOUBLE_COLON D_CTOR OPEN_PARENS type_list CLOSE_PARENS\r
+custom_type            : call_conv type type_spec DOUBLE_COLON method_name OPEN_PARENS type_list CLOSE_PARENS\r
                           {\r
                                 BaseTypeRef owner = (BaseTypeRef) $3;\r
                                 ArrayList arg_list = (ArrayList) $7;\r
@@ -2781,7 +2812,7 @@ custom_type               : call_conv type type_spec DOUBLE_COLON D_CTOR OPEN_PARENS type_lis
                                 $$ = owner.GetMethodRef ((BaseTypeRef) $2,\r
                                         (CallConv) $1, (string) $5, param_list, 0);\r
                           }\r
-                       | call_conv type D_CTOR OPEN_PARENS type_list CLOSE_PARENS\r
+                       | call_conv type method_name OPEN_PARENS type_list CLOSE_PARENS\r
                           {\r
                                 ArrayList arg_list = (ArrayList) $5;\r
                                 BaseTypeRef[] param_list;\r
@@ -3243,7 +3274,7 @@ float64                   : FLOAT64
                           {\r
                                 int i = (int) $3;\r
                                 byte[] intb = BitConverter.GetBytes (i);\r
-                                $$ = (double) BitConverter.ToSingle (intb, BitConverter.IsLittleEndian ? 0 : 4);\r
+                                $$ = (double) BitConverter.ToSingle (intb, 0);\r
                           }\r
                         | K_FLOAT32 OPEN_PARENS INT64 CLOSE_PARENS\r
                           {\r
@@ -3254,12 +3285,12 @@ float64                 : FLOAT64
                        | K_FLOAT64 OPEN_PARENS INT64 CLOSE_PARENS\r
                           {\r
                                 byte[] intb = BitConverter.GetBytes ((long) $3);\r
-                               $$ = BitConverter.ToDouble (intb, BitConverter.IsLittleEndian ? 0 : 4);\r
+                               $$ = BitConverter.ToDouble (intb, 0);\r
                           }\r
                         | K_FLOAT64 OPEN_PARENS INT32 CLOSE_PARENS\r
                           {\r
                                 byte[] intb = BitConverter.GetBytes ((int) $3);\r
-                                $$ = (double) BitConverter.ToSingle (intb, BitConverter.IsLittleEndian ? 0 : 4);\r
+                                $$ = (double) BitConverter.ToSingle (intb, 0);\r
                           }\r
                        ;\r
 \r