2009-07-02 Jb Evain <jbevain@novell.com>
[mcs.git] / tools / pdb2mdb / PdbConstant.cs
blobb37eee1c24159a39e28060c4bde2f6ace8be79a3
1 //-----------------------------------------------------------------------------
2 //
3 // Copyright (C) Microsoft Corporation. All Rights Reserved.
4 //
5 //-----------------------------------------------------------------------------
6 using System;
7 using System.Runtime.InteropServices;
9 namespace Microsoft.Cci.Pdb {
10 internal class PdbConstant {
11 internal string name;
12 internal uint token;
13 internal object value;
15 internal PdbConstant(BitAccess bits) {
16 bits.ReadUInt32(out this.token);
17 byte tag1;
18 bits.ReadUInt8(out tag1);
19 byte tag2;
20 bits.ReadUInt8(out tag2);
21 if (tag2 == 0) {
22 this.value = tag1;
23 } else if (tag2 == 0x80) {
24 switch (tag1) {
25 case 0x01: //short
26 short s;
27 bits.ReadInt16(out s);
28 this.value = s;
29 break;
30 case 0x02: //ushort
31 ushort us;
32 bits.ReadUInt16(out us);
33 this.value = us;
34 break;
35 case 0x03: //int
36 int i;
37 bits.ReadInt32(out i);
38 this.value = i;
39 break;
40 case 0x04: //uint
41 uint ui;
42 bits.ReadUInt32(out ui);
43 this.value = ui;
44 break;
45 case 0x05: //float
46 this.value = bits.ReadFloat();
47 break;
48 case 0x06: //double
49 this.value = bits.ReadDouble();
50 break;
51 case 0x09: //long
52 long sl;
53 bits.ReadInt64(out sl);
54 this.value = sl;
55 break;
56 case 0x0a: //ulong
57 ulong ul;
58 bits.ReadUInt64(out ul);
59 this.value = ul;
60 break;
61 case 0x10: //string
62 string str;
63 bits.ReadBString(out str);
64 this.value = str;
65 break;
66 case 0x19: //decimal
67 this.value = bits.ReadDecimal();
68 break;
69 default:
70 //TODO: error
71 break;
73 } else {
74 //TODO: error
76 bits.ReadCString(out name);