X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=mcs%2Filasm%2Fparser%2FILParser.jay;h=63ddee82bfa286db0e183495ef80d6a93e4d5b90;hb=e994a2aed27c781472b06b6b7e25b6b2acf0086e;hp=72a8a25b0f8ba8bf55e78ecbd91a2f5dc09ea7a5;hpb=a2850fc7dae0cf969b5d680a20496ac16526dcb8;p=mono.git diff --git a/mcs/ilasm/parser/ILParser.jay b/mcs/ilasm/parser/ILParser.jay index 72a8a25b0f8..63ddee82bfa 100644 --- a/mcs/ilasm/parser/ILParser.jay +++ b/mcs/ilasm/parser/ILParser.jay @@ -480,6 +480,9 @@ namespace Mono.ILASM { %token K_OFF %token K_FORWARDER %token K_CHARMAPERROR +%token K_LEGACY +%token K_LIBRARY +%token K_AUTO /* end generated */ @@ -591,9 +594,6 @@ class_head : D_CLASS class_attr comp_name formal_typars_clause extends_clause } ; -class_attrs : class_attrs class_attr - ; - class_attr : /* EMPTY */ { // Reset some flags @@ -610,8 +610,7 @@ class_attr : /* EMPTY */ | class_attr K_NESTED K_FAMANDASSEM { $$ = (TypeAttr)$1 | TypeAttr.NestedFamAndAssem; } | class_attr K_NESTED K_FAMORASSEM { $$ = (TypeAttr)$1 | TypeAttr.NestedFamOrAssem; } | class_attr K_VALUE { is_value_class = true; } - | class_attr K_ENUM { is_enum_class = true; is_value_class = true; - } + | class_attr K_ENUM { is_enum_class = true; } | class_attr K_INTERFACE { $$ = (TypeAttr)$1 | TypeAttr.Interface; } | class_attr K_SEALED { $$ = (TypeAttr)$1 | TypeAttr.Sealed; } | class_attr K_ABSTRACT { $$ = (TypeAttr)$1 | TypeAttr.Abstract; } @@ -657,22 +656,14 @@ impl_class_refs : K_IMPLEMENTS generic_class_ref formal_typars_clause : /* EMPTY */ | OPEN_ANGLE_BRACKET formal_typars CLOSE_ANGLE_BRACKET { -#if NET_2_0 || BOOTSTRAP_NET_2_0 $$ = $2; -#else - Report.Error ("Use ilasm2 for generics support."); -#endif } ; typars_clause : /* EMPTY */ | OPEN_ANGLE_BRACKET typars CLOSE_ANGLE_BRACKET { -#if NET_2_0 || BOOTSTRAP_NET_2_0 $$ = $2; -#else - Report.Error ("Use ilasm2 for generics support."); -#endif } ; @@ -697,13 +688,13 @@ constraints_clause : /* EMTPY */ ; -constraints : generic_class_ref +constraints : type { ArrayList al = new ArrayList (); al.Add ($1); $$ = al; } - | constraints COMMA generic_class_ref + | constraints COMMA type { ArrayList al = (ArrayList) $1; al.Add ($3); @@ -715,6 +706,10 @@ generic_class_ref : class_ref { $$ = $1; } + | K_OBJECT + { + $$ = new PrimitiveTypeRef (PrimitiveType.Object, "System.Object"); + } | K_CLASS class_ref typars_clause { if ($3 != null) @@ -929,17 +924,13 @@ class_decl : method_all type : generic_class_ref { - $$ = $1; - } - | K_OBJECT - { - $$ = new PrimitiveTypeRef (PrimitiveType.Object, "System.Object"); + $$ = GetTypeRef ((BaseTypeRef) $1); } | K_VALUE K_CLASS class_ref { - BaseClassRef class_ref = (BaseClassRef) $3; - class_ref.MakeValueClass (); - $$ = class_ref; + BaseClassRef class_ref = (BaseClassRef) $3; + class_ref.MakeValueClass (); + $$ = GetTypeRef (class_ref); } | K_VALUETYPE OPEN_BRACKET slashed_name CLOSE_BRACKET slashed_name typars_clause { @@ -947,7 +938,7 @@ type : generic_class_ref if ($6 != null) $$ = ext_ref.GetGenericTypeInst ((GenericArguments) $6); else - $$ = ext_ref; + $$ = GetTypeRef (ext_ref); } | K_VALUETYPE slashed_name typars_clause { @@ -956,51 +947,51 @@ type : generic_class_ref if ($3 != null) $$ = t_ref.GetGenericTypeInst ((GenericArguments) $3); else - $$ = t_ref; + $$ = GetTypeRef (t_ref); } | type OPEN_BRACKET CLOSE_BRACKET { - BaseTypeRef base_type = GetTypeRef ((BaseTypeRef) $1); + BaseTypeRef base_type = (BaseTypeRef) $1; base_type.MakeArray (); $$ = base_type; } | type OPEN_BRACKET bounds CLOSE_BRACKET { - BaseTypeRef base_type = GetTypeRef ((BaseTypeRef) $1); + BaseTypeRef base_type = (BaseTypeRef) $1; ArrayList bound_list = (ArrayList) $3; base_type.MakeBoundArray (bound_list); $$ = base_type; } | type AMPERSAND { - BaseTypeRef base_type = GetTypeRef ((BaseTypeRef) $1); + BaseTypeRef base_type = (BaseTypeRef) $1; base_type.MakeManagedPointer (); $$ = base_type; } | type STAR { - BaseTypeRef base_type = GetTypeRef ((BaseTypeRef) $1); + BaseTypeRef base_type = (BaseTypeRef) $1; base_type.MakeUnmanagedPointer (); $$ = base_type; } | type K_PINNED { - BaseTypeRef base_type = GetTypeRef ((BaseTypeRef) $1); + BaseTypeRef base_type = (BaseTypeRef) $1; base_type.MakePinned (); $$ = base_type; } - | type K_MODREQ OPEN_PARENS class_ref CLOSE_PARENS + | type K_MODREQ OPEN_PARENS custom_modifier_type CLOSE_PARENS { - BaseTypeRef base_type = GetTypeRef ((BaseTypeRef) $1); - BaseClassRef class_ref = (BaseClassRef) $4; + BaseTypeRef base_type = (BaseTypeRef) $1; + BaseTypeRef class_ref = (BaseTypeRef) $4; base_type.MakeCustomModified (codegen, CustomModifier.modreq, class_ref); $$ = base_type; } - | type K_MODOPT OPEN_PARENS class_ref CLOSE_PARENS + | type K_MODOPT OPEN_PARENS custom_modifier_type CLOSE_PARENS { - BaseTypeRef base_type = GetTypeRef ((BaseTypeRef) $1); - BaseClassRef class_ref = (BaseClassRef) $4; + BaseTypeRef base_type = (BaseTypeRef) $1; + BaseTypeRef class_ref = (BaseTypeRef) $4; base_type.MakeCustomModified (codegen, CustomModifier.modopt, class_ref); $$ = base_type; @@ -1012,8 +1003,6 @@ type : generic_class_ref | primitive_type ; - ; - primitive_type : K_INT8 { $$ = new PrimitiveTypeRef (PrimitiveType.Int8, "System.SByte"); @@ -1493,7 +1482,12 @@ variant_type : /* EMPTY */ | K_CLSID ; -field_decl : D_FIELD repeat_opt field_attr type id at_opt init_opt +custom_modifier_type + : primitive_type + | class_ref + ; + +field_decl : D_FIELD repeat_opt field_attr type id at_opt init_opt semicolon_opt { FieldDef field_def = new FieldDef((FieldAttr) $3, (string) $5, (BaseTypeRef) $4); @@ -1660,11 +1654,14 @@ field_init_primitive : K_FLOAT32 OPEN_PARENS float64 CLOSE_PARENS } ; -field_init : field_init_primitive +field_init_full : field_init_primitive | K_BYTEARRAY bytes_list { $$ = new ByteArrConst ((byte[]) $2); } + ; + +field_init : field_init_full | comp_qstring { // ******** THIS IS NOT IN THE DOCUMENTATION ******** // @@ -1676,6 +1673,30 @@ field_init : field_init_primitive } ; +member_init : field_init_full + | K_STRING OPEN_PARENS SQSTRING CLOSE_PARENS + { + $$ = new StringConst ((string) $3); + } + ; + +opt_truefalse_list + : truefalse_list + ; + +truefalse_list + : truefalse + { + $$ = new List () { new BoolConst ((bool) $1) }; + } + | truefalse_list truefalse + { + var l = (List) $1; + l.Add (new BoolConst ((bool) $2)); + $$ = l; + } + ; + data_decl : data_head data_body { DataDef datadef = (DataDef) $1; @@ -2691,22 +2712,22 @@ event_decls : /* EMPTY */ | event_decls event_decl ; -event_decl : D_ADDON method_ref +event_decl : D_ADDON method_ref semicolon_opt { codegen.CurrentTypeDef.CurrentEvent.AddAddon ( (MethodRef) $2); } - | D_REMOVEON method_ref + | D_REMOVEON method_ref semicolon_opt { codegen.CurrentTypeDef.CurrentEvent.AddRemoveon ( (MethodRef) $2); } - | D_FIRE method_ref + | D_FIRE method_ref semicolon_opt { codegen.CurrentTypeDef.CurrentEvent.AddFire ( (MethodRef) $2); } - | D_OTHER method_ref + | D_OTHER method_ref semicolon_opt { codegen.CurrentTypeDef.CurrentEvent.AddOther ( (MethodRef) $2); @@ -2782,21 +2803,76 @@ prop_decl : D_SET method_ref | language_decl ; -customattr_decl : D_CUSTOM custom_type - { - $$ = new CustomAttr ((BaseMethodRef) $2, null); - } - | D_CUSTOM custom_type ASSIGN comp_qstring - | D_CUSTOM custom_type ASSIGN bytes_list - { - $$ = new CustomAttr ((BaseMethodRef) $2, - (byte[]) $4); - } - | D_CUSTOM OPEN_PARENS owner_type CLOSE_PARENS custom_type - | D_CUSTOM OPEN_PARENS owner_type CLOSE_PARENS custom_type ASSIGN comp_qstring - | D_CUSTOM OPEN_PARENS owner_type CLOSE_PARENS custom_type ASSIGN - bytes_list - ; +customattr_decl + : D_CUSTOM customattr_owner_type_opt custom_type + { + $$ = new CustomAttr ((BaseMethodRef) $3, null); + } + | D_CUSTOM customattr_owner_type_opt custom_type ASSIGN comp_qstring + | D_CUSTOM customattr_owner_type_opt custom_type ASSIGN bytes_list + { + $$ = new CustomAttr ((BaseMethodRef) $3, new ByteArrConst ((byte[]) $5)); + } + | D_CUSTOM customattr_owner_type_opt custom_type ASSIGN OPEN_BRACE customattr_values CLOSE_BRACE + { + $$ = new CustomAttr ((BaseMethodRef) $3, (PEAPI.Constant) $6); + } + ; + +// TODO: unused for now +customattr_owner_type_opt + : /* empty */ + | OPEN_PARENS type CLOSE_PARENS + ; + +customattr_values + : /* empty */ + | K_BOOL OPEN_BRACKET int32 CLOSE_BRACKET OPEN_PARENS opt_truefalse_list CLOSE_PARENS + { + var l = (List) $6; + $$ = new ArrayConstant (l?.ToArray ()) { + ExplicitSize = (int) $3 + }; + } + | K_BYTEARRAY bytes_list + { + $$ = new ByteArrConst ((byte[]) $2); + } + | K_STRING OPEN_PARENS SQSTRING CLOSE_PARENS + { + $$ = new StringConst ((string) $3); + } + | customattr_ctor_args + { + var c = $1 as Constant; + $$ = c ?? new ArrayConstant (((List) $1).ToArray ()); + } + ; + +customattr_ctor_args + : customattr_ctor_arg + | customattr_ctor_args customattr_ctor_arg + { + var l = $1 as List; + if (l == null) { + l = new List () { + (DataConstant) $1 + }; + } + + l.Add ((DataConstant) $2); + $$ = l; + } + ; + +customattr_ctor_arg + : field_init_primitive + | K_TYPE OPEN_PARENS type CLOSE_PARENS + { + $$ = new StringConst (((TypeRef) $3).FullName); + } + ; + custom_type : call_conv type type_spec DOUBLE_COLON method_name OPEN_PARENS type_list CLOSE_PARENS { @@ -2850,11 +2926,7 @@ sec_decl : D_PERMISSION sec_action type_spec OPEN_PARENS nameval_pairs CLOSE_PA } | D_PERMISSIONSET sec_action ASSIGN OPEN_BRACE permissions CLOSE_BRACE { -#if NET_2_0 $$ = new MIPermissionSet ((PEAPI.SecurityAction) $2, (ArrayList) $5); -#else - Report.Error ("Use ilasm2 for 2.0 style declarative security attributes."); -#endif } ; @@ -2904,18 +2976,10 @@ permission_member : prop_or_field primitive_type perm_mbr_nameval_pair } ; -perm_mbr_nameval_pair : SQSTRING ASSIGN field_init_primitive +perm_mbr_nameval_pair : SQSTRING ASSIGN member_init { $$ = new NameValuePair ((string) $1, (PEAPI.Constant) $3); } - | SQSTRING ASSIGN K_BYTEARRAY bytes_list - { - $$ = new NameValuePair ((string) $1, new ByteArrConst ((byte[]) $4)); - } - | SQSTRING ASSIGN K_STRING OPEN_PARENS SQSTRING CLOSE_PARENS - { - $$ = new NameValuePair ((string) $1, new StringConst ((string) $5)); - } ; prop_or_field : K_PROPERTY @@ -3088,9 +3152,9 @@ assembly_all : assembly_head OPEN_BRACE assembly_decls CLOSE_BRACE } ; -assembly_head : D_ASSEMBLY asm_attr slashed_name +assembly_head : D_ASSEMBLY legacylibrary_opt asm_attr slashed_name { - codegen.SetThisAssembly ((string) $3, (PEAPI.AssemAttr) $2); + codegen.SetThisAssembly ((string) $4, (PEAPI.AssemAttr) $3); codegen.CurrentCustomAttrTarget = codegen.ThisAssembly; codegen.CurrentDeclSecurityTarget = codegen.ThisAssembly; } @@ -3150,19 +3214,19 @@ asm_or_ref_decl : D_PUBLICKEY ASSIGN bytes_list assemblyref_all : assemblyref_head OPEN_BRACE assemblyref_decls CLOSE_BRACE ; -assemblyref_head : D_ASSEMBLY K_EXTERN asm_attr slashed_name +assemblyref_head : D_ASSEMBLY K_EXTERN legacylibrary_opt asm_attr slashed_name { System.Reflection.AssemblyName asmb_name = new System.Reflection.AssemblyName (); - asmb_name.Name = (string) $4; - codegen.BeginAssemblyRef ((string) $4, asmb_name, (PEAPI.AssemAttr) $3); + asmb_name.Name = (string) $5; + codegen.BeginAssemblyRef ((string) $5, asmb_name, (PEAPI.AssemAttr) $4); } - | D_ASSEMBLY K_EXTERN asm_attr slashed_name K_AS slashed_name + | D_ASSEMBLY K_EXTERN legacylibrary_opt asm_attr slashed_name K_AS slashed_name { System.Reflection.AssemblyName asmb_name = new System.Reflection.AssemblyName (); - asmb_name.Name = (string) $4; - codegen.BeginAssemblyRef ((string) $6, asmb_name, (PEAPI.AssemAttr) $3); + asmb_name.Name = (string) $5; + codegen.BeginAssemblyRef ((string) $7, asmb_name, (PEAPI.AssemAttr) $4); } ; @@ -3197,6 +3261,7 @@ assemblyref_decl : D_VER int32 COLON int32 COLON int32 COLON int32 if (codegen.CurrentCustomAttrTarget != null) codegen.CurrentCustomAttrTarget.AddCustomAttribute ((CustomAttr) $1); } + | K_AUTO /* MS ilasm uses this keyword to lookup the specified assembly in the GAC and embeds its attributes, we just ignore it */ ; exptype_all : exptype_head OPEN_BRACE exptype_decls CLOSE_BRACE @@ -3208,7 +3273,7 @@ exptype_head : D_CLASS K_EXTERN expt_attr comp_name } ; -expt_attr : /* EMPTY */ +expt_attr : { $$ = 0; } /* EMPTY */ | expt_attr K_PRIVATE { $$ = (TypeAttr)$1 | TypeAttr.Private; } | expt_attr K_PUBLIC { $$ = (TypeAttr)$1 | TypeAttr.Public; } | expt_attr K_NESTED K_PUBLIC { $$ = (TypeAttr)$1 | TypeAttr.NestedPublic; } @@ -3358,6 +3423,15 @@ comp_name : id | COMP_NAME ; +semicolon_opt + : /* empty */ + | SEMICOLON + ; + +legacylibrary_opt : /* empty */ + | K_LEGACY K_LIBRARY /* MS ilasm has these keywords for backwards compatibility, we just ignore them */ + ; + %% }