MP2-generator.rig 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669
  1. -- MP_generator.rig Phoenix -> C++ code generator
  2. -- V 2.0
  3. -- Mikhail Auguston, 03/05/15
  4. -- last modified 04/05/15
  5. -- use: MP_generator intermediate_file
  6. --
  7. -----------------------------------
  8. #AG
  9. -- Globals:
  10. -- $roots -- retain the original MP code,
  11. -- $composites -- these are used for comment generation
  12. -- $atoms -- for event name generation
  13. -- $new_root_table
  14. -- $new_composites
  15. -- $composite_order -- for harvest() calls ordering
  16. -- $class_counter
  17. -- $generated_containers: <* work_name: T *>
  18. ----------------------------------------------
  19. $Parm:= #PARM(T);
  20. $input_file:= #IMPLODE( $Parm [1]);
  21. LOAD $model $input_file;
  22. $roots:= $model.roots;
  23. $composites:= $model.composites;
  24. $atoms:= $model.atomic_events;
  25. $new_root_table:= $model.new_root_table;
  26. $new_composites:= $model.new_composites;
  27. $composite_order:= $model.composite_order;
  28. $coordinate_ops:= $model.coordinate_ops;
  29. $share_all_ops:= $model.share_all_ops;
  30. OPEN GEN #IMPLODE( $model.schema '.cpp' ); -- for C++ code
  31. OPEN MSG ' '; --for error messages
  32. --MSG<< 'Phoenix/C++ generator v.2.0 input from ' $input_file;
  33. GEN<< '/* Monterey Phoenix-> C++ generator, v.2.0, March 2015';
  34. GEN<< ' Mikhail Auguston, NPS, CS Dept, Monterey, CA, USA';GEN<<;
  35. GEN<< ' traces derived for scope' $model.scope;
  36. GEN<< '----------------------------------------------------';
  37. GEN<< 'SCHEMA' $model.schema;
  38. -- print comments with the original MP code
  39. #print_rule_list(root $roots);
  40. #print_rule_list(composite $composites);
  41. GEN<<;
  42. GEN<< '*****************************************************************';
  43. GEN<< '***' generated constants are visible in the 'mp2_print_etc.h';
  44. GEN<< '*****************************************************************/';
  45. GEN<< '#include "mp2.h" // the permanent part';GEN<<;
  46. #generate_event_names();
  47. #generate_event_strings();
  48. GEN<< '#include "mp2_print_etc.h" // print methods';
  49. GEN<< '//***************************';
  50. GEN<< '//==== generated classes ====';
  51. GEN<< '//***************************';
  52. GEN<<;
  53. $class_counter:= 0;
  54. #generate_composite_producers($new_composites);
  55. #generate_composite_producers($new_root_table);
  56. #generate_event_class($new_composites);
  57. #generate_event_class($new_root_table);
  58. #generate_coordination_class($coordinate_ops);
  59. #generate_share_all_class($share_all_ops);
  60. #generate_schema_class($model.elt_list);
  61. GEN<< '//******************************************';
  62. GEN<< '//' main;
  63. GEN<< '//******************************************';
  64. GEN<< 'int main(){';
  65. GEN<< ' gen_start = clock();';
  66. GEN<< @ ' JSON.open("' $model.schema '.json");';
  67. GEN<< ' cout<< "generating traces for scope' $model.scope '"<<endl;';
  68. GEN<< '//----------------------------';
  69. #generate_harvest_calls($composite_order);
  70. #harvest_roots($new_root_table);
  71. #harvest_main_schema();
  72. -- generate statistics show
  73. GEN<< '//----------------------------';
  74. GEN<< ' show_statistics();';
  75. GEN<< 'return 0;';
  76. GEN<< '} // end main()';
  77. ##
  78. --------------------------------------------------
  79. -- print subroutines ----------------------------
  80. --------------------------------------------------
  81. #print_rule_list
  82. -- Global: $buffer_len -- should be <= 80
  83. ( root /$type:= ROOT/ ! $x)
  84. <* $rule_name:
  85. /GEN<< $type @ $rule_name ': ';
  86. $buffer_len:= #LEN($rule_name) + 10/
  87. <. pattern_list: #print_element .>
  88. / GEN<] ';'/
  89. *>
  90. ##
  91. #print_element
  92. <. type: plain,
  93. name: $event_name
  94. /IF LAST #print_rule_list $buffer_len + #LEN($event_name) > 68 ->
  95. GEN<< ' ';
  96. LAST #print_rule_list $buffer_len:= 10
  97. FI;
  98. GEN<] $event_name;
  99. LAST #print_rule_list $buffer_len +:= #LEN($event_name) +1/
  100. .>;;
  101. <. type: sequence,
  102. body: (. (* #print_element *) .)
  103. .>;;
  104. <. type: alternative,
  105. body: /GEN<] '('/
  106. (. (* /GEN<] $bar; $bar:= '|'/ #print_element *) .)
  107. /GEN<] ')'/
  108. .>;;
  109. <. type: iterator,
  110. body: /GEN<] '(*'/ #print_element /GEN<] '*)'/
  111. .>;;
  112. <. type: iterator_plus,
  113. body: /GEN<] '(+'/ #print_element /GEN<] '+)'/
  114. .>;;
  115. <. type: set,
  116. body: /GEN<] '{'/
  117. (. (* /GEN<] $bar; $bar:= ','/ #print_element *) .)
  118. /GEN<] '}'/
  119. .>;;
  120. <. type: set_iterator,
  121. body: /GEN<] '{*'/ #print_element /GEN<] '*}'/
  122. .>;;
  123. <. type: set_iterator_plus,
  124. body: /GEN<] '{+'/ #print_element /GEN<] '+}'/
  125. .>;;
  126. <. type: optional,
  127. body: /GEN<] '['/ #print_element /GEN<] ']'/
  128. .>;;
  129. <. type: empty .> ;; -- EMPTY
  130. $x /GEN<< '**' $x.type print not implemented yet '**'/
  131. ##
  132. ------------------------------------------------------------------
  133. -------- generate event names enum and strings
  134. ------------------------------------------------------------------
  135. -- GenericContainer is used for all Alt (OR), Seq (AND), Set producers
  136. #generate_event_names
  137. /GEN<< 'enum Event_name {Dummy_event, GenericContainer';
  138. GEN<< ' // atomic events';
  139. #print_event_name(LAST #AG $atoms);
  140. GEN<< ' // composite events';
  141. #print_event_name(LAST #AG $composites);
  142. GEN<< ' // coordination operations';
  143. #print_event_name(LAST #AG $coordinate_ops);
  144. GEN<< ' // share all operations';
  145. #print_event_name(LAST #AG $share_all_ops);
  146. GEN<< ' // ROOT events';
  147. #print_event_name(LAST #AG $roots);
  148. GEN<< ' // main schema event';
  149. GEN<< @ ' , Event_' LAST #AG $model.schema;
  150. GEN<] ' };'; GEN<<;/
  151. ##
  152. #print_event_name
  153. <* $event_name: $x
  154. /GEN<< @ ' , Event_' $event_name /
  155. *>
  156. ##
  157. #generate_event_strings
  158. /GEN<< 'string event_name_string[] = {"Dummy", "GenericContainer"';
  159. #print_event_string(LAST #AG $atoms);
  160. #print_event_string(LAST #AG $composites);
  161. #print_event_string(LAST #AG $coordinate_ops);
  162. #print_event_string(LAST #AG $share_all_ops);
  163. #print_event_string(LAST #AG $roots);
  164. GEN<< @ ' , "' LAST #AG $model.schema '"';
  165. GEN<] ' };'; GEN<<;/
  166. ##
  167. #print_event_string
  168. <* $event_name: $x
  169. /GEN<< @ ' , "' $event_name '"' /
  170. *>
  171. ##
  172. --********************************************************************
  173. --------------------------- EVENT CLASSES ----------------------------
  174. --********************************************************************
  175. #generate_composite_producers
  176. <* $event_name: <. pattern_list: #generate_container,
  177. [build_block: $comp_op_list
  178. -- here comes composition op class generator <<<<<<<<<<
  179. ]
  180. .>
  181. *>
  182. ##
  183. #generate_container
  184. <. type: ( plain ! composite ! empty ) .> ;;
  185. -- for event grammar patterns
  186. <. name: $work_name
  187. /IF LAST#AG $generated_containers.$work_name ->
  188. RETURN T
  189. FI/, -- to prevent duplication
  190. type: ( sequence /$base:= AND_node_producer_container/ !
  191. alternative /$base:= OR_node_producer_container/ !
  192. set /$base:= SET_node_producer_container/ ),
  193. body: (. (* #generate_container *) .), -- for nested ALT, SEQ, SET
  194. body:
  195. /GEN<< '//----' #class_counter() '----';
  196. GEN<< class $work_name ': public' $base '{';
  197. GEN<< 'public:' '//' constructor;
  198. GEN<< ' ' $work_name '():' $base '(GenericContainer){';
  199. GEN<< ' element = new Event_producer_ref[ element_count ='
  200. #LEN($.body) + #LEN(LAST #generate_composite_producers $comp_op_list)
  201. '];';
  202. $element_count:= 0 /
  203. (. (* /GEN<< ' element[' $element_count ']= '/
  204. #generate_element
  205. /GEN<] ';';
  206. $element_count +:= 1 /
  207. *) .)
  208. .>
  209. /GEN<< ' }';
  210. GEN<< '};//' end class $work_name;
  211. GEN<<;
  212. LAST#AG $generated_containers ++:= <. $work_name: T .> /
  213. ##
  214. #generate_element
  215. <. type: plain,
  216. name: $Id .>
  217. /GEN<] @ 'new Atomic_producer(Event_' $Id ')'/;;
  218. <. type: composite,
  219. name: $Id .>
  220. /GEN<] @ 'new Composite_secondary_producer(Event_' $Id ')'/;;
  221. <. type: (sequence ! alternative ! set),
  222. name: $work_name .>
  223. /GEN<] new $work_name/;;
  224. <. type: empty .>
  225. /GEN<] '&Dummy'/;;
  226. -- here come composition op elements <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  227. $x /PRINT (. '***' Unrecognized element $x .)/
  228. ##
  229. #generate_event_class
  230. <* $event_name:
  231. <. rule_type: ( composite /$target_event:= Composite_event_instance_node/ !
  232. ROOT /$target_event:= ROOT_node/ ),
  233. work_name: $work_name
  234. /GEN<< '//----' #class_counter() '----';
  235. GEN<< class $work_name ': public Composite_producer {';
  236. GEN<< 'public:' '//' constructor;
  237. GEN<< ' ' $work_name @ '(): Composite_producer(Event_' $event_name '){';
  238. GEN<< ' target_event =' $target_event ';';
  239. GEN<< ' element = new Event_producer_ref[ element_count ='
  240. 1 + #LEN($.$event_name.build_block) '];';
  241. $element_count:= 0 /,
  242. pattern_list: -- on the top level in composite always just single pattern
  243. /GEN<< ' element[' $element_count ']= '/
  244. #generate_element
  245. /GEN<] ';';
  246. $element_count +:= 1 /,
  247. [build_block: $comp_op_list ]
  248. .>
  249. /GEN<< ' }';
  250. GEN<< '};//' end class $work_name;
  251. GEN<< /
  252. *>
  253. ##
  254. #generate_coordination_class
  255. -- global:
  256. -- $nesting_depth for avoiding redundant create_matrices() calls
  257. -------------------------
  258. <* $work_name:
  259. /GEN<< '//----' #class_counter() '----';
  260. GEN<< class @ $work_name '_ob: public Coordinate {';
  261. GEN<< 'public:' '//' constructor;
  262. GEN<< ' ' @ $work_name '_ob(int n): Coordinate(n){ }';
  263. GEN<<;
  264. GEN<< ' Traversal_result traverse(){';
  265. GEN<< ' try{';
  266. $nesting_depth:= 0/
  267. #generate_operation
  268. /GEN<< ' }';
  269. GEN<< ' catch(Traversal_result t){';
  270. GEN<< ' delete_matrices();';
  271. GEN<< ' return failed;';
  272. GEN<< ' }';
  273. GEN<< ' delete_matrices();';
  274. GEN<< ' return success_and_completed;';
  275. GEN<< ' } // end traverse()';
  276. GEN<< '}; // end' @ $work_name '_ob class';
  277. GEN<</
  278. *>
  279. ##
  280. #generate_share_all_class
  281. <* $work_name:
  282. /GEN<< '//----' #class_counter() '----';
  283. GEN<< class @ $work_name '_ob: public Coordinate {';
  284. GEN<< 'public:' '//' constructor;
  285. GEN<< ' ' @ $work_name '_ob(int n): Coordinate(n){type = ShareAll_op;}';
  286. GEN<<;
  287. GEN<< ' Traversal_result traverse(){';
  288. GEN<< ' try{';/
  289. #generate_operation
  290. /GEN<< ' }';
  291. GEN<< ' catch(Traversal_result t){';
  292. GEN<< ' delete_matrices();';
  293. GEN<< ' return failed;';
  294. GEN<< ' }';
  295. GEN<< ' delete_matrices();';
  296. GEN<< ' return success_and_completed;';
  297. GEN<< ' } // end traverse()';
  298. GEN<< '}; // end' @ $work_name '_ob class';
  299. GEN<</
  300. *>
  301. ##
  302. #generate_operation
  303. /LAST #generate_coordination_class $nesting_depth +:= 1/
  304. <. synchronization: $synchronization,
  305. operation: COORDINATE
  306. /GEN<< ' //' $synchronization COORDINATE operation;
  307. GEN<< ' create_matrices();'/,
  308. source_list: <* $variable:
  309. /GEN<<;
  310. GEN<< ' int' $variable '; // variable';
  311. GEN<< @ ' vector<int> ' $variable
  312. '_list; // list of coordinated events' /
  313. <. from:
  314. ( <. comp: $source .>
  315. /$source_name:= #IMPLODE($source '_source');
  316. IF NOT $source_defined.$source ->
  317. GEN<< ' int ' $source_name
  318. '; // source of coordination';
  319. $source_defined++:= <. $source: T .>
  320. FI;
  321. GEN<<;
  322. GEN<< ' // find source event' $source;
  323. GEN<< ' for(int i = 0; i < Stack.size(); i++){';
  324. GEN<< @' if( Stack[i]->name == Event_' $source '){';
  325. GEN<< ' ' $source_name '= i; break; }';
  326. GEN<< ' }'/ !
  327. <. var: $v .>
  328. /$source_name:= $v/
  329. )
  330. /$source_list!.:= (. $variable $source_name .);
  331. $source_tree++:= <. $variable: $source_name .>/
  332. .>
  333. *>,
  334. -- second pass
  335. source_list: /GEN<<;
  336. GEN<< ' // create lists of coordinated events';
  337. GEN<< ' for(int i = 0; i < len; i++){'/
  338. <* $variable:
  339. /GEN<< ' if(in_matrix[i * len + ' $source_tree.$variable ']){';
  340. GEN<< @' if(';
  341. $or_op:= ' '/
  342. <. selection_pattern: (. (*
  343. /GEN<] @ $or_op '(Stack[i]->name == Event_' /
  344. $event_name
  345. /GEN<] @ $event_name ')';
  346. $or_op:= '||'/
  347. *) .)
  348. .>
  349. /GEN<] @ ' ){';
  350. GEN<< ' //' make sure this is fresh event not yet shared;
  351. GEN<< ' int found = 0;';
  352. GEN<< @' for(vector<int>:: iterator s = '
  353. $variable '_list.begin(); s != ' $variable '_list.end(); s++){';
  354. GEN<< ' if((found = eq_matrix[i * len + *s])) break;';
  355. GEN<< ' }';
  356. GEN<< @' if(!found) ' $variable '_list.push_back(i);';
  357. GEN<< ' }';
  358. GEN<< ' }'/
  359. *>
  360. /GEN<< ' }';
  361. IF #LEN($source_list) > 1 ->
  362. GEN<< ' //' check that selected lists are of the same length;
  363. GEN<< @ ' if(';
  364. $first_arg:= #IMPLODE($source_list[1][1] '_list.size() != ');
  365. $i:= 2;
  366. $or_op:= ' ';
  367. LOOP
  368. IF $i > #LEN($source_list) -> BREAK FI;
  369. GEN<] $or_op @ $first_arg $source_list[$i][1] '_list.size() ';
  370. $i +:= 1;
  371. $or_op:= '||';
  372. END;
  373. GEN<] ') throw failed;'
  374. FI/,
  375. synchronization: ( Synchronous
  376. /GEN<<;
  377. GEN<< ' //' for syncronized COORDINATE sort the list
  378. and check for total order;
  379. FORALL $var IN $source_list DO
  380. GEN<< @ ' sort_and_check_coordinated_events(' $var[1] '_list);'
  381. OD / !
  382. $a ),
  383. body: /GEN<<;
  384. GEN<< ' //' do the COORDINATE;
  385. GEN<< ' for(int i = 0; i <' #IMPLODE($source_list[1][1] '_list.size()') '; i++){';
  386. FORALL $var IN $source_list DO
  387. GEN<< @ ' ' $var[1] '= ' $var[1] '_list[i];'
  388. OD/
  389. (. (+
  390. ( <. operation:'ADD',
  391. relation_list: (. (+
  392. <.first: $var1,
  393. second: $var2,
  394. relation: ( PRECEDES
  395. /GEN<< @' Follows.insert(pair<int, int>(' $var2 ',' $var1 '));'/ !
  396. FOLLOWS
  397. /GEN<< @' Follows.insert(pair<int, int>(' $var1 ',' $var2 '));'/ !
  398. 'IN'
  399. /GEN<< @' Inside.insert(pair<int, int>(' $var1 ',' $var2 '));'/ !
  400. CONTAINS
  401. /GEN<< @' Inside.insert(pair<int, int>(' $var2 ',' $var1 '));'/
  402. )
  403. .>
  404. +) .)
  405. .> !
  406. #generate_operation !
  407. <. operation: $op .>
  408. /MSG<< '*****' operation $op is not yet implemented/
  409. )
  410. +)
  411. .)
  412. /GEN<< ' }';
  413. IF LAST #generate_coordination_class $nesting_depth < 2 ->
  414. GEN<< ' create_matrices(); //' to check for axiom violation;
  415. GEN<< ' //print_matrices(); //<<<<<<<<<<<<'
  416. FI;
  417. GEN<< ' //' end of COORDINATE;
  418. LAST #generate_coordination_class $nesting_depth +:= -1/
  419. .>;;
  420. ----------------------------------------------------------------------------------
  421. <. operation: SHARE_ALL
  422. /GEN<<;
  423. GEN<< ' //' SHARE ALL operation;
  424. GEN<< ' create_matrices();'/,
  425. shared_events: $shared_events,
  426. host_list: (. (* (. (<. comp: $host_name .> /$source_name:= #IMPLODE($host_name '_source')/ !
  427. <. var: $host_name .> /$source_name:= $host_name/)
  428. -- single host
  429. /$hosts ++:= <. $host_name: T .>;
  430. GEN<<;
  431. IF $source_name <> $host_name ->
  432. GEN<< ' int' $source_name ';// shareholder';
  433. GEN<< ' // find host event' $host_name;
  434. GEN<< ' for(int i = 0; i < Stack.size(); i++){';
  435. GEN<< @' if( Stack[i]->name == Event_' $host_name '){';
  436. GEN<< ' ' $source_name '= i; break; } }';
  437. FI;
  438. GEN<< ' // lists of shared events for ' $host_name;
  439. FORALL $e IN $shared_events DO
  440. GEN<< @' vector<int> ' $host_name '_' $e '_list;'
  441. OD;/
  442. .)
  443. *)
  444. .),
  445. host_list: /GEN<<;
  446. GEN<< ' //' create lists of shared events;
  447. GEN<< ' for(int i = 0; i < len; i++){'/
  448. (. (* (. (<. comp: $host_name .> /$source_name:= #IMPLODE($host_name '_source')/ !
  449. <. var: $host_name .> /$source_name:= $host_name/)
  450. -- single host
  451. /GEN<< ' if(in_matrix[i * len +' $source_name ']){';
  452. FORALL $e IN $shared_events DO
  453. GEN<< @' if( Stack[i]->name == Event_' $e ' ){';
  454. GEN<< ' //' make sure this is fresh event not yet shared;
  455. GEN<< ' int found = 0;';
  456. GEN<< ' for(vector<int>:: iterator s = '
  457. @$host_name '_' $e '_list.begin();';
  458. GEN<< @ ' s != ' $host_name '_' $e
  459. '_list.end(); s++){';
  460. GEN<< ' if((found = eq_matrix[i * len + *s])) break;';
  461. GEN<< ' }';
  462. GEN<< @' if(!found) ' $host_name '_' $e '_list.push_back(i);';
  463. GEN<< ' }'
  464. OD;
  465. GEN<< ' };'/
  466. .)
  467. *)
  468. .)
  469. /GEN<< ' } //' end for create lists of shared events;
  470. $single_host:= $host_name/,
  471. shared_events: /GEN<<;
  472. GEN<< ' //' check that selected lists are of the same length;
  473. GEN<< ' int len_to_compare;'/
  474. <* $event_name: $x
  475. /GEN<< @' len_to_compare = ' $single_host '_' $event_name '_list.size();';
  476. FORALL $h IN $hosts DO
  477. IF $h <> $single_host ->
  478. GEN<< @' if(' $h '_' $event_name '_list.size() != len_to_compare) '
  479. @ throw failed ';'
  480. FI
  481. OD/
  482. *>,
  483. host_list: /GEN<<;
  484. GEN<< ' //' sort the lists/
  485. (. (* (. (<. comp: $host_name .> /$source_name:= #IMPLODE($host_name '_source')/ !
  486. <. var: $host_name .> /$source_name:= $host_name/)
  487. -- single host
  488. /FORALL $e IN $shared_events DO
  489. GEN<< @' sort_events(' $host_name '_' $e '_list);';
  490. OD/
  491. .)
  492. *)
  493. .),
  494. shared_events: /GEN<<;
  495. GEN<< ' //' do the SHARE ALL/
  496. <* $event_name: $x
  497. /GEN<< @' len_to_compare = ' $single_host '_' $event_name '_list.size();';
  498. GEN<< ' for(int i = 0; i < len_to_compare; i++){';
  499. FORALL $h IN $hosts DO
  500. IF $h <> $single_host ->
  501. GEN<< @' make_equality_complete(' $single_host '_' $event_name '_list[i], '
  502. $h '_' $event_name '_list[i]);'
  503. FI
  504. OD;
  505. GEN<< ' }'/
  506. *>
  507. .>
  508. /GEN<< ;
  509. IF LAST #generate_coordination_class $nesting_depth < 2 ->
  510. GEN<< ' create_matrices(); //' to check for axiom violation;
  511. GEN<< ' //print_matrices(); //<<<<<<<<<<<<'
  512. FI;
  513. GEN<< ' //' end of SHARE ALL;
  514. LAST #generate_coordination_class $nesting_depth +:= -1/
  515. ;;
  516. $a /PRINT (. generation for $a not yet implemented .)/
  517. ##
  518. #generate_schema_class
  519. -- from $model.elt_list
  520. /GEN<< '//----' #class_counter() '----';
  521. GEN<< class @ 'SCHEMA_' LAST #AG $model.schema ': public Composite_producer {';
  522. GEN<< 'public:' '//' constructor;
  523. GEN<< ' ' @ 'SCHEMA_' LAST #AG $model.schema '(): Composite_producer(Event_'
  524. LAST #AG $model.schema '){';
  525. GEN<< ' target_event = Schema_node;';
  526. GEN<< ' element = new Event_producer_ref[ element_count ='
  527. #LEN(LAST #AG $model.elt_list) '];';
  528. $element_count:= 0 /
  529. (. (* ( <. ROOT: $root_name .>
  530. /GEN<< ' element[' $element_count
  531. @ ']= new Composite_secondary_producer(Event_' $root_name ');';
  532. $element_count +:= 1 / !
  533. ( <. COORDINATE: $work .> ! <. SHARE_ALL: $work .> )
  534. /GEN<< ' element[' $element_count
  535. @ ']= new ' $work '_ob(Event_' $work ');';
  536. $element_count +:= 1 / !
  537. $any -- other composition ops here
  538. )
  539. *)
  540. .)
  541. /GEN<< ' }';
  542. GEN<< '};//' end class @ 'SCHEMA_' LAST #AG $model.schema;
  543. GEN<< /
  544. ##
  545. #generate_harvest_calls
  546. (. /GEN<< ' //' harvesting traces for composite events/
  547. (* $comp_name
  548. /$t:= #class_counter();
  549. GEN<< ' ' LAST #AG $new_composites.$comp_name.work_name @ 'temp_' $t
  550. '; temp_' $t '.harvest();'/
  551. *)
  552. .)
  553. ##
  554. #harvest_roots
  555. -- works on $new_root_table
  556. /GEN<< ' //' harvesting traces for ROOT events/
  557. <* $event_name:
  558. <. work_name: $work_name,
  559. rule_type: ( composite !
  560. ROOT
  561. /$t:= #class_counter();
  562. GEN<< ' ' $work_name
  563. @ 'temp_' $t '; temp_' $t '.harvest();'/ )
  564. .>
  565. *>
  566. ##
  567. #harvest_main_schema
  568. /GEN<< ' //' harvesting traces for main schema;
  569. $t:= #class_counter();
  570. GEN<< ' ' @ 'SCHEMA_' LAST #AG $model.schema
  571. ' temp_' $t '; temp_' $t '.harvest();';
  572. -- generate text file with event traces
  573. GEN<< @ ' temp_' $t '.output_JSON();';
  574. GEN<< ' gen_end = clock();';
  575. GEN<< @ ' temp_' $t '.show_traces();'/
  576. ##
  577. --------------------------------------------------
  578. #class_counter
  579. /LAST #AG $class_counter +:=1;
  580. RETURN COPY(LAST #AG $class_counter)/
  581. ##