Lexikos: ACT_WHILE
| 10791 | |
| 10792 | // Lexikos: ACT_WHILE |
| 10793 | ResultType Line::PerformLoopWhile(ResultToken *aResultToken, Line *&aJumpToLine) |
| 10794 | { |
| 10795 | ResultType result = CONDITION_FALSE; |
| 10796 | Line *jump_to_line = nullptr; |
| 10797 | global_struct &g = *::g; // Might slightly speed up the loop below. |
| 10798 | |
| 10799 | for (;; ++g.mLoopIteration) |
| 10800 | { |
| 10801 | g_script.mCurrLine = this; // For error-reporting purposes. |
| 10802 | #ifdef CONFIG_DEBUGGER |
| 10803 | // L31: Let the debugger break at the 'While' line each iteration. Before this change, |
| 10804 | // a While loop with empty body such as While FuncWithSideEffect() {} would be "hit" |
| 10805 | // (via breakpoint or step) only once even if the loop had multiple iterations. |
| 10806 | // A_Index was also reported as "0"; it will now be reported correctly. |
| 10807 | if (g_Debugger.IsConnected()) |
| 10808 | g_Debugger.PreExecLine(this); |
| 10809 | #endif |
| 10810 | // Evaluate the expression only now that A_Index has been set. |
| 10811 | auto args_result = ExpandArgs(); |
| 10812 | if (args_result != OK) |
| 10813 | return args_result; |
| 10814 | |
| 10815 | // Unlike if(expression), performance isn't significantly improved to make cases like |
| 10816 | // "while x" and "while %x%" into non-expressions (the latter actually performs much |
| 10817 | // better as an expression). That is why the following check is much simpler than the |
| 10818 | // one used at ACT_IF in EvaluateCondition(): |
| 10819 | if (!ResultToBOOL(ARG1)) |
| 10820 | break; |
| 10821 | |
| 10822 | PERFORMLOOP_EXECUTE_BODY |
| 10823 | |
| 10824 | // Before re-evaluating the condition, add it to the ListLines log again. This is done |
| 10825 | // at the end of the loop rather than the beginning because ExecUntil already added the |
| 10826 | // line once immediately before the first iteration. |
| 10827 | if (g.ListLinesIsEnabled) |
| 10828 | LOG_LINE(this) |
| 10829 | } // for() |
| 10830 | return result; // The script's loop is now over. |
| 10831 | } |
| 10832 | |
| 10833 | |
| 10834 |
no test coverage detected