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); }
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); }
void WriteAssign(AssignActionBlock block) { WriteExpression(block.AssignExpression); }