private string pinvoke_mod;\r
private string pinvoke_meth;\r
private PEAPI.PInvokeAttr pinvoke_attr;\r
- private StreamReader stream;\r
+ private ILTokenizer tokenizer;\r
\r
- public ILParser (CodeGen codegen, StreamReader stream) {\r
+ public ILParser (CodeGen codegen, ILTokenizer tokenizer)\r
+ {\r
this.codegen = codegen;\r
- this.stream = stream;\r
+ this.tokenizer = tokenizer;\r
}\r
\r
public CodeGen CodeGen {\r
}\r
}\r
| OPEN_BRACKET D_MODULE slashed_name CLOSE_BRACKET slashed_name\r
+ {\r
+ if (codegen.IsThisModule ((string) $3)) {\r
+ $$ = new TypeRef ((string) $5, false, null);\r
+ } else {\r
+ $$ = codegen.ExternTable.GetModuleTypeRef ((string) $3, (string) $5, false);\r
+ }\r
+ }\r
| slashed_name\r
{\r
PrimitiveTypeRef prim = PrimitiveTypeRef.GetPrimitiveType ((string) $1);\r
{\r
$$ = new PrimitiveTypeRef (PrimitiveType.Char, "System.Char");\r
}\r
+ | K_WCHAR\r
+ {\r
+ $$ = new PrimitiveTypeRef (PrimitiveType.Char, "System.Char");\r
+ }\r
| K_VOID\r
{\r
$$ = new PrimitiveTypeRef (PrimitiveType.Void, "System.Void");\r
;\r
\r
bound : /* EMPTY */\r
+ {\r
+ // This is shortref for no lowerbound or size\r
+ $$ = new DictionaryEntry (TypeRef.Ellipsis, TypeRef.Ellipsis);\r
+ }\r
| ELLIPSIS\r
{\r
// No lower bound or size\r
if ($2 != null) {\r
field_def.SetOffset ((uint) $2);\r
}\r
- \r
+\r
if ($6 != null) {\r
field_def.AddDataValue ((string) $6);\r
}\r
- \r
+\r
if ($7 != null) {\r
field_def.SetValue ((Constant) $7);\r
}\r
}\r
| K_FLOAT64 OPEN_PARENS int64 CLOSE_PARENS\r
{\r
- $$ = new DoubleConst (Convert.ToDouble (3));\r
+ $$ = new DoubleConst (Convert.ToDouble ($3));\r
}\r
| K_INT64 OPEN_PARENS int64 CLOSE_PARENS\r
{\r
{\r
$$ = new CharConst (Convert.ToChar ($3));\r
}\r
+ | K_WCHAR OPEN_PARENS int64 CLOSE_PARENS\r
+ {\r
+ $$ = new CharConst (Convert.ToChar ($3));\r
+ }\r
| K_INT8 OPEN_PARENS int64 CLOSE_PARENS\r
{\r
$$ = new IntConst (Convert.ToByte ($3));\r
{\r
$$ = new BoolConst ((bool) $3);\r
}\r
- | K_BYTEARRAY OPEN_PARENS bytes CLOSE_PARENS\r
+ | K_BYTEARRAY bytes_list\r
{\r
- $$ = new ByteArrConst ((byte[]) $3);\r
+ $$ = new ByteArrConst ((byte[]) $2);\r
}\r
| comp_qstring\r
{\r
{\r
$$ = new StringConst ((string) $4);\r
}\r
+ | K_WCHAR STAR OPEN_PARENS comp_qstring CLOSE_PARENS\r
+ {\r
+ $$ = new StringConst ((string) $4);\r
+ }\r
| AMPERSAND OPEN_PARENS id CLOSE_PARENS\r
{\r
// DataDef def = codegen.CurrentTypeDef.GetDataDef ((string) $3);\r
// $$ = new AddressConstant ((DataConstant) def.PeapiConstant);\r
}\r
- | K_BYTEARRAY ASSIGN OPEN_PARENS bytes CLOSE_PARENS\r
+ | K_BYTEARRAY ASSIGN bytes_list\r
{\r
- $$ = new ByteArrConst ((byte[]) $4);\r
+ $$ = new ByteArrConst ((byte[]) $3);\r
}\r
- | K_BYTEARRAY OPEN_PARENS bytes CLOSE_PARENS\r
+ | K_BYTEARRAY bytes_list\r
{\r
// ******** THIS IS NOT IN THE SPECIFICATION ******** //\r
- $$ = new ByteArrConst ((byte[]) $3);\r
+ $$ = new ByteArrConst ((byte[]) $2);\r
}\r
| K_FLOAT32 OPEN_PARENS float64 CLOSE_PARENS repeat_opt\r
{\r
- FloatConst float_const = new FloatConst ((float) $3);\r
+ double d = (double) $3;\r
+ FloatConst float_const = new FloatConst ((float) d);\r
\r
if ($5 != null)\r
$$ = new RepeatedConstant (float_const, (int) $5);\r
}\r
| K_INT16 OPEN_PARENS int32 CLOSE_PARENS repeat_opt\r
{\r
- IntConst int_const = new IntConst ((short) $3);\r
+ int i = (int) $3;\r
+ IntConst int_const = new IntConst ((short) i);\r
\r
if ($5 != null)\r
$$ = new RepeatedConstant (int_const, (int) $5);\r
}\r
| K_INT8 OPEN_PARENS int32 CLOSE_PARENS repeat_opt\r
{\r
- IntConst int_const = new IntConst ((sbyte) $3);\r
+ int i = (int) $3;\r
+ IntConst int_const = new IntConst ((sbyte) i);\r
\r
if ($5 != null)\r
$$ = new RepeatedConstant (int_const, (int) $5);\r
// assembly. This is not supported in the MS version of ilasm\r
}\r
| OPEN_BRACKET D_MODULE slashed_name CLOSE_BRACKET\r
+ {\r
+\r
+ }\r
| type\r
;\r
\r
break;\r
}\r
}\r
- | INSTR_R OPEN_PARENS bytes CLOSE_PARENS\r
+ | INSTR_R bytes_list\r
| INSTR_BRTARGET int32\r
{\r
LabelInfo target = codegen.CurrentMethodDef.AddLabel ((int) $2);\r
if ((MiscInstr) $1 == MiscInstr.ldstr)\r
codegen.CurrentMethodDef.AddInstr (new LdstrInstr ((string) $2));\r
}\r
- | INSTR_STRING K_BYTEARRAY ASSIGN OPEN_PARENS\r
- bytes CLOSE_PARENS\r
+ | INSTR_STRING K_BYTEARRAY ASSIGN bytes_list\r
{\r
- byte[] bs = (byte[]) $5;\r
+ byte[] bs = (byte[]) $4;\r
if ((MiscInstr) $1 == MiscInstr.ldstr)\r
codegen.CurrentMethodDef.AddInstr (new LdstrInstr (bs));\r
}\r
- | INSTR_STRING K_BYTEARRAY OPEN_PARENS bytes\r
- CLOSE_PARENS\r
+ | INSTR_STRING K_BYTEARRAY bytes_list\r
{\r
- byte[] bs = (byte[]) $4;\r
+ byte[] bs = (byte[]) $3;\r
if ((MiscInstr) $1 == MiscInstr.ldstr)\r
codegen.CurrentMethodDef.AddInstr (new LdstrInstr (bs));\r
}\r
{\r
$$ = (FeatureAttr) $1 | FeatureAttr.Specialname;\r
}\r
+ | prop_attr K_INSTANCE\r
+ {\r
+ }\r
;\r
\r
prop_decls : /* EMPTY */\r
$$ = new CustomAttr ((IMethodRef) $2, null);\r
}\r
| D_CUSTOM custom_type ASSIGN comp_qstring\r
- | D_CUSTOM custom_type ASSIGN OPEN_PARENS bytes CLOSE_PARENS\r
+ | D_CUSTOM custom_type ASSIGN bytes_list\r
{\r
$$ = new CustomAttr ((IMethodRef) $2,\r
- (byte[]) $5);\r
+ (byte[]) $4);\r
}\r
| D_CUSTOM OPEN_PARENS owner_type CLOSE_PARENS custom_type\r
| D_CUSTOM OPEN_PARENS owner_type CLOSE_PARENS custom_type ASSIGN comp_qstring\r
| D_CUSTOM OPEN_PARENS owner_type CLOSE_PARENS custom_type ASSIGN\r
- OPEN_PARENS bytes CLOSE_PARENS\r
+ bytes_list\r
;\r
\r
custom_type : call_conv type type_spec DOUBLE_COLON D_CTOR OPEN_PARENS type_list CLOSE_PARENS\r
\r
sec_decl : D_PERMISSION sec_action type_spec OPEN_PARENS nameval_pairs CLOSE_PARENS\r
| D_PERMISSION sec_action type_spec\r
- | D_PERMISSIONSET sec_action ASSIGN OPEN_PARENS bytes CLOSE_PARENS\r
+ | D_PERMISSIONSET sec_action ASSIGN bytes_list\r
;\r
\r
nameval_pairs : nameval_pair \r
;\r
\r
module_head : D_MODULE\r
+ {\r
+ }\r
| D_MODULE comp_name\r
+ {\r
+ codegen.SetModuleName ((string) $2);\r
+ }\r
| D_MODULE K_EXTERN comp_name\r
+ {\r
+ codegen.ExternTable.AddModule ((string) $3); \r
+ }\r
;\r
\r
file_decl : D_FILE file_attr comp_name file_entry D_HASH ASSIGN\r
- OPEN_PARENS bytes CLOSE_PARENS file_entry\r
+ bytes_list file_entry\r
| D_FILE file_attr comp_name file_entry\r
;\r
\r
| assembly_decls assembly_decl\r
;\r
\r
-assembly_decl : D_HASH K_ALGORITHM int32\r
+assembly_decl : D_PUBLICKEY ASSIGN bytes_list\r
+ {\r
+ codegen.SetAssemblyPublicKey ((byte []) $3);\r
+ }\r
+ | D_VER int32 COLON int32 COLON int32 COLON int32\r
+ {\r
+ codegen.SetAssemblyVersion ((int) $2, (int) $4, (int) $6, (int) $8);\r
+ }\r
+ | D_LOCALE comp_qstring\r
+ {\r
+ codegen.SetAssemblyLocale ((string) $2);\r
+ }\r
+ | D_LOCALE ASSIGN bytes_list\r
+ | D_HASH K_ALGORITHM int32\r
+ {\r
+ codegen.SetAssemblyHashAlgorithm ((int) $3);\r
+ }\r
+ | customattr_decl\r
+ {\r
+ codegen.AddAssemblyCustomAttribute ((CustomAttr) $1);\r
+ }\r
| sec_decl\r
- | asm_or_ref_decl\r
;\r
\r
-asm_or_ref_decl : D_PUBLICKEY ASSIGN OPEN_PARENS bytes CLOSE_PARENS\r
+asm_or_ref_decl : D_PUBLICKEY ASSIGN bytes_list\r
| D_VER int32 COLON int32 COLON int32 COLON int32 \r
| D_LOCALE comp_qstring\r
- | D_LOCALE ASSIGN OPEN_PARENS bytes CLOSE_PARENS\r
+ | D_LOCALE ASSIGN bytes_list\r
| customattr_decl\r
;\r
\r
System.Reflection.AssemblyName asmb_name = \r
new System.Reflection.AssemblyName ();\r
asmb_name.Name = (string) $3;\r
- codegen.ExternTable.AddAssembly ((string) $3, asmb_name);\r
+ codegen.BeginAssemblyRef ((string) $3, asmb_name);\r
}\r
| D_ASSEMBLY K_EXTERN slashed_name K_AS slashed_name\r
{\r
System.Reflection.AssemblyName asmb_name = \r
new System.Reflection.AssemblyName ();\r
asmb_name.Name = (string) $3;\r
- codegen.ExternTable.AddAssembly ((string) $5, asmb_name);\r
+ codegen.BeginAssemblyRef ((string) $5, asmb_name);\r
}\r
;\r
\r
| assemblyref_decls assemblyref_decl\r
;\r
\r
-assemblyref_decl : D_HASH ASSIGN OPEN_PARENS bytes CLOSE_PARENS\r
- | asm_or_ref_decl\r
- | D_PUBLICKEYTOKEN ASSIGN OPEN_PARENS bytes CLOSE_PARENS\r
+assemblyref_decl : D_VER int32 COLON int32 COLON int32 COLON int32\r
+ {\r
+ codegen.CurrentAssemblyRef.SetVersion ((int) $2, (int) $4, (int) $6, (int) $8);\r
+ }\r
+ | D_PUBLICKEY ASSIGN bytes_list\r
+ {\r
+ codegen.CurrentAssemblyRef.SetPublicKey ((byte []) $3);\r
+ }\r
+ | D_PUBLICKEYTOKEN ASSIGN bytes_list\r
+ {\r
+ codegen.CurrentAssemblyRef.SetPublicKeyToken ((byte []) $3);\r
+ }\r
+ | D_LOCALE comp_qstring\r
+ {\r
+ codegen.CurrentAssemblyRef.SetLocale ((string) $2);\r
+ }\r
+ | D_LOCALE ASSIGN bytes_list\r
+ \r
+ | D_HASH ASSIGN bytes_list\r
+ {\r
+ codegen.CurrentAssemblyRef.SetHash ((byte []) $3);\r
+ }\r
+ | customattr_decl\r
;\r
\r
exptype_all : exptype_head OPEN_BRACE exptype_decls CLOSE_BRACE\r
{\r
long l = (long) $1;\r
byte[] intb = BitConverter.GetBytes (l);\r
- $$ = BitConverter.ToInt32 (intb, 0);\r
+ $$ = BitConverter.ToInt32 (intb, BitConverter.IsLittleEndian ? 0 : 4);\r
}\r
;\r
\r
{\r
int i = (int) $3;\r
byte[] intb = BitConverter.GetBytes (i);\r
- $$ = (double) BitConverter.ToSingle (intb, 0);\r
+ $$ = (double) BitConverter.ToSingle (intb, BitConverter.IsLittleEndian ? 0 : 4);\r
}\r
| K_FLOAT32 OPEN_PARENS INT64 CLOSE_PARENS\r
{\r
long l = (long) $3;\r
byte[] intb = BitConverter.GetBytes (l);\r
- $$ = (double) BitConverter.ToSingle (intb, 0);\r
+ $$ = (double) BitConverter.ToSingle (intb, BitConverter.IsLittleEndian ? 0 : 4);\r
}\r
| K_FLOAT64 OPEN_PARENS INT64 CLOSE_PARENS\r
{\r
byte[] intb = BitConverter.GetBytes ((long) $3);\r
- $$ = BitConverter.ToDouble (intb, 0);\r
+ $$ = BitConverter.ToDouble (intb, BitConverter.IsLittleEndian ? 0 : 4);\r
}\r
| K_FLOAT64 OPEN_PARENS INT32 CLOSE_PARENS\r
{\r
byte[] intb = BitConverter.GetBytes ((int) $3);\r
- $$ = (double) BitConverter.ToSingle (intb, 0);\r
+ $$ = (double) BitConverter.ToSingle (intb, BitConverter.IsLittleEndian ? 0 : 4);\r
}\r
;\r
\r
hexbyte : HEXBYTE { }\r
- | INT64\r
+ ;\r
+\r
+bytes_list : OPEN_PARENS\r
{\r
- long l = (long) $1;\r
- byte b = Byte.Parse (l.ToString (), NumberStyles.HexNumber);\r
- $$ = b;\r
+ tokenizer.InByteArray = true;\r
}\r
- | ID\r
+ bytes CLOSE_PARENS\r
{\r
- $$ = Byte.Parse ((string) $1, NumberStyles.HexNumber);\r
+ $$ = $3;\r
+ tokenizer.InByteArray = false;\r
}\r
- ;\r
+ ;\r
\r
bytes : /* EMPTY */ { $$ = new byte[0]; }\r
| hexbytes\r
;\r
\r
truefalse : K_TRUE\r
+ {\r
+ $$ = true;\r
+ }\r
| K_FALSE\r
+ {\r
+ $$ = false;\r
+ }\r
;\r
\r
id : ID\r