/// <summary> /// Build New Disassemblied CilBody /// </summary> /// <returns>New Method Body.</returns> public CilMethodBody BeginRead() { foreach (var Local in Owner.CilMethodBody.LocalVariables.Take(Owner.CilMethodBody.LocalVariables.Count - 2)) /* Skiping Locals Madden By CawkVM */ { _body.LocalVariables.Add(new(_importer.ImportTypeSignature(Local.VariableType))); } int ExceptionHandlersCount = _reader.ReadInt32(); ExceptionClause[] Claues = new ExceptionClause[ExceptionHandlersCount]; /* ExceptionHandler Restoration. */ for (int x = 0; x < ExceptionHandlersCount; x++) { uint TypeToken = (uint)_reader.ReadInt32(); int StartFilter = _reader.ReadInt32(); int HandlerEnd = _reader.ReadInt32(); int HandlerStart = _reader.ReadInt32(); byte HandlerType = _reader.ReadByte(); int TryEnd = _reader.ReadInt32(); int TryStart = _reader.ReadInt32(); Claues[x] = new ExceptionClause() { HandlerType = HandlerType switch { 1 => CilExceptionHandlerType.Exception, 2 => null, // No Duplicates. 3 => CilExceptionHandlerType.Fault, 4 => CilExceptionHandlerType.Filter, 5 => CilExceptionHandlerType.Finally, _ => throw new Exception("Unknown HandlerType.") },
// Begin a finally block on the current exception. public virtual void BeginFinallyBlock() { // Terminate the current clause. TerminateClause(); // The operation is invalid if current is finally or fault. if(exceptionStack.clauses != null) { if(exceptionStack.clauses.clauseType == Except_Finally || exceptionStack.clauses.clauseType == Except_Fault) { throw new InvalidOperationException (_("Emit_CatchAfterFinally")); } } // Create a new clause information block. ExceptionClause clause = new ExceptionClause(); clause.prev = exceptionStack.clauses; clause.clauseType = Except_Finally; clause.beginClause = offset; clause.endClause = -1; clause.classInfo = null; exceptionStack.clauses = clause; height = 1; // Top of stack is the exception object. if(height > maxHeight) { maxHeight = height; } }
// Begin a filter block on the current exception. public virtual void BeginExceptFilterBlock() { // Terminate the current clause. TerminateClause(); // Create a new clause information block. ExceptionClause clause = new ExceptionClause(); clause.prev = exceptionStack.clauses; clause.clauseType = Except_Filter; clause.beginClause = offset; clause.endClause = -1; clause.classInfo = null; exceptionStack.clauses = clause; }
// Begin a catch block on the current exception. public virtual void BeginCatchBlock(Type exceptionType) { // Terminate the current clause. TerminateClause(); // The operation is invalid if current is finally or fault. if(exceptionStack.clauses != null) { if(exceptionStack.clauses.clauseType == Except_Finally || exceptionStack.clauses.clauseType == Except_Fault) { throw new InvalidOperationException (_("Emit_CatchAfterFinally")); } } // Create a new clause information block. ExceptionClause clause = new ExceptionClause(); clause.prev = exceptionStack.clauses; clause.clauseType = Except_Catch; clause.beginClause = offset; clause.endClause = -1; clause.classInfo = exceptionType; exceptionStack.clauses = clause; }