Kernel-Dag.js 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684
  1. define(["amber/boot", "amber_core/Kernel-Objects"], function($boot){"use strict";
  2. if(!$boot.nilAsReceiver)$boot.nilAsReceiver=$boot.nil;
  3. var $core=$boot.api,nil=$boot.nilAsReceiver,$recv=$boot.asReceiver,$globals=$boot.globals;
  4. if(!$boot.nilAsClass)$boot.nilAsClass=$boot.dnu;
  5. $core.addPackage('Kernel-Dag');
  6. $core.packages["Kernel-Dag"].innerEval = function (expr) { return eval(expr); };
  7. $core.packages["Kernel-Dag"].transport = {"type":"amd","amdNamespace":"amber_core"};
  8. $core.addClass('AbstractDagVisitor', $globals.Object, [], 'Kernel-Dag');
  9. //>>excludeStart("ide", pragmas.excludeIdeData);
  10. $globals.AbstractDagVisitor.comment="I am base class of `DagNode` visitor.\x0a\x0aConcrete classes should implement `visitDagNode:`,\x0athey can reuse possible variants of implementation\x0aoffered directly: `visitDagNodeVariantSimple:`\x0aand `visitDagNodeVariantRedux:`.";
  11. //>>excludeEnd("ide");
  12. $core.addMethod(
  13. $core.method({
  14. selector: "visit:",
  15. protocol: 'visiting',
  16. fn: function (aNode){
  17. var self=this;
  18. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  19. return $core.withContext(function($ctx1) {
  20. //>>excludeEnd("ctx");
  21. return $recv(aNode)._acceptDagVisitor_(self);
  22. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  23. }, function($ctx1) {$ctx1.fill(self,"visit:",{aNode:aNode},$globals.AbstractDagVisitor)});
  24. //>>excludeEnd("ctx");
  25. },
  26. //>>excludeStart("ide", pragmas.excludeIdeData);
  27. args: ["aNode"],
  28. source: "visit: aNode\x0a\x09^ aNode acceptDagVisitor: self",
  29. referencedClasses: [],
  30. //>>excludeEnd("ide");
  31. messageSends: ["acceptDagVisitor:"]
  32. }),
  33. $globals.AbstractDagVisitor);
  34. $core.addMethod(
  35. $core.method({
  36. selector: "visitAll:",
  37. protocol: 'visiting',
  38. fn: function (aCollection){
  39. var self=this;
  40. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  41. return $core.withContext(function($ctx1) {
  42. //>>excludeEnd("ctx");
  43. return $recv(aCollection)._collect_((function(each){
  44. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  45. return $core.withContext(function($ctx2) {
  46. //>>excludeEnd("ctx");
  47. return self._visit_(each);
  48. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  49. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1,1)});
  50. //>>excludeEnd("ctx");
  51. }));
  52. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  53. }, function($ctx1) {$ctx1.fill(self,"visitAll:",{aCollection:aCollection},$globals.AbstractDagVisitor)});
  54. //>>excludeEnd("ctx");
  55. },
  56. //>>excludeStart("ide", pragmas.excludeIdeData);
  57. args: ["aCollection"],
  58. source: "visitAll: aCollection\x0a\x09^ aCollection collect: [ :each | self visit: each ]",
  59. referencedClasses: [],
  60. //>>excludeEnd("ide");
  61. messageSends: ["collect:", "visit:"]
  62. }),
  63. $globals.AbstractDagVisitor);
  64. $core.addMethod(
  65. $core.method({
  66. selector: "visitAllChildren:",
  67. protocol: 'visiting',
  68. fn: function (aDagNode){
  69. var self=this;
  70. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  71. return $core.withContext(function($ctx1) {
  72. //>>excludeEnd("ctx");
  73. return self._visitAll_($recv(aDagNode)._dagChildren());
  74. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  75. }, function($ctx1) {$ctx1.fill(self,"visitAllChildren:",{aDagNode:aDagNode},$globals.AbstractDagVisitor)});
  76. //>>excludeEnd("ctx");
  77. },
  78. //>>excludeStart("ide", pragmas.excludeIdeData);
  79. args: ["aDagNode"],
  80. source: "visitAllChildren: aDagNode\x0a\x09^ self visitAll: aDagNode dagChildren",
  81. referencedClasses: [],
  82. //>>excludeEnd("ide");
  83. messageSends: ["visitAll:", "dagChildren"]
  84. }),
  85. $globals.AbstractDagVisitor);
  86. $core.addMethod(
  87. $core.method({
  88. selector: "visitDagNode:",
  89. protocol: 'visiting',
  90. fn: function (aNode){
  91. var self=this;
  92. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  93. return $core.withContext(function($ctx1) {
  94. //>>excludeEnd("ctx");
  95. self._subclassResponsibility();
  96. return self;
  97. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  98. }, function($ctx1) {$ctx1.fill(self,"visitDagNode:",{aNode:aNode},$globals.AbstractDagVisitor)});
  99. //>>excludeEnd("ctx");
  100. },
  101. //>>excludeStart("ide", pragmas.excludeIdeData);
  102. args: ["aNode"],
  103. source: "visitDagNode: aNode\x0a\x09self subclassResponsibility",
  104. referencedClasses: [],
  105. //>>excludeEnd("ide");
  106. messageSends: ["subclassResponsibility"]
  107. }),
  108. $globals.AbstractDagVisitor);
  109. $core.addMethod(
  110. $core.method({
  111. selector: "visitDagNodeVariantRedux:",
  112. protocol: 'visiting',
  113. fn: function (aNode){
  114. var self=this;
  115. var newChildren,oldChildren;
  116. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  117. return $core.withContext(function($ctx1) {
  118. //>>excludeEnd("ctx");
  119. var $2,$3,$1,$4,$5;
  120. var $early={};
  121. try {
  122. oldChildren=$recv(aNode)._dagChildren();
  123. newChildren=self._visitAllChildren_(aNode);
  124. $2=$recv(oldChildren)._size();
  125. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  126. $ctx1.sendIdx["size"]=1;
  127. //>>excludeEnd("ctx");
  128. $3=$recv(newChildren)._size();
  129. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  130. $ctx1.sendIdx["size"]=2;
  131. //>>excludeEnd("ctx");
  132. $1=$recv($2).__eq($3);
  133. if($core.assert($1)){
  134. $recv((1)._to_($recv(oldChildren)._size()))._detect_ifNone_((function(i){
  135. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  136. return $core.withContext(function($ctx2) {
  137. //>>excludeEnd("ctx");
  138. $4=$recv(oldChildren)._at_(i);
  139. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  140. $ctx2.sendIdx["at:"]=1;
  141. //>>excludeEnd("ctx");
  142. return $recv($4).__tild_eq($recv(newChildren)._at_(i));
  143. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  144. }, function($ctx2) {$ctx2.fillBlock({i:i},$ctx1,2)});
  145. //>>excludeEnd("ctx");
  146. }),(function(){
  147. throw $early=[aNode];
  148. }));
  149. };
  150. $5=$recv(aNode)._copy();
  151. $recv($5)._dagChildren_(newChildren);
  152. return $recv($5)._yourself();
  153. }
  154. catch(e) {if(e===$early)return e[0]; throw e}
  155. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  156. }, function($ctx1) {$ctx1.fill(self,"visitDagNodeVariantRedux:",{aNode:aNode,newChildren:newChildren,oldChildren:oldChildren},$globals.AbstractDagVisitor)});
  157. //>>excludeEnd("ctx");
  158. },
  159. //>>excludeStart("ide", pragmas.excludeIdeData);
  160. args: ["aNode"],
  161. source: "visitDagNodeVariantRedux: aNode\x0a\x09\x22Immutable-guarded implementation of visitDagNode:.\x0a\x09Visits all children and checks if there were changes.\x0a\x09If not, returns aNode.\x0a\x09If yes, returns copy of aNode with new children.\x22\x0a\x0a\x09| newChildren oldChildren |\x0a\x09oldChildren := aNode dagChildren.\x0a\x09newChildren := self visitAllChildren: aNode.\x0a\x09oldChildren size = newChildren size ifTrue: [\x0a\x09\x09(1 to: oldChildren size) detect: [ :i |\x0a\x09\x09\x09(oldChildren at: i) ~= (newChildren at: i)\x0a\x09\x09] ifNone: [ \x22no change\x22 ^ aNode ] ].\x0a\x09^ aNode copy dagChildren: newChildren; yourself",
  162. referencedClasses: [],
  163. //>>excludeEnd("ide");
  164. messageSends: ["dagChildren", "visitAllChildren:", "ifTrue:", "=", "size", "detect:ifNone:", "to:", "~=", "at:", "dagChildren:", "copy", "yourself"]
  165. }),
  166. $globals.AbstractDagVisitor);
  167. $core.addMethod(
  168. $core.method({
  169. selector: "visitDagNodeVariantSimple:",
  170. protocol: 'visiting',
  171. fn: function (aNode){
  172. var self=this;
  173. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  174. return $core.withContext(function($ctx1) {
  175. //>>excludeEnd("ctx");
  176. self._visitAllChildren_(aNode);
  177. return aNode;
  178. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  179. }, function($ctx1) {$ctx1.fill(self,"visitDagNodeVariantSimple:",{aNode:aNode},$globals.AbstractDagVisitor)});
  180. //>>excludeEnd("ctx");
  181. },
  182. //>>excludeStart("ide", pragmas.excludeIdeData);
  183. args: ["aNode"],
  184. source: "visitDagNodeVariantSimple: aNode\x0a\x09\x22Simple implementation of visitDagNode:.\x0a\x09Visits children, then returns aNode\x22\x0a\x0a\x09self visitAllChildren: aNode.\x0a\x09^ aNode",
  185. referencedClasses: [],
  186. //>>excludeEnd("ide");
  187. messageSends: ["visitAllChildren:"]
  188. }),
  189. $globals.AbstractDagVisitor);
  190. $core.addClass('PathDagVisitor', $globals.AbstractDagVisitor, ['path', 'setParentSelector'], 'Kernel-Dag');
  191. //>>excludeStart("ide", pragmas.excludeIdeData);
  192. $globals.PathDagVisitor.comment="I am base class of `DagNode` visitor.\x0a\x0aI hold the path of ancestors up to actual node\x0ain `self path`.";
  193. //>>excludeEnd("ide");
  194. $core.addMethod(
  195. $core.method({
  196. selector: "initialize",
  197. protocol: 'initialization',
  198. fn: function (){
  199. var self=this;
  200. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  201. return $core.withContext(function($ctx1) {
  202. //>>excludeEnd("ctx");
  203. (
  204. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  205. $ctx1.supercall = true,
  206. //>>excludeEnd("ctx");
  207. ($globals.PathDagVisitor.superclass||$boot.nilAsClass).fn.prototype._initialize.apply($recv(self), []));
  208. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  209. $ctx1.supercall = false;
  210. //>>excludeEnd("ctx");;
  211. self["@setParentSelector"]=nil;
  212. self["@path"]=[];
  213. return self;
  214. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  215. }, function($ctx1) {$ctx1.fill(self,"initialize",{},$globals.PathDagVisitor)});
  216. //>>excludeEnd("ctx");
  217. },
  218. //>>excludeStart("ide", pragmas.excludeIdeData);
  219. args: [],
  220. source: "initialize\x0a\x09super initialize.\x0a\x0a\x09setParentSelector := nil.\x0a\x09path := #()",
  221. referencedClasses: [],
  222. //>>excludeEnd("ide");
  223. messageSends: ["initialize"]
  224. }),
  225. $globals.PathDagVisitor);
  226. $core.addMethod(
  227. $core.method({
  228. selector: "path",
  229. protocol: 'accessing',
  230. fn: function (){
  231. var self=this;
  232. return self["@path"];
  233. },
  234. //>>excludeStart("ide", pragmas.excludeIdeData);
  235. args: [],
  236. source: "path\x0a\x09^ path",
  237. referencedClasses: [],
  238. //>>excludeEnd("ide");
  239. messageSends: []
  240. }),
  241. $globals.PathDagVisitor);
  242. $core.addMethod(
  243. $core.method({
  244. selector: "setParentSelector",
  245. protocol: 'accessing',
  246. fn: function (){
  247. var self=this;
  248. return self["@setParentSelector"];
  249. },
  250. //>>excludeStart("ide", pragmas.excludeIdeData);
  251. args: [],
  252. source: "setParentSelector\x0a\x09^ setParentSelector",
  253. referencedClasses: [],
  254. //>>excludeEnd("ide");
  255. messageSends: []
  256. }),
  257. $globals.PathDagVisitor);
  258. $core.addMethod(
  259. $core.method({
  260. selector: "setParentSelector:",
  261. protocol: 'accessing',
  262. fn: function (anObject){
  263. var self=this;
  264. self["@setParentSelector"]=anObject;
  265. return self;
  266. },
  267. //>>excludeStart("ide", pragmas.excludeIdeData);
  268. args: ["anObject"],
  269. source: "setParentSelector: anObject\x0a\x09setParentSelector := anObject",
  270. referencedClasses: [],
  271. //>>excludeEnd("ide");
  272. messageSends: []
  273. }),
  274. $globals.PathDagVisitor);
  275. $core.addMethod(
  276. $core.method({
  277. selector: "visit:",
  278. protocol: 'visiting',
  279. fn: function (aNode){
  280. var self=this;
  281. var oldPath;
  282. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  283. return $core.withContext(function($ctx1) {
  284. //>>excludeEnd("ctx");
  285. var $1,$2,$receiver;
  286. var $early={};
  287. try {
  288. oldPath=self["@path"];
  289. $recv((function(){
  290. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  291. return $core.withContext(function($ctx2) {
  292. //>>excludeEnd("ctx");
  293. self["@path"]=$recv(self["@path"]).__comma([aNode]);
  294. self["@path"];
  295. $1=self["@setParentSelector"];
  296. if(($receiver = $1) == null || $receiver.isNil){
  297. $1;
  298. } else {
  299. $recv(oldPath)._ifNotEmpty_((function(){
  300. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  301. return $core.withContext(function($ctx3) {
  302. //>>excludeEnd("ctx");
  303. return $recv(aNode)._perform_withArguments_(self["@setParentSelector"],[$recv(oldPath)._last()]);
  304. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  305. }, function($ctx3) {$ctx3.fillBlock({},$ctx2,3)});
  306. //>>excludeEnd("ctx");
  307. }));
  308. };
  309. $2=(
  310. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  311. $ctx2.supercall = true,
  312. //>>excludeEnd("ctx");
  313. ($globals.PathDagVisitor.superclass||$boot.nilAsClass).fn.prototype._visit_.apply($recv(self), [aNode]));
  314. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  315. $ctx2.supercall = false;
  316. //>>excludeEnd("ctx");;
  317. throw $early=[$2];
  318. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  319. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)});
  320. //>>excludeEnd("ctx");
  321. }))._ensure_((function(){
  322. self["@path"]=oldPath;
  323. return self["@path"];
  324. }));
  325. return self;
  326. }
  327. catch(e) {if(e===$early)return e[0]; throw e}
  328. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  329. }, function($ctx1) {$ctx1.fill(self,"visit:",{aNode:aNode,oldPath:oldPath},$globals.PathDagVisitor)});
  330. //>>excludeEnd("ctx");
  331. },
  332. //>>excludeStart("ide", pragmas.excludeIdeData);
  333. args: ["aNode"],
  334. source: "visit: aNode\x0a\x09| oldPath |\x0a\x09oldPath := path.\x0a\x09[\x0a\x09\x09path := path, {aNode}.\x0a\x09\x09setParentSelector ifNotNil: [ oldPath ifNotEmpty: [\x0a\x09\x09\x09aNode\x0a\x09\x09\x09\x09perform: setParentSelector\x0a\x09\x09\x09\x09withArguments: {oldPath last} ] ].\x0a\x09\x09^ super visit: aNode\x0a\x09] ensure: [ path := oldPath ]",
  335. referencedClasses: [],
  336. //>>excludeEnd("ide");
  337. messageSends: ["ensure:", ",", "ifNotNil:", "ifNotEmpty:", "perform:withArguments:", "last", "visit:"]
  338. }),
  339. $globals.PathDagVisitor);
  340. $core.addMethod(
  341. $core.method({
  342. selector: "visitDagNodeVariantRedux:",
  343. protocol: 'visiting',
  344. fn: function (aNode){
  345. var self=this;
  346. var newNode;
  347. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  348. return $core.withContext(function($ctx1) {
  349. //>>excludeEnd("ctx");
  350. var $1;
  351. newNode=(
  352. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  353. $ctx1.supercall = true,
  354. //>>excludeEnd("ctx");
  355. ($globals.PathDagVisitor.superclass||$boot.nilAsClass).fn.prototype._visitDagNodeVariantRedux_.apply($recv(self), [aNode]));
  356. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  357. $ctx1.supercall = false;
  358. //>>excludeEnd("ctx");;
  359. $1=$recv(aNode).__eq_eq(newNode);
  360. if(!$core.assert($1)){
  361. $recv(self["@path"])._at_put_($recv(self["@path"])._size(),newNode);
  362. };
  363. return newNode;
  364. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  365. }, function($ctx1) {$ctx1.fill(self,"visitDagNodeVariantRedux:",{aNode:aNode,newNode:newNode},$globals.PathDagVisitor)});
  366. //>>excludeEnd("ctx");
  367. },
  368. //>>excludeStart("ide", pragmas.excludeIdeData);
  369. args: ["aNode"],
  370. source: "visitDagNodeVariantRedux: aNode\x0a\x09| newNode |\x0a\x09newNode := super visitDagNodeVariantRedux: aNode.\x0a\x09aNode == newNode ifFalse: [ path at: path size put: newNode ].\x0a\x09^ newNode",
  371. referencedClasses: [],
  372. //>>excludeEnd("ide");
  373. messageSends: ["visitDagNodeVariantRedux:", "ifFalse:", "==", "at:put:", "size"]
  374. }),
  375. $globals.PathDagVisitor);
  376. $core.addClass('DagNode', $globals.Object, [], 'Kernel-Dag');
  377. //>>excludeStart("ide", pragmas.excludeIdeData);
  378. $globals.DagNode.comment="I am the abstract root class of any directed acyclic graph.\x0a\x0aConcrete classes should implement `dagChildren` and `dagChildren:`\x0ato get / set direct successor nodes (aka child nodes / subnodes).";
  379. //>>excludeEnd("ide");
  380. $core.addMethod(
  381. $core.method({
  382. selector: "acceptDagVisitor:",
  383. protocol: 'visiting',
  384. fn: function (aVisitor){
  385. var self=this;
  386. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  387. return $core.withContext(function($ctx1) {
  388. //>>excludeEnd("ctx");
  389. return $recv(aVisitor)._visitDagNode_(self);
  390. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  391. }, function($ctx1) {$ctx1.fill(self,"acceptDagVisitor:",{aVisitor:aVisitor},$globals.DagNode)});
  392. //>>excludeEnd("ctx");
  393. },
  394. //>>excludeStart("ide", pragmas.excludeIdeData);
  395. args: ["aVisitor"],
  396. source: "acceptDagVisitor: aVisitor\x0a\x09^ aVisitor visitDagNode: self",
  397. referencedClasses: [],
  398. //>>excludeEnd("ide");
  399. messageSends: ["visitDagNode:"]
  400. }),
  401. $globals.DagNode);
  402. $core.addMethod(
  403. $core.method({
  404. selector: "allDagChildren",
  405. protocol: 'accessing',
  406. fn: function (){
  407. var self=this;
  408. var allNodes;
  409. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  410. return $core.withContext(function($ctx1) {
  411. //>>excludeEnd("ctx");
  412. var $1;
  413. $1=self._dagChildren();
  414. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  415. $ctx1.sendIdx["dagChildren"]=1;
  416. //>>excludeEnd("ctx");
  417. allNodes=$recv($1)._asSet();
  418. $recv(self._dagChildren())._do_((function(each){
  419. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  420. return $core.withContext(function($ctx2) {
  421. //>>excludeEnd("ctx");
  422. return $recv(allNodes)._addAll_($recv(each)._allDagChildren());
  423. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  424. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1,1)});
  425. //>>excludeEnd("ctx");
  426. }));
  427. return allNodes;
  428. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  429. }, function($ctx1) {$ctx1.fill(self,"allDagChildren",{allNodes:allNodes},$globals.DagNode)});
  430. //>>excludeEnd("ctx");
  431. },
  432. //>>excludeStart("ide", pragmas.excludeIdeData);
  433. args: [],
  434. source: "allDagChildren\x0a\x09| allNodes |\x0a\x09\x0a\x09allNodes := self dagChildren asSet.\x0a\x09self dagChildren do: [ :each | \x0a\x09\x09allNodes addAll: each allDagChildren ].\x0a\x09\x0a\x09^ allNodes",
  435. referencedClasses: [],
  436. //>>excludeEnd("ide");
  437. messageSends: ["asSet", "dagChildren", "do:", "addAll:", "allDagChildren"]
  438. }),
  439. $globals.DagNode);
  440. $core.addMethod(
  441. $core.method({
  442. selector: "dagChildren",
  443. protocol: 'accessing',
  444. fn: function (){
  445. var self=this;
  446. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  447. return $core.withContext(function($ctx1) {
  448. //>>excludeEnd("ctx");
  449. self._subclassResponsibility();
  450. return self;
  451. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  452. }, function($ctx1) {$ctx1.fill(self,"dagChildren",{},$globals.DagNode)});
  453. //>>excludeEnd("ctx");
  454. },
  455. //>>excludeStart("ide", pragmas.excludeIdeData);
  456. args: [],
  457. source: "dagChildren\x0a\x09self subclassResponsibility",
  458. referencedClasses: [],
  459. //>>excludeEnd("ide");
  460. messageSends: ["subclassResponsibility"]
  461. }),
  462. $globals.DagNode);
  463. $core.addMethod(
  464. $core.method({
  465. selector: "dagChildren:",
  466. protocol: 'accessing',
  467. fn: function (aCollection){
  468. var self=this;
  469. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  470. return $core.withContext(function($ctx1) {
  471. //>>excludeEnd("ctx");
  472. self._subclassResponsibility();
  473. return self;
  474. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  475. }, function($ctx1) {$ctx1.fill(self,"dagChildren:",{aCollection:aCollection},$globals.DagNode)});
  476. //>>excludeEnd("ctx");
  477. },
  478. //>>excludeStart("ide", pragmas.excludeIdeData);
  479. args: ["aCollection"],
  480. source: "dagChildren: aCollection\x0a\x09self subclassResponsibility",
  481. referencedClasses: [],
  482. //>>excludeEnd("ide");
  483. messageSends: ["subclassResponsibility"]
  484. }),
  485. $globals.DagNode);
  486. $core.addMethod(
  487. $core.method({
  488. selector: "isDagNode",
  489. protocol: 'testing',
  490. fn: function (){
  491. var self=this;
  492. return true;
  493. },
  494. //>>excludeStart("ide", pragmas.excludeIdeData);
  495. args: [],
  496. source: "isDagNode\x0a\x09^ true",
  497. referencedClasses: [],
  498. //>>excludeEnd("ide");
  499. messageSends: []
  500. }),
  501. $globals.DagNode);
  502. $core.addClass('DagParentNode', $globals.DagNode, ['nodes'], 'Kernel-Dag');
  503. //>>excludeStart("ide", pragmas.excludeIdeData);
  504. $globals.DagParentNode.comment="I am `DagNode` that stores a collection of its children,\x0alazy initialized to empty array.\x0a\x0aI can `addDagChild:` to add a child.";
  505. //>>excludeEnd("ide");
  506. $core.addMethod(
  507. $core.method({
  508. selector: "addDagChild:",
  509. protocol: 'accessing',
  510. fn: function (aDagNode){
  511. var self=this;
  512. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  513. return $core.withContext(function($ctx1) {
  514. //>>excludeEnd("ctx");
  515. $recv(self._dagChildren())._add_(aDagNode);
  516. return self;
  517. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  518. }, function($ctx1) {$ctx1.fill(self,"addDagChild:",{aDagNode:aDagNode},$globals.DagParentNode)});
  519. //>>excludeEnd("ctx");
  520. },
  521. //>>excludeStart("ide", pragmas.excludeIdeData);
  522. args: ["aDagNode"],
  523. source: "addDagChild: aDagNode\x0a\x09self dagChildren add: aDagNode",
  524. referencedClasses: [],
  525. //>>excludeEnd("ide");
  526. messageSends: ["add:", "dagChildren"]
  527. }),
  528. $globals.DagParentNode);
  529. $core.addMethod(
  530. $core.method({
  531. selector: "dagChildren",
  532. protocol: 'accessing',
  533. fn: function (){
  534. var self=this;
  535. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  536. return $core.withContext(function($ctx1) {
  537. //>>excludeEnd("ctx");
  538. var $1,$receiver;
  539. $1=self["@nodes"];
  540. if(($receiver = $1) == null || $receiver.isNil){
  541. self["@nodes"]=$recv($globals.Array)._new();
  542. return self["@nodes"];
  543. } else {
  544. return $1;
  545. };
  546. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  547. }, function($ctx1) {$ctx1.fill(self,"dagChildren",{},$globals.DagParentNode)});
  548. //>>excludeEnd("ctx");
  549. },
  550. //>>excludeStart("ide", pragmas.excludeIdeData);
  551. args: [],
  552. source: "dagChildren\x0a\x09^ nodes ifNil: [ nodes := Array new ]",
  553. referencedClasses: ["Array"],
  554. //>>excludeEnd("ide");
  555. messageSends: ["ifNil:", "new"]
  556. }),
  557. $globals.DagParentNode);
  558. $core.addMethod(
  559. $core.method({
  560. selector: "dagChildren:",
  561. protocol: 'accessing',
  562. fn: function (aCollection){
  563. var self=this;
  564. self["@nodes"]=aCollection;
  565. return self;
  566. },
  567. //>>excludeStart("ide", pragmas.excludeIdeData);
  568. args: ["aCollection"],
  569. source: "dagChildren: aCollection\x0a\x09nodes := aCollection",
  570. referencedClasses: [],
  571. //>>excludeEnd("ide");
  572. messageSends: []
  573. }),
  574. $globals.DagParentNode);
  575. $core.addClass('DagSink', $globals.DagNode, ['nodes'], 'Kernel-Dag');
  576. //>>excludeStart("ide", pragmas.excludeIdeData);
  577. $globals.DagSink.comment="I am `DagNode` with no direct successors.\x0a\x0aSending `dagChildren:` with empty collection is legal.";
  578. //>>excludeEnd("ide");
  579. $core.addMethod(
  580. $core.method({
  581. selector: "dagChildren",
  582. protocol: 'accessing',
  583. fn: function (){
  584. var self=this;
  585. return [];
  586. },
  587. //>>excludeStart("ide", pragmas.excludeIdeData);
  588. args: [],
  589. source: "dagChildren\x0a\x09^ #()",
  590. referencedClasses: [],
  591. //>>excludeEnd("ide");
  592. messageSends: []
  593. }),
  594. $globals.DagSink);
  595. $core.addMethod(
  596. $core.method({
  597. selector: "dagChildren:",
  598. protocol: 'accessing',
  599. fn: function (aCollection){
  600. var self=this;
  601. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  602. return $core.withContext(function($ctx1) {
  603. //>>excludeEnd("ctx");
  604. $recv(aCollection)._ifNotEmpty_((function(){
  605. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  606. return $core.withContext(function($ctx2) {
  607. //>>excludeEnd("ctx");
  608. return self._error_("A DagSink cannot have children.");
  609. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  610. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)});
  611. //>>excludeEnd("ctx");
  612. }));
  613. return self;
  614. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  615. }, function($ctx1) {$ctx1.fill(self,"dagChildren:",{aCollection:aCollection},$globals.DagSink)});
  616. //>>excludeEnd("ctx");
  617. },
  618. //>>excludeStart("ide", pragmas.excludeIdeData);
  619. args: ["aCollection"],
  620. source: "dagChildren: aCollection\x0a\x09aCollection ifNotEmpty: [ self error: 'A DagSink cannot have children.' ]",
  621. referencedClasses: [],
  622. //>>excludeEnd("ide");
  623. messageSends: ["ifNotEmpty:", "error:"]
  624. }),
  625. $globals.DagSink);
  626. $core.addMethod(
  627. $core.method({
  628. selector: "isDagNode",
  629. protocol: '*Kernel-Dag',
  630. fn: function (){
  631. var self=this;
  632. return false;
  633. },
  634. //>>excludeStart("ide", pragmas.excludeIdeData);
  635. args: [],
  636. source: "isDagNode\x0a\x09^ false",
  637. referencedClasses: [],
  638. //>>excludeEnd("ide");
  639. messageSends: []
  640. }),
  641. $globals.Object);
  642. });