EHClause.cs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. using System;
  2. using System.Collections;
  3. namespace QUT.PERWAPI
  4. {
  5. /**************************************************************************/
  6. internal enum EHClauseType { Exception, Filter, Finally, Fault = 4 }
  7. internal class EHClause
  8. {
  9. EHClauseType clauseType;
  10. uint tryOffset, tryLength, handlerOffset, handlerLength, filterOffset = 0;
  11. MetaDataElement classToken = null;
  12. internal EHClause(EHClauseType cType, uint tOff, uint tLen, uint hOff, uint hLen)
  13. {
  14. clauseType = cType;
  15. tryOffset = tOff;
  16. tryLength = tLen;
  17. handlerOffset = hOff;
  18. handlerLength = hLen;
  19. }
  20. internal void ClassToken(MetaDataElement cToken)
  21. {
  22. classToken = cToken;
  23. }
  24. internal void FilterOffset(uint fOff)
  25. {
  26. filterOffset = fOff;
  27. }
  28. internal TryBlock MakeTryBlock(ArrayList labels)
  29. {
  30. TryBlock tBlock = new TryBlock(CILInstructions.GetLabel(labels, tryOffset),
  31. CILInstructions.GetLabel(labels, tryOffset + tryLength));
  32. CILLabel hStart = CILInstructions.GetLabel(labels, handlerOffset);
  33. CILLabel hEnd = CILInstructions.GetLabel(labels, handlerOffset + handlerLength);
  34. HandlerBlock handler = null;
  35. switch (clauseType)
  36. {
  37. case (EHClauseType.Exception):
  38. handler = new Catch((Class)classToken, hStart, hEnd);
  39. break;
  40. case (EHClauseType.Filter):
  41. handler = new Filter(CILInstructions.GetLabel(labels, filterOffset), hStart, hEnd);
  42. break;
  43. case (EHClauseType.Finally):
  44. handler = new Finally(hStart, hEnd);
  45. break;
  46. case (EHClauseType.Fault):
  47. handler = new Fault(hStart, hEnd);
  48. break;
  49. }
  50. tBlock.AddHandler(handler);
  51. return tBlock;
  52. }
  53. }
  54. }