| 94 | } |
| 95 | |
| 96 | bool ControlParser::parseWhileBody(int keyword, const TokenLoc& loc, Scanner& scanner) |
| 97 | { |
| 98 | if (keyword == Scanner::K_endwhile) |
| 99 | { |
| 100 | Codes loop; |
| 101 | |
| 102 | Codes expr; |
| 103 | mExprParser.append(expr); |
| 104 | |
| 105 | Generator::jump(loop, -static_cast<int>(mCodeBlock.size() + expr.size())); |
| 106 | |
| 107 | std::copy(expr.begin(), expr.end(), std::back_inserter(mCode)); |
| 108 | |
| 109 | Codes skip; |
| 110 | |
| 111 | Generator::jumpOnZero(skip, static_cast<int>(mCodeBlock.size() + loop.size() + 1)); |
| 112 | |
| 113 | std::copy(skip.begin(), skip.end(), std::back_inserter(mCode)); |
| 114 | |
| 115 | std::copy(mCodeBlock.begin(), mCodeBlock.end(), std::back_inserter(mCode)); |
| 116 | |
| 117 | Codes loop2; |
| 118 | |
| 119 | Generator::jump(loop2, -static_cast<int>(mCodeBlock.size() + expr.size() + skip.size())); |
| 120 | |
| 121 | if (loop.size() != loop2.size()) |
| 122 | throw std::logic_error("Internal compiler error: failed to generate a while loop"); |
| 123 | |
| 124 | std::copy(loop2.begin(), loop2.end(), std::back_inserter(mCode)); |
| 125 | |
| 126 | mState = WhileEndwhileState; |
| 127 | return true; |
| 128 | } |
| 129 | else if (keyword == Scanner::K_if || keyword == Scanner::K_while) |
| 130 | { |
| 131 | // nested |
| 132 | ControlParser parser(getErrorHandler(), getContext(), mLocals, mLiterals); |
| 133 | |
| 134 | if (parser.parseKeyword(keyword, loc, scanner)) |
| 135 | scanner.scan(parser); |
| 136 | |
| 137 | parser.appendCode(mCodeBlock); |
| 138 | |
| 139 | return true; |
| 140 | } |
| 141 | else |
| 142 | { |
| 143 | mLineParser.reset(); |
| 144 | if (mLineParser.parseKeyword(keyword, loc, scanner)) |
| 145 | scanner.scan(mLineParser); |
| 146 | |
| 147 | return true; |
| 148 | } |
| 149 | } |
| 150 | |
| 151 | ControlParser::ControlParser(ErrorHandler& errorHandler, const Context& context, Locals& locals, Literals& literals) |
| 152 | : Parser(errorHandler, context) |
nothing calls this directly
no test coverage detected