AMPI: drop comm argument from AMPI_Comm_set_migratable and rename to AMPI_Set_migratable
[charm.git] / src / xlat-i / xi-AstNode.h
blobbb9595f1f84ca8f77067560bc5c620b615ded8fd
1 #ifndef _AST_NODE_H
2 #define _AST_NODE_H
4 #include "xi-util.h"
5 #include <list>
6 #include <algorithm>
8 namespace xi {
10 class AstNode : public Printable {
11 protected:
12 int line;
14 public:
15 explicit AstNode(int line_ = -1) : line(line_) { }
16 virtual void outputClosuresDecl(XStr& str) { (void)str; }
17 virtual void outputClosuresDef(XStr& str) { (void)str; }
18 virtual void genDecls(XStr& str) { (void)str; }
19 virtual void genDefs(XStr& str) { (void)str; }
20 virtual void genClosureEntryDecls(XStr& str) { }
21 virtual void genClosureEntryDefs(XStr& str) { }
22 virtual void genReg(XStr& str) { (void)str; }
23 virtual void genGlobalCode(XStr scope, XStr &decls, XStr &defs)
24 { (void)scope; (void)decls; (void)defs; }
25 virtual void preprocess() { }
26 virtual void check() { }
27 virtual void printChareNames() { }
29 virtual void genTramTypes() {}
30 virtual void genTramRegs(XStr &str) { (void)str; }
31 virtual void genTramPups(XStr& scope, XStr &decls, XStr &defs)
32 { (void) scope; (void)decls; (void)defs; }
34 // DMK - Accel Support
35 virtual int genAccels_spe_c_funcBodies(XStr& str) { (void)str; return 0; }
36 virtual void genAccels_spe_c_regFuncs(XStr& str) { (void)str; }
37 virtual void genAccels_spe_c_callInits(XStr& str) { (void)str; }
38 virtual void genAccels_spe_h_includes(XStr& str) { (void)str; }
39 virtual void genAccels_spe_h_fiCountDefs(XStr& str) { (void)str; }
40 virtual void genAccels_ppe_c_regFuncs(XStr& str) { (void)str; }
43 template <typename Child>
44 class AstChildren : public virtual AstNode {
45 protected:
46 std::list<Child*> children;
48 public:
49 AstChildren(int line_, Child *c, AstChildren *cs)
50 : AstNode(line_)
52 children.push_back(c);
53 if (cs)
54 children.insert(children.end(), cs->children.begin(), cs->children.end());
57 template <typename T>
58 explicit AstChildren(std::list<T*> &l)
60 children.insert(children.begin(), l.begin(), l.end());
61 l.clear();
63 void push_back(Child *c);
65 void preprocess();
66 void check();
67 void print(XStr& str);
69 void printChareNames();
71 void outputClosuresDecl(XStr& str);
72 void outputClosuresDef(XStr& str);
74 void genClosureEntryDecls(XStr& str);
75 void genClosureEntryDefs(XStr& str);
76 void genDecls(XStr& str);
77 void genDefs(XStr& str);
78 void genReg(XStr& str);
79 void genGlobalCode(XStr scope, XStr &decls, XStr &defs);
81 void genTramTypes();
82 void genTramRegs(XStr& str);
83 void genTramPups(XStr& scope, XStr &decls, XStr &defs);
85 // Accelerated Entry Method support
86 int genAccels_spe_c_funcBodies(XStr& str);
87 void genAccels_spe_c_regFuncs(XStr& str);
88 void genAccels_spe_c_callInits(XStr& str);
89 void genAccels_spe_h_includes(XStr& str);
90 void genAccels_spe_h_fiCountDefs(XStr& str);
91 void genAccels_ppe_c_regFuncs(XStr& str);
93 template <typename T>
94 void recurse(T arg, void (Child::*fn)(T));
95 void recursev(void (Child::*fn)());
98 namespace details {
99 using std::list;
100 using std::for_each;
103 Apply fn_ on each Construct in the list l, passing it arg as
104 the target. If between_ is passed, do that to arg between each
105 element.
107 template<typename T, typename U, typename A>
108 class perElemGenC
110 void (U::*fn)(A);
111 void (*between)(A);
112 A arg;
114 public:
115 perElemGenC(list<T*> &l,
116 A arg_,
117 void (U::*fn_)(A),
118 void (*between_)(A) = NULL)
119 : fn(fn_), between(between_), arg(arg_)
121 for_each(l.begin(), l.end(), *this);
123 void operator()(T* m)
125 if (m)
127 (m->*fn)(arg);
128 if (between)
129 between(arg);
134 template<typename T, typename U, typename A>
135 void perElemGen(list<T*> &l, A& arg_, void (U::*fn_)(A&),
136 // Sun Studio 7 (C++ compiler version 5.4) can't handle this
137 // void (*between_)(A&) = NULL)
138 void (*between_)(A&))
140 perElemGenC<T, U, A&>(l, arg_, fn_, between_);
143 template<typename T, typename U, typename A>
144 void perElemGen(list<T*> &l, A& arg_, void (U::*fn_)(A&))
146 perElemGenC<T, U, A&>(l, arg_, fn_, NULL);
149 template<typename T, typename U, typename A>
150 void perElemGen(list<T*> &l, A* arg_, void (U::*fn_)(A*),
151 // See above
152 // void (*between_)(A*) = NULL)
153 void (*between_)(A*))
155 perElemGenC<T, U, A*>(l, arg_, fn_, between_);
158 template<typename T, typename U, typename A>
159 void perElemGen(list<T*> &l, A* arg_, void (U::*fn_)(A*))
161 perElemGenC<T, U, A*>(l, arg_, fn_, NULL);
165 Apply fn_ on each Construct in the list l, passing it arg as
166 the target. If between_ is passed, do that to arg between each
167 element.
169 template<typename T, typename U, typename A>
170 class perElemGen2C
172 void (U::*fn)(A,A);
173 void (*between)(A,A);
174 A arg1, arg2;
176 public:
177 perElemGen2C(list<T*> &l,
178 A arg1_, A arg2_,
179 void (U::*fn_)(A,A),
180 void (*between_)(A,A) = NULL)
181 : fn(fn_), between(between_), arg1(arg1_), arg2(arg2_)
183 for_each(l.begin(), l.end(), *this);
185 void operator()(T* m)
187 if (m)
189 (m->*fn)(arg1, arg2);
190 if (between)
191 between(arg1, arg2);
196 template<typename T, typename U, typename A>
197 void perElemGen2(list<T*> &l, A& arg1_, A& arg2_, void (U::*fn_)(A&,A&),
198 // Sun Studio 7 (C++ compiler version 5.4) can't handle this
199 // void (*between_)(A&) = NULL)
200 void (*between_)(A&,A&))
202 perElemGen2C<T, U, A&>(l, arg1_, arg2_, fn_, between_);
205 template<typename T, typename U, typename A>
206 void perElemGen2(list<T*> &l, A& arg1_, A& arg2_, void (U::*fn_)(A&,A&))
208 perElemGen2C<T, U, A&>(l, arg1_, arg2_, fn_, NULL);
211 template<typename T, typename U, typename A>
212 void perElemGen2(list<T*> &l, A* arg1_, A* arg2_, void (U::*fn_)(A*,A*),
213 // See above
214 // void (*between_)(A*) = NULL)
215 void (*between_)(A*,A*))
217 perElemGen2C<T, U, A*>(l, arg1_, arg2_, fn_, between_);
220 template<typename T, typename U, typename A>
221 void perElemGen2(list<T*> &l, A* arg1_, A* arg2_, void (U::*fn_)(A*,A*))
223 perElemGen2C<T, U, A*>(l, arg1_, arg2_, fn_, NULL);
227 Apply fn_ on each non-NULL element in the list l.
228 If between_ is passed, do that between each element.
230 template<typename T, typename U>
231 class perElemC
233 void (U::*fn)();
234 public:
235 perElemC(list<T*> &l,
236 void (U::*fn_)())
237 : fn(fn_)
239 for_each(l.begin(), l.end(), *this);
241 void operator()(T* m)
243 if (m) {
244 (m->*fn)();
249 template<typename T, typename U>
250 void perElem(list<T*> &l, void (U::*fn_)())
252 perElemC<T, U>(l, fn_);
255 void newLine(XStr &str);
256 } // namespace details
259 template <typename Child>
260 void AstChildren<Child>::push_back(Child *m)
262 children.push_back(m);
265 template <typename Child>
266 void AstChildren<Child>::print(XStr& str)
268 details::perElemGen(children, str, &Child::print);
271 template <typename Child>
272 void AstChildren<Child>::preprocess()
274 details::perElem(children, &Child::preprocess);
277 template <typename Child>
278 void AstChildren<Child>::check() {
279 details::perElem(children, &Child::check);
282 template <typename Child>
283 void AstChildren<Child>::genDecls(XStr& str)
285 details::perElemGen(children, str, &Child::genDecls, details::newLine);
288 template <typename Child>
289 void AstChildren<Child>::genClosureEntryDecls(XStr& str)
291 details::perElemGen(children, str, &Child::genClosureEntryDecls, details::newLine);
294 template <typename Child>
295 void AstChildren<Child>::genClosureEntryDefs(XStr& str)
297 details::perElemGen(children, str, &Child::genClosureEntryDefs, details::newLine);
300 template <typename Child>
301 void AstChildren<Child>::outputClosuresDecl(XStr& str)
303 details::perElemGen(children, str, &Child::outputClosuresDecl, details::newLine);
306 template <typename Child>
307 void AstChildren<Child>::outputClosuresDef(XStr& str)
309 details::perElemGen(children, str, &Child::outputClosuresDef, details::newLine);
312 template <typename Child>
313 void AstChildren<Child>::genDefs(XStr& str)
315 details::perElemGen(children, str, &Child::genDefs, details::newLine);
318 template <typename Child>
319 void AstChildren<Child>::genReg(XStr& str)
321 details::perElemGen(children, str, &Child::genReg, details::newLine);
324 template <typename Child>
325 template <typename T>
326 void AstChildren<Child>::recurse(T t, void (Child::*fn)(T))
328 details::perElemGen(children, t, fn);
331 template <typename Child>
332 void AstChildren<Child>::recursev(void (Child::*fn)())
334 details::perElem(children, fn);
337 template <typename Child>
338 void AstChildren<Child>::genGlobalCode(XStr scope, XStr &decls, XStr &defs)
340 for (typename std::list<Child*>::iterator i = children.begin(); i != children.end(); ++i) {
341 if (*i) {
342 (*i)->genGlobalCode(scope, decls, defs);
347 template <typename Child>
348 void AstChildren<Child>::printChareNames()
350 details::perElem(children, &Child::printChareNames);
353 template <typename Child>
354 void
355 AstChildren<Child>::genTramTypes() {
356 details::perElem(children, &Child::genTramTypes);
359 template <typename Child>
360 void
361 AstChildren<Child>::genTramRegs(XStr &str) {
362 details::perElemGen(children, str, &Child::genTramRegs);
365 template <typename Child>
366 void
367 AstChildren<Child>::genTramPups(XStr& scope, XStr &decls, XStr &defs) {
368 for (typename std::list<Child*>::iterator i = children.begin(); i != children.end(); ++i) {
369 if (*i) {
370 (*i)->genTramPups(scope, decls, defs);
376 template <typename Child>
377 int AstChildren<Child>::genAccels_spe_c_funcBodies(XStr& str) {
378 int rtn = 0;
379 for (typename std::list<Child*>::iterator i = children.begin(); i != children.end(); ++i) {
380 if (*i) {
381 rtn += (*i)->genAccels_spe_c_funcBodies(str);
384 return rtn;
387 template <typename Child>
388 void AstChildren<Child>::genAccels_spe_c_regFuncs(XStr& str) {
389 details::perElemGen(children, str, &Child::genAccels_spe_c_regFuncs);
392 template <typename Child>
393 void AstChildren<Child>::genAccels_spe_c_callInits(XStr& str) {
394 details::perElemGen(children, str, &Child::genAccels_spe_c_callInits);
397 template <typename Child>
398 void AstChildren<Child>::genAccels_spe_h_includes(XStr& str) {
399 details::perElemGen(children, str, &Child::genAccels_spe_h_includes);
402 template <typename Child>
403 void AstChildren<Child>::genAccels_spe_h_fiCountDefs(XStr& str) {
404 details::perElemGen(children, str, &Child::genAccels_spe_h_fiCountDefs);
407 template <typename Child>
408 void AstChildren<Child>::genAccels_ppe_c_regFuncs(XStr& str) {
409 details::perElemGen(children, str, &Child::genAccels_ppe_c_regFuncs);
413 } // namespace xi
415 #endif // ifndef _AST_NODE_H