/Mono.Cecil/symbols/pdb/Microsoft.Cci.Pdb/PdbScope.cs

http://github.com/icsharpcode/ILSpy · C# · 122 lines · 91 code · 18 blank · 13 comment · 6 complexity · 6da111806650a8a5c6b4976706dfde1a MD5 · raw file

  1. //-----------------------------------------------------------------------------
  2. //
  3. // Copyright (c) Microsoft. All rights reserved.
  4. // This code is licensed under the Microsoft Public License.
  5. // THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
  6. // ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
  7. // IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
  8. // PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
  9. //
  10. //-----------------------------------------------------------------------------
  11. using System;
  12. namespace Microsoft.Cci.Pdb {
  13. internal class PdbScope {
  14. internal PdbConstant[] constants;
  15. internal PdbSlot[] slots;
  16. internal PdbScope[] scopes;
  17. internal string[] usedNamespaces;
  18. //internal uint segment;
  19. internal uint address;
  20. internal uint offset;
  21. internal uint length;
  22. internal PdbScope(uint address, uint length, PdbSlot[] slots, PdbConstant[] constants, string[] usedNamespaces) {
  23. this.constants = constants;
  24. this.slots = slots;
  25. this.scopes = new PdbScope[0];
  26. this.usedNamespaces = usedNamespaces;
  27. this.address = address;
  28. this.offset = 0;
  29. this.length = length;
  30. }
  31. internal PdbScope(uint funcOffset, BlockSym32 block, BitAccess bits, out uint typind) {
  32. //this.segment = block.seg;
  33. this.address = block.off;
  34. this.offset = block.off - funcOffset;
  35. this.length = block.len;
  36. typind = 0;
  37. int constantCount;
  38. int scopeCount;
  39. int slotCount;
  40. int namespaceCount;
  41. PdbFunction.CountScopesAndSlots(bits, block.end, out constantCount, out scopeCount, out slotCount, out namespaceCount);
  42. constants = new PdbConstant[constantCount];
  43. scopes = new PdbScope[scopeCount];
  44. slots = new PdbSlot[slotCount];
  45. usedNamespaces = new string[namespaceCount];
  46. int constant = 0;
  47. int scope = 0;
  48. int slot = 0;
  49. int usedNs = 0;
  50. while (bits.Position < block.end) {
  51. ushort siz;
  52. ushort rec;
  53. bits.ReadUInt16(out siz);
  54. int star = bits.Position;
  55. int stop = bits.Position + siz;
  56. bits.Position = star;
  57. bits.ReadUInt16(out rec);
  58. switch ((SYM)rec) {
  59. case SYM.S_BLOCK32: {
  60. BlockSym32 sub = new BlockSym32();
  61. bits.ReadUInt32(out sub.parent);
  62. bits.ReadUInt32(out sub.end);
  63. bits.ReadUInt32(out sub.len);
  64. bits.ReadUInt32(out sub.off);
  65. bits.ReadUInt16(out sub.seg);
  66. bits.SkipCString(out sub.name);
  67. bits.Position = stop;
  68. scopes[scope++] = new PdbScope(funcOffset, sub, bits, out typind);
  69. break;
  70. }
  71. case SYM.S_MANSLOT:
  72. slots[slot++] = new PdbSlot(bits, out typind);
  73. bits.Position = stop;
  74. break;
  75. case SYM.S_UNAMESPACE:
  76. bits.ReadCString(out usedNamespaces[usedNs++]);
  77. bits.Position = stop;
  78. break;
  79. case SYM.S_END:
  80. bits.Position = stop;
  81. break;
  82. case SYM.S_MANCONSTANT:
  83. constants[constant++] = new PdbConstant(bits);
  84. bits.Position = stop;
  85. break;
  86. default:
  87. //throw new PdbException("Unknown SYM in scope {0}", (SYM)rec);
  88. bits.Position = stop;
  89. break;
  90. }
  91. }
  92. if (bits.Position != block.end) {
  93. throw new Exception("Not at S_END");
  94. }
  95. ushort esiz;
  96. ushort erec;
  97. bits.ReadUInt16(out esiz);
  98. bits.ReadUInt16(out erec);
  99. if (erec != (ushort)SYM.S_END) {
  100. throw new Exception("Missing S_END");
  101. }
  102. }
  103. }
  104. }