private void ReadExceptions(IList <ExceptionHandlingClause> exceptionClauses)
        {
            foreach (var exceptionClause in exceptionClauses)
            {
                var handler = new ExceptionHandler((ExceptionHandlerType)exceptionClause.Flags);

                handler.TryStart = GetInstruction(exceptionClause.TryOffset);
                handler.TryEnd   = GetInstruction(handler.TryStart.Offset + exceptionClause.TryLength);

                handler.HandlerStart = GetInstruction(exceptionClause.HandlerOffset);
                handler.HandlerEnd   = GetInstruction(handler.HandlerStart.Offset + exceptionClause.HandlerLength);

                switch (handler.HandlerType)
                {
                case ExceptionHandlerType.Catch:
                    var token = new MetadataToken((uint)exceptionClause.CatchType.MetadataToken);
                    handler.CatchType = resolveTokens ? ResolveToken(token) : token;
                    break;

                case ExceptionHandlerType.Filter:
                    handler.FilterStart = GetInstruction(exceptionClause.FilterOffset);
                    break;
                }

                ExceptionHandlers.Add(handler);
            }
        }
        private unsafe void ReadExceptions(DynamicResolver dynamicResolver, int excCount)
        {
            var buf             = stackalloc CORINFO_EH_CLAUSE[1];
            var exceptionClause = &buf[0];

            for (int i = 0; i < excCount; ++i)
            {
                dynamicResolver.GetEHInfo(i, exceptionClause);

                var handler = new ExceptionHandler((ExceptionHandlerType)exceptionClause->Flags);

                handler.TryStart = GetInstruction(exceptionClause->TryOffset);
                handler.TryEnd   = GetInstruction(handler.TryStart.Offset + exceptionClause->TryLength);

                handler.HandlerStart = GetInstruction(exceptionClause->HandlerOffset);
                handler.HandlerEnd   = GetInstruction(handler.HandlerStart.Offset + exceptionClause->HandlerLength);

                switch (handler.HandlerType)
                {
                case ExceptionHandlerType.Catch:
                    var token = new MetadataToken((uint)exceptionClause->ClassTokenOrFilterOffset);
                    handler.CatchType = resolveTokens ? ResolveToken(token) : token;
                    break;

                case ExceptionHandlerType.Filter:
                    handler.FilterStart = GetInstruction(exceptionClause->ClassTokenOrFilterOffset);
                    break;
                }

                ExceptionHandlers.Add(handler);
            }
        }
        internal ByteCodeMethodBody(JavaClassImage classImage, CodeAttribute attribute)
        {
            MaxStack = attribute.MaxStack;

            // Read instructions.
            var disassembler = new ByteCodeDisassembler(new MemoryBigEndianReader(attribute.Code))
            {
                OperandResolver = new DefaultOperandResolver(classImage)
            };

            foreach (var instruction in disassembler.ReadInstructions())
            {
                Instructions.Add(instruction);
            }

            // Read exception handlers.
            foreach (var handler in attribute.ExceptionHandlers)
            {
                ExceptionHandlers.Add(new ExceptionHandler(classImage, this, handler));
            }

            // Read attributes.
            foreach (var attr in attribute.Attributes)
            {
                string name = classImage.ClassFile.ConstantPool.ResolveString(attr.NameIndex);
                switch (name)
                {
                // Local variables
                case LocalVariableTableAttribute.AttributeName:
                    var localsTable = LocalVariableTableAttribute.FromReader(new MemoryBigEndianReader(attr.Contents));
                    foreach (var info in localsTable.LocalVariables)
                    {
                        Variables.Add(new LocalVariable(classImage, this, info));
                    }
                    break;


                default:
                    ExtraAttributes.Add(name, attr.Clone());
                    break;
                }
            }
        }