X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=mcs%2Filasm%2Fparser%2FILParser.jay;h=1c4c9c40deca3fc71985ef52110d8cdcd1a4bd1b;hb=ba2604940e0dcfe116c44eea72932326aabaa8ff;hp=babcfc68e58235c3fe51ff44391bb88a1c11f657;hpb=8088be6ff044addab62fb37effd98edd7ff5ebab;p=mono.git diff --git a/mcs/ilasm/parser/ILParser.jay b/mcs/ilasm/parser/ILParser.jay index babcfc68e58..1c4c9c40dec 100644 --- a/mcs/ilasm/parser/ILParser.jay +++ b/mcs/ilasm/parser/ILParser.jay @@ -3,39 +3,25 @@ // // (C) Sergey Chaban (serge@wildwestsoftware.com) +using PEAPI; using System; -using System.Reflection; -using System.Reflection.Emit; +using System.Collections; +using System.Globalization; namespace Mono.ILASM { public class ILParser { - private Method method; - - private InstrBase currentInstr; - - private CallingConventions currentCallConv; - - private TypeAttributes currentTypeAttrs; - - private Class currentClass; - private CodeGen codegen; - private string defaultAsmName = "output"; - - public ILParser (CodeGen codegen) { this.codegen = codegen; } public CodeGen CodeGen { - get { - return codegen; - } + get { return codegen; } } - + %} %token EOF @@ -58,6 +44,8 @@ namespace Mono.ILASM { /* FLOAT64 - floating point number */ %token FLOAT64 +/* HEXBYTE - two digit hex number */ +%token HEXBYTE /* Punctuation */ @@ -80,7 +68,8 @@ namespace Mono.ILASM { %token BANG "!" %token ELLIPSIS "..." %token DASH "-" - +%token OPEN_ANGLE_BRACKET "<" +%token CLOSE_ANGLE_BRACKET ">" @@ -110,7 +99,6 @@ namespace Mono.ILASM { - /* Mechanically generated - DO NOT EDIT! */ @@ -146,7 +134,7 @@ namespace Mono.ILASM { %token D_LOCALE %token D_LOCALS %token D_MANIFESTRES -%token D_MAXSTCCK +%token D_MAXSTACK %token D_METHOD %token D_MIME %token D_MODULE @@ -370,968 +358,1619 @@ namespace Mono.ILASM { %% il_file : decls - ; - -decls : /* EMPTY */ - | decls decl - ; - -decl : classAll - | nameSpaceHead OPEN_BRACE decls CLOSE_BRACE - | 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 - ; - -classHead : D_CLASS classAttr id extendsClause implClause - { - currentTypeAttrs = 0; - currentClass = new Class ($3 as string); - currentClass.Attrs = currentTypeAttrs; - - // TODO: extends/implemets - } - ; - -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 className - ; - -implClause : /* EMPTY */ - | K_IMPLEMENTS classNames - ; - -classNames : classNames COMMA className - | className - ; - -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 id atOpt initOpt - ; - - -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 ; - -methodHeadPart1 : D_METHOD - { - method = new Method (); - currentCallConv = 0; /*?*/ - } - ; - -methodHead : methodHeadPart1 methAttr callConv paramAttr type methodName OPEN_PARENS sigArgs0 CLOSE_PARENS implAttr OPEN_BRACE - { - method.SetMethodName ($6 as MethodName); - method.CallConv = currentCallConv; - method.RetType = $5 as string; - } - | methodHeadPart1 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 K_STATIC {method.Attrs |= MethodAttributes.Static;} - | methAttr K_PUBLIC {method.Attrs |= MethodAttributes.Public;} - | methAttr K_PRIVATE {method.Attrs &= ~MethodAttributes.Public;} - | methAttr K_FAMILY {method.Attrs |= MethodAttributes.Family;} - | methAttr K_FINAL {method.Attrs |= MethodAttributes.Final;} - | methAttr K_SPECIALNAME {method.Attrs |= MethodAttributes.SpecialName;} - | methAttr K_VIRTUAL {method.Attrs |= MethodAttributes.Virtual;} - | methAttr K_ABSTRACT {method.Attrs |= MethodAttributes.Abstract;} - | methAttr K_ASSEMBLY {method.Attrs |= MethodAttributes.Assembly;} - | methAttr K_FAMANDASSEM {method.Attrs |= MethodAttributes.FamANDAssem;} - | methAttr K_FAMORASSEM {method.Attrs |= MethodAttributes.FamORAssem;} - | methAttr K_COMPILERCONTROLLED {/* FIXME */} - | methAttr K_HIDEBYSIG {method.Attrs |= MethodAttributes.HideBySig;} - | methAttr K_NEWSLOT {method.Attrs |= MethodAttributes.NewSlot;} - | methAttr K_RTSPECIALNAME /**/ {/* FIXME */} - | methAttr K_UNMANAGEDEXP {method.Attrs |= MethodAttributes.UnmanagedExport;} - | methAttr K_REQSECOBJ {method.Attrs |= MethodAttributes.RequireSecObject;} - | methAttr K_PINVOKEIMPL OPEN_PARENS compQstring K_AS compQstring pinvAttr CLOSE_PARENS {/* FIXME */} - | methAttr K_PINVOKEIMPL OPEN_PARENS compQstring pinvAttr CLOSE_PARENS {/* FIXME */} - | methAttr K_PINVOKEIMPL OPEN_PARENS pinvAttr CLOSE_PARENS {/* FIXME */} - ; - -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 {$$ = new MethodName ("ctor", true);} - | D_CCTOR {$$ = new MethodName ("cctor", true);} - | name1 {$$ = new MethodName ($1 as string);} - ; - -paramAttr : /* EMPTY */ - | paramAttr OPEN_BRACKET K_IN CLOSE_BRACKET - | paramAttr OPEN_BRACKET K_OUT CLOSE_BRACKET - | paramAttr OPEN_BRACKET K_OPT CLOSE_BRACKET - | paramAttr OPEN_BRACKET int32 CLOSE_BRACKET - ; - -fieldAttr : /* EMPTY */ - | fieldAttr K_STATIC - | fieldAttr K_PUBLIC - | fieldAttr K_PRIVATE - | fieldAttr K_FAMILY - | fieldAttr K_INITONLY - | fieldAttr K_RTSPECIALNAME /**/ - | fieldAttr K_SPECIALNAME - /* commented out because PInvoke for fields is not supported by EE - | fieldAttr K_PINVOKEIMPL OPEN_PARENS compQstring K_AS compQstring pinvAttr CLOSE_PARENS - | fieldAttr K_PINVOKEIMPL OPEN_PARENS compQstring pinvAttr CLOSE_PARENS - | fieldAttr K_PINVOKEIMPL OPEN_PARENS pinvAttr CLOSE_PARENS - */ - | fieldAttr K_MARSHAL OPEN_PARENS nativeType CLOSE_PARENS - | fieldAttr K_ASSEMBLY - | fieldAttr K_FAMANDASSEM - | fieldAttr K_FAMORASSEM - | fieldAttr K_COMPILERCONTROLLED - | fieldAttr K_LITERAL - | fieldAttr K_NOTSERIALIZED - ; - -implAttr : /* empty */ - | implAttr K_NATIVE - | implAttr ELLIPSIS - | implAttr K_IL /* LAMESPEC: absent in docs */ - | implAttr K_CIL /* LAMESPEC: same as above */ - | implAttr K_OPTIL - | implAttr K_MANAGED - | implAttr K_UNMANAGED - | implAttr K_FORWARDREF - | implAttr K_PRESERVESIG - | implAttr K_RUNTIME - | implAttr K_INTERNALCALL - | implAttr K_SYNCHRONIZED - | implAttr K_NOINLINING - ; - -localsHead : D_LOCALS - ; - - -methodDecl : D_EMITBYTE int32 - | sehBlock - | D_MAXSTACK int32 - | localsHead OPEN_PARENS sigArgs0 CLOSE_PARENS - | localsHead K_INIT OPEN_PARENS sigArgs0 CLOSE_PARENS - { - method.AddLocal ((string)$4); - } - | D_ENTRYPOINT {method.IsEntryPoint = true;} - | D_ZEROINIT - | dataDecl - | instr { - method.AddInstruction (currentInstr); - } - | id COLON - | secDecl - | extSourceSpec - | languageDecl - | customAttrDecl - | D_EXPORT OPEN_BRACKET int32 CLOSE_BRACKET - | D_EXPORT OPEN_BRACKET int32 CLOSE_BRACKET K_AS id +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 +} +