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