Beispiel #1
0
        void BeginCatch(ISehHandlerBlock block, AbcCode code, AbcExceptionHandler e, ref int var, bool dupException, bool catchAnyException)
        {
            var beginIndex = code.Count;

            var catchInfo = new CatchInfo
            {
                CatchAnyException = catchAnyException
            };
            bool coerceAny = catchAnyException;

            if (var < 0 || catchAnyException)
            {
                coerceAny           = true;
                var                 = SharedExceptionVar;
                catchInfo.IsTempVar = true;
            }
            catchInfo.ExceptionVar = var;
            e.LocalVariable        = var;

            var handlerInfo = block.Tag as SehHandlerInfo;

            if (handlerInfo == null)
            {
                handlerInfo = new SehHandlerInfo {
                    CatchInfo = catchInfo
                };
                block.Tag = handlerInfo;
            }
            else
            {
                handlerInfo.CatchInfo = catchInfo;
            }

            //NOTE: we store exception in temp variable to use for rethrow operation
            if (dupException && !catchAnyException)
            {
                code.Dup();
            }

            if (coerceAny)
            {
                code.CoerceAnyType();
            }

            //store exception in variable to use for rethrow operation
            code.SetLocal(var);

            _resolver.Add(code[beginIndex], new ExceptionTarget(e));
        }
Beispiel #2
0
        public IEnumerable <IInstruction> BeginCatch(ISehHandlerBlock handlerBlock)
        {
            var tryBlock = handlerBlock.Owner;

            var exceptionType = handlerBlock.ExceptionType;

            if (exceptionType != null)
            {
                EnsureType(exceptionType);
            }

            var seh = new AbcExceptionHandler();

            _body.Exceptions.Add(seh);
            _resolver.Add(tryBlock, new ExceptionFrom(seh), new ExceptionTo(seh));

            bool catchAnyException = MustCatchAnyException(handlerBlock);

            seh.Type = catchAnyException ? _abc.BuiltinTypes.Object : handlerBlock.ExceptionType.GetMultiname();

            int var = handlerBlock.ExceptionVariable;

            if (var >= 0)
            {
                var = GetVarIndex(var);
            }

            var code = new AbcCode(_abc);

            BeginCatch(handlerBlock, code, seh, ref var, !_popException, catchAnyException);

            if (catchAnyException)
            {
                RouteException(code, handlerBlock, var);
                _sehsToResolve.Add(tryBlock);
            }

            return(code);
        }
Beispiel #3
0
 public ExceptionTarget(AbcExceptionHandler e)
 {
     _e = e;
 }
Beispiel #4
0
 public ExceptionTo(AbcExceptionHandler e)
 {
     _e = e;
 }
Beispiel #5
0
 public ExceptionFrom(AbcExceptionHandler e)
 {
     _e = e;
 }
Beispiel #6
0
        private IEnumerable <IInstruction> BeginFinally(ISehHandlerBlock block, bool fault)
        {
            var e = new AbcExceptionHandler();

            _body.Exceptions.Add(e);
            e.To     = -1;
            e.Target = -1;

            var fi = new FinallyInfo {
                IsFault = fault
            };

            block.Tag = new SehHandlerInfo {
                FinallyInfo = fi
            };

            _resolver.Add(block.Owner, new ExceptionFrom(e), null);

            var code = new AbcCode(_abc);

            if (!fault)
            {
                //Reset rethrow flag
                fi.RethrowFlagVariable = NewTempVar(true);
                _initializableTempVars.Add(new TempVar(fi.RethrowFlagVariable, new Instruction(InstructionCode.Pushfalse)));
                code.PushNativeBool(false);
                // Trying to fix IVDiffGramTest. Coercing to any type does not help. The test failed with error:
                // The Dark Side clouds everything. Impossible to see, the future is. (c) Yoda
                // code.CoerceAnyType();
                code.SetLocal(fi.RethrowFlagVariable);
            }

            //Add goto finally body
            var gotoBody = code.Goto();

            _resolver.Add(gotoBody, new ExceptionTo(e));

            //NOTE: Insert empty handler to catch unhandled or rethrown exception
            //begin catch
            BeginCatch(block, code, e, ref fi.ExceptionVariable, false, false);

            var end = (Instruction)code[code.Count - 1];

            if (!fault)
            {
                //Set rethrow flag to true to rethrow exception
                code.PushNativeBool(true);
                // Trying to fix IVDiffGramTest. Coercing to any type does not help. The test failed with error:
                // The Dark Side clouds everything. Impossible to see, the future is. (c) Yoda
                // code.CoerceAnyType();
                end = code.SetLocal(fi.RethrowFlagVariable);
            }

            if (PopCatchScope)
            {
                end = code.PopScope(); //pops catch scope
            }
            //end of catch

            gotoBody.GotoNext(end);

            return(code);
        }