private static bool HasNoSideEffectsInBetween(ILStatement statement, ILExpression expression) { // Check if all expressions that are evaluated before the provided expression in the same containing statement // have potential side effects. var currentExpression = expression; while (true) { // Obtain the parent expression that contains the argument. var parentExpression = currentExpression.Parent as IILArgumentsProvider; if (parentExpression == null) { break; } // Figure out if all arguments evaluated before the current expression have any potential side effects. for (int i = 0; parentExpression.Arguments[i] != currentExpression; i++) { if (i >= parentExpression.Arguments.Count || parentExpression.Arguments[i].HasPotentialSideEffects) { return(true); } } currentExpression = (ILExpression)parentExpression; } // Verify that the two statements occur in the same block. var statement2 = (ILStatement)currentExpression.Parent; var block = (ILAstBlock)statement2.Parent; if ((ILAstBlock)statement.Parent != block) { return(true); } // Start at the first statement, and move up till we find the second statement containing the expression, // and figure out if any of the statements in between have potential side effects. int startIndex = block.Statements.IndexOf(statement); for (int i = startIndex + 1; block.Statements[i] != statement2; i++) { if (i >= block.Statements.Count || block.Statements[i].HasPotentialSideEffects) { return(true); } } // Nothing has been found that could cause side effects. return(false); }
public void AddStatement(ILStatement statement) { block.AddStatement(statement); }
public void Compile(CmlContext context, CmlScriptRequest request, CmlScriptValue this_value) { il_statement = CompileILStatement(context, request, this_value); }