public override void Visit(DoWhile node) { if (node != null) { // if we are stripping debugger statements and the body is // just a debugger statement, replace it with a null if (m_parser.Settings.StripDebugStatements && m_parser.Settings.IsModificationAllowed(TreeModifications.StripDebugStatements) && node.Body != null && node.Body.IsDebuggerStatement) { node.ReplaceChild(node.Body, null); } // recurse base.Visit(node); // if the body is now empty, make it null if (node.Body != null && node.Body.Count == 0) { node.ReplaceChild(node.Body, null); } } }
public override void Visit(DoWhile node) { if (node != null) { // depth-first base.Visit(node); if (m_parser.Settings.IsModificationAllowed(TreeModifications.EvaluateNumericExpressions)) { // if the condition is a constant, we can simplify things ConstantWrapper constantCondition = node.Condition as ConstantWrapper; if (constantCondition != null && constantCondition.IsNotOneOrPositiveZero) { try { // the condition is a constant, so it is always either true or false // we can replace the condition with a one or a zero -- only one byte node.ReplaceChild(node.Condition, new ConstantWrapper(constantCondition.ToBoolean() ? 1 : 0, PrimitiveType.Number, node.Condition.Context, m_parser)); } catch (InvalidCastException) { // ignore any invalid cast errors } } } } }