OPALX (Object Oriented Parallel Accelerator Library for Exascal) master (dc2a29eed580)
OPALX
Loading...
Searching...
No Matches
Union.cpp
Go to the documentation of this file.
2
3#include <regex>
4
5namespace mslang {
6 void Union::print(int indentwidth) {
7 std::string indent(indentwidth, ' ');
8 std::string indent2(indentwidth + 8, ' ');
9 std::string indent3(indentwidth + 16, ' ');
10 std::cout << indent << "union, " << std::endl;
11 std::cout << indent2 << "funcs: {\n";
12 funcs_m.front()->print(indentwidth + 16);
13 for (unsigned int i = 1; i < funcs_m.size(); ++i) {
14 std::cout << "\n" << indent3 << "," << std::endl;
15 funcs_m[i]->print(indentwidth + 16);
16 }
17 std::cout << "\n" << indent2 << "} ";
18 }
19
20 void Union::apply(std::vector<std::shared_ptr<Base> >& bfuncs) {
21 for (unsigned int i = 0; i < funcs_m.size(); ++i) {
22 std::vector<std::shared_ptr<Base> > children;
23 Function* func = funcs_m[i];
24 func->apply(children);
25 bfuncs.insert(bfuncs.end(), children.begin(), children.end());
26 }
27 }
28
29 bool Union::parse_detail(iterator& it, const iterator& end, Function*& fun) {
30 Union* unin = static_cast<Union*>(fun);
31 unin->funcs_m.push_back(nullptr);
32 if (!parse(it, end, unin->funcs_m.back())) return false;
33
34 std::regex argumentList("(,[a-z]+\\(.*)");
35 std::regex endParenthesis("\\)(.*)");
36 std::smatch what;
37
38 std::string str(it, end);
39 while (std::regex_match(str, what, argumentList)) {
40 iterator it2 = it + 1;
41 unin->funcs_m.push_back(nullptr);
42
43 if (!parse(it2, end, unin->funcs_m.back())) return false;
44
45 it = it2;
46 str = std::string(it, end);
47 }
48
49 str = std::string(it, end);
50 if (!std::regex_match(str, what, endParenthesis)) return false;
51
52 std::string fullMatch = what[0];
53 std::string rest = what[1];
54
55 it += (fullMatch.size() - rest.size());
56
57 return true;
58 }
59} // namespace mslang
std::string::iterator iterator
Definition MSLang.h:14
virtual void apply(std::vector< std::shared_ptr< Base > > &bfuncs)=0
static bool parse(iterator &it, const iterator &end, Function *&fun)
Definition MSLang.cpp:47
static bool parse_detail(iterator &it, const iterator &end, Function *&fun)
Definition Union.cpp:29
std::vector< Function * > funcs_m
Definition Union.h:8
virtual void print(int indentwidth)
Definition Union.cpp:6
virtual void apply(std::vector< std::shared_ptr< Base > > &bfuncs)
Definition Union.cpp:20