4
Copyright (c) 2021 МГТУ им. Н.Э. Баумана, кафедра ИУ-6, Михаил Фетисов,
6
https://bmstu.codes/lsx/simodo/loom
9
#include "simodo/ast/generator/FormationWrapper.h"
15
void FormationWrapper::addNode(const std::u16string & host,
17
const inout::Token & op_symbol,
18
const inout::Token & bound)
20
FormationFlow & stream = getStream_mutable(_current_stream_no);
22
stream.addNode(host, op, op_symbol, bound);
25
void FormationWrapper::addNode_StepInto(const std::u16string & host,
27
const inout::Token & op_symbol,
28
const inout::Token & bound)
30
FormationFlow & stream = getStream_mutable(_current_stream_no);
32
stream.addNode_StepInto(host, op, op_symbol, bound);
35
bool FormationWrapper::goParent()
37
FormationFlow & stream = getStream_mutable(_current_stream_no);
39
return stream.goParent();
42
void FormationWrapper::addFile(const std::string & file_path)
44
auto it = _ast_streams.find(_current_stream_no);
46
if (it == _ast_streams.end())
49
it->second.addFile(file_path);
52
const ast::Tree & FormationWrapper::tree() const
54
if (!_tree.root().branches().empty())
57
auto it = _ast_streams.find(_current_stream_no);
59
if (it == _ast_streams.end()) {
60
static Tree static_ast;
64
return it->second.tree();
67
void FormationWrapper::finalize()
69
_tree._root._branches.swap(_main_stream._tree._root._branches);
70
_tree._files.swap(_main_stream._tree._files);
72
auto & wb = _tree._root._branches;
74
for(auto & [no,s] : _ast_streams) {
75
assert(no != DEFAULT_STREAM_NO);
77
auto & sb = s._tree._root.branches();
79
wb.insert(wb.end(), sb.begin(), sb.end());
83
const FormationFlow &FormationWrapper::getStream(uint16_t no)
85
static FormationFlow dummy;
87
auto it = _ast_streams.find(no);
89
if (it == _ast_streams.end())
95
void FormationWrapper::removeStream(uint16_t no)
97
_ast_streams.erase(no);
100
FormationFlow &FormationWrapper::getStream_mutable(uint16_t stream_no)
102
if (stream_no == DEFAULT_STREAM_NO)
105
/// \todo Нужно оптимизировать из соображений, что чаще всего будет работать один номер потока
107
auto it = _ast_streams.find(stream_no);
109
if (it != _ast_streams.end())
112
auto [it_new, ok] = _ast_streams.emplace(stream_no,FormationFlow());
116
return it_new->second;