X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=mcs%2Filasm%2Fparser%2FILParser.jay;h=6ecbc48927d30c658640d8d5eccdb79763b0891f;hb=877e17230a375ff9595421cc9e63d042606f6507;hp=b4d32dde43ea30d474ab187aecaed421335b095e;hpb=37ce700bcd1bdd20431641d7e7a6bd7abb69434c;p=mono.git diff --git a/mcs/ilasm/parser/ILParser.jay b/mcs/ilasm/parser/ILParser.jay index b4d32dde43e..67c9d234af1 100644 --- a/mcs/ilasm/parser/ILParser.jay +++ b/mcs/ilasm/parser/ILParser.jay @@ -1,41 +1,55 @@ %{ -// Mono::ILASM::ILParser // +// Mono::ILASM::ILParser +// // (C) Sergey Chaban (serge@wildwestsoftware.com) +// (C) 2003 Jackson Harper, All rights reserved +// using PEAPI; using System; +using System.IO; 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) { + private bool is_value_class; + private bool is_enum_class; + private bool pinvoke_info; + private string pinvoke_mod; + private string pinvoke_meth; + private PEAPI.PInvokeAttr pinvoke_attr; + private ILTokenizer tokenizer; + + public ILParser (CodeGen codegen, ILTokenizer tokenizer) + { this.codegen = codegen; + this.tokenizer = tokenizer; } public CodeGen CodeGen { - get { - return codegen; - } + get { return codegen; } } - + + private ITypeRef GetTypeRef (ITypeRef b) + { + ExternTypeRefInst etri = b as ExternTypeRefInst; + ExternTypeRef etr; + + if (etri != null) + return etri.Clone (); + + etr = b as ExternTypeRef; + if (etr != null) + return etr.Clone (); + + return b; + } %} %token EOF @@ -49,6 +63,9 @@ namespace Mono.ILASM { /* SQSTRING - single quoted string */ %token SQSTRING +/* COMP_NAME - A name with dots */ +%token COMP_NAME + /* INT32 - 32 bit integer */ %token INT32 @@ -58,6 +75,8 @@ namespace Mono.ILASM { /* FLOAT64 - floating point number */ %token FLOAT64 +/* HEXBYTE - two digit hex number */ +%token HEXBYTE /* Punctuation */ @@ -80,7 +99,8 @@ namespace Mono.ILASM { %token BANG "!" %token ELLIPSIS "..." %token DASH "-" - +%token OPEN_ANGLE_BRACKET "<" +%token CLOSE_ANGLE_BRACKET ">" @@ -104,8 +124,8 @@ namespace Mono.ILASM { %token INSTR_TOK %token INSTR_SWITCH %token INSTR_PHI - - +%token INSTR_LOCAL +%token INSTR_PARAM @@ -125,6 +145,8 @@ namespace Mono.ILASM { %token D_CLASS %token D_COMTYPE %token D_CONFIG +%token D_CONSTRAINT +%token D_IMAGEBASE %token D_CORFLAGS %token D_CTOR %token D_CUSTOM @@ -146,7 +168,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 @@ -341,8 +363,8 @@ namespace Mono.ILASM { %token K_NOMETADATA %token K_ALGORITHM %token K_FULLORIGIN -%token K_NAN -%token K_INF +// %token K_NAN +// %token K_INF %token K_PUBLICKEY %token K_ENABLEJITTRACKING %token K_DISABLEJITOPTIMIZER @@ -358,6 +380,7 @@ namespace Mono.ILASM { %token K_STRING %token K_TRUE %token K_FALSE +%token K_IS /* end generated */ @@ -370,1113 +393,2279 @@ 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 - ; +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 + { + codegen.SetSubSystem ((int) $2); + } + | D_CORFLAGS int32 + { + codegen.SetCorFlags ((int) $2); + } + | D_FILE K_ALIGNMENT int32 + | D_IMAGEBASE int64 + { + codegen.SetImageBase ((long) $2); + } + | 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 + ; + +constraint_decl : D_CONSTRAINT BANG int32 K_IS type + { + codegen.CurrentTypeDef.AddGenericConstraint ((int) $3, (ITypeRef) $5); + } + ; + +vtfixup_decl : D_VTFIXUP OPEN_BRACKET int32 CLOSE_BRACKET + vtfixup_attr K_AT id + ; + +vtfixup_attr : /* EMPTY */ + | vtfixup_attr K_INT32 + | vtfixup_attr K_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 formal_typars_clause extends_clause + impl_clause + { + codegen.BeginTypeDef ((TypeAttr) $2, (string) $3, + $5 as IClassRef, $6 as ArrayList, null); + + if (is_value_class) + codegen.CurrentTypeDef.MakeValueClass (); + if (is_enum_class) + codegen.CurrentTypeDef.MakeEnumClass (); -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, $4 as Class, null); - } else { - codegen.AddClass ((TypeAttr)$2, (string) $3, null); - } - // TODO: extends/implements - } - ; - -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; */ } + if ($4 != null) { + ArrayList typars_list = (ArrayList) $4; + foreach (string id in typars_list) + codegen.CurrentTypeDef.AddGenericParam (id); + } + } ; -extendsClause : /* EMPTY */ - | K_EXTENDS type_ref {$$ = $2;} - ; - -implClause : /* EMPTY */ - | K_IMPLEMENTS classNames +class_attrs : class_attrs class_attr ; -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_ref id atOpt initOpt +class_attr : /* EMPTY */ + { + // Reset some flags + is_value_class = false; + is_enum_class = false; + $$ = 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 { is_value_class = true; } + | class_attr K_ENUM { is_enum_class = true; is_value_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; } + | 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; + } + ; + +formal_typars_clause : /* EMPTY */ + | OPEN_ANGLE_BRACKET formal_typars CLOSE_ANGLE_BRACKET + { + $$ = $2; + } + ; + +typars_clause : /* EMPTY */ + | OPEN_ANGLE_BRACKET 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 : id + { + $$ = $1; + } + ; + +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 slashed_name CLOSE_BRACKET slashed_name + { + if (codegen.IsThisAssembly ((string) $2)) { + $$ = new TypeRef ((string) $4, false, null); + } else { + $$ = codegen.ExternTable.GetTypeRef ((string) $2, (string) $4, false); + } + } + | OPEN_BRACKET D_MODULE slashed_name CLOSE_BRACKET slashed_name + { + if (codegen.IsThisModule ((string) $3)) { + $$ = new TypeRef ((string) $5, false, null); + } else { + $$ = codegen.ExternTable.GetModuleTypeRef ((string) $3, (string) $5, false); + } + } + | slashed_name + { + PrimitiveTypeRef prim = PrimitiveTypeRef.GetPrimitiveType ((string) $1); + + if (prim != null) + $$ = prim; + else + $$ = new TypeRef ((string) $1, false, 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 + { + codegen.CurrentTypeDef.AddCustomAttribute ((CustomAttr) $1); + } + | D_SIZE int32 + { + codegen.CurrentTypeDef.SetSize ((int) $2); + } + | D_PACK int32 + { + codegen.CurrentTypeDef.SetPack ((int) $2); + } + | D_OVERRIDE type_spec DOUBLE_COLON method_name K_WITH call_conv type + type_spec DOUBLE_COLON method_name type_list + { + // + // My copy of the spec didn't have a type_list but + // it seems pretty crucial + // + ITypeRef owner = (ITypeRef) $2; + ArrayList arg_list = (ArrayList) $11; + ITypeRef[] param_list; + IMethodRef decl; + + if (arg_list != null) + param_list = (ITypeRef[]) arg_list.ToArray (typeof (ITypeRef)); + else + param_list = new ITypeRef[0]; + + decl = owner.GetMethodRef ((ITypeRef) $7, + (CallConv) $6, (string) $4, param_list); + + string sig = MethodDef.CreateSignature ((string) $10, + param_list); + codegen.CurrentTypeDef.AddOverride (sig, decl); + } + OPEN_PARENS sig_args CLOSE_PARENS + | language_decl + | constraint_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 + { + IClassRef class_ref = (IClassRef) $3; + class_ref.MakeValueClass (); + $$ = class_ref; + } + | K_VALUETYPE OPEN_BRACKET slashed_name CLOSE_BRACKET slashed_name + { + ExternTypeRef ext_ref = codegen.ExternTable.GetTypeRef ((string) $3, (string) $5, false); + ExternTypeRefInst inst = new ExternTypeRefInst (ext_ref, true); + $$ = inst; + } + | K_VALUETYPE slashed_name + { + TypeRef t_ref = new TypeRef ((string) $2, true, null); + t_ref.MakeValueClass (); + $$ = t_ref; + } + | type OPEN_BRACKET CLOSE_BRACKET + { + ITypeRef base_type = GetTypeRef ((ITypeRef) $1); + base_type.MakeArray (); + $$ = base_type; + } + | type OPEN_BRACKET bounds CLOSE_BRACKET + { + ITypeRef base_type = GetTypeRef ((ITypeRef) $1); + ArrayList bound_list = (ArrayList) $3; + base_type.MakeBoundArray (bound_list); + $$ = base_type; + } + | type AMPERSAND + { + ITypeRef base_type = GetTypeRef ((ITypeRef) $1); + base_type.MakeManagedPointer (); + $$ = base_type; + } + | type STAR + { + ITypeRef base_type = GetTypeRef ((ITypeRef) $1); + base_type.MakeUnmanagedPointer (); + $$ = base_type; + } + | type K_PINNED + { + ITypeRef base_type = GetTypeRef ((ITypeRef) $1); + base_type.MakePinned (); + $$ = base_type; + } + | type K_MODREQ OPEN_PARENS class_ref CLOSE_PARENS + { + ITypeRef base_type = GetTypeRef ((ITypeRef) $1); + IClassRef class_ref = (IClassRef) $4; + base_type.MakeCustomModified (codegen, + CustomModifier.modopt, class_ref); + $$ = base_type; + } + | type K_MODOPT OPEN_PARENS class_ref CLOSE_PARENS + { + ITypeRef base_type = GetTypeRef ((ITypeRef) $1); + IClassRef class_ref = (IClassRef) $4; + base_type.MakeCustomModified (codegen, + CustomModifier.modopt, class_ref); + $$ = base_type; + } + | K_METHOD call_conv type STAR OPEN_PARENS sig_args CLOSE_PARENS + { + $$ = new MethodPointerTypeRef ((CallConv) $2, (ITypeRef) $3, (ArrayList) $6); + } + | K_TYPEDREF + { + $$ = new PrimitiveTypeRef (PrimitiveType.TypedRef, + "System.TypedReference"); + } + | K_CHAR + { + $$ = new PrimitiveTypeRef (PrimitiveType.Char, "System.Char"); + } + | K_WCHAR { - codegen.CurrentClass.AddField ((FieldAttr) $3, - (string) $5, (PEAPI.Type) $4); + $$ = new PrimitiveTypeRef (PrimitiveType.Char, "System.Char"); } - ; - -type_ref : primative_type_ref - | internal_type_ref - | external_type_ref - ; - -primative_type_ref : K_CHAR {$$ = PrimitiveType.Char; } - | K_VOID {$$ = PrimitiveType.Void; } - | K_BOOL {$$ = PrimitiveType.Boolean; } - | K_INT8 {$$ = PrimitiveType.Int8; } - | K_INT16 {$$ = PrimitiveType.Int16; } - | K_INT32 {$$ = PrimitiveType.Int32; } - | K_INT64 {$$ = PrimitiveType.Int64; } - | K_FLOAT32 {$$ = PrimitiveType.Float32; } - | K_FLOAT64 {$$ = PrimitiveType.Float64; } - | K_UNSIGNED K_INT8 {$$ = PrimitiveType.UInt8; } - | K_UNSIGNED K_INT16 {$$ = PrimitiveType.UInt16; } - | K_UNSIGNED K_INT32 {$$ = PrimitiveType.UInt32; } - | K_UNSIGNED K_INT64 {$$ = PrimitiveType.UInt64; } - | K_STRING {$$ = PrimitiveType.String; } - ; - -internal_type_ref : name1 + | 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 + { + GenericTypeSpec spec = new GenericTypeSpec ((int) $2); + $$ = new GenericTypeRef (spec, $2.ToString ()); + } + | BANG BANG int32 + { + MVar mvar = new MVar ((int) $3); + $$ = new GenericTypeRef (mvar, $3.ToString ()); + } + | K_CLASS slashed_name OPEN_ANGLE_BRACKET BANG int32 CLOSE_ANGLE_BRACKET + { + $$ = new TypeRef ((string) $2, false, null); + } + | K_CLASS slashed_name OPEN_ANGLE_BRACKET typars CLOSE_ANGLE_BRACKET + { + ArrayList typar_list = (ArrayList) $4; + ITypeRef[] typar_array = (ITypeRef[]) typar_list.ToArray (typeof (ITypeRef)); + + $$ = new GenericTypeInst ((string)$2, typar_array); + } + ; + +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 */ + { + // This is shortref for no lowerbound or size + $$ = new DictionaryEntry (TypeRef.Ellipsis, TypeRef.Ellipsis); + } + | ELLIPSIS + { + // No lower bound or size + $$ = new DictionaryEntry (TypeRef.Ellipsis, TypeRef.Ellipsis); + } + | 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 (TypeRef.Ellipsis, $1); + } + | int32 ELLIPSIS int32 + { + // lower bound and size + $$ = new DictionaryEntry ($1, $3); + } + | int32 ELLIPSIS + { + // Just lower bound + $$ = new DictionaryEntry ($1, TypeRef.Ellipsis); + } + ; + +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 ((string) $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 + { + $$ = $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.ToInt32 ($3)); + } + | K_INT16 OPEN_PARENS int64 CLOSE_PARENS + { + $$ = new IntConst (Convert.ToInt16 ($3)); + } + | K_CHAR OPEN_PARENS int64 CLOSE_PARENS + { + $$ = new CharConst (Convert.ToChar ($3)); + } + | K_WCHAR OPEN_PARENS int64 CLOSE_PARENS { - $$ = codegen.ClassTable.GetReference ((string) $1, null); + $$ = new CharConst (Convert.ToChar ($3)); } - ; - -external_type_ref : assembly_name namespace_name DOT id + | 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 bytes_list + { + $$ = new ByteArrConst ((byte[]) $2); + } + | comp_qstring + { + // ******** THIS IS NOT IN THE DOCUMENTATION ******** // + $$ = new StringConst ((string) $1); + } + | K_NULLREF + { + $$ = new NullConst (); + } + ; + +data_decl : data_head data_body + { + 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", false); + } + + } + | type ; -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 - ; - - -methodHeadPart1 : D_METHOD - { - /* - method = new Method (); - currentCallConv = 0; - */ - } - ; - -methodHead : methodHeadPart1 methAttr callConv paramAttr type methodName OPEN_PARENS arg_list CLOSE_PARENS implAttr OPEN_BRACE - { +scope_block : scope_block_begin method_decls CLOSE_BRACE + { + $$ = new HandlerBlock ((LabelInfo) $1, + codegen.CurrentMethodDef.AddLabel ()); + } + ; + +scope_block_begin : OPEN_BRACE + { + $$ = codegen.CurrentMethodDef.AddLabel (); + } + ; + + +seh_block : try_block seh_clauses + { + TryBlock try_block = (TryBlock) $1; + + ArrayList clause_list = (ArrayList) $2; + foreach (object clause in clause_list) + try_block.AddSehClause ((ISehClause) clause); + + codegen.CurrentMethodDef.AddInstr (try_block); + } + ; + +try_block : D_TRY scope_block + { + $$ = new TryBlock ((HandlerBlock) $2); + } + | D_TRY id K_TO id + { + LabelInfo from = codegen.CurrentMethodDef.AddLabelRef ((string) $2); + LabelInfo to = codegen.CurrentMethodDef.AddLabelRef ((string) $4); - /* - method.SetMethodName ($6 as MethodName); - method.SetParamList ($8 as ArrayList); - 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.Default; } - | fieldAttr K_STATIC {$$ = FieldAttr.Static; } - | fieldAttr K_PUBLIC {$$ = FieldAttr.Public; } - | fieldAttr K_PRIVATE {$$ = FieldAttr.Private; } - | fieldAttr K_FAMILY {$$ = FieldAttr.Family; } - | fieldAttr K_INITONLY {$$ = FieldAttr.Initonly; } - | fieldAttr K_RTSPECIALNAME {$$ = FieldAttr.RTSpecialName; } - | fieldAttr K_SPECIALNAME {$$ = FieldAttr.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 + $$ = new TryBlock (new HandlerBlock (from, to)); + } + | D_TRY int32 K_TO int32 + { + LabelInfo from = codegen.CurrentMethodDef.AddLabel ((int) $2); + LabelInfo to = codegen.CurrentMethodDef.AddLabel ((int) $4); - | fieldAttr K_MARSHAL OPEN_PARENS nativeType CLOSE_PARENS - */ - | fieldAttr K_ASSEMBLY {$$ = FieldAttr.Assembly; } - | fieldAttr K_FAMANDASSEM {$$ = FieldAttr.FamAndAssem; } - | fieldAttr K_FAMORASSEM {$$ = FieldAttr.FamOrAssem; } - /* | fieldAttr K_COMPILERCONTROLLED {$$ = FieldAttr. */ - | fieldAttr K_LITERAL {$$ = FieldAttr.Literal; } - | fieldAttr K_NOTSERIALIZED {$$ = FieldAttr.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 named_arg_list CLOSE_PARENS - { - /* - ArrayList arg_list = $4 as ArrayList; - - if (arg_list != null) { - foreach (DictionaryEntry local in arg_list) { - method.AddLocal (local); - } - } - */ - } - | 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 - | D_VTENTRY int32 COLON int32 - | D_OVERRIDE typeSpec DOUBLE_COLON methodName - | scopeBlock - | D_PARAM OPEN_BRACKET int32 CLOSE_BRACKET initOpt - ; - -scopeBlock : scopeOpen methodDecls CLOSE_BRACE - ; - -scopeOpen : OPEN_BRACE - ; - -sehBlock : tryBlock sehClauses - ; - -sehClauses : sehClause sehClauses - | sehClause - ; - -tryBlock : tryHead scopeBlock - | tryHead id K_TO id - | tryHead int32 K_TO int32 - ; - -tryHead : D_TRY - ; - - -sehClause : catchClause handlerBlock - | filterClause handlerBlock - | finallyClause handlerBlock - | faultClause handlerBlock - ; - - -filterClause : filterHead scopeBlock - | filterHead id - | filterHead int32 - ; - -filterHead : K_FILTER - ; - -catchClause : K_CATCH className - ; - -finallyClause : K_FINALLY - ; - -faultClause : K_FAULT - ; - -handlerBlock : scopeBlock - | K_HANDLER id K_TO id - | K_HANDLER int32 K_TO int32 - ; - - -methodDecls : /* EMPTY */ - | methodDecls methodDecl - ; - -dataDecl : ddHead ddBody - ; - -ddHead : D_DATA tls id ASSIGN - | D_DATA tls - ; - -tls : /* EMPTY */ - | K_TLS - ; - -ddBody : OPEN_BRACE ddItemList CLOSE_BRACE - | ddItem - ; - -ddItemList : ddItem COMMA ddItemList - | ddItem - ; - -ddItemCount : /* EMPTY */ - | OPEN_BRACKET int32 CLOSE_BRACKET - ; - -ddItem : K_CHAR STAR OPEN_PARENS compQstring CLOSE_PARENS - | AMPERSAND OPEN_PARENS id CLOSE_PARENS - | bytearrayhead bytes CLOSE_PARENS - | K_FLOAT32 OPEN_PARENS float64 CLOSE_PARENS ddItemCount - | K_FLOAT64 OPEN_PARENS float64 CLOSE_PARENS ddItemCount - | K_INT64 OPEN_PARENS int64 CLOSE_PARENS ddItemCount - | K_INT32 OPEN_PARENS int32 CLOSE_PARENS ddItemCount - | K_INT16 OPEN_PARENS int32 CLOSE_PARENS ddItemCount - | K_INT8 OPEN_PARENS int32 CLOSE_PARENS ddItemCount - | K_FLOAT32 ddItemCount - | K_FLOAT64 ddItemCount - | K_INT64 ddItemCount - | K_INT32 ddItemCount - | K_INT16 ddItemCount - | K_INT8 ddItemCount - ; - -fieldInit : K_FLOAT32 OPEN_PARENS float64 CLOSE_PARENS - | K_FLOAT64 OPEN_PARENS float64 CLOSE_PARENS - | K_FLOAT32 OPEN_PARENS int64 CLOSE_PARENS - | K_FLOAT64 OPEN_PARENS int64 CLOSE_PARENS - | K_INT64 OPEN_PARENS int64 CLOSE_PARENS - | K_INT32 OPEN_PARENS int64 CLOSE_PARENS - | K_INT16 OPEN_PARENS int64 CLOSE_PARENS - | K_CHAR OPEN_PARENS int64 CLOSE_PARENS - | K_INT8 OPEN_PARENS int64 CLOSE_PARENS - | K_BOOL OPEN_PARENS truefalse CLOSE_PARENS - | compQstring - | bytearrayhead bytes CLOSE_PARENS - | K_NULLREF - ; - -bytearrayhead : K_BYTEARRAY OPEN_PARENS - ; - - -hexbyte : INT32 - | id - ; - -bytes : /* EMPTY */ - | hexbytes - ; - -hexbytes : hexbyte - | hexbytes hexbyte - ; - -instr_r_head : INSTR_R OPEN_PARENS - ; - -methodSpec : K_METHOD + $$ = new TryBlock (new HandlerBlock (from, to)); + } ; -instr : INSTR_NONE {/* currentInstr = new InstrNone ((OpCode) $1);*/} - | INSTR_VAR int32 {/* currentInstr = new InstrVar ((OpCode) $1, $2);*/} - | INSTR_VAR id {/* currentInstr = new InstrVar ((OpCode) $1, $2); */} - | INSTR_I int32 {/* currentInstr = new InstrI ((OpCode) $1, (Int32) $2);*/} - | INSTR_I8 int64 {/* currentInstr = new InstrI8 ((OpCode) $1, (Int64) $2);*/} - | INSTR_R float64 {/* currentInstr = new InstrR ((OpCode) $1, (Double) $2);*/} - | INSTR_R int64 {/* currentInstr = new InstrR ((OpCode) $1, (Int64) $2);*/} - | instr_r_head bytes CLOSE_PARENS - | INSTR_BRTARGET int32 - | INSTR_BRTARGET id - | INSTR_METHOD binding_flags type full_type DOUBLE_COLON call_name OPEN_PARENS arg_list CLOSE_PARENS +seh_clauses : seh_clause + { + ArrayList clause_list = new ArrayList (); + clause_list.Add ($1); + $$ = clause_list; + } + | seh_clauses seh_clause + { + ArrayList clause_list = (ArrayList) $1; + clause_list.Add ($2); + } + ; + +seh_clause : K_CATCH class_ref handler_block + { + IClassRef type = (IClassRef) $2; + CatchBlock cb = new CatchBlock (type); + cb.SetHandlerBlock ((HandlerBlock) $3); + $$ = cb; + } + | K_FINALLY handler_block + { + FinallyBlock fb = new FinallyBlock (); + fb.SetHandlerBlock ((HandlerBlock) $2); + $$ = fb; + } + | K_FAULT handler_block + { + FaultBlock fb = new FaultBlock (); + fb.SetHandlerBlock ((HandlerBlock) $2); + $$ = fb; + } + | filter_clause handler_block + { + FilterBlock fb = (FilterBlock) $1; + fb.SetHandlerBlock ((HandlerBlock) $2); + } + ; + +filter_clause : K_FILTER scope_block + { + HandlerBlock block = (HandlerBlock) $2; + FilterBlock fb = new FilterBlock (block); + $$ = fb; + } + | K_FILTER id + { + LabelInfo from = codegen.CurrentMethodDef.AddLabelRef ((string) $2); + FilterBlock fb = new FilterBlock (new HandlerBlock (from, null)); + $$ = fb; + } + | K_FILTER int32 { - /* - if (OpCodes.Call.Equals ((OpCode)$1) || OpCodes.Callvirt.Equals ((OpCode)$1)) { - currentInstr = new InstrCall ((OpCode) $1, (string)$2, (string)$3, - (string)$4, (string)$6, $8 as ArrayList); - } else if (OpCodes.Newobj.Equals ((OpCode)$1)) { - currentInstr = new InstrNewobj ((OpCode) $1, (string)$2, (string)$3, - (string)$4, (string)$6, $8 as ArrayList); - } - */ + LabelInfo from = codegen.CurrentMethodDef.AddLabel ((int) $2); + FilterBlock fb = new FilterBlock (new HandlerBlock (from, null)); + $$ = fb; } - - - | INSTR_METHOD callConv type methodName OPEN_PARENS sigArgs0 CLOSE_PARENS - { - - } - | INSTR_NEWOBJ callConv type assembly_name name1 DOUBLE_COLON call_name OPEN_PARENS signature_args CLOSE_PARENS - { - - } - | INSTR_FIELD type typeSpec DOUBLE_COLON id - | INSTR_FIELD type id - | INSTR_TYPE typeSpec - | INSTR_STRING compQstring - { - /* currentInstr = new InstrString ((OpCode) $1, $2 as string); */ - } - | INSTR_STRING bytearrayhead bytes CLOSE_PARENS - | INSTR_SIG callConv type OPEN_PARENS sigArgs0 CLOSE_PARENS - | INSTR_RVA id - | INSTR_RVA int32 - | INSTR_TOK methodSpec callConv type typeSpec DOUBLE_COLON methodName OPEN_PARENS sigArgs0 CLOSE_PARENS - | INSTR_TOK methodSpec callConv type methodName OPEN_PARENS sigArgs0 CLOSE_PARENS - | INSTR_TOK K_FIELD type typeSpec DOUBLE_COLON id - | INSTR_TOK K_FIELD type id - | INSTR_TOK typeSpec - | INSTR_SWITCH OPEN_PARENS labels CLOSE_PARENS - | INSTR_PHI int16s - ; - -full_type - : type - | ID { $$ = $1; } - | assembly_name name1 { $$ = String.Format ("[{0}]{1}", $1, $2); } - ; - -arg_list - : /* EMPTY */ - | full_type - { - ArrayList arg_list = new ArrayList (); - arg_list.Add ($1); - - $$ = arg_list; - } - | arg_list COMMA type - { - ArrayList arg_list = (ArrayList) $1; - arg_list.Add ($3); - - $$ = arg_list; - } - ; - -named_arg - : full_type ID - { - $$ = new DictionaryEntry ((string) $1, (string) $2); - } - ; - -named_arg_list - : /* EMPTY */ - | named_arg - { - ArrayList arg_list = new ArrayList (); - arg_list.Add ($1); - - $$ = arg_list; - } - | named_arg_list COMMA named_arg - { - ArrayList arg_list = (ArrayList) $1; - arg_list.Add ($3); - - $$ = arg_list; - } - ; - - -signature_args : /* EMPTY */ - | type - | type COMMA signature_args - ; - -binding_flags : /* EMPTY */ - | K_INSTANCE ; -sigArgs0 : /* EMPTY */ - | sigArgs1 - ; - -sigArgs1 : sigArg - | sigArgs1 COMMA sigArg { $$ = String.Format ("{0},{1}", $1, $2); } - ; - -sigArg : ELLIPSIS - | paramAttr type - | paramAttr type id { $$ = String.Format ("{0} {1}", $2, $3); } - | paramAttr type K_MARSHAL OPEN_PARENS nativeType CLOSE_PARENS - | paramAttr type K_MARSHAL OPEN_PARENS nativeType CLOSE_PARENS id -sint ; - +handler_block : scope_block + { + + } + | K_HANDLER id K_TO id + { + LabelInfo from = codegen.CurrentMethodDef.AddLabelRef ((string) $2); + LabelInfo to = codegen.CurrentMethodDef.AddLabelRef ((string) $4); + + $$ = new HandlerBlock (from, to); + } + | K_HANDLER int32 K_TO int32 + { + LabelInfo from = codegen.CurrentMethodDef.AddLabelRef ((string) $2); + LabelInfo to = codegen.CurrentMethodDef.AddLabelRef ((string) $4); -dottedName : id DOT id {$$ = ($1 as string) + "." + ($3 as string);} + $$ = new HandlerBlock (from, to); + } ; - -name1 : id - | dottedName - | name1 DOT name1 {$$ = String.Format ("{0}.{1}", $1, $3); } +instr : INSTR_NONE + { + codegen.CurrentMethodDef.AddInstr ( + new SimpInstr ((Op) $1)); + } + | INSTR_LOCAL int32 + { + codegen.CurrentMethodDef.AddInstr ( + new IntInstr ((IntOp) $1, (int) $2)); + } + | INSTR_LOCAL id + { + int slot = codegen.CurrentMethodDef.GetNamedLocalSlot ((string) $2); + codegen.CurrentMethodDef.AddInstr ( + new IntInstr ((IntOp) $1, slot)); + } + | INSTR_PARAM int32 + { + codegen.CurrentMethodDef.AddInstr ( + new IntInstr ((IntOp) $1, (int) $2)); + } + | INSTR_PARAM id + { + int pos = codegen.CurrentMethodDef.GetNamedParamPos ((string) $2); + codegen.CurrentMethodDef.AddInstr ( + new IntInstr ((IntOp) $1, pos)); + } + | INSTR_I int32 + { + codegen.CurrentMethodDef.AddInstr (new + IntInstr ((IntOp) $1, (int) $2)); + } + | INSTR_I id + { + int slot = codegen.CurrentMethodDef.GetNamedLocalSlot ((string) $2); + codegen.CurrentMethodDef.AddInstr (new + IntInstr ((IntOp) $1, slot)); + } + | INSTR_I8 int64 + { + if ($1 is MiscInstr) { + switch ((MiscInstr) $1) { + case MiscInstr.ldc_i8: + codegen.CurrentMethodDef.AddInstr (new LdcInstr ((MiscInstr) $1, + (long) $2)); + break; + } + } + } + | INSTR_R float64 + { + switch ((MiscInstr) $1) { + case MiscInstr.ldc_r4: + case MiscInstr.ldc_r8: + codegen.CurrentMethodDef.AddInstr (new LdcInstr ((MiscInstr) $1, (double) $2)); + break; + } + } + | INSTR_R int64 + { + long l = (long) $2; + + switch ((MiscInstr) $1) { + case MiscInstr.ldc_r4: + case MiscInstr.ldc_r8: + codegen.CurrentMethodDef.AddInstr (new LdcInstr ((MiscInstr) $1, (double) l)); + break; + } + } + | INSTR_R bytes_list + | INSTR_BRTARGET int32 + { + LabelInfo target = codegen.CurrentMethodDef.AddLabel ((int) $2); + codegen.CurrentMethodDef.AddInstr (new BranchInstr ((BranchOp) $1, + target)); + } + | INSTR_BRTARGET id + { + LabelInfo target = codegen.CurrentMethodDef.AddLabelRef ((string) $2); + codegen.CurrentMethodDef.AddInstr (new BranchInstr ((BranchOp) $1, + target)); + } + | INSTR_METHOD method_ref + { + codegen.CurrentMethodDef.AddInstr (new MethodInstr ((MethodOp) $1, + (IMethodRef) $2)); + } + | INSTR_FIELD type type_spec DOUBLE_COLON id + { + + ITypeRef owner = (ITypeRef) $3; + IFieldRef fieldref = owner.GetFieldRef ( + (ITypeRef) $2, (string) $5); + + codegen.CurrentMethodDef.AddInstr (new FieldInstr ((FieldOp) $1, fieldref)); + } + | INSTR_FIELD type id + { + GlobalFieldRef fieldref = new GlobalFieldRef ((ITypeRef) $2, (string) $3); + + codegen.CurrentMethodDef.AddInstr (new FieldInstr ((FieldOp) $1, fieldref)); + } + | INSTR_TYPE type_spec + { + codegen.CurrentMethodDef.AddInstr (new TypeInstr ((TypeOp) $1, + (ITypeRef) $2)); + } + | INSTR_STRING comp_qstring + { + if ((MiscInstr) $1 == MiscInstr.ldstr) + codegen.CurrentMethodDef.AddInstr (new LdstrInstr ((string) $2)); + } + | INSTR_STRING K_BYTEARRAY ASSIGN bytes_list + { + byte[] bs = (byte[]) $4; + if ((MiscInstr) $1 == MiscInstr.ldstr) + codegen.CurrentMethodDef.AddInstr (new LdstrInstr (bs)); + } + | INSTR_STRING K_BYTEARRAY bytes_list + { + byte[] bs = (byte[]) $3; + if ((MiscInstr) $1 == MiscInstr.ldstr) + codegen.CurrentMethodDef.AddInstr (new LdstrInstr (bs)); + } + | INSTR_SIG call_conv type OPEN_PARENS type_list CLOSE_PARENS + { + ArrayList arg_list = (ArrayList) $5; + ITypeRef[] arg_array = null; + + if (arg_list != null) + arg_array = (ITypeRef[]) arg_list.ToArray (typeof (ITypeRef)); + + codegen.CurrentMethodDef.AddInstr (new CalliInstr ((CallConv) $2, + (ITypeRef) $3, arg_array)); + } + | INSTR_TOK owner_type + { + if ((MiscInstr) $1 == MiscInstr.ldtoken) { + if ($2 is IMethodRef) + codegen.CurrentMethodDef.AddInstr (new LdtokenInstr ((IMethodRef) $2)); + else if ($2 is IFieldRef) + codegen.CurrentMethodDef.AddInstr (new LdtokenInstr ((IFieldRef) $2)); + else + codegen.CurrentMethodDef.AddInstr (new LdtokenInstr ((ITypeRef) $2)); + + } + } + | INSTR_SWITCH OPEN_PARENS labels CLOSE_PARENS + { + codegen.CurrentMethodDef.AddInstr (new SwitchInstr ((ArrayList) $3)); + } + ; + +method_ref : call_conv type type_spec DOUBLE_COLON method_name + OPEN_PARENS type_list CLOSE_PARENS + { + ITypeRef owner = (ITypeRef) $3; + ArrayList arg_list = (ArrayList) $7; + ITypeRef[] param_list; + IMethodRef methref; + + if (arg_list != null) + param_list = (ITypeRef[]) arg_list.ToArray (typeof (ITypeRef)); + else + param_list = new ITypeRef[0]; + + if (owner.UseTypeSpec) { + methref = new TypeSpecMethodRef (owner, (ITypeRef) $2, + (CallConv) $1, (string) $5, param_list); + } else { + methref = owner.GetMethodRef ((ITypeRef) $2, + (CallConv) $1, (string) $5, param_list); + } + + $$ = methref; + } + | call_conv type method_name + OPEN_PARENS type_list CLOSE_PARENS + { + ArrayList arg_list = (ArrayList) $5; + ITypeRef[] param_list; + + if (arg_list != null) + param_list = (ITypeRef[]) arg_list.ToArray (typeof (ITypeRef)); + else + param_list = new ITypeRef[0]; + + $$ = new GlobalMethodRef ((ITypeRef) $2, (CallConv) $1, + (string) $3, param_list); + } + | call_conv type type_spec DOUBLE_COLON method_name + typars_clause OPEN_PARENS type_list CLOSE_PARENS + { + ITypeRef owner = (ITypeRef) $3; + ArrayList arg_list = (ArrayList) $8; + ITypeRef[] param_list; + IMethodRef methref; + + if (arg_list != null) + param_list = (ITypeRef[]) arg_list.ToArray (typeof (ITypeRef)); + else + param_list = new ITypeRef[0]; + + if (owner.UseTypeSpec) { + methref = new TypeSpecMethodRef (owner, (ITypeRef) $2, + (CallConv) $1, (string) $5, param_list); + } else { + methref = owner.GetMethodRef ((ITypeRef) $2, + (CallConv) $1, (string) $5, param_list); + } + + if ($6 != null) { + ArrayList tp = (ArrayList) $6; + ITypeRef[] ta = (ITypeRef[]) tp.ToArray (typeof (ITypeRef)); + + methref = new GenericMethodRef (methref, new GenericMethodSig (ta)); + } + + $$ = methref; + } ; -call_name : +labels : /* EMPTY */ | id - | D_CTOR - | D_CCTOR + { + ArrayList label_list = new ArrayList (); + label_list.Add ($1); + $$ = label_list; + } + | int32 + { + ArrayList label_list = new ArrayList (); + label_list.Add ($1); + $$ = label_list; + } + | labels COMMA id + { + ArrayList label_list = (ArrayList) $1; + label_list.Add ($3); + } + | labels COMMA int32 + { + ArrayList label_list = (ArrayList) $1; + label_list.Add ($3); + } + ; + +owner_type : type_spec + | member_ref + ; + +member_ref : K_METHOD method_ref + { + $$ = $2; + } + | K_FIELD type type_spec DOUBLE_COLON id + { + ITypeRef owner = (ITypeRef) $3; + + $$ = owner.GetFieldRef ( + (ITypeRef) $2, (string) $5); + } + | K_FIELD type id + { + $$ = new GlobalFieldRef ((ITypeRef) $2, (string) $3); + } + ; + +event_all : event_head OPEN_BRACE event_decls CLOSE_BRACE + { + codegen.CurrentTypeDef.EndEventDef (); + } + ; + +event_head : D_EVENT event_attr type_spec id + { + EventDef event_def = new EventDef ((FeatureAttr) $2, + (ITypeRef) $3, (string) $4); + codegen.CurrentTypeDef.BeginEventDef (event_def); + } + | D_EVENT event_attr id + ; + +event_attr : /* EMPTY */ + { + $$ = new FeatureAttr (); + } + | event_attr K_RTSPECIALNAME + { + $$ = (FeatureAttr) $1 & FeatureAttr.Rtspecialname; + } + | event_attr K_SPECIALNAME + { + $$ = (FeatureAttr) $1 & FeatureAttr.Specialname; + } + ; + +event_decls : /* EMPTY */ + | event_decls event_decl + ; + +event_decl : D_ADDON method_ref + { + codegen.CurrentTypeDef.CurrentEvent.AddAddon ( + (MethodRef) $2); + } + | D_REMOVEON method_ref + { + codegen.CurrentTypeDef.CurrentEvent.AddRemoveon ( + (MethodRef) $2); + } + | D_FIRE method_ref + { + codegen.CurrentTypeDef.CurrentEvent.AddFire ( + (MethodRef) $2); + } + | D_OTHER method_ref + { + codegen.CurrentTypeDef.CurrentEvent.AddOther ( + (MethodRef) $2); + } + | customattr_decl + | extsource_spec + | language_decl + ; + +prop_all : prop_head OPEN_BRACE prop_decls CLOSE_BRACE + { + codegen.CurrentTypeDef.EndPropertyDef (); + } + ; + +prop_head : D_PROPERTY prop_attr type id OPEN_PARENS type_list CLOSE_PARENS init_opt + { + PropertyDef prop_def = new PropertyDef ((FeatureAttr) $2, (ITypeRef) $3, + (string) $4, (ArrayList) $6); + codegen.CurrentTypeDef.BeginPropertyDef (prop_def); + + if ($8 != null) { + prop_def.AddInitValue ((Constant) $8); + } + } + ; + +prop_attr : /* EMPTY */ + { + $$ = new FeatureAttr (); + } + | prop_attr K_RTSPECIALNAME + { + $$ = (FeatureAttr) $1 | FeatureAttr.Rtspecialname; + } + | prop_attr K_SPECIALNAME + { + $$ = (FeatureAttr) $1 | FeatureAttr.Specialname; + } + | prop_attr K_INSTANCE + { + } + ; + +prop_decls : /* EMPTY */ + | prop_decls prop_decl + ; + +prop_decl : D_SET method_ref + { + codegen.CurrentTypeDef.CurrentProperty.AddSet ((MethodRef) $2); + } + | D_GET method_ref + { + codegen.CurrentTypeDef.CurrentProperty.AddGet ((MethodRef) $2); + } + | D_OTHER method_ref + { + codegen.CurrentTypeDef.CurrentProperty.AddOther ((MethodRef) $2); + } + | customattr_decl + | extsource_spec + | language_decl + ; + +customattr_decl : D_CUSTOM custom_type + { + $$ = new CustomAttr ((IMethodRef) $2, null); + } + | D_CUSTOM custom_type ASSIGN comp_qstring + | D_CUSTOM custom_type ASSIGN bytes_list + { + $$ = new CustomAttr ((IMethodRef) $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 ; -assembly_ref : id - | id DASH id {$$ = String.Format ("{0}-{1}", $1, $3);} - | id DASH assembly_ref {$$ = String.Format ("{0}-{1}", $1, $3);} - ; - -assembly_name : OPEN_BRACKET assembly_ref CLOSE_BRACKET {$$ = ($2 as string);} - ; - -className : OPEN_BRACKET name1 CLOSE_BRACKET slashedName - | OPEN_BRACKET D_MODULE name1 CLOSE_BRACKET slashedName - | slashedName - ; - -slashedName : name1 - | slashedName SLASH name1 {$$ = ($1 as string) + "/" + ($3 as string);} - ; - -typeSpec : className - | OPEN_BRACKET name1 CLOSE_BRACKET - | OPEN_BRACKET D_MODULE name1 CLOSE_BRACKET - | type - ; - -callConv : K_INSTANCE callConv { /* currentCallConv |= CallingConventions.HasThis; */} - | K_EXPLICIT callConv { /* currentCallConv |= CallingConventions.ExplicitThis; */} - | callKind - ; - -callKind : /* EMPTY */ - | K_DEFAULT { /* currentCallConv |= CallingConventions.Standard; */} - | K_VARARG { /* currentCallConv |= CallingConventions.VarArgs; */} - | K_UNMANAGED K_CDECL - | K_UNMANAGED K_STALL - | K_UNMANAGED K_THISCALL - | K_UNMANAGED K_FASTCALL - ; - -nativeType : /* EMPTY */ - | K_CUSTOM OPEN_PARENS compQstring COMMA compQstring COMMA compQstring COMMA compQstring CLOSE_PARENS - | K_CUSTOM OPEN_PARENS compQstring COMMA compQstring CLOSE_PARENS - | K_FIXED K_SYSSTRING OPEN_BRACKET int32 CLOSE_BRACKET - | K_FIXED K_ARRAY OPEN_BRACKET int32 CLOSE_BRACKET - | K_VARIANT - | K_CURRENCY - | K_SYSCHAR - | K_VOID - | K_BOOL - | K_INT8 - | K_INT16 - | K_INT32 - | K_INT64 - | K_FLOAT32 - | K_FLOAT64 - | K_ERROR - | K_UNSIGNED K_INT8 - | K_UNSIGNED K_INT16 - | K_UNSIGNED K_INT32 - | K_UNSIGNED K_INT64 - | nativeType STAR - | nativeType OPEN_BRACKET CLOSE_BRACKET - | nativeType OPEN_BRACKET int32 CLOSE_BRACKET - | nativeType OPEN_BRACKET int32 PLUS int32 CLOSE_BRACKET - | nativeType OPEN_BRACKET PLUS int32 CLOSE_BRACKET - | K_DECIMAL - | K_DATE - | K_BSTR - | K_LPSTR - | K_LPWSTR - | K_LPTSTR - | K_OBJECTREF - | K_IUNKNOWN - | K_IDISPATCH - | K_STRUCT - | K_INTERFACE - | K_SAFEARRAY variantType - | K_INT - | K_UNSIGNED K_INT - | K_NESTED K_STRUCT - | K_BYVALSTR - | K_ANSI K_BSTR - | K_TBSTR - | K_VARIANT K_BOOL - | methodSpec - | K_AS K_ANY - | K_LPSTRUCT - ; - -variantType : /* 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 - | variantType OPEN_BRACKET CLOSE_BRACKET - | variantType K_VECTOR - | variantType 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 - ; - -type : K_CLASS className - | K_OBJECT - | K_STRING - | K_VALUE K_CLASS className - | K_VALUETYPE className - | type OPEN_BRACKET CLOSE_BRACKET - | type OPEN_BRACKET bounds1 CLOSE_BRACKET - /* uncomment when and if this type is supported by the Runtime - | type K_VALUE OPEN_BRACKET int32 CLOSE_BRACKET - */ - | type AMPERSAND - | type STAR - | type K_PINNED - | type K_MODREQ OPEN_PARENS className CLOSE_PARENS - | type K_MODOPT OPEN_PARENS className CLOSE_PARENS - | BANG int32 - | methodSpec callConv type STAR OPEN_PARENS sigArgs0 CLOSE_PARENS - | K_TYPEDREF - | K_CHAR - | K_VOID - | K_BOOL - | K_INT8 - | K_INT16 - | K_INT32 - | K_INT64 - | K_FLOAT32 - | K_FLOAT64 - | K_UNSIGNED K_INT8 {$$ = "uint8";} - | K_UNSIGNED K_INT16 {$$ = "uint16";} - | K_UNSIGNED K_INT32 {$$ = "uint32";} - | K_UNSIGNED K_INT64 {$$ = "uint64";} - | K_NATIVE K_INT - | K_NATIVE K_UNSIGNED K_INT - | K_NATIVE K_FLOAT - ; - -bounds1 : bound - | bounds1 COMMA bound - ; - -bound : /* EMPTY */ - | ELLIPSIS - | int32 - | int32 ELLIPSIS int32 - | int32 ELLIPSIS - ; - -labels : /* empty */ - | id COMMA labels - | int32 COMMA labels - | id - | int32 - ; - - -id : ID - | SQSTRING - ; - -int16s : /* EMPTY */ - | int16s int32 - ; - -int32 : INT32 /* NOTE: it's INT64 in docs */ - ; - -int64 : INT64 - ; - -float64 : FLOAT64 - | K_FLOAT32 OPEN_PARENS int32 CLOSE_PARENS - | K_FLOAT64 OPEN_PARENS int64 CLOSE_PARENS - ; - -secDecl : D_PERMISSION secAction typeSpec OPEN_PARENS nameValPairs CLOSE_PARENS - | D_PERMISSION secAction typeSpec - | psetHead bytes CLOSE_PARENS - ; - -psetHead : D_PERMISSIONSET secAction ASSIGN OPEN_PARENS - ; - -nameValPairs : nameValPair - | nameValPair COMMA nameValPairs - ; - -nameValPair : compQstring ASSIGN caValue - ; - -truefalse : K_TRUE - | K_FALSE - ; - -caValue : truefalse - | int32 - | K_INT32 OPEN_PARENS int32 CLOSE_PARENS - | compQstring - | className OPEN_PARENS K_INT8 COLON int32 CLOSE_PARENS - | className OPEN_PARENS K_INT16 COLON int32 CLOSE_PARENS - | className OPEN_PARENS K_INT32 COLON int32 CLOSE_PARENS - | className OPEN_PARENS int32 CLOSE_PARENS +custom_type : call_conv type type_spec DOUBLE_COLON D_CTOR OPEN_PARENS type_list CLOSE_PARENS + { + ITypeRef owner = (ITypeRef) $3; + ArrayList arg_list = (ArrayList) $7; + ITypeRef[] param_list; + + if (arg_list != null) + param_list = (ITypeRef[]) arg_list.ToArray (typeof (ITypeRef)); + else + param_list = new ITypeRef[0]; + + $$ = owner.GetMethodRef ((ITypeRef) $2, + (CallConv) $1, (string) $5, param_list); + } + | call_conv type D_CTOR OPEN_PARENS type_list CLOSE_PARENS + { + ArrayList arg_list = (ArrayList) $5; + ITypeRef[] param_list; + + if (arg_list != null) + param_list = (ITypeRef[]) arg_list.ToArray (typeof (ITypeRef)); + else + param_list = new ITypeRef[0]; + + $$ = new GlobalMethodRef ((ITypeRef) $2, (CallConv) $1, + (string) $3, param_list); + } + ; + +sec_decl : D_PERMISSION sec_action type_spec OPEN_PARENS nameval_pairs CLOSE_PARENS + | D_PERMISSION sec_action type_spec + | D_PERMISSIONSET sec_action ASSIGN bytes_list + ; + +nameval_pairs : nameval_pair + | nameval_pairs COMMA nameval_pair + ; + +nameval_pair : comp_qstring ASSIGN cavalue + ; + +cavalue : truefalse + | int32 + | int32 OPEN_PARENS int32 CLOSE_PARENS + | comp_qstring + | class_ref OPEN_PARENS K_INT8 COLON int32 CLOSE_PARENS + | class_ref OPEN_PARENS K_INT16 COLON int32 CLOSE_PARENS + | class_ref OPEN_PARENS K_INT32 COLON int32 CLOSE_PARENS + | class_ref OPEN_PARENS int32 CLOSE_PARENS + ; + +sec_action : K_REQUEST + | K_DEMAND + | K_ASSERT + | K_DENY + | K_PERMITONLY + | K_LINKCHECK + | K_INHERITCHECK + | K_REQMIN + | K_REQOPT + | K_REQREFUSE + | K_PREJITGRANT + | K_PREJITDENY + | K_NONCASDEMAND + | K_NONCASLINKDEMAND + | K_NONCASINHERITANCE + ; + +module_head : D_MODULE + { + } + | D_MODULE comp_name + { + codegen.SetModuleName ((string) $2); + } + | D_MODULE K_EXTERN comp_name + { + codegen.ExternTable.AddModule ((string) $3); + } + ; + +file_decl : D_FILE file_attr comp_name file_entry D_HASH ASSIGN + bytes_list file_entry + { + codegen.SetFileRef (new FileRef ((string) $3, (byte []) $7, (bool) $2, (bool) $8)); + } + | D_FILE file_attr comp_name file_entry + { + // We need to compute the hash ourselves. :-( + // AssemblyName an = AssemblyName.GetName ((string) $3); + } + ; + +file_attr : /* EMPTY */ + { + $$ = true; + } + | file_attr K_NOMETADATA + { + $$ = false; + } + ; + +file_entry : /* EMPTY */ + { + $$ = false; + } + | D_ENTRYPOINT + { + $$ = true; + } + ; + +assembly_all : assembly_head OPEN_BRACE assembly_decls CLOSE_BRACE ; -secAction : K_REQUEST - | K_DEMAND - | K_ASSERT - | K_DENY - | K_PERMITONLY - | K_LINKCHECK - | K_INHERITCHECK - | K_REQMIN - | K_REQOPT - | K_REQREFUSE - | K_PREJITGRANT - | K_PREJITDENY - | K_NONCASDEMAND - | K_NONCASLINKDEMAND - | K_NONCASINHERITANCE +assembly_head : D_ASSEMBLY asm_attr slashed_name + { + codegen.SetAssemblyName ((string) $3); + } ; -extSourceSpec : D_LINE int32 SQSTRING - | D_LINE int32 - | D_XLINE int32 QSTRING +asm_attr : /* EMPTY */ + | asm_attr K_NOAPPDOMAIN + | asm_attr K_NOPROCESS + | asm_attr K_NOMACHINE ; -fileDecl : D_FILE fileAttr name1 fileEntry hashHead bytes CLOSE_PARENS fileEntry - | D_FILE fileAttr name1 fileEntry +assembly_decls : /* EMPTY */ + | assembly_decls assembly_decl ; -fileAttr : /* EMPTY */ - | fileAttr K_NOMETADATA +assembly_decl : D_PUBLICKEY ASSIGN bytes_list + { + codegen.SetAssemblyPublicKey ((byte []) $3); + } + | D_VER int32 COLON int32 COLON int32 COLON int32 + { + codegen.SetAssemblyVersion ((int) $2, (int) $4, (int) $6, (int) $8); + } + | D_LOCALE comp_qstring + { + codegen.SetAssemblyLocale ((string) $2); + } + | D_LOCALE ASSIGN bytes_list + | D_HASH K_ALGORITHM int32 + { + codegen.SetAssemblyHashAlgorithm ((int) $3); + } + | customattr_decl + { + codegen.AddAssemblyCustomAttribute ((CustomAttr) $1); + } + | sec_decl ; -fileEntry : /* EMPTY */ - | D_ENTRYPOINT +asm_or_ref_decl : D_PUBLICKEY ASSIGN bytes_list + | D_VER int32 COLON int32 COLON int32 COLON int32 + | D_LOCALE comp_qstring + | D_LOCALE ASSIGN bytes_list + | customattr_decl + ; + +assemblyref_all : assemblyref_head OPEN_BRACE assemblyref_decls CLOSE_BRACE + ; + +assemblyref_head : D_ASSEMBLY K_EXTERN slashed_name + { + System.Reflection.AssemblyName asmb_name = + new System.Reflection.AssemblyName (); + asmb_name.Name = (string) $3; + codegen.BeginAssemblyRef ((string) $3, asmb_name); + } + | D_ASSEMBLY K_EXTERN slashed_name K_AS slashed_name + { + System.Reflection.AssemblyName asmb_name = + new System.Reflection.AssemblyName (); + asmb_name.Name = (string) $3; + codegen.BeginAssemblyRef ((string) $5, asmb_name); + } + ; + +assemblyref_decls : /* EMPTY */ + | assemblyref_decls assemblyref_decl + ; + +assemblyref_decl : D_VER int32 COLON int32 COLON int32 COLON int32 + { + codegen.CurrentAssemblyRef.SetVersion ((int) $2, (int) $4, (int) $6, (int) $8); + } + | D_PUBLICKEY ASSIGN bytes_list + { + codegen.CurrentAssemblyRef.SetPublicKey ((byte []) $3); + } + | D_PUBLICKEYTOKEN ASSIGN bytes_list + { + codegen.CurrentAssemblyRef.SetPublicKeyToken ((byte []) $3); + } + | D_LOCALE comp_qstring + { + codegen.CurrentAssemblyRef.SetLocale ((string) $2); + } + | D_LOCALE ASSIGN bytes_list + + | D_HASH ASSIGN bytes_list + { + codegen.CurrentAssemblyRef.SetHash ((byte []) $3); + } + | customattr_decl + { + codegen.CurrentAssemblyRef.AddCustomAttribute ((CustomAttr) $1); + } ; -hashHead : D_HASH ASSIGN OPEN_PARENS +exptype_all : exptype_head OPEN_BRACE exptype_decls CLOSE_BRACE ; -assemblyHead : D_ASSEMBLY asmAttr name1 - { - /* - // TODO: set assembly attrs - codegen.SetName ($3 as string); - */ - } +exptype_head : D_CLASS K_EXTERN expt_attr comp_name ; -asmAttr : /* EMPTY */ - | asmAttr K_NOAPPDOMAIN - | asmAttr K_NOPROCESS - | asmAttr K_NOMACHINE +expt_attr : /* EMPTY */ + | expt_attr K_PRIVATE + | expt_attr K_PUBLIC + | expt_attr K_NESTED K_PUBLIC + | expt_attr K_NESTED K_PRIVATE + | expt_attr K_NESTED K_FAMILY + | expt_attr K_NESTED K_ASSEMBLY + | expt_attr K_NESTED K_FAMANDASSEM + | expt_attr K_NESTED K_FAMORASSEM ; -assemblyDecls : /* EMPTY */ - | assemblyDecls assemblyDecl +exptype_decls : /* EMPTY */ + | exptype_decls exptype_decl ; -assemblyDecl : D_HASH K_ALGORITHM int32 - | secDecl - | asmOrRefDecl +exptype_decl : D_FILE comp_name + | D_CLASS K_EXTERN comp_name + | D_CLASS int32 + | customattr_decl ; -asmOrRefDecl : publicKeyHead bytes CLOSE_PARENS - | D_VER int32 COLON int32 COLON int32 COLON int32 - | D_LOCALE compQstring - | localeHead bytes CLOSE_PARENS - | D_PROCESSOR int32 - | D_OS int32 D_VER int32 COLON int32 - | customAttrDecl +manifestres_all : manifestres_head OPEN_BRACE manifestres_decls CLOSE_BRACE ; -publicKeyHead : D_PUBLICKEY ASSIGN OPEN_PARENS +manifestres_head : D_MRESOURCE manres_attr comp_name ; -publicKeyTokenHead : D_PUBLICKEYTOKEN ASSIGN OPEN_PARENS +manres_attr : /* EMPTY */ + | manres_attr K_PUBLIC + | manres_attr K_PRIVATE ; -localeHead : D_LOCALE ASSIGN OPEN_PARENS +manifestres_decls : /* EMPTY */ + | manifestres_decls manifestres_decl ; -assemblyRefHead : D_ASSEMBLY K_EXTERN name1 +manifestres_decl : D_FILE comp_name K_AT int32 + | D_ASSEMBLY K_EXTERN slashed_name + | customattr_decl ; -assemblyRefDecls : /* EMPTY */ - | assemblyRefDecls assemblyRefDecl +comp_qstring : QSTRING + | comp_qstring PLUS QSTRING { $$ = String.Format ("{0}{1}", $1, $3); } ; -assemblyRefDecl : hashHead bytes CLOSE_PARENS - | asmOrRefDecl - | publicKeyTokenHead bytes CLOSE_PARENS +int32 : INT64 + { + long l = (long) $1; + byte[] intb = BitConverter.GetBytes (l); + $$ = BitConverter.ToInt32 (intb, BitConverter.IsLittleEndian ? 0 : 4); + } ; -comtypeHead : D_CLASS K_EXTERN comtAttr name1 +int64 : INT64 ; -exportHead : D_EXPORT comtAttr name1 +float64 : FLOAT64 + | K_FLOAT32 OPEN_PARENS INT32 CLOSE_PARENS + { + int i = (int) $3; + byte[] intb = BitConverter.GetBytes (i); + $$ = (double) BitConverter.ToSingle (intb, BitConverter.IsLittleEndian ? 0 : 4); + } + | K_FLOAT32 OPEN_PARENS INT64 CLOSE_PARENS + { + long l = (long) $3; + byte[] intb = BitConverter.GetBytes (l); + $$ = (double) BitConverter.ToSingle (intb, BitConverter.IsLittleEndian ? 0 : 4); + } + | K_FLOAT64 OPEN_PARENS INT64 CLOSE_PARENS + { + byte[] intb = BitConverter.GetBytes ((long) $3); + $$ = BitConverter.ToDouble (intb, BitConverter.IsLittleEndian ? 0 : 4); + } + | K_FLOAT64 OPEN_PARENS INT32 CLOSE_PARENS + { + byte[] intb = BitConverter.GetBytes ((int) $3); + $$ = (double) BitConverter.ToSingle (intb, BitConverter.IsLittleEndian ? 0 : 4); + } ; -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 +hexbyte : HEXBYTE { } ; -comtypeDecls : /* EMPTY */ - | comtypeDecls comtypeDecl - ; +bytes_list : OPEN_PARENS + { + tokenizer.InByteArray = true; + } + bytes CLOSE_PARENS + { + $$ = $3; + tokenizer.InByteArray = false; + } + ; -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 + { + $$ = true; + } + | K_FALSE + { + $$ = 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; + } + | COMP_NAME ; - - %% -} // namespace Mono.ILASM +} +