X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=mcs%2Filasm%2Fparser%2FILParser.jay;h=1c4c9c40deca3fc71985ef52110d8cdcd1a4bd1b;hb=ba2604940e0dcfe116c44eea72932326aabaa8ff;hp=e9defe18329285b4d683be56a7be04b46cb4f278;hpb=cb6e97b97a0ef0d3230c4254d0ebd9779919f0d0;p=mono.git diff --git a/mcs/ilasm/parser/ILParser.jay b/mcs/ilasm/parser/ILParser.jay index e9defe18329..1c4c9c40dec 100644 --- a/mcs/ilasm/parser/ILParser.jay +++ b/mcs/ilasm/parser/ILParser.jay @@ -6,6 +6,7 @@ using PEAPI; using System; using System.Collections; +using System.Globalization; namespace Mono.ILASM { @@ -43,6 +44,8 @@ namespace Mono.ILASM { /* FLOAT64 - floating point number */ %token FLOAT64 +/* HEXBYTE - two digit hex number */ +%token HEXBYTE /* Punctuation */ @@ -65,7 +68,8 @@ namespace Mono.ILASM { %token BANG "!" %token ELLIPSIS "..." %token DASH "-" - +%token OPEN_ANGLE_BRACKET "<" +%token CLOSE_ANGLE_BRACKET ">" @@ -95,7 +99,6 @@ namespace Mono.ILASM { - /* Mechanically generated - DO NOT EDIT! */ @@ -355,1246 +358,1619 @@ namespace Mono.ILASM { %% il_file : decls - ; - -decls : /* EMPTY */ - | decls decl - ; - -decl : classAll - | nameSpaceHead OPEN_BRACE decls CLOSE_BRACE { codegen.CurrentNameSpace = String.Empty; } - | methodAll - | fieldDecl - | dataDecl - | vtableDecl - | vtfixupDecl - | extSourceSpec - | fileDecl - | assemblyHead OPEN_BRACE assemblyDecls CLOSE_BRACE - | assemblyRefHead OPEN_BRACE assemblyRefDecls CLOSE_BRACE - | comtypeHead OPEN_BRACE comtypeDecls CLOSE_BRACE - | manifestResHead OPEN_BRACE manifestResDecls CLOSE_BRACE - | moduleHead - | secDecl - | customAttrDecl - | D_SUBSYSTEM int32 - | D_CORFLAGS int32 - | D_FILE K_ALIGNMENT int32 - | languageDecl - ; - -compQstring : QSTRING - | compQstring PLUS QSTRING {$$ = ($1 as string) + ($3 as string);} - ; - -languageDecl : D_LANGUAGE SQSTRING - | D_LANGUAGE SQSTRING COMMA SQSTRING - | D_LANGUAGE SQSTRING COMMA SQSTRING COMMA SQSTRING - ; - -customAttrDecl : D_CUSTOM customType - | D_CUSTOM customType ASSIGN compQstring - | customHead bytes CLOSE_PARENS - | D_CUSTOM OPEN_PARENS customType CLOSE_PARENS customType - | D_CUSTOM OPEN_PARENS customType CLOSE_PARENS customType ASSIGN compQstring - | customHeadWithOwner bytes CLOSE_PARENS - ; - -moduleHead : D_MODULE - | D_MODULE name1 - | D_MODULE K_EXTERN name1 - ; - -vtfixupDecl : D_VTFIXUP OPEN_BRACKET int32 CLOSE_BRACKET vtfixupAttr K_AT id - ; - -vtfixupAttr : /* EMPTY */ - | vtfixupAttr K_INT32 - | vtfixupAttr K_INT64 - | vtfixupAttr K_FROMUNMANAGED - | vtfixupAttr K_CALLMOSTDERIVED - ; - -vtableDecl : vtableHead bytes CLOSE_PARENS - ; - -vtableHead : D_VTABLE ASSIGN OPEN_PARENS - ; - -nameSpaceHead : D_NAMESPACE name1 - { - codegen.CurrentNameSpace = (string) $2; - } - ; - -classHead : D_CLASS type_attr id extendsClause implClause - { - if ($4 != null) { - codegen.AddClass ((TypeAttr) $2, (string) $3, - ((TypeRef)$4).Type as Class, null); - } else { - codegen.AddClass ((TypeAttr)$2, (string) $3, null); - } - - ArrayList impl_list = (ArrayList) $5; - if (impl_list != null) { - foreach (TypeRef type_ref in impl_list) - codegen.CurrentClass.AddImplementedInterface (type_ref.Type as Class); - } - } - ; - -type_attr : /* EMPTY */ { $$ = new TypeAttr (); } - | type_attr K_PUBLIC { $$ = (TypeAttr)$1 | TypeAttr.Public; } - | type_attr K_PRIVATE { $$ = (TypeAttr)$1 | TypeAttr.Private; } - | type_attr K_INTERFACE { $$ = (TypeAttr)$1 | TypeAttr.Interface; } - | type_attr K_SEALED { $$ = (TypeAttr)$1 | TypeAttr.Sealed; } - | type_attr K_ABSTRACT { $$ = (TypeAttr)$1 | TypeAttr.Abstract; } - | type_attr K_AUTO { /* */ } - | type_attr K_SEQUENTIAL { $$ = (TypeAttr)$1 | TypeAttr.SequentialLayout; } - | type_attr K_EXPLICIT { $$ = (TypeAttr)$1 | TypeAttr.ExplicitLayout; } - | type_attr K_ANSI { /* */ } - | type_attr K_UNICODE { $$ = (TypeAttr)$1 | TypeAttr.UnicodeClass; } - | type_attr K_AUTOCHAR { $$ = (TypeAttr)$1 | TypeAttr.AutoClass; } - | type_attr K_IMPORT { $$ = (TypeAttr)$1 | TypeAttr.Import; } - | type_attr K_SERIALIZABLE { $$ = (TypeAttr)$1 | TypeAttr.Serializable; } - | type_attr K_NESTED K_PUBLIC { $$ = (TypeAttr)$1 | TypeAttr.NestedPublic; } - | type_attr K_NESTED K_PRIVATE { $$ = (TypeAttr)$1 | TypeAttr.NestedPrivate; } - | type_attr K_NESTED K_FAMILY { $$ = (TypeAttr)$1 | TypeAttr.NestedFamily; } - | type_attr K_NESTED K_ASSEMBLY { $$ = (TypeAttr)$1 | TypeAttr.NestedAssembly; } - | type_attr K_NESTED K_FAMANDASSEM { $$ = (TypeAttr)$1 | TypeAttr.NestedFamAndAssem; } - | type_attr K_NESTED K_FAMORASSEM { $$ = (TypeAttr)$1 | TypeAttr.NestedFamOrAssem; } - | type_attr K_BEFOREFIELDINIT { $$ = (TypeAttr)$1 | TypeAttr.BeforeFieldInit; } - | type_attr K_SPECIALNAME { $$ = (TypeAttr)$1 | TypeAttr.SpecialName; } - | type_attr K_RTSPECIALNAME { $$ = (TypeAttr)$1 | TypeAttr.RTSpecialName; } - ; - -classAttr : /* EMPTY */ - | classAttr K_PUBLIC { /* currentTypeAttrs |= TypeAttributes.Public; */} - | classAttr K_PRIVATE { /* currentTypeAttrs &= ~TypeAttributes.Public; */} - | classAttr K_VALUE { /* FIXME */ } - | classAttr K_ENUM { /* FIXME */ } - | classAttr K_INTERFACE { /* currentTypeAttrs |= TypeAttributes.Interface; */ } - | classAttr K_SEALED { /* currentTypeAttrs |= TypeAttributes.Sealed; */ } - | classAttr K_ABSTRACT { /* currentTypeAttrs |= TypeAttributes.Abstract; */ } - | classAttr K_AUTO { /* currentTypeAttrs |= TypeAttributes.AutoLayout; */ } - | classAttr K_SEQUENTIAL { /* currentTypeAttrs |= TypeAttributes.SequentialLayout; */ } - | classAttr K_EXPLICIT { /* currentTypeAttrs |= TypeAttributes.ExplicitLayout; */ } - | classAttr K_ANSI { /* currentTypeAttrs |= TypeAttributes.AnsiClass; */ } - | classAttr K_UNICODE { /* currentTypeAttrs |= TypeAttributes.UnicodeClass; */ } - | classAttr K_AUTOCHAR { /* currentTypeAttrs |= TypeAttributes.AutoClass; */ } - | classAttr K_IMPORT { /* currentTypeAttrs |= TypeAttributes.Import; */ } - | classAttr K_SERIALIZABLE { /* currentTypeAttrs |= TypeAttributes.Serializable; */ } - | classAttr K_NESTED K_PUBLIC { /* currentTypeAttrs |= TypeAttributes.NestedPublic; */ } - | classAttr K_NESTED K_PRIVATE { /* currentTypeAttrs |= TypeAttributes.NestedPrivate; */ } - | classAttr K_NESTED K_FAMILY { /* currentTypeAttrs |= TypeAttributes.NestedFamily; */ } - | classAttr K_NESTED K_ASSEMBLY { /* currentTypeAttrs |= TypeAttributes.NestedAssembly; */ } - | classAttr K_NESTED K_FAMANDASSEM { /* currentTypeAttrs |= TypeAttributes.NestedFamANDAssem; */ } - | classAttr K_NESTED K_FAMORASSEM { /* currentTypeAttrs |= TypeAttributes.NestedFamORAssem; */ } - | classAttr K_BEFOREFIELDINIT { /* currentTypeAttrs |= TypeAttributes.BeforeFieldInit; */ } - | classAttr K_SPECIALNAME { /* currentTypeAttrs |= TypeAttributes.SpecialName; */ } - | classAttr K_RTSPECIALNAME { /* currentTypeAttrs |= TypeAttributes.RTSpecialName; */ } - ; - -extendsClause : /* EMPTY */ - | K_EXTENDS class_ref {$$ = $2;} - ; - -implClause : /* EMPTY */ - | K_IMPLEMENTS classNames {$$ = $2; } - ; - -classNames : classNames COMMA class_ref - { - ArrayList class_list = (ArrayList) $1; - class_list.Add ($3); - } - | class_ref - { - ArrayList class_list = new ArrayList (); - class_list.Add ($1); - $$ = class_list; - } - ; - -classDecls : /* EMPTY */ - | classDecls classDecl - ; - - -classAll : classHead OPEN_BRACE classDecls CLOSE_BRACE - { - /* - codegen.AddClass (currentClass); - currentClass = null; - */ - } - ; - - -classDecl : methodAll - | classAll - | eventHead OPEN_BRACE eventDecls CLOSE_BRACE - | propHead OPEN_BRACE propDecls CLOSE_BRACE - | fieldDecl - | dataDecl - | secDecl - | extSourceSpec - | customAttrDecl - | D_SIZE int32 - | D_PACK int32 - | exportHead OPEN_BRACE comtypeDecls CLOSE_BRACE - | D_OVERRIDE typeSpec DOUBLE_COLON methodName K_WITH callConv type typeSpec DOUBLE_COLON methodName OPEN_PARENS sigArgs0 CLOSE_PARENS - | languageDecl - ; - -fieldDecl : D_FIELD repeatOpt fieldAttr type_ref id atOpt initOpt - { - codegen.AddField ((FieldAttr) $3, - (string) $5, (TypeRef) $4, null); - } - ; - -type_ref : primative_type_ref - | internal_type_ref - | external_type_ref - ; - -class_ref : internal_type_ref - | external_type_ref - ; - -primative_type_ref : K_CHAR - {$$ = new TypeRef (PrimitiveType.Char, "System.Char"); } - | K_VOID - {$$ = new TypeRef (PrimitiveType.Void, "System.Void"); } - | K_BOOL - {$$ = new TypeRef (PrimitiveType.Boolean, "System.Bool"); } - | K_INT8 - {$$ = new TypeRef (PrimitiveType.Int8, "System.Int8"); } - | K_INT16 - {$$ = new TypeRef (PrimitiveType.Int16, "System.Int16"); } - | K_INT32 - {$$ = new TypeRef (PrimitiveType.Int32, "System.Int32"); } - | K_INT64 - {$$ = new TypeRef (PrimitiveType.Int64, "System.Int64"); } - | K_FLOAT32 - {$$ = new TypeRef (PrimitiveType.Float32, "System.Float32"); } - | K_FLOAT64 - {$$ = new TypeRef (PrimitiveType.Float64, "System.Float64"); } - | K_UNSIGNED K_INT8 - {$$ = new TypeRef (PrimitiveType.UInt8, "System.UInt8"); } - | K_UNSIGNED K_INT16 - {$$ = new TypeRef (PrimitiveType.UInt16, "System.UInt16"); } - | K_UNSIGNED K_INT32 - {$$ = new TypeRef (PrimitiveType.UInt32, "System.UInt32"); } - | K_UNSIGNED K_INT64 - {$$ = new TypeRef (PrimitiveType.UInt64, "System.UInt64"); } - | K_STRING - {$$ = new TypeRef (PrimitiveType.String, "System.String"); } - ; - -internal_type_ref : name1 - { - $$ = new TypeRef (codegen.ClassTable.GetReference ((string) $1, null), - (string) $1); - } - ; - -external_type_ref : assembly_name namespace_name DOT id - { - $$ = new TypeRef (codegen.ExternTable.GetClass ($1 as string, - $2 as string, $4 as string), String.Format ("{0}.{1}", $2, $4)); - } - ; - -namespace_name : /* EMPTY */ - | id - | namespace_name DOT id {$$ = String.Format ("{0}.{1}", $1, $3); } - ; - -atOpt : /* EMPTY */ - | K_AT id - ; - -initOpt : /* EMPTY */ - | ASSIGN fieldInit - ; - -repeatOpt : /* EMPTY */ - | OPEN_BRACKET int32 CLOSE_BRACKET - ; - -customHead : D_CUSTOM customType ASSIGN OPEN_PARENS - ; - -customHeadWithOwner : D_CUSTOM OPEN_PARENS customType CLOSE_PARENS customType ASSIGN OPEN_PARENS ; -customType : typeSpec - | callConv type typeSpec DOUBLE_COLON methodName OPEN_PARENS sigArgs0 CLOSE_PARENS - | callConv type methodName OPEN_PARENS sigArgs0 CLOSE_PARENS - ; - -eventHead : D_EVENT eventAttr typeSpec id - | D_EVENT eventAttr id - ; - - -eventAttr : /* EMPTY */ - | eventAttr K_RTSPECIALNAME /**/ - | eventAttr K_SPECIALNAME - ; - -eventDecls : /* EMPTY */ - | eventDecls eventDecl - ; - -eventDecl : D_ADDON callConv type typeSpec DOUBLE_COLON methodName OPEN_PARENS sigArgs0 CLOSE_PARENS - | D_ADDON callConv type methodName OPEN_PARENS sigArgs0 CLOSE_PARENS - | D_REMOVEON callConv type typeSpec DOUBLE_COLON methodName OPEN_PARENS sigArgs0 CLOSE_PARENS - | D_REMOVEON callConv type methodName OPEN_PARENS sigArgs0 CLOSE_PARENS - | D_FIRE callConv type typeSpec DOUBLE_COLON methodName OPEN_PARENS sigArgs0 CLOSE_PARENS - | D_FIRE callConv type methodName OPEN_PARENS sigArgs0 CLOSE_PARENS - | D_OTHER callConv type typeSpec DOUBLE_COLON methodName OPEN_PARENS sigArgs0 CLOSE_PARENS - | D_OTHER callConv type methodName OPEN_PARENS sigArgs0 CLOSE_PARENS - | extSourceSpec - | customAttrDecl - | languageDecl - ; - -propHead : D_PROPERTY propAttr callConv type id OPEN_PARENS sigArgs0 CLOSE_PARENS initOpt - ; - -propAttr : /* EMPTY */ - | propAttr K_RTSPECIALNAME /**/ - | propAttr K_SPECIALNAME - ; - -propDecls : /* EMPTY */ - | propDecls propDecl - ; - - -propDecl : D_SET callConv type typeSpec DOUBLE_COLON methodName OPEN_PARENS sigArgs0 CLOSE_PARENS - | D_SET callConv type methodName OPEN_PARENS sigArgs0 CLOSE_PARENS - | D_GET callConv type typeSpec DOUBLE_COLON methodName OPEN_PARENS sigArgs0 CLOSE_PARENS - | D_GET callConv type methodName OPEN_PARENS sigArgs0 CLOSE_PARENS - | D_OTHER callConv type typeSpec DOUBLE_COLON methodName OPEN_PARENS sigArgs0 CLOSE_PARENS - | D_OTHER callConv type methodName OPEN_PARENS sigArgs0 CLOSE_PARENS - | customAttrDecl - | extSourceSpec - | languageDecl - ; - -field_ref : internal_field_ref - | external_field_ref - ; - -internal_field_ref : type_ref internal_type_ref DOUBLE_COLON id - { - $$ = codegen.GetFieldRef ((TypeRef) $1, (TypeRef) $2, (string) $4, null); - } - ; - -external_field_ref : type_ref external_type_ref DOUBLE_COLON id - { - ClassRef parent = ((TypeRef) $2).Type as ClassRef; - TypeRef type = (TypeRef) $1; - - $$ = parent.AddField ((string) $4, type.Type); - } - ; - -method_ref : internal_method_ref - | external_method_ref - ; - -external_method_ref : type_ref external_type_ref DOUBLE_COLON name1 OPEN_PARENS arg_list CLOSE_PARENS - { - TypeRef ret_type = (TypeRef)$1; - ClassRef parent = (ClassRef) ((TypeRef) $2).Type; - PEAPI.Type[] type_array; - if ($6 != null) { - ArrayList param_list = $6 as ArrayList; - int index = 0; - type_array = new PEAPI.Type[param_list.Count]; - foreach (DictionaryEntry entry in param_list) { - type_array[index] = ((TypeRef)entry.Value).Type; - index++; - } - } else { - type_array = new PEAPI.Type[0]; - } - $$ = parent.AddMethod ((string) $4, ret_type.Type, type_array); - } - ; - -internal_method_ref : type_ref internal_type_ref DOUBLE_COLON name1 OPEN_PARENS arg_list CLOSE_PARENS - { - TypeRef parent, return_type; - parent = (TypeRef) $2; - return_type = (TypeRef) $1; - - Param[] param_array; - TypeRef[] typeref_array; - if ($6 != null) { - ArrayList param_list = $6 as ArrayList; - int index = 0; - param_array = new Param[param_list.Count]; - typeref_array = new TypeRef[param_list.Count]; - foreach (DictionaryEntry entry in param_list) { - param_array[index] = entry.Key as Param; - typeref_array[index] = entry.Value as TypeRef; - index++; - } - } else { - param_array = new Param[0]; - typeref_array = new TypeRef[0]; - } - - $$ = codegen.GetMethodRef (parent, (string) $4, return_type, param_array, - typeref_array, null); - } - ; - - -methodHead : D_METHOD methAttr callConv type_ref methodName - OPEN_PARENS arg_list CLOSE_PARENS implAttr OPEN_BRACE - { - Param[] param_array; - TypeRef[] typeref_array; - if ($7 != null) { - ArrayList param_list = $7 as ArrayList; - int index = 0; - param_array = new Param[param_list.Count]; - typeref_array = new TypeRef[param_list.Count]; - foreach (DictionaryEntry entry in param_list) { - param_array[index] = entry.Key as Param; - typeref_array[index] = entry.Value as TypeRef; - index++; - } - } else { - param_array = new Param[0]; - typeref_array = new TypeRef[0]; - } - - codegen.AddMethod ((MethAttr) $2, (ImplAttr) $9, (CallConv) $3, (string) $5, - (TypeRef) $4, param_array, typeref_array, null); - } - | D_METHOD methAttr callConv paramAttr type K_MARSHAL OPEN_PARENS nativeType CLOSE_PARENS methodName OPEN_PARENS sigArgs0 CLOSE_PARENS implAttr OPEN_BRACE - ; - - -methodAll : methodHead methodDecls CLOSE_BRACE - { - /* - // Console.WriteLine (method); - currentClass.AddMethod (method); - */ - } - ; - - -methAttr : /* EMPTY */ { $$ = MethAttr.Default; } - | methAttr K_STATIC { $$ = (MethAttr) $1 | MethAttr.Static; } - | methAttr K_PUBLIC { $$ = (MethAttr) $1 | MethAttr.Public; } - | methAttr K_PRIVATE { $$ = (MethAttr) $1 | MethAttr.Private; } - | methAttr K_FAMILY { $$ = (MethAttr) $1 | MethAttr.Family; } - | methAttr K_FINAL { $$ = (MethAttr) $1 | MethAttr.Final; } - | methAttr K_SPECIALNAME { $$ = (MethAttr) $1 | MethAttr.SpecialName; } - | methAttr K_VIRTUAL { $$ = (MethAttr) $1 | MethAttr.Virtual; } - | methAttr K_ABSTRACT { $$ = (MethAttr) $1 | MethAttr.Abstract; } - | methAttr K_ASSEMBLY { $$ = (MethAttr) $1 | MethAttr.Assembly; } - | methAttr K_FAMANDASSEM { $$ = (MethAttr) $1 | MethAttr.FamAndAssem; } - | methAttr K_FAMORASSEM { $$ = (MethAttr) $1 | MethAttr.FamOrAssem; } - | methAttr K_COMPILERCONTROLLED {/* FIXME */} - | methAttr K_HIDEBYSIG { $$ = (MethAttr) $1 | MethAttr.HideBySig; } - | methAttr K_NEWSLOT { $$ = (MethAttr) $1 | MethAttr.NewSlot; } - | methAttr K_RTSPECIALNAME { $$ = (MethAttr) $1 | MethAttr.RTSpecialName; } - | methAttr K_UNMANAGEDEXP {/* FIXME */} - | methAttr K_REQSECOBJ { $$ = (MethAttr) $1 | MethAttr.RequireSecObject; } - /* - | methAttr K_PINVOKEIMPL OPEN_PARENS compQstring K_AS compQstring pinvAttr CLOSE_PARENS { } - | methAttr K_PINVOKEIMPL OPEN_PARENS compQstring pinvAttr CLOSE_PARENS { } - | methAttr K_PINVOKEIMPL OPEN_PARENS pinvAttr CLOSE_PARENS { } - */ - ; - -pinvAttr : /* EMPTY */ - | pinvAttr K_NOMANGLE - | pinvAttr K_ANSI - | pinvAttr K_UNICODE - | pinvAttr K_AUTOCHAR - | pinvAttr K_LASTERR - | pinvAttr K_WINAPI - | pinvAttr K_CDECL - | pinvAttr K_STDCALL - | pinvAttr K_THISCALL - | pinvAttr K_FASTCALL - ; - -methodName : D_CTOR +decls : /* EMPTY */ + | decls decl + ; + +decl : class_all + | namespace_all + | method_all + | field_decl + | data_decl + | vtfixup_decl + | file_decl + | assembly_all + | assemblyref_all + | exptype_all + | manifestres_all + | module_head + | sec_decl + | customattr_decl + | D_SUBSYSTEM int32 + | D_CORFLAGS int32 + | D_FILE K_ALIGNMENT int32 + /* | D_IMAGEBASE int64 */ + | extsource_spec + | language_decl + ; + +extsource_spec : D_LINE int32 SQSTRING + | D_LINE int32 + | D_LINE int32 COLON int32 SQSTRING + | D_LINE int32 COLON int32 + ; + +language_decl : D_LANGUAGE SQSTRING + | D_LANGUAGE SQSTRING COMMA SQSTRING + | D_LANGUAGE SQSTRING COMMA SQSTRING COMMA SQSTRING + ; + +vtfixup_decl : D_VTFIXUP OPEN_BRACKET int32 CLOSE_BRACKET + vtfixup_attr K_AT id + ; + +vtfixup_attr : /* EMPTY */ + | vtfixup_attr int64 + | vtfixup_attr K_FROMUNMANAGED + | vtfixup_attr K_CALLMOSTDERIVED + ; + +namespace_all : namespace_head OPEN_BRACE decls CLOSE_BRACE + { + codegen.CurrentNameSpace = null; + } + ; + +namespace_head : D_NAMESPACE comp_name + { + codegen.CurrentNameSpace = (string) $2; + } + ; + +class_all : class_head OPEN_BRACE class_decls CLOSE_BRACE + { + codegen.EndTypeDef (); + } + ; + +class_head : D_CLASS class_attr id typars_clause extends_clause + impl_clause + { + codegen.BeginTypeDef ((TypeAttr) $2, (string) $3, + $5 as IClassRef, $6 as ArrayList, null); + + /* + // Lets not worry about generics for now :p + if ($4 != null) { + ArrayList typars_list = (ArrayList) $4; + int index = 0; + foreach (DictionaryEntry entry in typars_list) { + TypeRef type = (TypeRef) entry.Key; + string name = (string) entry.Value; + codegen.CurrentClass.AddGenericParameter ((short) index++, type.Type, name); + } + } + */ + } + ; + +class_attrs : class_attrs class_attr + ; + +class_attr : /* EMPTY */ { $$ = new TypeAttr (); } + | class_attr K_PUBLIC { $$ = (TypeAttr)$1 | TypeAttr.Public; } + | class_attr K_PRIVATE { $$ = (TypeAttr)$1 | TypeAttr.Private; } + | class_attr K_NESTED K_PRIVATE { $$ = (TypeAttr)$1 | TypeAttr.NestedPrivate; } + | class_attr K_NESTED K_PUBLIC { $$ = (TypeAttr)$1 | TypeAttr.NestedPublic; } + | class_attr K_NESTED K_FAMILY { $$ = (TypeAttr)$1 | TypeAttr.NestedFamily; } + | class_attr K_NESTED K_ASSEMBLY { $$ = (TypeAttr)$1 | TypeAttr.NestedAssembly;} + | class_attr K_NESTED K_FAMANDASSEM { $$ = (TypeAttr)$1 | TypeAttr.NestedFamAndAssem; } + | class_attr K_NESTED K_FAMORASSEM { $$ = (TypeAttr)$1 | TypeAttr.NestedFamOrAssem; } + | class_attr K_VALUE { } + | class_attr K_ENUM { } + | class_attr K_INTERFACE { $$ = (TypeAttr)$1 | TypeAttr.Interface; } + | class_attr K_SEALED { $$ = (TypeAttr)$1 | TypeAttr.Sealed; } + | class_attr K_ABSTRACT { $$ = (TypeAttr)$1 | TypeAttr.Abstract; } + | class_attr K_AUTO { } + | class_attr K_SEQUENTIAL { $$ = (TypeAttr)$1 | TypeAttr.SequentialLayout; } + | class_attr K_EXPLICIT { $$ = (TypeAttr)$1 | TypeAttr.ExplicitLayout; } + | class_attr K_ANSI { } + | class_attr K_UNICODE { $$ = (TypeAttr)$1 | TypeAttr.UnicodeClass; } + | class_attr K_AUTOCHAR { $$ = (TypeAttr)$1 | TypeAttr.AutoClass; } + | class_attr K_IMPORT { $$ = (TypeAttr)$1 | TypeAttr.Import; } + | class_attr K_SERIALIZABLE { $$ = (TypeAttr)$1 | TypeAttr.Serializable; } + | class_attr K_BEFOREFIELDINIT { $$ = (TypeAttr)$1 | TypeAttr.BeforeFieldInit; } + | class_attr K_SPECIALNAME { $$ = (TypeAttr)$1 | TypeAttr.SpecialName; } + | class_attr K_RTSPECIALNAME { $$ = (TypeAttr)$1 | TypeAttr.RTSpecialName; } + ; + +extends_clause : /* EMPTY */ + | K_EXTENDS class_ref + { + $$ = $2; + } + ; + +impl_clause : /* EMPTY */ + | K_IMPLEMENTS class_refs + { + $$ = $2; + } + ; + +typars_clause : /* EMPTY */ + | OPEN_ANGLE_BRACKET formal_typars CLOSE_ANGLE_BRACKET + { + $$ = $2; + } + ; + +typars : type + { + ArrayList typars_list = new ArrayList (); + typars_list.Add ($1); + $$ = typars_list; + } + | typars COMMA type + { + ArrayList typars_list = (ArrayList) $1; + typars_list.Add ($3); + $$ = typars_list; + } + ; + +formal_typars : formal_typar + { + ArrayList formal_list = new ArrayList (); + formal_list.Add ($1); + $$ = formal_list; + } + | formal_typars COMMA formal_typar + { + ArrayList formal_list = (ArrayList) $1; + formal_list.Add ($3); + $$ = formal_list; + } + ; + + +formal_typar : type { $$ = new DictionaryEntry ($1, null); } + | type id { $$ = new DictionaryEntry ($1, $2); } + ; + +class_refs : class_ref + { + ArrayList class_list = new ArrayList (); + class_list.Add ($1); + $$ = class_list; + } + | class_refs COMMA class_ref + { + ArrayList class_list = (ArrayList) $1; + class_list.Add ($3); + } + ; + +slashed_name : comp_name + | slashed_name SLASH comp_name + { + $$ = String.Format ("{0}/{1}", $1, $3); + } + ; + +class_ref : OPEN_BRACKET comp_name CLOSE_BRACKET slashed_name + { + ClassRef klass = codegen.ExternTable.GetClass ((string) $2, (string)$4); + $$ = new ExternTypeRef (klass, (string) $4); + } + | OPEN_BRACKET D_MODULE comp_name CLOSE_BRACKET slashed_name + | slashed_name + { + $$ = new TypeRef ((string) $1, null); + } + ; + +class_decls : /* EMPTY */ + | class_decls class_decl + ; + +class_decl : method_all + | class_all + | event_all + | prop_all + | field_decl + | data_decl + | sec_decl + | extsource_spec + | customattr_decl + | D_SIZE int32 + { + + } + | D_PACK int32 + | D_OVERRIDE type_spec DOUBLE_COLON method_name + K_WITH call_conv type type_spec DOUBLE_COLON method_name + OPEN_PARENS sig_args CLOSE_PARENS + | language_decl + ; + +type : K_CLASS class_ref + { + $$ = $2; + } + | K_OBJECT + { + $$ = new PrimitiveTypeRef (PrimitiveType.Object, "System.Object"); + } + | K_STRING + { + $$ = new PrimitiveTypeRef (PrimitiveType.String, "System.String"); + } + | K_VALUE K_CLASS class_ref + { + $$ = $3; + } + | K_VALUETYPE class_ref + { + $$ = $2; + } + | type OPEN_BRACKET CLOSE_BRACKET + { + ITypeRef base_type = (ITypeRef) $1; + base_type.MakeArray (); + } + | type OPEN_BRACKET bounds CLOSE_BRACKET + { + ITypeRef base_type = (ITypeRef) $1; + ArrayList bound_list = (ArrayList) $3; + base_type.MakeBoundArray (bound_list); + } + | type AMPERSAND + { + ITypeRef base_type = (ITypeRef) $1; + base_type.MakeManagedPointer (); + } + | type STAR + { + ITypeRef base_type = (ITypeRef) $1; + base_type.MakeUnmanagedPointer (); + } + | type K_PINNED + { + ITypeRef base_type = (ITypeRef) $1; + base_type.MakePinned (); + } + | type K_MODREQ OPEN_PARENS class_ref CLOSE_PARENS + { + /* + ITypeRef base_type = (ITypeRef) $1; + ITypeRef class_ref = (ITypeRef) $4; + + $$ = new CustomModifiedType (base_type.Type, + CustomModifier.modreq, (Class) class_ref.Type); + */ + } + | type K_MODOPT OPEN_PARENS class_ref CLOSE_PARENS + { + /* + TypeRef base_type = (TypeRef) $1; + TypeRef class_ref = (TypeRef) $4; + + $$ = new CustomModifiedType (base_type.Type, + CustomModifier.modopt, (Class) class_ref.Type); + */ + } + | K_METHOD call_conv type STAR OPEN_PARENS sig_args CLOSE_PARENS + | K_TYPEDREF + { + $$ = new PrimitiveTypeRef (PrimitiveType.TypedRef, + "System.TypedReference"); + } + | K_CHAR + { + $$ = new PrimitiveTypeRef (PrimitiveType.Char, "System.Char"); + } + | K_VOID + { + $$ = new PrimitiveTypeRef (PrimitiveType.Void, "System.Void"); + } + | K_BOOL + { + $$ = new PrimitiveTypeRef (PrimitiveType.Boolean, "System.Bool"); + } + | K_INT8 + { + $$ = new PrimitiveTypeRef (PrimitiveType.Int8, "System.Int8"); + } + | K_INT16 + { + $$ = new PrimitiveTypeRef (PrimitiveType.Int16, "System.Int16"); + } + | K_INT32 + { + $$ = new PrimitiveTypeRef (PrimitiveType.Int32, "System.Int32"); + } + | K_INT64 + { + $$ = new PrimitiveTypeRef (PrimitiveType.Int64, "System.Int64"); + } + | K_FLOAT32 + { + $$ = new PrimitiveTypeRef (PrimitiveType.Float32, "System.Float32"); + } + | K_FLOAT64 + { + $$ = new PrimitiveTypeRef (PrimitiveType.Float64, "System.Float64"); + } + | K_UNSIGNED K_INT8 + { + $$ = new PrimitiveTypeRef (PrimitiveType.UInt8, "System.UInt8"); + } + | K_UNSIGNED K_INT16 + { + $$ = new PrimitiveTypeRef (PrimitiveType.UInt16, "System.UInt16"); + } + | K_UNSIGNED K_INT32 + { + $$ = new PrimitiveTypeRef (PrimitiveType.UInt32, "System.UInt32"); + } + | K_UNSIGNED K_INT64 + { + $$ = new PrimitiveTypeRef (PrimitiveType.UInt64, "System.UInt64"); + } + | K_NATIVE K_INT + { + // TODO: Is this the proper full name + $$ = new PrimitiveTypeRef (PrimitiveType.NativeInt, "System.IntPtr"); + } + + | K_NATIVE K_UNSIGNED K_INT + { + $$ = new PrimitiveTypeRef (PrimitiveType.NativeUInt, "System.UIntPtr"); + } + | BANG int32 + { + // access class type parameter by number + } + | BANG BANG int32 + { + // access method type parameter by number + } + ; + +bounds : bound + { + ArrayList bound_list = new ArrayList (); + bound_list.Add ($1); + $$ = bound_list; + } + | bounds COMMA bound + { + ArrayList bound_list = (ArrayList) $1; + bound_list.Add ($3); + } + ; + +bound : /* EMPTY */ + | ELLIPSIS + { + // No lower bound or size + $$ = new DictionaryEntry (null,null); + } + | int32 + { + // ******** Not sure what this is? + // For now I will say it is size because there + // is allready a way to set lower + $$ = new DictionaryEntry (null, $1); + } + | int32 ELLIPSIS int32 + { + // lower bound and size + $$ = new DictionaryEntry ($1, $3); + } + | int32 ELLIPSIS + { + // Just lower bound + $$ = new DictionaryEntry ($1, null); + } + ; + +call_conv : K_INSTANCE call_conv + { + $$ = (CallConv) $2 | CallConv.Instance; + } + | K_EXPLICIT call_conv + { + $$ = (CallConv) $2 | CallConv.InstanceExplicit; + } + | call_kind + ; + +call_kind : /* EMPTY */ + { + $$ = new CallConv (); + } + | K_DEFAULT + { + $$ = CallConv.Default; + } + | K_VARARG + { + $$ = CallConv.Vararg; + } + | K_UNMANAGED K_CDECL + { + $$ = CallConv.Cdecl; + } + | K_UNMANAGED K_STDCALL + { + $$ = CallConv.Stdcall; + } + | K_UNMANAGED K_THISCALL + { + $$ = CallConv.Thiscall; + } + | K_UNMANAGED K_FASTCALL + { + $$ = CallConv.Fastcall; + } + ; + +native_type : /* EMPTY */ + | K_CUSTOM OPEN_PARENS comp_qstring COMMA comp_qstring CLOSE_PARENS + | K_FIXED K_SYSSTRING OPEN_BRACKET int32 CLOSE_BRACKET + { + $$ = NativeType.FixedSysString; + } + | K_FIXED K_ARRAY OPEN_BRACKET int32 CLOSE_BRACKET + | K_VARIANT + | K_CURRENCY + { + $$ = NativeType.Currency; + } + | K_SYSCHAR + | K_VOID + { + $$ = NativeType.Void; + } + | K_BOOL + { + $$ = NativeType.Boolean; + } + | K_INT8 + { + $$ = NativeType.Int8; + } + | K_INT16 + { + $$ = NativeType.Int16; + } + | K_INT32 + { + $$ = NativeType.Int32; + } + | K_INT64 + { + $$ = NativeType.Int64; + } + | K_FLOAT32 + { + $$ = NativeType.Float32; + } + | K_FLOAT64 + { + $$ = NativeType.Float64; + } + | K_ERROR + | K_UNSIGNED K_INT8 + { + $$ = NativeType.UInt8; + } + | K_UNSIGNED K_INT16 + { + $$ = NativeType.UInt16; + } + | K_UNSIGNED K_INT32 + { + $$ = NativeType.UInt32; + } + | K_UNSIGNED K_INT64 + { + $$ = NativeType.UInt64; + } + | native_type STAR + | native_type OPEN_BRACKET CLOSE_BRACKET + | native_type OPEN_BRACKET int32 CLOSE_BRACKET + | native_type OPEN_BRACKET int32 PLUS int32 CLOSE_BRACKET + | native_type OPEN_BRACKET PLUS int32 CLOSE_BRACKET + | K_DECIMAL + | K_DATE + | K_BSTR + { + $$ = NativeType.BStr; + } + | K_LPSTR + { + $$ = NativeType.LPStr; + } + | K_LPWSTR + { + $$ = NativeType.LPWStr; + } + | K_LPTSTR + { + $$ = NativeType.LPTStr; + } + | K_OBJECTREF + | K_IUNKNOWN + { + $$ = NativeType.IUnknown; + } + | K_IDISPATCH + { + $$ = NativeType.IDispatch; + } + | K_STRUCT + { + $$ = NativeType.Struct; + } + | K_INTERFACE + { + $$ = NativeType.Interface; + } + | K_SAFEARRAY variant_type + | K_SAFEARRAY variant_type COMMA comp_qstring + | K_INT + { + $$ = NativeType.Int; + } + | K_UNSIGNED K_INT + { + $$ = NativeType.UInt; + } + | K_NESTED K_STRUCT + | K_BYVALSTR + { + $$ = NativeType.ByValStr; + } + | K_ANSI K_BSTR + { + $$ = NativeType.AnsiBStr; + } + | K_TBSTR + { + $$ = NativeType.TBstr; + } + | K_VARIANT K_BOOL + { + $$ = NativeType.VariantBool; + } + | K_METHOD + | K_AS K_ANY + { + $$ = NativeType.AsAny; + } + | K_LPSTRUCT + ; + +variant_type : /* EMPTY */ + | K_NULL + | K_VARIANT + | K_CURRENCY + | K_VOID + | K_BOOL + | K_INT8 + | K_INT16 + | K_INT32 + | K_INT64 + | K_FLOAT32 + | K_FLOAT64 + | K_UNSIGNED K_INT8 + | K_UNSIGNED K_INT16 + | K_UNSIGNED K_INT32 + | K_UNSIGNED K_INT64 + | STAR + | variant_type OPEN_BRACKET CLOSE_BRACKET + | variant_type K_VECTOR + | variant_type AMPERSAND + | K_DECIMAL + | K_DATE + | K_BSTR + | K_LPSTR + | K_LPWSTR + | K_IUNKNOWN + | K_IDISPATCH + | K_SAFEARRAY + | K_INT + | K_UNSIGNED K_INT + | K_ERROR + | K_HRESULT + | K_CARRAY + | K_USERDEFINED + | K_RECORD + | K_FILETIME + | K_BLOB + | K_STREAM + | K_STORAGE + | K_STREAMED_OBJECT + | K_STORED_OBJECT + | K_BLOB_OBJECT + | K_CF + | K_CLSID + ; + +field_decl : D_FIELD repeat_opt field_attr type id at_opt init_opt + { + FieldDef field_def = new FieldDef((FieldAttr) $3, + (string) $5, (ITypeRef) $4); + codegen.AddFieldDef (field_def); + + if ($2 != null) { + field_def.SetOffset ((uint) $2); + } + /* + if ($6 != null) { + field_def.AddDataValue ((DataConstant) $6); + } + */ + if ($7 != null) { + field_def.SetValue ((Constant) $7); + } + } + ; + +repeat_opt : /* EMPTY */ + | OPEN_BRACKET int32 CLOSE_BRACKET + { + $$ = $2; + } + ; + +field_attr : /* EMPTY */ + { + $$ = new FieldAttr (); + } + | field_attr K_PUBLIC + { + $$ = (FieldAttr) $1 | FieldAttr.Public; + } + | field_attr K_PRIVATE + { + $$ = (FieldAttr) $1 | FieldAttr.Private; + } + | field_attr K_FAMILY + { + $$ = (FieldAttr) $1 | FieldAttr.Family; + } + | field_attr K_ASSEMBLY + { + $$ = (FieldAttr) $1 | FieldAttr.Assembly; + } + | field_attr K_FAMANDASSEM + { + $$ = (FieldAttr) $1 | FieldAttr.FamAndAssem; + } + | field_attr K_FAMORASSEM + { + $$ = (FieldAttr) $1 | FieldAttr.FamOrAssem; + } + | field_attr K_PRIVATESCOPE + { + // This is just 0x0000 + } + | field_attr K_STATIC + { + $$ = (FieldAttr) $1 | FieldAttr.Static; + } + | field_attr K_INITONLY + { + $$ = (FieldAttr) $1 | FieldAttr.Initonly; + } + | field_attr K_RTSPECIALNAME + { + $$ = (FieldAttr) $1 | FieldAttr.RTSpecialName; + } + | field_attr K_SPECIALNAME + { + $$ = (FieldAttr) $1 | FieldAttr.SpecialName; + } + | field_attr K_MARSHAL OPEN_PARENS native_type CLOSE_PARENS + { + + } + | field_attr K_LITERAL + { + $$ = (FieldAttr) $1 | FieldAttr.Literal; + } + | field_attr K_NOTSERIALIZED + { + $$ = (FieldAttr) $1 | FieldAttr.Notserialized; + } + ; + +at_opt : /* EMPTY */ + | K_AT id + { + // TODO: Implement DataTable + // $$ = new DataConstant (DataTable.GetOffset ((string) $2)); + } + ; + +init_opt : /* EMPTY */ + | ASSIGN field_init + { + $$ = $2; + } + ; + +field_init : K_FLOAT32 OPEN_PARENS float64 CLOSE_PARENS + { + $$ = new FloatConst (Convert.ToSingle ($3)); + } + | K_FLOAT64 OPEN_PARENS float64 CLOSE_PARENS + { + $$ = new DoubleConst (Convert.ToDouble ($3)); + } + | K_FLOAT32 OPEN_PARENS int64 CLOSE_PARENS + { + $$ = new FloatConst (Convert.ToSingle ($3)); + } + | K_FLOAT64 OPEN_PARENS int64 CLOSE_PARENS + { + $$ = new DoubleConst (Convert.ToDouble (3)); + } + | K_INT64 OPEN_PARENS int64 CLOSE_PARENS + { + $$ = new IntConst (Convert.ToInt64 ($3)); + } + | K_INT32 OPEN_PARENS int64 CLOSE_PARENS + { + $$ = new IntConst (Convert.ToUInt32 ($3)); + } + | K_INT16 OPEN_PARENS int64 CLOSE_PARENS + { + $$ = new IntConst (Convert.ToUInt16 ($3)); + } + | K_CHAR OPEN_PARENS int64 CLOSE_PARENS + { + $$ = new CharConst (Convert.ToChar ($3)); + } + | K_INT8 OPEN_PARENS int64 CLOSE_PARENS + { + $$ = new IntConst (Convert.ToByte ($3)); + } + | K_BOOL OPEN_PARENS truefalse CLOSE_PARENS + { + $$ = new BoolConst ((bool) $3); + } + | K_BYTEARRAY OPEN_PARENS bytes CLOSE_PARENS + { + $$ = new ByteArrConst ((byte[]) $3); + } + | comp_qstring + { + // ******** THIS IS NOT IN THE DOCUMENTATION ******** // + $$ = new StringConst ((string) $1); + } + | K_NULLREF + { + $$ = new NullConst (); + } + ; + +data_decl : data_head data_body + { + /* + Console.WriteLine ("Creating data decl: '{0}' '{1}'", $1, $2); + + DataDef datadef = (DataDef) $1; + + if ($2 is ArrayList) { + ArrayList const_list = (ArrayList) $2; + DataConstant[] const_arr = new DataConstant[const_list.Count]; + + for (int i=0; i Int32.MaxValue) + $$ = Int32.MaxValue; + else if (int64 < Int32.MinValue) + $$ = Int32.MinValue; + } ; -exportHead : D_EXPORT comtAttr name1 +int64 : INT64 + | INT32 ; -comtAttr : /* EMPTY */ - | comtAttr K_PRIVATE - | comtAttr K_PUBLIC - | comtAttr K_NESTED K_PUBLIC - | comtAttr K_NESTED K_PRIVATE - | comtAttr K_NESTED K_FAMILY - | comtAttr K_NESTED K_ASSEMBLY - | comtAttr K_NESTED K_FAMANDASSEM - | comtAttr K_NESTED K_FAMORASSEM +float64 : FLOAT64 + | K_FLOAT32 OPEN_PARENS int32 CLOSE_PARENS + | K_FLOAT64 OPEN_PARENS int64 CLOSE_PARENS ; -comtypeDecls : /* EMPTY */ - | comtypeDecls comtypeDecl +hexbyte : HEXBYTE + | INT32 { $$ = Convert.ToByte ($1); } + | ID + { + $$ = Byte.Parse ((string) $1, NumberStyles.HexNumber); + } ; -comtypeDecl : D_FILE name1 - | D_CLASS K_EXTERN name1 - | D_CLASS int32 - | customAttrDecl +bytes : /* EMPTY */ { $$ = new byte[0]; } + | hexbytes + { + ArrayList byte_list = (ArrayList) $1; + $$ = byte_list.ToArray (typeof (byte)); + } ; -manifestResHead : D_MRESOURCE manresAttr name1 +hexbytes : hexbyte + { + ArrayList byte_list = new ArrayList (); + byte_list.Add (Convert.ToByte ($1)); + $$ = byte_list; + } + | hexbytes hexbyte + { + ArrayList byte_list = (ArrayList) $1; + byte_list.Add (Convert.ToByte ($2)); + } ; -manresAttr : /* EMPTY */ - | manresAttr K_PUBLIC - | manresAttr K_PRIVATE +truefalse : K_TRUE + | K_FALSE ; -manifestResDecls : /* EMPTY */ - | manifestResDecls manifestResDecl +id : ID + | SQSTRING ; -manifestResDecl : D_FILE name1 K_AT int32 - | D_ASSEMBLY K_EXTERN name1 - | customAttrDecl +comp_name : id + | comp_name DOT id + { + $$ = (string) $1 + '.' + (string) $3; + } ; - %% -} // namespace Mono.ILASM +} +