Example #1
0
        //-----------------------------------------------------------------------------------------------------------------------------------------------------

        public StatementScope(StatementBlock statementBlock, RewriteMode rewriteMode)
        {
            m_Previous = s_Current;
            m_Root     = (m_Previous != null ? m_Previous.Root : this);

            m_StatementBlock = statementBlock;
            m_Writer         = statementBlock.OwnerMethod.TransparentWriter;
            m_OwnerMethod    = statementBlock.OwnerMethod;
            m_OwnerClass     = statementBlock.OwnerMethod.OwnerClass;
            m_Depth          = 1;

            m_ThisExceptionBlockType = ExceptionBlockType.None;
            m_ThisExceptionStatement = null;

            if (m_Previous != null)
            {
                m_InheritedLoopStatement      = m_Previous.InheritedLoopStatement;
                m_InheritedExceptionStatement = m_Previous.InheritedExceptionStatement;
                m_InheritedExceptionBlockType = m_Previous.InheritedExceptionBlockType;
            }

            m_StatementBlock        = statementBlock;
            m_IsRewriteMode         = true;
            m_RewriteInsertionIndex = 0;

            s_Current = this;
        }
Example #2
0
        //-----------------------------------------------------------------------------------------------------------------------------------------------------

        private StatementScope(StatementBlock statementBlock, bool attachStatementBlock)
        {
            m_Previous = s_Current;
            m_Root     = m_Previous.Root;

            if (m_Previous == null)
            {
                throw new InvalidOperationException("Parent scope is not present.");
            }

            m_StatementBlock = statementBlock;
            m_Writer         = m_Previous.m_Writer;
            m_OwnerMethod    = m_Previous.m_OwnerMethod;
            m_OwnerClass     = m_Previous.m_OwnerClass;
            m_Depth          = m_Previous.Depth + 1;

            m_InheritedLoopStatement      = m_Previous.InheritedLoopStatement;
            m_ThisExceptionBlockType      = ExceptionBlockType.None;
            m_ThisExceptionStatement      = null;
            m_InheritedExceptionStatement = m_Previous.InheritedExceptionStatement;
            m_InheritedExceptionBlockType = m_Previous.InheritedExceptionBlockType;

            m_StatementBlock = (attachStatementBlock ? AttachStatementBlock(statementBlock) : null);
            s_Current        = this;
        }
Example #3
0
        //-----------------------------------------------------------------------------------------------------------------------------------------------------

        public StatementScope(StatementBlock statementBlock, TryStatement exceptionStatement, ExceptionBlockType blockType)
            : this(statementBlock, attachStatementBlock : false)
        {
            m_ThisExceptionStatement      = exceptionStatement;
            m_ThisExceptionBlockType      = blockType;
            m_InheritedExceptionStatement = exceptionStatement;
            m_InheritedExceptionBlockType = blockType;

            m_StatementBlock = AttachStatementBlock(statementBlock);
        }
#pragma warning restore

        protected virtual void MarkExceptionBlock(ILGenerator il, ExceptionBlockInfo info)
        {
            ExceptionBlockType btype = info.blockType;

            if ((btype & ExceptionBlockType.End) != 0)
            {
                il.EndExceptionBlock();
            }
            else // begin
            {
                switch (btype & flagValue)
                {
                case ExceptionBlockType.BigBlock:
                    il.BeginExceptionBlock();
                    return;

                case ExceptionBlockType.FilterBlock:
                    il.BeginExceptFilterBlock();
                    return;

                case ExceptionBlockType.FinallyBlock:
                    il.BeginFinallyBlock();
                    return;

                case ExceptionBlockType.CatchBlock:
                    il.BeginCatchBlock(info.catchType);
                    return;

                case ExceptionBlockType.FaultBlock:
                    il.BeginFaultBlock();
                    return;

                default:
#if DEBUG
                    System.Diagnostics.Debug.WriteLine($"[ERROR] {btype}");
#endif
                    return;
                }
            }
        }
Example #5
0
        //-----------------------------------------------------------------------------------------------------------------------------------------------------

        public StatementScope(ClassType ownerClass, MethodWriterBase writer, StatementBlock statementBlock)
        {
            if (s_Current != null)
            {
                throw new InvalidOperationException("Root scope already exists.");
            }

            m_Writer      = writer;
            m_OwnerMethod = (writer != null ? writer.OwnerMethod : null);
            m_OwnerClass  = ownerClass;
            m_Depth       = 0;

            m_InheritedLoopStatement      = null;
            m_ThisExceptionBlockType      = ExceptionBlockType.None;
            m_ThisExceptionStatement      = null;
            m_InheritedExceptionStatement = null;
            m_InheritedExceptionBlockType = ExceptionBlockType.None;

            m_Previous = null;
            m_Root     = this;
            s_Current  = this;

            m_StatementBlock = AttachStatementBlock(statementBlock);
        }
Example #6
0
 /// <summary>Creates an exception block</summary>
 /// <param name="blockType">Block type</param>
 /// <param name="catchType">Catch type</param>
 ///
 public ExceptionBlock(ExceptionBlockType blockType, Type catchType = null)
 {
     this.blockType = blockType;
     this.catchType = catchType ?? typeof(object);
 }
Example #7
0
 public ExceptionBlock(ExceptionBlockType blockType, Type catchType)
 {
     this.blockType = blockType;
     this.catchType = catchType;
 }
Example #8
0
 public ExceptionBlockInfo(ExceptionBlockType blockType) : this(blockType, null)
 {
 }
 /// <summary>Creates an exception block</summary>
 /// <param name="blockType">Block type</param>
 /// <param name="catchType">Catch type</param>
 ///
 public ExceptionBlock(ExceptionBlockType blockType, Type catchType = null)
 {
     throw new PlatformNotSupportedException();
 }