/// <summary> /// Notifies this context when exiting a loop. /// </summary> internal void ExitLoop(ScriptLoopStatementBase loop) { OnExitLoop(loop); PopVariableScope(ScriptVariableScope.Loop); _loops.Pop(); _loopStep = 0; }
internal void EnterLoop(ScriptLoopStatementBase loop) { if (loop == null) { throw new ArgumentNullException(nameof(loop)); } loops.Push(loop); PushVariableScope(ScriptVariableScope.Loop); }
internal bool StepLoop(ScriptLoopStatementBase loop) { Debug.Assert(_loops.Count > 0); _loopStep++; if (_loopStep > LoopLimit) { var currentLoopStatement = _loops.Peek(); throw new ScriptRuntimeException(currentLoopStatement.Span, $"Exceeding number of iteration limit `{LoopLimit}` for loop statement."); // unit test: 215-for-statement-error1.txt } return(OnStepLoop(loop)); }
internal bool StepLoop(ScriptLoopStatementBase loop) { #if DEBUG Debug.Assert(_loops.Count > 0); #endif _loopStep++; if (_loopStep > LoopLimit) { ScriptLoopStatementBase currentLoopStatement = _loops.Peek(); throw new ScriptRuntimeException(currentLoopStatement.Span, string.Format(RS.IterationDepthLimitReached, LoopLimit, currentLoopStatement)); // unit test: 215-for-statement-error1.txt } return(OnStepLoop(loop)); }
/// <summary> /// Called when entering a loop. /// </summary> /// <param name="loop">The loop expression object</param> protected virtual void OnEnterLoop(ScriptLoopStatementBase loop) { }
/// <summary> /// Called when stepping into a loop. /// </summary> /// <param name="loop">The loop expression object</param> /// <returns><c>true</c> to continue loop; <c>false</c> to break the loop. Default is <c>true</c></returns> protected virtual bool OnStepLoop(ScriptLoopStatementBase loop) { return(true); }
/// <summary> /// Extracts a statement /// </summary> /// <param name="scriptStatements">Statement list to fill</param> /// <param name="statement">Statement to check</param> private static void ExtractStatement(List <ScriptStatement> scriptStatements, ScriptStatement statement) { if (!(statement is ScriptRawStatement)) { scriptStatements.Add(statement); } if (statement is ScriptLoopStatementBase) { ScriptLoopStatementBase loopStatement = (ScriptLoopStatementBase)statement; foreach (ScriptNode curChild in loopStatement.Children) { ScriptStatement curStatement = curChild as ScriptStatement; if (curStatement != null) { ExtractStatement(scriptStatements, curStatement); } } } else if (statement is ScriptIfStatement) { ScriptIfStatement ifStatement = (ScriptIfStatement)statement; if (ifStatement.Then != null) { scriptStatements.AddRange(ExtractStatementsFromList(ifStatement.Then.Statements)); } if (ifStatement.Else != null) { ExtractStatement(scriptStatements, ifStatement.Else); } } else if (statement is ScriptElseStatement) { ScriptElseStatement elseStatement = (ScriptElseStatement)statement; if (elseStatement.Body != null) { scriptStatements.AddRange(ExtractStatementsFromList(elseStatement.Body.Statements)); } } else if (statement is ScriptCaptureStatement) { ScriptCaptureStatement captureStatement = (ScriptCaptureStatement)statement; if (captureStatement.Body != null) { scriptStatements.AddRange(ExtractStatementsFromList(captureStatement.Body.Statements)); } } else if (statement is ScriptCaseStatement) { ScriptCaseStatement caseStatement = (ScriptCaseStatement)statement; if (caseStatement.Body != null) { scriptStatements.AddRange(ExtractStatementsFromList(caseStatement.Body.Statements)); } } else if (statement is ScriptFunction) { ScriptFunction functionStatement = (ScriptFunction)statement; if (functionStatement.Body != null) { ExtractStatement(scriptStatements, functionStatement.Body); } } else if (statement is ScriptWhenStatement) { ScriptWhenStatement whenStatement = (ScriptWhenStatement)statement; if (whenStatement.Body != null) { scriptStatements.AddRange(ExtractStatementsFromList(whenStatement.Body.Statements)); } } else if (statement is ScriptWithStatement) { ScriptWithStatement withStatement = (ScriptWithStatement)statement; if (withStatement.Body != null) { scriptStatements.AddRange(ExtractStatementsFromList(withStatement.Body.Statements)); } } else if (statement is ScriptWrapStatement) { ScriptWrapStatement wrapStatement = (ScriptWrapStatement)statement; if (wrapStatement.Body != null) { scriptStatements.AddRange(ExtractStatementsFromList(wrapStatement.Body.Statements)); } } else if (statement is ScriptBlockStatement) { ScriptBlockStatement blockStatement = (ScriptBlockStatement)statement; scriptStatements.AddRange(ExtractStatementsFromList(blockStatement.Statements)); } }