MCPcopy Create free account
hub / github.com/Flow-IPC/ipc / Script_interpreter

Method Script_interpreter

test/suite/transport_test/script_interpreter.cpp:298–366  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

296}
297
298Script_interpreter::Script_interpreter(flow::log::Logger* logger_ptr, flow::log::Logger* ipc_logger_ptr,
299 std::istream& is) :
300 flow::log::Log_context(logger_ptr),
301 m_ipc_logger(ipc_logger_ptr),
302 m_is(is),
303 m_cur_line_idx(0),
304 m_test_blob_stream_mq_peers
305 ({ { std::type_index(typeid(Posix_mq_sender)), Mq_peer_list<Posix_mq_sender>() },
306 { std::type_index(typeid(Bipc_mq_sender)), Mq_peer_list<Bipc_mq_sender>() },
307 { std::type_index(typeid(Posix_mq_receiver)), Mq_peer_list<Posix_mq_receiver>() },
308 { std::type_index(typeid(Bipc_mq_receiver)), Mq_peer_list<Bipc_mq_receiver>() } }),
309 m_test_chan_bundles
310 ({ { std::type_index(typeid(Posix_mqs_socket_stream_channel)),
311 Chan_bundle_list<Posix_mqs_socket_stream_channel>() },
312 { std::type_index(typeid(Bipc_mqs_socket_stream_channel)),
313 Chan_bundle_list<Bipc_mqs_socket_stream_channel>() } })
314{
315 using std::string;
316 using boost::algorithm::trim;
317
318 FLOW_LOG_TRACE("Interpreter is about to read all lines without tokenizing.");
319
320 // This can be perf-ier probably by using getline(), etc., but we don't care.
321 string line;
322 while (is.good())
323 {
324 const int ch_get = is.get();
325 if (!is.good())
326 {
327 continue;
328 }
329 // else
330
331 const auto ch = char(ch_get);
332 if (ch == '\n')
333 {
334 trim(line);
335 if (line.empty() || line.front() == '#')
336 {
337 m_lines.push_back("");
338 FLOW_LOG_TRACE("Line completed, ignored (blank or comment): [" << line << "], stored as blank.");
339 /* Subtlety: We could just not push_back() it at all; but then line counts get messed up resulting in
340 * bad error messages. We could also remember the full line, and the parser would skip them manually;
341 * but then in my (ygoldfel) experience the
342 * error messages look odd when printing context. Though, to be honest, I now don't remember the details;
343 * I just know I dumbly "fixed" it by not remembering the line at all -- which screwed up line numbers.
344 * So then I "re-fixed" it but saving the line but only as blank. */
345 }
346 else
347 {
348 m_lines.push_back(line);
349 FLOW_LOG_TRACE("Line completed, stored: [" << line << "].");
350 }
351 line.clear();
352 }
353 else
354 {
355 line += ch;

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected