| 1261 | } |
| 1262 | |
| 1263 | void translator_type::translate(const context_t &context, const std::deque<std::deque<token_base *>> &lines, |
| 1264 | std::deque<statement_base *> &statements, bool raw) |
| 1265 | { |
| 1266 | std::size_t method_line_num = 0, line_num = 0; |
| 1267 | std::deque<std::deque<token_base *>> tmp; |
| 1268 | stack_type<method_base *> methods; |
| 1269 | for (auto &it : lines) { |
| 1270 | std::deque<token_base *> line = it; |
| 1271 | line_num = static_cast<token_endline *>(line.back())->get_line_num(); |
| 1272 | try { |
| 1273 | if (raw) |
| 1274 | context->compiler->process_line(line); |
| 1275 | method_base *m = this->match(line); |
| 1276 | switch (m->get_type()) { |
| 1277 | case method_types::null: |
| 1278 | throw compile_error("Null type of grammar."); |
| 1279 | break; |
| 1280 | case method_types::single: { |
| 1281 | statement_base *sptr = nullptr; |
| 1282 | if (!methods.empty()) { |
| 1283 | method_base *expected_method = nullptr; |
| 1284 | if (m->get_target_type() == statement_types::end_) { |
| 1285 | if (raw) { |
| 1286 | context->instance->storage.remove_set(); |
| 1287 | domain_type domain = std::move(context->instance->storage.get_domain()); |
| 1288 | context->instance->storage.remove_domain(); |
| 1289 | methods.top()->postprocess(context, domain); |
| 1290 | } |
| 1291 | expected_method = methods.top(); |
| 1292 | methods.pop(); |
| 1293 | } |
| 1294 | if (methods.empty()) { |
| 1295 | line_num = method_line_num; |
| 1296 | if (m->get_target_type() == statement_types::end_) |
| 1297 | sptr = static_cast<method_end *>(m)->translate_end(expected_method, context, tmp, |
| 1298 | line); |
| 1299 | else |
| 1300 | sptr = expected_method->translate(context, tmp); |
| 1301 | tmp.clear(); |
| 1302 | } |
| 1303 | else { |
| 1304 | if (raw) |
| 1305 | m->preprocess(context, {line}); |
| 1306 | tmp.push_back(line); |
| 1307 | } |
| 1308 | } |
| 1309 | else { |
| 1310 | if (m->get_target_type() == statement_types::end_) |
| 1311 | throw compile_error("Hanging end statement."); |
| 1312 | else { |
| 1313 | if (raw) |
| 1314 | m->preprocess(context, {line}); |
| 1315 | sptr = m->translate(context, {line}); |
| 1316 | } |
| 1317 | } |
| 1318 | if (sptr != nullptr) |
| 1319 | statements.push_back(sptr); |
| 1320 | } |
nothing calls this directly
no test coverage detected