Ejemplo n.º 1
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;
        }
Ejemplo n.º 2
0
        //-----------------------------------------------------------------------------------------------------------------------------------------------------

        public WhileStatement(IOperand <bool> condition)
        {
            m_Condition = condition;
            m_BodyBlock = new StatementBlock();

            StatementScope.Current.Consume(condition);
        }
Ejemplo n.º 3
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;
        }
Ejemplo n.º 4
0
        //-----------------------------------------------------------------------------------------------------------------------------------------------------

        public void Attach(StatementScope scope)
        {
            m_OwnerMethod            = scope.OwnerMethod;
            m_ParentBlock            = (scope.Previous != null ? scope.Previous.StatementBlock : null);
            m_Depth                  = (m_ParentBlock != null ? m_ParentBlock.Depth + 1 : 0);
            m_EnclosingTryStatement  = scope.InheritedExceptionStatement;
            m_EnclosingLoopStatement = scope.InheritedLoopStatement;
        }
Ejemplo n.º 5
0
        //-----------------------------------------------------------------------------------------------------------------------------------------------------

        public IfStatement(IOperand <bool> condition, bool conditionIsAlwaysTrue)
        {
            m_Condition             = condition;
            m_ConditionIsAlwaysTrue = conditionIsAlwaysTrue;
            m_ThenBlock             = new StatementBlock();
            m_ElseBlock             = new StatementBlock();

            StatementScope.Current.Consume(condition);
        }
Ejemplo n.º 6
0
        //-----------------------------------------------------------------------------------------------------------------------------------------------------

        public DoWhileStatement(Action <ILoopBody> body)
        {
            m_BodyBlock = new StatementBlock();

            using (new StatementScope(m_BodyBlock, loopStatement: this))
            {
                body(this);
            }
        }
Ejemplo n.º 7
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);
        }
Ejemplo n.º 8
0
        //-----------------------------------------------------------------------------------------------------------------------------------------------------

        public ForStatement(Action precondition)
        {
            m_PreconditionBlock = new StatementBlock();
            m_NextBlock         = new StatementBlock();
            m_BodyBlock         = new StatementBlock();

            using (new StatementScope(m_PreconditionBlock))
            {
                precondition();
            }
        }
Ejemplo n.º 9
0
            //-------------------------------------------------------------------------------------------------------------------------------------------------

            public CaseBlock(SwitchStatement <T> ownerStatement, T value)
            {
                m_OwnerStatement = ownerStatement;
                m_Value          = value;
                m_Body           = new StatementBlock();

                if (typeof(T).IsPrimitive || typeof(T).IsEnum)
                {
                    m_Int64 = (long)Convert.ChangeType(value, typeof(long));
                }
            }
Ejemplo n.º 10
0
        //-----------------------------------------------------------------------------------------------------------------------------------------------------

        public TryStatement(Action body)
        {
            m_TryBlock     = new StatementBlock();
            m_CatchBlocks  = new List <CatchBlock>();
            m_FinallyBlock = new StatementBlock();
            m_LeaveBlocks  = new List <LeaveBlock>();

            using (new StatementScope(m_TryBlock, this, ExceptionBlockType.Try))
            {
                body();
            }
        }
Ejemplo n.º 11
0
        //-----------------------------------------------------------------------------------------------------------------------------------------------------

        public ProceedStatement(MethodMember ownerMethod, MethodWriterBase[] decoratedWriters, IMutableOperand returnValueLocal)
        {
            m_OwnerMethod         = ownerMethod;
            m_DecoratedStatements = new StatementBlock();
            m_ReturnValueLocal    = returnValueLocal;

            using (var scope = new StatementScope(m_DecoratedStatements /*, exceptionStatement: null, blockType: ExceptionBlockType.None*/))
            {
                m_LeaveLabel = scope.DefineLabel();

                foreach (var writer in decoratedWriters)
                {
                    writer.SetupDecoratedMode(returnValueLocal, m_LeaveLabel);
                    writer.Flush();
                }

                m_LeaveLabel.MarkLabel();
            }
        }
Ejemplo n.º 12
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);
        }
Ejemplo n.º 13
0
        //-----------------------------------------------------------------------------------------------------------------------------------------------------

        public void BindToMethod(MethodMember ownerMethod)
        {
            m_OwnerMethod = ownerMethod;
            m_ParentBlock = null;
        }
Ejemplo n.º 14
0
        //-----------------------------------------------------------------------------------------------------------------------------------------------------

        public LockStatement(IOperand <object> syncRoot, int millisecondsTimeout)
        {
            m_SyncRoot            = syncRoot;
            m_MillisecondsTimeout = millisecondsTimeout;
            m_BodyBlock           = new StatementBlock();
        }
Ejemplo n.º 15
0
        //-----------------------------------------------------------------------------------------------------------------------------------------------------

        public StatementScope(StatementBlock statementBlock)
            : this(statementBlock, attachStatementBlock : true)
        {
        }
Ejemplo n.º 16
0
        //-----------------------------------------------------------------------------------------------------------------------------------------------------

        private StatementBlock AttachStatementBlock(StatementBlock statementBlock)
        {
            statementBlock.Attach(this);
            return(statementBlock);
        }
Ejemplo n.º 17
0
        //-----------------------------------------------------------------------------------------------------------------------------------------------------

        public StatementScope(ClassType ownerClass, MethodMember method, StatementBlock statementBlock)
            : this(ownerClass, method.TransparentWriter, statementBlock)
        {
        }
Ejemplo n.º 18
0
        //-----------------------------------------------------------------------------------------------------------------------------------------------------

        public ForeachStatement(Local <TElement> element)
        {
            m_Element   = element;
            m_BodyBlock = new StatementBlock();
        }
Ejemplo n.º 19
0
        //-----------------------------------------------------------------------------------------------------------------------------------------------------

        public StatementScope(StatementBlock statementBlock, LoopStatementBase loopStatement)
            : this(statementBlock, attachStatementBlock : false)
        {
            m_InheritedLoopStatement = loopStatement;
            m_StatementBlock         = AttachStatementBlock(statementBlock);
        }
Ejemplo n.º 20
0
        //-----------------------------------------------------------------------------------------------------------------------------------------------------

        public UsingStatement(IOperand <IDisposable> disposable)
        {
            m_Disposable = disposable;
            m_BodyBlock  = new StatementBlock();
        }