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