Ejemplo n.º 1
0
        private ActionBlock OnAssign(AssignActionBlock block)
        {
            var assign   = block.AssignExpression;
            var variable = assign.Target as VariableReferenceExpression;

            if (variable == null)
            {
                CannotOptimize(assign);
            }
            if (HasBeenAlreadyAssignedTo(variable))
            {
                CannotOptimize(assign.Expression);
            }

            _variables.Add(GetVariableIndex(variable), assign.Expression);

            return(block.Next);
        }
Ejemplo n.º 2
0
        private static Expression GetQueryExpression(ActionFlowGraph afg)
        {
            IDictionary <int, Expression> variables = new Dictionary <int, Expression>();
            ActionBlock block = afg.Blocks[0];

            while (block != null)
            {
                switch (block.ActionType)
                {
                case ActionType.Invoke:
                    InvokeActionBlock          invokeBlock = (InvokeActionBlock)block;
                    MethodInvocationExpression invocation  = invokeBlock.Expression;
                    if (IsActivateInvocation(invocation) ||
                        IsNoSideEffectIndirectActivationInvocation(invocation))
                    {
                        block = invokeBlock.Next;
                        break;
                    }

                    UnsupportedExpression(invocation);
                    break;

                case ActionType.ConditionalBranch:
                    UnsupportedPredicate("Conditional blocks are not supported.");
                    break;

                case ActionType.Branch:
                    block = ((BranchActionBlock)block).Target;
                    break;

                case ActionType.Assign:
                {
                    AssignActionBlock           assignBlock = (AssignActionBlock)block;
                    AssignExpression            assign      = assignBlock.AssignExpression;
                    VariableReferenceExpression variable    = assign.Target as VariableReferenceExpression;
                    if (null == variable)
                    {
                        UnsupportedExpression(assign);
                    }
                    else
                    {
                        if (variables.ContainsKey(variable.Variable.Index))
                        {
                            UnsupportedExpression(assign.Expression);
                        }

                        variables.Add(variable.Variable.Index, assign.Expression);
                        block = assignBlock.Next;
                    }
                    break;
                }

                case ActionType.Return:
                {
                    Expression expression = ((ReturnActionBlock)block).Expression;
                    VariableReferenceExpression variable = expression as VariableReferenceExpression;
                    return(null == variable
                                                                ? expression
                                                                : variables[variable.Variable.Index]);
                }
                }
            }
            return(null);
        }
Ejemplo n.º 3
0
 void WriteAssign(AssignActionBlock block)
 {
     WriteExpression(block.AssignExpression);
 }